Slide 1

Slide 1 text

Abstrakte Maschinen

Slide 2

Slide 2 text

@igorwhiletrue

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

Programming is hard

Slide 5

Slide 5 text

Why?

Slide 6

Slide 6 text

• Link between our universe and computational universe • Cellular automata are self-replicating abstract machines • Humans are self-replicating biological machines (down to the cellular level) • Or is the entire universe a single machine?

Slide 7

Slide 7 text

• Abstract machine is a model of computation • Cellular automata are abstract machines

Slide 8

Slide 8 text

Conway’s Game of Life

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

• if alive • 2 or 3 neighbours to survive • if dead • exactly 3 neighbours to spawn • else • cell is dead

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

1 1 2 1 3 5 2 2 1 2 2 2 2 3 2 1

Slide 13

Slide 13 text

1 1 2 1 3 5 2 2 1 2 2 2 2 3 2 1

Slide 14

Slide 14 text

1 2 1 3 5 2 2 2 2 2 2 3 2 1

Slide 15

Slide 15 text

1 2 1 3 5 2 2 2 2 2 2 3 2 1

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

• Still lifes • Oscillators • Spaceships • Guns, puffers, breeders

Slide 25

Slide 25 text

• Cellular automaton • Metaphor for life • Complexity, emergence & stuff

Slide 26

Slide 26 text

• Other cellular automata • Codd’s automaton (8 states) • Langton’s loops (8 states) • Wireworld (4 states)

Slide 27

Slide 27 text

Deterministic finite automaton

Slide 28

Slide 28 text

• Endlicher automat • Regular expressions • Directed state transition graph

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

(refs|fixes|closes) #\d*

Slide 31

Slide 31 text

(refs|fixes|closes) #\d*

Slide 32

Slide 32 text

(refs|fixes|closes) #\d*

Slide 33

Slide 33 text

fixes #1234

Slide 34

Slide 34 text

ixes #1234

Slide 35

Slide 35 text

xes #1234

Slide 36

Slide 36 text

es #1234

Slide 37

Slide 37 text

s #1234

Slide 38

Slide 38 text

#1234

Slide 39

Slide 39 text

#1234

Slide 40

Slide 40 text

1234

Slide 41

Slide 41 text

234

Slide 42

Slide 42 text

34

Slide 43

Slide 43 text

4

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

• M = (Q, Σ, δ, q0, F) • Rule δ = (qi, a → qi1) • Can accept regular languages

Slide 47

Slide 47 text

• Regular expressions • Network protocols • Game states • Business rules • Workflows • Queues

Slide 48

Slide 48 text

$rules = [ 0 => ['c' => 1, 'f' => 7, 'r' => 9], 1 => ['l' => 2], 2 => ['o' => 3], ... ]; ! $tokens = ['f', 'i', 'x', 'e', 's', ' ', '#', '1', '2', '3', '4', 'EOF']; ! foreach ($tokens as $token) { if (!isset($rules[$state][$token])) { throw new NoTransitionException(); } ! $state = $rules[$state][$token]; } ! $accepted = in_array($state, $accept_states);

Slide 49

Slide 49 text

Nondeterministic finite automaton

Slide 50

Slide 50 text

baz

Slide 51

Slide 51 text

baz

Slide 52

Slide 52 text

az

Slide 53

Slide 53 text

z

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

• Does not add computational power • Can be compiled to a DFA • Previous DFA example already showed this • Basic quantum physics

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

Pushdown automaton

Slide 60

Slide 60 text

• Kellerautomat • Introduces a stack • Can determine balanced parens

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

e ( ( ( ( ) ) ) ( ) )

Slide 64

Slide 64 text

x e ( ( ( ) ) ) ( ) )

Slide 65

Slide 65 text

x x e ( ( ) ) ) ( ) )

Slide 66

Slide 66 text

x x x e ( ) ) ) ( ) )

Slide 67

Slide 67 text

x x x x e ) ) ) ( ) )

Slide 68

Slide 68 text

x x x e ) ) ( ) )

Slide 69

Slide 69 text

x x e ) ( ) )

Slide 70

Slide 70 text

x e ( ) )

Slide 71

Slide 71 text

x x e ) )

Slide 72

Slide 72 text

x e )

Slide 73

Slide 73 text

e

Slide 74

Slide 74 text

e

Slide 75

Slide 75 text

• M = (Q, Σ, Γ, δ, q0, Zo, F) • Rule δ = (qi, a, sj → qi1, sj1) • Can accept context-free languages

Slide 76

Slide 76 text

• Validation • Parsers • Stack machines

Slide 77

Slide 77 text

Turing Machine

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

No content

Slide 83

Slide 83 text

0 0 1 1

Slide 84

Slide 84 text

0 0 1 1

Slide 85

Slide 85 text

0 0 1 0

Slide 86

Slide 86 text

0 0 0 0

Slide 87

Slide 87 text

0 1 0 0

Slide 88

Slide 88 text

0 1 0 0

Slide 89

Slide 89 text

0 1 0 0

Slide 90

Slide 90 text

0 1 0 0

Slide 91

Slide 91 text

0 1 0 0

