]> matita.cs.unibo.it Git - helm.git/blob - weblib/tutorial/chapter9.ma
Small changes
[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 definition pmove ≝ λS:DeqSet.λx:S.λe:pre S. move ? x (\fst e).
29
30 lemma pmove_def : ∀S:DeqSet.∀x:S.∀i:pitem S.∀b. 
31   pmove ? x 〈i,b〉 = move ? x i.
32 // qed.
33
34 lemma eq_to_eq_hd: ∀A.∀l1,l2:list A.∀a,b. 
35   a::l1 = b::l2 → a = b.
36 #A #l1 #l2 #a #b #H destruct //
37 qed. 
38
39 lemma same_kernel: ∀S:DeqSet.∀a:S.∀i:pitem S.
40   |\fst (move ? a i)| = |i|.
41 #S #a #i elim i //
42   [#i1 #i2 #H1 #H2 >move_cat >erase_odot //
43   |#i1 #i2 #H1 #H2 >move_plus whd in ⊢ (??%%); // 
44   ]
45 qed.
46
47 theorem move_ok:
48  ∀S:DeqSet.∀a:S.∀i:pitem S.∀w: word S. 
49    \sem{move ? a i} w ↔ \sem{i} (a::w).
50 #S #a #i elim i 
51   [normalize /2/
52   |normalize /2/
53   |normalize /2/
54   |normalize #x #w cases (true_or_false (a==x)) #H >H normalize
55     [>(\P H) % [* // #bot @False_ind //| #H1 destruct /2/]
56     |% [@False_ind |#H1 cases (\Pf H) #H2 @H2 destruct //]
57     ]
58   |#i1 #i2 #HI1 #HI2 #w >move_cat
59    @iff_trans[|@sem_odot] >same_kernel >sem_cat_w
60    @iff_trans[||@(iff_or_l … (HI2 w))] @iff_or_r 
61    @iff_trans[||@iff_sym @deriv_middot //]
62    @cat_ext_l @HI1
63   |#i1 #i2 #HI1 #HI2 #w >(sem_plus S i1 i2) >move_plus >sem_plus_w 
64    @iff_trans[|@sem_oplus] 
65    @iff_trans[|@iff_or_l [|@HI2]| @iff_or_r //]
66   |#i1 #HI1 #w >move_star 
67    @iff_trans[|@sem_ostar] >same_kernel >sem_star_w 
68    @iff_trans[||@iff_sym @deriv_middot //]
69    @cat_ext_l @HI1
70   ]
71 qed.
72     
73 notation > "x ↦* E" non associative with precedence 60 for @{moves ? $x $E}.
74 let rec moves (S : DeqSet) w e on w : pre S ≝
75  match w with
76   [ nil ⇒ e
77   | cons x w' ⇒ w' ↦* (move S x (\fst e))]. 
78
79 lemma moves_empty: ∀S:DeqSet.∀e:pre S. 
80   moves ? [ ] e = e.
81 // qed.
82
83 lemma moves_cons: ∀S:DeqSet.∀a:S.∀w.∀e:pre S. 
84   moves ? (a::w)  e = moves ? w (move S a (\fst e)).
85 // qed.
86
87 lemma moves_left : ∀S,a,w,e. 
88   moves S (w@[a]) e = move S a (\fst (moves S w e)). 
89 #S #a #w elim w // #x #tl #Hind #e >moves_cons >moves_cons //
90 qed.
91
92 lemma not_epsilon_sem: ∀S:DeqSet.∀a:S.∀w: word S. ∀e:pre S. 
93   iff ((a::w) ∈ e) ((a::w) ∈ \fst e).
94 #S #a #w * #i #b cases b normalize 
95   [% /2/ * // #H destruct |% normalize /2/]
96 qed.
97
98 lemma same_kernel_moves: ∀S:DeqSet.∀w.∀e:pre S.
99   |\fst (moves ? w e)| = |\fst e|.
100 #S #w elim w //
101 qed.
102
103 theorem decidable_sem: ∀S:DeqSet.∀w: word S. ∀e:pre S. 
104    (\snd (moves ? w e) = true) ↔ \sem{e} w.
105 #S #w elim w 
106  [* #i #b >moves_empty cases b % /2/
107  |#a #w1 #Hind #e >moves_cons
108   @iff_trans [||@iff_sym @not_epsilon_sem]
109   @iff_trans [||@move_ok] @Hind
110  ]
111 qed.
112
113 (************************ pit state ***************************)
114 definition pit_pre ≝ λS.λi.〈blank S (|i|), false〉. 
115
116 let rec occur (S: DeqSet) (i: re S) on i ≝  
117   match i with
118   [ z ⇒ [ ]
119   | e ⇒ [ ]
120   | s y ⇒ [y]
121   | o e1 e2 ⇒ unique_append ? (occur S e1) (occur S e2) 
122   | c e1 e2 ⇒ unique_append ? (occur S e1) (occur S e2) 
123   | k e ⇒ occur S e].
124
125 lemma not_occur_to_pit: ∀S,a.∀i:pitem S. memb S a (occur S (|i|)) ≠ true →
126   move S a i  = pit_pre S i.
127 #S #a #i elim i //
128   [#x normalize cases (a==x) normalize // #H @False_ind /2/
129   |#i1 #i2 #Hind1 #Hind2 #H >move_cat 
130    >Hind1 [2:@(not_to_not … H) #H1 @sublist_unique_append_l1 //]
131    >Hind2 [2:@(not_to_not … H) #H1 @sublist_unique_append_l2 //] //
132   |#i1 #i2 #Hind1 #Hind2 #H >move_plus 
133    >Hind1 [2:@(not_to_not … H) #H1 @sublist_unique_append_l1 //]
134    >Hind2 [2:@(not_to_not … H) #H1 @sublist_unique_append_l2 //] //
135   |#i #Hind #H >move_star >Hind // 
136   ]
137 qed.
138
139 lemma move_pit: ∀S,a,i. move S a (\fst (pit_pre S i)) = pit_pre S i.
140 #S #a #i elim i //
141   [#i1 #i2 #Hind1 #Hind2 >move_cat >Hind1 >Hind2 // 
142   |#i1 #i2 #Hind1 #Hind2 >move_plus >Hind1 >Hind2 // 
143   |#i #Hind >move_star >Hind //
144   ]
145 qed. 
146
147 lemma moves_pit: ∀S,w,i. moves S w (pit_pre S i) = pit_pre S i.
148 #S #w #i elim w // 
149 qed. 
150  
151 lemma to_pit: ∀S,w,e. ¬ sublist S w (occur S (|\fst e|)) →
152  moves S w e = pit_pre S (\fst e).
153 #S #w elim w
154   [#e * #H @False_ind @H normalize #a #abs @False_ind /2/
155   |#a #tl #Hind #e #H cases (true_or_false (memb S a (occur S (|\fst e|))))
156     [#Htrue >moves_cons whd in ⊢ (???%); <(same_kernel … a) 
157      @Hind >same_kernel @(not_to_not … H) #H1 #b #memb cases (orb_true_l … memb)
158       [#H2 >(\P H2) // |#H2 @H1 //]
159     |#Hfalse >moves_cons >not_occur_to_pit // >Hfalse /2/ 
160     ]
161   ]
162 qed.