src/Pure/tactic.ML
author wenzelm
Wed, 31 Jul 2019 19:50:38 +0200
changeset 70451 550a5a822edb
parent 69101 991a3feaf270
child 74282 c2ee8d993d6a
permissions -rw-r--r--
clarified export: retain proof boxes as local definitions -- more scalable;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10805
89a29437cebc added norm_hhf(_tac);
wenzelm
parents: 10444
diff changeset
     1
(*  Title:      Pure/tactic.ML
89a29437cebc added norm_hhf(_tac);
wenzelm
parents: 10444
diff changeset
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     3
29276
94b1ffec9201 qualified Term.rename_wrt_term;
wenzelm
parents: 27243
diff changeset
     4
Fundamental tactics.
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     5
*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     6
11774
3bc4f67d7fe1 qualify some names;
wenzelm
parents: 11768
diff changeset
     7
signature BASIC_TACTIC =
3bc4f67d7fe1 qualify some names;
wenzelm
parents: 11768
diff changeset
     8
sig
23223
7791128b39a9 cleaned up signature;
wenzelm
parents: 23178
diff changeset
     9
  val trace_goalno_tac: (int -> tactic) -> int -> tactic
36546
a9873318fe30 proper context for rule_by_tactic;
wenzelm
parents: 36354
diff changeset
    10
  val rule_by_tactic: Proof.context -> tactic -> thm -> thm
58963
26bf09b95dda proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents: 58957
diff changeset
    11
  val assume_tac: Proof.context -> int -> tactic
23223
7791128b39a9 cleaned up signature;
wenzelm
parents: 23178
diff changeset
    12
  val eq_assume_tac: int -> tactic
58956
a816aa3ff391 proper context for compose_tac, Splitter.split_tac (relevant for unify trace options);
wenzelm
parents: 58950
diff changeset
    13
  val compose_tac: Proof.context -> (bool * thm * int) -> int -> tactic
23223
7791128b39a9 cleaned up signature;
wenzelm
parents: 23178
diff changeset
    14
  val make_elim: thm -> thm
59498
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 59164
diff changeset
    15
  val biresolve0_tac: (bool * thm) list -> int -> tactic
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 59164
diff changeset
    16
  val biresolve_tac: Proof.context -> (bool * thm) list -> int -> tactic
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 59164
diff changeset
    17
  val resolve0_tac: thm list -> int -> tactic
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 59164
diff changeset
    18
  val resolve_tac: Proof.context -> thm list -> int -> tactic
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 59164
diff changeset
    19
  val eresolve0_tac: thm list -> int -> tactic
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 59164
diff changeset
    20
  val eresolve_tac: Proof.context -> thm list -> int -> tactic
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 59164
diff changeset
    21
  val forward_tac: Proof.context -> thm list -> int -> tactic
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 59164
diff changeset
    22
  val dresolve0_tac: thm list -> int -> tactic
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 59164
diff changeset
    23
  val dresolve_tac: Proof.context -> thm list -> int -> tactic
60774
6c28d8ed2488 proper context;
wenzelm
parents: 59749
diff changeset
    24
  val ares_tac: Proof.context -> thm list -> int -> tactic
59498
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 59164
diff changeset
    25
  val solve_tac: Proof.context -> thm list -> int -> tactic
58957
c9e744ea8a38 proper context for match_tac etc.;
wenzelm
parents: 58956
diff changeset
    26
  val bimatch_tac: Proof.context -> (bool * thm) list -> int -> tactic
c9e744ea8a38 proper context for match_tac etc.;
wenzelm
parents: 58956
diff changeset
    27
  val match_tac: Proof.context -> thm list -> int -> tactic
c9e744ea8a38 proper context for match_tac etc.;
wenzelm
parents: 58956
diff changeset
    28
  val ematch_tac: Proof.context -> thm list -> int -> tactic
c9e744ea8a38 proper context for match_tac etc.;
wenzelm
parents: 58956
diff changeset
    29
  val dmatch_tac: Proof.context -> thm list -> int -> tactic
58950
d07464875dd4 optional proof context for unify operations, for the sake of proper local options;
wenzelm
parents: 58837
diff changeset
    30
  val flexflex_tac: Proof.context -> tactic
23223
7791128b39a9 cleaned up signature;
wenzelm
parents: 23178
diff changeset
    31
  val distinct_subgoals_tac: tactic
46704
f800eb467515 simplified cut_tac (cf. d549b5b0f344);
wenzelm
parents: 46472
diff changeset
    32
  val cut_tac: thm -> int -> tactic
23223
7791128b39a9 cleaned up signature;
wenzelm
parents: 23178
diff changeset
    33
  val cut_rules_tac: thm list -> int -> tactic
7791128b39a9 cleaned up signature;
wenzelm
parents: 23178
diff changeset
    34
  val cut_facts_tac: thm list -> int -> tactic
7791128b39a9 cleaned up signature;
wenzelm
parents: 23178
diff changeset
    35
  val filter_thms: (term * term -> bool) -> int * term * thm list -> thm list
59164
ff40c53d1af9 proper context for "net" tactics;
wenzelm
parents: 58963
diff changeset
    36
  val biresolution_from_nets_tac: Proof.context ->
ff40c53d1af9 proper context for "net" tactics;
wenzelm
parents: 58963
diff changeset
    37
    ('a list -> (bool * thm) list) -> bool -> 'a Net.net * 'a Net.net -> int -> tactic
ff40c53d1af9 proper context for "net" tactics;
wenzelm
parents: 58963
diff changeset
    38
  val biresolve_from_nets_tac: Proof.context ->
ff40c53d1af9 proper context for "net" tactics;
wenzelm
parents: 58963
diff changeset
    39
    (int * (bool * thm)) Net.net * (int * (bool * thm)) Net.net -> int -> tactic
ff40c53d1af9 proper context for "net" tactics;
wenzelm
parents: 58963
diff changeset
    40
  val bimatch_from_nets_tac: Proof.context ->
ff40c53d1af9 proper context for "net" tactics;
wenzelm
parents: 58963
diff changeset
    41
    (int * (bool * thm)) Net.net * (int * (bool * thm)) Net.net -> int -> tactic
ff40c53d1af9 proper context for "net" tactics;
wenzelm
parents: 58963
diff changeset
    42
  val filt_resolve_from_net_tac: Proof.context -> int -> (int * thm) Net.net -> int -> tactic
ff40c53d1af9 proper context for "net" tactics;
wenzelm
parents: 58963
diff changeset
    43
  val resolve_from_net_tac: Proof.context -> (int * thm) Net.net -> int -> tactic
ff40c53d1af9 proper context for "net" tactics;
wenzelm
parents: 58963
diff changeset
    44
  val match_from_net_tac: Proof.context -> (int * thm) Net.net -> int -> tactic
23223
7791128b39a9 cleaned up signature;
wenzelm
parents: 23178
diff changeset
    45
  val subgoals_of_brl: bool * thm -> int
7791128b39a9 cleaned up signature;
wenzelm
parents: 23178
diff changeset
    46
  val lessb: (bool * thm) * (bool * thm) -> bool
27243
d549b5b0f344 removed obsolete global instantiation tactics (cf. Isar/rule_insts.ML);
wenzelm
parents: 27209
diff changeset
    47
  val rename_tac: string list -> int -> tactic
23223
7791128b39a9 cleaned up signature;
wenzelm
parents: 23178
diff changeset
    48
  val rotate_tac: int -> int -> tactic
7791128b39a9 cleaned up signature;
wenzelm
parents: 23178
diff changeset
    49
  val defer_tac: int -> tactic
49865
eeaf1ec7eac2 clarified defer/prefer: more specific errors;
wenzelm
parents: 46704
diff changeset
    50
  val prefer_tac: int -> tactic
59498
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 59164
diff changeset
    51
  val filter_prems_tac: Proof.context -> (term -> bool) -> int -> tactic
11774
3bc4f67d7fe1 qualify some names;
wenzelm
parents: 11768
diff changeset
    52
end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    53
11774
3bc4f67d7fe1 qualify some names;
wenzelm
parents: 11768
diff changeset
    54
signature TACTIC =
3bc4f67d7fe1 qualify some names;
wenzelm
parents: 11768
diff changeset
    55
sig
3bc4f67d7fe1 qualify some names;
wenzelm
parents: 11768
diff changeset
    56
  include BASIC_TACTIC
23223
7791128b39a9 cleaned up signature;
wenzelm
parents: 23178
diff changeset
    57
  val insert_tagged_brl: 'a * (bool * thm) ->
7791128b39a9 cleaned up signature;
wenzelm
parents: 23178
diff changeset
    58
    ('a * (bool * thm)) Net.net * ('a * (bool * thm)) Net.net ->
7791128b39a9 cleaned up signature;
wenzelm
parents: 23178
diff changeset
    59
      ('a * (bool * thm)) Net.net * ('a * (bool * thm)) Net.net
7791128b39a9 cleaned up signature;
wenzelm
parents: 23178
diff changeset
    60
  val delete_tagged_brl: bool * thm ->
7791128b39a9 cleaned up signature;
wenzelm
parents: 23178
diff changeset
    61
    ('a * (bool * thm)) Net.net * ('a * (bool * thm)) Net.net ->
7791128b39a9 cleaned up signature;
wenzelm
parents: 23178
diff changeset
    62
      ('a * (bool * thm)) Net.net * ('a * (bool * thm)) Net.net
7791128b39a9 cleaned up signature;
wenzelm
parents: 23178
diff changeset
    63
  val eq_kbrl: ('a * (bool * thm)) * ('a * (bool * thm)) -> bool
32971
55ba9b6648ef less pervasive names;
wenzelm
parents: 31945
diff changeset
    64
  val build_net: thm list -> (int * thm) Net.net
11774
3bc4f67d7fe1 qualify some names;
wenzelm
parents: 11768
diff changeset
    65
end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    66
11774
3bc4f67d7fe1 qualify some names;
wenzelm
parents: 11768
diff changeset
    67
structure Tactic: TACTIC =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    68
struct
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    69
1501
bb7f99a0a6f0 Elimination of fully-functorial style.
paulson
parents: 1460
diff changeset
    70
(*Discover which goal is chosen:  SOMEGOAL(trace_goalno_tac tac) *)
10817
083d4a6734b4 tuned norm_hhf(_tac);
wenzelm
parents: 10805
diff changeset
    71
fun trace_goalno_tac tac i st =
4270
957c887b89b5 changed Sequence interface (now Seq, in seq.ML);
wenzelm
parents: 4213
diff changeset
    72
    case Seq.pull(tac i st) of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15464
diff changeset
    73
        NONE    => Seq.empty
12262
11ff5f47df6e use tracing function for trace output;
wenzelm
parents: 12212
diff changeset
    74
      | seqcell => (tracing ("Subgoal " ^ string_of_int i ^ " selected");
10805
89a29437cebc added norm_hhf(_tac);
wenzelm
parents: 10444
diff changeset
    75
                         Seq.make(fn()=> seqcell));
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    76
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    77
(*Makes a rule by applying a tactic to an existing rule*)
36546
a9873318fe30 proper context for rule_by_tactic;
wenzelm
parents: 36354
diff changeset
    78
fun rule_by_tactic ctxt tac rl =
19925
3f9341831812 eliminated freeze/varify in favour of Variable.import/export/trade;
wenzelm
parents: 19743
diff changeset
    79
  let
52087
f3075fc4f5f6 more precise treatment of theory vs. Proof.context;
wenzelm
parents: 51602
diff changeset
    80
    val thy = Proof_Context.theory_of ctxt;
36546
a9873318fe30 proper context for rule_by_tactic;
wenzelm
parents: 36354
diff changeset
    81
    val ctxt' = Variable.declare_thm rl ctxt;
52087
f3075fc4f5f6 more precise treatment of theory vs. Proof.context;
wenzelm
parents: 51602
diff changeset
    82
    val ((_, [st]), ctxt'') = Variable.import true [Thm.transfer thy rl] ctxt';
19925
3f9341831812 eliminated freeze/varify in favour of Variable.import/export/trade;
wenzelm
parents: 19743
diff changeset
    83
  in
3f9341831812 eliminated freeze/varify in favour of Variable.import/export/trade;
wenzelm
parents: 19743
diff changeset
    84
    (case Seq.pull (tac st) of
3f9341831812 eliminated freeze/varify in favour of Variable.import/export/trade;
wenzelm
parents: 19743
diff changeset
    85
      NONE => raise THM ("rule_by_tactic", 0, [rl])
36546
a9873318fe30 proper context for rule_by_tactic;
wenzelm
parents: 36354
diff changeset
    86
    | SOME (st', _) => zero_var_indexes (singleton (Variable.export ctxt'' ctxt') st'))
2688
889a1cbd1aca rule_by_tactic no longer standardizes its result
paulson
parents: 2672
diff changeset
    87
  end;
10817
083d4a6734b4 tuned norm_hhf(_tac);
wenzelm
parents: 10805
diff changeset
    88
19925
3f9341831812 eliminated freeze/varify in favour of Variable.import/export/trade;
wenzelm
parents: 19743
diff changeset
    89
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    90
(*** Basic tactics ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    91
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    92
(*** The following fail if the goal number is out of range:
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    93
     thus (REPEAT (resolve_tac rules i)) stops once subgoal i disappears. *)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    94
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    95
(*Solve subgoal i by assumption*)
58963
26bf09b95dda proper context for assume_tac (atac remains as fall-back without context);
wenzelm
parents: 58957
diff changeset
    96
fun assume_tac ctxt i = PRIMSEQ (Thm.assumption (SOME ctxt) i);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    97
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    98
(*Solve subgoal i by assumption, using no unification*)
31945
d5f186aa0bed structure Thm: less pervasive names;
wenzelm
parents: 31794
diff changeset
    99
fun eq_assume_tac i = PRIMITIVE (Thm.eq_assumption i);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   100
23223
7791128b39a9 cleaned up signature;
wenzelm
parents: 23178
diff changeset
   101
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   102
(** Resolution/matching tactics **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   103
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   104
(*The composition rule/state: no lifting or var renaming.
31945
d5f186aa0bed structure Thm: less pervasive names;
wenzelm
parents: 31794
diff changeset
   105
  The arg = (bires_flg, orule, m);  see Thm.bicompose for explanation.*)
58956
a816aa3ff391 proper context for compose_tac, Splitter.split_tac (relevant for unify trace options);
wenzelm
parents: 58950
diff changeset
   106
fun compose_tac ctxt arg i =
a816aa3ff391 proper context for compose_tac, Splitter.split_tac (relevant for unify trace options);
wenzelm
parents: 58950
diff changeset
   107
  PRIMSEQ (Thm.bicompose (SOME ctxt) {flatten = true, match = false, incremented = false} arg i);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   108
67721
5348bea4accd eliminated ASCII syntax from Pure bootstrap;
wenzelm
parents: 60793
diff changeset
   109
(*Converts a "destruct" rule like P \<and> Q \<Longrightarrow> P to an "elimination" rule
5348bea4accd eliminated ASCII syntax from Pure bootstrap;
wenzelm
parents: 60793
diff changeset
   110
  like \<lbrakk>P \<and> Q; P \<Longrightarrow> R\<rbrakk> \<Longrightarrow> R *)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   111
fun make_elim rl = zero_var_indexes (rl RS revcut_rl);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   112
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   113
(*Attack subgoal i by resolution, using flags to indicate elimination rules*)
59498
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 59164
diff changeset
   114
fun biresolve0_tac brules i = PRIMSEQ (Thm.biresolution NONE false brules i);
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 59164
diff changeset
   115
fun biresolve_tac ctxt brules i = PRIMSEQ (Thm.biresolution (SOME ctxt) false brules i);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   116
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   117
(*Resolution: the simple case, works for introduction rules*)
59498
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 59164
diff changeset
   118
fun resolve0_tac rules = biresolve0_tac (map (pair false) rules);
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 59164
diff changeset
   119
fun resolve_tac ctxt rules = biresolve_tac ctxt (map (pair false) rules);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   120
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   121
(*Resolution with elimination rules only*)
59498
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 59164
diff changeset
   122
fun eresolve0_tac rules = biresolve0_tac (map (pair true) rules);
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 59164
diff changeset
   123
fun eresolve_tac ctxt rules = biresolve_tac ctxt (map (pair true) rules);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   124
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   125
(*Forward reasoning using destruction rules.*)
60776
2164e7b47454 proper context;
wenzelm
parents: 60775
diff changeset
   126
fun forward_tac ctxt rls = resolve_tac ctxt (map make_elim rls) THEN' assume_tac ctxt;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   127
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   128
(*Like forward_tac, but deletes the assumption after use.*)
59498
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 59164
diff changeset
   129
fun dresolve0_tac rls = eresolve0_tac (map make_elim rls);
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 59164
diff changeset
   130
fun dresolve_tac ctxt rls = eresolve_tac ctxt (map make_elim rls);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   131
60774
6c28d8ed2488 proper context;
wenzelm
parents: 59749
diff changeset
   132
(*Use an assumption or some rules*)
6c28d8ed2488 proper context;
wenzelm
parents: 59749
diff changeset
   133
fun ares_tac ctxt rules = assume_tac ctxt ORELSE' resolve_tac ctxt rules;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   134
59498
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 59164
diff changeset
   135
fun solve_tac ctxt rules = resolve_tac ctxt rules THEN_ALL_NEW assume_tac ctxt;
5263
8862ed2db431 added solve_tac;
wenzelm
parents: 4713
diff changeset
   136
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   137
(*Matching tactics -- as above, but forbid updating of state*)
58957
c9e744ea8a38 proper context for match_tac etc.;
wenzelm
parents: 58956
diff changeset
   138
fun bimatch_tac ctxt brules i = PRIMSEQ (Thm.biresolution (SOME ctxt) true brules i);
c9e744ea8a38 proper context for match_tac etc.;
wenzelm
parents: 58956
diff changeset
   139
fun match_tac ctxt rules = bimatch_tac ctxt (map (pair false) rules);
c9e744ea8a38 proper context for match_tac etc.;
wenzelm
parents: 58956
diff changeset
   140
fun ematch_tac ctxt rules = bimatch_tac ctxt (map (pair true) rules);
c9e744ea8a38 proper context for match_tac etc.;
wenzelm
parents: 58956
diff changeset
   141
fun dmatch_tac ctxt rls = ematch_tac ctxt (map make_elim rls);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   142
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   143
(*Smash all flex-flex disagreement pairs in the proof state.*)
58950
d07464875dd4 optional proof context for unify operations, for the sake of proper local options;
wenzelm
parents: 58837
diff changeset
   144
fun flexflex_tac ctxt = PRIMSEQ (Thm.flexflex_rule (SOME ctxt));
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   145
19056
6ac9dfe98e54 sane version of distinct_subgoals_tac, based on composition with Drule.distinct_prems_rl;
wenzelm
parents: 18977
diff changeset
   146
(*Remove duplicate subgoals.*)
69101
991a3feaf270 more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents: 68825
diff changeset
   147
fun distinct_subgoals_tac st =
991a3feaf270 more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents: 68825
diff changeset
   148
  let
991a3feaf270 more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents: 68825
diff changeset
   149
    val subgoals = Thm.cprems_of st;
991a3feaf270 more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents: 68825
diff changeset
   150
    val (tab, n) =
991a3feaf270 more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents: 68825
diff changeset
   151
      (subgoals, (Ctermtab.empty, 0)) |-> fold (fn ct => fn (tab, i) =>
991a3feaf270 more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents: 68825
diff changeset
   152
        if Ctermtab.defined tab ct then (tab, i)
991a3feaf270 more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents: 68825
diff changeset
   153
        else (Ctermtab.update (ct, i) tab, i + 1));
991a3feaf270 more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents: 68825
diff changeset
   154
    val st' =
991a3feaf270 more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents: 68825
diff changeset
   155
      if n = length subgoals then st
991a3feaf270 more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents: 68825
diff changeset
   156
      else
991a3feaf270 more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents: 68825
diff changeset
   157
        let
991a3feaf270 more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents: 68825
diff changeset
   158
          val thy = Thm.theory_of_thm st;
991a3feaf270 more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents: 68825
diff changeset
   159
          fun cert_prop i = Thm.global_cterm_of thy (Free (Name.bound i, propT));
22560
f19ddf96c323 now exports distinct_subgoal_tac (needed by MetisAPI)
paulson
parents: 22360
diff changeset
   160
69101
991a3feaf270 more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents: 68825
diff changeset
   161
          val As = map (cert_prop o the o Ctermtab.lookup tab) subgoals;
991a3feaf270 more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents: 68825
diff changeset
   162
          val As' = map cert_prop (0 upto (n - 1));
991a3feaf270 more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents: 68825
diff changeset
   163
          val C = cert_prop n;
22560
f19ddf96c323 now exports distinct_subgoal_tac (needed by MetisAPI)
paulson
parents: 22360
diff changeset
   164
69101
991a3feaf270 more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents: 68825
diff changeset
   165
          val template = Drule.list_implies (As, C);
991a3feaf270 more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents: 68825
diff changeset
   166
          val inst =
991a3feaf270 more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents: 68825
diff changeset
   167
            (dest_Free (Thm.term_of C), Thm.cconcl_of st) ::
991a3feaf270 more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents: 68825
diff changeset
   168
              Ctermtab.fold (fn (ct, i) => cons ((Name.bound i, propT), ct)) tab [];
991a3feaf270 more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents: 68825
diff changeset
   169
        in
991a3feaf270 more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents: 68825
diff changeset
   170
          Thm.assume template
991a3feaf270 more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents: 68825
diff changeset
   171
          |> fold (Thm.elim_implies o Thm.assume) As
991a3feaf270 more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents: 68825
diff changeset
   172
          |> fold_rev Thm.implies_intr As'
991a3feaf270 more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents: 68825
diff changeset
   173
          |> Thm.implies_intr template
991a3feaf270 more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents: 68825
diff changeset
   174
          |> Thm.instantiate_frees ([], inst)
991a3feaf270 more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents: 68825
diff changeset
   175
          |> Thm.elim_implies st
991a3feaf270 more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents: 68825
diff changeset
   176
        end;
991a3feaf270 more direct implementation of distinct_subgoals_tac -- potentially more efficient;
wenzelm
parents: 68825
diff changeset
   177
  in Seq.single st' end;
3409
c0466958df5d Tidying of signature. More robust renaming in freeze_thaw.
paulson
parents: 2814
diff changeset
   178
1951
f2b8005bdc6e Declared thin_tac
paulson
parents: 1801
diff changeset
   179
270
d506ea00c825 tactic/make_elim_preserve: recoded to avoid using lift_inst_rule. Instead
lcp
parents: 230
diff changeset
   180
(*** Applications of cut_rl ***)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   181
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   182
(*The conclusion of the rule gets assumed in subgoal i,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   183
  while subgoal i+1,... are the premises of the rule.*)
59498
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 59164
diff changeset
   184
fun cut_tac rule i = resolve0_tac [cut_rl] i THEN resolve0_tac [rule] (i + 1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   185
13650
31bd2a8cdbe2 fixing the cut_tac method to work when there are no instantiations and the
paulson
parents: 13559
diff changeset
   186
(*"Cut" a list of rules into the goal.  Their premises will become new
31bd2a8cdbe2 fixing the cut_tac method to work when there are no instantiations and the
paulson
parents: 13559
diff changeset
   187
  subgoals.*)
46704
f800eb467515 simplified cut_tac (cf. d549b5b0f344);
wenzelm
parents: 46472
diff changeset
   188
fun cut_rules_tac ths i = EVERY (map (fn th => cut_tac th i) ths);
13650
31bd2a8cdbe2 fixing the cut_tac method to work when there are no instantiations and the
paulson
parents: 13559
diff changeset
   189
31bd2a8cdbe2 fixing the cut_tac method to work when there are no instantiations and the
paulson
parents: 13559
diff changeset
   190
(*As above, but inserts only facts (unconditional theorems);
31bd2a8cdbe2 fixing the cut_tac method to work when there are no instantiations and the
paulson
parents: 13559
diff changeset
   191
  generates no additional subgoals. *)
20232
31998a8c7f25 removed obsolete is_fact (cf. Thm.no_prems);
wenzelm
parents: 20218
diff changeset
   192
fun cut_facts_tac ths = cut_rules_tac (filter Thm.no_prems ths);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   193
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   194
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   195
(**** Indexing and filtering of theorems ****)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   196
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   197
(*Returns the list of potentially resolvable theorems for the goal "prem",
10805
89a29437cebc added norm_hhf(_tac);
wenzelm
parents: 10444
diff changeset
   198
        using the predicate  could(subgoal,concl).
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   199
  Resulting list is no longer than "limit"*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   200
fun filter_thms could (limit, prem, ths) =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   201
  let val pb = Logic.strip_assums_concl prem;   (*delete assumptions*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   202
      fun filtr (limit, []) = []
10805
89a29437cebc added norm_hhf(_tac);
wenzelm
parents: 10444
diff changeset
   203
        | filtr (limit, th::ths) =
89a29437cebc added norm_hhf(_tac);
wenzelm
parents: 10444
diff changeset
   204
            if limit=0 then  []
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59498
diff changeset
   205
            else if could(pb, Thm.concl_of th)  then th :: filtr(limit-1, ths)
10805
89a29437cebc added norm_hhf(_tac);
wenzelm
parents: 10444
diff changeset
   206
            else filtr(limit,ths)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   207
  in  filtr(limit,ths)  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   208
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   209
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   210
(*** biresolution and resolution using nets ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   211
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   212
(** To preserve the order of the rules, tag them with increasing integers **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   213
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   214
(*insert one tagged brl into the pair of nets*)
23178
07ba6b58b3d2 simplified/unified list fold;
wenzelm
parents: 22583
diff changeset
   215
fun insert_tagged_brl (kbrl as (k, (eres, th))) (inet, enet) =
12320
6e70d870ddf0 general type of delete_tagged_brl;
wenzelm
parents: 12262
diff changeset
   216
  if eres then
6e70d870ddf0 general type of delete_tagged_brl;
wenzelm
parents: 12262
diff changeset
   217
    (case try Thm.major_prem_of th of
16809
8ca51a846576 export eq_brl;
wenzelm
parents: 16666
diff changeset
   218
      SOME prem => (inet, Net.insert_term (K false) (prem, kbrl) enet)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15464
diff changeset
   219
    | NONE => error "insert_tagged_brl: elimination rule with no premises")
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59498
diff changeset
   220
  else (Net.insert_term (K false) (Thm.concl_of th, kbrl) inet, enet);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   221
12320
6e70d870ddf0 general type of delete_tagged_brl;
wenzelm
parents: 12262
diff changeset
   222
(*delete one kbrl from the pair of nets*)
22360
26ead7ed4f4b moved eq_thm etc. to structure Thm in Pure/more_thm.ML;
wenzelm
parents: 21708
diff changeset
   223
fun eq_kbrl ((_, (_, th)), (_, (_, th'))) = Thm.eq_thm_prop (th, th')
16809
8ca51a846576 export eq_brl;
wenzelm
parents: 16666
diff changeset
   224
23178
07ba6b58b3d2 simplified/unified list fold;
wenzelm
parents: 22583
diff changeset
   225
fun delete_tagged_brl (brl as (eres, th)) (inet, enet) =
13925
761af5c2fd59 catches exception DELETE
paulson
parents: 13650
diff changeset
   226
  (if eres then
12320
6e70d870ddf0 general type of delete_tagged_brl;
wenzelm
parents: 12262
diff changeset
   227
    (case try Thm.major_prem_of th of
16809
8ca51a846576 export eq_brl;
wenzelm
parents: 16666
diff changeset
   228
      SOME prem => (inet, Net.delete_term eq_kbrl (prem, ((), brl)) enet)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15464
diff changeset
   229
    | NONE => (inet, enet))  (*no major premise: ignore*)
16809
8ca51a846576 export eq_brl;
wenzelm
parents: 16666
diff changeset
   230
  else (Net.delete_term eq_kbrl (Thm.concl_of th, ((), brl)) inet, enet))
13925
761af5c2fd59 catches exception DELETE
paulson
parents: 13650
diff changeset
   231
  handle Net.DELETE => (inet,enet);
1801
927a31ba4346 Added delete function for brls
paulson
parents: 1501
diff changeset
   232
927a31ba4346 Added delete function for brls
paulson
parents: 1501
diff changeset
   233
10817
083d4a6734b4 tuned norm_hhf(_tac);
wenzelm
parents: 10805
diff changeset
   234
(*biresolution using a pair of nets rather than rules.
3706
e57b5902822f Generalized and exported biresolution_from_nets_tac to allow the declaration
paulson
parents: 3575
diff changeset
   235
    function "order" must sort and possibly filter the list of brls.
e57b5902822f Generalized and exported biresolution_from_nets_tac to allow the declaration
paulson
parents: 3575
diff changeset
   236
    boolean "match" indicates matching or unification.*)
59164
ff40c53d1af9 proper context for "net" tactics;
wenzelm
parents: 58963
diff changeset
   237
fun biresolution_from_nets_tac ctxt order match (inet, enet) =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   238
  SUBGOAL
59164
ff40c53d1af9 proper context for "net" tactics;
wenzelm
parents: 58963
diff changeset
   239
    (fn (prem, i) =>
ff40c53d1af9 proper context for "net" tactics;
wenzelm
parents: 58963
diff changeset
   240
      let
ff40c53d1af9 proper context for "net" tactics;
wenzelm
parents: 58963
diff changeset
   241
        val hyps = Logic.strip_assums_hyp prem;
ff40c53d1af9 proper context for "net" tactics;
wenzelm
parents: 58963
diff changeset
   242
        val concl = Logic.strip_assums_concl prem;
ff40c53d1af9 proper context for "net" tactics;
wenzelm
parents: 58963
diff changeset
   243
        val kbrls = Net.unify_term inet concl @ maps (Net.unify_term enet) hyps;
ff40c53d1af9 proper context for "net" tactics;
wenzelm
parents: 58963
diff changeset
   244
      in PRIMSEQ (Thm.biresolution (SOME ctxt) match (order kbrls) i) end);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   245
3706
e57b5902822f Generalized and exported biresolution_from_nets_tac to allow the declaration
paulson
parents: 3575
diff changeset
   246
(*versions taking pre-built nets.  No filtering of brls*)
59164
ff40c53d1af9 proper context for "net" tactics;
wenzelm
parents: 58963
diff changeset
   247
fun biresolve_from_nets_tac ctxt = biresolution_from_nets_tac ctxt order_list false;
ff40c53d1af9 proper context for "net" tactics;
wenzelm
parents: 58963
diff changeset
   248
fun bimatch_from_nets_tac ctxt = biresolution_from_nets_tac ctxt order_list true;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   249
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   250
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   251
(*** Simpler version for resolve_tac -- only one net, and no hyps ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   252
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   253
(*insert one tagged rl into the net*)
23178
07ba6b58b3d2 simplified/unified list fold;
wenzelm
parents: 22583
diff changeset
   254
fun insert_krl (krl as (k,th)) =
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59498
diff changeset
   255
  Net.insert_term (K false) (Thm.concl_of th, krl);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   256
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   257
(*build a net of rules for resolution*)
10817
083d4a6734b4 tuned norm_hhf(_tac);
wenzelm
parents: 10805
diff changeset
   258
fun build_net rls =
30558
2ef9892114fd renamed Tactic.taglist/untaglist/orderlist to tag_list/untag_list/order_list (in library.ML);
wenzelm
parents: 29276
diff changeset
   259
  fold_rev insert_krl (tag_list 1 rls) Net.empty;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   260
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   261
(*resolution using a net rather than rules; pred supports filt_resolve_tac*)
59164
ff40c53d1af9 proper context for "net" tactics;
wenzelm
parents: 58963
diff changeset
   262
fun filt_resolution_from_net_tac ctxt match pred net =
ff40c53d1af9 proper context for "net" tactics;
wenzelm
parents: 58963
diff changeset
   263
  SUBGOAL (fn (prem, i) =>
58950
d07464875dd4 optional proof context for unify operations, for the sake of proper local options;
wenzelm
parents: 58837
diff changeset
   264
    let val krls = Net.unify_term net (Logic.strip_assums_concl prem) in
d07464875dd4 optional proof context for unify operations, for the sake of proper local options;
wenzelm
parents: 58837
diff changeset
   265
      if pred krls then
59164
ff40c53d1af9 proper context for "net" tactics;
wenzelm
parents: 58963
diff changeset
   266
        PRIMSEQ (Thm.biresolution (SOME ctxt) match (map (pair false) (order_list krls)) i)
58950
d07464875dd4 optional proof context for unify operations, for the sake of proper local options;
wenzelm
parents: 58837
diff changeset
   267
      else no_tac
d07464875dd4 optional proof context for unify operations, for the sake of proper local options;
wenzelm
parents: 58837
diff changeset
   268
    end);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   269
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   270
(*Resolve the subgoal using the rules (making a net) unless too flexible,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   271
   which means more than maxr rules are unifiable.      *)
59164
ff40c53d1af9 proper context for "net" tactics;
wenzelm
parents: 58963
diff changeset
   272
fun filt_resolve_from_net_tac ctxt maxr net =
ff40c53d1af9 proper context for "net" tactics;
wenzelm
parents: 58963
diff changeset
   273
  let fun pred krls = length krls <= maxr
ff40c53d1af9 proper context for "net" tactics;
wenzelm
parents: 58963
diff changeset
   274
  in filt_resolution_from_net_tac ctxt false pred net end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   275
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   276
(*versions taking pre-built nets*)
59164
ff40c53d1af9 proper context for "net" tactics;
wenzelm
parents: 58963
diff changeset
   277
fun resolve_from_net_tac ctxt = filt_resolution_from_net_tac ctxt false (K true);
ff40c53d1af9 proper context for "net" tactics;
wenzelm
parents: 58963
diff changeset
   278
fun match_from_net_tac ctxt = filt_resolution_from_net_tac ctxt true (K true);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   279
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   280
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   281
(*** For Natural Deduction using (bires_flg, rule) pairs ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   282
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   283
(*The number of new subgoals produced by the brule*)
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59498
diff changeset
   284
fun subgoals_of_brl (true, rule) = Thm.nprems_of rule - 1
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59498
diff changeset
   285
  | subgoals_of_brl (false, rule) = Thm.nprems_of rule;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   286
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   287
(*Less-than test: for sorting to minimize number of new subgoals*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   288
fun lessb (brl1,brl2) = subgoals_of_brl brl1 < subgoals_of_brl brl2;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   289
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   290
27243
d549b5b0f344 removed obsolete global instantiation tactics (cf. Isar/rule_insts.ML);
wenzelm
parents: 27209
diff changeset
   291
(*Renaming of parameters in a subgoal*)
d549b5b0f344 removed obsolete global instantiation tactics (cf. Isar/rule_insts.ML);
wenzelm
parents: 27209
diff changeset
   292
fun rename_tac xs i =
59584
wenzelm
parents: 59582
diff changeset
   293
  case find_first (not o Symbol_Pos.is_identifier) xs of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15464
diff changeset
   294
      SOME x => error ("Not an identifier: " ^ x)
31945
d5f186aa0bed structure Thm: less pervasive names;
wenzelm
parents: 31794
diff changeset
   295
    | NONE => PRIMITIVE (Thm.rename_params_rule (xs, i));
9535
a60b0be5ee96 added rename_params_tac;
wenzelm
parents: 8977
diff changeset
   296
1501
bb7f99a0a6f0 Elimination of fully-functorial style.
paulson
parents: 1460
diff changeset
   297
(*rotate_tac n i: rotate the assumptions of subgoal i by n positions, from
bb7f99a0a6f0 Elimination of fully-functorial style.
paulson
parents: 1460
diff changeset
   298
  right to left if n is positive, and from left to right if n is negative.*)
2672
85d7e800d754 Replaced "flat" by the Basis Library function List.concat
paulson
parents: 2580
diff changeset
   299
fun rotate_tac 0 i = all_tac
31945
d5f186aa0bed structure Thm: less pervasive names;
wenzelm
parents: 31794
diff changeset
   300
  | rotate_tac k i = PRIMITIVE (Thm.rotate_rule k i);
1209
03dc596b3a18 added rotate_tac.
nipkow
parents: 1077
diff changeset
   301
59749
118f4995df8c tuned comments;
wenzelm
parents: 59584
diff changeset
   302
(*Rotate the given subgoal to be the last.*)
31945
d5f186aa0bed structure Thm: less pervasive names;
wenzelm
parents: 31794
diff changeset
   303
fun defer_tac i = PRIMITIVE (Thm.permute_prems (i - 1) 1);
7248
322151fe6f02 new primitive rule permute_prems to underlie defer_tac and rotate_prems
paulson
parents: 6979
diff changeset
   304
59749
118f4995df8c tuned comments;
wenzelm
parents: 59584
diff changeset
   305
(*Rotate the given subgoal to be the first.*)
49865
eeaf1ec7eac2 clarified defer/prefer: more specific errors;
wenzelm
parents: 46704
diff changeset
   306
fun prefer_tac i = PRIMITIVE (Thm.permute_prems (i - 1) 1 #> Thm.permute_prems 0 ~1);
eeaf1ec7eac2 clarified defer/prefer: more specific errors;
wenzelm
parents: 46704
diff changeset
   307
59749
118f4995df8c tuned comments;
wenzelm
parents: 59584
diff changeset
   308
(*Remove premises that do not satisfy pred; fails if all prems satisfy pred.*)
118f4995df8c tuned comments;
wenzelm
parents: 59584
diff changeset
   309
fun filter_prems_tac ctxt pred =
118f4995df8c tuned comments;
wenzelm
parents: 59584
diff changeset
   310
  let
118f4995df8c tuned comments;
wenzelm
parents: 59584
diff changeset
   311
    fun Then NONE tac = SOME tac
118f4995df8c tuned comments;
wenzelm
parents: 59584
diff changeset
   312
      | Then (SOME tac) tac' = SOME (tac THEN' tac');
118f4995df8c tuned comments;
wenzelm
parents: 59584
diff changeset
   313
    fun thins H (tac, n) =
118f4995df8c tuned comments;
wenzelm
parents: 59584
diff changeset
   314
      if pred H then (tac, n + 1)
118f4995df8c tuned comments;
wenzelm
parents: 59584
diff changeset
   315
      else (Then tac (rotate_tac n THEN' eresolve_tac ctxt [thin_rl]), 0);
118f4995df8c tuned comments;
wenzelm
parents: 59584
diff changeset
   316
  in
118f4995df8c tuned comments;
wenzelm
parents: 59584
diff changeset
   317
    SUBGOAL (fn (goal, i) =>
118f4995df8c tuned comments;
wenzelm
parents: 59584
diff changeset
   318
      let val Hs = Logic.strip_assums_hyp goal in
118f4995df8c tuned comments;
wenzelm
parents: 59584
diff changeset
   319
        (case fst (fold thins Hs (NONE, 0)) of
118f4995df8c tuned comments;
wenzelm
parents: 59584
diff changeset
   320
          NONE => no_tac
118f4995df8c tuned comments;
wenzelm
parents: 59584
diff changeset
   321
        | SOME tac => tac i)
118f4995df8c tuned comments;
wenzelm
parents: 59584
diff changeset
   322
      end)
5974
6acf3ff0f486 Added filter_prems_tac
nipkow
parents: 5956
diff changeset
   323
  end;
6acf3ff0f486 Added filter_prems_tac
nipkow
parents: 5956
diff changeset
   324
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   325
end;
1501
bb7f99a0a6f0 Elimination of fully-functorial style.
paulson
parents: 1460
diff changeset
   326
32971
55ba9b6648ef less pervasive names;
wenzelm
parents: 31945
diff changeset
   327
structure Basic_Tactic: BASIC_TACTIC = Tactic;
55ba9b6648ef less pervasive names;
wenzelm
parents: 31945
diff changeset
   328
open Basic_Tactic;