File size: 17,064 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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
import OAI.Probability.FKMaps.GraphWedge
import OAI.Probability.FKMaps.WordMaps

namespace OAI

noncomputable section
open List Equiv Equiv.Perm
namespace FKCRT.Inventory
variable {N : ℕ}

def liveAt (a : Perm (Fin N)) (k : ℕ) : List (Fin N) :=
  ((List.finRange N).filter (fun x => decide (x.val<k ∧ k≤(a x).val))).reverse

lemma mem_liveAt (a : Perm (Fin N)) (k : ℕ) (x : Fin N) :
    x∈liveAt a k ↔ x.val<k ∧ k≤(a x).val := by simp [liveAt]

lemma liveAt_sorted (a : Perm (Fin N)) (k : ℕ) : (liveAt a k).Pairwise (·>·) := by
  exact ((List.pairwise_lt_finRange N).filter _).reverse

lemma liveAt_zero (a : Perm (Fin N)) : liveAt a 0=[] := by simp [liveAt]
lemma liveAt_end (a : Perm (Fin N)) : liveAt a N=[] := by
  apply List.eq_nil_iff_forall_not_mem.mpr
  intro x hx
  have := (mem_liveAt a N x).mp hx
  omega

lemma liveAt_open (a : Perm (Fin N)) (ha : Function.Involutive a) (i : Fin N)
    (hi : i < a i) : liveAt a (i.val+1)=i::liveAt a i.val := by
  have hs : (i::liveAt a i.val).Pairwise (·>·) :=
    List.pairwise_cons.mpr ⟨fun x hx => (mem_liveAt a i.val x).mp hx |>.1,liveAt_sorted a _⟩
  apply List.Pairwise.eq_of_mem_iff (liveAt_sorted a _) hs
  intro x
  rw [mem_liveAt,List.mem_cons,mem_liveAt]
  have hx : a x=i → x=a i := fun h => by rw [← h,ha]
  constructor
  · rintro ⟨h1,h2⟩
    by_cases hxi : x=i
    · exact Or.inl hxi
    · exact Or.inr ⟨by have := Fin.val_ne_of_ne hxi; omega,by omega⟩
  · rintro (rfl|⟨h1,h2⟩)
    · exact ⟨by omega,hi⟩
    · refine ⟨by omega,?_⟩
      by_contra hh
      have he : a x=i := Fin.ext (by omega)
      have he' := hx he
      subst x
      have hi' : i.val<(a i).val := hi
      omega

lemma liveAt_close (a : Perm (Fin N)) (ha : Function.Involutive a) (i : Fin N)
    (hi : a i < i) : liveAt a (i.val+1)=(liveAt a i.val).erase (a i) := by
  apply List.Pairwise.eq_of_mem_iff (liveAt_sorted a _) ((liveAt_sorted a _).sublist List.erase_sublist)
  intro x
  rw [mem_liveAt,(liveAt_sorted a _).nodup.mem_erase_iff,mem_liveAt]
  have hx : x=a i ↔ a x=i := by
    constructor
    · intro h; rw [h,ha]
    · intro h; rw [← h,ha]
  have hi' : (a i).val < i.val := hi
  constructor
  · rintro ⟨h1,h2⟩
    refine ⟨?_,?_,by omega⟩
    · intro he; have := hx.mp he; subst x; rw [ha] at h2; omega
    · by_contra h
      have he : x=i := Fin.ext (by omega)
      subst x
      omega
  · rintro ⟨h1,h2,h3⟩
    refine ⟨by omega,?_⟩
    by_contra h
    have he : a x=i := Fin.ext (by omega)
    exact h1 (hx.mpr he)

lemma liveAt_mate (a : Perm (Fin N)) (ha : Function.Involutive a) (i : Fin N)
    (hi : a i < i) : a i∈liveAt a i.val := by rw [mem_liveAt,ha]; exact ⟨hi,le_rfl⟩

