59 let |
59 let |
60 val qty_args1 = map2 (fn ty => fn trm => (ty, trm, false)) alpha_tys alpha_trms |
60 val qty_args1 = map2 (fn ty => fn trm => (ty, trm, false)) alpha_tys alpha_trms |
61 val qty_args2 = map2 (fn descr => fn args1 => (descr, args1, (NONE, NONE))) qtys_descr qty_args1 |
61 val qty_args2 = map2 (fn descr => fn args1 => (descr, args1, (NONE, NONE))) qtys_descr qty_args1 |
62 val qty_args3 = qty_args2 ~~ alpha_equivp_thms |
62 val qty_args3 = qty_args2 ~~ alpha_equivp_thms |
63 in |
63 in |
64 fold_map Quotient_Type.add_quotient_type qty_args3 lthy |
64 fold_map (Quotient_Type.add_quotient_type {overloaded = false}) qty_args3 lthy |
65 end |
65 end |
66 |
66 |
67 (* a wrapper for lifting a raw constant *) |
67 (* a wrapper for lifting a raw constant *) |
68 fun lift_raw_const qtys (qconst_name, rconst, mx', rsp_thm) lthy = |
68 fun lift_raw_const qtys (qconst_name, rconst, mx', rsp_thm) lthy = |
69 let |
69 let |
71 val qty = Quotient_Term.derive_qtyp lthy qtys rty |
71 val qty = Quotient_Term.derive_qtyp lthy qtys rty |
72 val lhs_raw = Free (qconst_name, qty) |
72 val lhs_raw = Free (qconst_name, qty) |
73 val rhs_raw = rconst |
73 val rhs_raw = rconst |
74 |
74 |
75 val raw_var = (Binding.name qconst_name, NONE, mx') |
75 val raw_var = (Binding.name qconst_name, NONE, mx') |
76 val ([(binding, _, mx)], ctxt) = Proof_Context.cert_vars [raw_var] lthy |
76 val ((binding, _, mx), ctxt) = Proof_Context.cert_var raw_var lthy |
77 val lhs = Syntax.check_term ctxt lhs_raw |
77 val lhs = Syntax.check_term ctxt lhs_raw |
78 val rhs = Syntax.check_term ctxt rhs_raw |
78 val rhs = Syntax.check_term ctxt rhs_raw |
79 |
79 |
80 val (lhs_str, lhs_ty) = dest_Free lhs handle TERM _ => error "Constant already defined." |
80 val (lhs_str, lhs_ty) = dest_Free lhs handle TERM _ => error "Constant already defined." |
81 val _ = if null (strip_abs_vars rhs) then () else error "The definiens cannot be an abstraction" |
81 val _ = if null (strip_abs_vars rhs) then () else error "The definiens cannot be an abstraction" |
89 (* defines quotient constants *) |
89 (* defines quotient constants *) |
90 fun define_qconsts qtys consts_specs lthy = |
90 fun define_qconsts qtys consts_specs lthy = |
91 let |
91 let |
92 val (qconst_infos, lthy') = |
92 val (qconst_infos, lthy') = |
93 fold_map (lift_raw_const qtys) consts_specs lthy |
93 fold_map (lift_raw_const qtys) consts_specs lthy |
94 val phi = Proof_Context.export_morphism lthy' lthy |
94 val phi = |
|
95 Proof_Context.export_morphism lthy' |
|
96 (Proof_Context.transfer (Proof_Context.theory_of lthy') lthy) |
95 in |
97 in |
96 (map (Quotient_Info.transform_quotconsts phi) qconst_infos, lthy') |
98 (map (Quotient_Info.transform_quotconsts phi) qconst_infos, lthy') |
97 end |
99 end |
98 |
100 |
99 |
101 |
151 s |> raw_explode |
153 s |> raw_explode |
152 |> Scan.finite Symbol.stopper parser >> implode |
154 |> Scan.finite Symbol.stopper parser >> implode |
153 |> fst |
155 |> fst |
154 end |
156 end |
155 |
157 |
156 fun unraw_vars_thm thm = |
158 fun unraw_vars_thm ctxt thm = |
157 let |
159 let |
158 fun unraw_var_str ((s, i), T) = ((unraw_str s, i), T) |
160 fun unraw_var_str ((s, i), T) = ((unraw_str s, i), T) |
159 |
161 |
160 val vars = Term.add_vars (Thm.prop_of thm) [] |
162 val vars = Term.add_vars (Thm.prop_of thm) [] |
161 val vars' = map (Var o unraw_var_str) vars |
163 val vars' = map (Thm.cterm_of ctxt o Var o unraw_var_str) vars |
162 in |
164 in |
163 Thm.certify_instantiate ([], (vars ~~ vars')) thm |
165 Thm.instantiate ([], (vars ~~ vars')) thm |
164 end |
166 end |
165 |
167 |
166 fun unraw_bounds_thm th = |
168 fun unraw_bounds_thm th = |
167 let |
169 let |
168 val trm = Thm.prop_of th |
170 val trm = Thm.prop_of th |
226 |> map (mk_finite o mk_supp) |
228 |> map (mk_finite o mk_supp) |
227 |> foldr1 (HOLogic.mk_conj) |
229 |> foldr1 (HOLogic.mk_conj) |
228 |> HOLogic.mk_Trueprop |
230 |> HOLogic.mk_Trueprop |
229 |
231 |
230 val tac = |
232 val tac = |
231 EVERY' [ rtac @{thm supports_finite}, |
233 EVERY' [ resolve_tac ctxt' @{thms supports_finite}, |
232 resolve_tac ctxt' qsupports_thms, |
234 resolve_tac ctxt' qsupports_thms, |
233 asm_simp_tac (put_simpset HOL_ss ctxt' |
235 asm_simp_tac (put_simpset HOL_ss ctxt' |
234 addsimps @{thms finite_supp supp_Pair finite_Un}) ] |
236 addsimps @{thms finite_supp supp_Pair finite_Un}) ] |
235 in |
237 in |
236 Goal.prove ctxt' [] [] goals |
238 Goal.prove ctxt' [] [] goals |
237 (K (HEADGOAL (rtac qinduct THEN_ALL_NEW tac))) |
239 (K (HEADGOAL (resolve_tac ctxt' [qinduct] THEN_ALL_NEW tac))) |
238 |> singleton (Proof_Context.export ctxt' ctxt) |
240 |> singleton (Proof_Context.export ctxt' ctxt) |
239 |> Old_Datatype_Aux.split_conj_thm |
241 |> Old_Datatype_Aux.split_conj_thm |
240 |> map zero_var_indexes |
242 |> map zero_var_indexes |
241 end |
243 end |
242 |
244 |
498 |
500 |
499 val ss = bn_finite_thms @ @{thms supp_Pair finite_supp finite_sets_supp} |
501 val ss = bn_finite_thms @ @{thms supp_Pair finite_supp finite_sets_supp} |
500 @ @{thms finite.intros finite_Un finite_set finite_fset} |
502 @ @{thms finite.intros finite_Un finite_set finite_fset} |
501 in |
503 in |
502 Goal.prove ctxt [] [] goal |
504 Goal.prove ctxt [] [] goal |
503 (K (HEADGOAL (rtac @{thm at_set_avoiding1} |
505 (K (HEADGOAL (resolve_tac ctxt @{thms at_set_avoiding1} |
504 THEN_ALL_NEW (simp_tac (put_simpset HOL_ss ctxt addsimps ss))))) |
506 THEN_ALL_NEW (simp_tac (put_simpset HOL_ss ctxt addsimps ss))))) |
505 end |
507 end |
506 |
508 |
507 |
509 |
508 (* derives an abs_eq theorem of the form |
510 (* derives an abs_eq theorem of the form |
557 fun case_tac ctxt c bn_finite_thms eq_iff_thms bn_eqvt permute_bns perm_bn_alphas |
559 fun case_tac ctxt c bn_finite_thms eq_iff_thms bn_eqvt permute_bns perm_bn_alphas |
558 prems bclausess qexhaust_thm = |
560 prems bclausess qexhaust_thm = |
559 let |
561 let |
560 fun aux_tac prem bclauses = |
562 fun aux_tac prem bclauses = |
561 case (get_all_binders bclauses) of |
563 case (get_all_binders bclauses) of |
562 [] => EVERY' [rtac prem, assume_tac ctxt] |
564 [] => EVERY' [resolve_tac ctxt [prem], assume_tac ctxt] |
563 | binders => Subgoal.SUBPROOF (fn {params, prems, concl, context = ctxt, ...} => |
565 | binders => Subgoal.SUBPROOF (fn {params, prems, concl, context = ctxt, ...} => |
564 let |
566 let |
565 val parms = map (Thm.term_of o snd) params |
567 val parms = map (Thm.term_of o snd) params |
566 val fthm = fresh_thm ctxt c parms binders bn_finite_thms |
568 val fthm = fresh_thm ctxt c parms binders bn_finite_thms |
567 |
569 |
568 val ss = @{thms fresh_star_Pair union_eqvt fresh_star_Un} |
570 val ss = @{thms fresh_star_Pair union_eqvt fresh_star_Un} |
569 val (([(_, fperm)], fprops), ctxt') = Obtain.result |
571 val (([(_, fperm)], fprops), ctxt') = Obtain.result |
570 (fn ctxt' => EVERY1 [etac exE, |
572 (fn ctxt' => EVERY1 [eresolve_tac ctxt [exE], |
571 full_simp_tac (put_simpset HOL_basic_ss ctxt' addsimps ss), |
573 full_simp_tac (put_simpset HOL_basic_ss ctxt' addsimps ss), |
572 REPEAT o (etac @{thm conjE})]) [fthm] ctxt |
574 REPEAT o (eresolve_tac ctxt @{thms conjE})]) [fthm] ctxt |
573 |
575 |
574 val abs_eq_thms = flat |
576 val abs_eq_thms = flat |
575 (map (abs_eq_thm ctxt' fprops (Thm.term_of fperm) parms bn_eqvt permute_bns) bclauses) |
577 (map (abs_eq_thm ctxt' fprops (Thm.term_of fperm) parms bn_eqvt permute_bns) bclauses) |
576 |
578 |
577 val ((_, eqs), ctxt'') = Obtain.result |
579 val ((_, eqs), ctxt'') = Obtain.result |
578 (fn ctxt'' => EVERY1 |
580 (fn ctxt'' => EVERY1 |
579 [ REPEAT o (etac @{thm exE}), |
581 [ REPEAT o (eresolve_tac ctxt @{thms exE}), |
580 REPEAT o (etac @{thm conjE}), |
582 REPEAT o (eresolve_tac ctxt @{thms conjE}), |
581 REPEAT o (dtac setify), |
583 REPEAT o (dresolve_tac ctxt [setify]), |
582 full_simp_tac (put_simpset HOL_basic_ss ctxt'' |
584 full_simp_tac (put_simpset HOL_basic_ss ctxt'' |
583 addsimps @{thms set_append set_simps})]) abs_eq_thms ctxt' |
585 addsimps @{thms set_append set_simps})]) abs_eq_thms ctxt' |
584 |
586 |
585 val (abs_eqs, peqs) = split_filter is_abs_eq eqs |
587 val (abs_eqs, peqs) = split_filter is_abs_eq eqs |
586 |
588 |
590 |
592 |
591 (* for freshness conditions *) |
593 (* for freshness conditions *) |
592 val tac1 = SOLVED' (EVERY' |
594 val tac1 = SOLVED' (EVERY' |
593 [ simp_tac (put_simpset HOL_basic_ss ctxt'' addsimps peqs), |
595 [ simp_tac (put_simpset HOL_basic_ss ctxt'' addsimps peqs), |
594 rewrite_goal_tac ctxt'' (@{thms fresh_star_Un[THEN eq_reflection]}), |
596 rewrite_goal_tac ctxt'' (@{thms fresh_star_Un[THEN eq_reflection]}), |
595 conj_tac (DETERM o resolve_tac ctxt'' fprops') ]) |
597 conj_tac ctxt'' (DETERM o resolve_tac ctxt'' fprops') ]) |
596 |
598 |
597 (* for equalities between constructors *) |
599 (* for equalities between constructors *) |
598 val tac2 = SOLVED' (EVERY' |
600 val tac2 = SOLVED' (EVERY' |
599 [ rtac (@{thm ssubst} OF prems), |
601 [ resolve_tac ctxt [@{thm ssubst} OF prems], |
600 rewrite_goal_tac ctxt'' (map safe_mk_equiv eq_iff_thms), |
602 rewrite_goal_tac ctxt'' (map safe_mk_equiv eq_iff_thms), |
601 rewrite_goal_tac ctxt'' (map safe_mk_equiv abs_eqs), |
603 rewrite_goal_tac ctxt'' (map safe_mk_equiv abs_eqs), |
602 conj_tac (DETERM o resolve_tac ctxt'' (@{thms refl} @ perm_bn_alphas)) ]) |
604 conj_tac ctxt'' (DETERM o resolve_tac ctxt'' (@{thms refl} @ perm_bn_alphas)) ]) |
603 |
605 |
604 (* proves goal "P" *) |
606 (* proves goal "P" *) |
605 val side_thm = Goal.prove ctxt'' [] [] (Thm.term_of concl) |
607 val side_thm = Goal.prove ctxt'' [] [] (Thm.term_of concl) |
606 (K (EVERY1 [ rtac prem, RANGE [tac1, tac2] ])) |
608 (K (EVERY1 [ resolve_tac ctxt'' [prem], RANGE [tac1, tac2] ])) |
607 |> singleton (Proof_Context.export ctxt'' ctxt) |
609 |> singleton (Proof_Context.export ctxt'' ctxt) |
608 in |
610 in |
609 rtac side_thm 1 |
611 resolve_tac ctxt [side_thm] 1 |
610 end) ctxt |
612 end) ctxt |
611 in |
613 in |
612 EVERY1 [rtac qexhaust_thm, RANGE (map2 aux_tac prems bclausess)] |
614 EVERY1 [resolve_tac ctxt [qexhaust_thm], RANGE (map2 aux_tac prems bclausess)] |
613 end |
615 end |
614 |
616 |
615 |
617 |
616 fun prove_strong_exhausts lthy exhausts bclausesss bn_finite_thms eq_iff_thms bn_eqvt permute_bns |
618 fun prove_strong_exhausts lthy exhausts bclausesss bn_finite_thms eq_iff_thms bn_eqvt permute_bns |
617 perm_bn_alphas = |
619 perm_bn_alphas = |
724 Subgoal.FOCUS (fn {params, context = ctxt', ...} => |
726 Subgoal.FOCUS (fn {params, context = ctxt', ...} => |
725 let |
727 let |
726 val ty_parms = map (fn (_, ct) => (fastype_of (Thm.term_of ct), ct)) params |
728 val ty_parms = map (fn (_, ct) => (fastype_of (Thm.term_of ct), ct)) params |
727 val vs = Term.add_vars (Thm.prop_of thm) [] |
729 val vs = Term.add_vars (Thm.prop_of thm) [] |
728 val vs_tys = map (Type.legacy_freeze_type o snd) vs |
730 val vs_tys = map (Type.legacy_freeze_type o snd) vs |
729 val vs_ctrms = map (Thm.cterm_of ctxt' o Var) vs |
|
730 val assigns = map (lookup ty_parms) vs_tys |
731 val assigns = map (lookup ty_parms) vs_tys |
731 |
732 val thm' = infer_instantiate ctxt' (map #1 vs ~~ assigns) thm |
732 val thm' = cterm_instantiate (vs_ctrms ~~ assigns) thm |
|
733 in |
733 in |
734 rtac thm' 1 |
734 resolve_tac ctxt' [thm'] 1 |
735 end) ctxt |
735 end) ctxt |
736 THEN_ALL_NEW asm_full_simp_tac (put_simpset HOL_basic_ss ctxt) |
736 THEN_ALL_NEW asm_full_simp_tac (put_simpset HOL_basic_ss ctxt) |
737 |
737 |
738 fun size_simp_tac ctxt = |
738 fun size_simp_tac ctxt = |
739 simp_tac (put_simpset size_ss ctxt addsimps (@{thms comp_def snd_conv} @ size_thms)) |
739 simp_tac (put_simpset size_ss ctxt addsimps (@{thms comp_def snd_conv} @ size_thms)) |