math / data /lean /OAI /LinearAlgebra /MatrixMultiplication /Separation /ComplexFiniteControl.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
5.99 kB
import Mathlib.Data.Fintype.EquivFin
import Mathlib.Data.Fintype.BigOperators
import Mathlib.Logic.Equiv.Sum
import Mathlib.Algebra.Order.BigOperators.Ring.Finset
import Mathlib.Algebra.BigOperators.Group.Finset.Piecewise
import Mathlib.Combinatorics.Additive.AP.Three.Defs
import Mathlib.Basic.Real.Basic
import Mathlib.Data.Rat.Lemmas
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.Ring
namespace OAI
/-! Finite type counts, hierarchy separation and tensor execution bounds. -/
namespace MatrixMultiplication.Foundation
namespace FiniteControl
open scoped BigOperators
theorem every_path_safe {State : Type*} (Safe : β„• β†’ State β†’ Prop)
(Allows : β„• β†’ State β†’ State β†’ Prop) (n : β„•) (path : β„• β†’ State)
(initial : Safe 0 (path 0))
(closed : βˆ€ t < n, βˆ€ s s', Safe t s β†’ Allows t s s' β†’ Safe (t + 1) s')
(steps : βˆ€ t < n, Allows t (path t) (path (t + 1))) :
βˆ€ t ≀ n, Safe t (path t) := by
intro t
induction t with
| zero => intro _; exact initial
| succ t ih =>
intro ht
have htn : t < n := Nat.lt_of_succ_le ht
exact closed t htn (path t) (path (t + 1))
(ih (Nat.le_of_lt htn)) (steps t htn)
theorem exists_population_preserving_equiv {I J Node : Type*}
[Fintype I] [Fintype J] [DecidableEq Node]
(f : I β†’ Node) (g : J β†’ Node)
(counts : βˆ€ node, Fintype.card {i // f i = node} =
Fintype.card {j // g j = node}) :
βˆƒ e : I ≃ J, βˆ€ i, g (e i) = f i := by
classical
let ef : βˆ€ node, {i // f i = node} ≃ {j // g j = node} :=
fun node => Fintype.equivOfCardEq (counts node)
refine ⟨(Equiv.sigmaFiberEquiv f).symm.trans
((Equiv.sigmaCongrRight ef).trans (Equiv.sigmaFiberEquiv g)), ?_⟩
intro i
exact (ef (f i) ⟨i, rfl⟩).property
theorem population_product_eq {I J Node M : Type*}
[Fintype I] [Fintype J] [DecidableEq Node] [CommMonoid M]
(f : I β†’ Node) (g : J β†’ Node)
(counts : βˆ€ node, Fintype.card {i // f i = node} =
Fintype.card {j // g j = node}) (cost : Node β†’ M) :
(∏ i, cost (f i)) = ∏ j, cost (g j) := by
obtain ⟨e, he⟩ := exists_population_preserving_equiv f g counts
calc
(∏ i, cost (f i)) = ∏ i, cost (g (e i)) := by
apply Finset.prod_congr rfl
intro i _
rw [he i]
_ = ∏ j, cost (g j) := e.prod_comp (fun j => cost (g j))
theorem exists_common_bank_multiple {Node : Type*} [Fintype Node]
(denominator blockSize : Node β†’ β„•)
(denominator_pos : βˆ€ node, 0 < denominator node)
(blockSize_pos : βˆ€ node, 0 < blockSize node) :
βˆƒ bank : β„•, 0 < bank ∧
βˆ€ node, denominator node * blockSize node ∣ bank := by
classical
refine ⟨∏ node, denominator node * blockSize node, ?_, ?_⟩
Β· exact Finset.prod_pos fun node _ =>
Nat.mul_pos (denominator_pos node) (blockSize_pos node)
Β· intro node
exact Finset.dvd_prod_of_mem (fun node => denominator node * blockSize node)
(Finset.mem_univ node)
theorem exists_exact_rational_tiling {Node : Type*} [Fintype Node]
(weight : Node β†’ β„š) (nonnegative : βˆ€ node, 0 ≀ weight node)
(blockSize : Node β†’ β„•) (blockSize_pos : βˆ€ node, 0 < blockSize node) :
βˆƒ bank : β„•, 0 < bank ∧ βˆ€ node, βˆƒ copies : β„•,
(bank : β„š) * weight node = (copies * blockSize node : β„•) := by
obtain ⟨bank, bank_pos, divisible⟩ := exists_common_bank_multiple
(fun node => (weight node).den) blockSize
(fun node => (weight node).den_pos) blockSize_pos
refine ⟨bank, bank_pos, ?_⟩
intro node
obtain ⟨multiple, hmultiple⟩ := divisible node
refine ⟨multiple * (weight node).num.toNat, ?_⟩
have hnum : ((weight node).num.toNat : β„š) = ((weight node).num : β„š) := by
exact_mod_cast Int.toNat_of_nonneg (Rat.num_nonneg.mpr (nonnegative node))
have hden : ((weight node).den : β„š) β‰  0 := by
exact_mod_cast (weight node).den_ne_zero
calc
(bank : β„š) * weight node =
(bank : β„š) * (((weight node).num : β„š) / ((weight node).den : β„š)) := by
rw [(weight node).num_div_den]
_ = ((multiple * (weight node).num.toNat) * blockSize node : β„•) := by
rw [hmultiple]
push_cast
rw [hnum]
field_simp [hden]
theorem target_relation_of_windows (a b c : β„€) (x y z d : ℝ)
(hd : 0 < d) (tight : x + y + z = 0)
(hx : |x - (a : ℝ) * d| ≀ d / 10)
(hy : |y - (b : ℝ) * d| ≀ d / 10)
(hz : |z + 2 * (c : ℝ) * d| ≀ d / 10) :
a + b = c + c := by
obtain ⟨hxβ‚€, hxβ‚βŸ© := abs_le.mp hx
obtain ⟨hyβ‚€, hyβ‚βŸ© := abs_le.mp hy
obtain ⟨hzβ‚€, hzβ‚βŸ© := abs_le.mp hz
let k : β„€ := a + b - 2 * c
have hkcast : (k : ℝ) = (a : ℝ) + (b : ℝ) - 2 * (c : ℝ) := by
simp [k]
have hlow : -(1 : ℝ) < (k : ℝ) := by
by_contra hn
have hn' : (k : ℝ) ≀ -1 := le_of_not_gt hn
have hm := mul_le_mul_of_nonneg_right hn' (le_of_lt hd)
rw [hkcast] at hm
nlinarith
have hhigh : (k : ℝ) < 1 := by
by_contra hn
have hn' : 1 ≀ (k : ℝ) := le_of_not_gt hn
have hm := mul_le_mul_of_nonneg_right hn' (le_of_lt hd)
rw [hkcast] at hm
nlinarith
have hsmall : |(k : ℝ)| < 1 := abs_lt.mpr ⟨hlow, hhigh⟩
have hsmallInt : |k| < 1 := by exact_mod_cast hsmall
have hk : k = 0 := Int.abs_lt_one_iff.mp hsmallInt
dsimp [k] at hk
linarith
theorem synchronized_targets_of_windows (targets : Set β„€)
(free : ThreeAPFree targets) (a b c : β„€)
(ha : a ∈ targets) (hb : b ∈ targets) (hc : c ∈ targets)
(x y z d : ℝ) (hd : 0 < d) (tight : x + y + z = 0)
(hx : |x - (a : ℝ) * d| ≀ d / 10)
(hy : |y - (b : ℝ) * d| ≀ d / 10)
(hz : |z + 2 * (c : ℝ) * d| ≀ d / 10) :
a = b ∧ a = c := by
have hrelation := target_relation_of_windows a b c x y z d hd tight hx hy hz
have hac : a = c := free ha hc hb hrelation
exact ⟨by linarith, hac⟩
end FiniteControl
end MatrixMultiplication.Foundation
end OAI