CS 515 Homework 3 problems 1-4 solutions. PROBLEM 1 ;; 1.1 (f g x v) w --> ((((f g) x) v) w) ;; 1.2 \xy.(\z.x(y z))v w --> (\x.(\y.(((\z.(x (y z))) v) w))) ;; 1.3 \x.xx \x.xx --> ;; Note! don't be decieved into grouping by spaces (\x.(x (x (\x.(x x))))) ;; If we treated the spaces as grouping, we would get this: ((\x.(x x)) (\x.(x x))) PROBLEM 2 ======== reduction 1 ======== (\xyz.(x z) (y z)) (\xy.x) (\xy.x) -------------------------- ;; only choice: \xy.x for x (\yz.((\xy.x) z) (y z)) (\xy.x) ----------------- ;; innermost: z for x (\yz.(\y.z) (y z)) (\xy.x) ;; applicative: (y z) for y ------------ (\z. (\y.z) ((\xy.x) z)) ;; only choice: z for x ----------- (\z. (\y.z) (\y.z)) ------------- (\z. z) ============ reduction 2 ============= (\xyz.(x z) (y z)) (\xy.x) (\xy.x) -------------------------- ;; only choice: \xy.x for x (\yz.((\xy.x) z) (y z)) (\xy.x) ;; leftmost first: (\xy.x) for y ------------------------------- (\z.((\xy.x) z) ((\xy.x) z)) ;; two choices: take left ----------- (\z. (\y.z) ((\xy.x) z)) ;; only choice: take right ----------- (\z. (\y.z) (\y.z)) ------------- (\z. z) ============ reduction 3 (similar to 2) ============= (\xyz.(x z) (y z)) (\xy.x) (\xy.x) -------------------------- ;; only choice: \xy.x for x (\yz.((\xy.x) z) (y z)) (\xy.x) ;; normal: (\xy.x) for y ------------------------------- (\z.((\xy.x) z) ((\xy.x) z)) ;; two choices: take right ----------- (\z.((\xy.x) z) (\y.z)) ;; now take left (\z. (\y.z) (\y.z)) ------------- (\z. z) ============ reduction 4 =========== (\xyz.(x z) (y z)) (\xy.x) (\xy.x) -------------------------- ;; only choice: \xy.x for x (\yz.((\xy.x) z) (y z)) (\xy.x) ----------------- ;; applicative: z for x (\yz.(\y.z) (y z)) (\xy.x) ;; normal: (\xy.x) for y -------------------------- (\z.(\y.z) ((\xy.x) z)) ;; only choice: z for x ----------- (\z.(\y.z) (\y.z)) ------------- (\z. z) PROBLEM 3.1 or (not a) b --> (\x.\y.(x true) y) ((\x.(x false) true) a) b --> (normal order) (\y.(((\x.(x false) true) a) true) y) b --> (((\x.(x false) true) a) true) b --> (((a false) true) true) b PROBLEM 3.2 (and (or a b) (not (and a b))) --> (\x.\y.(x y) false) ((\x.\y.(x true) y) a b) ((\x.(x false) true) ((\x.\y.(x y) false) a b)) --> (\y.(((\x.\y.(x true) y) a b) y) false) ((\x.(x false) true) ((\x.\y.(x y) false) a b)) --> (((\x.\y.(x true) y) a b) ((\x.(x false) true) ((\x.\y.(x y) false) a b))) false --> (((a true) b) ((((\x.\y.(x y) false) a b) false) true)) false (((a true) b) ((((a b) false) false) true) false PROBLEM 4.1 (\x.xx) (\x.xx) --> (\x.xx) (\x.xx) (\x.xxx) (\x.xxx) --> (\x.xxx) (\x.xxx) (\x.xxx) (\x.xxxx) (\x.xxxx) --> (\x.xxxx) (\x.xxxx) (\x.xxxx) (\x.xxxx) PROBLEM 4.2 (\x.z) ((\x.xx) (\x.xx)) (\x.\y.z) ((\x.xx) (\x.xx)) ((\x.xx) (\x.xx)) PROBLEM 4.3 (a b) (((\x.x) c) ((\y.y) d)) PROBLEM 6 See ~uli/cs515/examples/Scheme/ValueDynamic.ss on ilab cluster.