home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.scheme
- Path: sparky!uunet!caen!news.cs.indiana.edu!mayer@moose.cs.indiana.edu
- From: Mayer Goldberg <mayer@moose.cs.indiana.edu>
- Subject: church numerals ...
- Message-ID: <1992Aug12.201701.18392@news.cs.indiana.edu>
- Organization: Computer Science, Indiana University
- Date: Wed, 12 Aug 1992 20:16:55 -0500
- Lines: 91
-
- Here are my 2 cents worth of church numeral stuff:
-
- It would really be neat if we had a successor and a zero. If we did,
- we could say the following (in either LC or Scheme):
-
- Let z be our zero combinator; let s be our successor combinator:
-
- zero == z
- one == (s z)
- two == (s (s z))
- etc.
-
- But unfortunately we con't have s and z in any obvious way, and so we
- abstract over the two, defining our numerals as follows:
-
- zero == \sz.z
- one == \sz.(s z) == \x.x
- two == \sz.(s (s z))
-
- etc.
-
- We want a successor.
- If we had a successor "add1" combinator, we could have: (add1 five) -> six.
- and in general (add1 'n') -> 'n+1', where 'n' is our church numeral
- representation for n, and 'n+1' is our church numeral rep for n+1,
- both quasi-quoted. If we had s and z, all we'd need is one more
- application of s:
-
- (s ('n' s z)) or the less obvious:
- ('n' s (s z))
-
- where 'n' is the rep for our n'th church numeral.
- But we don't have s and z and so we abstract them out, getting:
-
- 'n+1' == \sz.(s ('n' s z)) or the less obvious:
- 'n+1' == \sz.('n' s (s z))
-
- By abstracting over 'n' we can define add1 as follows:
-
- add1_version1 == \nsn.(s (n s z)) or the less obvious:
- add1_version2 == \nsz.(n s (s z)).
-
- We'll use version1 here because it's the easiest to prove things
- about.
-
- A church numeral is an abstraction over the n'th composition of a
- function, hence for some function f: ('n' f) -> f^n
- (right-associated).
-
- This means that for example (three add1) is just:
- \x.(add1 (add1 (add1 x)))
- So so we clearly have:
- ('n' add1 'm') -> 'n+m'.
- Remeber that in LC and CL we auto-left-associate, and so (a b c)
- is really ((a b) c) ... side note ...
-
- So we get addition by abstracting over 'n' and 'm':
- add == \nm.(n add1 m)
- where add1 is just a placeholder for the text of the add1 combinator,
- and a simple substitution can take place, yielding a formal mess.
-
- (add five) is the procedure which adds 5 to anything ...
- (four (add five)) is thus: \x.(add5 (add5 (add5 (add5 x)))). If
- we apply it to zero we get twenty. In general:
- ('n' (add 'm') zero) -> 'n*m'
- so we abstract over 'n' and 'm' getting:
- mul == \nm.(n (add m) zero)
-
- (mul three) is the procedure which multiplies something by three ...
- (two (mul three)) is thus: \x.(mul3 (mul3 x)). If we apply this to one
- we get 3^2 -> 9. In general:
- ('m' (mul 'n')) -> 'n^m'
- We abstract over 'n' and 'm' and thus get exponentiation:
- exp == \nm.(m (mul n) one)
-
- This can go on all the way to ackerman and above. Ackermann is gotten
- through exponentiating the lambda expression taking the
- super-n-exponent and returning the super-n+1-exponent and applying it
- to exponentiation ... :)
-
- Another interesting point is that exponentiation on church numerals is
- just \nm.(m n) or if you are willing to cope with a change of order in
- the arguments, it's just the identity \x.x. This is so because composition
- and exponentiation are governed by a similar algebraic structure.
-
- Church numerals are a lot of fun!
-
- Mayer.
-
-
-
-