Download lean/OAI/Computability/UniqueGames/Quadratic/Block.lean from roseking/openAI-math-dataset: direct link, hf CLI and curl.
- Browser
- Download file 6.77 kB
-
https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Computability/UniqueGames/Quadratic/Block.lean
- Command line
-
hf download hf://datasets/roseking/openAI-math-dataset/lean/OAI/Computability/UniqueGames/Quadratic/Block.lean
-
curl -L -o Block.lean https://huggingface.co/datasets/roseking/openAI-math-dataset/resolve/main/lean/OAI/Computability/UniqueGames/Quadratic/Block.lean
6.77 kB
| import Mathlib.Algebra.CharP.Two | |
| import Mathlib.Data.Fin.VecNotation | |
| import Mathlib.Data.ZMod.Basic | |
| import Mathlib.LinearAlgebra.Prod | |
| import Mathlib.LinearAlgebra.Span.Basic | |
| import Mathlib.Tactic.FinCases | |
| import Mathlib.Tactic.Ring | |
| namespace OAI | |
| section | |
| namespace UniqueGamesTheorem.Quadratic | |
| abbrev Vec (F : Type*) := Fin 3 → F | |
| variable {F : Type*} [Field F] | |
| /-- The three-coordinate quadratic block from equation (2.4). -/ | |
| def Q (x : Vec F) : Vec F := ![x 1 * x 2, x 0 * x 2, x 0 * x 1] | |
| /-- Its polar cross-terms. In characteristic two these equal | |
| `Q (x + a) + Q x + Q a`. -/ | |
| def D (x a : Vec F) : Vec F := | |
| ![x 1 * a 2 + a 1 * x 2, x 0 * a 2 + a 0 * x 2, | |
| x 0 * a 1 + a 0 * x 1] | |
| /-- Field dot product, with all three coordinates displayed. -/ | |
| def dot (v y : Vec F) : F := v 0 * y 0 + v 1 * y 1 + v 2 * y 2 | |
| @[simp] theorem Q_zero : Q (0 : Vec F) = 0 := by | |
| ext i | |
| fin_cases i <;> simp [Q] | |
| theorem Q_add (x a : Vec F) : Q (x + a) = Q x + Q a + D x a := by | |
| ext i | |
| fin_cases i <;> simp [Q, D] <;> ring | |
| @[simp] theorem D_zero_left (a : Vec F) : D 0 a = 0 := by | |
| ext i | |
| fin_cases i <;> simp [D] | |
| @[simp] theorem D_zero_right (x : Vec F) : D x 0 = 0 := by | |
| ext i | |
| fin_cases i <;> simp [D] | |
| theorem D_comm (x a : Vec F) : D x a = D a x := by | |
| ext i | |
| fin_cases i <;> simp [D, add_comm] | |
| theorem D_add_left (x y a : Vec F) : D (x + y) a = D x a + D y a := by | |
| ext i | |
| fin_cases i <;> simp [D] <;> ring | |
| theorem D_add_right (x a b : Vec F) : D x (a + b) = D x a + D x b := by | |
| rw [D_comm, D_add_left, D_comm a x, D_comm b x] | |
| theorem D_smul_left (t : F) (x a : Vec F) : D (t • x) a = t • D x a := by | |
| ext i | |
| fin_cases i <;> simp [D, smul_eq_mul] <;> ring | |
| theorem D_smul_right (t : F) (x a : Vec F) : D x (t • a) = t • D x a := by | |
| rw [D_comm, D_smul_left, D_comm a x] | |
| @[simp] theorem dot_zero_right (v : Vec F) : dot v 0 = 0 := by simp [dot] | |
| @[simp] theorem dot_zero_left (y : Vec F) : dot 0 y = 0 := by simp [dot] | |
| theorem dot_add_right (v y z : Vec F) : dot v (y + z) = dot v y + dot v z := by | |
| simp [dot] | |
| ring | |
| theorem dot_smul_right (v y : Vec F) (t : F) : dot v (t • y) = t * dot v y := by | |
| simp [dot, smul_eq_mul] | |
| ring | |
| theorem dot_smul_left (v y : Vec F) (t : F) : dot (t • v) y = t * dot v y := by | |
| simp [dot, smul_eq_mul] | |
| ring | |
| /-- The field line generated by `v`. -/ | |
| def line (v : Vec F) : Submodule F (Vec F) := Submodule.span F {v} | |
| /-- The field hyperplane perpendicular to the generator of the line. -/ | |
| def hyperplane (v : Vec F) : Submodule F (Vec F) where | |
| carrier := {y | dot v y = 0} | |
| zero_mem' := dot_zero_right v | |
| add_mem' := by | |
| intro y z hy hz | |
| rw [Set.mem_ofPred_eq, dot_add_right, hy, hz, add_zero] | |
| smul_mem' := by | |
| intro t y hy | |
| rw [Set.mem_ofPred_eq, dot_smul_right, hy, mul_zero] | |
| @[simp] theorem mem_hyperplane (v y : Vec F) : y ∈ hyperplane v ↔ dot v y = 0 := Iff.rfl | |
| theorem mem_line_iff (v a : Vec F) : a ∈ line v ↔ ∃ t : F, t • v = a := | |
| Submodule.mem_span_singleton | |
| section CharacteristicTwo | |
| variable [CharP F 2] | |
| @[simp] theorem vec_add_self (x : Vec F) : x + x = 0 := by | |
| ext i | |
| exact CharTwo.add_self_eq_zero (x i) | |
| theorem D_eq_polar (x a : Vec F) : D x a = Q (x + a) + Q x + Q a := by | |
| rw [Q_add] | |
| have h : Q x + Q a + D x a + Q x + Q a = | |
| D x a + (Q x + Q x) + (Q a + Q a) := by ac_rfl | |
| rw [h, vec_add_self, vec_add_self, add_zero, add_zero] | |
| private theorem cross_self_zero (u w s t : F) : | |
| (t * u) * (s * w) + (s * u) * (t * w) = 0 := by | |
| calc | |
| _ = (t * s * u * w) + (t * s * u * w) := by ring | |
| _ = 0 := CharTwo.add_self_eq_zero _ | |
| /-- The polar expression vanishes on any pair of vectors in the same field line. -/ | |
| theorem D_smul_smul_zero (v : Vec F) (t s : F) : D (t • v) (s • v) = 0 := by | |
| ext i | |
| fin_cases i <;> simp [D, smul_eq_mul, cross_self_zero] | |
| /-- Every cross-term arising from a shift along `Fv` is perpendicular to `v`. -/ | |
| theorem dot_D_smul (v x : Vec F) (t : F) : dot v (D x (t • v)) = 0 := by | |
| change v 0 * (x 1 * (t * v 2) + (t * v 1) * x 2) + | |
| v 1 * (x 0 * (t * v 2) + (t * v 0) * x 2) + | |
| v 2 * (x 0 * (t * v 1) + (t * v 0) * x 1) = 0 | |
| calc | |
| _ = (t * (v 0 * v 2 * x 1 + v 0 * v 1 * x 2 + v 1 * v 2 * x 0)) + | |
| (t * (v 0 * v 2 * x 1 + v 0 * v 1 * x 2 + v 1 * v 2 * x 0)) := by ring | |
| _ = 0 := CharTwo.add_self_eq_zero _ | |
| theorem D_mem_hyperplane (v x a : Vec F) (ha : a ∈ line v) : | |
| D x a ∈ hyperplane v := by | |
| obtain ⟨t, rfl⟩ := (mem_line_iff v a).mp ha | |
| exact dot_D_smul v x t | |
| theorem D_eq_zero_of_mem_line (v a b : Vec F) | |
| (ha : a ∈ line v) (hb : b ∈ line v) : D a b = 0 := by | |
| obtain ⟨t, rfl⟩ := (mem_line_iff v a).mp ha | |
| obtain ⟨s, rfl⟩ := (mem_line_iff v b).mp hb | |
| exact D_smul_smul_zero v t s | |
| /-- The restriction of the quadratic map to one field line is additive. -/ | |
| theorem Q_add_of_mem_line (v a b : Vec F) | |
| (ha : a ∈ line v) (hb : b ∈ line v) : Q (a + b) = Q a + Q b := by | |
| rw [Q_add, D_eq_zero_of_mem_line v a b ha hb, add_zero] | |
| variable [Algebra (ZMod 2) F] | |
| /-- The block space `U_A`, as an actual binary submodule. Membership uses | |
| `y + Q a` because subtraction equals addition in characteristic two. -/ | |
| def U (v : Vec F) : Submodule (ZMod 2) (Vec F × Vec F) where | |
| carrier := {p | p.1 ∈ line v ∧ dot v (p.2 + Q p.1) = 0} | |
| zero_mem' := by simp [Q_zero] | |
| add_mem' := by | |
| intro p q hp hq | |
| refine ⟨(line v).add_mem hp.1 hq.1, ?_⟩ | |
| change dot v ((p.2 + q.2) + Q (p.1 + q.1)) = 0 | |
| rw [Q_add_of_mem_line v p.1 q.1 hp.1 hq.1] | |
| have h : (p.2 + q.2) + (Q p.1 + Q q.1) = | |
| (p.2 + Q p.1) + (q.2 + Q q.1) := by ac_rfl | |
| rw [h, dot_add_right, hp.2, hq.2, add_zero] | |
| smul_mem' := by | |
| intro c p hp | |
| have hc : c = 0 ∨ c = 1 := by | |
| fin_cases c | |
| · exact Or.inl rfl | |
| · exact Or.inr rfl | |
| rcases hc with rfl | rfl | |
| · simp [Q_zero] | |
| · simpa using hp | |
| @[simp] theorem mem_U (v : Vec F) (p : Vec F × Vec F) : | |
| p ∈ U v ↔ p.1 ∈ line v ∧ dot v (p.2 + Q p.1) = 0 := Iff.rfl | |
| theorem pair_mem_U (v a w : Vec F) (ha : a ∈ line v) (hw : w ∈ hyperplane v) : | |
| (a, Q a + w) ∈ U v := by | |
| refine ⟨ha, ?_⟩ | |
| change dot v (Q a + w + Q a) = 0 | |
| have h : Q a + w + Q a = w + (Q a + Q a) := by ac_rfl | |
| simpa [h] using hw | |
| theorem mem_U_iff_exists (v : Vec F) (p : Vec F × Vec F) : | |
| p ∈ U v ↔ ∃ a ∈ line v, ∃ w ∈ hyperplane v, p = (a, Q a + w) := by | |
| constructor | |
| · intro hp | |
| refine ⟨p.1, hp.1, p.2 + Q p.1, hp.2, ?_⟩ | |
| apply Prod.ext | |
| · rfl | |
| · change p.2 = Q p.1 + (p.2 + Q p.1) | |
| have h : Q p.1 + (p.2 + Q p.1) = p.2 + (Q p.1 + Q p.1) := by ac_rfl | |
| rw [h, vec_add_self, add_zero] | |
| · rintro ⟨a, ha, w, hw, rfl⟩ | |
| exact pair_mem_U v a w ha hw | |
| end CharacteristicTwo | |
| end UniqueGamesTheorem.Quadratic | |
| end | |
| end OAI | |