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:

    He prayed more deeply for simple selflessness than he had ever prayed before—and, feeling an uprush of grace in the very intention, shed the night in his heart and called it light. And walking out of the little church he felt confirmed in not only the worth of his whispered prayer but in the realization, as well, that Christ had become man and not some bell-shaped Corinthian column with volutes for veins and a mandala of stone foliage for a heart.
    Alexander Theroux (b. 1940)