497 Abs ("x", domT, Const (@{const_name Fun_Def.THE_default}, ranT --> (ranT --> boolT) --> ranT) |
497 Abs ("x", domT, Const (@{const_name Fun_Def.THE_default}, ranT --> (ranT --> boolT) --> ranT) |
498 $ (default $ Bound 0) $ Abs ("y", ranT, G $ Bound 1 $ Bound 0)) |
498 $ (default $ Bound 0) $ Abs ("y", ranT, G $ Bound 1 $ Bound 0)) |
499 |> Syntax.check_term lthy |
499 |> Syntax.check_term lthy |
500 in |
500 in |
501 lthy |> Local_Theory.define |
501 lthy |> Local_Theory.define |
502 ((Binding.name (fname ^ "C") (* FIXME proper binding *), mixfix), ((f_def_binding, []), f_def)) |
502 ((Binding.map_name (suffix "C") fname, mixfix), ((f_def_binding, []), f_def)) |
503 end |
503 end |
504 |
504 |
505 fun define_recursion_relation (R_binding, R_type) qglrs clauses RCss lthy = |
505 fun define_recursion_relation (R_binding, R_type) qglrs clauses RCss lthy = |
506 let |
506 let |
507 val R = Free (Binding.name_of R_binding, R_type) |
507 val R = Free (Binding.name_of R_binding, R_type) |
824 |
824 |
825 fun prepare_function config defname [((fname, fT), mixfix)] abstract_qglrs lthy = |
825 fun prepare_function config defname [((fname, fT), mixfix)] abstract_qglrs lthy = |
826 let |
826 let |
827 val FunctionConfig {domintros, default=default_opt, ...} = config |
827 val FunctionConfig {domintros, default=default_opt, ...} = config |
828 |
828 |
829 val default_str = the_default "%x. HOL.undefined" default_opt |
829 val default_str = the_default "%x. HOL.undefined" (* FIXME proper term!? *) default_opt |
830 val fvar = Free (fname, fT) |
830 val fvar = (Binding.name_of fname, fT) |
831 val domT = domain_type fT |
831 val domT = domain_type fT |
832 val ranT = range_type fT |
832 val ranT = range_type fT |
833 |
833 |
834 val default = Syntax.parse_term lthy default_str |
834 val default = Syntax.parse_term lthy default_str |
835 |> Type.constraint fT |> Syntax.check_term lthy |
835 |> Type.constraint fT |> Syntax.check_term lthy |
836 |
836 |
837 val (globals, ctxt') = fix_globals domT ranT fvar lthy |
837 val (globals, ctxt') = fix_globals domT ranT (Free fvar) lthy |
838 |
838 |
839 val Globals { x, h, ... } = globals |
839 val Globals { x, h, ... } = globals |
840 |
840 |
841 val clauses = map (mk_clause_context x ctxt') abstract_qglrs |
841 val clauses = map (mk_clause_context x ctxt') abstract_qglrs |
842 |
842 |
843 val n = length abstract_qglrs |
843 val n = length abstract_qglrs |
844 |
844 |
845 fun build_tree (ClauseContext { ctxt, rhs, ...}) = |
845 fun build_tree (ClauseContext { ctxt, rhs, ...}) = |
846 Function_Context_Tree.mk_tree (fname, fT) h ctxt rhs |
846 Function_Context_Tree.mk_tree fvar h ctxt rhs |
847 |
847 |
848 val trees = map build_tree clauses |
848 val trees = map build_tree clauses |
849 val RCss = map find_calls trees |
849 val RCss = map find_calls trees |
850 |
850 |
851 val ((G, GIntro_thms, G_elim, G_induct), lthy) = |
851 val ((G, GIntro_thms, G_elim, G_induct), lthy) = |
852 PROFILE "def_graph" |
852 PROFILE "def_graph" |
853 (define_graph |
853 (define_graph |
854 (derived_name_suffix defname "_graph", domT --> ranT --> boolT) fvar clauses RCss) lthy |
854 (derived_name_suffix defname "_graph", domT --> ranT --> boolT) (Free fvar) clauses RCss) |
|
855 lthy |
855 |
856 |
856 val ((f, (_, f_defthm)), lthy) = |
857 val ((f, (_, f_defthm)), lthy) = |
857 PROFILE "def_fun" (define_function defname (fname, mixfix) domT ranT G default) lthy |
858 PROFILE "def_fun" (define_function defname (fname, mixfix) domT ranT G default) lthy |
858 |
859 |
859 val RCss = map (map (inst_RC lthy fvar f)) RCss |
860 val RCss = map (map (inst_RC lthy (Free fvar) f)) RCss |
860 val trees = map (Function_Context_Tree.inst_tree lthy fvar f) trees |
861 val trees = map (Function_Context_Tree.inst_tree lthy (Free fvar) f) trees |
861 |
862 |
862 val ((R, RIntro_thmss, R_elim), lthy) = |
863 val ((R, RIntro_thmss, R_elim), lthy) = |
863 PROFILE "def_rel" |
864 PROFILE "def_rel" |
864 (define_recursion_relation (derived_name_suffix defname "_rel", domT --> domT --> boolT) |
865 (define_recursion_relation (derived_name_suffix defname "_rel", domT --> domT --> boolT) |
865 abstract_qglrs clauses RCss) lthy |
866 abstract_qglrs clauses RCss) lthy |
866 |
867 |
867 val dom = mk_acc domT R |
868 val dom = mk_acc domT R |
868 val (_, lthy) = |
869 val (_, lthy) = |
869 Local_Theory.abbrev Syntax.mode_default |
870 Local_Theory.abbrev Syntax.mode_default |
870 ((name_suffix defname "_dom", NoSyn), dom) lthy |
871 ((derived_name_suffix defname "_dom", NoSyn), dom) lthy |
871 |
872 |
872 val newthy = Proof_Context.theory_of lthy |
873 val newthy = Proof_Context.theory_of lthy |
873 val clauses = map (transfer_clause_ctx newthy) clauses |
874 val clauses = map (transfer_clause_ctx newthy) clauses |
874 |
875 |
875 val xclauses = PROFILE "xclauses" |
876 val xclauses = PROFILE "xclauses" |