1 include "tutorial/chapter3.ma".
3 (* As a simple application of lists, let us now consider strings of characters
4 over a given alphabet Alpha. We shall assume to have a decidable equality between
5 characters, that is a (computable) function eqb associating a boolean value true
6 or false to each pair of characters; eqb is correct, in the sense that (eqb x y)
7 if and only if (x = y). The type Alpha of alphabets is hence defined by the
10 interpretation "iff" 'iff a b = (iff a b).
12 record Alpha : Type[1] ≝ { carr :> Type[0];
13 eqb: carr → carr →
\ 5a href="cic:/matita/basics/bool/bool.ind(1,0,0)"
\ 6bool
\ 5/a
\ 6;
14 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)
17 notation "a == b" non associative with precedence 45 for @{ 'eqb $a $b }.
18 interpretation "eqb" 'eqb a b = (eqb ? a b).
20 definition word ≝ λS:
\ 5a href="cic:/matita/tutorial/chapter4/Alpha.ind(1,0,0)"
\ 6Alpha
\ 5/a
\ 6.
\ 5a href="cic:/matita/tutorial/chapter3/list.ind(1,0,1)"
\ 6list
\ 5/a
\ 6 S.
22 inductive re (S:
\ 5a href="cic:/matita/tutorial/chapter4/Alpha.ind(1,0,0)"
\ 6Alpha
\ 5/a
\ 6) : Type[0] ≝
26 | concat: re S → re S → re S
27 | or: re S → re S → re S
30 (* notation < "a \sup ⋇" non associative with precedence 90 for @{ 'pk $a}. *)
31 notation "a ^ *" non associative with precedence 90 for @{ 'kstar $a}.
32 interpretation "star" 'kstar a = (star ? a).
33 interpretation "or" 'plus a b = (or ? a b).
35 notation "a · b" non associative with precedence 60 for @{ 'concat $a $b}.
36 interpretation "cat" 'concat a b = (concat ? a b).
38 (* to get rid of \middot
39 coercion c : ∀S:Alpha.∀p:re S. re S → re S ≝ c on _p : re ? to ∀_:?.?. *)
41 (* notation < "a" non associative with precedence 90 for @{ 'ps $a}. *)
42 notation "` term 90 a" non associative with precedence 90 for @{ 'atom $a}.
43 interpretation "atom" 'atom a = (char ? a).
45 notation "ϵ" non associative with precedence 90 for @{ 'epsilon }.
46 interpretation "epsilon" 'epsilon = (epsilon ?).
48 notation "∅" (* slash emptyv *) non associative with precedence 90 for @{ 'empty }.
49 interpretation "empty" 'empty = (zero ?).
51 let rec flatten (S :
\ 5a href="cic:/matita/tutorial/chapter4/Alpha.ind(1,0,0)"
\ 6Alpha
\ 5/a
\ 6) (l :
\ 5a href="cic:/matita/tutorial/chapter3/list.ind(1,0,1)"
\ 6list
\ 5/a
\ 6 (
\ 5a href="cic:/matita/tutorial/chapter4/word.def(3)"
\ 6word
\ 5/a
\ 6 S)) on l :
\ 5a href="cic:/matita/tutorial/chapter4/word.def(3)"
\ 6word
\ 5/a
\ 6 S ≝
52 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 ].
54 let rec conjunct (S :
\ 5a href="cic:/matita/tutorial/chapter4/Alpha.ind(1,0,0)"
\ 6Alpha
\ 5/a
\ 6) (l :
\ 5a href="cic:/matita/tutorial/chapter3/list.ind(1,0,1)"
\ 6list
\ 5/a
\ 6 (
\ 5a href="cic:/matita/tutorial/chapter4/word.def(3)"
\ 6word
\ 5/a
\ 6 S)) (L :
\ 5a href="cic:/matita/tutorial/chapter4/word.def(3)"
\ 6word
\ 5/a
\ 6 S → Prop) on l: Prop ≝
55 match l with [ nil ⇒
\ 5a href="cic:/matita/basics/logic/True.ind(1,0,0)"
\ 6True
\ 5/a
\ 6 | cons w tl ⇒ L w
\ 5a title="logical and" href="cic:/fakeuri.def(1)"
\ 6∧
\ 5/a
\ 6 conjunct ? tl L ].
57 definition empty_lang ≝ λS.λw:
\ 5a href="cic:/matita/tutorial/chapter4/word.def(3)"
\ 6word
\ 5/a
\ 6 S.
\ 5a href="cic:/matita/basics/logic/False.ind(1,0,0)"
\ 6False
\ 5/a
\ 6.
58 (* notation "{}" non associative with precedence 90 for @{'empty_lang}. *)
59 interpretation "empty lang" 'empty = (empty_lang ?).
61 definition sing_lang ≝ λS.λx,w:
\ 5a href="cic:/matita/tutorial/chapter4/word.def(3)"
\ 6word
\ 5/a
\ 6 S.x
\ 5a title="leibnitz's equality" href="cic:/fakeuri.def(1)"
\ 6=
\ 5/a
\ 6 w.
62 notation "{: x }" non associative with precedence 90 for @{'sing_lang $x}.
63 interpretation "sing lang" 'sing_lang x = (sing_lang ? x).
65 definition union : ∀S,L1,L2,w.Prop ≝ λS,L1,L2.λw:
\ 5a href="cic:/matita/tutorial/chapter4/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.
66 interpretation "union lang" 'union a b = (union ? a b).
68 definition cat : ∀S,l1,l2,w.Prop ≝
69 λS.λl1,l2.λw:
\ 5a href="cic:/matita/tutorial/chapter4/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.
70 interpretation "cat lang" 'concat a b = (cat ? a b).
72 definition star_lang ≝ λS.λl.λw:
\ 5a href="cic:/matita/tutorial/chapter4/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/chapter4/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/chapter4/conjunct.fix(0,1,4)"
\ 6conjunct
\ 5/a
\ 6 ? lw l.
73 interpretation "star lang" 'kstar l = (star_lang ? l).
75 (* notation "| term 70 E| " non associative with precedence 75 for @{in_l ? $E}. *)
77 let rec in_l (S :
\ 5a href="cic:/matita/tutorial/chapter4/Alpha.ind(1,0,0)"
\ 6Alpha
\ 5/a
\ 6) (r :
\ 5a href="cic:/matita/tutorial/chapter4/re.ind(1,0,1)"
\ 6re
\ 5/a
\ 6 S) on r :
\ 5a href="cic:/matita/tutorial/chapter4/word.def(3)"
\ 6word
\ 5/a
\ 6 S → Prop ≝
79 [ zero ⇒
\ 5a title="empty lang" href="cic:/fakeuri.def(1)"
\ 6∅
\ 5/a
\ 6
80 | epsilon ⇒
\ 5a title="sing lang" href="cic:/fakeuri.def(1)"
\ 6{
\ 5/a
\ 6:
\ 5a title="nil" href="cic:/fakeuri.def(1)"
\ 6[
\ 5/a
\ 6] }
81 | char x ⇒
\ 5a title="sing lang" href="cic:/fakeuri.def(1)"
\ 6{
\ 5/a
\ 6: x
\ 5a title="cons" href="cic:/fakeuri.def(1)"
\ 6:
\ 5/a
\ 6:
\ 5a title="nil" href="cic:/fakeuri.def(1)"
\ 6[
\ 5/a
\ 6] }
82 | concat r1 r2 ⇒ in_l ? r1
\ 5a title="cat lang" href="cic:/fakeuri.def(1)"
\ 6·
\ 5/a
\ 6 in_l ? r2
83 | or r1 r2 ⇒ in_l ? r1
\ 5a title="union lang" href="cic:/fakeuri.def(1)"
\ 6∪
\ 5/a
\ 6 in_l ? r2
84 | star r1 ⇒ (in_l ? r1)
\ 5a title="star lang" href="cic:/fakeuri.def(1)"
\ 6^
\ 5/a
\ 6*
87 notation "\sem{E}" non associative with precedence 75 for @{'sem $E}.
88 interpretation "in_l" 'sem E = (in_l ? E).
89 interpretation "in_l mem" 'mem w l = (in_l ? l w).
91 notation "a ∨ b" left associative with precedence 30 for @{'orb $a $b}.
92 interpretation "orb" 'orb a b = (orb a b).
94 (* ndefinition if_then_else ≝ λT:Type[0].λe,t,f.match e return λ_.T with [ true ⇒ t | false ⇒ f].
95 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 }.
96 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 }.
97 interpretation "if_then_else" 'if_then_else e t f = (if_then_else ? e t f). *)
99 inductive pitem (S:
\ 5a href="cic:/matita/tutorial/chapter4/Alpha.ind(1,0,0)"
\ 6Alpha
\ 5/a
\ 6) : Type[0] ≝
103 | ppoint: S → pitem S
104 | pconcat: pitem S → pitem S → pitem S
105 | por: pitem S → pitem S → pitem S
106 | pstar: pitem S → pitem S.
108 definition pre ≝ λS.
\ 5a href="cic:/matita/tutorial/chapter4/pitem.ind(1,0,1)"
\ 6pitem
\ 5/a
\ 6 S
\ 5a title="Product" href="cic:/fakeuri.def(1)"
\ 6×
\ 5/a
\ 6 \ 5a href="cic:/matita/basics/bool/bool.ind(1,0,0)" title="null"
\ 6bool
\ 5/a
\ 6.
110 definition test ≝ λS:Alpha.λe: pre S. match e with [mk_pair i b ⇒ e].
112 interpretation "pstar" 'kstar a = (pstar ? a).
113 interpretation "por" 'plus a b = (por ? a b).
114 interpretation "pcat" 'concat a b = (pconcat ? a b).
116 notation "• a" non associative with precedence 90 for @{ 'ppoint $a}.
117 (* notation > "`. term 90 a" non associative with precedence 90 for @{ 'pp $a}. *)
119 interpretation "ppatom" 'ppoint a = (ppoint ? a).
120 (* to get rid of \middot
121 ncoercion pc : ∀S.∀p:pitem S. pitem S → pitem S ≝ pc on _p : pitem ? to ∀_:?.?. *)
122 interpretation "patom" 'pchar a = (pchar ? a).
123 interpretation "pepsilon" 'epsilon = (pepsilon ?).
124 interpretation "pempty" 'empty = (pzero ?).
126 notation "| e |" non associative with precedence 65 for @{forget ? $e}.
128 let rec forget (S:
\ 5a href="cic:/matita/tutorial/chapter4/Alpha.ind(1,0,0)"
\ 6Alpha
\ 5/a
\ 6) (l :
\ 5a href="cic:/matita/tutorial/chapter4/pitem.ind(1,0,1)"
\ 6pitem
\ 5/a
\ 6 S) on l:
\ 5a href="cic:/matita/tutorial/chapter4/re.ind(1,0,1)"
\ 6re
\ 5/a
\ 6 S ≝
130 [ pzero ⇒
\ 5a title="empty" href="cic:/fakeuri.def(1)"
\ 6∅
\ 5/a
\ 6
131 | pepsilon ⇒
\ 5a title="epsilon" href="cic:/fakeuri.def(1)"
\ 6ϵ
\ 5/a
\ 6
132 | pchar x ⇒
\ 5a href="cic:/matita/tutorial/chapter4/re.con(0,3,1)"
\ 6char
\ 5/a
\ 6 ? x
133 | ppoint x ⇒
\ 5a href="cic:/matita/tutorial/chapter4/re.con(0,3,1)"
\ 6char
\ 5/a
\ 6 ? x
134 | pconcat e1 e2 ⇒ |e1|
\ 5a title="cat" href="cic:/fakeuri.def(1)"
\ 6·
\ 5/a
\ 6 |e2|
135 | por e1 e2 ⇒ |e1|
\ 5a title="or" href="cic:/fakeuri.def(1)"
\ 6+
\ 5/a
\ 6 |e2|
136 | pstar e ⇒ |e|
\ 5a title="star" href="cic:/fakeuri.def(1)"
\ 6^
\ 5/a
\ 6*
139 notation "| e |" non associative with precedence 65 for @{'fmap $e}.
140 interpretation "forget" 'fmap a = (forget ? a).
142 let rec in_pl (S :
\ 5a href="cic:/matita/tutorial/chapter4/Alpha.ind(1,0,0)"
\ 6Alpha
\ 5/a
\ 6) (r :
\ 5a href="cic:/matita/tutorial/chapter4/pitem.ind(1,0,1)"
\ 6pitem
\ 5/a
\ 6 S) on r :
\ 5a href="cic:/matita/tutorial/chapter4/word.def(3)"
\ 6word
\ 5/a
\ 6 S → Prop ≝
144 [ pzero ⇒
\ 5a title="empty lang" href="cic:/fakeuri.def(1)"
\ 6∅
\ 5/a
\ 6
145 | pepsilon ⇒
\ 5a title="empty lang" href="cic:/fakeuri.def(1)"
\ 6∅
\ 5/a
\ 6
146 | pchar _ ⇒
\ 5a title="empty lang" href="cic:/fakeuri.def(1)"
\ 6∅
\ 5/a
\ 6
147 | ppoint x ⇒
\ 5a title="sing lang" href="cic:/fakeuri.def(1)"
\ 6{
\ 5/a
\ 6: x
\ 5a title="cons" href="cic:/fakeuri.def(1)"
\ 6:
\ 5/a
\ 6:
\ 5a title="nil" href="cic:/fakeuri.def(1)"
\ 6[
\ 5/a
\ 6] }
148 | pconcat pe1 pe2 ⇒ in_pl ? pe1
\ 5a title="cat lang" href="cic:/fakeuri.def(1)"
\ 6·
\ 5/a
\ 6 \ 5a title="in_l" href="cic:/fakeuri.def(1)"
\ 6\sem
\ 5/a
\ 6{|pe2|}
\ 5a title="union lang" href="cic:/fakeuri.def(1)"
\ 6∪
\ 5/a
\ 6 in_pl ? pe2
149 | por pe1 pe2 ⇒ in_pl ? pe1
\ 5a title="union lang" href="cic:/fakeuri.def(1)"
\ 6∪
\ 5/a
\ 6 in_pl ? pe2
150 | pstar pe ⇒ in_pl ? pe
\ 5a title="cat lang" href="cic:/fakeuri.def(1)"
\ 6·
\ 5/a
\ 6 \ 5a title="in_l" href="cic:/fakeuri.def(1)"
\ 6\sem
\ 5/a
\ 6{|pe|}
\ 5a title="star lang" href="cic:/fakeuri.def(1)"
\ 6^
\ 5/a
\ 6*
153 interpretation "in_pl" 'sem E = (in_pl ? E).
154 interpretation "in_pl mem" 'mem w l = (in_pl ? l w).
156 definition eps: ∀S:
\ 5a href="cic:/matita/tutorial/chapter4/Alpha.ind(1,0,0)"
\ 6Alpha
\ 5/a
\ 6.
\ 5a href="cic:/matita/basics/bool/bool.ind(1,0,0)"
\ 6bool
\ 5/a
\ 6 →
\ 5a href="cic:/matita/tutorial/chapter4/word.def(3)"
\ 6word
\ 5/a
\ 6 S → Prop
157 ≝ λS,b.
\ 5a href="cic:/matita/basics/bool/if_then_else.def(1)"
\ 6if_then_else
\ 5/a
\ 6 ? b
\ 5a title="sing lang" href="cic:/fakeuri.def(1)"
\ 6{
\ 5/a
\ 6:
\ 5a title="nil" href="cic:/fakeuri.def(1)"
\ 6[
\ 5/a
\ 6] }
\ 5a title="empty lang" href="cic:/fakeuri.def(1)"
\ 6∅
\ 5/a
\ 6.
159 notation "ϵ _ b" non associative with precedence 90 for @{'app_epsilon $b}.
160 interpretation "epsilon lang" 'app_epsilon b = (eps ? b).
162 definition in_prl ≝ λS :
\ 5a href="cic:/matita/tutorial/chapter4/Alpha.ind(1,0,0)"
\ 6Alpha
\ 5/a
\ 6.λp:
\ 5a href="cic:/matita/tutorial/chapter4/pre.def(1)"
\ 6pre
\ 5/a
\ 6 S.
\ 5a title="in_pl" href="cic:/fakeuri.def(1)"
\ 6\sem
\ 5/a
\ 6{
\ 5a title="pair pi1" href="cic:/fakeuri.def(1)"
\ 6\fst
\ 5/a
\ 6 p}
\ 5a title="union lang" href="cic:/fakeuri.def(1)"
\ 6∪
\ 5/a
\ 6 \ 5a title="epsilon lang" href="cic:/fakeuri.def(1)"
\ 6ϵ
\ 5/a
\ 6_(
\ 5a title="pair pi2" href="cic:/fakeuri.def(1)"
\ 6\snd
\ 5/a
\ 6 p).
164 interpretation "in_prl mem" 'mem w l = (in_prl ? l w).
165 interpretation "in_prl" 'sem E = (in_prl ? E).
167 lemma not_epsilon_lp :∀S.∀pi:
\ 5a href="cic:/matita/tutorial/chapter4/pitem.ind(1,0,1)"
\ 6pitem
\ 5/a
\ 6 S.
\ 5a title="logical not" href="cic:/fakeuri.def(1)"
\ 6\neg
\ 5/a
\ 6(
\ 5a title="nil" href="cic:/fakeuri.def(1)"
\ 6[
\ 5/a
\ 6]
\ 5a title="in_pl mem" href="cic:/fakeuri.def(1)"
\ 6∈
\ 5/a
\ 6 pi).
168 #S #pi (elim pi) normalize /
\ 5span class="autotactic"
\ 62
\ 5span class="autotrace"
\ 6 trace
\ 5a href="cic:/matita/basics/logic/Not.con(0,1,1)"
\ 6nmk
\ 5/a
\ 6\ 5/span
\ 6\ 5/span
\ 6/
169 [#pi1 #pi2 #H1 #H2 % * /
\ 5span class="autotactic"
\ 62
\ 5span class="autotrace"
\ 6 trace
\ 5a href="cic:/matita/basics/logic/absurd.def(2)"
\ 6absurd
\ 5/a
\ 6\ 5/span
\ 6\ 5/span
\ 6/ * #w1 * #w2 * * #appnil
170 cases (
\ 5a href="cic:/matita/tutorial/chapter3/nil_to_nil.def(5)"
\ 6nil_to_nil
\ 5/a
\ 6 … appnil) /
\ 5span class="autotactic"
\ 62
\ 5span class="autotrace"
\ 6 trace
\ 5a href="cic:/matita/basics/logic/absurd.def(2)"
\ 6absurd
\ 5/a
\ 6\ 5/span
\ 6\ 5/span
\ 6/
171 |#p11 #p12 #H1 #H2 % * /
\ 5span class="autotactic"
\ 62
\ 5span class="autotrace"
\ 6 trace
\ 5a href="cic:/matita/basics/logic/absurd.def(2)"
\ 6absurd
\ 5/a
\ 6\ 5/span
\ 6\ 5/span
\ 6/
172 |#pi #H % * #w1 * #w2 * * #appnil (cases (
\ 5a href="cic:/matita/tutorial/chapter3/nil_to_nil.def(5)"
\ 6nil_to_nil
\ 5/a
\ 6 … appnil)) /
\ 5span class="autotactic"
\ 62
\ 5span class="autotrace"
\ 6 trace
\ 5a href="cic:/matita/basics/logic/absurd.def(2)"
\ 6absurd
\ 5/a
\ 6\ 5/span
\ 6\ 5/span
\ 6/
176 lemma if_true_epsilon: ∀S.∀e:
\ 5a href="cic:/matita/tutorial/chapter4/pre.def(1)"
\ 6pre
\ 5/a
\ 6 S.
\ 5a title="pair pi2" href="cic:/fakeuri.def(1)"
\ 6\snd
\ 5/a
\ 6 e
\ 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="nil" href="cic:/fakeuri.def(1)"
\ 6[
\ 5/a
\ 6]
\ 5a title="in_prl mem" href="cic:/fakeuri.def(1)"
\ 6∈
\ 5/a
\ 6 e).
177 #S #e #H %2 >H // qed.
179 lemma if_epsilon_true : ∀S.∀e:
\ 5a href="cic:/matita/tutorial/chapter4/pre.def(1)"
\ 6pre
\ 5/a
\ 6 S.
\ 5a title="nil" href="cic:/fakeuri.def(1)"
\ 6[
\ 5/a
\ 6 ]
\ 5a title="in_prl mem" href="cic:/fakeuri.def(1)"
\ 6∈
\ 5/a
\ 6 e →
\ 5a title="pair pi2" href="cic:/fakeuri.def(1)"
\ 6\snd
\ 5/a
\ 6 e
\ 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.
180 #S * #pi #b * [normalize #abs @
\ 5a href="cic:/matita/basics/logic/False_ind.fix(0,1,1)"
\ 6False_ind
\ 5/a
\ 6 /
\ 5span class="autotactic"
\ 62
\ 5span class="autotrace"
\ 6 trace
\ 5a href="cic:/matita/basics/logic/absurd.def(2)"
\ 6absurd
\ 5/a
\ 6\ 5/span
\ 6\ 5/span
\ 6/] cases b normalize // @
\ 5a href="cic:/matita/basics/logic/False_ind.fix(0,1,1)"
\ 6False_ind
\ 5/a
\ 6
183 definition lor ≝ λS:
\ 5a href="cic:/matita/tutorial/chapter4/Alpha.ind(1,0,0)"
\ 6Alpha
\ 5/a
\ 6.λa,b:
\ 5a href="cic:/matita/tutorial/chapter4/pre.def(1)"
\ 6pre
\ 5/a
\ 6 S.
\ 5a title="Pair construction" href="cic:/fakeuri.def(1)"
\ 6〈
\ 5/a
\ 6\ 5a title="pair pi1" href="cic:/fakeuri.def(1)"
\ 6\fst
\ 5/a
\ 6 a
\ 5a title="por" href="cic:/fakeuri.def(1)"
\ 6+
\ 5/a
\ 6 \ 5a title="pair pi1" href="cic:/fakeuri.def(1)"
\ 6\fst
\ 5/a
\ 6 b,
\ 5a title="pair pi2" href="cic:/fakeuri.def(1)"
\ 6\snd
\ 5/a
\ 6 a
\ 5a title="boolean or" href="cic:/fakeuri.def(1)"
\ 6∨
\ 5/a
\ 6 \ 5a title="pair pi2" href="cic:/fakeuri.def(1)"
\ 6\snd
\ 5/a
\ 6 b〉.
185 notation "a ⊕ b" left associative with precedence 60 for @{'oplus $a $b}.
186 interpretation "oplus" 'oplus a b = (lor ? a b).
188 definition item_concat: ∀S:
\ 5a href="cic:/matita/tutorial/chapter4/Alpha.ind(1,0,0)"
\ 6Alpha
\ 5/a
\ 6.
\ 5a href="cic:/matita/tutorial/chapter4/pitem.ind(1,0,1)"
\ 6pitem
\ 5/a
\ 6 S →
\ 5a href="cic:/matita/tutorial/chapter4/pre.def(1)"
\ 6pre
\ 5/a
\ 6 S →
\ 5a href="cic:/matita/tutorial/chapter4/pre.def(1)"
\ 6pre
\ 5/a
\ 6 S ≝
189 λS,i,e.
\ 5a title="Pair construction" href="cic:/fakeuri.def(1)"
\ 6〈
\ 5/a
\ 6i
\ 5a title="pcat" href="cic:/fakeuri.def(1)"
\ 6·
\ 5/a
\ 6 \ 5a title="pair pi1" href="cic:/fakeuri.def(1)"
\ 6\fst
\ 5/a
\ 6 e,
\ 5a title="pair pi2" href="cic:/fakeuri.def(1)"
\ 6\snd
\ 5/a
\ 6 e〉.
191 definition lcat: ∀S:Alpha.∀bcast:(∀S:Alpha.pre S →pre S).pre S → pre S → pre S
192 ≝ λS:Alpha.λbcast:∀S:Alpha.pre S → pre S.λe1,e2:pre S.
193 match e1 with [ mk_pair i1 b1 ⇒ e2].
195 match e1 with [ _ => e1].
198 [ false ⇒ e2 | _ => e1 ]].
200 | true ⇒ item_concat S i1 (bcast S e2)
204 notation < "a ⊙ b" left associative with precedence 60 for @{'lc $op $a $b}.
205 interpretation "lc" 'lc op a b = (lc ? op a b).
206 notation > "a ⊙ b" left associative with precedence 60 for @{'lc eclose $a $b}.
208 ndefinition lk ≝ λS:Alpha.λbcast:∀S:Alpha.∀E:pitem S.pre S.λa:pre S.
209 match a with [ mk_pair e1 b1 ⇒
211 [ false ⇒ 〈e1^*, false〉
212 | true ⇒ 〈(\fst (bcast ? e1))^*, true〉]].
214 notation < "a \sup ⊛" non associative with precedence 90 for @{'lk $op $a}.
215 interpretation "lk" 'lk op a = (lk ? op a).
216 notation > "a^⊛" non associative with precedence 90 for @{'lk eclose $a}.
218 notation > "•" non associative with precedence 60 for @{eclose ?}.
219 nlet rec eclose (S: Alpha) (E: pitem S) on E : pre S ≝
223 | ps x ⇒ 〈 `.x, false 〉
224 | pp x ⇒ 〈 `.x, false 〉
225 | po E1 E2 ⇒ •E1 ⊕ •E2
226 | pc E1 E2 ⇒ •E1 ⊙ 〈 E2, false 〉
227 | pk E ⇒ 〈(\fst (•E))^*,true〉].
228 notation < "• x" non associative with precedence 60 for @{'eclose $x}.
229 interpretation "eclose" 'eclose x = (eclose ? x).
230 notation > "• x" non associative with precedence 60 for @{'eclose $x}.
232 ndefinition reclose ≝ λS:Alpha.λp:pre S.let p' ≝ •\fst p in 〈\fst p',\snd p || \snd p'〉.
233 interpretation "reclose" 'eclose x = (reclose ? x).
235 ndefinition eq_f1 ≝ λS.λa,b:word S → Prop.∀w.a w ↔ b w.
236 notation > "A =1 B" non associative with precedence 45 for @{'eq_f1 $A $B}.
237 notation "A =\sub 1 B" non associative with precedence 45 for @{'eq_f1 $A $B}.
238 interpretation "eq f1" 'eq_f1 a b = (eq_f1 ? a b).
240 naxiom extP : ∀S.∀p,q:word S → Prop.(p =1 q) → p = q.
242 nlemma epsilon_or : ∀S:Alpha.∀b1,b2. ϵ(b1 || b2) = ϵ b1 ∪ ϵ b2. ##[##2: napply S]
243 #S b1 b2; ncases b1; ncases b2; napply extP; #w; nnormalize; @; /2/; *; //; *;
246 nlemma cupA : ∀S.∀a,b,c:word S → Prop.a ∪ b ∪ c = a ∪ (b ∪ c).
247 #S a b c; napply extP; #w; nnormalize; @; *; /3/; *; /3/; nqed.
249 nlemma cupC : ∀S. ∀a,b:word S → Prop.a ∪ b = b ∪ a.
250 #S a b; napply extP; #w; @; *; nnormalize; /2/; nqed.
253 nlemma oplus_cup : ∀S:Alpha.∀e1,e2:pre S.𝐋\p (e1 ⊕ e2) = 𝐋\p e1 ∪ 𝐋\p e2.
254 #S r1; ncases r1; #e1 b1 r2; ncases r2; #e2 b2;
255 nwhd in ⊢ (??(??%)?);
256 nchange in ⊢(??%?) with (𝐋\p (e1 + e2) ∪ ϵ (b1 || b2));
257 nchange in ⊢(??(??%?)?) with (𝐋\p (e1) ∪ 𝐋\p (e2));
258 nrewrite > (epsilon_or S …); nrewrite > (cupA S (𝐋\p e1) …);
259 nrewrite > (cupC ? (ϵ b1) …); nrewrite < (cupA S (𝐋\p e2) …);
260 nrewrite > (cupC ? ? (ϵ b1) …); nrewrite < (cupA …); //;
264 ∀S.∀e1,e2:pitem S.∀b2. 〈e1,true〉 ⊙ 〈e2,b2〉 = 〈e1 · \fst (•e2),b2 || \snd (•e2)〉.
265 #S e1 e2 b2; nnormalize; ncases (•e2); //; nqed.
267 nlemma LcatE : ∀S.∀e1,e2:pitem S.𝐋\p (e1 · e2) = 𝐋\p e1 · 𝐋 |e2| ∪ 𝐋\p e2. //; nqed.
269 nlemma cup_dotD : ∀S.∀p,q,r:word S → Prop.(p ∪ q) · r = (p · r) ∪ (q · r).
270 #S p q r; napply extP; #w; nnormalize; @;
271 ##[ *; #x; *; #y; *; *; #defw; *; /7/ by or_introl, or_intror, ex_intro, conj;
272 ##| *; *; #x; *; #y; *; *; /7/ by or_introl, or_intror, ex_intro, conj; ##]
275 nlemma cup0 :∀S.∀p:word S → Prop.p ∪ {} = p.
276 #S p; napply extP; #w; nnormalize; @; /2/; *; //; *; nqed.
278 nlemma erase_dot : ∀S.∀e1,e2:pitem S.𝐋 |e1 · e2| = 𝐋 |e1| · 𝐋 |e2|.
279 #S e1 e2; napply extP; nnormalize; #w; @; *; #w1; *; #w2; *; *; /7/ by ex_intro, conj;
282 nlemma erase_plus : ∀S.∀e1,e2:pitem S.𝐋 |e1 + e2| = 𝐋 |e1| ∪ 𝐋 |e2|.
283 #S e1 e2; napply extP; nnormalize; #w; @; *; /4/ by or_introl, or_intror; nqed.
285 nlemma erase_star : ∀S.∀e1:pitem S.𝐋 |e1|^* = 𝐋 |e1^*|. //; nqed.
287 ndefinition substract := λS.λp,q:word S → Prop.λw.p w ∧ ¬ q w.
288 interpretation "substract" 'minus a b = (substract ? a b).
290 nlemma cup_sub: ∀S.∀a,b:word S → Prop. ¬ (a []) → a ∪ (b - {[]}) = (a ∪ b) - {[]}.
291 #S a b c; napply extP; #w; nnormalize; @; *; /4/; *; /4/; nqed.
293 nlemma sub0 : ∀S.∀a:word S → Prop. a - {} = a.
294 #S a; napply extP; #w; nnormalize; @; /3/; *; //; nqed.
296 nlemma subK : ∀S.∀a:word S → Prop. a - a = {}.
297 #S a; napply extP; #w; nnormalize; @; *; /2/; nqed.
299 nlemma subW : ∀S.∀a,b:word S → Prop.∀w.(a - b) w → a w.
300 #S a b w; nnormalize; *; //; nqed.
302 nlemma erase_bull : ∀S.∀a:pitem S. |\fst (•a)| = |a|.
303 #S a; nelim a; // by {};
304 ##[ #e1 e2 IH1 IH2; nchange in ⊢ (???%) with (|e1| · |e2|);
305 nrewrite < IH1; nrewrite < IH2;
306 nchange in ⊢ (??(??%)?) with (\fst (•e1 ⊙ 〈e2,false〉));
307 ncases (•e1); #e3 b; ncases b; nnormalize;
308 ##[ ncases (•e2); //; ##| nrewrite > IH2; //]
309 ##| #e1 e2 IH1 IH2; nchange in ⊢ (???%) with (|e1| + |e2|);
310 nrewrite < IH2; nrewrite < IH1;
311 nchange in ⊢ (??(??%)?) with (\fst (•e1 ⊕ •e2));
312 ncases (•e1); ncases (•e2); //;
313 ##| #e IH; nchange in ⊢ (???%) with (|e|^* ); nrewrite < IH;
314 nchange in ⊢ (??(??%)?) with (\fst (•e))^*; //; ##]
317 nlemma eta_lp : ∀S.∀p:pre S.𝐋\p p = 𝐋\p 〈\fst p, \snd p〉.
318 #S p; ncases p; //; nqed.
320 nlemma epsilon_dot: ∀S.∀p:word S → Prop. {[]} · p = p.
321 #S e; napply extP; #w; nnormalize; @; ##[##2: #Hw; @[]; @w; /3/; ##]
322 *; #w1; *; #w2; *; *; #defw defw1 Hw2; nrewrite < defw; nrewrite < defw1;
325 (* theorem 16: 1 → 3 *)
326 nlemma odot_dot_aux : ∀S.∀e1,e2: pre S.
327 𝐋\p (•(\fst e2)) = 𝐋\p (\fst e2) ∪ 𝐋 |\fst e2| →
328 𝐋\p (e1 ⊙ e2) = 𝐋\p e1 · 𝐋 |\fst e2| ∪ 𝐋\p e2.
329 #S e1 e2 th1; ncases e1; #e1' b1'; ncases b1';
330 ##[ nwhd in ⊢ (??(??%)?); nletin e2' ≝ (\fst e2); nletin b2' ≝ (\snd e2);
331 nletin e2'' ≝ (\fst (•(\fst e2))); nletin b2'' ≝ (\snd (•(\fst e2)));
332 nchange in ⊢ (??%?) with (?∪?);
333 nchange in ⊢ (??(??%?)?) with (?∪?);
334 nchange in match (𝐋\p 〈?,?〉) with (?∪?);
335 nrewrite > (epsilon_or …); nrewrite > (cupC ? (ϵ ?)…);
336 nrewrite > (cupA …);nrewrite < (cupA ?? (ϵ?)…);
337 nrewrite > (?: 𝐋\p e2'' ∪ ϵ b2'' = 𝐋\p e2' ∪ 𝐋 |e2'|); ##[##2:
338 nchange with (𝐋\p 〈e2'',b2''〉 = 𝐋\p e2' ∪ 𝐋 |e2'|);
339 ngeneralize in match th1;
340 nrewrite > (eta_lp…); #th1; nrewrite > th1; //;##]
341 nrewrite > (eta_lp ? e2);
342 nchange in match (𝐋\p 〈\fst e2,?〉) with (𝐋\p e2'∪ ϵ b2');
343 nrewrite > (cup_dotD …); nrewrite > (epsilon_dot…);
344 nrewrite > (cupC ? (𝐋\p e2')…); nrewrite > (cupA…);nrewrite > (cupA…);
345 nrewrite < (erase_bull S e2') in ⊢ (???(??%?)); //;
346 ##| ncases e2; #e2' b2'; nchange in match (〈e1',false〉⊙?) with 〈?,?〉;
347 nchange in match (𝐋\p ?) with (?∪?);
348 nchange in match (𝐋\p (e1'·?)) with (?∪?);
349 nchange in match (𝐋\p 〈e1',?〉) with (?∪?);
351 nrewrite > (cupA…); //;##]
354 nlemma sub_dot_star :
355 ∀S.∀X:word S → Prop.∀b. (X - ϵ b) · X^* ∪ {[]} = X^*.
356 #S X b; napply extP; #w; @;
357 ##[ *; ##[##2: nnormalize; #defw; nrewrite < defw; @[]; @; //]
358 *; #w1; *; #w2; *; *; #defw sube; *; #lw; *; #flx cj;
359 @ (w1 :: lw); nrewrite < defw; nrewrite < flx; @; //;
360 @; //; napply (subW … sube);
361 ##| *; #wl; *; #defw Pwl; nrewrite < defw; nelim wl in Pwl; ##[ #_; @2; //]
362 #w' wl' IH; *; #Pw' IHp; nlapply (IH IHp); *;
363 ##[ *; #w1; *; #w2; *; *; #defwl' H1 H2;
364 @; ncases b in H1; #H1;
365 ##[##2: nrewrite > (sub0…); @w'; @(w1@w2);
366 nrewrite > (associative_append ? w' w1 w2);
367 nrewrite > defwl'; @; ##[@;//] @(wl'); @; //;
368 ##| ncases w' in Pw';
369 ##[ #ne; @w1; @w2; nrewrite > defwl'; @; //; @; //;
370 ##| #x xs Px; @(x::xs); @(w1@w2);
371 nrewrite > (defwl'); @; ##[@; //; @; //; @; nnormalize; #; ndestruct]
373 ##| #wlnil; nchange in match (flatten ? (w'::wl')) with (w' @ flatten ? wl');
374 nrewrite < (wlnil); nrewrite > (append_nil…); ncases b;
375 ##[ ncases w' in Pw'; /2/; #x xs Pxs; @; @(x::xs); @([]);
376 nrewrite > (append_nil…); @; ##[ @; //;@; //; nnormalize; @; #; ndestruct]
378 ##| @; @w'; @[]; nrewrite > (append_nil…); @; ##[##2: @[]; @; //]
379 @; //; @; //; @; *;##]##]##]
383 alias symbol "pc" (instance 13) = "cat lang".
384 alias symbol "in_pl" (instance 23) = "in_pl".
385 alias symbol "in_pl" (instance 5) = "in_pl".
386 alias symbol "eclose" (instance 21) = "eclose".
387 ntheorem bull_cup : ∀S:Alpha. ∀e:pitem S. 𝐋\p (•e) = 𝐋\p e ∪ 𝐋 |e|.
389 ##[ #a; napply extP; #w; nnormalize; @; *; /3/ by or_introl, or_intror;
390 ##| #a; napply extP; #w; nnormalize; @; *; /3/ by or_introl; *;
392 nchange in ⊢ (??(??(%))?) with (•e1 ⊙ 〈e2,false〉);
393 nrewrite > (odot_dot_aux S (•e1) 〈e2,false〉 IH2);
394 nrewrite > (IH1 …); nrewrite > (cup_dotD …);
395 nrewrite > (cupA …); nrewrite > (cupC ?? (𝐋\p ?) …);
396 nchange in match (𝐋\p 〈?,?〉) with (𝐋\p e2 ∪ {}); nrewrite > (cup0 …);
397 nrewrite < (erase_dot …); nrewrite < (cupA …); //;
399 nchange in match (•(?+?)) with (•e1 ⊕ •e2); nrewrite > (oplus_cup …);
400 nrewrite > (IH1 …); nrewrite > (IH2 …); nrewrite > (cupA …);
401 nrewrite > (cupC ? (𝐋\p e2)…);nrewrite < (cupA ??? (𝐋\p e2)…);
402 nrewrite > (cupC ?? (𝐋\p e2)…); nrewrite < (cupA …);
403 nrewrite < (erase_plus …); //.
404 ##| #e; nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e)); #IH;
405 nchange in match (𝐋\p ?) with (𝐋\p 〈e'^*,true〉);
406 nchange in match (𝐋\p ?) with (𝐋\p (e'^* ) ∪ {[ ]});
407 nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 |e'|^* );
408 nrewrite > (erase_bull…e);
409 nrewrite > (erase_star …);
410 nrewrite > (?: 𝐋\p e' = 𝐋\p e ∪ (𝐋 |e| - ϵ b')); ##[##2:
411 nchange in IH : (??%?) with (𝐋\p e' ∪ ϵ b'); ncases b' in IH;
412 ##[ #IH; nrewrite > (cup_sub…); //; nrewrite < IH;
413 nrewrite < (cup_sub…); //; nrewrite > (subK…); nrewrite > (cup0…);//;
414 ##| nrewrite > (sub0 …); #IH; nrewrite < IH; nrewrite > (cup0 …);//; ##]##]
415 nrewrite > (cup_dotD…); nrewrite > (cupA…);
416 nrewrite > (?: ((?·?)∪{[]} = 𝐋 |e^*|)); //;
417 nchange in match (𝐋 |e^*|) with ((𝐋 |e|)^* ); napply sub_dot_star;##]
422 ∀S.∀e1,e2: pre S. 𝐋\p (e1 ⊙ e2) = 𝐋\p e1 · 𝐋 |\fst e2| ∪ 𝐋\p e2.
423 #S e1 e2; napply odot_dot_aux; napply (bull_cup S (\fst e2)); nqed.
425 nlemma dot_star_epsilon : ∀S.∀e:re S.𝐋 e · 𝐋 e^* ∪ {[]} = 𝐋 e^*.
426 #S e; napply extP; #w; nnormalize; @;
427 ##[ *; ##[##2: #H; nrewrite < H; @[]; /3/] *; #w1; *; #w2;
428 *; *; #defw Hw1; *; #wl; *; #defw2 Hwl; @(w1 :: wl);
429 nrewrite < defw; nrewrite < defw2; @; //; @;//;
430 ##| *; #wl; *; #defw Hwl; ncases wl in defw Hwl; ##[#defw; #; @2; nrewrite < defw; //]
431 #x xs defw; *; #Hx Hxs; @; @x; @(flatten ? xs); nrewrite < defw;
435 nlemma nil_star : ∀S.∀e:re S. [ ] ∈ e^*.
436 #S e; @[]; /2/; nqed.
438 nlemma cupID : ∀S.∀l:word S → Prop.l ∪ l = l.
439 #S l; napply extP; #w; @; ##[*]//; #; @; //; nqed.
441 nlemma cup_star_nil : ∀S.∀l:word S → Prop. l^* ∪ {[]} = l^*.
442 #S a; napply extP; #w; @; ##[*; //; #H; nrewrite < H; @[]; @; //] #;@; //;nqed.
444 nlemma rcanc_sing : ∀S.∀A,C:word S → Prop.∀b:word S .
445 ¬ (A b) → A ∪ { (b) } = C → A = C - { (b) }.
446 #S A C b nbA defC; nrewrite < defC; napply extP; #w; @;
447 ##[ #Aw; /3/| *; *; //; #H nH; ncases nH; #abs; nlapply (abs H); *]
451 nlemma star_dot: ∀S.∀e:pre S. 𝐋\p (e^⊛) = 𝐋\p e · (𝐋 |\fst e|)^*.
452 #S p; ncases p; #e b; ncases b;
453 ##[ nchange in match (〈e,true〉^⊛) with 〈?,?〉;
454 nletin e' ≝ (\fst (•e)); nletin b' ≝ (\snd (•e));
455 nchange in ⊢ (??%?) with (?∪?);
456 nchange in ⊢ (??(??%?)?) with (𝐋\p e' · 𝐋 |e'|^* );
457 nrewrite > (?: 𝐋\p e' = 𝐋\p e ∪ (𝐋 |e| - ϵ b' )); ##[##2:
458 nlapply (bull_cup ? e); #bc;
459 nchange in match (𝐋\p (•e)) in bc with (?∪?);
460 nchange in match b' in bc with b';
461 ncases b' in bc; ##[##2: nrewrite > (cup0…); nrewrite > (sub0…); //]
462 nrewrite > (cup_sub…); ##[napply rcanc_sing] //;##]
463 nrewrite > (cup_dotD…); nrewrite > (cupA…);nrewrite > (erase_bull…);
464 nrewrite > (sub_dot_star…);
465 nchange in match (𝐋\p 〈?,?〉) with (?∪?);
466 nrewrite > (cup_dotD…); nrewrite > (epsilon_dot…); //;
467 ##| nwhd in match (〈e,false〉^⊛); nchange in match (𝐋\p 〈?,?〉) with (?∪?);
469 nchange in ⊢ (??%?) with (𝐋\p e · 𝐋 |e|^* );
470 nrewrite < (cup0 ? (𝐋\p e)); //;##]
473 nlet rec pre_of_re (S : Alpha) (e : re S) on e : pitem S ≝
478 | c e1 e2 ⇒ pc ? (pre_of_re ? e1) (pre_of_re ? e2)
479 | o e1 e2 ⇒ po ? (pre_of_re ? e1) (pre_of_re ? e2)
480 | k e1 ⇒ pk ? (pre_of_re ? e1)].
482 nlemma notFalse : ¬False. @; //; nqed.
484 nlemma dot0 : ∀S.∀A:word S → Prop. {} · A = {}.
485 #S A; nnormalize; napply extP; #w; @; ##[##2: *]
486 *; #w1; *; #w2; *; *; //; nqed.
488 nlemma Lp_pre_of_re : ∀S.∀e:re S. 𝐋\p (pre_of_re ? e) = {}.
489 #S e; nelim e; ##[##1,2,3: //]
490 ##[ #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1 e2))) with (?∪?);
491 nrewrite > H1; nrewrite > H2; nrewrite > (dot0…); nrewrite > (cupID…);//
492 ##| #e1 e2 H1 H2; nchange in match (𝐋\p (pre_of_re S (e1+e2))) with (?∪?);
493 nrewrite > H1; nrewrite > H2; nrewrite > (cupID…); //
494 ##| #e1 H1; nchange in match (𝐋\p (pre_of_re S (e1^* ))) with (𝐋\p (pre_of_re ??) · ?);
495 nrewrite > H1; napply dot0; ##]
498 nlemma erase_pre_of_reK : ∀S.∀e. 𝐋 |pre_of_re S e| = 𝐋 e.
500 ##[ #e1 e2 H1 H2; nchange in match (𝐋 (e1 · e2)) with (𝐋 e1·?);
501 nrewrite < H1; nrewrite < H2; //
502 ##| #e1 e2 H1 H2; nchange in match (𝐋 (e1 + e2)) with (𝐋 e1 ∪ ?);
503 nrewrite < H1; nrewrite < H2; //
504 ##| #e1 H1; nchange in match (𝐋 (e1^* )) with ((𝐋 e1)^* );
509 nlemma L_Lp_bull : ∀S.∀e:re S.𝐋 e = 𝐋\p (•pre_of_re ? e).
510 #S e; nrewrite > (bull_cup…); nrewrite > (Lp_pre_of_re…);
511 nrewrite > (cupC…); nrewrite > (cup0…); nrewrite > (erase_pre_of_reK…); //;
514 nlemma Pext : ∀S.∀f,g:word S → Prop. f = g → ∀w.f w → g w.
515 #S f g H; nrewrite > H; //; nqed.
518 ntheorem bull_true_epsilon : ∀S.∀e:pitem S. \snd (•e) = true ↔ [ ] ∈ |e|.
520 ##[ #defsnde; nlapply (bull_cup ? e); nchange in match (𝐋\p (•e)) with (?∪?);
521 nrewrite > defsnde; #H;
522 nlapply (Pext ??? H [ ] ?); ##[ @2; //] *; //;
526 notation > "\move term 90 x term 90 E"
527 non associative with precedence 60 for @{move ? $x $E}.
528 nlet rec move (S: Alpha) (x:S) (E: pitem S) on E : pre S ≝
532 | ps y ⇒ 〈 `y, false 〉
533 | pp y ⇒ 〈 `y, x == y 〉
534 | po e1 e2 ⇒ \move x e1 ⊕ \move x e2
535 | pc e1 e2 ⇒ \move x e1 ⊙ \move x e2
536 | pk e ⇒ (\move x e)^⊛ ].
537 notation < "\move\shy x\shy E" non associative with precedence 60 for @{'move $x $E}.
538 notation > "\move term 90 x term 90 E" non associative with precedence 60 for @{'move $x $E}.
539 interpretation "move" 'move x E = (move ? x E).
541 ndefinition rmove ≝ λS:Alpha.λx:S.λe:pre S. \move x (\fst e).
542 interpretation "rmove" 'move x E = (rmove ? x E).
544 nlemma XXz : ∀S:Alpha.∀w:word S. w ∈ ∅ → False.
545 #S w abs; ninversion abs; #; ndestruct;
549 nlemma XXe : ∀S:Alpha.∀w:word S. w .∈ ϵ → False.
550 #S w abs; ninversion abs; #; ndestruct;
553 nlemma XXze : ∀S:Alpha.∀w:word S. w .∈ (∅ · ϵ) → False.
554 #S w abs; ninversion abs; #; ndestruct; /2/ by XXz,XXe;
559 ∀S.∀w:word S.∀x.∀E1,E2:pitem S. w .∈ \move x (E1 · E2) →
560 (∃w1.∃w2. w = w1@w2 ∧ w1 .∈ \move x E1 ∧ w2 ∈ .|E2|) ∨ w .∈ \move x E2.
561 #S w x e1 e2 H; nchange in H with (w .∈ \move x e1 ⊙ \move x e2);
562 ncases e1 in H; ncases e2;
563 ##[##1: *; ##[*; nnormalize; #; ndestruct]
564 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
565 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
566 ##|##2: *; ##[*; nnormalize; #; ndestruct]
567 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
568 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz,XXze;
569 ##| #r; *; ##[ *; nnormalize; #; ndestruct]
570 #H; ninversion H; ##[##1,4,5,6: nnormalize; #; ndestruct]
571 ##[##2: nnormalize; #; ndestruct; @2; @2; //.##]
572 nnormalize; #; ndestruct; ncases (?:False); /2/ by XXz;
573 ##| #y; *; ##[ *; nnormalize; #defw defx; ndestruct; @2; @1; /2/ by conj;##]
574 #H; ninversion H; nnormalize; #; ndestruct;
575 ##[ncases (?:False); /2/ by XXz] /3/ by or_intror;
576 ##| #r1 r2; *; ##[ *; #defw]
581 ∀S:Alpha.∀E:pre S.∀a,w.w .∈ \move a E ↔ (a :: w) .∈ E.
582 #S E; ncases E; #r b; nelim r;
584 ##[##1,3: nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #abs; ncases (XXz … abs); ##]
585 #H; ninversion H; #; ndestruct;
586 ##|##*:nnormalize; *; ##[##1,3: *; #; ndestruct; ##| #H1; ncases (XXz … H1); ##]
587 #H; ninversion H; #; ndestruct;##]
588 ##|#a c w; @; nnormalize; ##[*; ##[*; #; ndestruct; ##] #abs; ninversion abs; #; ndestruct;##]
589 *; ##[##2: #abs; ninversion abs; #; ndestruct; ##] *; #; ndestruct;
590 ##|#a c w; @; nnormalize;
591 ##[ *; ##[ *; #defw; nrewrite > defw; #ca; @2; nrewrite > (eqb_t … ca); @; ##]
592 #H; ninversion H; #; ndestruct;
593 ##| *; ##[ *; #; ndestruct; ##] #H; ninversion H; ##[##2,3,4,5,6: #; ndestruct]
594 #d defw defa; ndestruct; @1; @; //; nrewrite > (eqb_true S d d); //. ##]
595 ##|#r1 r2 H1 H2 a w; @;
596 ##[ #H; ncases (in_move_cat … H);
597 ##[ *; #w1; *; #w2; *; *; #defw w1m w2m;
598 ncases (H1 a w1); #H1w1; #_; nlapply (H1w1 w1m); #good;
599 nrewrite > defw; @2; @2 (a::w1); //; ncases good; ##[ *; #; ndestruct] //.
608 notation > "x ↦* E" non associative with precedence 60 for @{move_star ? $x $E}.
609 nlet rec move_star (S : decidable) w E on w : bool × (pre S) ≝
612 | cons x w' ⇒ w' ↦* (x ↦ \snd E)].
614 ndefinition in_moves ≝ λS:decidable.λw.λE:bool × (pre S). \fst(w ↦* E).
616 ncoinductive equiv (S:decidable) : bool × (pre S) → bool × (pre S) → Prop ≝
618 ∀E1,E2: bool × (pre S).
620 (∀x. equiv S (x ↦ \snd E1) (x ↦ \snd E2)) →
623 ndefinition NAT: decidable.
627 include "hints_declaration.ma".
629 alias symbol "hint_decl" (instance 1) = "hint_decl_Type1".
630 unification hint 0 ≔ ; X ≟ NAT ⊢ carr X ≡ nat.
632 ninductive unit: Type[0] ≝ I: unit.
634 nlet corec foo_nop (b: bool):
636 〈 b, pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0))) 〉
637 〈 b, pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0) 〉 ≝ ?.
639 [ nnormalize in ⊢ (??%%); napply (foo_nop false)
641 [ nnormalize in ⊢ (??%%); napply (foo_nop false)
642 | #w; nnormalize in ⊢ (??%%); napply (foo_nop false) ]##]
646 nlet corec foo (a: unit):
648 (eclose NAT (pc ? (ps ? 0) (pk ? (pc ? (ps ? 1) (ps ? 0)))))
649 (eclose NAT (pc ? (pk ? (pc ? (ps ? 0) (ps ? 1))) (ps ? 0)))
654 [ nnormalize in ⊢ (??%%);
655 nnormalize in foo: (? → ??%%);
657 [ nnormalize in ⊢ (??%%); napply foo_nop
659 [ nnormalize in ⊢ (??%%);
661 ##| #z; nnormalize in ⊢ (??%%); napply foo_nop ]##]
662 ##| #y; nnormalize in ⊢ (??%%); napply foo_nop
667 ndefinition test1 : pre ? ≝ ❨ `0 | `1 ❩^* `0.
668 ndefinition test2 : pre ? ≝ ❨ (`0`1)^* `0 | (`0`1)^* `1 ❩.
669 ndefinition test3 : pre ? ≝ (`0 (`0`1)^* `1)^*.
672 nlemma foo: in_moves ? [0;0;1;0;1;1] (ɛ test3) = true.
673 nnormalize in match test3;
678 (**********************************************************)
680 ninductive der (S: Type[0]) (a: S) : re S → re S → CProp[0] ≝
681 der_z: der S a (z S) (z S)
682 | der_e: der S a (e S) (z S)
683 | der_s1: der S a (s S a) (e ?)
684 | der_s2: ∀b. a ≠ b → der S a (s S b) (z S)
685 | der_c1: ∀e1,e2,e1',e2'. in_l S [] e1 → der S a e1 e1' → der S a e2 e2' →
686 der S a (c ? e1 e2) (o ? (c ? e1' e2) e2')
687 | der_c2: ∀e1,e2,e1'. Not (in_l S [] e1) → der S a e1 e1' →
688 der S a (c ? e1 e2) (c ? e1' e2)
689 | der_o: ∀e1,e2,e1',e2'. der S a e1 e1' → der S a e2 e2' →
690 der S a (o ? e1 e2) (o ? e1' e2').
692 nlemma eq_rect_CProp0_r:
693 ∀A.∀a,x.∀p:eq ? x a.∀P: ∀x:A. eq ? x a → CProp[0]. P a (refl A a) → P x p.
694 #A; #a; #x; #p; ncases p; #P; #H; nassumption.
697 nlemma append1: ∀A.∀a:A.∀l. [a] @ l = a::l. //. nqed.
699 naxiom in_l1: ∀S,r1,r2,w. in_l S [ ] r1 → in_l S w r2 → in_l S w (c S r1 r2).
700 (* #S; #r1; #r2; #w; nelim r1
702 | #H1; #H2; napply (in_c ? []); //
703 | (* tutti casi assurdi *) *)
705 ninductive in_l' (S: Type[0]) : word S → re S → CProp[0] ≝
706 in_l_empty1: ∀E.in_l S [] E → in_l' S [] E
707 | in_l_cons: ∀a,w,e,e'. in_l' S w e' → der S a e e' → in_l' S (a::w) e.
709 ncoinductive eq_re (S: Type[0]) : re S → re S → CProp[0] ≝
711 (in_l S [] E1 → in_l S [] E2) →
712 (in_l S [] E2 → in_l S [] E1) →
713 (∀a,E1',E2'. der S a E1 E1' → der S a E2 E2' → eq_re S E1' E2') →
716 (* serve il lemma dopo? *)
717 ntheorem eq_re_is_eq: ∀S.∀E1,E2. eq_re S E1 E2 → ∀w. in_l ? w E1 → in_l ? w E2.
718 #S; #E1; #E2; #H1; #w; #H2; nelim H2 in E2 H1 ⊢ %
720 | #a; #w; #R1; #R2; #K1; #K2; #K3; #R3; #K4; @2 R2; //; ncases K4;
722 (* IL VICEVERSA NON VALE *)
723 naxiom in_l_to_in_l: ∀S,w,E. in_l' S w E → in_l S w E.
724 (* #S; #w; #E; #H; nelim H
726 | #a; #w'; #r; #r'; #H1; (* e si cade qua sotto! *)
730 ntheorem der1: ∀S,a,e,e',w. der S a e e' → in_l S w e' → in_l S (a::w) e.
731 #S; #a; #E; #E'; #w; #H; nelim H
732 [##1,2: #H1; ninversion H1
733 [##1,8: #_; #K; (* non va ndestruct K; *) ncases (?:False); (* perche' due goal?*) /2/
734 |##2,9: #X; #Y; #K; ncases (?:False); /2/
735 |##3,10: #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
736 |##4,11: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
737 |##5,12: #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
738 |##6,13: #x; #y; #K; ncases (?:False); /2/
739 |##7,14: #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/]
740 ##| #H1; ninversion H1
742 | #X; #Y; #K; ncases (?:False); /2/
743 | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
744 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
745 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
746 | #x; #y; #K; ncases (?:False); /2/
747 | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
748 ##| #H1; #H2; #H3; ninversion H3
749 [ #_; #K; ncases (?:False); /2/
750 | #X; #Y; #K; ncases (?:False); /2/
751 | #x; #y; #z; #w; #a; #b; #c; #d; #e; #K; ncases (?:False); /2/
752 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
753 | #x; #y; #z; #w; #a; #b; #K; ncases (?:False); /2/
754 | #x; #y; #K; ncases (?:False); /2/
755 | #x; #y; #z; #w; #a; #b; #c; #d; #K; ncases (?:False); /2/ ]
756 ##| #r1; #r2; #r1'; #r2'; #H1; #H2; #H3; #H4; #H5; #H6;