src/Pure/goal.ML
author wenzelm
Sat Dec 14 17:28:05 2013 +0100 (2013-12-14)
changeset 54742 7a86358a3c0b
parent 54567 cfe53047dc16
child 54883 dd04a8b654fc
permissions -rw-r--r--
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
clarified tool context in some boundary cases;
wenzelm@17980
     1
(*  Title:      Pure/goal.ML
wenzelm@29345
     2
    Author:     Makarius
wenzelm@17980
     3
wenzelm@49061
     4
Goals in tactical theorem proving, with support for forked proofs.
wenzelm@17980
     5
*)
wenzelm@17980
     6
wenzelm@17980
     7
signature BASIC_GOAL =
wenzelm@17980
     8
sig
wenzelm@32738
     9
  val parallel_proofs: int Unsynchronized.ref
wenzelm@17980
    10
  val SELECT_GOAL: tactic -> int -> tactic
wenzelm@52458
    11
  val PREFER_GOAL: tactic -> int -> tactic
wenzelm@23418
    12
  val CONJUNCTS: tactic -> int -> tactic
wenzelm@23414
    13
  val PRECISE_CONJUNCTS: int -> tactic -> int -> tactic
wenzelm@32365
    14
  val PARALLEL_CHOICE: tactic list -> tactic
wenzelm@32365
    15
  val PARALLEL_GOALS: tactic -> tactic
wenzelm@17980
    16
end;
wenzelm@17980
    17
wenzelm@17980
    18
signature GOAL =
wenzelm@17980
    19
sig
wenzelm@17980
    20
  include BASIC_GOAL
wenzelm@17980
    21
  val init: cterm -> thm
wenzelm@52456
    22
  val protect: int -> thm -> thm
wenzelm@17980
    23
  val conclude: thm -> thm
wenzelm@49845
    24
  val check_finished: Proof.context -> thm -> thm
wenzelm@32197
    25
  val finish: Proof.context -> thm -> thm
wenzelm@21604
    26
  val norm_result: thm -> thm
wenzelm@52499
    27
  val skip_proofs_enabled: unit -> bool
wenzelm@53189
    28
  val future_enabled: int -> bool
wenzelm@51423
    29
  val future_enabled_timing: Time.time -> bool
wenzelm@28973
    30
  val future_result: Proof.context -> thm future -> term -> thm
wenzelm@23356
    31
  val prove_internal: cterm list -> cterm -> (thm list -> tactic) -> thm
wenzelm@51553
    32
  val is_schematic: term -> bool
wenzelm@20290
    33
  val prove_multi: Proof.context -> string list -> term list -> term list ->
wenzelm@20290
    34
    ({prems: thm list, context: Proof.context} -> tactic) -> thm list
wenzelm@28446
    35
  val prove_future: Proof.context -> string list -> term list -> term ->
wenzelm@28340
    36
    ({prems: thm list, context: Proof.context} -> tactic) -> thm
wenzelm@20290
    37
  val prove: Proof.context -> string list -> term list -> term ->
wenzelm@20290
    38
    ({prems: thm list, context: Proof.context} -> tactic) -> thm
wenzelm@51118
    39
  val prove_global_future: theory -> string list -> term list -> term ->
wenzelm@51118
    40
    ({prems: thm list, context: Proof.context} -> tactic) -> thm
wenzelm@26713
    41
  val prove_global: theory -> string list -> term list -> term ->
wenzelm@26713
    42
    ({prems: thm list, context: Proof.context} -> tactic) -> thm
wenzelm@51551
    43
  val prove_sorry: Proof.context -> string list -> term list -> term ->
wenzelm@51551
    44
    ({prems: thm list, context: Proof.context} -> tactic) -> thm
wenzelm@51551
    45
  val prove_sorry_global: theory -> string list -> term list -> term ->
wenzelm@51551
    46
    ({prems: thm list, context: Proof.context} -> tactic) -> thm
wenzelm@52458
    47
  val restrict: int -> int -> thm -> thm
wenzelm@52458
    48
  val unrestrict: int -> thm -> thm
wenzelm@23418
    49
  val conjunction_tac: int -> tactic
wenzelm@23414
    50
  val precise_conjunction_tac: int -> int -> tactic
wenzelm@23418
    51
  val recover_conjunction_tac: tactic
wenzelm@54742
    52
  val norm_hhf_tac: Proof.context -> int -> tactic
wenzelm@23237
    53
  val assume_rule_tac: Proof.context -> int -> tactic
