Download data/lean/OAI/Probability/SATVariance/BystanderVariance.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 11 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/SATVariance/BystanderVariance.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Probability/SATVariance/BystanderVariance.lean
-
curl -L -o BystanderVariance.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Probability/SATVariance/BystanderVariance.lean
11 kB
| import OAI.Probability.SATVariance.SentinelBridge | |
| namespace OAI | |
| noncomputable section | |
| open MeasureTheory ProbabilityTheory | |
| namespace RandomKSAT | |
| open scoped Classical ENNReal | |
| lemma bystanders_perm_right {n k : β} {b l r : List (Clause n k)} | |
| (hb : Bystanders b l) (h : l.Perm r) : Bystanders b r := by | |
| induction b with | |
| | nil => trivial | |
| | cons c b ih => | |
| exact β¨private_perm (h.append_left b) hb.1,ih hb.2β© | |
| def shuffleVar.{u_1} {Ξ± : Type u_1} (l : List Ξ±) (f : List Ξ± β β) : β := | |
| shuffleAvg l (fun r => (f r)^2) - (shuffleAvg l f)^2 | |
| lemma shuffleVar_nonneg.{u_1} {Ξ± : Type u_1} (l : List Ξ±) (f : List Ξ± β β) : 0 β€ shuffleVar l f := | |
| sub_nonneg.mpr (shuffleAvg_sq_le l f) | |
| lemma shuffleVar_perm.{u_1} {Ξ± : Type u_1} {l r : List Ξ±} (h : l.Perm r) (f : List Ξ± β β) : | |
| shuffleVar l f = shuffleVar r f := by | |
| unfold shuffleVar | |
| rw [shuffleAvg_perm h,shuffleAvg_perm h] | |
| lemma shuffleVar_append_lower.{u_1} {Ξ± : Type u_1} (b l : List Ξ±) (f : List Ξ± β β) : | |
| shuffleAvg l (fun r => insertVar b r f) β€ shuffleVar (b++l) f := by | |
| simp only [shuffleVar,shuffleAvg_append,insertVar] | |
| rw [shuffleAvg_sub] | |
| have hh := shuffleAvg_sq_le l (fun r => insertAvg b r f) | |
| linarith | |
| lemma favg_shuffleVar_lower.{u_1} {Ξ± : Type u_1} [Fintype Ξ±] [Nonempty Ξ±] (M : β) (f : List Ξ± β β) : | |
| favg (fun w : Fin M β Ξ± => shuffleVar (List.ofFn w) f) β€ | |
| fvariance (fun w : Fin M β Ξ± => f (List.ofFn w)) := by | |
| simp only [shuffleVar,fvariance,favg_sub,favg_shuffle] | |
| have hh := favg_sq_le (fun w : Fin M β Ξ± => shuffleAvg (List.ofFn w) f) | |
| rw [favg_shuffle] at hh | |
| linarith | |
| def outsideWindow {n k : β} (Q V : β) (r : List (Clause n k)) : β := | |
| if listStop r < 2*Q β¨ V < listStop r then 1 else 0 | |
| lemma outsideWindow_nonneg {n k : β} (Q V : β) (r : List (Clause n k)) : | |
| 0 β€ outsideWindow Q V r := by unfold outsideWindow; positivity | |
| lemma bystander_variance {n k : β} {b l : List (Clause n k)} (hb : Bystanders b l) | |
| (Q V M : β) (hlen : b.length+l.length = M) (hbQ : b.length β€ Q) | |
| (hQV : Q+V β€ M+1) : | |
| ((Q:β)*((M:β)+1-Q-V)/((M:β)+1)^2)*b.length β€ | |
| shuffleVar (b++l) (fun r => (listStop r:β)) + | |
| ((Q:β)*((M:β)+1-Q-V)/((M:β)+1)^2)*b.length* | |
| shuffleAvg (b++l) (outsideWindow Q V) := by | |
| let p : β := (Q:β)*((M:β)+1-Q-V)/((M:β)+1)^2 | |
| have hC : 0 β€ (M:β)+1-Q-V := by | |
| have hh : (Q:β)+V β€ M+1 := by exact_mod_cast hQV | |
| linarith | |
| have hp : 0 β€ p := by dsimp [p]; positivity | |
| have hbl : (b.length:β)+(l.length:β) = M := by exact_mod_cast hlen | |
| have hq : (b.length:β) β€ Q := by exact_mod_cast hbQ | |
| have hlocal (r : List (Clause n k)) (hr : r.Perm l) : | |
| p*b.length β€ insertVar b r (fun s => (listStop s:β)) + | |
| p*b.length*insertAvg b r (outsideWindow Q V) := by | |
| have hb' : Bystanders b r := bystanders_perm_right hb hr.symm | |
| have hrlen : (r.length:β) = l.length := by exact_mod_cast hr.length_eq | |
| by_cases ht : Q β€ listStop r β§ listStop r β€ V | |
| Β· have hv := insertVar_stop_lower hb' hC (by positivity : (0:β) < (M:β)+1) | |
| (by exact_mod_cast ht.1 : (Q:β) β€ listStop r) | |
| (show (M:β)+1-Q-V β€ (r.length:β)+1-listStop r by | |
| have htv : (listStop r:β) β€ V := by exact_mod_cast ht.2 | |
| linarith) | |
| (show (b.length:β)+r.length+1 β€ (M:β)+1 by linarith) | |
| have hn : 0 β€ insertAvg b r (outsideWindow Q V) := by | |
| rw [βinsertAvg_const b r 0] | |
| exact insertAvg_mono b r (fun s _ => outsideWindow_nonneg Q V s) | |
| have hh : 0 β€ p*b.length*insertAvg b r (outsideWindow Q V) := by positivity | |
| dsimp [p] at hv β’ | |
| nlinarith | |
| Β· have hout : insertAvg b r (outsideWindow Q V) = 1 := by | |
| rw [βinsertAvg_const b r 1] | |
| apply insertAvg_congr | |
| intro s hs | |
| have hst := inserts_stop_bounds hb' hs | |
| have hh : listStop s < 2*Q β¨ V < listStop s := by omega | |
| simp [outsideWindow,hh] | |
| rw [hout,mul_one] | |
| linarith [insertVar_nonneg b r (fun s => (listStop s:β))] | |
| have hh := shuffleAvg_mono (l := l) hlocal | |
| rw [shuffleAvg_const,shuffleAvg_add,shuffleAvg_mul] at hh | |
| have hv := shuffleVar_append_lower b l (fun r => (listStop r:β)) | |
| rw [shuffleAvg_append] | |
| change p*b.length β€ _ + p*b.length*_ | |
| linarith | |
| lemma bystanders_map {n k M : β} (hk : 1 β€ k) (w : Fin M β Clause n k) | |
| {is js : List (Fin M)} (hnd : is.Nodup) | |
| (hi : β i β is, isolated w i) (hd : β i β is, i β js) : | |
| Bystanders (is.map w) (js.map w) := by | |
| induction is with | |
| | nil => trivial | |
| | cons i is ih => | |
| have hnd' := List.nodup_cons.mp hnd | |
| have hic := hi i (by simp) | |
| have hid := hd i (by simp) | |
| constructor | |
| Β· have hn : (w i).1.1.Nonempty := Finset.card_pos.mp (by rw [(w i).1.2]; omega) | |
| obtain β¨v,hvβ© := hn | |
| refine β¨β¨v,hvβ©,?_β© | |
| intro d hd' | |
| rcases List.mem_append.mp hd' with hd' | hd' | |
| Β· obtain β¨j,hj,rflβ© := List.mem_map.mp hd' | |
| have hji : j β i := by intro he; subst j; exact hnd'.1 hj | |
| exact Finset.disjoint_left.mp (hic j hji) hv | |
| Β· obtain β¨j,hj,rflβ© := List.mem_map.mp hd' | |
| have hji : j β i := by intro he; subst j; exact hid hj | |
| exact Finset.disjoint_left.mp (hic j hji) hv | |
| Β· exact ih hnd'.2 (fun j hj => hi j (by simp [hj])) (fun j hj => hd j (by simp [hj])) | |
| def chosenIsolates {n k M : β} (Q : β) (w : Fin M β Clause n k) : Finset (Fin M) := | |
| Classical.choose (Finset.exists_subset_card_eq (s := isolateSet w) (min_le_right Q (isolateSet w).card)) | |
| lemma chosenIsolates_subset {n k M : β} (Q : β) (w : Fin M β Clause n k) : | |
| chosenIsolates Q w β isolateSet w := | |
| (Classical.choose_spec (Finset.exists_subset_card_eq | |
| (s := isolateSet w) (min_le_right Q (isolateSet w).card))).1 | |
| lemma chosenIsolates_card {n k M : β} (Q : β) (w : Fin M β Clause n k) : | |
| (chosenIsolates Q w).card = min Q (isolateSet w).card := | |
| (Classical.choose_spec (Finset.exists_subset_card_eq | |
| (s := isolateSet w) (min_le_right Q (isolateSet w).card))).2 | |
| def bystanderList {n k M : β} (Q : β) (w : Fin M β Clause n k) : List (Clause n k) := | |
| (chosenIsolates Q w).toList.map w | |
| def activeList {n k M : β} (Q : β) (w : Fin M β Clause n k) : List (Clause n k) := | |
| (Finset.univ \ chosenIsolates Q w).toList.map w | |
| lemma selected_bystanders {n k M : β} (hk : 1 β€ k) (Q : β) (w : Fin M β Clause n k) : | |
| Bystanders (bystanderList Q w) (activeList Q w) := by | |
| apply bystanders_map hk w (Finset.nodup_toList _) | |
| Β· intro i hi | |
| exact (Finset.mem_filter.mp (chosenIsolates_subset Q w (Finset.mem_toList.mp hi))).2 | |
| Β· intro i hi | |
| simp only [Finset.mem_toList,Finset.mem_sdiff,Finset.mem_univ,true_and,not_not] | |
| exact Finset.mem_toList.mp hi | |
| lemma selected_perm {n k M : β} (Q : β) (w : Fin M β Clause n k) : | |
| ((bystanderList Q w)++(activeList Q w)).Perm (List.ofFn w) := by | |
| let I := chosenIsolates Q w | |
| have hnd : (I.toList++(Finset.univ\I).toList).Nodup := by | |
| apply List.nodup_append.mpr | |
| refine β¨Finset.nodup_toList _,Finset.nodup_toList _,?_β© | |
| intro i hi j hj he | |
| subst j | |
| exact (Finset.mem_sdiff.mp (Finset.mem_toList.mp hj)).2 (Finset.mem_toList.mp hi) | |
| have hid : (List.ofFn (id : Fin M β Fin M)).Nodup := List.nodup_ofFn.mpr Function.injective_id | |
| have hp : (I.toList++(Finset.univ\I).toList).Perm (List.ofFn (id : Fin M β Fin M)) := by | |
| rw [List.perm_ext_iff_of_nodup hnd hid] | |
| intro i | |
| simp only [List.mem_append,Finset.mem_toList,Finset.mem_sdiff,Finset.mem_univ,true_and,List.mem_ofFn] | |
| simp only [id_eq,exists_eq,iff_true] | |
| exact em (i β I) | |
| have hh := hp.map w | |
| change ((I.toList.map w)++((Finset.univ\I).toList.map w)).Perm (List.ofFn w) | |
| simpa only [List.map_append,List.map_ofFn,Function.comp_id] using hh | |
| lemma bystanderList_length {n k M : β} (Q : β) (w : Fin M β Clause n k) : | |
| (bystanderList Q w).length = min Q (isolateSet w).card := by | |
| simp only [bystanderList,List.length_map,Finset.length_toList,chosenIsolates_card] | |
| lemma selected_lengths {n k M : β} (Q : β) (w : Fin M β Clause n k) : | |
| (bystanderList Q w).length+(activeList Q w).length = M := by | |
| have := (selected_perm Q w).length_eq | |
| simpa only [List.length_append,List.length_ofFn] using this | |
| lemma selected_variance {n k M : β} (hk : 1 β€ k) (hkn : k β€ n) | |
| (Q V : β) (hQV : Q+V β€ M+1) : | |
| ((Q:β)*((M:β)+1-Q-V)/((M:β)+1)^2)* | |
| favg (fun w : Fin M β Clause n k => (min Q (isolateSet w).card : β)) β€ | |
| fvariance (fun w : Fin M β Clause n k => (listStop (List.ofFn w):β)) + | |
| ((Q:β)*((M:β)+1-Q-V)/((M:β)+1)^2)*Q* | |
| favg (fun w : Fin M β Clause n k => outsideWindow Q V (List.ofFn w)) := by | |
| let := clause_nonempty n k hkn | |
| let p : β := (Q:β)*((M:β)+1-Q-V)/((M:β)+1)^2 | |
| have hC : 0 β€ (M:β)+1-Q-V := by | |
| have hh : (Q:β)+V β€ M+1 := by exact_mod_cast hQV | |
| linarith | |
| have hp : 0 β€ p := by dsimp [p]; positivity | |
| have hh (w : Fin M β Clause n k) : | |
| p*(min Q (isolateSet w).card:β) β€ | |
| shuffleVar (List.ofFn w) (fun r => (listStop r:β)) + p*Q* | |
| shuffleAvg (List.ofFn w) (outsideWindow Q V) := by | |
| have ht := bystander_variance (selected_bystanders hk Q w) Q V M (selected_lengths Q w) | |
| (by rw [bystanderList_length]; exact min_le_left _ _) hQV | |
| rw [shuffleVar_perm (selected_perm Q w),shuffleAvg_perm (selected_perm Q w),bystanderList_length] at ht | |
| have hmin : (min Q (isolateSet w).card:β) β€ Q := by exact_mod_cast min_le_left Q (isolateSet w).card | |
| have hnon := shuffleAvg_nonneg (l := List.ofFn w) (fun r _ => outsideWindow_nonneg Q V r) | |
| have he := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hmin hp) hnon | |
| simp only [Nat.cast_min] at ht | |
| apply ht.trans | |
| dsimp only [p] at he | |
| linarith | |
| have hh' := favg_mono hh | |
| simp only [favg_mul,favg_add,favg_shuffle] at hh' | |
| have hv := favg_shuffleVar_lower M (fun r : List (Clause n k) => (listStop r:β)) | |
| change p*_ β€ _ + p*Q*_ | |
| linarith | |
| lemma min_isolate_mean_lower {n k M Q : β} (hM : 0 < M) (hQ : Q β€ M) | |
| {Ξ² : β} (hmean : (M:β)*Ξ² β€ favg (fun w : Fin M β Clause n k => ((isolateSet w).card:β))) : | |
| (Q:β)*Ξ² β€ favg (fun w : Fin M β Clause n k => (min Q (isolateSet w).card:β)) := by | |
| have hh (w : Fin M β Clause n k) : | |
| (Q:β)*(isolateSet w).card β€ (M:β)*(min Q (isolateSet w).card:β) := by | |
| have hJ : (isolateSet w).card β€ M := by simpa using Finset.card_le_univ (isolateSet w) | |
| have ht : Q*(isolateSet w).card β€ M*min Q (isolateSet w).card := by | |
| by_cases h : Q β€ (isolateSet w).card | |
| Β· rw [min_eq_left h]; nlinarith | |
| Β· rw [min_eq_right (by omega)]; nlinarith | |
| exact_mod_cast ht | |
| have ht := favg_mono hh | |
| rw [favg_mul,favg_mul] at ht | |
| have hh' := mul_le_mul_of_nonneg_left hmean (show (0:β) β€ Q by positivity) | |
| have hMR : (0:β) < M := by exact_mod_cast hM | |
| nlinarith | |
| end RandomKSAT | |
| end | |
| end OAI | |