life, the universal turing machine and everything › ~rhyspj › cs41talk.pdf · life, the...

55
Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science the George Washington University Internet version: I have removed pictures that may be copyrighted. Sorry - it detracts a lot from the talk

Upload: others

Post on 25-Jun-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Life, the Universal Turing Machine and Everything

Rhys Price JonesProfessor of Computer Science

the George Washington University

Internet version: I have removed pictures that may be copyrighted. Sorry - it detracts a lot from the talk

Page 2: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

What is this Life?WHAT is this life if, full of care,We have no time to stand and stare.

No time to stand beneath the boughsAnd stare as long as sheep or cows.

No time to see, when woods we pass,Where squirrels hide their nuts in grass.

No time to see, in broad daylight,Streams full of stars, like skies at night.

No time to turn at Beauty's glance,And watch her feet, how they can dance.

No time to wait till her mouth canEnrich that smile her eyes began.

A poor life this if, full of care,We have no time to stand and stare.

Leisure - William Henry DaviesWelsh “tramp” poet 1871-1940

Page 3: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

John Horton Conway

1970 invented Game of Life

1937 26xii bornLiverpool

(3 yrs before Lennon)

Page 4: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

What is that life?

A dead cell with 3 live neighbors comes is born

A live cell with 2 or 3 live neighbors stays alive

Death from overcrowding

Death from loneliness

Page 5: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

An applet

• Alan Hensel’s applet

• “stand and stare!”

• Buzzwords:

• cellular automata

• emergence

• complex behavior arising from simple rules

Page 6: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

What is Computing?

• Let’s ask some experts

• When did computing begin?

• Don’t believe any Association for Computing Machinery

Page 7: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Some people

• believe in the Lambda Calculus

• aka Scheme!

• exp :== identifier λ id. exp exp1 exp2

• α-reduction, β-reduction

Alonzo Church

Kent Dybvig

Guy Steele

Page 8: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Some Scheme Programs

> 4242> (+ 2 2)4> (+ 2 (* 3 4))14> (* 1357908642 91357990864201) ; no wimpy ints/floats124055805310255586325042>

Page 9: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

More Scheme

> (define fac (lambda (x) (if (zero? x) 1 (* x (fac (1- x))))))> (fac 3)6> (fac 5)120> (fac 100)93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000>

Page 10: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

What is computing?(1)

• A computer is a device that correctly interprets Scheme programs

Page 11: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

C for others#define DIT (#define DAH )#define __DAH ++#define DITDAH *#define DAHDIT for#define DIT_DAH malloc#define DAH_DIT gets#define _DAHDIT char_DAHDIT _DAH_[]=”ETIANMSURWDKGOHVFaLaPJBXCYZQb54a3d2f16g7c8a90l?e’b.s;i,d:”;main DIT DAH{_DAHDITDITDAH _DIT,DITDAH DAH_,DITDAH DIT_,DITDAH _DIT_,DITDAH DIT_DAH DITDAH,DITDAH DAH_DIT DIT DAH;DAHDITDIT _DIT=DIT_DAH DIT 81 DAH,DIT_=_DIT__DAH;_DIT==DAH_DIT DIT _DIT DAH;__DITDIT’\n’DAH DAH DAHDIT DIT DAH_=_DIT;DITDAHDAH_;__DIT DIT DITDAH_DIT_?_DAH DIT DITDAH DIT_ DAH:’?’DAH,__DITDIT’ ‘DAH,DAH_ __DAH DAH DAHDIT DITDITDAH DIT_=2,_DIT_=_DAH_; DITDAH _DIT_&&DITDITDAH _DIT_!=DIT DITDAH DAH_>=’a’? DITDAHDAH_&223:DITDAH DAH_ DAH DAH; DITDITDAH DIT_ DAH __DAH,_DIT_ __DAH DAHDITDAH DIT_+= DIT DITDAH _DIT_>=’a’? DITDAH _DIT_-’a’:0DAH;}_DAH DIT DIT_ DAH{ __DIT DITDIT_>3?_DAH DIT DIT_>>1 DAH:’\0’DAH;returnDIT_&1?’-’:’.’;}__DIT DIT DIT_ DAH _DAHDITDIT_;{DIT void DAH write DIT 1,&DIT_,1 DAH;}

