Course page › Code of Lecture 3 › library.py · 871 lines
raw file

The Boole Lab library: theorems of Boolean algebra from axioms H1–H8.

Code with colored syntax: click a line number to get a link to it; an underlined name leads to its definition.

1"""The Boole Lab library: theorems of Boolean algebra from axioms H1–H8.
2
3Every theorem has a full tactic script in the language of the lab (lab.py):
4rw [ … ] with Lean semantics, nth_rw, rfl, symm, trans, exact. The theorems
5come in the order of dependence: a script may use only the axioms and the
6earlier theorems. At every start the lab replays the whole library — every
7proof goes through the kernel (Kernel.theorem) with the original statement —
8and scripts/lean_biblioteka.py translates the same scripts into Lean 4 and
9compiles them (lean/BooleLab.lean in Polish, lean/BooleLabEn.lean in English).
10
11Every theorem has an English name (the main one) and a Polish name used by
12the Polish edition (the Polish lab page, book and slides). The Polish lab
13renames the theorems in the scripts and translates their comments with
14COMMENTS_PL; the English text is the source.
15
16Associativity is the hardest: Huntington (1904) took it without proof, but
17it follows from H1–H8. The idea: A = x + (y + z) and B = (x + y) + z have the
18same products with x and with n(x) (x * A = x = x * B,
19n(x) * A = n(x) * (y + z) = n(x) * B), and every term splits as
20y = x * y + n(x) * y (split_along). De Morgan's law: n(x) * n(y) is a
21complement of x + y, and a complement is unique — the chain
22b = b*1 = b*(a + n(a)) = b*a + b*n(a) = a*n(a) + b*n(a) = (a + b)*n(a)
23 = 1*n(a) = n(a) with a = x + y, b = n(x) * n(y).
24
25The later sections (added 2026-12-02, after the lecture) use abbreviations
26expanded by the lab's parser (lab.ABBREVIATIONS): med(x, y, z) = x*y + x*z +
27y*z, xor(x, y) = x*n(y) + n(x)*y, ite(p, a, b) = p*a + n(p)*b, nand(x, y) =
28n(x*y). The kernel and Lean see only +, *, n, 0, 1.
29* A single axiom: DN1 and Sh1 from W. McCune, R. Veroff, B. Fitelson,
30 K. Harris, A. Feist, L. Wos, "Short Single Axioms for Boolean Algebra",
31 J. Automated Reasoning 29 (2002) — each of these equations alone is an
32 axiom system for Boolean algebra (DN1 in the language +, n; Sh1 in the
33 language of the Sheffer stroke); here only the easy direction: both
34 equations hold. The basis {(x|y)|(x|(y|z)) = x, x|y = y|x}: R. Veroff,
35 "A Shortest 2-Basis for Boolean Algebra in Terms of the Sheffer Stroke".
36* Median algebra: distributivity of the median — a problem D. Knuth passed
37 to R. Veroff and W. McCune (the first equational proof from the median
38 axioms alone was found by theorem provers); in a Boolean algebra the
39 observation med(t, u, v) = a + b * t with a = u * v, b = u + v is
40 enough.
41* Symmetric difference: a Boolean algebra as a ring (xor, *).
42* Boolean differences: the derivative of f in z is f(z) ⊕ f(n(z)); the
43 product rule has a third term.
44* Decisions and cycles: ite and swapping the order of tests, cycles of
45 implications.
46"""
47
48
49def thm(name, name_pl, equation, desc_pl, desc_en, script):
50 return {"name": name, "name_pl": name_pl, "equation": equation,
51 "desc_pl": desc_pl, "desc_en": desc_en, "script": script}
52
53
54# Polish versions of the script comments (comments without words — pure
55# algebra — are the same in both languages).
56COMMENTS_PL = {
57 "-- (x + n(x)) * (x + 1): only the first 1":
58 "-- (x + n(x)) * (x + 1): tylko pierwsza 1",
59 "-- x * n(x) + x * 0: only the first 0":
60 "-- x * n(x) + x * 0: tylko pierwsze 0",
61 "-- A = x * A + n(x) * A and B = x * B + n(x) * B (split_along)":
62 "-- A = x * A + n(x) * A i B = x * B + n(x) * B (rozbicie)",
63 "-- x * A = x, n(x) * A = n(x) * (y + z) and the same for B":
64 "-- x * A = x, n(x) * A = n(x) * (y + z) i to samo dla B",
65 "-- n(x) * n(y) is a complement of x + y; complements are unique":
66 "-- n(x) * n(y) jest dopełnieniem x + y, a dopełnienie jest jedyne",
67 "-- n(n(z) + n(z + u)) = z * (z + u) = z: the variable u vanishes":
68 "-- n(n(z) + n(z + u)) = z * (z + u) = z: zmienna u znika",
69 "-- left half: n(x * y), right half: n(y) + z * x, product: n(y)":
70 "-- lewa połowa: n(x * y), prawa: n(y) + z * x, iloczyn: n(y)",
71 "-- (a + b * x) * (a + b * y) = a + b * (x * y) for each pair":
72 "-- (a + b * x) * (a + b * y) = a + b * (x * y) dla każdej pary",
73 "-- both sides are a + b * (…) for a = u * v and b = u + v":
74 "-- obie strony to a + b * (…) dla a = u * v i b = u + v",
75 "-- as med_distrib, but all the arguments are transformed":
76 "-- jak med_rozdz, ale przekształcone są wszystkie argumenty",
77 "-- both sides: the sum of the minterms with an odd number of 1s":
78 "-- obie strony to suma mintermów z nieparzystą liczbą jedynek",
79 "-- x + y = xor(x, y) + x * y, and x * y absorbs z * x * y":
80 "-- x + y = xor(x, y) + x * y, a x * y wchłania z * x * y",
81 "-- in the ring: x ⊕ (x ⊕ xy ⊕ xz ⊕ yz) = xy ⊕ xz ⊕ yz":
82 "-- w pierścieniu: x ⊕ (x ⊕ xy ⊕ xz ⊕ yz) = xy ⊕ xz ⊕ yz",
83 "-- med seen from x; a shift keeps the differences x ⊕ y":
84 "-- med widziana z x; przesunięcie nie zmienia różnic x ⊕ y",
85 "-- med = xy ⊕ z(x ⊕ y): xy cancels, the difference remains":
86 "-- med = xy ⊕ z(x ⊕ y): xy się skraca, zostaje różnica",
87 "-- w = n(z) and xor(z, n(z)) = 1":
88 "-- w = n(z) i xor(z, n(z)) = 1",
89 "-- (a ⊕ b)(c ⊕ d) = ac ⊕ bc ⊕ ad ⊕ bd; ac cancels ac":
90 "-- (a ⊕ b)(c ⊕ d) = ac ⊕ bc ⊕ ad ⊕ bd; ac skraca się z ac",
91 "-- both sides: the regions p * q, p * n(q), n(p) * q, n(p) * n(q)":
92 "-- obie strony: obszary p * q, p * n(q), n(p) * q, n(p) * n(q)",
93 "-- (n(x)n(y) + yz)(n(z) + x): only two products survive":
94 "-- (n(x)n(y) + yz)(n(z) + x): przeżywają tylko dwa iloczyny",
95 "-- pairs of implications: (n(x)n(y) + yz)(n(z)n(w) + wx)":
96 "-- pary implikacji: (n(x)n(y) + yz)(n(z)n(w) + wx)",
97}
98
99SECTIONS = [
100 {"title": "Basics", "title_pl": "Podstawy",
101 "theorems": [
102 thm("zero_add", "zero_plus",
103 "0 + x = x",
104 "zero z lewej",
105 "zero on the left",
106 "rw [H1, H5]"),
107 thm("one_mul", "jeden_razy",
108 "1 * x = x",
109 "jedynka z lewej",
110 "one on the left",
111 "rw [H2, H6]"),
112 thm("compl_add", "n_plus",
113 "n(x) + x = 1",
114 "dopełnienie z lewej",
115 "complement on the left",
116 "rw [H1, H7]"),
117 thm("compl_mul", "n_razy",
118 "n(x) * x = 0",
119 "dopełnienie z lewej",
120 "complement on the left",
121 "rw [H2, H8]"),
122 thm("add_idem", "idem_plus",
123 "x + x = x",
124 "idempotentność sumy (jak na wykładzie)",
125 "idempotence of + (as in the lecture)",
126 """
127 rw [← H6 (x + x)] -- (x + x) * 1
128 rw [← H7 x] -- (x + x) * (x + n(x))
129 rw [← H3] -- x + x * n(x)
130 rw [H8, H5] -- x + 0, x
131 """),
132 thm("mul_idem", "idem_razy",
133 "x * x = x",
134 "idempotentność iloczynu",
135 "idempotence of *",
136 """
137 rw [← H5 (x * x), ← H8 x] -- x * x + x * n(x)
138 rw [← H4, H7, H6] -- x * (x + n(x)), x * 1, x
139 """),
140 thm("add_one", "plus_jeden",
141 "x + 1 = 1",
142 "jedynka pochłania sumę",
143 "one absorbs the sum",
144 """
145 rw [← H6 (x + 1), H2] -- 1 * (x + 1)
146 nth_rw 1 [← H7 x] -- (x + n(x)) * (x + 1): only the first 1
147 rw [← H3, H6, H7] -- x + n(x) * 1, x + n(x), 1
148 """),
149 thm("one_add", "jeden_plus",
150 "1 + x = 1",
151 "jedynka pochłania sumę z lewej",
152 "one absorbs the sum on the left",
153 "rw [H1, add_one]"),
154 thm("mul_zero", "razy_zero",
155 "x * 0 = 0",
156 "zero pochłania iloczyn",
157 "zero absorbs the product",
158 """
159 rw [← H5 (x * 0), H1] -- 0 + x * 0
160 nth_rw 1 [← H8 x] -- x * n(x) + x * 0: only the first 0
161 rw [← H4, H5, H8] -- x * (n(x) + 0), x * n(x), 0
162 """),
163 thm("zero_mul", "zero_razy",
164 "0 * x = 0",
165 "zero pochłania iloczyn z lewej",
166 "zero absorbs the product on the left",
167 "rw [H2, mul_zero]"),
168 ]},
169 {"title": "Absorption", "title_pl": "Pochłanianie",
170 "theorems": [
171 thm("absorb", "pochlanianie",
172 "x + x * y = x",
173 "prawo pochłaniania",
174 "absorption law",
175 """
176 nth_rw 1 [← H6 x] -- x * 1 + x * y
177 rw [← H4, H1, add_one, H6] -- x * (1 + y), x * (y + 1), x
178 """),
179 thm("absorb_mul", "pochlanianie_razy",
180 "x * (x + y) = x",
181 "pochłanianie dla iloczynu",
182 "absorption for *",
183 "rw [H4, mul_idem, absorb]"),
184 thm("absorb_right", "pochlanianie_prawe",
185 "x * y + x = x",
186 "pochłanianie z prawej",
187 "absorption on the right",
188 "rw [H1, absorb]"),
189 thm("absorb_mul_right", "pochlanianie_razy_prawe",
190 "(x + y) * x = x",
191 "pochłanianie dla iloczynu z prawej",
192 "absorption for * on the right",
193 "rw [H2, absorb_mul]"),
194 thm("add_compl_mul", "plus_n_razy",
195 "x + n(x) * y = x + y",
196 "x wchłania dopełnienie w iloczynie",
197 "x absorbs its complement inside a product",
198 "rw [H3, H7, one_mul]"),
199 thm("mul_compl_add", "razy_n_plus",
200 "x * (n(x) + y) = x * y",
201 "dualnie: dopełnienie w sumie znika",
202 "dually: the complement inside a sum vanishes",
203 "rw [H4, H8, zero_add]"),
204 thm("compl_add_mul", "n_plus_razy",
205 "n(x) + x * y = n(x) + y",
206 "to samo dla n(x)",
207 "the same for n(x)",
208 "rw [H3, compl_add, one_mul]"),
209 thm("compl_mul_add", "n_razy_plus",
210 "n(x) * (x + y) = n(x) * y",
211 "to samo dla n(x), dualnie",
212 "the same for n(x), dually",
213 "rw [H4, compl_mul, zero_add]"),
214 ]},
215 {"title": "Complement", "title_pl": "Dopełnienie",
216 "theorems": [
217 thm("compl_zero", "n_zero",
218 "n(0) = 1",
219 "dopełnienie zera",
220 "complement of zero",
221 "rw [← zero_add n(0), H7]"),
222 thm("compl_one", "n_jeden",
223 "n(1) = 0",
224 "dopełnienie jedynki",
225 "complement of one",
226 "rw [← one_mul n(1), H8]"),
227 thm("compl_compl", "inwolucja",
228 "n(n(x)) = x",
229 "podwójne dopełnienie (łańcuch z wykładu)",
230 "double complement (the chain from the lecture)",
231 """
232 rw [← H6 n(n(x)), ← H7 x, H4] -- n(n(x)) * x + n(n(x)) * n(x)
233 rw [H2 n(n(x)) n(x), H8] -- n(n(x)) * x + 0
234 rw [← H8 x, H2 n(n(x)) x, ← H4] -- x * (n(n(x)) + n(x))
235 rw [H1, H7, H6] -- x * 1, x
236 """),
237 thm("merge", "sklejanie",
238 "x * y + x * n(y) = x",
239 "sklejanie",
240 "combining",
241 "rw [← H4, H7, H6]"),
242 thm("merge_mul", "sklejanie_plus",
243 "(x + y) * (x + n(y)) = x",
244 "sklejanie, dualnie",
245 "combining, dually",
246 "rw [← H3, H8, H5]"),
247 thm("split_along", "rozbicie",
248 "x * y + n(x) * y = y",
249 "rozbicie y według x (klucz do łączności)",
250 "splitting y along x (the key to associativity)",
251 "rw [H2 x y, H2 n(x) y, ← H4, H7, H6]"),
252 thm("split_along_mul", "rozbicie_plus",
253 "(x + y) * (n(x) + y) = y",
254 "rozbicie, dualnie",
255 "splitting, dually",
256 "rw [H1 x y, H1 n(x) y, ← H3, H8, H5]"),
257 ]},
258 {"title": "Distributivity", "title_pl": "Rozdzielność",
259 "theorems": [
260 thm("add_mul", "rozdz_prawa_razy",
261 "(x + y) * z = x * z + y * z",
262 "rozdzielność iloczynu z prawej",
263 "distributivity of * on the right",
264 "rw [H2, H4, H2 z x, H2 z y]"),
265 thm("add_distrib_right", "rozdz_prawa_plus",
266 "x * y + z = (x + z) * (y + z)",
267 "rozdzielność sumy z prawej",
268 "distributivity of + on the right",
269 "rw [H1, H3, H1 z x, H1 z y]"),
270 thm("add_mul_add", "rozdz_podwojna",
271 "(x + y) * (z + w) = x * z + x * w + (y * z + y * w)",
272 "wymnażanie dwóch sum",
273 "multiplying out two sums",
274 "rw [add_mul, H4, H4]"),
275 ]},
276 {"title": "Associativity", "title_pl": "Łączność",
277 "theorems": [
278 thm("assoc_lemma_1", "laczn_lemat_1",
279 "x * (x + y + z) = x",
280 "x * B = x",
281 "x * B = x",
282 "rw [H4, absorb_mul, absorb]"),
283 thm("assoc_lemma_2", "laczn_lemat_2",
284 "n(x) * (x + y + z) = n(x) * (y + z)",
285 "n(x) * B = n(x) * (y + z)",
286 "n(x) * B = n(x) * (y + z)",
287 "rw [H4, compl_mul_add, ← H4]"),
288 thm("add_assoc", "laczn_plus",
289 "x + (y + z) = x + y + z",
290 "łączność sumy (nie ma jej wśród H1–H8!)",
291 "associativity of + (not among H1–H8!)",
292 """
293 -- A = x * A + n(x) * A and B = x * B + n(x) * B (split_along)
294 rw [← split_along x (x + (y + z)), ← split_along x (x + y + z)]
295 -- x * A = x, n(x) * A = n(x) * (y + z) and the same for B
296 rw [absorb_mul, compl_mul_add, assoc_lemma_1, assoc_lemma_2]
297 """),
298 thm("assoc_lemma_3", "laczn_lemat_3",
299 "x + x * y * z = x",
300 "x + B = x, dualnie",
301 "x + B = x, dually",
302 "rw [H3, absorb, absorb_mul]"),
303 thm("assoc_lemma_4", "laczn_lemat_4",
304 "n(x) + x * y * z = n(x) + y * z",
305 "n(x) + B = n(x) + y * z",
306 "n(x) + B = n(x) + y * z",
307 "rw [H3, compl_add_mul, ← H3]"),
308 thm("mul_assoc", "laczn_razy",
309 "x * (y * z) = x * y * z",
310 "łączność iloczynu",
311 "associativity of *",
312 """
313 rw [← split_along_mul x (x * (y * z))]
314 rw [← split_along_mul x (x * y * z)]
315 rw [absorb, compl_add_mul, assoc_lemma_3, assoc_lemma_4]
316 """),
317 thm("add_left_comm", "lewa_przem_plus",
318 "x + (y + z) = y + (x + z)",
319 "przemienność z lewej (sumy)",
320 "left commutativity of +",
321 "rw [add_assoc, H1 x y, ← add_assoc]"),
322 thm("mul_left_comm", "lewa_przem_razy",
323 "x * (y * z) = y * (x * z)",
324 "przemienność z lewej (iloczyny)",
325 "left commutativity of *",
326 "rw [mul_assoc, H2 x y, ← mul_assoc]"),
327 thm("add_right_comm", "prawa_przem_plus",
328 "x + y + z = x + z + y",
329 "przemienność z prawej (sumy)",
330 "right commutativity of +",
331 "rw [← add_assoc, H1 y z, add_assoc]"),
332 thm("mul_right_comm", "prawa_przem_razy",
333 "x * y * z = x * z * y",
334 "przemienność z prawej (iloczyny)",
335 "right commutativity of *",
336 "rw [← mul_assoc, H2 y z, mul_assoc]"),
337 thm("add_idem_left", "idem_plus_lewe",
338 "x + (x + y) = x + y",
339 "x dodane drugi raz",
340 "adding x a second time",
341 "rw [add_assoc, add_idem]"),
342 thm("add_compl_add", "plus_n_jeden",
343 "x + (n(x) + y) = 1",
344 "suma z dopełnieniem to 1",
345 "a sum with the complement is 1",
346 "rw [add_assoc, H7, one_add]"),
347 thm("mul_compl_mul", "razy_n_zero",
348 "x * (n(x) * y) = 0",
349 "iloczyn z dopełnieniem to 0",
350 "a product with the complement is 0",
351 "rw [mul_assoc, H8, zero_mul]"),
352 thm("modular", "modularnosc",
353 "x + y * (x + z) = (x + y) * (x + z)",
354 "prawo modularności",
355 "the modular law",
356 "rw [H3, add_idem_left]"),
357 ]},
358 {"title": "De Morgan's laws", "title_pl": "Prawa De Morgana",
359 "theorems": [
360 thm("dm_one", "dm_jeden",
361 "x + y + n(x) * n(y) = 1",
362 "x + y i n(x) * n(y) dają razem 1",
363 "x + y and n(x) * n(y) add up to 1",
364 """
365 rw [H3] -- (x + y + n(x)) * (x + y + n(y))
366 rw [← add_assoc x y n(y), H7, add_one]
367 rw [H1 x y, ← add_assoc y x n(x), H7, add_one, H6]
368 """),
369 thm("dm_zero", "dm_zero",
370 "(x + y) * (n(x) * n(y)) = 0",
371 "x + y i n(x) * n(y) są rozłączne",
372 "x + y and n(x) * n(y) are disjoint",
373 "rw [add_mul, mul_compl_mul, H2 n(x) n(y), mul_compl_mul, H5]"),
374 thm("de_morgan_add", "de_morgan_plus",
375 "n(x + y) = n(x) * n(y)",
376 "prawo De Morgana dla sumy",
377 "De Morgan's law for +",
378 """
379 -- n(x) * n(y) is a complement of x + y; complements are unique
380 rw [← H6 (n(x) * n(y)), ← H7 (x + y), H4]
381 rw [H2 (n(x) * n(y)) (x + y), dm_zero]
382 rw [← H8 (x + y), ← add_mul, dm_one, one_mul]
383 """),
384 thm("de_morgan_mul", "de_morgan_razy",
385 "n(x * y) = n(x) + n(y)",
386 "prawo De Morgana dla iloczynu",
387 "De Morgan's law for *",
388 """
389 rw [← compl_compl (n(x) + n(y)), de_morgan_add, compl_compl]
390 rw [compl_compl]
391 """),
392 thm("de_morgan_add_compl", "de_morgan_n_plus",
393 "n(x + n(y)) = n(x) * y",
394 "De Morgan z dopełnieniem",
395 "De Morgan with a complement",
396 "rw [de_morgan_add, compl_compl]"),
397 thm("de_morgan_mul_compl", "de_morgan_n_razy",
398 "n(x * n(y)) = n(x) + y",
399 "to samo dla iloczynu",
400 "the same for *",
401 "rw [de_morgan_mul, compl_compl]"),
402 thm("mul_via_add", "razy_przez_plus",
403 "n(n(x) + n(y)) = x * y",
404 "iloczyn wyrażony sumą i dopełnieniem",
405 "the product expressed by + and n",
406 "rw [de_morgan_add, compl_compl, compl_compl]"),
407 thm("add_via_mul", "plus_przez_razy",
408 "n(n(x) * n(y)) = x + y",
409 "suma wyrażona iloczynem i dopełnieniem",
410 "the sum expressed by * and n",
411 "rw [de_morgan_mul, compl_compl, compl_compl]"),
412 thm("de_morgan_add3", "de_morgan_plus3",
413 "n(x + y + z) = n(x) * n(y) * n(z)",
414 "De Morgan dla trzech składników",
415 "De Morgan for three terms",
416 "rw [de_morgan_add, de_morgan_add]"),
417 thm("add_compl_sum", "plus_n_sumy",
418 "x + n(x + y) = x + n(y)",
419 "x wchłania dopełnienie sumy",
420 "x absorbs the complement of a sum",
421 "rw [de_morgan_add, add_compl_mul]"),
422 thm("mul_compl_prod", "razy_n_iloczynu",
423 "x * n(x * y) = x * n(y)",
424 "dualnie",
425 "dually",
426 "rw [de_morgan_mul, mul_compl_add]"),
427 ]},
428 {"title": "Huntington and Robbins", "title_pl": "Huntington i Robbins",
429 "theorems": [
430 thm("huntington", "huntington",
431 "n(n(x) + y) + n(n(x) + n(y)) = x",
432 "aksjomat Huntingtona (1933) zachodzi",
433 "Huntington's axiom (1933) holds",
434 """
435 rw [de_morgan_add, de_morgan_add, compl_compl, compl_compl, ← H4]
436 rw [compl_add, H6]
437 """),
438 thm("robbins", "robbins",
439 "n(n(x + y) + n(x + n(y))) = x",
440 "równanie Robbinsa zachodzi (odwrotnie: EQP, 1996)",
441 "the Robbins equation holds (the converse: EQP, 1996)",
442 "rw [de_morgan_add, compl_compl, compl_compl, ← H3, H8, H5]"),
443 thm("huntington_mul", "huntington_razy",
444 "n(n(x) * y) * n(n(x) * n(y)) = x",
445 "aksjomat Huntingtona, dualnie",
446 "Huntington's axiom, dually",
447 """
448 rw [de_morgan_mul, de_morgan_mul, compl_compl, compl_compl, ← H3]
449 rw [compl_mul, H5]
450 """),
451 thm("robbins_mul", "robbins_razy",
452 "n(n(x * y) * n(x * n(y))) = x",
453 "równanie Robbinsa, dualnie",
454 "the Robbins equation, dually",
455 "rw [de_morgan_mul, compl_compl, compl_compl, ← H4, H7, H6]"),
456 ]},
457 {"title": "Consensus and majority", "title_pl": "Konsensus i mediana",
458 "theorems": [
459 thm("consensus", "konsensus",
460 "x * y + n(x) * z + y * z = x * y + n(x) * z",
461 "twierdzenie o konsensusie",
462 "the consensus theorem",
463 """
464 rw [← H6 (y * z), ← H7 x, H4] -- y * z = y * z * x + y * z * n(x)
465 rw [H2 (y * z) x, mul_assoc] -- x * y * z
466 rw [H2 (y * z) n(x), H2 y z, mul_assoc] -- n(x) * z * y
467 rw [add_assoc, add_right_comm (x * y) (n(x) * z) (x * y * z)]
468 rw [absorb, ← add_assoc, absorb]
469 """),
470 thm("consensus_mul", "konsensus_razy",
471 "(x + y) * (n(x) + z) * (y + z) = (x + y) * (n(x) + z)",
472 "konsensus, dualnie",
473 "consensus, dually",
474 """
475 rw [← H5 (y + z), ← H8 x, H3]
476 rw [H1 (y + z) x, add_assoc]
477 rw [H1 (y + z) n(x), H1 y z, add_assoc]
478 rw [mul_assoc, mul_right_comm (x + y) (n(x) + z) (x + y + z)]
479 rw [absorb_mul, ← mul_assoc, absorb_mul]
480 """),
481 thm("median_self_dual", "mediana",
482 "(x + y) * (y + z) * (z + x) = x * y + y * z + z * x",
483 "mediana (funkcja większości) jest samodualna",
484 "the median (majority) is self-dual",
485 """
486 rw [H1 x y, ← H3] -- (y + x * z) * (z + x)
487 rw [add_mul, H4] -- y * z + y * x + x * z * (z + x)
488 rw [← mul_assoc x z (z + x), absorb_mul]
489 rw [H2 x y, H2 z x, H1 (y * z) (y * x)]
490 """),
491 ]},
492 {"title": "A single axiom", "title_pl": "Jeden aksjomat",
493 "theorems": [
494 thm("dn1", "dn1",
495 "n(n(n(x + y) + z) + n(x + n(n(z) + n(z + u)))) = z",
496 "DN1 (McCune i in., 2002): jedno równanie z + i n zastępuje "
497 "wszystkie aksjomaty",
498 "DN1 (McCune et al., 2002): one equation in + and n replaces "
499 "all the axioms",
500 """
501 -- n(n(z) + n(z + u)) = z * (z + u) = z: the variable u vanishes
502 rw [de_morgan_add, compl_compl, compl_compl]
503 rw [de_morgan_add n(z) n(z + u), compl_compl, compl_compl]
504 rw [absorb_mul]
505 rw [← add_distrib_right]
506 rw [de_morgan_add, H2 (n(x) * n(y)) x, mul_assoc, H8, zero_mul]
507 rw [zero_add]
508 """),
509 thm("sh1", "sh1",
510 "nand(nand(x, nand(nand(y, x), x)), nand(y, nand(z, x))) = y",
511 "Sh1: jeden aksjomat w samej kresce Sheffera, najkrótszy możliwy",
512 "Sh1: a single axiom in the Sheffer stroke alone, the shortest "
513 "possible",
514 """
515 -- left half: n(x * y), right half: n(y) + z * x, product: n(y)
516 rw [de_morgan_mul (n(y * x)) x, compl_compl (y * x)]
517 rw [H1 (y * x) n(x), mul_compl_add x (y * x), H2 y x, mul_assoc]
518 rw [mul_idem]
519 rw [de_morgan_mul y (n(z * x)), compl_compl (z * x)]
520 rw [de_morgan_mul x y]
521 rw [H1 n(x) n(y), ← H3, H2 z x, mul_assoc, compl_mul, zero_mul, H5]
522 rw [compl_compl]
523 """),
524 thm("sheffer_basis", "sheffer_baza",
525 "nand(nand(x, y), nand(x, nand(y, z))) = x",
526 "z przemiennością nand: najkrótsza baza z dwóch równań (Veroff)",
527 "with commutativity of nand: the shortest 2-basis (Veroff)",
528 """
529 -- x * y + x * n(y * z) = x * (y + n(y) + n(z)) = x
530 rw [add_via_mul, ← H4, de_morgan_mul, add_compl_add, H6]
531 """),
532 ]},
533 {"title": "Median algebra", "title_pl": "Algebra mediany",
534 "theorems": [
535 thm("med_ab", "med_ab",
536 "med(t, u, v) = u * v + (u + v) * t",
537 "mediana jako funkcja jednego argumentu: u * v + (u + v) * t",
538 "the median as a function of one argument: u * v + (u + v) * t",
539 "rw [H1, ← H4, ← H2 (u + v)]"),
540 thm("mul_common", "iloczyn_wspolny",
541 "x * y * (x * z) = x * (y * z)",
542 "wspólny czynnik dwóch iloczynów",
543 "a common factor of two products",
544 """
545 rw [← mul_assoc x y (x * z), mul_left_comm y x z]
546 rw [mul_assoc x x (y * z), mul_idem]
547 """),
548 thm("med_affine", "med_afiniczna",
549 "med(a + b * x, a + b * y, a + b * z) = a + b * med(x, y, z)",
550 "mediana przemienna z przekształceniami t ↦ a + b * t",
551 "the median commutes with the maps t ↦ a + b * t",
552 """
553 -- (a + b * x) * (a + b * y) = a + b * (x * y) for each pair
554 trans a + b * (x * y) + (a + b * (x * z)) + (a + b * (y * z))
555 rw [← H3 a (b * x) (b * y), ← H3 a (b * x) (b * z)]
556 rw [← H3 a (b * y) (b * z)]
557 rw [mul_common b x y, mul_common b x z]
558 rw [mul_common b y z]
559 rw [add_assoc, add_assoc, mul_assoc, mul_assoc, mul_assoc]
560 rw [add_right_comm a, add_idem, add_right_comm (a + b * x * y)]
561 rw [add_right_comm a, add_idem, ← mul_assoc b y]
562 rw [← mul_assoc b x z, ← mul_assoc, ← add_assoc a, ← add_assoc]
563 rw [← H4, ← H4]
564 """),
565 thm("med_affine_2", "med_afiniczna_2",
566 "med(x, a + b * y, a + b * z) = a + b * med(x, y, z)",
567 "to samo, gdy pierwszy argument się nie zmienia",
568 "the same with the first argument unchanged",
569 """
570 rw [← H3 a (b * y) (b * z), mul_common b y z]
571 rw [H4 x a (b * y), H4 x a (b * z), mul_left_comm x b y]
572 rw [mul_left_comm x b z]
573 rw [add_assoc, add_assoc, mul_assoc, mul_assoc, mul_assoc]
574 nth_rw 1 [H2 x a]
575 rw [H2 x, add_right_comm (a * x), add_idem]
576 rw [add_right_comm (a * x + b * x * y), add_right_comm (a * x)]
577 rw [H1 (a * x), absorb, ← mul_assoc b y, ← mul_assoc b x z]
578 rw [← mul_assoc, ← add_assoc a, ← add_assoc, ← H4, ← H4]
579 """),
580 thm("med_distrib", "med_rozdz",
581 "med(med(x, y, z), u, v) = med(x, med(y, u, v), med(z, u, v))",
582 "rozdzielność mediany (wyzwanie od Knutha dla dowodzenia "
583 "automatycznego)",
584 "distributivity of the median (a challenge from Knuth for "
585 "automated proving)",
586 """
587 -- both sides are a + b * (…) for a = u * v and b = u + v
588 rw [med_ab (med(x, y, z)) u v, med_ab y u v, med_ab z u v]
589 rw [med_affine_2]
590 """),
591 thm("med_distrib_sym", "med_rozdz_sym",
592 "med(med(x, y, z), u, v) = "
593 "med(med(x, u, v), med(y, u, v), med(z, u, v))",
594 "rozdzielność mediany, postać symetryczna",
595 "distributivity of the median, symmetric form",
596 """
597 -- as med_distrib, but all the arguments are transformed
598 rw [med_ab (med(x, y, z)) u v, med_ab x u v, med_ab y u v]
599 rw [med_ab z u v, med_affine]
600 """),
601 ]},
602 {"title": "Symmetric difference", "title_pl": "Różnica symetryczna",
603 "theorems": [
604 thm("xor_comm", "xor_przem",
605 "xor(x, y) = xor(y, x)",
606 "różnica symetryczna jest przemienna",
607 "symmetric difference is commutative",
608 "rw [H1, H2, ← H2 n(y)]"),
609 thm("xor_zero", "xor_zero",
610 "xor(x, 0) = x",
611 "0 jest elementem neutralnym",
612 "0 is neutral",
613 "rw [xor_comm, zero_mul, add_compl_mul, zero_add]"),
614 thm("zero_xor", "xor_zero_lewe",
615 "xor(0, x) = x",
616 "0 z lewej",
617 "0 on the left",
618 "rw [xor_comm, xor_zero]"),
619 thm("xor_one", "xor_jeden",
620 "xor(x, 1) = n(x)",
621 "dopełnienie to dodanie 1",
622 "the complement is adding 1",
623 "rw [compl_one, mul_zero, zero_add, H6]"),
624 thm("xor_self", "xor_samo",
625 "xor(x, x) = 0",
626 "każdy element jest swoim przeciwnym",
627 "every element is its own negative",
628 "rw [compl_mul, H5, H8]"),
629 thm("xor_compl", "xor_dopelnienie",
630 "xor(x, n(x)) = 1",
631 "x i n(x) różnią się wszędzie",
632 "x and n(x) differ everywhere",
633 "rw [xor_comm, mul_idem, add_compl_mul, compl_add]"),
634 thm("mul_xor", "razy_xor",
635 "x * xor(y, z) = xor(x * y, x * z)",
636 "mnożenie jest rozdzielne względem xor",
637 "* distributes over xor",
638 """
639 rw [de_morgan_mul, de_morgan_mul, H4 (x * y), add_mul]
640 rw [add_assoc, mul_assoc, mul_assoc, mul_right_comm, H8]
641 rw [zero_mul, zero_add, H2 n(x), H8, zero_mul, H5, H2 n(y) x]
642 rw [← mul_assoc x n(y), ← mul_assoc, ← H4]
643 """),
644 thm("xor_mul", "xor_razy",
645 "xor(x, y) * z = xor(x * z, y * z)",
646 "to samo z prawej",
647 "the same on the right",
648 "rw [H2 (xor(x, y)) z, mul_xor z x y, H2 z x, H2 z y]"),
649 thm("xor_assoc", "xor_lacz",
650 "xor(xor(x, y), z) = xor(x, xor(y, z))",
651 "xor jest łączny: algebra Boole'a to pierścień",
652 "xor is associative: a Boolean algebra is a ring",
653 """
654 -- both sides: the sum of the minterms with an odd number of 1s
655 trans x * y * z + x * n(y) * n(z) + n(x) * y * n(z) + n(x) * n(y) * z
656 rw [de_morgan_add, de_morgan_mul, compl_compl, de_morgan_mul]
657 rw [compl_compl, ← H1 (x * n(y) * n(z))]
658 rw [← add_right_comm (x * n(y) * n(z)), ← H2 y x, ← add_assoc]
659 rw [← add_mul (y * x), ← H5 (n(x) * n(y)), ← H8 y]
660 rw [← add_mul n(x), ← zero_add (y * x), ← compl_mul x]
661 rw [← add_mul n(x), ← H4, ← add_mul]
662 rw [← mul_right_comm, ← mul_assoc n(x) n(y), ← mul_assoc n(x)]
663 rw [← mul_assoc x n(y), ← mul_assoc, ← add_assoc, ← H4 n(x), ← H4]
664 rw [← H5 (n(y) * n(z)), ← H8 z, ← add_mul, ← zero_add (z * y)]
665 rw [← compl_mul y, ← add_mul, ← H4, de_morgan_add]
666 rw [de_morgan_mul, compl_compl, de_morgan_mul, compl_compl]
667 """),
668 thm("xor_right_comm", "xor_prawa_przem",
669 "xor(xor(x, y), z) = xor(xor(x, z), y)",
670 "przemienność z prawej (xor)",
671 "right commutativity of xor",
672 "rw [xor_assoc, xor_comm y z, ← xor_assoc]"),
673 thm("xor_shift", "xor_przesun",
674 "xor(xor(x, t), xor(y, t)) = xor(x, y)",
675 "przesunięcie o t nie zmienia różnicy",
676 "a shift by t keeps the difference",
677 """
678 rw [xor_assoc x t (xor(y, t)), xor_comm t (xor(y, t))]
679 rw [xor_assoc y t t, xor_self t, xor_zero y]
680 """),
681 thm("xor_shift_left", "xor_przesun_lewe",
682 "xor(xor(t, x), xor(t, y)) = xor(x, y)",
683 "to samo z t z lewej",
684 "the same with t on the left",
685 "rw [xor_comm t x, xor_comm t y, xor_shift x t y]"),
686 thm("add_via_xor", "plus_przez_xor",
687 "x + y = xor(x, y) + x * y",
688 "suma to różnica symetryczna plus iloczyn",
689 "or is symmetric difference plus and",
690 "rw [H1 (x * n(y) + n(x) * y), add_assoc, merge, add_compl_mul]"),
691 thm("xor_le_nand", "xor_pod_nand",
692 "n(x * y) * xor(x, y) = xor(x, y)",
693 "xor leży pod nand",
694 "xor lies below nand",
695 """
696 rw [de_morgan_mul, H4, add_mul, add_mul]
697 rw [add_assoc, mul_assoc, mul_assoc, mul_assoc, mul_assoc]
698 rw [H2 n(x), H8, zero_mul, zero_add, H2 n(y), ← mul_assoc]
699 rw [mul_idem, mul_idem, H2 n(y), mul_right_comm, ← mul_assoc]
700 rw [H8, mul_zero, H5]
701 """),
702 thm("mul_le_xnor", "iloczyn_pod_xnor",
703 "x * y * n(xor(x, y)) = x * y",
704 "iloczyn leży pod dopełnieniem xor",
705 "the product lies below the complement of xor",
706 """
707 rw [de_morgan_add, de_morgan_mul, compl_compl, de_morgan_mul]
708 rw [compl_compl, H4, add_mul, compl_mul, zero_add]
709 rw [add_mul, H8, H5, H4, mul_assoc, mul_assoc]
710 rw [← mul_assoc x, mul_idem, mul_right_comm, mul_idem]
711 rw [mul_right_comm x, H8, zero_mul, zero_mul, H5]
712 """),
713 thm("xor_disjoint", "xor_rozl",
714 "xor(x * y, z * xor(x, y)) = x * y + z * xor(x, y)",
715 "dla rozłącznych składników suma to xor",
716 "for disjoint parts, or is xor",
717 """
718 rw [de_morgan_mul z (xor(x, y)), H4 (x * y) n(z) (n(xor(x, y)))]
719 rw [mul_le_xnor x y]
720 rw [H1 (x * y * n(z)) (x * y), absorb (x * y) n(z)]
721 rw [mul_left_comm n(x * y) z (xor(x, y)), xor_le_nand x y]
722 """),
723 thm("med_xy", "med_xy",
724 "med(x, y, z) = x * y + z * xor(x, y)",
725 "mediana: zgoda x i y albo rozstrzyga z",
726 "the median: x and y agree, or z decides",
727 """
728 -- x + y = xor(x, y) + x * y, and x * y absorbs z * x * y
729 rw [← add_assoc (x * y) (x * z) (y * z), ← add_mul x y z]
730 rw [add_via_xor x y]
731 rw [add_mul (xor(x, y)) (x * y) z]
732 rw [H1 (xor(x, y) * z) (x * y * z)]
733 rw [add_assoc, absorb (x * y) z, H2 (xor(x, y)) z]
734 """),
735 thm("med_split", "med_rozklad",
736 "med(x, y, z) = xor(x * y, z * xor(x, y))",
737 "to samo w języku pierścienia",
738 "the same in the ring language",
739 "rw [med_xy x y z, ← xor_disjoint x y z]"),
740 thm("med_xor", "med_xor",
741 "med(x, y, z) = xor(xor(x * y, x * z), y * z)",
742 "mediana jako wielomian: xy ⊕ xz ⊕ yz",
743 "the median as a polynomial: xy ⊕ xz ⊕ yz",
744 "rw [med_split, mul_xor z x y, H2 z x, H2 z y, ← xor_assoc]"),
745 thm("med_from_x", "med_od_x",
746 "med(x, y, z) = xor(x, xor(x, y) * xor(x, z))",
747 "mediana widziana z punktu x",
748 "the median seen from the point x",
749 """
750 -- in the ring: x ⊕ (x ⊕ xy ⊕ xz ⊕ yz) = xy ⊕ xz ⊕ yz
751 rw [mul_xor (xor(x, y)) x z, xor_mul x y x, mul_idem x]
752 rw [xor_mul x y z]
753 rw [← xor_assoc x (xor(x, y * x)) (xor(x * z, y * z))]
754 rw [← xor_assoc x x (y * x)]
755 rw [xor_self x, zero_xor (y * x), H2 y x]
756 rw [← xor_assoc (x * y) (x * z) (y * z), ← med_xor x y z]
757 """),
758 thm("med_shift", "med_przesuniecie",
759 "med(xor(x, t), xor(y, t), xor(z, t)) = xor(med(x, y, z), t)",
760 "przesunięcie o t (xor) zachowuje medianę",
761 "a shift by t (xor) preserves the median",
762 """
763 -- med seen from x; a shift keeps the differences x ⊕ y
764 rw [med_from_x (xor(x, t)) (xor(y, t)) (xor(z, t))]
765 rw [xor_shift x t y]
766 rw [xor_shift x t z]
767 rw [xor_right_comm x t (xor(x, y) * xor(x, z)), ← med_from_x x y z]
768 """),
769 ]},
770 {"title": "Boolean differences", "title_pl": "Różnice boolowskie",
771 "theorems": [
772 thm("med_sensitivity", "med_wrazliwosc",
773 "xor(med(x, y, z), med(x, y, w)) = xor(x, y) * xor(z, w)",
774 "kiedy trzeci głos zmienia wynik większości",
775 "when the third vote changes the majority",
776 """
777 -- med = xy ⊕ z(x ⊕ y): xy cancels, the difference remains
778 rw [med_split x y z, med_split x y w]
779 rw [xor_shift_left (x * y) (z * xor(x, y)) (w * xor(x, y))]
780 rw [← xor_mul z w (xor(x, y)), H2 (xor(z, w)) (xor(x, y))]
781 """),
782 thm("med_derivative", "pochodna_med",
783 "xor(med(x, y, z), med(x, y, n(z))) = xor(x, y)",
784 "pochodna boolowska mediany po z to xor(x, y)",
785 "the Boolean derivative of the median in z is xor(x, y)",
786 """
787 -- w = n(z) and xor(z, n(z)) = 1
788 rw [med_sensitivity x y z n(z), xor_compl z, H6]
789 """),
790 thm("product_rule", "regula_iloczynu",
791 "xor(xor(a, b) * xor(c, d), a * c) = "
792 "xor(xor(a * d, b * c), b * d)",
793 "reguła iloczynu dla różnic boolowskich: z trzecim składnikiem",
794 "the product rule for Boolean differences: with a third term",
795 """
796 -- (a ⊕ b)(c ⊕ d) = ac ⊕ bc ⊕ ad ⊕ bd; ac cancels ac
797 rw [mul_xor (xor(a, b)) c d, xor_mul a b c, xor_mul a b d]
798 rw [xor_right_comm (xor(a * c, b * c)) (xor(a * d, b * d)) (a * c)]
799 rw [xor_right_comm (a * c) (b * c) (a * c), xor_self (a * c)]
800 rw [zero_xor (b * c)]
801 rw [← xor_assoc (b * c) (a * d) (b * d), xor_comm (b * c) (a * d)]
802 """),
803 ]},
804 {"title": "Decisions and cycles", "title_pl": "Decyzje i cykle",
805 "theorems": [
806 thm("ite_swap", "ite_zamiana",
807 "ite(p, ite(q, a, b), ite(q, c, d)) = "
808 "ite(q, ite(p, a, c), ite(p, b, d))",
809 "zamiana kolejności testów (drzewa decyzyjne)",
810 "swapping the order of tests (decision trees)",
811 """
812 -- both sides: the regions p * q, p * n(q), n(p) * q, n(p) * n(q)
813 rw [H4 p, H4 n(p), H4 q, H4 n(q)]
814 rw [mul_left_comm q p a, mul_left_comm q n(p) c]
815 rw [mul_left_comm n(q) p b, mul_left_comm n(q) n(p) d]
816 rw [add_assoc, ← add_right_comm (p * (q * a)), ← add_assoc]
817 """),
818 thm("ite_redundant", "ite_nadmiar",
819 "ite(p, ite(p, a, b), ite(p, c, d)) = ite(p, a, d)",
820 "drugi test tej samej zmiennej jest zbędny",
821 "a second test of the same variable is redundant",
822 """
823 rw [H4, H4, add_assoc, mul_assoc, mul_assoc, mul_assoc]
824 rw [mul_assoc, mul_idem]
825 nth_rw 1 [H2 p a]
826 rw [H8, zero_mul, H5, H2 n(p), H8, zero_mul, H5, mul_idem, ← H2]
827 """),
828 thm("two_implications", "implikacje_dwie",
829 "(n(x) + y) * (n(y) + z) = n(x) * n(y) + y * z",
830 "dwie implikacje x → y → z, przez konsensus",
831 "two implications x → y → z, by consensus",
832 """
833 rw [add_mul, H4 n(x), H4 y, H8 y, zero_add]
834 rw [H1 (n(x) * n(y) + n(x) * z) (y * z), add_assoc, H2 n(x) n(y)]
835 rw [H2 n(x) z]
836 rw [consensus y z n(x), H1 (y * z)]
837 """),
838 thm("cycle_3", "cykl_3",
839 "(n(x) + y) * (n(y) + z) * (n(z) + x) = "
840 "x * y * z + n(x) * n(y) * n(z)",
841 "cykl implikacji x → y → z → x: wszystkie równe",
842 "a cycle x → y → z → x of implications: all equal",
843 """
844 -- (n(x)n(y) + yz)(n(z) + x): only two products survive
845 rw [two_implications x y z]
846 rw [H4, add_mul, add_mul, add_assoc]
847 rw [← mul_assoc y, H8, mul_zero, H5, mul_right_comm n(x) n(y) x]
848 rw [H2 n(x) x, H8, zero_mul, H5, mul_right_comm y, H2 y, H1]
849 """),
850 thm("cycle_4", "cykl_4",
851 "(n(x) + y) * (n(y) + z) * (n(z) + w) * (n(w) + x) = "
852 "x * y * z * w + n(x) * n(y) * n(z) * n(w)",
853 "cykl czterech implikacji",
854 "a cycle of four implications",
855 """
856 -- pairs of implications: (n(x)n(y) + yz)(n(z)n(w) + wx)
857 rw [← mul_assoc ((n(x) + y) * (n(y) + z)) (n(z) + w) (n(w) + x)]
858 rw [two_implications x y z, two_implications z w x]
859 rw [H4, add_mul, add_mul, add_assoc, mul_assoc]
860 rw [mul_assoc, mul_assoc, mul_assoc]
861 nth_rw 1 [mul_right_comm (n(x) * n(y)) n(z) n(w)]
862 rw [mul_right_comm n(x), H2 n(x), ← mul_assoc y, H8, mul_zero]
863 rw [zero_mul, H5, mul_right_comm n(x), H2 n(x)]
864 rw [mul_right_comm (w * n(x)), mul_right_comm w, ← mul_assoc w]
865 rw [H8, mul_zero, zero_mul, H5, mul_right_comm y, H2 y]
866 rw [mul_right_comm (w * y), mul_right_comm w, H1, ← H2 n(x)]
867 rw [← mul_right_comm n(x), ← mul_right_comm (n(x) * n(y))]
868 rw [← H2 x, ← mul_right_comm x, ← mul_right_comm]
869 """),
870 ]},
871]