]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/lib/re/re.ma
regular expressions
[helm.git] / matita / matita / lib / re / re.ma
1
2
3 (**************************************************************************)
4 (*       ___                                                              *)
5 (*      ||M||                                                             *)
6 (*      ||A||       A project by Andrea Asperti                           *)
7 (*      ||T||                                                             *)
8 (*      ||I||       Developers:                                           *)
9 (*      ||T||         The HELM team.                                      *)
10 (*      ||A||         http://helm.cs.unibo.it                             *)
11 (*      \   /                                                             *)
12 (*       \ /        This file is distributed under the terms of the       *)
13 (*        v         GNU General Public License Version 2                  *)
14 (*                                                                        *)
15 (**************************************************************************)
16
17 include "arithmetics/nat.ma".
18 include "basics/list.ma".
19
20 interpretation "iff" 'iff a b = (iff a b).  
21
22 record Alpha : Type[1] ≝ { carr :> Type[0];
23    eqb: carr → carr → bool;
24    eqb_true: ∀x,y. (eqb x y = true) ↔ (x = y)
25 }.
26  
27 notation "a == b" non associative with precedence 45 for @{ 'eqb $a $b }.
28 interpretation "eqb" 'eqb a b = (eqb ? a b).
29
30 definition word ≝ λS:Alpha.list S.
31
32 inductive re (S: Alpha) : Type[0] ≝
33    z: re S
34  | e: re S
35  | s: S → re S
36  | c: re S → re S → re S
37  | o: re S → re S → re S
38  | k: re S → re S.
39  
40 (* notation < "a \sup ⋇" non associative with precedence 90 for @{ 'pk $a}.*)
41 notation "a ^ *" non associative with precedence 90 for @{ 'pk $a}.
42 interpretation "star" 'pk a = (k ? a).
43 interpretation "or" 'plus a b = (o ? a b).
44            
45 notation "a · b" non associative with precedence 60 for @{ 'pc $a $b}.
46 interpretation "cat" 'pc a b = (c ? a b).
47
48 (* to get rid of \middot 
49 ncoercion c  : ∀S:Alpha.∀p:re S.  re S →  re S   ≝ c  on _p : re ?  to ∀_:?.?.
50 *)
51
52 notation < "a" non associative with precedence 90 for @{ 'ps $a}.
53 notation > "` term 90 a" non associative with precedence 90 for @{ 'ps $a}.
54 interpretation "atom" 'ps a = (s ? a).
55
56 notation "ϵ" non associative with precedence 90 for @{ 'epsilon }.
57 interpretation "epsilon" 'epsilon = (e ?).
58
59 notation "∅" non associative with precedence 90 for @{ 'empty }.
60 interpretation "empty" 'empty = (z ?).
61
62 let rec flatten (S : Alpha) (l : list (word S)) on l : word S ≝ 
63 match l with [ nil ⇒ [ ] | cons w tl ⇒ w @ flatten ? tl ].
64
65 let rec conjunct (S : Alpha) (l : list (word S)) (r : word S → Prop) on l: Prop ≝
66 match l with [ nil ⇒ ? | cons w tl ⇒ r w ∧ conjunct ? tl r ]. 
67 // qed.
68
69 definition empty_lang ≝ λS.λw:word S.False.
70 notation "{}" non associative with precedence 90 for @{'empty_lang}.
71 interpretation "empty lang" 'empty_lang = (empty_lang ?).
72
73 definition sing_lang ≝ λS.λx,w:word S.x=w.
74 (* notation "{x}" non associative with precedence 90 for @{'sing_lang $x}.*)
75 interpretation "sing lang" 'singl x = (sing_lang ? x).
76
77 definition union : ∀S,l1,l2,w.Prop ≝ λS.λl1,l2.λw:word S.l1 w ∨ l2 w.
78 interpretation "union lang" 'union a b = (union ? a b).
79
80 definition cat : ∀S,l1,l2,w.Prop ≝ 
81   λS.λl1,l2.λw:word S.∃w1,w2.w1 @ w2 = w ∧ l1 w1 ∧ l2 w2.
82 interpretation "cat lang" 'pc a b = (cat ? a b).
83
84 definition star ≝ λS.λl.λw:word S.∃lw.flatten ? lw = w ∧ conjunct ? lw l. 
85 interpretation "star lang" 'pk l = (star ? l).
86
87 let rec in_l (S : Alpha) (r : re S) on r : word S → Prop ≝ 
88 match r with
89 [ z ⇒ {}
90 | e ⇒ { [ ] }
91 | s x ⇒ { [x] }
92 | c r1 r2 ⇒ (in_l ? r1) · (in_l ? r2)
93 | o r1 r2 ⇒ (in_l ? r1) ∪ (in_l ? r2)
94 | k r1 ⇒ (in_l ? r1) ^*].
95
96 notation "\sem{term 19 E}" non associative with precedence 75 for @{'in_l $E}.
97 interpretation "in_l" 'in_l E = (in_l ? E).
98 interpretation "in_l mem" 'mem w l = (in_l ? l w).
99
100 notation "a || b" left associative with precedence 30 for @{'orb $a $b}.
101 interpretation "orb" 'orb a b = (orb a b).
102
103 definition if_then_else ≝ λT:Type[0].λe,t,f.match e return λ_.T with [ true ⇒ t | false ⇒ f].
104 notation > "'if' term 19 e 'then' term 19 t 'else' term 19 f" non associative with precedence 19 for @{ 'if_then_else $e $t $f }.
105 notation < "'if' \nbsp term 19 e \nbsp 'then' \nbsp term 19 t \nbsp 'else' \nbsp term 90 f \nbsp" non associative with precedence 19 for @{ 'if_then_else $e $t $f }.
106 interpretation "if_then_else" 'if_then_else e t f = (if_then_else ? e t f).
107
108 inductive pitem (S: Alpha) : Type[0] ≝
109    pz: pitem S
110  | pe: pitem S
111  | ps: S → pitem S
112  | pp: S → pitem S
113  | pc: pitem S → pitem S → pitem S
114  | po: pitem S → pitem S → pitem S
115  | pk: pitem S → pitem S.
116  
117 definition pre ≝ λS.pitem S × bool.
118
119 interpretation "pstar" 'pk a = (pk ? a).
120 interpretation "por" 'plus a b = (po ? a b).
121 interpretation "pcat" 'pc a b = (pc ? a b).
122 notation < ".a" non associative with precedence 90 for @{ 'pp $a}.
123 notation > "`. term 90 a" non associative with precedence 90 for @{ 'pp $a}.
124 interpretation "ppatom" 'pp a = (pp ? a).
125 (* to get rid of \middot 
126 ncoercion pc : ∀S.∀p:pitem S. pitem S → pitem S  ≝ pc on _p : pitem ? to ∀_:?.?.
127 *)
128 interpretation "patom" 'ps a = (ps ? a).
129 interpretation "pepsilon" 'epsilon = (pe ?).
130 interpretation "pempty" 'empty = (pz ?).
131
132 let rec forget (S: Alpha) (l : pitem S) on l: re S ≝
133  match l with
134   [ pz ⇒ ∅
135   | pe ⇒ ϵ
136   | ps x ⇒ `x
137   | pp x ⇒ `x
138   | pc E1 E2 ⇒ (forget ? E1) · (forget ? E2)
139   | po E1 E2 ⇒ (forget ? E1) + (forget ? E2)
140   | pk E ⇒ (forget ? E)^* ].
141   
142 (* notation < "|term 19 e|" non associative with precedence 70 for @{'forget $e}.*)
143 interpretation "forget" 'norm a = (forget ? a).
144
145
146 let rec in_pl (S : Alpha) (r : pitem S) on r : word S → Prop ≝ 
147 match r with
148 [ pz ⇒ {}
149 | pe ⇒ {}
150 | ps _ ⇒ {}
151 | pp x ⇒ { [x] }
152 | pc r1 r2 ⇒ (in_pl ? r1) · \sem{forget ? r2} ∪ (in_pl ? r2)
153 | po r1 r2 ⇒ (in_pl ? r1) ∪ (in_pl ? r2)
154 | pk r1 ⇒ (in_pl ? r1) · \sem{forget ? r1}^*  ].
155
156 interpretation "in_pl" 'in_l E = (in_pl ? E).
157 interpretation "in_pl mem" 'mem w l = (in_pl ? l w).
158
159 definition epsilon ≝ λS,b.if b then { ([ ] : word S) } else {}.
160
161 interpretation "epsilon" 'epsilon = (epsilon ?).
162 notation < "ϵ b" non associative with precedence 90 for @{'app_epsilon $b}.
163 interpretation "epsilon lang" 'app_epsilon b = (epsilon ? b).
164
165 definition in_prl ≝ λS : Alpha.λp:pre S. 
166   if (\snd p) then \sem{\fst p} ∪ { ([ ] : word S) } else \sem{\fst p}.
167   
168 interpretation "in_prl mem" 'mem w l = (in_prl ? l w).
169 interpretation "in_prl" 'in_l E = (in_prl ? E).
170
171 lemma sem_pre_true : ∀S.∀i:pitem S. 
172   \sem{〈i,true〉} = \sem{i} ∪ { ([ ] : word S) }. 
173 // qed.
174
175 lemma sem_pre_false : ∀S.∀i:pitem S. 
176   \sem{〈i,false〉} = \sem{i}. 
177 // qed.
178
179 lemma sem_cat: ∀S.∀i1,i2:pitem S. 
180   \sem{i1 · i2} = \sem{i1} · \sem{|i2|} ∪ \sem{i2}.
181 // qed.
182
183 lemma sem_plus: ∀S.∀i1,i2:pitem S. 
184   \sem{i1 + i2} = \sem{i1} ∪ \sem{i2}.
185 // qed.
186
187 lemma sem_star : ∀S.∀i:pitem S.
188   \sem{i^*} = \sem{i} · \sem{|i|}^*.
189 // qed.
190
191 lemma append_eq_nil : ∀S.∀w1,w2:word S. w1 @ w2 = [ ] → w1 = [ ].
192 #S #w1 #w2 cases w1 // #a #tl normalize #H destruct qed.
193
194 lemma not_epsilon_lp : ∀S:Alpha.∀e:pitem S. ¬ ([ ] ∈ e).
195 #S #e elim e normalize /2/  
196   [#r1 #r2 * #n1 #n2 % * /2/ * #w1 * #w2 * * #H 
197    >(append_eq_nil …H…) /2/
198   |#r1 #r2 #n1 #n2 % * /2/
199   |#r #n % * #w1 * #w2 * * #H >(append_eq_nil …H…) /2/
200   ]
201 qed.
202
203 (* lemma 12 *)
204 lemma epsilon_to_true : ∀S.∀e:pre S. [ ] ∈ e → \snd e = true.
205 #S * #i #b cases b // normalize #H @False_ind /2/ 
206 qed.
207
208 lemma true_to_epsilon : ∀S.∀e:pre S. \snd e = true → [ ] ∈ e.
209 #S * #i #b #btrue normalize in btrue >btrue %2 // 
210 qed.
211
212 definition lo ≝ λS:Alpha.λa,b:pre S.〈\fst a + \fst b,\snd a || \snd b〉.
213 notation "a ⊕ b" left associative with precedence 60 for @{'oplus $a $b}.
214 interpretation "oplus" 'oplus a b = (lo ? a b).
215
216 lemma lo_def: ∀S.∀i1,i2:pitem S.∀b1,b2. 〈i1,b1〉⊕〈i2,b2〉=〈i1+i2,b1||b2〉.
217 // qed.
218
219 definition pre_concat_r ≝ λS:Alpha.λi:pitem S.λe:pre S.
220   match e with [ pair i1 b ⇒ 〈i · i1, b〉].
221  
222 notation "i ▸ e" left associative with precedence 60 for @{'trir $i $e}.
223 interpretation "pre_concat_r" 'trir i e = (pre_concat_r ? i e).
224   
225 definition eq_f1 ≝ λS.λa,b:word S → Prop.∀w.a w ↔ b w.
226 notation "A =1 B" non associative with precedence 45 for @{'eq_f1 $A $B}.
227 interpretation "eq f1" 'eq_f1 a b = (eq_f1 ? a b).
228
229 lemma eq_to_ex_eq: ∀S.∀A,B:word S → Prop. 
230   A = B → A =1 B. 
231 #S #A #B #H >H /2/ qed.
232
233 lemma ext_eq_trans: ∀S.∀A,B,C:word S → Prop. 
234   A =1 B → B =1 C → A =1 C. 
235 #S #A #B #C #eqAB #eqBC #w cases (eqAB w) cases (eqBC w) /4/
236 qed.   
237
238 lemma union_assoc: ∀S.∀A,B,C:word S → Prop. 
239   A ∪ B ∪ C =1 A ∪ (B ∪ C).
240 #S #A #B #C #w % [* [* /3/ | /3/] | * [/3/ | * /3/]
241 qed.   
242
243 lemma sem_pre_concat_r : ∀S,i.∀e:pre S.
244   \sem{i ▸ e} =1 \sem{i} · \sem{|\fst e|} ∪ \sem{e}.
245 #S #i * #i1 #b1 cases b1 /2/
246 >sem_pre_true >sem_cat >sem_pre_true /2/ 
247 qed.
248  
249 definition lc ≝ λS:Alpha.λbcast:∀S:Alpha.pitem S → pre S.λe1:pre S.λi2:pitem S.
250   match e1 with 
251   [ pair i1 b1 ⇒ match b1 with 
252     [ true ⇒ (i1 ▸ (bcast ? i2)) 
253     | false ⇒ 〈i1 · i2,false〉
254     ]
255   ].
256         
257 definition lift ≝ λf:∀S.pitem S →pre S.λS.λe:pre S. 
258   match e with 
259   [ pair i b ⇒ 〈\fst (f S i), \snd (f S i) || b〉].
260
261 notation < "a ⊙ b" left associative with precedence 60 for @{'lc $op $a $b}.
262 interpretation "lc" 'lc op a b = (lc ? op a b).
263 notation > "a ⊙ b" left associative with precedence 60 for @{'lc eclose $a $b}.
264
265 definition lk ≝ λS:Alpha.λbcast:∀S:Alpha.∀E:pitem S.pre S.λe:pre S.
266   match e with 
267   [ pair i1 b1 ⇒
268     match b1 with 
269     [true ⇒ 〈(\fst (bcast ? i1))^*, true〉
270     |false ⇒ 〈i1^*,true〉
271     ]
272   ].
273
274 (* notation < "a \sup ⊛" non associative with precedence 90 for @{'lk $op $a}.*)
275 interpretation "lk" 'lk op a = (lk ? op a).
276 notation > "a^⊛" non associative with precedence 90 for @{'lk eclose $a}.
277
278 notation > "•" non associative with precedence 60 for @{eclose ?}.
279
280 let rec eclose (S: Alpha) (i: pitem S) on i : pre S ≝
281  match i with
282   [ pz ⇒ 〈 ∅, false 〉
283   | pe ⇒ 〈 ϵ,  true 〉
284   | ps x ⇒ 〈 `.x, false〉
285   | pp x ⇒ 〈 `.x, false 〉
286   | po i1 i2 ⇒ •i1 ⊕ •i2
287   | pc i1 i2 ⇒ •i1 ⊙ i2
288   | pk i ⇒ 〈(\fst(•i))^*,true〉].
289   
290   
291 notation "• x" non associative with precedence 60 for @{'eclose $x}.
292 interpretation "eclose" 'eclose x = (eclose ? x).
293
294 lemma eclose_plus: ∀S:Alpha.∀i1,i2:pitem S.
295   •(i1 + i2) = •i1 ⊕ •i2.
296 // qed.
297
298 lemma eclose_dot: ∀S:Alpha.∀i1,i2:pitem S.
299   •(i1 · i2) = •i1 ⊙ i2.
300 // qed.
301
302 lemma eclose_star: ∀S:Alpha.∀i:pitem S.
303   •i^* = 〈(\fst(•i))^*,true〉.
304 // qed.
305
306 definition reclose ≝ lift eclose. 
307 interpretation "reclose" 'eclose x = (reclose ? x).
308
309 lemma epsilon_or : ∀S:Alpha.∀b1,b2. epsilon S (b1 || b2) =1 ϵ b1 ∪ ϵ b2. 
310 #S #b1 #b2 #w % cases b1 cases b2 normalize /2/ * /2/ * ;
311 qed.
312
313 (*
314 lemma cupA : ∀S.∀a,b,c:word S → Prop.a ∪ b ∪ c = a ∪ (b ∪ c).
315 #S a b c; napply extP; #w; nnormalize; @; *; /3/; *; /3/; nqed.
316
317 nlemma cupC : ∀S. ∀a,b:word S → Prop.a ∪ b = b ∪ a.
318 #S a b; napply extP; #w; @; *; nnormalize; /2/; nqed.*)
319
320 (* theorem 16: 2 *)
321 (*
322 lemma oplus_cup : ∀S:Alpha.∀e1,e2:pre S.
323   \sem{e1 ⊕ e2} =1 \sem{e1} ∪ \sem{e2}.
324 #S * #i1 #b1  * #i2 #b2 #w %
325 [normalize * [* /3/ | cases b1 cases b2 normalize /3/ ]
326 |normalize * * /3/ cases b1 cases b2 normalize /3/ *]
327 qed. *)
328
329 lemma odot_true : 
330   ∀S.∀i1,i2:pitem S.
331   〈i1,true〉 ⊙ i2 = i1 ▸ (•i2).
332 // qed.
333
334 lemma odot_true_bis : 
335   ∀S.∀i1,i2:pitem S.
336   〈i1,true〉 ⊙ i2 = 〈i1 · \fst (•i2), \snd (•i2)〉.
337 #S #i1 #i2 normalize cases (•i2) // qed.
338
339 lemma odot_false: 
340   ∀S.∀i1,i2:pitem S.
341   〈i1,false〉 ⊙ i2 = 〈i1 · i2, false〉.
342 // qed.
343
344 lemma LcatE : ∀S.∀e1,e2:pitem S.
345   \sem{e1 · e2} = \sem{e1} · \sem{|e2|} ∪ \sem{e2}. 
346 // qed.
347
348 (*
349 nlemma cup_dotD : ∀S.∀p,q,r:word S → Prop.(p ∪ q) · r = (p · r) ∪ (q · r). 
350 #S p q r; napply extP; #w; nnormalize; @; 
351 ##[ *; #x; *; #y; *; *; #defw; *; /7/ by or_introl, or_intror, ex_intro, conj;
352 ##| *; *; #x; *; #y; *; *; /7/ by or_introl, or_intror, ex_intro, conj; ##]
353 nqed.
354
355 nlemma cup0 :∀S.∀p:word S → Prop.p ∪ {} = p.
356 #S p; napply extP; #w; nnormalize; @; /2/; *; //; *; nqed.*)
357
358 lemma erase_dot : ∀S.∀e1,e2:pitem S. |e1 · e2| = c ? (|e1|) (|e2|).
359 // qed.
360
361 lemma erase_plus : ∀S.∀i1,i2:pitem S.
362   |i1 + i2| = |i1| + |i2|.
363 // qed.
364
365 lemma erase_star : ∀S.∀i:pitem S.|i^*| = |i|^*. 
366 // qed.
367
368 (*
369 definition substract := λS.λp,q:word S → Prop.λw.p w ∧ ¬ q w.
370 interpretation "substract" 'minus a b = (substract ? a b).
371
372 nlemma cup_sub: ∀S.∀a,b:word S → Prop. ¬ (a []) → a ∪ (b - {[]}) = (a ∪ b) - {[]}.
373 #S a b c; napply extP; #w; nnormalize; @; *; /4/; *; /4/; nqed.
374
375 nlemma sub0 : ∀S.∀a:word S → Prop. a - {} = a.
376 #S a; napply extP; #w; nnormalize; @; /3/; *; //; nqed.
377
378 nlemma subK : ∀S.∀a:word S → Prop. a - a = {}.
379 #S a; napply extP; #w; nnormalize; @; *; /2/; nqed.
380
381 nlemma subW : ∀S.∀a,b:word S → Prop.∀w.(a - b) w → a w.
382 #S a b w; nnormalize; *; //; nqed. *)
383
384 lemma erase_bull : ∀S.∀i:pitem S. |\fst (•i)| = |i|.
385 #S #i elim i // 
386   [ #i1 #i2 #IH1 #IH2 >erase_dot <IH1 >eclose_dot
387     cases (•i1) #i11 #b1 cases b1 // <IH2 >odot_true_bis //
388   | #i1 #i2 #IH1 #IH2 >eclose_plus >(erase_plus … i1) <IH1 <IH2
389     cases (•i1) #i11 #b1 cases (•i2) #i21 #b2 //  
390   | #i #IH >eclose_star >(erase_star … i) <IH cases (•i) //
391   ]
392 qed.
393
394 axiom eq_ext_sym: ∀S.∀A,B:word S →Prop. 
395   A =1 B → B =1 A.
396
397 axiom union_ext_l: ∀S.∀A,B,C:word S →Prop. 
398   A =1 C  → A ∪ B =1 C ∪ B.
399   
400 axiom union_ext_r: ∀S.∀A,B,C:word S →Prop. 
401   B =1 C → A ∪ B =1 A ∪ C.
402   
403 axiom union_comm : ∀S.∀A,B:word S →Prop. 
404   A ∪ B =1 B ∪ A.
405   
406 lemma distr_cat_r: ∀S.∀A,B,C:word S →Prop.
407   (A ∪ B) · C =1  A · C ∪ B · C. 
408 #S #A #B #C #w %
409   [* #w1 * #w2 * * #eqw * /6/ |* * #w1 * #w2 * * /6/] 
410 qed.
411
412 (* this kind of results are pretty bad for automation;
413    better not index them *)
414 lemma epsilon_cat_r: ∀S.∀A:word S →Prop.
415    A · { [ ] } =1  A. 
416 #S #A #w %
417   [* #w1 * #w2 * * #eqw #inw1 normalize #eqw2 <eqw //
418   |#inA @(ex_intro … w) @(ex_intro … [ ]) /3/
419   ]
420 qed-.
421
422 lemma epsilon_cat_l: ∀S.∀A:word S →Prop.
423    { [ ] } · A =1  A. 
424 #S #A #w %
425   [* #w1 * #w2 * * #eqw normalize #eqw2 <eqw <eqw2 //
426   |#inA @(ex_intro … [ ]) @(ex_intro … w) /3/
427   ]
428 qed-.
429
430
431 lemma distr_cat_r_eps: ∀S.∀A,C:word S →Prop.
432   (A ∪ { [ ] }) · C =1  A · C ∪ C. 
433 #S #A #C @ext_eq_trans [|@distr_cat_r |@union_ext_r @epsilon_cat_l]
434 qed.
435
436 (* axiom eplison_cut_l: ∀S.∀A:word S →Prop. 
437    { [ ] } · A =1  A.
438    
439  axiom eplison_cut_r: ∀S.∀A:word S →Prop.
440    A · { [ ] } =1  A. *)
441
442 (*
443 lemma eta_lp : ∀S.∀p:pre S.𝐋\p p = 𝐋\p 〈\fst p, \snd p〉.
444 #S p; ncases p; //; nqed.
445
446 nlemma epsilon_dot: ∀S.∀p:word S → Prop. {[]} · p = p. 
447 #S e; napply extP; #w; nnormalize; @; ##[##2: #Hw; @[]; @w; /3/; ##]
448 *; #w1; *; #w2; *; *; #defw defw1 Hw2; nrewrite < defw; nrewrite < defw1;
449 napply Hw2; nqed.*)
450
451 (* theorem 16: 1 → 3 *)
452 lemma odot_dot_aux : ∀S.∀e1:pre S.∀i2:pitem S.
453    \sem{•i2} =1  \sem{i2} ∪ \sem{|i2|} →
454    \sem{e1 ⊙ i2} =1  \sem{e1} · \sem{|i2|} ∪ \sem{i2}.
455 #S * #i1 #b1 #i2 cases b1
456   [2:#th >odot_false >sem_pre_false >sem_pre_false >sem_cat /2/
457   |#H >odot_true >sem_pre_true @(ext_eq_trans … (sem_pre_concat_r …))
458    >erase_bull 
459    @ext_eq_trans
460      [|@(union_ext_r … H)
461      |@ext_eq_trans
462        [|@union_ext_r [|@union_comm ]
463        |@ext_eq_trans (* /3 by eq_ext_sym, union_ext_l/; *)
464          [|@eq_ext_sym @union_assoc
465          |/3/ 
466           (*
467            by eq_ext_sym, union_ext_l;  @union_ext_l /3
468           /3/ ext_eq_trans /2/ 
469             /3 width=5 by eq_ext_sym, union_ext_r/ *)
470          ]
471        ]
472      ]
473    ]
474 qed.
475
476 (* nlemma sub_dot_star : 
477   ∀S.∀X:word S → Prop.∀b. (X - ϵ b) · X^* ∪ {[]} = X^*.
478 #S X b; napply extP; #w; @;
479 ##[ *; ##[##2: nnormalize; #defw; nrewrite < defw; @[]; @; //]
480     *; #w1; *; #w2; *; *; #defw sube; *; #lw; *; #flx cj;
481     @ (w1 :: lw); nrewrite < defw; nrewrite < flx; @; //;
482     @; //; napply (subW … sube);
483 ##| *; #wl; *; #defw Pwl; nrewrite < defw; nelim wl in Pwl; ##[ #_; @2; //]
484     #w' wl' IH; *; #Pw' IHp; nlapply (IH IHp); *;
485     ##[ *; #w1; *; #w2; *; *; #defwl' H1 H2;
486         @; ncases b in H1; #H1; 
487         ##[##2: nrewrite > (sub0…); @w'; @(w1@w2);
488                 nrewrite > (associative_append ? w' w1 w2);
489                 nrewrite > defwl'; @; ##[@;//] @(wl'); @; //;
490            ##| ncases w' in Pw';
491                ##[ #ne; @w1; @w2; nrewrite > defwl'; @; //; @; //;
492                ##| #x xs Px; @(x::xs); @(w1@w2); 
493                    nrewrite > (defwl'); @; ##[@; //; @; //; @; nnormalize; #; ndestruct]
494                    @wl'; @; //; ##] ##]
495         ##| #wlnil; nchange in match (flatten ? (w'::wl')) with (w' @ flatten ? wl');
496             nrewrite < (wlnil); nrewrite > (append_nil…); ncases b;
497             ##[ ncases w' in Pw'; /2/; #x xs Pxs; @; @(x::xs); @([]);
498                 nrewrite > (append_nil…); @; ##[ @; //;@; //; nnormalize; @; #; ndestruct]
499                 @[]; @; //;
500             ##| @; @w'; @[]; nrewrite > (append_nil…); @; ##[##2: @[]; @; //] 
501                 @; //; @; //; @; *;##]##]##] 
502 nqed. *)
503
504 (* theorem 16: 1 *)
505 alias symbol "pc" (instance 13) = "cat lang".
506 alias symbol "in_pl" (instance 23) = "in_pl".
507 alias symbol "in_pl" (instance 5) = "in_pl".
508 alias symbol "eclose" (instance 21) = "eclose".
509 ntheorem bull_cup : ∀S:Alpha. ∀e:pitem S.  𝐋\p (•e) =  𝐋\p e ∪ 𝐋 |e|.
510 #S e; nelim e; //;
511   ##[ #a; napply extP; #w; nnormalize; @; *; /3/ by or_introl, or_intror;
512   ##| #a; napply extP; #w; nnormalize; @; *; /3/ by or_introl; *;
513   ##| #e1 e2 IH1 IH2;  
514       nchange in ⊢ (??(??(%))?) with (•e1 ⊙ 〈e2,false〉);
515       nrewrite > (odot_dot_aux S (•e1) 〈e2,false〉 IH2);
516       nrewrite > (IH1 …); nrewrite > (cup_dotD …);
517       nrewrite > (cupA …); nrewrite > (cupC ?? (𝐋\p ?) …);
518       nchange in match (𝐋\p 〈?,?〉) with (𝐋\p e2 ∪ {}); nrewrite > (cup0 …);
519       nrewrite < (erase_dot …); nrewrite < (cupA …); //;
520   ##| #e1 e2 IH1 IH2;
521       nchange in match (•(?+?)) with (•e1 ⊕ •e2); nrewrite > (oplus_cup …);
522       nrewrite > (IH1 …); nrewrite > (IH2 …); nrewrite > (cupA …);
523       nrewrite > (cupC ? (𝐋\p e2)…);nrewrite < (cupA ??? (𝐋\p e2)…);
524       nrewrite > (cupC ?? (𝐋\p e2)…); nrewrite < (cupA …); 
525       nrewrite < (erase_plus …); //.
526   ##| #e; nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e)); #IH;
527       nchange in match (𝐋\p ?) with  (𝐋\p 〈e'^*,true〉);
528       nchange in match (𝐋\p ?) with (𝐋\p (e'^* ) ∪ {[ ]});
529       nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 |e'|^* );
530       nrewrite > (erase_bull…e);
531       nrewrite > (erase_star …);
532       nrewrite > (?: 𝐋\p e' =  𝐋\p e ∪ (𝐋 |e| - ϵ b')); ##[##2:
533         nchange in IH : (??%?) with (𝐋\p e' ∪ ϵ b'); ncases b' in IH; 
534         ##[ #IH; nrewrite > (cup_sub…); //; nrewrite < IH; 
535             nrewrite < (cup_sub…); //; nrewrite > (subK…); nrewrite > (cup0…);//;
536         ##| nrewrite > (sub0 …); #IH; nrewrite < IH; nrewrite > (cup0 …);//; ##]##]
537       nrewrite > (cup_dotD…); nrewrite > (cupA…); 
538       nrewrite > (?: ((?·?)∪{[]} = 𝐋 |e^*|)); //;
539       nchange in match (𝐋 |e^*|) with ((𝐋 |e|)^* ); napply sub_dot_star;##]
540  nqed.
541
542 (* theorem 16: 3 *)      
543 nlemma odot_dot: 
544   ∀S.∀e1,e2: pre S.  𝐋\p (e1 ⊙ e2) =  𝐋\p e1 · 𝐋 |\fst e2| ∪ 𝐋\p e2.
545 #S e1 e2; napply odot_dot_aux; napply (bull_cup S (\fst e2)); nqed.
546
547 nlemma dot_star_epsilon : ∀S.∀e:re S.𝐋 e · 𝐋 e^* ∪ {[]} =  𝐋 e^*.
548 #S e; napply extP; #w; nnormalize; @;
549 ##[ *; ##[##2: #H; nrewrite < H; @[]; /3/] *; #w1; *; #w2; 
550     *; *; #defw Hw1; *; #wl; *; #defw2 Hwl; @(w1 :: wl);
551     nrewrite < defw; nrewrite < defw2; @; //; @;//;
552 ##| *; #wl; *; #defw Hwl; ncases wl in defw Hwl; ##[#defw; #; @2; nrewrite < defw; //]
553     #x xs defw; *; #Hx Hxs; @; @x; @(flatten ? xs); nrewrite < defw;
554     @; /2/; @xs; /2/;##]
555  nqed.
556
557 nlemma nil_star : ∀S.∀e:re S. [ ] ∈ e^*.
558 #S e; @[]; /2/; nqed.
559
560 nlemma cupID : ∀S.∀l:word S → Prop.l ∪ l = l.
561 #S l; napply extP; #w; @; ##[*]//; #; @; //; nqed.
562
563 nlemma cup_star_nil : ∀S.∀l:word S → Prop. l^* ∪ {[]} = l^*.
564 #S a; napply extP; #w; @; ##[*; //; #H; nrewrite < H; @[]; @; //] #;@; //;nqed.
565
566 nlemma rcanc_sing : ∀S.∀A,C:word S → Prop.∀b:word S .
567   ¬ (A b) → A ∪ { (b) } = C → A = C - { (b) }.
568 #S A C b nbA defC; nrewrite < defC; napply extP; #w; @;
569 ##[ #Aw; /3/| *; *; //; #H nH; ncases nH; #abs; nlapply (abs H); *]
570 nqed.
571
572 (* theorem 16: 4 *)      
573 nlemma star_dot: ∀S.∀e:pre S. 𝐋\p (e^⊛) = 𝐋\p e · (𝐋 |\fst e|)^*.
574 #S p; ncases p; #e b; ncases b;
575 ##[ nchange in match (〈e,true〉^⊛) with 〈?,?〉;
576     nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e));
577     nchange in ⊢ (??%?) with (?∪?);
578     nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 |e'|^* );
579     nrewrite > (?: 𝐋\p e' = 𝐋\p e ∪ (𝐋 |e| - ϵ b' )); ##[##2:
580       nlapply (bull_cup ? e); #bc;
581       nchange in match (𝐋\p (•e)) in bc with (?∪?);
582       nchange in match b' in bc with b';
583       ncases b' in bc; ##[##2: nrewrite > (cup0…); nrewrite > (sub0…); //]
584       nrewrite > (cup_sub…); ##[napply rcanc_sing] //;##]
585     nrewrite > (cup_dotD…); nrewrite > (cupA…);nrewrite > (erase_bull…);
586     nrewrite > (sub_dot_star…);
587     nchange in match (𝐋\p 〈?,?〉) with (?∪?);
588     nrewrite > (cup_dotD…); nrewrite > (epsilon_dot…); //;    
589 ##| nwhd in match (〈e,false〉^⊛); nchange in match (𝐋\p 〈?,?〉) with (?∪?);
590     nrewrite > (cup0…);
591     nchange in ⊢ (??%?) with (𝐋\p e · 𝐋 |e|^* );
592     nrewrite < (cup0 ? (𝐋\p e)); //;##]
593 nqed.
594
595 nlet rec pre_of_re (S : Alpha) (e : re S) on e : pitem S ≝ 
596   match e with 
597   [ z ⇒ pz ?
598   | e ⇒ pe ?
599   | s x ⇒ ps ? x
600   | c e1 e2 ⇒ pc ? (pre_of_re ? e1) (pre_of_re ? e2)
601   | o e1 e2 ⇒ po ? (pre_of_re ? e1) (pre_of_re ? e2)
602   | k e1 ⇒ pk ? (pre_of_re ? e1)].
603
604 nlemma notFalse : ¬False. @; //; nqed.
605
606 nlemma dot0 : ∀S.∀A:word S → Prop. {} · A = {}.
607 #S A; nnormalize; napply extP; #w; @; ##[##2: *]
608 *; #w1; *; #w2; *; *; //; nqed.
609
610 nlemma Lp_pre_of_re : ∀S.∀e:re S. 𝐋\p (pre_of_re ? e) = {}.
611 #S e; nelim e; ##[##1,2,3: //]
612 ##[ #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1 e2))) with (?∪?);
613     nrewrite > H1; nrewrite > H2; nrewrite > (dot0…); nrewrite > (cupID…);//
614 ##| #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1+e2))) with (?∪?);
615     nrewrite > H1; nrewrite > H2; nrewrite > (cupID…); //
616 ##| #e1 H1; nchange in match (𝐋\p (pre_of_re S (e1^* ))) with (𝐋\p (pre_of_re ??) · ?);
617     nrewrite > H1; napply dot0; ##]
618 nqed.
619
620 nlemma erase_pre_of_reK : ∀S.∀e. 𝐋 |pre_of_re S e| = 𝐋 e.
621 #S A; nelim A; //; 
622 ##[ #e1 e2 H1 H2; nchange in match (𝐋 (e1 · e2)) with (𝐋 e1·?);
623     nrewrite < H1; nrewrite < H2; //
624 ##| #e1 e2 H1 H2; nchange in match (𝐋 (e1 + e2)) with (𝐋 e1 ∪ ?);
625     nrewrite < H1; nrewrite < H2; //
626 ##| #e1 H1; nchange in match (𝐋  (e1^* )) with ((𝐋 e1)^* );
627     nrewrite < H1; //]
628 nqed.     
629
630 (* corollary 17 *)
631 nlemma L_Lp_bull : ∀S.∀e:re S.𝐋 e = 𝐋\p (•pre_of_re ? e).
632 #S e; nrewrite > (bull_cup…); nrewrite > (Lp_pre_of_re…);
633 nrewrite > (cupC…); nrewrite > (cup0…); nrewrite > (erase_pre_of_reK…); //;
634 nqed.
635
636 nlemma Pext : ∀S.∀f,g:word S → Prop. f = g → ∀w.f w → g w.
637 #S f g H; nrewrite > H; //; nqed.
638  
639 (* corollary 18 *)
640 ntheorem bull_true_epsilon : ∀S.∀e:pitem S. \snd (•e) = true ↔ [ ] ∈ |e|.
641 #S e; @;
642 ##[ #defsnde; nlapply (bull_cup ? e); nchange in match (𝐋\p (•e)) with (?∪?);
643     nrewrite > defsnde; #H; 
644     nlapply (Pext ??? H [ ] ?); ##[ @2; //] *; //;
645
646 STOP
647
648 notation > "\move term 90 x term 90 E" 
649 non associative with precedence 60 for @{move ? $x $E}.
650 nlet rec move (S: Alpha) (x:S) (E: pitem S) on E : pre S ≝
651  match E with
652   [ pz ⇒ 〈 ∅, false 〉
653   | pe ⇒ 〈 ϵ, false 〉
654   | ps y ⇒ 〈 `y, false 〉
655   | pp y ⇒ 〈 `y, x == y 〉
656   | po e1 e2 ⇒ \move x e1 ⊕ \move x e2 
657   | pc e1 e2 ⇒ \move x e1 ⊙ \move x e2
658   | pk e ⇒ (\move x e)^⊛ ].
659 notation < "\move\shy x\shy E" non associative with precedence 60 for @{'move $x $E}.
660 notation > "\move term 90 x term 90 E" non associative with precedence 60 for @{'move $x $E}.
661 interpretation "move" 'move x E = (move ? x E).
662
663 ndefinition rmove ≝ λS:Alpha.λx:S.λe:pre S. \move x (\fst e).
664 interpretation "rmove" 'move x E = (rmove ? x E).
665
666 nlemma XXz :  ∀S:Alpha.∀w:word S. w ∈ ∅ → False.
667 #S w abs; ninversion abs; #; ndestruct;
668 nqed.
669
670
671 nlemma XXe :  ∀S:Alpha.∀w:word S. w .∈ ϵ → False.
672 #S w abs; ninversion abs; #; ndestruct;
673 nqed.
674
675 nlemma XXze :  ∀S:Alpha.∀w:word S. w .∈ (∅ · ϵ)  → False.
676 #S w abs; ninversion abs; #; ndestruct; /2/ by XXz,XXe;
677 nqed.
678
679
680 naxiom in_move_cat:
681  ∀S.∀w:word S.∀x.∀E1,E2:pitem S. w .∈ \move x (E1 · E2) → 
682    (∃w1.∃w2. w = w1@w2 ∧ w1 .∈ \move x E1 ∧ w2 ∈ .|E2|) ∨ w .∈ \move x E2.
683 #S w x e1 e2 H; nchange in H with (w .∈ \move x e1 ⊙ \move x e2);
684 ncases e1 in H; ncases e2;
685 ##[##1: *; ##[*; nnormalize; #; ndestruct] 
686    #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
687    nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
688 ##|##2: *; ##[*; nnormalize; #; ndestruct] 
689    #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
690    nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
691 ##| #r; *; ##[ *; nnormalize; #; ndestruct] 
692    #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
693    ##[##2: nnormalize; #; ndestruct; @2; @2; //.##]
694    nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz;
695 ##| #y; *; ##[ *; nnormalize; #defw defx; ndestruct; @2; @1; /2/ by conj;##]
696    #H; ninversion H; nnormalize; #; ndestruct; 
697    ##[ncases (?:False); /2/ by XXz] /3/ by or_intror;
698 ##| #r1 r2; *; ##[ *; #defw]
699     ...
700 nqed.
701
702 ntheorem move_ok:
703  ∀S:Alpha.∀E:pre S.∀a,w.w .∈ \move a E ↔ (a :: w) .∈ E. 
704 #S E; ncases E; #r b; nelim r;
705 ##[##1,2: #a w; @; 
706    ##[##1,3: nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #abs; ncases (XXz … abs); ##]
707       #H; ninversion H; #; ndestruct;
708    ##|##*:nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #H1; ncases (XXz … H1); ##]
709        #H; ninversion H; #; ndestruct;##]
710 ##|#a c w; @; nnormalize; ##[*; ##[*; #; ndestruct; ##] #abs; ninversion abs; #; ndestruct;##]
711    *; ##[##2: #abs; ninversion abs; #; ndestruct; ##] *; #; ndestruct;
712 ##|#a c w; @; nnormalize; 
713    ##[ *; ##[ *; #defw; nrewrite > defw; #ca; @2;  nrewrite > (eqb_t … ca); @; ##]
714        #H; ninversion H; #; ndestruct;
715    ##| *; ##[ *; #; ndestruct; ##] #H; ninversion H; ##[##2,3,4,5,6: #; ndestruct]
716               #d defw defa; ndestruct; @1; @; //; nrewrite > (eqb_true S d d); //. ##]
717 ##|#r1 r2 H1 H2 a w; @;
718    ##[ #H; ncases (in_move_cat … H);
719       ##[ *; #w1; *; #w2; *; *; #defw w1m w2m;
720           ncases (H1 a w1); #H1w1; #_; nlapply (H1w1 w1m); #good; 
721           nrewrite > defw; @2; @2 (a::w1); //; ncases good; ##[ *; #; ndestruct] //.
722       ##|
723       ...
724 ##|
725 ##|
726 ##]
727 nqed.
728
729
730 notation > "x ↦* E" non associative with precedence 60 for @{move_star ? $x $E}.
731 nlet rec move_star (S : decidable) w E on w : bool × (pre S) ≝
732  match w with
733   [ nil ⇒ E
734   | cons x w' ⇒ w' ↦* (x ↦ \snd E)].
735
736 ndefinition in_moves ≝ λS:decidable.λw.λE:bool × (pre S). \fst(w ↦* E).
737
738 ncoinductive equiv (S:decidable) : bool × (pre S) → bool × (pre S) → Prop ≝
739  mk_equiv:
740   ∀E1,E2: bool × (pre S).
741    \fst E1  = \fst E2 →
742     (∀x. equiv S (x ↦ \snd E1) (x ↦ \snd E2)) →
743      equiv S E1 E2.
744
745 ndefinition NAT: decidable.
746  @ nat eqb; /2/.
747 nqed.
748
749 include "hints_declaration.ma".
750
751 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
752 unification hint 0 ≔ ; X ≟ NAT ⊢ carr X ≡ nat.
753
754 ninductive unit: Type[0] ≝ I: unit.
755
756 nlet corec foo_nop (b: bool):
757  equiv ?
758   〈 b, pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0))) 〉
759   〈 b, pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0) 〉 ≝ ?.
760  @; //; #x; ncases x
761   [ nnormalize in ⊢ (??%%); napply (foo_nop false)
762   | #y; ncases y
763      [ nnormalize in ⊢ (??%%); napply (foo_nop false)
764      | #w; nnormalize in ⊢ (??%%); napply (foo_nop false) ]##]
765 nqed.
766
767 (*
768 nlet corec foo (a: unit):
769  equiv NAT
770   (eclose NAT (pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0)))))
771   (eclose NAT (pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0)))
772 ≝ ?.
773  @;
774   ##[ nnormalize; //
775   ##| #x; ncases x
776        [ nnormalize in ⊢ (??%%);
777          nnormalize in foo: (? → ??%%);
778          @; //; #y; ncases y
779            [ nnormalize in ⊢ (??%%); napply foo_nop
780            | #y; ncases y
781               [ nnormalize in ⊢ (??%%);
782                 
783             ##| #z; nnormalize in ⊢ (??%%); napply foo_nop ]##]
784      ##| #y; nnormalize in ⊢ (??%%); napply foo_nop
785   ##]
786 nqed.
787 *)
788
789 ndefinition test1 : pre ? ≝ ❨ `0 | `1 ❩^* `0.
790 ndefinition test2 : pre ? ≝ ❨ (`0`1)^* `0 | (`0`1)^* `1 ❩.
791 ndefinition test3 : pre ? ≝ (`0 (`0`1)^* `1)^*.
792
793
794 nlemma foo: in_moves ? [0;0;1;0;1;1] (ɛ test3) = true.
795  nnormalize in match test3;
796  nnormalize;
797 //;
798 nqed.
799
800 (**********************************************************)
801
802 ninductive der (S: Type[0]) (a: S) : re S → re S → CProp[0] ≝
803    der_z: der S a (z S) (z S)
804  | der_e: der S a (e S) (z S)
805  | der_s1: der S a (s S a) (e ?)
806  | der_s2: ∀b. a ≠ b → der S a (s S b) (z S)
807  | der_c1: ∀e1,e2,e1',e2'. in_l S [] e1 → der S a e1 e1' → der S a e2 e2' →
808             der S a (c ? e1 e2) (o ? (c ? e1' e2) e2')
809  | der_c2: ∀e1,e2,e1'. Not (in_l S [] e1) → der S a e1 e1' →
810             der S a (c ? e1 e2) (c ? e1' e2)
811  | der_o: ∀e1,e2,e1',e2'. der S a e1 e1' → der S a e2 e2' →
812     der S a (o ? e1 e2) (o ? e1' e2').
813
814 nlemma eq_rect_CProp0_r:
815  ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (refl A a) → P x p.
816  #A; #a; #x; #p; ncases p; #P; #H; nassumption.
817 nqed.
818
819 nlemma append1: ∀A.∀a:A.∀l. [a] @ l = a::l. //. nqed.
820
821 naxiom in_l1: ∀S,r1,r2,w. in_l S [ ] r1 → in_l S w r2 → in_l S w (c S r1 r2).
822 (* #S; #r1; #r2; #w; nelim r1
823   [ #K; ninversion K
824   | #H1; #H2; napply (in_c ? []); //
825   | (* tutti casi assurdi *) *)
826
827 ninductive in_l' (S: Type[0]) : word S → re S → CProp[0] ≝
828    in_l_empty1: ∀E.in_l S [] E → in_l' S [] E 
829  | in_l_cons: ∀a,w,e,e'. in_l' S w e' → der S a e e' → in_l' S (a::w) e.
830
831 ncoinductive eq_re (S: Type[0]) : re S → re S → CProp[0] ≝
832    mk_eq_re: ∀E1,E2.
833     (in_l S [] E1 → in_l S [] E2) →
834     (in_l S [] E2 → in_l S [] E1) →
835     (∀a,E1',E2'. der S a E1 E1' → der S a E2 E2' → eq_re S E1' E2') →
836       eq_re S E1 E2.
837
838 (* serve il lemma dopo? *)
839 ntheorem eq_re_is_eq: ∀S.∀E1,E2. eq_re S E1 E2 → ∀w. in_l ? w E1 → in_l ? w E2.
840  #S; #E1; #E2; #H1; #w; #H2; nelim H2 in E2 H1 ⊢ %
841   [ #r; #K (* ok *)
842   | #a; #w; #R1; #R2; #K1; #K2; #K3; #R3; #K4; @2 R2; //; ncases K4;
843
844 (* IL VICEVERSA NON VALE *)
845 naxiom in_l_to_in_l: ∀S,w,E. in_l' S w E → in_l S w E.
846 (* #S; #w; #E; #H; nelim H
847   [ //
848   | #a; #w'; #r; #r'; #H1; (* e si cade qua sotto! *)
849   ]
850 nqed. *)
851
852 ntheorem der1: ∀S,a,e,e',w. der S a e e' → in_l S w e' → in_l S (a::w) e.
853  #S; #a; #E; #E'; #w; #H; nelim H
854   [##1,2: #H1; ninversion H1
855      [##1,8: #_; #K; (* non va ndestruct K; *) ncases (?:False); (* perche' due goal?*) /2/
856      |##2,9: #X; #Y; #K; ncases (?:False); /2/
857      |##3,10: #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
858      |##4,11: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
859      |##5,12: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
860      |##6,13: #x; #y; #K; ncases (?:False); /2/
861      |##7,14: #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/]
862 ##| #H1; ninversion H1
863      [ //
864      | #X; #Y; #K; ncases (?:False); /2/
865      | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
866      | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
867      | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
868      | #x; #y; #K; ncases (?:False); /2/
869      | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
870 ##| #H1; #H2; #H3; ninversion H3
871      [ #_; #K; ncases (?:False); /2/
872      | #X; #Y; #K; ncases (?:False); /2/
873      | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
874      | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
875      | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
876      | #x; #y; #K; ncases (?:False); /2/
877      | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
878 ##| #r1; #r2; #r1'; #r2'; #H1; #H2; #H3; #H4; #H5; #H6;
879
880 lemma