"""The Boole Lab library: theorems of Boolean algebra from axioms H1–H8. Every theorem has a full tactic script in the language of the lab (lab.py): rw [ … ] with Lean semantics, nth_rw, rfl, symm, trans, exact. The theorems come in the order of dependence: a script may use only the axioms and the earlier theorems. At every start the lab replays the whole library — every proof goes through the kernel (Kernel.theorem) with the original statement — and scripts/lean_biblioteka.py translates the same scripts into Lean 4 and compiles them (lean/BooleLab.lean in Polish, lean/BooleLabEn.lean in English). Every theorem has an English name (the main one) and a Polish name used by the Polish edition (the Polish lab page, book and slides). The Polish lab renames the theorems in the scripts and translates their comments with COMMENTS_PL; the English text is the source. Associativity is the hardest: Huntington (1904) took it without proof, but it follows from H1–H8. The idea: A = x + (y + z) and B = (x + y) + z have the same products with x and with n(x) (x * A = x = x * B, n(x) * A = n(x) * (y + z) = n(x) * B), and every term splits as y = x * y + n(x) * y (split_along). De Morgan's law: n(x) * n(y) is a complement of x + y, and a complement is unique — the chain b = b*1 = b*(a + n(a)) = b*a + b*n(a) = a*n(a) + b*n(a) = (a + b)*n(a) = 1*n(a) = n(a) with a = x + y, b = n(x) * n(y). The later sections (added 2026-12-02, after the lecture) use abbreviations expanded by the lab's parser (lab.ABBREVIATIONS): med(x, y, z) = x*y + x*z + y*z, xor(x, y) = x*n(y) + n(x)*y, ite(p, a, b) = p*a + n(p)*b, nand(x, y) = n(x*y). The kernel and Lean see only +, *, n, 0, 1. * A single axiom: DN1 and Sh1 from W. McCune, R. Veroff, B. Fitelson, K. Harris, A. Feist, L. Wos, "Short Single Axioms for Boolean Algebra", J. Automated Reasoning 29 (2002) — each of these equations alone is an axiom system for Boolean algebra (DN1 in the language +, n; Sh1 in the language of the Sheffer stroke); here only the easy direction: both equations hold. The basis {(x|y)|(x|(y|z)) = x, x|y = y|x}: R. Veroff, "A Shortest 2-Basis for Boolean Algebra in Terms of the Sheffer Stroke". * Median algebra: distributivity of the median — a problem D. Knuth passed to R. Veroff and W. McCune (the first equational proof from the median axioms alone was found by theorem provers); in a Boolean algebra the observation med(t, u, v) = a + b * t with a = u * v, b = u + v is enough. * Symmetric difference: a Boolean algebra as a ring (xor, *). * Boolean differences: the derivative of f in z is f(z) ⊕ f(n(z)); the product rule has a third term. * Decisions and cycles: ite and swapping the order of tests, cycles of implications. """ def thm(name, name_pl, equation, desc_pl, desc_en, script): return {"name": name, "name_pl": name_pl, "equation": equation, "desc_pl": desc_pl, "desc_en": desc_en, "script": script} # Polish versions of the script comments (comments without words — pure # algebra — are the same in both languages). COMMENTS_PL = { "-- (x + n(x)) * (x + 1): only the first 1": "-- (x + n(x)) * (x + 1): tylko pierwsza 1", "-- x * n(x) + x * 0: only the first 0": "-- x * n(x) + x * 0: tylko pierwsze 0", "-- A = x * A + n(x) * A and B = x * B + n(x) * B (split_along)": "-- A = x * A + n(x) * A i B = x * B + n(x) * B (rozbicie)", "-- x * A = x, n(x) * A = n(x) * (y + z) and the same for B": "-- x * A = x, n(x) * A = n(x) * (y + z) i to samo dla B", "-- n(x) * n(y) is a complement of x + y; complements are unique": "-- n(x) * n(y) jest dopełnieniem x + y, a dopełnienie jest jedyne", "-- n(n(z) + n(z + u)) = z * (z + u) = z: the variable u vanishes": "-- n(n(z) + n(z + u)) = z * (z + u) = z: zmienna u znika", "-- left half: n(x * y), right half: n(y) + z * x, product: n(y)": "-- lewa połowa: n(x * y), prawa: n(y) + z * x, iloczyn: n(y)", "-- (a + b * x) * (a + b * y) = a + b * (x * y) for each pair": "-- (a + b * x) * (a + b * y) = a + b * (x * y) dla każdej pary", "-- both sides are a + b * (…) for a = u * v and b = u + v": "-- obie strony to a + b * (…) dla a = u * v i b = u + v", "-- as med_distrib, but all the arguments are transformed": "-- jak med_rozdz, ale przekształcone są wszystkie argumenty", "-- both sides: the sum of the minterms with an odd number of 1s": "-- obie strony to suma mintermów z nieparzystą liczbą jedynek", "-- x + y = xor(x, y) + x * y, and x * y absorbs z * x * y": "-- x + y = xor(x, y) + x * y, a x * y wchłania z * x * y", "-- in the ring: x ⊕ (x ⊕ xy ⊕ xz ⊕ yz) = xy ⊕ xz ⊕ yz": "-- w pierścieniu: x ⊕ (x ⊕ xy ⊕ xz ⊕ yz) = xy ⊕ xz ⊕ yz", "-- med seen from x; a shift keeps the differences x ⊕ y": "-- med widziana z x; przesunięcie nie zmienia różnic x ⊕ y", "-- med = xy ⊕ z(x ⊕ y): xy cancels, the difference remains": "-- med = xy ⊕ z(x ⊕ y): xy się skraca, zostaje różnica", "-- w = n(z) and xor(z, n(z)) = 1": "-- w = n(z) i xor(z, n(z)) = 1", "-- (a ⊕ b)(c ⊕ d) = ac ⊕ bc ⊕ ad ⊕ bd; ac cancels ac": "-- (a ⊕ b)(c ⊕ d) = ac ⊕ bc ⊕ ad ⊕ bd; ac skraca się z ac", "-- both sides: the regions p * q, p * n(q), n(p) * q, n(p) * n(q)": "-- obie strony: obszary p * q, p * n(q), n(p) * q, n(p) * n(q)", "-- (n(x)n(y) + yz)(n(z) + x): only two products survive": "-- (n(x)n(y) + yz)(n(z) + x): przeżywają tylko dwa iloczyny", "-- pairs of implications: (n(x)n(y) + yz)(n(z)n(w) + wx)": "-- pary implikacji: (n(x)n(y) + yz)(n(z)n(w) + wx)", } SECTIONS = [ {"title": "Basics", "title_pl": "Podstawy", "theorems": [ thm("zero_add", "zero_plus", "0 + x = x", "zero z lewej", "zero on the left", "rw [H1, H5]"), thm("one_mul", "jeden_razy", "1 * x = x", "jedynka z lewej", "one on the left", "rw [H2, H6]"), thm("compl_add", "n_plus", "n(x) + x = 1", "dopełnienie z lewej", "complement on the left", "rw [H1, H7]"), thm("compl_mul", "n_razy", "n(x) * x = 0", "dopełnienie z lewej", "complement on the left", "rw [H2, H8]"), thm("add_idem", "idem_plus", "x + x = x", "idempotentność sumy (jak na wykładzie)", "idempotence of + (as in the lecture)", """ rw [← H6 (x + x)] -- (x + x) * 1 rw [← H7 x] -- (x + x) * (x + n(x)) rw [← H3] -- x + x * n(x) rw [H8, H5] -- x + 0, x """), thm("mul_idem", "idem_razy", "x * x = x", "idempotentność iloczynu", "idempotence of *", """ rw [← H5 (x * x), ← H8 x] -- x * x + x * n(x) rw [← H4, H7, H6] -- x * (x + n(x)), x * 1, x """), thm("add_one", "plus_jeden", "x + 1 = 1", "jedynka pochłania sumę", "one absorbs the sum", """ rw [← H6 (x + 1), H2] -- 1 * (x + 1) nth_rw 1 [← H7 x] -- (x + n(x)) * (x + 1): only the first 1 rw [← H3, H6, H7] -- x + n(x) * 1, x + n(x), 1 """), thm("one_add", "jeden_plus", "1 + x = 1", "jedynka pochłania sumę z lewej", "one absorbs the sum on the left", "rw [H1, add_one]"), thm("mul_zero", "razy_zero", "x * 0 = 0", "zero pochłania iloczyn", "zero absorbs the product", """ rw [← H5 (x * 0), H1] -- 0 + x * 0 nth_rw 1 [← H8 x] -- x * n(x) + x * 0: only the first 0 rw [← H4, H5, H8] -- x * (n(x) + 0), x * n(x), 0 """), thm("zero_mul", "zero_razy", "0 * x = 0", "zero pochłania iloczyn z lewej", "zero absorbs the product on the left", "rw [H2, mul_zero]"), ]}, {"title": "Absorption", "title_pl": "Pochłanianie", "theorems": [ thm("absorb", "pochlanianie", "x + x * y = x", "prawo pochłaniania", "absorption law", """ nth_rw 1 [← H6 x] -- x * 1 + x * y rw [← H4, H1, add_one, H6] -- x * (1 + y), x * (y + 1), x """), thm("absorb_mul", "pochlanianie_razy", "x * (x + y) = x", "pochłanianie dla iloczynu", "absorption for *", "rw [H4, mul_idem, absorb]"), thm("absorb_right", "pochlanianie_prawe", "x * y + x = x", "pochłanianie z prawej", "absorption on the right", "rw [H1, absorb]"), thm("absorb_mul_right", "pochlanianie_razy_prawe", "(x + y) * x = x", "pochłanianie dla iloczynu z prawej", "absorption for * on the right", "rw [H2, absorb_mul]"), thm("add_compl_mul", "plus_n_razy", "x + n(x) * y = x + y", "x wchłania dopełnienie w iloczynie", "x absorbs its complement inside a product", "rw [H3, H7, one_mul]"), thm("mul_compl_add", "razy_n_plus", "x * (n(x) + y) = x * y", "dualnie: dopełnienie w sumie znika", "dually: the complement inside a sum vanishes", "rw [H4, H8, zero_add]"), thm("compl_add_mul", "n_plus_razy", "n(x) + x * y = n(x) + y", "to samo dla n(x)", "the same for n(x)", "rw [H3, compl_add, one_mul]"), thm("compl_mul_add", "n_razy_plus", "n(x) * (x + y) = n(x) * y", "to samo dla n(x), dualnie", "the same for n(x), dually", "rw [H4, compl_mul, zero_add]"), ]}, {"title": "Complement", "title_pl": "Dopełnienie", "theorems": [ thm("compl_zero", "n_zero", "n(0) = 1", "dopełnienie zera", "complement of zero", "rw [← zero_add n(0), H7]"), thm("compl_one", "n_jeden", "n(1) = 0", "dopełnienie jedynki", "complement of one", "rw [← one_mul n(1), H8]"), thm("compl_compl", "inwolucja", "n(n(x)) = x", "podwójne dopełnienie (łańcuch z wykładu)", "double complement (the chain from the lecture)", """ rw [← H6 n(n(x)), ← H7 x, H4] -- n(n(x)) * x + n(n(x)) * n(x) rw [H2 n(n(x)) n(x), H8] -- n(n(x)) * x + 0 rw [← H8 x, H2 n(n(x)) x, ← H4] -- x * (n(n(x)) + n(x)) rw [H1, H7, H6] -- x * 1, x """), thm("merge", "sklejanie", "x * y + x * n(y) = x", "sklejanie", "combining", "rw [← H4, H7, H6]"), thm("merge_mul", "sklejanie_plus", "(x + y) * (x + n(y)) = x", "sklejanie, dualnie", "combining, dually", "rw [← H3, H8, H5]"), thm("split_along", "rozbicie", "x * y + n(x) * y = y", "rozbicie y według x (klucz do łączności)", "splitting y along x (the key to associativity)", "rw [H2 x y, H2 n(x) y, ← H4, H7, H6]"), thm("split_along_mul", "rozbicie_plus", "(x + y) * (n(x) + y) = y", "rozbicie, dualnie", "splitting, dually", "rw [H1 x y, H1 n(x) y, ← H3, H8, H5]"), ]}, {"title": "Distributivity", "title_pl": "Rozdzielność", "theorems": [ thm("add_mul", "rozdz_prawa_razy", "(x + y) * z = x * z + y * z", "rozdzielność iloczynu z prawej", "distributivity of * on the right", "rw [H2, H4, H2 z x, H2 z y]"), thm("add_distrib_right", "rozdz_prawa_plus", "x * y + z = (x + z) * (y + z)", "rozdzielność sumy z prawej", "distributivity of + on the right", "rw [H1, H3, H1 z x, H1 z y]"), thm("add_mul_add", "rozdz_podwojna", "(x + y) * (z + w) = x * z + x * w + (y * z + y * w)", "wymnażanie dwóch sum", "multiplying out two sums", "rw [add_mul, H4, H4]"), ]}, {"title": "Associativity", "title_pl": "Łączność", "theorems": [ thm("assoc_lemma_1", "laczn_lemat_1", "x * (x + y + z) = x", "x * B = x", "x * B = x", "rw [H4, absorb_mul, absorb]"), thm("assoc_lemma_2", "laczn_lemat_2", "n(x) * (x + y + z) = n(x) * (y + z)", "n(x) * B = n(x) * (y + z)", "n(x) * B = n(x) * (y + z)", "rw [H4, compl_mul_add, ← H4]"), thm("add_assoc", "laczn_plus", "x + (y + z) = x + y + z", "łączność sumy (nie ma jej wśród H1–H8!)", "associativity of + (not among H1–H8!)", """ -- A = x * A + n(x) * A and B = x * B + n(x) * B (split_along) rw [← split_along x (x + (y + z)), ← split_along x (x + y + z)] -- x * A = x, n(x) * A = n(x) * (y + z) and the same for B rw [absorb_mul, compl_mul_add, assoc_lemma_1, assoc_lemma_2] """), thm("assoc_lemma_3", "laczn_lemat_3", "x + x * y * z = x", "x + B = x, dualnie", "x + B = x, dually", "rw [H3, absorb, absorb_mul]"), thm("assoc_lemma_4", "laczn_lemat_4", "n(x) + x * y * z = n(x) + y * z", "n(x) + B = n(x) + y * z", "n(x) + B = n(x) + y * z", "rw [H3, compl_add_mul, ← H3]"), thm("mul_assoc", "laczn_razy", "x * (y * z) = x * y * z", "łączność iloczynu", "associativity of *", """ rw [← split_along_mul x (x * (y * z))] rw [← split_along_mul x (x * y * z)] rw [absorb, compl_add_mul, assoc_lemma_3, assoc_lemma_4] """), thm("add_left_comm", "lewa_przem_plus", "x + (y + z) = y + (x + z)", "przemienność z lewej (sumy)", "left commutativity of +", "rw [add_assoc, H1 x y, ← add_assoc]"), thm("mul_left_comm", "lewa_przem_razy", "x * (y * z) = y * (x * z)", "przemienność z lewej (iloczyny)", "left commutativity of *", "rw [mul_assoc, H2 x y, ← mul_assoc]"), thm("add_right_comm", "prawa_przem_plus", "x + y + z = x + z + y", "przemienność z prawej (sumy)", "right commutativity of +", "rw [← add_assoc, H1 y z, add_assoc]"), thm("mul_right_comm", "prawa_przem_razy", "x * y * z = x * z * y", "przemienność z prawej (iloczyny)", "right commutativity of *", "rw [← mul_assoc, H2 y z, mul_assoc]"), thm("add_idem_left", "idem_plus_lewe", "x + (x + y) = x + y", "x dodane drugi raz", "adding x a second time", "rw [add_assoc, add_idem]"), thm("add_compl_add", "plus_n_jeden", "x + (n(x) + y) = 1", "suma z dopełnieniem to 1", "a sum with the complement is 1", "rw [add_assoc, H7, one_add]"), thm("mul_compl_mul", "razy_n_zero", "x * (n(x) * y) = 0", "iloczyn z dopełnieniem to 0", "a product with the complement is 0", "rw [mul_assoc, H8, zero_mul]"), thm("modular", "modularnosc", "x + y * (x + z) = (x + y) * (x + z)", "prawo modularności", "the modular law", "rw [H3, add_idem_left]"), ]}, {"title": "De Morgan's laws", "title_pl": "Prawa De Morgana", "theorems": [ thm("dm_one", "dm_jeden", "x + y + n(x) * n(y) = 1", "x + y i n(x) * n(y) dają razem 1", "x + y and n(x) * n(y) add up to 1", """ rw [H3] -- (x + y + n(x)) * (x + y + n(y)) rw [← add_assoc x y n(y), H7, add_one] rw [H1 x y, ← add_assoc y x n(x), H7, add_one, H6] """), thm("dm_zero", "dm_zero", "(x + y) * (n(x) * n(y)) = 0", "x + y i n(x) * n(y) są rozłączne", "x + y and n(x) * n(y) are disjoint", "rw [add_mul, mul_compl_mul, H2 n(x) n(y), mul_compl_mul, H5]"), thm("de_morgan_add", "de_morgan_plus", "n(x + y) = n(x) * n(y)", "prawo De Morgana dla sumy", "De Morgan's law for +", """ -- n(x) * n(y) is a complement of x + y; complements are unique rw [← H6 (n(x) * n(y)), ← H7 (x + y), H4] rw [H2 (n(x) * n(y)) (x + y), dm_zero] rw [← H8 (x + y), ← add_mul, dm_one, one_mul] """), thm("de_morgan_mul", "de_morgan_razy", "n(x * y) = n(x) + n(y)", "prawo De Morgana dla iloczynu", "De Morgan's law for *", """ rw [← compl_compl (n(x) + n(y)), de_morgan_add, compl_compl] rw [compl_compl] """), thm("de_morgan_add_compl", "de_morgan_n_plus", "n(x + n(y)) = n(x) * y", "De Morgan z dopełnieniem", "De Morgan with a complement", "rw [de_morgan_add, compl_compl]"), thm("de_morgan_mul_compl", "de_morgan_n_razy", "n(x * n(y)) = n(x) + y", "to samo dla iloczynu", "the same for *", "rw [de_morgan_mul, compl_compl]"), thm("mul_via_add", "razy_przez_plus", "n(n(x) + n(y)) = x * y", "iloczyn wyrażony sumą i dopełnieniem", "the product expressed by + and n", "rw [de_morgan_add, compl_compl, compl_compl]"), thm("add_via_mul", "plus_przez_razy", "n(n(x) * n(y)) = x + y", "suma wyrażona iloczynem i dopełnieniem", "the sum expressed by * and n", "rw [de_morgan_mul, compl_compl, compl_compl]"), thm("de_morgan_add3", "de_morgan_plus3", "n(x + y + z) = n(x) * n(y) * n(z)", "De Morgan dla trzech składników", "De Morgan for three terms", "rw [de_morgan_add, de_morgan_add]"), thm("add_compl_sum", "plus_n_sumy", "x + n(x + y) = x + n(y)", "x wchłania dopełnienie sumy", "x absorbs the complement of a sum", "rw [de_morgan_add, add_compl_mul]"), thm("mul_compl_prod", "razy_n_iloczynu", "x * n(x * y) = x * n(y)", "dualnie", "dually", "rw [de_morgan_mul, mul_compl_add]"), ]}, {"title": "Huntington and Robbins", "title_pl": "Huntington i Robbins", "theorems": [ thm("huntington", "huntington", "n(n(x) + y) + n(n(x) + n(y)) = x", "aksjomat Huntingtona (1933) zachodzi", "Huntington's axiom (1933) holds", """ rw [de_morgan_add, de_morgan_add, compl_compl, compl_compl, ← H4] rw [compl_add, H6] """), thm("robbins", "robbins", "n(n(x + y) + n(x + n(y))) = x", "równanie Robbinsa zachodzi (odwrotnie: EQP, 1996)", "the Robbins equation holds (the converse: EQP, 1996)", "rw [de_morgan_add, compl_compl, compl_compl, ← H3, H8, H5]"), thm("huntington_mul", "huntington_razy", "n(n(x) * y) * n(n(x) * n(y)) = x", "aksjomat Huntingtona, dualnie", "Huntington's axiom, dually", """ rw [de_morgan_mul, de_morgan_mul, compl_compl, compl_compl, ← H3] rw [compl_mul, H5] """), thm("robbins_mul", "robbins_razy", "n(n(x * y) * n(x * n(y))) = x", "równanie Robbinsa, dualnie", "the Robbins equation, dually", "rw [de_morgan_mul, compl_compl, compl_compl, ← H4, H7, H6]"), ]}, {"title": "Consensus and majority", "title_pl": "Konsensus i mediana", "theorems": [ thm("consensus", "konsensus", "x * y + n(x) * z + y * z = x * y + n(x) * z", "twierdzenie o konsensusie", "the consensus theorem", """ rw [← H6 (y * z), ← H7 x, H4] -- y * z = y * z * x + y * z * n(x) rw [H2 (y * z) x, mul_assoc] -- x * y * z rw [H2 (y * z) n(x), H2 y z, mul_assoc] -- n(x) * z * y rw [add_assoc, add_right_comm (x * y) (n(x) * z) (x * y * z)] rw [absorb, ← add_assoc, absorb] """), thm("consensus_mul", "konsensus_razy", "(x + y) * (n(x) + z) * (y + z) = (x + y) * (n(x) + z)", "konsensus, dualnie", "consensus, dually", """ rw [← H5 (y + z), ← H8 x, H3] rw [H1 (y + z) x, add_assoc] rw [H1 (y + z) n(x), H1 y z, add_assoc] rw [mul_assoc, mul_right_comm (x + y) (n(x) + z) (x + y + z)] rw [absorb_mul, ← mul_assoc, absorb_mul] """), thm("median_self_dual", "mediana", "(x + y) * (y + z) * (z + x) = x * y + y * z + z * x", "mediana (funkcja większości) jest samodualna", "the median (majority) is self-dual", """ rw [H1 x y, ← H3] -- (y + x * z) * (z + x) rw [add_mul, H4] -- y * z + y * x + x * z * (z + x) rw [← mul_assoc x z (z + x), absorb_mul] rw [H2 x y, H2 z x, H1 (y * z) (y * x)] """), ]}, {"title": "A single axiom", "title_pl": "Jeden aksjomat", "theorems": [ thm("dn1", "dn1", "n(n(n(x + y) + z) + n(x + n(n(z) + n(z + u)))) = z", "DN1 (McCune i in., 2002): jedno równanie z + i n zastępuje " "wszystkie aksjomaty", "DN1 (McCune et al., 2002): one equation in + and n replaces " "all the axioms", """ -- n(n(z) + n(z + u)) = z * (z + u) = z: the variable u vanishes rw [de_morgan_add, compl_compl, compl_compl] rw [de_morgan_add n(z) n(z + u), compl_compl, compl_compl] rw [absorb_mul] rw [← add_distrib_right] rw [de_morgan_add, H2 (n(x) * n(y)) x, mul_assoc, H8, zero_mul] rw [zero_add] """), thm("sh1", "sh1", "nand(nand(x, nand(nand(y, x), x)), nand(y, nand(z, x))) = y", "Sh1: jeden aksjomat w samej kresce Sheffera, najkrótszy możliwy", "Sh1: a single axiom in the Sheffer stroke alone, the shortest " "possible", """ -- left half: n(x * y), right half: n(y) + z * x, product: n(y) rw [de_morgan_mul (n(y * x)) x, compl_compl (y * x)] rw [H1 (y * x) n(x), mul_compl_add x (y * x), H2 y x, mul_assoc] rw [mul_idem] rw [de_morgan_mul y (n(z * x)), compl_compl (z * x)] rw [de_morgan_mul x y] rw [H1 n(x) n(y), ← H3, H2 z x, mul_assoc, compl_mul, zero_mul, H5] rw [compl_compl] """), thm("sheffer_basis", "sheffer_baza", "nand(nand(x, y), nand(x, nand(y, z))) = x", "z przemiennością nand: najkrótsza baza z dwóch równań (Veroff)", "with commutativity of nand: the shortest 2-basis (Veroff)", """ -- x * y + x * n(y * z) = x * (y + n(y) + n(z)) = x rw [add_via_mul, ← H4, de_morgan_mul, add_compl_add, H6] """), ]}, {"title": "Median algebra", "title_pl": "Algebra mediany", "theorems": [ thm("med_ab", "med_ab", "med(t, u, v) = u * v + (u + v) * t", "mediana jako funkcja jednego argumentu: u * v + (u + v) * t", "the median as a function of one argument: u * v + (u + v) * t", "rw [H1, ← H4, ← H2 (u + v)]"), thm("mul_common", "iloczyn_wspolny", "x * y * (x * z) = x * (y * z)", "wspólny czynnik dwóch iloczynów", "a common factor of two products", """ rw [← mul_assoc x y (x * z), mul_left_comm y x z] rw [mul_assoc x x (y * z), mul_idem] """), thm("med_affine", "med_afiniczna", "med(a + b * x, a + b * y, a + b * z) = a + b * med(x, y, z)", "mediana przemienna z przekształceniami t ↦ a + b * t", "the median commutes with the maps t ↦ a + b * t", """ -- (a + b * x) * (a + b * y) = a + b * (x * y) for each pair trans a + b * (x * y) + (a + b * (x * z)) + (a + b * (y * z)) rw [← H3 a (b * x) (b * y), ← H3 a (b * x) (b * z)] rw [← H3 a (b * y) (b * z)] rw [mul_common b x y, mul_common b x z] rw [mul_common b y z] rw [add_assoc, add_assoc, mul_assoc, mul_assoc, mul_assoc] rw [add_right_comm a, add_idem, add_right_comm (a + b * x * y)] rw [add_right_comm a, add_idem, ← mul_assoc b y] rw [← mul_assoc b x z, ← mul_assoc, ← add_assoc a, ← add_assoc] rw [← H4, ← H4] """), thm("med_affine_2", "med_afiniczna_2", "med(x, a + b * y, a + b * z) = a + b * med(x, y, z)", "to samo, gdy pierwszy argument się nie zmienia", "the same with the first argument unchanged", """ rw [← H3 a (b * y) (b * z), mul_common b y z] rw [H4 x a (b * y), H4 x a (b * z), mul_left_comm x b y] rw [mul_left_comm x b z] rw [add_assoc, add_assoc, mul_assoc, mul_assoc, mul_assoc] nth_rw 1 [H2 x a] rw [H2 x, add_right_comm (a * x), add_idem] rw [add_right_comm (a * x + b * x * y), add_right_comm (a * x)] rw [H1 (a * x), absorb, ← mul_assoc b y, ← mul_assoc b x z] rw [← mul_assoc, ← add_assoc a, ← add_assoc, ← H4, ← H4] """), thm("med_distrib", "med_rozdz", "med(med(x, y, z), u, v) = med(x, med(y, u, v), med(z, u, v))", "rozdzielność mediany (wyzwanie od Knutha dla dowodzenia " "automatycznego)", "distributivity of the median (a challenge from Knuth for " "automated proving)", """ -- both sides are a + b * (…) for a = u * v and b = u + v rw [med_ab (med(x, y, z)) u v, med_ab y u v, med_ab z u v] rw [med_affine_2] """), thm("med_distrib_sym", "med_rozdz_sym", "med(med(x, y, z), u, v) = " "med(med(x, u, v), med(y, u, v), med(z, u, v))", "rozdzielność mediany, postać symetryczna", "distributivity of the median, symmetric form", """ -- as med_distrib, but all the arguments are transformed rw [med_ab (med(x, y, z)) u v, med_ab x u v, med_ab y u v] rw [med_ab z u v, med_affine] """), ]}, {"title": "Symmetric difference", "title_pl": "Różnica symetryczna", "theorems": [ thm("xor_comm", "xor_przem", "xor(x, y) = xor(y, x)", "różnica symetryczna jest przemienna", "symmetric difference is commutative", "rw [H1, H2, ← H2 n(y)]"), thm("xor_zero", "xor_zero", "xor(x, 0) = x", "0 jest elementem neutralnym", "0 is neutral", "rw [xor_comm, zero_mul, add_compl_mul, zero_add]"), thm("zero_xor", "xor_zero_lewe", "xor(0, x) = x", "0 z lewej", "0 on the left", "rw [xor_comm, xor_zero]"), thm("xor_one", "xor_jeden", "xor(x, 1) = n(x)", "dopełnienie to dodanie 1", "the complement is adding 1", "rw [compl_one, mul_zero, zero_add, H6]"), thm("xor_self", "xor_samo", "xor(x, x) = 0", "każdy element jest swoim przeciwnym", "every element is its own negative", "rw [compl_mul, H5, H8]"), thm("xor_compl", "xor_dopelnienie", "xor(x, n(x)) = 1", "x i n(x) różnią się wszędzie", "x and n(x) differ everywhere", "rw [xor_comm, mul_idem, add_compl_mul, compl_add]"), thm("mul_xor", "razy_xor", "x * xor(y, z) = xor(x * y, x * z)", "mnożenie jest rozdzielne względem xor", "* distributes over xor", """ rw [de_morgan_mul, de_morgan_mul, H4 (x * y), add_mul] rw [add_assoc, mul_assoc, mul_assoc, mul_right_comm, H8] rw [zero_mul, zero_add, H2 n(x), H8, zero_mul, H5, H2 n(y) x] rw [← mul_assoc x n(y), ← mul_assoc, ← H4] """), thm("xor_mul", "xor_razy", "xor(x, y) * z = xor(x * z, y * z)", "to samo z prawej", "the same on the right", "rw [H2 (xor(x, y)) z, mul_xor z x y, H2 z x, H2 z y]"), thm("xor_assoc", "xor_lacz", "xor(xor(x, y), z) = xor(x, xor(y, z))", "xor jest łączny: algebra Boole'a to pierścień", "xor is associative: a Boolean algebra is a ring", """ -- both sides: the sum of the minterms with an odd number of 1s trans x * y * z + x * n(y) * n(z) + n(x) * y * n(z) + n(x) * n(y) * z rw [de_morgan_add, de_morgan_mul, compl_compl, de_morgan_mul] rw [compl_compl, ← H1 (x * n(y) * n(z))] rw [← add_right_comm (x * n(y) * n(z)), ← H2 y x, ← add_assoc] rw [← add_mul (y * x), ← H5 (n(x) * n(y)), ← H8 y] rw [← add_mul n(x), ← zero_add (y * x), ← compl_mul x] rw [← add_mul n(x), ← H4, ← add_mul] rw [← mul_right_comm, ← mul_assoc n(x) n(y), ← mul_assoc n(x)] rw [← mul_assoc x n(y), ← mul_assoc, ← add_assoc, ← H4 n(x), ← H4] rw [← H5 (n(y) * n(z)), ← H8 z, ← add_mul, ← zero_add (z * y)] rw [← compl_mul y, ← add_mul, ← H4, de_morgan_add] rw [de_morgan_mul, compl_compl, de_morgan_mul, compl_compl] """), thm("xor_right_comm", "xor_prawa_przem", "xor(xor(x, y), z) = xor(xor(x, z), y)", "przemienność z prawej (xor)", "right commutativity of xor", "rw [xor_assoc, xor_comm y z, ← xor_assoc]"), thm("xor_shift", "xor_przesun", "xor(xor(x, t), xor(y, t)) = xor(x, y)", "przesunięcie o t nie zmienia różnicy", "a shift by t keeps the difference", """ rw [xor_assoc x t (xor(y, t)), xor_comm t (xor(y, t))] rw [xor_assoc y t t, xor_self t, xor_zero y] """), thm("xor_shift_left", "xor_przesun_lewe", "xor(xor(t, x), xor(t, y)) = xor(x, y)", "to samo z t z lewej", "the same with t on the left", "rw [xor_comm t x, xor_comm t y, xor_shift x t y]"), thm("add_via_xor", "plus_przez_xor", "x + y = xor(x, y) + x * y", "suma to różnica symetryczna plus iloczyn", "or is symmetric difference plus and", "rw [H1 (x * n(y) + n(x) * y), add_assoc, merge, add_compl_mul]"), thm("xor_le_nand", "xor_pod_nand", "n(x * y) * xor(x, y) = xor(x, y)", "xor leży pod nand", "xor lies below nand", """ rw [de_morgan_mul, H4, add_mul, add_mul] rw [add_assoc, mul_assoc, mul_assoc, mul_assoc, mul_assoc] rw [H2 n(x), H8, zero_mul, zero_add, H2 n(y), ← mul_assoc] rw [mul_idem, mul_idem, H2 n(y), mul_right_comm, ← mul_assoc] rw [H8, mul_zero, H5] """), thm("mul_le_xnor", "iloczyn_pod_xnor", "x * y * n(xor(x, y)) = x * y", "iloczyn leży pod dopełnieniem xor", "the product lies below the complement of xor", """ rw [de_morgan_add, de_morgan_mul, compl_compl, de_morgan_mul] rw [compl_compl, H4, add_mul, compl_mul, zero_add] rw [add_mul, H8, H5, H4, mul_assoc, mul_assoc] rw [← mul_assoc x, mul_idem, mul_right_comm, mul_idem] rw [mul_right_comm x, H8, zero_mul, zero_mul, H5] """), thm("xor_disjoint", "xor_rozl", "xor(x * y, z * xor(x, y)) = x * y + z * xor(x, y)", "dla rozłącznych składników suma to xor", "for disjoint parts, or is xor", """ rw [de_morgan_mul z (xor(x, y)), H4 (x * y) n(z) (n(xor(x, y)))] rw [mul_le_xnor x y] rw [H1 (x * y * n(z)) (x * y), absorb (x * y) n(z)] rw [mul_left_comm n(x * y) z (xor(x, y)), xor_le_nand x y] """), thm("med_xy", "med_xy", "med(x, y, z) = x * y + z * xor(x, y)", "mediana: zgoda x i y albo rozstrzyga z", "the median: x and y agree, or z decides", """ -- x + y = xor(x, y) + x * y, and x * y absorbs z * x * y rw [← add_assoc (x * y) (x * z) (y * z), ← add_mul x y z] rw [add_via_xor x y] rw [add_mul (xor(x, y)) (x * y) z] rw [H1 (xor(x, y) * z) (x * y * z)] rw [add_assoc, absorb (x * y) z, H2 (xor(x, y)) z] """), thm("med_split", "med_rozklad", "med(x, y, z) = xor(x * y, z * xor(x, y))", "to samo w języku pierścienia", "the same in the ring language", "rw [med_xy x y z, ← xor_disjoint x y z]"), thm("med_xor", "med_xor", "med(x, y, z) = xor(xor(x * y, x * z), y * z)", "mediana jako wielomian: xy ⊕ xz ⊕ yz", "the median as a polynomial: xy ⊕ xz ⊕ yz", "rw [med_split, mul_xor z x y, H2 z x, H2 z y, ← xor_assoc]"), thm("med_from_x", "med_od_x", "med(x, y, z) = xor(x, xor(x, y) * xor(x, z))", "mediana widziana z punktu x", "the median seen from the point x", """ -- in the ring: x ⊕ (x ⊕ xy ⊕ xz ⊕ yz) = xy ⊕ xz ⊕ yz rw [mul_xor (xor(x, y)) x z, xor_mul x y x, mul_idem x] rw [xor_mul x y z] rw [← xor_assoc x (xor(x, y * x)) (xor(x * z, y * z))] rw [← xor_assoc x x (y * x)] rw [xor_self x, zero_xor (y * x), H2 y x] rw [← xor_assoc (x * y) (x * z) (y * z), ← med_xor x y z] """), thm("med_shift", "med_przesuniecie", "med(xor(x, t), xor(y, t), xor(z, t)) = xor(med(x, y, z), t)", "przesunięcie o t (xor) zachowuje medianę", "a shift by t (xor) preserves the median", """ -- med seen from x; a shift keeps the differences x ⊕ y rw [med_from_x (xor(x, t)) (xor(y, t)) (xor(z, t))] rw [xor_shift x t y] rw [xor_shift x t z] rw [xor_right_comm x t (xor(x, y) * xor(x, z)), ← med_from_x x y z] """), ]}, {"title": "Boolean differences", "title_pl": "Różnice boolowskie", "theorems": [ thm("med_sensitivity", "med_wrazliwosc", "xor(med(x, y, z), med(x, y, w)) = xor(x, y) * xor(z, w)", "kiedy trzeci głos zmienia wynik większości", "when the third vote changes the majority", """ -- med = xy ⊕ z(x ⊕ y): xy cancels, the difference remains rw [med_split x y z, med_split x y w] rw [xor_shift_left (x * y) (z * xor(x, y)) (w * xor(x, y))] rw [← xor_mul z w (xor(x, y)), H2 (xor(z, w)) (xor(x, y))] """), thm("med_derivative", "pochodna_med", "xor(med(x, y, z), med(x, y, n(z))) = xor(x, y)", "pochodna boolowska mediany po z to xor(x, y)", "the Boolean derivative of the median in z is xor(x, y)", """ -- w = n(z) and xor(z, n(z)) = 1 rw [med_sensitivity x y z n(z), xor_compl z, H6] """), thm("product_rule", "regula_iloczynu", "xor(xor(a, b) * xor(c, d), a * c) = " "xor(xor(a * d, b * c), b * d)", "reguła iloczynu dla różnic boolowskich: z trzecim składnikiem", "the product rule for Boolean differences: with a third term", """ -- (a ⊕ b)(c ⊕ d) = ac ⊕ bc ⊕ ad ⊕ bd; ac cancels ac rw [mul_xor (xor(a, b)) c d, xor_mul a b c, xor_mul a b d] rw [xor_right_comm (xor(a * c, b * c)) (xor(a * d, b * d)) (a * c)] rw [xor_right_comm (a * c) (b * c) (a * c), xor_self (a * c)] rw [zero_xor (b * c)] rw [← xor_assoc (b * c) (a * d) (b * d), xor_comm (b * c) (a * d)] """), ]}, {"title": "Decisions and cycles", "title_pl": "Decyzje i cykle", "theorems": [ thm("ite_swap", "ite_zamiana", "ite(p, ite(q, a, b), ite(q, c, d)) = " "ite(q, ite(p, a, c), ite(p, b, d))", "zamiana kolejności testów (drzewa decyzyjne)", "swapping the order of tests (decision trees)", """ -- both sides: the regions p * q, p * n(q), n(p) * q, n(p) * n(q) rw [H4 p, H4 n(p), H4 q, H4 n(q)] rw [mul_left_comm q p a, mul_left_comm q n(p) c] rw [mul_left_comm n(q) p b, mul_left_comm n(q) n(p) d] rw [add_assoc, ← add_right_comm (p * (q * a)), ← add_assoc] """), thm("ite_redundant", "ite_nadmiar", "ite(p, ite(p, a, b), ite(p, c, d)) = ite(p, a, d)", "drugi test tej samej zmiennej jest zbędny", "a second test of the same variable is redundant", """ rw [H4, H4, add_assoc, mul_assoc, mul_assoc, mul_assoc] rw [mul_assoc, mul_idem] nth_rw 1 [H2 p a] rw [H8, zero_mul, H5, H2 n(p), H8, zero_mul, H5, mul_idem, ← H2] """), thm("two_implications", "implikacje_dwie", "(n(x) + y) * (n(y) + z) = n(x) * n(y) + y * z", "dwie implikacje x → y → z, przez konsensus", "two implications x → y → z, by consensus", """ rw [add_mul, H4 n(x), H4 y, H8 y, zero_add] rw [H1 (n(x) * n(y) + n(x) * z) (y * z), add_assoc, H2 n(x) n(y)] rw [H2 n(x) z] rw [consensus y z n(x), H1 (y * z)] """), thm("cycle_3", "cykl_3", "(n(x) + y) * (n(y) + z) * (n(z) + x) = " "x * y * z + n(x) * n(y) * n(z)", "cykl implikacji x → y → z → x: wszystkie równe", "a cycle x → y → z → x of implications: all equal", """ -- (n(x)n(y) + yz)(n(z) + x): only two products survive rw [two_implications x y z] rw [H4, add_mul, add_mul, add_assoc] rw [← mul_assoc y, H8, mul_zero, H5, mul_right_comm n(x) n(y) x] rw [H2 n(x) x, H8, zero_mul, H5, mul_right_comm y, H2 y, H1] """), thm("cycle_4", "cykl_4", "(n(x) + y) * (n(y) + z) * (n(z) + w) * (n(w) + x) = " "x * y * z * w + n(x) * n(y) * n(z) * n(w)", "cykl czterech implikacji", "a cycle of four implications", """ -- pairs of implications: (n(x)n(y) + yz)(n(z)n(w) + wx) rw [← mul_assoc ((n(x) + y) * (n(y) + z)) (n(z) + w) (n(w) + x)] rw [two_implications x y z, two_implications z w x] rw [H4, add_mul, add_mul, add_assoc, mul_assoc] rw [mul_assoc, mul_assoc, mul_assoc] nth_rw 1 [mul_right_comm (n(x) * n(y)) n(z) n(w)] rw [mul_right_comm n(x), H2 n(x), ← mul_assoc y, H8, mul_zero] rw [zero_mul, H5, mul_right_comm n(x), H2 n(x)] rw [mul_right_comm (w * n(x)), mul_right_comm w, ← mul_assoc w] rw [H8, mul_zero, zero_mul, H5, mul_right_comm y, H2 y] rw [mul_right_comm (w * y), mul_right_comm w, H1, ← H2 n(x)] rw [← mul_right_comm n(x), ← mul_right_comm (n(x) * n(y))] rw [← H2 x, ← mul_right_comm x, ← mul_right_comm] """), ]}, ]