Boolean algebra as an equational theory: Huntington's axioms (1904).
Code with colored syntax: click a line number to get a link to it; an underlined name leads to its definition.
| 1 | """Boolean algebra as an equational theory: Huntington's axioms (1904). |
| 2 | |
| 3 | Operations: x + y (sum), x * y (product), n(x) (complement), constants 0, 1. |
| 4 | Every theorem has a proof built with tactics and checked by the kernel. |
| 5 | """ |
| 6 | |
| 7 | from kernel import Kernel |
| 8 | from syntax import equation |
| 9 | from tactics import calc, rw, prove, variables |
| 10 | |
| 11 | SIGNATURE = {"+": 2, "*": 2, "n": 1, "0": 0, "1": 0} |
| 12 | |
| 13 | AXIOMS = [ |
| 14 | ("H1", "x + y = y + x"), |
| 15 | ("H2", "x * y = y * x"), |
| 16 | ("H3", "x + y * z = (x + y) * (x + z)"), |
| 17 | ("H4", "x * (y + z) = x * y + x * z"), |
| 18 | ("H5", "x + 0 = x"), |
| 19 | ("H6", "x * 1 = x"), |
| 20 | ("H7", "x + n(x) = 1"), |
| 21 | ("H8", "x * n(x) = 0"), |
| 22 | ] |
| 23 | |
| 24 | |
| 25 | def theory(): |
| 26 | """A new kernel with Huntington's axioms (no theorems yet).""" |
| 27 | j = Kernel(SIGNATURE) |
| 28 | for name, text in AXIOMS: |
| 29 | l, r = equation(text) |
| 30 | j.axiom(name, variables(r, variables(l)), l, r) |
| 31 | return j |
| 32 | |
| 33 | |
| 34 | # Theorems in order: each may use only the earlier ones. |
| 35 | THEOREMS = [ |
| 36 | ("add_idem", "x + x = x", calc( |
| 37 | "x + x", |
| 38 | ("(x + x) * 1", rw("H6")), |
| 39 | ("(x + x) * (x + n(x))", rw("H7")), |
| 40 | ("x + x * n(x)", rw("H3")), |
| 41 | ("x + 0", rw("H8")), |
| 42 | ("x", rw("H5")))), |
| 43 | ("mul_idem", "x * x = x", calc( |
| 44 | "x * x", |
| 45 | ("x * x + 0", rw("H5")), |
| 46 | ("x * x + x * n(x)", rw("H8")), |
| 47 | ("x * (x + n(x))", rw("H4")), |
| 48 | ("x * 1", rw("H7")), |
| 49 | ("x", rw("H6")))), |
| 50 | ("add_one", "x + 1 = 1", calc( |
| 51 | "x + 1", |
| 52 | ("(x + 1) * 1", rw("H6")), |
| 53 | ("1 * (x + 1)", rw("H2")), |
| 54 | ("(x + n(x)) * (x + 1)", rw("H7")), |
| 55 | ("x + n(x) * 1", rw("H3")), |
| 56 | ("x + n(x)", rw("H6")), |
| 57 | ("1", rw("H7")))), |
| 58 | ("mul_zero", "x * 0 = 0", calc( |
| 59 | "x * 0", |
| 60 | ("x * 0 + 0", rw("H5")), |
| 61 | ("0 + x * 0", rw("H1")), |
| 62 | ("x * n(x) + x * 0", rw("H8")), |
| 63 | ("x * (n(x) + 0)", rw("H4")), |
| 64 | ("x * n(x)", rw("H5")), |
| 65 | ("0", rw("H8")))), |
| 66 | ("absorb", "x + x * y = x", calc( |
| 67 | "x + x * y", |
| 68 | ("x * 1 + x * y", rw("H6")), |
| 69 | ("x * (1 + y)", rw("H4")), |
| 70 | ("x * (y + 1)", rw("H1")), |
| 71 | ("x * 1", rw("add_one")), |
| 72 | ("x", rw("H6")))), |
| 73 | ("compl_compl", "n(n(x)) = x", calc( |
| 74 | "n(n(x))", |
| 75 | ("n(n(x)) * 1", rw("H6")), |
| 76 | ("n(n(x)) * (x + n(x))", rw("H7")), |
| 77 | ("n(n(x)) * x + n(n(x)) * n(x)", rw("H4")), |
| 78 | ("n(n(x)) * x + 0", rw("H2 n(n(x)) n(x)", "H8")), |
| 79 | ("n(n(x)) * x + x * n(x)", rw("H8")), |
| 80 | ("x * n(n(x)) + x * n(x)", rw("H2")), |
| 81 | ("x * (n(n(x)) + n(x))", rw("H4")), |
| 82 | ("x * 1", rw("H1", "H7")), |
| 83 | ("x", rw("H6")))), |
| 84 | ] |
| 85 | |
| 86 | |
| 87 | def theory_with_theorems(): |
| 88 | """A kernel with the axioms and the theorems; returns their proofs too.""" |
| 89 | j = theory() |
| 90 | proofs = {} |
| 91 | for name, text, tactic in THEOREMS: |
| 92 | proofs[name] = prove(j, name, text, tactic) |
| 93 | return j, proofs |