Docsity

Turing Machines and Recursive Functions: Equivalence and Primitive Recursive Functions, Study notes of Programming Languages

Toggle sidebar
bg1
Group 2 Notes: Brett Downs & Ignacio Garcia
- Turing machines are extremely basic symbol-manipulating devices which can be adapted to
recreate the logic of any computer that could be built. These machines were described by Alan
Turing in 1936.
- Von Neumann Architecture refers to a computer design model that uses a single storage
structure to hold both instructions and data, this kind of computer implements a Turing Machine.
-There are different ways one can calculate functions.
Alonzo Church
-The Church–Turing thesis stated that Turing machines and recursive functions are equivalent.
-"Every 'function which would naturally be regarded as computable' can be computed by
a Turing machine."-Alonzo Church
- Because any computer program can be translated into a Turing machine, and any Turing
machine can be translated into any general-purpose programming language, we know that any
general-purpose programming language is sufficient to express any algorithm.
Primitive Recursive Functions
F: N N
Natural Natural
Number Numbers
Initial functions (primitive recursive functions)
-Zero function: Z(x) = 0 xЄN
-Successor function: S(x) = x + 1 xЄN
-Projection function: Pnk(x1, x2, x3, x4,…,xn-1,…,xn) = xk1 < k < n
-n = # of arguments
-k = one in which is selected
-Using these functions we can create recursive functions.
Rules
Composition
-Suppose the functions g1, g2, g3…, gm, and h are primitive recursive, where the
domain of g1 is Nn, and the domain of h is Nm arguments.
x` = ( x1, x2, x3,…, xn) Then f(x) = h(g1(x`), g2(x`), g3(x`),…,gm(x`)) is primitive
recursive.
Recursion
-Suppose g and h are primitive recursive functions, where the domain of g is in Nn and
the domain of h is Nn+2. Then the pair of equations:
1) f(x`, 0 ) = g(x) Boundary Condition(Stop)
2) f(x`, y+1) = h(x`,y, f(x`,y)) Recursion equation
Defines a primitive recursive function with domain Nn+1.
Ex
pf3
pf4
pf5
pf8

Partial preview of the text

Download Turing Machines and Recursive Functions: Equivalence and Primitive Recursive Functions and more Study notes Programming Languages in PDF only on Docsity!

Group 2 Notes: Brett Downs & Ignacio Garcia

  • Turing machines are extremely basic symbol-manipulating devices which can be adapted to recreate the logic of any computer that could be built. These machines were described by Alan Turing in 1936.
  • Von Neumann Architecture refers to a computer design model that uses a single storage structure to hold both instructions and data, this kind of computer implements a Turing Machine. -There are different ways one can calculate functions. Alonzo Church -The Church–Turing thesis stated that Turing machines and recursive functions are equivalent.
    • "Every 'function which would naturally be regarded as computable' can be computed by a Turing machine." -Alonzo Church
  • Because any computer program can be translated into a Turing machine, and any Turing machine can be translated into any general-purpose programming language, we know that any general-purpose programming language is sufficient to express any algorithm. Primitive Recursive Functions F: N  N   Natural Natural Number Numbers Initial functions (primitive recursive functions) -Zero function: Z(x) = 0 xЄ N -Successor function: S(x) = x + 1 xЄ N - Projection function: Pnk(x 1 , x 2 , x 3 , x 4 ,…,xn-1,…,xn) = xk 1 < k < n -n = # of arguments -k = one in which is selected -Using these functions we can create recursive functions. Rules Composition -Suppose the functions g1, g2, g3…, gm, and h are primitive recursive, where the domain of g1 is N n, and the domain of h is N m^ ^ arguments. x= ( x1, x2, x3,…, xn) Then f(x) = h(g1(x), g2(x), g3(x),…,gm(x)) is primitive recursive. **Recursion** -Suppose g and h are primitive recursive functions, where the domain of g is in **N** n^ and the domain of h is **N** n+2. Then the pair of equations: 1) f(x, 0 ) = g(x) Boundary Condition(Stop) 2) f(x, y+1) = h(x,y, f(x`,y)) Recursion equation Defines a primitive recursive function with domain N n+1. Ex

ADD(X,Y) = X + Y

