Conditions, Booleans and Integers
Keywords
ver. 1.0.0
This chapter introduces untyped lambda calculus encodings for conditional expressions, boolean logic operations, natural numbers, and syntactic conveniences.
Chapter 3 explores building higher-level functional programming abstractions from the pure \(\lambda\)-calculus. It demonstrates how to encode conditional expressions (
cond), truth values (true,false), and boolean operations (not,and,or). Additionally, it constructs natural numbers via Church/pair-based encodings withzero,succ,iszero, andpred, while introducing syntactic simplifications like curried definitions andif...then...elsenotation.
NoteFull summary
3. Conditions, Booleans and Integers
This chapter constructs functional abstractions on top of the untyped \(\lambda\)-calculus:
- Truth Values and Conditional Expressions:
trueis defined asselect_first(\(\lambda \text{first}.\lambda \text{second}.\text{first}\)).falseis defined asselect_second(\(\lambda \text{first}.\lambda \text{second}.\text{second}\)).condis defined as \(\lambda e1.\lambda e2.\lambda c.((c\ e1)\ e2)\), taking the condition \(c\) as its last argument.
- Boolean Operations:
- NOT: Defined via conditional selection as \(\lambda x.((x\ \text{false})\ \text{true})\) or simply
def not x = x false true. - AND: Defined as \(\lambda x.\lambda y.((x\ y)\ \text{false})\) or
def and x y = x y false. - OR: Defined as \(\lambda x.\lambda y.((x\ \text{true})\ y)\) or
def or x y = x true y.
- NOT: Defined via conditional selection as \(\lambda x.((x\ \text{false})\ \text{true})\) or simply
- Natural Numbers:
- Numbers are represented as successor chains of zero:
zero=identity(\(\lambda x.x\))succ= \(\lambda n.\lambda s.((s\ \text{false})\ n)\) (constructing pairs withfalseand the previous number)
- Operations include:
iszero= \(\lambda n.(n\ \text{select\_first})\)pred= \(\lambda n.((( \text{iszero}\ n)\ \text{zero})\ (n\ \text{select\_second}))\), handling the edge case for zero by returningzero.
- Numbers are represented as successor chains of zero:
- Simplified Notations:
- Omitting nested parentheses using left-associative function application rules.
- Dropping \(\lambda\) and
.in definitions (e.g.,def and x y = x y false). - Introducing the syntactic form
if <condition> then <true choice> else <false choice>mapping tocond <true choice> <false choice> <condition>.
- Exercises:
- Deriving implementations and truth tables for
impliesandequiv. - Proving De Morgan’s laws and equivalence identities via functional reduction.
- Deriving implementations and truth tables for
Materials
Source document
- An Introduction To Functional Programming Through Lambda Calculus, Greg Michaelson, Dover Publications, 1989, 2011 — Page 39-50