<<

One-Slide Summary • The Turing is a fundamental model of . It models input, output, processing and memory. A Turing machine has a finite state machine AA UniversalUniversal ComputerComputer controller as well as an infinite tape. At each step it reads the current tape symbol, writes a new tape symbol, moves the tape head left or right one square, and moves to a new state in the finite state machine controller. Turing are universal: they are just as powerful as Scheme, Python, C, or Java. • The is also a universal, fundamental . You can view it as “the essence of Scheme”.

#2

Thursday December 6 • Presentations in OLS 009 at 5pm – Extra credit for attending. – I will provide pizza and soda. – Rough head-count? • Lecture on December 6th – Officially: Reading Day – Optional Class, you Vote • ? • Romance Novels? • Aspect-Oriented Programming? • Free-form Question and Answer? Why car? #3

Finite State Machine Turing’s Explanation • There are lots of things we can’t “We have said that the compute with only a finite of computable are states those whose decimals are calculable by finite • Solutions: means. ... For the – Infinite State Machine present I shall only say •Hard to describe and draw that the justification lies – Add an infinite tape to the Finite State in the fact that the Machine human memory is •We'll do this instead. necessarily limited.”

#5 #6 FSM + Infinite Tape Turing Machine Hardware • Start: – FSM in Start State • Infinite (“as much as you want”) Paper – Input on Infinite Tape Tape – Pointer (= read/write head) to start of input – can read from and write to • Step (4 sub-steps each time): – but only finite time ... – Read one input symbol from tape • Finite Brain (set of rules) – Write symbol on tape, and move or one square – modeling “” (People) – Follow transition rule from current state • Finish: – Transition to halt state

#7 #8

Turing Machine Matching Parentheses ...... # 1 0 1 1 0 1 1 1 0 1 1 0 1 1 1 # • Find the leftmost ) – If you don’t find one, the parentheses match, write a 1 at the tape head and halt. Input: # Start Input: • Replace it with an X Write: # 1 Move:  Write: 0 • Look left for the first ( Move:  1 2 – If you find it, replace it with an X (they Input: matched) Input: 1 0 Write: Write: 1 0 Input: 0 – If you don’t find it, the parentheses didn’t Move:  Move:  Write: # 3 Why is match – end write a 0 at the tape head and Move:  this machine not complete? halt

#9 #10 Matching Parentheses Matching Parentheses

