CS 5000: Theory of Computation                         Lecture 04                       Vladimir Kulyukin                D...
Outline    ●        Formalisms and Computations    ●        Choice of Formalism: Objective and Subjective Factors    ●    ...
Why a Programming Language?   ●       To a software developer, the question “why do we need       programming languages?” ...
Formalisms and Computations   ●       On first look, the previous answer seems circular and it       is: before deciding o...
Alonzo Church (1903 - 1995)       Dr. Church developed λ-calculus, a formal system for       defining functions, applying ...
Churchs Thesis   ●       The commonsense formulation of Churchs Thesis:       Everything computable can be computed by a  ...
Churchs Thesis   ●       Why is it a thesis?   ●       It is a thesis because it cannot be proved as a theorem   ●       W...
Choice of Formalism    ●        Choice of formalism is both objective and subjective    ●        It is objective in that m...
Why Not Use Assembly as a Formalism?www.youtube.com/vkedco     www.vkedco.blogspot.com
Low-Level Programming Languages   ●       Most high-level programming languages are compiled       into low-level assembly...
Junun Mark III Robot                       This robot has the 16f84a chip. The                chip runs programs written i...
16f84a Assembler Sample Code                Spot1    equ     H30                Spot2    equ     H31                      ...
What Does This Program Do?www.youtube.com/vkedco           www.vkedco.blogspot.com
16f84a Assembler Execution              Spot1              Spot2                    W BEFORE:                         movl...
16f84a Assembler Execution              Spot1              Spot2           W BEFORE:                                      ...
16f84a Assembler Execution              Spot1              Spot2                    W BEFORE:                5            ...
16f84a Assembler Execution              Spot1           Spot2                  W BEFORE:                5                 ...
Example: 16f84a Assembler              Spot1              Spot2                   W BEFORE:                5              ...
Example: 16f84a Assembler              Spot1              Spot2                    W BEFORE:                5             ...
Example: 16f84a Assembler              Spot1             Spot2                   W BEFORE:                5               ...
Example: 16f84a Assembler              Spot1             Spot2                   W BEFORE:                5               ...
Example: 16f84a Assembler              Spot1         Spot2                      W BEFORE:                4                ...
Example: 16f84a Assembler              Spot1               Spot2                   W BEFORE:                4             ...
Example: 16f84a Assembler              Spot1               Spot2                   W BEFORE:                0             ...
16f84a Assembler    ●        We could program Junun Mark III robots directly in 16f84a        Assembler    ●        The tw...
JAL Sample Code: Fibonacci                         function fib(byte in n) return byte is                          var byt...
JAL is Better Than This!!!                   Spot1   equ     H30                   Spot2   equ     H31                    ...
16f84a Assembler                           JAL                                   function fib(byte in n) return byte isSpo...
JAL vs 16f84a Assembler   ●       What is the point of this JAL vs. 16f84a Assembler       exercise that we just did?   ● ...
Back to Choice of Formalism   ●       We will use the programming language L developed in       Chapter 2 of Computability...
L’s Tokens            Input variables : X 1 , X 2 , X 3 ,...            Local variables : Z 1 , Z 2 , Z 3 ,...            ...
L’s Basic Instructions (Primitives)       1. V ← V + 1 (increment)       2. V ← V − 1 (decrement)       3. V ← V (no - opp...
Instruction V  V + 1    ●        These instructions are primitives:        –   X1  X1 + 1        –   Z10  Z10 + 1      ...
Instruction V  V - 1    ●        These instructions are primitives:        –   X1  X1 - 1        –   Z10  Z10 - 1      ...
Instruction V  V    ●        These instructions are primitives:        –   X1  X1        –   Z10  Z10        –   X120 ...
L’s Labeled Primitives         1. [ L ] V ←   V + 1 (increment)         2. [ L] V ←    V − 1 (decrement)         3. [ L ] ...
Labeled Primitives: Examples    ●        [A1] X1  X1 + 1    ●        [B1] X23  X23 – 1    ●        [C10] Z12  Z12 + 1  ...
Increments and Decrements   ●       Since there is no upper limit on variable values, the increment       instruction alwa...
The Output Value of L’s Program    ●        The output value of an L program is the value of the Y        variable.    ●  ...
Label E    ●        We will assume that each L program has a unique exit        label E or (E1)    ●        If conditional...
Example                       1 if x = 0             f ( x) =                        x otherwisewww.youtube.com/vkedco ...
Implementing f(x) in L: Version 1                    [ A1 ] X 1 ← X 1 − 1                         Y← Y+1                  ...
Reading Suggestions    ●        Ch. 2, Computability, Complexity, and Languages by        Davis, Weyuker, Sigalwww.youtube...
Feedback         Errors to vladimir dot kulyukin at gmail dot comwww.youtube.com/vkedco                www.vkedco.blogspot...
Upcoming SlideShare
Loading in …5
×

Theory of Computation: Lecture 04: Computation, Formalism, Church's Thesis, Programming Language L

1,116 views
984 views

Published on

1) What is computation?
2) What is formalism
3) Relationship between formalism and computation
4) Church's Thesis
5) Why is Church's Thesis a thesis, not a theorem?
6) Programming language L

