CS 541 Lecture -*- Outline -*- * Equational theory of the (simply typed) lambda calculus advert: answer to the question, when are two functions equal? computation when consider the directed conversion rules review notation from references used in course ** equational rules for the simply typed lambda calculus an equation is a 4-tuple H |> e = e' : s where terms e and e', a type env H, a type expr s such that H |> e : s and H |> e' : s equations are typed, including H also tells what variables the equation ranges over. ------------------- EQUATIONAL THEORY OF THE LAMBDA CALCULUS CONVERSION RULES (alpha) H |> (\x:s.U) = (\y:s.[y/x]U) : t if y not in Fv(U) (beta) H |> ((\x:s.e) e') = [e'/x]e : t (eta) H |> \x:s.e(x) = e : s->t if x not in Fv(e) ------------------- Some authors (e.g., Barendregt) give the (alpha) rule with the additional side condition that "y is not bound in U", but this is not necessary (Mitchell), as with that condition in place one can, by some extra conversions, first inside, get around it. the above is the interesting part, what follows is just machinery for induction ------------------- EQUIVALENCE RULES (refl) H |> e = e : s H |> e = e' : s (sym) ------------------ H |> e' = e : s H |> e = e' : s, H |> e' = e'' : s (trans) ------------------ H |> e = e'' : s CONGRUENCE RULES H[x:->s] |> e = e' : t (xi) ------------------------------- H |> (\x:s.e) = (\x:s.e') : (s -> t) H |> e0 = e0' : (s -> t), H |> e1 = e1' : s (mu) ------------------------------ H |> (e0 e1) = (e0' e1') : t ----------------------- conversion rules: (alpha), (beta), (eta) equivalence rules: (refl), (trans), (sym) used to prove that equality is an equivalence relation congruence rules: (cong), (xi) state that application and abstraction are congruences with respect to equality. ** conversion rules *** alpha, change of bound variables bound variable names usually considered unimportant: will treat raw terms as equivalence classes of terms under alpha-cnv --------------- SYNTACTIC IDENTITY (Congruence) (\x:t.x) == (\y:t.y) def: e is congruent to e' iff they are alpha convertable. ----------------- conventional not to distinguish congruent terms. problems: if y is free in U (\x.y) would become \y.([y/x]y) = \y.y *** beta, application --------------------- EXAMPLES OF CONVERSION (\x.add(square(x),1)) 3 = add(square(3),1) (\x.y) z = y --------------------- problem? use careful definition of substitution (cf 9.7 in Paulson) (\x . \y . y x) y *** eta, function abstraction, extensionality --------------------- (\x.inc x) = inc --------------------- problems: if x is free in M (\x.xx) would become x practical? see "Scheme and the Art of Programming" section 8.2. write both, neither, then both using neither and eta-reduce *** convertability relation denoted =, cnv, or <=> (some abuse of notation here) relfexive, transitive, symmetric closure of above ** equational theory a theory is a set of sequents (of form H |> e = e' : s) that are provable from the axioms using the proof rules. *** proofs a proof of H |> e = e' : s is (formally) a list of sequents such that the last element is the desired sequent, and such that each element in the list is either an axiom or follows by some proof rule from earlier elements. Notation: write |- H |> e = e' : s to mean that H |> e = e' : s is provable without hypotheses. Write H |> e = e' : s |- H |> e'' = e''' : t to mean that e'' = e''' is provable assuming e = e'. Conventionally proofs written as trees, with the conclusion at the bottom, the justification to the right of axioms and to the right of the line separating hypotheses from conclusions ------------------------ PROOFS OF EQUATIONS (refl) H[x:->o] |> x = x : o (xi) ------------------------------------- H |> (\x:o . x) = (\x:o . x) : (o -> o) ------------------------ Some rules split the proof: here H is z:((o -> o) -> (o -> o)) -------------------------- (lemma 2) H |> (\f:o -> o . \y:o . z f y) = z : (o -> o) -> o -> o (lemma 1) H |> (\x:o . x) = (\x:o . x) : o -> o (mu) ------------------------------------ H |> (\f:o -> o . \y:o . z f y) (\x:o . x) = z (\x:o . x) : o -> o where the proof of lemma 1 is: (refl) H[x:->o] |> x = x : o (xi) --------------------------------- H |> (\x:o . x) = (\x:o . x) : o -> o and the proof of lemma 2 is: (eta) H[f:->(o->o)] |> \y:o . z f y = z f : o->o (xi) ------------------------------------ H |> (\f:o -> o \y:o . z f y) = \f:o -> o. z f : (o -> o) -> o -> o, (eta) H |> \f: o -> o . z f = z (trans) --------------------------------- H |> (\f:o -> o . \y:o . z f y) = z : (o -> o) -> o -> o --------------------------- exercise in class: type check and then prove |> (\z:o . \f:o -> o . f (f z)) = (\z:o . \f:o->o . (\g:o->o . \x:o . g (g x)) f z : o *** complexity the simply typed theory theory is consistent (has a model, doesn't allow you to prove every equation) and decideable if we erase the type information, get a consistent, but *undecideable* theory