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 "logic/cprop.ma".
19 ninductive Admit : CProp[0] ≝ .
22 ninductive list (A:setoid) : Type[0] ≝
24 | cons: A -> list A -> list A.
26 nlet rec eq_list A (l1, l2 : list A) on l1 : CProp[0] ≝
28 [ nil ⇒ match l2 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;
36 P1 ≟ refl ? (eq (LIST S)),
37 P2 ≟ sym ? (eq (LIST S)),
38 P3 ≟ trans ? (eq (LIST S)),
39 X ≟ mk_setoid (list S) (mk_equivalence_relation ? (eq_list S) P1 P2 P3)
40 (*-----------------------------------------------------------------------*) ⊢
43 notation "hvbox(hd break :: tl)"
44 right associative with precedence 47
47 notation "[ list0 x sep ; ]"
48 non associative with precedence 90
49 for ${fold right @'nil rec acc @{'cons $x $acc}}.
51 notation "hvbox(l1 break @ l2)"
52 right associative with precedence 47
53 for @{'append $l1 $l2 }.
55 interpretation "nil" 'nil = (nil ?).
56 interpretation "cons" 'cons hd tl = (cons ? hd tl).
58 nlet rec append A (l1: list A) l2 on l1 ≝
61 | cons hd tl ⇒ hd :: append A tl l2 ].
63 interpretation "append" 'append l1 l2 = (append ? l1 l2).
65 ntheorem append_nil: ∀A.∀l:list A.l @ [] = l.
66 #A;#l;nelim l;//; #a;#l1;#IH;nnormalize;/2/;nqed.
68 ndefinition associative ≝ λA:setoid.λf:A → A → A.∀x,y,z.f x (f y z) = f (f x y) z.
70 ninductive one : Type[0] ≝ unit : one.
73 λS:Type[1].λs:S.λT:Type[1].λt:T.λlock:one.
74 match lock return λ_.Type[1] with [ unit ⇒ T].
76 nlet rec lift (S:Type[1]) (s:S) (T:Type[1]) (t:T) (lock:one) on lock : force S s T t lock ≝
77 match lock return λlock.force S s T t lock with [ unit ⇒ t ].
79 ncoercion lift : ∀S:Type[1].∀s:S.∀T:Type[1].∀t:T.∀lock:one. force S s T t lock ≝ lift
80 on s : ? to force ?????.
82 unification hint 0 ≔ R : setoid;
83 TR ≟ setoid, MR ≟ (carr R), lock ≟ unit
84 (* ---------------------------------------- *) ⊢
85 setoid ≡ force ?(*Type[0]*) MR TR R lock.
87 ntheorem associative_append: ∀A.associative (list A) (append A).
88 #A;#x;#y;#z;nelim x[//|#a;#x1;#H;nnormalize;/2/]nqed.
90 interpretation "iff" 'iff a b = (iff a b).
92 nrecord Alpha : Type[1] ≝ {
94 eqb: carr → carr → bool; (*
95 eqb_true: ∀x,y. (eqb x y = true) = (x = y) *)
98 notation "a == b" non associative with precedence 45 for @{ 'eqb $a $b }.
99 interpretation "eqb" 'eqb a b = (eqb ? a b).
101 ndefinition word ≝ λS:Alpha.list S.
103 ninductive re (S: Alpha) : Type[0] ≝
107 | c: re S → re S → re S
108 | o: re S → re S → re S
111 notation < "a \sup ⋇" non associative with precedence 90 for @{ 'pk $a}.
112 notation > "a ^ *" non associative with precedence 90 for @{ 'pk $a}.
113 interpretation "star" 'pk a = (k ? a).
114 interpretation "or" 'plus a b = (o ? a b).
116 notation "a · b" non associative with precedence 60 for @{ 'pc $a $b}.
117 interpretation "cat" 'pc a b = (c ? a b).
119 (* to get rid of \middot *)
120 ncoercion c : ∀S:Alpha.∀p:re S. re S → re S ≝ c on _p : re ? to ∀_:?.?.
122 notation < "a" non associative with precedence 90 for @{ 'ps $a}.
123 notation > "` term 90 a" non associative with precedence 90 for @{ 'ps $a}.
124 interpretation "atom" 'ps a = (s ? a).
126 notation "ϵ" non associative with precedence 90 for @{ 'epsilon }.
127 interpretation "epsilon" 'epsilon = (e ?).
129 notation "∅" non associative with precedence 90 for @{ 'empty }.
130 interpretation "empty" 'empty = (z ?).
132 nlet rec flatten (S : Alpha) (l : list (word S)) on l : word S ≝
133 match l with [ nil ⇒ [ ] | cons w tl ⇒ w @ flatten ? tl ].
135 nlet rec conjunct (S : Alpha) (l : list (word S)) (r : word S → Prop) on l: Prop ≝
136 match l with [ nil ⇒ ? | cons w tl ⇒ r w ∧ conjunct ? tl r ]. napply True. nqed.
138 ndefinition empty_lang ≝ λS.λw:word S.False.
139 notation "{}" non associative with precedence 90 for @{'empty_lang}.
140 interpretation "empty lang" 'empty_lang = (empty_lang ?).
142 ndefinition sing_lang ≝ λS.λx,w:word S.x=w.
143 notation "{x}" non associative with precedence 90 for @{'sing_lang $x}.
144 interpretation "sing lang" 'sing_lang x = (sing_lang ? x).
146 ndefinition union : ∀S,l1,l2,w.Prop ≝ λS.λl1,l2.λw:word S.l1 w ∨ l2 w.
147 interpretation "union lang" 'union a b = (union ? a b).
149 ndefinition cat : ∀S,l1,l2,w.Prop ≝
150 λS.λl1,l2.λw:word S.∃w1,w2.w1 @ w2 = w ∧ l1 w1 ∧ l2 w2.
151 interpretation "cat lang" 'pc a b = (cat ? a b).
153 ndefinition star ≝ λS.λl.λw:word S.∃lw.flatten ? lw = w ∧ conjunct ? lw l.
154 interpretation "star lang" 'pk l = (star ? l).
156 notation > "𝐋 term 90 E" non associative with precedence 90 for @{in_l ? $E}.
157 nlet rec in_l (S : Alpha) (r : re S) on r : word S → Prop ≝
162 | c r1 r2 ⇒ 𝐋 r1 · 𝐋 r2
163 | o r1 r2 ⇒ 𝐋 r1 ∪ 𝐋 r2
165 notation "𝐋 term 90 E" non associative with precedence 90 for @{'in_l $E}.
166 interpretation "in_l" 'in_l E = (in_l ? E).
167 interpretation "in_l mem" 'mem w l = (in_l ? l w).
169 notation "a || b" left associative with precedence 30 for @{'orb $a $b}.
170 interpretation "orb" 'orb a b = (orb a b).
172 ndefinition if_then_else ≝ λT:Type[0].λe,t,f.match e return λ_.T with [ true ⇒ t | false ⇒ f].
173 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 }.
174 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 }.
175 interpretation "if_then_else" 'if_then_else e t f = (if_then_else ? e t f).
177 ninductive pitem (S: Alpha) : Type[0] ≝
182 | pc: pitem S → pitem S → pitem S
183 | po: pitem S → pitem S → pitem S
184 | pk: pitem S → pitem S.
186 ndefinition pre ≝ λS.pitem S × bool.
188 interpretation "pstar" 'pk a = (pk ? a).
189 interpretation "por" 'plus a b = (po ? a b).
190 interpretation "pcat" 'pc a b = (pc ? a b).
191 notation < ".a" non associative with precedence 90 for @{ 'pp $a}.
192 notation > "`. term 90 a" non associative with precedence 90 for @{ 'pp $a}.
193 interpretation "ppatom" 'pp a = (pp ? a).
194 (* to get rid of \middot *)
195 ncoercion pc : ∀S.∀p:pitem S. pitem S → pitem S ≝ pc on _p : pitem ? to ∀_:?.?.
196 interpretation "patom" 'ps a = (ps ? a).
197 interpretation "pepsilon" 'epsilon = (pe ?).
198 interpretation "pempty" 'empty = (pz ?).
200 notation > "|term 19 e|" non associative with precedence 70 for @{forget ? $e}.
201 nlet rec forget (S: Alpha) (l : pitem S) on l: re S ≝
207 | pc E1 E2 ⇒ (|E1| · |E2|)
208 | po E1 E2 ⇒ (|E1| + |E2|)
210 notation < ".|term 19 e|" non associative with precedence 70 for @{'forget $e}.
211 interpretation "forget" 'forget a = (forget ? a).
213 notation "\fst term 90 x" non associative with precedence 90 for @{'fst $x}.
214 interpretation "fst" 'fst x = (fst ? ? x).
215 notation > "\snd term 90 x" non associative with precedence 90 for @{'snd $x}.
216 interpretation "snd" 'snd x = (snd ? ? x).
218 notation > "𝐋\p\ term 90 E" non associative with precedence 90 for @{in_pl ? $E}.
219 nlet rec in_pl (S : Alpha) (r : pitem S) on r : word S → Prop ≝
225 | pc r1 r2 ⇒ 𝐋\p\ r1 · 𝐋 .|r2| ∪ 𝐋\p\ r2
226 | po r1 r2 ⇒ 𝐋\p\ r1 ∪ 𝐋\p\ r2
227 | pk r1 ⇒ 𝐋\p\ r1 · 𝐋 (.|r1|^* ) ].
228 notation > "𝐋\p term 90 E" non associative with precedence 90 for @{'in_pl $E}.
229 notation "𝐋\sub(\p) term 90 E" non associative with precedence 90 for @{'in_pl $E}.
230 interpretation "in_pl" 'in_pl E = (in_pl ? E).
231 interpretation "in_pl mem" 'mem w l = (in_pl ? l w).
233 ndefinition epsilon ≝ λS,b.if b then { ([ ] : word S) } else {}.
235 interpretation "epsilon" 'epsilon = (epsilon ?).
236 notation < "ϵ b" non associative with precedence 90 for @{'app_epsilon $b}.
237 interpretation "epsilon lang" 'app_epsilon b = (epsilon ? b).
239 ndefinition in_prl ≝ λS : Alpha.λp:pre S. 𝐋\p\ (\fst p) ∪ ϵ (\snd p).
241 interpretation "in_prl mem" 'mem w l = (in_prl ? l w).
242 interpretation "in_prl" 'in_pl E = (in_prl ? E).
244 nlemma append_eq_nil : ∀S.∀w1,w2:word S. w1 @ w2 = [ ] → w1 = [ ].
245 #S w1; nelim w1; //. #x tl IH w2; nnormalize; #abs; ndestruct; nqed.
248 nlemma epsilon_in_true : ∀S.∀e:pre S. [ ] ∈ e ↔ \snd e = true.
249 #S r; ncases r; #e b; @; ##[##2: #H; nrewrite > H; @2; /2/; ##] ncases b;//;
250 nnormalize; *; ##[##2:*] nelim e;
251 ##[ ##1,2: *; ##| #c; *; ##| #c; nnormalize; #; ndestruct; ##| ##7: #p H;
252 ##| #r1 r2 H G; *; ##[##2: /3/ by or_intror]
253 ##| #r1 r2 H1 H2; *; /3/ by or_intror, or_introl; ##]
254 *; #w1; *; #w2; *; *; #defw1; nrewrite > (append_eq_nil … w1 w2 …); /3/ by {};//;
257 nlemma not_epsilon_lp : ∀S.∀e:pitem S. ¬ (𝐋\p e [ ]).
258 #S e; nelim e; nnormalize; /2/ by nmk;
259 ##[ #; @; #; ndestruct;
260 ##| #r1 r2 n1 n2; @; *; /2/; *; #w1; *; #w2; *; *; #H;
261 nrewrite > (append_eq_nil …H…); /2/;
262 ##| #r1 r2 n1 n2; @; *; /2/;
263 ##| #r n; @; *; #w1; *; #w2; *; *; #H;
264 nrewrite > (append_eq_nil …H…); /2/;##]
267 ndefinition lo ≝ λS:Alpha.λa,b:pre S.〈\fst a + \fst b,\snd a || \snd b〉.
268 notation "a ⊕ b" left associative with precedence 60 for @{'oplus $a $b}.
269 interpretation "oplus" 'oplus a b = (lo ? a b).
271 ndefinition lc ≝ λS:Alpha.λbcast:∀S:Alpha.∀E:pitem S.pre S.λa,b:pre S.
272 match a with [ mk_pair e1 b1 ⇒
274 [ false ⇒ 〈e1 · \fst b, \snd b〉
275 | true ⇒ 〈e1 · \fst (bcast ? (\fst b)),\snd b || \snd (bcast ? (\fst b))〉]].
277 notation < "a ⊙ b" left associative with precedence 60 for @{'lc $op $a $b}.
278 interpretation "lc" 'lc op a b = (lc ? op a b).
279 notation > "a ⊙ b" left associative with precedence 60 for @{'lc eclose $a $b}.
281 ndefinition lk ≝ λS:Alpha.λbcast:∀S:Alpha.∀E:pitem S.pre S.λa:pre S.
282 match a with [ mk_pair e1 b1 ⇒
284 [ false ⇒ 〈e1^*, false〉
285 | true ⇒ 〈(\fst (bcast ? e1))^*, true〉]].
287 notation < "a \sup ⊛" non associative with precedence 90 for @{'lk $op $a}.
288 interpretation "lk" 'lk op a = (lk ? op a).
289 notation > "a^⊛" non associative with precedence 90 for @{'lk eclose $a}.
291 notation > "•" non associative with precedence 60 for @{eclose ?}.
292 nlet rec eclose (S: Alpha) (E: pitem S) on E : pre S ≝
296 | ps x ⇒ 〈 `.x, false 〉
297 | pp x ⇒ 〈 `.x, false 〉
298 | po E1 E2 ⇒ •E1 ⊕ •E2
299 | pc E1 E2 ⇒ •E1 ⊙ 〈 E2, false 〉
300 | pk E ⇒ 〈(\fst (•E))^*,true〉].
301 notation < "• x" non associative with precedence 60 for @{'eclose $x}.
302 interpretation "eclose" 'eclose x = (eclose ? x).
303 notation > "• x" non associative with precedence 60 for @{'eclose $x}.
305 ndefinition reclose ≝ λS:Alpha.λp:pre S.let p' ≝ •\fst p in 〈\fst p',\snd p || \snd p'〉.
306 interpretation "reclose" 'eclose x = (reclose ? x).
308 ndefinition eq_f1 ≝ λS.λa,b:word S → Prop.∀w.a w ↔ b w.
309 notation > "A =1 B" non associative with precedence 45 for @{'eq_f1 $A $B}.
310 notation "A =\sub 1 B" non associative with precedence 45 for @{'eq_f1 $A $B}.
311 interpretation "eq f1" 'eq_f1 a b = (eq_f1 ? a b).
313 naxiom extP : ∀S.∀p,q:word S → Prop.(p =1 q) → p = q.
315 nlemma epsilon_or : ∀S:Alpha.∀b1,b2. ϵ(b1 || b2) = ϵ b1 ∪ ϵ b2. ##[##2: napply S]
316 #S b1 b2; ncases b1; ncases b2; napply extP; #w; nnormalize; @; /2/; *; //; *;
319 nlemma cupA : ∀S.∀a,b,c:word S → Prop.a ∪ b ∪ c = a ∪ (b ∪ c).
320 #S a b c; napply extP; #w; nnormalize; @; *; /3/; *; /3/; nqed.
322 nlemma cupC : ∀S. ∀a,b:word S → Prop.a ∪ b = b ∪ a.
323 #S a b; napply extP; #w; @; *; nnormalize; /2/; nqed.
326 nlemma oplus_cup : ∀S:Alpha.∀e1,e2:pre S.𝐋\p (e1 ⊕ e2) = 𝐋\p e1 ∪ 𝐋\p e2.
327 #S r1; ncases r1; #e1 b1 r2; ncases r2; #e2 b2;
328 nwhd in ⊢ (??(??%)?);
329 nchange in ⊢(??%?) with (𝐋\p (e1 + e2) ∪ ϵ (b1 || b2));
330 nchange in ⊢(??(??%?)?) with (𝐋\p (e1) ∪ 𝐋\p (e2));
331 nrewrite > (epsilon_or S …); nrewrite > (cupA S (𝐋\p e1) …);
332 nrewrite > (cupC ? (ϵ b1) …); nrewrite < (cupA S (𝐋\p e2) …);
333 nrewrite > (cupC ? ? (ϵ b1) …); nrewrite < (cupA …); //;
337 ∀S.∀e1,e2:pitem S.∀b2. 〈e1,true〉 ⊙ 〈e2,b2〉 = 〈e1 · \fst (•e2),b2 || \snd (•e2)〉.
338 #S e1 e2 b2; nnormalize; ncases (•e2); //; nqed.
340 nlemma LcatE : ∀S.∀e1,e2:pitem S.𝐋\p (e1 · e2) = 𝐋\p e1 · 𝐋 .|e2| ∪ 𝐋\p e2. //; nqed.
342 nlemma cup_dotD : ∀S.∀p,q,r:word S → Prop.(p ∪ q) · r = (p · r) ∪ (q · r).
343 #S p q r; napply extP; #w; nnormalize; @;
344 ##[ *; #x; *; #y; *; *; #defw; *; /7/ by or_introl, or_intror, ex_intro, conj;
345 ##| *; *; #x; *; #y; *; *; /7/ by or_introl, or_intror, ex_intro, conj; ##]
348 nlemma cup0 :∀S.∀p:word S → Prop.p ∪ {} = p.
349 #S p; napply extP; #w; nnormalize; @; /2/; *; //; *; nqed.
351 nlemma erase_dot : ∀S.∀e1,e2:pitem S.𝐋 .|e1 · e2| = 𝐋 .|e1| · 𝐋 .|e2|.
352 #S e1 e2; napply extP; nnormalize; #w; @; *; #w1; *; #w2; *; *; /7/ by ex_intro, conj;
355 nlemma erase_plus : ∀S.∀e1,e2:pitem S.𝐋 .|e1 + e2| = 𝐋 .|e1| ∪ 𝐋 .|e2|.
356 #S e1 e2; napply extP; nnormalize; #w; @; *; /4/ by or_introl, or_intror; nqed.
358 nlemma erase_star : ∀S.∀e1:pitem S.𝐋 .|e1|^* = 𝐋 .|e1^*|. //; nqed.
360 ndefinition substract := λS.λp,q:word S → Prop.λw.p w ∧ ¬ q w.
361 interpretation "substract" 'minus a b = (substract ? a b).
363 nlemma cup_sub: ∀S.∀a,b:word S → Prop. ¬ (a []) → a ∪ (b - {[]}) = (a ∪ b) - {[]}.
364 #S a b c; napply extP; #w; nnormalize; @; *; /4/; *; /4/; nqed.
366 nlemma sub0 : ∀S.∀a:word S → Prop. a - {} = a.
367 #S a; napply extP; #w; nnormalize; @; /3/; *; //; nqed.
369 nlemma subK : ∀S.∀a:word S → Prop. a - a = {}.
370 #S a; napply extP; #w; nnormalize; @; *; /2/; nqed.
372 nlemma subW : ∀S.∀a,b:word S → Prop.∀w.(a - b) w → a w.
373 #S a b w; nnormalize; *; //; nqed.
375 nlemma erase_bull : ∀S.∀a:pitem S. .|\fst (•a)| = .|a|.
376 #S a; nelim a; // by {};
377 ##[ #e1 e2 IH1 IH2; nchange in ⊢ (???%) with (.|e1| · .|e2|);
378 nrewrite < IH1; nrewrite < IH2;
379 nchange in ⊢ (??(??%)?) with (\fst (•e1 ⊙ 〈e2,false〉));
380 ncases (•e1); #e3 b; ncases b; nnormalize;
381 ##[ ncases (•e2); //; ##| nrewrite > IH2; //]
382 ##| #e1 e2 IH1 IH2; nchange in ⊢ (???%) with (.|e1| + .|e2|);
383 nrewrite < IH2; nrewrite < IH1;
384 nchange in ⊢ (??(??%)?) with (\fst (•e1 ⊕ •e2));
385 ncases (•e1); ncases (•e2); //;
386 ##| #e IH; nchange in ⊢ (???%) with (.|e|^* ); nrewrite < IH;
387 nchange in ⊢ (??(??%)?) with (\fst (•e))^*; //; ##]
390 nlemma eta_lp : ∀S.∀p:pre S.𝐋\p p = 𝐋\p 〈\fst p, \snd p〉.
391 #S p; ncases p; //; nqed.
393 nlemma epsilon_dot: ∀S.∀p:word S → Prop. {[]} · p = p.
394 #S e; napply extP; #w; nnormalize; @; ##[##2: #Hw; @[]; @w; /3/; ##]
395 *; #w1; *; #w2; *; *; #defw defw1 Hw2; nrewrite < defw; nrewrite < defw1;
398 (* theorem 16: 1 → 3 *)
399 nlemma odot_dot_aux : ∀S.∀e1,e2: pre S.
400 𝐋\p (•(\fst e2)) = 𝐋\p (\fst e2) ∪ 𝐋 .|\fst e2| →
401 𝐋\p (e1 ⊙ e2) = 𝐋\p e1 · 𝐋 .|\fst e2| ∪ 𝐋\p e2.
402 #S e1 e2 th1; ncases e1; #e1' b1'; ncases b1';
403 ##[ nwhd in ⊢ (??(??%)?); nletin e2' ≝ (\fst e2); nletin b2' ≝ (\snd e2);
404 nletin e2'' ≝ (\fst (•(\fst e2))); nletin b2'' ≝ (\snd (•(\fst e2)));
405 nchange in ⊢ (??%?) with (?∪?);
406 nchange in ⊢ (??(??%?)?) with (?∪?);
407 nchange in match (𝐋\p 〈?,?〉) with (?∪?);
408 nrewrite > (epsilon_or …); nrewrite > (cupC ? (ϵ ?)…);
409 nrewrite > (cupA …);nrewrite < (cupA ?? (ϵ?)…);
410 nrewrite > (?: 𝐋\p e2'' ∪ ϵ b2'' = 𝐋\p e2' ∪ 𝐋 .|e2'|); ##[##2:
411 nchange with (𝐋\p 〈e2'',b2''〉 = 𝐋\p e2' ∪ 𝐋 .|e2'|);
412 ngeneralize in match th1;
413 nrewrite > (eta_lp…); #th1; nrewrite > th1; //;##]
414 nrewrite > (eta_lp ? e2);
415 nchange in match (𝐋\p 〈\fst e2,?〉) with (𝐋\p e2'∪ ϵ b2');
416 nrewrite > (cup_dotD …); nrewrite > (epsilon_dot…);
417 nrewrite > (cupC ? (𝐋\p e2')…); nrewrite > (cupA…);nrewrite > (cupA…);
418 nrewrite < (erase_bull S e2') in ⊢ (???(??%?)); //;
419 ##| ncases e2; #e2' b2'; nchange in match (〈e1',false〉⊙?) with 〈?,?〉;
420 nchange in match (𝐋\p ?) with (?∪?);
421 nchange in match (𝐋\p (e1'·?)) with (?∪?);
422 nchange in match (𝐋\p 〈e1',?〉) with (?∪?);
424 nrewrite > (cupA…); //;##]
427 nlemma sub_dot_star :
428 ∀S.∀X:word S → Prop.∀b. (X - ϵ b) · X^* ∪ {[]} = X^*.
429 #S X b; napply extP; #w; @;
430 ##[ *; ##[##2: nnormalize; #defw; nrewrite < defw; @[]; @; //]
431 *; #w1; *; #w2; *; *; #defw sube; *; #lw; *; #flx cj;
432 @ (w1 :: lw); nrewrite < defw; nrewrite < flx; @; //;
433 @; //; napply (subW … sube);
434 ##| *; #wl; *; #defw Pwl; nrewrite < defw; nelim wl in Pwl; ##[ #_; @2; //]
435 #w' wl' IH; *; #Pw' IHp; nlapply (IH IHp); *;
436 ##[ *; #w1; *; #w2; *; *; #defwl' H1 H2;
437 @; ncases b in H1; #H1;
438 ##[##2: nrewrite > (sub0…); @w'; @(w1@w2);
439 nrewrite > (associative_append ? w' w1 w2);
440 nrewrite > defwl'; @; ##[@;//] @(wl'); @; //;
441 ##| ncases w' in Pw';
442 ##[ #ne; @w1; @w2; nrewrite > defwl'; @; //; @; //;
443 ##| #x xs Px; @(x::xs); @(w1@w2);
444 nrewrite > (defwl'); @; ##[@; //; @; //; @; nnormalize; #; ndestruct]
446 ##| #wlnil; nchange in match (flatten ? (w'::wl')) with (w' @ flatten ? wl');
447 nrewrite < (wlnil); nrewrite > (append_nil…); ncases b;
448 ##[ ncases w' in Pw'; /2/; #x xs Pxs; @; @(x::xs); @([]);
449 nrewrite > (append_nil…); @; ##[ @; //;@; //; nnormalize; @; #; ndestruct]
451 ##| @; @w'; @[]; nrewrite > (append_nil…); @; ##[##2: @[]; @; //]
452 @; //; @; //; @; *;##]##]##]
456 alias symbol "pc" (instance 13) = "cat lang".
457 alias symbol "in_pl" (instance 23) = "in_pl".
458 alias symbol "in_pl" (instance 5) = "in_pl".
459 alias symbol "eclose" (instance 21) = "eclose".
460 ntheorem bull_cup : ∀S:Alpha. ∀e:pitem S. 𝐋\p (•e) = 𝐋\p e ∪ 𝐋 .|e|.
462 ##[ #a; napply extP; #w; nnormalize; @; *; /3/ by or_introl, or_intror;
463 ##| #a; napply extP; #w; nnormalize; @; *; /3/ by or_introl; *;
465 nchange in ⊢ (??(??(%))?) with (•e1 ⊙ 〈e2,false〉);
466 nrewrite > (odot_dot_aux S (•e1) 〈e2,false〉 IH2);
467 nrewrite > (IH1 …); nrewrite > (cup_dotD …);
468 nrewrite > (cupA …); nrewrite > (cupC ?? (𝐋\p ?) …);
469 nchange in match (𝐋\p 〈?,?〉) with (𝐋\p e2 ∪ {}); nrewrite > (cup0 …);
470 nrewrite < (erase_dot …); nrewrite < (cupA …); //;
472 nchange in match (•(?+?)) with (•e1 ⊕ •e2); nrewrite > (oplus_cup …);
473 nrewrite > (IH1 …); nrewrite > (IH2 …); nrewrite > (cupA …);
474 nrewrite > (cupC ? (𝐋\p e2)…);nrewrite < (cupA ??? (𝐋\p e2)…);
475 nrewrite > (cupC ?? (𝐋\p e2)…); nrewrite < (cupA …);
476 nrewrite < (erase_plus …); //.
477 ##| #e; nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e)); #IH;
478 nchange in match (𝐋\p ?) with (𝐋\p 〈e'^*,true〉);
479 nchange in match (𝐋\p ?) with (𝐋\p (e'^* ) ∪ {[ ]});
480 nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 .|e'|^* );
481 nrewrite > (erase_bull…e);
482 nrewrite > (erase_star …);
483 nrewrite > (?: 𝐋\p e' = 𝐋\p e ∪ (𝐋 .|e| - ϵ b')); ##[##2:
484 nchange in IH : (??%?) with (𝐋\p e' ∪ ϵ b'); ncases b' in IH;
485 ##[ #IH; nrewrite > (cup_sub…); //; nrewrite < IH;
486 nrewrite < (cup_sub…); //; nrewrite > (subK…); nrewrite > (cup0…);//;
487 ##| nrewrite > (sub0 …); #IH; nrewrite < IH; nrewrite > (cup0 …);//; ##]##]
488 nrewrite > (cup_dotD…); nrewrite > (cupA…);
489 nrewrite > (?: ((?·?)∪{[]} = 𝐋 .|e^*|)); //;
490 nchange in match (𝐋 .|e^*|) with ((𝐋. |e|)^* ); napply sub_dot_star;##]
495 ∀S.∀e1,e2: pre S. 𝐋\p (e1 ⊙ e2) = 𝐋\p e1 · 𝐋 .|\fst e2| ∪ 𝐋\p e2.
496 #S e1 e2; napply odot_dot_aux; napply (bull_cup S (\fst e2)); nqed.
498 nlemma dot_star_epsilon : ∀S.∀e:re S.𝐋 e · 𝐋 e^* ∪ {[]} = 𝐋 e^*.
499 #S e; napply extP; #w; nnormalize; @;
500 ##[ *; ##[##2: #H; nrewrite < H; @[]; /3/] *; #w1; *; #w2;
501 *; *; #defw Hw1; *; #wl; *; #defw2 Hwl; @(w1 :: wl);
502 nrewrite < defw; nrewrite < defw2; @; //; @;//;
503 ##| *; #wl; *; #defw Hwl; ncases wl in defw Hwl; ##[#defw; #; @2; nrewrite < defw; //]
504 #x xs defw; *; #Hx Hxs; @; @x; @(flatten ? xs); nrewrite < defw;
508 nlemma nil_star : ∀S.∀e:re S. [ ] ∈ e^*.
509 #S e; @[]; /2/; nqed.
511 nlemma cupID : ∀S.∀l:word S → Prop.l ∪ l = l.
512 #S l; napply extP; #w; @; ##[*]//; #; @; //; nqed.
514 nlemma cup_star_nil : ∀S.∀l:word S → Prop. l^* ∪ {[]} = l^*.
515 #S a; napply extP; #w; @; ##[*; //; #H; nrewrite < H; @[]; @; //] #;@; //;nqed.
517 nlemma rcanc_sing : ∀S.∀A,C:word S → Prop.∀b:word S .
518 ¬ (A b) → A ∪ { (b) } = C → A = C - { (b) }.
519 #S A C b nbA defC; nrewrite < defC; napply extP; #w; @;
520 ##[ #Aw; /3/| *; *; //; #H nH; ncases nH; #abs; nlapply (abs H); *]
524 nlemma star_dot: ∀S.∀e:pre S. 𝐋\p (e^⊛) = 𝐋\p e · (𝐋 .|\fst e|)^*.
525 #S p; ncases p; #e b; ncases b;
526 ##[ nchange in match (〈e,true〉^⊛) with 〈?,?〉;
527 nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e));
528 nchange in ⊢ (??%?) with (?∪?);
529 nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 .|e'|^* );
530 nrewrite > (?: 𝐋\p e' = 𝐋\p e ∪ (𝐋 .|e| - ϵ b' )); ##[##2:
531 nlapply (bull_cup ? e); #bc;
532 nchange in match (𝐋\p (•e)) in bc with (?∪?);
533 nchange in match b' in bc with b';
534 ncases b' in bc; ##[##2: nrewrite > (cup0…); nrewrite > (sub0…); //]
535 nrewrite > (cup_sub…); ##[napply rcanc_sing] //;##]
536 nrewrite > (cup_dotD…); nrewrite > (cupA…);nrewrite > (erase_bull…);
537 nrewrite > (sub_dot_star…);
538 nchange in match (𝐋\p 〈?,?〉) with (?∪?);
539 nrewrite > (cup_dotD…); nrewrite > (epsilon_dot…); //;
540 ##| nwhd in match (〈e,false〉^⊛); nchange in match (𝐋\p 〈?,?〉) with (?∪?);
542 nchange in ⊢ (??%?) with (𝐋\p e · 𝐋 .|e|^* );
543 nrewrite < (cup0 ? (𝐋\p e)); //;##]
546 nlet rec pre_of_re (S : Alpha) (e : re S) on e : pitem S ≝
551 | c e1 e2 ⇒ pc ? (pre_of_re ? e1) (pre_of_re ? e2)
552 | o e1 e2 ⇒ po ? (pre_of_re ? e1) (pre_of_re ? e2)
553 | k e1 ⇒ pk ? (pre_of_re ? e1)].
555 nlemma notFalse : ¬False. @; //; nqed.
557 nlemma dot0 : ∀S.∀A:word S → Prop. {} · A = {}.
558 #S A; nnormalize; napply extP; #w; @; ##[##2: *]
559 *; #w1; *; #w2; *; *; //; nqed.
561 nlemma Lp_pre_of_re : ∀S.∀e:re S. 𝐋\p (pre_of_re ? e) = {}.
562 #S e; nelim e; ##[##1,2,3: //]
563 ##[ #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1 e2))) with (?∪?);
564 nrewrite > H1; nrewrite > H2; nrewrite > (dot0…); nrewrite > (cupID…);//
565 ##| #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1+e2))) with (?∪?);
566 nrewrite > H1; nrewrite > H2; nrewrite > (cupID…); //
567 ##| #e1 H1; nchange in match (𝐋\p (pre_of_re S (e1^* ))) with (𝐋\p (pre_of_re ??) · ?);
568 nrewrite > H1; napply dot0; ##]
571 nlemma erase_pre_of_reK : ∀S.∀e. 𝐋 .|pre_of_re S e| = 𝐋 e.
573 ##[ #e1 e2 H1 H2; nchange in match (𝐋 (e1 · e2)) with (𝐋 e1·?);
574 nrewrite < H1; nrewrite < H2; //
575 ##| #e1 e2 H1 H2; nchange in match (𝐋 (e1 + e2)) with (𝐋 e1 ∪ ?);
576 nrewrite < H1; nrewrite < H2; //
577 ##| #e1 H1; nchange in match (𝐋 (e1^* )) with ((𝐋 e1)^* );
582 nlemma L_Lp_bull : ∀S.∀e:re S.𝐋 e = 𝐋\p (•pre_of_re ? e).
583 #S e; nrewrite > (bull_cup…); nrewrite > (Lp_pre_of_re…);
584 nrewrite > (cupC…); nrewrite > (cup0…); nrewrite > (erase_pre_of_reK…); //;
587 nlemma Pext : ∀S.∀f,g:word S → Prop. f = g → ∀w.f w → g w.
588 #S f g H; nrewrite > H; //; nqed.
591 ntheorem bull_true_epsilon : ∀S.∀e:pitem S. \snd (•e) = true ↔ [ ] ∈ .|e|.
593 ##[ #defsnde; nlapply (bull_cup ? e); nchange in match (𝐋\p (•e)) with (?∪?);
594 nrewrite > defsnde; #H;
595 nlapply (Pext ??? H [ ] ?); ##[ @2; //] *; //;
600 notation > "\move term 90 x term 90 E"
601 non associative with precedence 60 for @{move ? $x $E}.
602 nlet rec move (S: Alpha) (x:S) (E: pitem S) on E : pre S ≝
606 | ps y ⇒ 〈 `y, false 〉
607 | pp y ⇒ 〈 `y, x == y 〉
608 | po e1 e2 ⇒ \move x e1 ⊕ \move x e2
609 | pc e1 e2 ⇒ \move x e1 ⊙ \move x e2
610 | pk e ⇒ (\move x e)^⊛ ].
611 notation < "\move\shy x\shy E" non associative with precedence 60 for @{'move $x $E}.
612 notation > "\move term 90 x term 90 E" non associative with precedence 60 for @{'move $x $E}.
613 interpretation "move" 'move x E = (move ? x E).
615 ndefinition rmove ≝ λS:Alpha.λx:S.λe:pre S. \move x (\fst e).
616 interpretation "rmove" 'move x E = (rmove ? x E).
618 nlemma XXz : ∀S:Alpha.∀w:word S. w .∈ ∅ → False.
619 #S w abs; ninversion abs; #; ndestruct;
623 nlemma XXe : ∀S:Alpha.∀w:word S. w .∈ ϵ → False.
624 #S w abs; ninversion abs; #; ndestruct;
627 nlemma XXze : ∀S:Alpha.∀w:word S. w .∈ (∅ · ϵ) → False.
628 #S w abs; ninversion abs; #; ndestruct; /2/ by XXz,XXe;
633 ∀S.∀w:word S.∀x.∀E1,E2:pitem S. w .∈ \move x (E1 · E2) →
634 (∃w1.∃w2. w = w1@w2 ∧ w1 .∈ \move x E1 ∧ w2 ∈ .|E2|) ∨ w .∈ \move x E2.
635 #S w x e1 e2 H; nchange in H with (w .∈ \move x e1 ⊙ \move x e2);
636 ncases e1 in H; ncases e2;
637 ##[##1: *; ##[*; nnormalize; #; ndestruct]
638 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
639 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
640 ##|##2: *; ##[*; nnormalize; #; ndestruct]
641 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
642 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
643 ##| #r; *; ##[ *; nnormalize; #; ndestruct]
644 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
645 ##[##2: nnormalize; #; ndestruct; @2; @2; //.##]
646 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz;
647 ##| #y; *; ##[ *; nnormalize; #defw defx; ndestruct; @2; @1; /2/ by conj;##]
648 #H; ninversion H; nnormalize; #; ndestruct;
649 ##[ncases (?:False); /2/ by XXz] /3/ by or_intror;
650 ##| #r1 r2; *; ##[ *; #defw]
655 ∀S:Alpha.∀E:pre S.∀a,w.w .∈ \move a E ↔ (a :: w) .∈ E.
656 #S E; ncases E; #r b; nelim r;
658 ##[##1,3: nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #abs; ncases (XXz … abs); ##]
659 #H; ninversion H; #; ndestruct;
660 ##|##*:nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #H1; ncases (XXz … H1); ##]
661 #H; ninversion H; #; ndestruct;##]
662 ##|#a c w; @; nnormalize; ##[*; ##[*; #; ndestruct; ##] #abs; ninversion abs; #; ndestruct;##]
663 *; ##[##2: #abs; ninversion abs; #; ndestruct; ##] *; #; ndestruct;
664 ##|#a c w; @; nnormalize;
665 ##[ *; ##[ *; #defw; nrewrite > defw; #ca; @2; nrewrite > (eqb_t … ca); @; ##]
666 #H; ninversion H; #; ndestruct;
667 ##| *; ##[ *; #; ndestruct; ##] #H; ninversion H; ##[##2,3,4,5,6: #; ndestruct]
668 #d defw defa; ndestruct; @1; @; //; nrewrite > (eqb_true S d d); //. ##]
669 ##|#r1 r2 H1 H2 a w; @;
670 ##[ #H; ncases (in_move_cat … H);
671 ##[ *; #w1; *; #w2; *; *; #defw w1m w2m;
672 ncases (H1 a w1); #H1w1; #_; nlapply (H1w1 w1m); #good;
673 nrewrite > defw; @2; @2 (a::w1); //; ncases good; ##[ *; #; ndestruct] //.
682 notation > "x ↦* E" non associative with precedence 60 for @{move_star ? $x $E}.
683 nlet rec move_star (S : decidable) w E on w : bool × (pre S) ≝
686 | cons x w' ⇒ w' ↦* (x ↦ \snd E)].
688 ndefinition in_moves ≝ λS:decidable.λw.λE:bool × (pre S). \fst(w ↦* E).
690 ncoinductive equiv (S:decidable) : bool × (pre S) → bool × (pre S) → Prop ≝
692 ∀E1,E2: bool × (pre S).
694 (∀x. equiv S (x ↦ \snd E1) (x ↦ \snd E2)) →
697 ndefinition NAT: decidable.
701 include "hints_declaration.ma".
703 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
704 unification hint 0 ≔ ; X ≟ NAT ⊢ carr X ≡ nat.
706 ninductive unit: Type[0] ≝ I: unit.
708 nlet corec foo_nop (b: bool):
710 〈 b, pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0))) 〉
711 〈 b, pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0) 〉 ≝ ?.
713 [ nnormalize in ⊢ (??%%); napply (foo_nop false)
715 [ nnormalize in ⊢ (??%%); napply (foo_nop false)
716 | #w; nnormalize in ⊢ (??%%); napply (foo_nop false) ]##]
720 nlet corec foo (a: unit):
722 (eclose NAT (pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0)))))
723 (eclose NAT (pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0)))
728 [ nnormalize in ⊢ (??%%);
729 nnormalize in foo: (? → ??%%);
731 [ nnormalize in ⊢ (??%%); napply foo_nop
733 [ nnormalize in ⊢ (??%%);
735 ##| #z; nnormalize in ⊢ (??%%); napply foo_nop ]##]
736 ##| #y; nnormalize in ⊢ (??%%); napply foo_nop
741 ndefinition test1 : pre ? ≝ ❨ `0 | `1 ❩^* `0.
742 ndefinition test2 : pre ? ≝ ❨ (`0`1)^* `0 | (`0`1)^* `1 ❩.
743 ndefinition test3 : pre ? ≝ (`0 (`0`1)^* `1)^*.
746 nlemma foo: in_moves ? [0;0;1;0;1;1] (ɛ test3) = true.
747 nnormalize in match test3;
752 (**********************************************************)
754 ninductive der (S: Type[0]) (a: S) : re S → re S → CProp[0] ≝
755 der_z: der S a (z S) (z S)
756 | der_e: der S a (e S) (z S)
757 | der_s1: der S a (s S a) (e ?)
758 | der_s2: ∀b. a ≠ b → der S a (s S b) (z S)
759 | der_c1: ∀e1,e2,e1',e2'. in_l S [] e1 → der S a e1 e1' → der S a e2 e2' →
760 der S a (c ? e1 e2) (o ? (c ? e1' e2) e2')
761 | der_c2: ∀e1,e2,e1'. Not (in_l S [] e1) → der S a e1 e1' →
762 der S a (c ? e1 e2) (c ? e1' e2)
763 | der_o: ∀e1,e2,e1',e2'. der S a e1 e1' → der S a e2 e2' →
764 der S a (o ? e1 e2) (o ? e1' e2').
766 nlemma eq_rect_CProp0_r:
767 ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (refl A a) → P x p.
768 #A; #a; #x; #p; ncases p; #P; #H; nassumption.
771 nlemma append1: ∀A.∀a:A.∀l. [a] @ l = a::l. //. nqed.
773 naxiom in_l1: ∀S,r1,r2,w. in_l S [ ] r1 → in_l S w r2 → in_l S w (c S r1 r2).
774 (* #S; #r1; #r2; #w; nelim r1
776 | #H1; #H2; napply (in_c ? []); //
777 | (* tutti casi assurdi *) *)
779 ninductive in_l' (S: Type[0]) : word S → re S → CProp[0] ≝
780 in_l_empty1: ∀E.in_l S [] E → in_l' S [] E
781 | in_l_cons: ∀a,w,e,e'. in_l' S w e' → der S a e e' → in_l' S (a::w) e.
783 ncoinductive eq_re (S: Type[0]) : re S → re S → CProp[0] ≝
785 (in_l S [] E1 → in_l S [] E2) →
786 (in_l S [] E2 → in_l S [] E1) →
787 (∀a,E1',E2'. der S a E1 E1' → der S a E2 E2' → eq_re S E1' E2') →
790 (* serve il lemma dopo? *)
791 ntheorem eq_re_is_eq: ∀S.∀E1,E2. eq_re S E1 E2 → ∀w. in_l ? w E1 → in_l ? w E2.
792 #S; #E1; #E2; #H1; #w; #H2; nelim H2 in E2 H1 ⊢ %
794 | #a; #w; #R1; #R2; #K1; #K2; #K3; #R3; #K4; @2 R2; //; ncases K4;
796 (* IL VICEVERSA NON VALE *)
797 naxiom in_l_to_in_l: ∀S,w,E. in_l' S w E → in_l S w E.
798 (* #S; #w; #E; #H; nelim H
800 | #a; #w'; #r; #r'; #H1; (* e si cade qua sotto! *)
804 ntheorem der1: ∀S,a,e,e',w. der S a e e' → in_l S w e' → in_l S (a::w) e.
805 #S; #a; #E; #E'; #w; #H; nelim H
806 [##1,2: #H1; ninversion H1
807 [##1,8: #_; #K; (* non va ndestruct K; *) ncases (?:False); (* perche' due goal?*) /2/
808 |##2,9: #X; #Y; #K; ncases (?:False); /2/
809 |##3,10: #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
810 |##4,11: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
811 |##5,12: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
812 |##6,13: #x; #y; #K; ncases (?:False); /2/
813 |##7,14: #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/]
814 ##| #H1; ninversion H1
816 | #X; #Y; #K; ncases (?:False); /2/
817 | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
818 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
819 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
820 | #x; #y; #K; ncases (?:False); /2/
821 | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
822 ##| #H1; #H2; #H3; ninversion H3
823 [ #_; #K; ncases (?:False); /2/
824 | #X; #Y; #K; ncases (?:False); /2/
825 | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
826 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
827 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
828 | #x; #y; #K; ncases (?:False); /2/
829 | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
830 ##| #r1; #r2; #r1'; #r2'; #H1; #H2; #H3; #H4; #H5; #H6;