Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
pp:2024:l07 [2024/04/11 00:05] tpruteanu ``````````` |
pp:2024:l07 [2024/05/23 12:09] (current) tpruteanu [7.4. Natural Numbers - Church numerals] |
||
---|---|---|---|
Line 78: | Line 78: | ||
**7.1.1. ** For every variable occurence, mention if it's a // free // or a // bounded // occurence: | **7.1.1. ** For every variable occurence, mention if it's a // free // or a // bounded // occurence: | ||
- $ \lambda y.(\lambda x.x \ (x \ y)) $ | - $ \lambda y.(\lambda x.x \ (x \ y)) $ | ||
- | - $ \lambda x.((x \ \lambda y.((x \ y) \ z)) \ (x \ \lambda y.x)) $ | + | - $ (\lambda x.(x \ \lambda y.((x \ y) \ z)) \ (x \ \lambda y.x)) $ |
- $ \lambda f.(\lambda x.f \ (x \ x)) \ (\lambda x.f \ (x \ x)) $ | - $ \lambda f.(\lambda x.f \ (x \ x)) \ (\lambda x.f \ (x \ x)) $ | ||
Line 90: | Line 90: | ||
| $ \lambda x.e $ | $ \lambda x.e $ | | | | $ \lambda x.e $ | $ \lambda x.e $ | | | ||
| $ \lambda y.e $ | $ \lambda y.e[x \ / \ e_2] $ | $ x \neq y $, $ y $ does not appear // free // in $ e_2 $| | | $ \lambda y.e $ | $ \lambda y.e[x \ / \ e_2] $ | $ x \neq y $, $ y $ does not appear // free // in $ e_2 $| | ||
- | | $ \lambda y.e $ | $ \{\lambda z.e[y \ / \ z]\}[x \ / \ e_2] $ | $ x \neq y $, appears // free // in $ e_2 $| ( $ z $ is a new variable that is not free in $ e $ or $ e_2 $ ) | | + | | $ \lambda y.e $ | $ \{\lambda z.e[y \ / \ z]\}[x \ / \ e_2] $ | $ x \neq y $, $ y $ appears // free // in $ e_2 $| ( $ z $ is a new variable that is not free in $ e $ or $ e_2 $ ) | |
==== Evaluation order ==== | ==== Evaluation order ==== | ||
Line 208: | Line 208: | ||
\\ | \\ | ||
To make this function be able to be iterated multiple times (on itself), we make the input another pair, where the second value is the 'real' input: \\ | To make this function be able to be iterated multiple times (on itself), we make the input another pair, where the second value is the 'real' input: \\ | ||
- | $ \phi = \lambda p.PAIR \ (SECOND \ p) \ (SUCC \ (SECOND \ p)) $ \\ | + | $ \phi = \lambda p.((PAIR \ (SECOND \ p)) \ (SUCC \ (SECOND \ p))) $ \\ |
\\ | \\ | ||
This takes a pair ( $ n $, $ (SUCC \ n) $) and returns another pair ($ (SUCC \ n) $, $ (SUCC \ (SUCC \ n)) $ | This takes a pair ( $ n $, $ (SUCC \ n) $) and returns another pair ($ (SUCC \ n) $, $ (SUCC \ (SUCC \ n)) $ | ||
\\ | \\ | ||
Now we can just iterate this **n** times starting with $ N0 $, and we get a pair ($ n - 1 $, $ n $), where the first value is our predecesor: \\ | Now we can just iterate this **n** times starting with $ N0 $, and we get a pair ($ n - 1 $, $ n $), where the first value is our predecesor: \\ | ||
- | $ PRED = \lambda n.(FIRST \ (n \ (\phi \ (PAIR \ N0 \ N0)))) $ \\ | + | $ PRED = \lambda n.(FIRST \ ((n \ \phi) \ (PAIR \ N0 \ N0))) $ \\ |
\\ | \\ | ||
An alternative solution, that uses a value container is the following (unfortunately, we will not explain this in further detail here): \\ | An alternative solution, that uses a value container is the following (unfortunately, we will not explain this in further detail here): \\ | ||
- | $ PRED = \lambda n.\lambda f.\lambda x.(((n \ (\lambda g.\lambda h.h \ (g \ f))) \ (\lambda u.x)) \ (\lambda v.v)) $ \\ | + | $ PRED = \lambda n.\lambda f.\lambda x.(((n \ (\lambda g.\lambda h.(h \ (g \ f)))) \ \lambda u.x) \ \lambda v.v) $ \\ |
\\ | \\ | ||
</hidden> | </hidden> |