Brian Kernighan

Dennis Ritchie

Bjarne Stroustrup

Page 12: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

What is computing? (2)

• A computer is a device that correctly interprets C programs

Segmentationfault for(i=0;i<n;i++)

{...

Page 13: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Yet Others

• could work in assembly language

• MOV R3,R4

John von Neumann

Eckert and Mauchly

Page 14: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

What is computing? (3)

• A computer is a device that correctly interprets Assembly Language programs

Page 15: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Computing is

• An accumulator, a program counter, a memory, and an ALU that can correctly interpret

• BR op ; branch to operand+1

• BRREL op ; branch to PC+op+1

• LNEG op ; load negated contents of op into accumulator

• STORE op ; store contents of accumulator at op

• SUB op ; subtract contents of op from accumulator

• SKIPNEG ; if (accumulator < 0) PC++

• HALT

Fred Williams

Tom Kilburn

Alan Turing

Manchester Mark I, 1949

Page 16: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Computing is

•a finite number of NAND gates connected together reasonably cleverly

•and some interface devices.Last year I couldn’t spell engineer

Now I is one

Page 17: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Computing is

•a finite number of states, a one-way infinite tape, a read-write head, a transition table specifying for some state/tape-symbol pairs a new state, a new symbol and a move L or R.

Derek Jacobi as Alan Turing

Turing machine simulation

Page 18: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

“Mathematical” Specification

• Finite set of states

• q0, q1, ..., qn

• one-way infinite tape

• Xa00YXBB...

• symbols in Γ

• head position in red

• transitions with tape updates

• δ : Q × Γ → Q × Γ × {L,R}

Page 19: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Encoding a Turing Machine

• Name the states

• q0, q1, ..., qn

• encode the transitions in a table

• store tape cells in a linked list

• indicate head position by an int

Page 20: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

CS41

• Computing is what you can do in Java

• Can you simulate the action of a Turing machine?

Michael Feldman, professor of engineering and applied science, will be presented with the 2003 Trachtenberg

Teaching Award

Page 21: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Shakespeare

• Can we write a Java program

• to analyze Shakespeare?

• be more precise please!

• say, count the occurrences of each unique word in the “Complete Works”

• sure...

Page 22: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Turing Machines

• Can we write a Scheme program to simulate a Turing machine?

• Sure...

• Can we write a java Program to simulate a Turing machine?

• sure... input: description of a TM and its starting tapeoutput: show the sequence of states and tape contents

Page 23: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Universal Turing Machine• Can we create a Turing machine U to simulate a Turing machine

java:input: description of a TM and its starting tapeoutput: show the sequence of states and tape contents

start with: encoding of a TM and its starting tape on U’s tapeoutput: show the sequence of states and tape contents

Page 24: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Turing’s Thesis

• The processes which could naturally be called algorithms are precisely those which can be carried out on Turing machines

Page 25: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Church’s Thesis

• All formalizations of algorithms will yield the same class of computable functions.

Page 26: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Theorem

• The preceding definitions of “computer’’ and “computing” are all equivalent. Each definition specifies exactly the same set of computable functions.

Page 27: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Universal Computing Device

• Any device that can do everything any Universal Computing Device can do!

• Examples:

• this Mac, any PC, any Java interpreter, any Scheme interpreter, any C machine, Manchester Mark I, ENIAC, ...

Page 28: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Prove it!!!

• How would you set aboutproving claims like this?

Page 29: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Simulate

• Simulate Scheme in Java:

• write Scheme interpreter in Java

• Simulate TM in C...

Page 30: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

And a Whole Lot More

• Post Machine

• Conway’s Game of Life

Emil Post

John Horton Conway

cells with < 2 living neighbors die of lonelinesscells with > 3 living neighbors die of overcrowdingdead cells with 3 living neighbors come alive

Page 31: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

What!!!!!

This is a TM designed by Paul Rendell

in 2002

Page 32: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Some amazing facts

• There is a Life configuration that implements the JVM

• There is a TM that implements Microsoft’s Word program

• GoogleEarth can be implemented on Manchester Mark I

Page 33: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Programming Languages

• Any algorithm expressible in one language can be equivalently expressed in another

• So it doesn’t matter

• What can be computed by Turing Machine can be computed in Java

• and vice versa

Page 34: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Constructive Proof

• Computer scientists are good at these

• To prove something is possible, write a program to do it!

Page 35: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Existence Proofs

René Descartes (1596–1650)

Page 36: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Non-existence proofs

Page 37: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Back to the real world

• We saw a Java program to “analyze” Shakespeare.

• Can we write Java programs to “analyze” Java programs?

• Tailor the CountWords program to do just that:

• count the individual words in a Java program and their frequency

Page 38: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Other Program Analysis• Balanced Parens?

• Are all the parens balanced?boolean balancedParens(Program p) { // use a stack; try { while (c = nextChar()) { if (c == ‘(‘)) push if (c == ‘)‘)) pop; } }catch(StackProb e) {return false;} return stack.empty();}

Page 39: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Proper declarations?• Do all uses of a variable come after the in-scope

declaration of that variable?boolean properDeclarations(Program p) { // use a linked list for each variable scope { ll = new LinkedList() { if isDeclaration(thisStatement){ ll.add(thisStatement.getVars()); else { for (var : thisStatement.getVars()) { if (var not in ll) return false; } } } } return true;

Page 40: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Are there strings?

• Are there any String constants in the program?

• Search for “

• is that enough?

Page 41: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Are there loops?

• Are there any loops in the program?

• search for “while” and “for”

• Is that enough?

Page 42: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

More Problems

• Will the program run on my Mac with input HaHaHa for at least 1 second?

• Will the program run on my Mac with input BlahBlahBlah terminate within 1 hour?

• Will the program run on my Mac with input BlahBlahBlah terminate within 423 years?

Page 43: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Switch to Scheme• Easier to pass

programs to each other

• don’t need a compile stage

• can treat programs both as data and as program

• same as a Turing Machine

• Easier to pass programs to each other

• don’t need a compile stage

• can treat programs both as data and as program

• same as a Turing Machine

Page 44: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

A fundamental problem

• The halting problem

• Can you write

boolean halts(Program p, Data x) { // return true if p run on x halts // return false otherwise}

Page 45: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Suppose you could

• You have written

• boolean halts(Program p, Data x)

• You guarantee to give me the correct answer in a finite time

• true or false

• I’m holding you to it!(define halt? (lambda (p x) (printf "Does program ~s halt on input ~s? " p x) (member (read) '(yes y Y))))

Page 46: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Gotcha!

(define foo (lambda (x) (cond ((halt? foo foo) (loop)) (else (stop)))))

Page 47: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Logical Impossibility

Page 48: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Contradiction

Page 49: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

What’s wrong?

• Am I allowed to write programs in Scheme?

• Are there infinite loops?

• Are there terminating programs?

• Are there boolean functions?

• Can I pass programs to programs?

• ...

Page 50: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

So if ..

• if program halt? says (foo foo) runs forever

• it halts

• if it says (foo foo) halts

• it runs forever

• What’s the explanation?

Page 51: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

halt? does not exist!

• neither does program-correct?

• neither does programs-equivalent?

• neither does ...

Page 52: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

Humility!

Page 53: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science

That’s the big picture

Page 54: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science
Page 55: Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the Universal Turing Machine and Everything Rhys Price Jones Professor of Computer Science