import OAI.Combinatorics.MatchingEntropy.Polytope namespace OAI noncomputable section open scoped BigOperators Topology open Filter universe uV uE uI uJ uA uB uC uW uF uD uι namespace MatchingEntropyBounds.LooplessGraph variable {V : Type uV} {E : Type uE} [Fintype V] [Fintype E] [DecidableEq V] [DecidableEq E] def positiveExtension (x : E → ℝ) : ({e // 0 if h : 0 simp [h] map_smul' := by intro a u; ext e; by_cases h : 0 simp [h] } omit [Fintype E] [DecidableEq E] in @[simp] theorem positiveExtension_pos (x : E → ℝ) (u : {e // 0 simp def cutLinear (G : LooplessGraph V E) (S : Finset V) : (E → ℝ) →ₗ[ℝ] ℝ where toFun := fun u => G.cutMass u S map_add' := by intro u v; simpa using G.cutMass_linear u v 1 1 S map_smul' := by intro a u; simp [cutMass,Finset.mul_sum] def faceSpace (G : LooplessGraph V E) (x : E → ℝ) : Submodule ℝ ({e // 0 positiveExtension_zero x u he) (congrFun hu.1) hu.2 omit [Fintype V] [DecidableEq E] in theorem faceSpace_of_eventually_line (G : LooplessGraph V E) {x : E → ℝ} (hx : x ∈ G.constraintPolytope) {u : {e // 0 -t) (𝓝 0) (𝓝 0) := by simpa using continuous_neg.tendsto (0:ℝ) exact hc.eventually hu have hh : ∀ᶠ t : ℝ in 𝓝[>] 0, (x+t • positiveExtension x u ∈ G.constraintPolytope ∧ x+(-t) • positiveExtension x u ∈ G.constraintPolytope) ∧ 0 x e.val def sideRestriction (G : LooplessGraph V E) (x : E → ℝ) (S : Finset V) : ({e // 0 u ⟨e.val.val,e.property⟩ map_add' := by intros; rfl map_smul' := by intros; rfl omit [Fintype V] [Fintype E] [DecidableEq V] [DecidableEq E] in theorem positiveExtension_side (G : LooplessGraph V E) (x : E → ℝ) (S : Finset V) (u : {e // 0 G.faceSpace_of_side_spaces heven hx S hS ht) theorem faceCodimension_strong_aux (n : ℕ) : ∀ {W : Type uW} {F : Type uF} [Fintype W] [Fintype F] [DecidableEq W] [DecidableEq F] (G : LooplessGraph W F), Fintype.card W=n → Even n → 4≤n → ∀ x ∈ G.constraintPolytope, G.faceCodimension x ≤ 2*(n-2) := by induction n using Nat.strong_induction_on with | h n ih => intro W F _ _ _ _ G hcard heven hfour x hx have heven' : Even (Fintype.card W) := hcard ▸ heven by_cases hcut : ∃ S : Finset W, Odd S.card ∧ 3≤S.card ∧ 3≤Sᶜ.card ∧ G.cutMass x S=1 · obtain ⟨S,hS,hlo,hhi,ht⟩ := hcut have hc := odd_compl_of_even heven' hS have hlt1 : Fintype.card (Option {v // v ∈ S}) < n := by simp only [Fintype.card_option,Fintype.card_coe] have hco := Finset.card_compl S omega have hlt2 : Fintype.card (Option {v // v ∈ Sᶜ}) < n := by simp only [Fintype.card_option,Fintype.card_coe] have hco := Finset.card_compl S have hle := Finset.card_le_univ S omega have hv1 : Even (Fintype.card (Option {v // v ∈ S})) := by simpa only [Fintype.card_option,Fintype.card_coe] using hS.add_odd odd_one have hv2 : Even (Fintype.card (Option {v // v ∈ Sᶜ})) := by simpa only [Fintype.card_option,Fintype.card_coe] using hc.add_odd odd_one have hn1 : 4≤Fintype.card (Option {v // v ∈ S}) := by simp only [Fintype.card_option,Fintype.card_coe]; omega have hn2 : 4≤Fintype.card (Option {v // v ∈ Sᶜ}) := by simp only [Fintype.card_option,Fintype.card_coe]; omega have hx1 := G.restriction_mem_constraints hx S hS ht have htc : G.cutMass x Sᶜ=1 := by simpa only [cutMass,cut_compl] using ht have hx2 := G.restriction_mem_constraints hx Sᶜ hc htc have hb1 := ih _ hlt1 (G.onSide S) rfl hv1 hn1 _ hx1 have hb2 := ih _ hlt2 (G.onSide Sᶜ) rfl hv2 hn2 _ hx2 have hb := G.faceCodimension_le_sides heven' hx S hS ht have hsum : Fintype.card (Option {v // v ∈ S}) + Fintype.card (Option {v // v ∈ Sᶜ})=n+2 := by simp only [Fintype.card_option,Fintype.card_coe] have hh := Finset.card_compl_add_card S omega change (G.onSide S).faceCodimension (G.sideMarginal x S) ≤ _ at hb1 change (G.onSide Sᶜ).faceCodimension (G.sideMarginal x Sᶜ) ≤ _ at hb2 omega · have hb := G.faceCodimension_no_tight heven' hcut omega theorem faceCodimension_bound (G : LooplessGraph V E) {x : E → ℝ} (heven : Even (Fintype.card V)) (hx : x ∈ G.polytope) : G.faceCodimension x ≤ 2*Fintype.card V := by by_cases hn : 4≤Fintype.card V · have hb := faceCodimension_strong_aux (Fintype.card V) G rfl heven hn x (G.polytope_subset_constraintPolytope hx) omega · have hnt : ¬ ∃ S : Finset V, Odd S.card ∧ 3≤S.card ∧ 3≤Sᶜ.card ∧ G.cutMass x S=1 := by rintro ⟨S,_,hlo,hhi,_⟩ have hh := Finset.card_compl_add_card S omega have hb := G.faceCodimension_no_tight heven hnt omega omit [Fintype V] [DecidableEq E] in theorem degree_add_smul (G : LooplessGraph V E) (x u : E → ℝ) (t : ℝ) (v : V) : G.degree (x+t • u) v=G.degree x v+t*G.degree u v := by simpa using G.degree_linear x u 1 t v omit [Fintype V] [DecidableEq E] in theorem cutMass_add_smul (G : LooplessGraph V E) (x u : E → ℝ) (t : ℝ) (S : Finset V) : G.cutMass (x+t • u) S=G.cutMass x S+t*G.cutMass u S := by simpa using G.cutMass_linear x u 1 t S omit [DecidableEq E] in theorem constraint_eventually_expand (G : LooplessGraph V E) {x : E → ℝ} (hx : x ∈ G.constraintPolytope) {t : ℝ} (ht : 0 (x+t⁻¹ • (y-x)) e) := by fun_prop have hh : ∀ᶠ y : E → ℝ in 𝓝 x, 0<(x+t⁻¹ • (y-x)) e := (isOpen_lt continuous_const hc).mem_nhds (by simpa using hp) exact (hh.filter_mono nhdsWithin_le_nhds).mono fun y hy => hy.le have hodd : ∀ᶠ y in 𝓝[G.constraintPolytope] x, ∀ S : Finset V, Odd S.card → 1≤G.cutMass (x+t⁻¹ • (y-x)) S := by apply Filter.eventually_all.mpr intro S by_cases hS : Odd S.card · by_cases hs : G.cutMass x S=1 · filter_upwards [eventually_mem_nhdsWithin] with y hy _ rw [cutMass_add_smul,cutMass_sub,hs] have hh := mul_nonneg (inv_nonneg.mpr ht.le) (sub_nonneg.mpr (hy.2.2 S hS)) linarith · have hp : 1 G.cutMass (x+t⁻¹ • (y-x)) S) := (G.continuous_cutMass S).comp (by fun_prop) have hh : ∀ᶠ y : E → ℝ in 𝓝 x, 1 hy.le · exact Filter.Eventually.of_forall fun _ h => (hS h).elim filter_upwards [hn,hodd,eventually_mem_nhdsWithin] with y hn hodd hy refine ⟨hn,?_,hodd⟩ intro v rw [degree_add_smul,degree_sub,hx.2.1,hy.2.1] ring theorem polytope_eventually_expand (G : LooplessGraph V E) {x : E → ℝ} (heven : Even (Fintype.card V)) (hx : x ∈ G.polytope) {t : ℝ} (ht : 0