src/HOL/Tools/recdef_package.ML
author wenzelm
Wed Jan 03 21:25:23 2001 +0100 (2001-01-03)
changeset 10775 3a5e5657e41c
parent 10268 ca52783f9801
child 11629 481148b273b5
permissions -rw-r--r--
added recdef_tc(_i);
wenzelm@6429
     1
(*  Title:      HOL/Tools/recdef_package.ML
wenzelm@6429
     2
    ID:         $Id$
wenzelm@6429
     3
    Author:     Markus Wenzel, TU Muenchen
wenzelm@9876
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
wenzelm@6429
     5
wenzelm@6429
     6
Wrapper module for Konrad Slind's TFL package.
wenzelm@6429
     7
*)
wenzelm@6429
     8
wenzelm@6429
     9
signature RECDEF_PACKAGE =
wenzelm@6429
    10
sig
wenzelm@6429
    11
  val quiet_mode: bool ref
wenzelm@6439
    12
  val print_recdefs: theory -> unit
wenzelm@8657
    13
  val get_recdef: theory -> string
wenzelm@8657
    14
    -> {simps: thm list, rules: thm list list, induct: thm, tcs: term list} option
wenzelm@9859
    15
  val simp_add_global: theory attribute
wenzelm@9859
    16
  val simp_del_global: theory attribute
wenzelm@9859
    17
  val cong_add_global: theory attribute
wenzelm@9859
    18
  val cong_del_global: theory attribute
wenzelm@9859
    19
  val wf_add_global: theory attribute
wenzelm@9859
    20
  val wf_del_global: theory attribute
wenzelm@9859
    21
  val simp_add_local: Proof.context attribute
wenzelm@9859
    22
  val simp_del_local: Proof.context attribute
wenzelm@9859
    23
  val cong_add_local: Proof.context attribute
wenzelm@9859
    24
  val cong_del_local: Proof.context attribute
wenzelm@9859
    25
  val wf_add_local: Proof.context attribute
wenzelm@9859
    26
  val wf_del_local: Proof.context attribute
wenzelm@9859
    27
  val add_recdef: xstring -> string -> ((bstring * string) * Args.src list) list ->
wenzelm@9859
    28
    Args.src option -> theory -> theory
wenzelm@9859
    29
      * {simps: thm list, rules: thm list list, induct: thm, tcs: term list}
wenzelm@9859
    30
  val add_recdef_i: xstring -> term -> ((bstring * term) * theory attribute list) list ->
wenzelm@9859
    31
    theory -> theory * {simps: thm list, rules: thm list list, induct: thm, tcs: term list}
wenzelm@9859
    32
  val add_recdef_old: xstring -> string -> ((bstring * string) * Args.src list) list ->
wenzelm@9859
    33
    simpset * thm list -> theory ->
wenzelm@9859
    34
    theory * {simps: thm list, rules: thm list list, induct: thm, tcs: term list}
wenzelm@6557
    35
  val defer_recdef: xstring -> string list -> (xstring * Args.src list) list
wenzelm@6557
    36
    -> theory -> theory * {induct_rules: thm}
wenzelm@6557
    37
  val defer_recdef_i: xstring -> term list -> (thm * theory attribute list) list
wenzelm@6557
    38
    -> theory -> theory * {induct_rules: thm}
wenzelm@10775
    39
  val recdef_tc: bstring * Args.src list -> xstring -> int option
wenzelm@10775
    40
    -> bool -> theory -> ProofHistory.T
wenzelm@10775
    41
  val recdef_tc_i: bstring * theory attribute list -> string -> int option
wenzelm@10775
    42
    -> bool -> theory -> ProofHistory.T
wenzelm@6439
    43
  val setup: (theory -> theory) list
wenzelm@6429
    44
end;
wenzelm@6429
    45
wenzelm@6429
    46
structure RecdefPackage: RECDEF_PACKAGE =
wenzelm@6429
    47
struct
wenzelm@6429
    48
wenzelm@9859
    49
