# Lambda calculus exercises ## Slide 12 ### Round 1 Using square bracket notation for redexes: [(\x.x) z] -> z (\xy.x) z = [(\x.(\y.x)) z] -> \y.z (\xy.x) z u = ([(\x.(\y.x)) z]) u -> [(\y.z) u] -> z Using underline notation for redexes: (\x.x) z -------- -> z (\xy.x) z = (\x.(\y.x)) z ------------- -> \y.z (\xy.x) z u = ((\x.(\y.x)) z) u ------------- -> (\y.z) u -------- -> z ### Round 2 (\x.x x) (\y.y) --------------- -> (\y.y) (\y.y) ------------- -> (\y.y) \x.(\y.y) z -------- -> \x.z (\x.(x (\y.x))) z ----------------- -> z (\y.z) ## Examples of free and bound variables (\x.x y) z Free: y and z Bound: x (\x.x y) x Free: x and y Bound: x (this is a different x!) (\x.x y) z Within the body of the abstraction (x y): Free: x and y ## Slide 25 Applicative-order reduction of Example 1: (λx.x x) ((λxy.y x) z (λx.x)) = (\x.x x) (((\x.(\y.y x)) z) (\x.x)) --------------- -> (\x.x x) ((\y.y z) (\x.x)) --------------- -> (\x.x x) ((\x.x) z) -------- -> (\x.x x) z ---------- -> z z Normal-order reduction of Example 1: (\x.x x) (((\x.(\y.y x)) z) (\x.x)) ----------------------------------- -> (((\x.(\y.y x)) z) (\x.x)) (((\x.(\y.y x)) z) (\x.x)) ... -> z z Applicative-order reduction of Example 2: (λxyz.x z) (λz.z) ((λy.y) (λz.z)) x = (((\x.\y.\z.x z) (\z.z)) ((\y.y) (\z.z))) x --------------------- -> (((\y.\z'.(\z.z) z')) ((\y.y) (\z.z))) x --------- -> ((\y.\z'.z') ((\y.y) (\z.z))) x ------------- -> ((\y.\z'.z') (\z.z)) x ------------------ -> (\z'.z') x ---------- -> x ## Church encoding practice succ two = (\nfx.f (n f x)) (\fx.f (f x)) ------------------------------ -> \fx.f ((\fx.f (f x)) f x) --------------- -> \fx.f ((\x.f (f x)) x) -------------- -> \fx.f (f (f x))