src/Pure/Tools/rule_insts.ML
author wenzelm
Wed, 08 Jul 2015 19:28:43 +0200
changeset 60695 757549b4bbe6
parent 60642 48dd1cefb4ae
child 61841 4d3527b94f2a
permissions -rw-r--r--
Variable.focus etc.: optional bindings provided by user; Subgoal.focus command: more careful treatment of user-provided bindings;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
53707
d1c6bff9ff58 moved module into plain Isabelle/ML user space;
wenzelm
parents: 53171
diff changeset
     1
(*  Title:      Pure/Tools/rule_insts.ML
20336
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
     3
53708
92aa282841f8 more antiquotations;
wenzelm
parents: 53707
diff changeset
     4
Rule instantiations -- operations within implicit rule / subgoal context.
20336
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
     5
*)
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
     6
59763
56d2c357e6b5 tuned signature;
wenzelm
parents: 59761
diff changeset
     7
signature RULE_INSTS =
20336
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
     8
sig
59763
56d2c357e6b5 tuned signature;
wenzelm
parents: 59761
diff changeset
     9
  val where_rule: Proof.context ->
56d2c357e6b5 tuned signature;
wenzelm
parents: 59761
diff changeset
    10
    ((indexname * Position.T) * string) list ->
56d2c357e6b5 tuned signature;
wenzelm
parents: 59761
diff changeset
    11
    (binding * string option * mixfix) list -> thm -> thm
56d2c357e6b5 tuned signature;
wenzelm
parents: 59761
diff changeset
    12
  val of_rule: Proof.context -> string option list * string option list ->
56d2c357e6b5 tuned signature;
wenzelm
parents: 59761
diff changeset
    13
    (binding * string option * mixfix) list -> thm -> thm
56d2c357e6b5 tuned signature;
wenzelm
parents: 59761
diff changeset
    14
  val read_instantiate: Proof.context ->
56d2c357e6b5 tuned signature;
wenzelm
parents: 59761
diff changeset
    15
    ((indexname * Position.T) * string) list -> string list -> thm -> thm
59827
04e569577c18 proper Rule_Insts.read_term, e.g. to enable case_tac using "_";
wenzelm
parents: 59825
diff changeset
    16
  val read_term: string -> Proof.context -> term * Proof.context
59829
4bce61dd88d2 clarified goal context;
wenzelm
parents: 59828
diff changeset
    17
  val goal_context: term -> Proof.context -> (string * typ) list * Proof.context
59755
f8d164ab0dc1 more position information;
wenzelm
parents: 59754
diff changeset
    18
  val res_inst_tac: Proof.context ->
59855
wenzelm
parents: 59853
diff changeset
    19
    ((indexname * Position.T) * string) list -> (binding * string option * mixfix) list ->
wenzelm
parents: 59853
diff changeset
    20
    thm -> int -> tactic
59755
f8d164ab0dc1 more position information;
wenzelm
parents: 59754
diff changeset
    21
  val eres_inst_tac: Proof.context ->
59855
wenzelm
parents: 59853
diff changeset
    22
    ((indexname * Position.T) * string) list -> (binding * string option * mixfix) list ->
wenzelm
parents: 59853
diff changeset
    23
    thm -> int -> tactic
59755
f8d164ab0dc1 more position information;
wenzelm
parents: 59754
diff changeset
    24
  val cut_inst_tac: Proof.context ->
59855
wenzelm
parents: 59853
diff changeset
    25
    ((indexname * Position.T) * string) list -> (binding * string option * mixfix) list ->
wenzelm
parents: 59853
diff changeset
    26
    thm -> int -> tactic
59755
f8d164ab0dc1 more position information;
wenzelm
parents: 59754
diff changeset
    27
  val forw_inst_tac: Proof.context ->
59855
wenzelm
parents: 59853
diff changeset
    28
    ((indexname * Position.T) * string) list -> (binding * string option * mixfix) list ->
wenzelm
parents: 59853
diff changeset
    29
    thm -> int -> tactic
59755
f8d164ab0dc1 more position information;
wenzelm
parents: 59754
diff changeset
    30
  val dres_inst_tac: Proof.context ->
59855
wenzelm
parents: 59853
diff changeset
    31
    ((indexname * Position.T) * string) list -> (binding * string option * mixfix) list ->
wenzelm
parents: 59853
diff changeset
    32
    thm -> int -> tactic
59780
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59775
diff changeset
    33
  val thin_tac: Proof.context -> string -> (binding * string option * mixfix) list ->
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59775
diff changeset
    34
    int -> tactic
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59775
diff changeset
    35
  val subgoal_tac: Proof.context -> string -> (binding * string option * mixfix) list ->
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59775
diff changeset
    36
    int -> tactic
58950
d07464875dd4 optional proof context for unify operations, for the sake of proper local options;
wenzelm
parents: 58027
diff changeset
    37
  val make_elim_preserve: Proof.context -> thm -> thm
59755
f8d164ab0dc1 more position information;
wenzelm
parents: 59754
diff changeset
    38
  val method:
59780
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59775
diff changeset
    39
    (Proof.context -> ((indexname * Position.T) * string) list ->
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59775
diff changeset
    40
      (binding * string option * mixfix) list -> thm -> int -> tactic) ->
59855
wenzelm
parents: 59853
diff changeset
    41
    (Proof.context -> thm list -> int -> tactic) ->
wenzelm
parents: 59853
diff changeset
    42
    (Proof.context -> Proof.method) context_parser
20336
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
    43
end;
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
    44
42806
4b660cdab9b7 modernized structure Rule_Insts;
wenzelm
parents: 42360
diff changeset
    45
structure Rule_Insts: RULE_INSTS =
20336
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
    46
struct
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
    47
59771
c6e60787ffe2 read instantiations uniformly for rules and tactics;
wenzelm
parents: 59770
diff changeset
    48
(** read instantiations **)
20336
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
    49
59771
c6e60787ffe2 read instantiations uniformly for rules and tactics;
wenzelm
parents: 59770
diff changeset
    50
