Lambda Calculus

Cards (58)

  • lambda calculus is a fully expressive (Turing complete) language of computable functions
  • definition of λ\lambda-terms: M::=M ::=xλ.xMM x | \lambda.x|MM
    where x is a variable, λ.x\lambda.x is an abstraction, MN is the application of function M to argument N .
  • redex means reducible expression, which can be reduced within a term, ie (λx.M)N(\lambda x.M)N
  • free variable: a variable that is not bound to any other variable in the program
    bound variable: a variable that is used in a calculation but is not stored in memory
  • alpha-conversion: how to rename variables
    This technique is used to avoid variable capture
    ie M[y/x] is “M with x renamed to y
  • β\beta-reduction: Substitution of terms
  • Proof by Induction
    (To prove that something ( P ) holds for every lambda-term N)
    1. Base case: P holds for x
    2. Inductive step 1: if P holds for N , then it holds for λx.N .
    3. Inductive step 2: prove it holds for MN
  • Church’s thesis: A function of positive integers is computable if and only if lambda-definable
  • Turing’s thesis: Something is computable if and only if a Turing Machine can compute it.
  • Turing shows: Something is lambda-definable if and only if a Turing Machine can compute it
  • True
    trueλx.λy.x,falseλx.λy.ytrue≜\lambda x.\lambda y.x, false≜\lambda x.\lambda y.y
  • if...then...else...
    ifthenelseλb.λx.λy.bxyifthenelse≜\lambda b. \lambda x. \lambda y. bxy
  • Conjunction (and): λb1.λb2.ifthenelse\lambda b_1.\lambda b_2.ifthenelse b1b2falseb_1b_2false
    Disjunction (or): λb1.λb2.ifthenelse\lambda b_1.\lambda b_2.ifthenelse b1trueb_1trueb2b_2
  • Church numerals:
    0λf.λx.x0≜\lambda f.\lambda x.x
    1λf.λx.fx1≜\lambda f.\lambda x.fx
    2λf.λx.f(fx)2≜\lambda f.\lambda x.f(fx)
    ...
  • successor
    succλn.λf.λx.f(nfx)succ≜\lambda n.\lambda f.\lambda x.f(nfx)
  • preceder
    predλn.λf.λx.n(λg.λh.h(gf))(λu.x)(λu.u)pred≜\lambda n.\lambda f.\lambda x.n(\lambda g.\lambda h.h(gf))(\lambda u.x)(\lambda u.u)
  • fixed point for F is a λ-term M such that M=M=βFM_\beta FM
  • Y-combinator: Yλf.(λx.f(xx))(λx.f(xx))Y≜\lambda f.(\lambda x.f(xx))(\lambda x.f(xx))
  • multiply
    mulλm.λn.λf.λx.m(nf)xmul≜\lambda m.\lambda n.\lambda f.\lambda x.m(nf)x
  • exponentiation
    expλm.λn.λf.λx.nmfxexp≜\lambda m.\lambda n.\lambda f.\lambda x.nmfx
  • Y-combinator exploits self-application to deliver fixed points
  • Types for λ-terms:
    τ::=\tau ::=oττ o | \tau \to \tau
    o is a fixed type called the base case
  • Types for λ-terms are right-associative
  • simply-typed lambda-calculus:
    M::=M::=xλxτ.xMM x|\lambda x^{\tau}.x|MM
  • computation of simply-typed lambda-calculus:
    (λxτ.M)NβM[N/x](\lambda x^{\tau}.M)N \to_{\beta} M[N/x]
  • A (typing) context Γ is a finite function from variables to types
    Γ=\Gamma =x1:τ1,x2:τ2,...,xn:τn x_1:\tau_1, x_2:\tau_2,..., x_n:\tau_n
  • By Γ,x:τ\Gamma, x:\tau means the context that is the same as Γ, but extended so that x has type τ
  • A (typing) judgementΓM:τ\Gamma\vdash M:\tausays that M has type τ in
    context Γ : “if each variable xix_i has type τi\tau_i then M has type τ
  • true typing judgements:
    1. Γ,x:τx:τ\over{\Gamma , x: \tau \vdash x: \tau}
    2. Γ,x:τM:σΓ,λxτ.M:τσ{\Gamma , x: \tau \vdash M: \sigma}\over{\Gamma , \lambda x^\tau.M: \tau \to\sigma}
    3. Γ,M:τσ,        Γ,M:τΓ,MN:σ{\Gamma , M: \tau \to\sigma , \space\space\space\space\space\space\space\space\Gamma , M: \tau}\over{\Gamma , MN: \sigma}
  • A term M is well-typed if there is a true judgement Γ ⊢M : τ
    and all subterms of M are also well-typed
  • addition
    addλm.λn.λf.λx.mf(nfx)add≜\lambda m.\lambda n.\lambda f.\lambda x.mf(nfx)
  • Proof by Induction(To prove that something ( P ) holds for every lambda-term N)
    1. Base case: P holds for any variable
    2. Inductive step 1: if P holds for N, then it holds for abstraction
    3. Inductive step 2: prove it holds for application
  • transitive closure β+\to_\beta ^ +
    have at least one reduction step
  • reflexive–transitive closure β\to_\beta ^ *
    have reduction steps with zero or more
  • reflexive–transitive–symmetric closure ==R_R
    reduction steps can go forward or backwards
  • An equivalence (relation) or equational theory is a relation that is reflexive, symmetric, and transitive.
  • alpha -equivalence : terms equivalent modulo variable names
  • beta -equivalence : terms equivalent modulo computation
  • A beta-expansion is a beta-reduction in reverse
  • Terms M and N are α -equivalent, written M =α N , if N can be obtained from M by renaming bound variables.