One and zero as readings. The identity reads a thing as itself, \(\mathrm {id}=\lambda x.\,x\) with \(\mathrm {id}\,a=a\). As readings of a rule \(f\) at a place \(x\), one and zero are
\(1\neq 0\). Suppose \(1=0\). Take any \(a,b\) and give both sides the constant rule \(\lambda y.\,b\) and the place \(a\):
Truth values from sameness. The same distinction appears as truth values. Let \(1:=(a=a)\), with witness \(\mathrm {refl}\), and let \(0\) be its negation, which has no witness. Then \(1\neq 0\): if they were equal, \(\mathrm {refl}\) would be a witness of \(0\). Asking whether two values are the same gives
operation | meaning | values |
\(\neg v:=(v=0)\) | negation | \(\neg 1=(1=0)=0\), \(\neg 0=(0=0)=1\) |
\(v+w:=\neg (v=w)\) | the two differ | \(1+1=0\), \(1+0=1\), \(0+0=0\) |
\(v\cdot w:=\bigl ((v,w)=(1,1)\bigr )\) | both are \(1\) | \(1\cdot 1=1\); otherwise \(0\) |
|
Two laws follow at once. Negation undoes itself, \(\neg \neg 1=\neg 0=1\) and \(\neg \neg 0=\neg 1=0\), so \(\neg \neg v=v\). Every value added to itself is zero,
One statement, \(a=a\), and one operation, taking the adjoint of a structural map, give composition, the adjunction with its unit and counit, \(0\) and \(1\), addition and multiplication with all their laws, \(\beta \) and \(\eta \), the quantifiers, equality, every rule of inference, the natural numbers, induction and recursion. Each item appears once and uses only the items before it.
CA1 (the two values). \(a=a\) has a witness, \(\mathrm {refl}\); its value is \(1\). Its negation has no witness; its value is \(0\). \(1\neq 0\), or else \(a=a\) would be refuted. Reading "the two differ" as \(v+w=\neg (v=w)\),
CA2 (three ways to use a place). The \(a\) of \(a=a\) can be used no times, once, or twice:
| uses | map | name |
| \(0\) | \(!:A\to 1\) | discard |
| \(1\) | \(\mathrm {id}:A\to A\) | keep |
| \(2\) | \(\Delta :A\to A\times A\) | copy |
Exchanging the two places is \(\sigma \), with \(\sigma \Delta =\Delta \) and \(\sigma \sigma =\mathrm {id}\).
CA3 (composition is the joining of equations). From \(p:a=b\) and \(q:b=c\) comes \(p\cdot q:a=c\). A statement about every equation out of \(a\) holds once it holds at \(\mathrm {refl}\) (reading at the identity). With \(\mathrm {refl}\cdot q=q\), each law is one line at \(\mathrm {refl}\):
| law | at \(\mathrm {refl}\) |
| \(p\cdot \mathrm {refl}=p\), \(\mathrm {refl}\cdot p=p\) | \(\mathrm {refl}\cdot \mathrm {refl}=\mathrm {refl}\) |
| \((p\cdot q)\cdot r=p\cdot (q\cdot r)\) | both sides are \(q\cdot r\) |
| \(p\cdot p^{-1}=\mathrm {refl}\) | \(\mathrm {refl}\cdot \mathrm {refl}^{-1}=\mathrm {refl}\) |
Composition and its laws are not laid down; they are \(a=a\), read.
CA4. Let \(L\) and \(R\) be two directions with a natural correspondence \(\varphi :\mathrm {Hom}(LX,Y)\cong \mathrm {Hom}(X,RY)\). Reading it at the two identities gives
CA5. In each row the adjoint exists because the kind in the third column is exhibited.
| adjoint | its elements | unit | counit |
1 | \(1\), right of \(!\) | one element \(*\), the witness \(\mathrm {refl}\) | \(!_A:A\to 1\) | — |
\(1'\) | \(0\), left of \(!\) | none: the witnesses of \(0=1\) | — | \(0\to A\) |
2 | \(\times \), right of \(\Delta \) | pairs \((a,b)\) | \(\Delta \) | \((\pi _1,\pi _2)\) |
\(2'\) | \(\sqcup \), left of \(\Delta \) | elements marked with their place | \((\mathrm {in}_1,\mathrm {in}_2)\) | \([\mathrm {id},\mathrm {id}]:\) |
3 | \((-)^A\), right of \(-\times A\) | things with one open place | \(c\mapsto \lambda a.(c,a)\) | \(\mathrm {ev}\) |
4 | \(\forall \), right of reading along \(\pi \) | “\(1\) at every \(a\)” | \(q\leq \forall \pi ^*q\) | \(\pi ^*\forall p\leq p\) |
\(4'\) | \(\exists \), left of the same | “\(1\) at some \(a\)” | \(p\leq \pi ^*\exists p\) | \(\exists \pi ^*q\leq q\) |
5 | \(=\), left of reading along \(\Delta \) | \(\exists _\Delta \top \) | \(\mathrm {refl}\) | substitution |
|
CA6 (\(\beta \) and \(\eta \)). They are the two triangles of row 3 (CA4):
CA7 (the source returns). In row 5 the unit is \(\mathrm {refl}\): the witness of \(a=a\) is the unit of the adjunction to the diagonal. The first line of the section is the last row of its table.
CA8. Since an adjoint is unique (CA4), two kinds are the same once they represent the same thing.
| law | computation |
| \(a+b=b+a\) | \(\mathrm {Hom}(A\sqcup B,X)\cong \mathrm {Hom}(A,X)\times \mathrm {Hom}(B,X)\overset {\sigma }{\cong }\mathrm {Hom}(B,X)\times \mathrm {Hom}(A,X)\) |
| \((a+b)+c=a+(b+c)\) | both represent three maps |
| \(a+0=a\) | \(\mathrm {Hom}(A,X)\times \mathrm {Hom}(0,X)=\mathrm {Hom}(A,X)\times 1\) |
| \(ab=ba\) | \(\sigma \) |
| \((ab)c=a(bc)\), \(a\cdot 1=a\) | the same on the side of pairs |
| \(a(b+c)=ab+ac\) | \(\mathrm {Hom}(A\times (B\sqcup C),X)\cong \mathrm {Hom}(B\sqcup C,X^A)\cong \mathrm {Hom}(B,X^A)\times \mathrm {Hom}(C,X^A)\cong \mathrm {Hom}(A\times B\sqcup A\times C,X)\) |
| \(a\cdot 0=0\) | \(\mathrm {Hom}(A\times 0,X)\cong \mathrm {Hom}(0,X^A)=1\) |
| \(x^{a+b}=x^ax^b\) | \(\mathrm {Hom}(C,X^{A\sqcup B})\cong \mathrm {Hom}(C\times A,X)\times \mathrm {Hom}(C\times B,X)\) |
| \((x^a)^b=x^{ab}\), \(x^1=x\), \(x^0=1\) | the same |
Exchange and distribution need no induction. Distribution is the statement that a left adjoint keeps sums.
CA9 (logic is the arithmetic of kinds with at most one element). For a part \(p\) of \(1\), \(p\times p=p\): this is \(x^2=x\). On such parts the same adjoints read as
| arithmetic | logic |
| \(0\), \(1\) | false, true |
| \(+\) | or |
| \(\cdot \) | and |
| \(q^p\) | if \(p\) then \(q\) |
| \(p^p=1\) | \(p\Rightarrow p\), that is \(a=a\) |
When the values are the two of \(\mathbf 2=1\sqcup 1\) (CA1), \(\neg \) is their swap and \(\neg \neg =\mathrm {id}\).
CA10. Every rule is a unit, a counit, or a transposition of CA5.
| rule | is |
| identity \(A\vdash A\); cut | \(\mathrm {id}\); composition (CA3) |
| weakening, contraction, exchange | \(!\), \(\Delta \), \(\sigma \) (CA2) |
| \(\top \) introduction; \(\bot \) elimination | unit of \(1\); counit of \(0\) |
| \(\wedge \) introduction; two eliminations | pairing; \(\pi _1,\pi _2\) |
| two \(\vee \) introductions; elimination | \(\mathrm {in}_1,\mathrm {in}_2\); cases |
| \(\Rightarrow \) introduction; elimination | \(\Lambda \); \(\mathrm {ev}\) |
| \(\neg \) introduction; elimination | the same, for \(p\Rightarrow 0\) |
| \(\forall \) introduction; elimination | transposition; counit (instantiate) |
| \(\exists \) introduction; elimination | unit (give a witness); transposition |
| \(=\) introduction; elimination | \(\mathrm {refl}\); substitution |
| \(\neg \neg p\vdash p\) | \(\neg \neg =\mathrm {id}\) on \(\mathbf 2\) (CA9) |
CA11 (kinds are subjects of \(a=a\)). \(A=A\) holds for a kind \(A\), so kinds can stand in the places of "\(=\)". Hence there is a kind \(U\) whose elements are (names of) kinds. This is the source applied to its own subjects.
CA12 (the whole is one level up). For any \(e:A\to \mathbf 2^A\) put \(d(a)=\neg \,e(a)(a)\): copy with \(\Delta \), read, reverse with \(\neg \). If \(d=e(a_0)\) then \(d(a_0)=\neg d(a_0)\), impossible since \(1\neq 0\). So no kind reaches all of its own parts, there is no largest kind, and \(U\) is not one of its own elements.
CA13 (\(\mathbb N\)). Put \(s=1\sqcup -\), "one more". Let \(\mathbb N\) be the least part of \(U\) that contains \(0\) and is closed under \(s\):
CA14 (induction). It is the counit of \(\forall \): if \(P\) contains \(0\) and is closed under \(s\), then \(\mathbb N\subseteq P\).
CA15 (\(\mathbb N\cong 1\sqcup \mathbb N\)). The map \([0,s]:1\sqcup \mathbb N\to \mathbb N\) has an inverse \(h\): leastness gives \(h\), and \([0,s]\circ h\) is a map of \(\mathbb N\) to itself keeping \(0\) and \(s\), hence \(\mathrm {id}\) by CA14. Two facts follow:
| fact | reason |
| \(0\neq sn\) | the two sides of a sum do not meet (\(1\neq 0\)) |
| \(sm=sn\Rightarrow m=n\) | \(h\) gives \(\mathrm {pred}\) with \(\mathrm {pred}\circ s=\mathrm {id}\); a map with a left inverse is injective |
CA16 (one more is one more \(a=a\)). \(1\) is the witness of \(a=a\) (CA5, row 1), so
| number | is |
| \(0\) | \(a=a\) placed no times: its negation |
| \(1\) | \(a=a\) once |
| \(2\) | \((a=a)+(a=a)\) |
| \(n\) | \(a=a\), \(n\) times |
Reading a pair \((m,k)\) as \(m-k\), with one of each cancelling,
Induction climbs by the first line, recursion descends by the second.
CA17 (recursion). Given \(a\) in \(X\) and \(g:X\to X\), let \(R\) be the least relation containing \((0,a)\) and closed under \((n,x)\mapsto (sn,gx)\). By CA14 and CA15, \(R\) is the graph of a map \(h\), the only one with
CA18 (counting; the Peano axioms are theorems). Each finite kind has one number, so the \(+\) and \(\cdot \) of CA8 are the operations of \(\mathbb N\). With \(sb=b+1\),
Once \(\beta \) and \(\eta \) are in hand (CA6), everything above can be reached a second time using nothing else: opening a place, \(\lambda x.\,t\), and filling it, \(t\,a\).
CA19 (identity and composition). \(\mathrm {id}=\lambda x.\,x\), and \(f\circ g=\lambda x.\,f(g\,x)\).
| law | computation | uses |
| \(f\circ \mathrm {id}=f\) | \(\lambda x.\,f(\mathrm {id}\,x)=\lambda x.\,f\,x=f\) | \(\beta \), \(\eta \) |
| \(\mathrm {id}\circ f=f\) | \(\lambda x.\,\mathrm {id}(f\,x)=\lambda x.\,f\,x=f\) | \(\beta \), \(\eta \) |
| \((h\circ g)\circ f=h\circ (g\circ f)\) | both are \(\lambda x.\,h(g(f\,x))\) | \(\beta \) |
CA20 (numbers count the uses of a place).
| uses of \(f\) | term | structural map |
| none | \(0=\lambda f.\lambda x.\,x\) | discard |
| one | \(1=\lambda f.\lambda x.\,f\,x=\mathrm {id}\) (by \(\eta \)) | keep |
| two | \(2=\lambda f.\,f\circ f\) | copy, then compose |
| one more | \(s\,n=\lambda f.\,f\circ (n\,f)\) | one more copy |
\(1\)is \(\mathrm {id}\), as in CA16. \(1\neq 0\): for any \(a,b\), \(0\,(\lambda y.b)\,a=a\) and \(1\,(\lambda y.b)\,a=b\), so \(0=1\) would make everything equal.
CA21 (the operations are composition at three levels).
| operation | term | computed |
| \(m+n\) | \(\lambda f.\,m(f)\circ n(f)\) | \(2+2=\lambda f.\,(f\circ f)\circ (f\circ f)=4\) |
| \(m\cdot n\) | \(m\circ n\) | \(2\cdot 3=\lambda f.\,(3f)\circ (3f)=6\) |
| \(m^n\) | \(n\,m\) | \(2^3=2\circ 2\circ 2=8\) |
| law | computation |
| \(a+0=a\) | \(a(f)\circ \mathrm {id}=a(f)\) |
| \(a\cdot 1=a\) | \(a\circ \mathrm {id}=a\) |
| \(a\cdot 0=0\) | \(a(\mathrm {id})=\mathrm {id}\circ \cdots \circ \mathrm {id}=\mathrm {id}\), so \(\lambda f.\,\mathrm {id}=0\) |
| \(\mathrm {id}^{\mathrm {id}}=\mathrm {id}\) | \(\mathrm {id}\,\mathrm {id}=\mathrm {id}\) |
The unit laws of arithmetic are the unit laws of \(\mathrm {id}\) (CA19). Reading a numeral at \(s\) and \(0\) gives the number of CA13: \(n(s)(0)=n\). Exchange and distribution for numerals follow from CA14.
CA22 (pairs, the copy, the swap). \(\langle a,b\rangle =\lambda s.\,s\,a\,b\), \(\pi _1p=p\,(\lambda xy.x)\), \(\pi _2p=p\,(\lambda xy.y)\).
CA23 (recursion without end is the diagonal). Filling a thing into itself is \(\omega =\mathrm {ev}\circ \Delta =\lambda x.\,x\,x\), and
| items | result | from |
| CA1–CA3 | values; \(!,\mathrm {id},\Delta ,\sigma \); composition | \(a=a\) |
| CA4 | unit, counit, triangles; uniqueness of adjoints | reading at \(\mathrm {id}\) |
| CA5–CA7 | \(0,1,\times ,\sqcup ,(-)^A,\forall ,\exists ,=\); \(\beta ,\eta \) | adjoints of \(!\), \(\Delta \), \(\pi \) |
| CA8–CA10 | every law; logic; every rule | uniqueness of adjoints |
| CA11–CA12 | \(U\), one level up | \(a=a\) said of kinds; \(\Delta \) and \(\neg \) |
| CA13–CA18 | \(\mathbb N\); induction; \(\mathrm {pred}\circ s=\mathrm {id}\); recursion; Peano | \(\forall \), leastness |
| CA19–CA23 | the same from \(\beta \), \(\eta \) alone; unending recursion | CA6 |
One step is not a computation: CA11, where \(a=a\) is said of the kinds themselves. It is the only place where the infinite enters. A world of finite kinds alone satisfies CA1–CA10 and has no \(\mathbb N\).
The cascade CA1–CA22 was checked in Lean 4 (Figure 278, Listing 386); every statement is accepted with no messages, and most are closed by rfl, that is, by computation alone. CA23 is not checked: the term there does not terminate, and Lean accepts only terminating terms, so it is left out of the file by design.
Nothing new is introduced here. The swap is derived from the pair (CA5), and each of the six objects below is a pair read with the swap.
CA24. The swap is derived. By CA5 a map \(C\to A\times B\) is the same thing as a pair of maps \((C\to A,\;C\to B)\); the identity of \(A\times B\) corresponds to the two readings \((\pi _1,\pi _2)\). The same two readings listed in the other order, \((\pi _2,\pi _1)\), are a pair of maps \((A\times B\to B,\;A\times B\to A)\), so they correspond to exactly one map
so \(\sigma \sigma \) has the readings of the identity, and a map into a pair is fixed by its readings: \(\sigma \sigma =\mathrm {id}\). In the same way \(\pi _1\sigma \Delta =\pi _2\Delta =\mathrm {id}\) and \(\pi _2\sigma \Delta =\mathrm {id}\), so \(\sigma \Delta =\Delta \): on a copy the swap does nothing. And \(\sigma \,(f\times g)=(g\times f)\,\sigma \).
CA25. Rows. A row of length \(n\) is a choice of one of the two values of CA1 at each of \(n\) places, that is, a map \(n\to 2\), an element of \(2^{n}\). By the laws of CA8,
CA26. Coefficients. Write \(\binom {n}{k}\) for the number of rows of length \(n\) with \(k\) ones. By distributivity (CA8), \(2^{n}\times 2=2^{n}\times (1\sqcup 1)\cong 2^{n}\sqcup 2^{n}\): a row of length \(n+1\) ends in \(0\) or ends in \(1\). A row with \(k+1\) ones is therefore a row of length \(n\) with \(k+1\) ones followed by \(0\), or one with \(k\) ones followed by \(1\):
| \(n\) | \(k=0\) | \(1\) | \(2\) | \(3\) | \(4\) | sum |
| \(0\) | \(1\) | \(1\) | ||||
| \(1\) | \(1\) | \(1\) | \(2\) | |||
| \(2\) | \(1\) | \(2\) | \(1\) | \(4\) | ||
| \(3\) | \(1\) | \(3\) | \(3\) | \(1\) | \(8\) | |
| \(4\) | \(1\) | \(4\) | \(6\) | \(4\) | \(1\) | \(16\) |
The same count gives the formula for a power of a sum. The product \((x+y)^{n}=(x+y)(x+y)\cdots (x+y)\) has \(n\) places; distributing (CA8) chooses \(x\) or \(y\) at each place, which is a row; by commutativity the term of a row with \(k\) ones is \(x^{k}y^{\,n-k}\). Therefore
CA27. Integers. Take a pair of numbers \((a,b)\) and read it as “\(a\) with \(b\) taken away”. By CA16 one more on both sides changes nothing, so \((a+1,b+1)\) and \((a,b)\) are the same; repeating this, \((a,b)\) and \((c,d)\) are the same exactly when
CA28. Fractions. Read the same pair with the product in place of the sum. For integers \(a,b\) with \(b\neq 0\), the same factor on both sides changes nothing, \((ac,bc)\sim (a,b)\), so \((a,b)\) and \((c,d)\) are the same exactly when
CA29. Complex numbers. Take a pair of numbers \((x,y)\). The swap alone satisfies \(\sigma \sigma =+1\). Put the sign of CA27 in the second place, \(K(x,y)=(x,-y)\), and then swap:
CA30. Loops. By CA3 equations \(a=a\) are joined, each \(p\) has a reverse \(p^{-1}\), and \(p\,p^{-1}=\mathrm {refl}=p^{-1}p\). Let \(\ell \) be an equation \(a=a\). A word in \(\ell \) and \(\ell ^{-1}\) is read as the pair \((m,n)\): the number of \(\ell \) and the number of \(\ell ^{-1}\). Removing one \(\ell \,\ell ^{-1}\) takes one from both sides, which is the relation of CA27. So the words in one loop, up to this removal, are the integers: joining is addition, the reverse is the swap, and \(\mathrm {refl}\) is \(0\). For example \(\ell \,\ell \,\ell ^{-1}\ell \) is \((3,1)\sim (2,0)\), the integer \(2\). Whether a kind has an \(\ell \) other than \(\mathrm {refl}\) is not decided here; that is the circle.
CA31. One table.
| object | pair | the same when | the swap is |
| integer | \((a,b)\), numbers | \(a+d=c+b\) | the negative |
| fraction | \((a,b)\), integers, \(b\neq 0\) | \(a\,d=c\,b\) | the inverse |
| complex number | \((x,y)\) | equal places | \(J\), with one sign: \(J^{2}=-1\) |
| loop word | \((m,n)\), counts of \(\ell ,\ell ^{-1}\) | \(m+n'=m'+n\) | the reverse |
| row | a map \(n\to 2\) | equal values | (reversal of each value) |
Remark 322.1 (Where pairs come from). Pairs are not introduced at CA24; they are already present earlier in the chain. At CA2, using a place twice is copying, \(\Delta :A\to A\times A\): the two occurrences of \(a\) in \(a=a\) are this copy itself, so the diagonal comes first. At CA5 (row 2), \(\times \) appears as the right adjoint of \(\Delta \). The correspondence is that one map \(C\to A\times B\) is the same as two maps \((C\to A,\ C\to B)\), and the projections \(\pi _1,\pi _2\) are its counit, the image of \(\mathrm {id}\). At CA24 the swap only writes the two readings in the other order, \(\sigma =\langle \pi _2,\pi _1\rangle \). The order is therefore
EV9 (injective means: the kernel is the diagonal). The kernel of \(f\) is \(\{(u,v)\mid f(u)=f(v)\}\). It always contains the diagonal, because \(f(u)=f(u)\). The map \(f\) is injective exactly when its kernel is the diagonal and nothing more. \(\Delta \) itself is injective, since \(\pi _1\Delta =\mathrm {id}\).
| where it is used | the map whose kernel is the diagonal |
| equal elements of a part are equal in \(A\) | the inclusion \(A_p\to A\) |
| \(sm=sn\Rightarrow m=n\) | “one more” (EV12) |
| \(a+c=b+c\Rightarrow a=b\) | “one more”, \(c\) times |
| \(e^{i\theta }=1\Rightarrow \theta \in 2\pi \mathbb Z\) | not injective: the kernel exceeds the diagonal by \(2\pi \mathbb Z\) (EV20) |
EV10 (the same count). \(\{x,y\}\) and \(\{u,v\}\): let \(f(x)=u\), \(f(y)=v\) and \(g(u)=x\), \(g(v)=y\). Then
EV11 (addition is forced: \(2+1\)). Let \(A=\{x,y\mid z\}\) and \(A'=\{u,v\mid w\}\), each with a statement whose parts are shown. Match the parts: \(x\mapsto u\), \(y\mapsto v\), and \(z\mapsto w\). Joined by reading the value (EV7), this is a map \(A\to A'\) with an inverse. So a kind split into parts of counts \(2\) and \(1\) has one count, whatever the kind. That count is \(2+1\).
Exchange. Reading the same \(A\) with \(\neg p\) gives \(\{z\mid x,y\}\), that is \(1+2\). The kind is the same: \(2+1=1+2\).
Grouping. On \(\{x,y,z\}\) take \(p\) with parts \(\{x\mid y,z\}\) and \(q\) with parts \(\{x,y\mid z\}\). The pieces are \(\{x\},\{y\},\{z\}\). Reading \(q\) first gives \((1+1)+1\); reading \(p\) first gives \(1+(1+1)\). The kind is the same.
EV12 (numbers, and \(2+2=4\)). Let \(sX\) be a kind with a statement whose one part is \(X\) and whose other part has one element. Put \(1=s0\), \(2=s1\), \(3=s2\), \(4=s3\). One more element in the second part is one more in the whole, so \(a+sb=s(a+b)\), and
EV13 (multiplication: \(2\cdot 3=6\)). The pairs of \(\{x,y\}\) and \(\{1,2,3\}\) are
| law | computed |
| \(ab=ba\) | \(\sigma (x,1)=(1,x)\), with \(\sigma \sigma =\mathrm {id}\) (EV6) |
| \(a\cdot 0=0\) | no element for the second place |
| \(a\cdot 1=a\) | the pairs are \((x,*),(y,*)\) |
EV14 (integers). An integer is a pair \((a,b)\): \(a\) elements with value \(1\) (to add) and \(b\) with value \(0\) (to take away). One of each cancels.
For a product, a pair of elements with values \(v,w\) gets the value \((v=w)\) (EV2): equal values give \(1\), different values give \(0\). Hence
The rule of signs is \((0=0)=1\): the negation applied twice.
EV15 (fractions). A fraction is a pair \((p,q)\) read \(p/q\), with \((p,q)\sim (p',q')\) when \(pq'=p'q\).
EV16 (complex numbers). On pairs of reals put \(J(a,b)=(-b,a)\): the swap, then the sign.
On the circle \(z\bar z=1\) the conjugate is the inverse.
EV17 (the binomial formula is a sum over statements). Expanding \((z+w)^2\) chooses \(z\) or \(w\) at each of the two places: a statement on \(\{1,2\}\), with \(z\) where its value is \(1\) and \(w\) where it is \(0\).
| value at place 1 | value at place 2 | term |
| \(1\) | \(1\) | \(zz\) |
| \(1\) | \(0\) | \(zw\) |
| \(0\) | \(1\) | \(wz\) |
| \(0\) | \(0\) | \(ww\) |
With \(zw=wz\): \((z+w)^2=z^2+2zw+w^2\). For three places there are eight statements, \(1,3,3,1\) by the number of places with value \(1\): \((z+w)^3=z^3+3z^2w+3zw^2+w^3\). In general \((z+w)^n=\sum _jC(n,j)z^jw^{n-j}\), with \(C(n,j)\) the number of statements on \(n\) places having \(j\) values \(1\).
EV18 (the Leibniz rule is the copy). A product of two functions copies the variable, \(\theta \mapsto (\theta ,\theta )\mapsto f(\theta )g(\theta )\). Changing one place at a time,
EV19 (the exponential turns sums into products). Let \(E(a)=1+a+\tfrac {a^2}2+\cdots \). To second order,
EV20 (\(e^{i\theta }\) lies on the circle). With EV16, \(E(i\theta )=(c,s)\), where \(c=1-\tfrac {\theta ^2}2+\cdots \) and \(s=\theta -\tfrac {\theta ^3}6+\cdots \). Then
EV21 (loops are integers). Let \(\ell \) be the loop once around and \(\bar \ell \) its inverse. A word is recorded by (number of \(\ell \), number of \(\bar \ell \)), and \(\ell \bar \ell \) cancels:
The following file was checked with Lean 4 (v4.36.0-rc2, core only); it compiles with no errors and no warnings (Figure 278).
Cascade.lean
/-
The cascade from a = a: a check of CA1-CA22 (core Lean 4, no Mathlib).
Values: true = 1 (a = a has a witness), false = 0 (its negation).
CA23 (recursion without end) is not checked: Lean accepts only terminating terms.
-/
namespace Cascade
variable {A B C X : Type}
/-- two kinds are the same when maps both ways undo each other (the two triangles) -/
structure Iso (α β : Type) where
fwd : α → β
bwd : β → α
left : ∀ a, bwd (fwd a) = a
right : ∀ b, fwd (bwd b) = b
/-! ## CA1: the two values -/
theorem one_ne_zero : true ≠ false := by decide
/-- `a + a = 0`: "the two differ" is false of `a` and `a` -/
theorem add_self (v : Bool) : (v != v) = false := by cases v <;> rfl
/-! ## CA2: three ways to use a place -/
def bang (_ : A) : Unit := () -- no use: discard
def Δ (a : A) : A × A := (a, a) -- two uses: copy
def σ (p : A × B) : B × A := (p.2, p.1) -- exchange of the two places
theorem swap_copy (a : A) : σ (Δ a) = Δ a := rfl
theorem swap_swap (p : A × B) : σ (σ p) = p := rfl
/-! ## CA3: composition is the joining of equations -/
theorem join_refl_right {a b : A} (p : a = b) : p.trans rfl = p := rfl
theorem join_refl_left {a b : A} (p : a = b) : (rfl : a = a).trans p = p := rfl
theorem join_assoc {a b c d : A} (p : a = b) (q : b = c) (r : c = d) :
(p.trans q).trans r = p.trans (q.trans r) := rfl
theorem join_inv {a b : A} (p : a = b) : p.trans p.symm = rfl := rfl
/-! ## CA4, CA6: one adjunction in full -- unit, counit, triangles, beta, eta -/
def curry (t : C × A → B) : C → A → B := fun c a => t (c, a)
def uncurry (h : C → A → B) : C × A → B := fun p => h p.1 p.2
/-- the unit is the image of the identity -/
def unit : C → A → C × A := curry id
/-- the counit is the image of the identity the other way: evaluation -/
def ev : (A → B) × A → B := uncurry id
theorem unit_eq (c : C) (a : A) : unit c a = (c, a) := rfl
theorem ev_eq (h : A → B) (a : A) : ev (h, a) = h a := rfl
/-- the correspondence and its inverse undo each other -/
theorem triangle_one (t : C × A → B) : uncurry (curry t) = t := by
funext ⟨c, a⟩; rfl
theorem triangle_two (h : C → A → B) : curry (uncurry h) = h := rfl
/-- beta: fill the open place, then read -/
theorem beta (t : C × A → B) (c : C) (a : A) : ev (curry t c, a) = t (c, a) := rfl
/-- eta: read, then open the place again -/
theorem eta : (curry ev : (A → B) → A → B) = id := rfl
/-! ## CA5: the other adjoints, each with its universal property -/
-- row 1: one map into Unit
theorem bang_unique (f g : A → Unit) : f = g := funext fun _ => rfl
-- row 1': one map out of Empty
theorem empty_unique (f g : Empty → A) : f = g := funext fun x => nomatch x
-- row 2: pairs
theorem pair_fst (f : C → A) (g : C → B) : (fun c => ((fun c => (f c, g c)) c).1) = f := rfl
theorem pair_snd (f : C → A) (g : C → B) : (fun c => ((fun c => (f c, g c)) c).2) = g := rfl
theorem pair_unique (h : C → A × B) : h = fun c => ((h c).1, (h c).2) := rfl
-- row 2': sums
theorem sum_inl (f : A → X) (g : B → X) : Sum.elim f g ∘ Sum.inl = f := rfl
theorem sum_inr (f : A → X) (g : B → X) : Sum.elim f g ∘ Sum.inr = g := rfl
theorem sum_unique (h : Sum A B → X) : h = Sum.elim (h ∘ Sum.inl) (h ∘ Sum.inr) := by
funext x; cases x <;> rfl
-- row 4: "for all" is right adjoint to reading along the projection
theorem forall_adj (p : C → A → Prop) (q : C → Prop) :
(∀ c a, q c → p c a) ↔ (∀ c, q c → ∀ a, p c a) :=
⟨fun h c hq a => h c a hq, fun h c a hq => h c hq a⟩
/-- its counit: instantiate -/
theorem forall_counit (p : C → A → Prop) (c : C) (a : A) : (∀ a, p c a) → p c a :=
fun h => h a
-- row 4': "exists" is left adjoint to the same
theorem exists_adj (p : C → A → Prop) (q : C → Prop) :
(∀ c a, p c a → q c) ↔ (∀ c, (∃ a, p c a) → q c) :=
⟨fun h c ⟨a, hp⟩ => h c a hp, fun h c a hp => h c ⟨a, hp⟩⟩
/-- its unit: give a witness -/
theorem exists_unit (p : C → A → Prop) (c : C) (a : A) : p c a → ∃ a, p c a :=
fun h => ⟨a, h⟩
-- row 5 (CA7): equality is left adjoint to reading along the diagonal; its unit is refl
theorem eq_adj (R : A → A → Prop) : (∀ a b, a = b → R a b) ↔ (∀ a, R a a) := by
constructor
· intro h a
exact h a a rfl
· intro h a b e
subst e
exact h a
/-! ## CA8: all the laws, with no induction -/
def sumComm : Iso (Sum A B) (Sum B A) where
fwd := fun x => match x with
| .inl a => .inr a
| .inr b => .inl b
bwd := fun x => match x with
| .inl b => .inr b
| .inr a => .inl a
left := by intro x; cases x <;> rfl
right := by intro x; cases x <;> rfl
def sumAssoc : Iso (Sum (Sum A B) C) (Sum A (Sum B C)) where
fwd := fun x => match x with
| .inl (.inl a) => .inl a
| .inl (.inr b) => .inr (.inl b)
| .inr c => .inr (.inr c)
bwd := fun x => match x with
| .inl a => .inl (.inl a)
| .inr (.inl b) => .inl (.inr b)
| .inr (.inr c) => .inr c
left := by
intro x
cases x with
| inl y => cases y <;> rfl
| inr c => rfl
right := by
intro x
cases x with
| inl a => rfl
| inr y => cases y <;> rfl
/-- `a + 0 = a` -/
def sumEmpty : Iso (Sum A Empty) A where
fwd := fun x => match x with
| .inl a => a
| .inr e => nomatch e
bwd := Sum.inl
left := by
intro x
cases x with
| inl a => rfl
| inr e => exact nomatch e
right := fun _ => rfl
def prodComm : Iso (A × B) (B × A) where
fwd := σ
bwd := σ
left := fun _ => rfl
right := fun _ => rfl
def prodAssoc : Iso ((A × B) × C) (A × (B × C)) where
fwd := fun p => (p.1.1, (p.1.2, p.2))
bwd := fun p => ((p.1, p.2.1), p.2.2)
left := fun _ => rfl
right := fun _ => rfl
/-- `a · 1 = a` -/
def prodUnit : Iso (A × Unit) A where
fwd := fun p => p.1
bwd := fun a => (a, ())
left := by intro ⟨a, u⟩; cases u; rfl
right := fun _ => rfl
/-- `a (b + c) = a b + a c` -/
def distrib : Iso (A × Sum B C) (Sum (A × B) (A × C)) where
fwd := fun p => match p.2 with
| .inl b => .inl (p.1, b)
| .inr c => .inr (p.1, c)
bwd := fun x => match x with
| .inl q => (q.1, .inl q.2)
| .inr q => (q.1, .inr q.2)
left := by intro ⟨a, x⟩; cases x <;> rfl
right := by intro x; cases x <;> rfl
/-- `a · 0 = 0` -/
def prodEmpty : Iso (A × Empty) Empty where
fwd := fun p => p.2
bwd := fun e => nomatch e
left := fun p => nomatch p.2
right := fun e => nomatch e
/-- `x^(a+b) = x^a · x^b` -/
def expSum : Iso (Sum A B → X) ((A → X) × (B → X)) where
fwd := fun h => (h ∘ Sum.inl, h ∘ Sum.inr)
bwd := fun p => Sum.elim p.1 p.2
left := by intro h; funext x; cases x <;> rfl
right := fun _ => rfl
/-- `(x^a)^b = x^(a·b)` -/
def expProd : Iso (B → A → X) (A × B → X) where
fwd := fun h p => h p.2 p.1
bwd := fun k b a => k (a, b)
left := fun _ => rfl
right := by intro k; funext ⟨a, b⟩; rfl
/-- `x^1 = x` -/
def expUnit : Iso (Unit → X) X where
fwd := fun h => h ()
bwd := fun x _ => x
left := by intro h; funext u; cases u; rfl
right := fun _ => rfl
/-- `x^0 = 1` -/
def expEmpty : Iso (Empty → X) Unit where
fwd := fun _ => ()
bwd := fun _ e => nomatch e
left := by intro h; funext e; exact nomatch e
right := by intro u; cases u; rfl
/-! ## CA9: on the two values the same operations are logic -/
theorem and_idem (v : Bool) : (v && v) = v := by cases v <;> rfl -- x² = x
theorem not_not' (v : Bool) : (!(!v)) = v := by cases v <;> rfl -- ¬¬ = id
theorem imp_self' (p : Prop) : p → p := id -- p^p has the element id
/-! ## CA11, CA12: kinds are subjects of a = a; the whole is one level up -/
example : Type 1 := Type -- the kind of kinds lives one level up
theorem kind_refl (K : Type) : K = K := rfl
/-- copy, read, reverse: no `e` reaches every part -/
theorem cantor (e : A → A → Bool) : ¬ ∃ a0, e a0 = fun a => !(e a a) := by
intro ⟨a0, h⟩
have h2 : e a0 a0 = !(e a0 a0) := congrFun h a0
cases h' : e a0 a0 <;> simp [h'] at h2
/-! ## CA13-CA15: the numbers, induction, N ≅ 1 + N -/
/-- induction: a part containing 0 and closed under "one more" is everything -/
theorem least (P : Nat → Prop) (h0 : P 0) (hs : ∀ n, P n → P (n + 1)) : ∀ n, P n := by
intro n
induction n with
| zero => exact h0
| succ n ih => exact hs n ih
def lambek : Iso (Sum Unit Nat) Nat where
fwd := fun x => match x with
| .inl _ => 0
| .inr n => n + 1
bwd := fun n => match n with
| 0 => .inl ()
| n + 1 => .inr n
left := by
intro x
cases x with
| inl u => cases u; rfl
| inr n => rfl
right := by intro n; cases n <;> rfl
theorem zero_ne_succ (n : Nat) : 0 ≠ n + 1 := fun h => Nat.noConfusion h
theorem pred_succ : Nat.pred ∘ Nat.succ = id := rfl
theorem succ_inj {m n : Nat} (h : m + 1 = n + 1) : m = n := Nat.succ.inj h
/-! ## CA16: one more is one more a = a -/
abbrev intEq (p q : Nat × Nat) : Prop := p.1 + q.2 = q.1 + p.2
/-- `(n + 1) - 1 = n`, as difference pairs: one of each cancels -/
theorem add_one_sub_one (n : Nat) : intEq (n + 1, 1) (n, 0) := rfl
theorem add_one_sub_one' (n : Nat) : (n + 1) - 1 = n := rfl
/-- one more on both sides: refl goes to refl -/
theorem up {n m : Nat} (h : n = m) : n + 1 = m + 1 := congrArg (· + 1) h
theorem up_refl (n : Nat) : up (rfl : n = n) = rfl := rfl
/-- one fewer on both sides -/
theorem down {n m : Nat} (h : n + 1 = m + 1) : n = m := succ_inj h
/-! ## CA17: recursion is one map out of N -/
def recN (a : X) (g : X → X) : Nat → X
| 0 => a
| n + 1 => g (recN a g n)
theorem recN_zero (a : X) (g : X → X) : recN a g 0 = a := rfl
theorem recN_succ (a : X) (g : X → X) (n : Nat) : recN a g (n + 1) = g (recN a g n) := rfl
/-- and it is the only one -/
theorem recN_unique (a : X) (g : X → X) (h : Nat → X)
(h0 : h 0 = a) (hs : ∀ n, h (n + 1) = g (h n)) : h = recN a g := by
funext n
induction n with
| zero => exact h0
| succ n ih => exact (hs n).trans (congrArg g ih)
/-! ## CA18: the recursion equations are theorems -/
theorem add_succ' (a b : Nat) : a + (b + 1) = (a + b) + 1 := rfl
theorem mul_succ' (a b : Nat) : a * (b + 1) = a * b + a := rfl
theorem add_zero'' (a : Nat) : a + 0 = a := rfl
/-! ## CA19: identity and composition from beta and eta -/
theorem comp_id' (f : A → B) : f ∘ id = f := rfl
theorem id_comp' (f : A → B) : id ∘ f = f := rfl
theorem comp_assoc' (h : C → X) (g : B → C) (f : A → B) : (h ∘ g) ∘ f = h ∘ (g ∘ f) := rfl
/-! ## CA20, CA21: numbers count the uses of a place -/
def Church : Type 1 := (X : Type) → (X → X) → X → X
def czero : Church := fun _ _ x => x -- no use
def cone : Church := fun _ f x => f x -- one use
def csucc (n : Church) : Church := fun X f x => f (n X f x)
def cadd (m n : Church) : Church := fun X f x => m X f (n X f x)
def cmul (m n : Church) : Church := fun X f => m X (n X f)
def toNat (n : Church) : Nat := n Nat Nat.succ 0
def ctwo : Church := csucc cone
def cthree : Church := csucc ctwo
/-- `1` is the identity (by eta) -/
theorem cone_is_id : cone = (fun (X : Type) (f : X → X) => f : Church) := rfl
theorem toNat_succ (n : Church) : toNat (csucc n) = toNat n + 1 := rfl
example : toNat czero = 0 := rfl
example : toNat (cadd ctwo ctwo) = 4 := rfl
example : toNat (cmul ctwo cthree) = 6 := rfl
example : toNat (cmul cthree ctwo) = 6 := rfl
theorem czero_ne_cone : czero ≠ cone := by
intro h
have h2 : toNat czero = toNat cone := congrArg toNat h
exact absurd h2 (by decide)
/-- the unit laws of arithmetic are the unit laws of the identity -/
theorem cadd_zero (a : Church) : cadd a czero = a := rfl
theorem czero_add (a : Church) : cadd czero a = a := rfl
theorem cmul_one (a : Church) : cmul a cone = a := rfl
theorem cone_mul (a : Church) : cmul cone a = a := rfl
theorem cadd_assoc (a b c : Church) : cadd (cadd a b) c = cadd a (cadd b c) := rfl
theorem cmul_assoc (a b c : Church) : cmul (cmul a b) c = cmul a (cmul b c) := rfl
/-- multiplication is composition -/
theorem cmul_is_comp (m n : Church) (X : Type) : cmul m n X = m X ∘ n X := rfl
/-! ## CA22: pairs from an open place -/
def cpair (a b : A) : (A → A → A) → A := fun s => s a b
def cfst (p : (A → A → A) → A) : A := p (fun x _ => x)
def csnd (p : (A → A → A) → A) : A := p (fun _ y => y)
theorem cfst_pair (a b : A) : cfst (cpair a b) = a := rfl
theorem csnd_pair (a b : A) : csnd (cpair a b) = b := rfl
theorem cfst_copy (a : A) : cfst (cpair a a) = a := rfl
end Cascade
CA24–CA30 were checked in Lean 4 in a separate file (Figure 279, Listing 387). The equality of the coefficients with the row counts and the formula for \((x+y)^{n}\) are checked there by computation for \(n=3,4\); the other statements are checked in general.
Swap.lean
/-
From the swap: a check of CA24-CA30 (core Lean 4, no Mathlib).
Rows, coefficients, integers, fractions, complex numbers and loops,
each as a pair read with the swap.
-/
namespace Swap
variable {A B C D : Type}
/-! ## CA24: the swap is the pair of the two readings in the other order -/
def pair (f : C → A) (g : C → B) : C → A × B := fun c => (f c, g c)
def Δ : A → A × A := pair id id -- both readings are id
def σ : A × B → B × A := pair Prod.snd Prod.fst -- the two readings, other order
theorem fst_swap (p : A × B) : (σ p).1 = p.2 := rfl
theorem snd_swap (p : A × B) : (σ p).2 = p.1 := rfl
/-- a map into a pair is fixed by its two readings -/
theorem pair_unique (h : C → A × B) : h = pair (Prod.fst ∘ h) (Prod.snd ∘ h) := rfl
/-- so the swap done twice, having the readings of id, is id -/
theorem swap_swap (p : A × B) : σ (σ p) = p := rfl
theorem swap_copy (a : A) : σ (Δ a) = Δ a := rfl
theorem swap_natural (f : A → C) (g : B → D) (p : A × B) :
σ (f p.1, g p.2) = (g (σ p).1, f (σ p).2) := rfl
/-! ## CA25: rows -/
/-- a row of length n + 1 is a row of length n and one more value -/
def allRows : Nat → List (List Bool)
| 0 => [[]]
| n + 1 => (allRows n).map (false :: ·) ++ (allRows n).map (true :: ·)
def ones : List Bool → Nat
| [] => 0
| b :: r => cond b 1 0 + ones r
theorem allRows_zero : allRows 0 = [[]] := rfl
/-- there are 2^n rows of length n -/
theorem length_allRows (n : Nat) : (allRows n).length = 2 ^ n := by
induction n with
| zero => rfl
| succ n ih =>
show ((allRows n).map (false :: ·) ++ (allRows n).map (true :: ·)).length = 2 ^ (n + 1)
rw [List.length_append, List.length_map, List.length_map, ih, Nat.pow_succ, Nat.mul_two]
/-- reversing every value exchanges ones and zeros -/
theorem ones_neg (r : List Bool) : ones (r.map (!·)) + ones r = r.length := by
induction r with
| nil => rfl
| cons b r ih =>
cases b
· show (1 + ones (r.map (!·))) + (0 + ones r) = r.length + 1
omega
· show (0 + ones (r.map (!·))) + (1 + ones r) = r.length + 1
omega
/-! ## CA26: coefficients -/
def choose : Nat → Nat → Nat
| _, 0 => 1
| 0, _ + 1 => 0
| n + 1, k + 1 => choose n k + choose n (k + 1)
theorem choose_zero (n : Nat) : choose n 0 = 1 := by cases n <;> rfl
theorem choose_succ (n k : Nat) :
choose (n + 1) (k + 1) = choose n k + choose n (k + 1) := rfl
/-- the number of rows of length n with k ones -/
def count (n k : Nat) : Nat := ((allRows n).filter (fun r => ones r == k)).length
example : [count 4 0, count 4 1, count 4 2, count 4 3, count 4 4] = [1, 4, 6, 4, 1] := by
decide
example : [choose 4 0, choose 4 1, choose 4 2, choose 4 3, choose 4 4] = [1, 4, 6, 4, 1] := by
decide
example : choose 4 0 + choose 4 1 + choose 4 2 + choose 4 3 + choose 4 4 = 2 ^ 4 := by
decide
/-- the term of a row: x at each 1, y at each 0 -/
def weight (x y : Nat) : List Bool → Nat
| [] => 1
| b :: r => cond b x y * weight x y r
def total (l : List Nat) : Nat := l.foldr (· + ·) 0
-- (x + y)^n is the sum of the terms of all rows; collected by the number of ones
example : total ((allRows 3).map (weight 2 3)) = (2 + 3) ^ 3 := by decide
example : choose 3 0 * 3 ^ 3 + choose 3 1 * (2 * 3 ^ 2) + choose 3 2 * (2 ^ 2 * 3)
+ choose 3 3 * 2 ^ 3 = (2 + 3) ^ 3 := by decide
/-! ## CA27: integers -- a pair read as a difference; the swap is the negative -/
abbrev intEq (p q : Nat × Nat) : Prop := p.1 + q.2 = q.1 + p.2
def addI (p q : Nat × Nat) : Nat × Nat := (p.1 + q.1, p.2 + q.2)
def mulI (p q : Nat × Nat) : Nat × Nat := (p.1 * q.1 + p.2 * q.2, p.1 * q.2 + p.2 * q.1)
theorem intEq_refl (p : Nat × Nat) : intEq p p := rfl
theorem intEq_symm {p q : Nat × Nat} (h : intEq p q) : intEq q p := Eq.symm h
theorem intEq_trans {p q r : Nat × Nat} (h1 : intEq p q) (h2 : intEq q r) : intEq p r := by
show p.1 + r.2 = r.1 + p.2
have h1' : p.1 + q.2 = q.1 + p.2 := h1
have h2' : q.1 + r.2 = r.1 + q.2 := h2
omega
/-- one more on both sides changes nothing -/
theorem up_both (a b : Nat) : intEq (a + 1, b + 1) (a, b) := by
show a + 1 + b = a + (b + 1)
omega
/-- x + (-x) = 0, the negative being the swap -/
theorem add_neg (a b : Nat) : intEq (addI (a, b) (σ (a, b))) (0, 0) := by
show a + b + 0 = 0 + (b + a)
omega
/-- (-1) x = -x -/
theorem neg_one_mul (a b : Nat) : intEq (mulI (0, 1) (a, b)) (σ (a, b)) := by
show 0 * a + 1 * b + a = b + (0 * b + 1 * a)
omega
example : mulI (0, 1) (0, 1) = (1, 0) := by decide -- (-1)(-1) = 1
example : intEq (mulI (2, 5) (1, 3)) (6, 0) := by decide -- (-3)(-2) = 6
theorem embed_add (m n : Nat) : addI (m, 0) (n, 0) = (m + n, 0) := rfl
/-! ## CA28: fractions -- the same pair read with the product; the swap is the inverse -/
abbrev fracEq (p q : Nat × Nat) : Prop := p.1 * q.2 = q.1 * p.2
def mulF (p q : Nat × Nat) : Nat × Nat := (p.1 * q.1, p.2 * q.2)
def addF (p q : Nat × Nat) : Nat × Nat := (p.1 * q.2 + q.1 * p.2, p.2 * q.2)
/-- the same factor on both sides changes nothing -/
theorem scale_both (a b c : Nat) : fracEq (a * c, b * c) (a, b) := by
show a * c * b = a * (b * c)
rw [Nat.mul_assoc, Nat.mul_comm c b]
/-- x · x⁻¹ = 1, the inverse being the swap -/
theorem mul_inv (a b : Nat) : fracEq (mulF (a, b) (σ (a, b))) (1, 1) := by
show a * b * 1 = 1 * (b * a)
rw [Nat.mul_one, Nat.one_mul, Nat.mul_comm]
example : fracEq (2, 4) (1, 2) := by decide
example : addF (1, 2) (1, 3) = (5, 6) := by decide -- 1/2 + 1/3 = 5/6
example : fracEq (mulF (2, 3) (σ (2, 3))) (1, 1) := by decide
/-! ## CA29: complex numbers -- the swap with one sign -/
def K (p : Int × Int) : Int × Int := (p.1, -p.2) -- the sign in the second place
def J (p : Int × Int) : Int × Int := (-p.2, p.1)
/-- J is the swap after the sign -/
theorem J_eq (p : Int × Int) : J p = σ (K p) := rfl
/-- the swap alone squares to +1; with the sign it squares to -1 -/
theorem J_sq (p : Int × Int) : J (J p) = (-p.1, -p.2) := rfl
theorem J_four (p : Int × Int) : J (J (J (J p))) = p := by
show (- -p.1, - -p.2) = p
rw [Int.neg_neg, Int.neg_neg]
theorem K_K (p : Int × Int) : K (K p) = p := by
show (p.1, - -p.2) = p
rw [Int.neg_neg]
def mulC (p q : Int × Int) : Int × Int := (p.1 * q.1 - p.2 * q.2, p.1 * q.2 + p.2 * q.1)
/-- J is multiplication by (0, 1) -/
theorem J_is_mul (p : Int × Int) : J p = mulC (0, 1) p := by
show (-p.2, p.1) = (0 * p.1 - 1 * p.2, 0 * p.2 + 1 * p.1)
rw [Int.zero_mul, Int.zero_mul, Int.one_mul, Int.one_mul, Int.zero_sub, Int.zero_add]
example : mulC (0, 1) (0, 1) = ((-1, 0) : Int × Int) := by decide -- J² = -1
example : mulC (1, 2) (3, 4) = ((-5, 10) : Int × Int) := by decide
example : mulC (1, 2) (K (1, 2)) = ((5, 0) : Int × Int) := by decide -- z · conj z = x² + y²
example : mulC (3, 4) (1, 2) = mulC (1, 2) (3, 4) := by decide
/-! ## CA30: loops -- words in one loop are the integers -/
/-- a word: `true` is the loop, `false` is the loop reversed -/
def wind : List Bool → Nat × Nat
| [] => (0, 0)
| true :: w => ((wind w).1 + 1, (wind w).2)
| false :: w => ((wind w).1, (wind w).2 + 1)
/-- cancelling a loop against its reverse does not change the integer -/
theorem cancel (w : List Bool) : intEq (wind (true :: false :: w)) (wind w) := by
show (wind w).1 + 1 + (wind w).2 = (wind w).1 + ((wind w).2 + 1)
omega
theorem cancel' (w : List Bool) : intEq (wind (false :: true :: w)) (wind w) := by
show (wind w).1 + 1 + (wind w).2 = (wind w).1 + ((wind w).2 + 1)
omega
/-- joining words is addition -/
theorem wind_append (u v : List Bool) :
(wind (u ++ v)).1 = (wind u).1 + (wind v).1 ∧
(wind (u ++ v)).2 = (wind u).2 + (wind v).2 := by
induction u with
| nil =>
show (wind v).1 = 0 + (wind v).1 ∧ (wind v).2 = 0 + (wind v).2
exact ⟨by omega, by omega⟩
| cons b u ih =>
cases b
· show (wind (u ++ v)).1 = (wind u).1 + (wind v).1 ∧
(wind (u ++ v)).2 + 1 = (wind u).2 + 1 + (wind v).2
exact ⟨by omega, by omega⟩
· show (wind (u ++ v)).1 + 1 = (wind u).1 + 1 + (wind v).1 ∧
(wind (u ++ v)).2 = (wind u).2 + (wind v).2
exact ⟨by omega, by omega⟩
/-- reversing every letter is the swap -/
theorem wind_flip (w : List Bool) : wind (w.map (!·)) = σ (wind w) := by
induction w with
| nil => rfl
| cons b w ih =>
cases b
· show ((wind (w.map (!·))).1 + 1, (wind (w.map (!·))).2) = ((wind w).2 + 1, (wind w).1)
rw [ih]
rfl
· show ((wind (w.map (!·))).1, (wind (w.map (!·))).2 + 1) = ((wind w).2, (wind w).1 + 1)
rw [ih]
rfl
def inv (w : List Bool) : List Bool := (w.map (!·)).reverse
example : wind [true, true, false, true] = (3, 1) := by decide
example : intEq (wind [true, true, false, true]) (2, 0) := by decide -- l l l⁻¹ l is 2
example : wind (inv [true, true, false, true]) = σ (wind [true, true, false, true]) := by
decide
example : intEq (addI (wind [true, false, true]) (wind (inv [true, false, true]))) (0, 0) := by
decide
end Swap