Lambda Calculus is used in computing, and forms the basis for functional programming.
Conditions
We can represent true and false in these two expressions respectively:
While it does not seem like the two represent anything at all, the idea lies in how they behave; the true function returns the first variable, and the false the second.
Now we can use these two boolean functions together to form an if statement, by passing in the functions as arguments (Input condition, either true or false), (Output if true), and (Output if false):
which maps to this:
def ifelse(b, x, y):
if b:
return x
else:
return y
But why?
Well let us follow this lambda expression, with = true.
You can try the same by passing in as false. We have now implemented a condition function.
Logic Gates
We can also construct logical operations using the true and false expressions. All inputs are either true or false.
NOT
Flips the input from true to false and vice versa.
- If is true, the result is false.
- If is false, the result is true.
AND
Returns true if both inputs and are true:
- If is true, the result is .
- If is false, the result is false, regardless of .
OR
Returns true if at least one input is true:
- If is true, the result is true, regardless of .
- If is false, the result is .
With this, we’ve shown that λ-Calculus can represent and compute logical operations purely through function abstraction and application, making it effectively a universal model of computation.