Lean / Reader
Lean reader

CubeParity.lean

76 lines13 declarationsno sorryimports Std
  1. import Std
  2. namespace CubeParity
  3. def Cube : Nat → Type
  4. | 0 => Unit
  5. | n+1 => Bool × Cube n
  6. def total : (n : Nat) → (Cube n → Rat) → Rat
  7. | 0, f => f ()
  8. | n+1, f => total n (fun y => f (false, y)) + total n (fun y => f (true, y))
  9. def parity : (n : Nat) → Cube n → Rat
  10. | 0, _ => 1
  11. | n+1, (b,x) => if b then -parity n x else parity n x
  12. def distance : (n : Nat) → Cube n → Cube n → Nat
  13. | 0, _, _ => 0
  14. | n+1, (b,x), (c,y) => distance n x y + (if b == c then 0 else 1)
  15. def diff : Nat → (Nat → Rat) → Rat
  16. | 0, f => f 0
  17. | n+1, f => diff n f - diff n (fun j => f (j+1))
  18. theorem total_neg (n : Nat) (f : Cube n → Rat) :
  19. total n (fun y => -(f y)) = -(total n f) := by
  20. induction n with
  21. | zero => rfl
  22. | succ n ih =>
  23. simp only [total, ih]
  24. grind
  25. theorem parity_row (n : Nat) (f : Nat → Rat) (x : Cube n) :
  26. total n (fun y => f (distance n x y) * parity n y) = parity n x * diff n f := by
  27. induction n generalizing f with
  28. | zero => simp [total, distance, parity, diff]
  29. | succ n ih =>
  30. obtain ⟨b,x⟩ := x
  31. cases b <;> simp [total, distance, parity, diff, Rat.mul_neg, total_neg,
  32. ih f x, ih (fun j => f (j+1)) x] <;> grind
  33. def choose2 (m : Nat) := m*(m-1)/2
  34. def entry (j : Nat) : Rat :=
  35. 16 / ((9*choose2 (8-j) + 15*j*(8-j) + 25*choose2 j : Nat) : Rat)
  36. theorem parity_eigenvalue (x : Cube 8) :
  37. total 8 (fun y => entry (distance 8 x y) * parity 8 y) =
  38. parity 8 x * (-190592 / 1063516360725) := by
  39. rw [parity_row]
  40. congr 1
  41. decide +kernel
  42. theorem parity_square (n : Nat) (x : Cube n) : parity n x * parity n x = 1 := by
  43. induction n with
  44. | zero => simp [parity]
  45. | succ n ih =>
  46. obtain ⟨b,x⟩ := x
  47. cases b <;> simp [parity, ih, Rat.neg_mul, Rat.mul_neg]
  48. def PosSemidefinite (n : Nat) (f : Nat → Rat) : Prop :=
  49. ∀ w : Cube n → Rat,
  50. 0 ≤ total n (fun x => w x * total n (fun y => f (distance n x y) * w y))
  51. theorem not_posSemidefinite : ¬ PosSemidefinite 8 entry := by
  52. intro h
  53. have bad := h (parity 8)
  54. have row (x : Cube 8) : parity 8 x *
  55. total 8 (fun y => entry (distance 8 x y) * parity 8 y) =
  56. -190592 / 1063516360725 := by
  57. rw [parity_eigenvalue, ← Rat.mul_assoc, parity_square, Rat.one_mul]
  58. simp only [row] at bad
  59. exact (by decide +kernel : ¬ (0 : Rat) ≤ total 8 (fun _ => -190592 / 1063516360725)) bad
  60. end CubeParity