97 (*** Construct the fixedpoint definition ***) |
97 (*** Construct the fixedpoint definition ***) |
98 val mk_variant = singleton (Name.variant_list (List.foldr Misc_Legacy.add_term_names [] intr_tms)); |
98 val mk_variant = singleton (Name.variant_list (List.foldr Misc_Legacy.add_term_names [] intr_tms)); |
99 |
99 |
100 val z' = mk_variant"z" and X' = mk_variant"X" and w' = mk_variant"w"; |
100 val z' = mk_variant"z" and X' = mk_variant"X" and w' = mk_variant"w"; |
101 |
101 |
102 fun dest_tprop (Const(@{const_name Trueprop},_) $ P) = P |
102 fun dest_tprop (Const(\<^const_name>\<open>Trueprop\<close>,_) $ P) = P |
103 | dest_tprop Q = error ("Ill-formed premise of introduction rule: " ^ |
103 | dest_tprop Q = error ("Ill-formed premise of introduction rule: " ^ |
104 Syntax.string_of_term ctxt Q); |
104 Syntax.string_of_term ctxt Q); |
105 |
105 |
106 (*Makes a disjunct from an introduction rule*) |
106 (*Makes a disjunct from an introduction rule*) |
107 fun fp_part intr = (*quantify over rule's free vars except parameters*) |
107 fun fp_part intr = (*quantify over rule's free vars except parameters*) |
281 val pred_name = "P"; (*name for predicate variables*) |
281 val pred_name = "P"; (*name for predicate variables*) |
282 |
282 |
283 (*Used to make induction rules; |
283 (*Used to make induction rules; |
284 ind_alist = [(rec_tm1,pred1),...] associates predicates with rec ops |
284 ind_alist = [(rec_tm1,pred1),...] associates predicates with rec ops |
285 prem is a premise of an intr rule*) |
285 prem is a premise of an intr rule*) |
286 fun add_induct_prem ind_alist (prem as Const (@{const_name Trueprop}, _) $ |
286 fun add_induct_prem ind_alist (prem as Const (\<^const_name>\<open>Trueprop\<close>, _) $ |
287 (Const (@{const_name mem}, _) $ t $ X), iprems) = |
287 (Const (\<^const_name>\<open>mem\<close>, _) $ t $ X), iprems) = |
288 (case AList.lookup (op aconv) ind_alist X of |
288 (case AList.lookup (op aconv) ind_alist X of |
289 SOME pred => prem :: FOLogic.mk_Trueprop (pred $ t) :: iprems |
289 SOME pred => prem :: FOLogic.mk_Trueprop (pred $ t) :: iprems |
290 | NONE => (*possibly membership in M(rec_tm), for M monotone*) |
290 | NONE => (*possibly membership in M(rec_tm), for M monotone*) |
291 let fun mk_sb (rec_tm,pred) = |
291 let fun mk_sb (rec_tm,pred) = |
292 (rec_tm, @{const Collect} $ rec_tm $ pred) |
292 (rec_tm, @{const Collect} $ rec_tm $ pred) |
498 Thm.global_cterm_of thy elem_tuple)]); |
498 Thm.global_cterm_of thy elem_tuple)]); |
499 |
499 |
500 (*strip quantifier and the implication*) |
500 (*strip quantifier and the implication*) |
501 val induct0 = inst (quant_induct RS @{thm spec} RSN (2, @{thm rev_mp})); |
501 val induct0 = inst (quant_induct RS @{thm spec} RSN (2, @{thm rev_mp})); |
502 |
502 |
503 val Const (@{const_name Trueprop}, _) $ (pred_var $ _) = Thm.concl_of induct0 |
503 val Const (\<^const_name>\<open>Trueprop\<close>, _) $ (pred_var $ _) = Thm.concl_of induct0 |
504 |
504 |
505 val induct = |
505 val induct = |
506 CP.split_rule_var (Proof_Context.init_global thy) |
506 CP.split_rule_var (Proof_Context.init_global thy) |
507 (pred_var, elem_type-->FOLogic.oT, induct0) |
507 (pred_var, elem_type-->FOLogic.oT, induct0) |
508 |> Drule.export_without_context |
508 |> Drule.export_without_context |
581 fun mk_ind (((((doms, intrs), monos), con_defs), type_intrs), type_elims) = |
581 fun mk_ind (((((doms, intrs), monos), con_defs), type_intrs), type_elims) = |
582 #1 o add_inductive doms (map (fn ((x, y), z) => ((x, z), y)) intrs) |
582 #1 o add_inductive doms (map (fn ((x, y), z) => ((x, z), y)) intrs) |
583 (monos, con_defs, type_intrs, type_elims); |
583 (monos, con_defs, type_intrs, type_elims); |
584 |
584 |
585 val ind_decl = |
585 val ind_decl = |
586 (@{keyword "domains"} |-- Parse.!!! (Parse.enum1 "+" Parse.term -- |
586 (\<^keyword>\<open>domains\<close> |-- Parse.!!! (Parse.enum1 "+" Parse.term -- |
587 ((@{keyword "\<subseteq>"} || @{keyword "<="}) |-- Parse.term))) -- |
587 ((\<^keyword>\<open>\<subseteq>\<close> || \<^keyword>\<open><=\<close>) |-- Parse.term))) -- |
588 (@{keyword "intros"} |-- |
588 (\<^keyword>\<open>intros\<close> |-- |
589 Parse.!!! (Scan.repeat1 (Parse_Spec.opt_thm_name ":" -- Parse.prop))) -- |
589 Parse.!!! (Scan.repeat1 (Parse_Spec.opt_thm_name ":" -- Parse.prop))) -- |
590 Scan.optional (@{keyword "monos"} |-- Parse.!!! Parse.thms1) [] -- |
590 Scan.optional (\<^keyword>\<open>monos\<close> |-- Parse.!!! Parse.thms1) [] -- |
591 Scan.optional (@{keyword "con_defs"} |-- Parse.!!! Parse.thms1) [] -- |
591 Scan.optional (\<^keyword>\<open>con_defs\<close> |-- Parse.!!! Parse.thms1) [] -- |
592 Scan.optional (@{keyword "type_intros"} |-- Parse.!!! Parse.thms1) [] -- |
592 Scan.optional (\<^keyword>\<open>type_intros\<close> |-- Parse.!!! Parse.thms1) [] -- |
593 Scan.optional (@{keyword "type_elims"} |-- Parse.!!! Parse.thms1) [] |
593 Scan.optional (\<^keyword>\<open>type_elims\<close> |-- Parse.!!! Parse.thms1) [] |
594 >> (Toplevel.theory o mk_ind); |
594 >> (Toplevel.theory o mk_ind); |
595 |
595 |
596 val _ = |
596 val _ = |
597 Outer_Syntax.command |
597 Outer_Syntax.command |
598 (if coind then @{command_keyword coinductive} else @{command_keyword inductive}) |
598 (if coind then \<^command_keyword>\<open>coinductive\<close> else \<^command_keyword>\<open>inductive\<close>) |
599 ("define " ^ co_prefix ^ "inductive sets") ind_decl; |
599 ("define " ^ co_prefix ^ "inductive sets") ind_decl; |
600 |
600 |
601 end; |
601 end; |
602 |
602 |