File size: 8,968 Bytes
d5b7741
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import Mathlib.Combinatorics.SimpleGraph.Acyclic
import Mathlib.Combinatorics.SimpleGraph.Finite
import Mathlib.Combinatorics.SimpleGraph.Operations
import Mathlib.Data.Finset.Max
import Lean.Elab.Tactic.Omega

namespace OAI

/-!
# The companion's maximum-capacity forest

Among finite acyclic subgraphs choose one of maximum total capacity.
Positive capacities make it spanning in each large-cell component. A
free edge can replace every tree edge on its path; optimality therefore
gives the exact path-capacity inequality used in the forest estimates.
-/

namespace ContingencyTables.MaximumForest

open scoped BigOperators Classical
open SimpleGraph

variable {V : Type*} [Fintype V]

noncomputable def weight (G : SimpleGraph V) (b : Sym2 V → ℕ) : ℕ :=
  ∑ e ∈ G.edgeFinset, b e

lemma weight_eq (G : SimpleGraph V) (b : Sym2 V → ℕ) [Fintype G.edgeSet] :
    weight G b=∑ e∈G.edgeFinset,b e := by
  unfold weight
  apply Finset.sum_congr
  · ext e
    simp only [mem_edgeFinset]
  · intro e _
    rfl

theorem exists_maximum (G : SimpleGraph V) (b : Sym2 V → ℕ) :
    ∃ T : SimpleGraph V, T ≤ G ∧ T.IsAcyclic ∧
      ∀ F : SimpleGraph V, F ≤ G → F.IsAcyclic → weight F b ≤ weight T b := by
  let S : Finset (SimpleGraph V) := Finset.univ.filter (fun F => F ≤ G ∧ F.IsAcyclic)
  have hS : S.Nonempty := ⟨⊥,by simp [S]⟩
  obtain ⟨T,hT,hmax⟩ := Finset.exists_max_image S (fun F => weight F b) hS
  have hp := (Finset.mem_filter.mp hT).2
  refine ⟨T,hp.1,hp.2,?_⟩
  intro F hFG hacyc
  exact hmax F (by simp [S,hFG,hacyc])

lemma weight_sup_edge (T : SimpleGraph V) (b : Sym2 V → ℕ) (u v : V)
    (hn : ¬T.Adj u v) (hne : u≠v) :
    weight (T ⊔ edge u v) b=b s(u,v)+weight T b := by
  rw [weight_eq (T ⊔ edge u v),weight_eq T,T.edgeFinset_sup_edge hn hne,Finset.sum_cons]

omit [Fintype V] in
/-- Deleting an edge of the unique tree path separates its endpoints. -/
lemma not_reachable_delete_path_edge (T : SimpleGraph V) (hT : T.IsAcyclic)
    {u v : V} (p : T.Walk u v) (hp : p.IsPath) (t : Sym2 V) (ht : t∈p.edges) :
    ¬(T.deleteEdges {t}).Reachable u v := by
  intro hreach
  obtain ⟨q,hq⟩ := hreach.exists_isPath
  have he : p=q.mapLe (T.deleteEdges_le {t}) := congrArg Subtype.val
    ((hT.subsingleton_path u v).elim ⟨p,hp⟩ ⟨q.mapLe (T.deleteEdges_le {t}),hq.mapLe _⟩)
  rw [he] at ht
  simp only [Walk.edges_map,Hom.coe_ofLE,Sym2.map_id,List.map_id_fun,id_eq] at ht
  have hmem := q.edges_subset_edgeSet ht
  rw [edgeSet_deleteEdges] at hmem
  exact hmem.2 (by simp)

