30
Cabbage, Goat, and Wolf Algorithmics, NP-completeness, and a little Latin USF Math Club, Tampa FL, Feb 2016 Hendrik Jan Hoogeboom Universiteit Leiden NL

Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

Cabbage, Goat, and Wolf

Algorithmics, NP-completeness, and a little Latin

USF Math Club, Tampa FL, Feb 2016

Hendrik Jan Hoogeboom

Universiteit Leiden NL

Page 2: Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

cabbage, goat, and wolf

2

algorithmics (problem solving)

complexity

natural computing

Page 3: Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

Algorithmics: a puzzle

3

Page 4: Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

transportation problems

4

Page 5: Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

cgw+

cw+g

cw+g

gw+c

w+cg

c+wg

cg+w

g+cw

g+cw

+cgw

Fcgw+

cw+gF

Fcw+g

Fgw+c

w+cgF

c+wgF

Fcg+w g+cwF

Fg+cw

+cgwF

cabbage, goat, wolf

5

Fg

Fg

Fw

Fg

Fg

Fw

F

Fc

Fc

F

Page 6: Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

Propositiones ad Acuendos Juvenes

http://en.wikipedia.org/wiki/Propositiones_ad_acuendos_juvenes

Alcuin of York (York ~735 - Tours 804)

XVIII. PROPOSITIO DE HOMINE ET CAPRA ET LVPO. Homo quidam debebat ultra fluuium transferre lupum, capram, et fasciculum cauli. Et non potuit aliam nauem inuenire, nisi quae duos tantum ex ipsis ferre ualebat. Praeceptum itaque ei fuerat, ut omnia haec ultra illaesa omnino transferret. Dicat, qui potest, quomodo eis illaesis transire potuit? Solutio Simili namque tenore ducerem prius capram et dimitterem foris lupum et caulum. Tum deinde uenirem, lupumque transferrem: lupoque foris misso capram naui receptam ultra reducerem; capramque foris missam caulum transueherem ultra; atque iterum remigassem, capramque assumptam ultra duxissem. Sicque faciendo facta erit remigatio salubris, absque uoragine lacerationis.

6

Page 7: Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

Propositiones ad Acuendos Juvenes

http://en.wikipedia.org/wiki/Propositiones_ad_acuendos_juvenes

Alcuin of York (York ~735 - Tours 804)

XVIII. PROPOSITIO DE HOMINE ET CAPRA ET LVPO. Homo quidam debebat ultra fluuium transferre lupum, capram, et fasciculum cauli. Et non potuit aliam nauem inuenire, nisi quae duos tantum ex ipsis ferre ualebat. Praeceptum itaque ei fuerat, ut omnia haec ultra illaesa omnino transferret. Dicat, qui potest, quomodo eis illaesis transire potuit? Solutio Simili namque tenore ducerem prius capram et dimitterem foris lupum et caulum. Tum deinde uenirem, lupumque transferrem: lupoque foris misso capram naui receptam ultra reducerem; capramque foris missam caulum transueherem ultra; atque iterum remigassem, capramque assumptam ultra duxissem. Sicque faciendo facta erit remigatio salubris, absque uoragine lacerationis.

7

Page 8: Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

LOGIC BOAT

http://xkcd.com/1134/ 10

Fcgw+

cw+gF

Fcw+g

Fgw+c

w+cgF

c+wgF

Fcg+w g+cwF

Fg+cw

+cgwF

Page 9: Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

jealous husbands

11

trip number left bank travel right bank

(start) Aa Bb Cc

1 Ab Cc Aa →

2 Ab Cc ← A a

3 A B C bc → a

4 A B C ← a b c

5 Aa BC → b c

6 Aa ← Bb Cc

7 a b AB → Cc

8 a b ← c A B C

9 b a c → A B C

10 b ← B Aa Cc

11 Bb → Aa Cc

(finish) Aa Bb Cc

wikipedia

Page 10: Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

missionaries and cannibals

12

(c,m) (3-c,3-m) c=0 or c≥m c=3 or c≤m (other bank!)

m

c start

finish

