math / data /lean /OAI /LinearAlgebra /MatrixFields /Extraction /JointMaskedGoodSelection.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
6.99 kB
import Mathlib
import OAI.LinearAlgebra.MatrixFields.Construction.JointMaskedAssignment
import OAI.LinearAlgebra.MatrixFields.Entropy.JointMaskedRates
namespace OAI
namespace MatrixAllFields
open scoped BigOperators Topology Polynomial
section
noncomputable section
namespace MatrixMultiplication.JointMaskedGoodSelection
open Filter JointCoarseHashing JointExtractionRates JointMaskedSelection
open JointOrdinarySelection (hashLevel hashSet)
open JointMaskedRates
open scoped Topology
attribute [local instance] Classical.propDecidable
theorem eventually_exists_good_selection
{P E O V : β„• β†’ Type*} [βˆ€ N, Fintype (P N)] [βˆ€ N, Fintype (E N)]
(d : βˆ€ N, OrbitData (P N) (E N) (O N) (V N))
(hinj : βˆ€ N, Function.Injective (d N).coarse)
(degree : β„• β†’ β„•) (B p : β„•)
(heligibility : βˆ€ N e, ((d N).eligibilityCompetitors e).card ≀ degree N)
(hdegree : βˆ€ N e, βˆ€ o ∈ (d N).orbits e, βˆ€ v ∈ (d N).passing e o,
((d N).competitors e o v).card ≀ degree N)
(horbits : βˆ€ N e, ((d N).orbits e).card ≀ B * (N + 1) ^ p)
{A D H : ℝ} (hH : 0 ≀ H) (hgap : D < H)
(hdegreeRate : βˆ€ Ξ· : ℝ, 0 < Ξ· β†’
βˆ€αΆ  N in atTop, Real.log (degree N : ℝ) / (N : ℝ) ≀ D + Ξ·)
(hpos : βˆ€αΆ  N in atTop, 0 < Fintype.card (E N))
(hE : Tendsto (fun N => Real.log (Fintype.card (E N) : ℝ) / (N : ℝ)) atTop (𝓝 A))
{Ξ΅ : ℝ} (hΞ΅ : 0 < Ξ΅) :
βˆ€αΆ  N in atTop, βˆƒ (s : Sample (P N) (hashLevel H N)) (G : Finset (E N)),
G.card = ⌊Real.exp ((N : ℝ) * (A - H - Ξ΅))βŒ‹β‚Š ∧
(βˆ€ e ∈ G, (d N).Good (hashLevel H N) (hashSet H N) (N : ℝ) e s) ∧
(βˆ€ e ∈ G, βˆ€ f ∈ G, e β‰  f β†’ ((d N).coarse e).1 β‰  ((d N).coarse f).1) := by
classical
have huniform := eventually_errorBound_le_half degree B p hH hgap hdegreeRate
have hsmall : βˆ€αΆ  N in atTop, βˆ€ e,
(((d N).eligibilityCompetitors e).card : ℝ) / (hashModulus H N : ℝ) +
(((d N).orbits e).card : ℝ) * (N : ℝ) *
((degree N : ℝ) / (hashModulus H N : ℝ)) ≀ 1 / 2 := by
filter_upwards [huniform] with N hN e
exact (count_error_le_envelope (d N) e (degree N) B p N (hashModulus H N)
(heligibility N e) (horbits N e)).trans hN
have hpositive : βˆ€αΆ  N : β„• in atTop, (0 : ℝ) < N := by
filter_upwards [eventually_gt_atTop (0 : β„•)] with N hN
exact_mod_cast hN
let good := fun N (s : Sample (P N) (hashLevel H N)) (e : E N) =>
(d N).Good (hashLevel H N) (hashSet H N) (N : ℝ) e s
have hinc : βˆ€αΆ  N in atTop, βˆ€ e,
(((JointAPFree.modularSet (hashModulus H N)).card : ℝ) /
(hashModulus H N : ℝ) ^ 2 / 2) *
(Fintype.card (Sample (P N) (hashLevel H N)) : ℝ) ≀
(goodIncidence (good N) e : ℝ) := by
filter_upwards [hsmall, hpositive] with N hN hNpos e
rw [show goodIncidence (good N) e =
((d N).goodEvent (hashLevel H N) (hashSet H N) (N : ℝ) e).card from
(d N).goodIncidence_eq _ _ _ _]
exact (d N).goodEvent_card_lower (hashLevel H N) (hashSet H N) (N : ℝ) hNpos e
(degree N) (hdegree N e) (hN e)
have hyield := eventually_exists_many_good_explicit good hH hpos hinc hE hΞ΅
have hselection := eventually_exists_good_subfamily good
(fun N => ⌊Real.exp ((N : ℝ) * (A - H - Ξ΅))βŒ‹β‚Š) hyield
filter_upwards [hselection] with N hN
obtain ⟨s, G, hcard, hgood⟩ := hN
refine ⟨s, G, hcard, hgood, ?_⟩
intro e he f hf hne
exact (d N).good_no_shared_x (hashLevel H N) (hashSet H N) (N : ℝ) f e s
(hgood f hf) (hgood e he) (fun h => hne ((hinj N) h))
end MatrixMultiplication.JointMaskedGoodSelection
namespace MatrixMultiplication.JointMaskedSelection.OrbitData
open JointCoarseHashing
attribute [local instance] Classical.propDecidable
variable {P E O V : Type*} [Fintype P] [Fintype E]
omit [Fintype E] in
theorem good_randomLossFraction_le (d : OrbitData P E O V) (k : β„•)
(U : Finset (ZMod (37 ^ k))) (N : ℝ) (e : E) (s : Sample P k)
(hg : d.Good k U N e s) (o : O) (ho : o ∈ d.orbits e) :
JointLossCounts.randomLossFraction (d.full e o) (d.passing e o)
(d.variableBad k U e o) s ≀ 1 / N := by
exact le_of_not_gt (fun h => hg.2 (Or.inr ⟨o, ho, h⟩))
theorem passing_actual_failure_subset_bad (d : OrbitData P E O V) (k : β„•)
(U : Finset (ZMod (37 ^ k)))
(hAP : βˆ€ x ∈ U, βˆ€ y ∈ U, βˆ€ z ∈ U, x + y = 2 * z β†’ x = z ∧ y = z)
(N : ℝ) (e : E) (o : O) (ho : o ∈ d.orbits e) (s : Sample P k)
(hg : d.Good k U N e s)
(compatible useful : Triple P β†’ V β†’ Prop) (keep : V β†’ Prop)
(hc : βˆ€ v ∈ d.passing e o, compatible (d.coarse e) v)
(hu : βˆ€ v ∈ d.passing e o, useful (d.coarse e) v)
(hk : βˆ€ v ∈ d.passing e o, keep v)
(hcover : βˆ€ v ∈ d.passing e o, βˆ€ f ∈ d.actualTargets,
f β‰  d.coarse e β†’ compatible f v β†’ f ∈ d.competitors e o v) :
(d.passing e o).filter (fun v => d.actualAssignment k U compatible useful keep s v β‰ 
some (d.coarse e)) βŠ† (d.passing e o).filter (fun v => d.variableBad k U e o v s) := by
intro v hv
obtain ⟨hpass, hfail⟩ := Finset.mem_filter.mp hv
refine Finset.mem_filter.mpr ⟨hpass, ?_⟩
by_contra hnotbad
have hret : v ∈ JointLossCounts.retained (d.passing e o) (d.variableBad k U e o) s :=
Finset.mem_filter.mpr ⟨hpass, hnotbad⟩
exact hfail (d.model_retained_assigned k U hAP N e o ho s hg
compatible useful keep v hret (hc v hpass) (hu v hpass) (hk v hpass) (hcover v hpass))
theorem good_passing_actual_failure_fraction_le (d : OrbitData P E O V) (k : β„•)
(U : Finset (ZMod (37 ^ k)))
(hAP : βˆ€ x ∈ U, βˆ€ y ∈ U, βˆ€ z ∈ U, x + y = 2 * z β†’ x = z ∧ y = z)
(N : ℝ) (e : E) (o : O) (ho : o ∈ d.orbits e) (s : Sample P k)
(hg : d.Good k U N e s)
(compatible useful : Triple P β†’ V β†’ Prop) (keep : V β†’ Prop)
(hc : βˆ€ v ∈ d.passing e o, compatible (d.coarse e) v)
(hu : βˆ€ v ∈ d.passing e o, useful (d.coarse e) v)
(hk : βˆ€ v ∈ d.passing e o, keep v)
(hcover : βˆ€ v ∈ d.passing e o, βˆ€ f ∈ d.actualTargets,
f β‰  d.coarse e β†’ compatible f v β†’ f ∈ d.competitors e o v) :
(((d.passing e o).filter (fun v => d.actualAssignment k U compatible useful keep s v β‰ 
some (d.coarse e))).card : ℝ) / ((d.full e o).card : ℝ) ≀ 1 / N := by
have hcard := Finset.card_le_card
(d.passing_actual_failure_subset_bad k U hAP N e o ho s hg
compatible useful keep hc hu hk hcover)
have hR : (((d.passing e o).filter (fun v =>
d.actualAssignment k U compatible useful keep s v β‰  some (d.coarse e))).card : ℝ) ≀
(((d.passing e o).filter (fun v => d.variableBad k U e o v s)).card : ℝ) := by
exact_mod_cast hcard
exact (div_le_div_of_nonneg_right hR (Nat.cast_nonneg _)).trans
(d.good_randomLossFraction_le k U N e s hg o ho)
end MatrixMultiplication.JointMaskedSelection.OrbitData
end
end
end MatrixAllFields
end OAI