1128
|
1 |
(* Title: Quotient_List.thy
|
937
|
2 |
Author: Cezary Kaliszyk and Christian Urban
|
1128
|
3 |
*)
|
|
4 |
theory Quotient_List
|
1129
|
5 |
imports Quotient Quotient_Syntax List
|
0
|
6 |
begin
|
|
7 |
|
937
|
8 |
section {* Quotient infrastructure for the list type. *}
|
|
9 |
|
0
|
10 |
fun
|
537
|
11 |
list_rel
|
0
|
12 |
where
|
537
|
13 |
"list_rel R [] [] = True"
|
|
14 |
| "list_rel R (x#xs) [] = False"
|
|
15 |
| "list_rel R [] (x#xs) = False"
|
|
16 |
| "list_rel R (x#xs) (y#ys) = (R x y \<and> list_rel R xs ys)"
|
0
|
17 |
|
600
|
18 |
declare [[map list = (map, list_rel)]]
|
|
19 |
|
1128
|
20 |
lemma split_list_all:
|
935
|
21 |
shows "(\<forall>x. P x) \<longleftrightarrow> P [] \<and> (\<forall>x xs. P (x#xs))"
|
936
|
22 |
apply(auto)
|
|
23 |
apply(case_tac x)
|
|
24 |
apply(simp_all)
|
|
25 |
done
|
935
|
26 |
|
1128
|
27 |
lemma map_id[id_simps]:
|
936
|
28 |
shows "map id = id"
|
935
|
29 |
apply(simp add: expand_fun_eq)
|
|
30 |
apply(rule allI)
|
|
31 |
apply(induct_tac x)
|
|
32 |
apply(simp_all)
|
|
33 |
done
|
|
34 |
|
|
35 |
|
|
36 |
lemma list_rel_reflp:
|
|
37 |
shows "equivp R \<Longrightarrow> list_rel R xs xs"
|
|
38 |
apply(induct xs)
|
|
39 |
apply(simp_all add: equivp_reflp)
|
|
40 |
done
|
|
41 |
|
|
42 |
lemma list_rel_symp:
|
1128
|
43 |
assumes a: "equivp R"
|
935
|
44 |
shows "list_rel R xs ys \<Longrightarrow> list_rel R ys xs"
|
|
45 |
apply(induct xs ys rule: list_induct2')
|
|
46 |
apply(simp_all)
|
|
47 |
apply(rule equivp_symp[OF a])
|
|
48 |
apply(simp)
|
|
49 |
done
|
|
50 |
|
|
51 |
lemma list_rel_transp:
|
1128
|
52 |
assumes a: "equivp R"
|
935
|
53 |
shows "list_rel R xs1 xs2 \<Longrightarrow> list_rel R xs2 xs3 \<Longrightarrow> list_rel R xs1 xs3"
|
|
54 |
apply(induct xs1 xs2 arbitrary: xs3 rule: list_induct2')
|
|
55 |
apply(simp_all)
|
|
56 |
apply(case_tac xs3)
|
|
57 |
apply(simp_all)
|
|
58 |
apply(rule equivp_transp[OF a])
|
|
59 |
apply(auto)
|
|
60 |
done
|
|
61 |
|
636
|
62 |
lemma list_equivp[quot_equiv]:
|
529
|
63 |
assumes a: "equivp R"
|
537
|
64 |
shows "equivp (list_rel R)"
|
935
|
65 |
apply(rule equivpI)
|
|
66 |
unfolding reflp_def symp_def transp_def
|
|
67 |
apply(subst split_list_all)
|
|
68 |
apply(simp add: equivp_reflp[OF a] list_rel_reflp[OF a])
|
|
69 |
apply(blast intro: list_rel_symp[OF a])
|
|
70 |
apply(blast intro: list_rel_transp[OF a])
|
539
|
71 |
done
|
0
|
72 |
|
539
|
73 |
lemma list_rel_rel:
|
529
|
74 |
assumes q: "Quotient R Abs Rep"
|
537
|
75 |
shows "list_rel R r s = (list_rel R r r \<and> list_rel R s s \<and> (map Abs r = map Abs s))"
|
539
|
76 |
apply(induct r s rule: list_induct2')
|
|
77 |
apply(simp_all)
|
|
78 |
using Quotient_rel[OF q]
|
|
79 |
apply(metis)
|
|
80 |
done
|
0
|
81 |
|
636
|
82 |
lemma list_quotient[quot_thm]:
|
529
|
83 |
assumes q: "Quotient R Abs Rep"
|
537
|
84 |
shows "Quotient (list_rel R) (map Abs) (map Rep)"
|
539
|
85 |
unfolding Quotient_def
|
935
|
86 |
apply(subst split_list_all)
|
|
87 |
apply(simp add: Quotient_abs_rep[OF q] abs_o_rep[OF q] map_id)
|
539
|
88 |
apply(rule conjI)
|
|
89 |
apply(rule allI)
|
|
90 |
apply(induct_tac a)
|
|
91 |
apply(simp)
|
|
92 |
apply(simp)
|
541
|
93 |
apply(simp add: Quotient_rep_reflp[OF q])
|
539
|
94 |
apply(rule allI)+
|
|
95 |
apply(rule list_rel_rel[OF q])
|
|
96 |
done
|
|
97 |
|
600
|
98 |
|
644
|
99 |
lemma cons_prs_aux:
|
540
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
100 |
assumes q: "Quotient R Abs Rep"
|
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
101 |
shows "(map Abs) ((Rep h) # (map Rep t)) = h # t"
|
927
|
102 |
by (induct t) (simp_all add: Quotient_abs_rep[OF q])
|
539
|
103 |
|
644
|
104 |
lemma cons_prs[quot_preserve]:
|
|
105 |
assumes q: "Quotient R Abs Rep"
|
|
106 |
shows "(Rep ---> (map Rep) ---> (map Abs)) (op #) = (op #)"
|
935
|
107 |
by (simp only: expand_fun_eq fun_map_def cons_prs_aux[OF q])
|
|
108 |
(simp)
|
644
|
109 |
|
636
|
110 |
lemma cons_rsp[quot_respect]:
|
529
|
111 |
assumes q: "Quotient R Abs Rep"
|
935
|
112 |
shows "(R ===> list_rel R ===> list_rel R) (op #) (op #)"
|
|
113 |
by (auto)
|
0
|
114 |
|
644
|
115 |
lemma nil_prs[quot_preserve]:
|
529
|
116 |
assumes q: "Quotient R Abs Rep"
|
927
|
117 |
shows "map Abs [] = []"
|
|
118 |
by simp
|
0
|
119 |
|
636
|
120 |
lemma nil_rsp[quot_respect]:
|
529
|
121 |
assumes q: "Quotient R Abs Rep"
|
537
|
122 |
shows "list_rel R [] []"
|
927
|
123 |
by simp
|
0
|
124 |
|
645
|
125 |
lemma map_prs_aux:
|
540
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
126 |
assumes a: "Quotient R1 abs1 rep1"
|
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
127 |
and b: "Quotient R2 abs2 rep2"
|
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
128 |
shows "(map abs2) (map ((abs1 ---> rep2) f) (map rep1 l)) = map f l"
|
1128
|
129 |
by (induct l)
|
935
|
130 |
(simp_all add: Quotient_abs_rep[OF a] Quotient_abs_rep[OF b])
|
0
|
131 |
|
645
|
132 |
|
|
133 |
lemma map_prs[quot_preserve]:
|
|
134 |
assumes a: "Quotient R1 abs1 rep1"
|
|
135 |
and b: "Quotient R2 abs2 rep2"
|
|
136 |
shows "((abs1 ---> rep2) ---> (map rep1) ---> (map abs2)) map = map"
|
935
|
137 |
by (simp only: expand_fun_eq fun_map_def map_prs_aux[OF a b])
|
|
138 |
(simp)
|
645
|
139 |
|
|
140 |
|
636
|
141 |
lemma map_rsp[quot_respect]:
|
529
|
142 |
assumes q1: "Quotient R1 Abs1 Rep1"
|
|
143 |
and q2: "Quotient R2 Abs2 Rep2"
|
565
|
144 |
shows "((R1 ===> R2) ===> (list_rel R1) ===> list_rel R2) map map"
|
927
|
145 |
apply(simp)
|
|
146 |
apply(rule allI)+
|
|
147 |
apply(rule impI)
|
|
148 |
apply(rule allI)+
|
|
149 |
apply (induct_tac xa ya rule: list_induct2')
|
|
150 |
apply simp_all
|
|
151 |
done
|
565
|
152 |
|
645
|
153 |
lemma foldr_prs_aux:
|
540
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
154 |
assumes a: "Quotient R1 abs1 rep1"
|
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
155 |
and b: "Quotient R2 abs2 rep2"
|
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
156 |
shows "abs2 (foldr ((abs1 ---> abs2 ---> rep2) f) (map rep1 l) (rep2 e)) = foldr f l e"
|
927
|
157 |
by (induct l) (simp_all add: Quotient_abs_rep[OF a] Quotient_abs_rep[OF b])
|
540
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
158 |
|
796
|
159 |
lemma foldr_prs[quot_preserve]:
|
645
|
160 |
assumes a: "Quotient R1 abs1 rep1"
|
|
161 |
and b: "Quotient R2 abs2 rep2"
|
|
162 |
shows "((abs1 ---> abs2 ---> rep2) ---> (map rep1) ---> rep2 ---> abs2) foldr = foldr"
|
935
|
163 |
by (simp only: expand_fun_eq fun_map_def foldr_prs_aux[OF a b])
|
|
164 |
(simp)
|
645
|
165 |
|
|
166 |
lemma foldl_prs_aux:
|
540
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
167 |
assumes a: "Quotient R1 abs1 rep1"
|
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
168 |
and b: "Quotient R2 abs2 rep2"
|
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
169 |
shows "abs1 (foldl ((abs1 ---> abs2 ---> rep1) f) (rep1 e) (map rep2 l)) = foldl f e l"
|
927
|
170 |
by (induct l arbitrary:e) (simp_all add: Quotient_abs_rep[OF a] Quotient_abs_rep[OF b])
|
645
|
171 |
|
|
172 |
|
|
173 |
lemma foldl_prs[quot_preserve]:
|
|
174 |
assumes a: "Quotient R1 abs1 rep1"
|
|
175 |
and b: "Quotient R2 abs2 rep2"
|
|
176 |
shows "((abs1 ---> abs2 ---> rep1) ---> rep1 ---> (map rep2) ---> abs1) foldl = foldl"
|
935
|
177 |
by (simp only: expand_fun_eq fun_map_def foldl_prs_aux[OF a b])
|
|
178 |
(simp)
|
645
|
179 |
|
1128
|
180 |
lemma list_rel_empty:
|
935
|
181 |
shows "list_rel R [] b \<Longrightarrow> length b = 0"
|
927
|
182 |
by (induct b) (simp_all)
|
0
|
183 |
|
1128
|
184 |
lemma list_rel_len:
|
935
|
185 |
shows "list_rel R a b \<Longrightarrow> length a = length b"
|
927
|
186 |
apply (induct a arbitrary: b)
|
|
187 |
apply (simp add: list_rel_empty)
|
|
188 |
apply (case_tac b)
|
|
189 |
apply simp_all
|
|
190 |
done
|
0
|
191 |
|
668
|
192 |
(* induct_tac doesn't accept 'arbitrary', so we manually 'spec' *)
|
636
|
193 |
lemma foldl_rsp[quot_respect]:
|
565
|
194 |
assumes q1: "Quotient R1 Abs1 Rep1"
|
|
195 |
and q2: "Quotient R2 Abs2 Rep2"
|
|
196 |
shows "((R1 ===> R2 ===> R1) ===> R1 ===> list_rel R2 ===> R1) foldl foldl"
|
927
|
197 |
apply(auto)
|
|
198 |
apply (subgoal_tac "R1 xa ya \<longrightarrow> list_rel R2 xb yb \<longrightarrow> R1 (foldl x xa xb) (foldl y ya yb)")
|
|
199 |
apply simp
|
|
200 |
apply (rule_tac x="xa" in spec)
|
|
201 |
apply (rule_tac x="ya" in spec)
|
|
202 |
apply (rule_tac xs="xb" and ys="yb" in list_induct2)
|
|
203 |
apply (rule list_rel_len)
|
|
204 |
apply (simp_all)
|
|
205 |
done
|
565
|
206 |
|
666
|
207 |
lemma foldr_rsp[quot_respect]:
|
|
208 |
assumes q1: "Quotient R1 Abs1 Rep1"
|
|
209 |
and q2: "Quotient R2 Abs2 Rep2"
|
|
210 |
shows "((R1 ===> R2 ===> R2) ===> list_rel R1 ===> R2 ===> R2) foldr foldr"
|
927
|
211 |
apply auto
|
|
212 |
apply(subgoal_tac "R2 xb yb \<longrightarrow> list_rel R1 xa ya \<longrightarrow> R2 (foldr x xa xb) (foldr y ya yb)")
|
|
213 |
apply simp
|
|
214 |
apply (rule_tac xs="xa" and ys="ya" in list_induct2)
|
|
215 |
apply (rule list_rel_len)
|
|
216 |
apply (simp_all)
|
|
217 |
done
|
540
c0b13fb70d6d
More code cleaning and renaming: moved rsp and prs lemmas from Int to QuotList
Cezary Kaliszyk <kaliszyk@in.tum.de>
diff
changeset
|
218 |
|
825
|
219 |
lemma list_rel_eq[id_simps]:
|
927
|
220 |
shows "(list_rel (op =)) = (op =)"
|
|
221 |
unfolding expand_fun_eq
|
|
222 |
apply(rule allI)+
|
|
223 |
apply(induct_tac x xa rule: list_induct2')
|
|
224 |
apply(simp_all)
|
|
225 |
done
|
0
|
226 |
|
541
|
227 |
lemma list_rel_refl:
|
539
|
228 |
assumes a: "\<And>x y. R x y = (R x = R y)"
|
|
229 |
shows "list_rel R x x"
|
927
|
230 |
by (induct x) (auto simp add: a)
|
0
|
231 |
|
539
|
232 |
end
|