; converts a Church numeral into an ordinary numeral (defn uh [f] ((f (fn [x] (+ x 1))) 0)) ; returns the successor of a Church numeral (defn sr [n] (fn [f] (fn [x] (f ((n f) x))))) ; adds two Church numerals (defn ps [m n] ((n sr) m)) ; raises one Church numeral to the power of another (defn ep [m n] (n m)) ; zero as a Church numeral (defn zo [f] (fn [x] x)) ; one as a Church numeral (defn oe [f] (fn [x] (f x))) ; returns the predecessor of a Church numeral (defn pd [n] (fn [f] (fn [x] (((n (fn [g] (fn [h] (h (g f))))) (fn [y] x)) (fn [z] z))))) ; returns the difference of two Church numerals (defn st [m n] ((m pd) n)) ; returns the absolute difference of two Church numerals (defn ae [m n] (ps (st m n) (st n m))) ; returns a if m=n, and b otherwise (defn il [m n a b] (((ae m n) (fn [x] b)) a)) ; returns 1 if m=n and zero otherwise (defn el [m n] (il m n oe zo)) ; returns 1 if a^n + b^n = c^n, and zero otherwise (defn ft [a b c n] (el (ps (ep a n) (ep b n)) (ep c n))) ; returns the first, second, third elements of a tuple (defn fd [x y z] x) (defn sd [x y z] y) (defn td [x y z] z) (defn mm [g] (let [ a (g fd) b (g sd) c (g td) ] (fn [h] (h a (sr b) (ps c (a b)))) )) ; returns f(n-1)+f(n-2)+...+f(0) (defn sv [n f] (((n mm) (fn [g] (g f zo zo))) td)) ; two as a Church numeral (def to (ps oe oe)) ; three as a Church numeral (def te (ps to oe)) ; 27 as a Church numeral (def tn (ep te te)) ; 27^27 as a Church numeral (def lt (ep tn tn)) ; Computes the number of solutions to x^n + y^n = z^n with 0 <= x,y,z,n-3 < 27^27. ; By Fermat's Last Theorem, the only solutions are the trival solutions x=0 or y=0. ; So the answer is (27^27)(2*27^27-1)= ; 393254100951105827236151817053824232565763475400186496084682581445313632500815. (def tm (sv lt (fn[a] (sv lt (fn[b] (sv lt (fn[c] (sv lt (fn[d] (ft a b c (ps d te))))))))))) (println (uh tm))