3 missionaries and 3 cannibals; 2 passengers. when the missionaries outnumber the cannibals the latter will be converted; how to get them safely over?

Graphical Solution of Difficult Crossing Puzzles R.Fraley, K.L.Cooke, P.Detrick, Mathematics Magazine 9 (1966) 151-157

Page 11: Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

missionaries and cannibals

13

m

c start

finish

3 missionaries and 3 cannibals; 2 passengers. when the missionaries outnumber the cannibals the latter will be converted; how to get them safely over?

Graphical Solution of Difficult Crossing Puzzles R.Fraley, K.L.Cooke, P.Detrick, Mathematics Magazine 9 (1966) 151-157

back and forth! 11 steps

(c,m) (3-c,3-m) c=0 or c≥m c=3 or c≤m (other bank!)

Page 12: Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

complexity: NP-completeness

14

Page 13: Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

Turing machine

15

(p,c,q,a,D) instruction p state c letter read q new state a letter written D direction move -1,0,+1

A.M. Turing (1936). On Computable Numbers, with an Application to the Entscheidungs problem. Proc London Math Soc (1937)

Emil Post. Finite Combinatory Processes—Formulation 1, J Symbolic Logic (1936)

␢ ␢ 1 1 1 0 ␢

space 1≤i≤p(n)

time 1

≤k≤

p(n

)

␢ ␢ 1 1 0 0 ␢

␢ ␢ 1 1 0 1 ␢

␢ ␢ 1 1 0 1 ␢

␢ ␢ 1 1 0 1 ␢

␢ ␢ 1 1 0 1 ␢

␢ ␢ 1 1 0 1 ␢

␢ ␢ 1 1 0 1 ␢

H

r

r

r

r

r

state position

Page 14: Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

dimensions

P ⊆ NP ⊆ PSPACE ⊆ EXPTIME ⊆ NEXPTIME ⊆ EXPSPACE

AL AP APSPACE AEXPTIME

NPSPACE NEXPSPACE

Chandra, Kozen, Stockmeyer. 'Alternation', J ACM 1981.

existential and universal states computation = tree

space time space time determinism L P PSPACE EXPTIME nondeterminism NL NP NPSPACE NEXPTIME alternation AL AP APSPACE AEXPTIME

log. polynomial exp.

Clay Institute Millenium Prize

21

Page 15: Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

proving complexity

22

Hard

river- crossing

3SAT

solution solution

Page 16: Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

3SAT

(w∨x∨y) ∧ (w∨¬x∨z) ∧ … ∧ (x∨¬y∨z)

clause

literal (negated) variable

3 conjunctive normalform

3SAT given: given formula φ in 3CNF question: is φ satisfiable? (can we find a variable assignment making formula true)

Cook’71/Levin’73 3SAT is NP-complete 29

Page 17: Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

Cook/Levin

␢ c a c ␢ ␢ ␢

space 1≤i≤p(n)

time 1

≤k≤

p(n

) specify computation at step k … Tiak cell i contains a Hik head at position i Qqk state q

conjunction of Tix[i]0 initial tape x[i]=xi or x[i]=␢ Qq00 initial state H00 initial position Tiak → ¬Tibk single symbol a≠b Qpk → ¬Qqk single state p≠q Hik → ¬Hjk single head i≠j Tiak ∧ Tib.k+1 → Hik changed only if written a≠b

Hik ∧ Qpk ∧ Tiak → V(p,a,q,b,d) Hi+d.k+1 ∧ Qq.k+1 ∧ Tib.k+1

Qh.p(n) accept

(p,a,p,a,0) for each p,a

31

Page 18: Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

Karp's 21 NP-complete problems

32 Richard M. Karp (1972) Reducibility Among Combinatorial Problems

set packing Vertex cover

Max cut

Partition Job sequencing

Knapsack

Exact cover Clique cover

Chromatic number

3-Satisfiability

Undirected Hamilton

Directed Hamilton

Clique

0–1 integer programming

SAT Satisfiability CNF

set covering

Feedback arc set

Feedback node set

3-dimensional matching

Steiner tree

Hitting set

Page 19: Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