wenzelm@17980
    54
end;
wenzelm@17980
    55
wenzelm@17980
    56
structure Goal: GOAL =
wenzelm@17980
    57
struct
wenzelm@17980
    58
wenzelm@18027
    59
(** goals **)
wenzelm@18027
    60
wenzelm@18027
    61
(*
wenzelm@18027
    62
  -------- (init)
wenzelm@18027
    63
  C ==> #C
wenzelm@18027
    64
*)
wenzelm@20290
    65
val init =
wenzelm@22902
    66
  let val A = #1 (Thm.dest_implies (Thm.cprop_of Drule.protectI))
wenzelm@20290
    67
  in fn C => Thm.instantiate ([], [(A, C)]) Drule.protectI end;
wenzelm@17980
    68
wenzelm@17980
    69
(*
wenzelm@52456
    70
  A1 ==> ... ==> An ==> C
wenzelm@52456
    71
  ------------------------ (protect n)
wenzelm@52456
    72
  A1 ==> ... ==> An ==> #C
wenzelm@17980
    73
*)
wenzelm@52456
    74
fun protect n th = Drule.comp_no_flatten (th, n) 1 Drule.protectI;
wenzelm@17980
    75
wenzelm@17980
    76
(*
wenzelm@18027
    77
  A ==> ... ==> #C
wenzelm@18027
    78
  ---------------- (conclude)
wenzelm@17980
    79
  A ==> ... ==> C
wenzelm@17980
    80
*)
wenzelm@29345
    81
fun conclude th = Drule.comp_no_flatten (th, Thm.nprems_of th) 1 Drule.protectD;
wenzelm@17980
    82
wenzelm@17980
    83
(*
wenzelm@18027
    84
  #C
wenzelm@18027
    85
  --- (finish)
wenzelm@18027
    86
   C
wenzelm@17983
    87
*)
wenzelm@32197
    88
fun check_finished ctxt th =
wenzelm@51608
    89
  if Thm.no_prems th then th
wenzelm@51608
    90
  else
wenzelm@51958
    91
    raise THM ("Proof failed.\n" ^ Pretty.string_of (Goal_Display.pretty_goal ctxt th), 0, [th]);
wenzelm@32197
    92
wenzelm@49845
    93
fun finish ctxt = check_finished ctxt #> conclude;
wenzelm@17980
    94
wenzelm@17980
    95
wenzelm@18027
    96
wenzelm@18027
    97
(** results **)
wenzelm@18027
    98
wenzelm@28340
    99
(* normal form *)
wenzelm@28340
   100
wenzelm@21604
   101
val norm_result =
wenzelm@21604
   102
  Drule.flexflex_unique
wenzelm@41228
   103
  #> Raw_Simplifier.norm_hhf_protect
wenzelm@21604
   104
  #> Thm.strip_shyps
wenzelm@21604
   105
  #> Drule.zero_var_indexes;
wenzelm@21604
   106
wenzelm@21604
   107
wenzelm@41703
   108
(* scheduling parameters *)
wenzelm@41703
   109
wenzelm@52499
   110
fun skip_proofs_enabled () =
wenzelm@52710
   111
  let val skip = Options.default_bool "skip_proofs" in
wenzelm@52499
   112
    if Proofterm.proofs_enabled () andalso skip then
wenzelm@52499
   113
      (warning "Proof terms enabled -- cannot skip proofs"; false)
wenzelm@52499
   114
    else skip
wenzelm@52499
   115
  end;
wenzelm@52499
   116
wenzelm@32738
   117
val parallel_proofs = Unsynchronized.ref 1;
wenzelm@29448
   118
wenzelm@53189
   119
fun future_enabled n =
wenzelm@49012
   120
  Multithreading.enabled () andalso ! parallel_proofs >= n andalso
wenzelm@41703
   121
  is_some (Future.worker_task ());
wenzelm@32061
   122
wenzelm@51423
   123
fun future_enabled_timing t =
wenzelm@53189
   124
  future_enabled 1 andalso
wenzelm@52104
   125
    Time.toReal t >= Options.default_real "parallel_subproofs_threshold";
wenzelm@29448
   126
wenzelm@29448
   127
wenzelm@28446
   128
(* future_result *)
wenzelm@28340
   129
wenzelm@28446
   130
fun future_result ctxt result prop =
wenzelm@28340
   131
  let
wenzelm@42360
   132
    val thy = Proof_Context.theory_of ctxt;
