/- Boole Lab — the library of theorems of Boolean algebra in Lean 4. A GENERATED FILE (scripts/lean_biblioteka.py from kernel/library.py) — do not edit by hand. 98 theorems, each with the same tactic script as in the lab (en/applets/boole-lab.html): rw with Lean's semantics, nth_rw k as rw (occs := .pos [k]), trans t as refine Eq.trans (b := t) ?_ ?_. No Mathlib. Check: lean BooleLabEn.lean -/ class HuntingtonAlgebra (α : Type) extends Add α, Mul α, Zero α, One α where n : α → α H1 : ∀ x y : α, x + y = y + x H2 : ∀ x y : α, x * y = y * x H3 : ∀ x y z : α, x + y * z = (x + y) * (x + z) H4 : ∀ x y z : α, x * (y + z) = x * y + x * z H5 : ∀ x : α, x + 0 = x H6 : ∀ x : α, x * 1 = x H7 : ∀ x : α, x + n x = 1 H8 : ∀ x : α, x * n x = 0 open HuntingtonAlgebra variable {α : Type} [HuntingtonAlgebra α] theorem zero_add (x : α) : 0 + x = x := by rw [H1, H5] theorem one_mul (x : α) : 1 * x = x := by rw [H2, H6] theorem compl_add (x : α) : n x + x = 1 := by rw [H1, H7] theorem compl_mul (x : α) : n x * x = 0 := by rw [H2, H8] theorem add_idem (x : α) : x + x = x := by 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 theorem mul_idem (x : α) : x * x = x := by rw [← H5 (x * x), ← H8 x] -- x * x + x * n(x) rw [← H4, H7, H6] -- x * (x + n(x)), x * 1, x theorem add_one (x : α) : x + 1 = 1 := by rw [← H6 (x + 1), H2] -- 1 * (x + 1) rw (occs := .pos [1]) [← H7 x] -- (x + n(x)) * (x + 1): only the first 1 rw [← H3, H6, H7] -- x + n(x) * 1, x + n(x), 1 theorem one_add (x : α) : 1 + x = 1 := by rw [H1, add_one] theorem mul_zero (x : α) : x * 0 = 0 := by rw [← H5 (x * 0), H1] -- 0 + x * 0 rw (occs := .pos [1]) [← H8 x] -- x * n(x) + x * 0: only the first 0 rw [← H4, H5, H8] -- x * (n(x) + 0), x * n(x), 0 theorem zero_mul (x : α) : 0 * x = 0 := by rw [H2, mul_zero] theorem absorb (x y : α) : x + x * y = x := by rw (occs := .pos [1]) [← H6 x] -- x * 1 + x * y rw [← H4, H1, add_one, H6] -- x * (1 + y), x * (y + 1), x theorem absorb_mul (x y : α) : x * (x + y) = x := by rw [H4, mul_idem, absorb] theorem absorb_right (x y : α) : x * y + x = x := by rw [H1, absorb] theorem absorb_mul_right (x y : α) : (x + y) * x = x := by rw [H2, absorb_mul] theorem add_compl_mul (x y : α) : x + n x * y = x + y := by rw [H3, H7, one_mul] theorem mul_compl_add (x y : α) : x * (n x + y) = x * y := by rw [H4, H8, zero_add] theorem compl_add_mul (x y : α) : n x + x * y = n x + y := by rw [H3, compl_add, one_mul] theorem compl_mul_add (x y : α) : n x * (x + y) = n x * y := by rw [H4, compl_mul, zero_add] theorem compl_zero : (n 0 : α) = 1 := by rw [← zero_add (n 0), H7] theorem compl_one : (n 1 : α) = 0 := by rw [← one_mul (n 1), H8] theorem compl_compl (x : α) : n (n x) = x := by 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 theorem merge (x y : α) : x * y + x * n y = x := by rw [← H4, H7, H6] theorem merge_mul (x y : α) : (x + y) * (x + n y) = x := by rw [← H3, H8, H5] theorem split_along (x y : α) : x * y + n x * y = y := by rw [H2 x y, H2 (n x) y, ← H4, H7, H6] theorem split_along_mul (x y : α) : (x + y) * (n x + y) = y := by rw [H1 x y, H1 (n x) y, ← H3, H8, H5] theorem add_mul (x y z : α) : (x + y) * z = x * z + y * z := by rw [H2, H4, H2 z x, H2 z y] theorem add_distrib_right (x y z : α) : x * y + z = (x + z) * (y + z) := by rw [H1, H3, H1 z x, H1 z y] theorem add_mul_add (x y z w : α) : (x + y) * (z + w) = x * z + x * w + (y * z + y * w) := by rw [add_mul, H4, H4] theorem assoc_lemma_1 (x y z : α) : x * (x + y + z) = x := by rw [H4, absorb_mul, absorb] theorem assoc_lemma_2 (x y z : α) : n x * (x + y + z) = n x * (y + z) := by rw [H4, compl_mul_add, ← H4] theorem add_assoc (x y z : α) : x + (y + z) = x + y + z := by -- 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] theorem assoc_lemma_3 (x y z : α) : x + x * y * z = x := by rw [H3, absorb, absorb_mul] theorem assoc_lemma_4 (x y z : α) : n x + x * y * z = n x + y * z := by rw [H3, compl_add_mul, ← H3] theorem mul_assoc (x y z : α) : x * (y * z) = x * y * z := by 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] theorem add_left_comm (x y z : α) : x + (y + z) = y + (x + z) := by rw [add_assoc, H1 x y, ← add_assoc] theorem mul_left_comm (x y z : α) : x * (y * z) = y * (x * z) := by rw [mul_assoc, H2 x y, ← mul_assoc] theorem add_right_comm (x y z : α) : x + y + z = x + z + y := by rw [← add_assoc, H1 y z, add_assoc] theorem mul_right_comm (x y z : α) : x * y * z = x * z * y := by rw [← mul_assoc, H2 y z, mul_assoc] theorem add_idem_left (x y : α) : x + (x + y) = x + y := by rw [add_assoc, add_idem] theorem add_compl_add (x y : α) : x + (n x + y) = 1 := by rw [add_assoc, H7, one_add] theorem mul_compl_mul (x y : α) : x * (n x * y) = 0 := by rw [mul_assoc, H8, zero_mul] theorem modular (x y z : α) : x + y * (x + z) = (x + y) * (x + z) := by rw [H3, add_idem_left] theorem dm_one (x y : α) : x + y + n x * n y = 1 := by 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] theorem dm_zero (x y : α) : (x + y) * (n x * n y) = 0 := by rw [add_mul, mul_compl_mul, H2 (n x) (n y), mul_compl_mul, H5] theorem de_morgan_add (x y : α) : n (x + y) = n x * n y := by -- 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] theorem de_morgan_mul (x y : α) : n (x * y) = n x + n y := by rw [← compl_compl (n x + n y), de_morgan_add, compl_compl] rw [compl_compl] theorem de_morgan_add_compl (x y : α) : n (x + n y) = n x * y := by rw [de_morgan_add, compl_compl] theorem de_morgan_mul_compl (x y : α) : n (x * n y) = n x + y := by rw [de_morgan_mul, compl_compl] theorem mul_via_add (x y : α) : n (n x + n y) = x * y := by rw [de_morgan_add, compl_compl, compl_compl] theorem add_via_mul (x y : α) : n (n x * n y) = x + y := by rw [de_morgan_mul, compl_compl, compl_compl] theorem de_morgan_add3 (x y z : α) : n (x + y + z) = n x * n y * n z := by rw [de_morgan_add, de_morgan_add] theorem add_compl_sum (x y : α) : x + n (x + y) = x + n y := by rw [de_morgan_add, add_compl_mul] theorem mul_compl_prod (x y : α) : x * n (x * y) = x * n y := by rw [de_morgan_mul, mul_compl_add] theorem huntington (x y : α) : n (n x + y) + n (n x + n y) = x := by rw [de_morgan_add, de_morgan_add, compl_compl, compl_compl, ← H4] rw [compl_add, H6] theorem robbins (x y : α) : n (n (x + y) + n (x + n y)) = x := by rw [de_morgan_add, compl_compl, compl_compl, ← H3, H8, H5] theorem huntington_mul (x y : α) : n (n x * y) * n (n x * n y) = x := by rw [de_morgan_mul, de_morgan_mul, compl_compl, compl_compl, ← H3] rw [compl_mul, H5] theorem robbins_mul (x y : α) : n (n (x * y) * n (x * n y)) = x := by rw [de_morgan_mul, compl_compl, compl_compl, ← H4, H7, H6] theorem consensus (x y z : α) : x * y + n x * z + y * z = x * y + n x * z := by 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] theorem consensus_mul (x y z : α) : (x + y) * (n x + z) * (y + z) = (x + y) * (n x + z) := by 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] theorem median_self_dual (x y z : α) : (x + y) * (y + z) * (z + x) = x * y + y * z + z * x := by 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)] theorem dn1 (x y z u : α) : n (n (n (x + y) + z) + n (x + n (n z + n (z + u)))) = z := by -- 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] -- nand(nand(x, nand(nand(y, x), x)), nand(y, nand(z, x))) = y theorem sh1 (x y z : α) : n (n (x * n (n (y * x) * x)) * n (y * n (z * x))) = y := by -- 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] -- nand(nand(x, y), nand(x, nand(y, z))) = x theorem sheffer_basis (x y z : α) : n (n (x * y) * n (x * n (y * z))) = x := by -- 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] -- med(t, u, v) = u * v + (u + v) * t theorem med_ab (t u v : α) : t * u + t * v + u * v = u * v + (u + v) * t := by rw [H1, ← H4, ← H2 (u + v)] theorem mul_common (x y z : α) : x * y * (x * z) = x * (y * z) := by rw [← mul_assoc x y (x * z), mul_left_comm y x z] rw [mul_assoc x x (y * z), mul_idem] -- med(a + b * x, a + b * y, a + b * z) = a + b * med(x, y, z) theorem med_affine (a b x y z : α) : (a + b * x) * (a + b * y) + (a + b * x) * (a + b * z) + (a + b * y) * (a + b * z) = a + b * (x * y + x * z + y * z) := by -- (a + b * x) * (a + b * y) = a + b * (x * y) for each pair refine Eq.trans (b := (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] -- med(x, a + b * y, a + b * z) = a + b * med(x, y, z) theorem med_affine_2 (x a b y z : α) : x * (a + b * y) + x * (a + b * z) + (a + b * y) * (a + b * z) = a + b * (x * y + x * z + y * z) := by 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] rw (occs := .pos [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] -- med(med(x, y, z), u, v) = med(x, med(y, u, v), med(z, u, v)) theorem med_distrib (x y z u v : α) : (x * y + x * z + y * z) * u + (x * y + x * z + y * z) * v + u * v = x * (y * u + y * v + u * v) + x * (z * u + z * v + u * v) + (y * u + y * v + u * v) * (z * u + z * v + u * v) := by -- both sides are a + b * (…) for a = u * v and b = u + v rw [med_ab (x * y + x * z + y * z) u v, med_ab y u v, med_ab z u v] rw [med_affine_2] -- med(med(x, y, z), u, v) = med(med(x, u, v), med(y, u, v), med(z, u, v)) theorem med_distrib_sym (x y z u v : α) : (x * y + x * z + y * z) * u + (x * y + x * z + y * z) * v + u * v = (x * u + x * v + u * v) * (y * u + y * v + u * v) + (x * u + x * v + u * v) * (z * u + z * v + u * v) + (y * u + y * v + u * v) * (z * u + z * v + u * v) := by -- as med_distrib, but all the arguments are transformed rw [med_ab (x * y + x * z + y * z) u v, med_ab x u v, med_ab y u v] rw [med_ab z u v, med_affine] -- xor(x, y) = xor(y, x) theorem xor_comm (x y : α) : x * n y + n x * y = y * n x + n y * x := by rw [H1, H2, ← H2 (n y)] -- xor(x, 0) = x theorem xor_zero (x : α) : x * n 0 + n x * 0 = x := by rw [xor_comm, zero_mul, add_compl_mul, zero_add] -- xor(0, x) = x theorem zero_xor (x : α) : 0 * n x + n 0 * x = x := by rw [xor_comm, xor_zero] -- xor(x, 1) = n(x) theorem xor_one (x : α) : x * n 1 + n x * 1 = n x := by rw [compl_one, mul_zero, zero_add, H6] -- xor(x, x) = 0 theorem xor_self (x : α) : x * n x + n x * x = 0 := by rw [compl_mul, H5, H8] -- xor(x, n(x)) = 1 theorem xor_compl (x : α) : x * n (n x) + n x * n x = 1 := by rw [xor_comm, mul_idem, add_compl_mul, compl_add] -- x * xor(y, z) = xor(x * y, x * z) theorem mul_xor (x y z : α) : x * (y * n z + n y * z) = x * y * n (x * z) + n (x * y) * (x * z) := by 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] -- xor(x, y) * z = xor(x * z, y * z) theorem xor_mul (x y z : α) : (x * n y + n x * y) * z = x * z * n (y * z) + n (x * z) * (y * z) := by rw [H2 (x * n y + n x * y) z, mul_xor z x y, H2 z x, H2 z y] -- xor(xor(x, y), z) = xor(x, xor(y, z)) theorem xor_assoc (x y z : α) : (x * n y + n x * y) * n z + n (x * n y + n x * y) * z = x * n (y * n z + n y * z) + n x * (y * n z + n y * z) := by -- both sides: the sum of the minterms with an odd number of 1s refine Eq.trans (b := (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] -- xor(xor(x, y), z) = xor(xor(x, z), y) theorem xor_right_comm (x y z : α) : (x * n y + n x * y) * n z + n (x * n y + n x * y) * z = (x * n z + n x * z) * n y + n (x * n z + n x * z) * y := by rw [xor_assoc, xor_comm y z, ← xor_assoc] -- xor(xor(x, t), xor(y, t)) = xor(x, y) theorem xor_shift (x t y : α) : (x * n t + n x * t) * n (y * n t + n y * t) + n (x * n t + n x * t) * (y * n t + n y * t) = x * n y + n x * y := by rw [xor_assoc x t (y * n t + n y * t), xor_comm t (y * n t + n y * t)] rw [xor_assoc y t t, xor_self t, xor_zero y] -- xor(xor(t, x), xor(t, y)) = xor(x, y) theorem xor_shift_left (t x y : α) : (t * n x + n t * x) * n (t * n y + n t * y) + n (t * n x + n t * x) * (t * n y + n t * y) = x * n y + n x * y := by rw [xor_comm t x, xor_comm t y, xor_shift x t y] -- x + y = xor(x, y) + x * y theorem add_via_xor (x y : α) : x + y = x * n y + n x * y + x * y := by rw [H1 (x * n y + n x * y), add_assoc, merge, add_compl_mul] -- n(x * y) * xor(x, y) = xor(x, y) theorem xor_le_nand (x y : α) : n (x * y) * (x * n y + n x * y) = x * n y + n x * y := by 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] -- x * y * n(xor(x, y)) = x * y theorem mul_le_xnor (x y : α) : x * y * n (x * n y + n x * y) = x * y := by 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] -- xor(x * y, z * xor(x, y)) = x * y + z * xor(x, y) theorem xor_disjoint (x y z : α) : x * y * n (z * (x * n y + n x * y)) + n (x * y) * (z * (x * n y + n x * y)) = x * y + z * (x * n y + n x * y) := by rw [de_morgan_mul z (x * n y + n x * y), H4 (x * y) (n z) (n (x * n y + n 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 (x * n y + n x * y), xor_le_nand x y] -- med(x, y, z) = x * y + z * xor(x, y) theorem med_xy (x y z : α) : x * y + x * z + y * z = x * y + z * (x * n y + n x * y) := by -- 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 (x * n y + n x * y) (x * y) z] rw [H1 ((x * n y + n x * y) * z) (x * y * z)] rw [add_assoc, absorb (x * y) z, H2 (x * n y + n x * y) z] -- med(x, y, z) = xor(x * y, z * xor(x, y)) theorem med_split (x y z : α) : x * y + x * z + y * z = x * y * n (z * (x * n y + n x * y)) + n (x * y) * (z * (x * n y + n x * y)) := by rw [med_xy x y z, ← xor_disjoint x y z] -- med(x, y, z) = xor(xor(x * y, x * z), y * z) theorem med_xor (x y z : α) : x * y + x * z + y * z = (x * y * n (x * z) + n (x * y) * (x * z)) * n (y * z) + n (x * y * n (x * z) + n (x * y) * (x * z)) * (y * z) := by rw [med_split, mul_xor z x y, H2 z x, H2 z y, ← xor_assoc] -- med(x, y, z) = xor(x, xor(x, y) * xor(x, z)) theorem med_from_x (x y z : α) : x * y + x * z + y * z = x * n ((x * n y + n x * y) * (x * n z + n x * z)) + n x * ((x * n y + n x * y) * (x * n z + n x * z)) := by -- in the ring: x ⊕ (x ⊕ xy ⊕ xz ⊕ yz) = xy ⊕ xz ⊕ yz rw [mul_xor (x * n y + n x * y) x z, xor_mul x y x, mul_idem x] rw [xor_mul x y z] rw [← xor_assoc x (x * n (y * x) + n x * (y * x)) (x * z * n (y * z) + n (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] -- med(xor(x, t), xor(y, t), xor(z, t)) = xor(med(x, y, z), t) theorem med_shift (x t y z : α) : (x * n t + n x * t) * (y * n t + n y * t) + (x * n t + n x * t) * (z * n t + n z * t) + (y * n t + n y * t) * (z * n t + n z * t) = (x * y + x * z + y * z) * n t + n (x * y + x * z + y * z) * t := by -- med seen from x; a shift keeps the differences x ⊕ y rw [med_from_x (x * n t + n x * t) (y * n t + n y * t) (z * n t + n z * t)] rw [xor_shift x t y] rw [xor_shift x t z] rw [xor_right_comm x t ((x * n y + n x * y) * (x * n z + n x * z)), ← med_from_x x y z] -- xor(med(x, y, z), med(x, y, w)) = xor(x, y) * xor(z, w) theorem med_sensitivity (x y z w : α) : (x * y + x * z + y * z) * n (x * y + x * w + y * w) + n (x * y + x * z + y * z) * (x * y + x * w + y * w) = (x * n y + n x * y) * (z * n w + n z * w) := by -- 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 * (x * n y + n x * y)) (w * (x * n y + n x * y))] rw [← xor_mul z w (x * n y + n x * y), H2 (z * n w + n z * w) (x * n y + n x * y)] -- xor(med(x, y, z), med(x, y, n(z))) = xor(x, y) theorem med_derivative (x y z : α) : (x * y + x * z + y * z) * n (x * y + x * n z + y * n z) + n (x * y + x * z + y * z) * (x * y + x * n z + y * n z) = x * n y + n x * y := by -- w = n(z) and xor(z, n(z)) = 1 rw [med_sensitivity x y z (n z), xor_compl z, H6] -- xor(xor(a, b) * xor(c, d), a * c) = xor(xor(a * d, b * c), b * d) theorem product_rule (a b c d : α) : (a * n b + n a * b) * (c * n d + n c * d) * n (a * c) + n ((a * n b + n a * b) * (c * n d + n c * d)) * (a * c) = (a * d * n (b * c) + n (a * d) * (b * c)) * n (b * d) + n (a * d * n (b * c) + n (a * d) * (b * c)) * (b * d) := by -- (a ⊕ b)(c ⊕ d) = ac ⊕ bc ⊕ ad ⊕ bd; ac cancels ac rw [mul_xor (a * n b + n a * b) c d, xor_mul a b c, xor_mul a b d] rw [xor_right_comm (a * c * n (b * c) + n (a * c) * (b * c)) (a * d * n (b * d) + n (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)] -- ite(p, ite(q, a, b), ite(q, c, d)) = ite(q, ite(p, a, c), ite(p, b, d)) theorem ite_swap (p q a b c d : α) : p * (q * a + n q * b) + n p * (q * c + n q * d) = q * (p * a + n p * c) + n q * (p * b + n p * d) := by -- 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] -- ite(p, ite(p, a, b), ite(p, c, d)) = ite(p, a, d) theorem ite_redundant (p a b c d : α) : p * (p * a + n p * b) + n p * (p * c + n p * d) = p * a + n p * d := by rw [H4, H4, add_assoc, mul_assoc, mul_assoc, mul_assoc] rw [mul_assoc, mul_idem] rw (occs := .pos [1]) [H2 p a] rw [H8, zero_mul, H5, H2 (n p), H8, zero_mul, H5, mul_idem, ← H2] theorem two_implications (x y z : α) : (n x + y) * (n y + z) = n x * n y + y * z := by 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)] theorem cycle_3 (x y z : α) : (n x + y) * (n y + z) * (n z + x) = x * y * z + n x * n y * n z := by -- (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] theorem cycle_4 (x y z w : α) : (n x + y) * (n y + z) * (n z + w) * (n w + x) = x * y * z * w + n x * n y * n z * n w := by -- 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] rw (occs := .pos [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] -- Assumptions: only the fields of the class (the axioms H1–H8), no axioms of Lean. #print axioms add_assoc #print axioms robbins