wenzelm@6429
    50
val quiet_mode = Tfl.quiet_mode;
wenzelm@6429
    51
val message = Tfl.message;
wenzelm@6429
    52
wenzelm@6429
    53
wenzelm@9859
    54
(** recdef hints **)
wenzelm@6439
    55
wenzelm@9859
    56
(* type hints *)
wenzelm@9859
    57
wenzelm@9859
    58
type hints = {simps: thm list, congs: (string * thm) list, wfs: thm list};
wenzelm@9859
    59
wenzelm@9859
    60
fun mk_hints (simps, congs, wfs) = {simps = simps, congs = congs, wfs = wfs}: hints;
wenzelm@9859
    61
fun map_hints f ({simps, congs, wfs}: hints) = mk_hints (f (simps, congs, wfs));
wenzelm@9859
    62
wenzelm@9859
    63
fun map_simps f = map_hints (fn (simps, congs, wfs) => (f simps, congs, wfs));
wenzelm@9859
    64
fun map_congs f = map_hints (fn (simps, congs, wfs) => (simps, f congs, wfs));
wenzelm@9859
    65
fun map_wfs f = map_hints (fn (simps, congs, wfs) => (simps, congs, f wfs));
wenzelm@9859
    66
wenzelm@9859
    67
fun pretty_hints ({simps, congs, wfs}: hints) =
wenzelm@9859
    68
 [Pretty.big_list "recdef simp hints:" (map Display.pretty_thm simps),
wenzelm@9859
    69
  Pretty.big_list "recdef cong hints:" (map Display.pretty_thm (map #2 congs)),
wenzelm@9859
    70
  Pretty.big_list "recdef wf hints:" (map Display.pretty_thm wfs)];
wenzelm@9859
    71
wenzelm@9859
    72
wenzelm@9859
    73
(* congruence rules *)
wenzelm@9859
    74
wenzelm@9859
    75
local
wenzelm@9859
    76
wenzelm@9859
    77
val cong_head =
wenzelm@9859
    78
  fst o Term.dest_Const o Term.head_of o fst o Logic.dest_equals o Thm.concl_of;
wenzelm@6439
    79
wenzelm@9859
    80
fun prep_cong raw_thm =
wenzelm@9859
    81
  let val thm = safe_mk_meta_eq raw_thm in (cong_head thm, thm) end;
wenzelm@9859
    82
wenzelm@9859
    83
in
wenzelm@9859
    84
wenzelm@9859
    85
fun add_cong raw_thm congs =
wenzelm@9859
    86
  let val (c, thm) = prep_cong raw_thm
wenzelm@9859
    87
  in overwrite_warn (congs, (c, thm)) ("Overwriting recdef congruence rule for " ^ quote c) end;
wenzelm@9859
    88
wenzelm@9859
    89
fun del_cong raw_thm congs =
wenzelm@9859
    90
  let
wenzelm@9859
    91
    val (c, thm) = prep_cong raw_thm;
wenzelm@9859
    92
    val (del, rest) = Library.partition (Library.equal c o fst) congs;
wenzelm@9859
    93
  in if null del then (warning ("No recdef congruence rule for " ^ quote c); congs) else rest end;
wenzelm@9859
    94
wenzelm@9859
    95
val add_congs = curry (foldr (uncurry add_cong));
wenzelm@9859
    96
wenzelm@9859
    97
end;
wenzelm@9859
    98
wenzelm@9859
    99
wenzelm@9859
   100
wenzelm@9859
   101
(** global and local recdef data **)
wenzelm@9859
   102
wenzelm@9859
   103
(* theory data kind 'HOL/recdef' *)
wenzelm@6439
   104
wenzelm@8657
   105
type recdef_info = {simps: thm list, rules: thm list list, induct: thm, tcs: term list};
wenzelm@6439
   106
wenzelm@9859
   107
structure GlobalRecdefArgs =
wenzelm@6439
   108
struct
wenzelm@6439
   109
  val name = "HOL/recdef";
wenzelm@9859
   110
  type T = recdef_info Symtab.table * hints;
wenzelm@6439
   111
wenzelm@9879
   112
  val empty = (Symtab.empty, mk_hints ([], [], [])): T;
wenzelm@6557
   113
  val copy = I;
wenzelm@6439
   114
  val prep_ext = I;
wenzelm@9859
   115
  fun merge
wenzelm@9859
   116
   ((tab1, {simps = simps1, congs = congs1, wfs = wfs1}),
wenzelm@9859
   117
    (tab2, {simps = simps2, congs = congs2, wfs = wfs2})) =
wenzelm@9859
   118
      (Symtab.merge (K true) (tab1, tab2),
wenzelm@9859
   119
        mk_hints (Drule.merge_rules (simps1, simps2),
wenzelm@9859
   120
          Library.merge_alists congs1 congs2,
wenzelm@9859
   121
          Drule.merge_rules (wfs1, wfs2)));
wenzelm@6439
   122
wenzelm@9859
   123
  fun print sg (tab, hints) =
wenzelm@9859
   124
   (Pretty.strs ("recdefs:" :: map #1 (Sign.cond_extern_table sg Sign.constK tab)) ::
wenzelm@9859
   125
     pretty_hints hints) |> Pretty.chunks |> Pretty.writeln;
wenzelm@6439
   126
end;
wenzelm@6439
   127
wenzelm@9859
   128
structure GlobalRecdefData = TheoryDataFun(GlobalRecdefArgs);
wenzelm@9859
   129
val print_recdefs = GlobalRecdefData.print;
wenzelm@6429
   130
wenzelm@6439
   131
wenzelm@9859
   132
fun get_recdef thy name = Symtab.lookup (#1 (GlobalRecdefData.get thy), name);
wenzelm@6439
   133
wenzelm@6439
   134
fun put_recdef name info thy =
wenzelm@6429
   135
  let
wenzelm@9859
   136
    val (tab, hints) = GlobalRecdefData.get thy;
wenzelm@9859
   137
    val tab' = Symtab.update_new ((name, info), tab)
wenzelm@6439
   138
      handle Symtab.DUP _ => error ("Duplicate recursive function definition " ^ quote name);
wenzelm@9859
   139
  in GlobalRecdefData.put (tab', hints) thy end;
wenzelm@9859
   140
wenzelm@9859
   141
val get_global_hints = #2 o GlobalRecdefData.get;
wenzelm@9859
   142
val map_global_hints = GlobalRecdefData.map o apsnd;
wenzelm@9859
   143
wenzelm@9859
   144
wenzelm@9859
   145
(* proof data kind 'HOL/recdef' *)
wenzelm@9859
   146
wenzelm@9859
   147
structure LocalRecdefArgs =
wenzelm@9859
   148
struct
wenzelm@9859
   149
  val name = "HOL/recdef";
wenzelm@9859
   150
  type T = hints;
wenzelm@9859
   151
  val init = get_global_hints;
wenzelm@9859
   152
  fun print _ hints = pretty_hints hints |> Pretty.chunks |> Pretty.writeln;
wenzelm@9859
   153
end;
wenzelm@9859
   154
wenzelm@9859
   155
structure LocalRecdefData = ProofDataFun(LocalRecdefArgs);
wenzelm@9859
   156
val get_local_hints = LocalRecdefData.get;
wenzelm@9859
   157
val map_local_hints = LocalRecdefData.map;
wenzelm@9859
   158
wenzelm@9859
   159
wenzelm@9859
   160
(* attributes *)
wenzelm@9859
   161
wenzelm@9859
   162
local
wenzelm@9859
   163
wenzelm@9859
   164
fun global_local f g =
wenzelm@9859
   165
 (fn (thy, thm) => (map_global_hints (f (g thm)) thy, thm),
wenzelm@9859
   166
  fn (ctxt, thm) => (map_local_hints (f (g thm)) ctxt, thm));
wenzelm@9859
   167
wenzelm@9859
   168
fun mk_attr (add1, add2) (del1, del2) =
wenzelm@9859
   169
 (Attrib.add_del_args add1 del1, Attrib.add_del_args add2 del2);
wenzelm@9859
   170
wenzelm@9859
   171
in
wenzelm@9859
   172
wenzelm@9859
   173
val (simp_add_global, simp_add_local) = global_local map_simps (Drule.add_rules o single);
wenzelm@9859
   174
val (simp_del_global, simp_del_local) = global_local map_simps (Drule.del_rules o single);
wenzelm@9859
   175
val (cong_add_global, cong_add_local) = global_local map_congs add_cong;
wenzelm@9859
   176
val (cong_del_global, cong_del_local) = global_local map_congs del_cong;
wenzelm@9859
   177
val (wf_add_global, wf_add_local) = global_local map_wfs (Drule.add_rules o single);
wenzelm@9859
   178
val (wf_del_global, wf_del_local) = global_local map_wfs (Drule.del_rules o single);
wenzelm@9859
   179
wenzelm@9859
   180
val simp_attr = mk_attr (simp_add_global, simp_add_local) (simp_del_global, simp_del_local);
wenzelm@9859
   181
val cong_attr = mk_attr (cong_add_global, cong_add_local) (cong_del_global, cong_del_local);
wenzelm@9859
   182
val wf_attr = mk_attr (wf_add_global, wf_add_local) (wf_del_global, wf_del_local);
wenzelm@9859
   183
wenzelm@9859
   184
end;
wenzelm@9859
   185
wenzelm@9859
   186
wenzelm@9949
   187
(* modifiers *)
wenzelm@9859
   188
wenzelm@9949
   189
val recdef_simpN = "recdef_simp";
wenzelm@9949
   190
val recdef_congN = "recdef_cong";
wenzelm@9949
   191
val recdef_wfN = "recdef_wf";
wenzelm@9859
   192
wenzelm@9859
   193
val recdef_modifiers =
wenzelm@9949
   194
 [Args.$$$ recdef_simpN -- Args.colon >> K ((I, simp_add_local): Method.modifier),
wenzelm@10032
   195
  Args.$$$ recdef_simpN -- Args.add -- Args.colon >> K (I, simp_add_local),
wenzelm@10032
   196
  Args.$$$ recdef_simpN -- Args.del -- Args.colon >> K (I, simp_del_local),
wenzelm@9949
   197
  Args.$$$ recdef_congN -- Args.colon >> K (I, cong_add_local),
wenzelm@10032
   198
  Args.$$$ recdef_congN -- Args.add -- Args.colon >> K (I, cong_add_local),
wenzelm@10032
   199
  Args.$$$ recdef_congN -- Args.del -- Args.colon >> K (I, cong_del_local),
wenzelm@9949
   200
  Args.$$$ recdef_wfN -- Args.colon >> K (I, wf_add_local),
wenzelm@10032
   201
  Args.$$$ recdef_wfN -- Args.add -- Args.colon >> K (I, wf_add_local),
wenzelm@10032
   202
  Args.$$$ recdef_wfN -- Args.del -- Args.colon >> K (I, wf_del_local)] @
wenzelm@9949
   203
  Clasimp.clasimp_modifiers;
wenzelm@9859
   204
wenzelm@9949
   205
wenzelm@9859
   206
wenzelm@9949
   207
(** prepare_hints(_i) **)
wenzelm@9859
   208
wenzelm@9859
   209
fun prepare_hints thy opt_src =
wenzelm@9859
   210
  let
wenzelm@9859
   211
    val ctxt0 = ProofContext.init thy;
wenzelm@9859
   212
    val ctxt =
wenzelm@9859
   213
      (case opt_src of
wenzelm@9859
   214
        None => ctxt0
wenzelm@9949
   215
      | Some src => Method.only_sectioned_args recdef_modifiers I src ctxt0);
wenzelm@9859
   216
    val {simps, congs, wfs} = get_local_hints ctxt;
wenzelm@9859
   217
    val cs = Classical.get_local_claset ctxt;
wenzelm@9859
   218
    val ss = Simplifier.get_local_simpset ctxt addsimps simps;
wenzelm@9859
   219
  in (cs, ss, map #2 congs, wfs) end;
wenzelm@9859
   220
wenzelm@9859
   221
fun prepare_hints_i thy () =
wenzelm@9859
   222
  let val {simps, congs, wfs} = get_global_hints thy
wenzelm@9859
   223
  in (Classical.claset_of thy, Simplifier.simpset_of thy addsimps simps, map #2 congs, wfs) end;
wenzelm@9859
   224
wenzelm@6439
   225
wenzelm@6439
   226
wenzelm@6439
   227
(** add_recdef(_i) **)
wenzelm@6439
   228
wenzelm@6557
   229
fun requires_recdef thy = Theory.requires thy "Recdef" "recursive functions";
wenzelm@6557
   230
wenzelm@9859
   231
fun gen_add_recdef tfl_fn prep_att prep_hints raw_name R eq_srcs hints thy =
wenzelm@6439
   232
  let
wenzelm@9859
   233
    val _ = requires_recdef thy;
wenzelm@9859
   234
wenzelm@6439
   235
    val name = Sign.intern_const (Theory.sign_of thy) raw_name;
wenzelm@6439
   236
    val bname = Sign.base_name name;
wenzelm@6429
   237
    val _ = message ("Defining recursive function " ^ quote name ^ " ...");
wenzelm@6429
   238
wenzelm@8657
   239
    val ((eq_names, eqs), raw_eq_atts) = apfst split_list (split_list eq_srcs);
wenzelm@8657
   240
    val eq_atts = map (map (prep_att thy)) raw_eq_atts;
wenzelm@8657
   241
wenzelm@9859
   242
    val (cs, ss, congs, wfs) = prep_hints thy hints;
wenzelm@9859
   243
    val (thy, {rules = rules_idx, induct, tcs}) = tfl_fn thy cs ss congs wfs name R eqs;
wenzelm@8657
   244
    val rules = map (map #1) (Library.partition_eq Library.eq_snd rules_idx);
wenzelm@8657
   245
    val simp_att = if null tcs then [Simplifier.simp_add_global] else [];
wenzelm@8657
   246
wenzelm@8430
   247
    val case_numbers = map Library.string_of_int (1 upto Thm.nprems_of induct);
wenzelm@8657
   248
    val (thy, (simps' :: rules', [induct'])) =
wenzelm@7798
   249
      thy
wenzelm@6439
   250
      |> Theory.add_path bname
wenzelm@8657
   251
      |> PureThy.add_thmss ((("simps", flat rules), simp_att) :: ((eq_names ~~ rules) ~~ eq_atts))
wenzelm@8430
   252
      |>>> PureThy.add_thms [(("induct", induct), [RuleCases.case_names case_numbers])];
wenzelm@8657
   253
    val result = {simps = simps', rules = rules', induct = induct', tcs = tcs};
wenzelm@7798
   254
    val thy =
wenzelm@7798
   255
      thy
wenzelm@6439
   256
      |> put_recdef name result
wenzelm@6429
   257
      |> Theory.parent_path;
wenzelm@7798
   258
  in (thy, result) end;
wenzelm@6429
   259
wenzelm@9859
   260
val add_recdef = gen_add_recdef Tfl.define Attrib.global_attribute prepare_hints;
wenzelm@9859
   261
fun add_recdef_i x y z = gen_add_recdef Tfl.define_i (K I) prepare_hints_i x y z ();
wenzelm@9859
   262
wenzelm@9859
   263
wenzelm@9859
   264
(* add_recdef_old -- legacy interface *)
wenzelm@9859
   265
wenzelm@9859
   266
fun prepare_hints_old thy (ss, thms) =
wenzelm@9859
   267
  let val {simps, congs, wfs} = get_global_hints thy
wenzelm@9859
   268
  in (Classical.claset_of thy, ss addsimps simps, map #2 (add_congs thms congs), wfs) end;
wenzelm@9859
   269
wenzelm@9859
   270
val add_recdef_old = gen_add_recdef Tfl.define Attrib.global_attribute prepare_hints_old;
wenzelm@6429
   271
wenzelm@6429
   272
wenzelm@6557
   273
wenzelm@6557
   274
(** defer_recdef(_i) **)
wenzelm@6557
   275
wenzelm@6557
   276
fun gen_defer_recdef tfl_fn app_thms raw_name eqs raw_congs thy =
wenzelm@6557
   277
  let
wenzelm@6557
   278
    val name = Sign.intern_const (Theory.sign_of thy) raw_name;
wenzelm@6557
   279
    val bname = Sign.base_name name;
wenzelm@6557
   280
wenzelm@6557
   281
    val _ = requires_recdef thy;
wenzelm@6557
   282
    val _ = message ("Deferred recursive function " ^ quote name ^ " ...");
wenzelm@6557
   283
wenzelm@6557
   284
    val (thy1, congs) = thy |> app_thms raw_congs;
wenzelm@9859
   285
    val (thy2, induct_rules) = tfl_fn thy1 congs name eqs;
wenzelm@8430
   286
    val (thy3, [induct_rules']) =
wenzelm@6557
   287
      thy2
wenzelm@6557
   288
      |> Theory.add_path bname
wenzelm@6557
   289
      |> PureThy.add_thms [(("induct_rules", induct_rules), [])]
wenzelm@8430
   290
      |>> Theory.parent_path;
wenzelm@8430
   291
  in (thy3, {induct_rules = induct_rules'}) end;
wenzelm@6557
   292
wenzelm@6557
   293
val defer_recdef = gen_defer_recdef Tfl.defer IsarThy.apply_theorems;
wenzelm@6557
   294
val defer_recdef_i = gen_defer_recdef Tfl.defer_i IsarThy.apply_theorems_i;
wenzelm@6557
   295
wenzelm@6557
   296
wenzelm@6557
   297
wenzelm@10775
   298
(** recdef_tc(_i) **)
wenzelm@10775
   299
wenzelm@10775
   300
fun gen_recdef_tc prep_att prep_name (bname, raw_atts) raw_name opt_i int thy =
wenzelm@10775
   301
  let
wenzelm@10775
   302
    val name = prep_name (Theory.sign_of thy) raw_name;
wenzelm@10775
   303
    val atts = map (prep_att thy) raw_atts;
wenzelm@10775
   304
    val tcs =
wenzelm@10775
   305
      (case get_recdef thy name of
wenzelm@10775
   306
        None => error ("No recdef definition of constant: " ^ quote name)
wenzelm@10775
   307
      | Some {tcs, ...} => tcs);
wenzelm@10775
   308
    val i = if_none opt_i 1;
wenzelm@10775
   309
    val tc = Library.nth_elem (i - 1, tcs) handle Library.LIST _ =>
wenzelm@10775
   310
      error ("No termination condition #" ^ string_of_int i ^
wenzelm@10775
   311
        " in recdef definition of " ^ quote name);
wenzelm@10775
   312
  in
wenzelm@10775
   313
    thy
wenzelm@10775
   314
    |> IsarThy.theorem_i (((bname, atts), (HOLogic.mk_Trueprop tc, ([], []))), Comment.none) int
wenzelm@10775
   315
  end;
wenzelm@10775
   316
wenzelm@10775
   317
val recdef_tc = gen_recdef_tc Attrib.global_attribute Sign.intern_const;
wenzelm@10775
   318
val recdef_tc_i = gen_recdef_tc (K I) (K I);
wenzelm@10775
   319
wenzelm@10775
   320
wenzelm@10775
   321
wenzelm@6439
   322
(** package setup **)
wenzelm@6439
   323
wenzelm@6439
   324
(* setup theory *)
wenzelm@6439
   325
wenzelm@9859
   326
val setup =
wenzelm@9859
   327
 [GlobalRecdefData.init, LocalRecdefData.init,
wenzelm@9859
   328
  Attrib.add_attributes
wenzelm@9949
   329
   [(recdef_simpN, simp_attr, "declaration of recdef simp rule"),
wenzelm@9949
   330
    (recdef_congN, cong_attr, "declaration of recdef cong rule"),
wenzelm@9949
   331
    (recdef_wfN, wf_attr, "declaration of recdef wf rule")]];
wenzelm@6439
   332
wenzelm@6439
   333
wenzelm@6429
   334
(* outer syntax *)
wenzelm@6429
   335
wenzelm@6723
   336
local structure P = OuterParse and K = OuterSyntax.Keyword in
wenzelm@6429
   337
wenzelm@9859
   338
val hints =
wenzelm@9859
   339
  P.$$$ "(" |-- P.!!! (P.position (P.$$$ "hints" -- P.arguments) --| P.$$$ ")") >> Args.src;
wenzelm@9859
   340
wenzelm@6429
   341
val recdef_decl =
wenzelm@9859
   342
  P.name -- P.term -- Scan.repeat1 (P.opt_thm_name ":" -- P.prop --| P.marg_comment)
wenzelm@9859
   343
    -- Scan.option hints
wenzelm@9859
   344
  >> (fn (((f, R), eqs), src) => #1 o add_recdef f R (map P.triple_swap eqs) src);
wenzelm@6429
   345
wenzelm@6429
   346
val recdefP =
wenzelm@6723
   347
  OuterSyntax.command "recdef" "define general recursive functions (TFL)" K.thy_decl
wenzelm@6429
   348
    (recdef_decl >> Toplevel.theory);
wenzelm@6429
   349
wenzelm@6557
   350
wenzelm@6557
   351
val defer_recdef_decl =
wenzelm@8657
   352
  P.name -- Scan.repeat1 P.prop --
wenzelm@6723
   353
  Scan.optional (P.$$$ "(" |-- P.$$$ "congs" |-- P.!!! (P.xthms1 --| P.$$$ ")")) []
wenzelm@6557
   354
  >> (fn ((f, eqs), congs) => #1 o defer_recdef f eqs congs);
wenzelm@6557
   355
wenzelm@6557
   356
val defer_recdefP =
wenzelm@6723
   357
  OuterSyntax.command "defer_recdef" "defer general recursive functions (TFL)" K.thy_decl
wenzelm@6557
   358
    (defer_recdef_decl >> Toplevel.theory);
wenzelm@6557
   359
wenzelm@10775
   360
wenzelm@10775
   361
val recdef_tc_decl =
wenzelm@10775
   362
  P.opt_thm_name ":" -- P.xname -- Scan.option (P.$$$ "(" |-- P.nat --| P.$$$ ")")
wenzelm@10775
   363
    --| P.marg_comment;
wenzelm@10775
   364
wenzelm@10775
   365
fun mk_recdef_tc ((thm_name, name), i) = recdef_tc thm_name name i;
wenzelm@10775
   366
wenzelm@10775
   367
val recdef_tcP =
wenzelm@10775
   368
  OuterSyntax.command "recdef_tc" "recommence proof of termination condition (TFL)" K.thy_goal
wenzelm@10775
   369
    (recdef_tc_decl >> (Toplevel.print oo (Toplevel.theory_to_proof o mk_recdef_tc)));
wenzelm@10775
   370
wenzelm@10775
   371
wenzelm@9999
   372
val _ = OuterSyntax.add_keywords ["congs", "hints"];
wenzelm@10775
   373
val _ = OuterSyntax.add_parsers [recdefP, defer_recdefP, recdef_tcP];
wenzelm@6429
   374
wenzelm@6429
   375
end;
wenzelm@6429
   376
wenzelm@6429
   377
wenzelm@6429
   378
end;