wenzelm@28340
   133
    val cert = Thm.cterm_of thy;
wenzelm@28340
   134
    val certT = Thm.ctyp_of thy;
wenzelm@28340
   135
wenzelm@30473
   136
    val assms = Assumption.all_assms_of ctxt;
wenzelm@28340
   137
    val As = map Thm.term_of assms;
wenzelm@28340
   138
wenzelm@28340
   139
    val xs = map Free (fold Term.add_frees (prop :: As) []);
wenzelm@28340
   140
    val fixes = map cert xs;
wenzelm@28340
   141
wenzelm@28340
   142
    val tfrees = fold Term.add_tfrees (prop :: As) [];
wenzelm@28340
   143
    val instT = map (fn (a, S) => (certT (TVar ((a, 0), S)), certT (TFree (a, S)))) tfrees;
wenzelm@28340
   144
wenzelm@28340
   145
    val global_prop =
wenzelm@45344
   146
      cert (Logic.varify_types_global (fold_rev Logic.all xs (Logic.list_implies (As, prop))))
wenzelm@32056
   147
      |> Thm.weaken_sorts (Variable.sorts_of ctxt);
wenzelm@28973
   148
    val global_result = result |> Future.map
wenzelm@33768
   149
      (Drule.flexflex_unique #>
wenzelm@33768
   150
        Thm.adjust_maxidx_thm ~1 #>
wenzelm@28973
   151
        Drule.implies_intr_list assms #>
wenzelm@28973
   152
        Drule.forall_intr_list fixes #>
wenzelm@36613
   153
        Thm.generalize (map #1 tfrees, []) 0 #>
wenzelm@36613
   154
        Thm.strip_shyps);
wenzelm@28340
   155
    val local_result =
wenzelm@32056
   156
      Thm.future global_result global_prop
wenzelm@50987
   157
      |> Thm.close_derivation
wenzelm@28340
   158
      |> Thm.instantiate (instT, [])
wenzelm@28340
   159
      |> Drule.forall_elim_list fixes
wenzelm@28340
   160
      |> fold (Thm.elim_implies o Thm.assume) assms;
wenzelm@28340
   161
  in local_result end;
wenzelm@28340
   162
wenzelm@28340
   163
wenzelm@18027
   164
wenzelm@18027
   165
(** tactical theorem proving **)
wenzelm@18027
   166
wenzelm@23356
   167
(* prove_internal -- minimal checks, no normalization of result! *)
wenzelm@20250
   168
wenzelm@23356
   169
fun prove_internal casms cprop tac =
wenzelm@20250
   170
  (case SINGLE (tac (map Assumption.assume casms)) (init cprop) of
wenzelm@32197
   171
    SOME th => Drule.implies_intr_list casms
wenzelm@32197
   172
      (finish (Syntax.init_pretty_global (Thm.theory_of_thm th)) th)
wenzelm@38875
   173
  | NONE => error "Tactic failed");
wenzelm@20250
   174
wenzelm@20250
   175
wenzelm@51553
   176
(* prove variations *)
wenzelm@51553
   177
wenzelm@51553
   178
fun is_schematic t =
wenzelm@51553
   179
  Term.exists_subterm Term.is_Var t orelse
wenzelm@51553
   180
  Term.exists_type (Term.exists_subtype Term.is_TVar) t;
wenzelm@17986
   181
wenzelm@52811
   182
fun prove_common immediate pri ctxt xs asms props tac =
wenzelm@17980
   183
  let
wenzelm@42360
   184
    val thy = Proof_Context.theory_of ctxt;
wenzelm@20056
   185
wenzelm@51553
   186
    val schematic = exists is_schematic props;
wenzelm@53189
   187
    val future = future_enabled 1;
wenzelm@52499
   188
    val skip = not immediate andalso not schematic andalso future andalso skip_proofs_enabled ();
wenzelm@51553
   189
wenzelm@28355
   190
    val pos = Position.thread_data ();
wenzelm@20250
   191
    fun err msg = cat_error msg
wenzelm@20250
   192
      ("The error(s) above occurred for the goal statement:\n" ^
wenzelm@54567
   193
        Syntax.string_of_term ctxt (Logic.list_implies (asms, Logic.mk_conjunction_list props)) ^
wenzelm@48992
   194
        (case Position.here pos of "" => "" | s => "\n" ^ s));
wenzelm@17980
   195
wenzelm@20250
   196
    fun cert_safe t = Thm.cterm_of thy (Envir.beta_norm (Term.no_dummy_patterns t))
wenzelm@17980
   197
      handle TERM (msg, _) => err msg | TYPE (msg, _, _) => err msg;
wenzelm@20250
   198
    val casms = map cert_safe asms;
wenzelm@20250
   199
    val cprops = map cert_safe props;
wenzelm@17980
   200
wenzelm@20250
   201
    val (prems, ctxt') = ctxt
wenzelm@20250
   202
      |> Variable.add_fixes_direct xs
wenzelm@27218
   203
      |> fold Variable.declare_term (asms @ props)
wenzelm@26713
   204
      |> Assumption.add_assumes casms
wenzelm@26713
   205
      ||> Variable.set_body true;
wenzelm@28619
   206
    val sorts = Variable.sorts_of ctxt';
wenzelm@17980
   207
wenzelm@28619
   208
    val stmt = Thm.weaken_sorts sorts (Conjunction.mk_conjunction_balanced cprops);
wenzelm@28340
   209
wenzelm@51553
   210
    fun tac' args st =
wenzelm@51553
   211
      if skip then ALLGOALS Skip_Proof.cheat_tac st before Skip_Proof.report ctxt
wenzelm@51553
   212
      else tac args st;
wenzelm@28340
   213
    fun result () =
wenzelm@51553
   214
      (case SINGLE (tac' {prems = prems, context = ctxt'}) (init stmt) of
wenzelm@38875
   215
        NONE => err "Tactic failed"
wenzelm@28340
   216
      | SOME st =>
wenzelm@54567
   217
          let
wenzelm@54567
   218
            val res =
wenzelm@54567
   219
              (finish ctxt' st
wenzelm@54567
   220
                |> Drule.flexflex_unique
wenzelm@54567
   221
                |> Thm.check_shyps sorts
wenzelm@54567
   222
                (* |> Assumption.check_hyps ctxt' FIXME *))
wenzelm@54567
   223
              handle THM (msg, _, _) => err msg | ERROR msg => err msg;
wenzelm@54567
   224
          in
wenzelm@54567
   225
            if Unify.matches_list thy [Thm.term_of stmt] [Thm.prop_of res] then res
wenzelm@54567
   226
            else err ("Proved a different theorem: " ^ Syntax.string_of_term ctxt' (Thm.prop_of res))
wenzelm@28340
   227
          end);
wenzelm@28340
   228
    val res =
wenzelm@53192
   229
      if immediate orelse schematic orelse not future orelse skip then result ()
wenzelm@53192
   230
      else
wenzelm@53192
   231
        future_result ctxt'
wenzelm@53192
   232
          (Execution.fork {name = "Goal.prove", pos = Position.thread_data (), pri = pri} result)
wenzelm@53192
   233
          (Thm.term_of stmt);
wenzelm@17980
   234
  in
wenzelm@28340
   235
    Conjunction.elim_balanced (length props) res
wenzelm@20290
   236
    |> map (Assumption.export false ctxt' ctxt)
wenzelm@20056
   237
    |> Variable.export ctxt' ctxt
wenzelm@20250
   238
    |> map Drule.zero_var_indexes
wenzelm@17980
   239
  end;
wenzelm@17980
   240
wenzelm@52811
   241
val prove_multi = prove_common true 0;
wenzelm@17980
   242
wenzelm@52811
   243
fun prove_future_pri pri ctxt xs asms prop tac =
wenzelm@52811
   244
  hd (prove_common false pri ctxt xs asms [prop] tac);
wenzelm@51118
   245
wenzelm@52811
   246
val prove_future = prove_future_pri ~1;
wenzelm@52811
   247
wenzelm@52811
   248
fun prove ctxt xs asms prop tac = hd (prove_multi ctxt xs asms [prop] tac);
wenzelm@20056
   249
wenzelm@51118
   250
fun prove_global_future thy xs asms prop tac =
wenzelm@51118
   251
  Drule.export_without_context (prove_future (Proof_Context.init_global thy) xs asms prop tac);
wenzelm@51118
   252
wenzelm@20056
   253
fun prove_global thy xs asms prop tac =
wenzelm@42360
   254
  Drule.export_without_context (prove (Proof_Context.init_global thy) xs asms prop tac);
wenzelm@18027
   255
wenzelm@51551
   256
fun prove_sorry ctxt xs asms prop tac =
wenzelm@52059
   257
  if Config.get ctxt quick_and_dirty then
wenzelm@51552
   258
    prove ctxt xs asms prop (fn _ => ALLGOALS Skip_Proof.cheat_tac)
wenzelm@53189
   259
  else (if future_enabled 1 then prove_future_pri ~2 else prove) ctxt xs asms prop tac;
wenzelm@51551
   260
wenzelm@51551
   261
fun prove_sorry_global thy xs asms prop tac =
wenzelm@51551
   262
  Drule.export_without_context
wenzelm@51551
   263
    (prove_sorry (Proof_Context.init_global thy) xs asms prop tac);
wenzelm@51551
   264
wenzelm@18027
   265
wenzelm@17980
   266
wenzelm@21687
   267
(** goal structure **)
wenzelm@21687
   268
wenzelm@52458
   269
(* rearrange subgoals *)
wenzelm@52458
   270
wenzelm@52458
   271
fun restrict i n st =
wenzelm@52458
   272
  if i < 1 orelse n < 1 orelse i + n - 1 > Thm.nprems_of st
wenzelm@52458
   273
  then raise THM ("Goal.restrict", i, [st])
wenzelm@52458
   274
  else rotate_prems (i - 1) st |> protect n;
wenzelm@52458
   275
wenzelm@52458
   276
fun unrestrict i = conclude #> rotate_prems (1 - i);
wenzelm@52458
   277
wenzelm@52458
   278
(*with structural marker*)
wenzelm@17980
   279
fun SELECT_GOAL tac i st =
wenzelm@19191
   280
  if Thm.nprems_of st = 1 andalso i = 1 then tac st
wenzelm@52458
   281
  else (PRIMITIVE (restrict i 1) THEN tac THEN PRIMITIVE (unrestrict i)) st;
wenzelm@52458
   282
wenzelm@52458
   283
(*without structural marker*)
wenzelm@52458
   284
fun PREFER_GOAL tac i st =
wenzelm@52458
   285
  if i < 1 orelse i > Thm.nprems_of st then Seq.empty
wenzelm@52458
   286
  else (PRIMITIVE (rotate_prems (i - 1)) THEN tac THEN PRIMITIVE (rotate_prems (1 - i))) st;
wenzelm@17980
   287
wenzelm@21687
   288
wenzelm@21687
   289
(* multiple goals *)
wenzelm@21687
   290
wenzelm@23418
   291
fun precise_conjunction_tac 0 i = eq_assume_tac i
wenzelm@23418
   292
  | precise_conjunction_tac 1 i = SUBGOAL (K all_tac) i
wenzelm@23418
   293
  | precise_conjunction_tac n i = PRIMITIVE (Drule.with_subgoal i (Conjunction.curry_balanced n));
wenzelm@23414
   294
wenzelm@23418
   295
val adhoc_conjunction_tac = REPEAT_ALL_NEW
wenzelm@23418
   296
  (SUBGOAL (fn (goal, i) =>
wenzelm@23418
   297
    if can Logic.dest_conjunction goal then rtac Conjunction.conjunctionI i
wenzelm@23418
   298
    else no_tac));
wenzelm@21687
   299
wenzelm@23418
   300
val conjunction_tac = SUBGOAL (fn (goal, i) =>
wenzelm@23418
   301
  precise_conjunction_tac (length (Logic.dest_conjunctions goal)) i ORELSE
wenzelm@23418
   302
  TRY (adhoc_conjunction_tac i));
wenzelm@21687
   303
wenzelm@23418
   304
val recover_conjunction_tac = PRIMITIVE (fn th =>
wenzelm@23418
   305
  Conjunction.uncurry_balanced (Thm.nprems_of th) th);
wenzelm@23414
   306
wenzelm@23414
   307
fun PRECISE_CONJUNCTS n tac =
wenzelm@23414
   308
  SELECT_GOAL (precise_conjunction_tac n 1
wenzelm@23414
   309
    THEN tac
wenzelm@23418
   310
    THEN recover_conjunction_tac);
wenzelm@23414
   311
wenzelm@21687
   312
fun CONJUNCTS tac =
wenzelm@21687
   313
  SELECT_GOAL (conjunction_tac 1
wenzelm@21687
   314
    THEN tac
wenzelm@23418
   315
    THEN recover_conjunction_tac);
wenzelm@21687
   316
wenzelm@21687
   317
wenzelm@21687
   318
(* hhf normal form *)
wenzelm@21687
   319
wenzelm@54742
   320
fun norm_hhf_tac ctxt =
wenzelm@21687
   321
  rtac Drule.asm_rl  (*cheap approximation -- thanks to builtin Logic.flatten_params*)
wenzelm@21687
   322
  THEN' SUBGOAL (fn (t, i) =>
wenzelm@21687
   323
    if Drule.is_norm_hhf t then all_tac
wenzelm@54742
   324
    else rewrite_goal_tac ctxt Drule.norm_hhf_eqs i);
wenzelm@21687
   325
wenzelm@23237
   326
wenzelm@23237
   327
(* non-atomic goal assumptions *)
wenzelm@23237
   328
wenzelm@23356
   329
fun non_atomic (Const ("==>", _) $ _ $ _) = true
wenzelm@23356
   330
  | non_atomic (Const ("all", _) $ _) = true
wenzelm@23356
   331
  | non_atomic _ = false;
wenzelm@23356
   332
wenzelm@54742
   333
fun assume_rule_tac ctxt = norm_hhf_tac ctxt THEN' CSUBGOAL (fn (goal, i) =>
wenzelm@23237
   334
  let
wenzelm@42495
   335
    val ((_, goal'), ctxt') = Variable.focus_cterm goal ctxt;
wenzelm@23237
   336
    val goal'' = Drule.cterm_rule (singleton (Variable.export ctxt' ctxt)) goal';
wenzelm@23356
   337
    val Rs = filter (non_atomic o Thm.term_of) (Drule.strip_imp_prems goal'');
wenzelm@23237
   338
    val tacs = Rs |> map (fn R =>
wenzelm@52732
   339
      etac (Raw_Simplifier.norm_hhf (Thm.trivial R)) THEN_ALL_NEW assume_tac);
wenzelm@23237
   340
  in fold_rev (curry op APPEND') tacs (K no_tac) i end);
wenzelm@23237
   341
wenzelm@32365
   342
wenzelm@52461
   343
wenzelm@52461
   344
(** parallel tacticals **)
wenzelm@32365
   345
wenzelm@52461
   346
(* parallel choice of single results *)
wenzelm@52461
   347
wenzelm@32365
   348
fun PARALLEL_CHOICE tacs st =
wenzelm@32365
   349
  (case Par_List.get_some (fn tac => SINGLE tac st) tacs of
wenzelm@32365
   350
    NONE => Seq.empty
wenzelm@32365
   351
  | SOME st' => Seq.single st');
wenzelm@32365
   352
wenzelm@52461
   353
wenzelm@52461
   354
(* parallel refinement of non-schematic goal by single results *)
wenzelm@52461
   355
wenzelm@52461
   356
local
wenzelm@52461
   357
wenzelm@32788
   358
exception FAILED of unit;
wenzelm@52461
   359
wenzelm@52461
   360
fun retrofit st' =
wenzelm@52461
   361
  rotate_prems ~1 #>
wenzelm@52461
   362
  Thm.bicompose {flatten = false, match = false, incremented = false}
wenzelm@52461
   363
      (false, conclude st', Thm.nprems_of st') 1;
wenzelm@52461
   364
wenzelm@52461
   365
in
wenzelm@52461
   366
wenzelm@42370
   367
fun PARALLEL_GOALS tac =
wenzelm@42370
   368
  Thm.adjust_maxidx_thm ~1 #>
wenzelm@42370
   369
  (fn st =>
wenzelm@42371
   370
    if not (Multithreading.enabled ()) orelse Thm.maxidx_of st >= 0 orelse Thm.nprems_of st <= 1
wenzelm@42370
   371
    then DETERM tac st
wenzelm@42370
   372
    else
wenzelm@42370
   373
      let
wenzelm@42370
   374
        fun try_tac g =
wenzelm@42370
   375
          (case SINGLE tac g of
wenzelm@42370
   376
            NONE => raise FAILED ()
wenzelm@42370
   377
          | SOME g' => g');
wenzelm@32365
   378
wenzelm@42370
   379
        val goals = Drule.strip_imp_prems (Thm.cprop_of st);
wenzelm@42370
   380
        val results = Par_List.map (try_tac o init) goals;
wenzelm@52461
   381
      in EVERY (map retrofit (rev results)) st end
wenzelm@42370
   382
      handle FAILED () => Seq.empty);
wenzelm@32365
   383
wenzelm@18207
   384
end;
wenzelm@18207
   385
wenzelm@52461
   386
end;
wenzelm@52461
   387
wenzelm@32365
   388
structure Basic_Goal: BASIC_GOAL = Goal;
wenzelm@32365
   389
open Basic_Goal;