author | huffman |
Wed, 24 Feb 2010 16:15:03 -0800 | |
changeset 35444 | 73f645fdd4ff |
parent 35443 | 2e0f9516947e |
child 35446 | b719dad322fa |
permissions | -rw-r--r-- |
32126 | 1 |
(* Title: HOLCF/Tools/Domain/domain_theorems.ML |
23152 | 2 |
Author: David von Oheimb |
32740 | 3 |
Author: Brian Huffman |
23152 | 4 |
|
5 |
Proof generator for domain command. |
|
6 |
*) |
|
7 |
||
26342 | 8 |
val HOLCF_ss = @{simpset}; |
23152 | 9 |
|
31005 | 10 |
signature DOMAIN_THEOREMS = |
11 |
sig |
|
35444 | 12 |
val theorems: |
13 |
Domain_Library.eq * Domain_Library.eq list |
|
14 |
-> typ * (binding * (bool * binding option * typ) list * mixfix) list |
|
15 |
-> theory -> thm list * theory; |
|
16 |
||
31005 | 17 |
val comp_theorems: bstring * Domain_Library.eq list -> theory -> thm list * theory; |
32740 | 18 |
val quiet_mode: bool Unsynchronized.ref; |
19 |
val trace_domain: bool Unsynchronized.ref; |
|
31005 | 20 |
end; |
21 |
||
31023 | 22 |
structure Domain_Theorems :> DOMAIN_THEOREMS = |
31005 | 23 |
struct |
23152 | 24 |
|
32740 | 25 |
val quiet_mode = Unsynchronized.ref false; |
26 |
val trace_domain = Unsynchronized.ref false; |
|
29402 | 27 |
|
28 |
fun message s = if !quiet_mode then () else writeln s; |
|
29 |
fun trace s = if !trace_domain then tracing s else (); |
|
30 |
||
25805 | 31 |
val adm_impl_admw = @{thm adm_impl_admw}; |
25895
0eaadfa8889e
converted adm_all and adm_ball to rule_format; cleaned up
huffman
parents:
25805
diff
changeset
|
32 |
val adm_all = @{thm adm_all}; |
25805 | 33 |
val adm_conj = @{thm adm_conj}; |
34 |
val adm_subst = @{thm adm_subst}; |
|
31076
99fe356cbbc2
rename constant sq_le to below; rename class sq_ord to below; less->below in many lemma names
huffman
parents:
31023
diff
changeset
|
35 |
val antisym_less_inverse = @{thm below_antisym_inverse}; |
25805 | 36 |
val beta_cfun = @{thm beta_cfun}; |
37 |
val cfun_arg_cong = @{thm cfun_arg_cong}; |
|
33396 | 38 |
val ch2ch_fst = @{thm ch2ch_fst}; |
39 |
val ch2ch_snd = @{thm ch2ch_snd}; |
|
25805 | 40 |
val ch2ch_Rep_CFunL = @{thm ch2ch_Rep_CFunL}; |
41 |
val ch2ch_Rep_CFunR = @{thm ch2ch_Rep_CFunR}; |
|
42 |
val chain_iterate = @{thm chain_iterate}; |
|
43 |
val compact_ONE = @{thm compact_ONE}; |
|
44 |
val compact_sinl = @{thm compact_sinl}; |
|
45 |
val compact_sinr = @{thm compact_sinr}; |
|
46 |
val compact_spair = @{thm compact_spair}; |
|
47 |
val compact_up = @{thm compact_up}; |
|
48 |
val contlub_cfun_arg = @{thm contlub_cfun_arg}; |
|
49 |
val contlub_cfun_fun = @{thm contlub_cfun_fun}; |
|
33396 | 50 |
val contlub_fst = @{thm contlub_fst}; |
51 |
val contlub_snd = @{thm contlub_snd}; |
|
52 |
val contlubE = @{thm contlubE}; |
|
53 |
val cont_const = @{thm cont_const}; |
|
54 |
val cont_id = @{thm cont_id}; |
|
55 |
val cont2cont_fst = @{thm cont2cont_fst}; |
|
56 |
val cont2cont_snd = @{thm cont2cont_snd}; |
|
57 |
val cont2cont_Rep_CFun = @{thm cont2cont_Rep_CFun}; |
|
25805 | 58 |
val fix_def2 = @{thm fix_def2}; |
59 |
val injection_eq = @{thm injection_eq}; |
|
31076
99fe356cbbc2
rename constant sq_le to below; rename class sq_ord to below; less->below in many lemma names
huffman
parents:
31023
diff
changeset
|
60 |
val injection_less = @{thm injection_below}; |
25805 | 61 |
val lub_equal = @{thm lub_equal}; |
62 |
val monofun_cfun_arg = @{thm monofun_cfun_arg}; |
|
63 |
val retraction_strict = @{thm retraction_strict}; |
|
64 |
val spair_eq = @{thm spair_eq}; |
|
31076
99fe356cbbc2
rename constant sq_le to below; rename class sq_ord to below; less->below in many lemma names
huffman
parents:
31023
diff
changeset
|
65 |
val spair_less = @{thm spair_below}; |
25805 | 66 |
val sscase1 = @{thm sscase1}; |
67 |
val ssplit1 = @{thm ssplit1}; |
|
68 |
val strictify1 = @{thm strictify1}; |
|
69 |
val wfix_ind = @{thm wfix_ind}; |
|
70 |
||
71 |
val iso_intro = @{thm iso.intro}; |
|
72 |
val iso_abs_iso = @{thm iso.abs_iso}; |
|
73 |
val iso_rep_iso = @{thm iso.rep_iso}; |
|
74 |
val iso_abs_strict = @{thm iso.abs_strict}; |
|
75 |
val iso_rep_strict = @{thm iso.rep_strict}; |
|
76 |
val iso_abs_defin' = @{thm iso.abs_defin'}; |
|
77 |
val iso_rep_defin' = @{thm iso.rep_defin'}; |
|
78 |
val iso_abs_defined = @{thm iso.abs_defined}; |
|
79 |
val iso_rep_defined = @{thm iso.rep_defined}; |
|
80 |
val iso_compact_abs = @{thm iso.compact_abs}; |
|
81 |
val iso_compact_rep = @{thm iso.compact_rep}; |
|
82 |
val iso_iso_swap = @{thm iso.iso_swap}; |
|
83 |
||
84 |
val exh_start = @{thm exh_start}; |
|
85 |
val ex_defined_iffs = @{thms ex_defined_iffs}; |
|
86 |
val exh_casedist0 = @{thm exh_casedist0}; |
|
87 |
val exh_casedists = @{thms exh_casedists}; |
|
23152 | 88 |
|
89 |
open Domain_Library; |
|
90 |
infixr 0 ===>; |
|
91 |
infixr 0 ==>; |
|
92 |
infix 0 == ; |
|
93 |
infix 1 ===; |
|
94 |
infix 1 ~= ; |
|
95 |
infix 1 <<; |
|
96 |
infix 1 ~<<; |
|
97 |
infix 9 ` ; |
|
98 |
infix 9 `% ; |
|
99 |
infix 9 `%%; |
|
100 |
infixr 9 oo; |
|
101 |
||
102 |
(* ----- general proof facilities ------------------------------------------- *) |
|
103 |
||
24503 | 104 |
fun legacy_infer_term thy t = |
105 |
let val ctxt = ProofContext.set_mode ProofContext.mode_schematic (ProofContext.init thy) |
|
106 |
in singleton (Syntax.check_terms ctxt) (Sign.intern_term thy t) end; |
|
107 |
||
23152 | 108 |
fun pg'' thy defs t tacs = |
109 |
let |
|
24503 | 110 |
val t' = legacy_infer_term thy t; |
23152 | 111 |
val asms = Logic.strip_imp_prems t'; |
112 |
val prop = Logic.strip_imp_concl t'; |
|
26711 | 113 |
fun tac {prems, context} = |
23152 | 114 |
rewrite_goals_tac defs THEN |
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
115 |
EVERY (tacs {prems = map (rewrite_rule defs) prems, context = context}) |
23152 | 116 |
in Goal.prove_global thy [] asms prop tac end; |
117 |
||
118 |
fun pg' thy defs t tacsf = |
|
119 |
let |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
120 |
fun tacs {prems, context} = |
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
121 |
if null prems then tacsf context |
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
122 |
else cut_facts_tac prems 1 :: tacsf context; |
23152 | 123 |
in pg'' thy defs t tacs end; |
124 |
||
35443
2e0f9516947e
change domain package's treatment of variable names in theorems to be like datatype package
huffman
parents:
35288
diff
changeset
|
125 |
(* FIXME!!!!!!!!! *) |
2e0f9516947e
change domain package's treatment of variable names in theorems to be like datatype package
huffman
parents:
35288
diff
changeset
|
126 |
(* We should NEVER re-parse variable names as strings! *) |
2e0f9516947e
change domain package's treatment of variable names in theorems to be like datatype package
huffman
parents:
35288
diff
changeset
|
127 |
(* The names can conflict with existing constants or other syntax! *) |
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
128 |
fun case_UU_tac ctxt rews i v = |
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
129 |
InductTacs.case_tac ctxt (v^"=UU") i THEN |
23152 | 130 |
asm_simp_tac (HOLCF_ss addsimps rews) i; |
131 |
||
132 |
val chain_tac = |
|
133 |
REPEAT_DETERM o resolve_tac |
|
33396 | 134 |
[chain_iterate, ch2ch_Rep_CFunR, ch2ch_Rep_CFunL, ch2ch_fst, ch2ch_snd]; |
23152 | 135 |
|
136 |
(* ----- general proofs ----------------------------------------------------- *) |
|
137 |
||
29064 | 138 |
val all2E = @{lemma "!x y . P x y ==> (P x y ==> R) ==> R" by simp} |
23152 | 139 |
|
31076
99fe356cbbc2
rename constant sq_le to below; rename class sq_ord to below; less->below in many lemma names
huffman
parents:
31023
diff
changeset
|
140 |
val dist_eqI = @{lemma "!!x::'a::po. ~ x << y ==> x ~= y" by (blast dest!: below_antisym_inverse)} |
23152 | 141 |
|
35444 | 142 |
fun theorems |
143 |
(((dname, _), cons) : eq, eqs : eq list) |
|
144 |
(dom_eqn : typ * (binding * (bool * binding option * typ) list * mixfix) list) |
|
145 |
(thy : theory) = |
|
23152 | 146 |
let |
147 |
||
29402 | 148 |
val _ = message ("Proving isomorphism properties of domain "^dname^" ..."); |
33801 | 149 |
val map_tab = Domain_Isomorphism.get_map_tab thy; |
150 |
||
23152 | 151 |
|
152 |
(* ----- getting the axioms and definitions --------------------------------- *) |
|
153 |
||
154 |
local |
|
26343
0dd2eab7b296
simplified get_thm(s): back to plain name argument;
wenzelm
parents:
26342
diff
changeset
|
155 |
fun ga s dn = PureThy.get_thm thy (dn ^ "." ^ s); |
23152 | 156 |
in |
157 |
val ax_abs_iso = ga "abs_iso" dname; |
|
158 |
val ax_rep_iso = ga "rep_iso" dname; |
|
159 |
val ax_when_def = ga "when_def" dname; |
|
35288 | 160 |
fun get_def mk_name (con, _, _) = ga (mk_name con^"_def") dname; |
23152 | 161 |
val axs_dis_def = map (get_def dis_name) cons; |
162 |
val axs_mat_def = map (get_def mat_name) cons; |
|
163 |
val axs_pat_def = map (get_def pat_name) cons; |
|
164 |
val axs_sel_def = |
|
165 |
let |
|
166 |
fun def_of_sel sel = ga (sel^"_def") dname; |
|
167 |
fun def_of_arg arg = Option.map def_of_sel (sel_of arg); |
|
35288 | 168 |
fun defs_of_con (_, _, args) = map_filter def_of_arg args; |
23152 | 169 |
in |
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26012
diff
changeset
|
170 |
maps defs_of_con cons |
23152 | 171 |
end; |
172 |
val ax_copy_def = ga "copy_def" dname; |
|
173 |
end; (* local *) |
|
174 |
||
35444 | 175 |
(* ----- define constructors ------------------------------------------------ *) |
176 |
||
177 |
val lhsT = fst dom_eqn; |
|
178 |
||
179 |
val rhsT = |
|
180 |
let |
|
181 |
fun mk_arg_typ (lazy, sel, T) = if lazy then mk_uT T else T; |
|
182 |
fun mk_con_typ (bind, args, mx) = |
|
183 |
if null args then oneT else foldr1 mk_sprodT (map mk_arg_typ args); |
|
184 |
fun mk_eq_typ (_, cons) = foldr1 mk_ssumT (map mk_con_typ cons); |
|
185 |
in |
|
186 |
mk_eq_typ dom_eqn |
|
187 |
end; |
|
188 |
||
189 |
val rep_const = Const(dname^"_rep", lhsT ->> rhsT); |
|
190 |
||
191 |
val abs_const = Const(dname^"_abs", rhsT ->> lhsT); |
|
192 |
||
193 |
val (result, thy) = |
|
194 |
Domain_Constructors.add_domain_constructors |
|
195 |
(Long_Name.base_name dname) dom_eqn |
|
196 |
(rep_const, abs_const) (ax_rep_iso, ax_abs_iso) thy; |
|
197 |
||
198 |
val axs_con_def = #con_defs result; |
|
199 |
||
23152 | 200 |
(* ----- theorems concerning the isomorphism -------------------------------- *) |
201 |
||
35444 | 202 |
val pg = pg' thy; |
203 |
||
23152 | 204 |
val dc_abs = %%:(dname^"_abs"); |
205 |
val dc_rep = %%:(dname^"_rep"); |
|
206 |
val dc_copy = %%:(dname^"_copy"); |
|
207 |
val x_name = "x"; |
|
208 |
||
209 |
val iso_locale = iso_intro OF [ax_abs_iso, ax_rep_iso]; |
|
210 |
val abs_strict = ax_rep_iso RS (allI RS retraction_strict); |
|
211 |
val rep_strict = ax_abs_iso RS (allI RS retraction_strict); |
|
212 |
val abs_defin' = iso_locale RS iso_abs_defin'; |
|
213 |
val rep_defin' = iso_locale RS iso_rep_defin'; |
|
35021
c839a4c670c6
renamed old-style Drule.standard to Drule.export_without_context, to emphasize that this is in no way a standard operation;
wenzelm
parents:
34974
diff
changeset
|
214 |
val iso_rews = map Drule.export_without_context [ax_abs_iso, ax_rep_iso, abs_strict, rep_strict]; |
23152 | 215 |
|
216 |
(* ----- generating beta reduction rules from definitions-------------------- *) |
|
217 |
||
29402 | 218 |
val _ = trace " Proving beta reduction rules..."; |
219 |
||
23152 | 220 |
local |
221 |
fun arglist (Const _ $ Abs (s, _, t)) = |
|
222 |
let |
|
223 |
val (vars,body) = arglist t; |
|
224 |
in (s :: vars, body) end |
|
225 |
| arglist t = ([], t); |
|
226 |
fun bind_fun vars t = Library.foldr mk_All (vars, t); |
|
227 |
fun bound_vars 0 = [] |
|
228 |
| bound_vars i = Bound (i-1) :: bound_vars (i - 1); |
|
229 |
in |
|
230 |
fun appl_of_def def = |
|
231 |
let |
|
232 |
val (_ $ con $ lam) = concl_of def; |
|
233 |
val (vars, rhs) = arglist lam; |
|
234 |
val lhs = list_ccomb (con, bound_vars (length vars)); |
|
235 |
val appl = bind_fun vars (lhs == rhs); |
|
236 |
val cs = ContProc.cont_thms lam; |
|
237 |
val betas = map (fn c => mk_meta_eq (c RS beta_cfun)) cs; |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
238 |
in pg (def::betas) appl (K [rtac reflexive_thm 1]) end; |
23152 | 239 |
end; |
240 |
||
29402 | 241 |
val _ = trace "Proving when_appl..."; |
23152 | 242 |
val when_appl = appl_of_def ax_when_def; |
29402 | 243 |
val _ = trace "Proving con_appls..."; |
23152 | 244 |
val con_appls = map appl_of_def axs_con_def; |
245 |
||
246 |
local |
|
247 |
fun arg2typ n arg = |
|
248 |
let val t = TVar (("'a", n), pcpoS) |
|
249 |
in (n + 1, if is_lazy arg then mk_uT t else t) end; |
|
250 |
||
251 |
fun args2typ n [] = (n, oneT) |
|
252 |
| args2typ n [arg] = arg2typ n arg |
|
253 |
| args2typ n (arg::args) = |
|
254 |
let |
|
255 |
val (n1, t1) = arg2typ n arg; |
|
256 |
val (n2, t2) = args2typ n1 args |
|
257 |
in (n2, mk_sprodT (t1, t2)) end; |
|
258 |
||
259 |
fun cons2typ n [] = (n,oneT) |
|
35288 | 260 |
| cons2typ n [con] = args2typ n (third con) |
23152 | 261 |
| cons2typ n (con::cons) = |
262 |
let |
|
35288 | 263 |
val (n1, t1) = args2typ n (third con); |
23152 | 264 |
val (n2, t2) = cons2typ n1 cons |
265 |
in (n2, mk_ssumT (t1, t2)) end; |
|
266 |
in |
|
267 |
fun cons2ctyp cons = ctyp_of thy (snd (cons2typ 1 cons)); |
|
268 |
end; |
|
269 |
||
35443
2e0f9516947e
change domain package's treatment of variable names in theorems to be like datatype package
huffman
parents:
35288
diff
changeset
|
270 |
local |
23152 | 271 |
val iso_swap = iso_locale RS iso_iso_swap; |
35288 | 272 |
fun one_con (con, _, args) = |
23152 | 273 |
let |
35443
2e0f9516947e
change domain package's treatment of variable names in theorems to be like datatype package
huffman
parents:
35288
diff
changeset
|
274 |
val vns = Name.variant_list ["x"] (map vname args); |
2e0f9516947e
change domain package's treatment of variable names in theorems to be like datatype package
huffman
parents:
35288
diff
changeset
|
275 |
val nonlazy_vns = map snd (filter_out (is_lazy o fst) (args ~~ vns)); |
23152 | 276 |
val eqn = %:x_name === con_app2 con %: vns; |
35443
2e0f9516947e
change domain package's treatment of variable names in theorems to be like datatype package
huffman
parents:
35288
diff
changeset
|
277 |
val conj = foldr1 mk_conj (eqn :: map (defined o %:) nonlazy_vns); |
23152 | 278 |
in Library.foldr mk_ex (vns, conj) end; |
279 |
||
23894
1a4167d761ac
tactics: avoid dynamic reference to accidental theory context (via ML_Context.the_context etc.);
wenzelm
parents:
23152
diff
changeset
|
280 |
val conj_assoc = @{thm conj_assoc}; |
23152 | 281 |
val exh = foldr1 mk_disj ((%:x_name === UU) :: map one_con cons); |
282 |
val thm1 = instantiate' [SOME (cons2ctyp cons)] [] exh_start; |
|
283 |
val thm2 = rewrite_rule (map mk_meta_eq ex_defined_iffs) thm1; |
|
25805 | 284 |
val thm3 = rewrite_rule [mk_meta_eq @{thm conj_assoc}] thm2; |
23152 | 285 |
|
286 |
(* first 3 rules replace "x = UU \/ P" with "rep$x = UU \/ P" *) |
|
287 |
val tacs = [ |
|
288 |
rtac disjE 1, |
|
289 |
etac (rep_defin' RS disjI1) 2, |
|
290 |
etac disjI2 2, |
|
291 |
rewrite_goals_tac [mk_meta_eq iso_swap], |
|
292 |
rtac thm3 1]; |
|
293 |
in |
|
29402 | 294 |
val _ = trace " Proving exhaust..."; |
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
295 |
val exhaust = pg con_appls (mk_trp exh) (K tacs); |
29402 | 296 |
val _ = trace " Proving casedist..."; |
23152 | 297 |
val casedist = |
35021
c839a4c670c6
renamed old-style Drule.standard to Drule.export_without_context, to emphasize that this is in no way a standard operation;
wenzelm
parents:
34974
diff
changeset
|
298 |
Drule.export_without_context (rewrite_rule exh_casedists (exhaust RS exh_casedist0)); |
23152 | 299 |
end; |
300 |
||
301 |
local |
|
302 |
fun bind_fun t = Library.foldr mk_All (when_funs cons, t); |
|
303 |
fun bound_fun i _ = Bound (length cons - i); |
|
304 |
val when_app = list_ccomb (%%:(dname^"_when"), mapn bound_fun 1 cons); |
|
305 |
in |
|
29402 | 306 |
val _ = trace " Proving when_strict..."; |
23152 | 307 |
val when_strict = |
308 |
let |
|
309 |
val axs = [when_appl, mk_meta_eq rep_strict]; |
|
310 |
val goal = bind_fun (mk_trp (strict when_app)); |
|
311 |
val tacs = [resolve_tac [sscase1, ssplit1, strictify1] 1]; |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
312 |
in pg axs goal (K tacs) end; |
23152 | 313 |
|
29402 | 314 |
val _ = trace " Proving when_apps..."; |
23152 | 315 |
val when_apps = |
316 |
let |
|
35288 | 317 |
fun one_when n (con, _, args) = |
23152 | 318 |
let |
319 |
val axs = when_appl :: con_appls; |
|
320 |
val goal = bind_fun (lift_defined %: (nonlazy args, |
|
321 |
mk_trp (when_app`(con_app con args) === |
|
322 |
list_ccomb (bound_fun n 0, map %# args)))); |
|
323 |
val tacs = [asm_simp_tac (HOLCF_ss addsimps [ax_abs_iso]) 1]; |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
324 |
in pg axs goal (K tacs) end; |
23152 | 325 |
in mapn one_when 1 cons end; |
326 |
end; |
|
327 |
val when_rews = when_strict :: when_apps; |
|
328 |
||
329 |
(* ----- theorems concerning the constructors, discriminators and selectors - *) |
|
330 |
||
331 |
local |
|
35288 | 332 |
fun dis_strict (con, _, _) = |
23152 | 333 |
let |
334 |
val goal = mk_trp (strict (%%:(dis_name con))); |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
335 |
in pg axs_dis_def goal (K [rtac when_strict 1]) end; |
23152 | 336 |
|
35288 | 337 |
fun dis_app c (con, _, args) = |
23152 | 338 |
let |
339 |
val lhs = %%:(dis_name c) ` con_app con args; |
|
26012 | 340 |
val rhs = if con = c then TT else FF; |
23152 | 341 |
val goal = lift_defined %: (nonlazy args, mk_trp (lhs === rhs)); |
342 |
val tacs = [asm_simp_tac (HOLCF_ss addsimps when_rews) 1]; |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
343 |
in pg axs_dis_def goal (K tacs) end; |
23152 | 344 |
|
29402 | 345 |
val _ = trace " Proving dis_apps..."; |
35288 | 346 |
val dis_apps = maps (fn (c,_,_) => map (dis_app c) cons) cons; |
23152 | 347 |
|
35288 | 348 |
fun dis_defin (con, _, args) = |
23152 | 349 |
let |
350 |
val goal = defined (%:x_name) ==> defined (%%:(dis_name con) `% x_name); |
|
351 |
val tacs = |
|
352 |
[rtac casedist 1, |
|
353 |
contr_tac 1, |
|
354 |
DETERM_UNTIL_SOLVED (CHANGED |
|
355 |
(asm_simp_tac (HOLCF_ss addsimps dis_apps) 1))]; |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
356 |
in pg [] goal (K tacs) end; |
23152 | 357 |
|
29402 | 358 |
val _ = trace " Proving dis_stricts..."; |
23152 | 359 |
val dis_stricts = map dis_strict cons; |
29402 | 360 |
val _ = trace " Proving dis_defins..."; |
23152 | 361 |
val dis_defins = map dis_defin cons; |
362 |
in |
|
363 |
val dis_rews = dis_stricts @ dis_defins @ dis_apps; |
|
364 |
end; |
|
365 |
||
366 |
local |
|
35288 | 367 |
fun mat_strict (con, _, _) = |
23152 | 368 |
let |
30912
4022298c1a86
change definition of match combinators for fixrec package
huffman
parents:
30911
diff
changeset
|
369 |
val goal = mk_trp (%%:(mat_name con) ` UU ` %:"rhs" === UU); |
4022298c1a86
change definition of match combinators for fixrec package
huffman
parents:
30911
diff
changeset
|
370 |
val tacs = [asm_simp_tac (HOLCF_ss addsimps [when_strict]) 1]; |
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
371 |
in pg axs_mat_def goal (K tacs) end; |
23152 | 372 |
|
29402 | 373 |
val _ = trace " Proving mat_stricts..."; |
23152 | 374 |
val mat_stricts = map mat_strict cons; |
375 |
||
35288 | 376 |
fun one_mat c (con, _, args) = |
23152 | 377 |
let |
30912
4022298c1a86
change definition of match combinators for fixrec package
huffman
parents:
30911
diff
changeset
|
378 |
val lhs = %%:(mat_name c) ` con_app con args ` %:"rhs"; |
23152 | 379 |
val rhs = |
380 |
if con = c |
|
30912
4022298c1a86
change definition of match combinators for fixrec package
huffman
parents:
30911
diff
changeset
|
381 |
then list_ccomb (%:"rhs", map %# args) |
26012 | 382 |
else mk_fail; |
23152 | 383 |
val goal = lift_defined %: (nonlazy args, mk_trp (lhs === rhs)); |
384 |
val tacs = [asm_simp_tac (HOLCF_ss addsimps when_rews) 1]; |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
385 |
in pg axs_mat_def goal (K tacs) end; |
23152 | 386 |
|
29402 | 387 |
val _ = trace " Proving mat_apps..."; |
23152 | 388 |
val mat_apps = |
35288 | 389 |
maps (fn (c,_,_) => map (one_mat c) cons) cons; |
23152 | 390 |
in |
391 |
val mat_rews = mat_stricts @ mat_apps; |
|
392 |
end; |
|
393 |
||
394 |
local |
|
395 |
fun ps args = mapn (fn n => fn _ => %:("pat" ^ string_of_int n)) 1 args; |
|
396 |
||
35288 | 397 |
fun pat_lhs (con,_,args) = mk_branch (list_comb (%%:(pat_name con), ps args)); |
23152 | 398 |
|
35288 | 399 |
fun pat_rhs (con,_,[]) = mk_return ((%:"rhs") ` HOLogic.unit) |
400 |
| pat_rhs (con,_,args) = |
|
26012 | 401 |
(mk_branch (mk_ctuple_pat (ps args))) |
23152 | 402 |
`(%:"rhs")`(mk_ctuple (map %# args)); |
403 |
||
404 |
fun pat_strict c = |
|
405 |
let |
|
25132 | 406 |
val axs = @{thm branch_def} :: axs_pat_def; |
23152 | 407 |
val goal = mk_trp (strict (pat_lhs c ` (%:"rhs"))); |
408 |
val tacs = [simp_tac (HOLCF_ss addsimps [when_strict]) 1]; |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
409 |
in pg axs goal (K tacs) end; |
23152 | 410 |
|
35288 | 411 |
fun pat_app c (con, _, args) = |
23152 | 412 |
let |
25132 | 413 |
val axs = @{thm branch_def} :: axs_pat_def; |
23152 | 414 |
val lhs = (pat_lhs c)`(%:"rhs")`(con_app con args); |
35288 | 415 |
val rhs = if con = first c then pat_rhs c else mk_fail; |
23152 | 416 |
val goal = lift_defined %: (nonlazy args, mk_trp (lhs === rhs)); |
417 |
val tacs = [asm_simp_tac (HOLCF_ss addsimps when_rews) 1]; |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
418 |
in pg axs goal (K tacs) end; |
23152 | 419 |
|
29402 | 420 |
val _ = trace " Proving pat_stricts..."; |
23152 | 421 |
val pat_stricts = map pat_strict cons; |
29402 | 422 |
val _ = trace " Proving pat_apps..."; |
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26012
diff
changeset
|
423 |
val pat_apps = maps (fn c => map (pat_app c) cons) cons; |
23152 | 424 |
in |
425 |
val pat_rews = pat_stricts @ pat_apps; |
|
426 |
end; |
|
427 |
||
428 |
local |
|
35288 | 429 |
fun con_strict (con, _, args) = |
23152 | 430 |
let |
30911
7809cbaa1b61
domain package: simplify internal proofs of con_rews
huffman
parents:
30829
diff
changeset
|
431 |
val rules = abs_strict :: @{thms con_strict_rules}; |
23152 | 432 |
fun one_strict vn = |
433 |
let |
|
434 |
fun f arg = if vname arg = vn then UU else %# arg; |
|
435 |
val goal = mk_trp (con_app2 con f args === UU); |
|
30911
7809cbaa1b61
domain package: simplify internal proofs of con_rews
huffman
parents:
30829
diff
changeset
|
436 |
val tacs = [simp_tac (HOL_basic_ss addsimps rules) 1]; |
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
437 |
in pg con_appls goal (K tacs) end; |
23152 | 438 |
in map one_strict (nonlazy args) end; |
439 |
||
35288 | 440 |
fun con_defin (con, _, args) = |
23152 | 441 |
let |
30913
10b26965a08f
domain package now generates iff rules for definedness of constructors
huffman
parents:
30912
diff
changeset
|
442 |
fun iff_disj (t, []) = HOLogic.mk_not t |
10b26965a08f
domain package now generates iff rules for definedness of constructors
huffman
parents:
30912
diff
changeset
|
443 |
| iff_disj (t, ts) = t === foldr1 HOLogic.mk_disj ts; |
10b26965a08f
domain package now generates iff rules for definedness of constructors
huffman
parents:
30912
diff
changeset
|
444 |
val lhs = con_app con args === UU; |
10b26965a08f
domain package now generates iff rules for definedness of constructors
huffman
parents:
30912
diff
changeset
|
445 |
val rhss = map (fn x => %:x === UU) (nonlazy args); |
10b26965a08f
domain package now generates iff rules for definedness of constructors
huffman
parents:
30912
diff
changeset
|
446 |
val goal = mk_trp (iff_disj (lhs, rhss)); |
10b26965a08f
domain package now generates iff rules for definedness of constructors
huffman
parents:
30912
diff
changeset
|
447 |
val rule1 = iso_locale RS @{thm iso.abs_defined_iff}; |
10b26965a08f
domain package now generates iff rules for definedness of constructors
huffman
parents:
30912
diff
changeset
|
448 |
val rules = rule1 :: @{thms con_defined_iff_rules}; |
10b26965a08f
domain package now generates iff rules for definedness of constructors
huffman
parents:
30912
diff
changeset
|
449 |
val tacs = [simp_tac (HOL_ss addsimps rules) 1]; |
30911
7809cbaa1b61
domain package: simplify internal proofs of con_rews
huffman
parents:
30829
diff
changeset
|
450 |
in pg con_appls goal (K tacs) end; |
23152 | 451 |
in |
29402 | 452 |
val _ = trace " Proving con_stricts..."; |
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26012
diff
changeset
|
453 |
val con_stricts = maps con_strict cons; |
30911
7809cbaa1b61
domain package: simplify internal proofs of con_rews
huffman
parents:
30829
diff
changeset
|
454 |
val _ = trace " Proving con_defins..."; |
23152 | 455 |
val con_defins = map con_defin cons; |
456 |
val con_rews = con_stricts @ con_defins; |
|
457 |
end; |
|
458 |
||
459 |
local |
|
460 |
val rules = |
|
461 |
[compact_sinl, compact_sinr, compact_spair, compact_up, compact_ONE]; |
|
35288 | 462 |
fun con_compact (con, _, args) = |
23152 | 463 |
let |
26012 | 464 |
val concl = mk_trp (mk_compact (con_app con args)); |
465 |
val goal = lift (fn x => mk_compact (%#x)) (args, concl); |
|
23152 | 466 |
val tacs = [ |
467 |
rtac (iso_locale RS iso_compact_abs) 1, |
|
468 |
REPEAT (resolve_tac rules 1 ORELSE atac 1)]; |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
469 |
in pg con_appls goal (K tacs) end; |
23152 | 470 |
in |
29402 | 471 |
val _ = trace " Proving con_compacts..."; |
23152 | 472 |
val con_compacts = map con_compact cons; |
473 |
end; |
|
474 |
||
475 |
local |
|
476 |
fun one_sel sel = |
|
477 |
pg axs_sel_def (mk_trp (strict (%%:sel))) |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
478 |
(K [simp_tac (HOLCF_ss addsimps when_rews) 1]); |
23152 | 479 |
|
35288 | 480 |
fun sel_strict (_, _, args) = |
32952 | 481 |
map_filter (Option.map one_sel o sel_of) args; |
23152 | 482 |
in |
29402 | 483 |
val _ = trace " Proving sel_stricts..."; |
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26012
diff
changeset
|
484 |
val sel_stricts = maps sel_strict cons; |
23152 | 485 |
end; |
486 |
||
487 |
local |
|
488 |
fun sel_app_same c n sel (con, args) = |
|
489 |
let |
|
490 |
val nlas = nonlazy args; |
|
491 |
val vns = map vname args; |
|
492 |
val vnn = List.nth (vns, n); |
|
33317 | 493 |
val nlas' = filter (fn v => v <> vnn) nlas; |
23152 | 494 |
val lhs = (%%:sel)`(con_app con args); |
495 |
val goal = lift_defined %: (nlas', mk_trp (lhs === %:vnn)); |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
496 |
fun tacs1 ctxt = |
23152 | 497 |
if vnn mem nlas |
35443
2e0f9516947e
change domain package's treatment of variable names in theorems to be like datatype package
huffman
parents:
35288
diff
changeset
|
498 |
(* FIXME! case_UU_tac *) |
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
499 |
then [case_UU_tac ctxt (when_rews @ con_stricts) 1 vnn] |
23152 | 500 |
else []; |
501 |
val tacs2 = [asm_simp_tac (HOLCF_ss addsimps when_rews) 1]; |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
502 |
in pg axs_sel_def goal (fn ctxt => (tacs1 ctxt @ tacs2)) end; |
23152 | 503 |
|
504 |
fun sel_app_diff c n sel (con, args) = |
|
505 |
let |
|
506 |
val nlas = nonlazy args; |
|
507 |
val goal = mk_trp (%%:sel ` con_app con args === UU); |
|
35443
2e0f9516947e
change domain package's treatment of variable names in theorems to be like datatype package
huffman
parents:
35288
diff
changeset
|
508 |
(* FIXME! case_UU_tac *) |
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
509 |
fun tacs1 ctxt = map (case_UU_tac ctxt (when_rews @ con_stricts) 1) nlas; |
23152 | 510 |
val tacs2 = [asm_simp_tac (HOLCF_ss addsimps when_rews) 1]; |
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
511 |
in pg axs_sel_def goal (fn ctxt => (tacs1 ctxt @ tacs2)) end; |
23152 | 512 |
|
35288 | 513 |
fun sel_app c n sel (con, _, args) = |
23152 | 514 |
if con = c |
515 |
then sel_app_same c n sel (con, args) |
|
516 |
else sel_app_diff c n sel (con, args); |
|
517 |
||
518 |
fun one_sel c n sel = map (sel_app c n sel) cons; |
|
519 |
fun one_sel' c n arg = Option.map (one_sel c n) (sel_of arg); |
|
35288 | 520 |
fun one_con (c, _, args) = |
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26012
diff
changeset
|
521 |
flat (map_filter I (mapn (one_sel' c) 0 args)); |
23152 | 522 |
in |
29402 | 523 |
val _ = trace " Proving sel_apps..."; |
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26012
diff
changeset
|
524 |
val sel_apps = maps one_con cons; |
23152 | 525 |
end; |
526 |
||
527 |
local |
|
528 |
fun sel_defin sel = |
|
529 |
let |
|
530 |
val goal = defined (%:x_name) ==> defined (%%:sel`%x_name); |
|
531 |
val tacs = [ |
|
532 |
rtac casedist 1, |
|
533 |
contr_tac 1, |
|
534 |
DETERM_UNTIL_SOLVED (CHANGED |
|
535 |
(asm_simp_tac (HOLCF_ss addsimps sel_apps) 1))]; |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
536 |
in pg [] goal (K tacs) end; |
23152 | 537 |
in |
29402 | 538 |
val _ = trace " Proving sel_defins..."; |
23152 | 539 |
val sel_defins = |
540 |
if length cons = 1 |
|
32952 | 541 |
then map_filter (fn arg => Option.map sel_defin (sel_of arg)) |
35288 | 542 |
(filter_out is_lazy (third (hd cons))) |
23152 | 543 |
else []; |
544 |
end; |
|
545 |
||
546 |
val sel_rews = sel_stricts @ sel_defins @ sel_apps; |
|
547 |
||
29402 | 548 |
val _ = trace " Proving dist_les..."; |
35117
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
549 |
val dist_les = |
23152 | 550 |
let |
551 |
fun dist (con1, args1) (con2, args2) = |
|
552 |
let |
|
35117
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
553 |
fun iff_disj (t, []) = HOLogic.mk_not t |
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
554 |
| iff_disj (t, ts) = t === foldr1 HOLogic.mk_disj ts; |
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
555 |
val lhs = con_app con1 args1 << con_app con2 args2; |
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
556 |
val rhss = map (fn x => %:x === UU) (nonlazy args1); |
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
557 |
val goal = mk_trp (iff_disj (lhs, rhss)); |
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
558 |
val rule1 = iso_locale RS @{thm iso.abs_below}; |
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
559 |
val rules = rule1 :: @{thms con_below_iff_rules}; |
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
560 |
val tacs = [simp_tac (HOL_ss addsimps rules) 1]; |
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
561 |
in pg con_appls goal (K tacs) end; |
23152 | 562 |
|
35288 | 563 |
fun distinct (con1, _, args1) (con2, _, args2) = |
23152 | 564 |
let |
565 |
val arg1 = (con1, args1); |
|
566 |
val arg2 = |
|
567 |
(con2, ListPair.map (fn (arg,vn) => upd_vname (K vn) arg) |
|
568 |
(args2, Name.variant_list (map vname args1) (map vname args2))); |
|
569 |
in [dist arg1 arg2, dist arg2 arg1] end; |
|
570 |
fun distincts [] = [] |
|
35117
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
571 |
| distincts (c::cs) = maps (distinct c) cs @ distincts cs; |
23152 | 572 |
in distincts cons end; |
29402 | 573 |
|
574 |
val _ = trace " Proving dist_eqs..."; |
|
23152 | 575 |
val dist_eqs = |
576 |
let |
|
35117
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
577 |
fun dist (con1, args1) (con2, args2) = |
23152 | 578 |
let |
35117
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
579 |
fun iff_disj (t, [], us) = HOLogic.mk_not t |
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
580 |
| iff_disj (t, ts, []) = HOLogic.mk_not t |
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
581 |
| iff_disj (t, ts, us) = |
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
582 |
let |
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
583 |
val disj1 = foldr1 HOLogic.mk_disj ts; |
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
584 |
val disj2 = foldr1 HOLogic.mk_disj us; |
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
585 |
in t === HOLogic.mk_conj (disj1, disj2) end; |
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
586 |
val lhs = con_app con1 args1 === con_app con2 args2; |
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
587 |
val rhss1 = map (fn x => %:x === UU) (nonlazy args1); |
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
588 |
val rhss2 = map (fn x => %:x === UU) (nonlazy args2); |
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
589 |
val goal = mk_trp (iff_disj (lhs, rhss1, rhss2)); |
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
590 |
val rule1 = iso_locale RS @{thm iso.abs_eq}; |
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
591 |
val rules = rule1 :: @{thms con_eq_iff_rules}; |
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
592 |
val tacs = [simp_tac (HOL_ss addsimps rules) 1]; |
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
593 |
in pg con_appls goal (K tacs) end; |
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
594 |
|
35288 | 595 |
fun distinct (con1, _, args1) (con2, _, args2) = |
35117
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
596 |
let |
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
597 |
val arg1 = (con1, args1); |
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
598 |
val arg2 = |
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
599 |
(con2, ListPair.map (fn (arg,vn) => upd_vname (K vn) arg) |
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
600 |
(args2, Name.variant_list (map vname args1) (map vname args2))); |
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
601 |
in [dist arg1 arg2, dist arg2 arg1] end; |
23152 | 602 |
fun distincts [] = [] |
35117
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
603 |
| distincts (c::cs) = maps (distinct c) cs @ distincts cs; |
eeec2a320a77
change generated lemmas dist_eqs and dist_les to iff-style
huffman
parents:
35060
diff
changeset
|
604 |
in distincts cons end; |
23152 | 605 |
|
606 |
local |
|
607 |
fun pgterm rel con args = |
|
608 |
let |
|
609 |
fun append s = upd_vname (fn v => v^s); |
|
610 |
val (largs, rargs) = (args, map (append "'") args); |
|
611 |
val concl = |
|
612 |
foldr1 mk_conj (ListPair.map rel (map %# largs, map %# rargs)); |
|
613 |
val prem = rel (con_app con largs, con_app con rargs); |
|
614 |
val sargs = case largs of [_] => [] | _ => nonlazy args; |
|
615 |
val prop = lift_defined %: (sargs, mk_trp (prem === concl)); |
|
616 |
in pg con_appls prop end; |
|
35288 | 617 |
val cons' = filter (fn (_, _, args) => args<>[]) cons; |
23152 | 618 |
in |
29402 | 619 |
val _ = trace " Proving inverts..."; |
23152 | 620 |
val inverts = |
621 |
let |
|
622 |
val abs_less = ax_abs_iso RS (allI RS injection_less); |
|
623 |
val tacs = |
|
624 |
[asm_full_simp_tac (HOLCF_ss addsimps [abs_less, spair_less]) 1]; |
|
35288 | 625 |
in map (fn (con, _, args) => pgterm (op <<) con args (K tacs)) cons' end; |
23152 | 626 |
|
29402 | 627 |
val _ = trace " Proving injects..."; |
23152 | 628 |
val injects = |
629 |
let |
|
630 |
val abs_eq = ax_abs_iso RS (allI RS injection_eq); |
|
631 |
val tacs = [asm_full_simp_tac (HOLCF_ss addsimps [abs_eq, spair_eq]) 1]; |
|
35288 | 632 |
in map (fn (con, _, args) => pgterm (op ===) con args (K tacs)) cons' end; |
23152 | 633 |
end; |
634 |
||
635 |
(* ----- theorems concerning one induction step ----------------------------- *) |
|
636 |
||
637 |
val copy_strict = |
|
638 |
let |
|
31232
689aa7da48cc
define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents:
31160
diff
changeset
|
639 |
val _ = trace " Proving copy_strict..."; |
23152 | 640 |
val goal = mk_trp (strict (dc_copy `% "f")); |
33504
b4210cc3ac97
map functions for various types, with ep_pair/deflation/finite_deflation lemmas
huffman
parents:
33427
diff
changeset
|
641 |
val rules = [abs_strict, rep_strict] @ @{thms domain_map_stricts}; |
31232
689aa7da48cc
define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents:
31160
diff
changeset
|
642 |
val tacs = [asm_simp_tac (HOLCF_ss addsimps rules) 1]; |
35058
d0cc1650b378
handle case where copy_stricts cannot be proven; rewrite proof script for take_apps
huffman
parents:
35057
diff
changeset
|
643 |
in |
d0cc1650b378
handle case where copy_stricts cannot be proven; rewrite proof script for take_apps
huffman
parents:
35057
diff
changeset
|
644 |
SOME (pg [ax_copy_def] goal (K tacs)) |
d0cc1650b378
handle case where copy_stricts cannot be proven; rewrite proof script for take_apps
huffman
parents:
35057
diff
changeset
|
645 |
handle |
d0cc1650b378
handle case where copy_stricts cannot be proven; rewrite proof script for take_apps
huffman
parents:
35057
diff
changeset
|
646 |
THM (s, _, _) => (trace s; NONE) |
d0cc1650b378
handle case where copy_stricts cannot be proven; rewrite proof script for take_apps
huffman
parents:
35057
diff
changeset
|
647 |
| ERROR s => (trace s; NONE) |
d0cc1650b378
handle case where copy_stricts cannot be proven; rewrite proof script for take_apps
huffman
parents:
35057
diff
changeset
|
648 |
end; |
23152 | 649 |
|
650 |
local |
|
35288 | 651 |
fun copy_app (con, _, args) = |
23152 | 652 |
let |
653 |
val lhs = dc_copy`%"f"`(con_app con args); |
|
31232
689aa7da48cc
define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents:
31160
diff
changeset
|
654 |
fun one_rhs arg = |
33971 | 655 |
if Datatype_Aux.is_rec_type (dtyp_of arg) |
33801 | 656 |
then Domain_Axioms.copy_of_dtyp map_tab |
657 |
(proj (%:"f") eqs) (dtyp_of arg) ` (%# arg) |
|
31232
689aa7da48cc
define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents:
31160
diff
changeset
|
658 |
else (%# arg); |
689aa7da48cc
define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents:
31160
diff
changeset
|
659 |
val rhs = con_app2 con one_rhs args; |
35059
acbc346e5310
correct definedness side conditions for copy_apps and take_apps
huffman
parents:
35058
diff
changeset
|
660 |
fun is_rec arg = Datatype_Aux.is_rec_type (dtyp_of arg); |
acbc346e5310
correct definedness side conditions for copy_apps and take_apps
huffman
parents:
35058
diff
changeset
|
661 |
fun is_nonlazy_rec arg = is_rec arg andalso not (is_lazy arg); |
acbc346e5310
correct definedness side conditions for copy_apps and take_apps
huffman
parents:
35058
diff
changeset
|
662 |
fun nonlazy_rec args = map vname (filter is_nonlazy_rec args); |
23152 | 663 |
val goal = lift_defined %: (nonlazy_rec args, mk_trp (lhs === rhs)); |
33317 | 664 |
val args' = filter_out (fn a => is_rec a orelse is_lazy a) args; |
33504
b4210cc3ac97
map functions for various types, with ep_pair/deflation/finite_deflation lemmas
huffman
parents:
33427
diff
changeset
|
665 |
val stricts = abs_strict :: rep_strict :: @{thms domain_map_stricts}; |
35443
2e0f9516947e
change domain package's treatment of variable names in theorems to be like datatype package
huffman
parents:
35288
diff
changeset
|
666 |
(* FIXME! case_UU_tac *) |
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
667 |
fun tacs1 ctxt = map (case_UU_tac ctxt stricts 1 o vname) args'; |
33504
b4210cc3ac97
map functions for various types, with ep_pair/deflation/finite_deflation lemmas
huffman
parents:
33427
diff
changeset
|
668 |
val rules = [ax_abs_iso] @ @{thms domain_map_simps}; |
31232
689aa7da48cc
define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents:
31160
diff
changeset
|
669 |
val tacs2 = [asm_simp_tac (HOLCF_ss addsimps rules) 1]; |
689aa7da48cc
define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents:
31160
diff
changeset
|
670 |
in pg (ax_copy_def::con_appls) goal (fn ctxt => (tacs1 ctxt @ tacs2)) end; |
23152 | 671 |
in |
29402 | 672 |
val _ = trace " Proving copy_apps..."; |
23152 | 673 |
val copy_apps = map copy_app cons; |
674 |
end; |
|
675 |
||
676 |
local |
|
35288 | 677 |
fun one_strict (con, _, args) = |
23152 | 678 |
let |
679 |
val goal = mk_trp (dc_copy`UU`(con_app con args) === UU); |
|
35058
d0cc1650b378
handle case where copy_stricts cannot be proven; rewrite proof script for take_apps
huffman
parents:
35057
diff
changeset
|
680 |
val rews = the_list copy_strict @ copy_apps @ con_rews; |
35443
2e0f9516947e
change domain package's treatment of variable names in theorems to be like datatype package
huffman
parents:
35288
diff
changeset
|
681 |
(* FIXME! case_UU_tac *) |
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
682 |
fun tacs ctxt = map (case_UU_tac ctxt rews 1) (nonlazy args) @ |
23152 | 683 |
[asm_simp_tac (HOLCF_ss addsimps rews) 1]; |
35058
d0cc1650b378
handle case where copy_stricts cannot be proven; rewrite proof script for take_apps
huffman
parents:
35057
diff
changeset
|
684 |
in |
d0cc1650b378
handle case where copy_stricts cannot be proven; rewrite proof script for take_apps
huffman
parents:
35057
diff
changeset
|
685 |
SOME (pg [] goal tacs) |
d0cc1650b378
handle case where copy_stricts cannot be proven; rewrite proof script for take_apps
huffman
parents:
35057
diff
changeset
|
686 |
handle |
d0cc1650b378
handle case where copy_stricts cannot be proven; rewrite proof script for take_apps
huffman
parents:
35057
diff
changeset
|
687 |
THM (s, _, _) => (trace s; NONE) |
d0cc1650b378
handle case where copy_stricts cannot be proven; rewrite proof script for take_apps
huffman
parents:
35057
diff
changeset
|
688 |
| ERROR s => (trace s; NONE) |
d0cc1650b378
handle case where copy_stricts cannot be proven; rewrite proof script for take_apps
huffman
parents:
35057
diff
changeset
|
689 |
end; |
23152 | 690 |
|
35288 | 691 |
fun has_nonlazy_rec (_, _, args) = exists is_nonlazy_rec args; |
23152 | 692 |
in |
29402 | 693 |
val _ = trace " Proving copy_stricts..."; |
35058
d0cc1650b378
handle case where copy_stricts cannot be proven; rewrite proof script for take_apps
huffman
parents:
35057
diff
changeset
|
694 |
val copy_stricts = map_filter one_strict (filter has_nonlazy_rec cons); |
23152 | 695 |
end; |
696 |
||
35058
d0cc1650b378
handle case where copy_stricts cannot be proven; rewrite proof script for take_apps
huffman
parents:
35057
diff
changeset
|
697 |
val copy_rews = the_list copy_strict @ copy_apps @ copy_stricts; |
23152 | 698 |
|
699 |
in |
|
700 |
thy |
|
30364
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents:
30280
diff
changeset
|
701 |
|> Sign.add_path (Long_Name.base_name dname) |
31004 | 702 |
|> snd o PureThy.add_thmss [ |
703 |
((Binding.name "iso_rews" , iso_rews ), [Simplifier.simp_add]), |
|
704 |
((Binding.name "exhaust" , [exhaust] ), []), |
|
705 |
((Binding.name "casedist" , [casedist] ), [Induct.cases_type dname]), |
|
706 |
((Binding.name "when_rews" , when_rews ), [Simplifier.simp_add]), |
|
707 |
((Binding.name "compacts" , con_compacts), [Simplifier.simp_add]), |
|
33427 | 708 |
((Binding.name "con_rews" , con_rews ), |
709 |
[Simplifier.simp_add, Fixrec.fixrec_simp_add]), |
|
31004 | 710 |
((Binding.name "sel_rews" , sel_rews ), [Simplifier.simp_add]), |
711 |
((Binding.name "dis_rews" , dis_rews ), [Simplifier.simp_add]), |
|
712 |
((Binding.name "pat_rews" , pat_rews ), [Simplifier.simp_add]), |
|
713 |
((Binding.name "dist_les" , dist_les ), [Simplifier.simp_add]), |
|
714 |
((Binding.name "dist_eqs" , dist_eqs ), [Simplifier.simp_add]), |
|
715 |
((Binding.name "inverts" , inverts ), [Simplifier.simp_add]), |
|
716 |
((Binding.name "injects" , injects ), [Simplifier.simp_add]), |
|
717 |
((Binding.name "copy_rews" , copy_rews ), [Simplifier.simp_add]), |
|
33427 | 718 |
((Binding.name "match_rews", mat_rews ), |
719 |
[Simplifier.simp_add, Fixrec.fixrec_simp_add])] |
|
24712
64ed05609568
proper Sign operations instead of Theory aliases;
wenzelm
parents:
24503
diff
changeset
|
720 |
|> Sign.parent_path |
28536 | 721 |
|> pair (iso_rews @ when_rews @ con_rews @ sel_rews @ dis_rews @ |
23152 | 722 |
pat_rews @ dist_les @ dist_eqs @ copy_rews) |
723 |
end; (* let *) |
|
724 |
||
725 |
fun comp_theorems (comp_dnam, eqs: eq list) thy = |
|
726 |
let |
|
27232 | 727 |
val global_ctxt = ProofContext.init thy; |
33801 | 728 |
val map_tab = Domain_Isomorphism.get_map_tab thy; |
27232 | 729 |
|
23152 | 730 |
val dnames = map (fst o fst) eqs; |
731 |
val conss = map snd eqs; |
|
28965 | 732 |
val comp_dname = Sign.full_bname thy comp_dnam; |
23152 | 733 |
|
29402 | 734 |
val _ = message ("Proving induction properties of domain "^comp_dname^" ..."); |
23152 | 735 |
val pg = pg' thy; |
736 |
||
737 |
(* ----- getting the composite axiom and definitions ------------------------ *) |
|
738 |
||
739 |
local |
|
26343
0dd2eab7b296
simplified get_thm(s): back to plain name argument;
wenzelm
parents:
26342
diff
changeset
|
740 |
fun ga s dn = PureThy.get_thm thy (dn ^ "." ^ s); |
23152 | 741 |
in |
742 |
val axs_reach = map (ga "reach" ) dnames; |
|
743 |
val axs_take_def = map (ga "take_def" ) dnames; |
|
744 |
val axs_finite_def = map (ga "finite_def") dnames; |
|
745 |
val ax_copy2_def = ga "copy_def" comp_dnam; |
|
35444 | 746 |
(* TEMPORARILY DISABLED |
23152 | 747 |
val ax_bisim_def = ga "bisim_def" comp_dnam; |
35444 | 748 |
TEMPORARILY DISABLED *) |
23152 | 749 |
end; |
750 |
||
751 |
local |
|
26343
0dd2eab7b296
simplified get_thm(s): back to plain name argument;
wenzelm
parents:
26342
diff
changeset
|
752 |
fun gt s dn = PureThy.get_thm thy (dn ^ "." ^ s); |
0dd2eab7b296
simplified get_thm(s): back to plain name argument;
wenzelm
parents:
26342
diff
changeset
|
753 |
fun gts s dn = PureThy.get_thms thy (dn ^ "." ^ s); |
23152 | 754 |
in |
755 |
val cases = map (gt "casedist" ) dnames; |
|
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26012
diff
changeset
|
756 |
val con_rews = maps (gts "con_rews" ) dnames; |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26012
diff
changeset
|
757 |
val copy_rews = maps (gts "copy_rews") dnames; |
23152 | 758 |
end; |
759 |
||
760 |
fun dc_take dn = %%:(dn^"_take"); |
|
761 |
val x_name = idx_name dnames "x"; |
|
762 |
val P_name = idx_name dnames "P"; |
|
763 |
val n_eqs = length eqs; |
|
764 |
||
765 |
(* ----- theorems concerning finite approximation and finite induction ------ *) |
|
766 |
||
767 |
local |
|
32149
ef59550a55d3
renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
wenzelm
parents:
32126
diff
changeset
|
768 |
val iterate_Cprod_ss = global_simpset_of @{theory Fix}; |
23152 | 769 |
val copy_con_rews = copy_rews @ con_rews; |
770 |
val copy_take_defs = |
|
771 |
(if n_eqs = 1 then [] else [ax_copy2_def]) @ axs_take_def; |
|
29402 | 772 |
val _ = trace " Proving take_stricts..."; |
35057 | 773 |
fun one_take_strict ((dn, args), _) = |
23152 | 774 |
let |
35057 | 775 |
val goal = mk_trp (strict (dc_take dn $ %:"n")); |
776 |
val rules = [ |
|
777 |
@{thm monofun_fst [THEN monofunE]}, |
|
778 |
@{thm monofun_snd [THEN monofunE]}]; |
|
779 |
val tacs = [ |
|
780 |
rtac @{thm UU_I} 1, |
|
781 |
rtac @{thm below_eq_trans} 1, |
|
782 |
resolve_tac axs_reach 2, |
|
783 |
rtac @{thm monofun_cfun_fun} 1, |
|
784 |
REPEAT (resolve_tac rules 1), |
|
785 |
rtac @{thm iterate_below_fix} 1]; |
|
786 |
in pg axs_take_def goal (K tacs) end; |
|
787 |
val take_stricts = map one_take_strict eqs; |
|
23152 | 788 |
fun take_0 n dn = |
789 |
let |
|
35058
d0cc1650b378
handle case where copy_stricts cannot be proven; rewrite proof script for take_apps
huffman
parents:
35057
diff
changeset
|
790 |
val goal = mk_trp ((dc_take dn $ @{term "0::nat"}) `% x_name n === UU); |
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
791 |
in pg axs_take_def goal (K [simp_tac iterate_Cprod_ss 1]) end; |
23152 | 792 |
val take_0s = mapn take_0 1 dnames; |
29402 | 793 |
val _ = trace " Proving take_apps..."; |
35288 | 794 |
fun one_take_app dn (con, _, args) = |
23152 | 795 |
let |
35058
d0cc1650b378
handle case where copy_stricts cannot be proven; rewrite proof script for take_apps
huffman
parents:
35057
diff
changeset
|
796 |
fun mk_take n = dc_take (List.nth (dnames, n)) $ %:"n"; |
d0cc1650b378
handle case where copy_stricts cannot be proven; rewrite proof script for take_apps
huffman
parents:
35057
diff
changeset
|
797 |
fun one_rhs arg = |
d0cc1650b378
handle case where copy_stricts cannot be proven; rewrite proof script for take_apps
huffman
parents:
35057
diff
changeset
|
798 |
if Datatype_Aux.is_rec_type (dtyp_of arg) |
d0cc1650b378
handle case where copy_stricts cannot be proven; rewrite proof script for take_apps
huffman
parents:
35057
diff
changeset
|
799 |
then Domain_Axioms.copy_of_dtyp map_tab |
d0cc1650b378
handle case where copy_stricts cannot be proven; rewrite proof script for take_apps
huffman
parents:
35057
diff
changeset
|
800 |
mk_take (dtyp_of arg) ` (%# arg) |
d0cc1650b378
handle case where copy_stricts cannot be proven; rewrite proof script for take_apps
huffman
parents:
35057
diff
changeset
|
801 |
else (%# arg); |
d0cc1650b378
handle case where copy_stricts cannot be proven; rewrite proof script for take_apps
huffman
parents:
35057
diff
changeset
|
802 |
val lhs = (dc_take dn $ (%%:"Suc" $ %:"n"))`(con_app con args); |
d0cc1650b378
handle case where copy_stricts cannot be proven; rewrite proof script for take_apps
huffman
parents:
35057
diff
changeset
|
803 |
val rhs = con_app2 con one_rhs args; |
35059
acbc346e5310
correct definedness side conditions for copy_apps and take_apps
huffman
parents:
35058
diff
changeset
|
804 |
fun is_rec arg = Datatype_Aux.is_rec_type (dtyp_of arg); |
acbc346e5310
correct definedness side conditions for copy_apps and take_apps
huffman
parents:
35058
diff
changeset
|
805 |
fun is_nonlazy_rec arg = is_rec arg andalso not (is_lazy arg); |
acbc346e5310
correct definedness side conditions for copy_apps and take_apps
huffman
parents:
35058
diff
changeset
|
806 |
fun nonlazy_rec args = map vname (filter is_nonlazy_rec args); |
acbc346e5310
correct definedness side conditions for copy_apps and take_apps
huffman
parents:
35058
diff
changeset
|
807 |
val goal = lift_defined %: (nonlazy_rec args, mk_trp (lhs === rhs)); |
acbc346e5310
correct definedness side conditions for copy_apps and take_apps
huffman
parents:
35058
diff
changeset
|
808 |
val tacs = [asm_simp_tac (HOLCF_ss addsimps copy_con_rews) 1]; |
acbc346e5310
correct definedness side conditions for copy_apps and take_apps
huffman
parents:
35058
diff
changeset
|
809 |
in pg copy_take_defs goal (K tacs) end; |
35058
d0cc1650b378
handle case where copy_stricts cannot be proven; rewrite proof script for take_apps
huffman
parents:
35057
diff
changeset
|
810 |
fun one_take_apps ((dn, _), cons) = map (one_take_app dn) cons; |
d0cc1650b378
handle case where copy_stricts cannot be proven; rewrite proof script for take_apps
huffman
parents:
35057
diff
changeset
|
811 |
val take_apps = maps one_take_apps eqs; |
23152 | 812 |
in |
35021
c839a4c670c6
renamed old-style Drule.standard to Drule.export_without_context, to emphasize that this is in no way a standard operation;
wenzelm
parents:
34974
diff
changeset
|
813 |
val take_rews = map Drule.export_without_context |
35058
d0cc1650b378
handle case where copy_stricts cannot be proven; rewrite proof script for take_apps
huffman
parents:
35057
diff
changeset
|
814 |
(take_stricts @ take_0s @ take_apps); |
23152 | 815 |
end; (* local *) |
816 |
||
817 |
local |
|
35288 | 818 |
fun one_con p (con, _, args) = |
23152 | 819 |
let |
35443
2e0f9516947e
change domain package's treatment of variable names in theorems to be like datatype package
huffman
parents:
35288
diff
changeset
|
820 |
val P_names = map P_name (1 upto (length dnames)); |
2e0f9516947e
change domain package's treatment of variable names in theorems to be like datatype package
huffman
parents:
35288
diff
changeset
|
821 |
val vns = Name.variant_list P_names (map vname args); |
2e0f9516947e
change domain package's treatment of variable names in theorems to be like datatype package
huffman
parents:
35288
diff
changeset
|
822 |
val nonlazy_vns = map snd (filter_out (is_lazy o fst) (args ~~ vns)); |
23152 | 823 |
fun ind_hyp arg = %:(P_name (1 + rec_of arg)) $ bound_arg args arg; |
824 |
val t1 = mk_trp (%:p $ con_app2 con (bound_arg args) args); |
|
33317 | 825 |
val t2 = lift ind_hyp (filter is_rec args, t1); |
35443
2e0f9516947e
change domain package's treatment of variable names in theorems to be like datatype package
huffman
parents:
35288
diff
changeset
|
826 |
val t3 = lift_defined (bound_arg vns) (nonlazy_vns, t2); |
2e0f9516947e
change domain package's treatment of variable names in theorems to be like datatype package
huffman
parents:
35288
diff
changeset
|
827 |
in Library.foldr mk_All (vns, t3) end; |
23152 | 828 |
|
829 |
fun one_eq ((p, cons), concl) = |
|
830 |
mk_trp (%:p $ UU) ===> Logic.list_implies (map (one_con p) cons, concl); |
|
831 |
||
832 |
fun ind_term concf = Library.foldr one_eq |
|
833 |
(mapn (fn n => fn x => (P_name n, x)) 1 conss, |
|
834 |
mk_trp (foldr1 mk_conj (mapn concf 1 dnames))); |
|
835 |
val take_ss = HOL_ss addsimps take_rews; |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
836 |
fun quant_tac ctxt i = EVERY |
27239 | 837 |
(mapn (fn n => fn _ => res_inst_tac ctxt [(("x", 0), x_name n)] spec i) 1 dnames); |
23152 | 838 |
|
839 |
fun ind_prems_tac prems = EVERY |
|
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26012
diff
changeset
|
840 |
(maps (fn cons => |
23152 | 841 |
(resolve_tac prems 1 :: |
35288 | 842 |
maps (fn (_,_,args) => |
23152 | 843 |
resolve_tac prems 1 :: |
844 |
map (K(atac 1)) (nonlazy args) @ |
|
33317 | 845 |
map (K(atac 1)) (filter is_rec args)) |
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26012
diff
changeset
|
846 |
cons)) |
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26012
diff
changeset
|
847 |
conss); |
23152 | 848 |
local |
849 |
(* check whether every/exists constructor of the n-th part of the equation: |
|
850 |
it has a possibly indirectly recursive argument that isn't/is possibly |
|
851 |
indirectly lazy *) |
|
852 |
fun rec_to quant nfn rfn ns lazy_rec (n,cons) = quant (exists (fn arg => |
|
853 |
is_rec arg andalso not(rec_of arg mem ns) andalso |
|
854 |
((rec_of arg = n andalso nfn(lazy_rec orelse is_lazy arg)) orelse |
|
855 |
rec_of arg <> n andalso rec_to quant nfn rfn (rec_of arg::ns) |
|
856 |
(lazy_rec orelse is_lazy arg) (n, (List.nth(conss,rec_of arg)))) |
|
35288 | 857 |
) o third) cons; |
23152 | 858 |
fun all_rec_to ns = rec_to forall not all_rec_to ns; |
859 |
fun warn (n,cons) = |
|
860 |
if all_rec_to [] false (n,cons) |
|
861 |
then (warning ("domain "^List.nth(dnames,n)^" is empty!"); true) |
|
862 |
else false; |
|
863 |
fun lazy_rec_to ns = rec_to exists I lazy_rec_to ns; |
|
864 |
||
865 |
in |
|
866 |
val n__eqs = mapn (fn n => fn (_,cons) => (n,cons)) 0 eqs; |
|
867 |
val is_emptys = map warn n__eqs; |
|
868 |
val is_finite = forall (not o lazy_rec_to [] false) n__eqs; |
|
869 |
end; |
|
870 |
in (* local *) |
|
29402 | 871 |
val _ = trace " Proving finite_ind..."; |
23152 | 872 |
val finite_ind = |
873 |
let |
|
874 |
fun concf n dn = %:(P_name n) $ (dc_take dn $ %:"n" `%(x_name n)); |
|
875 |
val goal = ind_term concf; |
|
876 |
||
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
877 |
fun tacf {prems, context} = |
23152 | 878 |
let |
879 |
val tacs1 = [ |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
880 |
quant_tac context 1, |
23152 | 881 |
simp_tac HOL_ss 1, |
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
882 |
InductTacs.induct_tac context [[SOME "n"]] 1, |
23152 | 883 |
simp_tac (take_ss addsimps prems) 1, |
884 |
TRY (safe_tac HOL_cs)]; |
|
885 |
fun arg_tac arg = |
|
35443
2e0f9516947e
change domain package's treatment of variable names in theorems to be like datatype package
huffman
parents:
35288
diff
changeset
|
886 |
(* FIXME! case_UU_tac *) |
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
887 |
case_UU_tac context (prems @ con_rews) 1 |
23152 | 888 |
(List.nth (dnames, rec_of arg) ^ "_take n$" ^ vname arg); |
35288 | 889 |
fun con_tacs (con, _, args) = |
23152 | 890 |
asm_simp_tac take_ss 1 :: |
33317 | 891 |
map arg_tac (filter is_nonlazy_rec args) @ |
23152 | 892 |
[resolve_tac prems 1] @ |
33317 | 893 |
map (K (atac 1)) (nonlazy args) @ |
894 |
map (K (etac spec 1)) (filter is_rec args); |
|
23152 | 895 |
fun cases_tacs (cons, cases) = |
27239 | 896 |
res_inst_tac context [(("x", 0), "x")] cases 1 :: |
23152 | 897 |
asm_simp_tac (take_ss addsimps prems) 1 :: |
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26012
diff
changeset
|
898 |
maps con_tacs cons; |
23152 | 899 |
in |
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26012
diff
changeset
|
900 |
tacs1 @ maps cases_tacs (conss ~~ cases) |
23152 | 901 |
end; |
31232
689aa7da48cc
define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents:
31160
diff
changeset
|
902 |
in pg'' thy [] goal tacf |
689aa7da48cc
define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents:
31160
diff
changeset
|
903 |
handle ERROR _ => (warning "Proof of finite_ind failed."; TrueI) |
689aa7da48cc
define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents:
31160
diff
changeset
|
904 |
end; |
23152 | 905 |
|
29402 | 906 |
val _ = trace " Proving take_lemmas..."; |
23152 | 907 |
val take_lemmas = |
908 |
let |
|
909 |
fun take_lemma n (dn, ax_reach) = |
|
910 |
let |
|
911 |
val lhs = dc_take dn $ Bound 0 `%(x_name n); |
|
912 |
val rhs = dc_take dn $ Bound 0 `%(x_name n^"'"); |
|
913 |
val concl = mk_trp (%:(x_name n) === %:(x_name n^"'")); |
|
914 |
val goal = mk_All ("n", mk_trp (lhs === rhs)) ===> concl; |
|
33396 | 915 |
val rules = [contlub_fst RS contlubE RS ssubst, |
916 |
contlub_snd RS contlubE RS ssubst]; |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
917 |
fun tacf {prems, context} = [ |
27239 | 918 |
res_inst_tac context [(("t", 0), x_name n )] (ax_reach RS subst) 1, |
919 |
res_inst_tac context [(("t", 0), x_name n^"'")] (ax_reach RS subst) 1, |
|
23152 | 920 |
stac fix_def2 1, |
921 |
REPEAT (CHANGED |
|
33396 | 922 |
(resolve_tac rules 1 THEN chain_tac 1)), |
23152 | 923 |
stac contlub_cfun_fun 1, |
924 |
stac contlub_cfun_fun 2, |
|
925 |
rtac lub_equal 3, |
|
926 |
chain_tac 1, |
|
927 |
rtac allI 1, |
|
928 |
resolve_tac prems 1]; |
|
929 |
in pg'' thy axs_take_def goal tacf end; |
|
930 |
in mapn take_lemma 1 (dnames ~~ axs_reach) end; |
|
931 |
||
932 |
(* ----- theorems concerning finiteness and induction ----------------------- *) |
|
933 |
||
29402 | 934 |
val _ = trace " Proving finites, ind..."; |
23152 | 935 |
val (finites, ind) = |
31232
689aa7da48cc
define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents:
31160
diff
changeset
|
936 |
( |
23152 | 937 |
if is_finite |
938 |
then (* finite case *) |
|
939 |
let |
|
940 |
fun take_enough dn = mk_ex ("n",dc_take dn $ Bound 0 ` %:"x" === %:"x"); |
|
941 |
fun dname_lemma dn = |
|
942 |
let |
|
943 |
val prem1 = mk_trp (defined (%:"x")); |
|
944 |
val disj1 = mk_all ("n", dc_take dn $ Bound 0 ` %:"x" === UU); |
|
945 |
val prem2 = mk_trp (mk_disj (disj1, take_enough dn)); |
|
946 |
val concl = mk_trp (take_enough dn); |
|
947 |
val goal = prem1 ===> prem2 ===> concl; |
|
948 |
val tacs = [ |
|
949 |
etac disjE 1, |
|
950 |
etac notE 1, |
|
951 |
resolve_tac take_lemmas 1, |
|
952 |
asm_simp_tac take_ss 1, |
|
953 |
atac 1]; |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
954 |
in pg [] goal (K tacs) end; |
31232
689aa7da48cc
define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents:
31160
diff
changeset
|
955 |
val _ = trace " Proving finite_lemmas1a"; |
23152 | 956 |
val finite_lemmas1a = map dname_lemma dnames; |
957 |
||
31232
689aa7da48cc
define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents:
31160
diff
changeset
|
958 |
val _ = trace " Proving finite_lemma1b"; |
23152 | 959 |
val finite_lemma1b = |
960 |
let |
|
961 |
fun mk_eqn n ((dn, args), _) = |
|
962 |
let |
|
963 |
val disj1 = dc_take dn $ Bound 1 ` Bound 0 === UU; |
|
964 |
val disj2 = dc_take dn $ Bound 1 ` Bound 0 === Bound 0; |
|
965 |
in |
|
966 |
mk_constrainall |
|
967 |
(x_name n, Type (dn,args), mk_disj (disj1, disj2)) |
|
968 |
end; |
|
969 |
val goal = |
|
970 |
mk_trp (mk_all ("n", foldr1 mk_conj (mapn mk_eqn 1 eqs))); |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
971 |
fun arg_tacs ctxt vn = [ |
27239 | 972 |
eres_inst_tac ctxt [(("x", 0), vn)] all_dupE 1, |
23152 | 973 |
etac disjE 1, |
974 |
asm_simp_tac (HOL_ss addsimps con_rews) 1, |
|
975 |
asm_simp_tac take_ss 1]; |
|
35288 | 976 |
fun con_tacs ctxt (con, _, args) = |
23152 | 977 |
asm_simp_tac take_ss 1 :: |
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
978 |
maps (arg_tacs ctxt) (nonlazy_rec args); |
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
979 |
fun foo_tacs ctxt n (cons, cases) = |
23152 | 980 |
simp_tac take_ss 1 :: |
981 |
rtac allI 1 :: |
|
27239 | 982 |
res_inst_tac ctxt [(("x", 0), x_name n)] cases 1 :: |
23152 | 983 |
asm_simp_tac take_ss 1 :: |
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
984 |
maps (con_tacs ctxt) cons; |
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
985 |
fun tacs ctxt = |
23152 | 986 |
rtac allI 1 :: |
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
987 |
InductTacs.induct_tac ctxt [[SOME "n"]] 1 :: |
23152 | 988 |
simp_tac take_ss 1 :: |
989 |
TRY (safe_tac (empty_cs addSEs [conjE] addSIs [conjI])) :: |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
990 |
flat (mapn (foo_tacs ctxt) 1 (conss ~~ cases)); |
23152 | 991 |
in pg [] goal tacs end; |
992 |
||
993 |
fun one_finite (dn, l1b) = |
|
994 |
let |
|
995 |
val goal = mk_trp (%%:(dn^"_finite") $ %:"x"); |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
996 |
fun tacs ctxt = [ |
35443
2e0f9516947e
change domain package's treatment of variable names in theorems to be like datatype package
huffman
parents:
35288
diff
changeset
|
997 |
(* FIXME! case_UU_tac *) |
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
998 |
case_UU_tac ctxt take_rews 1 "x", |
23152 | 999 |
eresolve_tac finite_lemmas1a 1, |
1000 |
step_tac HOL_cs 1, |
|
1001 |
step_tac HOL_cs 1, |
|
1002 |
cut_facts_tac [l1b] 1, |
|
1003 |
fast_tac HOL_cs 1]; |
|
1004 |
in pg axs_finite_def goal tacs end; |
|
1005 |
||
31232
689aa7da48cc
define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents:
31160
diff
changeset
|
1006 |
val _ = trace " Proving finites"; |
27232 | 1007 |
val finites = map one_finite (dnames ~~ atomize global_ctxt finite_lemma1b); |
31232
689aa7da48cc
define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents:
31160
diff
changeset
|
1008 |
val _ = trace " Proving ind"; |
23152 | 1009 |
val ind = |
1010 |
let |
|
1011 |
fun concf n dn = %:(P_name n) $ %:(x_name n); |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
1012 |
fun tacf {prems, context} = |
23152 | 1013 |
let |
1014 |
fun finite_tacs (finite, fin_ind) = [ |
|
1015 |
rtac(rewrite_rule axs_finite_def finite RS exE)1, |
|
1016 |
etac subst 1, |
|
1017 |
rtac fin_ind 1, |
|
1018 |
ind_prems_tac prems]; |
|
1019 |
in |
|
1020 |
TRY (safe_tac HOL_cs) :: |
|
27232 | 1021 |
maps finite_tacs (finites ~~ atomize global_ctxt finite_ind) |
23152 | 1022 |
end; |
1023 |
in pg'' thy [] (ind_term concf) tacf end; |
|
1024 |
in (finites, ind) end (* let *) |
|
1025 |
||
1026 |
else (* infinite case *) |
|
1027 |
let |
|
1028 |
fun one_finite n dn = |
|
27239 | 1029 |
read_instantiate global_ctxt [(("P", 0), dn ^ "_finite " ^ x_name n)] excluded_middle; |
23152 | 1030 |
val finites = mapn one_finite 1 dnames; |
1031 |
||
1032 |
val goal = |
|
1033 |
let |
|
26012 | 1034 |
fun one_adm n _ = mk_trp (mk_adm (%:(P_name n))); |
23152 | 1035 |
fun concf n dn = %:(P_name n) $ %:(x_name n); |
1036 |
in Logic.list_implies (mapn one_adm 1 dnames, ind_term concf) end; |
|
33396 | 1037 |
val cont_rules = |
1038 |
[cont_id, cont_const, cont2cont_Rep_CFun, |
|
1039 |
cont2cont_fst, cont2cont_snd]; |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
1040 |
fun tacf {prems, context} = |
23152 | 1041 |
map (fn ax_reach => rtac (ax_reach RS subst) 1) axs_reach @ [ |
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
1042 |
quant_tac context 1, |
23152 | 1043 |
rtac (adm_impl_admw RS wfix_ind) 1, |
25895
0eaadfa8889e
converted adm_all and adm_ball to rule_format; cleaned up
huffman
parents:
25805
diff
changeset
|
1044 |
REPEAT_DETERM (rtac adm_all 1), |
23152 | 1045 |
REPEAT_DETERM ( |
1046 |
TRY (rtac adm_conj 1) THEN |
|
1047 |
rtac adm_subst 1 THEN |
|
33396 | 1048 |
REPEAT (resolve_tac cont_rules 1) THEN |
1049 |
resolve_tac prems 1), |
|
23152 | 1050 |
strip_tac 1, |
1051 |
rtac (rewrite_rule axs_take_def finite_ind) 1, |
|
1052 |
ind_prems_tac prems]; |
|
1053 |
val ind = (pg'' thy [] goal tacf |
|
1054 |
handle ERROR _ => |
|
33396 | 1055 |
(warning "Cannot prove infinite induction rule"; TrueI)); |
31232
689aa7da48cc
define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents:
31160
diff
changeset
|
1056 |
in (finites, ind) end |
689aa7da48cc
define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents:
31160
diff
changeset
|
1057 |
) |
689aa7da48cc
define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents:
31160
diff
changeset
|
1058 |
handle THM _ => |
689aa7da48cc
define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents:
31160
diff
changeset
|
1059 |
(warning "Induction proofs failed (THM raised)."; ([], TrueI)) |
689aa7da48cc
define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents:
31160
diff
changeset
|
1060 |
| ERROR _ => |
33810
38375b16ffd9
nicer warning message for indirect-recursive domain definitions
huffman
parents:
33801
diff
changeset
|
1061 |
(warning "Cannot prove induction rule"; ([], TrueI)); |
31232
689aa7da48cc
define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents:
31160
diff
changeset
|
1062 |
|
689aa7da48cc
define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents:
31160
diff
changeset
|
1063 |
|
23152 | 1064 |
end; (* local *) |
1065 |
||
1066 |
(* ----- theorem concerning coinduction ------------------------------------- *) |
|
1067 |
||
35444 | 1068 |
(* COINDUCTION TEMPORARILY DISABLED |
23152 | 1069 |
local |
1070 |
val xs = mapn (fn n => K (x_name n)) 1 dnames; |
|
1071 |
fun bnd_arg n i = Bound(2*(n_eqs - n)-i-1); |
|
1072 |
val take_ss = HOL_ss addsimps take_rews; |
|
1073 |
val sproj = prj (fn s => K("fst("^s^")")) (fn s => K("snd("^s^")")); |
|
29402 | 1074 |
val _ = trace " Proving coind_lemma..."; |
23152 | 1075 |
val coind_lemma = |
1076 |
let |
|
1077 |
fun mk_prj n _ = proj (%:"R") eqs n $ bnd_arg n 0 $ bnd_arg n 1; |
|
1078 |
fun mk_eqn n dn = |
|
1079 |
(dc_take dn $ %:"n" ` bnd_arg n 0) === |
|
1080 |
(dc_take dn $ %:"n" ` bnd_arg n 1); |
|
1081 |
fun mk_all2 (x,t) = mk_all (x, mk_all (x^"'", t)); |
|
1082 |
val goal = |
|
1083 |
mk_trp (mk_imp (%%:(comp_dname^"_bisim") $ %:"R", |
|
1084 |
Library.foldr mk_all2 (xs, |
|
1085 |
Library.foldr mk_imp (mapn mk_prj 0 dnames, |
|
1086 |
foldr1 mk_conj (mapn mk_eqn 0 dnames))))); |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
1087 |
fun x_tacs ctxt n x = [ |
23152 | 1088 |
rotate_tac (n+1) 1, |
1089 |
etac all2E 1, |
|
27239 | 1090 |
eres_inst_tac ctxt [(("P", 1), sproj "R" eqs n^" "^x^" "^x^"'")] (mp RS disjE) 1, |
23152 | 1091 |
TRY (safe_tac HOL_cs), |
1092 |
REPEAT (CHANGED (asm_simp_tac take_ss 1))]; |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
1093 |
fun tacs ctxt = [ |
23152 | 1094 |
rtac impI 1, |
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
1095 |
InductTacs.induct_tac ctxt [[SOME "n"]] 1, |
23152 | 1096 |
simp_tac take_ss 1, |
1097 |
safe_tac HOL_cs] @ |
|
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
1098 |
flat (mapn (x_tacs ctxt) 0 xs); |
23152 | 1099 |
in pg [ax_bisim_def] goal tacs end; |
1100 |
in |
|
29402 | 1101 |
val _ = trace " Proving coind..."; |
23152 | 1102 |
val coind = |
1103 |
let |
|
1104 |
fun mk_prj n x = mk_trp (proj (%:"R") eqs n $ %:x $ %:(x^"'")); |
|
1105 |
fun mk_eqn x = %:x === %:(x^"'"); |
|
1106 |
val goal = |
|
1107 |
mk_trp (%%:(comp_dname^"_bisim") $ %:"R") ===> |
|
1108 |
Logic.list_implies (mapn mk_prj 0 xs, |
|
1109 |
mk_trp (foldr1 mk_conj (map mk_eqn xs))); |
|
1110 |
val tacs = |
|
1111 |
TRY (safe_tac HOL_cs) :: |
|
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26012
diff
changeset
|
1112 |
maps (fn take_lemma => [ |
23152 | 1113 |
rtac take_lemma 1, |
1114 |
cut_facts_tac [coind_lemma] 1, |
|
1115 |
fast_tac HOL_cs 1]) |
|
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26012
diff
changeset
|
1116 |
take_lemmas; |
27208
5fe899199f85
proper context for tactics derived from res_inst_tac;
wenzelm
parents:
27153
diff
changeset
|
1117 |
in pg [] goal (K tacs) end; |
23152 | 1118 |
end; (* local *) |
35444 | 1119 |
COINDUCTION TEMPORARILY DISABLED *) |
23152 | 1120 |
|
32172 | 1121 |
val inducts = Project_Rule.projections (ProofContext.init thy) ind; |
30829 | 1122 |
fun ind_rule (dname, rule) = ((Binding.empty, [rule]), [Induct.induct_type dname]); |
31232
689aa7da48cc
define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents:
31160
diff
changeset
|
1123 |
val induct_failed = (Thm.prop_of ind = Thm.prop_of TrueI); |
30829 | 1124 |
|
24712
64ed05609568
proper Sign operations instead of Theory aliases;
wenzelm
parents:
24503
diff
changeset
|
1125 |
in thy |> Sign.add_path comp_dnam |
31004 | 1126 |
|> snd o PureThy.add_thmss [ |
1127 |
((Binding.name "take_rews" , take_rews ), [Simplifier.simp_add]), |
|
1128 |
((Binding.name "take_lemmas", take_lemmas ), []), |
|
1129 |
((Binding.name "finites" , finites ), []), |
|
1130 |
((Binding.name "finite_ind" , [finite_ind]), []), |
|
35444 | 1131 |
((Binding.name "ind" , [ind] ), [])(*, |
1132 |
((Binding.name "coind" , [coind] ), [])*)] |
|
31232
689aa7da48cc
define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents:
31160
diff
changeset
|
1133 |
|> (if induct_failed then I |
689aa7da48cc
define copy functions using combinators; add checking for failed proofs of induction rules
huffman
parents:
31160
diff
changeset
|
1134 |
else snd o PureThy.add_thmss (map ind_rule (dnames ~~ inducts))) |
28536 | 1135 |
|> Sign.parent_path |> pair take_rews |
23152 | 1136 |
end; (* let *) |
1137 |
end; (* struct *) |