1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| The HELM team. *)
8 (* ||A|| http://helm.cs.unibo.it *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU General Public License Version 2 *)
13 (**************************************************************************)
15 include "datatypes/pairs.ma".
16 include "datatypes/bool.ma".
17 include "sets/sets.ma".
19 ninductive Admit : CProp[0] ≝ .
22 ninductive list (A:Type[0]) : Type[0] ≝
24 | cons: A -> list A -> list A.
26 nlet rec eq_list (A : setoid) (l1, l2 : list A) on l1 : CProp[0] ≝
28 [ nil ⇒ match l2 return λ_.CProp[0] with [ nil ⇒ ? | _ ⇒ ? ]
29 | cons x xs ⇒ match l2 with [ nil ⇒ ? | cons y ys ⇒ x = y ∧ eq_list ? xs ys]].
30 ##[ napply True|napply False|napply False]nqed.
32 ndefinition LIST : setoid → setoid.
33 #S; @(list S); @(eq_list S); ncases admit; nqed.
35 unification hint 0 ≔ S : setoid;
36 P1 ≟ refl ? (eq0 (LIST S)),
37 P2 ≟ sym ? (eq0 (LIST S)),
38 P3 ≟ trans ? (eq0 (LIST S)),
39 X ≟ mk_setoid (list S) (mk_equivalence_relation ? (eq_list S) P1 P2 P3),
41 (*-----------------------------------------------------------------------*) ⊢
44 notation "hvbox(hd break :: tl)"
45 right associative with precedence 47
48 notation "[ list0 x sep ; ]"
49 non associative with precedence 90
50 for ${fold right @'nil rec acc @{'cons $x $acc}}.
52 notation "hvbox(l1 break @ l2)"
53 right associative with precedence 47
54 for @{'append $l1 $l2 }.
56 interpretation "nil" 'nil = (nil ?).
57 interpretation "cons" 'cons hd tl = (cons ? hd tl).
59 nlet rec append A (l1: list A) l2 on l1 ≝
62 | cons hd tl ⇒ hd :: append A tl l2 ].
64 interpretation "append" 'append l1 l2 = (append ? l1 l2).
66 ntheorem append_nil: ∀A:setoid.∀l:list A.l @ [] = l.
67 #A;#l;nelim l;//; #a;#l1;#IH;nnormalize;/2/;nqed.
69 ndefinition associative ≝ λA:setoid.λf:A → A → A.∀x,y,z.f x (f y z) = f (f x y) z.
71 ninductive one : Type[0] ≝ unit : one.
74 λS:Type[2].λs:S.λT:Type[2].λt:T.λlock:one.
75 match lock return λ_.Type[2] with [ unit ⇒ T].
77 nlet rec lift (S:Type[2]) (s:S) (T:Type[2]) (t:T) (lock:one) on lock : force S s T t lock ≝
78 match lock return λlock.force S s T t lock with [ unit ⇒ t ].
80 ncoercion lift1 : ∀S:Type[1].∀s:S.∀T:Type[1].∀t:T.∀lock:one. force S s T t lock ≝ lift
81 on s : ? to force ?????.
83 ncoercion lift2 : ∀S:Type[2].∀s:S.∀T:Type[2].∀t:T.∀lock:one. force S s T t lock ≝ lift
84 on s : ? to force ?????.
86 unification hint 0 ≔ R : setoid;
87 TR ≟ setoid, MR ≟ (carr R), lock ≟ unit
88 (* ---------------------------------------- *) ⊢
89 setoid ≡ force ?(*Type[0]*) MR TR R lock.
91 unification hint 0 ≔ R : setoid1;
92 TR ≟ setoid1, MR ≟ (carr1 R), lock ≟ unit
93 (* ---------------------------------------- *) ⊢
94 setoid1 ≡ force ? MR TR R lock.
96 ntheorem associative_append: ∀A:setoid.associative (list A) (append A).
97 #A;#x;#y;#z;nelim x[//|#a;#x1;#H;nnormalize;/2/]nqed.
99 interpretation "iff" 'iff a b = (iff a b).
101 ninductive eq (A:Type[0]) (x:A) : A → CProp[0] ≝ refl: eq A x x.
103 nlemma eq_rect_Type0_r':
104 ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → Type[0]. P a (refl A a) → P x p.
105 #A; #a; #x; #p; ncases p; #P; #H; nassumption.
108 nlemma eq_rect_Type0_r:
109 ∀A.∀a.∀P: ∀x:A. eq ? x a → Type[0]. P a (refl A a) → ∀x.∀p:eq ? x a.P x p.
110 #A; #a; #P; #p; #x0; #p0; napply (eq_rect_Type0_r' ??? p0); nassumption.
113 nlemma eq_rect_CProp0_r':
114 ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (refl A a) → P x p.
115 #A; #a; #x; #p; ncases p; #P; #H; nassumption.
118 nlemma eq_rect_CProp0_r:
119 ∀A.∀a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (refl A a) → ∀x.∀p:eq ? x a.P x p.
120 #A; #a; #P; #p; #x0; #p0; napply (eq_rect_CProp0_r' ??? p0); nassumption.
123 notation < "a = b" non associative with precedence 45 for @{ 'eqpp $a $b}.
124 interpretation "bool eq" 'eqpp a b = (eq bool a b).
126 ndefinition BOOL : setoid.
127 @bool; @(eq bool); ncases admit.nqed.
129 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
130 alias id "refl" = "cic:/matita/ng/properties/relations/refl.fix(0,1,3)".
131 unification hint 0 ≔ ;
132 P1 ≟ refl ? (eq0 BOOL),
133 P2 ≟ sym ? (eq0 BOOL),
134 P3 ≟ trans ? (eq0 BOOL),
135 X ≟ mk_setoid bool (mk_equivalence_relation ? (eq bool) P1 P2 P3)
136 (*-----------------------------------------------------------------------*) ⊢
139 nrecord Alpha : Type[1] ≝ {
141 eqb: acarr → acarr → bool;
142 eqb_true: ∀x,y. (eqb x y = true) = (x = y)
145 notation "a == b" non associative with precedence 45 for @{ 'eqb $a $b }.
146 interpretation "eqb" 'eqb a b = (eqb ? a b).
148 ninductive re (S: Type[0]) : Type[0] ≝
152 | c: re S → re S → re S
153 | o: re S → re S → re S
156 naxiom eq_re : ∀S:Alpha.re S → re S → CProp[0].
157 ndefinition RE : Alpha → setoid.
158 #A; @(re A); @(eq_re A); ncases admit. nqed.
160 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
161 alias id "carr" = "cic:/matita/ng/sets/setoids/carr.fix(0,0,1)".
162 unification hint 0 ≔ A : Alpha;
163 P1 ≟ refl ? (eq0 (RE A)),
164 P2 ≟ sym ? (eq0 (RE A)),
165 P3 ≟ trans ? (eq0 (RE A)),
166 X ≟ mk_setoid (re A) (mk_equivalence_relation ? (eq_re A) P1 P2 P3),
168 (*-----------------------------------------------------------------------*) ⊢
171 notation < "a \sup ⋇" non associative with precedence 90 for @{ 'pk $a}.
172 notation > "a ^ *" non associative with precedence 90 for @{ 'pk $a}.
173 interpretation "star" 'pk a = (k ? a).
174 interpretation "or" 'plus a b = (o ? a b).
176 notation "a · b" non associative with precedence 60 for @{ 'pc $a $b}.
177 interpretation "cat" 'pc a b = (c ? a b).
179 (* to get rid of \middot *)
180 ncoercion c : ∀S.∀p:re S. re S → re S ≝ c on _p : re ? to ∀_:?.?.
182 notation < "a" non associative with precedence 90 for @{ 'ps $a}.
183 notation > "` term 90 a" non associative with precedence 90 for @{ 'ps $a}.
184 interpretation "atom" 'ps a = (s ? a).
186 notation "ϵ" non associative with precedence 90 for @{ 'epsilon }.
187 interpretation "epsilon" 'epsilon = (e ?).
189 notation "0" non associative with precedence 90 for @{ 'empty }.
190 interpretation "empty" 'empty = (z ?).
192 notation > "'lang' S" non associative with precedence 90 for @{ Ω^(list $S) }.
193 notation > "'Elang' S" non associative with precedence 90 for @{ 𝛀^(list $S) }.
195 nlet rec flatten S (l : list (list S)) on l : list S ≝
196 match l with [ nil ⇒ [ ] | cons w tl ⇒ w @ flatten ? tl ].
198 nlet rec conjunct S (l : list (list S)) (L : lang S) on l: CProp[0] ≝
199 match l with [ nil ⇒ True | cons w tl ⇒ w ∈ L ∧ conjunct ? tl L ].
202 ndefinition empty_set : ∀A.Ω^A ≝ λA.{ w | False }.
203 notation "∅" non associative with precedence 90 for @{'emptyset}.
204 interpretation "empty set" 'emptyset = (empty_set ?).
207 notation "{}" non associative with precedence 90 for @{'empty_lang}.
208 interpretation "empty lang" 'empty_lang = (empty_lang ?).
211 ndefinition sing_lang : ∀A:setoid.∀x:A.Ω^A ≝ λS.λx.{ w | x = w }.
212 interpretation "sing lang" 'singl x = (sing_lang ? x).
214 interpretation "subset construction with type" 'comprehension t \eta.x =
217 ndefinition cat : ∀A:setoid.∀l1,l2:lang A.lang A ≝
218 λS.λl1,l2.{ w ∈ list S | ∃w1,w2.w =_0 w1 @ w2 ∧ w1 ∈ l1 ∧ w2 ∈ l2}.
219 interpretation "cat lang" 'pc a b = (cat ? a b).
221 ndefinition star : ∀A:setoid.∀l:lang A.lang A ≝
222 λS.λl.{ w ∈ list S | ∃lw.flatten ? lw = w ∧ conjunct ? lw l}.
223 interpretation "star lang" 'pk l = (star ? l).
225 notation > "𝐋 term 70 E" non associative with precedence 75 for @{L_re ? $E}.
226 nlet rec L_re (S : Alpha) (r : re S) on r : lang S ≝
231 | c r1 r2 ⇒ 𝐋 r1 · 𝐋 r2
232 | o r1 r2 ⇒ 𝐋 r1 ∪ 𝐋 r2
234 notation "𝐋 term 70 E" non associative with precedence 75 for @{'L_re $E}.
235 interpretation "in_l" 'L_re E = (L_re ? E).
237 notation "a || b" left associative with precedence 30 for @{'orb $a $b}.
238 ndefinition orb ≝ λa,b:bool. match a with [ true ⇒ true | _ ⇒ b ].
239 interpretation "orb" 'orb a b = (orb a b).
241 ninductive pitem (S: Type[0]) : Type[0] ≝
246 | pc: pitem S → pitem S → pitem S
247 | po: pitem S → pitem S → pitem S
248 | pk: pitem S → pitem S.
250 ndefinition pre ≝ λS.pitem S × bool.
252 notation "\fst term 90 x" non associative with precedence 90 for @{'fst $x}.
253 interpretation "fst" 'fst x = (fst ? ? x).
254 notation > "\snd term 90 x" non associative with precedence 90 for @{'snd $x}.
255 interpretation "snd" 'snd x = (snd ? ? x).
257 interpretation "pstar" 'pk a = (pk ? a).
258 interpretation "por" 'plus a b = (po ? a b).
259 interpretation "pcat" 'pc a b = (pc ? a b).
260 notation < ".a" non associative with precedence 90 for @{ 'pp $a}.
261 notation > "`. term 90 a" non associative with precedence 90 for @{ 'pp $a}.
262 interpretation "ppatom" 'pp a = (pp ? a).
263 (* to get rid of \middot *)
264 ncoercion pc : ∀S.∀p:pitem S. pitem S → pitem S ≝ pc on _p : pitem ? to ∀_:?.?.
265 interpretation "patom" 'ps a = (ps ? a).
266 interpretation "pepsilon" 'epsilon = (pe ?).
267 interpretation "pempty" 'empty = (pz ?).
269 notation > "|term 19 e|" non associative with precedence 70 for @{forget ? $e}.
270 nlet rec forget (S: Alpha) (l : pitem S) on l: re S ≝
276 | pc E1 E2 ⇒ (|E1| · |E2|)
277 | po E1 E2 ⇒ (|E1| + |E2|)
279 notation < "|term 19 e|" non associative with precedence 70 for @{'forget $e}.
280 interpretation "forget" 'forget a = (forget ? a).
282 notation > "𝐋\p\ term 70 E" non associative with precedence 75 for @{L_pi ? $E}.
283 nlet rec L_pi (S : Alpha) (r : pitem S) on r : lang S ≝
289 | pc r1 r2 ⇒ 𝐋\p\ r1 · 𝐋 |r2| ∪ 𝐋\p\ r2
290 | po r1 r2 ⇒ 𝐋\p\ r1 ∪ 𝐋\p\ r2
291 | pk r1 ⇒ 𝐋\p\ r1 · 𝐋 (|r1|^* ) ].
292 notation > "𝐋\p term 70 E" non associative with precedence 75 for @{'L_pi $E}.
293 notation "𝐋\sub(\p) term 70 E" non associative with precedence 75 for @{'L_pi $E}.
294 interpretation "in_pl" 'L_pi E = (L_pi ? E).
296 unification hint 0 ≔ S,a,b;
298 (* -------------------------------------------- *) ⊢
299 eq_list S a b ≡ eq_rel (list S) (eq0 R) a b.
301 notation > "B ⇒_0 C" right associative with precedence 72 for @{'umorph0 $B $C}.
302 notation > "B ⇒_1 C" right associative with precedence 72 for @{'umorph1 $B $C}.
303 notation "B ⇒\sub 0 C" right associative with precedence 72 for @{'umorph0 $B $C}.
304 notation "B ⇒\sub 1 C" right associative with precedence 72 for @{'umorph1 $B $C}.
306 interpretation "unary morphism 0" 'umorph0 A B = (unary_morphism A B).
307 interpretation "unary morphism 1" 'umorph1 A B = (unary_morphism1 A B).
309 ncoercion setoid1_of_setoid : ∀s:setoid. setoid1 ≝ setoid1_of_setoid on _s: setoid to setoid1.
311 nlemma exists_is_morph: (* BUG *) ∀S,T:setoid.∀P: S ⇒_1 (T ⇒_1 (CProp[0]:?)).
312 ∀y,z:S.y =_0 z → (Ex T (P y)) = (Ex T (P z)).
314 ##[ *; #x Px; @x; alias symbol "refl" (instance 4) = "refl".
315 alias symbol "prop2" (instance 2) = "prop21".
316 napply (. E^-1‡#); napply Px;
317 ##| *; #x Px; @x; napply (. E‡#); napply Px;##]
320 ndefinition ex_morph : ∀S:setoid. (S ⇒_1 CPROP) ⇒_1 CPROP.
321 #S; @; ##[ #P; napply (Ex ? P); ##| #P1 P2 E; @;
322 *; #x; #H; @ x; nlapply (E x x ?); //; *; /2/;
325 nlemma d : ∀S:setoid1. ∀ee: S ⇒_1 S ⇒_1 CPROP.
326 ∀x,y:S.x =_1 y → (Ex1 S (λw.ee x w)) =_1 (Ex1 S (λw.ee y w)).
327 let form ≝ comp1_unary_morphisms ??? (ex_morph (list S)) ee in
330 nletin F ≝ (comp1_unary_morphisms ??? (ex_morph (list S)) ee);
333 nchange in E with (eq_rel1 ? (eq1 (setoid1_of_setoid (LIST S))) x y);
335 ncheck (exists_is_morph (LIST S) (LIST S) ? ?? (E‡#)).
336 nletin xxx ≝ (exists_is_morph); (LIST S)); (LIST S) ee x y E);
338 nchange with (F x = F y);
339 nchange in E with (eq_rel1 ? (eq1 (setoid1_of_setoid (LIST S))) x y);
348 Σ(λx.(#‡E)‡#) : ∃x.x = w ∧ m → ∃x.x = w2 ∧ m
349 λx.(#‡E)‡# : ∀x.x = w ∧ m → x = w2 ∧ m
355 ------------------------------
356 ex (λx.g w x) ==?== fun11 F w
358 x ⊢ fun11 ?h ≟ λw. ?g w x
359 ?G ≟ morphism_leibniz (T → S) ∘ ?h
360 ------------------------------
361 (λw. (λx:T.?g w x)) ==?== fun11 ?G
364 x ⊢ fun11 ?h ==?== λw. eq x w ∧ m [w]
365 (λw,x.eq x w ∧ m[w]) ==?== fun11 ?G
366 ex (λx.?g w x) ==?== ex (λx.x = w ∧ m[w])
368 ndefinition ex_morph : ∀S:setoid. (S ⇒_1 CPROP) ⇒_1 CPROP.
369 #S; @; ##[ #P; napply (Ex ? P); ##| ncases admit. ##] nqed.
371 ndefinition ex_morph1 : ∀S:setoid. (S ⇒_1 CPROP) ⇒_1 CPROP.
372 #S; @; ##[ #P; napply (Ex ? (λx.P); ##| ncases admit. ##] nqed.
376 ∀ee: (setoid1_of_setoid (list S)) ⇒_1 (setoid1_of_setoid (list S)) ⇒_1 CPROP.
378 let form ≝ comp1_unary_morphisms ??? (ex_morph (list S)) ee in
381 nletin F ≝ (comp1_unary_morphisms ??? (ex_morph (list S)) ee);
385 nchange with (F x = F y);
386 nchange in E with (eq_rel1 ? (eq1 (setoid1_of_setoid (LIST S))) x y);
392 nlemma d : ∀S:Alpha.∀ee: (setoid1_of_setoid (list S)) ⇒_1 (setoid1_of_setoid (list S)) ⇒_1 CPROP.∀x,y:list S.x = y →
393 let form ≝ comp1_unary_morphisms ??? (ex_morph (list S)) ee in
396 nletin F ≝ (comp1_unary_morphisms ??? (ex_morph (list S)) ee);
400 nchange with (F x = F y);
401 nchange in E with (eq_rel1 ? (eq1 (setoid1_of_setoid (LIST S))) x y);
407 nlemma d : ∀S:Alpha.(setoid1_of_setoid (list S)) ⇒_1 CPROP.
408 #S; napply (comp1_unary_morphisms ??? (ex_morph (list S)) ?);
414 ndefinition comp_ex : ∀X,S,T,K.∀P:X ⇒_1 (S ⇒_1 T).∀Pc : (S ⇒_1 T) ⇒_1 K. X ⇒_1 K.
417 ndefinition L_pi_ext : ∀S:Alpha.∀r:pitem S.Elang S.
418 #S r; @(𝐋\p r); #w1 w2 E; nelim r; /2/;
419 ##[ #x; @; #H; ##[ nchange in H ⊢ % with ([?]=?); napply ((.= H) E)]
420 nchange in H ⊢ % with ([?]=?); napply ((.= H) E^-1);
422 nchange in match (w1 ∈ 𝐋\p (?·?)) with ((∃_.?)∨?);
424 napply (.= (Eexists ?? ? w1 w2 E)‡#);
427 nchange in match (w2 ∈ 𝐋\p (?·?)) with (?∨?);
431 //; napply (trans ?? ??? H E);
432 napply (trans (list S) (eq0 (LIST S)) ? [?] ?(*w1 [x] w2*) H E);
433 nlapply (trans (list S) (eq0 (LIST S))).
435 napply (.= H); nnormalize; nlapply (trans ? [x] w1 w2 E H); napply (.= ?) [napply (w1 = [x])] ##[##2: napply #; napply sym1; napply refl1 ]
437 ndefinition epsilon ≝
438 λS:Alpha.λb.match b return λ_.lang S with [ true ⇒ { [ ] } | _ ⇒ ∅ ].
440 interpretation "epsilon" 'epsilon = (epsilon ?).
441 notation < "ϵ b" non associative with precedence 90 for @{'app_epsilon $b}.
442 interpretation "epsilon lang" 'app_epsilon b = (epsilon ? b).
444 ndefinition L_pr ≝ λS : Alpha.λp:pre S. 𝐋\p\ (\fst p) ∪ ϵ (\snd p).
446 interpretation "L_pr" 'L_pi E = (L_pr ? E).
448 nlemma append_eq_nil : ∀S:setoid.∀w1,w2:list S. w1 @ w2 = [ ] → w1 = [ ].
449 #S w1; ncases w1; //. nqed.
452 nlemma epsilon_in_true : ∀S:Alpha.∀e:pre S. [ ] ∈ 𝐋\p e = (\snd e = true).
453 #S r; ncases r; #e b; @; ##[##2: #H; nrewrite > H; @2; /2/; ##] ncases b;//;
454 *; ##[##2:*] nelim e;
455 ##[ ##1,2: *; ##| #c; *; ##| #c; *| ##7: #p H;
456 ##| #r1 r2 H G; *; ##[##2: nassumption; ##]
457 ##| #r1 r2 H1 H2; *; /2/ by {}]
458 *; #w1; *; #w2; *; *;
459 ##[ #defw1 H1 foo; napply H; napply (. #‡#); (append_eq_nil … defw1)^-1‡#);
461 nrewrite > (append_eq_nil ? … w1 w2 …); /3/ by {};//;
464 nlemma not_epsilon_lp : ∀S.∀e:pitem S. ¬ (𝐋\p e [ ]).
465 #S e; nelim e; nnormalize; /2/ by nmk;
466 ##[ #; @; #; ndestruct;
467 ##| #r1 r2 n1 n2; @; *; /2/; *; #w1; *; #w2; *; *; #H;
468 nrewrite > (append_eq_nil …H…); /2/;
469 ##| #r1 r2 n1 n2; @; *; /2/;
470 ##| #r n; @; *; #w1; *; #w2; *; *; #H;
471 nrewrite > (append_eq_nil …H…); /2/;##]
474 ndefinition lo ≝ λS:Alpha.λa,b:pre S.〈\fst a + \fst b,\snd a || \snd b〉.
475 notation "a ⊕ b" left associative with precedence 60 for @{'oplus $a $b}.
476 interpretation "oplus" 'oplus a b = (lo ? a b).
478 ndefinition lc ≝ λS:Alpha.λbcast:∀S:Alpha.∀E:pitem S.pre S.λa,b:pre S.
479 match a with [ mk_pair e1 b1 ⇒
481 [ false ⇒ 〈e1 · \fst b, \snd b〉
482 | true ⇒ 〈e1 · \fst (bcast ? (\fst b)),\snd b || \snd (bcast ? (\fst b))〉]].
484 notation < "a ⊙ b" left associative with precedence 60 for @{'lc $op $a $b}.
485 interpretation "lc" 'lc op a b = (lc ? op a b).
486 notation > "a ⊙ b" left associative with precedence 60 for @{'lc eclose $a $b}.
488 ndefinition lk ≝ λS:Alpha.λbcast:∀S:Alpha.∀E:pitem S.pre S.λa:pre S.
489 match a with [ mk_pair e1 b1 ⇒
491 [ false ⇒ 〈e1^*, false〉
492 | true ⇒ 〈(\fst (bcast ? e1))^*, true〉]].
494 notation < "a \sup ⊛" non associative with precedence 90 for @{'lk $op $a}.
495 interpretation "lk" 'lk op a = (lk ? op a).
496 notation > "a^⊛" non associative with precedence 90 for @{'lk eclose $a}.
498 notation > "•" non associative with precedence 60 for @{eclose ?}.
499 nlet rec eclose (S: Alpha) (E: pitem S) on E : pre S ≝
503 | ps x ⇒ 〈 `.x, false 〉
504 | pp x ⇒ 〈 `.x, false 〉
505 | po E1 E2 ⇒ •E1 ⊕ •E2
506 | pc E1 E2 ⇒ •E1 ⊙ 〈 E2, false 〉
507 | pk E ⇒ 〈(\fst (•E))^*,true〉].
508 notation < "• x" non associative with precedence 60 for @{'eclose $x}.
509 interpretation "eclose" 'eclose x = (eclose ? x).
510 notation > "• x" non associative with precedence 60 for @{'eclose $x}.
512 ndefinition reclose ≝ λS:Alpha.λp:pre S.let p' ≝ •\fst p in 〈\fst p',\snd p || \snd p'〉.
513 interpretation "reclose" 'eclose x = (reclose ? x).
515 ndefinition eq_f1 ≝ λS.λa,b:word S → Prop.∀w.a w ↔ b w.
516 notation > "A =1 B" non associative with precedence 45 for @{'eq_f1 $A $B}.
517 notation "A =\sub 1 B" non associative with precedence 45 for @{'eq_f1 $A $B}.
518 interpretation "eq f1" 'eq_f1 a b = (eq_f1 ? a b).
520 naxiom extP : ∀S.∀p,q:word S → Prop.(p =1 q) → p = q.
522 nlemma epsilon_or : ∀S:Alpha.∀b1,b2. ϵ(b1 || b2) = ϵ b1 ∪ ϵ b2. ##[##2: napply S]
523 #S b1 b2; ncases b1; ncases b2; napply extP; #w; nnormalize; @; /2/; *; //; *;
526 nlemma cupA : ∀S.∀a,b,c:word S → Prop.a ∪ b ∪ c = a ∪ (b ∪ c).
527 #S a b c; napply extP; #w; nnormalize; @; *; /3/; *; /3/; nqed.
529 nlemma cupC : ∀S. ∀a,b:word S → Prop.a ∪ b = b ∪ a.
530 #S a b; napply extP; #w; @; *; nnormalize; /2/; nqed.
533 nlemma oplus_cup : ∀S:Alpha.∀e1,e2:pre S.𝐋\p (e1 ⊕ e2) = 𝐋\p e1 ∪ 𝐋\p e2.
534 #S r1; ncases r1; #e1 b1 r2; ncases r2; #e2 b2;
535 nwhd in ⊢ (??(??%)?);
536 nchange in ⊢(??%?) with (𝐋\p (e1 + e2) ∪ ϵ (b1 || b2));
537 nchange in ⊢(??(??%?)?) with (𝐋\p (e1) ∪ 𝐋\p (e2));
538 nrewrite > (epsilon_or S …); nrewrite > (cupA S (𝐋\p e1) …);
539 nrewrite > (cupC ? (ϵ b1) …); nrewrite < (cupA S (𝐋\p e2) …);
540 nrewrite > (cupC ? ? (ϵ b1) …); nrewrite < (cupA …); //;
544 ∀S.∀e1,e2:pitem S.∀b2. 〈e1,true〉 ⊙ 〈e2,b2〉 = 〈e1 · \fst (•e2),b2 || \snd (•e2)〉.
545 #S e1 e2 b2; nnormalize; ncases (•e2); //; nqed.
547 nlemma LcatE : ∀S.∀e1,e2:pitem S.𝐋\p (e1 · e2) = 𝐋\p e1 · 𝐋 .|e2| ∪ 𝐋\p e2. //; nqed.
549 nlemma cup_dotD : ∀S.∀p,q,r:word S → Prop.(p ∪ q) · r = (p · r) ∪ (q · r).
550 #S p q r; napply extP; #w; nnormalize; @;
551 ##[ *; #x; *; #y; *; *; #defw; *; /7/ by or_introl, or_intror, ex_intro, conj;
552 ##| *; *; #x; *; #y; *; *; /7/ by or_introl, or_intror, ex_intro, conj; ##]
555 nlemma cup0 :∀S.∀p:word S → Prop.p ∪ {} = p.
556 #S p; napply extP; #w; nnormalize; @; /2/; *; //; *; nqed.
558 nlemma erase_dot : ∀S.∀e1,e2:pitem S.𝐋 .|e1 · e2| = 𝐋 .|e1| · 𝐋 .|e2|.
559 #S e1 e2; napply extP; nnormalize; #w; @; *; #w1; *; #w2; *; *; /7/ by ex_intro, conj;
562 nlemma erase_plus : ∀S.∀e1,e2:pitem S.𝐋 .|e1 + e2| = 𝐋 .|e1| ∪ 𝐋 .|e2|.
563 #S e1 e2; napply extP; nnormalize; #w; @; *; /4/ by or_introl, or_intror; nqed.
565 nlemma erase_star : ∀S.∀e1:pitem S.𝐋 .|e1|^* = 𝐋 .|e1^*|. //; nqed.
567 ndefinition substract := λS.λp,q:word S → Prop.λw.p w ∧ ¬ q w.
568 interpretation "substract" 'minus a b = (substract ? a b).
570 nlemma cup_sub: ∀S.∀a,b:word S → Prop. ¬ (a []) → a ∪ (b - {[]}) = (a ∪ b) - {[]}.
571 #S a b c; napply extP; #w; nnormalize; @; *; /4/; *; /4/; nqed.
573 nlemma sub0 : ∀S.∀a:word S → Prop. a - {} = a.
574 #S a; napply extP; #w; nnormalize; @; /3/; *; //; nqed.
576 nlemma subK : ∀S.∀a:word S → Prop. a - a = {}.
577 #S a; napply extP; #w; nnormalize; @; *; /2/; nqed.
579 nlemma subW : ∀S.∀a,b:word S → Prop.∀w.(a - b) w → a w.
580 #S a b w; nnormalize; *; //; nqed.
582 nlemma erase_bull : ∀S.∀a:pitem S. .|\fst (•a)| = .|a|.
583 #S a; nelim a; // by {};
584 ##[ #e1 e2 IH1 IH2; nchange in ⊢ (???%) with (.|e1| · .|e2|);
585 nrewrite < IH1; nrewrite < IH2;
586 nchange in ⊢ (??(??%)?) with (\fst (•e1 ⊙ 〈e2,false〉));
587 ncases (•e1); #e3 b; ncases b; nnormalize;
588 ##[ ncases (•e2); //; ##| nrewrite > IH2; //]
589 ##| #e1 e2 IH1 IH2; nchange in ⊢ (???%) with (.|e1| + .|e2|);
590 nrewrite < IH2; nrewrite < IH1;
591 nchange in ⊢ (??(??%)?) with (\fst (•e1 ⊕ •e2));
592 ncases (•e1); ncases (•e2); //;
593 ##| #e IH; nchange in ⊢ (???%) with (.|e|^* ); nrewrite < IH;
594 nchange in ⊢ (??(??%)?) with (\fst (•e))^*; //; ##]
597 nlemma eta_lp : ∀S.∀p:pre S.𝐋\p p = 𝐋\p 〈\fst p, \snd p〉.
598 #S p; ncases p; //; nqed.
600 nlemma epsilon_dot: ∀S.∀p:word S → Prop. {[]} · p = p.
601 #S e; napply extP; #w; nnormalize; @; ##[##2: #Hw; @[]; @w; /3/; ##]
602 *; #w1; *; #w2; *; *; #defw defw1 Hw2; nrewrite < defw; nrewrite < defw1;
605 (* theorem 16: 1 → 3 *)
606 nlemma odot_dot_aux : ∀S.∀e1,e2: pre S.
607 𝐋\p (•(\fst e2)) = 𝐋\p (\fst e2) ∪ 𝐋 .|\fst e2| →
608 𝐋\p (e1 ⊙ e2) = 𝐋\p e1 · 𝐋 .|\fst e2| ∪ 𝐋\p e2.
609 #S e1 e2 th1; ncases e1; #e1' b1'; ncases b1';
610 ##[ nwhd in ⊢ (??(??%)?); nletin e2' ≝ (\fst e2); nletin b2' ≝ (\snd e2);
611 nletin e2'' ≝ (\fst (•(\fst e2))); nletin b2'' ≝ (\snd (•(\fst e2)));
612 nchange in ⊢ (??%?) with (?∪?);
613 nchange in ⊢ (??(??%?)?) with (?∪?);
614 nchange in match (𝐋\p 〈?,?〉) with (?∪?);
615 nrewrite > (epsilon_or …); nrewrite > (cupC ? (ϵ ?)…);
616 nrewrite > (cupA …);nrewrite < (cupA ?? (ϵ?)…);
617 nrewrite > (?: 𝐋\p e2'' ∪ ϵ b2'' = 𝐋\p e2' ∪ 𝐋 .|e2'|); ##[##2:
618 nchange with (𝐋\p 〈e2'',b2''〉 = 𝐋\p e2' ∪ 𝐋 .|e2'|);
619 ngeneralize in match th1;
620 nrewrite > (eta_lp…); #th1; nrewrite > th1; //;##]
621 nrewrite > (eta_lp ? e2);
622 nchange in match (𝐋\p 〈\fst e2,?〉) with (𝐋\p e2'∪ ϵ b2');
623 nrewrite > (cup_dotD …); nrewrite > (epsilon_dot…);
624 nrewrite > (cupC ? (𝐋\p e2')…); nrewrite > (cupA…);nrewrite > (cupA…);
625 nrewrite < (erase_bull S e2') in ⊢ (???(??%?)); //;
626 ##| ncases e2; #e2' b2'; nchange in match (〈e1',false〉⊙?) with 〈?,?〉;
627 nchange in match (𝐋\p ?) with (?∪?);
628 nchange in match (𝐋\p (e1'·?)) with (?∪?);
629 nchange in match (𝐋\p 〈e1',?〉) with (?∪?);
631 nrewrite > (cupA…); //;##]
634 nlemma sub_dot_star :
635 ∀S.∀X:word S → Prop.∀b. (X - ϵ b) · X^* ∪ {[]} = X^*.
636 #S X b; napply extP; #w; @;
637 ##[ *; ##[##2: nnormalize; #defw; nrewrite < defw; @[]; @; //]
638 *; #w1; *; #w2; *; *; #defw sube; *; #lw; *; #flx cj;
639 @ (w1 :: lw); nrewrite < defw; nrewrite < flx; @; //;
640 @; //; napply (subW … sube);
641 ##| *; #wl; *; #defw Pwl; nrewrite < defw; nelim wl in Pwl; ##[ #_; @2; //]
642 #w' wl' IH; *; #Pw' IHp; nlapply (IH IHp); *;
643 ##[ *; #w1; *; #w2; *; *; #defwl' H1 H2;
644 @; ncases b in H1; #H1;
645 ##[##2: nrewrite > (sub0…); @w'; @(w1@w2);
646 nrewrite > (associative_append ? w' w1 w2);
647 nrewrite > defwl'; @; ##[@;//] @(wl'); @; //;
648 ##| ncases w' in Pw';
649 ##[ #ne; @w1; @w2; nrewrite > defwl'; @; //; @; //;
650 ##| #x xs Px; @(x::xs); @(w1@w2);
651 nrewrite > (defwl'); @; ##[@; //; @; //; @; nnormalize; #; ndestruct]
653 ##| #wlnil; nchange in match (flatten ? (w'::wl')) with (w' @ flatten ? wl');
654 nrewrite < (wlnil); nrewrite > (append_nil…); ncases b;
655 ##[ ncases w' in Pw'; /2/; #x xs Pxs; @; @(x::xs); @([]);
656 nrewrite > (append_nil…); @; ##[ @; //;@; //; nnormalize; @; #; ndestruct]
658 ##| @; @w'; @[]; nrewrite > (append_nil…); @; ##[##2: @[]; @; //]
659 @; //; @; //; @; *;##]##]##]
663 alias symbol "pc" (instance 13) = "cat lang".
664 alias symbol "in_pl" (instance 23) = "in_pl".
665 alias symbol "in_pl" (instance 5) = "in_pl".
666 alias symbol "eclose" (instance 21) = "eclose".
667 ntheorem bull_cup : ∀S:Alpha. ∀e:pitem S. 𝐋\p (•e) = 𝐋\p e ∪ 𝐋 .|e|.
669 ##[ #a; napply extP; #w; nnormalize; @; *; /3/ by or_introl, or_intror;
670 ##| #a; napply extP; #w; nnormalize; @; *; /3/ by or_introl; *;
672 nchange in ⊢ (??(??(%))?) with (•e1 ⊙ 〈e2,false〉);
673 nrewrite > (odot_dot_aux S (•e1) 〈e2,false〉 IH2);
674 nrewrite > (IH1 …); nrewrite > (cup_dotD …);
675 nrewrite > (cupA …); nrewrite > (cupC ?? (𝐋\p ?) …);
676 nchange in match (𝐋\p 〈?,?〉) with (𝐋\p e2 ∪ {}); nrewrite > (cup0 …);
677 nrewrite < (erase_dot …); nrewrite < (cupA …); //;
679 nchange in match (•(?+?)) with (•e1 ⊕ •e2); nrewrite > (oplus_cup …);
680 nrewrite > (IH1 …); nrewrite > (IH2 …); nrewrite > (cupA …);
681 nrewrite > (cupC ? (𝐋\p e2)…);nrewrite < (cupA ??? (𝐋\p e2)…);
682 nrewrite > (cupC ?? (𝐋\p e2)…); nrewrite < (cupA …);
683 nrewrite < (erase_plus …); //.
684 ##| #e; nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e)); #IH;
685 nchange in match (𝐋\p ?) with (𝐋\p 〈e'^*,true〉);
686 nchange in match (𝐋\p ?) with (𝐋\p (e'^* ) ∪ {[ ]});
687 nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 .|e'|^* );
688 nrewrite > (erase_bull…e);
689 nrewrite > (erase_star …);
690 nrewrite > (?: 𝐋\p e' = 𝐋\p e ∪ (𝐋 .|e| - ϵ b')); ##[##2:
691 nchange in IH : (??%?) with (𝐋\p e' ∪ ϵ b'); ncases b' in IH;
692 ##[ #IH; nrewrite > (cup_sub…); //; nrewrite < IH;
693 nrewrite < (cup_sub…); //; nrewrite > (subK…); nrewrite > (cup0…);//;
694 ##| nrewrite > (sub0 …); #IH; nrewrite < IH; nrewrite > (cup0 …);//; ##]##]
695 nrewrite > (cup_dotD…); nrewrite > (cupA…);
696 nrewrite > (?: ((?·?)∪{[]} = 𝐋 .|e^*|)); //;
697 nchange in match (𝐋 .|e^*|) with ((𝐋. |e|)^* ); napply sub_dot_star;##]
702 ∀S.∀e1,e2: pre S. 𝐋\p (e1 ⊙ e2) = 𝐋\p e1 · 𝐋 .|\fst e2| ∪ 𝐋\p e2.
703 #S e1 e2; napply odot_dot_aux; napply (bull_cup S (\fst e2)); nqed.
705 nlemma dot_star_epsilon : ∀S.∀e:re S.𝐋 e · 𝐋 e^* ∪ {[]} = 𝐋 e^*.
706 #S e; napply extP; #w; nnormalize; @;
707 ##[ *; ##[##2: #H; nrewrite < H; @[]; /3/] *; #w1; *; #w2;
708 *; *; #defw Hw1; *; #wl; *; #defw2 Hwl; @(w1 :: wl);
709 nrewrite < defw; nrewrite < defw2; @; //; @;//;
710 ##| *; #wl; *; #defw Hwl; ncases wl in defw Hwl; ##[#defw; #; @2; nrewrite < defw; //]
711 #x xs defw; *; #Hx Hxs; @; @x; @(flatten ? xs); nrewrite < defw;
715 nlemma nil_star : ∀S.∀e:re S. [ ] ∈ e^*.
716 #S e; @[]; /2/; nqed.
718 nlemma cupID : ∀S.∀l:word S → Prop.l ∪ l = l.
719 #S l; napply extP; #w; @; ##[*]//; #; @; //; nqed.
721 nlemma cup_star_nil : ∀S.∀l:word S → Prop. l^* ∪ {[]} = l^*.
722 #S a; napply extP; #w; @; ##[*; //; #H; nrewrite < H; @[]; @; //] #;@; //;nqed.
724 nlemma rcanc_sing : ∀S.∀A,C:word S → Prop.∀b:word S .
725 ¬ (A b) → A ∪ { (b) } = C → A = C - { (b) }.
726 #S A C b nbA defC; nrewrite < defC; napply extP; #w; @;
727 ##[ #Aw; /3/| *; *; //; #H nH; ncases nH; #abs; nlapply (abs H); *]
731 nlemma star_dot: ∀S.∀e:pre S. 𝐋\p (e^⊛) = 𝐋\p e · (𝐋 .|\fst e|)^*.
732 #S p; ncases p; #e b; ncases b;
733 ##[ nchange in match (〈e,true〉^⊛) with 〈?,?〉;
734 nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e));
735 nchange in ⊢ (??%?) with (?∪?);
736 nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 .|e'|^* );
737 nrewrite > (?: 𝐋\p e' = 𝐋\p e ∪ (𝐋 .|e| - ϵ b' )); ##[##2:
738 nlapply (bull_cup ? e); #bc;
739 nchange in match (𝐋\p (•e)) in bc with (?∪?);
740 nchange in match b' in bc with b';
741 ncases b' in bc; ##[##2: nrewrite > (cup0…); nrewrite > (sub0…); //]
742 nrewrite > (cup_sub…); ##[napply rcanc_sing] //;##]
743 nrewrite > (cup_dotD…); nrewrite > (cupA…);nrewrite > (erase_bull…);
744 nrewrite > (sub_dot_star…);
745 nchange in match (𝐋\p 〈?,?〉) with (?∪?);
746 nrewrite > (cup_dotD…); nrewrite > (epsilon_dot…); //;
747 ##| nwhd in match (〈e,false〉^⊛); nchange in match (𝐋\p 〈?,?〉) with (?∪?);
749 nchange in ⊢ (??%?) with (𝐋\p e · 𝐋 .|e|^* );
750 nrewrite < (cup0 ? (𝐋\p e)); //;##]
753 nlet rec pre_of_re (S : Alpha) (e : re S) on e : pitem S ≝
758 | c e1 e2 ⇒ pc ? (pre_of_re ? e1) (pre_of_re ? e2)
759 | o e1 e2 ⇒ po ? (pre_of_re ? e1) (pre_of_re ? e2)
760 | k e1 ⇒ pk ? (pre_of_re ? e1)].
762 nlemma notFalse : ¬False. @; //; nqed.
764 nlemma dot0 : ∀S.∀A:word S → Prop. {} · A = {}.
765 #S A; nnormalize; napply extP; #w; @; ##[##2: *]
766 *; #w1; *; #w2; *; *; //; nqed.
768 nlemma Lp_pre_of_re : ∀S.∀e:re S. 𝐋\p (pre_of_re ? e) = {}.
769 #S e; nelim e; ##[##1,2,3: //]
770 ##[ #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1 e2))) with (?∪?);
771 nrewrite > H1; nrewrite > H2; nrewrite > (dot0…); nrewrite > (cupID…);//
772 ##| #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1+e2))) with (?∪?);
773 nrewrite > H1; nrewrite > H2; nrewrite > (cupID…); //
774 ##| #e1 H1; nchange in match (𝐋\p (pre_of_re S (e1^* ))) with (𝐋\p (pre_of_re ??) · ?);
775 nrewrite > H1; napply dot0; ##]
778 nlemma erase_pre_of_reK : ∀S.∀e. 𝐋 .|pre_of_re S e| = 𝐋 e.
780 ##[ #e1 e2 H1 H2; nchange in match (𝐋 (e1 · e2)) with (𝐋 e1·?);
781 nrewrite < H1; nrewrite < H2; //
782 ##| #e1 e2 H1 H2; nchange in match (𝐋 (e1 + e2)) with (𝐋 e1 ∪ ?);
783 nrewrite < H1; nrewrite < H2; //
784 ##| #e1 H1; nchange in match (𝐋 (e1^* )) with ((𝐋 e1)^* );
789 nlemma L_Lp_bull : ∀S.∀e:re S.𝐋 e = 𝐋\p (•pre_of_re ? e).
790 #S e; nrewrite > (bull_cup…); nrewrite > (Lp_pre_of_re…);
791 nrewrite > (cupC…); nrewrite > (cup0…); nrewrite > (erase_pre_of_reK…); //;
794 nlemma Pext : ∀S.∀f,g:word S → Prop. f = g → ∀w.f w → g w.
795 #S f g H; nrewrite > H; //; nqed.
798 ntheorem bull_true_epsilon : ∀S.∀e:pitem S. \snd (•e) = true ↔ [ ] ∈ .|e|.
800 ##[ #defsnde; nlapply (bull_cup ? e); nchange in match (𝐋\p (•e)) with (?∪?);
801 nrewrite > defsnde; #H;
802 nlapply (Pext ??? H [ ] ?); ##[ @2; //] *; //;
807 notation > "\move term 90 x term 90 E"
808 non associative with precedence 60 for @{move ? $x $E}.
809 nlet rec move (S: Alpha) (x:S) (E: pitem S) on E : pre S ≝
813 | ps y ⇒ 〈 `y, false 〉
814 | pp y ⇒ 〈 `y, x == y 〉
815 | po e1 e2 ⇒ \move x e1 ⊕ \move x e2
816 | pc e1 e2 ⇒ \move x e1 ⊙ \move x e2
817 | pk e ⇒ (\move x e)^⊛ ].
818 notation < "\move\shy x\shy E" non associative with precedence 60 for @{'move $x $E}.
819 notation > "\move term 90 x term 90 E" non associative with precedence 60 for @{'move $x $E}.
820 interpretation "move" 'move x E = (move ? x E).
822 ndefinition rmove ≝ λS:Alpha.λx:S.λe:pre S. \move x (\fst e).
823 interpretation "rmove" 'move x E = (rmove ? x E).
825 nlemma XXz : ∀S:Alpha.∀w:word S. w .∈ ∅ → False.
826 #S w abs; ninversion abs; #; ndestruct;
830 nlemma XXe : ∀S:Alpha.∀w:word S. w .∈ ϵ → False.
831 #S w abs; ninversion abs; #; ndestruct;
834 nlemma XXze : ∀S:Alpha.∀w:word S. w .∈ (∅ · ϵ) → False.
835 #S w abs; ninversion abs; #; ndestruct; /2/ by XXz,XXe;
840 ∀S.∀w:word S.∀x.∀E1,E2:pitem S. w .∈ \move x (E1 · E2) →
841 (∃w1.∃w2. w = w1@w2 ∧ w1 .∈ \move x E1 ∧ w2 ∈ .|E2|) ∨ w .∈ \move x E2.
842 #S w x e1 e2 H; nchange in H with (w .∈ \move x e1 ⊙ \move x e2);
843 ncases e1 in H; ncases e2;
844 ##[##1: *; ##[*; nnormalize; #; ndestruct]
845 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
846 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
847 ##|##2: *; ##[*; nnormalize; #; ndestruct]
848 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
849 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
850 ##| #r; *; ##[ *; nnormalize; #; ndestruct]
851 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
852 ##[##2: nnormalize; #; ndestruct; @2; @2; //.##]
853 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz;
854 ##| #y; *; ##[ *; nnormalize; #defw defx; ndestruct; @2; @1; /2/ by conj;##]
855 #H; ninversion H; nnormalize; #; ndestruct;
856 ##[ncases (?:False); /2/ by XXz] /3/ by or_intror;
857 ##| #r1 r2; *; ##[ *; #defw]
862 ∀S:Alpha.∀E:pre S.∀a,w.w .∈ \move a E ↔ (a :: w) .∈ E.
863 #S E; ncases E; #r b; nelim r;
865 ##[##1,3: nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #abs; ncases (XXz … abs); ##]
866 #H; ninversion H; #; ndestruct;
867 ##|##*:nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #H1; ncases (XXz … H1); ##]
868 #H; ninversion H; #; ndestruct;##]
869 ##|#a c w; @; nnormalize; ##[*; ##[*; #; ndestruct; ##] #abs; ninversion abs; #; ndestruct;##]
870 *; ##[##2: #abs; ninversion abs; #; ndestruct; ##] *; #; ndestruct;
871 ##|#a c w; @; nnormalize;
872 ##[ *; ##[ *; #defw; nrewrite > defw; #ca; @2; nrewrite > (eqb_t … ca); @; ##]
873 #H; ninversion H; #; ndestruct;
874 ##| *; ##[ *; #; ndestruct; ##] #H; ninversion H; ##[##2,3,4,5,6: #; ndestruct]
875 #d defw defa; ndestruct; @1; @; //; nrewrite > (eqb_true S d d); //. ##]
876 ##|#r1 r2 H1 H2 a w; @;
877 ##[ #H; ncases (in_move_cat … H);
878 ##[ *; #w1; *; #w2; *; *; #defw w1m w2m;
879 ncases (H1 a w1); #H1w1; #_; nlapply (H1w1 w1m); #good;
880 nrewrite > defw; @2; @2 (a::w1); //; ncases good; ##[ *; #; ndestruct] //.
889 notation > "x ↦* E" non associative with precedence 60 for @{move_star ? $x $E}.
890 nlet rec move_star (S : decidable) w E on w : bool × (pre S) ≝
893 | cons x w' ⇒ w' ↦* (x ↦ \snd E)].
895 ndefinition in_moves ≝ λS:decidable.λw.λE:bool × (pre S). \fst(w ↦* E).
897 ncoinductive equiv (S:decidable) : bool × (pre S) → bool × (pre S) → Prop ≝
899 ∀E1,E2: bool × (pre S).
901 (∀x. equiv S (x ↦ \snd E1) (x ↦ \snd E2)) →
904 ndefinition NAT: decidable.
908 include "hints_declaration.ma".
910 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
911 unification hint 0 ≔ ; X ≟ NAT ⊢ carr X ≡ nat.
913 ninductive unit: Type[0] ≝ I: unit.
915 nlet corec foo_nop (b: bool):
917 〈 b, pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0))) 〉
918 〈 b, pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0) 〉 ≝ ?.
920 [ nnormalize in ⊢ (??%%); napply (foo_nop false)
922 [ nnormalize in ⊢ (??%%); napply (foo_nop false)
923 | #w; nnormalize in ⊢ (??%%); napply (foo_nop false) ]##]
927 nlet corec foo (a: unit):
929 (eclose NAT (pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0)))))
930 (eclose NAT (pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0)))
935 [ nnormalize in ⊢ (??%%);
936 nnormalize in foo: (? → ??%%);
938 [ nnormalize in ⊢ (??%%); napply foo_nop
940 [ nnormalize in ⊢ (??%%);
942 ##| #z; nnormalize in ⊢ (??%%); napply foo_nop ]##]
943 ##| #y; nnormalize in ⊢ (??%%); napply foo_nop
948 ndefinition test1 : pre ? ≝ ❨ `0 | `1 ❩^* `0.
949 ndefinition test2 : pre ? ≝ ❨ (`0`1)^* `0 | (`0`1)^* `1 ❩.
950 ndefinition test3 : pre ? ≝ (`0 (`0`1)^* `1)^*.
953 nlemma foo: in_moves ? [0;0;1;0;1;1] (ɛ test3) = true.
954 nnormalize in match test3;
959 (**********************************************************)
961 ninductive der (S: Type[0]) (a: S) : re S → re S → CProp[0] ≝
962 der_z: der S a (z S) (z S)
963 | der_e: der S a (e S) (z S)
964 | der_s1: der S a (s S a) (e ?)
965 | der_s2: ∀b. a ≠ b → der S a (s S b) (z S)
966 | der_c1: ∀e1,e2,e1',e2'. in_l S [] e1 → der S a e1 e1' → der S a e2 e2' →
967 der S a (c ? e1 e2) (o ? (c ? e1' e2) e2')
968 | der_c2: ∀e1,e2,e1'. Not (in_l S [] e1) → der S a e1 e1' →
969 der S a (c ? e1 e2) (c ? e1' e2)
970 | der_o: ∀e1,e2,e1',e2'. der S a e1 e1' → der S a e2 e2' →
971 der S a (o ? e1 e2) (o ? e1' e2').
973 nlemma eq_rect_CProp0_r:
974 ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (refl A a) → P x p.
975 #A; #a; #x; #p; ncases p; #P; #H; nassumption.
978 nlemma append1: ∀A.∀a:A.∀l. [a] @ l = a::l. //. nqed.
980 naxiom in_l1: ∀S,r1,r2,w. in_l S [ ] r1 → in_l S w r2 → in_l S w (c S r1 r2).
981 (* #S; #r1; #r2; #w; nelim r1
983 | #H1; #H2; napply (in_c ? []); //
984 | (* tutti casi assurdi *) *)
986 ninductive in_l' (S: Type[0]) : word S → re S → CProp[0] ≝
987 in_l_empty1: ∀E.in_l S [] E → in_l' S [] E
988 | in_l_cons: ∀a,w,e,e'. in_l' S w e' → der S a e e' → in_l' S (a::w) e.
990 ncoinductive eq_re (S: Type[0]) : re S → re S → CProp[0] ≝
992 (in_l S [] E1 → in_l S [] E2) →
993 (in_l S [] E2 → in_l S [] E1) →
994 (∀a,E1',E2'. der S a E1 E1' → der S a E2 E2' → eq_re S E1' E2') →
997 (* serve il lemma dopo? *)
998 ntheorem eq_re_is_eq: ∀S.∀E1,E2. eq_re S E1 E2 → ∀w. in_l ? w E1 → in_l ? w E2.
999 #S; #E1; #E2; #H1; #w; #H2; nelim H2 in E2 H1 ⊢ %
1001 | #a; #w; #R1; #R2; #K1; #K2; #K3; #R3; #K4; @2 R2; //; ncases K4;
1003 (* IL VICEVERSA NON VALE *)
1004 naxiom in_l_to_in_l: ∀S,w,E. in_l' S w E → in_l S w E.
1005 (* #S; #w; #E; #H; nelim H
1007 | #a; #w'; #r; #r'; #H1; (* e si cade qua sotto! *)
1011 ntheorem der1: ∀S,a,e,e',w. der S a e e' → in_l S w e' → in_l S (a::w) e.
1012 #S; #a; #E; #E'; #w; #H; nelim H
1013 [##1,2: #H1; ninversion H1
1014 [##1,8: #_; #K; (* non va ndestruct K; *) ncases (?:False); (* perche' due goal?*) /2/
1015 |##2,9: #X; #Y; #K; ncases (?:False); /2/
1016 |##3,10: #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
1017 |##4,11: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1018 |##5,12: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1019 |##6,13: #x; #y; #K; ncases (?:False); /2/
1020 |##7,14: #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/]
1021 ##| #H1; ninversion H1
1023 | #X; #Y; #K; ncases (?:False); /2/
1024 | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
1025 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1026 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1027 | #x; #y; #K; ncases (?:False); /2/
1028 | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
1029 ##| #H1; #H2; #H3; ninversion H3
1030 [ #_; #K; ncases (?:False); /2/
1031 | #X; #Y; #K; ncases (?:False); /2/
1032 | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
1033 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1034 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
1035 | #x; #y; #K; ncases (?:False); /2/
1036 | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
1037 ##| #r1; #r2; #r1'; #r2'; #H1; #H2; #H3; #H4; #H5; #H6;