| author | wenzelm | 
| Wed, 26 Oct 2022 15:02:11 +0200 | |
| changeset 76378 | c0566b6f6ca8 | 
| parent 70521 | 9ddd66d53130 | 
| child 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: 
68130diff
changeset | 17 | val strip_goals: thm -> cterm list option | 
| 
9ddd66d53130
added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
 wenzelm parents: 
68130diff
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: 
68130diff
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: 
68130diff
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: 
68130diff
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: 
68130diff
changeset | 44 | local | 
| 
9ddd66d53130
added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
 wenzelm parents: 
68130diff
changeset | 45 | |
| 
9ddd66d53130
added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
 wenzelm parents: 
68130diff
changeset | 46 | exception FAILED of unit; | 
| 
9ddd66d53130
added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
 wenzelm parents: 
68130diff
changeset | 47 | |
| 
9ddd66d53130
added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
 wenzelm parents: 
68130diff
changeset | 48 | fun retrofit {close} st' =
 | 
| 
9ddd66d53130
added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
 wenzelm parents: 
68130diff
changeset | 49 | rotate_prems ~1 #> | 
| 
9ddd66d53130
added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
 wenzelm parents: 
68130diff
changeset | 50 |   Thm.bicompose NONE {flatten = false, match = false, incremented = false}
 | 
| 
9ddd66d53130
added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
 wenzelm parents: 
68130diff
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: 
68130diff
changeset | 52 | |
| 
9ddd66d53130
added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
 wenzelm parents: 
68130diff
changeset | 53 | in | 
| 
9ddd66d53130
added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
 wenzelm parents: 
68130diff
changeset | 54 | |
| 
9ddd66d53130
added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
 wenzelm parents: 
68130diff
changeset | 55 | fun retrofit_tac close = EVERY o map (retrofit close); | 
| 
9ddd66d53130
added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
 wenzelm parents: 
68130diff
changeset | 56 | |
| 
9ddd66d53130
added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
 wenzelm parents: 
68130diff
changeset | 57 | fun PARALLEL_GOALS tac st = | 
| 
9ddd66d53130
added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
 wenzelm parents: 
68130diff
changeset | 58 | (case strip_goals st of | 
| 
9ddd66d53130
added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
 wenzelm parents: 
68130diff
changeset | 59 | SOME goals => | 
| 
9ddd66d53130
added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
 wenzelm parents: 
68130diff
changeset | 60 | if Future.relevant goals then | 
| 
9ddd66d53130
added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
 wenzelm parents: 
68130diff
changeset | 61 | let | 
| 
9ddd66d53130
added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
 wenzelm parents: 
68130diff
changeset | 62 | fun try_goal g = | 
| 
9ddd66d53130
added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
 wenzelm parents: 
68130diff
changeset | 63 | (case SINGLE tac (Goal.init g) of | 
| 
9ddd66d53130
added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
 wenzelm parents: 
68130diff
changeset | 64 | NONE => raise FAILED () | 
| 
9ddd66d53130
added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
 wenzelm parents: 
68130diff
changeset | 65 | | SOME st' => st'); | 
| 
9ddd66d53130
added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
 wenzelm parents: 
68130diff
changeset | 66 | val results = Par_List.map try_goal goals; | 
| 
9ddd66d53130
added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
 wenzelm parents: 
68130diff
changeset | 67 |         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: 
68130diff
changeset | 68 | else DETERM tac st | 
| 
9ddd66d53130
added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
 wenzelm parents: 
68130diff
changeset | 69 | | NONE => DETERM tac st); | 
| 
9ddd66d53130
added SUBPROOFS / "subproofs" method combinator, for more compact proofterms;
 wenzelm parents: 
68130diff
changeset | 70 | |
| 58009 | 71 | end; | 
| 72 | ||
| 73 | val PARALLEL_ALLGOALS = PARALLEL_GOALS o ALLGOALS; | |
| 74 | ||
| 75 | end; | |
| 76 | ||
| 77 | structure Basic_Par_Tactical: BASIC_PAR_TACTICAL = Par_Tactical; | |
| 78 | open Basic_Par_Tactical; |