2 include "basics/listb.ma".
4 let rec move (S: DeqSet) (x:S) (E: pitem S) on E : pre S ≝
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)^⊛ ].
14 lemma move_plus: ∀S:DeqSet.∀x:S.∀i1,i2:pitem S.
15 move S x (i1 + i2) = (move ? x i1) ⊕ (move ? x i2).
18 lemma move_cat: ∀S:DeqSet.∀x:S.∀i1,i2:pitem S.
19 move S x (i1 · i2) = (move ? x i1) ⊙ (move ? x i2).
22 lemma move_star: ∀S:DeqSet.∀x:S.∀i:pitem S.
23 move S x i^* = (move ? x i)^⊛.
26 definition pmove ≝ λS:DeqSet.λx:S.λe:pre S. move ? x (\fst e).
28 lemma pmove_def : ∀S:DeqSet.∀x:S.∀i:pitem S.∀b.
29 pmove ? x 〈i,b〉 = move ? x i.
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 //
37 lemma same_kernel: ∀S:DeqSet.∀a:S.∀i:pitem S.
38 |\fst (move ? a i)| = |i|.
40 [#i1 #i2 #H1 #H2 >move_cat >erase_odot //
41 |#i1 #i2 #H1 #H2 >move_plus whd in ⊢ (??%%); //
46 ∀S:DeqSet.∀a:S.∀i:pitem S.∀w: word S.
47 \sem{move ? a i} w ↔ \sem{i} (a::w).
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 //]
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 //]
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 //]
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 ≝
75 | cons x w' ⇒ w' ↦* (move S x (\fst e))].
77 lemma moves_empty: ∀S:DeqSet.∀e:pre S.
81 lemma moves_cons: ∀S:DeqSet.∀a:S.∀w.∀e:pre S.
82 moves ? (a::w) e = moves ? w (move S a (\fst e)).
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 //
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/]
96 lemma same_kernel_moves: ∀S:DeqSet.∀w.∀e:pre S.
97 |\fst (moves ? w e)| = |\fst e|.
101 theorem decidable_sem: ∀S:DeqSet.∀w: word S. ∀e:pre S.
102 (\snd (moves ? w e) = true) ↔ \sem{e} 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
111 (************************ pit state ***************************)
112 definition pit_pre ≝ λS.λi.〈blank S (|i|), false〉.
114 let rec occur (S: DeqSet) (i: re S) on i ≝
119 | o e1 e2 ⇒ unique_append ? (occur S e1) (occur S e2)
120 | c e1 e2 ⇒ unique_append ? (occur S e1) (occur S e2)
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.
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 //
137 lemma move_pit: ∀S,a,i. move S a (\fst (pit_pre S i)) = pit_pre S 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 //
145 lemma moves_pit: ∀S,w,i. moves S w (pit_pre S i) = pit_pre S i.
149 lemma to_pit: ∀S,w,e. ¬ sublist S w (occur S (|\fst e|)) →
150 moves S w e = pit_pre S (\fst e).
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/