File size: 12,238 Bytes
f61e547
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
import OAI.Probability.FreeIsing.Trees.ConnectedExhaustion
import OAI.Probability.FreeIsing.Trees.Parents

namespace OAI

noncomputable section

namespace Problem367

def rootComponentFinset {d : ℕ} (D : Finset (TreeVertex d)) (c : Fin d) :
    Finset (TreeVertex d) := by
  classical
  exact D.filter (fun v => [c] <+: v.1)

def rootComplementFinset {d : ℕ} (D : Finset (TreeVertex d)) (c : Fin d) :
    Finset (TreeVertex d) := by
  classical
  exact D.filter (fun v => ¬ [c] <+: v.1)

@[simp] theorem mem_rootComponentFinset {d : ℕ} {D : Finset (TreeVertex d)}
    {c : Fin d} {v : TreeVertex d} : v ∈ rootComponentFinset D c ↔
      v ∈ D ∧ [c] <+: v.1 := by
  classical
  simp [rootComponentFinset]

@[simp] theorem mem_rootComplementFinset {d : ℕ} {D : Finset (TreeVertex d)}
    {c : Fin d} {v : TreeVertex d} : v ∈ rootComplementFinset D c ↔
      v ∈ D ∧ ¬ [c] <+: v.1 := by
  classical
  simp [rootComplementFinset]

theorem ConnectedFinset.prefix_mem_of_root_mem {d : ℕ}
    {D : Finset (TreeVertex d)} (hD : ConnectedFinset D)
    (hroot : ConnectedHull.root d ∈ D) {u v : TreeVertex d}
    (hv : v ∈ D) (huv : u.1 <+: v.1) : u ∈ D :=
  hD.prefix_mem_of_min_length_le hroot (fun _ _ => Nat.zero_le _) hv huv (Nat.zero_le _)

theorem ConnectedFinset.filter_prefix_connected {d : ℕ}
    {D : Finset (TreeVertex d)} (hD : ConnectedFinset D)
    (hroot : ConnectedHull.root d ∈ D) (r : TreeVertex d) (hr : r ∈ D) :
    ConnectedFinset (D.filter (fun v => r.1 <+: v.1)) := by
  classical
  let E := D.filter (fun v => r.1 <+: v.1)
  have hrE : r ∈ E := Finset.mem_filter.mpr ⟨hr, List.prefix_refl _⟩
  let R := fun x y : TreeVertex d => x ∈ E ∧ y ∈ E ∧ treeAdj x y
  have paths : ∀ n : ℕ, ∀ v : TreeVertex d, v.1.length = n → v ∈ E →
      Relation.ReflTransGen R r v ∧ Relation.ReflTransGen R v r := by
    intro n
    induction n using Nat.strong_induction_on with
    | h n ih =>
      intro v hn hv
      by_cases heq : v = r
      · subst v
        exact ⟨.refl, .refl⟩
      have hv' := Finset.mem_filter.mp hv
      have hnil : v.1 ≠ [] := by
        intro he
        have hre : r.1 = [] := by
          have hlen : r.1.length ≤ 0 := by simpa only [he, List.length_nil] using hv'.2.length_le
          exact List.length_eq_zero_iff.mp (by omega)
        exact heq (Subtype.ext (he.trans hre.symm))
      have hadj := treeAdj_parentVertex hnil
      have hpD : parentVertex v ∈ D :=
        hD.prefix_mem_of_root_mem hroot hv'.1 (List.dropLast_prefix v.1)
      have hpE : parentVertex v ∈ E := Finset.mem_filter.mpr
        ⟨hpD, treeAdj_preserves_prefix hv'.2 hadj.symm heq⟩
      have hlt : (parentVertex v).1.length < n := by
        have hpos := List.length_pos_iff.mpr hnil
        rw [parentVertex_length]
        omega
      obtain ⟨hforward, hbackward⟩ := ih _ hlt _ rfl hpE
      exact ⟨hforward.trans (.single ⟨hpE, hv, hadj⟩),
        (Relation.ReflTransGen.single ⟨hv, hpE, hadj.symm⟩).trans hbackward⟩
  refine ⟨⟨r, hrE⟩, ?_⟩
  intro u hu v hv
  exact (paths _ u rfl hu).2.trans (paths _ v rfl hv).1