/-- This is the source's actual maximum-forest path inequality. -/
theorem free_edge_le_path_edge (G T : SimpleGraph V) (b : Sym2 V → ℕ)
    (hTG : T ≤ G) (hT : T.IsAcyclic)
    (hmax : ∀ F : SimpleGraph V, F ≤ G → F.IsAcyclic → weight F b ≤ weight T b)
    {u v : V} (hG : G.Adj u v) (hfree : ¬T.Adj u v)
    (p : T.Walk u v) (hp : p.IsPath) (t : Sym2 V) (ht : t∈p.edges) :
    b s(u,v) ≤ b t := by
  let D := T.deleteEdges {t}
  have hDT : D ≤ T := T.deleteEdges_le {t}
  have hDfree : ¬D.Adj u v := fun h => hfree (hDT h)
  have hcut : ¬D.Reachable u v := not_reachable_delete_path_edge T hT p hp t ht
  have hnew : (D ⊔ edge u v).IsAcyclic := (hT.anti hDT).sup_edge_of_not_reachable hcut
  have hnewG : D ⊔ edge u v ≤ G := sup_le (hDT.trans hTG) ((G.edge_le_iff).mpr (Or.inr hG))
  have hopt := hmax (D ⊔ edge u v) hnewG hnew
  have hsum := weight_sup_edge D b u v hDfree hG.ne
  have hmem : t∈T.edgeFinset := by simpa using p.edges_subset_edgeSet ht
  have hdelete : D.edgeFinset=T.edgeFinset.erase t := by
    ext e
    simp [D,edgeSet_deleteEdges,and_comm]
  have hsumDelete : weight D b+b t=weight T b := by
    rw [weight_eq D,weight_eq T,hdelete]
    exact Finset.sum_erase_add (s := T.edgeFinset) (a := t) b hmem
  omega

/-- The same exchange argument applies directly to a separating cut;
this avoids choosing a path when using the forest's component cuts. -/
theorem free_edge_le_separating_edge (G T : SimpleGraph V) (b : Sym2 V → ℕ)
    (hTG : T ≤ G) (hT : T.IsAcyclic)
    (hmax : ∀ F : SimpleGraph V, F ≤ G → F.IsAcyclic → weight F b ≤ weight T b)
    (t : Sym2 V) (ht : t∈T.edgeSet) {u v : V}
    (hG : G.Adj u v) (hfree : ¬T.Adj u v)
    (hcut : ¬(T.deleteEdges {t}).Reachable u v) : b s(u,v) ≤ b t := by
  let D := T.deleteEdges {t}
  have hDT : D ≤ T := T.deleteEdges_le {t}
  have hDfree : ¬D.Adj u v := fun h => hfree (hDT h)
  have hnew : (D ⊔ edge u v).IsAcyclic := (hT.anti hDT).sup_edge_of_not_reachable hcut
  have hnewG : D ⊔ edge u v ≤ G := sup_le (hDT.trans hTG) ((G.edge_le_iff).mpr (Or.inr hG))
  have hopt := hmax (D ⊔ edge u v) hnewG hnew
  have hsum := weight_sup_edge D b u v hDfree hG.ne
  have hmem : t∈T.edgeFinset := by simpa using ht
  have hdelete : D.edgeFinset=T.edgeFinset.erase t := by
    ext e
    simp [D,edgeSet_deleteEdges,and_comm]
  have hsumDelete : weight D b+b t=weight T b := by
    rw [weight_eq D,weight_eq T,hdelete]
    exact Finset.sum_erase_add (s := T.edgeFinset) (a := t) b hmem
  omega

omit [Fintype V] in
noncomputable def side (D : SimpleGraph V) (u v : V) : Bool := decide (D.Reachable u v)

omit [Fintype V] in
lemma side_self (D : SimpleGraph V) (u : V) : side D u u=true := by
  simp [side]

omit [Fintype V] in
lemma side_eq_of_reachable (D : SimpleGraph V) (u : V) {v w : V}
    (h : D.Reachable v w) : side D u v=side D u w := by
  apply Bool.eq_iff_iff.mpr
  simp only [side,decide_eq_true_eq]
  exact ⟨fun hv => hv.trans h,fun hw => hw.trans h.symm⟩

omit [Fintype V] in
lemma not_reachable_of_side_ne (D : SimpleGraph V) (u : V) {v w : V}
    (h : side D u v≠side D u w) : ¬D.Reachable v w := by
  exact fun hr => h (side_eq_of_reachable D u hr)

