author | wenzelm |
Mon, 11 Dec 2023 11:46:12 +0100 | |
changeset 79237 | f97fe7ad62a7 |
parent 77908 | a6bd716a6124 |
permissions | -rw-r--r-- |
58009 | 1 |
(* Title: Pure/par_tactical.ML |
2 |
Author: Makarius |
|
3 |
||
4 |
Parallel tacticals. |
|
5 |
*) |
|
6 |
||
7 |
signature BASIC_PAR_TACTICAL = |
|
8 |
sig |
|
9 |
val PARALLEL_CHOICE: tactic list -> tactic |
|
10 |
val PARALLEL_GOALS: tactic -> tactic |
|
11 |
val PARALLEL_ALLGOALS: (int -> tactic) -> tactic |
|
12 |
end; |
|
13 |
||
14 |
signature PAR_TACTICAL = |
|
15 |
sig |
|
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 | 19 |
end; |
20 |
||
21 |
structure Par_Tactical: PAR_TACTICAL = |
|
22 |
struct |
|
23 |
||
24 |
(* parallel choice of single results *) |
|
25 |
||
26 |
fun PARALLEL_CHOICE tacs st = |
|
27 |
(case Par_List.get_some (fn tac => SINGLE tac st) tacs of |
|
28 |
NONE => Seq.empty |
|
29 |
| SOME st' => Seq.single st'); |
|
30 |
||
31 |
||
32 |
(* parallel refinement of non-schematic goal by single results *) |
|
33 |
||
70521
9ddd66d53130
added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
wenzelm
parents:
68130
diff
changeset
|
34 |
fun strip_goals st = |
67660 | 35 |
let |
36 |
val goals = |
|
37 |
Drule.strip_imp_prems (Thm.cprop_of st) |
|
38 |
|> map (Thm.adjust_maxidx_cterm ~1); |
|
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 | 42 |
end; |
58009 | 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 | 68 |
end; |
69 |
||
70 |
val PARALLEL_ALLGOALS = PARALLEL_GOALS o ALLGOALS; |
|
71 |
||
72 |
end; |
|
73 |
||
74 |
structure Basic_Par_Tactical: BASIC_PAR_TACTICAL = Par_Tactical; |
|
75 |
open Basic_Par_Tactical; |