theorem ConnectedFinset.filter_not_prefix_connected {d : ℕ}
    {D : Finset (TreeVertex d)} (hD : ConnectedFinset D)
    (hroot : ConnectedHull.root d ∈ D) (r : TreeVertex d) (hr : r.1 ≠ []) :
    ConnectedFinset (D.filter (fun v => ¬ r.1 <+: v.1)) := by
  classical
  let E := D.filter (fun v => ¬ r.1 <+: v.1)
  have hrootE : ConnectedHull.root d ∈ E := by
    apply Finset.mem_filter.mpr
    exact ⟨hroot, by simpa [ConnectedHull.root] using hr⟩
  have paths (v : TreeVertex d) (hv : v ∈ E) :
      Relation.ReflTransGen
        (fun x y : TreeVertex d => x ∈ E ∧ y ∈ E ∧ treeAdj x y)
        (ConnectedHull.root d) v ∧
      Relation.ReflTransGen
        (fun x y : TreeVertex d => x ∈ E ∧ y ∈ E ∧ treeAdj x y)
        v (ConnectedHull.root d) := by
    have hp : ∀ n ≤ v.1.length, ConnectedHull.takeVertex v n ∈ E := by
      intro n hn
      apply Finset.mem_filter.mpr
      refine ⟨hD.prefix_mem_of_root_mem hroot (Finset.mem_filter.mp hv).1
        (List.take_prefix n v.1), ?_⟩
      intro hpre
      exact (Finset.mem_filter.mp hv).2 (hpre.trans (List.take_prefix n v.1))
    simpa only [ConnectedHull.prefix_length] using
      ConnectedHull.prefix_paths E v hp (Nat.le_refl v.1.length)
  refine ⟨⟨ConnectedHull.root d, hrootE⟩, ?_⟩
  intro u hu v hv
  exact (paths u hu).2.trans (paths v hv).1

theorem rootComponentFinset_connected {d : ℕ} {D : Finset (TreeVertex d)}
    (hD : ConnectedFinset D) (hroot : ConnectedHull.root d ∈ D)
    (c : Fin d) (hc : (⟨[c], List.IsChain.singleton c⟩ : TreeVertex d) ∈ D) :
    ConnectedFinset (rootComponentFinset D c) :=
  hD.filter_prefix_connected hroot ⟨[c], List.IsChain.singleton c⟩ hc

theorem rootComplementFinset_connected {d : ℕ} {D : Finset (TreeVertex d)}
    (hD : ConnectedFinset D) (hroot : ConnectedHull.root d ∈ D) (c : Fin d) :
    ConnectedFinset (rootComplementFinset D c) :=
  hD.filter_not_prefix_connected hroot ⟨[c], List.IsChain.singleton c⟩ (by simp)

theorem rootComponentFinset_union_complement {d : ℕ} (D : Finset (TreeVertex d))
    (c : Fin d) : rootComponentFinset D c ∪ rootComplementFinset D c = D := by
  classical
  ext v
  simp only [Finset.mem_union, mem_rootComponentFinset, mem_rootComplementFinset]
  tauto

theorem rootComponentFinset_disjoint_complement {d : ℕ} (D : Finset (TreeVertex d))
    (c : Fin d) : Disjoint (rootComponentFinset D c) (rootComplementFinset D c) := by
  classical
  apply Finset.disjoint_left.mpr
  intro v hv hw
  exact (mem_rootComplementFinset.mp hw).2 (mem_rootComponentFinset.mp hv).2

theorem root_component_crossing_edge {d : ℕ} {c : Fin d} {u v : TreeVertex d}
    (hu : [c] <+: u.1) (hv : ¬ [c] <+: v.1) (hadj : treeAdj u v) :
    u = ⟨[c], List.IsChain.singleton c⟩ ∧ v = ConnectedHull.root d := by
  have hueq : u = (⟨[c], List.IsChain.singleton c⟩ : TreeVertex d) := by
    by_contra hne
    exact hv (treeAdj_preserves_prefix (r := ⟨[c], List.IsChain.singleton c⟩) hu hadj hne)
  refine ⟨hueq, ?_⟩
  subst u
  rcases hadj with ⟨a, ha⟩ | ⟨a, ha⟩
  · exfalso
    apply hv
    rw [ha]
    exact List.prefix_append _ _
  · apply Subtype.ext
    change v.1 = []
    have hlen := congrArg List.length ha
    simp only [List.length_singleton, List.length_append] at hlen
    exact List.length_eq_zero_iff.mp (by omega)

