Download data/lean/OAI/Combinatorics/PerfectMatching/Main.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 9.83 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/PerfectMatching/Main.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/PerfectMatching/Main.lean
-
curl -L -o Main.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/PerfectMatching/Main.lean
9.83 kB
| import OAI.Combinatorics.PerfectMatching.MatchingCovariance | |
| namespace OAI | |
| /-! | |
| The nonlinear entropy defect bound | |
| `F - H β€ 8m (1 - exp (-F/m))` for finite loopless multigraphs on `2m` vertices, | |
| and the perfect matching count bound `[k exp (-8 (1 - 1/k))]^m`, | |
| with its coarse bound `(exp (-8) k)^m`, when the entire edge set | |
| is partitioned into `k β₯ 1` perfect matchings. | |
| -/ | |
| noncomputable section | |
| open scoped BigOperators Topology | |
| open Filter | |
| namespace MatchingEntropy | |
| open Matrix | |
| variable {V E : Type*} [Fintype V] [Fintype E] [DecidableEq V] [DecidableEq E] | |
| /-- The small-entropy regime of the nonlinear barrier function. -/ | |
| theorem entropy_barrier_ge_id {t : β} (ht : 0 β€ t) (h8 : t β€ Real.log 8) : | |
| t β€ 8 * (1-Real.exp (-t)) := by | |
| have he : 1 β€ Real.exp t := Real.one_le_exp_iff.mpr ht | |
| have he8 : Real.exp t β€ 8 := by | |
| have hh := Real.exp_le_exp.mpr h8 | |
| rw [Real.exp_log (by norm_num : (0 : β) < 8)] at hh | |
| exact hh | |
| have hlog := Real.log_le_sub_one_of_pos (Real.exp_pos t) | |
| rw [Real.log_exp] at hlog | |
| have hin := Real.exp_neg t | |
| rw [hin] | |
| have hp := Real.exp_pos t | |
| apply (mul_le_mul_iff_rightβ hp).mp | |
| have hmain : t * Real.exp t β€ 8 * (Real.exp t - 1) := by | |
| have : t β€ Real.exp t - 1 := hlog | |
| nlinarith | |
| have hprod : Real.exp t * (8*(1-(Real.exp t)β»ΒΉ)) = 8*(Real.exp t-1) := by | |
| field_simp [hp.ne'] | |
| calc | |
| Real.exp t * t = t * Real.exp t := mul_comm _ _ | |
| _ β€ 8 * (Real.exp t-1) := hmain | |
| _ = _ := hprod.symm | |
| /-- Entropy on s positive edge coordinates of total mass m is at most m log(s/m). -/ | |
| theorem marginal_entropy_support_bound (G : LooplessGraph V E) {m : β} | |
| (hm : 0 < m) (hV : Fintype.card V=2*m) {x : E β β} (hx : x β G.polytope) : | |
| 0 β€ entropy x β§ 0 < Fintype.card {e // 0 < x e} β§ | |
| entropy x β€ (m:β)*Real.log ((Fintype.card {e // 0 < x e}:β)/(m:β)) := by | |
| have hmR : (0:β) < m := by exact_mod_cast hm | |
| have hmass := G.marginal_sum hV hx | |
| have hn : β e, 0 β€ x e := fun e => (G.coordinate_mem_Icc hx e).1 | |
| have hz : β e, Β¬ 0 < x e β x e=0 := fun e he => le_antisymm (le_of_not_gt he) (hn e) | |
| have hsum : (β e : {e // 0 < x e}, x e.val)=(m:β) := | |
| (sum_positive_support x x hz).symm.trans hmass | |
| have hent : entropy (fun e : {e // 0 < x e} => x e.val)=entropy x := by | |
| unfold entropy | |
| exact (sum_positive_support x (fun e => Real.negMulLog (x e)) | |
| (fun e he => by rw [hz e he,Real.negMulLog_zero])).symm | |
| have hpossum : 0 < β e, x e := by rw [hmass]; exact hmR | |
| obtain β¨e,_,heβ© := (Finset.sum_pos_iff_of_nonneg (fun e _ => hn e)).mp hpossum | |
| have hs : 0 < Fintype.card {e // 0 < x e} := Fintype.card_pos_iff.mpr β¨β¨e,heβ©β© | |
| have hsR : (0:β) < Fintype.card {e // 0 < x e} := by exact_mod_cast hs | |
| refine β¨Finset.sum_nonneg (fun e _ => Real.negMulLog_nonneg (hn e) (G.coordinate_mem_Icc hx e).2),hs,?_β© | |
| let c : β := (Fintype.card {e // 0 < x e}:β)/(m:β) | |
| have hc : 0 < c := div_pos hsR hmR | |
| have hcm : c*(m:β)=Fintype.card {e // 0 < x e} := div_mul_cancelβ _ hmR.ne' | |
| have hb := Finset.sum_le_sum (s := Finset.univ) (fun e : {e // 0 < x e} => fun _ => | |
| Real.negMulLog_le_one_sub_self (mul_nonneg hc.le e.property.le)) | |
| simp_rw [Real.negMulLog_mul] at hb | |
| rw [Finset.sum_add_distrib,β Finset.sum_mul,β Finset.mul_sum,hsum, | |
| Finset.sum_sub_distrib,β Finset.mul_sum,hsum] at hb | |
| simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,mul_one] at hb | |
| change (m:β)*Real.negMulLog c+c*entropy (fun e : {e // 0 < x e} => x e.val) β€ | |
| (Fintype.card {e // 0 < x e}:β)-c*(m:β) at hb | |
| rw [hent,Real.negMulLog,hcm,sub_self] at hb | |
| change entropy x β€ (m:β)*Real.log c | |
| nlinarith | |
| /-- Main entropy comparison, for every marginal in the actual matching polytope. -/ | |
| theorem entropy_main (G : LooplessGraph V E) (m : β) | |
| (hm : 0 < m) (hV : Fintype.card V = 2 * m) | |
| (hPM : Nonempty G.Matching) (y : E β β) (hy : y β G.polytope) : | |
| marginalEntropy y - maxMatchingEntropy G y β€ | |
| 8 * (m : β) * (1 - Real.exp (-marginalEntropy y / (m : β))) := by | |
| have hmR : (0:β) < m := by exact_mod_cast hm | |
| have heven : Even (Fintype.card V) := by rw [hV]; exact even_two_mul m | |
| obtain β¨x,hx,hmaxβ© := entropyDefect_attains_max G heven hPM (m:β) | |
| by_contra htarget | |
| have hypos : 0 < entropyDefect G (m:β) y := by | |
| dsimp [entropyDefect,entropyBarrier,marginalEntropy] at * | |
| linarith | |
| have hpos : 0 < entropyDefect G (m:β) x := hypos.trans_le (hmax y hy) | |
| obtain β¨p,hp,hoptβ© := maxMatchingEntropy_attained G hx | |
| obtain β¨hxnon,hspos,hentropyβ© := marginal_entropy_support_bound G hm hV hx | |
| have hH := maxMatchingEntropy_nonneg G hx | |
| let s : β := Fintype.card {e // 0 < x e} | |
| have hsR : 0 < s := by dsimp only [s]; exact_mod_cast hspos | |
| have hrpos : 0 < s/(m:β) := div_pos hsR hmR | |
| have hu : entropy x/(m:β) β€ Real.log (s/(m:β)) := by | |
| apply (div_le_iffβ hmR).mpr | |
| simpa only [mul_comm] using hentropy | |
| have hlo : Real.log 8 < entropy x/(m:β) := by | |
| by_contra hle | |
| have hb := entropy_barrier_ge_id (div_nonneg hxnon hmR.le) (le_of_not_gt hle) | |
| have hb' := (div_le_iffβ hmR).mp hb | |
| dsimp only [entropyDefect,entropyBarrier] at hpos | |
| rw [neg_div] at hpos | |
| nlinarith | |
| have hs8 : 8*(m:β) < s := by | |
| have hh := (Real.log_lt_log_iff (by norm_num : (0:β)<8) hrpos).mp (hlo.trans_le hu) | |
| exact (lt_div_iffβ hmR).mp hh | |
| have ha : 8*(m:β)/s β€ 8*Real.exp (-entropy x/(m:β)) := by | |
| have hh := Real.exp_le_exp.mpr (neg_le_neg hu) | |
| rw [Real.exp_neg,Real.exp_log hrpos,inv_div] at hh | |
| rw [neg_div,mul_div_assoc] | |
| exact mul_le_mul_of_nonneg_left hh (by norm_num) | |
| have hrankNat := matching_covariance_rank G heven hp hopt | |
| rw [hV] at hrankNat | |
| have hrankR : s β€ 2*(2*(m:β))+(covariance p (matchingNormalized G x)).rank := by | |
| dsimp only [s] | |
| exact_mod_cast hrankNat | |
| have hrank : s-4*(m:β) β€ (covariance p (matchingNormalized G x)).rank := by linarith | |
| exact covariance_contradiction (covariance_posSemidef p (matchingNormalized G x)) hmR hs8 | |
| hrank (matching_covariance_trace G hp hV) ha | |
| (matching_covariance_second_variation G hp hopt hmR hmax) | |
| omit [Fintype V] [Fintype E] [DecidableEq V] in | |
| /-- An edge partition into k matchings places the exact uniform edge vector in P. -/ | |
| theorem uniform_decomposition_mem (G : LooplessGraph V E) {k : β} (hk : 1 β€ k) | |
| (M : Fin k β G.Matching) | |
| (hpartition : β e : E, β! i : Fin k, e β (M i).val) : | |
| (fun _ : E => 1/(k:β)) β G.polytope := by | |
| classical | |
| have hkR : (0:β) < k := by exact_mod_cast (show 0 < k by omega) | |
| have hsum : (β i : Fin k, (1/(k:β)))=1 := by | |
| simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] | |
| field_simp | |
| have hmean := (convex_convexHull β (Set.range G.indicator)).sum_mem | |
| (fun (i : Fin k) _ => (one_div_pos.mpr hkR).le) hsum | |
| (fun i _ => subset_convexHull β _ (Set.mem_range_self (M i))) | |
| have heq : (β i : Fin k, (1/(k:β)) β’ G.indicator (M i)) = (fun _ : E => 1/(k:β)) := by | |
| ext e | |
| simp only [Finset.sum_apply,Pi.smul_apply,smul_eq_mul] | |
| rw [β Finset.mul_sum] | |
| have hi : (β i : Fin k, G.indicator (M i) e)=1 := by | |
| obtain β¨i,hi,huβ© := hpartition e | |
| rw [Finset.sum_eq_single i] | |
| Β· simp [LooplessGraph.indicator,hi] | |
| Β· intro j _ hji | |
| have hj : e β (M j).val := fun h => hji (hu j h) | |
| simp [LooplessGraph.indicator,hj] | |
| Β· simp | |
| rw [hi,mul_one] | |
| rwa [heq] at hmean | |
| /-- The exact decomposable-graph count theorem, including its coarser bound. -/ | |
| theorem count_main (G : LooplessGraph V E) (m k : β) | |
| (hm : 0 < m) (hV : Fintype.card V = 2 * m) (hk : 1 β€ k) | |
| (M : Fin k β G.Matching) | |
| (hpartition : β e : E, β! i : Fin k, e β (M i).val) : | |
| ((k : β) * Real.exp (-8 * (1 - 1 / (k : β)))) ^ m β€ | |
| (Fintype.card G.Matching : β) β§ | |
| (Real.exp (-8) * (k : β)) ^ m β€ | |
| ((k : β) * Real.exp (-8 * (1 - 1 / (k : β)))) ^ m := by | |
| have hkR : (0:β) < k := by exact_mod_cast (show 0 < k by omega) | |
| have hmR : (0:β) < m := by exact_mod_cast hm | |
| have hPM : Nonempty G.Matching := β¨M β¨0,by omegaβ©β© | |
| let x : E β β := fun _ => 1/(k:β) | |
| have hx : x β G.polytope := uniform_decomposition_mem G hk M hpartition | |
| have hh : marginalEntropy x=(m:β)*Real.log (k:β) := by | |
| have hlog : Real.negMulLog (1/(k:β))=(1/(k:β))*Real.log (k:β) := by | |
| rw [one_div,Real.negMulLog,Real.log_inv] | |
| ring | |
| change (β e : E, Real.negMulLog (1/(k:β)))=_ | |
| simp_rw [hlog] | |
| rw [β Finset.sum_mul] | |
| exact congrArg (fun t : β => t*Real.log (k:β)) (G.marginal_sum hV hx) | |
| have hi := entropy_main G m hm hV hPM x hx | |
| have hH := maxMatchingEntropy_le_log_card G hx | |
| have hexp : Real.exp (-((m:β)*Real.log (k:β))/(m:β))=1/(k:β) := by | |
| have he : -((m:β)*Real.log (k:β))/(m:β) = -Real.log (k:β) := by | |
| field_simp | |
| rw [he,Real.exp_neg,Real.exp_log hkR] | |
| simp only [one_div] | |
| rw [hh,hexp] at hi | |
| have hlogbound : (m:β)*(Real.log (k:β)+(-8*(1-1/(k:β)))) β€ | |
| Real.log (Fintype.card G.Matching:β) := by nlinarith | |
| have hN : (0:β) < Fintype.card G.Matching := by | |
| exact_mod_cast Fintype.card_pos_iff.mpr hPM | |
| constructor | |
| Β· have he := Real.exp_le_exp.mpr hlogbound | |
| rw [Real.exp_log hN,Real.exp_nat_mul,Real.exp_add,Real.exp_log hkR] at he | |
| exact he | |
| Β· apply pow_le_pow_leftβ (mul_nonneg (Real.exp_pos _).le hkR.le) | |
| have he : Real.exp (-8) β€ Real.exp (-8*(1-1/(k:β))) := by | |
| apply Real.exp_le_exp.mpr | |
| have hq := (one_div_pos.mpr hkR).le | |
| nlinarith | |
| calc | |
| Real.exp (-8)*(k:β) = (k:β)*Real.exp (-8) := mul_comm _ _ | |
| _ β€ _ := mul_le_mul_of_nonneg_left he hkR.le | |
| end MatchingEntropy | |
| end | |
| end OAI | |