Download data/lean/OAI/LinearAlgebra/MatrixMultiplication/JointExtraction/MaskedSelection.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 11.6 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixMultiplication/JointExtraction/MaskedSelection.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/LinearAlgebra/MatrixMultiplication/JointExtraction/MaskedSelection.lean
-
curl -L -o MaskedSelection.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/LinearAlgebra/MatrixMultiplication/JointExtraction/MaskedSelection.lean
11.6 kB
| import OAI.LinearAlgebra.MatrixMultiplication.JointExtraction.CoarseHashing | |
| import OAI.LinearAlgebra.MatrixMultiplication.JointExtraction.AssignmentLoss | |
| import OAI.LinearAlgebra.MatrixMultiplication.JointExtraction.ExtractionRates | |
| namespace OAI | |
| /-! Joint tensor extraction, compatibility and entropy estimates. -/ | |
| noncomputable section | |
| namespace MatrixMultiplication.JointMaskedSelection | |
| open JointCoarseHashing JointExtractionRates | |
| attribute [local instance] Classical.propDecidable | |
| variable {P E O V : Type*} | |
| structure OrbitData (P E O V : Type*) where | |
| ambient : Finset (Triple P) | |
| support : P β β | |
| coarse : E β Triple P | |
| support_ambient : β f β ambient, HasSupportSum support f | |
| target_mem : β e, coarse e β ambient | |
| orbits : E β Finset O | |
| full : E β O β Finset V | |
| passing : E β O β Finset V | |
| full_pos : β e, β o β orbits e, 0 < (full e o).card | |
| passing_subset : β e, β o β orbits e, passing e o β full e o | |
| competitors : E β O β V β Finset (Triple P) | |
| competitor_mem : β e, β o β orbits e, β v β passing e o, | |
| β f β competitors e o v, f β ambient | |
| competitor_ne : β e, β o β orbits e, β v β passing e o, | |
| β f β competitors e o v, f β coarse e | |
| competitor_shares : β e, β o β orbits e, β v β passing e o, | |
| β f β competitors e o v, SharesSide (coarse e) f | |
| namespace OrbitData | |
| def eligibilityCompetitors (d : OrbitData P E O V) (e : E) : Finset (Triple P) := | |
| d.ambient.filter (fun f => f β d.coarse e β§ f.1 = (d.coarse e).1) | |
| @[simp] theorem mem_eligibilityCompetitors (d : OrbitData P E O V) (e : E) (f : Triple P) : | |
| f β d.eligibilityCompetitors e β | |
| f β d.ambient β§ f β d.coarse e β§ f.1 = (d.coarse e).1 := by | |
| simp only [eligibilityCompetitors, Finset.mem_filter] | |
| section Finite | |
| variable [Fintype P] | |
| def variableBad (d : OrbitData P E O V) (k : β) (U : Finset (ZMod (37 ^ k))) | |
| (e : E) (o : O) (v : V) (s : Sample P k) : Prop := | |
| β f β d.competitors e o v, Survives k U f s | |
| def eligibilityGood (d : OrbitData P E O V) (k : β) (U : Finset (ZMod (37 ^ k))) | |
| (e : E) (s : Sample P k) : Prop := | |
| Β¬ β f β d.eligibilityCompetitors e, Survives k U f s | |
| def Failure (d : OrbitData P E O V) (k : β) (U : Finset (ZMod (37 ^ k))) | |
| (N : β) (e : E) (s : Sample P k) : Prop := | |
| JointLossCounts.targetBad (d.orbits e) (d.full e) (d.passing e) | |
| (d.variableBad k U e) (d.eligibilityGood k U e) N s | |
| def Good (d : OrbitData P E O V) (k : β) (U : Finset (ZMod (37 ^ k))) | |
| (N : β) (e : E) (s : Sample P k) : Prop := | |
| Survives k U (d.coarse e) s β§ Β¬ d.Failure k U N e s | |
| def goodEvent (d : OrbitData P E O V) (k : β) (U : Finset (ZMod (37 ^ k))) | |
| (N : β) (e : E) : Finset (Sample P k) := | |
| (ownEvent k U (d.coarse e)).filter (fun s => Β¬ d.Failure k U N e s) | |
| @[simp] theorem mem_goodEvent (d : OrbitData P E O V) (k : β) | |
| (U : Finset (ZMod (37 ^ k))) (N : β) (e : E) (s : Sample P k) : | |
| s β d.goodEvent k U N e β d.Good k U N e s := by | |
| simp only [goodEvent, ownEvent, Finset.mem_filter, Finset.mem_univ, true_and, Good] | |
| theorem variableBad_card_le (d : OrbitData P E O V) (k : β) | |
| (U : Finset (ZMod (37 ^ k))) (e : E) (o : O) (ho : o β d.orbits e) | |
| (v : V) (hv : v β d.passing e o) (D : β) | |
| (hdegree : (d.competitors e o v).card β€ D) : | |
| (((ownEvent k U (d.coarse e)).filter (d.variableBad k U e o v)).card : β) β€ | |
| ((D : β) / ((37 ^ k : β) : β)) * ((ownEvent k U (d.coarse e)).card : β) := by | |
| have h := competitor_union_card_le k U d.support (d.coarse e) | |
| (d.support_ambient _ (d.target_mem e)) (d.competitors e o v) | |
| (fun f hf => d.support_ambient f (d.competitor_mem e o ho v hv f hf)) | |
| (d.competitor_ne e o ho v hv) (d.competitor_shares e o ho v hv) | |
| have hdegreeR : ((d.competitors e o v).card : β) β€ (D : β) := by | |
| exact_mod_cast hdegree | |
| have hfilter : (ownEvent k U (d.coarse e)).filter (d.variableBad k U e o v) = | |
| (ownEvent k U (d.coarse e)).filter | |
| (fun s => β f β d.competitors e o v, Survives k U f s) := by | |
| ext s | |
| simp only [Finset.mem_filter, variableBad] | |
| rw [hfilter] | |
| exact h.trans (mul_le_mul_of_nonneg_right | |
| (div_le_div_of_nonneg_right hdegreeR (Nat.cast_nonneg _)) | |
| (Nat.cast_nonneg _)) | |
| theorem eligibilityFailure_card_le (d : OrbitData P E O V) (k : β) | |
| (U : Finset (ZMod (37 ^ k))) (e : E) : | |
| (((ownEvent k U (d.coarse e)).filter (fun s => Β¬ d.eligibilityGood k U e s)).card : β) β€ | |
| (((d.eligibilityCompetitors e).card : β) / ((37 ^ k : β) : β)) * | |
| ((ownEvent k U (d.coarse e)).card : β) := by | |
| have h := competitor_union_card_le k U d.support (d.coarse e) | |
| (d.support_ambient _ (d.target_mem e)) (d.eligibilityCompetitors e) | |
| (fun f hf => d.support_ambient f ((d.mem_eligibilityCompetitors e f).1 hf).1) | |
| (fun f hf => ((d.mem_eligibilityCompetitors e f).1 hf).2.1) | |
| (fun f hf => Or.inl ((d.mem_eligibilityCompetitors e f).1 hf).2.2) | |
| simpa only [eligibilityGood, not_not] using h | |
| theorem failure_card_le (d : OrbitData P E O V) (k : β) | |
| (U : Finset (ZMod (37 ^ k))) (N : β) (hN : 0 < N) (e : E) (D : β) | |
| (hdegree : β o β d.orbits e, β v β d.passing e o, (d.competitors e o v).card β€ D) : | |
| (((ownEvent k U (d.coarse e)).filter (d.Failure k U N e)).card : β) β€ | |
| (((d.eligibilityCompetitors e).card : β) / ((37 ^ k : β) : β) + | |
| ((d.orbits e).card : β) * N * ((D : β) / ((37 ^ k : β) : β))) * | |
| ((ownEvent k U (d.coarse e)).card : β) := by | |
| exact JointLossCounts.targetBad_card_le (ownEvent k U (d.coarse e)) | |
| (d.orbits e) (d.full e) (d.passing e) (d.variableBad k U e) | |
| (d.eligibilityGood k U e) ((D : β) / ((37 ^ k : β) : β)) | |
| (((d.eligibilityCompetitors e).card : β) / ((37 ^ k : β) : β)) N | |
| (div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _)) hN (d.full_pos e) | |
| (d.passing_subset e) | |
| (fun o ho v hv => d.variableBad_card_le k U e o ho v hv D (hdegree o ho v hv)) | |
| (d.eligibilityFailure_card_le k U e) | |
| theorem ownEvent_card_real (d : OrbitData P E O V) (k : β) | |
| (U : Finset (ZMod (37 ^ k))) (e : E) : | |
| ((ownEvent k U (d.coarse e)).card : β) = | |
| ((U.card : β) / ((37 ^ k : β) : β) ^ 2) * (Fintype.card (Sample P k) : β) := by | |
| have hsample : (Fintype.card (Sample P k) : β) β 0 := by | |
| exact_mod_cast Fintype.card_ne_zero | |
| have hf : ((ownEvent k U (d.coarse e)).card : β) / (Fintype.card (Sample P k) : β) = | |
| (U.card : β) / ((37 ^ k : β) : β) ^ 2 := by | |
| change | |
| ((Finset.univ.filter (fun s => | |
| JointHashing.Survives (U : Set (ZMod (37 ^ k))) | |
| (castWord k (d.coarse e).1) (castWord k (d.coarse e).2.1) s)).card : β) / | |
| (Fintype.card (JointHashing.Sample P (ZMod (37 ^ k))) : β) = _ | |
| simpa only [Fintype.card_subtype, ZMod.card] using | |
| JointHashing.survival_fraction U (castWord k (d.coarse e).1) (castWord k (d.coarse e).2.1) | |
| exact (div_eq_iff hsample).mp hf | |
| theorem goodEvent_card_lower (d : OrbitData P E O V) (k : β) | |
| (U : Finset (ZMod (37 ^ k))) (N : β) (hN : 0 < N) (e : E) (D : β) | |
| (hdegree : β o β d.orbits e, β v β d.passing e o, (d.competitors e o v).card β€ D) | |
| (hsmall : ((d.eligibilityCompetitors e).card : β) / ((37 ^ k : β) : β) + | |
| ((d.orbits e).card : β) * N * ((D : β) / ((37 ^ k : β) : β)) β€ 1 / 2) : | |
| ((U.card : β) / ((37 ^ k : β) : β) ^ 2 / 2) * | |
| (Fintype.card (Sample P k) : β) β€ (d.goodEvent k U N e).card := by | |
| have hb : (((ownEvent k U (d.coarse e)).filter (d.Failure k U N e)).card : β) β€ | |
| (1 / 2) * ((ownEvent k U (d.coarse e)).card : β) := | |
| (d.failure_card_le k U N hN e D hdegree).trans | |
| (mul_le_mul_of_nonneg_right hsmall (Nat.cast_nonneg _)) | |
| have hg := JointLossCounts.good_card_lower (ownEvent k U (d.coarse e)) | |
| (d.Failure k U N e) (1 / 2) hb | |
| rw [d.ownEvent_card_real] at hg | |
| change _ β€ ((d.goodEvent k U N e).card : β) at hg | |
| convert hg using 1 | |
| ring | |
| theorem goodIncidence_eq (d : OrbitData P E O V) (k : β) | |
| (U : Finset (ZMod (37 ^ k))) (N : β) (e : E) : | |
| goodIncidence (fun s e => d.Good k U N e s) e = (d.goodEvent k U N e).card := by | |
| unfold goodIncidence | |
| congr 1 | |
| ext s | |
| simp only [Finset.mem_filter, Finset.mem_univ, true_and, mem_goodEvent] | |
| theorem good_eligibility (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) : d.eligibilityGood k U e s := by | |
| by_contra h | |
| exact hg.2 (Or.inl h) | |
| theorem good_no_shared_x (d : OrbitData P E O V) (k : β) | |
| (U : Finset (ZMod (37 ^ k))) (N : β) (e f : E) (s : Sample P k) | |
| (he : d.Good k U N e s) (hf : d.Good k U N f s) | |
| (hne : d.coarse f β d.coarse e) : (d.coarse f).1 β (d.coarse e).1 := by | |
| intro hx | |
| exact d.good_eligibility k U N e s he | |
| β¨d.coarse f, (d.mem_eligibilityCompetitors e _).2 β¨d.target_mem f, hne, hxβ©, hf.1β© | |
| theorem good_missingFraction_le (d : OrbitData P E O V) (k : β) | |
| (U : Finset (ZMod (37 ^ k))) (Cβ N : β) (e : E) (s : Sample P k) | |
| (hg : d.Good k U N e s) | |
| (hdet : β o β d.orbits e, | |
| JointLossCounts.deterministicLossFraction (d.full e o) (d.passing e o) β€ Cβ / N) | |
| (o : O) (ho : o β d.orbits e) : | |
| JointLossCounts.missingFraction (d.full e o) (d.passing e o) | |
| (d.variableBad k U e o) s β€ (Cβ + 1) / N := | |
| JointLossCounts.good_missingFraction_le (d.orbits e) (d.full e) (d.passing e) | |
| (d.variableBad k U e) (d.eligibilityGood k U e) Cβ N s hg.2 | |
| (d.passing_subset e) hdet o ho | |
| theorem exists_selection [Fintype E] (d : OrbitData P E O V) | |
| (hinj : Function.Injective d.coarse) (k : β) (U : Finset (ZMod (37 ^ k))) | |
| (Cβ N : β) (hN : 0 < N) (D K : β) | |
| (hdegree : β e, β o β d.orbits e, β v β d.passing e o, | |
| (d.competitors e o v).card β€ D) | |
| (hsmall : β e, ((d.eligibilityCompetitors e).card : β) / ((37 ^ k : β) : β) + | |
| ((d.orbits e).card : β) * N * ((D : β) / ((37 ^ k : β) : β)) β€ 1 / 2) | |
| (hdet : β e, β o β d.orbits e, | |
| JointLossCounts.deterministicLossFraction (d.full e o) (d.passing e o) β€ Cβ / N) | |
| (hK : (K : β) β€ (Fintype.card E : β) * | |
| ((U.card : β) / ((37 ^ k : β) : β) ^ 2 / 2)) : | |
| β (s : Sample P k) (G : Finset E), G.card = K β§ | |
| (β e β G, d.Good k U N e s) β§ | |
| (β e β G, β f β G, e β f β (d.coarse e).1 β (d.coarse f).1) β§ | |
| β e β G, β o β d.orbits e, | |
| JointLossCounts.missingFraction (d.full e o) (d.passing e o) | |
| (d.variableBad k U e o) s β€ (Cβ + 1) / N := by | |
| classical | |
| have hi (e : E) : | |
| ((U.card : β) / ((37 ^ k : β) : β) ^ 2 / 2) * | |
| (Fintype.card (Sample P k) : β) β€ | |
| (goodIncidence (fun s e => d.Good k U N e s) e : β) := by | |
| rw [d.goodIncidence_eq] | |
| exact d.goodEvent_card_lower k U N hN e D (hdegree e) (hsmall e) | |
| obtain β¨s, hsβ© := exists_goodCount_ge (fun s e => d.Good k U N e s) _ hi | |
| have hk : K β€ goodCount (fun s e => d.Good k U N e s) s := by exact_mod_cast hK.trans hs | |
| obtain β¨G, hcard, hgoodβ© := exists_good_subfamily (fun s e => d.Good k U N e s) s K hk | |
| refine β¨s, G, hcard, hgood, ?_, ?_β© | |
| Β· intro e he f hf hne | |
| exact d.good_no_shared_x k U N f e s (hgood f hf) (hgood e he) | |
| (fun h => hne (hinj h)) | |
| Β· intro e he o ho | |
| exact d.good_missingFraction_le k U Cβ N e s (hgood e he) (hdet e) o ho | |
| end Finite | |
| end OrbitData | |
| end MatrixMultiplication.JointMaskedSelection | |
| end | |
| end OAI | |