author | Cezary Kaliszyk <kaliszyk@in.tum.de> |
Fri, 04 Dec 2009 09:25:27 +0100 | |
changeset 514 | 6b3be083229c |
parent 511 | 28bb34eeedc5 |
child 515 | b00a9b58264d |
permissions | -rw-r--r-- |
0 | 1 |
theory QuotList |
2 |
imports QuotScript |
|
3 |
begin |
|
4 |
||
5 |
lemma LIST_map_I: |
|
6 |
shows "map (\<lambda>x. x) = (\<lambda>x. x)" |
|
7 |
by simp |
|
8 |
||
9 |
fun |
|
10 |
LIST_REL |
|
11 |
where |
|
12 |
"LIST_REL R [] [] = True" |
|
13 |
| "LIST_REL R (x#xs) [] = False" |
|
14 |
| "LIST_REL R [] (x#xs) = False" |
|
15 |
| "LIST_REL R (x#xs) (y#ys) = (R x y \<and> LIST_REL R xs ys)" |
|
16 |
||
17 |
lemma LIST_REL_EQ: |
|
511
28bb34eeedc5
Changing = to \<equiv> in case if we want to use simp.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
57
diff
changeset
|
18 |
shows "LIST_REL (op =) \<equiv> (op =)" |
0 | 19 |
unfolding expand_fun_eq |
20 |
apply(rule allI)+ |
|
21 |
apply(induct_tac x xa rule: list_induct2') |
|
22 |
apply(simp_all) |
|
23 |
done |
|
24 |
||
25 |
lemma LIST_REL_REFL: |
|
26 |
assumes a: "\<And>x y. R x y = (R x = R y)" |
|
27 |
shows "LIST_REL R x x" |
|
28 |
by (induct x) (auto simp add: a) |
|
29 |
||
30 |
lemma LIST_EQUIV: |
|
31 |
assumes a: "EQUIV R" |
|
32 |
shows "EQUIV (LIST_REL R)" |
|
33 |
unfolding EQUIV_def |
|
34 |
apply(rule allI)+ |
|
35 |
apply(induct_tac x y rule: list_induct2') |
|
36 |
apply(simp) |
|
37 |
apply(simp add: expand_fun_eq) |
|
38 |
apply(metis LIST_REL.simps(1) LIST_REL.simps(2)) |
|
39 |
apply(simp add: expand_fun_eq) |
|
40 |
apply(metis LIST_REL.simps(1) LIST_REL.simps(2)) |
|
41 |
apply(simp add: expand_fun_eq) |
|
42 |
apply(rule iffI) |
|
43 |
apply(rule allI) |
|
44 |
apply(case_tac x) |
|
45 |
apply(simp) |
|
46 |
apply(simp) |
|
47 |
using a |
|
48 |
apply(unfold EQUIV_def) |
|
49 |
apply(auto)[1] |
|
50 |
apply(metis LIST_REL.simps(4)) |
|
51 |
done |
|
52 |
||
53 |
lemma LIST_REL_REL: |
|
54 |
assumes q: "QUOTIENT R Abs Rep" |
|
55 |
shows "LIST_REL R r s = (LIST_REL R r r \<and> LIST_REL R s s \<and> (map Abs r = map Abs s))" |
|
56 |
apply(induct r s rule: list_induct2') |
|
57 |
apply(simp_all) |
|
58 |
using QUOTIENT_REL[OF q] |
|
59 |
apply(metis) |
|
60 |
done |
|
61 |
||
62 |
lemma LIST_QUOTIENT: |
|
63 |
assumes q: "QUOTIENT R Abs Rep" |
|
64 |
shows "QUOTIENT (LIST_REL R) (map Abs) (map Rep)" |
|
65 |
unfolding QUOTIENT_def |
|
66 |
apply(rule conjI) |
|
67 |
apply(rule allI) |
|
68 |
apply(induct_tac a) |
|
69 |
apply(simp) |
|
70 |
apply(simp add: QUOTIENT_ABS_REP[OF q]) |
|
71 |
apply(rule conjI) |
|
72 |
apply(rule allI) |
|
73 |
apply(induct_tac a) |
|
74 |
apply(simp) |
|
75 |
apply(simp) |
|
76 |
apply(simp add: QUOTIENT_REP_REFL[OF q]) |
|
77 |
apply(rule allI)+ |
|
78 |
apply(rule LIST_REL_REL[OF q]) |
|
79 |
done |
|
80 |
||
81 |
lemma CONS_PRS: |
|
82 |
assumes q: "QUOTIENT R Abs Rep" |
|
83 |
shows "(h#t) = (map Abs) ((Rep h)#(map Rep t))" |
|
84 |
by (induct t) (simp_all add: QUOTIENT_ABS_REP[OF q]) |
|
85 |
||
86 |
lemma CONS_RSP: |
|
87 |
assumes q: "QUOTIENT R Abs Rep" |
|
88 |
and a: "R h1 h2" "LIST_REL R t1 t2" |
|
89 |
shows "LIST_REL R (h1#t1) (h2#t2)" |
|
90 |
using a by (auto) |
|
91 |
||
92 |
lemma NIL_PRS: |
|
93 |
assumes q: "QUOTIENT R Abs Rep" |
|
94 |
shows "[] = (map Abs [])" |
|
95 |
by (simp) |
|
96 |
||
97 |
lemma NIL_RSP: |
|
98 |
assumes q: "QUOTIENT R Abs Rep" |
|
99 |
shows "LIST_REL R [] []" |
|
100 |
by simp |
|
101 |
||
102 |
lemma MAP_PRS: |
|
103 |
assumes q1: "QUOTIENT R1 Abs1 Rep1" |
|
104 |
and q2: "QUOTIENT R2 Abs2 Rep2" |
|
105 |
shows "map f l = (map Abs2) (map ((Abs1 ---> Rep2) f) (map Rep1 l))" |
|
106 |
by (induct l) |
|
107 |
(simp_all add: QUOTIENT_ABS_REP[OF q1] QUOTIENT_ABS_REP[OF q2]) |
|
108 |
||
109 |
lemma MAP_RSP: |
|
110 |
assumes q1: "QUOTIENT R1 Abs1 Rep1" |
|
111 |
and q2: "QUOTIENT R2 Abs2 Rep2" |
|
112 |
and a: "(R1 ===> R2) f1 f2" |
|
113 |
and b: "LIST_REL R1 l1 l2" |
|
114 |
shows "LIST_REL R2 (map f1 l1) (map f2 l2)" |
|
115 |
using b a |
|
116 |
by (induct l1 l2 rule: list_induct2') |
|
117 |
(simp_all) |
|
118 |
||
119 |
||
120 |
end |
|
121 |
||
122 |
(* |
|
123 |
val LENGTH_PRS = store_thm |
|
124 |
("LENGTH_PRS", |
|
125 |
(--!R (abs:'a -> 'b) rep. QUOTIENT R abs rep ==> |
|
126 |
!l. LENGTH l = LENGTH (MAP rep l)--), |
|
127 |
||
128 |
val LENGTH_RSP = store_thm |
|
129 |
("LENGTH_RSP", |
|
130 |
(--!R (abs:'a -> 'b) rep. QUOTIENT R abs rep ==> |
|
131 |
!l1 l2. |
|
132 |
(LIST_REL R) l1 l2 ==> |
|
133 |
(LENGTH l1 = LENGTH l2)--), |
|
134 |
val APPEND_PRS = store_thm |
|
135 |
("APPEND_PRS", |
|
136 |
(--!R (abs:'a -> 'b) rep. QUOTIENT R abs rep ==> |
|
137 |
!l m. APPEND l m = MAP abs (APPEND (MAP rep l) (MAP rep m))--), |
|
138 |
||
139 |
val APPEND_RSP = store_thm |
|
140 |
("APPEND_RSP", |
|
141 |
(--!R (abs:'a -> 'b) rep. QUOTIENT R abs rep ==> |
|
142 |
!l1 l2 m1 m2. |
|
143 |
(LIST_REL R) l1 l2 /\ (LIST_REL R) m1 m2 ==> |
|
144 |
(LIST_REL R) (APPEND l1 m1) (APPEND l2 m2)--), |
|
145 |
val FLAT_PRS = store_thm |
|
146 |
("FLAT_PRS", |
|
147 |
(--!R (abs:'a -> 'b) rep. QUOTIENT R abs rep ==> |
|
148 |
!l. FLAT l = MAP abs (FLAT (MAP (MAP rep) l))--), |
|
149 |
||
150 |
val FLAT_RSP = store_thm |
|
151 |
("FLAT_RSP", |
|
152 |
(--!R (abs:'a -> 'b) rep. QUOTIENT R abs rep ==> |
|
153 |
!l1 l2. |
|
154 |
LIST_REL (LIST_REL R) l1 l2 ==> |
|
155 |
(LIST_REL R) (FLAT l1) (FLAT l2)--), |
|
156 |
||
157 |
val REVERSE_PRS = store_thm |
|
158 |
("REVERSE_PRS", |
|
159 |
(--!R (abs:'a -> 'b) rep. QUOTIENT R abs rep ==> |
|
160 |
!l. REVERSE l = MAP abs (REVERSE (MAP rep l))--), |
|
161 |
||
162 |
val REVERSE_RSP = store_thm |
|
163 |
("REVERSE_RSP", |
|
164 |
(--!R (abs:'a -> 'b) rep. QUOTIENT R abs rep ==> |
|
165 |
!l1 l2. |
|
166 |
LIST_REL R l1 l2 ==> |
|
167 |
(LIST_REL R) (REVERSE l1) (REVERSE l2)--), |
|
168 |
||
169 |
val FILTER_PRS = store_thm |
|
170 |
("FILTER_PRS", |
|
171 |
(--!R (abs:'a -> 'b) rep. QUOTIENT R abs rep ==> |
|
172 |
!P l. FILTER P l = (MAP abs) (FILTER ((abs --> I) P) (MAP rep l)) |
|
173 |
--), |
|
174 |
||
175 |
val FILTER_RSP = store_thm |
|
176 |
("FILTER_RSP", |
|
177 |
(--!R (abs:'a -> 'b) rep. QUOTIENT R abs rep ==> |
|
178 |
!P1 P2 l1 l2. |
|
179 |
(R ===> $=) P1 P2 /\ (LIST_REL R) l1 l2 ==> |
|
180 |
(LIST_REL R) (FILTER P1 l1) (FILTER P2 l2)--), |
|
181 |
||
182 |
val NULL_PRS = store_thm |
|
183 |
("NULL_PRS", |
|
184 |
(--!R (abs:'a -> 'b) rep. QUOTIENT R abs rep ==> |
|
185 |
!l. NULL l = NULL (MAP rep l)--), |
|
186 |
||
187 |
val NULL_RSP = store_thm |
|
188 |
("NULL_RSP", |
|
189 |
(--!R (abs:'a -> 'b) rep. QUOTIENT R abs rep ==> |
|
190 |
!l1 l2. |
|
191 |
LIST_REL R l1 l2 ==> |
|
192 |
(NULL l1 = NULL l2)--), |
|
193 |
||
194 |
val SOME_EL_PRS = store_thm |
|
195 |
("SOME_EL_PRS", |
|
196 |
(--!R (abs:'a -> 'b) rep. QUOTIENT R abs rep ==> |
|
197 |
!l P. SOME_EL P l = SOME_EL ((abs --> I) P) (MAP rep l)--), |
|
198 |
||
199 |
val SOME_EL_RSP = store_thm |
|
200 |
("SOME_EL_RSP", |
|
201 |
(--!R (abs:'a -> 'b) rep. QUOTIENT R abs rep ==> |
|
202 |
!l1 l2 P1 P2. |
|
203 |
(R ===> $=) P1 P2 /\ (LIST_REL R) l1 l2 ==> |
|
204 |
(SOME_EL P1 l1 = SOME_EL P2 l2)--), |
|
205 |
||
206 |
val ALL_EL_PRS = store_thm |
|
207 |
("ALL_EL_PRS", |
|
208 |
(--!R (abs:'a -> 'b) rep. QUOTIENT R abs rep ==> |
|
209 |
!l P. ALL_EL P l = ALL_EL ((abs --> I) P) (MAP rep l)--), |
|
210 |
||
211 |
val ALL_EL_RSP = store_thm |
|
212 |
("ALL_EL_RSP", |
|
213 |
(--!R (abs:'a -> 'b) rep. QUOTIENT R abs rep ==> |
|
214 |
!l1 l2 P1 P2. |
|
215 |
(R ===> $=) P1 P2 /\ (LIST_REL R) l1 l2 ==> |
|
216 |
(ALL_EL P1 l1 = ALL_EL P2 l2)--), |
|
217 |
||
218 |
val FOLDL_PRS = store_thm |
|
219 |
("FOLDL_PRS", |
|
220 |
(--!R1 (abs1:'a -> 'c) rep1. QUOTIENT R1 abs1 rep1 ==> |
|
221 |
!R2 (abs2:'b -> 'd) rep2. QUOTIENT R2 abs2 rep2 ==> |
|
222 |
!l f e. FOLDL f e l = |
|
223 |
abs1 (FOLDL ((abs1 --> abs2 --> rep1) f) |
|
224 |
(rep1 e) |
|
225 |
(MAP rep2 l))--), |
|
226 |
||
227 |
val FOLDL_RSP = store_thm |
|
228 |
("FOLDL_RSP", |
|
229 |
(--!R1 (abs1:'a -> 'c) rep1. QUOTIENT R1 abs1 rep1 ==> |
|
230 |
!R2 (abs2:'b -> 'd) rep2. QUOTIENT R2 abs2 rep2 ==> |
|
231 |
!l1 l2 f1 f2 e1 e2. |
|
232 |
(R1 ===> R2 ===> R1) f1 f2 /\ |
|
233 |
R1 e1 e2 /\ (LIST_REL R2) l1 l2 ==> |
|
234 |
R1 (FOLDL f1 e1 l1) (FOLDL f2 e2 l2)--), |
|
235 |
||
236 |
val FOLDR_PRS = store_thm |
|
237 |
("FOLDR_PRS", |
|
238 |
(--!R1 (abs1:'a -> 'c) rep1. QUOTIENT R1 abs1 rep1 ==> |
|
239 |
!R2 (abs2:'b -> 'd) rep2. QUOTIENT R2 abs2 rep2 ==> |
|
240 |
!l f e. FOLDR f e l = |
|
241 |
abs2 (FOLDR ((abs1 --> abs2 --> rep2) f) |
|
242 |
(rep2 e) |
|
243 |
(MAP rep1 l))--), |
|
244 |
||
245 |
val FOLDR_RSP = store_thm |
|
246 |
("FOLDR_RSP", |
|
247 |
(--!R1 (abs1:'a -> 'c) rep1. QUOTIENT R1 abs1 rep1 ==> |
|
248 |
!R2 (abs2:'b -> 'd) rep2. QUOTIENT R2 abs2 rep2 ==> |
|
249 |
!l1 l2 f1 f2 e1 e2. |
|
250 |
(R1 ===> R2 ===> R2) f1 f2 /\ |
|
251 |
R2 e1 e2 /\ (LIST_REL R1) l1 l2 ==> |
|
252 |
R2 (FOLDR f1 e1 l1) (FOLDR f2 e2 l2)--), |
|
253 |
*) |
|
254 |