2 include "arithmetics/nat.ma".
3 include "basics/list.ma".
5 interpretation "iff" 'iff a b = (iff a b).
7 record Alpha : Type[1] ≝ { carr :> Type[0];
8 eqb: carr → carr →
\ 5a href="cic:/matita/basics/bool/bool.ind(1,0,0)"
\ 6bool
\ 5/a
\ 6;
9 eqb_true: ∀x,y. (eqb x y
\ 5a title="leibnitz's equality" href="cic:/fakeuri.def(1)"
\ 6=
\ 5/a
\ 6 \ 5a href="cic:/matita/basics/bool/bool.con(0,1,0)"
\ 6true
\ 5/a
\ 6)
\ 5a title="iff" href="cic:/fakeuri.def(1)"
\ 6↔
\ 5/a
\ 6 (x
\ 5a title="leibnitz's equality" href="cic:/fakeuri.def(1)"
\ 6=
\ 5/a
\ 6 y)
12 notation "a == b" non associative with precedence 45 for @{ 'eqb $a $b }.
13 interpretation "eqb" 'eqb a b = (eqb ? a b).
15 definition word ≝ λS:
\ 5a href="cic:/matita/tutorial/re/Alpha.ind(1,0,0)"
\ 6Alpha
\ 5/a
\ 6.
\ 5a href="cic:/matita/basics/list/list.ind(1,0,1)"
\ 6list
\ 5/a
\ 6 S.
17 inductive re (S:
\ 5a href="cic:/matita/tutorial/re/Alpha.ind(1,0,0)"
\ 6Alpha
\ 5/a
\ 6) : Type[0] ≝
21 | c: re S → re S → re S
22 | o: re S → re S → re S
25 notation < "a \sup ⋇" non associative with precedence 90 for @{ 'pk $a}.
26 notation > "a ^ *" non associative with precedence 90 for @{ 'pk $a}.
27 interpretation "star" 'pk a = (k ? a).
28 interpretation "or" 'plus a b = (o ? a b).
30 notation "a · b" non associative with precedence 60 for @{ 'pc $a $b}.
31 interpretation "cat" 'pc a b = (c ? a b).
33 (* to get rid of \middot
34 coercion c : ∀S:Alpha.∀p:re S. re S → re S ≝ c on _p : re ? to ∀_:?.?. *)
36 notation < "a" non associative with precedence 90 for @{ 'ps $a}.
37 notation > "` term 90 a" non associative with precedence 90 for @{ 'ps $a}.
38 interpretation "atom" 'ps a = (s ? a).
40 notation "ϵ" non associative with precedence 90 for @{ 'epsilon }.
41 interpretation "epsilon" 'epsilon = (e ?).
43 notation "∅" non associative with precedence 90 for @{ 'empty }.
44 interpretation "empty" 'empty = (z ?).
46 let rec flatten (S :
\ 5a href="cic:/matita/tutorial/re/Alpha.ind(1,0,0)"
\ 6Alpha
\ 5/a
\ 6) (l :
\ 5a href="cic:/matita/basics/list/list.ind(1,0,1)"
\ 6list
\ 5/a
\ 6 (
\ 5a href="cic:/matita/tutorial/re/word.def(3)"
\ 6word
\ 5/a
\ 6 S)) on l :
\ 5a href="cic:/matita/tutorial/re/word.def(3)"
\ 6word
\ 5/a
\ 6 S ≝
47 match l with [ nil ⇒
\ 5a title="nil" href="cic:/fakeuri.def(1)"
\ 6[
\ 5/a
\ 6 ] | cons w tl ⇒ w
\ 5a title="append" href="cic:/fakeuri.def(1)"
\ 6@
\ 5/a
\ 6 flatten ? tl ].
49 let rec conjunct (S :
\ 5a href="cic:/matita/tutorial/re/Alpha.ind(1,0,0)"
\ 6Alpha
\ 5/a
\ 6) (l :
\ 5a href="cic:/matita/basics/list/list.ind(1,0,1)"
\ 6list
\ 5/a
\ 6 (
\ 5a href="cic:/matita/tutorial/re/word.def(3)"
\ 6word
\ 5/a
\ 6 S)) (r :
\ 5a href="cic:/matita/tutorial/re/word.def(3)"
\ 6word
\ 5/a
\ 6 S → Prop) on l: Prop ≝
50 match l with [ nil ⇒
\ 5a href="cic:/matita/basics/logic/True.ind(1,0,0)"
\ 6True
\ 5/a
\ 6 | cons w tl ⇒ r w
\ 5a title="logical and" href="cic:/fakeuri.def(1)"
\ 6∧
\ 5/a
\ 6 conjunct ? tl r ].
52 definition empty_lang ≝ λS.λw:
\ 5a href="cic:/matita/tutorial/re/word.def(3)"
\ 6word
\ 5/a
\ 6 S.
\ 5a href="cic:/matita/basics/logic/False.ind(1,0,0)"
\ 6False
\ 5/a
\ 6.
53 notation "{}" non associative with precedence 90 for @{'empty_lang}.
54 interpretation "empty lang" 'empty_lang = (empty_lang ?).
56 definition sing_lang ≝ λS.λx,w:
\ 5a href="cic:/matita/tutorial/re/word.def(3)"
\ 6word
\ 5/a
\ 6 S.x
\ 5a title="leibnitz's equality" href="cic:/fakeuri.def(1)"
\ 6=
\ 5/a
\ 6w.
57 notation "{x}" non associative with precedence 90 for @{'sing_lang $x}.
58 interpretation "sing lang" 'sing_lang x = (sing_lang ? x).
60 definition union : ∀S,l1,l2,w.Prop ≝ λS.λl1,l2.λw:
\ 5a href="cic:/matita/tutorial/re/word.def(3)"
\ 6word
\ 5/a
\ 6 S.l1 w
\ 5a title="logical or" href="cic:/fakeuri.def(1)"
\ 6∨
\ 5/a
\ 6 l2 w.
61 interpretation "union lang" 'union a b = (union ? a b).
63 definition cat : ∀S,l1,l2,w.Prop ≝
64 λS.λl1,l2.λw:
\ 5a href="cic:/matita/tutorial/re/word.def(3)"
\ 6word
\ 5/a
\ 6 S.
\ 5a title="exists" href="cic:/fakeuri.def(1)"
\ 6∃
\ 5/a
\ 6w1,w2.w1
\ 5a title="append" href="cic:/fakeuri.def(1)"
\ 6@
\ 5/a
\ 6 w2
\ 5a title="leibnitz's equality" href="cic:/fakeuri.def(1)"
\ 6=
\ 5/a
\ 6 w
\ 5a title="logical and" href="cic:/fakeuri.def(1)"
\ 6∧
\ 5/a
\ 6 l1 w1
\ 5a title="logical and" href="cic:/fakeuri.def(1)"
\ 6∧
\ 5/a
\ 6 l2 w2.
65 interpretation "cat lang" 'pc a b = (cat ? a b).
67 definition star ≝ λS.λl.λw:
\ 5a href="cic:/matita/tutorial/re/word.def(3)"
\ 6word
\ 5/a
\ 6 S.
\ 5a title="exists" href="cic:/fakeuri.def(1)"
\ 6∃
\ 5/a
\ 6lw.
\ 5a href="cic:/matita/tutorial/re/flatten.fix(0,1,4)"
\ 6flatten
\ 5/a
\ 6 ? lw
\ 5a title="leibnitz's equality" href="cic:/fakeuri.def(1)"
\ 6=
\ 5/a
\ 6 w
\ 5a title="logical and" href="cic:/fakeuri.def(1)"
\ 6∧
\ 5/a
\ 6 \ 5a href="cic:/matita/tutorial/re/conjunct.fix(0,1,4)"
\ 6conjunct
\ 5/a
\ 6 ? lw l.
68 interpretation "star lang" 'pk l = (star ? l).
70 notation > "𝐋 term 70 E" non associative with precedence 75 for @{in_l ? $E}.
72 let rec in_l (S : Alpha) (r : re S) on r : word S → Prop ≝
77 | c r1 r2 ⇒ 𝐋 r1 · 𝐋 r2
78 | o r1 r2 ⇒ 𝐋 r1 ∪ 𝐋 r2
81 notation "𝐋 term 70 E" non associative with precedence 75 for @{'in_l $E}.
82 interpretation "in_l" 'in_l E = (in_l ? E).
83 interpretation "in_l mem" 'mem w l = (in_l ? l w).
85 notation "a || b" left associative with precedence 30 for @{'orb $a $b}.
86 interpretation "orb" 'orb a b = (orb a b).
88 ndefinition if_then_else ≝ λT:Type[0].λe,t,f.match e return λ_.T with [ true ⇒ t | false ⇒ f].
89 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 }.
90 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 }.
91 interpretation "if_then_else" 'if_then_else e t f = (if_then_else ? e t f).
93 ninductive pitem (S: Alpha) : Type[0] ≝
98 | pc: pitem S → pitem S → pitem S
99 | po: pitem S → pitem S → pitem S
100 | pk: pitem S → pitem S.
102 ndefinition pre ≝ λS.pitem S × bool.
104 interpretation "pstar" 'pk a = (pk ? a).
105 interpretation "por" 'plus a b = (po ? a b).
106 interpretation "pcat" 'pc a b = (pc ? a b).
107 notation < ".a" non associative with precedence 90 for @{ 'pp $a}.
108 notation > "`. term 90 a" non associative with precedence 90 for @{ 'pp $a}.
109 interpretation "ppatom" 'pp a = (pp ? a).
110 (* to get rid of \middot *)
111 ncoercion pc : ∀S.∀p:pitem S. pitem S → pitem S ≝ pc on _p : pitem ? to ∀_:?.?.
112 interpretation "patom" 'ps a = (ps ? a).
113 interpretation "pepsilon" 'epsilon = (pe ?).
114 interpretation "pempty" 'empty = (pz ?).
116 notation > "|term 19 e|" non associative with precedence 70 for @{forget ? $e}.
117 nlet rec forget (S: Alpha) (l : pitem S) on l: re S ≝
123 | pc E1 E2 ⇒ (|E1| · |E2|)
124 | po E1 E2 ⇒ (|E1| + |E2|)
126 notation < "|term 19 e|" non associative with precedence 70 for @{'forget $e}.
127 interpretation "forget" 'forget a = (forget ? a).
129 notation "\fst term 90 x" non associative with precedence 90 for @{'fst $x}.
130 interpretation "fst" 'fst x = (fst ? ? x).
131 notation > "\snd term 90 x" non associative with precedence 90 for @{'snd $x}.
132 interpretation "snd" 'snd x = (snd ? ? x).
134 notation > "𝐋\p\ term 70 E" non associative with precedence 75 for @{in_pl ? $E}.
135 nlet rec in_pl (S : Alpha) (r : pitem S) on r : word S → Prop ≝
141 | pc r1 r2 ⇒ 𝐋\p\ r1 · 𝐋 |r2| ∪ 𝐋\p\ r2
142 | po r1 r2 ⇒ 𝐋\p\ r1 ∪ 𝐋\p\ r2
143 | pk r1 ⇒ 𝐋\p\ r1 · 𝐋 (|r1|^* ) ].
144 notation > "𝐋\p term 70 E" non associative with precedence 75 for @{'in_pl $E}.
145 notation "𝐋\sub(\p) term 70 E" non associative with precedence 75 for @{'in_pl $E}.
146 interpretation "in_pl" 'in_pl E = (in_pl ? E).
147 interpretation "in_pl mem" 'mem w l = (in_pl ? l w).
149 ndefinition epsilon ≝ λS,b.if b then { ([ ] : word S) } else {}.
151 interpretation "epsilon" 'epsilon = (epsilon ?).
152 notation < "ϵ b" non associative with precedence 90 for @{'app_epsilon $b}.
153 interpretation "epsilon lang" 'app_epsilon b = (epsilon ? b).
155 ndefinition in_prl ≝ λS : Alpha.λp:pre S. 𝐋\p (\fst p) ∪ ϵ (\snd p).
157 interpretation "in_prl mem" 'mem w l = (in_prl ? l w).
158 interpretation "in_prl" 'in_pl E = (in_prl ? E).
160 nlemma append_eq_nil : ∀S.∀w1,w2:word S. w1 @ w2 = [ ] → w1 = [ ].
161 #S w1; nelim w1; //. #x tl IH w2; nnormalize; #abs; ndestruct; nqed.
164 nlemma epsilon_in_true : ∀S.∀e:pre S. [ ] ∈ e ↔ \snd e = true.
165 #S r; ncases r; #e b; @; ##[##2: #H; nrewrite > H; @2; /2/; ##] ncases b;//;
166 nnormalize; *; ##[##2:*] nelim e;
167 ##[ ##1,2: *; ##| #c; *; ##| #c; nnormalize; #; ndestruct; ##| ##7: #p H;
168 ##| #r1 r2 H G; *; ##[##2: /3/ by or_intror]
169 ##| #r1 r2 H1 H2; *; /3/ by or_intror, or_introl; ##]
170 *; #w1; *; #w2; *; *; #defw1; nrewrite > (append_eq_nil … w1 w2 …); /3/ by {};//;
173 nlemma not_epsilon_lp : ∀S:Alpha.∀e:pitem S. ¬ ((𝐋\p e) [ ]).
174 #S e; nelim e; nnormalize; /2/ by nmk;
175 ##[ #; @; #; ndestruct;
176 ##| #r1 r2 n1 n2; @; *; /2/; *; #w1; *; #w2; *; *; #H;
177 nrewrite > (append_eq_nil …H…); /2/;
178 ##| #r1 r2 n1 n2; @; *; /2/;
179 ##| #r n; @; *; #w1; *; #w2; *; *; #H;
180 nrewrite > (append_eq_nil …H…); /2/;##]
183 ndefinition lo ≝ λS:Alpha.λa,b:pre S.〈\fst a + \fst b,\snd a || \snd b〉.
184 notation "a ⊕ b" left associative with precedence 60 for @{'oplus $a $b}.
185 interpretation "oplus" 'oplus a b = (lo ? a b).
187 ndefinition lc ≝ λS:Alpha.λbcast:∀S:Alpha.∀E:pitem S.pre S.λa,b:pre S.
188 match a with [ mk_pair e1 b1 ⇒
190 [ false ⇒ 〈e1 · \fst b, \snd b〉
191 | true ⇒ 〈e1 · \fst (bcast ? (\fst b)),\snd b || \snd (bcast ? (\fst b))〉]].
193 notation < "a ⊙ b" left associative with precedence 60 for @{'lc $op $a $b}.
194 interpretation "lc" 'lc op a b = (lc ? op a b).
195 notation > "a ⊙ b" left associative with precedence 60 for @{'lc eclose $a $b}.
197 ndefinition lk ≝ λS:Alpha.λbcast:∀S:Alpha.∀E:pitem S.pre S.λa:pre S.
198 match a with [ mk_pair e1 b1 ⇒
200 [ false ⇒ 〈e1^*, false〉
201 | true ⇒ 〈(\fst (bcast ? e1))^*, true〉]].
203 notation < "a \sup ⊛" non associative with precedence 90 for @{'lk $op $a}.
204 interpretation "lk" 'lk op a = (lk ? op a).
205 notation > "a^⊛" non associative with precedence 90 for @{'lk eclose $a}.
207 notation > "•" non associative with precedence 60 for @{eclose ?}.
208 nlet rec eclose (S: Alpha) (E: pitem S) on E : pre S ≝
212 | ps x ⇒ 〈 `.x, false 〉
213 | pp x ⇒ 〈 `.x, false 〉
214 | po E1 E2 ⇒ •E1 ⊕ •E2
215 | pc E1 E2 ⇒ •E1 ⊙ 〈 E2, false 〉
216 | pk E ⇒ 〈(\fst (•E))^*,true〉].
217 notation < "• x" non associative with precedence 60 for @{'eclose $x}.
218 interpretation "eclose" 'eclose x = (eclose ? x).
219 notation > "• x" non associative with precedence 60 for @{'eclose $x}.
221 ndefinition reclose ≝ λS:Alpha.λp:pre S.let p' ≝ •\fst p in 〈\fst p',\snd p || \snd p'〉.
222 interpretation "reclose" 'eclose x = (reclose ? x).
224 ndefinition eq_f1 ≝ λS.λa,b:word S → Prop.∀w.a w ↔ b w.
225 notation > "A =1 B" non associative with precedence 45 for @{'eq_f1 $A $B}.
226 notation "A =\sub 1 B" non associative with precedence 45 for @{'eq_f1 $A $B}.
227 interpretation "eq f1" 'eq_f1 a b = (eq_f1 ? a b).
229 naxiom extP : ∀S.∀p,q:word S → Prop.(p =1 q) → p = q.
231 nlemma epsilon_or : ∀S:Alpha.∀b1,b2. ϵ(b1 || b2) = ϵ b1 ∪ ϵ b2. ##[##2: napply S]
232 #S b1 b2; ncases b1; ncases b2; napply extP; #w; nnormalize; @; /2/; *; //; *;
235 nlemma cupA : ∀S.∀a,b,c:word S → Prop.a ∪ b ∪ c = a ∪ (b ∪ c).
236 #S a b c; napply extP; #w; nnormalize; @; *; /3/; *; /3/; nqed.
238 nlemma cupC : ∀S. ∀a,b:word S → Prop.a ∪ b = b ∪ a.
239 #S a b; napply extP; #w; @; *; nnormalize; /2/; nqed.
242 nlemma oplus_cup : ∀S:Alpha.∀e1,e2:pre S.𝐋\p (e1 ⊕ e2) = 𝐋\p e1 ∪ 𝐋\p e2.
243 #S r1; ncases r1; #e1 b1 r2; ncases r2; #e2 b2;
244 nwhd in ⊢ (??(??%)?);
245 nchange in ⊢(??%?) with (𝐋\p (e1 + e2) ∪ ϵ (b1 || b2));
246 nchange in ⊢(??(??%?)?) with (𝐋\p (e1) ∪ 𝐋\p (e2));
247 nrewrite > (epsilon_or S …); nrewrite > (cupA S (𝐋\p e1) …);
248 nrewrite > (cupC ? (ϵ b1) …); nrewrite < (cupA S (𝐋\p e2) …);
249 nrewrite > (cupC ? ? (ϵ b1) …); nrewrite < (cupA …); //;
253 ∀S.∀e1,e2:pitem S.∀b2. 〈e1,true〉 ⊙ 〈e2,b2〉 = 〈e1 · \fst (•e2),b2 || \snd (•e2)〉.
254 #S e1 e2 b2; nnormalize; ncases (•e2); //; nqed.
256 nlemma LcatE : ∀S.∀e1,e2:pitem S.𝐋\p (e1 · e2) = 𝐋\p e1 · 𝐋 |e2| ∪ 𝐋\p e2. //; nqed.
258 nlemma cup_dotD : ∀S.∀p,q,r:word S → Prop.(p ∪ q) · r = (p · r) ∪ (q · r).
259 #S p q r; napply extP; #w; nnormalize; @;
260 ##[ *; #x; *; #y; *; *; #defw; *; /7/ by or_introl, or_intror, ex_intro, conj;
261 ##| *; *; #x; *; #y; *; *; /7/ by or_introl, or_intror, ex_intro, conj; ##]
264 nlemma cup0 :∀S.∀p:word S → Prop.p ∪ {} = p.
265 #S p; napply extP; #w; nnormalize; @; /2/; *; //; *; nqed.
267 nlemma erase_dot : ∀S.∀e1,e2:pitem S.𝐋 |e1 · e2| = 𝐋 |e1| · 𝐋 |e2|.
268 #S e1 e2; napply extP; nnormalize; #w; @; *; #w1; *; #w2; *; *; /7/ by ex_intro, conj;
271 nlemma erase_plus : ∀S.∀e1,e2:pitem S.𝐋 |e1 + e2| = 𝐋 |e1| ∪ 𝐋 |e2|.
272 #S e1 e2; napply extP; nnormalize; #w; @; *; /4/ by or_introl, or_intror; nqed.
274 nlemma erase_star : ∀S.∀e1:pitem S.𝐋 |e1|^* = 𝐋 |e1^*|. //; nqed.
276 ndefinition substract := λS.λp,q:word S → Prop.λw.p w ∧ ¬ q w.
277 interpretation "substract" 'minus a b = (substract ? a b).
279 nlemma cup_sub: ∀S.∀a,b:word S → Prop. ¬ (a []) → a ∪ (b - {[]}) = (a ∪ b) - {[]}.
280 #S a b c; napply extP; #w; nnormalize; @; *; /4/; *; /4/; nqed.
282 nlemma sub0 : ∀S.∀a:word S → Prop. a - {} = a.
283 #S a; napply extP; #w; nnormalize; @; /3/; *; //; nqed.
285 nlemma subK : ∀S.∀a:word S → Prop. a - a = {}.
286 #S a; napply extP; #w; nnormalize; @; *; /2/; nqed.
288 nlemma subW : ∀S.∀a,b:word S → Prop.∀w.(a - b) w → a w.
289 #S a b w; nnormalize; *; //; nqed.
291 nlemma erase_bull : ∀S.∀a:pitem S. |\fst (•a)| = |a|.
292 #S a; nelim a; // by {};
293 ##[ #e1 e2 IH1 IH2; nchange in ⊢ (???%) with (|e1| · |e2|);
294 nrewrite < IH1; nrewrite < IH2;
295 nchange in ⊢ (??(??%)?) with (\fst (•e1 ⊙ 〈e2,false〉));
296 ncases (•e1); #e3 b; ncases b; nnormalize;
297 ##[ ncases (•e2); //; ##| nrewrite > IH2; //]
298 ##| #e1 e2 IH1 IH2; nchange in ⊢ (???%) with (|e1| + |e2|);
299 nrewrite < IH2; nrewrite < IH1;
300 nchange in ⊢ (??(??%)?) with (\fst (•e1 ⊕ •e2));
301 ncases (•e1); ncases (•e2); //;
302 ##| #e IH; nchange in ⊢ (???%) with (|e|^* ); nrewrite < IH;
303 nchange in ⊢ (??(??%)?) with (\fst (•e))^*; //; ##]
306 nlemma eta_lp : ∀S.∀p:pre S.𝐋\p p = 𝐋\p 〈\fst p, \snd p〉.
307 #S p; ncases p; //; nqed.
309 nlemma epsilon_dot: ∀S.∀p:word S → Prop. {[]} · p = p.
310 #S e; napply extP; #w; nnormalize; @; ##[##2: #Hw; @[]; @w; /3/; ##]
311 *; #w1; *; #w2; *; *; #defw defw1 Hw2; nrewrite < defw; nrewrite < defw1;
314 (* theorem 16: 1 → 3 *)
315 nlemma odot_dot_aux : ∀S.∀e1,e2: pre S.
316 𝐋\p (•(\fst e2)) = 𝐋\p (\fst e2) ∪ 𝐋 |\fst e2| →
317 𝐋\p (e1 ⊙ e2) = 𝐋\p e1 · 𝐋 |\fst e2| ∪ 𝐋\p e2.
318 #S e1 e2 th1; ncases e1; #e1' b1'; ncases b1';
319 ##[ nwhd in ⊢ (??(??%)?); nletin e2' ≝ (\fst e2); nletin b2' ≝ (\snd e2);
320 nletin e2'' ≝ (\fst (•(\fst e2))); nletin b2'' ≝ (\snd (•(\fst e2)));
321 nchange in ⊢ (??%?) with (?∪?);
322 nchange in ⊢ (??(??%?)?) with (?∪?);
323 nchange in match (𝐋\p 〈?,?〉) with (?∪?);
324 nrewrite > (epsilon_or …); nrewrite > (cupC ? (ϵ ?)…);
325 nrewrite > (cupA …);nrewrite < (cupA ?? (ϵ?)…);
326 nrewrite > (?: 𝐋\p e2'' ∪ ϵ b2'' = 𝐋\p e2' ∪ 𝐋 |e2'|); ##[##2:
327 nchange with (𝐋\p 〈e2'',b2''〉 = 𝐋\p e2' ∪ 𝐋 |e2'|);
328 ngeneralize in match th1;
329 nrewrite > (eta_lp…); #th1; nrewrite > th1; //;##]
330 nrewrite > (eta_lp ? e2);
331 nchange in match (𝐋\p 〈\fst e2,?〉) with (𝐋\p e2'∪ ϵ b2');
332 nrewrite > (cup_dotD …); nrewrite > (epsilon_dot…);
333 nrewrite > (cupC ? (𝐋\p e2')…); nrewrite > (cupA…);nrewrite > (cupA…);
334 nrewrite < (erase_bull S e2') in ⊢ (???(??%?)); //;
335 ##| ncases e2; #e2' b2'; nchange in match (〈e1',false〉⊙?) with 〈?,?〉;
336 nchange in match (𝐋\p ?) with (?∪?);
337 nchange in match (𝐋\p (e1'·?)) with (?∪?);
338 nchange in match (𝐋\p 〈e1',?〉) with (?∪?);
340 nrewrite > (cupA…); //;##]
343 nlemma sub_dot_star :
344 ∀S.∀X:word S → Prop.∀b. (X - ϵ b) · X^* ∪ {[]} = X^*.
345 #S X b; napply extP; #w; @;
346 ##[ *; ##[##2: nnormalize; #defw; nrewrite < defw; @[]; @; //]
347 *; #w1; *; #w2; *; *; #defw sube; *; #lw; *; #flx cj;
348 @ (w1 :: lw); nrewrite < defw; nrewrite < flx; @; //;
349 @; //; napply (subW … sube);
350 ##| *; #wl; *; #defw Pwl; nrewrite < defw; nelim wl in Pwl; ##[ #_; @2; //]
351 #w' wl' IH; *; #Pw' IHp; nlapply (IH IHp); *;
352 ##[ *; #w1; *; #w2; *; *; #defwl' H1 H2;
353 @; ncases b in H1; #H1;
354 ##[##2: nrewrite > (sub0…); @w'; @(w1@w2);
355 nrewrite > (associative_append ? w' w1 w2);
356 nrewrite > defwl'; @; ##[@;//] @(wl'); @; //;
357 ##| ncases w' in Pw';
358 ##[ #ne; @w1; @w2; nrewrite > defwl'; @; //; @; //;
359 ##| #x xs Px; @(x::xs); @(w1@w2);
360 nrewrite > (defwl'); @; ##[@; //; @; //; @; nnormalize; #; ndestruct]
362 ##| #wlnil; nchange in match (flatten ? (w'::wl')) with (w' @ flatten ? wl');
363 nrewrite < (wlnil); nrewrite > (append_nil…); ncases b;
364 ##[ ncases w' in Pw'; /2/; #x xs Pxs; @; @(x::xs); @([]);
365 nrewrite > (append_nil…); @; ##[ @; //;@; //; nnormalize; @; #; ndestruct]
367 ##| @; @w'; @[]; nrewrite > (append_nil…); @; ##[##2: @[]; @; //]
368 @; //; @; //; @; *;##]##]##]
372 alias symbol "pc" (instance 13) = "cat lang".
373 alias symbol "in_pl" (instance 23) = "in_pl".
374 alias symbol "in_pl" (instance 5) = "in_pl".
375 alias symbol "eclose" (instance 21) = "eclose".
376 ntheorem bull_cup : ∀S:Alpha. ∀e:pitem S. 𝐋\p (•e) = 𝐋\p e ∪ 𝐋 |e|.
378 ##[ #a; napply extP; #w; nnormalize; @; *; /3/ by or_introl, or_intror;
379 ##| #a; napply extP; #w; nnormalize; @; *; /3/ by or_introl; *;
381 nchange in ⊢ (??(??(%))?) with (•e1 ⊙ 〈e2,false〉);
382 nrewrite > (odot_dot_aux S (•e1) 〈e2,false〉 IH2);
383 nrewrite > (IH1 …); nrewrite > (cup_dotD …);
384 nrewrite > (cupA …); nrewrite > (cupC ?? (𝐋\p ?) …);
385 nchange in match (𝐋\p 〈?,?〉) with (𝐋\p e2 ∪ {}); nrewrite > (cup0 …);
386 nrewrite < (erase_dot …); nrewrite < (cupA …); //;
388 nchange in match (•(?+?)) with (•e1 ⊕ •e2); nrewrite > (oplus_cup …);
389 nrewrite > (IH1 …); nrewrite > (IH2 …); nrewrite > (cupA …);
390 nrewrite > (cupC ? (𝐋\p e2)…);nrewrite < (cupA ??? (𝐋\p e2)…);
391 nrewrite > (cupC ?? (𝐋\p e2)…); nrewrite < (cupA …);
392 nrewrite < (erase_plus …); //.
393 ##| #e; nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e)); #IH;
394 nchange in match (𝐋\p ?) with (𝐋\p 〈e'^*,true〉);
395 nchange in match (𝐋\p ?) with (𝐋\p (e'^* ) ∪ {[ ]});
396 nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 |e'|^* );
397 nrewrite > (erase_bull…e);
398 nrewrite > (erase_star …);
399 nrewrite > (?: 𝐋\p e' = 𝐋\p e ∪ (𝐋 |e| - ϵ b')); ##[##2:
400 nchange in IH : (??%?) with (𝐋\p e' ∪ ϵ b'); ncases b' in IH;
401 ##[ #IH; nrewrite > (cup_sub…); //; nrewrite < IH;
402 nrewrite < (cup_sub…); //; nrewrite > (subK…); nrewrite > (cup0…);//;
403 ##| nrewrite > (sub0 …); #IH; nrewrite < IH; nrewrite > (cup0 …);//; ##]##]
404 nrewrite > (cup_dotD…); nrewrite > (cupA…);
405 nrewrite > (?: ((?·?)∪{[]} = 𝐋 |e^*|)); //;
406 nchange in match (𝐋 |e^*|) with ((𝐋 |e|)^* ); napply sub_dot_star;##]
411 ∀S.∀e1,e2: pre S. 𝐋\p (e1 ⊙ e2) = 𝐋\p e1 · 𝐋 |\fst e2| ∪ 𝐋\p e2.
412 #S e1 e2; napply odot_dot_aux; napply (bull_cup S (\fst e2)); nqed.
414 nlemma dot_star_epsilon : ∀S.∀e:re S.𝐋 e · 𝐋 e^* ∪ {[]} = 𝐋 e^*.
415 #S e; napply extP; #w; nnormalize; @;
416 ##[ *; ##[##2: #H; nrewrite < H; @[]; /3/] *; #w1; *; #w2;
417 *; *; #defw Hw1; *; #wl; *; #defw2 Hwl; @(w1 :: wl);
418 nrewrite < defw; nrewrite < defw2; @; //; @;//;
419 ##| *; #wl; *; #defw Hwl; ncases wl in defw Hwl; ##[#defw; #; @2; nrewrite < defw; //]
420 #x xs defw; *; #Hx Hxs; @; @x; @(flatten ? xs); nrewrite < defw;
424 nlemma nil_star : ∀S.∀e:re S. [ ] ∈ e^*.
425 #S e; @[]; /2/; nqed.
427 nlemma cupID : ∀S.∀l:word S → Prop.l ∪ l = l.
428 #S l; napply extP; #w; @; ##[*]//; #; @; //; nqed.
430 nlemma cup_star_nil : ∀S.∀l:word S → Prop. l^* ∪ {[]} = l^*.
431 #S a; napply extP; #w; @; ##[*; //; #H; nrewrite < H; @[]; @; //] #;@; //;nqed.
433 nlemma rcanc_sing : ∀S.∀A,C:word S → Prop.∀b:word S .
434 ¬ (A b) → A ∪ { (b) } = C → A = C - { (b) }.
435 #S A C b nbA defC; nrewrite < defC; napply extP; #w; @;
436 ##[ #Aw; /3/| *; *; //; #H nH; ncases nH; #abs; nlapply (abs H); *]
440 nlemma star_dot: ∀S.∀e:pre S. 𝐋\p (e^⊛) = 𝐋\p e · (𝐋 |\fst e|)^*.
441 #S p; ncases p; #e b; ncases b;
442 ##[ nchange in match (〈e,true〉^⊛) with 〈?,?〉;
443 nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e));
444 nchange in ⊢ (??%?) with (?∪?);
445 nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 |e'|^* );
446 nrewrite > (?: 𝐋\p e' = 𝐋\p e ∪ (𝐋 |e| - ϵ b' )); ##[##2:
447 nlapply (bull_cup ? e); #bc;
448 nchange in match (𝐋\p (•e)) in bc with (?∪?);
449 nchange in match b' in bc with b';
450 ncases b' in bc; ##[##2: nrewrite > (cup0…); nrewrite > (sub0…); //]
451 nrewrite > (cup_sub…); ##[napply rcanc_sing] //;##]
452 nrewrite > (cup_dotD…); nrewrite > (cupA…);nrewrite > (erase_bull…);
453 nrewrite > (sub_dot_star…);
454 nchange in match (𝐋\p 〈?,?〉) with (?∪?);
455 nrewrite > (cup_dotD…); nrewrite > (epsilon_dot…); //;
456 ##| nwhd in match (〈e,false〉^⊛); nchange in match (𝐋\p 〈?,?〉) with (?∪?);
458 nchange in ⊢ (??%?) with (𝐋\p e · 𝐋 |e|^* );
459 nrewrite < (cup0 ? (𝐋\p e)); //;##]
462 nlet rec pre_of_re (S : Alpha) (e : re S) on e : pitem S ≝
467 | c e1 e2 ⇒ pc ? (pre_of_re ? e1) (pre_of_re ? e2)
468 | o e1 e2 ⇒ po ? (pre_of_re ? e1) (pre_of_re ? e2)
469 | k e1 ⇒ pk ? (pre_of_re ? e1)].
471 nlemma notFalse : ¬False. @; //; nqed.
473 nlemma dot0 : ∀S.∀A:word S → Prop. {} · A = {}.
474 #S A; nnormalize; napply extP; #w; @; ##[##2: *]
475 *; #w1; *; #w2; *; *; //; nqed.
477 nlemma Lp_pre_of_re : ∀S.∀e:re S. 𝐋\p (pre_of_re ? e) = {}.
478 #S e; nelim e; ##[##1,2,3: //]
479 ##[ #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1 e2))) with (?∪?);
480 nrewrite > H1; nrewrite > H2; nrewrite > (dot0…); nrewrite > (cupID…);//
481 ##| #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1+e2))) with (?∪?);
482 nrewrite > H1; nrewrite > H2; nrewrite > (cupID…); //
483 ##| #e1 H1; nchange in match (𝐋\p (pre_of_re S (e1^* ))) with (𝐋\p (pre_of_re ??) · ?);
484 nrewrite > H1; napply dot0; ##]
487 nlemma erase_pre_of_reK : ∀S.∀e. 𝐋 |pre_of_re S e| = 𝐋 e.
489 ##[ #e1 e2 H1 H2; nchange in match (𝐋 (e1 · e2)) with (𝐋 e1·?);
490 nrewrite < H1; nrewrite < H2; //
491 ##| #e1 e2 H1 H2; nchange in match (𝐋 (e1 + e2)) with (𝐋 e1 ∪ ?);
492 nrewrite < H1; nrewrite < H2; //
493 ##| #e1 H1; nchange in match (𝐋 (e1^* )) with ((𝐋 e1)^* );
498 nlemma L_Lp_bull : ∀S.∀e:re S.𝐋 e = 𝐋\p (•pre_of_re ? e).
499 #S e; nrewrite > (bull_cup…); nrewrite > (Lp_pre_of_re…);
500 nrewrite > (cupC…); nrewrite > (cup0…); nrewrite > (erase_pre_of_reK…); //;
503 nlemma Pext : ∀S.∀f,g:word S → Prop. f = g → ∀w.f w → g w.
504 #S f g H; nrewrite > H; //; nqed.
507 ntheorem bull_true_epsilon : ∀S.∀e:pitem S. \snd (•e) = true ↔ [ ] ∈ |e|.
509 ##[ #defsnde; nlapply (bull_cup ? e); nchange in match (𝐋\p (•e)) with (?∪?);
510 nrewrite > defsnde; #H;
511 nlapply (Pext ??? H [ ] ?); ##[ @2; //] *; //;
515 notation > "\move term 90 x term 90 E"
516 non associative with precedence 60 for @{move ? $x $E}.
517 nlet rec move (S: Alpha) (x:S) (E: pitem S) on E : pre S ≝
521 | ps y ⇒ 〈 `y, false 〉
522 | pp y ⇒ 〈 `y, x == y 〉
523 | po e1 e2 ⇒ \move x e1 ⊕ \move x e2
524 | pc e1 e2 ⇒ \move x e1 ⊙ \move x e2
525 | pk e ⇒ (\move x e)^⊛ ].
526 notation < "\move\shy x\shy E" non associative with precedence 60 for @{'move $x $E}.
527 notation > "\move term 90 x term 90 E" non associative with precedence 60 for @{'move $x $E}.
528 interpretation "move" 'move x E = (move ? x E).
530 ndefinition rmove ≝ λS:Alpha.λx:S.λe:pre S. \move x (\fst e).
531 interpretation "rmove" 'move x E = (rmove ? x E).
533 nlemma XXz : ∀S:Alpha.∀w:word S. w ∈ ∅ → False.
534 #S w abs; ninversion abs; #; ndestruct;
538 nlemma XXe : ∀S:Alpha.∀w:word S. w .∈ ϵ → False.
539 #S w abs; ninversion abs; #; ndestruct;
542 nlemma XXze : ∀S:Alpha.∀w:word S. w .∈ (∅ · ϵ) → False.
543 #S w abs; ninversion abs; #; ndestruct; /2/ by XXz,XXe;
548 ∀S.∀w:word S.∀x.∀E1,E2:pitem S. w .∈ \move x (E1 · E2) →
549 (∃w1.∃w2. w = w1@w2 ∧ w1 .∈ \move x E1 ∧ w2 ∈ .|E2|) ∨ w .∈ \move x E2.
550 #S w x e1 e2 H; nchange in H with (w .∈ \move x e1 ⊙ \move x e2);
551 ncases e1 in H; ncases e2;
552 ##[##1: *; ##[*; nnormalize; #; ndestruct]
553 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
554 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
555 ##|##2: *; ##[*; nnormalize; #; ndestruct]
556 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
557 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
558 ##| #r; *; ##[ *; nnormalize; #; ndestruct]
559 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
560 ##[##2: nnormalize; #; ndestruct; @2; @2; //.##]
561 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz;
562 ##| #y; *; ##[ *; nnormalize; #defw defx; ndestruct; @2; @1; /2/ by conj;##]
563 #H; ninversion H; nnormalize; #; ndestruct;
564 ##[ncases (?:False); /2/ by XXz] /3/ by or_intror;
565 ##| #r1 r2; *; ##[ *; #defw]
570 ∀S:Alpha.∀E:pre S.∀a,w.w .∈ \move a E ↔ (a :: w) .∈ E.
571 #S E; ncases E; #r b; nelim r;
573 ##[##1,3: nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #abs; ncases (XXz … abs); ##]
574 #H; ninversion H; #; ndestruct;
575 ##|##*:nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #H1; ncases (XXz … H1); ##]
576 #H; ninversion H; #; ndestruct;##]
577 ##|#a c w; @; nnormalize; ##[*; ##[*; #; ndestruct; ##] #abs; ninversion abs; #; ndestruct;##]
578 *; ##[##2: #abs; ninversion abs; #; ndestruct; ##] *; #; ndestruct;
579 ##|#a c w; @; nnormalize;
580 ##[ *; ##[ *; #defw; nrewrite > defw; #ca; @2; nrewrite > (eqb_t … ca); @; ##]
581 #H; ninversion H; #; ndestruct;
582 ##| *; ##[ *; #; ndestruct; ##] #H; ninversion H; ##[##2,3,4,5,6: #; ndestruct]
583 #d defw defa; ndestruct; @1; @; //; nrewrite > (eqb_true S d d); //. ##]
584 ##|#r1 r2 H1 H2 a w; @;
585 ##[ #H; ncases (in_move_cat … H);
586 ##[ *; #w1; *; #w2; *; *; #defw w1m w2m;
587 ncases (H1 a w1); #H1w1; #_; nlapply (H1w1 w1m); #good;
588 nrewrite > defw; @2; @2 (a::w1); //; ncases good; ##[ *; #; ndestruct] //.
597 notation > "x ↦* E" non associative with precedence 60 for @{move_star ? $x $E}.
598 nlet rec move_star (S : decidable) w E on w : bool × (pre S) ≝
601 | cons x w' ⇒ w' ↦* (x ↦ \snd E)].
603 ndefinition in_moves ≝ λS:decidable.λw.λE:bool × (pre S). \fst(w ↦* E).
605 ncoinductive equiv (S:decidable) : bool × (pre S) → bool × (pre S) → Prop ≝
607 ∀E1,E2: bool × (pre S).
609 (∀x. equiv S (x ↦ \snd E1) (x ↦ \snd E2)) →
612 ndefinition NAT: decidable.
616 include "hints_declaration.ma".
618 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
619 unification hint 0 ≔ ; X ≟ NAT ⊢ carr X ≡ nat.
621 ninductive unit: Type[0] ≝ I: unit.
623 nlet corec foo_nop (b: bool):
625 〈 b, pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0))) 〉
626 〈 b, pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0) 〉 ≝ ?.
628 [ nnormalize in ⊢ (??%%); napply (foo_nop false)
630 [ nnormalize in ⊢ (??%%); napply (foo_nop false)
631 | #w; nnormalize in ⊢ (??%%); napply (foo_nop false) ]##]
635 nlet corec foo (a: unit):
637 (eclose NAT (pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0)))))
638 (eclose NAT (pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0)))
643 [ nnormalize in ⊢ (??%%);
644 nnormalize in foo: (? → ??%%);
646 [ nnormalize in ⊢ (??%%); napply foo_nop
648 [ nnormalize in ⊢ (??%%);
650 ##| #z; nnormalize in ⊢ (??%%); napply foo_nop ]##]
651 ##| #y; nnormalize in ⊢ (??%%); napply foo_nop
656 ndefinition test1 : pre ? ≝ ❨ `0 | `1 ❩^* `0.
657 ndefinition test2 : pre ? ≝ ❨ (`0`1)^* `0 | (`0`1)^* `1 ❩.
658 ndefinition test3 : pre ? ≝ (`0 (`0`1)^* `1)^*.
661 nlemma foo: in_moves ? [0;0;1;0;1;1] (ɛ test3) = true.
662 nnormalize in match test3;
667 (**********************************************************)
669 ninductive der (S: Type[0]) (a: S) : re S → re S → CProp[0] ≝
670 der_z: der S a (z S) (z S)
671 | der_e: der S a (e S) (z S)
672 | der_s1: der S a (s S a) (e ?)
673 | der_s2: ∀b. a ≠ b → der S a (s S b) (z S)
674 | der_c1: ∀e1,e2,e1',e2'. in_l S [] e1 → der S a e1 e1' → der S a e2 e2' →
675 der S a (c ? e1 e2) (o ? (c ? e1' e2) e2')
676 | der_c2: ∀e1,e2,e1'. Not (in_l S [] e1) → der S a e1 e1' →
677 der S a (c ? e1 e2) (c ? e1' e2)
678 | der_o: ∀e1,e2,e1',e2'. der S a e1 e1' → der S a e2 e2' →
679 der S a (o ? e1 e2) (o ? e1' e2').
681 nlemma eq_rect_CProp0_r:
682 ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (refl A a) → P x p.
683 #A; #a; #x; #p; ncases p; #P; #H; nassumption.
686 nlemma append1: ∀A.∀a:A.∀l. [a] @ l = a::l. //. nqed.
688 naxiom in_l1: ∀S,r1,r2,w. in_l S [ ] r1 → in_l S w r2 → in_l S w (c S r1 r2).
689 (* #S; #r1; #r2; #w; nelim r1
691 | #H1; #H2; napply (in_c ? []); //
692 | (* tutti casi assurdi *) *)
694 ninductive in_l' (S: Type[0]) : word S → re S → CProp[0] ≝
695 in_l_empty1: ∀E.in_l S [] E → in_l' S [] E
696 | in_l_cons: ∀a,w,e,e'. in_l' S w e' → der S a e e' → in_l' S (a::w) e.
698 ncoinductive eq_re (S: Type[0]) : re S → re S → CProp[0] ≝
700 (in_l S [] E1 → in_l S [] E2) →
701 (in_l S [] E2 → in_l S [] E1) →
702 (∀a,E1',E2'. der S a E1 E1' → der S a E2 E2' → eq_re S E1' E2') →
705 (* serve il lemma dopo? *)
706 ntheorem eq_re_is_eq: ∀S.∀E1,E2. eq_re S E1 E2 → ∀w. in_l ? w E1 → in_l ? w E2.
707 #S; #E1; #E2; #H1; #w; #H2; nelim H2 in E2 H1 ⊢ %
709 | #a; #w; #R1; #R2; #K1; #K2; #K3; #R3; #K4; @2 R2; //; ncases K4;
711 (* IL VICEVERSA NON VALE *)
712 naxiom in_l_to_in_l: ∀S,w,E. in_l' S w E → in_l S w E.
713 (* #S; #w; #E; #H; nelim H
715 | #a; #w'; #r; #r'; #H1; (* e si cade qua sotto! *)
719 ntheorem der1: ∀S,a,e,e',w. der S a e e' → in_l S w e' → in_l S (a::w) e.
720 #S; #a; #E; #E'; #w; #H; nelim H
721 [##1,2: #H1; ninversion H1
722 [##1,8: #_; #K; (* non va ndestruct K; *) ncases (?:False); (* perche' due goal?*) /2/
723 |##2,9: #X; #Y; #K; ncases (?:False); /2/
724 |##3,10: #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
725 |##4,11: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
726 |##5,12: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
727 |##6,13: #x; #y; #K; ncases (?:False); /2/
728 |##7,14: #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/]
729 ##| #H1; ninversion H1
731 | #X; #Y; #K; ncases (?:False); /2/
732 | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
733 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
734 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
735 | #x; #y; #K; ncases (?:False); /2/
736 | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
737 ##| #H1; #H2; #H3; ninversion H3
738 [ #_; #K; ncases (?:False); /2/
739 | #X; #Y; #K; ncases (?:False); /2/
740 | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
741 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
742 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
743 | #x; #y; #K; ncases (?:False); /2/
744 | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
745 ##| #r1; #r2; #r1'; #r2'; #H1; #H2; #H3; #H4; #H5; #H6;