Published in: Science, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,116
On SlideShare
0
From Embeds
0
Number of Embeds
256
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Theory of Computation: Lecture 04: Computation, Formalism, Church's Thesis, Programming Language L

  1. 1. CS 5000: Theory of Computation Lecture 04 Vladimir Kulyukin Department of Computer Science Utah State Universitywww.youtube.com/vkedco www.vkedco.blogspot.com
  2. 2. Outline ● Formalisms and Computations ● Choice of Formalism: Objective and Subjective Factors ● Programming language Lwww.youtube.com/vkedco www.vkedco.blogspot.com
  3. 3. Why a Programming Language? ● To a software developer, the question “why do we need programming languages?” seems silly: we need programming languages to develop software, of course! ● To a CS theorist, there is a different answer: in order to study computation, one must have a formalism in which that computation can be expressed ● Question: Is there the best formalism to work with? ● Answer: Unlikely, because the formalism we use is inseparable from the computation we studywww.youtube.com/vkedco www.vkedco.blogspot.com
  4. 4. Formalisms and Computations ● On first look, the previous answer seems circular and it is: before deciding on a formalism we must have a pretty good idea of the computation we want to study and, vice versa, we cannot begin to study computation until we have a formalism that makes our ideas precise ● Chicken-and-egg conundrum: which comes first – formalism or computation? ● This is the heart of what is known as Churchs thesiswww.youtube.com/vkedco www.vkedco.blogspot.com
  5. 5. Alonzo Church (1903 - 1995) Dr. Church developed λ-calculus, a formal system for defining functions, applying functions, and recursionwww.youtube.com/vkedco www.vkedco.blogspot.com
  6. 6. Churchs Thesis ● The commonsense formulation of Churchs Thesis: Everything computable can be computed by a formalism X ● X can be replaced by λ-calculus or Turing machine or some other formalism ● Another subtle and often unstated assumption is that there is a device that can mechanically execute computational instructions expressed in that formalismwww.youtube.com/vkedco www.vkedco.blogspot.com
  7. 7. Churchs Thesis ● Why is it a thesis? ● It is a thesis because it cannot be proved as a theorem ● Why not? ● Because of its circular nature: a formalism is needed to reason about computation but no formalism can be developed without precise a priori notions of what sort of computation it is supposed to capture ● We are back to our chicken-and-egg conundrum: what comes first – formalism or computation?www.youtube.com/vkedco www.vkedco.blogspot.com
  8. 8. Choice of Formalism ● Choice of formalism is both objective and subjective ● It is objective in that many formalisms (at least, on natural numbers) have been shown to be equivalent: any computation that can be expressed in one can be expressed in another, and vice versa ● Similarly, programming languages are equivalent in the sense that an algorithm implemented in one language, can be implemented in a different one without any loss of generality ● It is subjective in that people always have their own personal preferenceswww.youtube.com/vkedco www.vkedco.blogspot.com
  9. 9. Why Not Use Assembly as a Formalism?www.youtube.com/vkedco www.vkedco.blogspot.com
  10. 10. Low-Level Programming Languages ● Most high-level programming languages are compiled into low-level assembly languages ● A typical assembly language has a finite number of instructions ● The number of instructions depends on the target chip: do a web search on “number of instructions in 8086” Intel 8086www.youtube.com/vkedco www.vkedco.blogspot.com
  11. 11. Junun Mark III Robot This robot has the 16f84a chip. The chip runs programs written in 16f84a Assembler.www.youtube.com/vkedco www.vkedco.blogspot.com
  12. 12. 16f84a Assembler Sample Code Spot1 equ H30 Spot2 equ H31 movlw D5 movwf Spot1 movlw D2 addwf Spot1,W movwf Spot2 movlw D3 subwf Spot2,W movwf Spot1 clrw clrf Spot1 clrf Spot2 nop endwww.youtube.com/vkedco www.vkedco.blogspot.com
  13. 13. What Does This Program Do?www.youtube.com/vkedco www.vkedco.blogspot.com
  14. 14. 16f84a Assembler Execution Spot1 Spot2 W BEFORE: movlw D5 Spot1 Spot2 W AFTER: 5www.youtube.com/vkedco www.vkedco.blogspot.com
  15. 15. 16f84a Assembler Execution Spot1 Spot2 W BEFORE: 5 movwf Spot1 Spot1 Spot2 W AFTER: 5 5www.youtube.com/vkedco
  16. 16. 16f84a Assembler Execution Spot1 Spot2 W BEFORE: 5 5 movlw D’2’ Spot1 Spot2 W AFTER: 5 2www.youtube.com/vkedco www.vkedco.blogspot.com
  17. 17. 16f84a Assembler Execution Spot1 Spot2 W BEFORE: 5 2 addwf Spot1,W Spot1 Spot2 W AFTER: 5 7www.youtube.com/vkedco www.vkedco.blogspot.com
  18. 18. Example: 16f84a Assembler Spot1 Spot2 W BEFORE: 5 7 movwf Spot2 Spot1 Spot2 W AFTER: 5 7 7www.youtube.com/vkedco www.vkedco.blogspot.com
  19. 19. Example: 16f84a Assembler Spot1 Spot2 W BEFORE: 5 7 7 movlw D’3’ Spot1 Spot2 W AFTER: 5 7 3www.youtube.com/vkedco www.vkedco.blogspot.com
  20. 20. Example: 16f84a Assembler Spot1 Spot2 W BEFORE: 5 7 3 subwf Spot2,W Spot1 Spot2 W AFTER: 5 7 4www.youtube.com/vkedco www.vkedco.blogspot.com
  21. 21. Example: 16f84a Assembler Spot1 Spot2 W BEFORE: 5 7 4 movwf Spot1 Spot1 Spot2 W AFTER: 4 7 4www.youtube.com/vkedco www.vkedco.blogspot.com
  22. 22. Example: 16f84a Assembler Spot1 Spot2 W BEFORE: 4 7 4 clrw Spot1 Spot2 W AFTER: 4 7 0www.youtube.com/vkedco www.vkedco.blogspot.com
  23. 23. Example: 16f84a Assembler Spot1 Spot2 W BEFORE: 4 7 0 clrf Spot1 Spot1 Spot2 W AFTER: 0 7 0www.youtube.com/vkedco www.vkedco.blogspot.com
  24. 24. Example: 16f84a Assembler Spot1 Spot2 W BEFORE: 0 7 0 clrf Spot2 Spot1 Spot2 W AFTER: 0 0 0www.youtube.com/vkedco www.vkedco.blogspot.com
  25. 25. 16f84a Assembler ● We could program Junun Mark III robots directly in 16f84a Assembler ● The two well known problems are: – Hard to debug – Hard to maintain ● That is why software developers seek higher level alternatives that can be compiled into the target assembly ● JAL is one higher level alternative for 16f84a Assemblerwww.youtube.com/vkedco www.vkedco.blogspot.com
  26. 26. JAL Sample Code: Fibonacci function fib(byte in n) return byte is var byte fib_rslt = 0 if ( n == 0 | n == 1 ) then fib_rslt = 1 return fib_rslt else var byte temp = 0 var byte prev = 0 var byte curr = 1 var byte count = n while ( count != 0 ) loop temp = curr curr = prev + curr prev = temp count = count - 1 end loop return curr end if end functionwww.youtube.com/vkedco www.vkedco.blogspot.com
  27. 27. JAL is Better Than This!!! Spot1 equ H30 Spot2 equ H31 movlw D5 movwf Spot1 movlw D2 addwf Spot1,W movwf Spot2 movlw D3 subwf Spot2,W movwf Spot1 clrw clrf Spot1 clrf Spot2 nop endwww.youtube.com/vkedco www.vkedco.blogspot.com
  28. 28. 16f84a Assembler JAL function fib(byte in n) return byte isSpot1 equ H30 var byte fib_rslt = 0Spot2 equ H31 if ( n == 0 | n == 1 ) movlw D5 then fib_rslt = 1 return fib_rslt movwf Spot1 else movlw D2 var byte temp = 0 addwf Spot1,W var byte prev = 0 var byte curr = 1 movwf Spot2 var byte count = n movlw D3 subwf Spot2,W while ( count != 0 ) loop movwf Spot1 temp = curr curr = prev + curr clrw prev = temp clrf Spot1 count = count - 1 clrf Spot2 end loop nop return curr end end if end functionwww.youtube.com/vkedco www.vkedco.blogspot.com
  29. 29. JAL vs 16f84a Assembler ● What is the point of this JAL vs. 16f84a Assembler exercise that we just did? ● The point is to appreciate another objective characteristic of a formalism: whatever formalism we choose, it has to be reasonably high-level to make formal reasoning about computation easier, not harderwww.youtube.com/vkedco www.vkedco.blogspot.com
  30. 30. Back to Choice of Formalism ● We will use the programming language L developed in Chapter 2 of Computability, Complexity, and Languages by Davis, Weyuker, and Sigal ● While L is a theoretical construct, it can be thought of as a higher level assembly language ● Since L is a programming language, it is, in my humble opinion, more appealing to the programmatically inclined than more formal constructs such as λ-calculus or Turing machinewww.youtube.com/vkedco www.vkedco.blogspot.com
  31. 31. L’s Tokens Input variables : X 1 , X 2 , X 3 ,... Local variables : Z 1 , Z 2 , Z 3 ,... Output variable : Y Labels : A1 , B1 , C1 , D1 , E1 , A2 ,... If the subscript is omitted, it is assumed to be 1. For example, X is the same as X 1 Z is the same as Z 1 A is the same as A1www.youtube.com/vkedco www.vkedco.blogspot.com
  32. 32. L’s Basic Instructions (Primitives) 1. V ← V + 1 (increment) 2. V ← V − 1 (decrement) 3. V ← V (no - opp) 4. IF V ≠ 0 GOTO L (cond. branch) NOTE : In instructions 1, 2, 3 the variables on the left - hand side and the right - hand side are the samewww.youtube.com/vkedco www.vkedco.blogspot.com
  33. 33. Instruction V  V + 1 ● These instructions are primitives: – X1  X1 + 1 – Z10  Z10 + 1 – YY+1 – X102  X102 + 1 ● These instructions are NOT primitives: – X1  X10 + 1 – Z10  X1 + 1 – Y  X102 + 1www.youtube.com/vkedco www.vkedco.blogspot.com
  34. 34. Instruction V  V - 1 ● These instructions are primitives: – X1  X1 - 1 – Z10  Z10 - 1 – YY-1 – X102  X102 - 1 ● These instructions are NOT primitives: – X1  X10 - 1 – Z10  X1 - 1 – Y  X102 - 1www.youtube.com/vkedco www.vkedco.blogspot.com
  35. 35. Instruction V  V ● These instructions are primitives: – X1  X1 – Z10  Z10 – X120  X120 – YY ● These instructions are NOT primitives: – X1  Y – X120  Z10 – Z10  X1www.youtube.com/vkedco www.vkedco.blogspot.com
  36. 36. L’s Labeled Primitives 1. [ L ] V ← V + 1 (increment) 2. [ L] V ← V − 1 (decrement) 3. [ L ] V ← V (no - opp) 4. [ L] IF V ≠ 0 GOTO L (cond. branch) NOTE : At the beginning of the line the label is in square brackets. However, in conditional dispatches the square brackets are dropped after GOTO.www.youtube.com/vkedco www.vkedco.blogspot.com
  37. 37. Labeled Primitives: Examples ● [A1] X1  X1 + 1 ● [B1] X23  X23 – 1 ● [C10] Z12  Z12 + 1 ● [E1] Y  Y ● [D101] IF X1 != 0 GOTO E1www.youtube.com/vkedco www.vkedco.blogspot.com
  38. 38. Increments and Decrements ● Since there is no upper limit on variable values, the increment instruction always succeeds (there are no buffer overflows): – VV+1 – In the above instruction V’s value is always incremented by 1 ● Since variable values are natural numbers, the decrement instruction has no effect if the value of the variable is 0 – VV–1 – if V is 0 before the instruction, V remains 0 after the instruction – If V > 0 before the instruction, V’s value is decremented by 1www.youtube.com/vkedco www.vkedco.blogspot.com
  39. 39. The Output Value of L’s Program ● The output value of an L program is the value of the Y variable. ● If an L program goes into an infinite loop, the value is undefined. ● Thus, an L program implements a function that maps the values of the input variables into the value of Y.www.youtube.com/vkedco www.vkedco.blogspot.com
  40. 40. Label E ● We will assume that each L program has a unique exit label E or (E1) ● If conditional dispatch with GOTO E or GOTO E1 is executed, the control exits the program and its execution terminates ● If we want to be explicit about this, we can assume that the implicit last statement of every L-program is [E1] return Ywww.youtube.com/vkedco www.vkedco.blogspot.com
  41. 41. Example  1 if x = 0 f ( x) =   x otherwisewww.youtube.com/vkedco www.vkedco.blogspot.com
  42. 42. Implementing f(x) in L: Version 1 [ A1 ] X 1 ← X 1 − 1 Y← Y+1 IF X 1 ≠ 0 GOTO A1 Or, if we do not want to use subscripts : [ A] X ← X − 1 Y← Y+1 IF X ≠ 0 GOTO Awww.youtube.com/vkedco www.vkedco.blogspot.com
  43. 43. Reading Suggestions ● Ch. 2, Computability, Complexity, and Languages by Davis, Weyuker, Sigalwww.youtube.com/vkedco www.vkedco.blogspot.com
  44. 44. Feedback Errors to vladimir dot kulyukin at gmail dot comwww.youtube.com/vkedco www.vkedco.blogspot.com

×