Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is a lambda Calculus question: Lambda calculus (also written as -calculus or called the lambda calculus) is a formal system in mathematical logic and

This is a lambda Calculus question:

"Lambda calculus (also written as -calculus or called "the lambda calculus") is a formal system in mathematical logic and computer science for expressing computation by way of variable binding and substitution.

Question:

Computing the exponent of a number (i.e., n^k) 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^8 as: n * n * n * n * n * n *n * n, we can compute it by repeatedly squaring, beginning with n, computing n^2, n^4 and finally n^8. In general, the algorithm would do the following:

n^k = (n^(k/2))^2 if k is even n^k = n * n^(k-1) if k is odd

Write the lambda expression for this function. You will need to use the if function of the type required for Problem 4 (assume you have a correct implementation). Because this is a recursive function, you will have to nest the lambdas taking n and k within a 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Sham Navathe

4th Edition

0321122267, 978-0321122261

More Books

Students also viewed these Databases questions