Download data/lean/OAI/Combinatorics/CliqueFree/Optimizer.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 9.53 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/CliqueFree/Optimizer.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Combinatorics/CliqueFree/Optimizer.lean
-
curl -L -o Optimizer.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Combinatorics/CliqueFree/Optimizer.lean
9.53 kB
| import OAI.Combinatorics.CliqueFree.WeightedGraph | |
| namespace OAI | |
| noncomputable section | |
| open scoped BigOperators | |
| open Finset | |
| attribute [local instance] Classical.propDecidable | |
| namespace CliqueFreeIndependence.WeightedGraph | |
| universe u | |
| variable {V : Type u} [Fintype V] | |
| /-- The directed bilinear edge form (twice the quadratic mass on the diagonal). -/ | |
| noncomputable def edgeForm (G : SimpleGraph V) (a b : V β β) : β := | |
| β u, β v, if G.Adj u v then a u * b v else 0 | |
| lemma edgeForm_self (G : SimpleGraph V) (a : V β β) : edgeForm G a a = 2 * edgeMass G a := by | |
| simp only [edgeForm,edgeMass,crossMass] | |
| ring | |
| lemma edgeForm_symm (G : SimpleGraph V) (a b : V β β) : edgeForm G a b = edgeForm G b a := by | |
| unfold edgeForm | |
| rw [sum_comm] | |
| simp_rw [G.adj_comm,mul_comm] | |
| lemma edgeForm_add_left (G : SimpleGraph V) (a b c : V β β) : | |
| edgeForm G (a+b) c = edgeForm G a c + edgeForm G b c := by | |
| unfold edgeForm | |
| rw [β sum_add_distrib] | |
| apply sum_congr rfl | |
| intro u _ | |
| rw [β sum_add_distrib] | |
| apply sum_congr rfl | |
| intro v _ | |
| split_ifs <;> simp [Pi.add_apply,add_mul] | |
| lemma edgeForm_add_right (G : SimpleGraph V) (a b c : V β β) : | |
| edgeForm G a (b+c) = edgeForm G a b + edgeForm G a c := by | |
| rw [edgeForm_symm,edgeForm_add_left,edgeForm_symm _ b,edgeForm_symm _ c] | |
| lemma edgeForm_neighbor (G : SimpleGraph V) (a b : V β β) : | |
| edgeForm G a b = β u, a u * neighborMass G b u := by | |
| simp only [edgeForm,neighborMass,mass,neighbors,sum_filter,mul_sum,mul_ite,mul_zero] | |
| lemma edgeMass_add (G : SimpleGraph V) (a b : V β β) : | |
| edgeMass G (a+b) = edgeMass G a + edgeMass G b + edgeForm G a b := by | |
| have h := edgeForm_self G (a+b) | |
| rw [edgeForm_add_left,edgeForm_add_right,edgeForm_add_right,edgeForm_self,edgeForm_self, | |
| edgeForm_symm G b a] at h | |
| linarith | |
| lemma edgeForm_mono (G : SimpleGraph V) {a b c d : V β β} | |
| (ha : β v, 0 β€ a v) (hb : β v, 0 β€ b v) (hac : β v, a v β€ c v) (hbd : β v, b v β€ d v) : | |
| edgeForm G a b β€ edgeForm G c d := by | |
| apply sum_le_sum | |
| intro u _ | |
| apply sum_le_sum | |
| intro v _ | |
| split_ifs | |
| Β· exact mul_le_mul (hac u) (hbd v) (hb v) ((ha u).trans (hac u)) | |
| Β· rfl | |
| lemma edgeMass_mono_weight (G : SimpleGraph V) {w q : V β β} | |
| (hw : β v, 0 β€ w v) (hwq : β v, w v β€ q v) : edgeMass G w β€ edgeMass G q := by | |
| have h := edgeForm_mono G hw hw hwq hwq | |
| rw [edgeForm_self,edgeForm_self] at h | |
| linarith | |
| noncomputable def spike [DecidableEq V] (v : V) (t : β) : V β β := fun u β¦ if u = v then t else 0 | |
| lemma edgeForm_spike [DecidableEq V] (G : SimpleGraph V) (w : V β β) (v : V) (t : β) : | |
| edgeForm G (spike v t) w = t * neighborMass G w v := by | |
| rw [edgeForm_neighbor] | |
| simp [spike,ite_mul] | |
| lemma edgeMass_spike [DecidableEq V] (G : SimpleGraph V) (v : V) (t : β) : | |
| edgeMass G (spike v t) = 0 := by | |
| have h := edgeForm_self G (spike v t) | |
| rw [edgeForm_spike] at h | |
| have hn : neighborMass G (spike v t) v = 0 := by | |
| simp [neighborMass,mass,neighbors,spike] | |
| rw [hn] at h | |
| linarith | |
| omit [Fintype V] in | |
| lemma update_eq_add_spike [DecidableEq V] (w : V β β) (v : V) (t : β) : | |
| Function.update w v t = w + spike v (t-w v) := by | |
| funext u | |
| by_cases h : u = v <;> simp [Function.update,spike,h] | |
| lemma edgeMass_update [DecidableEq V] (G : SimpleGraph V) (w : V β β) (v : V) (t : β) : | |
| edgeMass G (Function.update w v t) = edgeMass G w + (t-w v)*neighborMass G w v := by | |
| rw [update_eq_add_spike,edgeMass_add,edgeMass_spike,edgeForm_symm,edgeForm_spike] | |
| ring | |
| /-- The vertex summand, with Mathlib's log(0)=0 convention. -/ | |
| def vertexPotential (t : β) : β := t * (1-Real.log t) | |
| noncomputable def potential (G : SimpleGraph V) (w : V β β) : β := | |
| β v, vertexPotential (w v) - edgeMass G w | |
| def IsOptimizer (G : SimpleGraph V) (w : V β β) : Prop := | |
| (β v, 0 β€ w v) β§ β q : V β β, (β v, 0 β€ q v) β potential G q β€ potential G w | |
| lemma continuous_vertexPotential : Continuous vertexPotential := by | |
| have h := continuous_id.sub Real.continuous_mul_log | |
| convert h using 1 | |
| ext x | |
| simp [vertexPotential] | |
| ring | |
| lemma continuous_edgeMass (G : SimpleGraph V) : Continuous (edgeMass G) := by | |
| classical | |
| unfold edgeMass crossMass | |
| apply Continuous.div_const | |
| apply continuous_finsetSum | |
| intro u _ | |
| apply continuous_finsetSum | |
| intro v _ | |
| split_ifs <;> fun_prop | |
| lemma continuous_potential (G : SimpleGraph V) : Continuous (potential G) := by | |
| unfold potential | |
| apply Continuous.sub _ (continuous_edgeMass G) | |
| exact continuous_finsetSum _ fun v _ β¦ continuous_vertexPotential.comp (continuous_apply v) | |
| lemma vertexPotential_le_one {t : β} (ht : 0 β€ t) : vertexPotential t β€ 1 := by | |
| rcases ht.eq_or_lt with rfl | ht | |
| Β· norm_num [vertexPotential] | |
| have h := mul_le_mul_of_nonneg_left (Real.one_sub_inv_le_log_of_pos ht) ht.le | |
| rw [mul_sub,mul_inv_cancelβ ht.ne'] at h | |
| unfold vertexPotential | |
| nlinarith | |
| lemma potential_clamp (G : SimpleGraph V) {w : V β β} (hw : β v, 0 β€ w v) : | |
| potential G w β€ potential G (fun v β¦ min (w v) 1) := by | |
| have hv (v : V) : vertexPotential (w v) β€ vertexPotential (min (w v) 1) := by | |
| by_cases h : w v β€ 1 | |
| Β· rw [min_eq_left h] | |
| Β· rw [min_eq_right (le_of_not_ge h)] | |
| simpa [vertexPotential] using vertexPotential_le_one (hw v) | |
| have hs := sum_le_sum (s := univ) (fun v _ β¦ hv v) | |
| have he := edgeMass_mono_weight G (fun v β¦ le_min (hw v) zero_le_one) (fun v β¦ min_le_left (w v) 1) | |
| unfold potential | |
| linarith | |
| lemma exists_optimizer (G : SimpleGraph V) : β w : V β β, IsOptimizer G w := by | |
| let S : Set (V β β) := Set.Icc 0 1 | |
| have hS : IsCompact S := isCompact_Icc | |
| have hne : S.Nonempty := β¨0,by simp [S]β© | |
| obtain β¨w,hw,hmaxβ© := hS.exists_isMaxOn hne (continuous_potential G).continuousOn | |
| refine β¨w,hw.1,?_β© | |
| intro q hq | |
| apply (potential_clamp G hq).trans | |
| apply hmax | |
| exact β¨fun v β¦ le_min (hq v) zero_le_one,fun v β¦ min_le_right (q v) 1β© | |
| lemma potential_update [DecidableEq V] (G : SimpleGraph V) (w : V β β) (v : V) (t : β) : | |
| potential G (Function.update w v t) - potential G w = | |
| vertexPotential t - vertexPotential (w v) - (t-w v)*neighborMass G w v := by | |
| have hs : (β u, vertexPotential (Function.update w v t u)) = | |
| β u, vertexPotential (w u) + (vertexPotential t - vertexPotential (w v)) := by | |
| rw [β add_sum_erase _ _ (mem_univ v), β add_sum_erase _ _ (mem_univ v)] | |
| simp only [Function.update_self] | |
| have h : (β u β univ.erase v, vertexPotential (Function.update w v t u)) = | |
| β u β univ.erase v, vertexPotential (w u) := by | |
| apply sum_congr rfl | |
| intro u hu | |
| rw [Function.update_of_ne (by simpa using (mem_erase.1 hu).1)] | |
| rw [h] | |
| ring | |
| unfold potential | |
| rw [hs,edgeMass_update] | |
| ring | |
| lemma optimizer_stationary {G : SimpleGraph V} {w : V β β} (hw : IsOptimizer G w) (v : V) : | |
| 0 < w v β§ Real.log (1/w v) = neighborMass G w v β§ w v β€ 1 := by | |
| classical | |
| let N := neighborMass G w v | |
| let a := Real.exp (-N) | |
| have ha : 0 < a := Real.exp_pos _ | |
| have hN : 0 β€ N := neighborMass_nonneg G hw.1 v | |
| have ha1 : a β€ 1 := Real.exp_le_one_iff.2 (by linarith) | |
| have hloga : Real.log a = -N := Real.log_exp _ | |
| have hmax := hw.2 (Function.update w v a) (fun u β¦ by | |
| by_cases h : u = v | |
| Β· subst u; simpa using ha.le | |
| Β· simpa [h] using hw.1 u) | |
| have heq := potential_update G w v a | |
| have hbound : a β€ w v * (1-Real.log (w v)-N) := by | |
| rw [vertexPotential,vertexPotential,hloga] at heq | |
| dsimp [N] at * | |
| nlinarith only [hmax,heq] | |
| have hwv : 0 < w v := by | |
| have h0 := hw.1 v | |
| by_contra hn | |
| have hz : w v = 0 := le_antisymm (le_of_not_gt hn) h0 | |
| simp only [hz,zero_mul] at hbound | |
| linarith | |
| have hwa : w v = a := by | |
| by_contra hn | |
| have hdiv : a / w v β 1 := by | |
| intro he | |
| exact hn ((div_eq_one_iff_eq hwv.ne').1 he).symm | |
| have hl := Real.log_lt_sub_one_of_pos (div_pos ha hwv) hdiv | |
| rw [Real.log_div ha.ne' hwv.ne',hloga] at hl | |
| have hh := mul_lt_mul_of_pos_left hl hwv | |
| have hid : w v * (a / w v - 1) = a-w v := by field_simp | |
| rw [hid] at hh | |
| nlinarith | |
| refine β¨hwv,?_,hwa βΈ ha1β© | |
| rw [one_div,Real.log_inv,hwa,hloga] | |
| simp [N] | |
| /-- Expansion around a stationary positive maximizer. -/ | |
| lemma optimizer_divergence {G : SimpleGraph V} {w : V β β} (hw : IsOptimizer G w) | |
| (q : V β β) (hq : β v, 0 β€ q v) : | |
| 0 β€ potential G w - potential G q β§ | |
| potential G w - potential G q = | |
| (β v, (q v * Real.log (q v / w v) - q v + w v)) + edgeMass G (q-w) := by | |
| refine β¨sub_nonneg.2 (hw.2 q hq),?_β© | |
| have hsum (v : V) : vertexPotential (w v) - vertexPotential (q v) + | |
| (q v-w v)*neighborMass G w v = q v*Real.log (q v/w v) - q v + w v := by | |
| obtain β¨hwv,hstat,_β© := optimizer_stationary hw v | |
| rw [one_div,Real.log_inv] at hstat | |
| rcases (hq v).eq_or_lt with hz | hqv | |
| Β· simp [β hz,vertexPotential,hstat.symm] | |
| ring | |
| Β· rw [Real.log_div hqv.ne' hwv.ne'] | |
| unfold vertexPotential | |
| rw [β hstat] | |
| ring | |
| have he := edgeMass_add G (q-w) w | |
| have hqw : q-w+w = q := sub_add_cancel _ _ | |
| rw [hqw,edgeForm_neighbor] at he | |
| simp only [Pi.sub_apply] at he | |
| have hs := congrArg (fun f : V β β β¦ β v, f v) (funext hsum) | |
| simp only [sum_add_distrib,sum_sub_distrib] at hs | |
| unfold potential | |
| simp only [sum_add_distrib,sum_sub_distrib] | |
| linarith | |
| end CliqueFreeIndependence.WeightedGraph | |
| end | |
| end OAI | |