63 ags: thm list, |
63 ags: thm list, |
64 case_hyp : thm} |
64 case_hyp : thm} |
65 |
65 |
66 |
66 |
67 fun transfer_clause_ctx thy (ClauseContext { ctxt, qs, gs, lhs, rhs, cqs, ags, case_hyp }) = |
67 fun transfer_clause_ctx thy (ClauseContext { ctxt, qs, gs, lhs, rhs, cqs, ags, case_hyp }) = |
68 ClauseContext { ctxt = ProofContext.transfer thy ctxt, |
68 ClauseContext { ctxt = Proof_Context.transfer thy ctxt, |
69 qs = qs, gs = gs, lhs = lhs, rhs = rhs, cqs = cqs, ags = ags, case_hyp = case_hyp } |
69 qs = qs, gs = gs, lhs = lhs, rhs = rhs, cqs = cqs, ags = ags, case_hyp = case_hyp } |
70 |
70 |
71 |
71 |
72 datatype clause_info = ClauseInfo of |
72 datatype clause_info = ClauseInfo of |
73 {no: int, |
73 {no: int, |
143 fun mk_clause_context x ctxt (pre_qs,pre_gs,pre_lhs,pre_rhs) = |
143 fun mk_clause_context x ctxt (pre_qs,pre_gs,pre_lhs,pre_rhs) = |
144 let |
144 let |
145 val (qs, ctxt') = Variable.variant_fixes (map fst pre_qs) ctxt |
145 val (qs, ctxt') = Variable.variant_fixes (map fst pre_qs) ctxt |
146 |>> map2 (fn (_, T) => fn n => Free (n, T)) pre_qs |
146 |>> map2 (fn (_, T) => fn n => Free (n, T)) pre_qs |
147 |
147 |
148 val thy = ProofContext.theory_of ctxt' |
148 val thy = Proof_Context.theory_of ctxt' |
149 |
149 |
150 fun inst t = subst_bounds (rev qs, t) |
150 fun inst t = subst_bounds (rev qs, t) |
151 val gs = map inst pre_gs |
151 val gs = map inst pre_gs |
152 val lhs = inst pre_lhs |
152 val lhs = inst pre_lhs |
153 val rhs = inst pre_rhs |
153 val rhs = inst pre_rhs |
181 fun mk_clause_info globals G f no cdata qglr tree RCs GIntro_thm RIntro_thms = |
181 fun mk_clause_info globals G f no cdata qglr tree RCs GIntro_thm RIntro_thms = |
182 let |
182 let |
183 val Globals {h, ...} = globals |
183 val Globals {h, ...} = globals |
184 |
184 |
185 val ClauseContext { ctxt, qs, cqs, ags, ... } = cdata |
185 val ClauseContext { ctxt, qs, cqs, ags, ... } = cdata |
186 val cert = Thm.cterm_of (ProofContext.theory_of ctxt) |
186 val cert = Thm.cterm_of (Proof_Context.theory_of ctxt) |
187 |
187 |
188 (* Instantiate the GIntro thm with "f" and import into the clause context. *) |
188 (* Instantiate the GIntro thm with "f" and import into the clause context. *) |
189 val lGI = GIntro_thm |
189 val lGI = GIntro_thm |
190 |> Thm.forall_elim (cert f) |
190 |> Thm.forall_elim (cert f) |
191 |> fold Thm.forall_elim cqs |
191 |> fold Thm.forall_elim cqs |
201 |
201 |
202 val h_assum = |
202 val h_assum = |
203 HOLogic.mk_Trueprop (G $ rcarg $ (h $ rcarg)) |
203 HOLogic.mk_Trueprop (G $ rcarg $ (h $ rcarg)) |
204 |> fold_rev (curry Logic.mk_implies o prop_of) rcassm |
204 |> fold_rev (curry Logic.mk_implies o prop_of) rcassm |
205 |> fold_rev (Logic.all o Free) rcfix |
205 |> fold_rev (Logic.all o Free) rcfix |
206 |> Pattern.rewrite_term (ProofContext.theory_of ctxt) [(f, h)] [] |
206 |> Pattern.rewrite_term (Proof_Context.theory_of ctxt) [(f, h)] [] |
207 |> abstract_over_list (rev qs) |
207 |> abstract_over_list (rev qs) |
208 in |
208 in |
209 RCInfo {RIvs=rcfix, rcarg=rcarg, CCas=rcassm, llRI=llRI, h_assum=h_assum} |
209 RCInfo {RIvs=rcfix, rcarg=rcarg, CCas=rcassm, llRI=llRI, h_assum=h_assum} |
210 end |
210 end |
211 |
211 |
384 |
384 |
385 |
385 |
386 fun prove_stuff ctxt globals G f R clauses complete compat compat_store G_elim f_def = |
386 fun prove_stuff ctxt globals G f R clauses complete compat compat_store G_elim f_def = |
387 let |
387 let |
388 val Globals {h, domT, ranT, x, ...} = globals |
388 val Globals {h, domT, ranT, x, ...} = globals |
389 val thy = ProofContext.theory_of ctxt |
389 val thy = Proof_Context.theory_of ctxt |
390 |
390 |
391 (* Inductive Hypothesis: !!z. (z,x):R ==> EX!y. (z,y):G *) |
391 (* Inductive Hypothesis: !!z. (z,x):R ==> EX!y. (z,y):G *) |
392 val ihyp = Term.all domT $ Abs ("z", domT, |
392 val ihyp = Term.all domT $ Abs ("z", domT, |
393 Logic.mk_implies (HOLogic.mk_Trueprop (R $ Bound 0 $ x), |
393 Logic.mk_implies (HOLogic.mk_Trueprop (R $ Bound 0 $ x), |
394 HOLogic.mk_Trueprop (Const (@{const_name Ex1}, (ranT --> boolT) --> boolT) $ |
394 HOLogic.mk_Trueprop (Const (@{const_name Ex1}, (ranT --> boolT) --> boolT) $ |
445 [] (* no parameters *) |
445 [] (* no parameters *) |
446 (map (fn t => (Attrib.empty_binding, t)) intrs) (* intro rules *) |
446 (map (fn t => (Attrib.empty_binding, t)) intrs) (* intro rules *) |
447 [] (* no special monos *) |
447 [] (* no special monos *) |
448 ||> Local_Theory.restore_naming lthy |
448 ||> Local_Theory.restore_naming lthy |
449 |
449 |
450 val cert = cterm_of (ProofContext.theory_of lthy) |
450 val cert = cterm_of (Proof_Context.theory_of lthy) |
451 fun requantify orig_intro thm = |
451 fun requantify orig_intro thm = |
452 let |
452 let |
453 val (qs, t) = dest_all_all orig_intro |
453 val (qs, t) = dest_all_all orig_intro |
454 val frees = frees_in_term lthy t |> remove (op =) (Binding.name_of R, T) |
454 val frees = frees_in_term lthy t |> remove (op =) (Binding.name_of R, T) |
455 val vars = Term.add_vars (prop_of thm) [] |> rev |
455 val vars = Term.add_vars (prop_of thm) [] |> rev |
690 |
690 |
691 |
691 |
692 (* FIXME: broken by design *) |
692 (* FIXME: broken by design *) |
693 fun mk_domain_intro ctxt (Globals {domT, ...}) R R_cases clause = |
693 fun mk_domain_intro ctxt (Globals {domT, ...}) R R_cases clause = |
694 let |
694 let |
695 val thy = ProofContext.theory_of ctxt |
695 val thy = Proof_Context.theory_of ctxt |
696 val ClauseInfo {cdata = ClauseContext {gs, lhs, cqs, ...}, |
696 val ClauseInfo {cdata = ClauseContext {gs, lhs, cqs, ...}, |
697 qglr = (oqs, _, _, _), ...} = clause |
697 qglr = (oqs, _, _, _), ...} = clause |
698 val goal = HOLogic.mk_Trueprop (mk_acc domT R $ lhs) |
698 val goal = HOLogic.mk_Trueprop (mk_acc domT R $ lhs) |
699 |> fold_rev (curry Logic.mk_implies) gs |
699 |> fold_rev (curry Logic.mk_implies) gs |
700 |> cterm_of thy |
700 |> cterm_of thy |
847 PROFILE "def_graph" (define_graph (graph_name defname) fvar domT ranT clauses RCss) lthy |
847 PROFILE "def_graph" (define_graph (graph_name defname) fvar domT ranT clauses RCss) lthy |
848 |
848 |
849 val ((f, (_, f_defthm)), lthy) = |
849 val ((f, (_, f_defthm)), lthy) = |
850 PROFILE "def_fun" (define_function (defname ^ "_sumC_def") (fname, mixfix) domT ranT G default) lthy |
850 PROFILE "def_fun" (define_function (defname ^ "_sumC_def") (fname, mixfix) domT ranT G default) lthy |
851 |
851 |
852 val RCss = map (map (inst_RC (ProofContext.theory_of lthy) fvar f)) RCss |
852 val RCss = map (map (inst_RC (Proof_Context.theory_of lthy) fvar f)) RCss |
853 val trees = map (Function_Ctx_Tree.inst_tree (ProofContext.theory_of lthy) fvar f) trees |
853 val trees = map (Function_Ctx_Tree.inst_tree (Proof_Context.theory_of lthy) fvar f) trees |
854 |
854 |
855 val ((R, RIntro_thmss, R_elim), lthy) = |
855 val ((R, RIntro_thmss, R_elim), lthy) = |
856 PROFILE "def_rel" (define_recursion_relation (rel_name defname) domT abstract_qglrs clauses RCss) lthy |
856 PROFILE "def_rel" (define_recursion_relation (rel_name defname) domT abstract_qglrs clauses RCss) lthy |
857 |
857 |
858 val (_, lthy) = |
858 val (_, lthy) = |
859 Local_Theory.abbrev Syntax.mode_default ((Binding.name (dom_name defname), NoSyn), mk_acc domT R) lthy |
859 Local_Theory.abbrev Syntax.mode_default ((Binding.name (dom_name defname), NoSyn), mk_acc domT R) lthy |
860 |
860 |
861 val newthy = ProofContext.theory_of lthy |
861 val newthy = Proof_Context.theory_of lthy |
862 val clauses = map (transfer_clause_ctx newthy) clauses |
862 val clauses = map (transfer_clause_ctx newthy) clauses |
863 |
863 |
864 val cert = cterm_of (ProofContext.theory_of lthy) |
864 val cert = cterm_of (Proof_Context.theory_of lthy) |
865 |
865 |
866 val xclauses = PROFILE "xclauses" |
866 val xclauses = PROFILE "xclauses" |
867 (map7 (mk_clause_info globals G f) (1 upto n) clauses abstract_qglrs trees |
867 (map7 (mk_clause_info globals G f) (1 upto n) clauses abstract_qglrs trees |
868 RCss GIntro_thms) RIntro_thmss |
868 RCss GIntro_thms) RIntro_thmss |
869 |
869 |