omit [Fintype V] in
/-- Every other tree edge is internal to a deletion component. -/
lemma side_eq_of_tree_edge (T : SimpleGraph V) (t : Sym2 V) (u : V) {v w : V}
    (h : T.Adj v w) (hne : s(v,w)≠t) :
    side (T.deleteEdges {t}) u v=side (T.deleteEdges {t}) u w := by
  apply side_eq_of_reachable
  exact (show (T.deleteEdges {t}).Adj v w by simp [h,hne]).reachable

omit [Fintype V] in
/-- One deletion component contains an endpoint of the removed edge
and avoids the chosen root. This also works for isolated components. -/
lemma exists_root_avoiding_side (T : SimpleGraph V) (hT : T.IsAcyclic)
    {u v : V} (ht : T.Adj u v) (root : V) (hroot : T.Reachable root u) :
    ∃ r : V, T.Reachable root r ∧ side (T.deleteEdges {s(u,v)}) r root=false ∧
      side (T.deleteEdges {s(u,v)}) r u≠side (T.deleteEdges {s(u,v)}) r v := by
  let D := T.deleteEdges {s(u,v)}
  have hsep : ¬D.Reachable u v :=
    isBridge_iff.mp (isAcyclic_iff_forall_adj_isBridge.mp hT ht)
  by_cases hru : D.Reachable u root
  · refine ⟨v,hroot.trans ht.reachable,?_,?_⟩
    · have hn : ¬D.Reachable v root := fun h => hsep (hru.trans h.symm)
      simpa only [side,decide_eq_false_iff_not] using hn
    · have hn : ¬D.Reachable v u := fun h => hsep h.symm
      change side D v u≠side D v v
      simp [side,hn]
  · refine ⟨u,hroot,?_,?_⟩
    · simpa only [side,decide_eq_false_iff_not] using hru
    · change side D u u≠side D u v
      simp [side,hsep]

/-- Capacities of actual free edges crossing a deletion component are
bounded by the capacity of its unique deleted tree edge. -/
theorem crossing_free_edge_le (G T : SimpleGraph V) (b : Sym2 V → ℕ)
    (hTG : T ≤ G) (hT : T.IsAcyclic)
    (hmax : ∀ F : SimpleGraph V, F ≤ G → F.IsAcyclic → weight F b ≤ weight T b)
    (t : Sym2 V) (ht : t∈T.edgeSet) (r : V) {u v : V}
    (hG : G.Adj u v) (hfree : ¬T.Adj u v)
    (hcross : side (T.deleteEdges {t}) r u≠side (T.deleteEdges {t}) r v) :
    b s(u,v) ≤ b t :=
  free_edge_le_separating_edge G T b hTG hT hmax t ht hG hfree
    (not_reachable_of_side_ne _ r hcross)

/-- Positive capacities force the maximizing acyclic subgraph to span
every original connected component, including isolated vertices. -/
theorem maximum_spans (G T : SimpleGraph V) (b : Sym2 V → ℕ)
    (hTG : T ≤ G) (hT : T.IsAcyclic)
    (hmax : ∀ F : SimpleGraph V, F ≤ G → F.IsAcyclic → weight F b ≤ weight T b)
    (hb : ∀ e∈G.edgeSet, 0 < b e) : T.Reachable=G.Reachable := by
  have hadj : ∀ u v, G.Adj u v → T.Reachable u v := by
    intro u v hG
    by_contra hnreach
    have hn : ¬T.Adj u v := fun h => hnreach h.reachable
    have hnew := hT.sup_edge_of_not_reachable hnreach
    have hle : T ⊔ edge u v ≤ G := sup_le hTG ((G.edge_le_iff).mpr (Or.inr hG))
    have hopt := hmax (T ⊔ edge u v) hle hnew
    have hsum := weight_sup_edge T b u v hn hG.ne
    have hpos := hb s(u,v) (by simpa using hG)
    omega
  funext u v
  apply propext
  constructor
  · intro h; exact h.mono hTG
  · rintro ⟨p⟩
    induction p with
    | nil => exact ⟨Walk.nil⟩
    | cons h p ih => exact (hadj _ _ h).trans ih

end ContingencyTables.MaximumForest

end OAI