src/HOL/Tools/recdef_package.ML
author wenzelm
Fri, 17 Jun 2005 18:35:27 +0200
changeset 16458 4c6fd0c01d28
parent 16364 dc9f7066d80a
child 16646 666774b0d1b0
permissions -rw-r--r--
accomodate change of TheoryDataFun; accomodate identification of type Sign.sg and theory;
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
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    14
  val simp_add_global: theory attribute
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    15
  val simp_del_global: theory attribute
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    16
  val cong_add_global: theory attribute
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    17
  val cong_del_global: theory attribute
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    18
  val wf_add_global: theory attribute
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    19
  val wf_del_global: theory attribute
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    20
  val simp_add_local: Proof.context attribute
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    21
  val simp_del_local: Proof.context attribute
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    22
  val cong_add_local: Proof.context attribute
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    23
  val cong_del_local: Proof.context attribute
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    24
  val wf_add_local: Proof.context attribute
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    25
  val wf_del_local: Proof.context attribute
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15574
diff changeset
    26
  val add_recdef: bool -> xstring -> string -> ((bstring * string) * Attrib.src list) list ->
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15574
diff changeset
    27
    Attrib.src option -> theory -> theory
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    28
      * {simps: thm list, rules: thm list list, induct: thm, tcs: term list}
11629
481148b273b5 permissive option;
wenzelm
parents: 10775
diff changeset
    29
  val add_recdef_i: bool -> xstring -> term -> ((bstring * term) * theory attribute list) list ->
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    30
    theory -> theory * {simps: thm list, rules: thm list list, induct: thm, tcs: term list}
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15574
diff changeset
    31
  val add_recdef_old: xstring -> string -> ((bstring * string) * Attrib.src list) list ->
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    32
    simpset * thm list -> theory ->
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    33
    theory * {simps: thm list, rules: thm list list, induct: thm, tcs: term list}
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15574
diff changeset
    34
  val defer_recdef: xstring -> string list -> (thmref * Attrib.src list) list
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
    35
    -> theory -> theory * {induct_rules: thm}
12708
31672377dadc clarified IsarThy.apply_theorems_i;
wenzelm
parents: 12694
diff changeset
    36
  val defer_recdef_i: xstring -> term list -> (thm list * theory attribute list) list
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
    37
    -> theory -> theory * {induct_rules: thm}
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15574
diff changeset
    38
  val recdef_tc: bstring * Attrib.src list -> xstring -> int option
