introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
5.26 kB
import OAI.LinearAlgebra.MatrixMultiplication.Separation.ComplexFiniteControl
namespace OAI
/-! Tensor extraction over arbitrary fields and its asymptotic rate. -/
namespace MatrixMultiplication.AllFieldPopulationCounts
open scoped BigOperators
noncomputable section
variable {I : Type*} [Fintype I] [DecidableEq I]
def denominator (w : I β†’ β„š) : β„• := ∏ i, (w i).den
def baseCount (w : I β†’ β„š) (i : I) : β„• :=
(w i).num.toNat * ∏ j ∈ Finset.univ.erase i, (w j).den
def count (w : I β†’ β„š) (m : β„•) (i : I) : β„• := m * baseCount w i
def blockLength (w : I β†’ β„š) (m : β„•) : β„• := m * denominator w
omit [DecidableEq I] in
theorem denominator_pos (w : I β†’ β„š) : 0 < denominator w := by
exact Finset.prod_pos fun i _ => (w i).den_pos
theorem denominator_factor (w : I β†’ β„š) (i : I) :
(w i).den * (∏ j ∈ Finset.univ.erase i, (w j).den) = denominator w := by
exact Finset.mul_prod_erase Finset.univ (fun j => (w j).den) (Finset.mem_univ i)
theorem baseCount_cast (w : I β†’ β„š) (hw : βˆ€ i, 0 ≀ w i) (i : I) :
(baseCount w i : β„š) = (denominator w : β„š) * w i := by
have hnum : ((w i).num.toNat : β„š) = ((w i).num : β„š) := by
exact_mod_cast Int.toNat_of_nonneg (Rat.num_nonneg.mpr (hw i))
have hden : ((w i).den : β„š) β‰  0 := by exact_mod_cast (w i).den_ne_zero
have hq : ((w i).num : β„š) = w i * ((w i).den : β„š) := by
calc
((w i).num : β„š) =
(((w i).num : β„š) / ((w i).den : β„š)) * ((w i).den : β„š) :=
(div_mul_cancelβ‚€ _ hden).symm
_ = w i * ((w i).den : β„š) := by rw [(w i).num_div_den]
rw [baseCount, ← denominator_factor w i]
push_cast
rw [hnum, hq]
ring
theorem count_cast (w : I β†’ β„š) (hw : βˆ€ i, 0 ≀ w i) (m : β„•) (i : I) :
(count w m i : β„š) = (m : β„š) * (denominator w : β„š) * w i := by
simp only [count, Nat.cast_mul, baseCount_cast w hw, mul_assoc]
theorem count_cast_blockLength (w : I β†’ β„š) (hw : βˆ€ i, 0 ≀ w i)
(m : β„•) (i : I) :
(count w m i : β„š) = (blockLength w m : β„š) * w i := by
simpa only [blockLength, Nat.cast_mul] using count_cast w hw m i
omit [DecidableEq I] in
theorem blockLength_pos (w : I β†’ β„š) {m : β„•} (hm : 0 < m) :
0 < blockLength w m := Nat.mul_pos hm (denominator_pos w)
theorem count_zero_iff (w : I β†’ β„š) (hw : βˆ€ i, 0 ≀ w i)
{m : β„•} (hm : 0 < m) (i : I) : count w m i = 0 ↔ w i = 0 := by
have hD : (denominator w : β„š) β‰  0 := by
exact_mod_cast (ne_of_gt (denominator_pos w))
have hM : (m : β„š) β‰  0 := by exact_mod_cast (ne_of_gt hm)
have h : (count w m i : β„š) = 0 ↔ w i = 0 := by
rw [count_cast w hw]
simp only [mul_eq_zero, hM, hD, false_or]
simpa only [Nat.cast_eq_zero] using h
theorem count_pos_iff (w : I β†’ β„š) (hw : βˆ€ i, 0 ≀ w i)
{m : β„•} (hm : 0 < m) (i : I) : 0 < count w m i ↔ 0 < w i := by
rw [Nat.pos_iff_ne_zero, ne_eq, count_zero_iff w hw hm]
constructor
Β· intro h
exact lt_of_le_of_ne (hw i) (Ne.symm h)
Β· exact ne_of_gt
theorem sum_count_cast {J : Type*} (w : I β†’ β„š) (hw : βˆ€ i, 0 ≀ w i)
(m : β„•) (s : Finset J) (f : J β†’ I) :
((βˆ‘ j ∈ s, count w m (f j) : β„•) : β„š) =
(blockLength w m : β„š) * βˆ‘ j ∈ s, w (f j) := by
simp only [Nat.cast_sum, count_cast_blockLength w hw]
rw [Finset.mul_sum]
theorem transition_sum {J : Type*} (w : I β†’ β„š) (hw : βˆ€ i, 0 ≀ w i)
(m : β„•) (s : Finset J) (f : J β†’ I) (parent : I)
(hs : βˆ‘ j ∈ s, w (f j) = w parent) :
βˆ‘ j ∈ s, count w m (f j) = count w m parent := by
apply Nat.cast_injective (R := β„š)
rw [sum_count_cast w hw, hs, count_cast_blockLength w hw]
theorem unit_sum {J : Type*} (w : I β†’ β„š) (hw : βˆ€ i, 0 ≀ w i)
(m : β„•) (s : Finset J) (f : J β†’ I)
(hs : βˆ‘ j ∈ s, w (f j) = 1) :
βˆ‘ j ∈ s, count w m (f j) = blockLength w m := by
apply Nat.cast_injective (R := β„š)
rw [sum_count_cast w hw, hs, mul_one]
theorem count_eq_of_mass_eq (w : I β†’ β„š) (hw : βˆ€ i, 0 ≀ w i)
(m : β„•) {i j : I} (h : w i = w j) : count w m i = count w m j := by
apply Nat.cast_injective (R := β„š)
rw [count_cast w hw, count_cast w hw, h]
theorem count_ratio (w : I β†’ β„š) (hw : βˆ€ i, 0 ≀ w i)
{m : β„•} (hm : 0 < m) (i : I) :
(count w m i : β„š) / blockLength w m = w i := by
rw [count_cast_blockLength w hw]
have h : (blockLength w m : β„š) β‰  0 := by
exact_mod_cast (ne_of_gt (blockLength_pos w hm))
exact mul_div_cancel_leftβ‚€ _ h
theorem count_dilate (w : I β†’ β„š) (m n : β„•) (i : I) :
count w (m * n) i = m * count w n i := by simp [count, Nat.mul_assoc]
theorem dilation_le_count (w : I β†’ β„š) (hw : βˆ€ i, 0 ≀ w i)
(m : β„•) (i : I) (hi : 0 < w i) : m ≀ count w m i := by
have hb : 0 < baseCount w i := by
have h := (count_pos_iff w hw (m := 1) (by decide) i).2 hi
simpa only [count, one_mul] using h
calc
m = m * 1 := (Nat.mul_one m).symm
_ ≀ m * baseCount w i := Nat.mul_le_mul_left m hb
theorem two_le_positive_count (w : I β†’ β„š) (hw : βˆ€ i, 0 ≀ w i)
{m : β„•} (hm : 2 ≀ m) (i : I) (hi : 0 < w i) : 2 ≀ count w m i :=
hm.trans (dilation_le_count w hw m i hi)
end
end MatrixMultiplication.AllFieldPopulationCounts
end OAI