298x Filetype PDF File size 0.09 MB Source: cs.pomona.edu
Lecture 5: Lambda Calculus See lambda calculus cheat
CSC 131 sheet on “links” page of
Fall, 2011 course web page!
Kim Bruce
Pure Lambda Calculus Computability
• Terms of pure lambda calculus
- M ::= v | (M M) | λv. M
- Provide theoretical foundations for functional • Can encode all computable functions in pure
languages. untyped lambda calculus.
- Turing-complete - true = λ u. λ v. u
• Reduction rules for lambda calculus: - false = λ u. λ v. v
(α) λx. M → λy. ([y/x] M), if y ̸∉ FV(M). - cond = λ u. λ v. λ w. u v w
(β) (λx. M) N → [N/x] M.
(η) λx. (M x) → M. Optional rule
Lambda Encoding Encoding Integers
• Integers:
• Pairing: - 0 = λ s. λ z. z.
Pair = λ m. λ n. λ b. cond b m n. - 1 = λ s. λ z. s z.
- - 2 = λ s. λ z. s (s z).
- fst = λp. p true
- snd = λp. p false • Integers encode repetition:
- 2 f x = f (f x)
(n)
- n f x = f (x)
Arithmetic Predecessor
• Succ = λ n. λ s. λ z. s (n s z) • PZero = <0,0> = Pair 0 0
- Succ n = λ s. λ z. s (n s z) = λ s. λ z. s (s(n) z) = n+1 • PSucc = λ n. Pair (snd n) (Succ (snd n))
• Plus = λ n. λ m. λ s. λ z. m s (n s z). - PSucc PZero =
• Mult = λ n. λ m. (m ( Plus n) 0). - n PSucc PZero = for n > 0
• isZero = λ n. n (λ x. false) true • Pred = λ n. fst (n PSucc PZero)
- Pred n = n - 1, for n > 0,
• Subtraction is hard!! - Pred 0 = 0
Recursion Fixed Points
• Recursive definitions are handy • Several fixed point operators:
- fact = λn. cond (isZero n) 1 (Mult n (fact (Pred n))) - Ex: Y = λf . (λx. f (xx))(λx. f (xx))
- Not a definition because can’t name functions! • Claim for all g, Y g = g (Y g)
• Let F stand for the closed term: Y g = λf . (λx. f (xx))(λx. f (xx)) g
- λf. λn. cond (isZero n) 1 (Mult n (f (Pred n))) = (λx. g(xx))(λx. g(xx))
- Notice F(fact) = fact. = g((λx. g(xx))(λx. g(xx)))
- fact is a fixed point of F = g (Y g)
- To find fact, need only find fixed point of F! If let x = Y g, then g (x ) = x .
• 0 0 0
Factorial Computing Factorials
• Recursive definition: fact 1 = (F (fact)) 1 because fact is a fixed point of F
- let F = λf. λn. cond (isZero n) 1 (Mult n (f (Pred n))) = (λn. cond (isZero n) 1 (Mult n (fact (Pred n)))) 1
- let fact = Y F expanding F
- then F(fact) = fact = cond (isZero 1) 1 (Mult 1 (fact (Pred 1))) applying it
• Compute: = Mult 1 (fact (Pred 1)) by the definition of cond
fact 0 = (F (fact)) 0 because fact is a fixed point of F = fact 0 by the definition of Mult and Pred
= cond (isZero 0) 1 (Mult 0 (fact (Pred 0))) = 1 by the above calculation
= 1 by the definition of cond
Lambda Calculus
• λ-calculus invented in 1928 by Church in
Princeton & first published in 1932.
Some History • Goal to provide a foundation for logic
• First to state explicit conversion rules.
• Original version inconsistent, but corrected
• 1933, definition of natural numbers
Collaborators Undecidability
• 1931-1934: Grad students:
- J. Barkley Rosser and Stephen Kleene • Convertibility problem for λ-calculus
- Church-Rosser confluence theorem ensured undecidable.
consistency (earlier version inconsistent) • Validity in first-order predicate logic
- Kleene showed λ-definable functions very rich undecidable.
• Equivalent to Herbrand-Gödel recursive functions
• Equivalent to Turing-computable functions. • Proved independently year later by Turing.
• Founder of recursion theory, invented regular expressions - First showed halting problem undecidable
• Church’s thesis:
- λ-definability ≡ effectively computable
Alan Turing Combinatory Logic
• Turing • Schönfinkel - get rid of bound variables
- 1936, in Cambridge, England, definition of Turing • Combinators K, S sufficient to write all
machine computable functions:
- 1936-38, in Princeton to get Ph.D. under Church. - K x y = x
- 1937, first published fixed point combinator - S x y z = (x y)(x z)
- Kleene did not use fixed-point operator in defining a% CL terms include K, S, variables and all terms
recursive functions on natural numbers! •
- Broke German enigma code in WW2, Turing test AI created by function application.
- Persecuted as homosexual, committed suicide in 1954 • All computable fcns, equivalent to λ-calculus
Types
• Start with base type e and build up types and
terms:
Typed Lambda Calculus - Type ::= e | Type → Type
- M ::= v | (M M) | λv : Type. M
• Examples:
- Types: e, e → e, e → e → e, (e → e) → e, ...
- Terms: λx: e. x, λf: e → e. λz: e. f(f(z))
Definitions Totally Awesome!!
• Earlier definitions generalize over types t:
t • Theorem: If M is a term of the typed lambda
- true = λx:t. λy:u. x calculus, then M has a unique normal form.
t (n)
- n = λs: t→t. λz: t. s (z) I.e., every term of the typed lambda calculus is total.
• Some untyped terms can’t be typed: • Corollary: The typed lambda calculus does not
- Ω = (λx. (x x))(λx. (x x)) include all computable functions.
- Y = λf . (λx. f (x x))(λx. f (x x))
no reviews yet
Please Login to review.