]> matita.cs.unibo.it Git - helm.git/blob - weblib/tutorial/chapter9.ma
commit by user andrea
[helm.git] / weblib / tutorial / chapter9.ma
1 (* 
2 \ 5h1\ 6Moves\ 5/h1\ 6*)
3
4 include "chapter8.ma".
5
6 let rec move (S: DeqSet) (x:S) (E: pitem S) on E : pre S ≝
7  match E with
8   [ pz ⇒ 〈 `∅, false 〉
9   | pe ⇒ 〈 ϵ, false 〉
10   | ps y ⇒ 〈 `y, false 〉
11   | pp y ⇒ 〈 `y, x == y 〉
12   | po e1 e2 ⇒ (move ? x e1) ⊕ (move ? x e2) 
13   | pc e1 e2 ⇒ (move ? x e1) ⊙ (move ? x e2)
14   | pk e ⇒ (move ? x e)^⊛ ].
15   
16 lemma move_plus: ∀S:DeqSet.∀x:S.∀i1,i2:pitem S.
17   move S x (i1 + i2) = (move ? x i1) ⊕ (move ? x i2).
18 // qed.
19
20 lemma move_cat: ∀S:DeqSet.∀x:S.∀i1,i2:pitem S.
21   move S x (i1 · i2) = (move ? x i1) ⊙ (move ? x i2).
22 // qed.
23
24 lemma move_star: ∀S:DeqSet.∀x:S.∀i:pitem S.
25   move S x i^* = (move ? x i)^⊛.
26 // qed.
27
28 (*
29 Example. Let us consider the item                      
30   
31                                (•a + ϵ)((•b)*•a + •b)b
32
33 and the two moves w.r.t. the characters a and b. 
34 For a, we have two possible positions (all other points gets erased); the innermost 
35 point stops in front of the final b, while the other one broadcast inside (b^*a + b)b, 
36 so
37  
38       move((•a + ϵ)((•b)*•a + •b)b,a) = 〈(a + ϵ)((•b)^*•a + •b)•b, false〉
39
40 For b, we have two positions too. The innermost point stops in front of the final b too, 
41 while the other point reaches the end of b* and must go back through b*a:  
42     
43       move((•a + ϵ)((•b)*•a + •b)b ,b) = 〈(a +  ϵ)((•b)*•a + b)•b, false〉
44
45 *)
46
47 definition pmove ≝ λS:DeqSet.λx:S.λe:pre S. move ? x (\fst e).
48
49 lemma pmove_def : ∀S:DeqSet.∀x:S.∀i:pitem S.∀b. 
50   pmove ? x 〈i,b〉 = move ? x i.
51 // qed.
52
53 lemma eq_to_eq_hd: ∀A.∀l1,l2:list A.∀a,b. 
54   a::l1 = b::l2 → a = b.
55 #A #l1 #l2 #a #b #H destruct //
56 qed. 
57
58 lemma same_kernel: ∀S:DeqSet.∀a:S.∀i:pitem S.
59   |\fst (move ? a i)| = |i|.
60 #S #a #i elim i //
61   [#i1 #i2 #H1 #H2 >move_cat >erase_odot //
62   |#i1 #i2 #H1 #H2 >move_plus whd in ⊢ (??%%); // 
63   ]
64 qed.
65
66 theorem move_ok:
67  ∀S:DeqSet.∀a:S.∀i:pitem S.∀w: word S. 
68    \sem{move ? a i} w ↔ \sem{i} (a::w).
69 #S #a #i elim i 
70   [normalize /2/
71   |normalize /2/
72   |normalize /2/
73   |normalize #x #w cases (true_or_false (a==x)) #H >H normalize
74     [>(\P H) % [* // #bot @False_ind //| #H1 destruct /2/]
75     |% [@False_ind |#H1 cases (\Pf H) #H2 @H2 destruct //]
76     ]
77   |#i1 #i2 #HI1 #HI2 #w >move_cat
78    @iff_trans[|@sem_odot] >same_kernel >sem_cat_w
79    @iff_trans[||@(iff_or_l … (HI2 w))] @iff_or_r 
80    @iff_trans[||@iff_sym @deriv_middot //]
81    @cat_ext_l @HI1
82   |#i1 #i2 #HI1 #HI2 #w >(sem_plus S i1 i2) >move_plus >sem_plus_w 
83    @iff_trans[|@sem_oplus] 
84    @iff_trans[|@iff_or_l [|@HI2]| @iff_or_r //]
85   |#i1 #HI1 #w >move_star 
86    @iff_trans[|@sem_ostar] >same_kernel >sem_star_w 
87    @iff_trans[||@iff_sym @deriv_middot //]
88    @cat_ext_l @HI1
89   ]
90 qed.
91     
92 notation > "x ↦* E" non associative with precedence 60 for @{moves ? $x $E}.
93 let rec moves (S : DeqSet) w e on w : pre S ≝
94  match w with
95   [ nil ⇒ e
96   | cons x w' ⇒ w' ↦* (move S x (\fst e))]. 
97
98 lemma moves_empty: ∀S:DeqSet.∀e:pre S. 
99   moves ? [ ] e = e.
100 // qed.
101
102 lemma moves_cons: ∀S:DeqSet.∀a:S.∀w.∀e:pre S. 
103   moves ? (a::w)  e = moves ? w (move S a (\fst e)).
104 // qed.
105
106 lemma moves_left : ∀S,a,w,e. 
107   moves S (w@[a]) e = move S a (\fst (moves S w e)). 
108 #S #a #w elim w // #x #tl #Hind #e >moves_cons >moves_cons //
109 qed.
110
111 lemma not_epsilon_sem: ∀S:DeqSet.∀a:S.∀w: word S. ∀e:pre S. 
112   iff ((a::w) ∈ e) ((a::w) ∈ \fst e).
113 #S #a #w * #i #b cases b normalize 
114   [% /2/ * // #H destruct |% normalize /2/]
115 qed.
116
117 lemma same_kernel_moves: ∀S:DeqSet.∀w.∀e:pre S.
118   |\fst (moves ? w e)| = |\fst e|.
119 #S #w elim w //
120 qed.
121
122 theorem decidable_sem: ∀S:DeqSet.∀w: word S. ∀e:pre S. 
123    (\snd (moves ? w e) = true) ↔ \sem{e} w.
124 #S #w elim w 
125  [* #i #b >moves_empty cases b % /2/
126  |#a #w1 #Hind #e >moves_cons
127   @iff_trans [||@iff_sym @not_epsilon_sem]
128   @iff_trans [||@move_ok] @Hind
129  ]
130 qed.
131
132 (************************ pit state ***************************)
133 definition pit_pre ≝ λS.λi.〈blank S (|i|), false〉. 
134
135 let rec occur (S: DeqSet) (i: re S) on i ≝  
136   match i with
137   [ z ⇒ [ ]
138   | e ⇒ [ ]
139   | s y ⇒ [y]
140   | o e1 e2 ⇒ unique_append ? (occur S e1) (occur S e2) 
141   | c e1 e2 ⇒ unique_append ? (occur S e1) (occur S e2) 
142   | k e ⇒ occur S e].
143
144 lemma not_occur_to_pit: ∀S,a.∀i:pitem S. memb S a (occur S (|i|)) ≠ true →
145   move S a i  = pit_pre S i.
146 #S #a #i elim i //
147   [#x normalize cases (a==x) normalize // #H @False_ind /2/
148   |#i1 #i2 #Hind1 #Hind2 #H >move_cat 
149    >Hind1 [2:@(not_to_not … H) #H1 @sublist_unique_append_l1 //]
150    >Hind2 [2:@(not_to_not … H) #H1 @sublist_unique_append_l2 //] //
151   |#i1 #i2 #Hind1 #Hind2 #H >move_plus 
152    >Hind1 [2:@(not_to_not … H) #H1 @sublist_unique_append_l1 //]
153    >Hind2 [2:@(not_to_not … H) #H1 @sublist_unique_append_l2 //] //
154   |#i #Hind #H >move_star >Hind // 
155   ]
156 qed.
157
158 lemma move_pit: ∀S,a,i. move S a (\fst (pit_pre S i)) = pit_pre S i.
159 #S #a #i elim i //
160   [#i1 #i2 #Hind1 #Hind2 >move_cat >Hind1 >Hind2 // 
161   |#i1 #i2 #Hind1 #Hind2 >move_plus >Hind1 >Hind2 // 
162   |#i #Hind >move_star >Hind //
163   ]
164 qed. 
165
166 lemma moves_pit: ∀S,w,i. moves S w (pit_pre S i) = pit_pre S i.
167 #S #w #i elim w // 
168 qed. 
169  
170 lemma to_pit: ∀S,w,e. ¬ sublist S w (occur S (|\fst e|)) →
171  moves S w e = pit_pre S (\fst e).
172 #S #w elim w
173   [#e * #H @False_ind @H normalize #a #abs @False_ind /2/
174   |#a #tl #Hind #e #H cases (true_or_false (memb S a (occur S (|\fst e|))))
175     [#Htrue >moves_cons whd in ⊢ (???%); <(same_kernel … a) 
176      @Hind >same_kernel @(not_to_not … H) #H1 #b #memb cases (orb_true_l … memb)
177       [#H2 >(\P H2) // |#H2 @H1 //]
178     |#Hfalse >moves_cons >not_occur_to_pit // >Hfalse /2/ 
179     ]
180   ]
181 qed.