Church Encoding - Church Booleans

Church booleans are the Church encoding of the boolean values true and false. Some programming languages use these as an implementation model for boolean arithmetic; examples are Smalltalk and Pico. The boolean values are represented as functions of two values that evaluate to one or the other of their arguments.

Formal definition in lambda calculus:

trueλa.λb. a
falseλa.λb. b

Note that this definition allows predicates (i.e. functions returning logical values) to directly act as if-clauses, e.g. if predicate is a unary predicate,

predicate x then-clause else-clause

evaluates to then-clause if predicate x evaluates to true, and to else-clause if predicate x evaluates to false.

Functions of boolean arithmetic can be derived for Church booleans:

andλm.λn. m n m
orλm.λn. m m n
not1λm.λa.λb. m b a
not2λm. m (λa.λb. b) (λa.λb. a)
xorλa.λb. a (not2 b) b
ifλm.λa.λb. m a b

Some examples:

and true false(λm.λn. m n m) (λa.λb. a) (λa.λb. b) ≡ (λa.λb. a) (λa.λb. b) (λa.λb. a)(λa.λb. b)false
or true false(λm.λn. m m n) (λa.λb. a) (λa.λb. b)(λa.λb. a) (λa.λb. a) (λa.λb. b)(λa.λb. a)true
not1 true(λm.λa.λb. m b a) (λa.λb. a)(λa.λb. (λa.λb. a) b a)(λa.λb. (λb.b) a)(λa.λb. b)false
not2 true(λm. m (λa.λb. b) (λa.λb. a)) (λa.λb. a)(λa.λb. a) (λa.λb. b) (λa.λb. a)(λb. (λa.λb. b)) (λa.λb. a)λ1.λb. bfalse

Read more about this topic:  Church Encoding

Famous quotes containing the word church:

    The Tories in England had long imagined that they were enthusiastic about the monarchy, the church and beauties of the old English Constitution, until the day of danger wrung from them the confession that they are enthusiastic only about rent.
    Karl Marx (1818–1883)