theorem rootComponentFinset_mono {d : ℕ} (c : Fin d) :
    Monotone (fun D : Finset (TreeVertex d) => rootComponentFinset D c) := by
  intro D E hDE v hv
  exact mem_rootComponentFinset.mpr ⟨hDE (mem_rootComponentFinset.mp hv).1,
    (mem_rootComponentFinset.mp hv).2⟩

theorem rootComplementFinset_mono {d : ℕ} (c : Fin d) :
    Monotone (fun D : Finset (TreeVertex d) => rootComplementFinset D c) := by
  intro D E hDE v hv
  exact mem_rootComplementFinset.mpr ⟨hDE (mem_rootComplementFinset.mp hv).1,
    (mem_rootComplementFinset.mp hv).2⟩

theorem rootComponentFinset_exhausts {d : ℕ} (D : ℕ → Finset (TreeVertex d))
    (hex : ∀ v, ∃ n, v ∈ D n) (c : Fin d) (v : TreeVertex d)
    (hv : [c] <+: v.1) : ∃ n, v ∈ rootComponentFinset (D n) c := by
  obtain ⟨n, hn⟩ := hex v
  exact ⟨n, mem_rootComponentFinset.mpr ⟨hn, hv⟩⟩

theorem singleton_prefix_iff_cons {d : ℕ} (c : Fin d) (v : TreeVertex d) :
    [c] <+: v.1 ↔ ∃ w, v.1 = c :: w := by
  constructor
  · rintro ⟨w, hw⟩
    exact ⟨w, hw.symm⟩
  · rintro ⟨w, hw⟩
    exact ⟨w, hw.symm⟩

theorem rootComponentFinset_eq_filter {d : ℕ} (D : Finset (TreeVertex d)) (c : Fin d) :
    rootComponentFinset D c = (by
      classical
      exact D.filter (fun v => ∃ w, v.1 = c :: w)) := by
  classical
  ext v
  simp only [mem_rootComponentFinset, Finset.mem_filter, singleton_prefix_iff_cons]

theorem rootComplementFinset_eq_sdiff {d : ℕ} (D : Finset (TreeVertex d)) (c : Fin d) :
    rootComplementFinset D c = D \ rootComponentFinset D c := by
  classical
  ext v
  simp only [mem_rootComplementFinset, Finset.mem_sdiff, mem_rootComponentFinset]
  tauto

theorem rootComponentFinset_root_mem {d : ℕ} {D : Finset (TreeVertex d)} (c : Fin d)
    (hc : (⟨[c], List.IsChain.singleton c⟩ : TreeVertex d) ∈ D) :
    (⟨[c], List.IsChain.singleton c⟩ : TreeVertex d) ∈ rootComponentFinset D c :=
  mem_rootComponentFinset.mpr ⟨hc, List.prefix_refl _⟩

theorem rootComplementFinset_root_mem {d : ℕ} {D : Finset (TreeVertex d)} (c : Fin d)
    (hroot : ConnectedHull.root d ∈ D) :
    ConnectedHull.root d ∈ rootComplementFinset D c := by
  apply mem_rootComplementFinset.mpr
  refine ⟨hroot, ?_⟩
  intro h
  have hlen := h.length_le
  change 1 ≤ 0 at hlen
  omega

private theorem mem_inducedEdges_cut {d : ℕ} {D : Finset (TreeVertex d)}
    {u v : TreeVertex d} : (u, v) ∈ inducedEdges D ↔
      u ∈ D ∧ v ∈ D ∧ treeAdj u v ∧ u.1.length < v.1.length := by
  classical
  simp [inducedEdges, and_assoc]

