src/Pure/Isar/context_rules.ML
author wenzelm
Sat, 21 Jan 2006 23:02:14 +0100
changeset 18728 6790126ab5f6
parent 18708 4b3dadb4fe33
child 18874 05585eee8d74
permissions -rw-r--r--
simplified type attribute;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Isar/context_rules.ML
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
     3
    Author:     Stefan Berghofer and Markus Wenzel, TU Muenchen
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
     4
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
     5
Declarations of intro/elim/dest rules in Pure (see also
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
     6
Provers/classical.ML for a more specialized version of the same idea).
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
     7
*)
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
     8
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
     9
signature CONTEXT_RULES =
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    10
sig
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    11
  type netpair
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    12
  type T
13372
18790d503fe0 module now right after ProofContext (for locales);
wenzelm
parents: 13105
diff changeset
    13
  val netpair_bang: ProofContext.context -> netpair
18790d503fe0 module now right after ProofContext (for locales);
wenzelm
parents: 13105
diff changeset
    14
  val netpair: ProofContext.context -> netpair
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    15
  val orderlist: ((int * int) * 'a) list -> 'a list
12399
wenzelm
parents: 12380
diff changeset
    16
  val find_rules_netpair: bool -> thm list -> term -> netpair -> thm list
13372
18790d503fe0 module now right after ProofContext (for locales);
wenzelm
parents: 13105
diff changeset
    17
  val find_rules: bool -> thm list -> term -> ProofContext.context -> thm list list
18637
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
    18
  val print_rules: Context.generic -> unit
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    19
  val addSWrapper: ((int -> tactic) -> int -> tactic) -> theory -> theory
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    20
  val addWrapper: ((int -> tactic) -> int -> tactic) -> theory -> theory
13372
18790d503fe0 module now right after ProofContext (for locales);
wenzelm
parents: 13105
diff changeset
    21
  val Swrap: ProofContext.context -> (int -> tactic) -> int -> tactic
18790d503fe0 module now right after ProofContext (for locales);
wenzelm
parents: 13105
diff changeset
    22
  val wrap: ProofContext.context -> (int -> tactic) -> int -> tactic
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    23
  val intro_bang: int option -> attribute
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    24
  val elim_bang: int option -> attribute
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    25
  val dest_bang: int option -> attribute
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    26
  val intro: int option -> attribute
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    27
  val elim: int option -> attribute
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    28
  val dest: int option -> attribute
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    29
  val intro_query: int option -> attribute
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    30
  val elim_query: int option -> attribute
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    31
  val dest_query: int option -> attribute
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    32
  val rule_del: attribute
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    33
  val add_args:
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    34
    (int option -> attribute) -> (int option -> attribute) -> (int option -> attribute) ->
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
    35
    Attrib.src -> attribute
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    36
end;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    37
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    38
structure ContextRules: CONTEXT_RULES =
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    39
struct
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    40
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    41
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    42
(** rule declaration contexts **)
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    43
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    44
(* rule kinds *)
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    45
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    46
val intro_bangK = (0, false);
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    47
val elim_bangK = (0, true);
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    48
val introK = (1, false);
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    49
val elimK = (1, true);
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    50
val intro_queryK = (2, false);
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    51
val elim_queryK = (2, true);
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    52
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    53
val kind_names =
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    54
 [(intro_bangK, "safe introduction rules (intro!)"),
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    55
  (elim_bangK, "safe elimination rules (elim!)"),
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    56
  (introK, "introduction rules (intro)"),
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    57
  (elimK, "elimination rules (elim)"),
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    58
  (intro_queryK, "extra introduction rules (intro?)"),
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    59
  (elim_queryK, "extra elimination rules (elim?)")];
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    60
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    61
val rule_kinds = map #1 kind_names;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    62
val rule_indexes = distinct (map #1 rule_kinds);
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    63
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    64
18637
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
    65
(* context data *)
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    66
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    67
type netpair = ((int * int) * (bool * thm)) Net.net * ((int * int) * (bool * thm)) Net.net;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    68
val empty_netpairs: netpair list = replicate (length rule_indexes) (Net.empty, Net.empty);
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    69
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    70
datatype T = Rules of
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    71
 {next: int,
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    72
  rules: (int * ((int * bool) * thm)) list,
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    73
  netpairs: netpair list,
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    74
  wrappers: (((int -> tactic) -> int -> tactic) * stamp) list *
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    75
    (((int -> tactic) -> int -> tactic) * stamp) list};
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    76
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    77
fun make_rules next rules netpairs wrappers =
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    78
  Rules {next = next, rules = rules, netpairs = netpairs, wrappers = wrappers};
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    79
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    80
fun add_rule (i, b) opt_w th (Rules {next, rules, netpairs, wrappers}) =
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
    81
  let val w = (case opt_w of SOME w => w | NONE => Tactic.subgoals_of_brl (b, th)) in
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    82
    make_rules (next - 1) ((w, ((i, b), th)) :: rules)
18011
685d95c793ff cleaned up nth, nth_update, nth_map and nth_string functions
haftmann
parents: 17511
diff changeset
    83
      (nth_map i (curry insert_tagged_brl ((w, next), (b, th))) netpairs) wrappers
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    84
  end;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    85
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    86
fun del_rule th (rs as Rules {next, rules, netpairs, wrappers}) =
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    87
  let
13105
3d1e7a199bdc use eq_thm_prop instead of slightly inadequate eq_thm;
wenzelm
parents: 12805
diff changeset
    88
    fun eq_th (_, (_, th')) = Drule.eq_thm_prop (th, th');
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    89
    fun del b netpair = delete_tagged_brl ((b, th), netpair) handle Net.DELETE => netpair;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    90
  in
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    91
    if not (exists eq_th rules) then rs
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    92
    else make_rules next (filter_out eq_th rules) (map (del false o del true) netpairs) wrappers
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    93
  end;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    94
18637
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
    95
structure Rules = GenericDataFun
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
    96
(
17511
wenzelm
parents: 17496
diff changeset
    97
  val name = "Isar/rules";
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    98
  type T = T;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    99
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   100
  val empty = make_rules ~1 [] empty_netpairs ([], []);
16424
18a07ad8fea8 accomodate change of TheoryDataFun;
wenzelm
parents: 15973
diff changeset
   101
  val extend = I;
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   102
16424
18a07ad8fea8 accomodate change of TheoryDataFun;
wenzelm
parents: 15973
diff changeset
   103
  fun merge _ (Rules {rules = rules1, wrappers = (ws1, ws1'), ...},
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   104
      Rules {rules = rules2, wrappers = (ws2, ws2'), ...}) =
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   105
    let
18637
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   106
      val wrappers =
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   107
        (gen_merge_lists' (eq_snd (op =)) ws1 ws2, gen_merge_lists' (eq_snd (op =)) ws1' ws2');
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   108
      val rules = gen_merge_lists' (fn ((_, (k1, th1)), (_, (k2, th2))) =>
13105
3d1e7a199bdc use eq_thm_prop instead of slightly inadequate eq_thm;
wenzelm
parents: 12805
diff changeset
   109
          k1 = k2 andalso Drule.eq_thm_prop (th1, th2)) rules1 rules2;
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   110
      val next = ~ (length rules);
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
   111
      val netpairs = Library.foldl (fn (nps, (n, (w, ((i, b), th)))) =>
18011
685d95c793ff cleaned up nth, nth_update, nth_map and nth_string functions
haftmann
parents: 17511
diff changeset
   112
          nth_map i (curry insert_tagged_brl ((w, n), (b, th))) nps)
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   113
        (empty_netpairs, next upto ~1 ~~ rules);
18637
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   114
    in make_rules (next - 1) rules netpairs wrappers end
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   115
18637
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   116
  fun print generic (Rules {rules, ...}) =
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   117
    let
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   118
      val ctxt = Context.proof_of generic;
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   119
      fun prt_kind (i, b) =
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   120
        Pretty.big_list ((the o AList.lookup (op =) kind_names) (i, b) ^ ":")
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   121
          (List.mapPartial (fn (_, (k, th)) =>
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   122
              if k = (i, b) then SOME (ProofContext.pretty_thm ctxt th) else NONE)
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   123
            (sort (int_ord o pairself fst) rules));
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   124
    in Pretty.writeln (Pretty.chunks (map prt_kind rule_kinds)) end;
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   125
);
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   126
18708
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18692
diff changeset
   127
val _ = Context.add_setup Rules.init;
18637
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   128
val print_rules = Rules.print;
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   129
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   130
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   131
(* access data *)
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   132
18637
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   133
fun netpairs ctxt = let val Rules {netpairs, ...} = Rules.get (Context.Proof ctxt) in netpairs end;
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   134
val netpair_bang = hd o netpairs;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   135
val netpair = hd o tl o netpairs;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   136
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   137
12399
wenzelm
parents: 12380
diff changeset
   138
(* retrieving rules *)
wenzelm
parents: 12380
diff changeset
   139
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   140
fun untaglist [] = []
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   141
  | untaglist [(k : int * int, x)] = [x]
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   142
  | untaglist ((k, x) :: (rest as (k', x') :: _)) =
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   143
      if k = k' then untaglist rest
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   144
      else x :: untaglist rest;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   145
16424
18a07ad8fea8 accomodate change of TheoryDataFun;
wenzelm
parents: 15973
diff changeset
   146
fun orderlist brls =
16512
wenzelm
parents: 16424
diff changeset
   147
  untaglist (sort (prod_ord int_ord int_ord o pairself fst) brls);
16424
18a07ad8fea8 accomodate change of TheoryDataFun;
wenzelm
parents: 15973
diff changeset
   148
18a07ad8fea8 accomodate change of TheoryDataFun;
wenzelm
parents: 15973
diff changeset
   149
fun orderlist_no_weight brls =
16512
wenzelm
parents: 16424
diff changeset
   150
  untaglist (sort (int_ord o pairself (snd o fst)) brls);
12399
wenzelm
parents: 12380
diff changeset
   151
wenzelm
parents: 12380
diff changeset
   152
fun may_unify weighted t net =
wenzelm
parents: 12380
diff changeset
   153
  map snd ((if weighted then orderlist else orderlist_no_weight) (Net.unify_term net t));
wenzelm
parents: 12380
diff changeset
   154
wenzelm
parents: 12380
diff changeset
   155
fun find_erules _ [] = K []
12805
3be853cf19cf Thm.prop_of;
wenzelm
parents: 12412
diff changeset
   156
  | find_erules w (fact :: _) = may_unify w (Logic.strip_assums_concl (Thm.prop_of fact));
16424
18a07ad8fea8 accomodate change of TheoryDataFun;
wenzelm
parents: 15973
diff changeset
   157
12399
wenzelm
parents: 12380
diff changeset
   158
fun find_irules w goal = may_unify w (Logic.strip_assums_concl goal);
12380
3402d300f5ef export low-level addXXs;
wenzelm
parents: 12350
diff changeset
   159
12399
wenzelm
parents: 12380
diff changeset
   160
fun find_rules_netpair weighted facts goal (inet, enet) =
wenzelm
parents: 12380
diff changeset
   161
  find_erules weighted facts enet @ find_irules weighted goal inet;
12380
3402d300f5ef export low-level addXXs;
wenzelm
parents: 12350
diff changeset
   162
16424
18a07ad8fea8 accomodate change of TheoryDataFun;
wenzelm
parents: 15973
diff changeset
   163
fun find_rules weighted facts goals =
18a07ad8fea8 accomodate change of TheoryDataFun;
wenzelm
parents: 15973
diff changeset
   164
  map (find_rules_netpair weighted facts goals) o netpairs;
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   165
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   166
12399
wenzelm
parents: 12380
diff changeset
   167
(* wrappers *)
wenzelm
parents: 12380
diff changeset
   168
18667
wenzelm
parents: 18637
diff changeset
   169
fun gen_add_wrapper upd w =
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   170
  Context.theory_map (Rules.map (fn (rs as Rules {next, rules, netpairs, wrappers}) =>
18667
wenzelm
parents: 18637
diff changeset
   171
    make_rules next rules netpairs (upd (fn ws => (w, stamp ()) :: ws) wrappers)));
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   172
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   173
val addSWrapper = gen_add_wrapper Library.apfst;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   174
val addWrapper = gen_add_wrapper Library.apsnd;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   175
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   176
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   177
fun gen_wrap which ctxt =
18637
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   178
  let val Rules {wrappers, ...} = Rules.get (Context.Proof ctxt)
17351
wenzelm
parents: 17314
diff changeset
   179
  in fold_rev fst (which wrappers) end;
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   180
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   181
val Swrap = gen_wrap #1;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   182
val wrap = gen_wrap #2;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   183
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   184
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   185
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   186
(** attributes **)
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   187
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   188
(* add and del rules *)
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   189
18637
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   190
fun rule_del (x, th) =
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   191
  (Rules.map (del_rule th o del_rule (Tactic.make_elim th)) x, th);
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   192
18637
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   193
fun rule_add k view opt_w =
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   194
  (fn (x, th) => (Rules.map (add_rule k opt_w (view th)) x, th)) o rule_del;
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   195
18637
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   196
val intro_bang  = rule_add intro_bangK I;
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   197
val elim_bang   = rule_add elim_bangK I;
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   198
val dest_bang   = rule_add elim_bangK Tactic.make_elim;
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   199
val intro       = rule_add introK I;
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   200
val elim        = rule_add elimK I;
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   201
val dest        = rule_add elimK Tactic.make_elim;
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   202
val intro_query = rule_add intro_queryK I;
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   203
val elim_query  = rule_add elim_queryK I;
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   204
val dest_query  = rule_add elim_queryK Tactic.make_elim;
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   205
18637
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   206
val _ = Context.add_setup
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   207
  (snd o PureThy.add_thms [(("", Drule.equal_intr_rule), [intro_query NONE])]);
18637
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   208
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   209
18637
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   210
(* concrete syntax *)
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   211
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   212
fun add_args a b c x = Attrib.syntax
18692
2270e25e9128 export add_args;
wenzelm
parents: 18667
diff changeset
   213
  (Scan.lift ((Args.bang >> K a || Args.query >> K c || Scan.succeed b) -- Scan.option Args.nat)
18637
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   214
    >> (fn (f, n) => f n)) x;
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   215
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   216
val rule_atts =
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   217
 [("intro", add_args intro_bang intro intro_query, "declaration of introduction rule"),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   218
  ("elim", add_args elim_bang elim elim_query, "declaration of elimination rule"),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   219
  ("dest", add_args dest_bang dest dest_query, "declaration of destruction rule"),
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18708
diff changeset
   220
  ("rule", Attrib.syntax (Scan.lift Args.del >> K rule_del),
18637
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   221
    "remove declaration of intro/elim/dest rule")];
33a6f6caa617 generic data and attributes;
wenzelm
parents: 18418
diff changeset
   222
18708
4b3dadb4fe33 setup: theory -> theory;
wenzelm
parents: 18692
diff changeset
   223
val _ = Context.add_setup (Attrib.add_attributes rule_atts);
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   224
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   225
end;