163
|
1 |
theory FSet
|
|
2 |
imports QuotMain
|
|
3 |
begin
|
|
4 |
|
|
5 |
inductive
|
|
6 |
list_eq (infix "\<approx>" 50)
|
|
7 |
where
|
|
8 |
"a#b#xs \<approx> b#a#xs"
|
|
9 |
| "[] \<approx> []"
|
|
10 |
| "xs \<approx> ys \<Longrightarrow> ys \<approx> xs"
|
|
11 |
| "a#a#xs \<approx> a#xs"
|
|
12 |
| "xs \<approx> ys \<Longrightarrow> a#xs \<approx> a#ys"
|
|
13 |
| "\<lbrakk>xs1 \<approx> xs2; xs2 \<approx> xs3\<rbrakk> \<Longrightarrow> xs1 \<approx> xs3"
|
|
14 |
|
|
15 |
lemma list_eq_refl:
|
|
16 |
shows "xs \<approx> xs"
|
|
17 |
apply (induct xs)
|
|
18 |
apply (auto intro: list_eq.intros)
|
|
19 |
done
|
|
20 |
|
|
21 |
lemma equiv_list_eq:
|
|
22 |
shows "EQUIV list_eq"
|
|
23 |
unfolding EQUIV_REFL_SYM_TRANS REFL_def SYM_def TRANS_def
|
|
24 |
apply(auto intro: list_eq.intros list_eq_refl)
|
|
25 |
done
|
|
26 |
|
|
27 |
quotient fset = "'a list" / "list_eq"
|
|
28 |
apply(rule equiv_list_eq)
|
|
29 |
done
|
|
30 |
|
|
31 |
print_theorems
|
|
32 |
|
|
33 |
typ "'a fset"
|
|
34 |
thm "Rep_fset"
|
|
35 |
thm "ABS_fset_def"
|
|
36 |
|
|
37 |
ML {* @{term "Abs_fset"} *}
|
|
38 |
local_setup {*
|
|
39 |
make_const_def @{binding EMPTY} @{term "[]"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd
|
|
40 |
*}
|
|
41 |
|
|
42 |
term Nil
|
|
43 |
term EMPTY
|
|
44 |
thm EMPTY_def
|
|
45 |
|
|
46 |
|
|
47 |
local_setup {*
|
|
48 |
make_const_def @{binding INSERT} @{term "op #"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd
|
|
49 |
*}
|
|
50 |
|
|
51 |
term Cons
|
|
52 |
term INSERT
|
|
53 |
thm INSERT_def
|
|
54 |
|
|
55 |
local_setup {*
|
|
56 |
make_const_def @{binding UNION} @{term "op @"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd
|
|
57 |
*}
|
|
58 |
|
|
59 |
term append
|
|
60 |
term UNION
|
|
61 |
thm UNION_def
|
|
62 |
|
|
63 |
|
|
64 |
thm QUOTIENT_fset
|
|
65 |
|
|
66 |
thm QUOT_TYPE_I_fset.thm11
|
|
67 |
|
|
68 |
|
|
69 |
fun
|
|
70 |
membship :: "'a \<Rightarrow> 'a list \<Rightarrow> bool" (infix "memb" 100)
|
|
71 |
where
|
|
72 |
m1: "(x memb []) = False"
|
|
73 |
| m2: "(x memb (y#xs)) = ((x=y) \<or> (x memb xs))"
|
|
74 |
|
|
75 |
fun
|
|
76 |
card1 :: "'a list \<Rightarrow> nat"
|
|
77 |
where
|
|
78 |
card1_nil: "(card1 []) = 0"
|
|
79 |
| card1_cons: "(card1 (x # xs)) = (if (x memb xs) then (card1 xs) else (Suc (card1 xs)))"
|
|
80 |
|
|
81 |
local_setup {*
|
|
82 |
make_const_def @{binding card} @{term "card1"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd
|
|
83 |
*}
|
|
84 |
|
|
85 |
term card1
|
|
86 |
term card
|
|
87 |
thm card_def
|
|
88 |
|
|
89 |
(* text {*
|
|
90 |
Maybe make_const_def should require a theorem that says that the particular lifted function
|
|
91 |
respects the relation. With it such a definition would be impossible:
|
|
92 |
make_const_def @{binding CARD} @{term "length"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd
|
|
93 |
*}*)
|
|
94 |
|
|
95 |
lemma card1_0:
|
|
96 |
fixes a :: "'a list"
|
|
97 |
shows "(card1 a = 0) = (a = [])"
|
|
98 |
apply (induct a)
|
|
99 |
apply (simp)
|
|
100 |
apply (simp_all)
|
|
101 |
apply meson
|
|
102 |
apply (simp_all)
|
|
103 |
done
|
|
104 |
|
|
105 |
lemma not_mem_card1:
|
|
106 |
fixes x :: "'a"
|
|
107 |
fixes xs :: "'a list"
|
|
108 |
shows "~(x memb xs) \<Longrightarrow> card1 (x # xs) = Suc (card1 xs)"
|
|
109 |
by simp
|
|
110 |
|
|
111 |
|
|
112 |
lemma mem_cons:
|
|
113 |
fixes x :: "'a"
|
|
114 |
fixes xs :: "'a list"
|
|
115 |
assumes a : "x memb xs"
|
|
116 |
shows "x # xs \<approx> xs"
|
|
117 |
using a
|
|
118 |
apply (induct xs)
|
|
119 |
apply (auto intro: list_eq.intros)
|
|
120 |
done
|
|
121 |
|
|
122 |
lemma card1_suc:
|
|
123 |
fixes xs :: "'a list"
|
|
124 |
fixes n :: "nat"
|
|
125 |
assumes c: "card1 xs = Suc n"
|
|
126 |
shows "\<exists>a ys. ~(a memb ys) \<and> xs \<approx> (a # ys)"
|
|
127 |
using c
|
|
128 |
apply(induct xs)
|
|
129 |
apply (metis Suc_neq_Zero card1_0)
|
|
130 |
apply (metis QUOT_TYPE_I_fset.R_trans card1_cons list_eq_refl mem_cons)
|
|
131 |
done
|
|
132 |
|
|
133 |
primrec
|
|
134 |
fold1
|
|
135 |
where
|
|
136 |
"fold1 f (g :: 'a \<Rightarrow> 'b) (z :: 'b) [] = z"
|
|
137 |
| "fold1 f g z (a # A) =
|
|
138 |
(if ((!u v. (f u v = f v u))
|
|
139 |
\<and> (!u v w. ((f u (f v w) = f (f u v) w))))
|
|
140 |
then (
|
|
141 |
if (a memb A) then (fold1 f g z A) else (f (g a) (fold1 f g z A))
|
|
142 |
) else z)"
|
|
143 |
|
|
144 |
(* fold1_def is not usable, but: *)
|
|
145 |
thm fold1.simps
|
|
146 |
|
|
147 |
lemma fs1_strong_cases:
|
|
148 |
fixes X :: "'a list"
|
|
149 |
shows "(X = []) \<or> (\<exists>a. \<exists> Y. (~(a memb Y) \<and> (X \<approx> a # Y)))"
|
|
150 |
apply (induct X)
|
|
151 |
apply (simp)
|
|
152 |
apply (metis QUOT_TYPE_I_fset.thm11 list_eq_refl mem_cons m1)
|
|
153 |
done
|
|
154 |
|
|
155 |
local_setup {*
|
|
156 |
make_const_def @{binding IN} @{term "membship"} NoSyn @{typ "'a list"} @{typ "'a fset"} #> snd
|
|
157 |
*}
|
|
158 |
|
|
159 |
term membship
|
|
160 |
term IN
|
|
161 |
thm IN_def
|
|
162 |
|
|
163 |
ML {*
|
|
164 |
val consts = [@{const_name "Nil"}, @{const_name "Cons"},
|
|
165 |
@{const_name "membship"}, @{const_name "card1"},
|
|
166 |
@{const_name "append"}, @{const_name "fold1"}];
|
|
167 |
*}
|
|
168 |
|
|
169 |
ML {* val fset_defs = @{thms EMPTY_def IN_def UNION_def card_def INSERT_def} *}
|
|
170 |
ML {* val fset_defs_sym = map (fn t => symmetric (unabs_def @{context} t)) fset_defs *}
|
|
171 |
|
|
172 |
thm fun_map.simps
|
|
173 |
text {* Respectfullness *}
|
|
174 |
|
164
|
175 |
lemma memb_rsp:
|
163
|
176 |
fixes z
|
|
177 |
assumes a: "list_eq x y"
|
|
178 |
shows "(z memb x) = (z memb y)"
|
|
179 |
using a by induct auto
|
|
180 |
|
164
|
181 |
lemma ho_memb_rsp:
|
|
182 |
"(op = ===> (op \<approx> ===> op =)) (op memb) (op memb)"
|
|
183 |
apply (simp add: FUN_REL.simps)
|
|
184 |
apply (metis memb_rsp)
|
|
185 |
done
|
|
186 |
|
163
|
187 |
lemma card1_rsp:
|
|
188 |
fixes a b :: "'a list"
|
|
189 |
assumes e: "a \<approx> b"
|
|
190 |
shows "card1 a = card1 b"
|
|
191 |
using e apply induct
|
164
|
192 |
apply (simp_all add:memb_rsp)
|
163
|
193 |
done
|
|
194 |
|
164
|
195 |
lemma cons_rsp:
|
163
|
196 |
fixes z
|
|
197 |
assumes a: "xs \<approx> ys"
|
|
198 |
shows "(z # xs) \<approx> (z # ys)"
|
|
199 |
using a by (rule list_eq.intros(5))
|
|
200 |
|
164
|
201 |
lemma ho_cons_rsp:
|
|
202 |
"op = ===> op \<approx> ===> op \<approx> op # op #"
|
|
203 |
apply (simp add: FUN_REL.simps)
|
|
204 |
apply (metis cons_rsp)
|
|
205 |
done
|
|
206 |
|
163
|
207 |
lemma append_respects_fst:
|
|
208 |
assumes a : "list_eq l1 l2"
|
|
209 |
shows "list_eq (l1 @ s) (l2 @ s)"
|
|
210 |
using a
|
|
211 |
apply(induct)
|
|
212 |
apply(auto intro: list_eq.intros)
|
|
213 |
apply(simp add: list_eq_refl)
|
|
214 |
done
|
|
215 |
|
|
216 |
thm list.induct
|
|
217 |
lemma list_induct_hol4:
|
|
218 |
fixes P :: "'a list \<Rightarrow> bool"
|
|
219 |
assumes "((P []) \<and> (\<forall>t. (P t) \<longrightarrow> (\<forall>h. (P (h # t)))))"
|
|
220 |
shows "(\<forall>l. (P l))"
|
|
221 |
sorry
|
|
222 |
|
|
223 |
ML {* atomize_thm @{thm list_induct_hol4} *}
|
|
224 |
|
|
225 |
prove list_induct_r: {*
|
|
226 |
build_regularize_goal (atomize_thm @{thm list_induct_hol4}) @{typ "'a List.list"} @{term "op \<approx>"} @{context} *}
|
|
227 |
apply (simp only: equiv_res_forall[OF equiv_list_eq])
|
|
228 |
thm RIGHT_RES_FORALL_REGULAR
|
|
229 |
apply (rule RIGHT_RES_FORALL_REGULAR)
|
|
230 |
prefer 2
|
|
231 |
apply (assumption)
|
|
232 |
apply (metis)
|
|
233 |
done
|
|
234 |
|
|
235 |
ML {*
|
|
236 |
fun instantiate_tac thm = Subgoal.FOCUS (fn {concl, ...} =>
|
|
237 |
let
|
|
238 |
val pat = Drule.strip_imp_concl (cprop_of thm)
|
|
239 |
val insts = Thm.match (pat, concl)
|
|
240 |
in
|
|
241 |
rtac (Drule.instantiate insts thm) 1
|
|
242 |
end
|
|
243 |
handle _ => no_tac
|
|
244 |
)
|
|
245 |
*}
|
|
246 |
|
|
247 |
ML {*
|
|
248 |
fun res_forall_rsp_tac ctxt =
|
|
249 |
(simp_tac ((Simplifier.context ctxt HOL_ss) addsimps @{thms FUN_REL.simps}))
|
|
250 |
THEN' rtac @{thm allI} THEN' rtac @{thm allI} THEN' rtac @{thm impI}
|
|
251 |
THEN' instantiate_tac @{thm RES_FORALL_RSP} ctxt THEN'
|
|
252 |
(simp_tac ((Simplifier.context ctxt HOL_ss) addsimps @{thms FUN_REL.simps}))
|
|
253 |
*}
|
|
254 |
|
|
255 |
|
|
256 |
ML {*
|
|
257 |
fun quotient_tac quot_thm =
|
|
258 |
REPEAT_ALL_NEW (FIRST' [
|
|
259 |
rtac @{thm FUN_QUOTIENT},
|
|
260 |
rtac quot_thm,
|
|
261 |
rtac @{thm IDENTITY_QUOTIENT}
|
|
262 |
])
|
|
263 |
*}
|
|
264 |
|
|
265 |
ML {*
|
164
|
266 |
fun LAMBDA_RES_TAC ctxt =
|
|
267 |
case (term_of o #concl o fst) (Subgoal.focus ctxt 1 (Isar.goal ())) of
|
|
268 |
(_ $ (_ $ (Abs(_,_,_))$(Abs(_,_,_)))) =>
|
|
269 |
(EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN'
|
|
270 |
(rtac @{thm allI}) THEN' (rtac @{thm allI}) THEN' (rtac @{thm impI})
|
|
271 |
| _ => fn _ => no_tac
|
|
272 |
*}
|
|
273 |
|
|
274 |
|
|
275 |
ML {*
|
163
|
276 |
fun r_mk_comb_tac ctxt quot_thm reflex_thm trans_thm =
|
|
277 |
(FIRST' [
|
|
278 |
rtac @{thm FUN_QUOTIENT},
|
|
279 |
rtac quot_thm,
|
|
280 |
rtac @{thm IDENTITY_QUOTIENT},
|
|
281 |
rtac @{thm ext},
|
|
282 |
rtac trans_thm,
|
164
|
283 |
LAMBDA_RES_TAC ctxt,
|
163
|
284 |
res_forall_rsp_tac ctxt,
|
|
285 |
(instantiate_tac @{thm REP_ABS_RSP(1)} ctxt THEN' (RANGE [quotient_tac quot_thm])),
|
164
|
286 |
rtac refl,
|
163
|
287 |
(instantiate_tac @{thm APPLY_RSP} ctxt THEN' (RANGE [quotient_tac quot_thm, quotient_tac quot_thm])),
|
164
|
288 |
rtac reflex_thm,
|
163
|
289 |
atac,
|
|
290 |
(
|
|
291 |
(simp_tac ((Simplifier.context @{context} HOL_ss) addsimps @{thms FUN_REL.simps}))
|
|
292 |
THEN_ALL_NEW (fn _ => no_tac)
|
|
293 |
)
|
|
294 |
])
|
|
295 |
*}
|
|
296 |
|
|
297 |
ML {*
|
|
298 |
fun r_mk_comb_tac_fset ctxt =
|
|
299 |
r_mk_comb_tac ctxt @{thm QUOTIENT_fset} @{thm list_eq_refl} @{thm QUOT_TYPE_I_fset.R_trans2}
|
|
300 |
*}
|
|
301 |
|
|
302 |
|
|
303 |
ML {* val thm = @{thm list_induct_r} OF [atomize_thm @{thm list_induct_hol4}] *}
|
|
304 |
ML {* val trm_r = build_repabs_goal @{context} thm consts @{typ "'a list"} @{typ "'a fset"} *}
|
|
305 |
ML {* val trm = build_repabs_term @{context} thm consts @{typ "'a list"} @{typ "'a fset"} *}
|
|
306 |
|
164
|
307 |
|
163
|
308 |
prove list_induct_tr: trm_r
|
|
309 |
apply (atomize(full))
|
|
310 |
(* APPLY_RSP_TAC *)
|
|
311 |
apply (tactic {* REPEAT_ALL_NEW (r_mk_comb_tac_fset @{context}) 1 *})
|
|
312 |
(* LAMBDA_RES_TAC *)
|
164
|
313 |
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
|
163
|
314 |
(* MK_COMB_TAC *)
|
|
315 |
apply (tactic {* Cong_Tac.cong_tac @{thm cong} 1 *})
|
|
316 |
(* MK_COMB_TAC *)
|
|
317 |
apply (tactic {* Cong_Tac.cong_tac @{thm cong} 1 *})
|
|
318 |
(* REFL_TAC *)
|
|
319 |
apply (simp)
|
|
320 |
(* MK_COMB_TAC *)
|
|
321 |
apply (tactic {* Cong_Tac.cong_tac @{thm cong} 1 *})
|
|
322 |
(* MK_COMB_TAC *)
|
|
323 |
apply (tactic {* Cong_Tac.cong_tac @{thm cong} 1 *})
|
|
324 |
(* REFL_TAC *)
|
164
|
325 |
apply (tactic {* REPEAT_ALL_NEW (r_mk_comb_tac_fset @{context}) 1 *})
|
163
|
326 |
(* APPLY_RSP_TAC *)
|
|
327 |
apply (tactic {* REPEAT_ALL_NEW (r_mk_comb_tac_fset @{context}) 1 *})
|
|
328 |
apply (tactic {* REPEAT_ALL_NEW (r_mk_comb_tac_fset @{context}) 1 *})
|
164
|
329 |
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
|
163
|
330 |
(* MK_COMB_TAC *)
|
|
331 |
apply (tactic {* Cong_Tac.cong_tac @{thm cong} 1 *})
|
|
332 |
(* MK_COMB_TAC *)
|
|
333 |
apply (tactic {* Cong_Tac.cong_tac @{thm cong} 1 *})
|
|
334 |
(* REFL_TAC *)
|
|
335 |
apply (simp)
|
|
336 |
(* APPLY_RSP *)
|
|
337 |
apply (tactic {* REPEAT_ALL_NEW (r_mk_comb_tac_fset @{context}) 1 *})
|
|
338 |
(* MK_COMB_TAC *)
|
|
339 |
apply (tactic {* Cong_Tac.cong_tac @{thm cong} 1 *})
|
|
340 |
(* REFL_TAC *)
|
164
|
341 |
apply (tactic {* REPEAT_ALL_NEW (r_mk_comb_tac_fset @{context}) 1 *})
|
163
|
342 |
(* W(C (curry op THEN) (G... *)
|
164
|
343 |
apply (tactic {* (r_mk_comb_tac_fset @{context}) 1 *})
|
163
|
344 |
apply (tactic {* REPEAT_ALL_NEW (r_mk_comb_tac_fset @{context}) 1 *})
|
|
345 |
(* CONS respects *)
|
164
|
346 |
apply (rule ho_cons_rsp)
|
163
|
347 |
apply (tactic {* REPEAT_ALL_NEW (r_mk_comb_tac_fset @{context}) 1 *})
|
164
|
348 |
apply (subst FUN_REL.simps)
|
163
|
349 |
apply (rule allI)
|
|
350 |
apply (rule allI)
|
|
351 |
apply (rule impI)
|
|
352 |
apply (tactic {* REPEAT_ALL_NEW (r_mk_comb_tac_fset @{context}) 1 *})
|
|
353 |
done
|
|
354 |
|
|
355 |
prove list_induct_t: trm
|
|
356 |
apply (simp only: list_induct_tr[symmetric])
|
|
357 |
apply (tactic {* rtac thm 1 *})
|
|
358 |
done
|
|
359 |
|
|
360 |
ML {* val nthm = MetaSimplifier.rewrite_rule fset_defs_sym (snd (no_vars (Context.Theory @{theory}, @{thm list_induct_t}))) *}
|
|
361 |
|
|
362 |
thm list.recs(2)
|
|
363 |
thm m2
|
|
364 |
ML {* atomize_thm @{thm m2} *}
|
|
365 |
|
|
366 |
prove m2_r_p: {*
|
|
367 |
build_regularize_goal (atomize_thm @{thm m2}) @{typ "'a List.list"} @{term "op \<approx>"} @{context} *}
|
|
368 |
apply (simp add: equiv_res_forall[OF equiv_list_eq])
|
|
369 |
done
|
|
370 |
|
|
371 |
ML {* val m2_r = @{thm m2_r_p} OF [atomize_thm @{thm m2}] *}
|
|
372 |
ML {* val m2_t_g = build_repabs_goal @{context} m2_r consts @{typ "'a list"} @{typ "'a fset"} *}
|
|
373 |
ML {* val m2_t = build_repabs_term @{context} m2_r consts @{typ "'a list"} @{typ "'a fset"} *}
|
|
374 |
prove m2_t_p: m2_t_g
|
|
375 |
apply (atomize(full))
|
|
376 |
apply (tactic {* REPEAT_ALL_NEW (r_mk_comb_tac_fset @{context}) 1 *})
|
|
377 |
prefer 2
|
164
|
378 |
apply (subst FUN_REL.simps)
|
163
|
379 |
apply (rule allI)
|
|
380 |
apply (rule allI)
|
|
381 |
apply (rule impI)
|
|
382 |
apply (tactic {* REPEAT_ALL_NEW (r_mk_comb_tac_fset @{context}) 1 *})
|
|
383 |
prefer 2
|
164
|
384 |
apply (subst FUN_REL.simps)
|
163
|
385 |
apply (rule allI)
|
|
386 |
apply (rule allI)
|
|
387 |
apply (rule impI)
|
|
388 |
apply (tactic {* REPEAT_ALL_NEW (r_mk_comb_tac_fset @{context}) 1 *})
|
164
|
389 |
apply (subst FUN_REL.simps)
|
163
|
390 |
apply (rule allI)
|
|
391 |
apply (rule allI)
|
|
392 |
apply (rule impI)
|
164
|
393 |
apply (tactic {* REPEAT_ALL_NEW (r_mk_comb_tac_fset @{context}) 1 *})
|
|
394 |
apply (rule ho_memb_rsp)
|
|
395 |
apply (rule ho_cons_rsp)
|
|
396 |
apply (rule ho_memb_rsp)
|
163
|
397 |
apply (auto)
|
|
398 |
done
|
|
399 |
|
|
400 |
prove m2_t: m2_t
|
|
401 |
apply (simp only: m2_t_p[symmetric])
|
|
402 |
apply (tactic {* rtac m2_r 1 *})
|
|
403 |
done
|
|
404 |
|
|
405 |
lemma id_apply2 [simp]: "id x \<equiv> x"
|
|
406 |
by (simp add: id_def)
|
|
407 |
|
|
408 |
thm LAMBDA_PRS
|
|
409 |
ML {*
|
|
410 |
val t = prop_of @{thm LAMBDA_PRS}
|
|
411 |
val tt = Drule.instantiate' [SOME @{ctyp "'a list"}, SOME @{ctyp "'a fset"}] [] @{thm LAMBDA_PRS}
|
|
412 |
val ttt = @{thm LAMBDA_PRS} OF [@{thm QUOTIENT_fset}, @{thm IDENTITY_QUOTIENT}]
|
|
413 |
val tttt = @{thm "HOL.sym"} OF [ttt]
|
|
414 |
*}
|
|
415 |
ML {*
|
|
416 |
val ttttt = MetaSimplifier.rewrite_rule [@{thm id_apply2}] tttt
|
|
417 |
val zzz = @{thm m2_t}
|
|
418 |
*}
|
|
419 |
|
|
420 |
ML {*
|
|
421 |
fun eqsubst_thm ctxt thms thm =
|
|
422 |
let
|
|
423 |
val goalstate = Goal.init (Thm.cprop_of thm)
|
|
424 |
val a' = case (SINGLE (EqSubst.eqsubst_tac ctxt [0] thms 1) goalstate) of
|
|
425 |
NONE => error "eqsubst_thm"
|
|
426 |
| SOME th => cprem_of th 1
|
|
427 |
val tac = (EqSubst.eqsubst_tac ctxt [0] thms 1) THEN simp_tac HOL_ss 1
|
|
428 |
val cgoal = cterm_of (ProofContext.theory_of ctxt) (Logic.mk_equals (term_of (Thm.cprop_of thm), term_of a'))
|
|
429 |
val rt = Toplevel.program (fn () => Goal.prove_internal [] cgoal (fn _ => tac));
|
|
430 |
in
|
|
431 |
Simplifier.rewrite_rule [rt] thm
|
|
432 |
end
|
|
433 |
*}
|
|
434 |
ML {* val m2_t' = eqsubst_thm @{context} [ttttt] @{thm m2_t} *}
|
|
435 |
ML {* val rwr = @{thm FORALL_PRS[OF QUOTIENT_fset]} *}
|
|
436 |
ML {* val rwrs = @{thm "HOL.sym"} OF [ObjectLogic.rulify rwr] *}
|
164
|
437 |
ML {* val ithm = eqsubst_thm @{context} [rwrs] m2_t' *}
|
|
438 |
ML {* val rthm = MetaSimplifier.rewrite_rule fset_defs_sym ithm *}
|
|
439 |
ML {* ObjectLogic.rulify rthm *}
|
163
|
440 |
|
|
441 |
|
|
442 |
ML {* val card1_suc_f = Thm.freezeT (atomize_thm @{thm card1_suc}) *}
|
|
443 |
|
|
444 |
prove card1_suc_r: {*
|
|
445 |
Logic.mk_implies
|
|
446 |
((prop_of card1_suc_f),
|
|
447 |
(regularise (prop_of card1_suc_f) @{typ "'a List.list"} @{term "op \<approx>"} @{context})) *}
|
|
448 |
apply (simp add: equiv_res_forall[OF equiv_list_eq] equiv_res_exists[OF equiv_list_eq])
|
|
449 |
done
|
|
450 |
|
|
451 |
ML {* @{thm card1_suc_r} OF [card1_suc_f] *}
|
|
452 |
|
|
453 |
ML {* val li = Thm.freezeT (atomize_thm @{thm fold1.simps(2)}) *}
|
|
454 |
prove fold1_def_2_r: {*
|
|
455 |
Logic.mk_implies
|
|
456 |
((prop_of li),
|
|
457 |
(regularise (prop_of li) @{typ "'a List.list"} @{term "op \<approx>"} @{context})) *}
|
|
458 |
apply (simp add: equiv_res_forall[OF equiv_list_eq])
|
|
459 |
done
|
|
460 |
|
|
461 |
ML {* @{thm fold1_def_2_r} OF [li] *}
|
|
462 |
|
|
463 |
|
|
464 |
lemma yy:
|
|
465 |
shows "(False = x memb []) = (False = IN (x::nat) EMPTY)"
|
|
466 |
unfolding IN_def EMPTY_def
|
|
467 |
apply(rule_tac f="(op =) False" in arg_cong)
|
164
|
468 |
apply(rule memb_rsp)
|
163
|
469 |
apply(simp only: QUOT_TYPE_I_fset.REP_ABS_rsp)
|
|
470 |
apply(rule list_eq.intros)
|
|
471 |
done
|
|
472 |
|
|
473 |
lemma
|
|
474 |
shows "IN (x::nat) EMPTY = False"
|
|
475 |
using m1
|
|
476 |
apply -
|
|
477 |
apply(rule yy[THEN iffD1, symmetric])
|
|
478 |
apply(simp)
|
|
479 |
done
|
|
480 |
|
|
481 |
lemma
|
|
482 |
shows "((x=y) \<or> (IN x xs) = (IN (x::nat) (INSERT y xs))) =
|
|
483 |
((x=y) \<or> x memb REP_fset xs = x memb (y # REP_fset xs))"
|
|
484 |
unfolding IN_def INSERT_def
|
|
485 |
apply(rule_tac f="(op \<or>) (x=y)" in arg_cong)
|
|
486 |
apply(rule_tac f="(op =) (x memb REP_fset xs)" in arg_cong)
|
164
|
487 |
apply(rule memb_rsp)
|
163
|
488 |
apply(rule list_eq.intros(3))
|
|
489 |
apply(unfold REP_fset_def ABS_fset_def)
|
|
490 |
apply(simp only: QUOT_TYPE.REP_ABS_rsp[OF QUOT_TYPE_fset])
|
|
491 |
apply(rule list_eq_refl)
|
|
492 |
done
|
|
493 |
|
|
494 |
lemma yyy:
|
|
495 |
shows "
|
|
496 |
(
|
|
497 |
(UNION EMPTY s = s) &
|
|
498 |
((UNION (INSERT e s1) s2) = (INSERT e (UNION s1 s2)))
|
|
499 |
) = (
|
|
500 |
((ABS_fset ([] @ REP_fset s)) = s) &
|
|
501 |
((ABS_fset ((e # (REP_fset s1)) @ REP_fset s2)) = ABS_fset (e # (REP_fset s1 @ REP_fset s2)))
|
|
502 |
)"
|
|
503 |
unfolding UNION_def EMPTY_def INSERT_def
|
|
504 |
apply(rule_tac f="(op &)" in arg_cong2)
|
|
505 |
apply(rule_tac f="(op =)" in arg_cong2)
|
|
506 |
apply(simp only: QUOT_TYPE_I_fset.thm11[symmetric])
|
|
507 |
apply(rule append_respects_fst)
|
|
508 |
apply(simp only: QUOT_TYPE_I_fset.REP_ABS_rsp)
|
|
509 |
apply(rule list_eq_refl)
|
|
510 |
apply(simp)
|
|
511 |
apply(rule_tac f="(op =)" in arg_cong2)
|
|
512 |
apply(simp only: QUOT_TYPE_I_fset.thm11[symmetric])
|
|
513 |
apply(rule append_respects_fst)
|
|
514 |
apply(simp only: QUOT_TYPE_I_fset.REP_ABS_rsp)
|
|
515 |
apply(rule list_eq_refl)
|
|
516 |
apply(simp only: QUOT_TYPE_I_fset.thm11[symmetric])
|
|
517 |
apply(rule list_eq.intros(5))
|
|
518 |
apply(simp only: QUOT_TYPE_I_fset.REP_ABS_rsp)
|
|
519 |
apply(rule list_eq_refl)
|
|
520 |
done
|
|
521 |
|
|
522 |
lemma
|
|
523 |
shows "
|
|
524 |
(UNION EMPTY s = s) &
|
|
525 |
((UNION (INSERT e s1) s2) = (INSERT e (UNION s1 s2)))"
|
|
526 |
apply (simp add: yyy)
|
|
527 |
apply (simp add: QUOT_TYPE_I_fset.thm10)
|
|
528 |
done
|
|
529 |
|
|
530 |
ML {*
|
|
531 |
val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm m2}))
|
|
532 |
*}
|
|
533 |
|
|
534 |
ML {*
|
|
535 |
cterm_of @{theory} (prop_of m1_novars);
|
|
536 |
cterm_of @{theory} (build_repabs_term @{context} m1_novars consts @{typ "'a list"} @{typ "'a fset"});
|
|
537 |
*}
|
|
538 |
|
|
539 |
|
|
540 |
(* Has all the theorems about fset plugged in. These should be parameters to the tactic *)
|
|
541 |
ML {*
|
|
542 |
fun transconv_fset_tac' ctxt =
|
|
543 |
(LocalDefs.unfold_tac @{context} fset_defs) THEN
|
|
544 |
ObjectLogic.full_atomize_tac 1 THEN
|
|
545 |
REPEAT_ALL_NEW (FIRST' [
|
|
546 |
rtac @{thm list_eq_refl},
|
|
547 |
rtac @{thm cons_preserves},
|
164
|
548 |
rtac @{thm memb_rsp},
|
163
|
549 |
rtac @{thm card1_rsp},
|
|
550 |
rtac @{thm QUOT_TYPE_I_fset.R_trans2},
|
|
551 |
CHANGED o (simp_tac ((Simplifier.context ctxt HOL_ss) addsimps @{thms QUOT_TYPE_I_fset.REP_ABS_rsp})),
|
|
552 |
Cong_Tac.cong_tac @{thm cong},
|
|
553 |
rtac @{thm ext}
|
|
554 |
]) 1
|
|
555 |
*}
|
|
556 |
|
|
557 |
ML {*
|
|
558 |
val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm m1}))
|
|
559 |
val goal = build_repabs_goal @{context} m1_novars consts @{typ "'a list"} @{typ "'a fset"}
|
|
560 |
val cgoal = cterm_of @{theory} goal
|
|
561 |
val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite false fset_defs_sym cgoal)
|
|
562 |
*}
|
|
563 |
|
|
564 |
(*notation ( output) "prop" ("#_" [1000] 1000) *)
|
|
565 |
notation ( output) "Trueprop" ("#_" [1000] 1000)
|
|
566 |
|
|
567 |
|
|
568 |
prove {* (Thm.term_of cgoal2) *}
|
|
569 |
apply (tactic {* transconv_fset_tac' @{context} *})
|
|
570 |
done
|
|
571 |
|
|
572 |
thm length_append (* Not true but worth checking that the goal is correct *)
|
|
573 |
ML {*
|
|
574 |
val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm length_append}))
|
|
575 |
val goal = build_repabs_goal @{context} m1_novars consts @{typ "'a list"} @{typ "'a fset"}
|
|
576 |
val cgoal = cterm_of @{theory} goal
|
|
577 |
val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite false fset_defs_sym cgoal)
|
|
578 |
*}
|
|
579 |
prove {* Thm.term_of cgoal2 *}
|
|
580 |
apply (tactic {* transconv_fset_tac' @{context} *})
|
|
581 |
sorry
|
|
582 |
|
|
583 |
thm m2
|
|
584 |
ML {*
|
|
585 |
val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm m2}))
|
|
586 |
val goal = build_repabs_goal @{context} m1_novars consts @{typ "'a list"} @{typ "'a fset"}
|
|
587 |
val cgoal = cterm_of @{theory} goal
|
|
588 |
val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite false fset_defs_sym cgoal)
|
|
589 |
*}
|
|
590 |
prove {* Thm.term_of cgoal2 *}
|
|
591 |
apply (tactic {* transconv_fset_tac' @{context} *})
|
|
592 |
done
|
|
593 |
|
|
594 |
thm list_eq.intros(4)
|
|
595 |
ML {*
|
|
596 |
val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm list_eq.intros(4)}))
|
|
597 |
val goal = build_repabs_goal @{context} m1_novars consts @{typ "'a list"} @{typ "'a fset"}
|
|
598 |
val cgoal = cterm_of @{theory} goal
|
|
599 |
val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite false fset_defs_sym cgoal)
|
|
600 |
val cgoal3 = Thm.rhs_of (MetaSimplifier.rewrite true @{thms QUOT_TYPE_I_fset.thm10} cgoal2)
|
|
601 |
*}
|
|
602 |
|
|
603 |
(* It is the same, but we need a name for it. *)
|
|
604 |
prove zzz : {* Thm.term_of cgoal3 *}
|
|
605 |
apply (tactic {* transconv_fset_tac' @{context} *})
|
|
606 |
done
|
|
607 |
|
|
608 |
(*lemma zzz' :
|
|
609 |
"(REP_fset (INSERT a (INSERT a (ABS_fset xs))) \<approx> REP_fset (INSERT a (ABS_fset xs)))"
|
|
610 |
using list_eq.intros(4) by (simp only: zzz)
|
|
611 |
|
|
612 |
thm QUOT_TYPE_I_fset.REPS_same
|
|
613 |
ML {* val zzz'' = MetaSimplifier.rewrite_rule @{thms QUOT_TYPE_I_fset.REPS_same} @{thm zzz'} *}
|
|
614 |
*)
|
|
615 |
|
|
616 |
thm list_eq.intros(5)
|
|
617 |
(* prove {* build_repabs_goal @{context} (atomize_thm @{thm list_eq.intros(5)}) consts @{typ "'a list"} @{typ "'a fset"} *} *)
|
|
618 |
ML {*
|
|
619 |
val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm list_eq.intros(5)}))
|
|
620 |
val goal = build_repabs_goal @{context} m1_novars consts @{typ "'a list"} @{typ "'a fset"}
|
|
621 |
val cgoal = cterm_of @{theory} goal
|
|
622 |
val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite true fset_defs_sym cgoal)
|
|
623 |
*}
|
|
624 |
prove {* Thm.term_of cgoal2 *}
|
|
625 |
apply (tactic {* transconv_fset_tac' @{context} *})
|
|
626 |
done
|
|
627 |
|
|
628 |
ML {*
|
|
629 |
fun lift_theorem_fset_aux thm lthy =
|
|
630 |
let
|
|
631 |
val ((_, [novars]), lthy2) = Variable.import true [thm] lthy;
|
|
632 |
val goal = build_repabs_goal @{context} novars consts @{typ "'a list"} @{typ "'a fset"};
|
|
633 |
val cgoal = cterm_of @{theory} goal;
|
|
634 |
val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite true fset_defs_sym cgoal);
|
|
635 |
val tac = transconv_fset_tac' @{context};
|
|
636 |
val cthm = Goal.prove_internal [] cgoal2 (fn _ => tac);
|
|
637 |
val nthm = MetaSimplifier.rewrite_rule [symmetric cthm] (snd (no_vars (Context.Theory @{theory}, thm)))
|
|
638 |
val nthm2 = MetaSimplifier.rewrite_rule @{thms QUOT_TYPE_I_fset.REPS_same QUOT_TYPE_I_fset.thm10} nthm;
|
|
639 |
val [nthm3] = ProofContext.export lthy2 lthy [nthm2]
|
|
640 |
in
|
|
641 |
nthm3
|
|
642 |
end
|
|
643 |
*}
|
|
644 |
|
|
645 |
ML {* lift_theorem_fset_aux @{thm m1} @{context} *}
|
|
646 |
|
|
647 |
ML {*
|
|
648 |
fun lift_theorem_fset name thm lthy =
|
|
649 |
let
|
|
650 |
val lifted_thm = lift_theorem_fset_aux thm lthy;
|
|
651 |
val (_, lthy2) = note (name, lifted_thm) lthy;
|
|
652 |
in
|
|
653 |
lthy2
|
|
654 |
end;
|
|
655 |
*}
|
|
656 |
|
|
657 |
(* These do not work without proper definitions to rewrite back *)
|
|
658 |
local_setup {* lift_theorem_fset @{binding "m1_lift"} @{thm m1} *}
|
|
659 |
local_setup {* lift_theorem_fset @{binding "leqi4_lift"} @{thm list_eq.intros(4)} *}
|
|
660 |
local_setup {* lift_theorem_fset @{binding "leqi5_lift"} @{thm list_eq.intros(5)} *}
|
|
661 |
local_setup {* lift_theorem_fset @{binding "m2_lift"} @{thm m2} *}
|
|
662 |
thm m1_lift
|
|
663 |
thm leqi4_lift
|
|
664 |
thm leqi5_lift
|
|
665 |
thm m2_lift
|
|
666 |
ML {* @{thm card1_suc_r} OF [card1_suc_f] *}
|
|
667 |
(*ML {* Toplevel.program (fn () => lift_theorem_fset @{binding "card_suc"}
|
|
668 |
(@{thm card1_suc_r} OF [card1_suc_f]) @{context}) *}*)
|
|
669 |
(*local_setup {* lift_theorem_fset @{binding "card_suc"} @{thm card1_suc} *}*)
|
|
670 |
|
|
671 |
thm leqi4_lift
|
|
672 |
ML {*
|
|
673 |
val (nam, typ) = hd (Term.add_vars (prop_of @{thm leqi4_lift}) [])
|
|
674 |
val (_, l) = dest_Type typ
|
|
675 |
val t = Type ("FSet.fset", l)
|
|
676 |
val v = Var (nam, t)
|
|
677 |
val cv = cterm_of @{theory} ((term_of @{cpat "REP_fset"}) $ v)
|
|
678 |
*}
|
|
679 |
|
|
680 |
ML {*
|
|
681 |
Toplevel.program (fn () =>
|
|
682 |
MetaSimplifier.rewrite_rule @{thms QUOT_TYPE_I_fset.thm10} (
|
|
683 |
Drule.instantiate' [] [NONE, SOME (cv)] @{thm leqi4_lift}
|
|
684 |
)
|
|
685 |
)
|
|
686 |
*}
|
|
687 |
|
|
688 |
|
|
689 |
|
|
690 |
(*prove aaa: {* (Thm.term_of cgoal2) *}
|
|
691 |
apply (tactic {* LocalDefs.unfold_tac @{context} fset_defs *} )
|
|
692 |
apply (atomize(full))
|
|
693 |
apply (tactic {* transconv_fset_tac' @{context} 1 *})
|
|
694 |
done*)
|
|
695 |
|
|
696 |
(*
|
|
697 |
datatype obj1 =
|
|
698 |
OVAR1 "string"
|
|
699 |
| OBJ1 "(string * (string \<Rightarrow> obj1)) list"
|
|
700 |
| INVOKE1 "obj1 \<Rightarrow> string"
|
|
701 |
| UPDATE1 "obj1 \<Rightarrow> string \<Rightarrow> (string \<Rightarrow> obj1)"
|
|
702 |
*)
|
|
703 |
|
|
704 |
end
|