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