INTG 002: Mathematical magicdeturck/isp/april-08.pdfD. DeTurck INTG 002 001 2014A:Magic 2/28...

Preview:

Citation preview

INTG 002: Mathematical magic

D. DeTurck

University of Pennsylvania

April 8, 2014

D. DeTurck INTG 002 001 2014A:Magic 1 / 28

deBruijn sequences

• Crux of the trick:There were 32 = 2× 2× 2× 2× 2 cards.

• And the question “Who has red cards?” can be answered in32 possible ways.

• The deck was arranged so each consecutive set of five cardshas a different color pattern.

• My memory is not so prodigious, so there’s a little more tothe trick that I might explain at the end of class.

D. DeTurck INTG 002 001 2014A:Magic 2 / 28

deBruijn sequences

• Crux of the trick:There were 32 = 2× 2× 2× 2× 2 cards.

• And the question “Who has red cards?” can be answered in32 possible ways.

• The deck was arranged so each consecutive set of five cardshas a different color pattern.

• My memory is not so prodigious, so there’s a little more tothe trick that I might explain at the end of class.

D. DeTurck INTG 002 001 2014A:Magic 2 / 28

How to arrange the deck?

• Let’s try it with just 8 = 2× 2× 2 cards.

• Sequences:

RRR RRB RBR RBB BRR BRR BRB BBR BBB

• Want to find a sequence of eight R/B colors so each set ofthree occurs just once.

RRRBBBRB

“going around the corner”

D. DeTurck INTG 002 001 2014A:Magic 3 / 28

How to arrange the deck?

• Let’s try it with just 8 = 2× 2× 2 cards.

• Sequences:

RRR RRB RBR RBB BRR BRR BRB BBR BBB

• Want to find a sequence of eight R/B colors so each set ofthree occurs just once.

RRRBBBRB

“going around the corner”

D. DeTurck INTG 002 001 2014A:Magic 3 / 28

Zeros and ones

• Replace R by 1 and B by 0 so RRRBBBRB becomes11100010.

• deBruijn sequence with window length k : total length 2k suchthat every k consecutive digits occurs just once (going aroundthe corner). So 11100010 has window length 3.

• For the trick, need a sequence of window length 5.

• Math problem: Given k do there exist deBruijn sequences ofwindow length k? If so, how many are there and how do youfind them?

D. DeTurck INTG 002 001 2014A:Magic 4 / 28

Zeros and ones

• Replace R by 1 and B by 0 so RRRBBBRB becomes11100010.

• deBruijn sequence with window length k : total length 2k suchthat every k consecutive digits occurs just once (going aroundthe corner). So 11100010 has window length 3.

• For the trick, need a sequence of window length 5.

• Math problem: Given k do there exist deBruijn sequences ofwindow length k? If so, how many are there and how do youfind them?

D. DeTurck INTG 002 001 2014A:Magic 4 / 28

Graph theory approach:

• To find a deBruijn sequence of window length 3, take thedirected graph whose vertices are all (four) two-bit sequences,and draw an edge vertex A to vertex B if the last bit of A isthe same as the first bit of B. (In general we would have thelast k − 1 bits of A the same as the first k − 1 bits of B.)

D. DeTurck INTG 002 001 2014A:Magic 5 / 28

Euler circuits again

• The problem becomes one of finding an Euler circuit (rememberthose?) in this graph that obeys the arrows. This is possible ifand only if each vertex has the same number of arrows goingout as coming in.

• So we’re in luck and now we know there’s at least one deBruijnsequence for each k.

D. DeTurck INTG 002 001 2014A:Magic 6 / 28

Greedy algorithm

• DeBruijn sequences can also be constructed by the “greedyalgorithm” :

• Start with a sequence of k zeros and then add a 1 to thesequence whenever possible (i.e., when adding a 1 doesn’tform a pattern already seen), otherwise add a zero.

• For instance, for k = 4 this gives:

0000111101100101(000)

D. DeTurck INTG 002 001 2014A:Magic 7 / 28

How many?

• How many deBruijn sequences are there with a fixed windowlength?

• Consider two to be the same if they differ only by a cyclicshift. Then for k = 3 there are only two:

00011101 and 11100010.

• For k = 4 there are 16. For k = 5 there are 211 = 2048.

• The reason they’re called deBruijn sequences is that heproved:For any k there are exactly 22

k−1−k different deBruijnsequences.

• Lots of open questions about these.

D. DeTurck INTG 002 001 2014A:Magic 8 / 28

How many?

• How many deBruijn sequences are there with a fixed windowlength?

• Consider two to be the same if they differ only by a cyclicshift. Then for k = 3 there are only two:

00011101 and 11100010.

• For k = 4 there are 16. For k = 5 there are 211 = 2048.

• The reason they’re called deBruijn sequences is that heproved:For any k there are exactly 22

k−1−k different deBruijnsequences.

• Lots of open questions about these.

D. DeTurck INTG 002 001 2014A:Magic 8 / 28

Applications?

• Location of robot along a hallway.

• 2D versions of deBruijn sequences (deBruijn tori) for locationin a room — or location on a page.

