(Notes)
2021/04/03 – 2021/04/10
Here’s my definitions:
inductive N where
: N
Z : N -> N
S : {R : U} -> R -> (R -> R) -> N -> R
rec \n m, rec n S m
add := \n m, rec Z (add n) m mul :=
Now for some laws:
: rec z s Z = z
recZ : rec z s (S n) = s (rec z s n)
recS : rec a (\b, b) n = a
triv : rec Z S n = n
extn : rec (f a) (\b, f (g b)) n = f (rec a (\b, g (f b)) n)
extr
: add n Z = n
addZ
from recZ: add n (S m) = S (add n m)
addS
from recS: add Z m = m
Zadd
from extn: add (S n) m = m
Sadd
from extr: mul n Z = Z
mulZ
from recZ: mul n (S Z) = n
mulSZ
from indS, addZ: mul Z m = Z
Zmul
from Zadd, triv: mul (S Z) m = m
SZmul from Sadd, Zadd, extn
recZ
and recS
are the standard computation rules, of course. triv
and extn
are kind of obvious lemmas and it turns out they let us compute Z
on the “wrong” side of add
and mul
. extr
is a little tricky, but the idea is if every case ends in the same thing, we should be able to pull it out, extract it through the cases, and in particular we pull the successor through addition. (It makes sense to restrict f
to be a series of constructors, to avoid issues of higher-order unification, of course.)
However we get stuck here: mul (S (S Z)) m = rec Z (add (S (S Z))) m = rec Z (\r, S (S r)) m
but mul n (S (S Z)) = rec Z (add n) (S (S Z)) = add n (add n Z) = add n n = rec n S n
. We don’t get a general mulS
or Smul
lemma.
I have some vague notion that maybe we can split the recursor rec a (\b, f (f b)) m = rec (rec a f m) f m
. But this still only handles 2, and we need to generalize to any n. A full theory here would basically capture the relationship of natural-number powers of endofunctions.
A lot of these things can be generalized to arbitrary inductive types.
Not sure of the behavior of these rules as an actual rewrite system …
Anyways, still doesn’t get judgmental commutativity, but we can get the next best thing (at least for addition): constructors compute on both sides.
= rec id (f .)
pow f
tension between structure and concrete knowledge
extr(f a) (f . g) n = f (rec a (g . f) n)
rec = f a
Z: refl: f a (f.g): f (g (rec (f a) (f . g) n)) = f (g (f (rec a (g . f) n))
S: cong
pow2(rec a f n) f n = rec a (f . f) n
rec = a
Z: refl: a (f.f) . extr: f (rec (f (rec a f n)) f n) = f (f (rec (rec a f n) f n)) = f (f (rec a (f . f) n))
S: cong
(rec a f n) (\b. rec b f m) l = rec a f (add n (mul m l))???
rec
(rec a f n) (pow f m) n = rec a (pow f m . f) n
rec = a
Z: refl: a
S:(rec a f (S n)) id (S n) = rec a f (S n)
Z: refl: rec (f . rec id (f .) m) (rec (f (rec a f n)) (f . rec id (f .) m) n) = ... = (f . rec id (f .) m . f) (rec a (f . rec id (f .) m . f) n)
S:
(pow f m) n = pow f (mul m n) a
rec a
(rec a (\b. rec b f x) m) (\b. rec b f y) n) = rec a f (x*m + y*n) rec
. pow f m = pow f (n + m)
pow f n (g .) n a = rec (f a) g n
rec f
= S (n + m) = n + S m
S n + m
\n m, rec n S m
add := \n m, rec Z (add n) m
mul :=
(S n) * m
(add (S n)) m
rec Z (S . add n) m
rec Z (\r, S (rec n S r)) m
rec Z (rec Z (add n) m)
?? add m (n * m)
m +
(S n)
m * (add m) (S n)
rec Z (rec Z (add m) n)
add m (m * n)
m +
(a + b) * x
(add (a + b)) x
rec Z (rec (a + b) S) x
rec Z (rec (rec a S b) S) x
rec Z
(x + y)
a * (add a) (x + y)
rec Z (rec a S) (rec x S y) rec A