src/HOL/Tools/recdef.ML
author haftmann
Thu, 08 Jul 2010 16:19:24 +0200
changeset 37744 3daaf23b9ab4
parent 36960 01594f816e3a
child 39557 fe5722fce758
permissions -rw-r--r--
tuned titles
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31723
f5cafe803b55 discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents: 31243
diff changeset
     1
(*  Title:      HOL/Tools/recdef.ML
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
     2
    Author:     Markus Wenzel, TU Muenchen
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
     3
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
     4
Wrapper module for Konrad Slind's TFL package.
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
     5
*)
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
     6
31723
f5cafe803b55 discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents: 31243
diff changeset
     7
signature RECDEF =
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
     8
sig
8657
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
     9
  val get_recdef: theory -> string
35756
cfde251d03a5 refining and adding Spec_Rules to definitional packages old_primrec, primrec, recdef, size and function
bulwahn
parents: 35690
diff changeset
    10
    -> {lhs: term, simps: thm list, rules: thm list list, induct: thm, tcs: term list} option
21505
13d4dba99337 prefer Proof.context over Context.generic;
wenzelm
parents: 21434
diff changeset
    11
  val get_hints: Proof.context -> {simps: thm list, congs: (string * thm) list, wfs: thm list}
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    12
  val simp_add: attribute
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    13
  val simp_del: attribute
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    14
  val cong_add: attribute
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    15
  val cong_del: attribute
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    16
  val wf_add: attribute
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    17
  val wf_del: attribute
29579
cb520b766e00 binding replaces bstring
haftmann
parents: 29006
diff changeset
    18
  val add_recdef: bool -> xstring -> string -> ((binding * string) * Attrib.src list) list ->
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15574
diff changeset
    19
    Attrib.src option -> theory -> theory
35756
cfde251d03a5 refining and adding Spec_Rules to definitional packages old_primrec, primrec, recdef, size and function
bulwahn
parents: 35690
diff changeset
    20
      * {lhs: term, simps: thm list, rules: thm list list, induct: thm, tcs: term list}
29579
cb520b766e00 binding replaces bstring
haftmann
parents: 29006
diff changeset
    21
  val add_recdef_i: bool -> xstring -> term -> ((binding * term) * attribute list) list ->
35756
cfde251d03a5 refining and adding Spec_Rules to definitional packages old_primrec, primrec, recdef, size and function
bulwahn
parents: 35690
diff changeset
    22
    theory -> theory * {lhs: term, simps: thm list, rules: thm list list, induct: thm, tcs: term list}
26336
a0e2b706ce73 renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents: 24927
diff changeset
    23
  val defer_recdef: xstring -> string list -> (Facts.ref * Attrib.src list) list
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
    24
    -> theory -> theory * {induct_rules: thm}
27727
2397e310b2cc simplified defer_recdef(_i): plain facts via Attrib.eval_thms;
wenzelm
parents: 27353
diff changeset
    25
  val defer_recdef_i: xstring -> term list -> thm list -> theory -> theory * {induct_rules: thm}
2397e310b2cc simplified defer_recdef(_i): plain facts via Attrib.eval_thms;
wenzelm
parents: 27353
diff changeset
    26
  val recdef_tc: bstring * Attrib.src list -> xstring -> int option -> bool ->
2397e310b2cc simplified defer_recdef(_i): plain facts via Attrib.eval_thms;
wenzelm
parents: 27353
diff changeset
    27
    local_theory -> Proof.state
2397e310b2cc simplified defer_recdef(_i): plain facts via Attrib.eval_thms;
wenzelm
parents: 27353
diff changeset
    28
  val recdef_tc_i: bstring * Attrib.src list -> string -> int option -> bool ->
2397e310b2cc simplified defer_recdef(_i): plain facts via Attrib.eval_thms;
wenzelm
parents: 27353
diff changeset
    29
    local_theory -> Proof.state
18708
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18688
diff changeset
    30
  val setup: theory -> theory
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    31
end;
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    32
31723
f5cafe803b55 discontinued ancient tradition to suffix certain ML module names with "_package"
haftmann
parents: 31243
diff changeset
    33
structure Recdef: RECDEF =
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    34
struct
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    35
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    36
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    37
(** recdef hints **)
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
    38
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    39
(* type hints *)
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    40
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    41
type hints = {simps: thm list, congs: (string * thm) list, wfs: thm list};
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    42
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    43
fun mk_hints (simps, congs, wfs) = {simps = simps, congs = congs, wfs = wfs}: hints;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    44
fun map_hints f ({simps, congs, wfs}: hints) = mk_hints (f (simps, congs, wfs));
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    45
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    46
fun map_simps f = map_hints (fn (simps, congs, wfs) => (f simps, congs, wfs));
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    47
fun map_congs f = map_hints (fn (simps, congs, wfs) => (simps, f congs, wfs));
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    48
fun map_wfs f = map_hints (fn (simps, congs, wfs) => (simps, congs, f wfs));
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    49
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    50
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    51
(* congruence rules *)
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    52
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    53
local
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    54
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    55
val cong_head =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    56
  fst o Term.dest_Const o Term.head_of o fst o Logic.dest_equals o Thm.concl_of;
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
    57
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    58
fun prep_cong raw_thm =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    59
  let val thm = safe_mk_meta_eq raw_thm in (cong_head thm, thm) end;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    60
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    61
in
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    62
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    63
fun add_cong raw_thm congs =
21098
d0d8a48ae4e6 switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents: 21078
diff changeset
    64
  let
d0d8a48ae4e6 switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents: 21078
diff changeset
    65
    val (c, thm) = prep_cong raw_thm;
d0d8a48ae4e6 switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents: 21078
diff changeset
    66
    val _ = if AList.defined (op =) congs c
d0d8a48ae4e6 switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents: 21078
diff changeset
    67
      then warning ("Overwriting recdef congruence rule for " ^ quote c)
d0d8a48ae4e6 switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents: 21078
diff changeset
    68
      else ();
d0d8a48ae4e6 switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents: 21078
diff changeset
    69
  in AList.update (op =) (c, thm) congs end;
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    70
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    71
fun del_cong raw_thm congs =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    72
  let
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    73
    val (c, thm) = prep_cong raw_thm;
21098
d0d8a48ae4e6 switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents: 21078
diff changeset
    74
    val _ = if AList.defined (op =) congs c
d0d8a48ae4e6 switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents: 21078
diff changeset
    75
      then ()
d0d8a48ae4e6 switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents: 21078
diff changeset
    76
      else warning ("No recdef congruence rule for " ^ quote c);
d0d8a48ae4e6 switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents: 21078
diff changeset
    77
  in AList.delete (op =) c congs end;
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    78
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    79
end;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    80
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    81
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    82
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    83
(** global and local recdef data **)
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    84
17920
5c3e9415c653 removed obsolete add_recdef_old;
wenzelm
parents: 17593
diff changeset
    85
(* theory data *)
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
    86
35756
cfde251d03a5 refining and adding Spec_Rules to definitional packages old_primrec, primrec, recdef, size and function
bulwahn
parents: 35690
diff changeset
    87
type recdef_info = {lhs: term, simps: thm list, rules: thm list list, induct: thm, tcs: term list};
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
    88
33522
737589bb9bb8 adapted Theory_Data;
wenzelm
parents: 33519
diff changeset
    89
structure GlobalRecdefData = Theory_Data
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22360
diff changeset
    90
(
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    91
  type T = recdef_info Symtab.table * hints;
9879
a1fcaf2d080d make SML/NJ happy;
wenzelm
parents: 9876
diff changeset
    92
  val empty = (Symtab.empty, mk_hints ([], [], [])): T;
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
    93
  val extend = I;
33522
737589bb9bb8 adapted Theory_Data;
wenzelm
parents: 33519
diff changeset
    94
  fun merge
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    95
   ((tab1, {simps = simps1, congs = congs1, wfs = wfs1}),
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
    96
    (tab2, {simps = simps2, congs = congs2, wfs = wfs2})) : T =
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    97
      (Symtab.merge (K true) (tab1, tab2),
24039
273698405054 renamed Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 22846
diff changeset
    98
        mk_hints (Thm.merge_thms (simps1, simps2),
33699
f33b036ef318 permissive AList.merge -- most likely setup for theory data (beware of spurious AList.DUP);
wenzelm
parents: 33643
diff changeset
    99
          AList.merge (op =) (K true) (congs1, congs2),
24039
273698405054 renamed Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 22846
diff changeset
   100
          Thm.merge_thms (wfs1, wfs2)));
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22360
diff changeset
   101
);
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   102
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17336
diff changeset
   103
val get_recdef = Symtab.lookup o #1 o GlobalRecdefData.get;
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   104
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   105
fun put_recdef name info thy =
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   106
  let
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   107
    val (tab, hints) = GlobalRecdefData.get thy;
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17336
diff changeset
   108
    val tab' = Symtab.update_new (name, info) tab
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   109
      handle Symtab.DUP _ => error ("Duplicate recursive function definition " ^ quote name);
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   110
  in GlobalRecdefData.put (tab', hints) thy end;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   111
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   112
val get_global_hints = #2 o GlobalRecdefData.get;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   113
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   114
17920
5c3e9415c653 removed obsolete add_recdef_old;
wenzelm
parents: 17593
diff changeset
   115
(* proof data *)
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   116
33519
e31a85f92ce9 adapted Generic_Data, Proof_Data;
wenzelm
parents: 33278
diff changeset
   117
structure LocalRecdefData = Proof_Data
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22360
diff changeset
   118
(
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   119
  type T = hints;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   120
  val init = get_global_hints;
22846
fb79144af9a3 simplified DataFun interfaces;
wenzelm
parents: 22360
diff changeset
   121
);
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   122
21505
13d4dba99337 prefer Proof.context over Context.generic;
wenzelm
parents: 21434
diff changeset
   123
val get_hints = LocalRecdefData.get;
13d4dba99337 prefer Proof.context over Context.generic;
wenzelm
parents: 21434
diff changeset
   124
fun map_hints f = Context.mapping (GlobalRecdefData.map (apsnd f)) (LocalRecdefData.map f);
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   125
20291
c82b667b6dcc export get_hints;
wenzelm
parents: 19770
diff changeset
   126
c82b667b6dcc export get_hints;
wenzelm
parents: 19770
diff changeset
   127
(* attributes *)
c82b667b6dcc export get_hints;
wenzelm
parents: 19770
diff changeset
   128
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   129
fun attrib f = Thm.declaration_attribute (map_hints o f);
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   130
24039
273698405054 renamed Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 22846
diff changeset
   131
val simp_add = attrib (map_simps o Thm.add_thm);
273698405054 renamed Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 22846
diff changeset
   132
val simp_del = attrib (map_simps o Thm.del_thm);
18688
abf0f018b5ec generic attributes;
wenzelm
parents: 18418
diff changeset
   133
val cong_add = attrib (map_congs o add_cong);
abf0f018b5ec generic attributes;
wenzelm
parents: 18418
diff changeset
   134
val cong_del = attrib (map_congs o del_cong);
24039
273698405054 renamed Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 22846
diff changeset
   135
val wf_add = attrib (map_wfs o Thm.add_thm);
273698405054 renamed Drule.add/del/merge_rules to Thm.add/del/merge_thms;
wenzelm
parents: 22846
diff changeset
   136
val wf_del = attrib (map_wfs o Thm.del_thm);
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   137
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   138
9949
1741a61d4b33 tuned recdef hints;
wenzelm
parents: 9893
diff changeset
   139
(* modifiers *)
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   140
9949
1741a61d4b33 tuned recdef hints;
wenzelm
parents: 9893
diff changeset
   141
val recdef_simpN = "recdef_simp";
1741a61d4b33 tuned recdef hints;
wenzelm
parents: 9893
diff changeset
   142
val recdef_congN = "recdef_cong";
1741a61d4b33 tuned recdef hints;
wenzelm
parents: 9893
diff changeset
   143
val recdef_wfN = "recdef_wf";
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   144
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   145
val recdef_modifiers =
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   146
 [Args.$$$ recdef_simpN -- Args.colon >> K ((I, simp_add): Method.modifier),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   147
  Args.$$$ recdef_simpN -- Args.add -- Args.colon >> K (I, simp_add),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   148
  Args.$$$ recdef_simpN -- Args.del -- Args.colon >> K (I, simp_del),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   149
  Args.$$$ recdef_congN -- Args.colon >> K (I, cong_add),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   150
  Args.$$$ recdef_congN -- Args.add -- Args.colon >> K (I, cong_add),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   151
  Args.$$$ recdef_congN -- Args.del -- Args.colon >> K (I, cong_del),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   152
  Args.$$$ recdef_wfN -- Args.colon >> K (I, wf_add),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   153
  Args.$$$ recdef_wfN -- Args.add -- Args.colon >> K (I, wf_add),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   154
  Args.$$$ recdef_wfN -- Args.del -- Args.colon >> K (I, wf_del)] @
9949
1741a61d4b33 tuned recdef hints;
wenzelm
parents: 9893
diff changeset
   155
  Clasimp.clasimp_modifiers;
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   156
9949
1741a61d4b33 tuned recdef hints;
wenzelm
parents: 9893
diff changeset
   157
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   158
9949
1741a61d4b33 tuned recdef hints;
wenzelm
parents: 9893
diff changeset
   159
(** prepare_hints(_i) **)
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   160
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   161
fun prepare_hints thy opt_src =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   162
  let
36610
bafd82950e24 renamed ProofContext.init to ProofContext.init_global to emphasize that this is not the real thing;
wenzelm
parents: 35756
diff changeset
   163
    val ctxt0 = ProofContext.init_global thy;
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   164
    val ctxt =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   165
      (case opt_src of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15458
diff changeset
   166
        NONE => ctxt0
31243
4c34331a88f9 simplified method syntax;
wenzelm
parents: 31172
diff changeset
   167
      | SOME src => #2 (Method.syntax (Method.sections recdef_modifiers) src ctxt0));
21505
13d4dba99337 prefer Proof.context over Context.generic;
wenzelm
parents: 21434
diff changeset
   168
    val {simps, congs, wfs} = get_hints ctxt;
32149
ef59550a55d3 renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
wenzelm
parents: 32091
diff changeset
   169
    val cs = claset_of ctxt;
ef59550a55d3 renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
wenzelm
parents: 32091
diff changeset
   170
    val ss = simpset_of ctxt addsimps simps;
21098
d0d8a48ae4e6 switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents: 21078
diff changeset
   171
  in (cs, ss, rev (map snd congs), wfs) end;
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   172
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   173
fun prepare_hints_i thy () =
15032
02aed07e01bf local_cla/simpset_of;
wenzelm
parents: 14981
diff changeset
   174
  let
36610
bafd82950e24 renamed ProofContext.init to ProofContext.init_global to emphasize that this is not the real thing;
wenzelm
parents: 35756
diff changeset
   175
    val ctxt0 = ProofContext.init_global thy;
15032
02aed07e01bf local_cla/simpset_of;
wenzelm
parents: 14981
diff changeset
   176
    val {simps, congs, wfs} = get_global_hints thy;
32149
ef59550a55d3 renamed simpset_of to global_simpset_of, and local_simpset_of to simpset_of -- same for claset and clasimpset;
wenzelm
parents: 32091
diff changeset
   177
  in (claset_of ctxt0, simpset_of ctxt0 addsimps simps, rev (map snd congs), wfs) end;
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   178
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   179
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   180
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   181
(** add_recdef(_i) **)
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   182
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   183
fun requires_recdef thy = Theory.requires thy "Recdef" "recursive functions";
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   184
17920
5c3e9415c653 removed obsolete add_recdef_old;
wenzelm
parents: 17593
diff changeset
   185
fun gen_add_recdef tfl_fn prep_att prep_hints not_permissive raw_name R eq_srcs hints thy =
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   186
  let
36865
7330e4eefbd7 updated/unified some legacy warnings;
wenzelm
parents: 36610
diff changeset
   187
    val _ = legacy_feature "Old 'recdef' command -- use 'fun' or 'function' instead";
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   188
    val _ = requires_recdef thy;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   189
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
   190
    val name = Sign.intern_const thy raw_name;
30364
577edc39b501 moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents: 30280
diff changeset
   191
    val bname = Long_Name.base_name name;
26478
9d1029ce0e13 eliminated quiete_mode ref (not really needed);
wenzelm
parents: 26336
diff changeset
   192
    val _ = writeln ("Defining recursive function " ^ quote name ^ " ...");
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   193
8657
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
   194
    val ((eq_names, eqs), raw_eq_atts) = apfst split_list (split_list eq_srcs);
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
   195
    val eq_atts = map (map (prep_att thy)) raw_eq_atts;
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
   196
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   197
    val (cs, ss, congs, wfs) = prep_hints thy hints;
14241
dfae7eb2830c Prevent recdef from looping when the inductio rule is simplified
paulson
parents: 12876
diff changeset
   198
    (*We must remove imp_cong to prevent looping when the induction rule
dfae7eb2830c Prevent recdef from looping when the inductio rule is simplified
paulson
parents: 12876
diff changeset
   199
      is simplified. Many induction rules have nested implications that would
dfae7eb2830c Prevent recdef from looping when the inductio rule is simplified
paulson
parents: 12876
diff changeset
   200
      give rise to looping conditional rewriting.*)
35756
cfde251d03a5 refining and adding Spec_Rules to definitional packages old_primrec, primrec, recdef, size and function
bulwahn
parents: 35690
diff changeset
   201
    val (thy, {lhs, rules = rules_idx, induct, tcs}) =
17920
5c3e9415c653 removed obsolete add_recdef_old;
wenzelm
parents: 17593
diff changeset
   202
        tfl_fn not_permissive thy cs (ss delcongs [imp_cong])
14241
dfae7eb2830c Prevent recdef from looping when the inductio rule is simplified
paulson
parents: 12876
diff changeset
   203
               congs wfs name R eqs;
21098
d0d8a48ae4e6 switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents: 21078
diff changeset
   204
    val rules = (map o map) fst (partition_eq (eq_snd (op = : int * int -> bool)) rules_idx);
33552
506f80a9afe8 removed unused Quickcheck_RecFun_Simps;
wenzelm
parents: 33522
diff changeset
   205
    val simp_att =
506f80a9afe8 removed unused Quickcheck_RecFun_Simps;
wenzelm
parents: 33522
diff changeset
   206
      if null tcs then [Simplifier.simp_add, Nitpick_Simps.add, Code.add_default_eqn_attribute]
506f80a9afe8 removed unused Quickcheck_RecFun_Simps;
wenzelm
parents: 33522
diff changeset
   207
      else [];
18377
0e1d025d57b3 oriented result pairs in PureThy
haftmann
parents: 17920
diff changeset
   208
    val ((simps' :: rules', [induct']), thy) =
7798
42e94b618f34 return stored thms with proper naming in derivation;
wenzelm
parents: 7262
diff changeset
   209
      thy
24712
64ed05609568 proper Sign operations instead of Theory aliases;
wenzelm
parents: 24624
diff changeset
   210
      |> Sign.add_path bname
18688
abf0f018b5ec generic attributes;
wenzelm
parents: 18418
diff changeset
   211
      |> PureThy.add_thmss
32952
aeb1e44fbc19 replaced String.concat by implode;
wenzelm
parents: 32863
diff changeset
   212
        (((Binding.name "simps", flat rules), simp_att) :: ((eq_names ~~ rules) ~~ eq_atts))
34952
bd7e347eb768 added registration of equational theorems from prim_rec and rec_def to Spec_Rules
bulwahn
parents: 33699
diff changeset
   213
      ||>> PureThy.add_thms [((Binding.name "induct", induct), [])]
35756
cfde251d03a5 refining and adding Spec_Rules to definitional packages old_primrec, primrec, recdef, size and function
bulwahn
parents: 35690
diff changeset
   214
      ||> Spec_Rules.add_global Spec_Rules.Equational ([lhs], flat rules);
cfde251d03a5 refining and adding Spec_Rules to definitional packages old_primrec, primrec, recdef, size and function
bulwahn
parents: 35690
diff changeset
   215
    val result = {lhs = lhs, simps = simps', rules = rules', induct = induct', tcs = tcs};
7798
42e94b618f34 return stored thms with proper naming in derivation;
wenzelm
parents: 7262
diff changeset
   216
    val thy =
42e94b618f34 return stored thms with proper naming in derivation;
wenzelm
parents: 7262
diff changeset
   217
      thy
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   218
      |> put_recdef name result
24712
64ed05609568 proper Sign operations instead of Theory aliases;
wenzelm
parents: 24624
diff changeset
   219
      |> Sign.parent_path;
7798
42e94b618f34 return stored thms with proper naming in derivation;
wenzelm
parents: 7262
diff changeset
   220
  in (thy, result) end;
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   221
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   222
val add_recdef = gen_add_recdef Tfl.define Attrib.attribute prepare_hints;
11629
481148b273b5 permissive option;
wenzelm
parents: 10775
diff changeset
   223
fun add_recdef_i x y z w = gen_add_recdef Tfl.define_i (K I) prepare_hints_i x y z w ();
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   224
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   225
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   226
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   227
(** defer_recdef(_i) **)
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   228
27727
2397e310b2cc simplified defer_recdef(_i): plain facts via Attrib.eval_thms;
wenzelm
parents: 27353
diff changeset
   229
fun gen_defer_recdef tfl_fn eval_thms raw_name eqs raw_congs thy =
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   230
  let
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
   231
    val name = Sign.intern_const thy raw_name;
30364
577edc39b501 moved basic algebra of long names from structure NameSpace to Long_Name;
wenzelm
parents: 30280
diff changeset
   232
    val bname = Long_Name.base_name name;
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   233
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   234
    val _ = requires_recdef thy;
26478
9d1029ce0e13 eliminated quiete_mode ref (not really needed);
wenzelm
parents: 26336
diff changeset
   235
    val _ = writeln ("Deferred recursive function " ^ quote name ^ " ...");
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   236
36610
bafd82950e24 renamed ProofContext.init to ProofContext.init_global to emphasize that this is not the real thing;
wenzelm
parents: 35756
diff changeset
   237
    val congs = eval_thms (ProofContext.init_global thy) raw_congs;
27727
2397e310b2cc simplified defer_recdef(_i): plain facts via Attrib.eval_thms;
wenzelm
parents: 27353
diff changeset
   238
    val (thy2, induct_rules) = tfl_fn thy congs name eqs;
18377
0e1d025d57b3 oriented result pairs in PureThy
haftmann
parents: 17920
diff changeset
   239
    val ([induct_rules'], thy3) =
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   240
      thy2
24712
64ed05609568 proper Sign operations instead of Theory aliases;
wenzelm
parents: 24624
diff changeset
   241
      |> Sign.add_path bname
29579
cb520b766e00 binding replaces bstring
haftmann
parents: 29006
diff changeset
   242
      |> PureThy.add_thms [((Binding.name "induct_rules", induct_rules), [])]
24712
64ed05609568 proper Sign operations instead of Theory aliases;
wenzelm
parents: 24624
diff changeset
   243
      ||> Sign.parent_path;
8430
dbd897e0d804 adapted to new PureThy.add_thms etc.;
wenzelm
parents: 7798
diff changeset
   244
  in (thy3, {induct_rules = induct_rules'}) end;
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   245
27727
2397e310b2cc simplified defer_recdef(_i): plain facts via Attrib.eval_thms;
wenzelm
parents: 27353
diff changeset
   246
val defer_recdef = gen_defer_recdef Tfl.defer Attrib.eval_thms;
2397e310b2cc simplified defer_recdef(_i): plain facts via Attrib.eval_thms;
wenzelm
parents: 27353
diff changeset
   247
val defer_recdef_i = gen_defer_recdef Tfl.defer_i (K I);
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   248
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   249
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   250
10775
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   251
(** recdef_tc(_i) **)
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   252
24457
a33258c78ed2 Adapted to changes in interface of Specification.theorem_i
berghofe
parents: 24039
diff changeset
   253
fun gen_recdef_tc prep_att prep_name (bname, raw_atts) raw_name opt_i int lthy =
10775
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   254
  let
21351
1fb804b96d7c recdef_tc(_i): local_theory interface via Specification.theorem_i;
wenzelm
parents: 21098
diff changeset
   255
    val thy = ProofContext.theory_of lthy;
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
   256
    val name = prep_name thy raw_name;
10775
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   257
    val atts = map (prep_att thy) raw_atts;
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   258
    val tcs =
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   259
      (case get_recdef thy name of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15458
diff changeset
   260
        NONE => error ("No recdef definition of constant: " ^ quote name)
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15458
diff changeset
   261
      | SOME {tcs, ...} => tcs);
21351
1fb804b96d7c recdef_tc(_i): local_theory interface via Specification.theorem_i;
wenzelm
parents: 21098
diff changeset
   262
    val i = the_default 1 opt_i;
1fb804b96d7c recdef_tc(_i): local_theory interface via Specification.theorem_i;
wenzelm
parents: 21098
diff changeset
   263
    val tc = nth tcs (i - 1) handle Subscript =>
10775
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   264
      error ("No termination condition #" ^ string_of_int i ^
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   265
        " in recdef definition of " ^ quote name);
21351
1fb804b96d7c recdef_tc(_i): local_theory interface via Specification.theorem_i;
wenzelm
parents: 21098
diff changeset
   266
  in
33643
b275f26a638b eliminated obsolete "internal" kind -- collapsed to unspecific "";
wenzelm
parents: 33552
diff changeset
   267
    Specification.theorem "" NONE (K I)
33278
ba9f52f56356 conceal internal bindings;
wenzelm
parents: 33056
diff changeset
   268
      (Binding.conceal (Binding.name bname), atts) []
ba9f52f56356 conceal internal bindings;
wenzelm
parents: 33056
diff changeset
   269
      (Element.Shows [(Attrib.empty_binding, [(HOLogic.mk_Trueprop tc, [])])]) int lthy
21351
1fb804b96d7c recdef_tc(_i): local_theory interface via Specification.theorem_i;
wenzelm
parents: 21098
diff changeset
   270
  end;
10775
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   271
21351
1fb804b96d7c recdef_tc(_i): local_theory interface via Specification.theorem_i;
wenzelm
parents: 21098
diff changeset
   272
val recdef_tc = gen_recdef_tc Attrib.intern_src Sign.intern_const;
10775
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   273
val recdef_tc_i = gen_recdef_tc (K I) (K I);
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   274
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   275
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   276
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   277
(** package setup **)
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   278
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   279
(* setup theory *)
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   280
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   281
val setup =
30528
7173bf123335 simplified attribute setup;
wenzelm
parents: 30364
diff changeset
   282
  Attrib.setup @{binding recdef_simp} (Attrib.add_del simp_add simp_del)
7173bf123335 simplified attribute setup;
wenzelm
parents: 30364
diff changeset
   283
    "declaration of recdef simp rule" #>
7173bf123335 simplified attribute setup;
wenzelm
parents: 30364
diff changeset
   284
  Attrib.setup @{binding recdef_cong} (Attrib.add_del cong_add cong_del)
7173bf123335 simplified attribute setup;
wenzelm
parents: 30364
diff changeset
   285
    "declaration of recdef cong rule" #>
7173bf123335 simplified attribute setup;
wenzelm
parents: 30364
diff changeset
   286
  Attrib.setup @{binding recdef_wf} (Attrib.add_del wf_add wf_del)
7173bf123335 simplified attribute setup;
wenzelm
parents: 30364
diff changeset
   287
    "declaration of recdef wf rule";
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   288
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   289
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   290
(* outer syntax *)
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   291
36960
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36954
diff changeset
   292
val _ = List.app Keyword.keyword ["permissive", "congs", "hints"];
24867
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24712
diff changeset
   293
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   294
val hints =
36960
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36954
diff changeset
   295
  Parse.$$$ "(" |--
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36954
diff changeset
   296
    Parse.!!! (Parse.position (Parse.$$$ "hints" -- Args.parse) --| Parse.$$$ ")") >> Args.src;
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   297
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   298
val recdef_decl =
36960
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36954
diff changeset
   299
  Scan.optional
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36954
diff changeset
   300
    (Parse.$$$ "(" -- Parse.!!! (Parse.$$$ "permissive" -- Parse.$$$ ")") >> K false) true --
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36954
diff changeset
   301
  Parse.name -- Parse.term -- Scan.repeat1 (Parse_Spec.opt_thm_name ":" -- Parse.prop)
28083
103d9282a946 explicit type Name.binding for higher-specification elements;
wenzelm
parents: 27809
diff changeset
   302
    -- Scan.option hints
36960
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36954
diff changeset
   303
  >> (fn ((((p, f), R), eqs), src) => #1 o add_recdef p f R (map Parse.triple_swap eqs) src);
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   304
24867
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24712
diff changeset
   305
val _ =
36960
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36954
diff changeset
   306
  Outer_Syntax.command "recdef" "define general recursive functions (TFL)" Keyword.thy_decl
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   307
    (recdef_decl >> Toplevel.theory);
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   308
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   309
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   310
val defer_recdef_decl =
36960
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36954
diff changeset
   311
  Parse.name -- Scan.repeat1 Parse.prop --
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36954
diff changeset
   312
  Scan.optional
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36954
diff changeset
   313
    (Parse.$$$ "(" |-- Parse.$$$ "congs" |-- Parse.!!! (Parse_Spec.xthms1 --| Parse.$$$ ")")) []
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   314
  >> (fn ((f, eqs), congs) => #1 o defer_recdef f eqs congs);
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   315
24867
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24712
diff changeset
   316
val _ =
36960
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36954
diff changeset
   317
  Outer_Syntax.command "defer_recdef" "defer general recursive functions (TFL)" Keyword.thy_decl
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   318
    (defer_recdef_decl >> Toplevel.theory);
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   319
24867
e5b55d7be9bb simplified interfaces for outer syntax;
wenzelm
parents: 24712
diff changeset
   320
val _ =
36960
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36954
diff changeset
   321
  Outer_Syntax.local_theory_to_proof' "recdef_tc" "recommence proof of termination condition (TFL)"
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36954
diff changeset
   322
    Keyword.thy_goal
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36954
diff changeset
   323
    ((Parse_Spec.opt_thm_name ":" >> apfst Binding.name_of) -- Parse.xname --
01594f816e3a prefer structure Keyword, Parse, Parse_Spec, Outer_Syntax;
wenzelm
parents: 36954
diff changeset
   324
        Scan.option (Parse.$$$ "(" |-- Parse.nat --| Parse.$$$ ")")
26988
742e26213212 more uniform treatment of OuterSyntax.local_theory commands;
wenzelm
parents: 26478
diff changeset
   325
      >> (fn ((thm_name, name), i) => recdef_tc thm_name name i));
10775
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   326
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   327
end;