% 15-814 Fall 2020 % Lecture 2 % Primitive Recursion % Frank Pfenning defn zero = \s. \z. z defn succ = \n. \s. \z. s (n s z) norm _0 = zero norm _1 = succ _0 norm _2 = succ _1 defn plus = \n. \k. n succ k defn times = \n. \k. n (plus k) zero defn exp = \n. \k. k (times n) (succ zero) norm _5 = plus _1 (plus _2 _2) norm _32 = exp _2 _5 defn omega = \x. x x defn Omega = omega omega % check that Omega doesn't normalize in 10 million steps !norm 10000000 _ = Omega norm 0 _ = omega % omega is in normal form % flipped the pairs from the lecture order % to be consistent with the notes % specification: pred2 n = (where 0-1 = 0) defn pair = \x. \y. \p. p x y defn pred2 = \n. n (\w. w (\x. \y. pair (succ x) x)) (pair zero zero) defn pred = \n. (pred2 n) (\x. \y. y) norm _4 = pred _5