(, (, R (, (, R X, X, L X, X, L

X, X, R ), X, L X, X, R ), X, L 1: 2: look 1: 2: look Start look Start look for ) for ( for ) for (

(, X, R (, X, R #, 1, # #, 0, # #, 1, # #, 0, # HALT HALT Will this report the correct result for (()?

#11 #12 Matching Parentheses Turing Machine Infinite Tape (, (, R X, X, L z z z z z z z z z z z z z z z z z z z z ), X, L X, X, R TuringMachine ::= < Alphabet, Tape, FSM >

), #, R 2: look ), X, L Alphabet ::= { Symbol* } (, #, L 1 (, X, R for ( 2: Tape ::= < LeftSide, Current, RightSide > Start 1 look for ( Start OneSquare ::= Symbol | # (, X, R Current ::= OneSquare

#, #, L HAL T #, 0, - LeftSide ::= [ Square* ] #, 1, - RightSide ::= [ Square* ] #, 1, # #, 0, # Finite State Machine

3: look #, 1, # Everything to left of LeftSide is #. X, X, L for ( Everything to right of RightSide is #. HALT

(, 0, # How well does this model your ?

#13 #14

Turing Machine: FSM + Infinite Tape Liberal Arts Trivia: Politics • Start: – FSM in Start State • This military alliance, established by the – Input on Infinite Tape North Atlantic Treaty in 1949, provides for a – Tape head at start of input system of collective defense whereby its • Step (4 sub-steps): member states agree to help each other in – Read current input symbol from tape response to an attack by an external party. – Follow transition rule from current state on input An infamous initial goal was “to keep the • Write symbol on tape Russians out, the Americans in, and the • Move L or R one square • Update FSM state Germans down.” The combined military • Finish: Transition to halt state spending of its members accounts for over 70% of the world's total defense spending.

#15 #16

Liberal Arts Trivia: Chemistry A f (w) has:

• Diacetylmorphine was first synthesized in 1874. It was later commercialized by (the company that would become) Bayer in a failed effort to Domain D w D produce codeine. From 1898 to 1910 it was marketed as a non-addictive morphine substitute and cough suppressant, and as a cure for morphine addiction. It was quickly discovered that it rapidly metabolized into morphine, and, S f (w) S as such, was essentially just a quicker form of Result Region morphine. Give today's name for this drug, which made field subjects feel heroic. #17 #18 Integer Domain: A function may have many parameters:

Unary: 11111 Example:

Binary: 101 Addition function Decimal: 5 f (x, y)  x  y

We prefer Unary representation: x, y are integers

Easier to manipulate #19 #20 Definition: Example A function f is computable if The function f (x, y)  x  y is computable there is a Turing Machine M such that: x, y are integers  w   f (w)  Turing Machine: q0 q f final state Input string: x0y unary Initial Configuration Final configuration Output string: xy0 unary

w D Domain #21 #22 Start x y Turing machine for function f (x, y)  x  y

 1 1  1 0 1  1 

q0 11, R 11, R 11, L x  y Finish 0 1, R   , L 1 0, L q0 q1 q2 q3  1 1  1 1 0    , R q f final state q4 #23 #24 Time 0 Time 1 Execution Example: Time 0  1 1 0 1 1   1 1 0 1 1  x y x 11 (2)  1 1 0 1 1  q0 q0

q0 y 11 (2) 11, R 11, R 11, L

Final Result x  y 0 1, R   , L 1 0, L q0 q1 q2 q3  1 1 1 1 0    , R q4 q4 #25 #26 Time 2 Time 3 Time 4 Time 5  1 1 0 1 1   1 1 1 1 1   1 1 1 1 1   1 1 1 1 1 

q0 q1 q1 q1

11, R 11, R 11, L 11, R 11, R 11, L

0 1, R   , L 1 0, L 0 1, R   , L 1 0, L q0 q1 q2 q3 q0 q1 q2 q3   , R   , R q4 q4 #27 #28 Time 6 Time 7 Time 8 Time 9  1 1 1 1 1   1 1 1 1 0   1 1 1 1 0   1 1 1 1 0 

q2 q3 q3 q3

11, R 11, R 11, L 11, R 11, R 11, L

0 1, R   , L 1 0, L 0 1, R   , L 1 0, L q0 q1 q2 q3 q0 q1 q2 q3   , R   , R q4 q4 #29 #30 Time 10 Time 11 Time 12  1 1 1 1 0   1 1 1 1 0   1 1 1 1 0 

q q q 3 3 4 HALT & accept

11, R 11, R 11, L 11, R 11, R 11, L

0 1, R   , L 1 0, L 0 1, R   , L 1 0, L q0 q1 q2 q3 q0 q1 q2 q3   , R   , R q4 q4 #31 #32

Liberal Arts Trivia: American Lit Liberal Arts Trivia: Chemistry

• This early-20th-century American author • This highly flammable compound is formed by invited and wrote about cosmic horror, the nitrating cellulose through exposure to nitric idea that life is incomprehensible to human acid. It can be used as a propellant or low- minds and that the universe is fundamentally order explosive. French chemist Paul Vieille alien. Thus, those who genuinely reason invited the first practical smokeless powder gamble with insanity. He was little read for firearms and artillery ammunition from during life but is now regarded with Edgar this; is has also been used as a film base for Allen Poe as one of the most influential horror medical X-rays. It is commonly produced in writers of the 20th century. introductory chemistry classes by treating cotton balls with nitric acid.

#33 #34

Liberal Arts Trivia: Taoism Turing Machine

z z z z z z z z z z z z z z z z z z z z • Name the group of legendary, undying xian from Chinese TuringMachine ::= < Alphabet, Tape, FSM > ), X, L mythology. Each member's ), #, R Alphabet ::= { Symbol* } (, #, L 2: Tape ::= < LeftSide, Current, RightSide > 1 look power can be transferred to a for ( Start OneSquare ::= Symbol | # tool that can give life or (, X, R Current ::= OneSquare

HAL T #, 0, - LeftSide ::= [ Square* ] #, 1, - destroy evil. They are revered RightSide ::= [ Square* ] by Taoists, and include Royal Finite State Machine Uncle Cao, Iron Crutch Li, Everything to left of LeftSide is #. Everything to right of RightSide is #. Elder Zhang Guo, and Lu Tung- Pin. Many of them were said to practice neidan, or internal alchemy. #35 #36 Describing Finite State Machines Enumerating Turing Machines

TuringMachine ::= < Alphabet, Tape, FSM > FSM ::= < States, TransitionRules, InitialState, HaltingStates > • Now that we’ve decided how to describe States ::= { StateName* } Turing Machines, we can number them InitialState ::= StateName must be element of States HaltingStates ::= { StateName* } all must be elements of States • TM-5023582376 = balancing parens TransitionRules ::= { TransitionRule* } TransitionRule ::= • TM-57239683 = even number of 1s < StateName, ;; Current State Transition Rule is a procedure: • TM-3523796834721038296738259873 = Photomosaic Program OneSquare, ;; Current square Inputs: StateName, OneSquare StateName, ;; Next State Outputs: StateName, OneSquare, • TM-3672349872381692309875823987609823712347823 = Windows 7 OneSquare, ;; Write on tape Direction Direction > ;; Move tape Direction ::= L, R, #

#37 #38

Enumerating Turing Machines

• Now that we’ve decided how to describe Turing Machines, we can number them P Output • TM-5023582376 = balancing parens Number Universal of TM Tape • TM-57239683 = even number of 1s Turing for running

• TM-3523796834721038296738259873 = Photomosaic Program I TM-P Machine in tape I • TM-3672349872381692309875823987609823712347823 = Windows 7 Input Not the real Tape numbers – they Can we make a Universal Turing Machine? would be much also, just a number! bigger!

#39 #40

Yes! • People have designed Universal Turing Machines with – 4 symbols, 7 states () – 4 symbols, 5 states – 2 symbols, 22 states – 18 symbols, 2 states – 2 states, 5 symbols () • No one knows what the smallest possible UTM is Manchester Illuminated Universal Turing Machine, #9 from http://www.verostko.com/manchester/manchester.html

#41 #42 Church-Turing Thesis Universal Language • Any mechanical computation can be performed by a Turing Machine • Is Java/Python/C as powerful as a • There is a TM-n corresponding to every Universal Turing Machine? computable problem • We can simulate any “normal” (classical • Is a Universal Turing Machine as powerful mechanics) computer with a TM as Java/Python/C? – If a problem is in polynomial time on a TM, it is in polynomial time on a PC, iPhone, etc. – But maybe not a quantum computer! (later class?)

#43 #44

Universal Language Complexity in Python

• Special Forms If we have lazy evaluation and • Is Java/Python/C as powerful as a don’t care about abstraction, – if, return, define, etc. we don’t need these. Universal Turing Machine? • Primitives Yes: show we can simulate a UTM with a Python program – Numbers (infinitely many) • Is a Universal Turing Machine as powerful – Booleans: True, False Hard to get rid of? as Java/Python/C? – Functions (+, -, and, or, etc.)

Can we simulate a Python interpreter with a TM? • Evaluation Complexity – Environments (more than ½ of our eval code)

Can we get rid of all this and still have a useful language?

#45 #46

-calculus What is Calculus?

Alonzo Church, 1940 • In High School: (LISP was developed from -calculus, d/dx xn = nxn-1 [Power Rule] not the other way round.) d/dx (f + g) = d/dx f + d/dx g [Sum Rule] term = variable | term term Calculus is a branch of | (term) that deals with limits and the differentiation and integration of |  variable . term functions of one or more variables...

#47 #48 Surprise Liberal Arts Trivia Real Definition

• This branch of mathematics involving • A calculus is just a bunch of rules for symbolic expressions manipulated according manipulating symbols. to fixed rules takes its name from the – Latin word calx meaning pebble ... diminutive form of calx/calcis, the latin word • People can give meaning to those for rock or limestone. The diminutive word symbols, but that’s not part of the thus means “pebble”: in ancient times calculus. pebbles were placed in sand and used for • Differential calculus is a bunch of rules counting using techniques akin to those of the for manipulating symbols. There is an abacus. interpretation of those symbols corresponds with physics, slopes, etc.

#49 #50

Lambda Calculus Why?

• Rules for manipulating strings of • Once we have precise and formal rules symbols in the language: for manipulating symbols, we can use it term = variable to reason with. | term term • Since we can interpret the symbols as | (term) representing , we can use it |  variable . term to reason about programs. • Humans can give meaning to those symbols in a way that corresponds to computations.

#51 #52

Evaluation Rules Homework

- (renaming) • Exam 2 Due • Work on PS 9! y. M  v. (M [each y replaced by v]) where v does not occur in M.

-reduction (substitution)

(x. M)N   M [each x replaced by N ]

#53 #54