lemma pop_map_erase {α : Type*} [DecidableEq α] (c : α→Bool) (s : List α) (x : α)
    (hx : x∈s) (hfirst : ∀ t u,s=t++x::u → ∀ y∈t,c y≠c x) :
    pop (some (c x)) (s.map c)=some ((s.erase x).map c) := by
  induction s with
  | nil => simp at hx
  | cons y s ih =>
    by_cases hy : y=x
    · subst y; simp [pop,eligible]
    · have hxs : x∈s := List.mem_of_ne_of_mem (Ne.symm hy) hx
      obtain ⟨t,u,htu⟩ := List.mem_iff_append.mp hxs
      have hcy := hfirst (y::t) u (by rw [htu]; rfl) y (by simp)
      have hh := ih hxs (by
        intro t u he z hz
        exact hfirst (y::t) u (by rw [he]; rfl) z (List.mem_cons_of_mem y hz))
      simp [pop,eligible,Ne.symm hcy,hy,hh]

/-- For noncrossing same-colour arcs, the literal typed stack is the list of
live openers in reverse chronological order. No choice of a stack matching
is assumed. -/
lemma matching_step_live (a : Perm (Fin N)) (ha : Function.Involutive a)
    (hf : ∀ x,a x≠x) (c : Fin N→Bool) (hc : ∀ x,c (a x)=c x)
    (hn : ∀ x y,c x=c y → x < y → y < a x → a x < a y → False) (i : Fin N) :
    stackTypedStep ((liveAt a i.val).map c)
      (if i < a i then .burger (c i) else .order (c i))=
        some ((liveAt a (i.val+1)).map c) := by
  by_cases hi : i < a i
  · rw [ite_eq_left hi,liveAt_open a ha i hi]
    rfl
  · have hlt : a i < i := lt_of_le_of_ne (le_of_not_gt hi) (hf i)
    rw [ite_eq_right hi,stackTypedStep,liveAt_close a ha i hlt,← hc i]
    apply pop_map_erase c _ _ (liveAt_mate a ha i hlt)
    intro t u he y hy hcy
    have hs := liveAt_sorted a i.val
    rw [he,List.pairwise_append] at hs
    have hiy : a i<y := hs.2.2 y hy (a i) (by simp)
    have hym : y∈liveAt a i.val := he ▸ List.mem_append_left _ hy
    obtain ⟨hy1,hy2⟩ := (mem_liveAt a i.val y).mp hym
    have hneq : a y≠i := fun hh => (ne_of_lt hiy) (by rw [← hh,ha])
    have hy3 : i < a y := by have := Fin.val_ne_of_ne hneq; change (i : ℕ)<(a y : ℕ); omega
    exact hn (a i) y hcy.symm hiy (by rwa [ha]) (by rwa [ha])

end FKCRT.Inventory
end


noncomputable section
open List Equiv Equiv.Perm
namespace FKCRT.Inventory
variable {N : ℕ}

lemma liveAt_first_colour (a : Perm (Fin N)) (ha : Function.Involutive a)
    (c : Fin N→Bool)
    (hn : ∀ x y,c x=c y → x < y → y < a x → a x < a y → False)
    (i : Fin N) (_hi : a i < i) :
    ∀ t u,liveAt a i.val=t++a i::u → ∀ y∈t,c y≠c (a i) := by
  intro t u he y hy hcy
  have hs := liveAt_sorted a i.val
  rw [he,List.pairwise_append] at hs
  have hiy : a i < y := hs.2.2 y hy (a i) (by simp)
  have hym : y∈liveAt a i.val := he ▸ List.mem_append_left _ hy
  obtain ⟨hy1,hy2⟩ := (mem_liveAt a i.val y).mp hym
  have hneq : a y≠i := fun hh => (ne_of_lt hiy) (by rw [← hh,ha])
  have hy3 : i < a y := by have := Fin.val_ne_of_ne hneq; change (i : ℕ)<(a y : ℕ); omega
  exact hn (a i) y hcy.symm hiy (by rwa [ha]) (by rwa [ha])

lemma head_map_eq_of_first {α : Type*} (c : α→Bool) (s : List α) (x : α)
    (hx : x∈s) (hfirst : ∀ t u,s=t++x::u → ∀ y∈t,c y≠c x) :
    (s.map c).head?=some (c x) ↔ s.head?=some x := by
  obtain ⟨t,u,rfl⟩ := List.mem_iff_append.mp hx
  cases t with
  | nil => simp
  | cons y t =>
    have hh := hfirst (y::t) u rfl y (by simp)
    have hy : y≠x := fun he => hh (congrArg c he)
    simp [hh,hy]

lemma head_eq_iff_greatest {α : Type*} [LinearOrder α] (s : List α)
    (hs : s.Pairwise (·>·)) (x : α) (hx : x∈s) :
    s.head?=some x ↔ ∀ y∈s,y≤x := by
  cases s with
  | nil => simp at hx
  | cons z s =>
    simp only [List.head?_cons,Option.some.injEq]
    constructor
    · rintro rfl y hy
      rcases List.mem_cons.mp hy with rfl|hy
      · exact le_rfl
      · exact ((List.pairwise_cons.mp hs).1 y hy).le
    · intro hh
      have hz := hh z (by simp)
      rcases List.mem_cons.mp hx with rfl|hx
      · rfl
      · exact False.elim (not_lt_of_ge hz ((List.pairwise_cons.mp hs).1 x hx))

/-- The source's flexible-mark obstruction, with the strict first-occurrence
order and both closing endpoints retained exactly. -/
theorem flexibleClosing_iff_no_later_cross (a : Perm (Fin N)) (ha : Function.Involutive a)
    (c : Fin N→Bool) (hc : ∀ x,c (a x)=c x)
    (hn : ∀ x y,c x=c y → x < y → y < a x → a x < a y → False)
    (i : Fin N) (hi : a i < i) :
    flexibleClosing ((liveAt a i.val).map c) (.order (c i)) ↔
      ¬∃ j : Fin N,a i < j ∧ j < i ∧ i < a j := by
  change (List.map c (liveAt a i.val)).head?=some (c i) ↔ _
  rw [← hc i,head_map_eq_of_first c _ _ (liveAt_mate a ha i hi)
    (liveAt_first_colour a ha c hn i hi),
    head_eq_iff_greatest _ (liveAt_sorted a _) _ (liveAt_mate a ha i hi)]
  constructor
  · intro hh ⟨j,h1,h2,h3⟩
    exact not_lt_of_ge (hh j ((mem_liveAt a _ j).mpr ⟨h2,h3.le⟩)) h1
  · intro hh j hj
    by_contra h
    obtain ⟨h2,h3⟩ := (mem_liveAt a _ j).mp hj
    have h1 : a i < j := lt_of_not_ge h
    have hne : a j≠i := fun he => (ne_of_lt h1) (by rw [← he,ha])
    have h4 : i < a j := by have := Fin.val_ne_of_ne hne; change i.val<(a j).val; omega
    exact hh ⟨j,h1,h2,h4⟩

end FKCRT.Inventory
end


noncomputable section
open List Equiv Equiv.Perm
open scoped BigOperators
namespace FKCRT.Inventory
attribute [local instance] Classical.propDecidable

lemma flexibleCount_ofFn {N : ℕ} (w : Fin N→TypedLetter) (S : Fin (N+1)→List Bool)
    (hs : ∀ i,stackTypedStep (S i.castSucc) (w i)=some (S i.succ)) :
    flexibleCount (List.ofFn w) (S 0)=
      ∑ i,if flexibleClosing (S i.castSucc) (w i) then 1 else 0 := by
  induction N with
  | zero => simp [flexibleCount]
  | succ N ih =>
    have h0 := hs 0
    simp only [Fin.castSucc_zero] at h0
    rw [List.ofFn_succ,flexibleCount,h0,Fin.sum_univ_succ]
    simp only [Fin.castSucc_zero]
    congr 1
    exact ih (fun i => w i.succ) (fun i => S i.succ) (fun i => hs i.succ)

