Download data/lean/OAI/Combinatorics/HalvingLines/Decomposition.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 22.3 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/HalvingLines/Decomposition.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/HalvingLines/Decomposition.lean
-
curl -L -o Decomposition.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/HalvingLines/Decomposition.lean
22.3 kB
| import OAI.Combinatorics.HalvingLines.Greedy | |
| namespace OAI | |
| open Filter Topology | |
| namespace PlanarHalving.Sweep | |
| open Set | |
| lemma state_eq_insert_below {n k : β} {P : Fin n β Point} (hP : GeneralPosition P) | |
| {s : β} {M : Finset (Fin n)} (hM : Separates P s M) (hcard : M.card=k) | |
| {a b : Fin n} (hab : aβ b) (hx : (P a).1β (P b).1) | |
| (hR : Refines P (slope (P a) (P b)) s) | |
| (hs : projection s (P a)<projection s (P b)) (hk : 0<k) | |
| (hbelow : belowCount P a b=k-1) : M=insert a (belowSet P a b) := by | |
| classical | |
| apply states_unique hM (below_insert_separates hP hab hx hR hs) | |
| have hna : aβbelowSet P a b := by simp only [mem_belowSet,lt_self_iff_false,not_false_eq_true] | |
| rw [hcard,Finset.card_insert_of_notMem hna,card_belowSet,hbelow] | |
| omega | |
| lemma states_change_of_pair {n k : β} {P : Fin n β Point} (hP : Generic P) (hk : kβ€n) | |
| (i : Fin (traversal (criticalSlopes P)).size) {a b : Fin n} (hab : aβ b) | |
| (hc : (traversal (criticalSlopes P)).cut i.succ.castSucc=slope (P a) (P b)) | |
| (hkpos : 0<k) (hbelow : belowCount P a b=k-1) : | |
| (states P hP hk).marks i.castSuccβ (states P hP hk).marks i.succ := by | |
| classical | |
| let T := traversal (criticalSlopes P) | |
| let S := states P hP hk | |
| have aux (a b : Fin n) (hx : (P a).1<(P b).1) | |
| (hc : T.cut i.succ.castSucc=slope (P a) (P b)) | |
| (hb : belowCount P a b=k-1) : S.marks i.castSuccβ S.marks i.succ := by | |
| have hbounds := T.cut_bounds i | |
| rw [hc] at hbounds | |
| have ho := projection_order_at_slope hx hbounds.1 hbounds.2 | |
| have hR := (T.sample_refines hP i).1 | |
| rw [hc] at hR | |
| have hab' : aβ b := fun he => ne_of_lt hx (congrArg (fun x => (P x).1) he) | |
| have he := state_eq_insert_below hP.1 (S.separates i.castSucc) (S.card_marks i.castSucc) | |
| hab' hx.ne hR ho.1 hkpos hb | |
| intro hsame | |
| have ha : aβS.marks i.succ := by rw [β hsame,he];exact Finset.mem_insert_self _ _ | |
| have hb' : bβS.marks i.succ := by | |
| rw [β hsame,he,Finset.mem_insert] | |
| simp only [mem_belowSet,tied_projection (P a) (P b) hx.ne,lt_self_iff_false,or_false] | |
| exact hab'.symm | |
| exact not_lt_of_gt ho.2 (S.separates i.succ a ha b hb') | |
| rcases lt_or_gt_of_ne (hP.2.1 a b hab) with hx | hx | |
| Β· exact aux a b hx hc hbelow | |
| Β· apply aux b a hx | |
| Β· simpa only [slope_symm (P b) (P a)] using hc | |
| Β· simpa only [belowCount_symm (hP.2.1 a b hab)] using hbelow | |
| noncomputable def switchPairs {n : β} (P : Fin n β Point) (k : β) : Finset (Fin n Γ Fin n) := | |
| Finset.univ.filter (fun ij => ij.1 < ij.2 β§ 0<k β§ k<n β§ belowCount P ij.1 ij.2=k-1) | |
| lemma mem_switchPairs {n : β} (P : Fin n β Point) (k : β) (p : Fin n Γ Fin n) : | |
| pβswitchPairs P k β p.1<p.2 β§ 0<k β§ k<n β§ belowCount P p.1 p.2=k-1 := by | |
| classical | |
| simp only [switchPairs,Finset.mem_filter,Finset.mem_univ,true_and] | |
| noncomputable def States.changeSteps {n T k : β} {P : Fin n β Point} (S : @States n T k P) : Finset (Fin T) := | |
| Finset.univ.filter (fun i => S.marks i.castSuccβ S.marks i.succ) | |
| lemma States.mem_changeSteps {n T k : β} {P : Fin n β Point} (S : @States n T k P) (i : Fin T) : | |
| iβS.changeSteps β S.marks i.castSuccβ S.marks i.succ := by | |
| classical | |
| simp only [States.changeSteps,Finset.mem_filter,Finset.mem_univ,true_and] | |
| lemma switchCount_le_changes {n k : β} {P : Fin n β Point} (hP : Generic P) (hk : kβ€n) : | |
| switchCount P kβ€(states P hP hk).changeSteps.card := by | |
| classical | |
| let T := traversal (criticalSlopes P) | |
| let S := states P hP hk | |
| have hex (p : β₯(switchPairs P k)) : β i : Fin T.size, iβS.changeSteps β§ | |
| T.cut i.succ.castSucc=slope (P p.val.1) (P p.val.2) := by | |
| have hp := (mem_switchPairs P k p.val).mp p.property | |
| obtain β¨i,hiβ© := (T.critical _).mp (mem_criticalSlopes P hp.1.ne) | |
| exact β¨i,(S.mem_changeSteps i).mpr (states_change_of_pair hP hk i hp.1.ne hi hp.2.1 hp.2.2.2),hiβ© | |
| choose f hf hs using hex | |
| let g : β₯(switchPairs P k) β β₯S.changeSteps := fun p => β¨f p,hf pβ© | |
| have hg : Function.Injective g := by | |
| intro p q h | |
| have he : f p=f q := congrArg Subtype.val h | |
| have heq := (hs p).symm.trans ((congrArg (fun j => T.cut j.succ.castSucc) he).trans (hs q)) | |
| have hp := (mem_switchPairs P k p.val).mp p.property | |
| have hq := (mem_switchPairs P k q.val).mp q.property | |
| obtain β¨h1,h2β© := hP.2.2.1 _ _ _ _ hp.1 hq.1 heq | |
| exact Subtype.ext (Prod.ext h1 h2) | |
| change (switchPairs P k).cardβ€S.changeSteps.card | |
| simpa only [Fintype.card_coe] using Fintype.card_le_of_injective g hg | |
| lemma local_change_event {n k : β} {P : Fin n β Point} (hP : Generic P) | |
| {s t c : β} {M N : Finset (Fin n)} | |
| (hM : Separates P s M) (hN : Separates P t N) (hcardM : M.card=k) (hcardN : N.card=k) | |
| (hRs : Refines P c s) (hRt : Refines P c t) (hne : Mβ N) : | |
| β pβswitchPairs P k, slope (P p.1) (P p.2)=c := by | |
| classical | |
| have hneM : (M\N).Nonempty := by | |
| by_contra hh | |
| have hsub : MβN := Finset.sdiff_eq_empty_iff_subset.mp (Finset.not_nonempty_iff_eq_empty.mp hh) | |
| exact hne (Finset.eq_of_subset_of_card_le hsub (hcardN.trans hcardM.symm).le) | |
| obtain β¨a,haβ© := hneM | |
| have hneN : (N\M).Nonempty := by | |
| rw [β Finset.card_pos,β Finset.card_sdiff_comm (hcardM.trans hcardN.symm)] | |
| exact Finset.card_pos.mpr β¨a,haβ© | |
| obtain β¨b,hbβ© := hneN | |
| have haM := (Finset.mem_sdiff.mp ha).1 | |
| have haN := (Finset.mem_sdiff.mp ha).2 | |
| have hbN := (Finset.mem_sdiff.mp hb).1 | |
| have hbM := (Finset.mem_sdiff.mp hb).2 | |
| have hab : aβ b := fun he => hbM (he βΈ haM) | |
| have hc : projection c (P a)=projection c (P b) := by | |
| apply le_antisymm | |
| Β· by_contra h | |
| exact not_lt_of_gt (hM a haM b hbM) (hRs b a (lt_of_not_ge h)) | |
| Β· by_contra h | |
| exact not_lt_of_gt (hN b hbN a haN) (hRt a b (lt_of_not_ge h)) | |
| have hsc : c=slope (P a) (P b) := (projection_eq_iff_slope (hP.2.1 a b hab)).mp hc | |
| have hbelow : belowCount P a b=k-1 := by | |
| rw [β card_belowSet,belowSet_eq_erase hP.1 hM haM hbM (hP.2.1 a b hab) (hsc βΈ hRs), | |
| Finset.card_erase_of_mem haM,hcardM] | |
| have hkpos : 0<k := hcardM βΈ Finset.card_pos.mpr β¨a,haMβ© | |
| have hkn : k<n := by | |
| have he : MβFinset.univ := Finset.ssubset_iff_subset_ne.mpr β¨Finset.subset_univ _,by intro h;apply hbM;rw [h];exact Finset.mem_univ _β© | |
| simpa only [hcardM,Finset.card_univ,Fintype.card_fin] using Finset.card_lt_card he | |
| rcases lt_or_gt_of_ne hab with hab | hba | |
| Β· exact β¨(a,b),(mem_switchPairs P k _).mpr β¨hab,hkpos,hkn,hbelowβ©,hsc.symmβ© | |
| Β· exact β¨(b,a),(mem_switchPairs P k _).mpr β¨hba,hkpos,hkn,by rw [belowCount_symm (hP.2.1 a b (ne_of_gt hba)),hbelow]β©, | |
| (slope_symm (P b) (P a)).trans hsc.symmβ© | |
| end PlanarHalving.Sweep | |
| namespace PlanarHalving.Sweep | |
| open Set | |
| noncomputable def subsetIndex {n : β} (A : Finset (Fin n)) : Fin A.card β Fin n := | |
| fun i => (A.orderIsoOfFin rfl i : Fin n) | |
| lemma subsetIndex_strictMono {n : β} (A : Finset (Fin n)) : StrictMono (subsetIndex A) := | |
| fun _ _ h => (A.orderIsoOfFin rfl).strictMono h | |
| lemma subsetIndex_mem {n : β} (A : Finset (Fin n)) (i : Fin A.card) : subsetIndex A iβA := | |
| (A.orderIsoOfFin rfl i).property | |
| lemma subsetIndex_surj {n : β} (A : Finset (Fin n)) {x : Fin n} (hx : xβA) : | |
| β i, subsetIndex A i=x := by | |
| exact β¨(A.orderIsoOfFin rfl).symm β¨x,hxβ©,congrArg Subtype.val ((A.orderIsoOfFin rfl).apply_symm_apply β¨x,hxβ©)β© | |
| noncomputable def subsetPoints {n : β} (P : Fin n β Point) (A : Finset (Fin n)) : Fin A.card β Point := | |
| PβsubsetIndex A | |
| lemma subsetPoints_generic {n : β} {P : Fin n β Point} (hP : Generic P) (A : Finset (Fin n)) : | |
| Generic (subsetPoints P A) := hP.comp_strictMono (subsetIndex_strictMono A) | |
| noncomputable def restrictMarks {n : β} (A M : Finset (Fin n)) : Finset (Fin A.card) := | |
| Finset.univ.filter (fun i => subsetIndex A iβM) | |
| lemma mem_restrictMarks {n : β} (A M : Finset (Fin n)) (i : Fin A.card) : | |
| iβrestrictMarks A M β subsetIndex A iβM := by | |
| classical | |
| simp only [restrictMarks,Finset.mem_filter,Finset.mem_univ,true_and] | |
| lemma card_restrictMarks {n : β} (A M : Finset (Fin n)) : | |
| (restrictMarks A M).card=(Mβ©A).card := by | |
| classical | |
| have he : (restrictMarks A M).image (subsetIndex A)=Mβ©A := by | |
| ext x | |
| constructor | |
| Β· intro hx | |
| obtain β¨i,hi,rflβ© := Finset.mem_image.mp hx | |
| exact Finset.mem_inter.mpr β¨(mem_restrictMarks A M i).mp hi,subsetIndex_mem A iβ© | |
| Β· intro hx | |
| obtain β¨i,rflβ© := subsetIndex_surj A (Finset.mem_inter.mp hx).2 | |
| exact Finset.mem_image.mpr β¨i,(mem_restrictMarks A M i).mpr (Finset.mem_inter.mp hx).1,rflβ© | |
| rw [β he,Finset.card_image_of_injective _ (subsetIndex_strictMono A).injective] | |
| lemma restrictMarks_separates {n : β} {P : Fin n β Point} {s : β} {M : Finset (Fin n)} | |
| (hM : Separates P s M) (A : Finset (Fin n)) : | |
| Separates (subsetPoints P A) s (restrictMarks A M) := by | |
| intro i hi j hj | |
| exact hM _ ((mem_restrictMarks A M i).mp hi) _ (fun h => hj ((mem_restrictMarks A M j).mpr h)) | |
| lemma Refines.subset {n : β} {P : Fin n β Point} {c s : β} (hR : Refines P c s) | |
| (A : Finset (Fin n)) : Refines (subsetPoints P A) c s := fun _ _ h => hR _ _ h | |
| variable {n T k : β} {P : Fin n β Point} | |
| lemma States.restrict_activity_card (S : @States n T k P) | |
| {u v : Fin (T+1)} (huv : u β€ v) {i : Fin (T+1)} (hui : u β€ i) (hiv : i β€ v) : | |
| (restrictMarks (S.intervalActivity u v huv) (S.marks i)).card= | |
| ((S.marks u)β©S.intervalActivity u v huv).card := by | |
| classical | |
| let A := S.intervalActivity u v huv | |
| have he : S.marks i\A=S.marks u\A := by | |
| ext x | |
| simp only [Finset.mem_sdiff] | |
| by_cases hx : xβA | |
| Β· simp [hx] | |
| Β· rw [S.outside_activity_constant huv hx hui hiv] | |
| have h1 := Finset.card_inter_add_card_sdiff (S.marks i) A | |
| have h2 := Finset.card_inter_add_card_sdiff (S.marks u) A | |
| rw [S.card_marks] at h1 h2 | |
| rw [he] at h1 | |
| rw [card_restrictMarks] | |
| change (S.marks iβ©A).card=(S.marks uβ©A).card | |
| omega | |
| lemma States.restrict_activity_change (S : @States n T k P) | |
| {u v : Fin (T+1)} (huv : u β€ v) {i j : Fin (T+1)} | |
| (hui : u β€ i) (hiv : i β€ v) (huj : u β€ j) (hjv : j β€ v) | |
| (hne : S.marks iβ S.marks j) : | |
| restrictMarks (S.intervalActivity u v huv) (S.marks i)β | |
| restrictMarks (S.intervalActivity u v huv) (S.marks j) := by | |
| classical | |
| intro he | |
| apply hne | |
| ext x | |
| by_cases hx : xβS.intervalActivity u v huv | |
| Β· obtain β¨a,rflβ© := subsetIndex_surj _ hx | |
| exact (mem_restrictMarks _ _ a).symm.trans ((congrArg (fun M => aβM) he).to_iff.trans (mem_restrictMarks _ _ a)) | |
| Β· exact (S.outside_activity_constant huv hx hui hiv).trans (S.outside_activity_constant huv hx huj hjv).symm | |
| noncomputable def States.blockSteps (S : @States n T k P) (u v : Fin (T+1)) : Finset (Fin T) := | |
| S.changeSteps.filter (fun i => u β€ i.castSucc β§ i.succ β€ v) | |
| lemma States.mem_blockSteps (S : @States n T k P) (u v : Fin (T+1)) (i : Fin T) : | |
| iβS.blockSteps u v β iβS.changeSteps β§ u β€ i.castSucc β§ i.succ β€ v := by | |
| classical | |
| simp only [States.blockSteps,Finset.mem_filter] | |
| lemma card_le_of_injective_labels {Ξ± Ξ² Ξ³ : Type*} [DecidableEq Ξ±] [DecidableEq Ξ²] | |
| (A : Finset Ξ±) (B : Finset Ξ²) (f : Ξ± β Ξ³) (g : Ξ² β Ξ³) | |
| (hf : Set.InjOn f A) (hex : β aβA, β bβB, g b=f a) : A.cardβ€B.card := by | |
| classical | |
| choose h hh he using (fun a : β₯A => hex a a.property) | |
| let F : β₯A β β₯B := fun a => β¨h a,hh aβ© | |
| have hF : Function.Injective F := by | |
| intro a b hab | |
| have hh' : h a=h b := congrArg Subtype.val hab | |
| exact Subtype.ext (hf a.property b.property ((he a).symm.trans ((congrArg g hh').trans (he b)))) | |
| simpa only [Fintype.card_coe] using Fintype.card_le_of_injective F hF | |
| lemma block_step_event {n k : β} {P : Fin n β Point} (hP : Generic P) (hk : kβ€n) | |
| {u v : Fin ((traversal (criticalSlopes P)).size+1)} (huv : u β€ v) | |
| {i : Fin (traversal (criticalSlopes P)).size} (hi : iβ(states P hP hk).blockSteps u v) : | |
| let A := (states P hP hk).intervalActivity u v huv | |
| let r := ((states P hP hk).marks uβ©A).card | |
| β pβswitchPairs (subsetPoints P A) r, | |
| slope (subsetPoints P A p.1) (subsetPoints P A p.2)=(traversal (criticalSlopes P)).cut i.succ.castSucc := by | |
| let T := traversal (criticalSlopes P) | |
| let S := states P hP hk | |
| let A := S.intervalActivity u v huv | |
| have hi' := (S.mem_blockSteps u v i).mp hi | |
| have hs := T.sample_refines hP i | |
| exact local_change_event (subsetPoints_generic hP A) | |
| (restrictMarks_separates (S.separates i.castSucc) A) | |
| (restrictMarks_separates (S.separates i.succ) A) | |
| (S.restrict_activity_card huv hi'.2.1 ((Fin.castSucc_le_succ _).trans hi'.2.2)) | |
| (S.restrict_activity_card huv (hi'.2.1.trans (Fin.castSucc_le_succ _)) hi'.2.2) | |
| (hs.1.subset A) (hs.2.subset A) | |
| (S.restrict_activity_change huv hi'.2.1 ((Fin.castSucc_le_succ _).trans hi'.2.2) | |
| (hi'.2.1.trans (Fin.castSucc_le_succ _)) hi'.2.2 ((S.mem_changeSteps _).mp hi'.1)) | |
| lemma block_count_le {n k : β} {P : Fin n β Point} (hP : Generic P) (hk : kβ€n) | |
| {u v : Fin ((traversal (criticalSlopes P)).size+1)} (huv : u β€ v) : | |
| β r : β, rβ€((states P hP hk).intervalActivity u v huv).card β§ | |
| ((states P hP hk).blockSteps u v).cardβ€ | |
| switchCount (subsetPoints P ((states P hP hk).intervalActivity u v huv)) r := by | |
| classical | |
| let T := traversal (criticalSlopes P) | |
| let S := states P hP hk | |
| let A := S.intervalActivity u v huv | |
| let r := (S.marks uβ©A).card | |
| refine β¨r,(Finset.card_le_card (Finset.inter_subset_right)),?_β© | |
| change (S.blockSteps u v).cardβ€(switchPairs (subsetPoints P A) r).card | |
| apply card_le_of_injective_labels _ _ (fun i => T.cut i.succ.castSucc) | |
| (fun p => slope (subsetPoints P A p.1) (subsetPoints P A p.2)) | |
| Β· intro i _ j _ he | |
| exact Fin.succ_inj.mp (Fin.castSucc_inj.mp (T.increasing.injective he)) | |
| Β· exact fun i hi => block_step_event hP hk huv hi | |
| end PlanarHalving.Sweep | |
| namespace PlanarHalving.Sweep | |
| open Set | |
| variable {n T k : β} {P : Fin n β Point} | |
| lemma States.blockSteps_self (S : @States n T k P) (u : Fin (T+1)) : S.blockSteps u u=β := by | |
| classical | |
| apply Finset.eq_empty_iff_forall_notMem.mpr | |
| intro i hi | |
| have h := (S.mem_blockSteps u u i).mp hi | |
| exact not_lt_of_ge (h.2.2.trans h.2.1) (Fin.castSucc_lt_succ (i:=i)) | |
| lemma States.blockSteps_all (S : @States n T k P) : S.blockSteps 0 (Fin.last T)=S.changeSteps := by | |
| classical | |
| ext i | |
| simp only [S.mem_blockSteps,Fin.zero_le,Fin.le_last,and_true] | |
| lemma States.blockSteps_card_add (S : @States n T k P) {u v w : Fin (T+1)} | |
| (huv : u β€ v) (hvw : v β€ w) : | |
| (S.blockSteps u v).card+(S.blockSteps v w).card=(S.blockSteps u w).card := by | |
| classical | |
| have hdis : Disjoint (S.blockSteps u v) (S.blockSteps v w) := by | |
| apply Finset.disjoint_left.mpr | |
| intro i hi hj | |
| have hi' := (S.mem_blockSteps u v i).mp hi | |
| have hj' := (S.mem_blockSteps v w i).mp hj | |
| exact not_lt_of_ge (hi'.2.2.trans hj'.2.1) (Fin.castSucc_lt_succ (i:=i)) | |
| have he : S.blockSteps u v βͺ S.blockSteps v w=S.blockSteps u w := by | |
| ext i | |
| simp only [Finset.mem_union,S.mem_blockSteps] | |
| constructor | |
| Β· rintro (β¨hi,hu,hvβ© | β¨hi,hv,hwβ©) | |
| Β· exact β¨hi,hu,hv.trans hvwβ© | |
| Β· exact β¨hi,huv.trans hv,hwβ© | |
| Β· rintro β¨hi,hu,hwβ© | |
| by_cases h : i.succ β€ v | |
| Β· exact Or.inl β¨hi,hu,hβ© | |
| Β· exact Or.inr β¨hi,(by change v.val β€ i.val;change Β¬i.val+1 β€ v.val at h;omega),hwβ© | |
| rw [β he,Finset.card_union_of_disjoint hdis] | |
| lemma States.sum_blockSteps (S : @States n T k P) (m : β) | |
| (f : Fin (m+1) β Fin (T+1)) (hf : Monotone f) : | |
| β j : Fin m, (S.blockSteps (f j.castSucc) (f j.succ)).card= | |
| (S.blockSteps (f 0) (f (Fin.last m))).card := by | |
| induction m with | |
| | zero => simp [S.blockSteps_self] | |
| | succ m ih => | |
| rw [Fin.sum_univ_castSucc] | |
| have hh := ih (fun j : Fin (m+1) => f j.castSucc) (fun _ _ h => hf (Fin.castSucc_le_castSucc_iff.mpr h)) | |
| simp only [Fin.castSucc_succ] at hh | |
| rw [hh] | |
| exact S.blockSteps_card_add (hf (Fin.zero_le _)) (hf (Fin.castSucc_le_succ _)) | |
| noncomputable def States.ActivityGreedy.fullIndex (S : @States n T k P) {s : Fin (T+1)} {b : β} | |
| (G : S.ActivityGreedy s b) : Fin (G.count+2) β Fin (T+1) := | |
| Fin.snoc G.index (Fin.last T) | |
| lemma States.ActivityGreedy.fullIndex_mono (S : @States n T k P) {s : Fin (T+1)} {b : β} | |
| (G : S.ActivityGreedy s b) : Monotone (G.fullIndex S) := by | |
| intro i j hij | |
| revert hij | |
| refine Fin.lastCases ?_ (fun j => ?_) j | |
| Β· intro _ | |
| simpa only [States.ActivityGreedy.fullIndex,Fin.snoc_last] using (Fin.le_last (G.fullIndex S i)) | |
| Β· refine Fin.lastCases ?_ (fun i => ?_) i | |
| Β· intro hij | |
| exact False.elim (not_le_of_gt (Fin.castSucc_lt_last j) hij) | |
| Β· intro hij | |
| simpa only [States.ActivityGreedy.fullIndex,Fin.snoc_castSucc] using G.increasing.monotone (Fin.castSucc_le_castSucc_iff.mp hij) | |
| lemma States.ActivityGreedy.fullIndex_first (S : @States n T k P) {s : Fin (T+1)} {b : β} | |
| (G : S.ActivityGreedy s b) : G.fullIndex S 0=s := by | |
| simpa only [States.ActivityGreedy.fullIndex,βFin.castSucc_zero,Fin.snoc_castSucc] using G.first | |
| lemma States.ActivityGreedy.fullIndex_last (S : @States n T k P) {s : Fin (T+1)} {b : β} | |
| (G : S.ActivityGreedy s b) : G.fullIndex S (Fin.last (G.count+1))=Fin.last T := Fin.snoc_last _ _ | |
| lemma States.ActivityGreedy.fullIndex_activity (S : @States n T k P) {s : Fin (T+1)} {b : β} | |
| (G : S.ActivityGreedy s b) (j : Fin (G.count+1)) : | |
| S.activitySize (G.fullIndex S j.castSucc) (G.fullIndex S j.succ)β€b+1 := by | |
| refine Fin.lastCases ?_ (fun i => ?_) j | |
| Β· simpa only [States.ActivityGreedy.fullIndex,Fin.snoc_castSucc,Fin.succ_last,Fin.snoc_last] using G.tail.le.trans (Nat.le_succ b) | |
| Β· simpa only [States.ActivityGreedy.fullIndex,βFin.castSucc_succ,Fin.snoc_castSucc] using G.upper i | |
| lemma activity_decomposition {n k : β} {P : Fin n β Point} (hP : Generic P) (hk : kβ€n) | |
| {b : β} (hb : 0<b) : | |
| β (A : Fin (((states P hP hk).activityGreedy 0 b hb).count+1) β Finset (Fin n)) | |
| (r : Fin (((states P hP hk).activityGreedy 0 b hb).count+1) β β), | |
| (β j, (A j).cardβ€b+1) β§ (β j, r jβ€(A j).card) β§ | |
| switchCount P k β€ β j, switchCount (subsetPoints P (A j)) (r j) := by | |
| classical | |
| let S := states P hP hk | |
| let G := S.activityGreedy 0 b hb | |
| let f := G.fullIndex S | |
| have hf : Monotone f := G.fullIndex_mono S | |
| let A (j : Fin (G.count+1)) := S.intervalActivity (f j.castSucc) (f j.succ) (hf (Fin.castSucc_le_succ j)) | |
| have hex (j : Fin (G.count+1)) : β r : β, rβ€(A j).card β§ | |
| (S.blockSteps (f j.castSucc) (f j.succ)).card β€ switchCount (subsetPoints P (A j)) r := | |
| block_count_le hP hk (hf (Fin.castSucc_le_succ j)) | |
| choose r hr hcount using hex | |
| refine β¨A,r,?_,hr,?_β© | |
| Β· intro j | |
| rw [β S.activitySize_eq] | |
| exact G.fullIndex_activity S j | |
| Β· have hsum := S.sum_blockSteps (G.count+1) f hf | |
| dsimp only [f] at hsum | |
| rw [G.fullIndex_first S,G.fullIndex_last S,S.blockSteps_all] at hsum | |
| calc | |
| switchCount P k β€ S.changeSteps.card := switchCount_le_changes hP hk | |
| _ = β j : Fin (G.count+1), (S.blockSteps (f j.castSucc) (f j.succ)).card := hsum.symm | |
| _ β€ _ := Finset.sum_le_sum (fun j _ => hcount j) | |
| end PlanarHalving.Sweep | |
| namespace PlanarHalving.Sweep | |
| lemma division_scale {n q : β} (hq : 4β€q) (hn : 4*qβ€n) : | |
| let b := n/q-1 | |
| 0<b β§ b+1=n/q β§ (b+1:β)β€(n:β)/q β§ nβ€2*q*b β§ (b+1)<n := by | |
| have hq0 : 0<q := by omega | |
| have hd : 4β€n/q := (Nat.le_div_iff_mul_le hq0).mpr hn | |
| have hbd : n/q-1+1=n/q := by omega | |
| refine β¨by omega,hbd,?_,?_,?_β© | |
| Β· have he : ((n/q-1:β):β)+1=(n/q:β) := by exact_mod_cast hbd | |
| rw [he] | |
| exact (le_div_iffβ (by exact_mod_cast hq0)).mpr (by exact_mod_cast Nat.div_mul_le_self n q) | |
| Β· have he := Nat.mod_add_div n q | |
| have hm := Nat.mod_lt n hq0 | |
| nlinarith | |
| Β· rw [hbd] | |
| exact Nat.div_lt_self (by omega) (by omega) | |
| lemma greedy_count_bound {q : β} (hq : 4β€q) {m n b : β} (hb : 0<b) | |
| (hn : nβ€2*q*b) (hp : (m:β)^3*(b:β)^4β€(n:β)^4/1024) : | |
| (m:β)+1β€(q:β)^((4:β)/3)/2 := by | |
| have hq0 : (0:β)<q := by exact_mod_cast (show 0<q by omega) | |
| have hbr : (0:β)<b := by exact_mod_cast hb | |
| have hnr : (n:β)β€2*(q:β)*b := by exact_mod_cast hn | |
| have hpow : ((q:β)^((4:β)/3))^3=(q:β)^4 := by | |
| rw [βReal.rpow_mul_natCast hq0.le] | |
| norm_num | |
| have hm : (m:β)β€(q:β)^((4:β)/3)/4 := by | |
| apply le_of_pow_le_pow_leftβ (by decide : (3:β)β 0) (by positivity) | |
| have hn4 := pow_le_pow_leftβ (show (0:β)β€n by positivity) hnr 4 | |
| have ht : (m:β)^3*(b:β)^4β€((q:β)^((4:β)/3)/4)^3*(b:β)^4 := by | |
| rw [div_pow,hpow] | |
| nlinarith | |
| exact (mul_le_mul_iff_leftβ (pow_pos hbr 4)).mp ht | |
| have hqpow : (4:β)β€(q:β)^((4:β)/3) := by | |
| have h1 := Real.rpow_le_rpow_of_exponent_le (show (1:β)β€q by exact_mod_cast (show 1β€q by omega)) (by norm_num : (1:β)β€4/3) | |
| rw [Real.rpow_one] at h1 | |
| exact (show (4:β)β€q by exact_mod_cast hq).trans h1 | |
| linarith | |
| lemma recurrence_exponent {q : β} (hq : 4β€q) : | |
| β Ξ΅ : β, 0<Ξ΅ β§ 0<(4:β)/3-Ξ΅ β§ | |
| (q:β)^((4:β)/3)/2β€(q:β)^((4:β)/3-Ξ΅) := by | |
| have hq2 : (2:β)β€q := by exact_mod_cast (show 2β€q by omega) | |
| have hq0 : (0:β)<q := lt_of_lt_of_le (by norm_num) hq2 | |
| have hl2 : 0<Real.log 2 := Real.log_pos (by norm_num) | |
| have hlq : 0<Real.log (q:β) := Real.log_pos (by linarith) | |
| have hlog : Real.log 2β€Real.log (q:β) := Real.log_le_log (by norm_num) hq2 | |
| let Ξ΅ : β := Real.log 2/(2*Real.log (q:β)) | |
| have he : 0<Ξ΅ := div_pos hl2 (by positivity) | |
| have hehalf : Ξ΅β€1/2 := by | |
| dsimp [Ξ΅] | |
| apply (div_le_iffβ (by positivity : 0<2*Real.log (q:β))).mpr | |
| nlinarith | |
| refine β¨Ξ΅,he,by linarith,?_β© | |
| rw [Real.rpow_sub hq0] | |
| apply div_le_div_of_nonneg_left (by positivity) (Real.rpow_pos_of_pos hq0 Ξ΅) | |
| rw [Real.rpow_def_of_pos hq0] | |
| calc | |
| Real.exp (Real.log (q:β)*Ξ΅) β€ Real.exp (Real.log 2) := by | |
| apply Real.exp_le_exp.mpr | |
| dsimp [Ξ΅] | |
| have hl0 := ne_of_gt hlq | |
| field_simp | |
| nlinarith | |
| _ = 2 := Real.exp_log (by norm_num) | |
| end PlanarHalving.Sweep | |
| end OAI | |