Given: iszero? = \x.(x (\y.\z.false) (\x.x) true) true = \x.\y.x false = \x.\y.y add = \n.\m.\f.\x.n f (m f x) 2 = \f.\x.(f (f x)) In the lambda evaluations, the function being applied is underlined at each step. Problem #1: Show that (iszero? 2) evaluates to FALSE ---------- Here's one way to evaluate the expression, using the equivalent of lazy evaluation: (iszero? 2) \x.(x (\y.\z.FALSE) (\x.x) TRUE) 2 // Expand iszero, apply -------------------------------- 2 (\y.\z.FALSE) (\x.x) TRUE \f.\x.(f (f x)) (\y.\z.FALSE) (\x.x) TRUE // Expand 2, apply --------------- \x.((\y.\z.FALSE) ((\y.\z.FALSE) x)) (\x.x) TRUE ------------------------------------ ((\y.\z.FALSE) ((\y.\z.FALSE) (\x.x))) TRUE // <--- Lazy eval ----------- (\z.FALSE) TRUE -------- FALSE In the line above marked "Lazy eval" I chose to apply the first \y.\z.FALSE function to its unevaluated first argument. Eager evaluation would've evaluated the argument first, then passed it to \y.\z.FALSE as shown below. We get the same answer in either case: <...First few lines would be the same...> ((\y.\z.FALSE) ((\y.\z.FALSE) (\x.x))) TRUE // <--- Eager eval ------------- ((\y.\z.FALSE) (\z.FALSE)) TRUE // Now pass arg to \y. ------------- (\z.FALSE) TRUE ---------- FALSE Problem #2: Show that ((add 2) 3) evaluates to 5 ---------- ((add 2) 3) (((\n.\m.\f.\x.n f (m f x)) \a.\b.(a (a b))) 3) ------------------------- (\m.\f.\x.((\a.\b.(a (a b))) f (m f x)) 3) ----------------- (\m.\f.\x.((\b.(f (f b)) (m f x)) 3) ------------- (\m.\f.\x.(f (f (m f x))) 3) (\m.\f.\x.(f (f (m f x))) (\r.\s.(r (r (r s))))) ------------------------ \f.\x.(f (f ((\r.\s.(r (r (r s)))) f x))) ------------------- \f.\x.(f (f (\s.(f (f (f s))) x))) ---------------- \f.\x.(f (f (f (f (f x)))) 5 %% Problem #3 ?- mother(Mom,holly), mother(Mom,Sib), Sib \= holly. %% Problem #4 great_aunt(Aunt, Person) :- grandparent(Grand, Person), sister(Aunt, Grand). sister(Sis, Person) :- parent(P, Sis), parent(P, Person), female(Sis), Sis \= Person. %% \= is "not equal" ?- great_aunt(Aunt, brad). % My great aunts ?- great_aunt(Aunt, P). % All great aunts %% Problem #5 full_brother(Bro, Person) :- mother(Mom, Bro), father(Pop, Bro), mother(Mom, Person), father(Pop, Person), male(Bro), Bro \= Person. ?- full_brother(Bro, P). % all full brothers %% Problem #6 brother(durkee, elmo) / | \ / | \ / | \ son(durkee, virginia) parent(virginia,elmo) durkee \= elmo / \ | / \ | parent(virginia, durkee) male(durkee) mother(virginia,elmo) | | mother(virginia, durkee)