the power of symmetry

114
The power of symmetry

Upload: felienne-hermans

Post on 09-May-2015

11.900 views

Category:

Technology


2 download

DESCRIPTION

This presentation by @Felienne presents programming problems, and how they can be solved efficiently and elegantly using symmetry.

TRANSCRIPT

Page 1: The power of symmetry

The power of symmetry

Page 2: The power of symmetry

People love symmetry

They find symmetrical faces more attractive

Page 3: The power of symmetry

Mathematicians are just like people :)

They too love symmetry

Page 4: The power of symmetry

This is Johann Carl Friedrich Gauss (1777-1855)

He used symmetry to sum the numbers from 1 to 100

Page 5: The power of symmetry

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?

Page 6: The power of symmetry

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+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

Page 7: The power of symmetry

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

Well… it are 99 plusses, so 99 points of effort (and possibly mistake)

Could we do this with less operations(plusses)?

Page 8: The power of symmetry

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+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

Page 9: The power of symmetry

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+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

Page 10: The power of symmetry

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+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

Page 11: The power of symmetry

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

Page 12: The power of 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 = 1012+99 = 1013+98 = 101

Page 13: The power of symmetry

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 = 1012+99 = 1013+98 = 101

Page 14: The power of symmetry

Start loving symmetry already?

Page 15: The power of symmetry

Start loving symmetry already?

I do!

Page 16: The power of symmetry

Let’s have a look at the next problem

Concerning a shepherd, a sheep, a wolf and a cabbage

Page 17: The power of symmetry

And a river, which they have to cross

And a boat. But, the boat can only carry the shepherd plus one item

Page 18: The power of symmetry

So he takes either the sheep with him, or the wolf or the cabbage

Ow, and one more thing

Page 19: The power of symmetry

When left alone (without the shepherd present)

The wolf will eat the sheep, and the sheep will eat the cabbage

Page 20: The power of symmetry

Can we get the entire party safely to the other side?

Page 21: The power of symmetry

Lets make a diagram representing the shepherds choices

Initially, all are at the right side of the river

|HSCW

Page 22: The power of symmetry

So let’s place the whole party right of the |

The shepherd (his name is Hank), the Sheep, the Wolf and the Cabbage

|HSCW

Page 23: The power of symmetry

Now what can Hank do?

He can take either one of the three items with him

|HSCW

HC|SW HS | CW HW | SC

Page 24: The power of symmetry

However, remember

Wolf eats sheep, sheep eats cabbage

|HSCW

HC|SW HS | CW HW | SC

Page 25: The power of symmetry

So these two options are no good!

|HSCW

HC|SW HS | CW HW | SC

Page 26: The power of symmetry

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

Page 27: The power of symmetry

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

Page 28: The power of symmetry

Can you finish this diagram?

0|HSCW

HC|SW

S | HCW

HW | SCHS | CW

HSC | W HSW | C

Page 29: The power of symmetry

Come on, try it yourself!

0|HSCW

HC|SW

S | HCW

HW | SCHS | CW

HSC | W HSW | C

Page 30: The power of symmetry

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|

Page 31: The power of symmetry

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|

Page 32: The power of symmetry

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|

Page 33: The power of symmetry

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|

Page 34: The power of symmetry

Lets go back to the original problem:

Wolf eats sheep, sheep eats cabbage

Page 35: The power of symmetry

If we were to model this problem

We might come up with something this

Page 36: The power of symmetry

But is this necessary?

All that matters is sheep can’t be with wolfs and cabbages

Page 37: The power of symmetry

Who eats who…

Is irrelevant!

Page 38: The power of symmetry

So let’s try modeling the problem again!

Page 39: The power of symmetry

We have a shepherd, a sheep,

Plus two things that we shouldn’t combine with sheep

Page 40: The power of symmetry

Lets call them anti-sheep (A)

It we construct the diagram now, it is way more simple

Page 41: The power of symmetry

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|

Page 42: The power of symmetry

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!

Page 43: The power of symmetry

So next time when you are modeling something, be aware of antisheep

Don’t overmodel

Page 44: The power of symmetry

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

Page 45: The power of symmetry

So far we’ve see how symmetry can help in solving problems

Of course seeing this symmetry is not always easy

Page 46: The power of symmetry

But if you practice a little, you start seeing it everywhere

Let’s try another problem!

Page 47: The power of symmetry

Finding the greatest common divisor (gcd) of two numbers

Page 48: The power of symmetry

Given two numbers A en B

Determine the maximum number x, that divides both A en B

612

Page 49: The power of symmetry

For instance 6 and 12

2, 3 and 6 all divide both numbers, but 6 is the largest

612

Page 50: The power of symmetry

But how do we calculate the gcd of larger numbers?

We could try all numbers up to 105

105252

Page 51: The power of symmetry

Can we do better?

Using symmetry?

105252

Page 52: The power of symmetry

So let’s search for a problem that is smaller

But can be solved in the same way

105252

Page 53: The power of symmetry

Rephrasing our problem definition

We search for an x that ‘fits’ into both A and B

105 = x * z 252 = x * y

Page 54: The power of symmetry

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

Page 55: The power of symmetry

So how can we reduce this problem?

While keeping it similar?

105 = x * z 252 = x * y

Page 56: The power of symmetry

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)

Page 57: The power of symmetry

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)

Page 58: The power of symmetry

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

Page 59: The power of symmetry

Symmetry!

Wanna try it with a new problem?

Page 60: The power of symmetry

Suppose you’re going on a backpacking trip

And you need to decide what items to bring with you

