src/HOL/Tools/function_package/fundef_package.ML
changeset 21211 5370cfbf3070
parent 21051 c49467a9c1e1
child 21235 674e2731b519
equal deleted inserted replaced
21210:c17fd2df4e9e 21211:5370cfbf3070
    11 sig
    11 sig
    12     val add_fundef :  (string * string option * mixfix) list
    12     val add_fundef :  (string * string option * mixfix) list
    13                       -> ((bstring * Attrib.src list) * string list) list list
    13                       -> ((bstring * Attrib.src list) * string list) list list
    14                       -> FundefCommon.fundef_config
    14                       -> FundefCommon.fundef_config
    15                       -> local_theory
    15                       -> local_theory
    16                       -> Proof.state
    16                       -> string * Proof.state
    17 
    17 
    18     val add_fundef_i:  (string * typ option * mixfix) list
    18     val add_fundef_i:  (string * typ option * mixfix) list
    19                        -> ((bstring * Attrib.src list) * term list) list list
    19                        -> ((bstring * Attrib.src list) * term list) list list
    20                        -> bool
    20                        -> bool
    21                        -> local_theory
    21                        -> local_theory
    22                        -> Proof.state
    22                        -> string * Proof.state
       
    23 
       
    24     val setup_termination_proof : string option -> local_theory -> Proof.state
    23 
    25 
    24     val cong_add: attribute
    26     val cong_add: attribute
    25     val cong_del: attribute
    27     val cong_del: attribute
    26 
    28 
    27     val setup : theory -> theory
    29     val setup : theory -> theory
   103       val ((mutual_info, name, prep_result as Prep {goal, goalI, ...}), lthy) =
   105       val ((mutual_info, name, prep_result as Prep {goal, goalI, ...}), lthy) =
   104           FundefMutual.prepare_fundef_mutual fixes t_eqns default lthy
   106           FundefMutual.prepare_fundef_mutual fixes t_eqns default lthy
   105 
   107 
   106       val afterqed = fundef_afterqed fixes spec mutual_info name prep_result
   108       val afterqed = fundef_afterqed fixes spec mutual_info name prep_result
   107     in
   109     in
   108         lthy
   110       (name, lthy
   109           |> Proof.theorem_i PureThy.internalK NONE afterqed NONE ("", []) [(("", []), [(goal, [])])]
   111          |> Proof.theorem_i PureThy.internalK NONE afterqed NONE ("", []) [(("", []), [(goal, [])])]
   110           |> Proof.refine (Method.primitive_text (fn _ => goalI)) |> Seq.hd
   112          |> Proof.refine (Method.primitive_text (fn _ => goalI)) |> Seq.hd)
   111     end
   113     end
   112 
   114 
   113 
   115 
   114 fun total_termination_afterqed defname data [[totality]] lthy =
   116 fun total_termination_afterqed defname data [[totality]] lthy =
   115     let
   117     let
   130           |> add_simps "simps" [] mutual_info fixes tsimps stmts
   132           |> add_simps "simps" [] mutual_info fixes tsimps stmts
   131           |> LocalTheory.note ((qualify "induct", []), tinduct) |> snd
   133           |> LocalTheory.note ((qualify "induct", []), tinduct) |> snd
   132     end
   134     end
   133 
   135 
   134 
   136 
   135 fun fundef_setup_termination_proof name_opt lthy =
   137 fun setup_termination_proof name_opt lthy =
   136     let
   138     let
   137         val name = the_default (get_last_fundef (Context.Proof lthy)) name_opt
   139         val name = the_default (get_last_fundef (Context.Proof lthy)) name_opt
   138         val data = the (get_fundef_data name (Context.Proof lthy))
   140         val data = the (get_fundef_data name (Context.Proof lthy))
   139                    handle Option.Option => raise ERROR ("No such function definition: " ^ name)
   141                    handle Option.Option => raise ERROR ("No such function definition: " ^ name)
   140 
   142 
   188 
   190 
   189 val functionP =
   191 val functionP =
   190   OuterSyntax.command "function" "define general recursive functions" K.thy_goal
   192   OuterSyntax.command "function" "define general recursive functions" K.thy_goal
   191   ((config_parser default_config -- P.opt_locale_target -- P.fixes --| P.$$$ "where" -- statements_ow)
   193   ((config_parser default_config -- P.opt_locale_target -- P.fixes --| P.$$$ "where" -- statements_ow)
   192      >> (fn (((config, target), fixes), statements) =>
   194      >> (fn (((config, target), fixes), statements) =>
   193             Toplevel.print o
   195             Toplevel.local_theory_to_proof target (add_fundef fixes statements config #> snd)
   194             Toplevel.local_theory_to_proof target (add_fundef fixes statements config)));
   196             #> Toplevel.print));
   195 
   197 
   196 
   198 
   197 
   199 
   198 val terminationP =
   200 val terminationP =
   199   OuterSyntax.command "termination" "prove termination of a recursive function" K.thy_goal
   201   OuterSyntax.command "termination" "prove termination of a recursive function" K.thy_goal
   200   (P.opt_locale_target -- Scan.option P.name
   202   (P.opt_locale_target -- Scan.option P.name
   201     >> (fn (target, name) =>
   203     >> (fn (target, name) =>
   202            Toplevel.print o
   204            Toplevel.print o
   203            Toplevel.local_theory_to_proof target (fundef_setup_termination_proof name)));
   205            Toplevel.local_theory_to_proof target (setup_termination_proof name)));
   204 
   206 
   205 
   207 
   206 val _ = OuterSyntax.add_parsers [functionP];
   208 val _ = OuterSyntax.add_parsers [functionP];
   207 val _ = OuterSyntax.add_parsers [terminationP];
   209 val _ = OuterSyntax.add_parsers [terminationP];
   208 val _ = OuterSyntax.add_keywords ["sequential", "otherwise"];
   210 val _ = OuterSyntax.add_keywords ["sequential", "otherwise"];