TRICKS: 1. write "By induction on the derivation of ...." where ... shows in the if part of the lemma. 2. Write down equations between variables whenever you can 3. Write down what it is you need to prove for each case 4. Try to find a way to apply the inductive hypothesis, in particular look at the premise of the rules with the same form as what you are doing induction on 5. Look at rules you have and use them --------------------------------------------------- Prove: if |- add N1 N2 N3 then |- add N1 (S N2) (S N3) Proof: By induction on the derivation of |- add N1 N2 N3 Case: ------------- (note N1 = Z, N2 = N, N3 = N) |- add Z N N M.P. (must prove): |- add Z (S N) (S N) (add-Z) Case: |- add N1 N2 N3 ----------------------- |- add (S N1) N2 (S N3) renaming to: (1) |- add Na Nb Nc ----------------------- (note: N1 = S Na, N2 = Nb, N3 = S Nc) |- add (S Na) Nb (S Nc) M.P.: |- add (S Na) (S Nb) (S (S Nc)) (2) (a) |- add Na (S Nb) (S Nc) (By (1) and I.H.) (3) |- add (S Na) (S Nb) (S S Nc) (By (2) an addS) case proved. ------------------------------- e1 -> e1' ------------------ (App1) e1 e2 -> e1' e2 e2 -> e2' --------------- (App2) v e2 -> v e2' ------------------- (beta-val) (\x.e) v -> e[v/x] --------- (reflexivity) e ->* e e1 -> e2 e2 ->* e3 ------------------- (trans) e1 ->* e3 Prove: If e1 ->* e1'; then e1 e2 ->* e1' e2 Proof: By induction on e1 ->* e1' Case: --------- (Note e1 = e, e1' = e) e ->* e e1 e2 ->* e1 e2 (reflexivity) Case: ea -> eb eb ->* ec ------------------- (Note e1 = ea, e1' = ec) ea ->* ec M.P.: e1 e2 ->* ec e2 |- eb e2 ->* ec e2 (By 2 and IH) |- ea e2 -> eb e2 (By App 1) |- ea c2 -> ec e2 (By 3 and 4 and Trans) case proved. Pairs and Unit --------------- v:= ... | (v1, v2) | () e:= ... | let (x1, x2) = e1 in e2 | (e1, e2) | () | e1; e2 t:= ... | t1 * t2 | unit Operational semantics: e1 -> e1' --------------------- (e1, e2) -> (e1', e2) e2 -> e2' -------------------- (v, e2) -> (v, e2') e1 -> e1' -------------------------- let (x1, x2) = e1 in e2 -> let (x1, x2) = e1' in e2 -------------------------------- let (x1, x2) = (v1, v2) in e2 -> e2 [v1/x1][v2/x2] e1 -> e1' ------------------ e1; e2 -> e1'; e2 ------------- (); e2 -> e2 Typing rules ------------ G |- e1 : t1 G |- e2 : t2 -------------------------- G |- (e1 e2) : t1 * t2 G |- e1 : t1 * t2 G, x1: t1, x2 : t2 |- e2: t3 ----------------------------------------------- G |- let (x1, x2) = e1 in e2 : t3 --------------- G |- () : unit G|- e1 : unit G |- e2 : t -------------------------- G |- e1; e2 : t Example: ------------- --------------- ;.,x1:bool, x2:bool |- x1: bool |- true: bool |- false : bool ;.,x1:bool, x2:bool |- x2: bool ------------------------------ -------------------------------------- |- (true, false) : bool * bool ., x1:bool, x2:bool |-x1 and x2 : bool ----------------------------------------------------------------------- |- let (x1, x2) = (true, false) in (x1 and x2) : bool