src/Pure/par_tactical.ML
author wenzelm
Mon, 11 Dec 2023 11:46:12 +0100
changeset 79237 f97fe7ad62a7
parent 77908 a6bd716a6124
permissions -rw-r--r--
proper ZTerm.lift_proof (amending 4a1a25bdf81d);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
58009
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/par_tactical.ML
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
     3
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
     4
Parallel tacticals.
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
     5
*)
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
     6
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
     7
signature BASIC_PAR_TACTICAL =
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
     8
sig
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
     9
  val PARALLEL_CHOICE: tactic list -> tactic
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    10
  val PARALLEL_GOALS: tactic -> tactic
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    11
  val PARALLEL_ALLGOALS: (int -> tactic) -> tactic
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    12
end;
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    13
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    14
signature PAR_TACTICAL =
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    15
sig
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    16
  include BASIC_PAR_TACTICAL
70521
9ddd66d53130 added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
wenzelm
parents: 68130
diff changeset
    17
  val strip_goals: thm -> cterm list option
9ddd66d53130 added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
wenzelm
parents: 68130
diff changeset
    18
  val retrofit_tac: {close: bool} -> thm list -> tactic
58009
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    19
end;
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    20
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    21
structure Par_Tactical: PAR_TACTICAL =
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    22
struct
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    23
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    24
(* parallel choice of single results *)
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    25
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    26
fun PARALLEL_CHOICE tacs st =
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    27
  (case Par_List.get_some (fn tac => SINGLE tac st) tacs of
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    28
    NONE => Seq.empty
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    29
  | SOME st' => Seq.single st');
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    30
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    31
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    32
(* parallel refinement of non-schematic goal by single results *)
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    33
70521
9ddd66d53130 added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
wenzelm
parents: 68130
diff changeset
    34
fun strip_goals st =
67660
0cae317eda7b misc tuning and clarification;
wenzelm
parents: 60372
diff changeset
    35
  let
0cae317eda7b misc tuning and clarification;
wenzelm
parents: 60372
diff changeset
    36
    val goals =
0cae317eda7b misc tuning and clarification;
wenzelm
parents: 60372
diff changeset
    37
      Drule.strip_imp_prems (Thm.cprop_of st)
0cae317eda7b misc tuning and clarification;
wenzelm
parents: 60372
diff changeset
    38
      |> map (Thm.adjust_maxidx_cterm ~1);
0cae317eda7b misc tuning and clarification;
wenzelm
parents: 60372
diff changeset
    39
  in
70521
9ddd66d53130 added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
wenzelm
parents: 68130
diff changeset
    40
    if not (null goals) andalso forall (fn g => Thm.maxidx_of_cterm g = ~1) goals
9ddd66d53130 added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
wenzelm
parents: 68130
diff changeset
    41
    then SOME goals else NONE
67660
0cae317eda7b misc tuning and clarification;
wenzelm
parents: 60372
diff changeset
    42
  end;
58009
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    43
70521
9ddd66d53130 added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
wenzelm
parents: 68130
diff changeset
    44
local
9ddd66d53130 added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
wenzelm
parents: 68130
diff changeset
    45
9ddd66d53130 added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
wenzelm
parents: 68130
diff changeset
    46
exception FAILED of unit;
9ddd66d53130 added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
wenzelm
parents: 68130
diff changeset
    47
9ddd66d53130 added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
wenzelm
parents: 68130
diff changeset
    48
fun retrofit {close} st' =
9ddd66d53130 added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
wenzelm
parents: 68130
diff changeset
    49
  rotate_prems ~1 #>
9ddd66d53130 added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
wenzelm
parents: 68130
diff changeset
    50
  Thm.bicompose NONE {flatten = false, match = false, incremented = false}
9ddd66d53130 added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
wenzelm
parents: 68130
diff changeset
    51
      (false, Goal.conclude st' |> close ? Thm.close_derivation \<^here>, Thm.nprems_of st') 1;
9ddd66d53130 added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
wenzelm
parents: 68130
diff changeset
    52
9ddd66d53130 added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
wenzelm
parents: 68130
diff changeset
    53
in
9ddd66d53130 added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
wenzelm
parents: 68130
diff changeset
    54
9ddd66d53130 added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
wenzelm
parents: 68130
diff changeset
    55
fun retrofit_tac close = EVERY o map (retrofit close);
9ddd66d53130 added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
wenzelm
parents: 68130
diff changeset
    56
9ddd66d53130 added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
wenzelm
parents: 68130
diff changeset
    57
fun PARALLEL_GOALS tac st =
9ddd66d53130 added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
wenzelm
parents: 68130
diff changeset
    58
  (case strip_goals st of
9ddd66d53130 added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
wenzelm
parents: 68130
diff changeset
    59
    SOME goals =>
9ddd66d53130 added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
wenzelm
parents: 68130
diff changeset
    60
      if Future.relevant goals then
9ddd66d53130 added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
wenzelm
parents: 68130
diff changeset
    61
        let
77908
a6bd716a6124 tuned: concise combinators instead of bulky case-expressions;
wenzelm
parents: 70521
diff changeset
    62
          fun try_goal g = SINGLE tac (Goal.init g) |> \<^if_none>\<open>raise FAILED ()\<close>;
70521
9ddd66d53130 added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
wenzelm
parents: 68130
diff changeset
    63
          val results = Par_List.map try_goal goals;
9ddd66d53130 added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
wenzelm
parents: 68130
diff changeset
    64
        in retrofit_tac {close = false} (rev results) st end handle FAILED () => Seq.empty
9ddd66d53130 added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
wenzelm
parents: 68130
diff changeset
    65
      else DETERM tac st
9ddd66d53130 added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
wenzelm
parents: 68130
diff changeset
    66
  | NONE => DETERM tac st);
9ddd66d53130 added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
wenzelm
parents: 68130
diff changeset
    67
58009
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    68
end;
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    69
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    70
val PARALLEL_ALLGOALS = PARALLEL_GOALS o ALLGOALS;
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    71
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    72
end;
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    73
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    74
structure Basic_Par_Tactical: BASIC_PAR_TACTICAL = Par_Tactical;
987c848d509b clarified modules;
wenzelm
parents:
diff changeset
    75
open Basic_Par_Tactical;