/-- The complete flexible exponent of the actual identified word is the
number of its matched pairs with no later-first crossing edge. -/
theorem matching_flexibleCount {N : ℕ} (a : Perm (Fin N)) (ha : Function.Involutive a)
    (hf : ∀ x,a x≠x) (c : Fin N→Bool) (hc : ∀ x,c (a x)=c x)
    (hn : ∀ x y,c x=c y → x < y → y < a x → a x < a y → False) :
    flexibleCount (List.ofFn (fun i => if i<a i then .burger (c i) else .order (c i))) []=
      ∑ i : Fin N,if a i < i ∧ ¬∃ j : Fin N,a i < j ∧ j < i ∧ i < a j then 1 else 0 := by
  let w : Fin N→TypedLetter := fun i => if i<a i then .burger (c i) else .order (c i)
  let S : Fin (N+1)→List Bool := fun i => (liveAt a i.val).map c
  have hs : ∀ i,stackTypedStep (S i.castSucc) (w i)=some (S i.succ) :=
    matching_step_live a ha hf c hc hn
  have hS : S 0=[] := by simp [S,liveAt_zero]
  rw [← hS,flexibleCount_ofFn w S hs]
  apply Finset.sum_congr rfl
  intro i _
  by_cases hi : i<a i
  · have hn' : ¬a i < i := not_lt_of_ge hi.le
    simp [w,hi,flexibleClosing,hn']
  · have hlt : a i < i := lt_of_le_of_ne (le_of_not_gt hi) (hf i)
    have hh := flexibleClosing_iff_no_later_cross a ha c hc hn i hlt
    change (if flexibleClosing ((liveAt a i.val).map c)
      (if i<a i then .burger (c i) else .order (c i)) then 1 else 0)=_
    simp only [ite_eq_right hi,hh,hlt,true_and]

end FKCRT.Inventory
end


noncomputable section
open List Equiv Equiv.Perm
attribute [local instance] Classical.propDecidable
namespace FKCRT.Chords
variable {N : ℕ}

lemma componentDarts_mate (a : Perm (Fin N)) (ha : Function.Involutive a)
    (r : Opener a) (d : Fin N) :
    a d∈componentDarts a r ↔ d∈componentDarts a r := by
  have hd (i : Fin N) : i∈componentDarts a r → a i∈componentDarts a r := by
    intro hi
    obtain ⟨x,hx,rfl|rfl⟩ := (mem_componentDarts a r i).mp hi
    · exact (mem_componentDarts a r _).mpr ⟨x,hx,Or.inr rfl⟩
    · rw [ha]
      exact (mem_componentDarts a r _).mpr ⟨x,hx,Or.inl rfl⟩
  constructor
  · intro h
    have hh := hd (a d) h
    rw [ha] at hh
    exact hh
  · exact hd d

def opener (a : Perm (Fin N)) (ha : Function.Involutive a) (hf : ∀ d,a d≠d)
    (d : Fin N) : Opener a :=
  if h : d<a d then ⟨d,h⟩ else ⟨a d,by rw [ha]; exact lt_of_le_of_ne (le_of_not_gt h) (hf d)⟩

lemma opener_endpoints (a : Perm (Fin N)) (ha : Function.Involutive a)
    (hf : ∀ d,a d≠d) (d : Fin N) :
    d=(opener a ha hf d).val ∨ d=a (opener a ha hf d).val := by
  unfold opener
  split_ifs
  · exact Or.inl rfl
  · exact Or.inr (ha d).symm

lemma gapIndex_mate (a : Perm (Fin N)) (ha : Function.Involutive a)
    (hf : ∀ d,a d≠d) (r : Opener a) (hr : r.val.val=0)
    (d : Fin N) (hd : d∉componentDarts a r) : gapIndex a r (a d)=gapIndex a r d := by
  let f := opener a ha hf d
  have hroot : r.val≤f.val := by change r.val.val≤f.val.val; rw [hr]; omega
  have he := opener_endpoints a ha hf d
  have hn : ¬(graph a).Reachable r f := fun h => hd ((mem_componentDarts a r d).mpr ⟨f,h,he⟩)
  have hh := exterior_same_gap a ha r f hroot hn
  rcases he with he|he
  · rw [he]; exact hh.symm
  · rw [he,ha]; exact hh

def cornerDarts (a : Perm (Fin N)) (r : Opener a) (k : ℕ) : Finset (Fin N) :=
  Finset.univ.filter (fun d => d∉componentDarts a r ∧ gapIndex a r d=k)

lemma cornerDarts_mate (a : Perm (Fin N)) (ha : Function.Involutive a)
    (hf : ∀ d,a d≠d) (r : Opener a) (hr : r.val.val=0) (d : Fin N) (k : ℕ) :
    a d∈cornerDarts a r k ↔ d∈cornerDarts a r k := by
  simp only [cornerDarts,Finset.mem_filter,Finset.mem_univ,true_and,componentDarts_mate a ha]
  by_cases hd : d∈componentDarts a r
  · simp [hd]
  · simp only [gapIndex_mate a ha hf r hr d hd]

lemma component_card_even (a : Perm (Fin N)) (ha : Function.Involutive a)
    (hf : ∀ d,a d≠d) (S : Finset (Fin N)) (hS : ∀ d∈S,a d∈S) :
    S.card=2*(S.filter (fun d => d<a d)).card := by
  let O := S.filter (fun d => d<a d)
  have he : S=O∪O.image a := by
    ext d
    simp only [Finset.mem_union,Finset.mem_image]
    constructor
    · intro hd
      by_cases h : d<a d
      · exact Or.inl (Finset.mem_filter.mpr ⟨hd,h⟩)
      · refine Or.inr ⟨a d,?_,ha d⟩
        apply Finset.mem_filter.mpr
        exact ⟨hS d hd,by rw [ha]; exact lt_of_le_of_ne (le_of_not_gt h) (hf d)⟩
    · rintro (hd|⟨i,hi,rfl⟩)
      · exact Finset.mem_of_mem_filter _ hd
      · exact hS i (Finset.mem_of_mem_filter _ hi)
  have hd : Disjoint O (O.image a) := by
    apply Finset.disjoint_left.mpr
    intro d hd hd'
    obtain ⟨i,hi,rfl⟩ := Finset.mem_image.mp hd'
    have hi' := (Finset.mem_filter.mp hi).2
    have hd'' := (Finset.mem_filter.mp hd).2
    rw [ha] at hd''
    exact (not_lt_of_ge hi'.le) hd''
  calc
    S.card=(O∪O.image a).card := congrArg Finset.card he
    _=O.card+O.card := by rw [Finset.card_union_of_disjoint hd,Finset.card_image_of_injective _ a.injective]
    _=2*O.card := by omega

end Chords
namespace Inventory
open MapCycles
variable {N : ℕ}

def pairWord (a : Perm (Fin N)) (c : Fin N→Bool) (i : Fin N) : TypedLetter :=
  if i<a i then .burger (c i) else .order (c i)

/-- Any pair-closed ordered subword of a two-colour noncrossing matching is
itself an actual successful inventory word. This applies both to a root
crossing component and to each of its corner intervals. -/
theorem typedRun_closed_subword (a : Perm (Fin N)) (ha : Function.Involutive a)
    (hf : ∀ x,a x≠x) (c : Fin N→Bool) (hc : ∀ x,c (a x)=c x)
    (hn : ∀ x y,c x=c y → x < y → y < a x → a x < a y → False)
    (l : List (Fin N)) (hl : l.Pairwise (·<·)) (hclosed : ∀ x∈l,a x∈l) :
    stackTypedRun (l.map (pairWord a c)) []=some [] := by
  have hm (b : Bool) : ∃ E,Arches l E ∧
      (endpoints E).Perm (l.filter (fun i => decide (c i=b))) ∧
      ∀ e∈E,e.2=a e.1 ∧ c e.1=b := by
    obtain ⟨E,hE,hcov,hp⟩ := arches_of_noncrossing a ha (fun i => decide (c i=b))
      (fun i => by rw [hc]) l hl (fun x hx _ => hclosed x hx) (fun x _ _ => hf x)
      (by
        intro x _ y _ hx hy hxy hyx hax
        exact hn x y ((of_decide_eq_true hx).trans (of_decide_eq_true hy).symm) hxy hyx hax)
    exact ⟨E,hE,hcov,fun e he => ⟨(hp e he).1,of_decide_eq_true (hp e he).2⟩⟩
  obtain ⟨E,hE,hce,hpe⟩ := hm true
  obtain ⟨F,hF,hcf,hpf⟩ := hm false
  have hcov : (endpoints (E++F)).Perm l := by
    rw [endpoints_append]
    apply (hce.append hcf).trans
    simpa using List.filter_append_perm c l
  have hlabel (b : Bool) (G : List (Fin N×Fin N)) (hG : Arches l G)
      (hp : ∀ e∈G,e.2=a e.1 ∧ c e.1=b) :
      ∀ e∈G,pairWord a c e.1=.burger b ∧ pairWord a c e.2=.order b := by
    intro e he
    obtain ⟨hpair,hcol⟩ := hp e he
    have hlt := hG.increasing hl e he
    have hmate : a e.2=e.1 := by rw [hpair,ha]
    have hcol' : c e.2=b := by rw [hpair,hc,hcol]
    simp only [pairWord,← hpair,hmate,ite_eq_left hlt,ite_eq_right (not_lt_of_ge hlt.le),hcol,hcol',and_self]
  exact typedRun_of_matchings _ _ hl.nodup E F hE hF hcov (hlabel true E hE hpe) (hlabel false F hF hpf)

/-- Every root component and every one of its literal corner subwords reduce
empty. The conclusion uses the full ordered subword, not independent fresh
words postulated at a random cut. -/
theorem component_and_corners_empty (a : Perm (Fin N)) (ha : Function.Involutive a)
    (hf : ∀ x,a x≠x) (c : Fin N→Bool) (hc : ∀ x,c (a x)=c x)
    (hn : ∀ x y,c x=c y → x < y → y < a x → a x < a y → False)
    (r : Chords.Opener a) (hr : r.val.val=0) :
    stackTypedRun (((List.finRange N).filter (fun d => decide (d∈Chords.componentDarts a r))).map
      (pairWord a c)) []=some [] ∧
    ∀ k,stackTypedRun (((List.finRange N).filter (fun d => decide (d∈Chords.cornerDarts a r k))).map
      (pairWord a c)) []=some [] := by
  constructor
  · apply typedRun_closed_subword a ha hf c hc hn _ ((List.pairwise_lt_finRange N).filter _)
    intro x hx
    simp only [List.mem_filter,List.mem_finRange,true_and,decide_eq_true_eq] at hx ⊢
    exact (Chords.componentDarts_mate a ha r x).mpr hx
  · intro k
    apply typedRun_closed_subword a ha hf c hc hn _ ((List.pairwise_lt_finRange N).filter _)
    intro x hx
    simp only [List.mem_filter,List.mem_finRange,true_and,decide_eq_true_eq] at hx ⊢
    exact (Chords.cornerDarts_mate a ha hf r hr x k).mpr hx

end Inventory
end FKCRT
end

end OAI