‘generalized’ river crossing D drivers P passengers c capacity boat m max moves forbidden combinations: FR right bank FL left bank FB boat

forbidden: otherwise polynomial, using graph traversal Thm. [Ito etal.] Polynomial if FB = ∅, and m=∞.

Ito, Langerman, Yoshida. Generalized River Crossing Problems, Th. Comp. Sys. 2015

D = { Man }, P = { Wolf, Goat, Cabbage }, FL = FR = { {Wolf, Goat}, {Goat, Cabbage}, {Wolf, Goat, Cabbage} }, FB = ∅, c = 2, m = 100.

37

Page 20: Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

3 dim matching

given: U,V,W, with |U|=|V|=|W|=k and M ⊆ U x V x W problem: is there P⊆M with |P|=k containing each element exactly once?

38

k=3 {a,b,c} x {p,q,r} x {x,y,z} P = { (a,p,y), (b,q,y), (b,r,x), (c,p,x), (c,q,z) }

Page 21: Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

3 dim matching

k=3 {a,b,c} x {p,q,r} x {x,y,z} P = { (a,p,y), (b,q,y), (b,r,x), (c,p,x), (c,q,z) }

39

given: U,V,W, with |U|=|V|=|W|=k and M ⊆ U x V x W problem: is there P⊆M with |P|=k containing each element exactly once?

Page 22: Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

reduction

3D matching U,V,W, with |U|=|V|=|W|=k en M ⊆ U x V x W

river crossing D=U∪{s1,s2,s3}, P=V∪W, c=3, m=3k-1, FR = ∅, FL = ∅, FB

C = { {u,v,w} | (u,v,w) ∈ M } ∪ { {s1,s2,s3} }

solution (matching)

complement!

40

solution (crossing)

Page 23: Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

reduction

P = { (a,p,y), (b,r,x), (c,q,z), (d,t,w) } k=4 (even)

{s1,s2,s3} → ← s1 {a,p,y} → ← s2 {b,r,x} → ← s3 {s1,s2,s3} → ← s1 {c,q,z} → ← s2 {d,s,w} → ← s3 {s1,s2,s3} → m=3k+1 3k+3 objects

41

crossing matching

Page 24: Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

Natural Computing: a model

42

Page 25: Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

nature inspires

nested compartments - information membranes – communication

43

Page 26: Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

simple system

Uniport Symport Antiport

A A B A

B

• only move together

• how many membranes? • how many passengers? • antiport necessary?

45

Page 27: Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

( a1…ak ↔ b1…b ) antiport

( a1…ak →) symport (in)

( ← a1…ak ) (out)

rules

contents

•objects multiset symbols infinite supply in environment

P systems with symport/antiport

Păun & Păun

P systems with symport/antiport

rules in membrane

46

Page 28: Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

antiport single membrane will do

p

p

q

A

A A

A

A

(p→q, +A) (p→q, -A) (p→q, A=0)

( qA ↔ p ) ( q ↔ pA )

see next

counter aut antiport ‘simulation’

sadly enough

#

#

simulate a counter automaton (=register machine)

increment, decrement, zero test

B

B

state p counter A=3

B=1

47

A

Page 29: Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

conclusion

three person boat + forbidden combination:

back to where we started!

done

and this is the oldest ‘paper’ I ever cited:

51

Page 30: Cabbage, Goat, and Wolf - Leiden Universityliacs.leidenuniv.nl/~hoogeboomhj/praatjes/... · cabbage, goat, and wolf 2 algorithmics (problem solving) complexity natural computing

references

Stephen Cook. The complexity of theorem proving procedures, Proc. 3rd Ann. ACM STOC (1971) pp. 151-158 H.J. Hoogeboom. Carriers and Counters: P Systems with Carriers vs. (Blind) Counter Automata, LNCS 2450 (2003) pp. 140-151 DOI 10.1007/3-540-45005-X_12 Hiro Ito, Stefan Langerman, Yuichi Yoshida. Generalized River Crossing Problems, Th. Comp. Sys. 56 (2015) 418-435 DOI 10.1007/s00224-014-9562-8

52