Formal Definition: ADD(X,0) = I(X) = P^11 (X) = X ADD(X,Y+1) = H`(X, Y, ADD(X,Y)) H(X,Y,Z) = S(P^33 (X, Y, ADD(X,Y)) ADD(2,3) = = S(P^33 (2,3,ADD(2,2))) = S(P^33 (2,3, S(P^33 (2,2, ADD(2,1))))) = S(P^33 (2,3, S(P^33 (2,2, S(P^33 (2,1, ADD(2,0))))))) = S(P^33 (2,3, S(P^33 (2,2, S(P^33 (2,1,2)))))) = S(P^33 (2,3, S(P^33 (2,2, S(2))))) = S(P^33 (2,3, S(P^33 (2,2,3)))) = S(P^33 (2,3, S(3))) = S(P^33 (2,3,4)) = S(4) = 5 Multiplication MUL(X,0) = Z(X) MUL(X, Y+1) = H(X,Y,MUL(X,Y)) H(X,Y,Z) = ADD(P^31 (X,Y,Z), P^33 (X,Y,Z)) Or ADD(X,Y,MUL(X,Y)) Factorial FAC(X) = X! FAC(0) = 1 FAC(X+1) = MUL(X+1,FAC(X)) Pred PRED(0) = Z(0) PRED(Y+1) = P^21 (Y, PRED(Y)) λ-Calculus -The goal of λ-calculus is to simplify the notion of computable functions. -A calculus is a notation that can be manipulated mechanically to achieve some end. -One reason for developing a calculus is that, by reducing some process to a set of simple mechanical rules, one decreases the chance of making errors. Scope

  • Scope: where a variable is visible to a range of statements or where the variable can be accessed.
  • Binding: declared in, accessible, etc
  • Bound Identifiers: are often called bound variables

mI=1I nj=1 j + I - a | |________| | | | | | Scope of j | |______________| | Scope of I λ-Calculus -It is a theory of functions developed by Alonzo Church. -In 1920 Moses Schonfinkel developed a theory of functions base of “combinations” -From that in 1930 Haskell curry rediscovered and extended schonfinkel’s theory and showed that it was equivalent to λ-Calculus. -From there in 1930 Alonzo Church developed λ-Calculus. -From there in 1950 S.C. Kleene showed that λ-Calculus was a universal computing system(any computable function can be expressed and evaluated using λ-Calculus). -From there in 1950 John Mccarthy who was inspired by λ-Calculus, invented the programming language LISP.

  • λ-Calculus is equivalent to Turing machines, but λ-Calculus emphasizes the use of transformation rules and doesn’t care about the actual machine implementing them. - λ-Calculus is more related to software than hardware. - The λ-Calculus is a notation for defining functions. -Any computable function can be expressed and evaluated using λ-Calculus. -The central concept in λ-Calculus is the expression. -Each λ expression denotes a function. -0 is a λ-expression to represent the number zero. -There are just 3 kinds of λ-expression and using BNF, the syntax of λ-expressions are: < λ-expression>::= |(< λ-expression>< λ-expression>) |( λ(variable>< λ-expression>)

-If V ranges over the class of and E, E1, E2… range over the syntax of class < λ- expression>, then the BNF simplifies to: E ::= V -Variable |(E1,E2) -Application combination(Procedure call) | λV.E -Abstraction Ex: -(λx.x) denotes the identity function -Functions can be applied to expressions (λx.x)E -( λx.xx)5  [5/x]xx x]xx  5 -Function applications are evaluated by substituting the value of the argument: (λ(x.x)E)  [E/x]xx x]x = y Ex: (λx. λP(fx))E (λf.(fx))[E/x]xx x]  λf.(fE) If we apply (λf.(fE))E (fE)[E/x]x*x f]  (E`E)

  • λ-Calculus was the basis for LISP
  • The meaning of [E/x]xx x] = all occurrences of x are substituted by E in the expression to the right. Ex: (λx.x)y  [y/x]xx x]x  y (λx.x)y  λy.y  y ((λx.λy.x+y 2)3)  (λy.x+y 2)[3/x]xx x]  (λy.3+y 2)  (3+y)[2/x]xx y]  (3+2)  5 Conversion Rules -An arithmetic expression like (2+3)5 can be represent as a λ-expression and its value 25 can also be represented as a λ-expression. -The process of simplifying (2+3)5 is called conversion or reduction. 1)”Renaming Rule”(-conversion or -reduction) -one expression may be replace to another by changing a bound identifier throughout its scope to any other identifier that doesn’t occur within that scope. One Abstraction of the form λv.E can be converted to λv.E[v’/x]x*x v] provided that the substitution v’ for v is valid in E Ex: λx.x^2 +2x+1  λm.m^2 +2m+

Ex: (λx.λy.(x)2y) (λz.z+1)5  (λy.(λz.z+1)2y)5  ((λz.z+1)2*5)  (λz.z+1)10  10+1  11 Ex: (λx.λy.yx)(+3 4) (λx.+x 2)  (λy.y(+3 4)) (λx.+x 2)  ((λx.+x 2)(+3 4))  +(+3 4)2  +7 2  9

  • In λ-expressions all functions have one variable
  • Functions of several variables may be expressed as a function of one variable through “carrying”
    • H(x,y) = x+y comes from H:(zxz)  z
  • With carrying we can input one variable at a time into separate functions
    • The first function takes the first argument, x, and returns a function that will take the second variable, y, and will in turn provide the desired output to create the same function by carrying
    • F:z (zz) G:zz o F maps integers to a function while G maps integers to integers o F(x) returns a function G(x) that provides the appropriate result when supplied with y  F(2)  G2 when G2(y)  2+y  F(2)(3)  G2(3)  2+3  5 o In λ-calculus this function is described as (λx.λy.x+y) o For function applications ((λx.λy.x+y)2)3  (λy.2+y)3  2+3  5
    • To be able to program significant function in λ-calculus, it is convenient to have a way to attach names to λ-expressions Ex: Plusp  (λx.x ≥ 0) Minusp  (λx.x < 0) Succ  (λx.x+1) Square  (λx.x*x) Minusp(Succ(2))  (λx.x < 0)(Succ(2))  (Succ(2) < 0)  ((λx.x+1)2 < 0)  ((2+1) < 0)  3 < 0  False λ-Expressions to handle truth values

(if c TF) Selects T if c is true  (λTF.T) we always select True Selects F if c is false  (λTF.F) we always select False Ex: (Less26)26  (True)26  (λTF.T)26  2

  • (True -> E 1 .E 2 )^ ^ True E 1 E 2 ^ (λTF.T)E 1 E 2 ^ E 1
  • (False -> E 1 .E 2 )^ ^ False E 1 E 2 ^ (λTF.F)E 1 E 2 ^ E 2