local
59755
f8d164ab0dc1 more position information;
wenzelm
parents: 59754
diff changeset
    51
f8d164ab0dc1 more position information;
wenzelm
parents: 59754
diff changeset
    52
fun error_var msg (xi, pos) =
f8d164ab0dc1 more position information;
wenzelm
parents: 59754
diff changeset
    53
  error (msg ^ quote (Term.string_of_vname xi) ^ Position.here pos);
59754
696d87036f04 misc tuning;
wenzelm
parents: 59623
diff changeset
    54
59755
f8d164ab0dc1 more position information;
wenzelm
parents: 59754
diff changeset
    55
fun the_sort tvars (xi, pos) : sort =
45611
wenzelm
parents: 44241
diff changeset
    56
  (case AList.lookup (op =) tvars xi of
wenzelm
parents: 44241
diff changeset
    57
    SOME S => S
59755
f8d164ab0dc1 more position information;
wenzelm
parents: 59754
diff changeset
    58
  | NONE => error_var "No such type variable in theorem: " (xi, pos));
20336
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
    59
59755
f8d164ab0dc1 more position information;
wenzelm
parents: 59754
diff changeset
    60
fun the_type vars (xi, pos) : typ =
45611
wenzelm
parents: 44241
diff changeset
    61
  (case AList.lookup (op =) vars xi of
wenzelm
parents: 44241
diff changeset
    62
    SOME T => T
59755
f8d164ab0dc1 more position information;
wenzelm
parents: 59754
diff changeset
    63
  | NONE => error_var "No such variable in theorem: " (xi, pos));
20336
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
    64
59774
wenzelm
parents: 59772
diff changeset
    65
fun read_type ctxt tvars ((xi, pos), s) =
59759
cb1966f3a92b tuned -- prepare instantiation more uniformly;
wenzelm
parents: 59755
diff changeset
    66
  let
cb1966f3a92b tuned -- prepare instantiation more uniformly;
wenzelm
parents: 59755
diff changeset
    67
    val S = the_sort tvars (xi, pos);
cb1966f3a92b tuned -- prepare instantiation more uniformly;
wenzelm
parents: 59755
diff changeset
    68
    val T = Syntax.read_typ ctxt s;
cb1966f3a92b tuned -- prepare instantiation more uniformly;
wenzelm
parents: 59755
diff changeset
    69
  in
cb1966f3a92b tuned -- prepare instantiation more uniformly;
wenzelm
parents: 59755
diff changeset
    70
    if Sign.of_sort (Proof_Context.theory_of ctxt) (T, S) then ((xi, S), T)
59768
wenzelm
parents: 59767
diff changeset
    71
    else error_var "Bad sort for instantiation of type variable: " (xi, pos)
59759
cb1966f3a92b tuned -- prepare instantiation more uniformly;
wenzelm
parents: 59755
diff changeset
    72
  end;
cb1966f3a92b tuned -- prepare instantiation more uniformly;
wenzelm
parents: 59755
diff changeset
    73
59827
04e569577c18 proper Rule_Insts.read_term, e.g. to enable case_tac using "_";
wenzelm
parents: 59825
diff changeset
    74
fun make_instT f v =
04e569577c18 proper Rule_Insts.read_term, e.g. to enable case_tac using "_";
wenzelm
parents: 59825
diff changeset
    75
  let
04e569577c18 proper Rule_Insts.read_term, e.g. to enable case_tac using "_";
wenzelm
parents: 59825
diff changeset
    76
    val T = TVar v;
04e569577c18 proper Rule_Insts.read_term, e.g. to enable case_tac using "_";
wenzelm
parents: 59825
diff changeset
    77
    val T' = f T;
04e569577c18 proper Rule_Insts.read_term, e.g. to enable case_tac using "_";
wenzelm
parents: 59825
diff changeset
    78
  in if T = T' then NONE else SOME (v, T') end;
04e569577c18 proper Rule_Insts.read_term, e.g. to enable case_tac using "_";
wenzelm
parents: 59825
diff changeset
    79
04e569577c18 proper Rule_Insts.read_term, e.g. to enable case_tac using "_";
wenzelm
parents: 59825
diff changeset
    80
fun make_inst f v =
04e569577c18 proper Rule_Insts.read_term, e.g. to enable case_tac using "_";
wenzelm
parents: 59825
diff changeset
    81
  let
04e569577c18 proper Rule_Insts.read_term, e.g. to enable case_tac using "_";
wenzelm
parents: 59825
diff changeset
    82
    val t = Var v;
04e569577c18 proper Rule_Insts.read_term, e.g. to enable case_tac using "_";
wenzelm
parents: 59825
diff changeset
    83
    val t' = f t;
04e569577c18 proper Rule_Insts.read_term, e.g. to enable case_tac using "_";
wenzelm
parents: 59825
diff changeset
    84
  in if t aconv t' then NONE else SOME (v, t') end;
04e569577c18 proper Rule_Insts.read_term, e.g. to enable case_tac using "_";
wenzelm
parents: 59825
diff changeset
    85
59796
f05ef8c62e4f admit dummy patterns in instantiations;
wenzelm
parents: 59790
diff changeset
    86
fun read_terms ss Ts ctxt =
25329
63e8de11c8e9 attribute where/of: proper Syntax.parse/check;
wenzelm
parents: 22692
diff changeset
    87
  let
63e8de11c8e9 attribute where/of: proper Syntax.parse/check;
wenzelm
parents: 22692
diff changeset
    88
    fun parse T = if T = propT then Syntax.parse_prop ctxt else Syntax.parse_term ctxt;
