src/Pure/Isar/context_rules.ML
author haftmann
Fri, 28 Oct 2005 16:35:40 +0200
changeset 18011 685d95c793ff
parent 17511 51314f4bd01d
child 18377 0e1d025d57b3
permissions -rw-r--r--
cleaned up nth, nth_update, nth_map and nth_string functions
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
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
     5
Declarations of intro/elim/dest rules in Pure; see
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
     6
Provers/classical.ML for a more specialized version of the same idea.
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
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    18
  val print_global_rules: theory -> unit
13372
18790d503fe0 module now right after ProofContext (for locales);
wenzelm
parents: 13105
diff changeset
    19
  val print_local_rules: ProofContext.context -> unit
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    20
  val addSWrapper: ((int -> tactic) -> int -> tactic) -> theory -> theory
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    21
  val addWrapper: ((int -> tactic) -> int -> tactic) -> theory -> theory
13372
18790d503fe0 module now right after ProofContext (for locales);
wenzelm
parents: 13105
diff changeset
    22
  val Swrap: ProofContext.context -> (int -> tactic) -> int -> tactic
18790d503fe0 module now right after ProofContext (for locales);
wenzelm
parents: 13105
diff changeset
    23
  val wrap: ProofContext.context -> (int -> tactic) -> int -> tactic
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    24
  val intro_bang_global: int option -> theory attribute
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    25
  val elim_bang_global: int option -> theory attribute
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    26
  val dest_bang_global: int option -> theory attribute
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    27
  val intro_global: int option -> theory attribute
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    28
  val elim_global: int option -> theory attribute
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    29
  val dest_global: int option -> theory attribute
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    30
  val intro_query_global: int option -> theory attribute
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    31
  val elim_query_global: int option -> theory attribute
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    32
  val dest_query_global: int option -> theory attribute
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    33
  val rule_del_global: theory attribute
13372
18790d503fe0 module now right after ProofContext (for locales);
wenzelm
parents: 13105
diff changeset
    34
  val intro_bang_local: int option -> ProofContext.context attribute
18790d503fe0 module now right after ProofContext (for locales);
wenzelm
parents: 13105
diff changeset
    35
  val elim_bang_local: int option -> ProofContext.context attribute
18790d503fe0 module now right after ProofContext (for locales);
wenzelm
parents: 13105
diff changeset
    36
  val dest_bang_local: int option -> ProofContext.context attribute
18790d503fe0 module now right after ProofContext (for locales);
wenzelm
parents: 13105
diff changeset
    37
  val intro_local: int option -> ProofContext.context attribute
18790d503fe0 module now right after ProofContext (for locales);
wenzelm
parents: 13105
diff changeset
    38
  val elim_local: int option -> ProofContext.context attribute
18790d503fe0 module now right after ProofContext (for locales);
wenzelm
parents: 13105
diff changeset
    39
  val dest_local: int option -> ProofContext.context attribute
18790d503fe0 module now right after ProofContext (for locales);
wenzelm
parents: 13105
diff changeset
    40
  val intro_query_local: int option -> ProofContext.context attribute
18790d503fe0 module now right after ProofContext (for locales);
wenzelm
parents: 13105
diff changeset
    41
  val elim_query_local: int option -> ProofContext.context attribute
18790d503fe0 module now right after ProofContext (for locales);
wenzelm
parents: 13105
diff changeset
    42
  val dest_query_local: int option -> ProofContext.context attribute
18790d503fe0 module now right after ProofContext (for locales);
wenzelm
parents: 13105
diff changeset
    43
  val rule_del_local: ProofContext.context attribute
12380
3402d300f5ef export low-level addXXs;
wenzelm
parents: 12350
diff changeset
    44
  val addXIs_global: theory * thm list -> theory
3402d300f5ef export low-level addXXs;
wenzelm
parents: 12350
diff changeset
    45
  val addXEs_global: theory * thm list -> theory
3402d300f5ef export low-level addXXs;
wenzelm
parents: 12350
diff changeset
    46
  val addXDs_global: theory * thm list -> theory
3402d300f5ef export low-level addXXs;
wenzelm
parents: 12350
diff changeset
    47
  val delrules_global: theory * thm list -> theory
13372
18790d503fe0 module now right after ProofContext (for locales);
wenzelm
parents: 13105
diff changeset
    48
  val addXIs_local: ProofContext.context * thm list -> ProofContext.context
18790d503fe0 module now right after ProofContext (for locales);
wenzelm
parents: 13105
diff changeset
    49
  val addXEs_local: ProofContext.context * thm list -> ProofContext.context
18790d503fe0 module now right after ProofContext (for locales);
wenzelm
parents: 13105
diff changeset
    50
  val addXDs_local: ProofContext.context * thm list -> ProofContext.context