Page 61: The power of symmetry

For example: Food, a towel, a first aid kit and entertainment

Page 62: The power of symmetry

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

Page 63: The power of symmetry

How to decide on the maximum value we can bring?

Weight

Value

1 2

2 1

1 3

3 4

Page 64: The power of symmetry

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

Page 65: The power of symmetry

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

Page 66: The power of symmetry

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

Page 67: The power of symmetry

Like before, we want to find a smaller problem

That we can solve similar to the ‘big’ problem

Page 68: The power of symmetry

Suppose this rectangle is an empty backpack

Page 69: The power of symmetry

If we put one item is, what we in fact have left is…

Page 70: The power of symmetry

If we put one item is, what we in fact have left is…

A smaller backpack!

Page 71: The power of symmetry

With this idea we are going to solve the problem:

We put an item in the backpack, and continue with a smaller one

Page 72: The power of symmetry

But we are cheating a little bit,

Since we don’t know beforehand which items to take

Page 73: The power of symmetry

Therefore, we need a table listing all values for smaller backpack

From those values, we can calculate the end result

Page 74: The power of symmetry

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

Page 75: The power of symmetry

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

Page 76: The power of symmetry

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

Page 77: The power of symmetry

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

Page 78: The power of symmetry

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 0Items up to 1 0Items up to 2 0Items up to 3 0Items up to 4 0

Page 79: The power of symmetry

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 0Items up to 1 0Items up to 2 0Items up to 3 0Items up to 4 0

Page 80: The power of symmetry

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 0Items up to 1 0Items up to 2 0Items up to 3 0Items up to 4 0

Page 81: The power of symmetry

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 0Items up to 1 0Items up to 2 0Items up to 3 0Items up to 4 0

Page 82: The power of symmetry

Max. value Max weight:0

Max weight:1

Max weight:2

Max weight:3

Items up to 0 0 0 0 0Items up to 1 0Items up to 2 0Items up to 3 0Items 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

Page 83: The power of symmetry

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 0Items up to 1 0 2 2 2Items up to 2 0Items up to 3 0Items up to 4 0

Page 84: The power of symmetry

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 0Items up to 1 0 2 2 2Items up to 2 0 2Items up to 3 0Items up to 4 0

Page 85: The power of symmetry

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 0Items up to 1 0 2 2 2Items up to 2 0 2Items up to 3 0Items up to 4 0

Page 86: The power of symmetry

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 0Items up to 1 0 2 2 2Items up to 2 0 2Items up to 3 0Items up to 4 0

Page 87: The power of symmetry

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 0Items up to 1 0 2 2 2Items up to 2 0 2Items up to 3 0Items up to 4 0

Page 88: The power of symmetry

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 0Items up to 1 0 2 2 2Items up to 2 0 2Items up to 3 0Items up to 4 0

Page 89: The power of symmetry

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 0Items up to 1 0 2 2 2Items up to 2 0 2Items up to 3 0 3Items up to 4 0

Page 90: The power of symmetry

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 0Items up to 1 0 2 2 2Items up to 2 0 2 2 3Items up to 3 0 3 3 3Items up to 4 0 3 3 5

Page 91: The power of symmetry

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 0Items up to 1 0 2 2 2Items up to 2 0 2 2 3Items up to 3 0 3 3 3Items up to 4 0 3 3 5

Page 92: The power of symmetry

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 0Items up to 1 0 2 2 2Items up to 2 0 2 2 3Items up to 3 0 3 3 3Items up to 4 0 3 3 5

Page 93: The power of symmetry

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 0Items up to 1 0 2 2 2Items up to 2 0 2 2 3Items up to 3 0 3 3 3Items up to 4 0 3 3 5

Page 94: The power of symmetry

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 0Items up to 1 0 2 2 2Items up to 2 0 2 2 3Items up to 3 0 3 3 3Items up to 4 0 3 3 5

Page 95: The power of symmetry

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 0Items up to 1 0 2 2 2Items up to 2 0 2 2 3Items up to 3 0 3 3 3Items up to 4 0 3 3 5

Page 96: The power of symmetry

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 0Items up to 1 0 2 2 2Items up to 2 0 2 2 3Items up to 3 0 3 3 3Items up to 4 0 3 3 5

Page 97: The power of symmetry

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 0Items up to 1 0 2 2 2Items up to 2 0 2 2 3Items up to 3 0 3 3 3Items up to 4 0 3 3 5

Page 98: The power of symmetry

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 0Items up to 1 0 2 2 2Items up to 2 0 2 2 3Items up to 3 0 3 3 3Items up to 4 0 3 3 5

Page 99: The power of symmetry

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 0Items up to 1 0 2 2 2Items up to 2 0 2 2 3Items up to 3 0 3 3 3Items up to 4 0 3 3 5

Page 100: The power of symmetry

So let’s do one little more problem

Page 101: The power of symmetry

Calculating all prime numbers

Did you know they were named after this guy?

Page 102: The power of symmetry

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

Page 103: The power of symmetry

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

Page 104: The power of symmetry

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

Page 105: The power of symmetry

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

Page 106: The power of symmetry

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

Page 107: The power of symmetry

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

Page 108: The power of symmetry

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

Page 109: The power of symmetry

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

Page 110: The power of symmetry

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

Page 111: The power of symmetry

The power of symmetry

Thanks for your attention!

Page 112: The power of symmetry

The power of symmetry

And remember:

Try to find symmetry everywhere2n is never funAnd beware of antisheep

Page 113: The power of symmetry

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

Page 114: The power of symmetry

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