Life, the Universal Turing Machine and Everything › ~rhyspj › cs41talk.pdf · Life, the...

Post on 25-Jun-2020

6 views 0 download

transcript

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

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

John Horton Conway

1970 invented Game of Life

1937 26xii bornLiverpool

(3 yrs before Lennon)

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

An applet

• Alan Hensel’s applet

• “stand and stare!”

• Buzzwords:

• cellular automata

• emergence

• complex behavior arising from simple rules

What is Computing?

• Let’s ask some experts

• When did computing begin?

• Don’t believe any Association for Computing Machinery

Some people

• believe in the Lambda Calculus

• aka Scheme!

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

• α-reduction, β-reduction

Alonzo Church

Kent Dybvig

Guy Steele

Some Scheme Programs

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

More Scheme

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

What is computing?(1)

• A computer is a device that correctly interprets Scheme programs

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

What is computing? (2)

• A computer is a device that correctly interprets C programs

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

{...

Yet Others

• could work in assembly language

• MOV R3,R4

John von Neumann

Eckert and Mauchly

What is computing? (3)

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

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

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

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

“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}

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

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

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

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

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

Turing’s Thesis

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

Church’s Thesis

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

Theorem

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

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, ...

Prove it!!!

• How would you set aboutproving claims like this?

Simulate

• Simulate Scheme in Java:

• write Scheme interpreter in Java

• Simulate TM in C...

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

What!!!!!

This is a TM designed by Paul Rendell

in 2002

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

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

Constructive Proof

• Computer scientists are good at these

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

Existence Proofs

René Descartes (1596–1650)

Non-existence proofs

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

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();}

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;

Are there strings?

• Are there any String constants in the program?

• Search for “

• is that enough?

Are there loops?

• Are there any loops in the program?

• search for “while” and “for”

• Is that enough?

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?

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

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}

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

Gotcha!

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

Logical Impossibility

Contradiction

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?

• ...

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?

halt? does not exist!

• neither does program-correct?

• neither does programs-equivalent?

• neither does ...

Humility!

That’s the big picture