Robbins algebras are Boolean: the whole proof, written with tactics.
Code with colored syntax: click a line number to get a link to it; an underlined name leads to its definition.
| 1 | """Robbins algebras are Boolean: the whole proof, written with tactics. |
| 2 | |
| 3 | From the three laws of a Robbins algebra (module robbins) |
| 4 | |
| 5 | A1 x + y = y + x, A2 x + y + z = x + (y + z), |
| 6 | R n(n(x + y) + n(x + n(y))) = x |
| 7 | |
| 8 | to Huntington's equation n(n(x) + n(y)) + n(n(x) + y) = x, which with |
| 9 | A1 and A2 makes a Boolean algebra (Huntington, 1933). The plan is the one |
| 10 | of A. L. Mann (A Complete Proof of the Robbins Conjecture, 2003) and of its |
| 11 | formalization in Lean's mathlib (Archive/Robbins.lean, J. Tan, 2026, |
| 12 | Apache 2.0), which follows M. Wampler-Doty's Isabelle version. The lemma |
| 13 | names are Mann's numbers. Lemmas 44-54 are, up to A1 and A2, the twelve |
| 14 | equations of W. McCune's EQP proof of Winker's condition (search m5-50, |
| 15 | November 1996) — the shortest published computer proof. |
| 16 | |
| 17 | Stages: |
| 18 | 1. mann_44 ... mann_54, winker: Winker's condition q + 2a = 2a with |
| 19 | q = n(n(3a) + a) — twelve lemmas, each a few tactic calls; |
| 20 | 2. Mann's lemmas 33-40: lemmas with hypotheses (Hypothetical); |
| 21 | 3. section WS: from A + B = B an element e with e + e = e; |
| 22 | 4. section ES: from e + e = e a zero, n(n(x)) = x and Huntington; |
| 23 | 5. the sections used: A, B, e replaced by the real terms. |
| 24 | |
| 25 | K = robbins_theorem() # a few seconds; the kernel checks it all |
| 26 | K.assumptions["huntington"] # {'A1', 'A2', 'R'} |
| 27 | """ |
| 28 | |
| 29 | from kernel import Inst, Refl, Symm, Trans |
| 30 | from syntax import term |
| 31 | from robbins import (theory, Goal, lemma, times, Hypothetical, Section, |
| 32 | rewrite_at, congr_n) |
| 33 | |
| 34 | # Abbreviations for the statements (texts of terms). |
| 35 | W = "n(n(n(a) + b) + a + b + b) + n(n(a) + b)" |
| 36 | W2 = f"n({W} + n(b + c) + c) + c" |
| 37 | A3, A4, A5 = times(3), times(4), times(5) # a + a + a, ... |
| 38 | Q = f"n(n({A3}) + a)" # Mann's q a |
| 39 | |
| 40 | # The twelve equations, as in the EQP proof (Mann 44-54 and Winker). |
| 41 | STATEMENTS = { |
| 42 | "mann_44": "n(n(n(a + b) + n(a) + b) + b) = n(a + b)", |
| 43 | "mann_45": "n(n(n(n(a) + b) + a + b) + b) = n(n(a) + b)", |
| 44 | "mann_46": f"n({W}) = b", |
| 45 | "mann_47": f"n(n({W} + c) + n(b + c)) = c", |
| 46 | "mann_48": f"n(n({W} + n(b + c) + c) + c) = n(b + c)", |
| 47 | "mann_49": f"n(n({W2} + d) + n(n(b + c) + d)) = d", |
| 48 | "mann_50": f"n(n({Q} + n({A3})) + n({Q} + ({A5}))) = {Q}", |
| 49 | "mann_51": f"n({Q} + ({A5})) = n({A3})", |
| 50 | "mann_52": f"n(n({Q} + n({A3}) + (a + a)) + n({A3})) = {Q} + (a + a)", |
| 51 | "mann_53": f"n({Q} + n({A3})) = a", |
| 52 | "mann_54": f"n(n({Q} + n({A3}) + b) + n(a + b)) = b", |
| 53 | "winker": f"{Q} + (a + a) = a + a", |
| 54 | } |
| 55 | |
| 56 | |
| 57 | def winker_by_hand(K): |
| 58 | """Stage 1 as in mathlib: every creative step written out.""" |
| 59 | def prove(name, *script): |
| 60 | lemma(K, name, STATEMENTS[name], |
| 61 | lambda g: [step(g) for step in script]) |
| 62 | |
| 63 | prove("mann_44", lambda g: g.nth_rw(2, "← R (n(a + b)) (n(a) + b)"), |
| 64 | lambda g: g.nth_rw(3, "← R b a"), lambda g: g.ac()) |
| 65 | prove("mann_45", lambda g: g.nth_rw(2, "← R (n(n(a) + b)) (a + b)"), |
| 66 | lambda g: g.nth_rw(3, "← R b a"), lambda g: g.ac()) |
| 67 | prove("mann_46", |
| 68 | lambda g: g.rw("← R b (n(n(a) + b) + a + b)", side="rhs"), |
| 69 | lambda g: g.nth_rw(2, "← mann_45 a b"), lambda g: g.ac()) |
| 70 | prove("mann_47", lambda g: g.nth_rw(3, f"← R c ({W})"), |
| 71 | lambda g: g.rw("mann_46 a b"), lambda g: g.ac()) |
| 72 | prove("mann_48", |
| 73 | lambda g: g.rw(f"← R (n(b + c)) ({W} + c)", side="rhs"), |
| 74 | lambda g: g.rw_ac("mann_47 a b c"), lambda g: g.ac()) |
| 75 | prove("mann_49", lambda g: g.nth_rw(3, f"← R d ({W2})"), |
| 76 | lambda g: g.rw("mann_48 a b c"), lambda g: g.ac()) |
| 77 | winker_rest(K) |
| 78 | |
| 79 | |
| 80 | def winker_by_auto(K): |
| 81 | """Stage 1 with the tactic auto: only the rules are named.""" |
| 82 | rules = {"mann_44": (), "mann_45": (), |
| 83 | "mann_46": ("← R", "← mann_45"), |
| 84 | "mann_47": ("← R", "← mann_46"), |
| 85 | "mann_48": ("← R", "← mann_47", "mann_47"), |
| 86 | "mann_49": ("← R", "← mann_48", "mann_48")} |
| 87 | for name, names in rules.items(): |
| 88 | lemma(K, name, STATEMENTS[name], lambda g: g.auto(*names, pool=3)) |
| 89 | winker_rest(K) |
| 90 | |
| 91 | |
| 92 | def winker_rest(K): |
| 93 | """Lemmas 50-54 and Winker's condition (here the instances of the |
| 94 | earlier lemmas are named, auto would search too long).""" |
| 95 | def prove(name, script): |
| 96 | lemma(K, name, STATEMENTS[name], script) |
| 97 | |
| 98 | def mann_50(g): |
| 99 | k = g.fact(f"mann_49 ({A3}) a (a + a) ({Q})") |
| 100 | k = rewrite_at(K, k, f"mann_44 ({A3}) ({Q} + (a + a))", ac=True) |
| 101 | g.exact_ac(k) |
| 102 | |
| 103 | def mann_51(g): |
| 104 | k = g.fact(f"R (n({Q} + ({A5}))) ({Q} + n({A3}))") |
| 105 | g.have("k", rewrite_at(K, k, "mann_50 a", ac=True)) |
| 106 | g.nth_rw(1, "← k") |
| 107 | g.exact_ac(g.fact(f"mann_47 ({A3}) a (n({A3}))")) |
| 108 | |
| 109 | def mann_53(g): |
| 110 | k = g.fact(f"R a ({Q} + ({A4}))") |
| 111 | g.exact_ac(rewrite_at(K, k, "mann_51 a", f"mann_45 ({A3}) a", |
| 112 | ac=True)) |
| 113 | |
| 114 | prove("mann_50", mann_50) |
| 115 | prove("mann_51", mann_51) |
| 116 | prove("mann_52", lambda g: (g.rw(f"← R ({Q} + (a + a)) ({A3})"), |
| 117 | g.rw_ac("mann_51 a"), g.ac())) |
| 118 | prove("mann_53", mann_53) |
| 119 | prove("mann_54", |
| 120 | lambda g: (g.rw(f"← R b ({Q} + n({A3}))", side="rhs"), |
| 121 | g.rw("mann_53 a"), g.ac())) |
| 122 | prove("winker", lambda g: (g.rw("← mann_52 a", side="lhs"), |
| 123 | g.rw("← mann_54 a (a + a)", side="rhs"), |
| 124 | g.ac())) |
| 125 | |
| 126 | |
| 127 | def hypothetical_lemmas(K): |
| 128 | """Stage 2: Mann's lemmas 33-40, which have hypotheses. Lemma 36 is |
| 129 | proved in mathlib by induction on k; we need k = 1, 2, 3, so the |
| 130 | induction is unrolled: the proof for k uses the one for k - 1.""" |
| 131 | def H(name, constants, hypotheses, statement, script): |
| 132 | return Hypothetical(K, name, constants, hypotheses, statement, |
| 133 | script) |
| 134 | |
| 135 | h = Inst("h1", ()) |
| 136 | M = {} |
| 137 | M[33] = H("mann_33", "abc", ["n(a + n(b + c)) = n(a + b + n(c))"], |
| 138 | "a + b = a", lambda g: (g.rw("← R (a + b) c"), g.rw("← h1"), |
| 139 | g.rw_ac("R a (b + c)"))) |
| 140 | M[34] = H("mann_34", "abc", ["n(a + n(b + c)) = n(b + n(a + c))"], |
| 141 | "a = b", lambda g: (g.nth_rw(1, "← R a (b + c)"), g.rw("h1"), |
| 142 | g.rw_ac("R b (a + c)"))) |
| 143 | M[35] = H("mann_35", "abc", ["n(a + n(b)) = c"], "n(n(a + b) + c) = a", |
| 144 | lambda g: (g.rw("← h1"), g.rw("R a b"))) |
| 145 | |
| 146 | def lemma_36(k): |
| 147 | def script(g): |
| 148 | ih = h if k == 1 else M[36, k - 1]( |
| 149 | {"a": "a", "b": "b", "c": "c"}, h) |
| 150 | b = "b" if k == 1 else f"b + {times(k - 1, 'a + c')}" |
| 151 | g.have("m35", M[35]({"a": "a", "b": b, "c": "c"}, ih)) |
| 152 | g.nth_rw(1, "← m35") |
| 153 | g.rw(f"← R c (a + {b})", side="rhs") |
| 154 | g.ac() |
| 155 | return H(f"mann_36_{k}", "abc", ["n(a + n(b)) = c"], |
| 156 | f"n(a + n(b + {times(k, 'a + c')})) = c", script) |
| 157 | |
| 158 | c = "n(a + n(b))" |
| 159 | t = f"a + {c}" |
| 160 | |
| 161 | def lemma_37(k): |
| 162 | def script(g): |
| 163 | bk = f"b + {times(k, t)}" |
| 164 | g34 = Goal(g.kernel, f"n(n({bk}) + n(n(b) + {c})) = " |
| 165 | f"n(n(b) + n(n({bk}) + {c}))", |
| 166 | {"aux": M[36, k]({"a": c, "b": "b", "c": "a"}, h), |
| 167 | "m36": M[36, k]({"a": "a", "b": "b", "c": c}, |
| 168 | Refl(term(c)))}) |
| 169 | g34.ac_simp("h1", "aux", "m36") |
| 170 | g.exact(M[34]({"a": f"n({bk})", "b": "n(b)", "c": c}, |
| 171 | g34.qed())) |
| 172 | return H(f"mann_37_{k}", "ab", [f"n({c} + n(b)) = a"], |
| 173 | f"n(b + {times(k, t)}) = n(b)", script) |
| 174 | |
| 175 | def lemma_38(k): |
| 176 | def script(g): |
| 177 | g37 = Goal(g.kernel, f"n({c} + n(b)) = a") |
| 178 | g37.nth_rw(2, "← R a b") |
| 179 | g37.nth_rw(2, "← h1") |
| 180 | g37.ac() |
| 181 | g.exact(M[37, k]({"a": "a", "b": "b"}, g37.qed())) |
| 182 | return H(f"mann_38_{k}", "ab", ["n(a + b) = n(b)"], |
| 183 | f"n(b + {times(k, t)}) = n(b)", script) |
| 184 | |
| 185 | for k in (1, 2, 3): |
| 186 | M[36, k] = lemma_36(k) |
| 187 | for k in (1, 2, 3): |
| 188 | M[37, k] = lemma_37(k) |
| 189 | M[38, k] = lemma_38(k) |
| 190 | |
| 191 | def lemma_39(g): |
| 192 | L, h2 = g.kernel, Inst("h2", ()) |
| 193 | h3 = Goal(L, "n(a + (a + a + b)) = n(a + a + b)") |
| 194 | h3 = h3.exact_ac(Trans(h2, Symm(h))).qed() |
| 195 | e1 = M[38, 1]({"a": "a + a", "b": "b"}, h) |
| 196 | e2 = rewrite_at(L, M[38, 1]({"a": "a", "b": "a + a + b"}, h3), "h1") |
| 197 | h33 = Goal(L, "n(a + a + b + n(a + (a + n(b)))) = " |
| 198 | "n(a + a + b + a + n(a + n(b)))") |
| 199 | h33 = h33.exact_ac(Trans(e1, Symm(e2))).qed() |
| 200 | g.have("m33", M[33]({"a": "a + a + b", "b": "a", "c": "a + n(b)"}, |
| 201 | h33)) |
| 202 | g.nth_rw(1, "← m33") |
| 203 | g.ac() |
| 204 | |
| 205 | M[39] = H("mann_39", "ab", ["n(a + a + b) = n(b)", |
| 206 | "n(a + a + a + b) = n(b)"], |
| 207 | "a + a + b = a + a + a + b", lemma_39) |
| 208 | |
| 209 | def lemma_40(via): |
| 210 | def script(g): |
| 211 | q2 = Goal(g.kernel, f"n({times(2, t)} + b) = n(b)") |
| 212 | q2 = q2.exact_ac(M[via, 2]({"a": "a", "b": "b"}, h)).qed() |
| 213 | q3 = Goal(g.kernel, f"n({times(3, t)} + b) = n(b)") |
| 214 | q3 = q3.exact_ac(M[via, 3]({"a": "a", "b": "b"}, h)).qed() |
| 215 | g.exact_ac(M[39]({"a": t, "b": "b"}, q2, q3)) |
| 216 | return script |
| 217 | |
| 218 | statement = f"b + {times(2, t)} = b + {times(3, t)}" |
| 219 | M["40a"] = H("mann_40a", "ab", ["n(a + b) = n(b)"], statement, |
| 220 | lemma_40(38)) |
| 221 | M["40b"] = H("mann_40b", "ab", [f"n({c} + n(b)) = a"], statement, |
| 222 | lemma_40(37)) |
| 223 | return M |
| 224 | |
| 225 | |
| 226 | # Terms of the third stage: N, c, d over the constants A, B, and e = 3d. |
| 227 | N = "n(A + n(B))" |
| 228 | C = f"B + ({N} + {N})" |
| 229 | D = f"{C} + n({C} + n({C}))" |
| 230 | E = f"{D} + ({D}) + ({D})" |
| 231 | |
| 232 | |
| 233 | def idempotent_section(K, M): |
| 234 | """Stage 3 (mathlib: exists_idempotent): if A + B = B, then |
| 235 | e = 3d with d = c + n(c + n(c)), c = B + 2 n(A + n(B)) has e + e = e. |
| 236 | A and B are constants: the terms stay short.""" |
| 237 | S = Section(K, "AB", ["A + B = B"]) |
| 238 | h = Inst("h1", ()) |
| 239 | S.lemma("k1", f"A + ({C}) = {C}", lambda g: (g.rw_ac("h1"), g.ac())) |
| 240 | m38 = M[38, 2]({"a": "A", "b": "B"}, congr_n(h)) |
| 241 | m38 = rewrite_at(S.kernel, m38, "h1", "h1", ac=True) |
| 242 | S.lemma("k2", f"n(B) = n({C})", lambda g: g.exact_ac(Symm(m38))) |
| 243 | S.lemma("k3a", "A + (A + (A + B)) = B", |
| 244 | lambda g: g.rw("h1", "h1", "h1")) |
| 245 | |
| 246 | def k3(g): |
| 247 | g.have("m40", M["40a"]({"a": "A", "b": "B"}, congr_n(h))) |
| 248 | g.rw("← k2") # n(c) -> n(B) on the left |
| 249 | g.sides[0].step((1, 1), Symm(Inst("k3a", ()))) # B -> 3A + B |
| 250 | g.rw_ac("← m40", side="lhs") |
| 251 | g.rw_ac("h1", "h1", side="lhs") |
| 252 | g.ac() |
| 253 | |
| 254 | S.lemma("k3", f"{C} + n(A + n({C})) = {C}", k3) |
| 255 | S.lemma("k4", f"n(n({C} + n({C})) + n({C})) = {C}", |
| 256 | lambda g: (g.nth_rw(4, f"← R ({C}) (A + n({C}))"), |
| 257 | g.nth_rw(3, "← k3"), g.nth_rw(1, "← k1"), g.ac())) |
| 258 | S.lemma("fin", f"{D} + ({D}) + ({D}) + ({D}) = {D} + ({D}) + ({D})", |
| 259 | lambda g: (g.have("m40", M["40b"]({"a": C, "b": C}, |
| 260 | Inst("k4", ()))), |
| 261 | g.rw_ac("← m40", side="lhs"), g.ac())) |
| 262 | S.lemma("idem", f"{E} + ({E}) = {E}", |
| 263 | lambda g: (g.rw_ac("fin", "fin", "fin", side="lhs"), g.ac())) |
| 264 | return S |
| 265 | |
| 266 | |
| 267 | def huntington_section(K): |
| 268 | """Stage 4 (mathlib: exists_zero, neg_neg, huntington): if e + e = e, |
| 269 | then z = n(e + n(e)) is a zero, n(n(x)) = x and Huntington holds.""" |
| 270 | S = Section(K, "e", ["e + e = e"]) |
| 271 | z = "n(e + n(e))" |
| 272 | for name, statement, script in [ |
| 273 | ("z1", f"e = n(n(e) + {z})", |
| 274 | lambda g: (g.nth_rw(1, "← R e e"), g.rw("h1"))), |
| 275 | ("z2", "e + x = n(n(e + x) + n(e + x + n(e)))", |
| 276 | lambda g: (g.nth_rw(1, "← R (e + x) e"), g.rw_ac("h1"), g.ac())), |
| 277 | ("z3", f"x = n(n(x + n(e) + {z}) + n(x + e))", |
| 278 | lambda g: (g.nth_rw(1, f"← R x (n(e) + {z})"), g.rw("← z1"), |
| 279 | g.ac())), |
| 280 | ("z4", "n(e) = n(n(e + n(e) + n(e)) + e)", |
| 281 | lambda g: (g.nth_rw(1, "← R (n(e)) (e + n(e))"), g.rw("← z1"), |
| 282 | g.ac())), |
| 283 | ("z5", f"e = n(n(e + n(e) + {z}) + n(e))", |
| 284 | lambda g: (g.nth_rw(1, "z3 e"), g.rw("h1"))), |
| 285 | ("z6", "e = n(n(e + n(e) + n(e)) + n(e))", |
| 286 | lambda g: (g.nth_rw(1, "← R e (e + n(e) + n(e))"), |
| 287 | g.rw_ac("← z4"), g.rw_ac("h1"), g.ac())), |
| 288 | ("z7", f"n(e + n(e) + n(e)) = {z}", |
| 289 | lambda g: (g.rw("← R (n(e + n(e) + n(e))) e"), |
| 290 | g.rw("← z4", "← z6"), g.ac())), |
| 291 | ("z8", f"n(e) = n(e + {z})", |
| 292 | lambda g: (g.nth_rw(1, "z4"), g.rw("z7"), g.ac())), |
| 293 | ("z9", f"e + {z} = e", |
| 294 | lambda g: (g.rw(f"z2 ({z})"), g.rw("← z8"), |
| 295 | g.nth_rw(1, "z5", side="rhs"), g.ac())), |
| 296 | ("zero", f"x + {z} = x", |
| 297 | lambda g: (g.nth_rw(2, "z3 x"), g.rw(f"← R (x + {z}) e"), |
| 298 | g.rw_ac("z9"), g.ac())), |
| 299 | ("nn1", f"{z} = n(n(x) + n(n(x)))", |
| 300 | lambda g: (g.rw(f"← R ({z}) x"), g.ac_simp("zero"))), |
| 301 | ("nn2", "n(x) = n(n(n(x) + n(n(n(x)))))", |
| 302 | lambda g: (g.nth_rw(1, "← R (n(x)) (n(n(x)))"), |
| 303 | g.rw_ac("← nn1 x"), g.ac_simp("zero"))), |
| 304 | ("nn3", "n(n(n(x))) = n(x)", |
| 305 | lambda g: (g.nth_rw(1, "← R (n(n(n(x)))) (n(x))"), |
| 306 | g.rw_ac("← nn1 (n(x))"), g.ac_simp("zero"), |
| 307 | g.rw_ac("← nn2 x"))), |
| 308 | ]: |
| 309 | S.lemma(name, statement, script) |
| 310 | y = term(f"n(x + {z}) + n(x + n({z}))") # R: n(y) = x, so n(n(n(y))) |
| 311 | S.lemma("neg_neg", "n(n(x)) = x", lambda g: g.exact( |
| 312 | rewrite_at(S.kernel, Inst("nn3", (y,)), f"R x ({z})"))) |
| 313 | S.lemma("huntington", "n(n(x) + n(y)) + n(n(x) + y) = x", |
| 314 | lambda g: (g.rw("← neg_neg x", side="rhs"), |
| 315 | g.nth_rw(1, "← R (n(x)) y", side="rhs"), |
| 316 | g.rw("neg_neg", side="rhs"), g.ac())) |
| 317 | return S |
| 318 | |
| 319 | |
| 320 | def robbins_theorem(by_auto=False): |
| 321 | """All stages; returns the kernel with every theorem of the proof.""" |
| 322 | K = theory() |
| 323 | (winker_by_auto if by_auto else winker_by_hand)(K) |
| 324 | M = hypothetical_lemmas(K) |
| 325 | WS = idempotent_section(K, M) |
| 326 | ES = huntington_section(K) |
| 327 | ES.use(WS, {"e": E}, Inst("idem", ())) # e := 3d over A, B |
| 328 | WS.use(K, {"A": Q, "B": "a + a"}, Inst("winker", ("a",))) |
| 329 | return K |