Questions tagged [church-numerals]

Church numerals are an encoding of integers in the lambda calculus

Church numerals are an encoding of natural numbers in the lambda calculus .

In the lambda calculus, the single fundamental object type is functions. The Church encoding of the natural number $n$ is the composition operator: $$c_n = \lambda f. \lambda x. f (\ldots (f \, x) \ldots )$$ where $f$ is applied $n$ times.

The usual arithmetic operations can be encoded as operations on functions, for example: $$ \begin{align} \mathrm{plus} &= \lambda m. \lambda n. \lambda f. \lambda x. m \, f \, (n \, f \, x) && \text{(\(m+n\) maps \(f\) to \(m f\) composed with \(n f\))} \\ \mathrm{mult} &= \lambda m. \lambda n. m \, (n \, f) && \text{(\(m \times n\) composes \((n f)\) \(m\) times)} \\ \end{align} $$

Other data structures can be encoded following similar principles. Church encodings exist for booleans, pairs, etc.

14 questions
10
votes
1 answer

A lambda calculus evaluation involving Church numerals

I understand that a Church numeral $c_n$ looks like $\lambda s. \lambda z. s$ (... n times ...) $s\;z$. This means nothing more than "the function $s$ applied $n$ times to the function $z$". A possible definition of the $\mathtt{times}$ function is…
codd
  • 701
  • 3
  • 14
7
votes
1 answer

How to prove that the Church encoding, forall r. (F r -> r) -> r, gives an initial algebra of the functor F?

The well-known Church encoding of natural numbers can be generalized to use an arbitrary (covariant) functor F. The result is the type, call it C, defined by data C = Cfix { run :: forall r. (F r -> r) -> r } Here and below, for simplicity, we…
5
votes
1 answer

How do I arrive at the multiplication function in lambda calculus?

I'm familiar with how Church numerals are defined in the lambda calculus, i.e. as functions that take two arguments and apply the first argument $n$ times to the second. Then I have the successor and addition functions, both of which I managed to…
Mandelmus100
  • 85
  • 1
  • 7
5
votes
4 answers

Why don't we encode church numerals like this?

I think the following encoding also works. 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…
czheo
  • 177
  • 3
4
votes
1 answer

How can I study the nature of the structure of evaluation of function in lambda calculus?

I am specifically focusing on lambda calculus, following this paper: A Tutorial Introduction to the Lambda Calculus. Suppose we have three functions that represent the natural numbers 0 and 1, and a successor function: $\lambda sz.z = 0$ $\lambda…
CinchBlue
  • 614
  • 4
  • 16
3
votes
2 answers

Is there a systematic way to know when to alpha-transform free variables?

So, using Church numerals, we define $3 = {\lambda} f. {\lambda}x.f(f(f(x)))$, and $4 = {\lambda} f. {\lambda}x.f(f(f(f(x))))$. We can then add with an expression like $3\ g\ (4\ g\ z)$ And this reduces to: $(g (g (g (g (g (g (g\ z)))))))$ ... but…
Ben I.
  • 1,730
  • 14
  • 26
2
votes
1 answer

Is there a hierarchy of computational expressivity that is sensitive to evaluation strategies?

Various computational hierarchies describes the relative expressivity of different classes of languages, machines, or other models of computing, with the classic progression for Automata Theory [0] being: Deterministic Finite Automata (DFA) <…
2
votes
1 answer

Church Numerals represented as a List?

Afternoon All, Perhaps an easy one for many, but am new to Lambda calculus: Is the below list, Ni, a representation of the Church numerals? I think it is but how do I prove it...if not, what is it...? The terms Ni and N'i for each natural number i…
user130129
2
votes
1 answer

Church numerals without functions

This is really a second part to my first question, but I felt that this was different enough from the first part that it merited its own question. So, using Church numerals, we define $3 = {\lambda} f. {\lambda}x.f(f(f(x)))$, and $4 = {\lambda} f.…
Ben I.
  • 1,730
  • 14
  • 26
1
vote
1 answer

Recognizing primitive recursion

I am trying to write a program to recognize if a given lambda calculus expression is primitive recursive. I believe that a general algorithm to do this does not exist, but I am interested in the most general algorithm. This is a subset of the…
1
vote
0 answers

How can I show these two expressions for the the product of Church numerals are equivalent?

Given this implementation of the addition of Churck numerals, plus = λm. λn. λs. λz. m s (n s z) and this first implementation of the product, that builds on top of it, times = λm. λn. m (plus n) c0 exercise 5.2.3 asks to implement times without…
1
vote
1 answer

What's wrong with my beta reduction of pred c_0 on Church numerals?

I'm trying to calculate $\text{pred}\, c_0$, where $\text{pred}$ is the previous church encoded number and $c_0$ is the number $0$ ($\lambda s. \lambda z. z$). The formula for $\text{pred}$ is $\lambda n. \lambda s. \lambda z. n (\lambda g. \lambda…
Clash
  • 123
  • 5
1
vote
2 answers

lambda calculus with church numerals

today I found this term in our exercises: ((^fx.f(f(f x)) ^gy.g(g y )) ^z.z + 1) (0) I am quit unaware how to solve this type of question. I know this is the church numeral 3 , 2 , the identity function +1 and zero. But for my understanding it lacks…
0
votes
1 answer

Can the lambda functions in Church numbers be swapped?

I've learned that one can represent natural numbers with lambda calculus like this: \begin{align*} c_0 &= \lambda s. \lambda z. z\\ c_1 &= \lambda s. \lambda z. s~z\\ c_2 &= \lambda s. \lambda z. s~(s~z)\\ c_3 &= \lambda s. \lambda z.…
Martin Thoma
  • 2,360
  • 1
  • 22
  • 41