59796
f05ef8c62e4f admit dummy patterns in instantiations;
wenzelm
parents: 59790
diff changeset
    89
    val (ts, ctxt') = fold_map Variable.fix_dummy_patterns (map2 parse Ts ss) ctxt;
25329
63e8de11c8e9 attribute where/of: proper Syntax.parse/check;
wenzelm
parents: 22692
diff changeset
    90
    val ts' =
39288
f1ae2493d93f eliminated aliases of Type.constraint;
wenzelm
parents: 37145
diff changeset
    91
      map2 (Type.constraint o Type_Infer.paramify_vars) Ts ts
59796
f05ef8c62e4f admit dummy patterns in instantiations;
wenzelm
parents: 59790
diff changeset
    92
      |> Syntax.check_terms ctxt'
f05ef8c62e4f admit dummy patterns in instantiations;
wenzelm
parents: 59790
diff changeset
    93
      |> Variable.polymorphic ctxt';
25329
63e8de11c8e9 attribute where/of: proper Syntax.parse/check;
wenzelm
parents: 22692
diff changeset
    94
    val Ts' = map Term.fastype_of ts';
59839
62d69ffa639f more standard Sign.typ_match: sorts should be alright in result of Syntax.check_terms;
wenzelm
parents: 59836
diff changeset
    95
    val tyenv = fold (Sign.typ_match (Proof_Context.theory_of ctxt)) (Ts ~~ Ts') Vartab.empty;
59759
cb1966f3a92b tuned -- prepare instantiation more uniformly;
wenzelm
parents: 59755
diff changeset
    96
    val tyenv' = Vartab.fold (fn (xi, (S, T)) => cons ((xi, S), T)) tyenv [];
59796
f05ef8c62e4f admit dummy patterns in instantiations;
wenzelm
parents: 59790
diff changeset
    97
  in ((ts', tyenv'), ctxt') end;
25329
63e8de11c8e9 attribute where/of: proper Syntax.parse/check;
wenzelm
parents: 22692
diff changeset
    98
59827
04e569577c18 proper Rule_Insts.read_term, e.g. to enable case_tac using "_";
wenzelm
parents: 59825
diff changeset
    99
in
59771
c6e60787ffe2 read instantiations uniformly for rules and tactics;
wenzelm
parents: 59770
diff changeset
   100
59827
04e569577c18 proper Rule_Insts.read_term, e.g. to enable case_tac using "_";
wenzelm
parents: 59825
diff changeset
   101
fun read_term s ctxt =
59771
c6e60787ffe2 read instantiations uniformly for rules and tactics;
wenzelm
parents: 59770
diff changeset
   102
  let
59827
04e569577c18 proper Rule_Insts.read_term, e.g. to enable case_tac using "_";
wenzelm
parents: 59825
diff changeset
   103
    val (t, ctxt') = Variable.fix_dummy_patterns (Syntax.parse_term ctxt s) ctxt;
04e569577c18 proper Rule_Insts.read_term, e.g. to enable case_tac using "_";
wenzelm
parents: 59825
diff changeset
   104
    val t' = Syntax.check_term ctxt' t;
04e569577c18 proper Rule_Insts.read_term, e.g. to enable case_tac using "_";
wenzelm
parents: 59825
diff changeset
   105
  in (t', ctxt') end;
59771
c6e60787ffe2 read instantiations uniformly for rules and tactics;
wenzelm
parents: 59770
diff changeset
   106
59853
4039d8aecda4 more uniform syntax for named instantiations;
wenzelm
parents: 59846
diff changeset
   107
fun read_insts thm raw_insts raw_fixes ctxt =
20336
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   108
  let
59771
c6e60787ffe2 read instantiations uniformly for rules and tactics;
wenzelm
parents: 59770
diff changeset
   109
    val (type_insts, term_insts) =
59853
4039d8aecda4 more uniform syntax for named instantiations;
wenzelm
parents: 59846
diff changeset
   110
      List.partition (fn (((x, _), _), _) => String.isPrefix "'" x) raw_insts;
59768
wenzelm
parents: 59767
diff changeset
   111
59769
wenzelm
parents: 59768
diff changeset
   112
    val tvars = Thm.fold_terms Term.add_tvars thm [];
wenzelm
parents: 59768
diff changeset
   113
    val vars = Thm.fold_terms Term.add_vars thm [];
20336
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   114
59853
4039d8aecda4 more uniform syntax for named instantiations;
wenzelm
parents: 59846
diff changeset
   115
    (*eigen-context*)
60469
d1ea37df7358 tuned signature;
wenzelm
parents: 60379
diff changeset
   116
    val (_, ctxt1) = ctxt
59853
4039d8aecda4 more uniform syntax for named instantiations;
wenzelm
parents: 59846
diff changeset
   117
      |> Variable.declare_thm thm
60469
d1ea37df7358 tuned signature;
wenzelm
parents: 60379
diff changeset
   118
      |> Proof_Context.add_fixes_cmd raw_fixes;
59853
4039d8aecda4 more uniform syntax for named instantiations;
wenzelm
parents: 59846
diff changeset
   119
59771
c6e60787ffe2 read instantiations uniformly for rules and tactics;
wenzelm
parents: 59770
diff changeset
   120
    (*explicit type instantiations*)
59825
9fb7661651ad clarified goal context;
wenzelm
parents: 59805
diff changeset
   121
    val instT1 = Term_Subst.instantiateT (map (read_type ctxt1 tvars) type_insts);
20343
e093a54bf25e reworked read_instantiate -- separate read_insts;
wenzelm
parents: 20336
diff changeset
   122
    val vars1 = map (apsnd instT1) vars;
20336
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   123
59771
c6e60787ffe2 read instantiations uniformly for rules and tactics;
wenzelm
parents: 59770
diff changeset
   124
    (*term instantiations*)
45613
70e5b43535cd simplified read_instantiate -- no longer need to assign values, since rule attributes are now static;
wenzelm
parents: 45611
diff changeset
   125
    val (xs, ss) = split_list term_insts;
70e5b43535cd simplified read_instantiate -- no longer need to assign values, since rule attributes are now static;
wenzelm
parents: 45611
diff changeset
   126
    val Ts = map (the_type vars1) xs;
59825
9fb7661651ad clarified goal context;
wenzelm
parents: 59805
diff changeset
   127
    val ((ts, inferred), ctxt2) = read_terms ss Ts ctxt1;
45613
70e5b43535cd simplified read_instantiate -- no longer need to assign values, since rule attributes are now static;
wenzelm
parents: 45611
diff changeset
   128
59771
c6e60787ffe2 read instantiations uniformly for rules and tactics;
wenzelm
parents: 59770
diff changeset
   129
    (*implicit type instantiations*)
59759
cb1966f3a92b tuned -- prepare instantiation more uniformly;
wenzelm
parents: 59755
diff changeset
   130
    val instT2 = Term_Subst.instantiateT inferred;
20343
e093a54bf25e reworked read_instantiate -- separate read_insts;
wenzelm
parents: 20336
diff changeset
   131
    val vars2 = map (apsnd instT2) vars1;
59774
wenzelm
parents: 59772
diff changeset
   132
    val inst2 =
wenzelm
parents: 59772
diff changeset
   133
      Term_Subst.instantiate ([], map2 (fn (xi, _) => fn t => ((xi, Term.fastype_of t), t)) xs ts)
wenzelm
parents: 59772
diff changeset
   134
      #> Envir.beta_norm;
20336
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   135
45613
70e5b43535cd simplified read_instantiate -- no longer need to assign values, since rule attributes are now static;
wenzelm
parents: 45611
diff changeset
   136
    val inst_tvars = map_filter (make_instT (instT2 o instT1)) tvars;
70e5b43535cd simplified read_instantiate -- no longer need to assign values, since rule attributes are now static;
wenzelm
parents: 45611
diff changeset
   137
    val inst_vars = map_filter (make_inst inst2) vars2;
59825
9fb7661651ad clarified goal context;
wenzelm
parents: 59805
diff changeset
   138
  in ((inst_tvars, inst_vars), ctxt2) end;
20343
e093a54bf25e reworked read_instantiate -- separate read_insts;
wenzelm
parents: 20336
diff changeset
   139
59771
c6e60787ffe2 read instantiations uniformly for rules and tactics;
wenzelm
parents: 59770
diff changeset
   140
end;
c6e60787ffe2 read instantiations uniformly for rules and tactics;
wenzelm
parents: 59770
diff changeset
   141
c6e60787ffe2 read instantiations uniformly for rules and tactics;
wenzelm
parents: 59770
diff changeset
   142
c6e60787ffe2 read instantiations uniformly for rules and tactics;
wenzelm
parents: 59770
diff changeset
   143
c6e60787ffe2 read instantiations uniformly for rules and tactics;
wenzelm
parents: 59770
diff changeset
   144
(** forward rules **)
c6e60787ffe2 read instantiations uniformly for rules and tactics;
wenzelm
parents: 59770
diff changeset
   145
59853
4039d8aecda4 more uniform syntax for named instantiations;
wenzelm
parents: 59846
diff changeset
   146
fun where_rule ctxt raw_insts raw_fixes thm =
20343
e093a54bf25e reworked read_instantiate -- separate read_insts;
wenzelm
parents: 20336
diff changeset
   147
  let
59853
4039d8aecda4 more uniform syntax for named instantiations;
wenzelm
parents: 59846
diff changeset
   148
    val ((inst_tvars, inst_vars), ctxt') = read_insts thm raw_insts raw_fixes ctxt;
20343
e093a54bf25e reworked read_instantiate -- separate read_insts;
wenzelm
parents: 20336
diff changeset
   149
  in
59769
wenzelm
parents: 59768
diff changeset
   150
    thm
wenzelm
parents: 59768
diff changeset
   151
    |> Drule.instantiate_normalize
60642
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 60469
diff changeset
   152
      (map (apsnd (Thm.ctyp_of ctxt')) inst_tvars,
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 60469
diff changeset
   153
       map (apsnd (Thm.cterm_of ctxt')) inst_vars)
59853
4039d8aecda4 more uniform syntax for named instantiations;
wenzelm
parents: 59846
diff changeset
   154
    |> singleton (Variable.export ctxt' ctxt)
45613
70e5b43535cd simplified read_instantiate -- no longer need to assign values, since rule attributes are now static;
wenzelm
parents: 45611
diff changeset
   155
    |> Rule_Cases.save thm
20343
e093a54bf25e reworked read_instantiate -- separate read_insts;
wenzelm
parents: 20336
diff changeset
   156
  end;
20336
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   157
55143
04448228381d explicit eigen-context for attributes "where", "of", and corresponding read_instantiate, instantiate_tac;
wenzelm
parents: 55111
diff changeset
   158
fun of_rule ctxt (args, concl_args) fixes thm =
20343
e093a54bf25e reworked read_instantiate -- separate read_insts;
wenzelm
parents: 20336
diff changeset
   159
  let
e093a54bf25e reworked read_instantiate -- separate read_insts;
wenzelm
parents: 20336
diff changeset
   160
    fun zip_vars _ [] = []
45613
70e5b43535cd simplified read_instantiate -- no longer need to assign values, since rule attributes are now static;
wenzelm
parents: 45611
diff changeset
   161
      | zip_vars (_ :: xs) (NONE :: rest) = zip_vars xs rest
59755
f8d164ab0dc1 more position information;
wenzelm
parents: 59754
diff changeset
   162
      | zip_vars ((x, _) :: xs) (SOME t :: rest) = ((x, Position.none), t) :: zip_vars xs rest
20343
e093a54bf25e reworked read_instantiate -- separate read_insts;
wenzelm
parents: 20336
diff changeset
   163
      | zip_vars [] _ = error "More instantiations than variables in theorem";
e093a54bf25e reworked read_instantiate -- separate read_insts;
wenzelm
parents: 20336
diff changeset
   164
    val insts =
e093a54bf25e reworked read_instantiate -- separate read_insts;
wenzelm
parents: 20336
diff changeset
   165
      zip_vars (rev (Term.add_vars (Thm.full_prop_of thm) [])) args @
e093a54bf25e reworked read_instantiate -- separate read_insts;
wenzelm
parents: 20336
diff changeset
   166
      zip_vars (rev (Term.add_vars (Thm.concl_of thm) [])) concl_args;
55143
04448228381d explicit eigen-context for attributes "where", "of", and corresponding read_instantiate, instantiate_tac;
wenzelm
parents: 55111
diff changeset
   167
  in where_rule ctxt insts fixes thm end;
27236
80356567e7ad added read_instantiate;
wenzelm
parents: 27219
diff changeset
   168
55143
04448228381d explicit eigen-context for attributes "where", "of", and corresponding read_instantiate, instantiate_tac;
wenzelm
parents: 55111
diff changeset
   169
fun read_instantiate ctxt insts xs =
04448228381d explicit eigen-context for attributes "where", "of", and corresponding read_instantiate, instantiate_tac;
wenzelm
parents: 55111
diff changeset
   170
  where_rule ctxt insts (map (fn x => (Binding.name x, NONE, NoSyn)) xs);
20336
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   171
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   172
20343
e093a54bf25e reworked read_instantiate -- separate read_insts;
wenzelm
parents: 20336
diff changeset
   173
e093a54bf25e reworked read_instantiate -- separate read_insts;
wenzelm
parents: 20336
diff changeset
   174
(** attributes **)
e093a54bf25e reworked read_instantiate -- separate read_insts;
wenzelm
parents: 20336
diff changeset
   175
20336
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   176
(* where: named instantiation *)
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   177
59855
wenzelm
parents: 59853
diff changeset
   178
val named_insts =
59853
4039d8aecda4 more uniform syntax for named instantiations;
wenzelm
parents: 59846
diff changeset
   179
  Parse.and_list1 (Parse.position Args.var -- (Args.$$$ "=" |-- Parse.!!! Args.name_inner_syntax))
4039d8aecda4 more uniform syntax for named instantiations;
wenzelm
parents: 59846
diff changeset
   180
    -- Parse.for_fixes;
4039d8aecda4 more uniform syntax for named instantiations;
wenzelm
parents: 59846
diff changeset
   181
53171
a5e54d4d9081 added Theory.setup convenience;
wenzelm
parents: 52732
diff changeset
   182
val _ = Theory.setup
53708
92aa282841f8 more antiquotations;
wenzelm
parents: 53707
diff changeset
   183
  (Attrib.setup @{binding "where"}
59855
wenzelm
parents: 59853
diff changeset
   184
    (Scan.lift named_insts >> (fn args =>
wenzelm
parents: 59853
diff changeset
   185
      Thm.rule_attribute (fn context => uncurry (where_rule (Context.proof_of context)) args)))
53171
a5e54d4d9081 added Theory.setup convenience;
wenzelm
parents: 52732
diff changeset
   186
    "named instantiation of theorem");
20336
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   187
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   188
20343
e093a54bf25e reworked read_instantiate -- separate read_insts;
wenzelm
parents: 20336
diff changeset
   189
(* of: positional instantiation (terms only) *)
20336
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   190
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   191
local
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   192
55111
5792f5106c40 tuned signature;
wenzelm
parents: 53708
diff changeset
   193
val inst = Args.maybe Args.name_inner_syntax;
20336
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   194
val concl = Args.$$$ "concl" -- Args.colon;
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   195
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   196
val insts =
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   197
  Scan.repeat (Scan.unless concl inst) --
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   198
  Scan.optional (concl |-- Scan.repeat inst) [];
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   199
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   200
in
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   201
53171
a5e54d4d9081 added Theory.setup convenience;
wenzelm
parents: 52732
diff changeset
   202
val _ = Theory.setup
53708
92aa282841f8 more antiquotations;
wenzelm
parents: 53707
diff changeset
   203
  (Attrib.setup @{binding "of"}
59855
wenzelm
parents: 59853
diff changeset
   204
    (Scan.lift (insts -- Parse.for_fixes) >> (fn args =>
wenzelm
parents: 59853
diff changeset
   205
      Thm.rule_attribute (fn context => uncurry (of_rule (Context.proof_of context)) args)))
53171
a5e54d4d9081 added Theory.setup convenience;
wenzelm
parents: 52732
diff changeset
   206
    "positional instantiation of theorem");
20336
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   207
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   208
end;
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   209
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   210
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   211
27245
817d34377170 added instantiate_tac, cut_inst_tac, forw_inst_tac, dres_inst_tac, make_elim_preserve (from tactic.ML);
wenzelm
parents: 27236
diff changeset
   212
(** tactics **)
20336
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   213
59825
9fb7661651ad clarified goal context;
wenzelm
parents: 59805
diff changeset
   214
(* goal context *)
9fb7661651ad clarified goal context;
wenzelm
parents: 59805
diff changeset
   215
59829
4bce61dd88d2 clarified goal context;
wenzelm
parents: 59828
diff changeset
   216
fun goal_context goal ctxt =
20336
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   217
  let
59828
0e9baaf0e0bb prefer Variable.focus, despite subtle differences of Logic.strip_params vs. Term.strip_all_vars;
wenzelm
parents: 59827
diff changeset
   218
    val ((_, params), ctxt') = ctxt
59829
4bce61dd88d2 clarified goal context;
wenzelm
parents: 59828
diff changeset
   219
      |> Variable.declare_constraints goal
59790
85c572d089fc implicit goal parameters are improper;
wenzelm
parents: 59787
diff changeset
   220
      |> Variable.improper_fixes
60695
757549b4bbe6 Variable.focus etc.: optional bindings provided by user;
wenzelm
parents: 60642
diff changeset
   221
      |> Variable.focus_params NONE goal
60331
f215fd466e30 discontinued legacy;
wenzelm
parents: 59855
diff changeset
   222
      ||> Variable.restore_proper_fixes ctxt;
59828
0e9baaf0e0bb prefer Variable.focus, despite subtle differences of Logic.strip_params vs. Term.strip_all_vars;
wenzelm
parents: 59827
diff changeset
   223
  in (params, ctxt') end;
59825
9fb7661651ad clarified goal context;
wenzelm
parents: 59805
diff changeset
   224
9fb7661651ad clarified goal context;
wenzelm
parents: 59805
diff changeset
   225
9fb7661651ad clarified goal context;
wenzelm
parents: 59805
diff changeset
   226
(* resolution after lifting and instantiation; may refer to parameters of the subgoal *)
9fb7661651ad clarified goal context;
wenzelm
parents: 59805
diff changeset
   227
59853
4039d8aecda4 more uniform syntax for named instantiations;
wenzelm
parents: 59846
diff changeset
   228
fun bires_inst_tac bires_flag ctxt raw_insts raw_fixes thm i st = CSUBGOAL (fn (cgoal, _) =>
59825
9fb7661651ad clarified goal context;
wenzelm
parents: 59805
diff changeset
   229
  let
59855
wenzelm
parents: 59853
diff changeset
   230
    (*goal context*)
59834
wenzelm
parents: 59829
diff changeset
   231
    val (params, goal_ctxt) = goal_context (Thm.term_of cgoal) ctxt;
59825
9fb7661651ad clarified goal context;
wenzelm
parents: 59805
diff changeset
   232
    val paramTs = map #2 params;
59754
696d87036f04 misc tuning;
wenzelm
parents: 59623
diff changeset
   233
59855
wenzelm
parents: 59853
diff changeset
   234
    (*instantiation context*)
59853
4039d8aecda4 more uniform syntax for named instantiations;
wenzelm
parents: 59846
diff changeset
   235
    val ((inst_tvars, inst_vars), inst_ctxt) = read_insts thm raw_insts raw_fixes goal_ctxt;
59846
c7b7bca8592c tuned signature;
wenzelm
parents: 59839
diff changeset
   236
    val fixed = map #1 (fold (Variable.add_newly_fixed inst_ctxt goal_ctxt o #2) inst_vars []);
59805
a162f779925a dummies may depend on goal params as well;
wenzelm
parents: 59801
diff changeset
   237
59780
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59775
diff changeset
   238
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59775
diff changeset
   239
    (* lift and instantiate rule *)
59754
696d87036f04 misc tuning;
wenzelm
parents: 59623
diff changeset
   240
59774
wenzelm
parents: 59772
diff changeset
   241
    val inc = Thm.maxidx_of st + 1;
59825
9fb7661651ad clarified goal context;
wenzelm
parents: 59805
diff changeset
   242
    val lift_type = Logic.incr_tvar inc;
60642
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 60469
diff changeset
   243
    fun lift_var ((a, j), T) = ((a, j + inc), paramTs ---> lift_type T);
59825
9fb7661651ad clarified goal context;
wenzelm
parents: 59805
diff changeset
   244
    fun lift_term t = fold_rev Term.absfree params (Logic.incr_indexes (fixed, paramTs, inc) t);
59754
696d87036f04 misc tuning;
wenzelm
parents: 59623
diff changeset
   245
59771
c6e60787ffe2 read instantiations uniformly for rules and tactics;
wenzelm
parents: 59770
diff changeset
   246
    val inst_tvars' = inst_tvars
60642
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 60469
diff changeset
   247
      |> map (fn (((a, i), S), T) => (((a, i + inc), S), Thm.ctyp_of inst_ctxt (lift_type T)));
59771
c6e60787ffe2 read instantiations uniformly for rules and tactics;
wenzelm
parents: 59770
diff changeset
   248
    val inst_vars' = inst_vars
60642
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 60469
diff changeset
   249
      |> map (fn (v, t) => (lift_var v, Thm.cterm_of inst_ctxt (lift_term t)));
59771
c6e60787ffe2 read instantiations uniformly for rules and tactics;
wenzelm
parents: 59770
diff changeset
   250
59825
9fb7661651ad clarified goal context;
wenzelm
parents: 59805
diff changeset
   251
    val thm' = Thm.lift_rule cgoal thm
9fb7661651ad clarified goal context;
wenzelm
parents: 59805
diff changeset
   252
      |> Drule.instantiate_normalize (inst_tvars', inst_vars')
59836
5e77a35adc67 clarified context;
wenzelm
parents: 59835
diff changeset
   253
      |> singleton (Variable.export inst_ctxt ctxt);
5e77a35adc67 clarified context;
wenzelm
parents: 59835
diff changeset
   254
  in compose_tac ctxt (bires_flag, thm', Thm.nprems_of thm) i end) i st;
20336
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   255
27120
b21eec437295 added (e)res_inst_tac;
wenzelm
parents: 26463
diff changeset
   256
val res_inst_tac = bires_inst_tac false;
b21eec437295 added (e)res_inst_tac;
wenzelm
parents: 26463
diff changeset
   257
val eres_inst_tac = bires_inst_tac true;
b21eec437295 added (e)res_inst_tac;
wenzelm
parents: 26463
diff changeset
   258
b21eec437295 added (e)res_inst_tac;
wenzelm
parents: 26463
diff changeset
   259
27245
817d34377170 added instantiate_tac, cut_inst_tac, forw_inst_tac, dres_inst_tac, make_elim_preserve (from tactic.ML);
wenzelm
parents: 27236
diff changeset
   260
(* forward resolution *)
817d34377170 added instantiate_tac, cut_inst_tac, forw_inst_tac, dres_inst_tac, make_elim_preserve (from tactic.ML);
wenzelm
parents: 27236
diff changeset
   261
58950
d07464875dd4 optional proof context for unify operations, for the sake of proper local options;
wenzelm
parents: 58027
diff changeset
   262
fun make_elim_preserve ctxt rl =
27245
817d34377170 added instantiate_tac, cut_inst_tac, forw_inst_tac, dres_inst_tac, make_elim_preserve (from tactic.ML);
wenzelm
parents: 27236
diff changeset
   263
  let
817d34377170 added instantiate_tac, cut_inst_tac, forw_inst_tac, dres_inst_tac, make_elim_preserve (from tactic.ML);
wenzelm
parents: 27236
diff changeset
   264
    val maxidx = Thm.maxidx_of rl;
60642
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 60469
diff changeset
   265
    fun var x = ((x, 0), propT);
59623
920889b0788e clarified context;
wenzelm
parents: 59621
diff changeset
   266
    fun cvar xi = Thm.cterm_of ctxt (Var (xi, propT));
27245
817d34377170 added instantiate_tac, cut_inst_tac, forw_inst_tac, dres_inst_tac, make_elim_preserve (from tactic.ML);
wenzelm
parents: 27236
diff changeset
   267
    val revcut_rl' =
60642
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 60469
diff changeset
   268
      Drule.instantiate_normalize ([], [(var "V", cvar ("V", maxidx + 1)),
48dd1cefb4ae simplified Thm.instantiate and derivatives: the LHS refers to non-certified variables -- this merely serves as index into already certified structures (or is ignored);
wenzelm
parents: 60469
diff changeset
   269
        (var "W", cvar ("W", maxidx + 1))]) Drule.revcut_rl;
27245
817d34377170 added instantiate_tac, cut_inst_tac, forw_inst_tac, dres_inst_tac, make_elim_preserve (from tactic.ML);
wenzelm
parents: 27236
diff changeset
   270
  in
52223
5bb6ae8acb87 tuned signature -- more explicit flags for low-level Thm.bicompose;
wenzelm
parents: 46476
diff changeset
   271
    (case Seq.list_of
58950
d07464875dd4 optional proof context for unify operations, for the sake of proper local options;
wenzelm
parents: 58027
diff changeset
   272
      (Thm.bicompose (SOME ctxt) {flatten = true, match = false, incremented = false}
52223
5bb6ae8acb87 tuned signature -- more explicit flags for low-level Thm.bicompose;
wenzelm
parents: 46476
diff changeset
   273
        (false, rl, Thm.nprems_of rl) 1 revcut_rl')
5bb6ae8acb87 tuned signature -- more explicit flags for low-level Thm.bicompose;
wenzelm
parents: 46476
diff changeset
   274
     of
27245
817d34377170 added instantiate_tac, cut_inst_tac, forw_inst_tac, dres_inst_tac, make_elim_preserve (from tactic.ML);
wenzelm
parents: 27236
diff changeset
   275
      [th] => th
817d34377170 added instantiate_tac, cut_inst_tac, forw_inst_tac, dres_inst_tac, make_elim_preserve (from tactic.ML);
wenzelm
parents: 27236
diff changeset
   276
    | _ => raise THM ("make_elim_preserve", 1, [rl]))
817d34377170 added instantiate_tac, cut_inst_tac, forw_inst_tac, dres_inst_tac, make_elim_preserve (from tactic.ML);
wenzelm
parents: 27236
diff changeset
   277
  end;
817d34377170 added instantiate_tac, cut_inst_tac, forw_inst_tac, dres_inst_tac, make_elim_preserve (from tactic.ML);
wenzelm
parents: 27236
diff changeset
   278
817d34377170 added instantiate_tac, cut_inst_tac, forw_inst_tac, dres_inst_tac, make_elim_preserve (from tactic.ML);
wenzelm
parents: 27236
diff changeset
   279
(*instantiate and cut -- for atomic fact*)
59780
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59775
diff changeset
   280
fun cut_inst_tac ctxt insts fixes rule =
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59775
diff changeset
   281
  res_inst_tac ctxt insts fixes (make_elim_preserve ctxt rule);
27245
817d34377170 added instantiate_tac, cut_inst_tac, forw_inst_tac, dres_inst_tac, make_elim_preserve (from tactic.ML);
wenzelm
parents: 27236
diff changeset
   282
817d34377170 added instantiate_tac, cut_inst_tac, forw_inst_tac, dres_inst_tac, make_elim_preserve (from tactic.ML);
wenzelm
parents: 27236
diff changeset
   283
(*forward tactic applies a rule to an assumption without deleting it*)
59780
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59775
diff changeset
   284
fun forw_inst_tac ctxt insts fixes rule =
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59775
diff changeset
   285
  cut_inst_tac ctxt insts fixes rule THEN' assume_tac ctxt;
27245
817d34377170 added instantiate_tac, cut_inst_tac, forw_inst_tac, dres_inst_tac, make_elim_preserve (from tactic.ML);
wenzelm
parents: 27236
diff changeset
   286
817d34377170 added instantiate_tac, cut_inst_tac, forw_inst_tac, dres_inst_tac, make_elim_preserve (from tactic.ML);
wenzelm
parents: 27236
diff changeset
   287
(*dresolve tactic applies a rule to replace an assumption*)
59780
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59775
diff changeset
   288
fun dres_inst_tac ctxt insts fixes rule =
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59775
diff changeset
   289
  eres_inst_tac ctxt insts fixes (make_elim_preserve ctxt rule);
27245
817d34377170 added instantiate_tac, cut_inst_tac, forw_inst_tac, dres_inst_tac, make_elim_preserve (from tactic.ML);
wenzelm
parents: 27236
diff changeset
   290
817d34377170 added instantiate_tac, cut_inst_tac, forw_inst_tac, dres_inst_tac, make_elim_preserve (from tactic.ML);
wenzelm
parents: 27236
diff changeset
   291
817d34377170 added instantiate_tac, cut_inst_tac, forw_inst_tac, dres_inst_tac, make_elim_preserve (from tactic.ML);
wenzelm
parents: 27236
diff changeset
   292
(* derived tactics *)
817d34377170 added instantiate_tac, cut_inst_tac, forw_inst_tac, dres_inst_tac, make_elim_preserve (from tactic.ML);
wenzelm
parents: 27236
diff changeset
   293
817d34377170 added instantiate_tac, cut_inst_tac, forw_inst_tac, dres_inst_tac, make_elim_preserve (from tactic.ML);
wenzelm
parents: 27236
diff changeset
   294
(*deletion of an assumption*)
59780
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59775
diff changeset
   295
fun thin_tac ctxt s fixes =
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59775
diff changeset
   296
  eres_inst_tac ctxt [((("V", 0), Position.none), s)] fixes Drule.thin_rl;
27245
817d34377170 added instantiate_tac, cut_inst_tac, forw_inst_tac, dres_inst_tac, make_elim_preserve (from tactic.ML);
wenzelm
parents: 27236
diff changeset
   297
817d34377170 added instantiate_tac, cut_inst_tac, forw_inst_tac, dres_inst_tac, make_elim_preserve (from tactic.ML);
wenzelm
parents: 27236
diff changeset
   298
(*Introduce the given proposition as lemma and subgoal*)
59780
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59775
diff changeset
   299
fun subgoal_tac ctxt A fixes =
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59775
diff changeset
   300
  DETERM o res_inst_tac ctxt [((("psi", 0), Position.none), A)] fixes cut_rl;
27245
817d34377170 added instantiate_tac, cut_inst_tac, forw_inst_tac, dres_inst_tac, make_elim_preserve (from tactic.ML);
wenzelm
parents: 27236
diff changeset
   301
817d34377170 added instantiate_tac, cut_inst_tac, forw_inst_tac, dres_inst_tac, make_elim_preserve (from tactic.ML);
wenzelm
parents: 27236
diff changeset
   302
53708
92aa282841f8 more antiquotations;
wenzelm
parents: 53707
diff changeset
   303
(* method wrapper *)
27245
817d34377170 added instantiate_tac, cut_inst_tac, forw_inst_tac, dres_inst_tac, make_elim_preserve (from tactic.ML);
wenzelm
parents: 27236
diff changeset
   304
30545
8209a7196389 export method parser;
wenzelm
parents: 30528
diff changeset
   305
fun method inst_tac tac =
59855
wenzelm
parents: 59853
diff changeset
   306
  Args.goal_spec -- Scan.optional (Scan.lift (named_insts --| Args.$$$ "in")) ([], []) --
wenzelm
parents: 59853
diff changeset
   307
  Attrib.thms >> (fn ((quant, (insts, fixes)), thms) => fn ctxt => METHOD (fn facts =>
59780
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59775
diff changeset
   308
    if null insts andalso null fixes
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59775
diff changeset
   309
    then quant (Method.insert_tac facts THEN' tac ctxt thms)
30515
bca05b17b618 simplified method setup;
wenzelm
parents: 30510
diff changeset
   310
    else
bca05b17b618 simplified method setup;
wenzelm
parents: 30510
diff changeset
   311
      (case thms of
59780
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59775
diff changeset
   312
        [thm] => quant (Method.insert_tac facts THEN' inst_tac ctxt insts fixes thm)
30515
bca05b17b618 simplified method setup;
wenzelm
parents: 30510
diff changeset
   313
      | _ => error "Cannot have instantiations with multiple rules")));
20336
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   314
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   315
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   316
(* setup *)
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   317
53708
92aa282841f8 more antiquotations;
wenzelm
parents: 53707
diff changeset
   318
(*warning: rule_tac etc. refer to dynamic subgoal context!*)
92aa282841f8 more antiquotations;
wenzelm
parents: 53707
diff changeset
   319
53171
a5e54d4d9081 added Theory.setup convenience;
wenzelm
parents: 52732
diff changeset
   320
val _ = Theory.setup
59498
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 59058
diff changeset
   321
 (Method.setup @{binding rule_tac} (method res_inst_tac resolve_tac)
53708
92aa282841f8 more antiquotations;
wenzelm
parents: 53707
diff changeset
   322
    "apply rule (dynamic instantiation)" #>
59498
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 59058
diff changeset
   323
  Method.setup @{binding erule_tac} (method eres_inst_tac eresolve_tac)
30515
bca05b17b618 simplified method setup;
wenzelm
parents: 30510
diff changeset
   324
    "apply rule in elimination manner (dynamic instantiation)" #>
59498
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 59058
diff changeset
   325
  Method.setup @{binding drule_tac} (method dres_inst_tac dresolve_tac)
30515
bca05b17b618 simplified method setup;
wenzelm
parents: 30510
diff changeset
   326
    "apply rule in destruct manner (dynamic instantiation)" #>
59498
50b60f501b05 proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents: 59058
diff changeset
   327
  Method.setup @{binding frule_tac} (method forw_inst_tac forward_tac)
30515
bca05b17b618 simplified method setup;
wenzelm
parents: 30510
diff changeset
   328
    "apply rule in forward manner (dynamic instantiation)" #>
53708
92aa282841f8 more antiquotations;
wenzelm
parents: 53707
diff changeset
   329
  Method.setup @{binding cut_tac} (method cut_inst_tac (K cut_rules_tac))
92aa282841f8 more antiquotations;
wenzelm
parents: 53707
diff changeset
   330
    "cut rule (dynamic instantiation)" #>
92aa282841f8 more antiquotations;
wenzelm
parents: 53707
diff changeset
   331
  Method.setup @{binding subgoal_tac}
59780
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59775
diff changeset
   332
    (Args.goal_spec -- Scan.lift (Scan.repeat1 Args.name_inner_syntax -- Parse.for_fixes) >>
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59775
diff changeset
   333
      (fn (quant, (props, fixes)) => fn ctxt =>
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59775
diff changeset
   334
        SIMPLE_METHOD'' quant (EVERY' (map (fn prop => subgoal_tac ctxt prop fixes) props))))
30515
bca05b17b618 simplified method setup;
wenzelm
parents: 30510
diff changeset
   335
    "insert subgoal (dynamic instantiation)" #>
53708
92aa282841f8 more antiquotations;
wenzelm
parents: 53707
diff changeset
   336
  Method.setup @{binding thin_tac}
59780
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59775
diff changeset
   337
    (Args.goal_spec -- Scan.lift (Args.name_inner_syntax -- Parse.for_fixes) >>
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59775
diff changeset
   338
      (fn (quant, (prop, fixes)) => fn ctxt => SIMPLE_METHOD'' quant (thin_tac ctxt prop fixes)))
23b67731f4f0 support 'for' fixes in rule_tac etc.;
wenzelm
parents: 59775
diff changeset
   339
    "remove premise (dynamic instantiation)");
20336
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   340
aac494583949 Rule instantiations -- operations within a rule/subgoal context.
wenzelm
parents:
diff changeset
   341
end;