math / data /lean /OAI /LinearAlgebra /MatrixFields /Histories /InverseLinearRecovery.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
28.8 kB
import Mathlib
import OAI.LinearAlgebra.MatrixFields.Construction.FiniteCover
import OAI.LinearAlgebra.MatrixFields.Tensors.ComplexDotPairing
namespace OAI
namespace MatrixAllFields
open scoped BigOperators Topology Polynomial
section
open scoped BigOperators
open MatrixMultiplication.Foundation
namespace MatrixMultiplication.ExactRecovery
variable {K X Y Z I A B C : Type*} [CommSemiring K]
def delete (Q : Tensor K X Y Z) (px : X β†’ Prop) (py : Y β†’ Prop)
(pz : Z β†’ Prop) [DecidablePred px] [DecidablePred py] [DecidablePred pz] :
Tensor K X Y Z := fun x y z => if px x ∧ py y ∧ pz z then Q x y z else 0
def presence [Fintype I] [DecidableEq I] (p : I β†’ X β†’ Prop)
[βˆ€ i, DecidablePred (p i)] (x : X) : Finset I :=
Finset.univ.filter fun i => p i x
@[simp] theorem mem_presence [Fintype I] [DecidableEq I] (p : I β†’ X β†’ Prop)
[βˆ€ i, DecidablePred (p i)] (x : X) (i : I) :
i ∈ presence p x ↔ p i x := by simp [presence]
theorem restrict_rectangles
[Fintype X] [Fintype Y] [Fintype Z]
[Fintype A] [Fintype B] [Fintype C]
[DecidableEq X] [DecidableEq Y] [DecidableEq Z]
[DecidableEq A] [DecidableEq B] [DecidableEq C]
(Q H : Tensor K X Y Z) (cx : X β†’ A) (cy : Y β†’ B) (cz : Z β†’ C)
(fx : A Γ— B Γ— C β†’ X β†’ X) (fy : A Γ— B Γ— C β†’ Y β†’ Y)
(fz : A Γ— B Γ— C β†’ Z β†’ Z)
(h : βˆ€ x y z, H (fx (cx x, cy y, cz z) x)
(fy (cx x, cy y, cz z) y) (fz (cx x, cy y, cz z) z) = Q x y z) :
Tensor.restrict
(fun x s => if cx x = s.1.1 ∧ s.2 = fx s.1 x then (1 : K) else 0)
(fun y s => if cy y = s.1.2.1 ∧ s.2 = fy s.1 y then (1 : K) else 0)
(fun z s => if cz z = s.1.2.2 ∧ s.2 = fz s.1 z then (1 : K) else 0)
(Tensor.directSum (fun _ : A Γ— B Γ— C => H)) = Q := by
funext x y z
simp [Tensor.restrict, Tensor.directSum, Fintype.sum_prod_type,
ite_and, ite_mul, mul_ite, h]
theorem repair_of_cover
[Fintype X] [Fintype Y] [Fintype Z] [Fintype I] [DecidableEq I] [Nonempty I]
(Q H : Tensor K X Y Z)
(px : I β†’ X β†’ Prop) (py : I β†’ Y β†’ Prop) (pz : I β†’ Z β†’ Prop)
(fx : I β†’ X β†’ X) (fy : I β†’ Y β†’ Y) (fz : I β†’ Z β†’ Z)
(hshift : βˆ€ i x y z, H (fx i x) (fy i y) (fz i z) =
@delete K X Y Z _ Q (px i) (py i) (pz i)
(Classical.decPred _) (Classical.decPred _) (Classical.decPred _) x y z)
(hcover : βˆ€ x y z, Q x y z β‰  0 β†’ βˆƒ i, px i x ∧ py i y ∧ pz i z) :
βˆƒ (a : X β†’ ((Finset I Γ— Finset I Γ— Finset I) Γ— X) β†’ K)
(b : Y β†’ ((Finset I Γ— Finset I Γ— Finset I) Γ— Y) β†’ K)
(c : Z β†’ ((Finset I Γ— Finset I Γ— Finset I) Γ— Z) β†’ K),
Tensor.restrict a b c
(Tensor.directSum (fun _ : Finset I Γ— Finset I Γ— Finset I => H)) = Q := by
classical
let pick : Finset I Γ— Finset I Γ— Finset I β†’ I := fun r =>
if h : βˆƒ i, i ∈ r.1 ∧ i ∈ r.2.1 ∧ i ∈ r.2.2 then Classical.choose h
else Classical.choice inferInstance
have hpick (r : Finset I Γ— Finset I Γ— Finset I)
(hr : βˆƒ i, i ∈ r.1 ∧ i ∈ r.2.1 ∧ i ∈ r.2.2) :
pick r ∈ r.1 ∧ pick r ∈ r.2.1 ∧ pick r ∈ r.2.2 := by
simpa [pick, hr] using Classical.choose_spec hr
let cx := presence px
let cy := presence py
let cz := presence pz
have hrect (x : X) (y : Y) (z : Z) :
H (fx (pick (cx x, cy y, cz z)) x)
(fy (pick (cx x, cy y, cz z)) y)
(fz (pick (cx x, cy y, cz z)) z) = Q x y z := by
rw [hshift]
by_cases hq : Q x y z = 0
Β· simp [delete, hq]
· rcases hcover x y z hq with ⟨i, hix, hiy, hiz⟩
have hp := hpick (cx x, cy y, cz z)
⟨i, by simpa [cx] using hix, by simpa [cy] using hiy,
by simpa [cz] using hiz⟩
have hpx : px (pick (cx x, cy y, cz z)) x := by simpa [cx] using hp.1
have hpy : py (pick (cx x, cy y, cz z)) y := by simpa [cy] using hp.2.1
have hpz : pz (pick (cx x, cy y, cz z)) z := by simpa [cz] using hp.2.2
simp [delete, hpx, hpy, hpz]
exact ⟨_, _, _, restrict_rectangles Q H cx cy cz
(fun r => fx (pick r)) (fun r => fy (pick r)) (fun r => fz (pick r)) hrect⟩
theorem card_mask_rectangles [Fintype I] :
Fintype.card (Finset I Γ— Finset I Γ— Finset I) = 2 ^ (3 * Fintype.card I) := by
classical
simp only [Fintype.card_prod, Fintype.card_finset]
rw [Nat.mul_comm 3 (Fintype.card I), pow_mul]
simp [pow_succ, mul_assoc]
theorem repair_of_counting
[Fintype X] [Fintype Y] [Fintype Z] [Fintype I]
[DecidableEq X] [DecidableEq Y] [DecidableEq Z] [DecidableEq I]
(Q H : Tensor K X Y Z)
(px : I β†’ X β†’ Prop) (py : I β†’ Y β†’ Prop) (pz : I β†’ Z β†’ Prop)
(fx : I β†’ X β†’ X) (fy : I β†’ Y β†’ Y) (fz : I β†’ Z β†’ Z)
(hshift : βˆ€ i x y z, H (fx i x) (fy i y) (fz i z) =
@delete K X Y Z _ Q (px i) (py i) (pz i)
(Classical.decPred _) (Classical.decPred _) (Classical.decPred _) x y z)
(t L : β„•) (hL : 0 < L)
(hbad : βˆ€ x y z, Q x y z β‰  0 β†’
(@Finset.filter I (fun i => ¬(px i x ∧ py i y ∧ pz i z))
(Classical.decPred _) Finset.univ).card ≀ t)
(hbudget : (@Finset.filter (X Γ— Y Γ— Z)
(fun p => Q p.1 p.2.1 p.2.2 β‰  0) (Classical.decPred _) Finset.univ).card * t ^ L <
Fintype.card I ^ L) :
βˆƒ (a : X β†’ ((Finset (Fin L) Γ— Finset (Fin L) Γ— Finset (Fin L)) Γ— X) β†’ K)
(b : Y β†’ ((Finset (Fin L) Γ— Finset (Fin L) Γ— Finset (Fin L)) Γ— Y) β†’ K)
(c : Z β†’ ((Finset (Fin L) Γ— Finset (Fin L) Γ— Finset (Fin L)) Γ— Z) β†’ K),
Tensor.restrict a b c
(Tensor.directSum (fun _ : Finset (Fin L) Γ— Finset (Fin L) Γ— Finset (Fin L) => H)) = Q := by
classical
let support : Finset (X Γ— Y Γ— Z) := @Finset.filter (X Γ— Y Γ— Z)
(fun p => Q p.1 p.2.1 p.2.2 β‰  0) (Classical.decPred _) Finset.univ
let good (i : I) (p : X Γ— Y Γ— Z) : Prop := px i p.1 ∧ py i p.2.1 ∧ pz i p.2.2
have hbad' : βˆ€ p ∈ support, (Finset.univ.filter fun i => Β¬good i p).card ≀ t := by
intro p hp
have heq : (Finset.univ.filter fun i => Β¬good i p) =
@Finset.filter I (fun i => ¬(px i p.1 ∧ py i p.2.1 ∧ pz i p.2.2))
(Classical.decPred _) Finset.univ := by
ext i
simp only [Finset.mem_filter, good]
rw [heq]
apply hbad p.1 p.2.1 p.2.2
simpa only [support, Finset.mem_filter, Finset.mem_univ, true_and] using hp
obtain ⟨f, hf⟩ := FiniteCover.exists_cover support good t L hbad' hbudget
let : Nonempty (Fin L) := ⟨⟨0, hL⟩⟩
exact repair_of_cover Q H (fun i => px (f i)) (fun i => py (f i))
(fun i => pz (f i)) (fun i => fx (f i)) (fun i => fy (f i))
(fun i => fz (f i)) (fun i => hshift (f i))
(fun x y z hq => hf (x, y, z) (by simp [support, hq]))
end MatrixMultiplication.ExactRecovery
end
section
open scoped BigOperators
namespace MatrixMultiplication.OrbitCounting
variable {G X : Type*} [Group G] [MulAction G X] [Fintype G] [DecidableEq X]
def orbitSet (x : X) : Finset X := Finset.univ.image fun g : G => g β€’ x
@[simp] theorem smul_mem_orbitSet (x : X) (g : G) : g β€’ x ∈ orbitSet (G := G) x := by
exact Finset.mem_image.mpr ⟨g, Finset.mem_univ _, rfl⟩
theorem card_fiber_eq (x y : X) (hy : y ∈ orbitSet (G := G) x) :
Fintype.card {g : G // g β€’ x = y} = Fintype.card {g : G // g β€’ x = x} := by
classical
obtain ⟨r, _, hr⟩ := Finset.mem_image.mp hy
let e : {g : G // g β€’ x = y} ≃ {g : G // g β€’ x = x} :=
{ toFun := fun g => ⟨r⁻¹ * g.1, by
rw [mul_smul, g.2, ← hr, inv_smul_smul]⟩
invFun := fun g => ⟨r * g.1, by
rw [mul_smul, g.2, hr]⟩
left_inv := by intro g; apply Subtype.ext; simp
right_inv := by intro g; apply Subtype.ext; simp }
exact Fintype.card_congr e
theorem card_group (x : X) :
Fintype.card G = (orbitSet (G := G) x).card *
Fintype.card {g : G // g β€’ x = x} := by
classical
let e := Equiv.sigmaSubtypeFiberEquiv (fun g : G => g β€’ x)
(fun y => y ∈ orbitSet (G := G) x) (smul_mem_orbitSet x)
calc
Fintype.card G = Fintype.card (Σ y : {y // y ∈ orbitSet (G := G) x},
{g : G // g β€’ x = y.1}) := (Fintype.card_congr e).symm
_ = βˆ‘ y : {y // y ∈ orbitSet (G := G) x},
Fintype.card {g : G // g β€’ x = y.1} := Fintype.card_sigma
_ = βˆ‘ _y : {y // y ∈ orbitSet (G := G) x},
Fintype.card {g : G // g β€’ x = x} := by
apply Finset.sum_congr rfl
intro y _
exact card_fiber_eq x y.1 y.2
_ = _ := by simp
theorem bad_shift_count (x : X) (bad : X β†’ Prop) [DecidablePred bad] :
(Finset.univ.filter fun g : G => bad (g β€’ x)).card =
((orbitSet (G := G) x).filter bad).card *
Fintype.card {g : G // g β€’ x = x} := by
classical
let e := Equiv.sigmaSubtypeFiberEquivSubtype (fun g : G => g β€’ x)
(p := fun g => bad (g β€’ x))
(q := fun y => y ∈ (orbitSet (G := G) x).filter bad)
(fun g => by simp)
calc
(Finset.univ.filter fun g : G => bad (g β€’ x)).card =
Fintype.card {g : G // bad (g β€’ x)} := (Fintype.card_subtype _).symm
_ = Fintype.card (Σ y : {y // y ∈ (orbitSet (G := G) x).filter bad},
{g : G // g β€’ x = y.1}) := (Fintype.card_congr e).symm
_ = βˆ‘ y : {y // y ∈ (orbitSet (G := G) x).filter bad},
Fintype.card {g : G // g β€’ x = y.1} := Fintype.card_sigma
_ = βˆ‘ _y : {y // y ∈ (orbitSet (G := G) x).filter bad},
Fintype.card {g : G // g β€’ x = x} := by
apply Finset.sum_congr rfl
intro y _
exact card_fiber_eq x y.1 (Finset.mem_filter.mp y.2).1
_ = _ := by simp
theorem bad_shift_bound (x : X) (bad : X β†’ Prop) [DecidablePred bad] (N C : β„•)
(h : N * ((orbitSet (G := G) x).filter bad).card ≀ C * (orbitSet (G := G) x).card) :
N * (Finset.univ.filter fun g : G => bad (g β€’ x)).card ≀ C * Fintype.card G := by
rw [bad_shift_count, card_group (G := G) x]
simpa only [Nat.mul_assoc] using Nat.mul_le_mul_right
(Fintype.card {g : G // g β€’ x = x}) h
theorem bad_shift_fraction (x : X) (bad : X β†’ Prop) [DecidablePred bad] :
((Finset.univ.filter fun g : G => bad (g β€’ x)).card : ℝ) / Fintype.card G =
(((orbitSet (G := G) x).filter bad).card : ℝ) / (orbitSet (G := G) x).card := by
have hsNat : 0 < Fintype.card {g : G // g β€’ x = x} :=
Fintype.card_pos_iff.mpr ⟨⟨1, one_smul G x⟩⟩
have hs : (Fintype.card {g : G // g β€’ x = x} : ℝ) β‰  0 :=
Nat.cast_ne_zero.mpr (Nat.ne_of_gt hsNat)
rw [bad_shift_count, card_group (G := G) x]
simp only [Nat.cast_mul]
exact mul_div_mul_right _ _ hs
end MatrixMultiplication.OrbitCounting
end
section
open scoped BigOperators
open MatrixMultiplication.Foundation
namespace MatrixMultiplication.OrbitRecovery
variable {G X Y Z : Type*} [Group G] [Fintype G]
[MulAction G X] [MulAction G Y] [MulAction G Z]
[DecidableEq X] [DecidableEq Y] [DecidableEq Z]
def badShifts (px : X β†’ Prop) (py : Y β†’ Prop) (pz : Z β†’ Prop)
[DecidablePred px] [DecidablePred py] [DecidablePred pz]
(x : X) (y : Y) (z : Z) : Finset G :=
Finset.univ.filter fun g => Β¬(px (g β€’ x) ∧ py (g β€’ y) ∧ pz (g β€’ z))
omit [DecidableEq X] [DecidableEq Y] [DecidableEq Z] in
theorem badShifts_card_le (px : X β†’ Prop) (py : Y β†’ Prop) (pz : Z β†’ Prop)
[DecidablePred px] [DecidablePred py] [DecidablePred pz]
(x : X) (y : Y) (z : Z) :
(badShifts (G := G) px py pz x y z).card ≀
(Finset.univ.filter fun g : G => Β¬px (g β€’ x)).card +
(Finset.univ.filter fun g : G => Β¬py (g β€’ y)).card +
(Finset.univ.filter fun g : G => Β¬pz (g β€’ z)).card := by
classical
have heq : badShifts (G := G) px py pz x y z =
(Finset.univ.filter fun g : G => Β¬px (g β€’ x)) βˆͺ
((Finset.univ.filter fun g : G => Β¬py (g β€’ y)) βˆͺ
(Finset.univ.filter fun g : G => Β¬pz (g β€’ z))) := by
ext g
by_cases hx : px (g β€’ x) <;> by_cases hy : py (g β€’ y) <;>
by_cases hz : pz (g β€’ z) <;> simp [badShifts, hx, hy, hz]
rw [heq]
exact (Finset.card_union_le _ _).trans
((Nat.add_le_add_left (Finset.card_union_le _ _) _).trans (le_of_eq (Nat.add_assoc _ _ _).symm))
theorem badShifts_fraction_le_at (px : X β†’ Prop) (py : Y β†’ Prop) (pz : Z β†’ Prop)
[DecidablePred px] [DecidablePred py] [DecidablePred pz]
(Ξ³ : ℝ) (x : X) (y : Y) (z : Z)
(hx : (((OrbitCounting.orbitSet (G := G) x).filter fun v => Β¬px v).card : ℝ) /
(OrbitCounting.orbitSet (G := G) x).card ≀ Ξ³)
(hy : (((OrbitCounting.orbitSet (G := G) y).filter fun v => Β¬py v).card : ℝ) /
(OrbitCounting.orbitSet (G := G) y).card ≀ Ξ³)
(hz : (((OrbitCounting.orbitSet (G := G) z).filter fun v => Β¬pz v).card : ℝ) /
(OrbitCounting.orbitSet (G := G) z).card ≀ Ξ³)
:
((badShifts (G := G) px py pz x y z).card : ℝ) / Fintype.card G ≀ 3 * Ξ³ := by
have hg : (0 : ℝ) < Fintype.card G := Nat.cast_pos.mpr Fintype.card_pos
have hx' := hx
have hy' := hy
have hz' := hz
rw [← OrbitCounting.bad_shift_fraction (G := G) x (fun v => Β¬px v)] at hx'
rw [← OrbitCounting.bad_shift_fraction (G := G) y (fun v => Β¬py v)] at hy'
rw [← OrbitCounting.bad_shift_fraction (G := G) z (fun v => Β¬pz v)] at hz'
have hxc := (div_le_iffβ‚€ hg).mp hx'
have hyc := (div_le_iffβ‚€ hg).mp hy'
have hzc := (div_le_iffβ‚€ hg).mp hz'
have hc : ((badShifts (G := G) px py pz x y z).card : ℝ) ≀
((Finset.univ.filter fun g : G => Β¬px (g β€’ x)).card : ℝ) +
((Finset.univ.filter fun g : G => Β¬py (g β€’ y)).card : ℝ) +
((Finset.univ.filter fun g : G => Β¬pz (g β€’ z)).card : ℝ) := by
exact_mod_cast badShifts_card_le (G := G) px py pz x y z
apply (div_le_iffβ‚€ hg).mpr
linarith
theorem floor_loss_fraction (Ξ³ : ℝ) (hΞ³ : 0 ≀ Ξ³) :
(Nat.floor (3 * Ξ³ * Fintype.card G) : ℝ) / Fintype.card G ≀ 3 * Ξ³ := by
have hg : (0 : ℝ) < Fintype.card G := Nat.cast_pos.mpr Fintype.card_pos
apply (div_le_iffβ‚€ hg).mpr
exact Nat.floor_le (by positivity)
theorem repair_from_orbit_loss
{K : Type*} [CommSemiring K] [Fintype X] [Fintype Y] [Fintype Z]
(Q : Tensor K X Y Z)
(px : X β†’ Prop) (py : Y β†’ Prop) (pz : Z β†’ Prop)
[DecidablePred px] [DecidablePred py] [DecidablePred pz]
(hpreserve : βˆ€ (g : G) x y z, Q (g β€’ x) (g β€’ y) (g β€’ z) = Q x y z)
(Ξ³ : ℝ)
(hx : βˆ€ x, (βˆƒ y z, Q x y z β‰  0) β†’ (((OrbitCounting.orbitSet (G := G) x).filter fun v => Β¬px v).card : ℝ) /
(OrbitCounting.orbitSet (G := G) x).card ≀ Ξ³)
(hy : βˆ€ y, (βˆƒ x z, Q x y z β‰  0) β†’ (((OrbitCounting.orbitSet (G := G) y).filter fun v => Β¬py v).card : ℝ) /
(OrbitCounting.orbitSet (G := G) y).card ≀ Ξ³)
(hz : βˆ€ z, (βˆƒ x y, Q x y z β‰  0) β†’ (((OrbitCounting.orbitSet (G := G) z).filter fun v => Β¬pz v).card : ℝ) /
(OrbitCounting.orbitSet (G := G) z).card ≀ Ξ³)
(L : β„•) (hL : 0 < L)
(hbudget : (@Finset.filter (X Γ— Y Γ— Z)
(fun p => Q p.1 p.2.1 p.2.2 β‰  0) (Classical.decPred _) Finset.univ).card *
Nat.floor (3 * Ξ³ * Fintype.card G) ^ L < Fintype.card G ^ L) :
βˆƒ (a : X β†’ ((Finset (Fin L) Γ— Finset (Fin L) Γ— Finset (Fin L)) Γ— X) β†’ K)
(b : Y β†’ ((Finset (Fin L) Γ— Finset (Fin L) Γ— Finset (Fin L)) Γ— Y) β†’ K)
(c : Z β†’ ((Finset (Fin L) Γ— Finset (Fin L) Γ— Finset (Fin L)) Γ— Z) β†’ K),
Tensor.restrict a b c (Tensor.directSum
(fun _ : Finset (Fin L) Γ— Finset (Fin L) Γ— Finset (Fin L) =>
ExactRecovery.delete Q px py pz)) = Q := by
classical
apply ExactRecovery.repair_of_counting (I := G) Q (ExactRecovery.delete Q px py pz)
(fun g x => px (g β€’ x)) (fun g y => py (g β€’ y)) (fun g z => pz (g β€’ z))
(fun g x => g β€’ x) (fun g y => g β€’ y) (fun g z => g β€’ z)
(fun g x y z => by simp [ExactRecovery.delete, hpreserve])
(Nat.floor (3 * Ξ³ * Fintype.card G)) L hL ?_ hbudget
intro x y z hq
have heq : (@Finset.filter G
(fun g => Β¬(px (g β€’ x) ∧ py (g β€’ y) ∧ pz (g β€’ z)))
(Classical.decPred _) Finset.univ) = badShifts (G := G) px py pz x y z := by
ext g
simp only [badShifts, Finset.mem_filter]
rw [heq]
apply Nat.le_floor
have hg : (0 : ℝ) < Fintype.card G := Nat.cast_pos.mpr Fintype.card_pos
exact (div_le_iffβ‚€ hg).mp (badShifts_fraction_le_at (G := G) px py pz Ξ³ x y z
(hx x ⟨y, z, hq⟩) (hy y ⟨x, z, hq⟩) (hz z ⟨x, y, hq⟩))
end MatrixMultiplication.OrbitRecovery
end
section
noncomputable section
namespace MatrixMultiplication.RecoveryGrowth
open Filter
open scoped Topology BigOperators
def shiftCount (b C : ℝ) (N : β„•) : β„• :=
⌈(b + 1) * (N : ℝ) / Real.log ((N : ℝ) / (3 * C))βŒ‰β‚Š
def replicationCount (b C : ℝ) (N : β„•) : β„• :=
2 ^ (3 * shiftCount b C N)
theorem shiftCount_pos {b C : ℝ} {N : β„•}
(hb : 0 ≀ b) (hC : 0 < C) (hN : 3 * C < (N : ℝ)) :
0 < shiftCount b C N := by
have hC3 : 0 < 3 * C := by linarith
have hN0 : 0 < (N : ℝ) := hC3.trans hN
have hlog : 0 < Real.log ((N : ℝ) / (3 * C)) :=
Real.log_pos ((one_lt_div hC3).2 hN)
exact Nat.ceil_pos.2 (div_pos (mul_pos (by linarith) hN0) hlog)
theorem support_loss_bound {b C : ℝ} {N : β„•}
(hC : 0 < C) (hN : 3 * C < (N : ℝ)) :
Real.exp (b * N) * (3 * C / (N : ℝ)) ^ shiftCount b C N ≀
Real.exp (-(N : ℝ)) := by
have hC3 : 0 < 3 * C := by linarith
have hN0 : 0 < (N : ℝ) := hC3.trans hN
have hlog : 0 < Real.log ((N : ℝ) / (3 * C)) :=
Real.log_pos ((one_lt_div hC3).2 hN)
have hceil : (b + 1) * (N : ℝ) ≀
(shiftCount b C N : ℝ) * Real.log ((N : ℝ) / (3 * C)) := by
exact (div_le_iffβ‚€ hlog).1 (Nat.le_ceil _)
have hbase : 3 * C / (N : ℝ) =
Real.exp (-Real.log ((N : ℝ) / (3 * C))) := by
rw [Real.exp_neg, Real.exp_log (div_pos hN0 hC3)]
simp
rw [hbase, ← Real.exp_nat_mul, ← Real.exp_add]
apply Real.exp_le_exp.mpr
nlinarith
theorem cardinal_budget {b C : ℝ} {N S t g : β„•}
(hC : 0 < C) (hN : 3 * C < (N : ℝ)) (hg : 0 < g)
(hS : (S : ℝ) ≀ Real.exp (b * N))
(ht : (t : ℝ) / (g : ℝ) ≀ 3 * C / (N : ℝ)) :
S * t ^ shiftCount b C N < g ^ shiftCount b C N := by
have hgr : 0 < (g : ℝ) := by exact_mod_cast hg
have hN0 : 0 < (N : ℝ) := by linarith
have hpow := pow_le_pow_leftβ‚€
(div_nonneg (Nat.cast_nonneg t) hgr.le) ht (shiftCount b C N)
have hprob : (S : ℝ) * ((t : ℝ) / (g : ℝ)) ^ shiftCount b C N < 1 := by
calc
(S : ℝ) * ((t : ℝ) / (g : ℝ)) ^ shiftCount b C N ≀
Real.exp (b * N) * (3 * C / (N : ℝ)) ^ shiftCount b C N :=
mul_le_mul hS hpow (pow_nonneg (div_nonneg (Nat.cast_nonneg t) hgr.le) _)
(Real.exp_pos _).le
_ ≀ Real.exp (-(N : ℝ)) := support_loss_bound hC hN
_ < 1 := by rw [Real.exp_lt_one_iff]; linarith
rw [div_pow, ← mul_div_assoc] at hprob
have hreal := (div_lt_iffβ‚€ (pow_pos hgr (shiftCount b C N))).1 hprob
simp only [one_mul] at hreal
exact_mod_cast hreal
theorem exists_cover {M G : Type*} [Fintype G] [Nonempty G]
[DecidableEq G] [DecidableEq M]
(s : Finset M) (good : G β†’ M β†’ Prop) [βˆ€ g, DecidablePred (good g)]
{b C : ℝ} {N : β„•} (hC : 0 < C) (hN : 3 * C < (N : ℝ))
(hs : (s.card : ℝ) ≀ Real.exp (b * N))
(hbad : βˆ€ m ∈ s,
((Finset.univ.filter fun g => Β¬good g m).card : ℝ) / Fintype.card G ≀
3 * C / (N : ℝ)) :
βˆƒ f : Fin (shiftCount b C N) β†’ G, βˆ€ m ∈ s, βˆƒ i, good (f i) m := by
let t := ⌊(3 * C / (N : ℝ)) * Fintype.card GβŒ‹β‚Š
have hg : 0 < (Fintype.card G : ℝ) := by exact_mod_cast Fintype.card_pos
have harg : 0 ≀ (3 * C / (N : ℝ)) * Fintype.card G := by
exact mul_nonneg (div_nonneg (by linarith) (Nat.cast_nonneg N)) hg.le
apply FiniteCover.exists_cover s good t (shiftCount b C N)
Β· intro m hm
exact Nat.le_floor ((div_le_iffβ‚€ hg).1 (hbad m hm))
Β· apply cardinal_budget hC hN Fintype.card_pos hs
exact (div_le_iffβ‚€ hg).2 (Nat.floor_le harg)
theorem shiftCount_div_nat_le {b C : ℝ} {N : β„•}
(hb : 0 < b) (hC : 0 < C) (hN : 3 * C < (N : ℝ)) :
(shiftCount b C N : ℝ) / (N : ℝ) ≀
(b + 1) / Real.log ((N : ℝ) / (3 * C)) + 1 / (N : ℝ) := by
have hC3 : 0 < 3 * C := by linarith
have hN0 : 0 < (N : ℝ) := hC3.trans hN
have hlog : 0 < Real.log ((N : ℝ) / (3 * C)) :=
Real.log_pos ((one_lt_div hC3).2 hN)
have harg : 0 ≀ (b + 1) * (N : ℝ) / Real.log ((N : ℝ) / (3 * C)) :=
div_nonneg (mul_nonneg (by linarith) hN0.le) hlog.le
have hceil := div_le_div_of_nonneg_right (Nat.ceil_lt_add_one harg).le hN0.le
change (shiftCount b C N : ℝ) / (N : ℝ) ≀ _ at hceil
convert hceil using 1
field_simp [hN0.ne', hlog.ne']
theorem tendsto_shiftCount_div_nat {b C : ℝ} (hb : 0 < b) (hC : 0 < C) :
Tendsto (fun N : β„• => (shiftCount b C N : ℝ) / (N : ℝ)) atTop (𝓝 0) := by
have hnat : Tendsto (fun N : β„• => (N : ℝ)) atTop atTop :=
tendsto_natCast_atTop_atTop
have hlog : Tendsto (fun N : β„• => Real.log ((N : ℝ) / (3 * C))) atTop atTop :=
Real.tendsto_log_atTop.comp (hnat.atTop_div_const (by linarith))
have hmain : Tendsto (fun N : β„• =>
(b + 1) / Real.log ((N : ℝ) / (3 * C))) atTop (𝓝 0) :=
tendsto_const_nhds.div_atTop hlog
have herr : Tendsto (fun N : β„• => 1 / (N : ℝ)) atTop (𝓝 0) :=
tendsto_const_nhds.div_atTop hnat
apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds
(by simpa only [add_zero] using hmain.add herr)
Β· exact Eventually.of_forall fun N => div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _)
Β· filter_upwards [hnat.eventually_gt_atTop (3 * C)] with N hN
exact shiftCount_div_nat_le hb hC hN
theorem eventually_shiftCount_div_nat_le_log {b C : ℝ} (hb : 0 < b) (hC : 0 < C) :
βˆ€αΆ  N : β„• in atTop, (shiftCount b C N : ℝ) / (N : ℝ) ≀
(2 * b + 3) / Real.log (N : ℝ) := by
have hnat : Tendsto (fun N : β„• => (N : ℝ)) atTop atTop :=
tendsto_natCast_atTop_atTop
have hlognat := Real.tendsto_log_atTop.comp hnat
filter_upwards [hnat.eventually_gt_atTop (3 * C), hnat.eventually_gt_atTop 1,
hlognat.eventually_ge_atTop (2 * Real.log (3 * C))] with N hN hN1 hlarge
change 2 * Real.log (3 * C) ≀ Real.log (N : ℝ) at hlarge
have hN0 : 0 < (N : ℝ) := lt_trans zero_lt_one hN1
have hC3 : 0 < 3 * C := by linarith
have hlog : 0 < Real.log (N : ℝ) := Real.log_pos hN1
have hden : 0 < Real.log ((N : ℝ) / (3 * C)) :=
Real.log_pos ((one_lt_div hC3).2 hN)
have hhalf : Real.log (N : ℝ) ≀ 2 * Real.log ((N : ℝ) / (3 * C)) := by
rw [Real.log_div hN0.ne' hC3.ne']
linarith
have hmain : (b + 1) / Real.log ((N : ℝ) / (3 * C)) ≀
(2 * (b + 1)) / Real.log (N : ℝ) := by
apply (div_le_div_iffβ‚€ hden hlog).2
nlinarith [mul_le_mul_of_nonneg_left hhalf (show 0 ≀ b + 1 by linarith)]
have herr : 1 / (N : ℝ) ≀ 1 / Real.log (N : ℝ) :=
div_le_div_of_nonneg_left zero_le_one hlog (Real.log_le_self hN0.le)
calc
(shiftCount b C N : ℝ) / (N : ℝ) ≀
(b + 1) / Real.log ((N : ℝ) / (3 * C)) + 1 / (N : ℝ) :=
shiftCount_div_nat_le hb hC hN
_ ≀ (2 * (b + 1)) / Real.log (N : ℝ) + 1 / Real.log (N : ℝ) :=
add_le_add hmain herr
_ = (2 * b + 3) / Real.log (N : ℝ) := by ring
theorem log_replicationCount (b C : ℝ) (N : β„•) :
Real.log (replicationCount b C N : ℝ) =
(3 * Real.log 2) * (shiftCount b C N : ℝ) := by
simp only [replicationCount, Nat.cast_pow, Real.log_pow, Nat.cast_mul, Nat.cast_ofNat]
ring
theorem eventually_log_replicationCount_div_nat_le_log {b C : ℝ}
(hb : 0 < b) (hC : 0 < C) :
βˆ€αΆ  N : β„• in atTop, Real.log (replicationCount b C N : ℝ) / (N : ℝ) ≀
(3 * Real.log 2 * (2 * b + 3)) / Real.log (N : ℝ) := by
filter_upwards [eventually_shiftCount_div_nat_le_log hb hC] with N hN
have hlog2 : 0 ≀ 3 * Real.log 2 :=
mul_nonneg (by norm_num) (Real.log_nonneg (by norm_num))
simpa only [log_replicationCount, mul_div_assoc] using
mul_le_mul_of_nonneg_left hN hlog2
theorem tendsto_log_replicationCount_div_nat {b C : ℝ} (hb : 0 < b) (hC : 0 < C) :
Tendsto (fun N : β„• => Real.log (replicationCount b C N : ℝ) / (N : ℝ))
atTop (𝓝 0) := by
have h := (tendsto_shiftCount_div_nat hb hC).const_mul (3 * Real.log 2)
simp only [mul_zero] at h
convert h using 1
ext N
simp only [log_replicationCount]
ring
theorem eventually_replicationCount_le_exp {b C Ξ΅ : ℝ}
(hb : 0 < b) (hC : 0 < C) (hΞ΅ : 0 < Ξ΅) :
βˆ€αΆ  N : β„• in atTop, (replicationCount b C N : ℝ) ≀ Real.exp (Ξ΅ * N) := by
filter_upwards [(tendsto_log_replicationCount_div_nat hb hC).eventually_lt_const hΞ΅,
eventually_gt_atTop (0 : β„•)] with N hrate hN
have hN0 : 0 < (N : ℝ) := by exact_mod_cast hN
have hrep : 0 < (replicationCount b C N : ℝ) := by
simp only [replicationCount, Nat.cast_pow, Nat.cast_ofNat]
exact pow_pos (by norm_num) _
exact (Real.log_le_iff_le_exp hrep).1 ((div_lt_iffβ‚€ hN0).1 hrate).le
theorem tendsto_log_prod_div_nat {J : Type*} (s : Finset J)
{r : J β†’ β„• β†’ β„•}
(hr : βˆ€ j ∈ s, βˆ€ N, 0 < r j N)
(hlim : βˆ€ j ∈ s, Tendsto (fun N => Real.log (r j N : ℝ) / (N : ℝ))
atTop (𝓝 0)) :
Tendsto (fun N => Real.log ((∏ j ∈ s, r j N : β„•) : ℝ) / (N : ℝ))
atTop (𝓝 0) := by
have hsum := tendsto_finsetSum s hlim
simp only [Finset.sum_const_zero] at hsum
apply hsum.congr
intro N
rw [Nat.cast_prod, Real.log_prod
(fun j hj => Nat.cast_ne_zero.mpr (Nat.ne_of_gt (hr j hj N)))]
simp only [div_eq_mul_inv, Finset.sum_mul]
end MatrixMultiplication.RecoveryGrowth
end
end
section
open MatrixMultiplication.Foundation
namespace MatrixMultiplication.InverseLinearRecovery
abbrev MaskRectangles (L : β„•) := Finset (Fin L) Γ— Finset (Fin L) Γ— Finset (Fin L)
def RecoveredBy {K X Y Z : Type*} [CommSemiring K]
[Fintype X] [Fintype Y] [Fintype Z]
(Q H : Tensor K X Y Z) (L : β„•) : Prop :=
βˆƒ (a : X β†’ (MaskRectangles L Γ— X) β†’ K)
(b : Y β†’ (MaskRectangles L Γ— Y) β†’ K)
(c : Z β†’ (MaskRectangles L Γ— Z) β†’ K),
Tensor.restrict a b c (Tensor.directSum (fun _ : MaskRectangles L => H)) = Q
theorem repair_inverse_linear
{K G X Y Z : Type*} [CommSemiring K] [Group G] [Fintype G]
[MulAction G X] [MulAction G Y] [MulAction G Z]
[Fintype X] [Fintype Y] [Fintype Z]
[DecidableEq X] [DecidableEq Y] [DecidableEq Z]
(Q : Tensor K X Y Z)
(px : X β†’ Prop) (py : Y β†’ Prop) (pz : Z β†’ Prop)
[DecidablePred px] [DecidablePred py] [DecidablePred pz]
(hpreserve : βˆ€ (g : G) x y z, Q (g β€’ x) (g β€’ y) (g β€’ z) = Q x y z)
{b C : ℝ} {N : β„•} (hb : 0 ≀ b) (hC : 0 < C) (hN : 3 * C < (N : ℝ))
(hsupport : ((@Finset.filter (X Γ— Y Γ— Z)
(fun p => Q p.1 p.2.1 p.2.2 β‰  0) (Classical.decPred _) Finset.univ).card : ℝ) ≀
Real.exp (b * N))
(hx : βˆ€ x, (βˆƒ y z, Q x y z β‰  0) β†’ (((OrbitCounting.orbitSet (G := G) x).filter fun v => Β¬px v).card : ℝ) /
(OrbitCounting.orbitSet (G := G) x).card ≀ C / N)
(hy : βˆ€ y, (βˆƒ x z, Q x y z β‰  0) β†’ (((OrbitCounting.orbitSet (G := G) y).filter fun v => Β¬py v).card : ℝ) /
(OrbitCounting.orbitSet (G := G) y).card ≀ C / N)
(hz : βˆ€ z, (βˆƒ x y, Q x y z β‰  0) β†’ (((OrbitCounting.orbitSet (G := G) z).filter fun v => Β¬pz v).card : ℝ) /
(OrbitCounting.orbitSet (G := G) z).card ≀ C / N) :
RecoveredBy Q (ExactRecovery.delete Q px py pz) (RecoveryGrowth.shiftCount b C N) := by
classical
apply OrbitRecovery.repair_from_orbit_loss Q px py pz hpreserve (C / N) hx hy hz
(RecoveryGrowth.shiftCount b C N) (RecoveryGrowth.shiftCount_pos hb hC hN)
apply RecoveryGrowth.cardinal_budget hC hN Fintype.card_pos hsupport
simpa only [mul_div_assoc] using
OrbitRecovery.floor_loss_fraction (G := G) (C / N)
(div_nonneg hC.le (Nat.cast_nonneg N))
theorem card_recovery_copies (b C : ℝ) (N : β„•) :
Fintype.card (MaskRectangles (RecoveryGrowth.shiftCount b C N)) =
RecoveryGrowth.replicationCount b C N := by
simpa only [MaskRectangles, Fintype.card_fin, RecoveryGrowth.replicationCount] using
(ExactRecovery.card_mask_rectangles (I := Fin (RecoveryGrowth.shiftCount b C N)))
theorem subexponential_copies {b C : ℝ} (hb : 0 < b) (hC : 0 < C) :
Filter.Tendsto (fun N : β„• =>
Real.log (Fintype.card (MaskRectangles (RecoveryGrowth.shiftCount b C N))) / N)
Filter.atTop (nhds 0) := by
simp_rw [card_recovery_copies]
exact RecoveryGrowth.tendsto_log_replicationCount_div_nat hb hC
end MatrixMultiplication.InverseLinearRecovery
end
end MatrixAllFields
end OAI