18790d503fe0 module now right after ProofContext (for locales);
wenzelm
parents: 13105
diff changeset
    51
  val delrules_local: ProofContext.context * thm list -> ProofContext.context
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    52
end;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    53
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    54
structure ContextRules: CONTEXT_RULES =
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    55
struct
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    56
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    57
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    58
(** rule declaration contexts **)
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    59
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    60
(* rule kinds *)
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    61
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    62
val intro_bangK = (0, false);
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    63
val elim_bangK = (0, true);
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    64
val introK = (1, false);
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    65
val elimK = (1, true);
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    66
val intro_queryK = (2, false);
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    67
val elim_queryK = (2, true);
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    68
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    69
val kind_names =
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    70
 [(intro_bangK, "safe introduction rules (intro!)"),
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    71
  (elim_bangK, "safe elimination rules (elim!)"),
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    72
  (introK, "introduction rules (intro)"),
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    73
  (elimK, "elimination rules (elim)"),
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    74
  (intro_queryK, "extra introduction rules (intro?)"),
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    75
  (elim_queryK, "extra elimination rules (elim?)")];
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
val rule_kinds = map #1 kind_names;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    78
val rule_indexes = distinct (map #1 rule_kinds);
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
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    81
(* raw data *)
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    82
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    83
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
    84
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
    85
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    86
datatype T = Rules of
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    87
 {next: int,
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    88
  rules: (int * ((int * bool) * thm)) list,
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    89
  netpairs: netpair list,
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    90
  wrappers: (((int -> tactic) -> int -> tactic) * stamp) list *
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    91
    (((int -> tactic) -> int -> tactic) * stamp) list};
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    92
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    93
fun make_rules next rules netpairs wrappers =
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    94
  Rules {next = next, rules = rules, netpairs = netpairs, wrappers = wrappers};
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    95
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
    96
fun add_rule (i, b) opt_w th (Rules {next, rules, netpairs, wrappers}) =
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
    97
  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
    98
    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
    99
      (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
   100
  end;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   101
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   102
fun del_rule th (rs as Rules {next, rules, netpairs, wrappers}) =
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   103
  let
13105
3d1e7a199bdc use eq_thm_prop instead of slightly inadequate eq_thm;
wenzelm
parents: 12805
diff changeset
   104
    fun eq_th (_, (_, th')) = Drule.eq_thm_prop (th, th');
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   105
    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
   106
  in
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   107
    if not (exists eq_th rules) then rs
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   108
    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
   109
  end;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   110
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   111
fun print_rules prt x (Rules {rules, ...}) =
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   112
  let
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   113
    fun prt_kind (i, b) =
17314
04e21a27c0ad introduces some modern-style AList operations
haftmann
parents: 16512
diff changeset
   114
      Pretty.big_list ((the o AList.lookup (op =) kind_names) (i, b) ^ ":")
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
   115
        (List.mapPartial (fn (_, (k, th)) => if k = (i, b) then SOME (prt x th) else NONE)
16512
wenzelm
parents: 16424
diff changeset
   116
          (sort (int_ord o pairself fst) rules));
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   117
  in Pretty.writeln (Pretty.chunks (map prt_kind rule_kinds)) end;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   118
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   119
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   120
(* theory and proof data *)
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   121
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   122
structure GlobalRulesArgs =
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   123
struct
17511
wenzelm
parents: 17496
diff changeset
   124
  val name = "Isar/rules";
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   125
  type T = T;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   126
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   127
  val empty = make_rules ~1 [] empty_netpairs ([], []);
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   128
  val copy = I;
16424
18a07ad8fea8 accomodate change of TheoryDataFun;
wenzelm
parents: 15973
diff changeset
   129
  val extend = I;
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   130
16424
18a07ad8fea8 accomodate change of TheoryDataFun;
wenzelm
parents: 15973
diff changeset
   131
  fun merge _ (Rules {rules = rules1, wrappers = (ws1, ws1'), ...},
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   132
      Rules {rules = rules2, wrappers = (ws2, ws2'), ...}) =
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   133
    let
17496
26535df536ae slight adaptions to library changes
haftmann
parents: 17351
diff changeset
   134
      val wrappers = (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
   135
      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
   136
          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
   137
      val next = ~ (length rules);
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
   138
      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
   139
          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
   140
        (empty_netpairs, next upto ~1 ~~ rules);
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   141
    in make_rules (next - 1) rules netpairs wrappers end;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   142
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   143
  val print = print_rules Display.pretty_thm_sg;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   144
end;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   145
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   146
structure GlobalRules = TheoryDataFun(GlobalRulesArgs);
15801
d2f5ca3c048d superceded by Pure.thy and CPure.thy;
wenzelm
parents: 15574
diff changeset
   147
val _ = Context.add_setup [GlobalRules.init];
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   148
val print_global_rules = GlobalRules.print;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   149
16424
18a07ad8fea8 accomodate change of TheoryDataFun;
wenzelm
parents: 15973
diff changeset
   150
structure LocalRules = ProofDataFun
18a07ad8fea8 accomodate change of TheoryDataFun;
wenzelm
parents: 15973
diff changeset
   151
(struct
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   152
  val name = GlobalRulesArgs.name;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   153
  type T = GlobalRulesArgs.T;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   154
  val init = GlobalRules.get;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   155
  val print = print_rules ProofContext.pretty_thm;
16424
18a07ad8fea8 accomodate change of TheoryDataFun;
wenzelm
parents: 15973
diff changeset
   156
end);
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   157
15801
d2f5ca3c048d superceded by Pure.thy and CPure.thy;
wenzelm
parents: 15574
diff changeset
   158
val _ = Context.add_setup [LocalRules.init];
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   159
val print_local_rules = LocalRules.print;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   160
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   161
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   162
(* access data *)
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   163
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   164
fun netpairs ctxt = let val Rules {netpairs, ...} = LocalRules.get ctxt in netpairs end;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   165
val netpair_bang = hd o netpairs;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   166
val netpair = hd o tl o netpairs;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   167
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   168
12399
wenzelm
parents: 12380
diff changeset
   169
(* retrieving rules *)
wenzelm
parents: 12380
diff changeset
   170
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   171
fun untaglist [] = []
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   172
  | untaglist [(k : int * int, x)] = [x]
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   173
  | untaglist ((k, x) :: (rest as (k', x') :: _)) =
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   174
      if k = k' then untaglist rest
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   175
      else x :: untaglist rest;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   176
16424
18a07ad8fea8 accomodate change of TheoryDataFun;
wenzelm
parents: 15973
diff changeset
   177
fun orderlist brls =
16512
wenzelm
parents: 16424
diff changeset
   178
  untaglist (sort (prod_ord int_ord int_ord o pairself fst) brls);
16424
18a07ad8fea8 accomodate change of TheoryDataFun;
wenzelm
parents: 15973
diff changeset
   179
18a07ad8fea8 accomodate change of TheoryDataFun;
wenzelm
parents: 15973
diff changeset
   180
fun orderlist_no_weight brls =
16512
wenzelm
parents: 16424
diff changeset
   181
  untaglist (sort (int_ord o pairself (snd o fst)) brls);
12399
wenzelm
parents: 12380
diff changeset
   182
wenzelm
parents: 12380
diff changeset
   183
fun may_unify weighted t net =
wenzelm
parents: 12380
diff changeset
   184
  map snd ((if weighted then orderlist else orderlist_no_weight) (Net.unify_term net t));
wenzelm
parents: 12380
diff changeset
   185
wenzelm
parents: 12380
diff changeset
   186
fun find_erules _ [] = K []
12805
3be853cf19cf Thm.prop_of;
wenzelm
parents: 12412
diff changeset
   187
  | 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
   188
12399
wenzelm
parents: 12380
diff changeset
   189
fun find_irules w goal = may_unify w (Logic.strip_assums_concl goal);
12380
3402d300f5ef export low-level addXXs;
wenzelm
parents: 12350
diff changeset
   190
12399
wenzelm
parents: 12380
diff changeset
   191
fun find_rules_netpair weighted facts goal (inet, enet) =
wenzelm
parents: 12380
diff changeset
   192
  find_erules weighted facts enet @ find_irules weighted goal inet;
12380
3402d300f5ef export low-level addXXs;
wenzelm
parents: 12350
diff changeset
   193
16424
18a07ad8fea8 accomodate change of TheoryDataFun;
wenzelm
parents: 15973
diff changeset
   194
fun find_rules weighted facts goals =
18a07ad8fea8 accomodate change of TheoryDataFun;
wenzelm
parents: 15973
diff changeset
   195
  map (find_rules_netpair weighted facts goals) o netpairs;
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   196
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   197
12399
wenzelm
parents: 12380
diff changeset
   198
(* wrappers *)
wenzelm
parents: 12380
diff changeset
   199
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   200
fun gen_add_wrapper upd w = GlobalRules.map (fn (rs as Rules {next, rules, netpairs, wrappers}) =>
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   201
  make_rules next rules netpairs (upd (fn ws => (w, stamp ()) :: ws) wrappers));
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   202
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   203
val addSWrapper = gen_add_wrapper Library.apfst;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   204
val addWrapper = gen_add_wrapper Library.apsnd;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   205
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   206
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   207
fun gen_wrap which ctxt =
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   208
  let val Rules {wrappers, ...} = LocalRules.get ctxt
17351
wenzelm
parents: 17314
diff changeset
   209
  in fold_rev fst (which wrappers) end;
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   210
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   211
val Swrap = gen_wrap #1;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   212
val wrap = gen_wrap #2;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   213
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   214
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   215
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   216
(** attributes **)
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   217
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   218
(* add and del rules *)
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   219
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   220
local
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   221
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   222
fun del map_data (x, th) =
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   223
  (map_data (del_rule th o del_rule (Tactic.make_elim th)) x, th);
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
fun add k view map_data opt_w =
12412
d0857ea70f23 fixed dest atts;
wenzelm
parents: 12399
diff changeset
   226
  (fn (x, th) => (map_data (add_rule k opt_w (view th)) x, th)) o del map_data;
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   227
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   228
in
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   229
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   230
val intro_bang_global  = add intro_bangK I GlobalRules.map;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   231
val elim_bang_global   = add elim_bangK I GlobalRules.map;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   232
val dest_bang_global   = add elim_bangK Tactic.make_elim GlobalRules.map;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   233
val intro_global       = add introK I GlobalRules.map;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   234
val elim_global        = add elimK I GlobalRules.map;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   235
val dest_global        = add elimK Tactic.make_elim GlobalRules.map;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   236
val intro_query_global = add intro_queryK I GlobalRules.map;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   237
val elim_query_global  = add elim_queryK I GlobalRules.map;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   238
val dest_query_global  = add elim_queryK Tactic.make_elim GlobalRules.map;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   239
val rule_del_global    = del GlobalRules.map;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   240
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   241
val intro_bang_local   = add intro_bangK I LocalRules.map;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   242
val elim_bang_local    = add elim_bangK I LocalRules.map;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   243
val dest_bang_local    = add elim_bangK Tactic.make_elim LocalRules.map;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   244
val intro_local        = add introK I LocalRules.map;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   245
val elim_local         = add elimK I LocalRules.map;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   246
val dest_local         = add elimK Tactic.make_elim LocalRules.map;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   247
val intro_query_local  = add intro_queryK I LocalRules.map;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   248
val elim_query_local   = add elim_queryK I LocalRules.map;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   249
val dest_query_local   = add elim_queryK Tactic.make_elim LocalRules.map;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   250
val rule_del_local     = del LocalRules.map;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   251
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   252
end;
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   253
15801
d2f5ca3c048d superceded by Pure.thy and CPure.thy;
wenzelm
parents: 15574
diff changeset
   254
val _ = Context.add_setup
d2f5ca3c048d superceded by Pure.thy and CPure.thy;
wenzelm
parents: 15574
diff changeset
   255
  [#1 o PureThy.add_thms [(("", Drule.equal_intr_rule), [intro_query_global NONE])]];
d2f5ca3c048d superceded by Pure.thy and CPure.thy;
wenzelm
parents: 15574
diff changeset
   256
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   257
12380
3402d300f5ef export low-level addXXs;
wenzelm
parents: 12350
diff changeset
   258
(* low-level modifiers *)
3402d300f5ef export low-level addXXs;
wenzelm
parents: 12350
diff changeset
   259
3402d300f5ef export low-level addXXs;
wenzelm
parents: 12350
diff changeset
   260
fun modifier att (x, ths) =
3402d300f5ef export low-level addXXs;
wenzelm
parents: 12350
diff changeset
   261
  #1 (Thm.applys_attributes ((x, rev ths), [att]));
3402d300f5ef export low-level addXXs;
wenzelm
parents: 12350
diff changeset
   262
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
   263
val addXIs_global = modifier (intro_query_global NONE);
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
   264
val addXEs_global = modifier (elim_query_global NONE);
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
   265
val addXDs_global = modifier (dest_query_global NONE);
12380
3402d300f5ef export low-level addXXs;
wenzelm
parents: 12350
diff changeset
   266
val delrules_global = modifier rule_del_global;
3402d300f5ef export low-level addXXs;
wenzelm
parents: 12350
diff changeset
   267
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
   268
val addXIs_local = modifier (intro_query_local NONE);
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
   269
val addXEs_local = modifier (elim_query_local NONE);
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
   270
val addXDs_local = modifier (dest_query_local NONE);
12380
3402d300f5ef export low-level addXXs;
wenzelm
parents: 12350
diff changeset
   271
val delrules_local = modifier rule_del_local;
3402d300f5ef export low-level addXXs;
wenzelm
parents: 12350
diff changeset
   272
12350
5fad0e7129c3 renamed rule_context.ML to context_rules.ML;
wenzelm
parents:
diff changeset
   273
end;