author | wenzelm |
Sun, 26 Jul 2009 13:12:54 +0200 | |
changeset 32200 | 2bd8ab91a426 |
parent 31794 | 71af1fd6a5e4 |
child 32210 | a5e9d9f3e5e1 |
permissions | -rw-r--r-- |
20210
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
1 |
(* Title: Pure/subgoal.ML |
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
2 |
Author: Makarius |
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
3 |
|
32200
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
4 |
Tactical operations with explicit subgoal focus, based on |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
5 |
canonical proof decomposition (similar to fix/assume/show). |
20210
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
6 |
*) |
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
7 |
|
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
8 |
signature SUBGOAL = |
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
9 |
sig |
32200
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
10 |
type focus = {context: Proof.context, params: (string * cterm) list, prems: thm list, |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
11 |
asms: cterm list, concl: cterm, schematics: ctyp list * cterm list} |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
12 |
val focus: Proof.context -> int -> thm -> focus * thm |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
13 |
val retrofit: Proof.context -> (string * cterm) list -> cterm list -> |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
14 |
int -> thm -> thm -> thm Seq.seq |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
15 |
val FOCUS: (focus -> tactic) -> Proof.context -> int -> tactic |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
16 |
val SUBPROOF: (focus -> tactic) -> Proof.context -> int -> tactic |
20210
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
17 |
end; |
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
18 |
|
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
19 |
structure Subgoal: SUBGOAL = |
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
20 |
struct |
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
21 |
|
32200
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
22 |
(* focus *) |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
23 |
|
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
24 |
type focus = {context: Proof.context, params: (string * cterm) list, prems: thm list, |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
25 |
asms: cterm list, concl: cterm, schematics: ctyp list * cterm list}; |
20210
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
26 |
|
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
27 |
fun focus ctxt i st = |
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
28 |
let |
21605 | 29 |
val ((schematics, [st']), ctxt') = |
31794
71af1fd6a5e4
renamed Variable.import_thms to Variable.import (back again cf. ed7aa5a350ef -- Alice is no longer supported);
wenzelm
parents:
30552
diff
changeset
|
30 |
Variable.import true [Simplifier.norm_hhf_protect st] ctxt; |
20301 | 31 |
val ((params, goal), ctxt'') = Variable.focus_subgoal i st' ctxt'; |
20210
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
32 |
val asms = Drule.strip_imp_prems goal; |
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
33 |
val concl = Drule.strip_imp_concl goal; |
20231 | 34 |
val (prems, context) = Assumption.add_assumes asms ctxt''; |
20210
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
35 |
in |
32200
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
36 |
({context = context, params = params, prems = prems, |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
37 |
asms = asms, concl = concl, schematics = schematics}, Goal.init concl) |
20210
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
38 |
end; |
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
39 |
|
32200
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
40 |
|
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
41 |
(* lift and retrofit *) |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
42 |
|
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
43 |
(* |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
44 |
B [?'b, ?y] |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
45 |
---------------- |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
46 |
B ['b, y params] |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
47 |
*) |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
48 |
fun lift_import params th ctxt = |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
49 |
let |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
50 |
val cert = Thm.cterm_of (Thm.theory_of_thm th); |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
51 |
val ((_, [th']), ctxt') = Variable.importT [th] ctxt; |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
52 |
|
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
53 |
val Ts = map (#T o Thm.rep_cterm) params; |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
54 |
val ts = map Thm.term_of params; |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
55 |
|
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
56 |
val vars = rev (Term.add_vars (Thm.full_prop_of th') []); |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
57 |
val (ys, ctxt'') = Variable.variant_fixes (map (Name.clean o #1 o #1) vars) ctxt'; |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
58 |
fun var_inst (v as (_, T)) y = |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
59 |
(cert (Var v), cert (list_comb (Free (y, Ts ---> T), ts))); |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
60 |
val th'' = Thm.instantiate ([], map2 var_inst vars ys) th'; |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
61 |
in (th'', ctxt'') end; |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
62 |
|
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
63 |
(* |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
64 |
[A x] |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
65 |
: |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
66 |
B x ==> C |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
67 |
------------------ |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
68 |
[!!x. A x ==> B x] |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
69 |
: |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
70 |
C |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
71 |
*) |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
72 |
fun lift_subgoals params asms th = |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
73 |
let |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
74 |
val lift = fold_rev Thm.all_name params o curry Drule.list_implies asms; |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
75 |
val unlift = |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
76 |
fold (Thm.elim_implies o Thm.assume) asms o |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
77 |
Drule.forall_elim_list (map #2 params) o Thm.assume; |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
78 |
val subgoals = map lift (Drule.strip_imp_prems (Thm.cprop_of th)); |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
79 |
val th' = fold (Thm.elim_implies o unlift) subgoals th; |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
80 |
in (subgoals, th') end; |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
81 |
|
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
82 |
fun retrofit ctxt params asms i th = |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
83 |
let |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
84 |
val ps = map #2 params; |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
85 |
val res0 = Goal.conclude th; |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
86 |
val (res1, ctxt1) = lift_import ps res0 ctxt; |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
87 |
val (subgoals, res2) = lift_subgoals params asms res1; |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
88 |
val result = res2 |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
89 |
|> Drule.implies_intr_list asms |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
90 |
|> Drule.forall_intr_list ps |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
91 |
|> Drule.implies_intr_list subgoals |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
92 |
|> singleton (Variable.export ctxt1 ctxt); |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
93 |
in Thm.compose_no_flatten false (result, Thm.nprems_of res0) i end; |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
94 |
|
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
95 |
|
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
96 |
(* tacticals *) |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
97 |
|
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
98 |
fun FOCUS tac ctxt i st = |
20210
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
99 |
if Thm.nprems_of st < i then Seq.empty |
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
100 |
else |
32200
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
101 |
let val (args as {context, params, asms, ...}, st') = focus ctxt i st; |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
102 |
in Seq.lifts (retrofit context params asms i) (tac args st') st end; |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
103 |
|
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
104 |
fun SUBPROOF tac = FOCUS (FILTER Thm.no_prems o tac); |
20210
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
105 |
|
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
106 |
end; |
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
107 |
|
32200
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
108 |
val FOCUS = Subgoal.FOCUS; |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
109 |
val SUBPROOF = Subgoal.SUBPROOF; |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
110 |