eval skipl_false : SKIP1 INC (PAIR FALSE ZERO) =n> (\b -> b TRUE ZERO) PAIR TRUE ZERO eval skip1_true_zero : SKIP1 INC (PAIR TRUE ZERO) =n> (\b -> b TRUE ONE) PAIR TRUE ONE -- eval skip1_true_one : SKIP1 INC (PAIR TRUE ONE) =n> (\b -> b TRUE TWO) PAIR TRUE TWO
Lambda calculus
--------------------------------------------------------------------------------
-- Booleans
--------------------------------------------------------------------------------
let TRUE = \x y -> x
let FALSE = \x y -> y
let ITE = \b x y -> b x y
let AND = \b1 b2 -> ITE b1 b2 FALSE
let OR = \b1 b2 -> ITE b1 TRUE b2
--------------------------------------------------------------------------------
-- Numbers
--------------------------------------------------------------------------------
let ZERO = \f x -> x
let ONE = \f x -> f x
let TWO = \f x -> f (f x)
let INC = \n f x -> f (n f x)
--------------------------------------------------------------------------------
-- Pairs
--------------------------------------------------------------------------------
let PAIR = \x y b -> ITE b x y
let FST = \p -> p TRUE
let SND = \p -> p FALSE
--------------------------------------------------------------------------------
-- Ignore this definition; it's a hack to allow you to test some parts before
-- completing others
--------------------------------------------------------------------------------
let TODO = \i g n o r e -> i g n o r e
--------------------------------------------------------------------------------
-- do not modify text BEFORE this line
--------------------------------------------------------------------------------
let SKIP1 = TODO -- (a)
let DEC = TODO -- (b)
let SUB = TODO -- (c)
let ISZ = TODO -- (d)
let EQL = TODO -- (e)
--------------------------------------------------------------------------------
-- do not modify text AFTER this line
--------------------------------------------------------------------------------
-- Part (a)
eval skip1_false :
SKIP1 INC (PAIR FALSE ZERO)
=~> (\b -> b TRUE ZERO) -- PAIR TRUE ZERO
eval skip1_true_zero :
SKIP1 INC (PAIR TRUE ZERO)
=~> (\b -> b TRUE ONE) -- PAIR TRUE ONE
eval skip1_true_one :
SKIP1 INC (PAIR TRUE ONE)
=~> (\b -> b TRUE TWO) -- PAIR TRUE TWO
--------------------------------------------------------------------------------
-- Part (b)
eval decr_zero :
DEC ZERO
=~> ZERO
eval decr_one :
DEC ONE
=~> ZERO
eval decr_two :
DEC TWO
=~> ONE
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images