Download data/lean/OAI/Combinatorics/PerfectMatching/Separable.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 7.22 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/PerfectMatching/Separable.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/PerfectMatching/Separable.lean
-
curl -L -o Separable.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/PerfectMatching/Separable.lean
7.22 kB
| import OAI.Combinatorics.PerfectMatching.Main | |
| namespace OAI | |
| universe u_1 u_2 | |
| section | |
| noncomputable section | |
| open scoped BigOperators Topology | |
| open Filter | |
| namespace MatchingEntropy | |
| variable {V : Type u_1} {E : Type u_2} [Fintype V] [Fintype E] [DecidableEq V] [DecidableEq E] | |
| def binaryEntropy (x : E β β) : β := entropy x + entropy (fun e => 1 - x e) | |
| def separableLower (x : E β β) : β := entropy x - 3 * entropy (fun e => 1 - x e) | |
| def structuralBase (k : β) : β := | |
| if k = 1 then 1 else (k : β) * (1 - 1 / (k : β)) ^ (3 * (k - 1)) | |
| omit [Fintype V] [DecidableEq V] [DecidableEq E] in | |
| theorem continuous_separableLower : Continuous (separableLower (E := E)) := by | |
| exact continuous_entropy.sub (continuous_const.mul (continuous_entropy.comp (by fun_prop))) | |
| def separableLineD (x v : E β β) (t : β) : β := | |
| entropyLineD x v t - 3 * entropyLineD (fun e => 1-x e) (fun e => -v e) t | |
| omit [Fintype V] [DecidableEq V] [DecidableEq E] in | |
| theorem separable_line_eventually_hasDerivAt (x v : E β β) | |
| (hzero : β e, x e = 0 β v e = 0) (hone : β e, x e = 1 β v e = 0) : | |
| βαΆ t : β in π 0, | |
| HasDerivAt (fun t => separableLower (fun e => x e+t*v e)) | |
| (separableLineD x v t) t := by | |
| have hbar : β e, 1-x e=0 β -v e=0 := by | |
| intro e he | |
| rw [hone e (by linarith), neg_zero] | |
| filter_upwards [entropy_line_eventually_hasDerivAt x v hzero, | |
| entropy_line_eventually_hasDerivAt (fun e => 1-x e) (fun e => -v e) hbar] | |
| with t ht hb | |
| have he : (fun t => separableLower (fun e => x e+t*v e)) = | |
| (fun t => entropy (fun e => x e+t*v e) - | |
| 3 * entropy (fun e => (1-x e)+t*(-v e))) := by | |
| funext t | |
| unfold separableLower | |
| congr 2 | |
| congr 1 | |
| funext e | |
| ring | |
| rw [he] | |
| exact ht.sub (hb.const_mul 3) | |
| omit [Fintype V] [DecidableEq V] [DecidableEq E] in | |
| theorem separableLineD_hasDerivAt (x v : E β β) | |
| (hzero : β e, x e = 0 β v e = 0) (hone : β e, x e = 1 β v e = 0) : | |
| HasDerivAt (separableLineD x v) | |
| (-(β e, (v e)^2/x e) + 3*(β e, (v e)^2/(1-x e))) 0 := by | |
| have hbar : β e, 1-x e=0 β -v e=0 := by | |
| intro e he | |
| rw [hone e (by linarith), neg_zero] | |
| have hd := (entropyLineD_hasDerivAt x v hzero).sub | |
| ((entropyLineD_hasDerivAt (fun e => 1-x e) (fun e => -v e) hbar).const_mul 3) | |
| exact hd.congr_deriv (by simp only [neg_sq]; ring) | |
| omit [Fintype V] [DecidableEq V] [DecidableEq E] in | |
| theorem separable_second_variation {A : Type*} [Fintype A] | |
| (x v : E β β) (hzero : β e, x e=0 β v e=0) (hone : β e, x e=1 β v e=0) | |
| {p : A β β} (hp : p β probabilitySimplex A) (a : A β β) | |
| (hcenter : β i, p i*a i=0) (cβ cβ : β) | |
| (hlocal : IsLocalMax (fun t => separableLower (fun e => x e+t*v e) + | |
| cβ+t*cβ+t^2*(β i, p i*(a i)^2)-Real.log (partition p a t)) 0) : | |
| -(β e, (v e)^2/x e) + 3*(β e, (v e)^2/(1-x e)) + | |
| (β i, p i*(a i)^2) β€ 0 := by | |
| have hf := separable_line_eventually_hasDerivAt x v hzero hone | |
| have hg : βαΆ t : β in π 0, HasDerivAt (fun t => Real.log (partition p a t)) | |
| (partition (fun i => p i*a i) a t / partition p a t) t := | |
| Filter.Eventually.of_forall (logPartition_hasDerivAt hp a) | |
| have hd := second_deriv_quadratic_adjustment (cβ := cβ) (cβ := cβ) | |
| (v := β i, p i*(a i)^2) hf hg (separableLineD_hasDerivAt x v hzero hone) | |
| (logPartition_second hp a) | |
| have hc : ContinuousAt (fun t => separableLower (fun e => x e+t*v e) + | |
| cβ+t*cβ+t^2*(β i, p i*(a i)^2)-Real.log (partition p a t)) 0 := by | |
| apply ContinuousAt.sub | |
| Β· apply ContinuousAt.add | |
| Β· apply ContinuousAt.add | |
| Β· exact hf.self_of_nhds.continuousAt.add_const cβ | |
| Β· fun_prop | |
| Β· fun_prop | |
| Β· exact hg.self_of_nhds.continuousAt | |
| have hh := second_deriv_nonpos_of_local_max hlocal hc | |
| rw [hd.deriv, hcenter] at hh | |
| nlinarith | |
| omit [Fintype V] [DecidableEq V] in | |
| theorem mean_score_one (G : LooplessGraph V E) {p : G.Matching β β} | |
| (hp : p β probabilitySimplex G.Matching) (a : G.Matching β β) | |
| (hcenter : β M, p M*a M=0) : | |
| β e, G.mean p e=1 β G.mean (fun M => p M*a M) e=0 := by | |
| intro e he | |
| have hz : β M, p M*(1-G.indicator M e)=0 := by | |
| simp only [mul_sub, mul_one, Finset.sum_sub_distrib, hp.2] | |
| change 1-G.mean p e=0 | |
| rw [he, sub_self] | |
| have hterms : β M, p M*(1-G.indicator M e)=0 := by | |
| exact fun M => (Finset.sum_eq_zero_iff_of_nonneg | |
| (fun M (_ : M β Finset.univ) => | |
| mul_nonneg (hp.1 M) (sub_nonneg.mpr (G.indicator_le_one M e)))).mp hz M (by simp) | |
| calc | |
| _ = β M, p M*a M := by | |
| apply Finset.sum_congr rfl | |
| intro M _ | |
| have hh := hterms M | |
| have hh' : a M*(p M*(1-G.indicator M e))=0 := by rw [hh, mul_zero] | |
| nlinarith [hh'] | |
| _ = 0 := hcenter | |
| omit [Fintype V] [DecidableEq V] in | |
| theorem matching_separable_second_variation (G : LooplessGraph V E) {x : E β β} | |
| {p : G.Matching β β} (hp : p β G.feasibleLaws x) | |
| (hopt : entropy p=maxMatchingEntropy G x) | |
| (hmax : β y β G.polytope, separableLower y-maxMatchingEntropy G y β€ | |
| separableLower x-maxMatchingEntropy G x) | |
| (u : E β β) (c : β) (hcenter : β M, p M*linearScore G u c M=0) : | |
| -(β e, (G.mean (fun M => p M*linearScore G u c M) e)^2/x e) + | |
| 3*(β e, (G.mean (fun M => p M*linearScore G u c M) e)^2/(1-x e)) + | |
| (β M, p M*(linearScore G u c M)^2) β€ 0 := by | |
| let a := linearScore G u c | |
| let v := G.mean (fun M => p M*a M) | |
| let cβ := β M, p M*Real.log (p M) | |
| let cβ := β M, (p M*a M)*Real.log (p M) | |
| have hzero : β e, x e=0 β v e=0 := by | |
| rw [β hp.2] | |
| exact mean_score_support G hp.1 a | |
| have hone : β e, x e=1 β v e=0 := by | |
| rw [β hp.2] | |
| exact mean_score_one G hp.1 a hcenter | |
| apply separable_second_variation x v hzero hone hp.1 a hcenter cβ cβ | |
| filter_upwards [score_law_eventually_simplex hp.1 a hcenter] with t ht | |
| let r := fun M => p M+t*(p M*a M) | |
| have hr : r β probabilitySimplex G.Matching := ht | |
| have hrmean : G.mean r=fun e => x e+t*v e := by | |
| change G.meanLinear (p+t β’ (fun M => p M*a M)) = _ | |
| rw [map_add, map_smul] | |
| change G.mean p+t β’ v = _ | |
| rw [hp.2] | |
| rfl | |
| have hdual := matching_entropy_dual_bound G hp hopt hr | |
| (fun M hM => by dsimp [r]; simp [hM]) u c t | |
| have hscore : (β M, r M*a M)=t*(β M, p M*(a M)^2) := by | |
| dsimp [r] | |
| simp_rw [add_mul, mul_assoc t, Finset.sum_add_distrib, β Finset.mul_sum] | |
| rw [hcenter, zero_add] | |
| congr 1 | |
| apply Finset.sum_congr rfl | |
| intro M _ | |
| ring | |
| have hlog : (β M, r M*Real.log (p M))=cβ+t*cβ := by | |
| dsimp [r, cβ, cβ] | |
| simp_rw [add_mul, mul_assoc t, Finset.sum_add_distrib, β Finset.mul_sum] | |
| change maxMatchingEntropy G (G.mean r) β€ | |
| Real.log (partition p a t) - (β M, r M*Real.log (p M)) - t*(β M, r M*a M) at hdual | |
| rw [hlog, hscore] at hdual | |
| have hmaxr := hmax (G.mean r) (G.mean_mem_polytope hr) | |
| have hpart := partition_zero hp.1 a | |
| simp only [zero_mul, zero_pow (by omega : 2 β 0), add_zero, hpart, | |
| Real.log_one, sub_zero] | |
| rw [β hopt, entropy_eq p] at hmaxr | |
| rw [β hrmean] | |
| dsimp only [cβ] at * | |
| nlinarith | |
| end MatchingEntropy | |
| end | |
| end | |
| end OAI | |