theorem inducedEdges_rootComponent_split {d : ℕ} {D : Finset (TreeVertex d)}
    (hroot : ConnectedHull.root d ∈ D) (c : Fin d)
    (hc : (⟨[c], List.IsChain.singleton c⟩ : TreeVertex d) ∈ D) :
    inducedEdges D = insert (ConnectedHull.root d, ⟨[c], List.IsChain.singleton c⟩)
      (inducedEdges (rootComponentFinset D c) ∪ inducedEdges (rootComplementFinset D c)) := by
  classical
  ext ⟨u, v⟩
  constructor
  · intro he
    obtain ⟨hu, hv, hadj, hlen⟩ := mem_inducedEdges_cut.mp he
    by_cases hcu : [c] <+: u.1
    · by_cases hcv : [c] <+: v.1
      · apply Finset.mem_insert_of_mem
        apply Finset.mem_union.mpr
        exact Or.inl (mem_inducedEdges_cut.mpr
          ⟨mem_rootComponentFinset.mpr ⟨hu, hcu⟩,
            mem_rootComponentFinset.mpr ⟨hv, hcv⟩, hadj, hlen⟩)
      · obtain ⟨rfl, rfl⟩ := root_component_crossing_edge hcu hcv hadj
        change 1 < 0 at hlen
        omega
    · by_cases hcv : [c] <+: v.1
      · obtain ⟨rfl, rfl⟩ := root_component_crossing_edge hcv hcu hadj.symm
        exact Finset.mem_insert_self _ _
      · apply Finset.mem_insert_of_mem
        apply Finset.mem_union.mpr
        exact Or.inr (mem_inducedEdges_cut.mpr
          ⟨mem_rootComplementFinset.mpr ⟨hu, hcu⟩,
            mem_rootComplementFinset.mpr ⟨hv, hcv⟩, hadj, hlen⟩)
  · intro he
    rcases Finset.mem_insert.mp he with heq | he
    · have hu : u = ConnectedHull.root d := congrArg Prod.fst heq
      have hv : v = (⟨[c], List.IsChain.singleton c⟩ : TreeVertex d) := congrArg Prod.snd heq
      subst u
      subst v
      exact mem_inducedEdges_cut.mpr ⟨hroot, hc, Or.inl ⟨c, rfl⟩, by change 0 < 1; omega⟩
    · rcases Finset.mem_union.mp he with he | he
      · obtain ⟨hu, hv, hadj, hlen⟩ := mem_inducedEdges_cut.mp he
        exact mem_inducedEdges_cut.mpr ⟨(mem_rootComponentFinset.mp hu).1,
          (mem_rootComponentFinset.mp hv).1, hadj, hlen⟩
      · obtain ⟨hu, hv, hadj, hlen⟩ := mem_inducedEdges_cut.mp he
        exact mem_inducedEdges_cut.mpr ⟨(mem_rootComplementFinset.mp hu).1,
          (mem_rootComplementFinset.mp hv).1, hadj, hlen⟩

theorem inducedEdges_rootComponent_disjoint {d : ℕ} (D : Finset (TreeVertex d))
    (c : Fin d) : Disjoint (inducedEdges (rootComponentFinset D c))
      (inducedEdges (rootComplementFinset D c)) := by
  classical
  apply Finset.disjoint_left.mpr
  rintro ⟨u, v⟩ hu hv
  exact (mem_rootComplementFinset.mp (mem_inducedEdges_cut.mp hv).1).2
    (mem_rootComponentFinset.mp (mem_inducedEdges_cut.mp hu).1).2

theorem root_bridge_not_mem_inducedEdges_cut {d : ℕ} (D : Finset (TreeVertex d))
    (c : Fin d) : (ConnectedHull.root d, (⟨[c], List.IsChain.singleton c⟩ : TreeVertex d)) ∉
      inducedEdges (rootComponentFinset D c) ∪ inducedEdges (rootComplementFinset D c) := by
  classical
  intro he
  rcases Finset.mem_union.mp he with he | he
  · have h := (mem_rootComponentFinset.mp (mem_inducedEdges_cut.mp he).1).2.length_le
    change 1 ≤ 0 at h
    omega
  · exact (mem_rootComplementFinset.mp (mem_inducedEdges_cut.mp he).2.1).2
      (List.prefix_refl _)

end Problem367

end

end OAI