Slide 92

Slide 92 text

0 1 0 0

Slide 93

Slide 93 text

0 1 0 0

Slide 94

Slide 94 text

0 1 0 1

Slide 95

Slide 95 text

0 1 0 1

Slide 96

Slide 96 text

0 1 0 1

Slide 97

Slide 97 text

0 1 0 1

Slide 98

Slide 98 text

• M = (Q, Σ, Γ, δ, q0, b, F) • Rule δ = (qi, aj → qi1, aj1, dk) • Can accept recursively enumerable languages • Or loop forever

Slide 99

Slide 99 text

while (!in_array($state, $accept_states)) { $read_val = isset($tape[$position]) ? $tape[$position] : '_'; ! if (!isset($rules[$state][$read_val])) { throw new NoTransitionException(); } ! list($write_val, $move_dir, $new_state) = $rules[$state][$read_val]; ! $tape[$position] = $write_val; ! if ('l' === $move_dir) { $position--; if ($position < 0) { $position++; array_unshift($tape, '_'); } } else if ('r' === $move_dir) { $position++; if ($position >= count($tape)) { array_push($tape, '_'); } } ! $state = $new_state; }

Slide 100

Slide 100 text

This machine can run any algorithm

Slide 101

Slide 101 text

This machine can run any algorithm etsy.com/shop/sharpwriter

Slide 102

Slide 102 text

Universality

Slide 103

Slide 103 text

add increment one-third

Slide 104

Slide 104 text

add increment one-third add increment one-third

Slide 105

Slide 105 text

add increment one-third

Slide 106

Slide 106 text

add increment one-third U

Slide 107

Slide 107 text

U M

Slide 108

Slide 108 text

No content

Slide 109

Slide 109 text

• Stored-program computer (John von Neumann) • Programs as data • FPGA • PHPPHP

Slide 110

Slide 110 text

Turing completeness

Slide 111

Slide 111 text

• System capable of emulating a turing machine • Unbounded storage • Conditional branching • Recursion

Slide 112

Slide 112 text

• Universal Turing Machine • λ-calculus (Alonzo Church) • Game of Life • Brainfuck • PHP

Slide 113

Slide 113 text

• If PHP can only do as much as a turing machine, why bother? • Beware of the Turing tar-pit in which everything is possible but nothing of interest is easy. • Epigrams on Programming by Alan Perlis

Slide 114

Slide 114 text

• Is our universe really turing complete? • Or are the possible paths finite and pre- determined? • Do even stronger forces exist?

Slide 115

Slide 115 text

Self-reference

Slide 116

Slide 116 text

Slide 117

Slide 117 text

Recursion

Slide 118

Slide 118 text

No content

Slide 119

Slide 119 text

call_user_func( function ($x) { return $x($x); }, function ($x) { return $x($x); } );

Slide 120

Slide 120 text

while (true);

Slide 121

Slide 121 text

No content

Slide 122

Slide 122 text

Russell’s paradox

Slide 123

Slide 123 text

• Let R be the set of all sets that do not contain themselves • Does R contain itself? • If yes, then R’s definition is incorrect • If no, R is not in the set, so it must contain itself

Slide 124

Slide 124 text

• Liar paradox: “This sentence is false.” • Type theory • Hierarchy of types avoids self-reference

Slide 125

Slide 125 text

Entscheidungsproblem

Slide 126

Slide 126 text

• David Hilbert asks for an algorithm that decides if a statement in first-order logic is universally valid • Halting problem can be reduced to Entscheidungsproblem • Machine that determines if another machine will halt

Slide 127

Slide 127 text

Halts?

Slide 128

Slide 128 text

Halts? Negate

Slide 129

Slide 129 text

Halts? Negate Copy

Slide 130

Slide 130 text

Halts? Negate Copy { X

Slide 131

Slide 131 text

( ) X X

Slide 132

Slide 132 text

Halts? Negate Copy X

Slide 133

Slide 133 text

Halts? Negate Copy X X

Slide 134

Slide 134 text

Halts? Negate Copy true X X

Slide 135

Slide 135 text

Halts? Negate Copy X ∞ true X

Slide 136

Slide 136 text

Halts? Negate Copy X ∞ true X X X }

Slide 137

Slide 137 text

Halts? Negate Copy false X X

Slide 138

Slide 138 text

Halts? Negate Copy false halting now X X

Slide 139

Slide 139 text

Halts? Negate Copy false halting now X X X X }

Slide 140

Slide 140 text

• Proof by contradiction • Decision machine cannot exist • We are screwed

Slide 141

Slide 141 text

Ways to cope

Slide 142

Slide 142 text

No content

Slide 143

Slide 143 text

No content

Slide 144

Slide 144 text

Use finite state machines in parts of your programs

Slide 145

Slide 145 text

Build restricted subsets of computing such as type systems that cannot loop forever

Slide 146

Slide 146 text

Conclusion

Slide 147

Slide 147 text

Programming is hard

Slide 148

Slide 148 text

No content

Slide 149

Slide 149 text

Questions? • github.com/igorw • conway-php • turing-php • lambda-php • @igorwhiletrue