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 07:55] tpruteanu [7.4. Natural Numbers - Church numerals] |
pp:2024:l07 [2024/05/23 12:09] (current) tpruteanu [7.4. Natural Numbers - Church numerals] |
||
---|---|---|---|
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> |