• 4-by-4 version with 2-by-2 window.

1 1 0 10 0 0 11 0 0 01 0 1 1

D. DeTurck INTG 002 001 2014A:Magic 9 / 28

Thinking bigger

• This contains every 2-by-2 binary matrix if we view it as atorus (or extend periodically):

0 0 1 0 0 0 1 0 0 0 1 01 1 1 0 1 1 1 0 1 1 1 0

0 1 1 1 0 1 1 1 0 1 1 10 1 0 0 0 1 0 0 0 1 0 00 0 1 0 0 0 1 0 0 0 1 01 1 1 0 1 1 1 0 1 1 1 0

0 1 1 1 0 1 1 1 0 1 1 10 1 0 0 0 1 0 0 0 1 0 00 0 1 0 0 0 1 0 0 0 1 01 1 1 0 1 1 1 0 1 1 1 0

0 1 1 1 0 1 1 1 0 1 1 10 1 0 0 0 1 0 0 0 1 0 0

D. DeTurck INTG 002 001 2014A:Magic 10 / 28

Still bigger

• Here is a 256-by-256 version (dots represent 1s) containing all4-by-4 binary arrays:

D. DeTurck INTG 002 001 2014A:Magic 11 / 28

Dynamical systems

• Dynamical systems (usually expressed as differential ordifference equations) relate the rate of change of somequantity back to the quantity itself.

• Example:

D. DeTurck INTG 002 001 2014A:Magic 12 / 28

Dynamical systems

• Dynamical systems (usually expressed as differential ordifference equations) relate the rate of change of somequantity back to the quantity itself.

• Example:

D. DeTurck INTG 002 001 2014A:Magic 12 / 28

More realistic

• Here’s a better one – with air resistance, the acceleration of afalling object is the acceleration of gravity minus theacceleration due to air resistance, which for some objects isproportional to the square of the velocity. For such an objectwe have the differential equation:

D. DeTurck INTG 002 001 2014A:Magic 13 / 28

In a different field

• Radioactive substances decompose at a rate proportional tothe amount present.

D. DeTurck INTG 002 001 2014A:Magic 14 / 28

The same equation

D. DeTurck INTG 002 001 2014A:Magic 15 / 28

More realistic for populations

• An ecosystem may have a maximum capacity to support acertain kind of organism.

• In this case, the rate of change of the population isproportional to the number of organisms present and to theamount of excess capacity in the environment (overcrowdingwill cause the population growth to decrease)

• If the carrying capacity of the environment is the constantPmax then we get the equation

dP

dt= kP(Pmax − P).

D. DeTurck INTG 002 001 2014A:Magic 16 / 28

More realistic for populations

• An ecosystem may have a maximum capacity to support acertain kind of organism.

• In this case, the rate of change of the population isproportional to the number of organisms present and to theamount of excess capacity in the environment (overcrowdingwill cause the population growth to decrease)

• If the carrying capacity of the environment is the constantPmax then we get the equation

dP

dt= kP(Pmax − P).

D. DeTurck INTG 002 001 2014A:Magic 16 / 28

The slope field for P ′ = 2P(1− P)

D. DeTurck INTG 002 001 2014A:Magic 17 / 28

Discrete version

• From one year to the next: Say

P(n + 1) = kP(n)(1− P(n))

• If 0 ≤ k ≤ 4 then we’ll have 0 ≤ P(n + 1) ≤ 1 provided0 ≤ P(n) ≤ 1.

• It’s surprising that for different values of k in this range, thebehavior of P(n) can be quite different.

D. DeTurck INTG 002 001 2014A:Magic 18 / 28

First exploration: numerical

D. DeTurck INTG 002 001 2014A:Magic 19 / 28

Iteration plots: yn+1 = 1.8yn(1− yn)

D. DeTurck INTG 002 001 2014A:Magic 20 / 28

Iteration plots: yn+1 = 1.8yn(1− yn)

D. DeTurck INTG 002 001 2014A:Magic 21 / 28

Iteration plots: yn+1 = 1.8yn(1− yn)

D. DeTurck INTG 002 001 2014A:Magic 22 / 28

Iteration plots: yn+1 = 1.8yn(1− yn)

D. DeTurck INTG 002 001 2014A:Magic 23 / 28

Iteration plots: yn+1 = 1.8yn(1− yn)

D. DeTurck INTG 002 001 2014A:Magic 24 / 28

Iteration plots: yn+1 = 2.8yn(1− yn)

D. DeTurck INTG 002 001 2014A:Magic 25 / 28

Iteration plots: yn+1 = 3.3yn(1− yn)

D. DeTurck INTG 002 001 2014A:Magic 26 / 28

Iteration plots: yn+1 = 3.3yn(1− yn)

D. DeTurck INTG 002 001 2014A:Magic 27 / 28

Geometric approach

• Period doubling and chaotic phenomena

• Real magic: complex behavior from simple systems

• see iterplot worksheet and

• see Logistic map

D. DeTurck INTG 002 001 2014A:Magic 28 / 28