The two complete proofs of the Robbins theorem, step by step, for the Boole Lab: bl theory robbins (and robbins_ab, robbins_e, robbins_cd, robbins_c), bl prove <step>, hint, bl replay mann | mccune.
Code with colored syntax: click a line number to get a link to it; an underlined name leads to its definition.
| 1 | """The two complete proofs of the Robbins theorem, step by step, for the |
| 2 | Boole Lab: bl theory robbins (and robbins_ab, robbins_e, robbins_cd, |
| 3 | robbins_c), bl prove <step>, hint, bl replay mann | mccune. |
| 4 | |
| 5 | * Mann's variant: A. L. Mann, A Complete Proof of the Robbins Conjecture |
| 6 | (2003), as formalized in mathlib (Archive/Robbins.lean, J. Tan, 2026, |
| 7 | Apache 2.0). The scripts write out every creative step, as mathlib |
| 8 | does: nth_rw, rw_ac and ac_rfl. The proofs are those of module |
| 9 | robbins_proof, in the syntax of the lab. |
| 10 | * McCune's variant: the proofs found by W. McCune's program EQP in 1996 |
| 11 | (files eqp-lemma3, eqp-lemma1 and eqp-lemma0 at |
| 12 | www.cs.unm.edu/~mccune/papers/robbins/). Every equation is quoted with |
| 13 | its EQP number and justification (para(a,b): equation a substituted |
| 14 | into equation b; demod: simplified by the listed equations). A step is |
| 15 | one call of auto with the instances of its parents, found once offline. |
| 16 | |
| 17 | A stage is a list of steps proved in one theory of theories.py. The |
| 18 | stages are joined outside the lab (assemble): the constants of a stage |
| 19 | are replaced by terms, as in robbins_proof (Section.use). |
| 20 | """ |
| 21 | |
| 22 | import re |
| 23 | |
| 24 | from kernel import Inst |
| 25 | from syntax import term |
| 26 | from tactics import TacticError |
| 27 | import robbins as rb |
| 28 | import robbins_proof as rp |
| 29 | |
| 30 | W, W2, Q = rp.W, rp.W2, rp.Q |
| 31 | A3, A4, A5 = rp.A3, rp.A4, rp.A5 |
| 32 | |
| 33 | # (depth, pool) of robbins.Goal.auto, tried in turn by the tactic auto |
| 34 | SEARCH = ((1, 2), (1, 3), (2, 2)) |
| 35 | SEARCH_LIMIT = 60_000 |
| 36 | |
| 37 | |
| 38 | def both_ways(rules): |
| 39 | """Each rule as written and backwards, unless it has ← already.""" |
| 40 | texts = [] |
| 41 | for rule in rules: |
| 42 | rule = " ".join(rule.split()) |
| 43 | for t in ([rule] if rule.startswith("←") else [rule, "← " + rule]): |
| 44 | if t not in texts: |
| 45 | texts.append(t) |
| 46 | return texts |
| 47 | |
| 48 | |
| 49 | def auto(g, rules): |
| 50 | """The tactic auto in a Robbins theory: a search of robbins.Goal.auto |
| 51 | (one, then two rewrites on each side, modulo A1 and A2) with the rules |
| 52 | in both directions. Returns (depth, pool) of the search that found |
| 53 | the proof; on failure g is unchanged.""" |
| 54 | texts = both_ways(rules or ["R"]) |
| 55 | for depth, pool in SEARCH: |
| 56 | try: |
| 57 | g.auto(*texts, pool=pool, depth=depth, limit=SEARCH_LIMIT) |
| 58 | return depth, pool |
| 59 | except TacticError: |
| 60 | continue |
| 61 | raise TacticError("auto: no proof found") |
| 62 | |
| 63 | |
| 64 | # --- Mann's variant (mathlib) ---------------------------------------------- |
| 65 | |
| 66 | MANN_1 = [ |
| 67 | ("mann_44", "44", ["nth_rw 2 [← R (n(a + b)) (n(a) + b)]", |
| 68 | "nth_rw 3 [← R b a]", "ac_rfl"]), |
| 69 | ("mann_45", "45", ["nth_rw 2 [← R (n(n(a) + b)) (a + b)]", |
| 70 | "nth_rw 3 [← R b a]", "ac_rfl"]), |
| 71 | ("mann_46", "46", ["nth_rw 5 [← R b (n(n(a) + b) + a + b)]", |
| 72 | "nth_rw 2 [← mann_45 a b]", "ac_rfl"]), |
| 73 | ("mann_47", "47", [f"nth_rw 3 [← R c ({W})]", "rw [mann_46 a b]", |
| 74 | "ac_rfl"]), |
| 75 | ("mann_48", "48", [f"nth_rw 2 [← R (n(b + c)) ({W} + c)]", |
| 76 | "rw_ac [mann_47 a b c]", "ac_rfl"]), |
| 77 | ("mann_49", "49", [f"nth_rw 3 [← R d ({W2})]", "rw [mann_48 a b c]", |
| 78 | "ac_rfl"]), |
| 79 | ("mann_50", "50", [f"nth_rw 3 [← mann_49 ({A3}) a (a + a) ({Q})]", |
| 80 | f"rw_ac [mann_44 ({A3}) ({Q} + (a + a))]", |
| 81 | "ac_rfl"]), |
| 82 | ("mann_51", "51", [f"nth_rw 1 [← R (n({Q} + ({A5}))) ({Q} + n({A3}))]", |
| 83 | "rw_ac [mann_50 a]", |
| 84 | f"rw_ac [mann_47 ({A3}) a (n({A3}))]"]), |
| 85 | ("mann_52", "52", [f"rw [← R ({Q} + (a + a)) ({A3})]", |
| 86 | "rw_ac [mann_51 a]", "ac_rfl"]), |
| 87 | ("mann_53", "53", [f"nth_rw 8 [← R a ({Q} + ({A4}))]", |
| 88 | "rw_ac [mann_51 a]", f"rw_ac [mann_45 ({A3}) a]", |
| 89 | "ac_rfl"]), |
| 90 | ("mann_54", "54", [f"nth_rw 3 [← R b ({Q} + n({A3}))]", |
| 91 | "rw [mann_53 a]", "ac_rfl"]), |
| 92 | ("winker", "Winker", ["rw [← mann_52 a]", |
| 93 | "nth_rw 5 [← mann_54 a (a + a)]", "ac_rfl"]), |
| 94 | ] |
| 95 | |
| 96 | N = "n(A + n(B))" |
| 97 | MANN_3 = [ |
| 98 | ("pair1", "A + c = c", ["rw [hc]", "rw_ac [h]", "ac_rfl"]), |
| 99 | ("pair2", "n(B) = n(c)", ["rw [hc]", "nth_rw 1 [← m38]", |
| 100 | "rw_ac [h, h]", "ac_rfl"]), |
| 101 | ("pair3a", "A + (A + (A + B)) = B", ["rw [h, h, h]"]), |
| 102 | ("pair3", "c + n(A + n(c)) = c", |
| 103 | ["rw [← pair2]", "nth_rw 1 [hc]", "nth_rw 1 [← pair3a]", |
| 104 | "rw_ac [← m40a]", "rw_ac [h, h]", "rw [hc]", "ac_rfl"]), |
| 105 | ("pair4", "n(n(c + n(c)) + n(c)) = c", |
| 106 | ["nth_rw 4 [← R c (A + n(c))]", "nth_rw 3 [← pair3]", |
| 107 | "nth_rw 1 [← pair1]", "ac_rfl"]), |
| 108 | ("fin", "d + d + d + d = d + d + d", ["nth_rw 1 [hd]", |
| 109 | "rw_ac [← m40b]", |
| 110 | "rw_ac [← hd]"]), |
| 111 | ("idem", "d + d + d + (d + d + d) = d + d + d", |
| 112 | ["rw_ac [fin, fin, fin]"]), |
| 113 | ] |
| 114 | |
| 115 | Z = "n(e + n(e))" |
| 116 | MANN_4 = [ |
| 117 | ("zero1", f"e = n(n(e) + {Z})", ["nth_rw 1 [← R e e]", "rw [h]"]), |
| 118 | ("zero2", "e + x = n(n(e + x) + n(e + x + n(e)))", |
| 119 | ["nth_rw 1 [← R (e + x) e]", "rw_ac [h]", "ac_rfl"]), |
| 120 | ("zero3", f"x = n(n(x + n(e) + {Z}) + n(x + e))", |
| 121 | [f"nth_rw 1 [← R x (n(e) + {Z})]", "rw [← zero1]", "ac_rfl"]), |
| 122 | ("zero4", "n(e) = n(n(e + n(e) + n(e)) + e)", |
| 123 | ["nth_rw 1 [← R (n(e)) (e + n(e))]", "rw [← zero1]", "ac_rfl"]), |
| 124 | ("zero5", f"e = n(n(e + n(e) + {Z}) + n(e))", |
| 125 | ["nth_rw 1 [zero3 e]", "rw [h]"]), |
| 126 | ("zero6", "e = n(n(e + n(e) + n(e)) + n(e))", |
| 127 | ["nth_rw 1 [← R e (e + n(e) + n(e))]", "rw_ac [← zero4]", |
| 128 | "rw_ac [h]", "ac_rfl"]), |
| 129 | ("zero7", f"n(e + n(e) + n(e)) = {Z}", |
| 130 | ["rw [← R (n(e + n(e) + n(e))) e]", "rw [← zero4, ← zero6]", |
| 131 | "ac_rfl"]), |
| 132 | ("zero8", f"n(e) = n(e + {Z})", |
| 133 | ["nth_rw 1 [zero4]", "rw [zero7]", "ac_rfl"]), |
| 134 | ("zero9", f"e + {Z} = e", |
| 135 | [f"rw [zero2 ({Z})]", "rw [← zero8]", "nth_rw 6 [zero5]", "ac_rfl"]), |
| 136 | ("zero", f"x + {Z} = x", ["nth_rw 2 [zero3 x]", |
| 137 | f"rw [← R (x + {Z}) e]", "rw_ac [zero9]", |
| 138 | "ac_rfl"]), |
| 139 | ("nn1", f"{Z} = n(n(x) + n(n(x)))", [f"rw [← R ({Z}) x]", |
| 140 | "ac_simp [zero]"]), |
| 141 | ("nn2", "n(x) = n(n(n(x) + n(n(n(x)))))", |
| 142 | ["nth_rw 1 [← R (n(x)) (n(n(x)))]", "rw_ac [← nn1 x]", |
| 143 | "ac_simp [zero]"]), |
| 144 | ("nn3", "n(n(n(x))) = n(x)", |
| 145 | ["nth_rw 1 [← R (n(n(n(x)))) (n(x))]", "rw_ac [← nn1 (n(x))]", |
| 146 | "ac_simp [zero]", "rw_ac [← nn2 x]"]), |
| 147 | ("neg_neg", "n(n(x)) = x", |
| 148 | [f"auto [nn3 (n(x + {Z}) + n(x + n({Z}))), R x ({Z})]"]), |
| 149 | ("huntington", "n(n(x) + n(y)) + n(n(x) + y) = x", |
| 150 | ["nth_rw 3 [← neg_neg x]", "nth_rw 3 [← R (n(x)) y]", |
| 151 | "rw [neg_neg]", "ac_rfl"]), |
| 152 | ] |
| 153 | |
| 154 | # --- McCune's variant (EQP, 1996) ------------------------------------------ |
| 155 | # (EQP number, EQP justification, the equation as EQP printed it, script). |
| 156 | # The equations are W. McCune's (EQP 0.9 proofs, 1996), quoted with |
| 157 | # attribution; the scripts are ours. |
| 158 | |
| 159 | EQP_M550 = [ |
| 160 | ('10', 'para(7,7)', |
| 161 | 'n(n(n(x+y)+n(x)+y)+y) = n(x+y)', |
| 162 | ['auto [R]']), |
| 163 | ('11', 'para(7,7)', |
| 164 | 'n(n(n(n(x)+y)+x+y)+y) = n(n(x)+y)', |
| 165 | ['auto [R]']), |
| 166 | ('29', 'para(11,7)', |
| 167 | 'n(n(n(n(x)+y)+x+y+y)+n(n(x)+y)) = y', |
| 168 | ['auto [eqp11, R]']), |
| 169 | ('54', 'para(29,7)', |
| 170 | 'n(n(n(n(n(x)+y)+x+y+y)+n(n(x)+y)+z)+n(y+z)) = z', |
| 171 | ['auto [eqp29, R]']), |
| 172 | ('217', 'para(54,7)', |
| 173 | 'n(n(n(n(n(x)+y)+x+y+y)+n(n(x)+y)+n(y+z)+z)+z) = n(y+z)', |
| 174 | ['auto [R (n(y + z)) (n(n(n(x) + y) + x + y + y) + n(n(x) + y) + z), ' |
| 175 | 'eqp54 x y z]']), |
| 176 | ('674', 'para(217,7)', |
| 177 | 'n(n(n(n(n(n(x)+y)+x+y+y)+n(n(x)+y)+n(y+z)+z)+z+u)+n(n(y+z)+u)) = u', |
| 178 | ['auto [eqp217, R]']), |
| 179 | ('6736', 'para(10,674)', |
| 180 | 'n(n(n(n(x+x+x)+x)+n(x+x+x))+n(n(n(x+x+x)+x)+x+x+x+x+x)) = n(n(x+x+x)+x)', |
| 181 | ['auto [eqp10 (x + x + x) (n(n(x + x + x) + x) + (x + x)), eqp674 (x + x ' |
| 182 | '+ x) x (x + x) (n(n(x + x + x) + x))]']), |
| 183 | ('8855', 'para(6736,7),demod([54]),flip(1)', |
| 184 | 'n(n(n(x+x+x)+x)+x+x+x+x+x) = n(x+x+x)', |
| 185 | ['auto [R (n(n(n(x + x + x) + x) + (x + x + x + x + x))) (n(n(x + x + ' |
| 186 | 'x) + x) + n(x + x + x)), eqp6736 x, eqp54 (x + x + x) x ' |
| 187 | '(n(x + x + x))]']), |
| 188 | ('8865', 'para(8855,7)', |
| 189 | 'n(n(n(n(x+x+x)+x)+n(x+x+x)+x+x)+n(x+x+x)) = n(n(x+x+x)+x)+x+x', |
| 190 | ['auto [R (n(n(x + x + x) + x) + (x + x)) (x + x + x), eqp8855 x]']), |
| 191 | ('8866', 'para(8855,7),demod([11])', |
| 192 | 'n(n(n(x+x+x)+x)+n(x+x+x)) = x', |
| 193 | ['auto [R x (n(n(x + x + x) + x) + (x + x + x + x)), eqp8855 x, eqp11 (x ' |
| 194 | '+ x + x) x]']), |
| 195 | ('8870', 'para(8866,7)', |
| 196 | 'n(n(n(n(x+x+x)+x)+n(x+x+x)+y)+n(x+y)) = y', |
| 197 | ['auto [R y (n(n(x + x + x) + x) + n(x + x + x)), eqp8866 x]']), |
| 198 | ('8871', 'back_demod(8865),demod([8870]),flip(1)', |
| 199 | 'n(n(x+x+x)+x)+x+x = x+x', |
| 200 | ['auto [eqp8865 x, eqp8870 x (x + x)]']), |
| 201 | ] |
| 202 | |
| 203 | EQP_LEMMA1 = [ |
| 204 | ('4', 'para(2,3)', |
| 205 | 'n(n(C) + n(D + n(C))) = D', |
| 206 | ['auto [h, R]']), |
| 207 | ('8', "para(2',3)", |
| 208 | 'n(n(D + n(C + x) + y) + n(C + x + y)) = D + y', |
| 209 | ['auto [h, R]']), |
| 210 | ('20', 'para(4,3)', |
| 211 | 'n(D + n(C + n(D + n(C)))) = n(D + n(C))', |
| 212 | ['auto [eqp4, R]']), |
| 213 | ('34', 'para(3,3)', |
| 214 | 'n(n(n(n(x) + y) + n(x + y) + z) + n(y + z)) = z', |
| 215 | ['auto [R]']), |
| 216 | ('35', 'para(3,3)', |
| 217 | 'n(n(n(n(x) + y) + x + y) + y) = n(n(x) + y)', |
| 218 | ['auto [R]']), |
| 219 | ('56', 'para(2,34)', |
| 220 | 'n(n(C) + n(D + n(C + n(x)) + n(C + x))) = D', |
| 221 | ['auto [h, eqp34]']), |
| 222 | ('151', 'para(20,3)', |
| 223 | 'n(n(D + n(C + n(D + n(C))) + x) + n(n(D + n(C)) + x)) = x', |
| 224 | ['auto [eqp20, R]']), |
| 225 | ('152', 'para(20,3),demod([2])', |
| 226 | 'n(n(D + n(C)) + n(C + n(D + n(C)))) = D', |
| 227 | ['auto [h, R D (C + n(D + n(C))), eqp20]']), |
| 228 | ('173', 'para(152,3)', |
| 229 | 'n(D + n(D + n(C) + n(C + n(D + n(C))))) = n(C + n(D + n(C)))', |
| 230 | ['auto [eqp152, R]']), |
| 231 | ('197', "para(2',151)", |
| 232 | 'n(n(C + n(D + n(C))) + n(C + n(C + n(D + n(C))))) = C', |
| 233 | ['auto [h, eqp151]']), |
| 234 | ('280', 'para(35,3)', |
| 235 | 'n(n(n(n(n(x) + y) + x + y) + y + z) + n(n(n(x) + y) + z)) = z', |
| 236 | ['auto [eqp35, R]']), |
| 237 | ('837', 'para(4,151),demod([173])', |
| 238 | 'n(C + n(D + n(C))) = n(C)', |
| 239 | ['auto [eqp4, eqp151, eqp173]']), |
| 240 | ('839', 'back_demod(197),demod([837,837])', |
| 241 | 'n(n(C) + n(C + n(C))) = C', |
| 242 | ['auto [eqp837, eqp197]']), |
| 243 | ('842', 'para(839,3)', |
| 244 | 'n(n(C + x) + n(n(C) + n(C + n(C)) + x)) = x', |
| 245 | ['auto [eqp839, R]']), |
| 246 | ('844', 'para(839,3)', |
| 247 | 'n(C + n(C + n(C + n(C)))) = n(C + n(C))', |
| 248 | ['auto [eqp839, R]']), |
| 249 | ('883', 'para(844,3)', |
| 250 | 'n(n(C + n(C)) + n(C + C + n(C + n(C)))) = C', |
| 251 | ['auto [eqp844, R]']), |
| 252 | ('946', 'para(883,3)', |
| 253 | 'n(C + n(C + n(C) + n(C + C + n(C + n(C))))) = n(C + C + n(C + n(C)))', |
| 254 | ['auto [eqp883, R]']), |
| 255 | ('1706', 'para(839,280),demod([946])', |
| 256 | 'n(C + C + n(C + n(C))) = n(C)', |
| 257 | ['auto [eqp280 C C (n(C)), eqp839, eqp946]']), |
| 258 | ('1734', 'para(1706,8),demod([56]),flip(1)', |
| 259 | 'D + n(C + n(C)) = D', |
| 260 | ['auto [eqp8 C (n(C + n(C))), eqp1706, eqp56 C]']), |
| 261 | ('1745', "para(2',1734'),demod([2])", |
| 262 | 'C + n(C + n(C)) = C', |
| 263 | ['auto [h, eqp1734]']), |
| 264 | ('1802', "para(1745',3),demod([842]),flip(1)", |
| 265 | 'n(C + n(C)) + x = x', |
| 266 | ['auto [R (n(C + n(C)) + x) C, eqp1745, eqp842 x]']), |
| 267 | ] |
| 268 | |
| 269 | EQP_LEMMA0 = [ |
| 270 | ('4', 'para(1,2)', |
| 271 | 'n(n(C) + n(C + n(C))) = C', |
| 272 | ['auto [h, R]']), |
| 273 | ('5', "para(1',2)", |
| 274 | 'n(n(C + n(C) + x) + n(C + x)) = C + x', |
| 275 | ['auto [h, R]']), |
| 276 | ('8', 'para(4,2)', |
| 277 | 'n(n(C + x) + n(n(C) + n(C + n(C)) + x)) = x', |
| 278 | ['auto [eqp4, R]']), |
| 279 | ('9', 'para(4,2)', |
| 280 | 'n(C + n(C + n(C) + n(C))) = n(C)', |
| 281 | ['auto [eqp4, R]']), |
| 282 | ('13', 'para(1,8)', |
| 283 | 'n(n(C) + n(C + n(C) + n(C + n(C)))) = C', |
| 284 | ['auto [h, eqp8]']), |
| 285 | ('20', 'para(9,2),demod([1])', |
| 286 | 'n(n(C) + n(C + n(C) + n(C))) = C', |
| 287 | ['auto [h, R C (C + n(C) + n(C)), eqp9]']), |
| 288 | ('22', 'para(9,2),demod([20]),flip(1)', |
| 289 | 'n(C + n(C) + n(C)) = n(C + n(C))', |
| 290 | ['auto [eqp20, eqp9, R (n(C + n(C) + n(C))) C]']), |
| 291 | ('24', 'back_demod(9),demod([22])', |
| 292 | 'n(C + n(C + n(C))) = n(C)', |
| 293 | ['auto [eqp22, eqp9]']), |
| 294 | ('32', 'para(24,5),demod([13]),flip(1)', |
| 295 | 'C + n(C + n(C)) = C', |
| 296 | ['auto [eqp24, eqp5, eqp13]']), |
| 297 | ('35', "para(32',2),demod([8]),flip(1)", |
| 298 | 'n(C + n(C)) + x = x', |
| 299 | ['auto [eqp32, eqp8 x, R (x + n(C + n(C))) C]']), |
| 300 | ('42', 'para(35,2),demod([35])', |
| 301 | 'n(n(n(x)) + n(x)) = n(C + n(C))', |
| 302 | ['auto [eqp35 (n(x)), R (n(C + n(C))) x, eqp35 x]']), |
| 303 | ('50', 'para(42,2),demod([35])', |
| 304 | 'n(n(n(n(x)) + x)) = n(n(x))', |
| 305 | ['auto [eqp42 x, R (n(n(x))) x, eqp35 (n(x + n(n(x))))]']), |
| 306 | ('52', 'para(42,2),demod([35,50])', |
| 307 | 'n(n(n(x))) = n(x)', |
| 308 | ['auto [eqp42, R, eqp35, eqp50]']), |
| 309 | ('58', 'para(2,52),demod([2])', |
| 310 | 'n(n(x)) = x', |
| 311 | ['auto [R, eqp52]']), |
| 312 | ('87', 'para(2,58),flip(1)', |
| 313 | 'n(n(x) + y) + n(x + y) = n(y)', |
| 314 | ['auto [R, eqp58]']), |
| 315 | ] |
| 316 | # EQP's Lemma 0 ends with a contradiction with -(n(B + n(A)) + n(n(B) + |
| 317 | # n(A)) = A): equations 87 and 58 give Huntington's equation. |
| 318 | EQP_FINAL = ("88", "87, 58", "n(n(x) + n(y)) + n(n(x) + y) = x", |
| 319 | ["rw_ac [eqp87 y (n(x))]", "rw [eqp58]"]) |
| 320 | |
| 321 | |
| 322 | def _mann(rows, statements): |
| 323 | return [{"name": name, "statement": statements(name, text), |
| 324 | "script": script, "source_pl": source(text, "pl"), |
| 325 | "source_en": source(text, "en")} |
| 326 | for name, text, script in rows] |
| 327 | |
| 328 | |
| 329 | def source(text, lang): |
| 330 | if text.isdigit(): |
| 331 | return f"Mann, {'lemat' if lang == 'pl' else 'lemma'} {text}" |
| 332 | if text == "Winker": |
| 333 | return ("Mann: warunek Winkera" if lang == "pl" |
| 334 | else "Mann: Winker's condition") |
| 335 | return "mathlib: exists_idempotent / exists_zero" |
| 336 | |
| 337 | |
| 338 | def _theorem_4(name): |
| 339 | """The mathlib theorem whose proof the step of stage 4 belongs to.""" |
| 340 | if name.startswith("zero"): |
| 341 | return "exists_zero" |
| 342 | return "huntington" if name == "huntington" else "neg_neg" |
| 343 | |
| 344 | |
| 345 | def _eqp(rows, extra=None): |
| 346 | steps = [{"name": f"eqp{num}", "statement": eq, "script": script, |
| 347 | "source_pl": f"EQP {num} [{just}]", |
| 348 | "source_en": f"EQP {num} [{just}]"} |
| 349 | for num, just, eq, script in rows] |
| 350 | if extra: |
| 351 | num, parents, eq, script = extra |
| 352 | steps.append({"name": "huntington", "statement": eq, |
| 353 | "script": script, |
| 354 | "source_pl": f"EQP {num}: z równań {parents}", |
| 355 | "source_en": f"EQP {num}: from equations {parents}"}) |
| 356 | return steps |
| 357 | |
| 358 | |
| 359 | VARIANTS = { |
| 360 | "mann": { |
| 361 | "title_pl": "Mann (2003), jak w mathlib", |
| 362 | "title_en": "Mann (2003), as in mathlib", |
| 363 | "stages": [ |
| 364 | {"theory": "robbins", |
| 365 | "title_pl": "lematy 44–54 i warunek Winkera q + 2a = 2a", |
| 366 | "title_en": "lemmas 44–54 and Winker's condition q + 2a = 2a", |
| 367 | "steps": _mann(MANN_1, lambda n, t: rp.STATEMENTS[n])}, |
| 368 | {"theory": None, |
| 369 | "title_pl": "lematy 33–40 z założeniami (w robbins_ab jako " |
| 370 | "fakty dane)", |
| 371 | "title_en": "lemmas 33–40 with hypotheses (given facts in " |
| 372 | "robbins_ab)", |
| 373 | "steps": []}, |
| 374 | {"theory": "robbins_ab", |
| 375 | "title_pl": "z A + B = B element idempotentny d + d + d", |
| 376 | "title_en": "from A + B = B an idempotent d + d + d", |
| 377 | "steps": [{"name": n, "statement": s, "script": script, |
| 378 | "source_pl": "mathlib: exists_idempotent", |
| 379 | "source_en": "mathlib: exists_idempotent"} |
| 380 | for n, s, script in MANN_3]}, |
| 381 | {"theory": "robbins_e", |
| 382 | "title_pl": "z e + e = e: zero, n(n(x)) = x i równanie " |
| 383 | "Huntingtona", |
| 384 | "title_en": "from e + e = e: a zero, n(n(x)) = x and " |
| 385 | "Huntington's equation", |
| 386 | "steps": [{"name": n, "statement": s, "script": script, |
| 387 | "source_pl": "mathlib: " + _theorem_4(n), |
| 388 | "source_en": "mathlib: " + _theorem_4(n)} |
| 389 | for n, s, script in MANN_4]}, |
| 390 | ], |
| 391 | }, |
| 392 | "mccune": { |
| 393 | "title_pl": "McCune (EQP, 1996)", |
| 394 | "title_en": "McCune (EQP, 1996)", |
| 395 | "stages": [ |
| 396 | {"theory": "robbins", |
| 397 | "title_pl": "poszukiwanie m5-50: 12 równań do warunku Winkera", |
| 398 | "title_en": "search m5-50: 12 equations to Winker's " |
| 399 | "condition", |
| 400 | "steps": _eqp(EQP_M550)}, |
| 401 | {"theory": "robbins_cd", |
| 402 | "title_pl": "lemat 1: z D + C = C zero n(C + n(C))", |
| 403 | "title_en": "Lemma 1: from D + C = C a zero n(C + n(C))", |
| 404 | "steps": _eqp(EQP_LEMMA1)}, |
| 405 | {"theory": "robbins_c", |
| 406 | "title_pl": "lemat 0: z C + C = C równanie Huntingtona", |
| 407 | "title_en": "Lemma 0: from C + C = C Huntington's equation", |
| 408 | "steps": _eqp(EQP_LEMMA0, EQP_FINAL)}, |
| 409 | ], |
| 410 | }, |
| 411 | } |
| 412 | |
| 413 | |
| 414 | def steps_of(theory): |
| 415 | """The steps of both variants in a theory: [(variant, stage number, |
| 416 | step)], in the order of the variants.""" |
| 417 | found = [] |
| 418 | for key, variant in VARIANTS.items(): |
| 419 | for i, stage in enumerate(variant["stages"], 1): |
| 420 | if stage["theory"] == theory: |
| 421 | found += [(key, i, step) for step in stage["steps"]] |
| 422 | return found |
| 423 | |
| 424 | |
| 425 | # --- running a script outside the lab (assemble, tests) -------------------- |
| 426 | |
| 427 | _LINE = re.compile(r"(rw|rw_ac|ac_simp|auto)\s*\[(.*)\]|nth_rw\s+(\d+)\s*" |
| 428 | r"\[(.*)\]|(ac_rfl)") |
| 429 | |
| 430 | |
| 431 | def _rules(text): |
| 432 | """'a, R (x + y) z' -> ['a', 'R (x + y) z']: split at top-level |
| 433 | commas.""" |
| 434 | parts, depth, now = [], 0, "" |
| 435 | for ch in text: |
| 436 | depth += {"(": 1, ")": -1}.get(ch, 0) |
| 437 | if ch == "," and depth == 0: |
| 438 | parts.append(now.strip()) |
| 439 | now = "" |
| 440 | else: |
| 441 | now += ch |
| 442 | return parts + [now.strip()] |
| 443 | |
| 444 | |
| 445 | def run_line(g, line, hypothesis="h"): |
| 446 | """One line of a script on a robbins.Goal (only the forms used in the |
| 447 | scripts above). `hypothesis` renames h (h1 in a Section).""" |
| 448 | line = re.sub(r"\bh\b", hypothesis, line) |
| 449 | m = _LINE.fullmatch(line.strip()) |
| 450 | if m is None: |
| 451 | raise TacticError(f"cannot run {line!r}") |
| 452 | tag, rules, k, nth, rfl = m.groups() |
| 453 | if rfl: |
| 454 | g.ac() |
| 455 | elif k: |
| 456 | g.nth_rw(int(k), *_rules(nth)) |
| 457 | elif tag == "auto": |
| 458 | auto(g, _rules(rules)) |
| 459 | else: |
| 460 | getattr(g, tag)(*_rules(rules)) |
| 461 | |
| 462 | |
| 463 | def script(lines, hypothesis="h"): |
| 464 | def run(g): |
| 465 | for line in lines: |
| 466 | run_line(g, line, hypothesis) |
| 467 | return run |
| 468 | |
| 469 | |
| 470 | def mccune_theorem(): |
| 471 | """McCune's three EQP proofs joined into one kernel: the 12 equations |
| 472 | of m5-50 in the Robbins algebra, Lemma 1 for C, D and Lemma 0 for C as |
| 473 | sections, then C := n(C + n(C)) (equation 1802), C := x + x and D := q |
| 474 | (equation 8871). Returns the kernel; its theorem huntington is |
| 475 | Huntington's equation from A1, A2 and R.""" |
| 476 | K = rb.theory() |
| 477 | m550, lemma1, lemma0 = (s["steps"] for s in |
| 478 | VARIANTS["mccune"]["stages"]) |
| 479 | for step in m550: |
| 480 | rb.lemma(K, step["name"], step["statement"], script(step["script"])) |
| 481 | S1 = rb.Section(K, "CD", ["D + C = C"]) |
| 482 | for step in lemma1: |
| 483 | S1.lemma(step["name"], step["statement"], |
| 484 | script(step["script"], "h1")) |
| 485 | S0 = rb.Section(K, "C", ["C + C = C"]) |
| 486 | for step in lemma0: |
| 487 | S0.lemma(step["name"], step["statement"], |
| 488 | script(step["script"], "h1")) |
| 489 | zero = term("n(C + n(C))") |
| 490 | S0.use(S1, {"C": zero}, Inst("eqp1802", (zero,)), prefix="l0_") |
| 491 | # C := a + a, D := q(a): a, not x, which the lemmas use themselves |
| 492 | winker = rb.Goal(K, f"{Q} + (a + a) = a + a") |
| 493 | winker.exact_ac(Inst("eqp8871", ("a",))) |
| 494 | S1.use(K, {"C": "a + a", "D": Q}, winker.qed(), prefix="l1_") |
| 495 | return K |
| 496 | |
| 497 | |
| 498 | def assemble(variant): |
| 499 | """The whole proof in one kernel: (kernel, name of the theorem).""" |
| 500 | if variant == "mann": |
| 501 | return rp.robbins_theorem(), "huntington" |
| 502 | return mccune_theorem(), "l1_l0_huntington" |
| 503 | |
| 504 | |
| 505 | # --- given facts: Mann's lemmas with hypotheses in robbins_ab ------------- |
| 506 | |
| 507 | def given(theory, kernel): |
| 508 | """Facts of a theory proved by the engine before the lab starts: |
| 509 | [(name, l, r, proof, note_pl, note_en)]. In robbins_ab these are the |
| 510 | instances of Mann's lemmas 38 and 40 (lemmas with hypotheses, which |
| 511 | the lab cannot state); the kernel checks them like any proof.""" |
| 512 | if theory != "robbins_ab": |
| 513 | return [] |
| 514 | M = rp.hypothetical_lemmas(rb.theory()) |
| 515 | hyp = rb.congr_n(Inst("h", ())) # n(A + B) = n(B) |
| 516 | K = rb.Library(dict(kernel.signature)) |
| 517 | K.facts, K.assumptions = dict(kernel.facts), dict(kernel.assumptions) |
| 518 | found = [] |
| 519 | |
| 520 | def add(name, proof, pl, en, statement=None): |
| 521 | if statement is not None: |
| 522 | g = rb.Goal(K, statement) |
| 523 | g.rw("hd") |
| 524 | g.exact_ac(proof) |
| 525 | proof = g.qed() |
| 526 | l, r = K.conclusion(proof) |
| 527 | K.theorem(name, (), l, r, proof) |
| 528 | found.append((name, l, r, proof, pl, en)) |
| 529 | |
| 530 | add("m38", M[38, 2]({"a": "A", "b": "B"}, hyp), |
| 531 | "lemat 38 Manna dla k = 2 (założenie: n(A + B) = n(B))", |
| 532 | "Mann's lemma 38 for k = 2 (hypothesis: n(A + B) = n(B))") |
| 533 | add("m40a", M["40a"]({"a": "A", "b": "B"}, hyp), |
| 534 | "lemat 40 Manna (założenie: n(A + B) = n(B))", |
| 535 | "Mann's lemma 40 (hypothesis: n(A + B) = n(B))") |
| 536 | proofs = {} |
| 537 | for name, statement, lines in MANN_3[:5]: # pair1 ... pair4 |
| 538 | g = rb.Goal(K, statement) |
| 539 | script(lines)(g) |
| 540 | proofs[name] = rb.transport(g.qed(), {}, proofs) |
| 541 | K.theorem(name, (), *K.conclusion(proofs[name]), proofs[name]) |
| 542 | add("m40b", M["40b"]({"a": "c", "b": "c"}, proofs["pair4"]), |
| 543 | "lemat 40 Manna dla a = b = c (założenie: pair4, dowiedzione " |
| 544 | "przez silnik tak samo)", |
| 545 | "Mann's lemma 40 for a = b = c (hypothesis: pair4, proved by " |
| 546 | "the engine the same way)", "c + (d + d) = c + (d + d + d)") |
| 547 | return [f for f in found if f[0] in ("m38", "m40a", "m40b")] |