Hey everyone and welcome back! I’ve already announced this posts subject in my previous post, algebra of sets. So algebra is difficult and scary. At least that’s what people say (hmm hmm), so let’s shake that off. I’m sorry if you got the reference 🙂
If you haven’t read my previous posts I really suggest you do so as this post will continue where the previous one left off.
- Maths in IT #1: Basic set theory
- Maths in IT #2: Venn diagrams
- Maths in IT #3: Algebra of sets
- Coming soon…
Here’s a quick cheat sheet of symbols introduced in the previous post:
Universe U: The collection of all elements we consider for our scenario.
Absolute complement (or simply complement):
Relative complement of A in B:
What exactly is algebra? It’s about the study of symbols, or operations, and laws for manipulating these operations. Elementary algebra, for example, is a set of laws for operations (+, -, /, *) on numbers. Just like that and are operations on sets and the laws used to manipulating them is called the algebra of sets.
These laws can help us to simplify formulas. So let’s get started.
Consider the following addition: 2 + 3. I’m pretty sure we all know the answer is 5 and the answer doesn’t change if we switch the numbers to 3 + 2. More abstract we can say that for every two numbers x and y goes that .
When the order of operands (that is the objects on which an operation is performed) in an operation doesn’t matter for the outcome of that operation we call that operation commutative.
Multiplication (on real numbers) is commutative too, because (you may be used to seeing x or * as multiplication symbol, but you should remember from high school). Minus isn’t commutative, because and neither is division, .
When working with sets we can say that and . That means both and are commutative.
When the order in which the same operation is performed in a single formula is unimportant for the outcome of that formula we say that the operation is associative. For example . It doesn’t matter if we first evaluate 1 + 2 and then add 3 or first evaluate 2 + 3 and add it to 1, the outcome is always 6.
The same holds true for multiplication, because but not for subtraction, and division, .
When looking at sets we find that both and are associative, because and .
That means parenthesis can be omitted, removing any confusion on operator precedence.
And with the commutative and associative properties of both intersection and union we can now simplify
And when we combine intersection and union we can simplify as well. can be simplified to . Notice that we still need parenthesis to define the order of the and operations.
We can now also take the intersection or union of any number of sets because we don’t have to worry about the order of operands or operators. gets tiresome really quick though. So suppose we have to . The intersection or union of all those sets can now be expressed as follows:
And inline this look like and .
Sometimes we don’t know if a set has 100 sets. Especially when a set is an infinite set of sets the above notation is not feasible. We can now use index notation to intersect or union all sets within the set.
and basically means “intersect/union for every set i in set I” (think of a foreach loop on a List of Lists in C#).
The distributive property is difficult to describe in words. Just remember that multiplication is distributive over addition, meaning that . More generally (the multiplication symbol is often omitted between letters).
is distributive over , meaning that
Likewise is distributive over , so
We can now show that . When we apply the distributive property on we get .
Here it is again, but with colors (and non-mathematical notation) so you can follow where everything went:
(A n B) n (A u B) = ((A n B) n A) u ((A n B) n B).
Applying commutativity and associativity we can now simplify further:
In the previous article, Maths in IT #2: Venn diagrams, we have seen that and . This is called idempotence and can be applied here (twice) to simplify further:
Let’s repeat that:
So we could make use of distributivity, associativity, commutativity, and idempotence to make a rather difficult formula pretty easy! Unfortunately it was a lot less easy to do…
Unfortunately we’re not done yet. There are a few more properties, some of which we’ve already encountered, that I’d like to go over.
First we have the absorption law, which states that and .
We’ve seen the so called null element, or empty set, . Just like with numbers (, and ) there are some rules for working with . Luckily they’re not that hard.
When a universe U is defined we can say the following:
I’ve shown you that a double complement returns the original: .
Also, and .
De Morgan’s Law
Finally we’ll look at the law of De Morgan, named after its inventor, the British mathematician Augustus De Morgan.
Suppose my blog can only be read by people who have not studied maths or IT. Let and let . So now the people who may read my blog are people who haven’t studied maths or IT: . I could also say people who haven’t studied maths and people who haven’t studied IT may read my blog: . But that’s the same set of people!
In the following Venn diagram this is represented by the white part.
So in short .
Now suppose my blog may be read only by people who haven’t studied both maths and IT. So that’s . Or we could say people who haven’t studied maths and who haven’t studied IT, . And again this is the same set of people. In the Venn diagram it’s the part where A and B don’t overlap (so almost everything).
And so that means .
Now let’s take another example of how to simplify a formula. Suppose we have . So let’s first apply De Morgan’s law: . And now you may recognize a nice pattern for distributivity! So let’s apply distributivity, . That’s nice, because we know that . And now we know that . And maybe you’ll remember this from my previous post, this is . And there you have it!
Again, let’s repeat:
De Morgan’s law
And there you go! You algebra master, you!
So how will this help you in your day to day programming tasks? For most of us very little I’m afraid, except that you can work out some difficult set operations on paper and possibly simplify requirements. I’m no database developer, but I can imagine you’d need this when developing databases (and to a lesser extent when working with databases).
We did venture into the world of algebra though, and if you’re still with me I say congratulations! Algebra is a bit too abstract and difficult for many people.
I’m leaving you with a little cheat sheet of today’s lessons and I hope to see you again next time (no algebra, I promise)!
De Morgan’s Law: