SlideShare a Scribd company logo
1 of 114
The power of
symmetry
People love symmetry
They find symmetrical faces more attractive
Mathematicians are just like people :)
They too love symmetry
This is Johann Carl Friedrich Gauss (1777-1855)
He used symmetry to sum the numbers from 1 to 100
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
96 97 98 99 100
Suppose you have to sum these guys
How would you do that?
You could do this…
Is this a smart solution?
1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+
17+18+19+20+21+22+23+24+25+26+27+28+29+30+31+32+33+34+35+3
6+37+38+39+40+41+42+43+44+45+46+47+48+49+50+51+52+53+54+55
+56+57+58+59+60+61+62+63+64+65+66+67+68+69+70+71+72+73+74+
75+76+77+78+79+80+81+82+83+84+85+86+87+88+89+90+91+92+93+9
4+95+96+97+98+99+100
1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+
17+18+19+20+21+22+23+24+25+26+27+28+29+30+31+32+33+34+35+3
6+37+38+39+40+41+42+43+44+45+46+47+48+49+50+51+52+53+54+55
+56+57+58+59+60+61+62+63+64+65+66+67+68+69+70+71+72+73+74+
75+76+77+78+79+80+81+82+83+84+85+86+87+88+89+90+91+92+93+9
4+95+96+97+98+99+100
Well… it are 99 plusses, so 99 points of effort (and possibly mistake)
Could we do this with less operations(plusses)?
Remember Gauss?
1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+
17+18+19+20+21+22+23+24+25+26+27+28+29+30+31+32+33+34+35+3
6+37+38+39+40+41+42+43+44+45+46+47+48+49+50+51+52+53+54+55
+56+57+58+59+60+61+62+63+64+65+66+67+68+69+70+71+72+73+74+
75+76+77+78+79+80+81+82+83+84+85+86+87+88+89+90+91+92+93+9
4+95+96+97+98+99+100
Remember Gauss?
That’s me!
1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+
17+18+19+20+21+22+23+24+25+26+27+28+29+30+31+32+33+34+35+3
6+37+38+39+40+41+42+43+44+45+46+47+48+49+50+51+52+53+54+55
+56+57+58+59+60+61+62+63+64+65+66+67+68+69+70+71+72+73+74+
75+76+77+78+79+80+81+82+83+84+85+86+87+88+89+90+91+92+93+9
4+95+96+97+98+99+100
Remember Gauss?
He could do it with only 2 operations, using symmetry
That’s me!
1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+
17+18+19+20+21+22+23+24+25+26+27+28+29+30+31+32+33+34+35+3
6+37+38+39+40+41+42+43+44+45+46+47+48+49+50+51+52+53+54+55
+56+57+58+59+60+61+62+63+64+65+66+67+68+69+70+71+72+73+74+
75+76+77+78+79+80+81+82+83+84+85+86+87+88+89+90+91+92+93+9
4+95+96+97+98+99+100
1+2+3+4+5+ … +95+96+97+98+99+100
Let’s position the numbers a bit differently
Now we can ‘see’ the symmetry
1+2+3+4+5+ … +95+96+97+98+99+100
It’s like there’s a mirror in the middle!
This way we can make 50 groups op two
1+100 = 101
2+99 = 101
3+98 = 101
1+2+3+4+5+ … +95+96+97+98+99+100
50 groups of 101 -> 50 * (100 + 1) = 5050
With only 2 operations!
1+100 = 101
2+99 = 101
3+98 = 101
Start loving symmetry already?
Start loving symmetry already?
I do!
Let’s have a look at the next problem
Concerning a shepherd, a sheep, a wolf and a cabbage
And a river, which they have to cross
And a boat. But, the boat can only carry the shepherd plus one item
So he takes either the sheep with him, or the wolf or the cabbage
Ow, and one more thing
When left alone (without the shepherd present)
The wolf will eat the sheep, and the sheep will eat the cabbage
Can we get the entire party safely to the other side?
Lets make a diagram representing the shepherds choices
Initially, all are at the right side of the river
|HSCW
So let’s place the whole party right of the |
The shepherd (his name is Hank), the Sheep, the Wolf and the Cabbage
|HSCW
Now what can Hank do?
He can take either one of the three items with him
|HSCW
HC|SW HS | CW HW | SC
However, remember
Wolf eats sheep, sheep eats cabbage
|HSCW
HC|SW HS | CW HW | SC
So these two options are no good!
|HSCW
HC|SW HS | CW HW | SC
Now Hank is at the left side of the river, he only has one choice
Going back alone (Taking the sheep gets him back where he started)
|HSCW
HC|SW
S | HCW
HW | SCHS | CW
So what’s next?
He can take either the wolf or the cabbage
|HSCW
HC|SW
S | HCW
HW | SCHS | CW
HSC | W HSW | C
Can you finish this diagram?
0|HSCW
HC|SW
S | HCW
HW | SCHS | CW
HSC | W HSW | C
Come on, try it yourself!
0|HSCW
HC|SW
S | HCW
HW | SCHS | CW
HSC | W HSW | C
Okay, here is it 
|HSCW
HC|SW
S|HCW
HW|SCHS|CW
HSC|W HSW|C
SC|HW C|HSW W|HSC SW|HC
HSC|W HWC|S
WC|SH
WCHS|
HSW|CHWC|S
WC|SH
WCHS|
See how symmetrical it is?
|HSCW
HC|SW
S|HCW
HW|SCHS|CW
HSC|W HSW|C
SC|HW C|HSW W|HSC SW|HC
HSC|W HWC|S
WC|SH
WCHS|
HSW|CHWC|S
WC|SH
WCHS|
It doesn’t matter what we choose at the yellow point
Which means: it doesn’t matter whether we take the wolf or the cabbage
|HSCW
HC|SW
S|HCW
HW|SCHS|CW
HSC|W HSW|C
SC|HW C|HSW W|HSC SW|HC
HSC|W HWC|S
WC|SH
WCHS|
HSW|CHWC|S
WC|SH
WCHS|
We see this symmetry now in the diagram
Could we have notice this before?
|HSCW
HC|SW
S|HCW
HW|SCHS|CW
HSC|W HSW|C
SC|HW C|HSW W|HSC SW|HC
HSC|W HWC|S
WC|SH
WCHS|
HSW|CHWC|S
WC|SH
WCHS|
Lets go back to the original problem:
Wolf eats sheep, sheep eats cabbage
If we were to model this problem
We might come up with something this
But is this necessary?
All that matters is sheep can’t be with wolfs and cabbages
Who eats who…
Is irrelevant!
So let’s try modeling the problem again!
We have a shepherd, a sheep,
Plus two things that we shouldn’t combine with sheep
Lets call them anti-sheep (A)
It we construct the diagram now, it is way more simple
See how little choice there is?
We reduced the state space (# states) by half
|HSAA
HA|SA
S|HAA
HS|AA
HAS|A
SA|HA A|HSA
HAS|A HAA|S
AA|SH
AAHS|
See how little choice there is?
We reduced the state space (# states) by half
|HSAA
HA|SA
S|HAA
HS|AA
HAS|A
SA|HA A|HSA
HAS|A HAA|S
AA|SH
AAHS|
Symmetry for the win!
So next time when you are modeling something, be aware of antisheep
Don’t overmodel
The symmetric solution was invented by this guy
Edsger W. Dijkstra, a Dutch computer scientist
Edsger W. Dijkstra – Pruning the search tree http://www.cs.utexas.edu/users/EWD/transcriptions/EWD12xx/EWD1255.html
So far we’ve see how symmetry can help in solving problems
Of course seeing this symmetry is not always easy
But if you practice a little, you start seeing it everywhere
Let’s try another problem!
Finding the greatest common divisor (gcd) of two numbers
Given two numbers A en B
Determine the maximum number x, that divides both A en B
6
12
For instance 6 and 12
2, 3 and 6 all divide both numbers, but 6 is the largest
6
12
But how do we calculate the gcd of larger numbers?
We could try all numbers up to 105
105
252
Can we do better?
Using symmetry?
105
252
So let’s search for a problem that is smaller
But can be solved in the same way
105
252
Rephrasing our problem definition
We search for an x that ‘fits’ into both A and B
105 = x * z
252 = x * y
But we don’t really care about how often x fit in A and B
Remember: be aware of antisheep!
105 = x * z
252 = x * y
So how can we reduce this problem?
While keeping it similar?
105 = x * z
252 = x * y
Well, we could subtract
Now we again have two numbers in which x fits nicely, but smaller!
105 = x * z -
252 = x * y
147 = x * (y-z)
Now we can continue with 105 and 147
And again have two numbers in which x fits nicely, but smaller!
105 = x * z -
147 = x * y
42 = x * (y-z)
You can check yourself that within 5 steps we reach the answer
That’s way better that 105 steps. Thanks to…
105 = 5 * 21
252 = 21 * 21
Symmetry!
Wanna try it with a new problem?
Suppose you’re going on a backpacking trip
And you need to decide what items to bring with you
For example: Food, a towel, a first aid kit and entertainment
Each item has a certain weight and a value
But we cannot take all of them, we can only carry three kilos
Weight Value
1 2
2 1
1 3
3 4
How to decide on the maximum value we can bring?
Weight Value
1 2
2 1
1 3
3 4
Like before, we could make a decision tree
For each item, we can either take it (left arrow) or leave it (right arrow)
Start
W:1 V:2 W:0 V:0
W:3 V:3 W:1 V:2 W:2 V:1 W:0 V:0
Weight Value
1 2
2 1
1 3
3 4
Is that a smart move?
Well for four items it is okay, we have to create 16 path (2 ^ 4)
Start
W:1 V:2 W:0 V:0
W:3 V:3 W:1 V:2 W:2 V:1 W:0 V:0
Weight Value
1 2
2 1
1 3
3 4
However: 2^n is not a sweet formula!!
For 10 items, we already have more than 1000 (1024) paths
Weight Value
1 2
2 1
1 3
3 4
Like before, we want to find a smaller problem
That we can solve similar to the ‘big’ problem
Suppose this rectangle is an empty backpack
If we put one item is, what we in fact have left is…
If we put one item is, what we in fact have left is…
A smaller backpack!
With this idea we are going to solve the problem:
We put an item in the backpack, and continue with a smaller one
But we are cheating a little bit,
Since we don’t know beforehand which items to take
Therefore, we need a table listing all values for smaller backpack
From those values, we can calculate the end result
We calculate the maximum value to be obtained
For each weight (horizontal) choosing from a certain list of items (vertical)
W V
1 2
2 1
1 3
3 4
Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3
Items up to 0
Items up to 1
Items up to 2
Items up to 3
Items up to 4
This way, the final solution can be found in the lower right corner
Since there we can choose from all items, carrying weight 3
W V
1 2
2 1
1 3
3 4
Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3
Items up to 0
Items up to 1
Items up to 2
Items up to 3
Items up to 4
So how to fill this nice table?
Some values are very easy to figure out. Do you know some?
W V
1 2
2 1
1 3
3 4
Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3
Items up to 0
Items up to 1
Items up to 2
Items up to 3
Items up to 4
Well, if you cannot carry any weight…
W V
1 2
2 1
1 3
3 4
Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3
Items up to 0
Items up to 1
Items up to 2
Items up to 3
Items up to 4
Well, if you cannot carry any weight…
You will not carry anything of value anyway
W V
1 2
2 1
1 3
3 4
Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3
Items up to 0
0
Items up to 1
0
Items up to 2
0
Items up to 3
0
Items up to 4
0
And if you cannot choose from any item…
W V
1 2
2 1
1 3
3 4
Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3
Items up to 0
0
Items up to 1
0
Items up to 2
0
Items up to 3
0
Items up to 4
0
And if you cannot choose from any item…
Nothing is to be gained either
W V
1 2
2 1
1 3
3 4
Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3
Items up to 0
0 0 0 0
Items up to 1
0
Items up to 2
0
Items up to 3
0
Items up to 4
0
What else is easy?
Lets try the second row…
W V
1 2
2 1
1 3
3 4
Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3
Items up to 0
0 0 0 0
Items up to 1
0
Items up to 2
0
Items up to 3
0
Items up to 4
0
Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3
Items up to 0
0 0 0 0
Items up to 1
0
Items up to 2
0
Items up to 3
0
Items up to 4
0
With the burger only, we can never do better than value 2
Which is the value of the burger
W V
1 2
2 1
1 3
3 4
Now for the remainder of the second row
In the yellow box we have: items up to 2, max weight 1
W V
1 2
2 1
1 3
3 4
Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3
Items up to 0
0 0 0 0
Items up to 1
0 2 2 2
Items up to 2
0
Items up to 3
0
Items up to 4
0
What can we do? We can’t take the towel, since it weights 2
So there’s no option, but just sticking with the burger (value 2)
W V
1 2
2 1
1 3
3 4
Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3
Items up to 0
0 0 0 0
Items up to 1
0 2 2 2
Items up to 2
0 2
Items up to 3
0
Items up to 4
0
Let’s do one more!
Now we can choose from the first three items
W V
1 2
2 1
1 3
3 4
Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3
Items up to 0
0 0 0 0
Items up to 1
0 2 2 2
Items up to 2
0 2
Items up to 3
0
Items up to 4
0
So now we could also take the mushroom.
It has weight 1, so at least it fits
W V
1 2
2 1
1 3
3 4
Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3
Items up to 0
0 0 0 0
Items up to 1
0 2 2 2
Items up to 2
0 2
Items up to 3
0
Items up to 4
0
But is this better?
Well… What we have now is value 2, and the mushroom is worth 3
W V
1 2
2 1
1 3
3 4
Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3
Items up to 0
0 0 0 0
Items up to 1
0 2 2 2
Items up to 2
0 2
Items up to 3
0
Items up to 4
0
But is this better?
Well… What we have now is value 2, and the mushroom is worth 3
W V
1 2
2 1
1 3
3 4
Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3
Items up to 0
0 0 0 0
Items up to 1
0 2 2 2
Items up to 2
0 2
Items up to 3
0
Items up to 4
0
So let’s ditch the burger, and go for the mushrooms
Than our maximum value is 3, and that is obviously better than 2.
W V
1 2
2 1
1 3
3 4
Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3
Items up to 0
0 0 0 0
Items up to 1
0 2 2 2
Items up to 2
0 2
Items up to 3
0 3
Items up to 4
0
This way, we can fill the entire table
W V
1 2
2 1
1 3
3 4
Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3
Items up to 0
0 0 0 0
Items up to 1
0 2 2 2
Items up to 2
0 2 2 3
Items up to 3
0 3 3 3
Items up to 4
0 3 3 5
To calculate the values, we secretly used a recurrence relation
This means describing a value in the table with other values in the table
W V
1 2
2 1
1 3
3 4
Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3
Items up to 0
0 0 0 0
Items up to 1
0 2 2 2
Items up to 2
0 2 2 3
Items up to 3
0 3 3 3
Items up to 4
0 3 3 5
Let’s call the table T. T has two dimensions, i (items) and w(weight)
Here we highlight T[2,1], indicating items up to 2, maximum weight 1
W V
1 2
2 1
1 3
3 4
Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3
Items up to 0
0 0 0 0
Items up to 1
0 2 2 2
Items up to 2
0 2 2 3
Items up to 3
0 3 3 3
Items up to 4
0 3 3 5
How can we calculate this value T[2,1]?
In stead of reasoning about it as we did before?
W V
1 2
2 1
1 3
3 4
Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3
Items up to 0
0 0 0 0
Items up to 1
0 2 2 2
Items up to 2
0 2 2 3
Items up to 3
0 3 3 3
Items up to 4
0 3 3 5
Well what did we do before?
We said: Since the towel does not fit, we stick with the burger
W V
1 2
2 1
1 3
3 4
Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3
Items up to 0
0 0 0 0
Items up to 1
0 2 2 2
Items up to 2
0 2 2 3
Items up to 3
0 3 3 3
Items up to 4
0 3 3 5
if wi < w (the new item is too heavy)
then T[i,w] = T[i-1,w] (we stick with what we already have)
W V
1 2
2 1
1 3
3 4
Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3
Items up to 0
0 0 0 0
Items up to 1
0 2 2 2
Items up to 2
0 2 2 3
Items up to 3
0 3 3 3
Items up to 4
0 3 3 5
Now, let’s have a look at what we did at T[3,1]
We said: It fits, and now we have value 2, and the mushrooms is worth 3
W V
1 2
2 1
1 3
3 4
Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3
Items up to 0
0 0 0 0
Items up to 1
0 2 2 2
Items up to 2
0 2 2 3
Items up to 3
0 3 3 3
Items up to 4
0 3 3 5
if wi <= w (this new item fits)
then T[i,w] = Max (T[i-1,w], T[i-1-w-wi]+vi) (we check if we can do better)
W V
1 2
2 1
1 3
3 4
Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3
Items up to 0
0 0 0 0
Items up to 1
0 2 2 2
Items up to 2
0 2 2 3
Items up to 3
0 3 3 3
Items up to 4
0 3 3 5
To perform this calculation, we only need n2 operations
In stead of 2n Okay, in this case both are 16, but you get the idea :)
W V
1 2
2 1
1 3
3 4
Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3
Items up to 0
0 0 0 0
Items up to 1
0 2 2 2
Items up to 2
0 2 2 3
Items up to 3
0 3 3 3
Items up to 4
0 3 3 5
Again, we reduced complexity by seeing the symmetry!
W V
1 2
2 1
1 3
3 4
Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3
Items up to 0
0 0 0 0
Items up to 1
0 2 2 2
Items up to 2
0 2 2 3
Items up to 3
0 3 3 3
Items up to 4
0 3 3 5
So let’s do one little more problem
Calculating all prime numbers
Did you know they were named after this guy?
Okay they weren’t, but he does makes a nice background
Prime numbers are numbers only divisible by 1 and itself
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
So how do we know what’s a prime number and what’s not?
We could check all divisors, per number.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
But that could take up to the root of each number
Lets use symmetry, and find a smaller problem like this one.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
Suppose we already have a number that’s prime.
Say 2. What do we know now?
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
A hint: It is something about every multiple of two…
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
Exactly, they are not primes!
Since they have 2 as a divisor
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
We have eliminated half of the numbers
(Okay we have infinitely many left, but still…)
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
We can do the same trick with 3
Identify it as prime, and remove all numbers divisible by it
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
This way we can quickly determine all prime numbers
Thanks to…
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
The power of
symmetry
Thanks for your attention!
The power of
symmetry
And remember:
Try to find symmetry everywhere
2n is never fun
And beware of antisheep
The power of
symmetry
This presentation was created by Felienne Hermans,
PhD student and entrepreneur
And presented at the yearly Devnology Community Day 6 november 2010
@Felienne
If you liked this presentation, you might also like these books
The author of the first two is nice to follow on Twitter: @marcusdusautoy
Books on symmetry
(in increasing order of difficulty)
General mathematical
awesomeness
More cool programming

More Related Content

Viewers also liked

New trends in data analysis and visualization on the web
New trends in data analysis and visualization on the webNew trends in data analysis and visualization on the web
New trends in data analysis and visualization on the web
Javier de la Torre
 
Mastering Customer Data on Apache Spark
Mastering Customer Data on Apache SparkMastering Customer Data on Apache Spark
Mastering Customer Data on Apache Spark
Caserta
 
Introduction to Dublin Core Metadata
Introduction to Dublin Core MetadataIntroduction to Dublin Core Metadata
Introduction to Dublin Core Metadata
Hannes Ebner
 

Viewers also liked (20)

Lasst die Daten sprechen
Lasst die Daten sprechenLasst die Daten sprechen
Lasst die Daten sprechen
 
Presentatie data visualisatie, interactive storytelling
Presentatie data visualisatie, interactive storytellingPresentatie data visualisatie, interactive storytelling
Presentatie data visualisatie, interactive storytelling
 
Tips and Tricks for Graph Data Modeling
Tips and Tricks for Graph Data ModelingTips and Tricks for Graph Data Modeling
Tips and Tricks for Graph Data Modeling
 
New trends in data analysis and visualization on the web
New trends in data analysis and visualization on the webNew trends in data analysis and visualization on the web
New trends in data analysis and visualization on the web
 
Panama Papers and Beyond: Unveiling Secrecy with Graphs
Panama Papers and Beyond: Unveiling Secrecy with GraphsPanama Papers and Beyond: Unveiling Secrecy with Graphs
Panama Papers and Beyond: Unveiling Secrecy with Graphs
 
Neo4j the Anti Crime Database
Neo4j the Anti Crime DatabaseNeo4j the Anti Crime Database
Neo4j the Anti Crime Database
 
Neo4j GraphTalks Panama Papers
Neo4j GraphTalks Panama PapersNeo4j GraphTalks Panama Papers
Neo4j GraphTalks Panama Papers
 
Continuous Delivery
Continuous DeliveryContinuous Delivery
Continuous Delivery
 
Neo4j PartnerDay Amsterdam 2017
Neo4j PartnerDay Amsterdam 2017Neo4j PartnerDay Amsterdam 2017
Neo4j PartnerDay Amsterdam 2017
 
Continuous Delivery
Continuous DeliveryContinuous Delivery
Continuous Delivery
 
TEDxDelft
TEDxDelftTEDxDelft
TEDxDelft
 
raph Databases with Neo4j – Emil Eifrem
raph Databases with Neo4j – Emil Eifremraph Databases with Neo4j – Emil Eifrem
raph Databases with Neo4j – Emil Eifrem
 
Museo Torino - un esempio reale d'uso di NOSQL-GraphDB, Linked Data e Web Sem...
Museo Torino - un esempio reale d'uso di NOSQL-GraphDB, Linked Data e Web Sem...Museo Torino - un esempio reale d'uso di NOSQL-GraphDB, Linked Data e Web Sem...
Museo Torino - un esempio reale d'uso di NOSQL-GraphDB, Linked Data e Web Sem...
 
Presentatie Marktonderzoek
Presentatie MarktonderzoekPresentatie Marktonderzoek
Presentatie Marktonderzoek
 
Graph db
Graph dbGraph db
Graph db
 
AWS Summit London 2014 | Improving Availability and Lowering Costs (300)
AWS Summit London 2014 | Improving Availability and Lowering Costs (300)AWS Summit London 2014 | Improving Availability and Lowering Costs (300)
AWS Summit London 2014 | Improving Availability and Lowering Costs (300)
 
Graphs in the Real World
Graphs in the Real WorldGraphs in the Real World
Graphs in the Real World
 
Mastering Customer Data on Apache Spark
Mastering Customer Data on Apache SparkMastering Customer Data on Apache Spark
Mastering Customer Data on Apache Spark
 
Introduction to Dublin Core Metadata
Introduction to Dublin Core MetadataIntroduction to Dublin Core Metadata
Introduction to Dublin Core Metadata
 
Graph Databases for Master Data Management
Graph Databases for Master Data ManagementGraph Databases for Master Data Management
Graph Databases for Master Data Management
 

Similar to The power of symmetry

Precalculus 10 Sequences and Series.pptx
Precalculus 10 Sequences and Series.pptxPrecalculus 10 Sequences and Series.pptx
Precalculus 10 Sequences and Series.pptx
DominicCaling
 
The volume of curved side objects
The volume of curved side objectsThe volume of curved side objects
The volume of curved side objects
reezali foundation
 
mathplus-module-FINALREVISED-2023.pdf
mathplus-module-FINALREVISED-2023.pdfmathplus-module-FINALREVISED-2023.pdf
mathplus-module-FINALREVISED-2023.pdf
AdonisBrutas
 

Similar to The power of symmetry (20)

Amatyc Ignite 2015 Second Half
Amatyc Ignite 2015 Second HalfAmatyc Ignite 2015 Second Half
Amatyc Ignite 2015 Second Half
 
Yr7-AlgebraicExpressions (1).pptx
Yr7-AlgebraicExpressions (1).pptxYr7-AlgebraicExpressions (1).pptx
Yr7-AlgebraicExpressions (1).pptx
 
6) Equations involving x².pptx
6) Equations involving x².pptx6) Equations involving x².pptx
6) Equations involving x².pptx
 
02 Analysis of Algorithms: Divide and Conquer
02 Analysis of Algorithms: Divide and Conquer02 Analysis of Algorithms: Divide and Conquer
02 Analysis of Algorithms: Divide and Conquer
 
Middle school math quiz
Middle school math quizMiddle school math quiz
Middle school math quiz
 
Real numbers
Real numbers Real numbers
Real numbers
 
Mathematics high school level quiz - Part I
Mathematics high school level quiz - Part IMathematics high school level quiz - Part I
Mathematics high school level quiz - Part I
 
Maths project
Maths projectMaths project
Maths project
 
class 10 chapter 1- real numbers
class 10 chapter 1- real numbersclass 10 chapter 1- real numbers
class 10 chapter 1- real numbers
 
Maths project
Maths projectMaths project
Maths project
 
Maths project
Maths projectMaths project
Maths project
 
Aed.pptx
Aed.pptxAed.pptx
Aed.pptx
 
P1-Chp12-Differentiation.pptx
P1-Chp12-Differentiation.pptxP1-Chp12-Differentiation.pptx
P1-Chp12-Differentiation.pptx
 
Precalculus 10 Sequences and Series.pptx
Precalculus 10 Sequences and Series.pptxPrecalculus 10 Sequences and Series.pptx
Precalculus 10 Sequences and Series.pptx
 
The volume of curved side objects
The volume of curved side objectsThe volume of curved side objects
The volume of curved side objects
 
mathplus-module-FINALREVISED-2023.pdf
mathplus-module-FINALREVISED-2023.pdfmathplus-module-FINALREVISED-2023.pdf
mathplus-module-FINALREVISED-2023.pdf
 
Math Drill
Math DrillMath Drill
Math Drill
 
Math Drill2
Math Drill2Math Drill2
Math Drill2
 
Weekly Dose 19 - Maths Olympiad Practice
Weekly Dose 19 - Maths Olympiad PracticeWeekly Dose 19 - Maths Olympiad Practice
Weekly Dose 19 - Maths Olympiad Practice
 
Vectors Yr 1.pptx
Vectors Yr 1.pptxVectors Yr 1.pptx
Vectors Yr 1.pptx
 

More from Felienne Hermans

Do Code Smell Hamper Novice Programmers?
Do Code Smell Hamper Novice Programmers?Do Code Smell Hamper Novice Programmers?
Do Code Smell Hamper Novice Programmers?
Felienne Hermans
 
An overview of my PhD research
An overview of my PhD researchAn overview of my PhD research
An overview of my PhD research
Felienne Hermans
 

More from Felienne Hermans (17)

Using F# and genetic programming to play computer bridge
Using F# and genetic programming to play computer bridgeUsing F# and genetic programming to play computer bridge
Using F# and genetic programming to play computer bridge
 
Functional Programming in Excel
Functional Programming in ExcelFunctional Programming in Excel
Functional Programming in Excel
 
How does code sound?
How does code sound?How does code sound?
How does code sound?
 
Programming is logical reasoning?
Programming is logical reasoning?Programming is logical reasoning?
Programming is logical reasoning?
 
Do Code Smell Hamper Novice Programmers?
Do Code Smell Hamper Novice Programmers?Do Code Smell Hamper Novice Programmers?
Do Code Smell Hamper Novice Programmers?
 
Programming by Calculation
Programming by CalculationProgramming by Calculation
Programming by Calculation
 
A board game night with geeks: attacking Quarto ties with SAT solvers
A board game night with geeks: attacking Quarto ties with SAT solversA board game night with geeks: attacking Quarto ties with SAT solvers
A board game night with geeks: attacking Quarto ties with SAT solvers
 
Spreadsheets for developers
Spreadsheets for developersSpreadsheets for developers
Spreadsheets for developers
 
Spreadsheets are code
Spreadsheets are codeSpreadsheets are code
Spreadsheets are code
 
Presenting: structure story and support
Presenting: structure story and supportPresenting: structure story and support
Presenting: structure story and support
 
Improving Spreadsheet Test Practices
Improving Spreadsheet Test PracticesImproving Spreadsheet Test Practices
Improving Spreadsheet Test Practices
 
Putting the science in computer science
Putting the science in computer sciencePutting the science in computer science
Putting the science in computer science
 
Spreadsheets are graphs too: Using Neo4J as backend to store spreadsheet info...
Spreadsheets are graphs too: Using Neo4J as backend to store spreadsheet info...Spreadsheets are graphs too: Using Neo4J as backend to store spreadsheet info...
Spreadsheets are graphs too: Using Neo4J as backend to store spreadsheet info...
 
Social media for the busy scientist
Social media for the busy scientistSocial media for the busy scientist
Social media for the busy scientist
 
An overview of my PhD research
An overview of my PhD researchAn overview of my PhD research
An overview of my PhD research
 
Detecting and Visualizing Inter-worksheet Smells in Spreadsheets
Detecting and Visualizing Inter-worksheet Smells in Spreadsheets Detecting and Visualizing Inter-worksheet Smells in Spreadsheets
Detecting and Visualizing Inter-worksheet Smells in Spreadsheets
 
Spreadsheet Testing
Spreadsheet TestingSpreadsheet Testing
Spreadsheet Testing
 

Recently uploaded

Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
UK Journal
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
FIDO Alliance
 

Recently uploaded (20)

Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & Ireland
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream Processing
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
 
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
TEST BANK For, Information Technology Project Management 9th Edition Kathy Sc...
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
 
TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024TopCryptoSupers 12thReport OrionX May2024
TopCryptoSupers 12thReport OrionX May2024
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
 

The power of symmetry

  • 2. People love symmetry They find symmetrical faces more attractive
  • 3. Mathematicians are just like people :) They too love symmetry
  • 4. This is Johann Carl Friedrich Gauss (1777-1855) He used symmetry to sum the numbers from 1 to 100
  • 5. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 Suppose you have to sum these guys How would you do that?
  • 6. You could do this… Is this a smart solution? 1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+ 17+18+19+20+21+22+23+24+25+26+27+28+29+30+31+32+33+34+35+3 6+37+38+39+40+41+42+43+44+45+46+47+48+49+50+51+52+53+54+55 +56+57+58+59+60+61+62+63+64+65+66+67+68+69+70+71+72+73+74+ 75+76+77+78+79+80+81+82+83+84+85+86+87+88+89+90+91+92+93+9 4+95+96+97+98+99+100
  • 10. Remember Gauss? He could do it with only 2 operations, using symmetry That’s me! 1+2+3+4+5+6+7+8+9+10+11+12+13+14+15+16+ 17+18+19+20+21+22+23+24+25+26+27+28+29+30+31+32+33+34+35+3 6+37+38+39+40+41+42+43+44+45+46+47+48+49+50+51+52+53+54+55 +56+57+58+59+60+61+62+63+64+65+66+67+68+69+70+71+72+73+74+ 75+76+77+78+79+80+81+82+83+84+85+86+87+88+89+90+91+92+93+9 4+95+96+97+98+99+100
  • 11. 1+2+3+4+5+ … +95+96+97+98+99+100 Let’s position the numbers a bit differently Now we can ‘see’ the symmetry
  • 12. 1+2+3+4+5+ … +95+96+97+98+99+100 It’s like there’s a mirror in the middle! This way we can make 50 groups op two 1+100 = 101 2+99 = 101 3+98 = 101
  • 13. 1+2+3+4+5+ … +95+96+97+98+99+100 50 groups of 101 -> 50 * (100 + 1) = 5050 With only 2 operations! 1+100 = 101 2+99 = 101 3+98 = 101
  • 15. Start loving symmetry already? I do!
  • 16. Let’s have a look at the next problem Concerning a shepherd, a sheep, a wolf and a cabbage
  • 17. And a river, which they have to cross And a boat. But, the boat can only carry the shepherd plus one item
  • 18. So he takes either the sheep with him, or the wolf or the cabbage Ow, and one more thing
  • 19. When left alone (without the shepherd present) The wolf will eat the sheep, and the sheep will eat the cabbage
  • 20. Can we get the entire party safely to the other side?
  • 21. Lets make a diagram representing the shepherds choices Initially, all are at the right side of the river |HSCW
  • 22. So let’s place the whole party right of the | The shepherd (his name is Hank), the Sheep, the Wolf and the Cabbage |HSCW
  • 23. Now what can Hank do? He can take either one of the three items with him |HSCW HC|SW HS | CW HW | SC
  • 24. However, remember Wolf eats sheep, sheep eats cabbage |HSCW HC|SW HS | CW HW | SC
  • 25. So these two options are no good! |HSCW HC|SW HS | CW HW | SC
  • 26. Now Hank is at the left side of the river, he only has one choice Going back alone (Taking the sheep gets him back where he started) |HSCW HC|SW S | HCW HW | SCHS | CW
  • 27. So what’s next? He can take either the wolf or the cabbage |HSCW HC|SW S | HCW HW | SCHS | CW HSC | W HSW | C
  • 28. Can you finish this diagram? 0|HSCW HC|SW S | HCW HW | SCHS | CW HSC | W HSW | C
  • 29. Come on, try it yourself! 0|HSCW HC|SW S | HCW HW | SCHS | CW HSC | W HSW | C
  • 30. Okay, here is it  |HSCW HC|SW S|HCW HW|SCHS|CW HSC|W HSW|C SC|HW C|HSW W|HSC SW|HC HSC|W HWC|S WC|SH WCHS| HSW|CHWC|S WC|SH WCHS|
  • 31. See how symmetrical it is? |HSCW HC|SW S|HCW HW|SCHS|CW HSC|W HSW|C SC|HW C|HSW W|HSC SW|HC HSC|W HWC|S WC|SH WCHS| HSW|CHWC|S WC|SH WCHS|
  • 32. It doesn’t matter what we choose at the yellow point Which means: it doesn’t matter whether we take the wolf or the cabbage |HSCW HC|SW S|HCW HW|SCHS|CW HSC|W HSW|C SC|HW C|HSW W|HSC SW|HC HSC|W HWC|S WC|SH WCHS| HSW|CHWC|S WC|SH WCHS|
  • 33. We see this symmetry now in the diagram Could we have notice this before? |HSCW HC|SW S|HCW HW|SCHS|CW HSC|W HSW|C SC|HW C|HSW W|HSC SW|HC HSC|W HWC|S WC|SH WCHS| HSW|CHWC|S WC|SH WCHS|
  • 34. Lets go back to the original problem: Wolf eats sheep, sheep eats cabbage
  • 35. If we were to model this problem We might come up with something this
  • 36. But is this necessary? All that matters is sheep can’t be with wolfs and cabbages
  • 37. Who eats who… Is irrelevant!
  • 38. So let’s try modeling the problem again!
  • 39. We have a shepherd, a sheep, Plus two things that we shouldn’t combine with sheep
  • 40. Lets call them anti-sheep (A) It we construct the diagram now, it is way more simple
  • 41. See how little choice there is? We reduced the state space (# states) by half |HSAA HA|SA S|HAA HS|AA HAS|A SA|HA A|HSA HAS|A HAA|S AA|SH AAHS|
  • 42. See how little choice there is? We reduced the state space (# states) by half |HSAA HA|SA S|HAA HS|AA HAS|A SA|HA A|HSA HAS|A HAA|S AA|SH AAHS| Symmetry for the win!
  • 43. So next time when you are modeling something, be aware of antisheep Don’t overmodel
  • 44. The symmetric solution was invented by this guy Edsger W. Dijkstra, a Dutch computer scientist Edsger W. Dijkstra – Pruning the search tree http://www.cs.utexas.edu/users/EWD/transcriptions/EWD12xx/EWD1255.html
  • 45. So far we’ve see how symmetry can help in solving problems Of course seeing this symmetry is not always easy
  • 46. But if you practice a little, you start seeing it everywhere Let’s try another problem!
  • 47. Finding the greatest common divisor (gcd) of two numbers
  • 48. Given two numbers A en B Determine the maximum number x, that divides both A en B 6 12
  • 49. For instance 6 and 12 2, 3 and 6 all divide both numbers, but 6 is the largest 6 12
  • 50. But how do we calculate the gcd of larger numbers? We could try all numbers up to 105 105 252
  • 51. Can we do better? Using symmetry? 105 252
  • 52. So let’s search for a problem that is smaller But can be solved in the same way 105 252
  • 53. Rephrasing our problem definition We search for an x that ‘fits’ into both A and B 105 = x * z 252 = x * y
  • 54. But we don’t really care about how often x fit in A and B Remember: be aware of antisheep! 105 = x * z 252 = x * y
  • 55. So how can we reduce this problem? While keeping it similar? 105 = x * z 252 = x * y
  • 56. Well, we could subtract Now we again have two numbers in which x fits nicely, but smaller! 105 = x * z - 252 = x * y 147 = x * (y-z)
  • 57. Now we can continue with 105 and 147 And again have two numbers in which x fits nicely, but smaller! 105 = x * z - 147 = x * y 42 = x * (y-z)
  • 58. You can check yourself that within 5 steps we reach the answer That’s way better that 105 steps. Thanks to… 105 = 5 * 21 252 = 21 * 21
  • 59. Symmetry! Wanna try it with a new problem?
  • 60. Suppose you’re going on a backpacking trip And you need to decide what items to bring with you
  • 61. For example: Food, a towel, a first aid kit and entertainment
  • 62. Each item has a certain weight and a value But we cannot take all of them, we can only carry three kilos Weight Value 1 2 2 1 1 3 3 4
  • 63. How to decide on the maximum value we can bring? Weight Value 1 2 2 1 1 3 3 4
  • 64. Like before, we could make a decision tree For each item, we can either take it (left arrow) or leave it (right arrow) Start W:1 V:2 W:0 V:0 W:3 V:3 W:1 V:2 W:2 V:1 W:0 V:0 Weight Value 1 2 2 1 1 3 3 4
  • 65. Is that a smart move? Well for four items it is okay, we have to create 16 path (2 ^ 4) Start W:1 V:2 W:0 V:0 W:3 V:3 W:1 V:2 W:2 V:1 W:0 V:0 Weight Value 1 2 2 1 1 3 3 4
  • 66. However: 2^n is not a sweet formula!! For 10 items, we already have more than 1000 (1024) paths Weight Value 1 2 2 1 1 3 3 4
  • 67. Like before, we want to find a smaller problem That we can solve similar to the ‘big’ problem
  • 68. Suppose this rectangle is an empty backpack
  • 69. If we put one item is, what we in fact have left is…
  • 70. If we put one item is, what we in fact have left is… A smaller backpack!
  • 71. With this idea we are going to solve the problem: We put an item in the backpack, and continue with a smaller one
  • 72. But we are cheating a little bit, Since we don’t know beforehand which items to take
  • 73. Therefore, we need a table listing all values for smaller backpack From those values, we can calculate the end result
  • 74. We calculate the maximum value to be obtained For each weight (horizontal) choosing from a certain list of items (vertical) W V 1 2 2 1 1 3 3 4 Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3 Items up to 0 Items up to 1 Items up to 2 Items up to 3 Items up to 4
  • 75. This way, the final solution can be found in the lower right corner Since there we can choose from all items, carrying weight 3 W V 1 2 2 1 1 3 3 4 Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3 Items up to 0 Items up to 1 Items up to 2 Items up to 3 Items up to 4
  • 76. So how to fill this nice table? Some values are very easy to figure out. Do you know some? W V 1 2 2 1 1 3 3 4 Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3 Items up to 0 Items up to 1 Items up to 2 Items up to 3 Items up to 4
  • 77. Well, if you cannot carry any weight… W V 1 2 2 1 1 3 3 4 Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3 Items up to 0 Items up to 1 Items up to 2 Items up to 3 Items up to 4
  • 78. Well, if you cannot carry any weight… You will not carry anything of value anyway W V 1 2 2 1 1 3 3 4 Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3 Items up to 0 0 Items up to 1 0 Items up to 2 0 Items up to 3 0 Items up to 4 0
  • 79. And if you cannot choose from any item… W V 1 2 2 1 1 3 3 4 Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3 Items up to 0 0 Items up to 1 0 Items up to 2 0 Items up to 3 0 Items up to 4 0
  • 80. And if you cannot choose from any item… Nothing is to be gained either W V 1 2 2 1 1 3 3 4 Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3 Items up to 0 0 0 0 0 Items up to 1 0 Items up to 2 0 Items up to 3 0 Items up to 4 0
  • 81. What else is easy? Lets try the second row… W V 1 2 2 1 1 3 3 4 Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3 Items up to 0 0 0 0 0 Items up to 1 0 Items up to 2 0 Items up to 3 0 Items up to 4 0
  • 82. Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3 Items up to 0 0 0 0 0 Items up to 1 0 Items up to 2 0 Items up to 3 0 Items up to 4 0 With the burger only, we can never do better than value 2 Which is the value of the burger W V 1 2 2 1 1 3 3 4
  • 83. Now for the remainder of the second row In the yellow box we have: items up to 2, max weight 1 W V 1 2 2 1 1 3 3 4 Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3 Items up to 0 0 0 0 0 Items up to 1 0 2 2 2 Items up to 2 0 Items up to 3 0 Items up to 4 0
  • 84. What can we do? We can’t take the towel, since it weights 2 So there’s no option, but just sticking with the burger (value 2) W V 1 2 2 1 1 3 3 4 Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3 Items up to 0 0 0 0 0 Items up to 1 0 2 2 2 Items up to 2 0 2 Items up to 3 0 Items up to 4 0
  • 85. Let’s do one more! Now we can choose from the first three items W V 1 2 2 1 1 3 3 4 Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3 Items up to 0 0 0 0 0 Items up to 1 0 2 2 2 Items up to 2 0 2 Items up to 3 0 Items up to 4 0
  • 86. So now we could also take the mushroom. It has weight 1, so at least it fits W V 1 2 2 1 1 3 3 4 Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3 Items up to 0 0 0 0 0 Items up to 1 0 2 2 2 Items up to 2 0 2 Items up to 3 0 Items up to 4 0
  • 87. But is this better? Well… What we have now is value 2, and the mushroom is worth 3 W V 1 2 2 1 1 3 3 4 Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3 Items up to 0 0 0 0 0 Items up to 1 0 2 2 2 Items up to 2 0 2 Items up to 3 0 Items up to 4 0
  • 88. But is this better? Well… What we have now is value 2, and the mushroom is worth 3 W V 1 2 2 1 1 3 3 4 Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3 Items up to 0 0 0 0 0 Items up to 1 0 2 2 2 Items up to 2 0 2 Items up to 3 0 Items up to 4 0
  • 89. So let’s ditch the burger, and go for the mushrooms Than our maximum value is 3, and that is obviously better than 2. W V 1 2 2 1 1 3 3 4 Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3 Items up to 0 0 0 0 0 Items up to 1 0 2 2 2 Items up to 2 0 2 Items up to 3 0 3 Items up to 4 0
  • 90. This way, we can fill the entire table W V 1 2 2 1 1 3 3 4 Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3 Items up to 0 0 0 0 0 Items up to 1 0 2 2 2 Items up to 2 0 2 2 3 Items up to 3 0 3 3 3 Items up to 4 0 3 3 5
  • 91. To calculate the values, we secretly used a recurrence relation This means describing a value in the table with other values in the table W V 1 2 2 1 1 3 3 4 Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3 Items up to 0 0 0 0 0 Items up to 1 0 2 2 2 Items up to 2 0 2 2 3 Items up to 3 0 3 3 3 Items up to 4 0 3 3 5
  • 92. Let’s call the table T. T has two dimensions, i (items) and w(weight) Here we highlight T[2,1], indicating items up to 2, maximum weight 1 W V 1 2 2 1 1 3 3 4 Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3 Items up to 0 0 0 0 0 Items up to 1 0 2 2 2 Items up to 2 0 2 2 3 Items up to 3 0 3 3 3 Items up to 4 0 3 3 5
  • 93. How can we calculate this value T[2,1]? In stead of reasoning about it as we did before? W V 1 2 2 1 1 3 3 4 Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3 Items up to 0 0 0 0 0 Items up to 1 0 2 2 2 Items up to 2 0 2 2 3 Items up to 3 0 3 3 3 Items up to 4 0 3 3 5
  • 94. Well what did we do before? We said: Since the towel does not fit, we stick with the burger W V 1 2 2 1 1 3 3 4 Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3 Items up to 0 0 0 0 0 Items up to 1 0 2 2 2 Items up to 2 0 2 2 3 Items up to 3 0 3 3 3 Items up to 4 0 3 3 5
  • 95. if wi < w (the new item is too heavy) then T[i,w] = T[i-1,w] (we stick with what we already have) W V 1 2 2 1 1 3 3 4 Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3 Items up to 0 0 0 0 0 Items up to 1 0 2 2 2 Items up to 2 0 2 2 3 Items up to 3 0 3 3 3 Items up to 4 0 3 3 5
  • 96. Now, let’s have a look at what we did at T[3,1] We said: It fits, and now we have value 2, and the mushrooms is worth 3 W V 1 2 2 1 1 3 3 4 Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3 Items up to 0 0 0 0 0 Items up to 1 0 2 2 2 Items up to 2 0 2 2 3 Items up to 3 0 3 3 3 Items up to 4 0 3 3 5
  • 97. if wi <= w (this new item fits) then T[i,w] = Max (T[i-1,w], T[i-1-w-wi]+vi) (we check if we can do better) W V 1 2 2 1 1 3 3 4 Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3 Items up to 0 0 0 0 0 Items up to 1 0 2 2 2 Items up to 2 0 2 2 3 Items up to 3 0 3 3 3 Items up to 4 0 3 3 5
  • 98. To perform this calculation, we only need n2 operations In stead of 2n Okay, in this case both are 16, but you get the idea :) W V 1 2 2 1 1 3 3 4 Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3 Items up to 0 0 0 0 0 Items up to 1 0 2 2 2 Items up to 2 0 2 2 3 Items up to 3 0 3 3 3 Items up to 4 0 3 3 5
  • 99. Again, we reduced complexity by seeing the symmetry! W V 1 2 2 1 1 3 3 4 Max. value Max weight:0 Max weight:1 Max weight:2 Max weight:3 Items up to 0 0 0 0 0 Items up to 1 0 2 2 2 Items up to 2 0 2 2 3 Items up to 3 0 3 3 3 Items up to 4 0 3 3 5
  • 100. So let’s do one little more problem
  • 101. Calculating all prime numbers Did you know they were named after this guy?
  • 102. Okay they weren’t, but he does makes a nice background Prime numbers are numbers only divisible by 1 and itself 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
  • 103. So how do we know what’s a prime number and what’s not? We could check all divisors, per number. 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
  • 104. But that could take up to the root of each number Lets use symmetry, and find a smaller problem like this one. 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
  • 105. Suppose we already have a number that’s prime. Say 2. What do we know now? 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
  • 106. A hint: It is something about every multiple of two… 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
  • 107. Exactly, they are not primes! Since they have 2 as a divisor 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
  • 108. We have eliminated half of the numbers (Okay we have infinitely many left, but still…) 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
  • 109. We can do the same trick with 3 Identify it as prime, and remove all numbers divisible by it 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
  • 110. This way we can quickly determine all prime numbers Thanks to… 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
  • 111. The power of symmetry Thanks for your attention!
  • 112. The power of symmetry And remember: Try to find symmetry everywhere 2n is never fun And beware of antisheep
  • 113. The power of symmetry This presentation was created by Felienne Hermans, PhD student and entrepreneur And presented at the yearly Devnology Community Day 6 november 2010 @Felienne
  • 114. If you liked this presentation, you might also like these books The author of the first two is nice to follow on Twitter: @marcusdusautoy Books on symmetry (in increasing order of difficulty) General mathematical awesomeness More cool programming

Editor's Notes

  1. [NatureItem||Abstract Bool Eats(n:NatureItem)]^[Vegetable||Abstract Bool Eats(n:NatureItem)], [NatureItem]^[Animal||Abstract Bool Eats(n:NatureItem)], [Vegetable]^[Cabbage||Bool Eats(n:NatureItem)],[Animal]^[Sheep||Bool Eats(n:NatureItem)], [Animal]^[Wolf||Bool Eats(n:NatureItem)]