• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Theory of Computation: Lecture 04
 

Theory of Computation: Lecture 04

on

  • 892 views

1) What is computation? ...

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
7) Class home page is at http://vkedco.blogspot.com/2011/08/theory-of-computation-home.html

Statistics

Views

Total Views
892
Views on SlideShare
689
Embed Views
203

Actions

Likes
0
Downloads
0
Comments
0

22 Embeds 203

http://vkedco.blogspot.com 141
http://vkedco.blogspot.in 8
http://www.vkedco.blogspot.com 6
http://vkedco.blogspot.de 6
http://vkedco.blogspot.com.br 6
http://vkedco.blogspot.co.il 5
http://vkedco.blogspot.ca 4
http://vkedco.blogspot.hu 4
http://vkedco.blogspot.ro 3
http://vkedco.blogspot.cz 3
http://vkedco.blogspot.fr 2
http://vkedco.blogspot.com.ar 2
http://vkedco.blogspot.se 2
http://vkedco.blogspot.co.uk 2
http://vkedco.blogspot.it 2
http://vkedco.blogspot.pt 1
http://vkedco.blogspot.kr 1
http://vkedco.blogspot.com.es 1
http://vkedco.blogspot.gr 1
http://vkedco.blogspot.co.nz 1
http://translate.googleusercontent.com 1
http://vkedco.blogspot.sg 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Theory of Computation: Lecture 04 Theory of Computation: Lecture 04 Presentation Transcript

    • CS 5000: Theory of Computation Lecture 04 Vladimir Kulyukin Department of Computer Science Utah State Universitywww.youtube.com/vkedco www.vkedco.blogspot.com
    • Outline ● Formalisms and Computations ● Choice of Formalism: Objective and Subjective Factors ● Programming language Lwww.youtube.com/vkedco www.vkedco.blogspot.com
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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 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
    • 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
    • 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
    • What Does This Program Do?www.youtube.com/vkedco www.vkedco.blogspot.com
    • 16f84a Assembler Execution Spot1 Spot2 W BEFORE: movlw D5 Spot1 Spot2 W AFTER: 5www.youtube.com/vkedco www.vkedco.blogspot.com
    • 16f84a Assembler Execution Spot1 Spot2 W BEFORE: 5 movwf Spot1 Spot1 Spot2 W AFTER: 5 5www.youtube.com/vkedco
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • Example  1 if x = 0 f ( x) =   x otherwisewww.youtube.com/vkedco www.vkedco.blogspot.com
    • 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
    • Reading Suggestions ● Ch. 2, Computability, Complexity, and Languages by Davis, Weyuker, Sigalwww.youtube.com/vkedco www.vkedco.blogspot.com
    • Feedback Errors to vladimir dot kulyukin at gmail dot comwww.youtube.com/vkedco www.vkedco.blogspot.com