Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Consider a function ite ( for if then else ) which takes three arguments: a boolean, an expression to evaluate if the boolean is true,
Consider a function ite
for if then else
which takes three arguments: a boolean, an expression to evaluate if the boolean is true, and a second expression to evaluate if the boolean is false.
a
Given the lambda expressions for boolean constants and operators presented in class, write the lambda expression for this ite function.
b
Write the lambda expression for a function iteite
for if then elseif then else
which takes five arguments: a boolean, an expression to evaluate if the boolean is true, another boolean, an expression to evaluate if the second boolean is true, and a third expression to evaluate if both booleans are false. You may assume that a correct implementation of function ite from
a
is available to you, and use it if you like.
Problem
Points
Computing the exponent of a number
i
e
nk
can take O
n
time if done by simply multiplying by n
k number of times. A logarithmic way for computing exponents is by using the idea of successive squaring. For instance, rather than computing n
as: n
n
n
n
n
n
n
n
we can compute it by repeatedly squaring, beginning with n
computing n
n
and finally n
In general, the algorithm would do the following:
nk
n
k
if k is even
nk
n
n
k
if k is odd
Write a lambda expression for this function. You may assume that the function required in Problem
a
is already available to you, and you may use it if you like. You may also assume that if you use the function from Problem
a
you are simply able to state the condition as a logical statement.
Because this is a recursive function, you will have to nest the lambda expression taking argument k within another lambda taking f
the function
which you will then recursively call within the body. Plus, you will have to precede this definition with the letter Y
which represents a special kind of lambda expression called the Y combinator, which actually makes the recursion happen. So
your solution will look something like:
Y lambda f
rest of your solution
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started