[Programming Languages And Lambda calculi] 4.3 Coding Boolean values in Lambda expressions

4.3 Boolean coding

In language B, we chose f and t to "represent" "false" and "true". In Lambda calculus, we will make different choices-although in principle it is random, but it turns out that this is the case very convenient:
Insert picture description here

The ≐ symbol indicates that we are shorthand XOR "macro" expressions. The "true", "false" and "if" macros will be very helpful if they are useful. For example, we would think that for any M and N:
if true M N = n M if \ true \ M\ N=_nMi f t r u e M N   =nM
we can expand the macro to prove:
Insert picture description here

Similarly, if false MN = n N:
Insert picture description here

In fact, we found that (if true) = n true and (if false) = n false. In other words, the shorthand (macro) of true will go to the first parameter branch. The shorthand (macro) of false will go to the second parameter branch. The shorthand (macro) of if is just for readability.

Exercise 4.3

Prove (if true) = n and (if false) = n false.

answer

(if true) = (λv.λt.λf.v t f) (λx.λy.x)

nβ (λt.λf.(λx.λy.x) t f)

nβ (λf.(λx.λy.x) f)

nβ (λx.λy.x) = true

(if false) = (λv.λt.λf.v t f) (λx.λy.y)

nβ (λt.λf.(λx.λy.y) t f)

nβ (λf.(λx.λy.y) f)

nβ (λx.λy.y) = false

Exercise

Define and or macro operators to make their behavior consistent with natural conditions (then and true false = n false, etc.)

answer
  • and ≐ λx.λy if x y false
  • or ≐ λx.λy if x true y

Guess you like

Origin blog.csdn.net/qq_35714301/article/details/113812178