"""Robbins algebras are Boolean: the whole proof, written with tactics. From the three laws of a Robbins algebra (module robbins) A1 x + y = y + x, A2 x + y + z = x + (y + z), R n(n(x + y) + n(x + n(y))) = x to Huntington's equation n(n(x) + n(y)) + n(n(x) + y) = x, which with A1 and A2 makes a Boolean algebra (Huntington, 1933). The plan is the one of A. L. Mann (A Complete Proof of the Robbins Conjecture, 2003) and of its formalization in Lean's mathlib (Archive/Robbins.lean, J. Tan, 2026, Apache 2.0), which follows M. Wampler-Doty's Isabelle version. The lemma names are Mann's numbers. Lemmas 44-54 are, up to A1 and A2, the twelve equations of W. McCune's EQP proof of Winker's condition (search m5-50, November 1996) — the shortest published computer proof. Stages: 1. mann_44 ... mann_54, winker: Winker's condition q + 2a = 2a with q = n(n(3a) + a) — twelve lemmas, each a few tactic calls; 2. Mann's lemmas 33-40: lemmas with hypotheses (Hypothetical); 3. section WS: from A + B = B an element e with e + e = e; 4. section ES: from e + e = e a zero, n(n(x)) = x and Huntington; 5. the sections used: A, B, e replaced by the real terms. K = robbins_theorem() # a few seconds; the kernel checks it all K.assumptions["huntington"] # {'A1', 'A2', 'R'} """ from kernel import Inst, Refl, Symm, Trans from syntax import term from robbins import (theory, Goal, lemma, times, Hypothetical, Section, rewrite_at, congr_n) # Abbreviations for the statements (texts of terms). W = "n(n(n(a) + b) + a + b + b) + n(n(a) + b)" W2 = f"n({W} + n(b + c) + c) + c" A3, A4, A5 = times(3), times(4), times(5) # a + a + a, ... Q = f"n(n({A3}) + a)" # Mann's q a # The twelve equations, as in the EQP proof (Mann 44-54 and Winker). STATEMENTS = { "mann_44": "n(n(n(a + b) + n(a) + b) + b) = n(a + b)", "mann_45": "n(n(n(n(a) + b) + a + b) + b) = n(n(a) + b)", "mann_46": f"n({W}) = b", "mann_47": f"n(n({W} + c) + n(b + c)) = c", "mann_48": f"n(n({W} + n(b + c) + c) + c) = n(b + c)", "mann_49": f"n(n({W2} + d) + n(n(b + c) + d)) = d", "mann_50": f"n(n({Q} + n({A3})) + n({Q} + ({A5}))) = {Q}", "mann_51": f"n({Q} + ({A5})) = n({A3})", "mann_52": f"n(n({Q} + n({A3}) + (a + a)) + n({A3})) = {Q} + (a + a)", "mann_53": f"n({Q} + n({A3})) = a", "mann_54": f"n(n({Q} + n({A3}) + b) + n(a + b)) = b", "winker": f"{Q} + (a + a) = a + a", } def winker_by_hand(K): """Stage 1 as in mathlib: every creative step written out.""" def prove(name, *script): lemma(K, name, STATEMENTS[name], lambda g: [step(g) for step in script]) prove("mann_44", lambda g: g.nth_rw(2, "← R (n(a + b)) (n(a) + b)"), lambda g: g.nth_rw(3, "← R b a"), lambda g: g.ac()) prove("mann_45", lambda g: g.nth_rw(2, "← R (n(n(a) + b)) (a + b)"), lambda g: g.nth_rw(3, "← R b a"), lambda g: g.ac()) prove("mann_46", lambda g: g.rw("← R b (n(n(a) + b) + a + b)", side="rhs"), lambda g: g.nth_rw(2, "← mann_45 a b"), lambda g: g.ac()) prove("mann_47", lambda g: g.nth_rw(3, f"← R c ({W})"), lambda g: g.rw("mann_46 a b"), lambda g: g.ac()) prove("mann_48", lambda g: g.rw(f"← R (n(b + c)) ({W} + c)", side="rhs"), lambda g: g.rw_ac("mann_47 a b c"), lambda g: g.ac()) prove("mann_49", lambda g: g.nth_rw(3, f"← R d ({W2})"), lambda g: g.rw("mann_48 a b c"), lambda g: g.ac()) winker_rest(K) def winker_by_auto(K): """Stage 1 with the tactic auto: only the rules are named.""" rules = {"mann_44": (), "mann_45": (), "mann_46": ("← R", "← mann_45"), "mann_47": ("← R", "← mann_46"), "mann_48": ("← R", "← mann_47", "mann_47"), "mann_49": ("← R", "← mann_48", "mann_48")} for name, names in rules.items(): lemma(K, name, STATEMENTS[name], lambda g: g.auto(*names, pool=3)) winker_rest(K) def winker_rest(K): """Lemmas 50-54 and Winker's condition (here the instances of the earlier lemmas are named, auto would search too long).""" def prove(name, script): lemma(K, name, STATEMENTS[name], script) def mann_50(g): k = g.fact(f"mann_49 ({A3}) a (a + a) ({Q})") k = rewrite_at(K, k, f"mann_44 ({A3}) ({Q} + (a + a))", ac=True) g.exact_ac(k) def mann_51(g): k = g.fact(f"R (n({Q} + ({A5}))) ({Q} + n({A3}))") g.have("k", rewrite_at(K, k, "mann_50 a", ac=True)) g.nth_rw(1, "← k") g.exact_ac(g.fact(f"mann_47 ({A3}) a (n({A3}))")) def mann_53(g): k = g.fact(f"R a ({Q} + ({A4}))") g.exact_ac(rewrite_at(K, k, "mann_51 a", f"mann_45 ({A3}) a", ac=True)) prove("mann_50", mann_50) prove("mann_51", mann_51) prove("mann_52", lambda g: (g.rw(f"← R ({Q} + (a + a)) ({A3})"), g.rw_ac("mann_51 a"), g.ac())) prove("mann_53", mann_53) prove("mann_54", lambda g: (g.rw(f"← R b ({Q} + n({A3}))", side="rhs"), g.rw("mann_53 a"), g.ac())) prove("winker", lambda g: (g.rw("← mann_52 a", side="lhs"), g.rw("← mann_54 a (a + a)", side="rhs"), g.ac())) def hypothetical_lemmas(K): """Stage 2: Mann's lemmas 33-40, which have hypotheses. Lemma 36 is proved in mathlib by induction on k; we need k = 1, 2, 3, so the induction is unrolled: the proof for k uses the one for k - 1.""" def H(name, constants, hypotheses, statement, script): return Hypothetical(K, name, constants, hypotheses, statement, script) h = Inst("h1", ()) M = {} M[33] = H("mann_33", "abc", ["n(a + n(b + c)) = n(a + b + n(c))"], "a + b = a", lambda g: (g.rw("← R (a + b) c"), g.rw("← h1"), g.rw_ac("R a (b + c)"))) M[34] = H("mann_34", "abc", ["n(a + n(b + c)) = n(b + n(a + c))"], "a = b", lambda g: (g.nth_rw(1, "← R a (b + c)"), g.rw("h1"), g.rw_ac("R b (a + c)"))) M[35] = H("mann_35", "abc", ["n(a + n(b)) = c"], "n(n(a + b) + c) = a", lambda g: (g.rw("← h1"), g.rw("R a b"))) def lemma_36(k): def script(g): ih = h if k == 1 else M[36, k - 1]( {"a": "a", "b": "b", "c": "c"}, h) b = "b" if k == 1 else f"b + {times(k - 1, 'a + c')}" g.have("m35", M[35]({"a": "a", "b": b, "c": "c"}, ih)) g.nth_rw(1, "← m35") g.rw(f"← R c (a + {b})", side="rhs") g.ac() return H(f"mann_36_{k}", "abc", ["n(a + n(b)) = c"], f"n(a + n(b + {times(k, 'a + c')})) = c", script) c = "n(a + n(b))" t = f"a + {c}" def lemma_37(k): def script(g): bk = f"b + {times(k, t)}" g34 = Goal(g.kernel, f"n(n({bk}) + n(n(b) + {c})) = " f"n(n(b) + n(n({bk}) + {c}))", {"aux": M[36, k]({"a": c, "b": "b", "c": "a"}, h), "m36": M[36, k]({"a": "a", "b": "b", "c": c}, Refl(term(c)))}) g34.ac_simp("h1", "aux", "m36") g.exact(M[34]({"a": f"n({bk})", "b": "n(b)", "c": c}, g34.qed())) return H(f"mann_37_{k}", "ab", [f"n({c} + n(b)) = a"], f"n(b + {times(k, t)}) = n(b)", script) def lemma_38(k): def script(g): g37 = Goal(g.kernel, f"n({c} + n(b)) = a") g37.nth_rw(2, "← R a b") g37.nth_rw(2, "← h1") g37.ac() g.exact(M[37, k]({"a": "a", "b": "b"}, g37.qed())) return H(f"mann_38_{k}", "ab", ["n(a + b) = n(b)"], f"n(b + {times(k, t)}) = n(b)", script) for k in (1, 2, 3): M[36, k] = lemma_36(k) for k in (1, 2, 3): M[37, k] = lemma_37(k) M[38, k] = lemma_38(k) def lemma_39(g): L, h2 = g.kernel, Inst("h2", ()) h3 = Goal(L, "n(a + (a + a + b)) = n(a + a + b)") h3 = h3.exact_ac(Trans(h2, Symm(h))).qed() e1 = M[38, 1]({"a": "a + a", "b": "b"}, h) e2 = rewrite_at(L, M[38, 1]({"a": "a", "b": "a + a + b"}, h3), "h1") h33 = Goal(L, "n(a + a + b + n(a + (a + n(b)))) = " "n(a + a + b + a + n(a + n(b)))") h33 = h33.exact_ac(Trans(e1, Symm(e2))).qed() g.have("m33", M[33]({"a": "a + a + b", "b": "a", "c": "a + n(b)"}, h33)) g.nth_rw(1, "← m33") g.ac() M[39] = H("mann_39", "ab", ["n(a + a + b) = n(b)", "n(a + a + a + b) = n(b)"], "a + a + b = a + a + a + b", lemma_39) def lemma_40(via): def script(g): q2 = Goal(g.kernel, f"n({times(2, t)} + b) = n(b)") q2 = q2.exact_ac(M[via, 2]({"a": "a", "b": "b"}, h)).qed() q3 = Goal(g.kernel, f"n({times(3, t)} + b) = n(b)") q3 = q3.exact_ac(M[via, 3]({"a": "a", "b": "b"}, h)).qed() g.exact_ac(M[39]({"a": t, "b": "b"}, q2, q3)) return script statement = f"b + {times(2, t)} = b + {times(3, t)}" M["40a"] = H("mann_40a", "ab", ["n(a + b) = n(b)"], statement, lemma_40(38)) M["40b"] = H("mann_40b", "ab", [f"n({c} + n(b)) = a"], statement, lemma_40(37)) return M # Terms of the third stage: N, c, d over the constants A, B, and e = 3d. N = "n(A + n(B))" C = f"B + ({N} + {N})" D = f"{C} + n({C} + n({C}))" E = f"{D} + ({D}) + ({D})" def idempotent_section(K, M): """Stage 3 (mathlib: exists_idempotent): if A + B = B, then e = 3d with d = c + n(c + n(c)), c = B + 2 n(A + n(B)) has e + e = e. A and B are constants: the terms stay short.""" S = Section(K, "AB", ["A + B = B"]) h = Inst("h1", ()) S.lemma("k1", f"A + ({C}) = {C}", lambda g: (g.rw_ac("h1"), g.ac())) m38 = M[38, 2]({"a": "A", "b": "B"}, congr_n(h)) m38 = rewrite_at(S.kernel, m38, "h1", "h1", ac=True) S.lemma("k2", f"n(B) = n({C})", lambda g: g.exact_ac(Symm(m38))) S.lemma("k3a", "A + (A + (A + B)) = B", lambda g: g.rw("h1", "h1", "h1")) def k3(g): g.have("m40", M["40a"]({"a": "A", "b": "B"}, congr_n(h))) g.rw("← k2") # n(c) -> n(B) on the left g.sides[0].step((1, 1), Symm(Inst("k3a", ()))) # B -> 3A + B g.rw_ac("← m40", side="lhs") g.rw_ac("h1", "h1", side="lhs") g.ac() S.lemma("k3", f"{C} + n(A + n({C})) = {C}", k3) S.lemma("k4", f"n(n({C} + n({C})) + n({C})) = {C}", lambda g: (g.nth_rw(4, f"← R ({C}) (A + n({C}))"), g.nth_rw(3, "← k3"), g.nth_rw(1, "← k1"), g.ac())) S.lemma("fin", f"{D} + ({D}) + ({D}) + ({D}) = {D} + ({D}) + ({D})", lambda g: (g.have("m40", M["40b"]({"a": C, "b": C}, Inst("k4", ()))), g.rw_ac("← m40", side="lhs"), g.ac())) S.lemma("idem", f"{E} + ({E}) = {E}", lambda g: (g.rw_ac("fin", "fin", "fin", side="lhs"), g.ac())) return S def huntington_section(K): """Stage 4 (mathlib: exists_zero, neg_neg, huntington): if e + e = e, then z = n(e + n(e)) is a zero, n(n(x)) = x and Huntington holds.""" S = Section(K, "e", ["e + e = e"]) z = "n(e + n(e))" for name, statement, script in [ ("z1", f"e = n(n(e) + {z})", lambda g: (g.nth_rw(1, "← R e e"), g.rw("h1"))), ("z2", "e + x = n(n(e + x) + n(e + x + n(e)))", lambda g: (g.nth_rw(1, "← R (e + x) e"), g.rw_ac("h1"), g.ac())), ("z3", f"x = n(n(x + n(e) + {z}) + n(x + e))", lambda g: (g.nth_rw(1, f"← R x (n(e) + {z})"), g.rw("← z1"), g.ac())), ("z4", "n(e) = n(n(e + n(e) + n(e)) + e)", lambda g: (g.nth_rw(1, "← R (n(e)) (e + n(e))"), g.rw("← z1"), g.ac())), ("z5", f"e = n(n(e + n(e) + {z}) + n(e))", lambda g: (g.nth_rw(1, "z3 e"), g.rw("h1"))), ("z6", "e = n(n(e + n(e) + n(e)) + n(e))", lambda g: (g.nth_rw(1, "← R e (e + n(e) + n(e))"), g.rw_ac("← z4"), g.rw_ac("h1"), g.ac())), ("z7", f"n(e + n(e) + n(e)) = {z}", lambda g: (g.rw("← R (n(e + n(e) + n(e))) e"), g.rw("← z4", "← z6"), g.ac())), ("z8", f"n(e) = n(e + {z})", lambda g: (g.nth_rw(1, "z4"), g.rw("z7"), g.ac())), ("z9", f"e + {z} = e", lambda g: (g.rw(f"z2 ({z})"), g.rw("← z8"), g.nth_rw(1, "z5", side="rhs"), g.ac())), ("zero", f"x + {z} = x", lambda g: (g.nth_rw(2, "z3 x"), g.rw(f"← R (x + {z}) e"), g.rw_ac("z9"), g.ac())), ("nn1", f"{z} = n(n(x) + n(n(x)))", lambda g: (g.rw(f"← R ({z}) x"), g.ac_simp("zero"))), ("nn2", "n(x) = n(n(n(x) + n(n(n(x)))))", lambda g: (g.nth_rw(1, "← R (n(x)) (n(n(x)))"), g.rw_ac("← nn1 x"), g.ac_simp("zero"))), ("nn3", "n(n(n(x))) = n(x)", lambda g: (g.nth_rw(1, "← R (n(n(n(x)))) (n(x))"), g.rw_ac("← nn1 (n(x))"), g.ac_simp("zero"), g.rw_ac("← nn2 x"))), ]: S.lemma(name, statement, script) y = term(f"n(x + {z}) + n(x + n({z}))") # R: n(y) = x, so n(n(n(y))) S.lemma("neg_neg", "n(n(x)) = x", lambda g: g.exact( rewrite_at(S.kernel, Inst("nn3", (y,)), f"R x ({z})"))) S.lemma("huntington", "n(n(x) + n(y)) + n(n(x) + y) = x", lambda g: (g.rw("← neg_neg x", side="rhs"), g.nth_rw(1, "← R (n(x)) y", side="rhs"), g.rw("neg_neg", side="rhs"), g.ac())) return S def robbins_theorem(by_auto=False): """All stages; returns the kernel with every theorem of the proof.""" K = theory() (winker_by_auto if by_auto else winker_by_hand)(K) M = hypothetical_lemmas(K) WS = idempotent_section(K, M) ES = huntington_section(K) ES.use(WS, {"e": E}, Inst("idem", ())) # e := 3d over A, B WS.use(K, {"A": Q, "B": "a + a"}, Inst("winker", ("a",))) return K