patternMinor
Why don't we encode church numerals like this?
Viewed 0 times
thiswhylikenumeralschurchencodedon
Problem
I think the following encoding also works.
Note: the original encoding is
Why is the original one better?
ZERO := λf. λx. x
ONE := λf. f
TWO := λf. f f
THREE:= λf. f (f f)Note: the original encoding is
ZERO := λf. λx. x
ONE := λf. λx. f x
TWO := λf. λx. f (f x)
THREE:= λf. λx. f (f (f x))Why is the original one better?
Solution
I think what you really are asking for are criteria for judging correctness of coding. Once you have got these, you can answer your question on your own.
Correctness of coding of some structure always originates from the structure itself. The structure of natural numbers $\mathbb{N}$ is:
$$\mathsf{rec}_A \; x \; f \; 0 = x$$
and
$$\mathsf{rec}_A \; x \; f \; (S n) = f \; n \; (\mathsf{rec}_A \; x \; f \; n).$$
So whatever your coding of natural numbers is, it has to have $0$, $S$ and $\mathsf{rec}$ (only one will do in the untyped $\lambda$-calculus as there are no types to worry about) such that the above equations are satisfied for all suitable $x$, $f$ and $n$.
You can ask yourself:
Does your coding allow you write down $0$, $S$ and $\mathsf{rec}$ which satisfy the desired equations?
If it does, then it's a valid coding. There are many codings of natural numbers.
Correctness of coding of some structure always originates from the structure itself. The structure of natural numbers $\mathbb{N}$ is:
- A constant $0$,
- A unary operation $S$,
- For each set $A$, a recursion operator $\mathsf{rec}_A : A \to (\mathbb{N} \to A \to A) \to \mathbb{N} \to A$, subject to equations:
$$\mathsf{rec}_A \; x \; f \; 0 = x$$
and
$$\mathsf{rec}_A \; x \; f \; (S n) = f \; n \; (\mathsf{rec}_A \; x \; f \; n).$$
So whatever your coding of natural numbers is, it has to have $0$, $S$ and $\mathsf{rec}$ (only one will do in the untyped $\lambda$-calculus as there are no types to worry about) such that the above equations are satisfied for all suitable $x$, $f$ and $n$.
You can ask yourself:
Does your coding allow you write down $0$, $S$ and $\mathsf{rec}$ which satisfy the desired equations?
If it does, then it's a valid coding. There are many codings of natural numbers.
Context
StackExchange Computer Science Q#83157, answer score: 3
Revisions (0)
No revisions yet.