Question

In: Advanced Math

How do you define a function that tests if a number is even using lambda calculus?...

How do you define a function that tests if a number is even using lambda calculus? The function should return true if the number is even, and false otherwise.

Solutions

Expert Solution

Lambda calculus is a notation for describing mathematical functions and programs. It is a mathematical system for studying the interaction of functional abstraction and functional application. It captures some of the essential, common features of a wide variety of programming languages. Because it directly supports abstraction, it is a more natural model of universal computation than a Turing machine is.

A λ-calculus term is:

  • a variable xVar, where Var is a countably infinite set of variables;
  • an application, a function e0 applied to an argument e1, usually written e0e1 or e0(e1); or
  • a lambda abstraction, an expression λx.e representing a function with input parameter x and body e. Where a mathematician would write xx2, or an SML programmer would write fn x => x*x, in the λ-calculus we write λx.x2.

In BNF notation,

e ::= x | λx.e | e0e1

We use the metavariable e to represent a λ-calculus term.

Parentheses are used just for grouping; they have no meaning on their own. Like other familiar binding constructs from mathematics (e.g., sums, integrals), lambda terms are greedy, extending as far to the right as they can. Therefore, the term λx. λy. y is the same as λx.(xy.y)), not (λx.x) (λy.y). As in SML, application terms are left-associative, so x yz is the same thing as (x y) z.

For simplicity, multiple variables may be placed after the lambda, and this is considered shorthand for having a lambda in front of each variable. For example, we write λxy.e as shorthand for λxy.e. This shorthand is an example of syntactic sugar. The process of removing this shorthand is currying, just as in SML, and adding it is called uncurrying.

We can apply a curried function like λxy.x one argument at a time. Applying it to one argument results in a function that takes in a value for x and returns a constant function, one that returns the value of x no matter what argument it is applied to. As this suggests, functions are just ordinary values, and can be the results of functions or passed as arguments to functions (even to themselves!). Thus, in the lambda calculus, functions are first-class values: lambda terms serve both as functions and data.

We introduce the following two functions

which we call the values

“true” T ≡ λxy.x and

“false” F ≡ λxy.y

The first function takes two arguments and returns the first one, the second function returns the second of two arguments.

3Logical operations It is now possible to define logical operations using this representation of the truth values.

The AND function of two arguments can be defined as ∧ ≡ λxy.xy(λuv.v) ≡ λxy.xyF

The OR function of two arguments can be defined as ∨ ≡ λxy.x(λuv.u)y ≡ λxy.xTy

Negation of one argument can be defined as ¬ ≡ λx.x(λuv.v)(λab.a) ≡ λx.xFT

The negation function applied to “true” is ¬T ≡ λx.x(λuv.v)(λab.a)(λcd.c)

which reduces to TFT ≡ (λcd.c)(λuv.v)(λab.a) = (λuv.v) ≡ F that is, the truth value “false”


Related Solutions

Prove that even number of fermions produces boson using wave function.
Prove that even number of fermions produces boson using wave function.
(Advanced Calculus and Real Analysis) - Cantor set, Cantor function * (a) Define the Cantor function....
(Advanced Calculus and Real Analysis) - Cantor set, Cantor function * (a) Define the Cantor function. (b) Prove that the Cantor function is non-decreasing.
How do you compute a break even point using thevCVP and variable costing
How do you compute a break even point using thevCVP and variable costing
how do you relate the air fuel ratio to the equivalence ratio, and the ‘lambda’ ratio
how do you relate the air fuel ratio to the equivalence ratio, and the ‘lambda’ ratio
How do you define personality?
How do you define personality? What are the main approaches to the study of personality.
Using the principles of free trade, how do you define globalization in relation to the current...
Using the principles of free trade, how do you define globalization in relation to the current perceived multipolarity of the world? Consider using the dilemmas in trade that we have discussed to organize your response.
Using Haskell, how do you make a function i.e test that will take a list of...
Using Haskell, how do you make a function i.e test that will take a list of integers and add a 5 to the end of that list ex: test [1, 2, 3] will be changed to test [1, 2, 3, 5]
How would you define the null hypothesis? How would you define the alternative hypothesis? How do...
How would you define the null hypothesis? How would you define the alternative hypothesis? How do you know when it is a left tailed/right tailed/or two tailed test? What is a p value and how can you use it to test a hypothesis? What is a p-value and how can you use it to test a hypothesis? Give your description of it in your own words that make sense to you. What does a low p-value mean? What about a...
Develop a C++ function to find the number of even and odd integers in a given...
Develop a C++ function to find the number of even and odd integers in a given array of integers Pass in an array of integers Pass in the size of the array of integers Pass in a reference parameter for the number of even values Pass in a reference parameter for the number of odd values The function doesn't return anything Develop a C++ program to test your function
How do you calculate Payback Period on Excel by using FAME function? What is the formula?
How do you calculate Payback Period on Excel by using FAME function? What is the formula?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT