Recap
- Term :
- convertible:
- convertible: substitution
- theory
- Fixed-point conbinator: combinator, …
Programming in calculus
There are no loops, no classes, no objects — only functions. And yet, from this minimalism, entire worlds of computation unfold.
reduction
The key idea is substitution implement the computation.
Example
Normal Form
- is in normal form if there is no term s.t.
- has a normal form or is normalizable if there is a term in normal form s.t.
- is strongly normalizable if there does not exist an infinite sequence s.t.
Example
- is in normal form.
- has a normal form and is strongly normalizable.
- is not normalizable, because when trying reduce it, it reduces to itself!
- is normalizable but not strongly normalizable:
- if we reduce first, it reduces into , which is in normal form
- but as mentioned above, if we try to reduce , it reduces to itself.
Theorem
Leftmost reduction always finds the normal form if it exists.
- The proof is complicated
Church-Rosser Property
Is it possible that a term has two different normal form?
Definition
- Relation has diamond property if implies for some
- Relation is Church-Rosser if has diamond property
- Relation has unique normal form if implies if are in normal form.
Lemma 1
If is CR, then it has unique normal form property.
Proof is easy. if there are two normal forms of , then there must exists a term , , which is impossible because a term in normal form cannot reduce anymore.
Lemma 2
If is diamond, then is diamond.
Can be proved by a diagram:
Obviously, any two terms reduced by the original one can reduce into the same term, which is equivalent to the statement.
Lemma 3
If is CR and is its refl, sym and trans closure, then iff for some .
is trivial.
For the other direction, we illustrate it with a diagram:
implies that and are linked by some kind of route in the diagram, and because has the diamond property, we can always find a ,
Corollary
If is CR, are normal forms for and , then .
Now if reduction is CR, then we can say rule does not follow from :
Terms and are not convertible as they are normal forms but not convertible.
Church-Rosser for reduction
Theorem
A fundamental result is that reduction has CR property.
- is the transitive closure of
Then we prove has diamond property, which means that if , then for some .
Proof
Case 1. is by (refl), then . Take , then
Case 2. and are by (app).
Case 3. is by (app) and is by ().
Case 4. both use (abs).
Case 5. Both use ().
Here I omit the detailed proof…
calc as a Programming Language
Boolean
true and false:
Then define
We can simply verify it.
Then define (if then else)
Interestingly, can always be omited.
Natual Numbers
define successor
Then we can define add and multiply.
Currying
In calc, a function with multiple arguments can take fewer arguments, transforming into another function, while in traditional calc can not.
In the example of , we use the idea of currying.
General Function
A term represents a function iff
We can define :
The difference is that ignore the input of , avoiding turn into .
A more complicated example: