src/HOL/Tools/recdef_package.ML
author wenzelm
Tue, 14 Nov 2006 00:15:39 +0100
changeset 21351 1fb804b96d7c
parent 21098 d0d8a48ae4e6
child 21434 944f80576be0
permissions -rw-r--r--
recdef_tc(_i): local_theory interface via Specification.theorem_i; incorporated IsarThy into IsarCmd;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
     1
(*  Title:      HOL/Tools/recdef_package.ML
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
     4
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
     5
Wrapper module for Konrad Slind's TFL package.
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
     6
*)
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
     7
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
     8
signature RECDEF_PACKAGE =
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
     9
sig
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    10
  val quiet_mode: bool ref
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
    11
  val print_recdefs: theory -> unit
8657
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
    12
  val get_recdef: theory -> string
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
    13
    -> {simps: thm list, rules: thm list list, induct: thm, tcs: term list} option
20291
c82b667b6dcc export get_hints;
wenzelm
parents: 19770
diff changeset
    14
  val get_hints: Context.generic -> {simps: thm list, congs: (string * thm) list, wfs: thm list}
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    15
  val simp_add: attribute
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    16
  val simp_del: attribute
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    17
  val cong_add: attribute
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    18
  val cong_del: attribute
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    19
  val wf_add: attribute
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    20
  val wf_del: attribute
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15574
diff changeset
    21
  val add_recdef: bool -> xstring -> string -> ((bstring * string) * Attrib.src list) list ->
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15574
diff changeset
    22
    Attrib.src option -> theory -> theory
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    23
      * {simps: thm list, rules: thm list list, induct: thm, tcs: term list}
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    24
  val add_recdef_i: bool -> xstring -> term -> ((bstring * term) * attribute list) list ->
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    25
    theory -> theory * {simps: thm list, rules: thm list list, induct: thm, tcs: term list}
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15574
diff changeset
    26
  val defer_recdef: xstring -> string list -> (thmref * Attrib.src list) list
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
    27
    -> theory -> theory * {induct_rules: thm}
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    28
  val defer_recdef_i: xstring -> term list -> (thm list * attribute list) list
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
    29
    -> theory -> theory * {induct_rules: thm}
21351
1fb804b96d7c recdef_tc(_i): local_theory interface via Specification.theorem_i;
wenzelm
parents: 21098
diff changeset
    30
  val recdef_tc: bstring * Attrib.src list -> xstring -> int option -> local_theory -> Proof.state
1fb804b96d7c recdef_tc(_i): local_theory interface via Specification.theorem_i;
wenzelm
parents: 21098
diff changeset
    31
  val recdef_tc_i: bstring * Attrib.src list -> string -> int option -> local_theory -> Proof.state
18708
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18688
diff changeset
    32
  val setup: theory -> theory
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    33
end;
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    34
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    35
structure RecdefPackage: RECDEF_PACKAGE =
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    36
struct
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    37
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    38
val quiet_mode = Tfl.quiet_mode;
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    39
val message = Tfl.message;
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    40
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    41
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    42
(** recdef hints **)
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
    43
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    44
(* type hints *)
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    45
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    46
type hints = {simps: thm list, congs: (string * thm) list, wfs: thm list};
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    47
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    48
fun mk_hints (simps, congs, wfs) = {simps = simps, congs = congs, wfs = wfs}: hints;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    49
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
    50
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    51
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
    52
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
    53
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
    54
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    55
fun pretty_hints ({simps, congs, wfs}: hints) =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    56
 [Pretty.big_list "recdef simp hints:" (map Display.pretty_thm simps),
21098
d0d8a48ae4e6 switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents: 21078
diff changeset
    57
  Pretty.big_list "recdef cong hints:" (map Display.pretty_thm (map snd congs)),
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    58
  Pretty.big_list "recdef wf hints:" (map Display.pretty_thm wfs)];
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    59
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    60
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    61
(* congruence rules *)
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    62
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    63
local
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    64
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    65
val cong_head =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    66
  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
    67
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    68
fun prep_cong raw_thm =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    69
  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
    70
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    71
in
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    72
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    73
fun add_cong raw_thm congs =
21098
d0d8a48ae4e6 switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents: 21078
diff changeset
    74
  let
d0d8a48ae4e6 switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents: 21078
diff changeset
    75
    val (c, thm) = prep_cong raw_thm;
d0d8a48ae4e6 switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents: 21078
diff changeset
    76
    val _ = if AList.defined (op =) congs c
d0d8a48ae4e6 switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents: 21078
diff changeset
    77
      then warning ("Overwriting recdef congruence rule for " ^ quote c)
d0d8a48ae4e6 switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents: 21078
diff changeset
    78
      else ();
d0d8a48ae4e6 switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents: 21078
diff changeset
    79
  in AList.update (op =) (c, thm) congs end;
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    80
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    81
fun del_cong raw_thm congs =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    82
  let
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    83
    val (c, thm) = prep_cong raw_thm;
21098
d0d8a48ae4e6 switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents: 21078
diff changeset
    84
    val _ = if AList.defined (op =) congs c
d0d8a48ae4e6 switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents: 21078
diff changeset
    85
      then ()
d0d8a48ae4e6 switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents: 21078
diff changeset
    86
      else warning ("No recdef congruence rule for " ^ quote c);
d0d8a48ae4e6 switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents: 21078
diff changeset
    87
  in AList.delete (op =) c congs end;
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    88
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    89
end;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    90
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    91
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    92
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    93
(** global and local recdef data **)
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    94
17920
5c3e9415c653 removed obsolete add_recdef_old;
wenzelm
parents: 17593
diff changeset
    95
(* theory data *)
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
    96
8657
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
    97
type recdef_info = {simps: thm list, rules: thm list list, induct: thm, tcs: term list};
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
    98
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
    99
structure GlobalRecdefData = TheoryDataFun
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
   100
(struct
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   101
  val name = "HOL/recdef";
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   102
  type T = recdef_info Symtab.table * hints;
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   103
9879
a1fcaf2d080d make SML/NJ happy;
wenzelm
parents: 9876
diff changeset
   104
  val empty = (Symtab.empty, mk_hints ([], [], [])): T;
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   105
  val copy = I;
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
   106
  val extend = I;
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
   107
  fun merge _
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   108
   ((tab1, {simps = simps1, congs = congs1, wfs = wfs1}),
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
   109
    (tab2, {simps = simps2, congs = congs2, wfs = wfs2})) : T =
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   110
      (Symtab.merge (K true) (tab1, tab2),
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   111
        mk_hints (Drule.merge_rules (simps1, simps2),
21098
d0d8a48ae4e6 switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents: 21078
diff changeset
   112
          AList.merge (op =) eq_thm (congs1, congs2),
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   113
          Drule.merge_rules (wfs1, wfs2)));
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   114
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
   115
  fun print thy (tab, hints) =
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
   116
    (Pretty.strs ("recdefs:" :: map #1 (NameSpace.extern_table (Sign.const_space thy, tab))) ::
16364
dc9f7066d80a refer to name spaces values instead of names;
wenzelm
parents: 16122
diff changeset
   117
      pretty_hints hints) |> Pretty.chunks |> Pretty.writeln;
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
   118
end);
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   119
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   120
val print_recdefs = GlobalRecdefData.print;
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   121
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   122
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17336
diff changeset
   123
val get_recdef = Symtab.lookup o #1 o GlobalRecdefData.get;
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   124
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   125
fun put_recdef name info thy =
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   126
  let
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   127
    val (tab, hints) = GlobalRecdefData.get thy;
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17336
diff changeset
   128
    val tab' = Symtab.update_new (name, info) tab
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   129
      handle Symtab.DUP _ => error ("Duplicate recursive function definition " ^ quote name);
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   130
  in GlobalRecdefData.put (tab', hints) thy end;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   131
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   132
val get_global_hints = #2 o GlobalRecdefData.get;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   133
val map_global_hints = GlobalRecdefData.map o apsnd;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   134
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   135
17920
5c3e9415c653 removed obsolete add_recdef_old;
wenzelm
parents: 17593
diff changeset
   136
(* proof data *)
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   137
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
   138
structure LocalRecdefData = ProofDataFun
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
   139
(struct
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   140
  val name = "HOL/recdef";
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   141
  type T = hints;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   142
  val init = get_global_hints;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   143
  fun print _ hints = pretty_hints hints |> Pretty.chunks |> Pretty.writeln;
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
   144
end);
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   145
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   146
val get_local_hints = LocalRecdefData.get;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   147
val map_local_hints = LocalRecdefData.map;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   148
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   149
20291
c82b667b6dcc export get_hints;
wenzelm
parents: 19770
diff changeset
   150
(* generic data *)
c82b667b6dcc export get_hints;
wenzelm
parents: 19770
diff changeset
   151
c82b667b6dcc export get_hints;
wenzelm
parents: 19770
diff changeset
   152
fun get_hints (Context.Theory thy) = get_global_hints thy
c82b667b6dcc export get_hints;
wenzelm
parents: 19770
diff changeset
   153
  | get_hints (Context.Proof ctxt) = get_local_hints ctxt;
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   154
18688
abf0f018b5ec generic attributes;
wenzelm
parents: 18418
diff changeset
   155
fun map_hints f (Context.Theory thy) = Context.Theory (map_global_hints f thy)
abf0f018b5ec generic attributes;
wenzelm
parents: 18418
diff changeset
   156
  | map_hints f (Context.Proof ctxt) = Context.Proof (map_local_hints f ctxt);
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   157
20291
c82b667b6dcc export get_hints;
wenzelm
parents: 19770
diff changeset
   158
c82b667b6dcc export get_hints;
wenzelm
parents: 19770
diff changeset
   159
(* attributes *)
c82b667b6dcc export get_hints;
wenzelm
parents: 19770
diff changeset
   160
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   161
fun attrib f = Thm.declaration_attribute (map_hints o f);
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   162
18688
abf0f018b5ec generic attributes;
wenzelm
parents: 18418
diff changeset
   163
val simp_add = attrib (map_simps o Drule.add_rule);
abf0f018b5ec generic attributes;
wenzelm
parents: 18418
diff changeset
   164
val simp_del = attrib (map_simps o Drule.del_rule);
abf0f018b5ec generic attributes;
wenzelm
parents: 18418
diff changeset
   165
val cong_add = attrib (map_congs o add_cong);
abf0f018b5ec generic attributes;
wenzelm
parents: 18418
diff changeset
   166
val cong_del = attrib (map_congs o del_cong);
abf0f018b5ec generic attributes;
wenzelm
parents: 18418
diff changeset
   167
val wf_add = attrib (map_wfs o Drule.add_rule);
abf0f018b5ec generic attributes;
wenzelm
parents: 18418
diff changeset
   168
val wf_del = attrib (map_wfs o Drule.del_rule);
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   169
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   170
9949
1741a61d4b33 tuned recdef hints;
wenzelm
parents: 9893
diff changeset
   171
(* modifiers *)
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   172
9949
1741a61d4b33 tuned recdef hints;
wenzelm
parents: 9893
diff changeset
   173
val recdef_simpN = "recdef_simp";
1741a61d4b33 tuned recdef hints;
wenzelm
parents: 9893
diff changeset
   174
val recdef_congN = "recdef_cong";
1741a61d4b33 tuned recdef hints;
wenzelm
parents: 9893
diff changeset
   175
val recdef_wfN = "recdef_wf";
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   176
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   177
val recdef_modifiers =
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   178
 [Args.$$$ recdef_simpN -- Args.colon >> K ((I, simp_add): Method.modifier),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   179
  Args.$$$ recdef_simpN -- Args.add -- Args.colon >> K (I, simp_add),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   180
  Args.$$$ recdef_simpN -- Args.del -- Args.colon >> K (I, simp_del),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   181
  Args.$$$ recdef_congN -- Args.colon >> K (I, cong_add),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   182
  Args.$$$ recdef_congN -- Args.add -- Args.colon >> K (I, cong_add),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   183
  Args.$$$ recdef_congN -- Args.del -- Args.colon >> K (I, cong_del),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   184
  Args.$$$ recdef_wfN -- Args.colon >> K (I, wf_add),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   185
  Args.$$$ recdef_wfN -- Args.add -- Args.colon >> K (I, wf_add),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   186
  Args.$$$ recdef_wfN -- Args.del -- Args.colon >> K (I, wf_del)] @
9949
1741a61d4b33 tuned recdef hints;
wenzelm
parents: 9893
diff changeset
   187
  Clasimp.clasimp_modifiers;
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   188
9949
1741a61d4b33 tuned recdef hints;
wenzelm
parents: 9893
diff changeset
   189
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   190
9949
1741a61d4b33 tuned recdef hints;
wenzelm
parents: 9893
diff changeset
   191
(** prepare_hints(_i) **)
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   192
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   193
fun prepare_hints thy opt_src =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   194
  let
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   195
    val ctxt0 = ProofContext.init thy;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   196
    val ctxt =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   197
      (case opt_src of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15458
diff changeset
   198
        NONE => ctxt0
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15458
diff changeset
   199
      | SOME src => Method.only_sectioned_args recdef_modifiers I src ctxt0);
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   200
    val {simps, congs, wfs} = get_local_hints ctxt;
15032
02aed07e01bf local_cla/simpset_of;
wenzelm
parents: 14981
diff changeset
   201
    val cs = local_claset_of ctxt;
02aed07e01bf local_cla/simpset_of;
wenzelm
parents: 14981
diff changeset
   202
    val ss = local_simpset_of ctxt addsimps simps;
21098
d0d8a48ae4e6 switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents: 21078
diff changeset
   203
  in (cs, ss, rev (map snd congs), wfs) end;
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   204
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   205
fun prepare_hints_i thy () =
15032
02aed07e01bf local_cla/simpset_of;
wenzelm
parents: 14981
diff changeset
   206
  let
02aed07e01bf local_cla/simpset_of;
wenzelm
parents: 14981
diff changeset
   207
    val ctxt0 = ProofContext.init thy;
02aed07e01bf local_cla/simpset_of;
wenzelm
parents: 14981
diff changeset
   208
    val {simps, congs, wfs} = get_global_hints thy;
21098
d0d8a48ae4e6 switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents: 21078
diff changeset
   209
  in (local_claset_of ctxt0, local_simpset_of ctxt0 addsimps simps, rev (map snd congs), wfs) end;
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   210
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   211
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   212
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   213
(** add_recdef(_i) **)
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   214
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   215
fun requires_recdef thy = Theory.requires thy "Recdef" "recursive functions";
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   216
17920
5c3e9415c653 removed obsolete add_recdef_old;
wenzelm
parents: 17593
diff changeset
   217
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
   218
  let
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   219
    val _ = requires_recdef thy;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   220
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
   221
    val name = Sign.intern_const thy raw_name;
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   222
    val bname = Sign.base_name name;
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   223
    val _ = message ("Defining recursive function " ^ quote name ^ " ...");
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   224
8657
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
   225
    val ((eq_names, eqs), raw_eq_atts) = apfst split_list (split_list eq_srcs);
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
   226
    val eq_atts = map (map (prep_att thy)) raw_eq_atts;
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
   227
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   228
    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
   229
    (*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
   230
      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
   231
      give rise to looping conditional rewriting.*)
dfae7eb2830c Prevent recdef from looping when the inductio rule is simplified
paulson
parents: 12876
diff changeset
   232
    val (thy, {rules = rules_idx, induct, tcs}) =
17920
5c3e9415c653 removed obsolete add_recdef_old;
wenzelm
parents: 17593
diff changeset
   233
        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
   234
               congs wfs name R eqs;
21098
d0d8a48ae4e6 switched merge_alists'' to AList.merge'' whenever appropriate
haftmann
parents: 21078
diff changeset
   235
    val rules = (map o map) fst (partition_eq (eq_snd (op = : int * int -> bool)) rules_idx);
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   236
    val simp_att = if null tcs then [Simplifier.simp_add, RecfunCodegen.add NONE] else [];
8657
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
   237
18377
0e1d025d57b3 oriented result pairs in PureThy
haftmann
parents: 17920
diff changeset
   238
    val ((simps' :: rules', [induct']), thy) =
7798
42e94b618f34 return stored thms with proper naming in derivation;
wenzelm
parents: 7262
diff changeset
   239
      thy
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   240
      |> Theory.add_path bname
18688
abf0f018b5ec generic attributes;
wenzelm
parents: 18418
diff changeset
   241
      |> PureThy.add_thmss
abf0f018b5ec generic attributes;
wenzelm
parents: 18418
diff changeset
   242
        ((("simps", List.concat rules), simp_att) :: ((eq_names ~~ rules) ~~ eq_atts))
18377
0e1d025d57b3 oriented result pairs in PureThy
haftmann
parents: 17920
diff changeset
   243
      ||>> PureThy.add_thms [(("induct", induct), [])];
8657
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
   244
    val result = {simps = simps', rules = rules', induct = induct', tcs = tcs};
7798
42e94b618f34 return stored thms with proper naming in derivation;
wenzelm
parents: 7262
diff changeset
   245
    val thy =
42e94b618f34 return stored thms with proper naming in derivation;
wenzelm
parents: 7262
diff changeset
   246
      thy
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   247
      |> put_recdef name result
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   248
      |> Theory.parent_path;
7798
42e94b618f34 return stored thms with proper naming in derivation;
wenzelm
parents: 7262
diff changeset
   249
  in (thy, result) end;
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   250
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   251
val add_recdef = gen_add_recdef Tfl.define Attrib.attribute prepare_hints;
11629
481148b273b5 permissive option;
wenzelm
parents: 10775
diff changeset
   252
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
   253
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   254
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   255
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   256
(** defer_recdef(_i) **)
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   257
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   258
fun gen_defer_recdef tfl_fn app_thms raw_name eqs raw_congs thy =
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   259
  let
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
   260
    val name = Sign.intern_const thy raw_name;
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   261
    val bname = Sign.base_name name;
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   262
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   263
    val _ = requires_recdef thy;
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   264
    val _ = message ("Deferred recursive function " ^ quote name ^ " ...");
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   265
18418
bf448d999b7e re-arranged tuples (theory * 'a) to ('a * theory) in Pure
haftmann
parents: 18377
diff changeset
   266
    val (congs, thy1) = thy |> app_thms raw_congs;
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   267
    val (thy2, induct_rules) = tfl_fn thy1 congs name eqs;
18377
0e1d025d57b3 oriented result pairs in PureThy
haftmann
parents: 17920
diff changeset
   268
    val ([induct_rules'], thy3) =
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   269
      thy2
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   270
      |> Theory.add_path bname
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   271
      |> PureThy.add_thms [(("induct_rules", induct_rules), [])]
18377
0e1d025d57b3 oriented result pairs in PureThy
haftmann
parents: 17920
diff changeset
   272
      ||> Theory.parent_path;
8430
dbd897e0d804 adapted to new PureThy.add_thms etc.;
wenzelm
parents: 7798
diff changeset
   273
  in (thy3, {induct_rules = induct_rules'}) end;
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   274
21351
1fb804b96d7c recdef_tc(_i): local_theory interface via Specification.theorem_i;
wenzelm
parents: 21098
diff changeset
   275
val defer_recdef = gen_defer_recdef Tfl.defer IsarCmd.apply_theorems;
1fb804b96d7c recdef_tc(_i): local_theory interface via Specification.theorem_i;
wenzelm
parents: 21098
diff changeset
   276
val defer_recdef_i = gen_defer_recdef Tfl.defer_i IsarCmd.apply_theorems_i;
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   277
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   278
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   279
10775
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   280
(** recdef_tc(_i) **)
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   281
21351
1fb804b96d7c recdef_tc(_i): local_theory interface via Specification.theorem_i;
wenzelm
parents: 21098
diff changeset
   282
fun gen_recdef_tc prep_att prep_name (bname, raw_atts) raw_name opt_i lthy =
10775
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   283
  let
21351
1fb804b96d7c recdef_tc(_i): local_theory interface via Specification.theorem_i;
wenzelm
parents: 21098
diff changeset
   284
    val thy = ProofContext.theory_of lthy;
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
   285
    val name = prep_name thy raw_name;
10775
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   286
    val atts = map (prep_att thy) raw_atts;
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   287
    val tcs =
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   288
      (case get_recdef thy name of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15458
diff changeset
   289
        NONE => error ("No recdef definition of constant: " ^ quote name)
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15458
diff changeset
   290
      | SOME {tcs, ...} => tcs);
21351
1fb804b96d7c recdef_tc(_i): local_theory interface via Specification.theorem_i;
wenzelm
parents: 21098
diff changeset
   291
    val i = the_default 1 opt_i;
1fb804b96d7c recdef_tc(_i): local_theory interface via Specification.theorem_i;
wenzelm
parents: 21098
diff changeset
   292
    val tc = nth tcs (i - 1) handle Subscript =>
10775
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   293
      error ("No termination condition #" ^ string_of_int i ^
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   294
        " in recdef definition of " ^ quote name);
21351
1fb804b96d7c recdef_tc(_i): local_theory interface via Specification.theorem_i;
wenzelm
parents: 21098
diff changeset
   295
  in
1fb804b96d7c recdef_tc(_i): local_theory interface via Specification.theorem_i;
wenzelm
parents: 21098
diff changeset
   296
    Specification.theorem_i PureThy.internalK NONE (K I) (bname, atts)
1fb804b96d7c recdef_tc(_i): local_theory interface via Specification.theorem_i;
wenzelm
parents: 21098
diff changeset
   297
      [] (Element.Shows [(("", []), [(HOLogic.mk_Trueprop tc, [])])]) lthy
1fb804b96d7c recdef_tc(_i): local_theory interface via Specification.theorem_i;
wenzelm
parents: 21098
diff changeset
   298
  end;
10775
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   299
21351
1fb804b96d7c recdef_tc(_i): local_theory interface via Specification.theorem_i;
wenzelm
parents: 21098
diff changeset
   300
val recdef_tc = gen_recdef_tc Attrib.intern_src Sign.intern_const;
10775
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   301
val recdef_tc_i = gen_recdef_tc (K I) (K I);
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   302
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   303
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   304
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   305
(** package setup **)
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   306
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   307
(* setup theory *)
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   308
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   309
val setup =
18708
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18688
diff changeset
   310
  GlobalRecdefData.init #>
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18688
diff changeset
   311
  LocalRecdefData.init #>
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   312
  Attrib.add_attributes
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   313
   [(recdef_simpN, Attrib.add_del_args simp_add simp_del, "declaration of recdef simp rule"),
19770
be5c23ebe1eb HOL/Tools/function_package: Added support for mutual recursive definitions.
krauss
parents: 19686
diff changeset
   314
    (recdef_congN, Attrib.add_del_args cong_add cong_del, "declaration of recdef cong rule"),
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   315
    (recdef_wfN, Attrib.add_del_args wf_add wf_del, "declaration of recdef wf rule")];
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   316
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   317
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   318
(* outer syntax *)
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   319
17057
0934ac31985f OuterKeyword;
wenzelm
parents: 16646
diff changeset
   320
local structure P = OuterParse and K = OuterKeyword in
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   321
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   322
val hints =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   323
  P.$$$ "(" |-- P.!!! (P.position (P.$$$ "hints" -- P.arguments) --| P.$$$ ")") >> Args.src;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   324
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   325
val recdef_decl =
11629
481148b273b5 permissive option;
wenzelm
parents: 10775
diff changeset
   326
  Scan.optional (P.$$$ "(" -- P.!!! (P.$$$ "permissive" -- P.$$$ ")") >> K false) true --
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12755
diff changeset
   327
  P.name -- P.term -- Scan.repeat1 (P.opt_thm_name ":" -- P.prop) -- Scan.option hints
11629
481148b273b5 permissive option;
wenzelm
parents: 10775
diff changeset
   328
  >> (fn ((((p, f), R), eqs), src) => #1 o add_recdef p f R (map P.triple_swap eqs) src);
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   329
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   330
val recdefP =
6723
f342449d73ca outer syntax keyword classification;
wenzelm
parents: 6576
diff changeset
   331
  OuterSyntax.command "recdef" "define general recursive functions (TFL)" K.thy_decl
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   332
    (recdef_decl >> Toplevel.theory);
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   333
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   334
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   335
val defer_recdef_decl =
8657
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
   336
  P.name -- Scan.repeat1 P.prop --
6723
f342449d73ca outer syntax keyword classification;
wenzelm
parents: 6576
diff changeset
   337
  Scan.optional (P.$$$ "(" |-- P.$$$ "congs" |-- P.!!! (P.xthms1 --| P.$$$ ")")) []
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   338
  >> (fn ((f, eqs), congs) => #1 o defer_recdef f eqs congs);
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   339
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   340
val defer_recdefP =
6723
f342449d73ca outer syntax keyword classification;
wenzelm
parents: 6576
diff changeset
   341
  OuterSyntax.command "defer_recdef" "defer general recursive functions (TFL)" K.thy_decl
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   342
    (defer_recdef_decl >> Toplevel.theory);
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   343
10775
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   344
val recdef_tcP =
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   345
  OuterSyntax.command "recdef_tc" "recommence proof of termination condition (TFL)" K.thy_goal
21351
1fb804b96d7c recdef_tc(_i): local_theory interface via Specification.theorem_i;
wenzelm
parents: 21098
diff changeset
   346
    (P.opt_locale_target --
1fb804b96d7c recdef_tc(_i): local_theory interface via Specification.theorem_i;
wenzelm
parents: 21098
diff changeset
   347
      P.opt_thm_name ":" -- P.xname -- Scan.option (P.$$$ "(" |-- P.nat --| P.$$$ ")")
1fb804b96d7c recdef_tc(_i): local_theory interface via Specification.theorem_i;
wenzelm
parents: 21098
diff changeset
   348
      >> (fn (((loc, thm_name), name), i) =>
1fb804b96d7c recdef_tc(_i): local_theory interface via Specification.theorem_i;
wenzelm
parents: 21098
diff changeset
   349
        Toplevel.print o Toplevel.local_theory_to_proof loc (recdef_tc thm_name name i)));
10775
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   350
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   351
11629
481148b273b5 permissive option;
wenzelm
parents: 10775
diff changeset
   352
val _ = OuterSyntax.add_keywords ["permissive", "congs", "hints"];
10775
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   353
val _ = OuterSyntax.add_parsers [recdefP, defer_recdefP, recdef_tcP];
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   354
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   355
end;
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   356
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   357
end;