10775
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
    39
    -> bool -> theory -> ProofHistory.T
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
    40
  val recdef_tc_i: bstring * theory attribute list -> string -> int option
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
    41
    -> bool -> theory -> ProofHistory.T
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
    42
  val setup: (theory -> theory) list
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    43
end;
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    44
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    45
structure RecdefPackage: RECDEF_PACKAGE =
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    46
struct
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    47
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    48
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    49
val quiet_mode = Tfl.quiet_mode;
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    50
val message = Tfl.message;
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    51
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
    52
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    53
(** recdef hints **)
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
    54
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    55
(* type hints *)
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    56
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    57
type hints = {simps: thm list, congs: (string * thm) list, wfs: thm list};
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    58
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    59
fun mk_hints (simps, congs, wfs) = {simps = simps, congs = congs, wfs = wfs}: hints;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    60
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
    61
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    62
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
    63
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
    64
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
    65
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    66
fun pretty_hints ({simps, congs, wfs}: hints) =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    67
 [Pretty.big_list "recdef simp hints:" (map Display.pretty_thm simps),
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    68
  Pretty.big_list "recdef cong hints:" (map Display.pretty_thm (map #2 congs)),
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    69
  Pretty.big_list "recdef wf hints:" (map Display.pretty_thm wfs)];
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    70
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    71
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    72
(* congruence rules *)
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    73
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    74
local
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    75
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    76
val cong_head =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    77
  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
    78
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    79
fun prep_cong raw_thm =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    80
  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
    81
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    82
in
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    83
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    84
fun add_cong raw_thm congs =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    85
  let val (c, thm) = prep_cong raw_thm
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    86
  in overwrite_warn (congs, (c, thm)) ("Overwriting recdef congruence rule for " ^ quote c) end;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    87
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    88
fun del_cong raw_thm congs =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    89
  let
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    90
    val (c, thm) = prep_cong raw_thm;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    91
    val (del, rest) = Library.partition (Library.equal c o fst) congs;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    92
  in if null del then (warning ("No recdef congruence rule for " ^ quote c); congs) else rest end;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    93
15574
b1d1b5bfc464 Removed practically all references to Library.foldr.
skalberg
parents: 15570
diff changeset
    94
val add_congs = foldr (uncurry add_cong);
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    95
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    96
end;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    97
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    98
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
    99
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   100
(** global and local recdef data **)
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   101
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   102
(* theory data kind 'HOL/recdef' *)
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   103
8657
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
   104
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
   105
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
   106
structure GlobalRecdefData = TheoryDataFun
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
   107
(struct
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   108
  val name = "HOL/recdef";
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   109
  type T = recdef_info Symtab.table * hints;
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   110
9879
a1fcaf2d080d make SML/NJ happy;
wenzelm
parents: 9876
diff changeset
   111
  val empty = (Symtab.empty, mk_hints ([], [], [])): T;
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   112
  val copy = I;
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
   113
  val extend = I;
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
   114
  fun merge _
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   115
   ((tab1, {simps = simps1, congs = congs1, wfs = wfs1}),
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
   116
    (tab2, {simps = simps2, congs = congs2, wfs = wfs2})) : T =
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   117
      (Symtab.merge (K true) (tab1, tab2),
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   118
        mk_hints (Drule.merge_rules (simps1, simps2),
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   119
          Library.merge_alists congs1 congs2,
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   120
          Drule.merge_rules (wfs1, wfs2)));
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   121
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
   122
  fun print thy (tab, hints) =
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
   123
    (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
   124
      pretty_hints hints) |> Pretty.chunks |> Pretty.writeln;
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
   125
end);
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   126
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   127
val print_recdefs = GlobalRecdefData.print;
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   128
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   129
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   130
fun get_recdef thy name = Symtab.lookup (#1 (GlobalRecdefData.get thy), name);
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   131
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   132
fun put_recdef name info thy =
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   133
  let
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   134
    val (tab, hints) = GlobalRecdefData.get thy;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   135
    val tab' = Symtab.update_new ((name, info), tab)
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   136
      handle Symtab.DUP _ => error ("Duplicate recursive function definition " ^ quote name);
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   137
  in GlobalRecdefData.put (tab', hints) thy end;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   138
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   139
val get_global_hints = #2 o GlobalRecdefData.get;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   140
val map_global_hints = GlobalRecdefData.map o apsnd;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   141
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   142
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   143
(* proof data kind 'HOL/recdef' *)
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   144
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
   145
structure LocalRecdefData = ProofDataFun
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
   146
(struct
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   147
  val name = "HOL/recdef";
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   148
  type T = hints;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   149
  val init = get_global_hints;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   150
  fun print _ hints = pretty_hints hints |> Pretty.chunks |> Pretty.writeln;
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
   151
end);
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   152
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   153
val get_local_hints = LocalRecdefData.get;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   154
val map_local_hints = LocalRecdefData.map;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   155
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   156
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   157
(* attributes *)
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   158
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   159
local
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 global_local f g =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   162
 (fn (thy, thm) => (map_global_hints (f (g thm)) thy, thm),
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   163
  fn (ctxt, thm) => (map_local_hints (f (g thm)) ctxt, thm));
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   164
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   165
fun mk_attr (add1, add2) (del1, del2) =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   166
 (Attrib.add_del_args add1 del1, Attrib.add_del_args add2 del2);
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   167
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   168
in
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   169
12371
wenzelm
parents: 12311
diff changeset
   170
val (simp_add_global, simp_add_local) = global_local map_simps Drule.add_rule;
wenzelm
parents: 12311
diff changeset
   171
val (simp_del_global, simp_del_local) = global_local map_simps Drule.del_rule;
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   172
val (cong_add_global, cong_add_local) = global_local map_congs add_cong;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   173
val (cong_del_global, cong_del_local) = global_local map_congs del_cong;
12371
wenzelm
parents: 12311
diff changeset
   174
val (wf_add_global, wf_add_local) = global_local map_wfs Drule.add_rule;
wenzelm
parents: 12311
diff changeset
   175
val (wf_del_global, wf_del_local) = global_local map_wfs Drule.del_rule;
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 simp_attr = mk_attr (simp_add_global, simp_add_local) (simp_del_global, simp_del_local);
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   178
val cong_attr = mk_attr (cong_add_global, cong_add_local) (cong_del_global, cong_del_local);
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   179
val wf_attr = mk_attr (wf_add_global, wf_add_local) (wf_del_global, wf_del_local);
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   180
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   181
end;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   182
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   183
9949
1741a61d4b33 tuned recdef hints;
wenzelm
parents: 9893
diff changeset
   184
(* modifiers *)
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   185
9949
1741a61d4b33 tuned recdef hints;
wenzelm
parents: 9893
diff changeset
   186
val recdef_simpN = "recdef_simp";
1741a61d4b33 tuned recdef hints;
wenzelm
parents: 9893
diff changeset
   187
val recdef_congN = "recdef_cong";
1741a61d4b33 tuned recdef hints;
wenzelm
parents: 9893
diff changeset
   188
val recdef_wfN = "recdef_wf";
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   189
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   190
val recdef_modifiers =
9949
1741a61d4b33 tuned recdef hints;
wenzelm
parents: 9893
diff changeset
   191
 [Args.$$$ recdef_simpN -- Args.colon >> K ((I, simp_add_local): Method.modifier),
10032
wenzelm
parents: 9999
diff changeset
   192
  Args.$$$ recdef_simpN -- Args.add -- Args.colon >> K (I, simp_add_local),
wenzelm
parents: 9999
diff changeset
   193
  Args.$$$ recdef_simpN -- Args.del -- Args.colon >> K (I, simp_del_local),
9949
1741a61d4b33 tuned recdef hints;
wenzelm
parents: 9893
diff changeset
   194
  Args.$$$ recdef_congN -- Args.colon >> K (I, cong_add_local),
10032
wenzelm
parents: 9999
diff changeset
   195
  Args.$$$ recdef_congN -- Args.add -- Args.colon >> K (I, cong_add_local),
wenzelm
parents: 9999
diff changeset
   196
  Args.$$$ recdef_congN -- Args.del -- Args.colon >> K (I, cong_del_local),
9949
1741a61d4b33 tuned recdef hints;
wenzelm
parents: 9893
diff changeset
   197
  Args.$$$ recdef_wfN -- Args.colon >> K (I, wf_add_local),
10032
wenzelm
parents: 9999
diff changeset
   198
  Args.$$$ recdef_wfN -- Args.add -- Args.colon >> K (I, wf_add_local),
wenzelm
parents: 9999
diff changeset
   199
  Args.$$$ recdef_wfN -- Args.del -- Args.colon >> K (I, wf_del_local)] @
9949
1741a61d4b33 tuned recdef hints;
wenzelm
parents: 9893
diff changeset
   200
  Clasimp.clasimp_modifiers;
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   201
9949
1741a61d4b33 tuned recdef hints;
wenzelm
parents: 9893
diff changeset
   202
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   203
9949
1741a61d4b33 tuned recdef hints;
wenzelm
parents: 9893
diff changeset
   204
(** prepare_hints(_i) **)
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   205
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   206
fun prepare_hints thy opt_src =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   207
  let
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   208
    val ctxt0 = ProofContext.init thy;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   209
    val ctxt =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   210
      (case opt_src of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15458
diff changeset
   211
        NONE => ctxt0
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15458
diff changeset
   212
      | SOME src => Method.only_sectioned_args recdef_modifiers I src ctxt0);
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   213
    val {simps, congs, wfs} = get_local_hints ctxt;
15032
02aed07e01bf local_cla/simpset_of;
wenzelm
parents: 14981
diff changeset
   214
    val cs = local_claset_of ctxt;
02aed07e01bf local_cla/simpset_of;
wenzelm
parents: 14981
diff changeset
   215
    val ss = local_simpset_of ctxt addsimps simps;
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   216
  in (cs, ss, map #2 congs, wfs) end;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   217
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   218
fun prepare_hints_i thy () =
15032
02aed07e01bf local_cla/simpset_of;
wenzelm
parents: 14981
diff changeset
   219
  let
02aed07e01bf local_cla/simpset_of;
wenzelm
parents: 14981
diff changeset
   220
    val ctxt0 = ProofContext.init thy;
02aed07e01bf local_cla/simpset_of;
wenzelm
parents: 14981
diff changeset
   221
    val {simps, congs, wfs} = get_global_hints thy;
02aed07e01bf local_cla/simpset_of;
wenzelm
parents: 14981
diff changeset
   222
  in (local_claset_of ctxt0, local_simpset_of ctxt0 addsimps simps, map #2 congs, wfs) end;
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   223
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   224
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   225
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   226
(** add_recdef(_i) **)
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   227
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   228
fun requires_recdef thy = Theory.requires thy "Recdef" "recursive functions";
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   229
14241
dfae7eb2830c Prevent recdef from looping when the inductio rule is simplified
paulson
parents: 12876
diff changeset
   230
(*"strict" is true iff (permissive) has been omitted*)
11629
481148b273b5 permissive option;
wenzelm
parents: 10775
diff changeset
   231
fun gen_add_recdef tfl_fn prep_att prep_hints strict raw_name R eq_srcs hints thy =
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   232
  let
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   233
    val _ = requires_recdef thy;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   234
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
   235
    val name = Sign.intern_const thy raw_name;
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   236
    val bname = Sign.base_name name;
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   237
    val _ = message ("Defining recursive function " ^ quote name ^ " ...");
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   238
8657
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
   239
    val ((eq_names, eqs), raw_eq_atts) = apfst split_list (split_list eq_srcs);
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
   240
    val eq_atts = map (map (prep_att thy)) raw_eq_atts;
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
   241
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   242
    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
   243
    (*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
   244
      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
   245
      give rise to looping conditional rewriting.*)
dfae7eb2830c Prevent recdef from looping when the inductio rule is simplified
paulson
parents: 12876
diff changeset
   246
    val (thy, {rules = rules_idx, induct, tcs}) =
dfae7eb2830c Prevent recdef from looping when the inductio rule is simplified
paulson
parents: 12876
diff changeset
   247
        tfl_fn strict thy cs (ss delcongs [imp_cong])
dfae7eb2830c Prevent recdef from looping when the inductio rule is simplified
paulson
parents: 12876
diff changeset
   248
               congs wfs name R eqs;
8657
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
   249
    val rules = map (map #1) (Library.partition_eq Library.eq_snd rules_idx);
12448
473cb9f9e237 Recursive equations to be used for code generation are now registered
berghofe
parents: 12371
diff changeset
   250
    val simp_att = if null tcs then
473cb9f9e237 Recursive equations to be used for code generation are now registered
berghofe
parents: 12371
diff changeset
   251
      [Simplifier.simp_add_global, RecfunCodegen.add] else [];
8657
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
   252
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
   253
    val (thy, (simps' :: rules', [induct'])) =
7798
42e94b618f34 return stored thms with proper naming in derivation;
wenzelm
parents: 7262
diff changeset
   254
      thy
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   255
      |> Theory.add_path bname
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
   256
      |> PureThy.add_thmss ((("simps", List.concat rules), simp_att) :: ((eq_names ~~ rules) ~~ eq_atts))
12755
a906a8b364f1 removed case_numbers (already covered by default);
wenzelm
parents: 12708
diff changeset
   257
      |>>> PureThy.add_thms [(("induct", induct), [])];
8657
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
   258
    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
   259
    val thy =
42e94b618f34 return stored thms with proper naming in derivation;
wenzelm
parents: 7262
diff changeset
   260
      thy
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   261
      |> put_recdef name result
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   262
      |> Theory.parent_path;
7798
42e94b618f34 return stored thms with proper naming in derivation;
wenzelm
parents: 7262
diff changeset
   263
  in (thy, result) end;
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   264
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   265
val add_recdef = gen_add_recdef Tfl.define Attrib.global_attribute prepare_hints;
11629
481148b273b5 permissive option;
wenzelm
parents: 10775
diff changeset
   266
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
   267
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   268
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   269
(* add_recdef_old -- legacy interface *)
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   270
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   271
fun prepare_hints_old thy (ss, thms) =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   272
  let val {simps, congs, wfs} = get_global_hints thy
15574
b1d1b5bfc464 Removed practically all references to Library.foldr.
skalberg
parents: 15570
diff changeset
   273
  in (Classical.claset_of thy, ss addsimps simps, map #2 (add_congs congs thms), wfs) end;
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   274
11629
481148b273b5 permissive option;
wenzelm
parents: 10775
diff changeset
   275
val add_recdef_old = gen_add_recdef Tfl.define Attrib.global_attribute prepare_hints_old false;
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   276
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   277
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   278
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   279
(** defer_recdef(_i) **)
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   280
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   281
fun gen_defer_recdef tfl_fn app_thms raw_name eqs raw_congs thy =
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   282
  let
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
   283
    val name = Sign.intern_const thy raw_name;
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   284
    val bname = Sign.base_name name;
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   285
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   286
    val _ = requires_recdef thy;
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   287
    val _ = message ("Deferred recursive function " ^ quote name ^ " ...");
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   288
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   289
    val (thy1, congs) = thy |> app_thms raw_congs;
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   290
    val (thy2, induct_rules) = tfl_fn thy1 congs name eqs;
8430
dbd897e0d804 adapted to new PureThy.add_thms etc.;
wenzelm
parents: 7798
diff changeset
   291
    val (thy3, [induct_rules']) =
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   292
      thy2
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   293
      |> Theory.add_path bname
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   294
      |> PureThy.add_thms [(("induct_rules", induct_rules), [])]
8430
dbd897e0d804 adapted to new PureThy.add_thms etc.;
wenzelm
parents: 7798
diff changeset
   295
      |>> Theory.parent_path;
dbd897e0d804 adapted to new PureThy.add_thms etc.;
wenzelm
parents: 7798
diff changeset
   296
  in (thy3, {induct_rules = induct_rules'}) end;
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   297
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   298
val defer_recdef = gen_defer_recdef Tfl.defer IsarThy.apply_theorems;
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   299
val defer_recdef_i = gen_defer_recdef Tfl.defer_i IsarThy.apply_theorems_i;
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   300
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   301
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   302
10775
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   303
(** recdef_tc(_i) **)
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   304
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   305
fun gen_recdef_tc prep_att prep_name (bname, raw_atts) raw_name opt_i int thy =
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   306
  let
16458
4c6fd0c01d28 accomodate change of TheoryDataFun;
wenzelm
parents: 16364
diff changeset
   307
    val name = prep_name thy raw_name;
10775
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   308
    val atts = map (prep_att thy) raw_atts;
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   309
    val tcs =
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   310
      (case get_recdef thy name of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15458
diff changeset
   311
        NONE => error ("No recdef definition of constant: " ^ quote name)
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15458
diff changeset
   312
      | SOME {tcs, ...} => tcs);
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
   313
    val i = getOpt (opt_i, 1);
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
   314
    val tc = List.nth (tcs, i - 1) handle Subscript =>
10775
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   315
      error ("No termination condition #" ^ string_of_int i ^
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   316
        " in recdef definition of " ^ quote name);
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   317
  in
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12755
diff changeset
   318
    thy
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12755
diff changeset
   319
    |> IsarThy.theorem_i Drule.internalK ((bname, atts), (HOLogic.mk_Trueprop tc, ([], []))) int
10775
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   320
  end;
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   321
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   322
val recdef_tc = gen_recdef_tc Attrib.global_attribute Sign.intern_const;
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   323
val recdef_tc_i = gen_recdef_tc (K I) (K I);
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   324
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   325
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   326
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   327
(** package setup **)
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   328
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   329
(* setup theory *)
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   330
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   331
val setup =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   332
 [GlobalRecdefData.init, LocalRecdefData.init,
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   333
  Attrib.add_attributes
9949
1741a61d4b33 tuned recdef hints;
wenzelm
parents: 9893
diff changeset
   334
   [(recdef_simpN, simp_attr, "declaration of recdef simp rule"),
1741a61d4b33 tuned recdef hints;
wenzelm
parents: 9893
diff changeset
   335
    (recdef_congN, cong_attr, "declaration of recdef cong rule"),
1741a61d4b33 tuned recdef hints;
wenzelm
parents: 9893
diff changeset
   336
    (recdef_wfN, wf_attr, "declaration of recdef wf rule")]];
6439
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   337
7eea9f25dc49 'HOL/recdef' theory data;
wenzelm
parents: 6429
diff changeset
   338
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   339
(* outer syntax *)
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   340
6723
f342449d73ca outer syntax keyword classification;
wenzelm
parents: 6576
diff changeset
   341
local structure P = OuterParse and K = OuterSyntax.Keyword in
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   342
9859
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   343
val hints =
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   344
  P.$$$ "(" |-- P.!!! (P.position (P.$$$ "hints" -- P.arguments) --| P.$$$ ")") >> Args.src;
2cd338998b53 recdef hints (attributes and modifiers);
wenzelm
parents: 9652
diff changeset
   345
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   346
val recdef_decl =
11629
481148b273b5 permissive option;
wenzelm
parents: 10775
diff changeset
   347
  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
   348
  P.name -- P.term -- Scan.repeat1 (P.opt_thm_name ":" -- P.prop) -- Scan.option hints
11629
481148b273b5 permissive option;
wenzelm
parents: 10775
diff changeset
   349
  >> (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
   350
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   351
val recdefP =
6723
f342449d73ca outer syntax keyword classification;
wenzelm
parents: 6576
diff changeset
   352
  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
   353
    (recdef_decl >> Toplevel.theory);
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   354
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   355
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   356
val defer_recdef_decl =
8657
b9475dad85ed recdef: admit names/atts;
wenzelm
parents: 8625
diff changeset
   357
  P.name -- Scan.repeat1 P.prop --
6723
f342449d73ca outer syntax keyword classification;
wenzelm
parents: 6576
diff changeset
   358
  Scan.optional (P.$$$ "(" |-- P.$$$ "congs" |-- P.!!! (P.xthms1 --| P.$$$ ")")) []
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   359
  >> (fn ((f, eqs), congs) => #1 o defer_recdef f eqs congs);
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   360
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   361
val defer_recdefP =
6723
f342449d73ca outer syntax keyword classification;
wenzelm
parents: 6576
diff changeset
   362
  OuterSyntax.command "defer_recdef" "defer general recursive functions (TFL)" K.thy_decl
6557
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   363
    (defer_recdef_decl >> Toplevel.theory);
d7e7532c128a peoper defer_recdef interface;
wenzelm
parents: 6520
diff changeset
   364
10775
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   365
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   366
val recdef_tc_decl =
12876
a70df1e5bf10 got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents: 12755
diff changeset
   367
  P.opt_thm_name ":" -- P.xname -- Scan.option (P.$$$ "(" |-- P.nat --| P.$$$ ")");
10775
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   368
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   369
fun mk_recdef_tc ((thm_name, name), i) = recdef_tc thm_name name i;
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   370
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   371
val recdef_tcP =
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   372
  OuterSyntax.command "recdef_tc" "recommence proof of termination condition (TFL)" K.thy_goal
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   373
    (recdef_tc_decl >> (Toplevel.print oo (Toplevel.theory_to_proof o mk_recdef_tc)));
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   374
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   375
11629
481148b273b5 permissive option;
wenzelm
parents: 10775
diff changeset
   376
val _ = OuterSyntax.add_keywords ["permissive", "congs", "hints"];
10775
3a5e5657e41c added recdef_tc(_i);
wenzelm
parents: 10268
diff changeset
   377
val _ = OuterSyntax.add_parsers [recdefP, defer_recdefP, recdef_tcP];
6429
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   378
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   379
end;
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   380
9771ce553e56 Wrapper module for Konrad Slind's TFL package.
wenzelm
parents:
diff changeset
   381
end;