author | wenzelm |
Wed, 01 Jul 2015 21:57:21 +0200 | |
changeset 60625 | f64658887a05 |
parent 60623 | be39fe6c5620 |
child 60626 | 9eefb9f39021 |
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 |
60623 | 3 |
Author: Daniel Matichuk, NICTA/UNSW |
20210
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
4 |
|
32281
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
5 |
Tactical operations with explicit subgoal focus, based on canonical |
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
6 |
proof decomposition. The "visible" part of the text within the |
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
7 |
context is fixed, the remaining goal may be schematic. |
60623 | 8 |
|
9 |
Isar subgoal command for proof structure within unstructured proof |
|
10 |
scripts. |
|
20210
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
11 |
*) |
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
12 |
|
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
13 |
signature SUBGOAL = |
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
14 |
sig |
32200
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
15 |
type focus = {context: Proof.context, params: (string * cterm) list, prems: thm list, |
32281
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
16 |
asms: cterm list, concl: cterm, schematics: (ctyp * ctyp) list * (cterm * cterm) list} |
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
17 |
val focus_params: Proof.context -> int -> thm -> focus * thm |
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
18 |
val focus_prems: Proof.context -> int -> thm -> focus * thm |
32200
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
19 |
val focus: Proof.context -> int -> thm -> focus * thm |
32210
a5e9d9f3e5e1
retrofit: actually handle schematic variables -- need to export into original context;
wenzelm
parents:
32200
diff
changeset
|
20 |
val retrofit: Proof.context -> Proof.context -> (string * cterm) list -> cterm list -> |
32200
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
21 |
int -> thm -> thm -> thm Seq.seq |
32281
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
22 |
val FOCUS_PARAMS: (focus -> tactic) -> Proof.context -> int -> tactic |
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
23 |
val FOCUS_PREMS: (focus -> tactic) -> Proof.context -> int -> tactic |
32200
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
24 |
val FOCUS: (focus -> tactic) -> Proof.context -> int -> tactic |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
25 |
val SUBPROOF: (focus -> tactic) -> Proof.context -> int -> tactic |
60623 | 26 |
val subgoal: Attrib.binding -> Attrib.binding option -> (binding * mixfix) list -> |
27 |
Proof.state -> focus * Proof.state |
|
28 |
val subgoal_cmd: Attrib.binding -> Attrib.binding option -> (binding * mixfix) list -> |
|
29 |
Proof.state -> focus * Proof.state |
|
20210
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
30 |
end; |
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
31 |
|
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
32 |
structure Subgoal: SUBGOAL = |
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
33 |
struct |
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
34 |
|
32200
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
35 |
(* focus *) |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
36 |
|
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
37 |
type focus = {context: Proof.context, params: (string * cterm) list, prems: thm list, |
32281
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
38 |
asms: cterm list, concl: cterm, schematics: (ctyp * ctyp) list * (cterm * cterm) list}; |
20210
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
39 |
|
32281
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
40 |
fun gen_focus (do_prems, do_concl) ctxt i raw_st = |
20210
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
41 |
let |
60367 | 42 |
val st = raw_st |
43 |
|> Thm.transfer (Proof_Context.theory_of ctxt) |
|
44 |
|> Simplifier.norm_hhf_protect ctxt; |
|
32281
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
45 |
val ((schematic_types, [st']), ctxt1) = Variable.importT [st] ctxt; |
42495
1af81b70cf09
clarified Variable.focus vs. Variable.focus_cterm -- eliminated clone;
wenzelm
parents:
42360
diff
changeset
|
46 |
val ((params, goal), ctxt2) = Variable.focus_cterm (Thm.cprem_of st' i) ctxt1; |
32281
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
47 |
|
32213
f1b166317ae2
added focus_params/FOCUS_PARAMS, which focus on the parameter prefix only;
wenzelm
parents:
32210
diff
changeset
|
48 |
val (asms, concl) = |
32281
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
49 |
if do_prems then (Drule.strip_imp_prems goal, Drule.strip_imp_concl goal) |
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
50 |
else ([], goal); |
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
51 |
val text = asms @ (if do_concl then [concl] else []); |
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
52 |
|
60367 | 53 |
val (inst, ctxt3) = Variable.import_inst true (map Thm.term_of text) ctxt2; |
54 |
val (_, schematic_terms) = Thm.certify_inst ctxt3 inst; |
|
32281
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
55 |
|
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
56 |
val schematics = (schematic_types, schematic_terms); |
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
57 |
val asms' = map (Thm.instantiate_cterm schematics) asms; |
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
58 |
val concl' = Thm.instantiate_cterm schematics concl; |
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
59 |
val (prems, context) = Assumption.add_assumes asms' ctxt3; |
20210
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
60 |
in |
32200
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
61 |
({context = context, params = params, prems = prems, |
32281
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
62 |
asms = asms', concl = concl', schematics = schematics}, Goal.init concl') |
20210
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
63 |
end; |
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
64 |
|
32281
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
65 |
val focus_params = gen_focus (false, false); |
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
66 |
val focus_prems = gen_focus (true, false); |
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
67 |
val focus = gen_focus (true, true); |
32213
f1b166317ae2
added focus_params/FOCUS_PARAMS, which focus on the parameter prefix only;
wenzelm
parents:
32210
diff
changeset
|
68 |
|
32200
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 |
(* lift and retrofit *) |
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 |
(* |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
73 |
B [?'b, ?y] |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
74 |
---------------- |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
75 |
B ['b, y params] |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
76 |
*) |
32284
d8ee8a956f19
retrofit: more precise handling of locally introduced schematic variables (avoid zero_var_indexes);
wenzelm
parents:
32283
diff
changeset
|
77 |
fun lift_import idx params th ctxt = |
32200
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
78 |
let |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
79 |
val ((_, [th']), ctxt') = Variable.importT [th] ctxt; |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
80 |
|
59586 | 81 |
val Ts = map Thm.typ_of_cterm params; |
32200
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
82 |
val ts = map Thm.term_of params; |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
83 |
|
32281
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
84 |
val prop = Thm.full_prop_of th'; |
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
85 |
val concl_vars = Term.add_vars (Logic.strip_imp_concl prop) []; |
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
86 |
val vars = rev (Term.add_vars prop []); |
32200
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
87 |
val (ys, ctxt'') = Variable.variant_fixes (map (Name.clean o #1 o #1) vars) ctxt'; |
32284
d8ee8a956f19
retrofit: more precise handling of locally introduced schematic variables (avoid zero_var_indexes);
wenzelm
parents:
32283
diff
changeset
|
88 |
|
d8ee8a956f19
retrofit: more precise handling of locally introduced schematic variables (avoid zero_var_indexes);
wenzelm
parents:
32283
diff
changeset
|
89 |
fun var_inst v y = |
d8ee8a956f19
retrofit: more precise handling of locally introduced schematic variables (avoid zero_var_indexes);
wenzelm
parents:
32283
diff
changeset
|
90 |
let |
d8ee8a956f19
retrofit: more precise handling of locally introduced schematic variables (avoid zero_var_indexes);
wenzelm
parents:
32283
diff
changeset
|
91 |
val ((x, i), T) = v; |
d8ee8a956f19
retrofit: more precise handling of locally introduced schematic variables (avoid zero_var_indexes);
wenzelm
parents:
32283
diff
changeset
|
92 |
val (U, args) = |
d8ee8a956f19
retrofit: more precise handling of locally introduced schematic variables (avoid zero_var_indexes);
wenzelm
parents:
32283
diff
changeset
|
93 |
if member (op =) concl_vars v then (T, []) |
d8ee8a956f19
retrofit: more precise handling of locally introduced schematic variables (avoid zero_var_indexes);
wenzelm
parents:
32283
diff
changeset
|
94 |
else (Ts ---> T, ts); |
d8ee8a956f19
retrofit: more precise handling of locally introduced schematic variables (avoid zero_var_indexes);
wenzelm
parents:
32283
diff
changeset
|
95 |
val u = Free (y, U); |
d8ee8a956f19
retrofit: more precise handling of locally introduced schematic variables (avoid zero_var_indexes);
wenzelm
parents:
32283
diff
changeset
|
96 |
in ((Var v, list_comb (u, args)), (u, Var ((x, i + idx), U))) end; |
59616 | 97 |
val (inst1, inst2) = |
59621
291934bac95e
Thm.cterm_of and Thm.ctyp_of operate on local context;
wenzelm
parents:
59616
diff
changeset
|
98 |
split_list (map (apply2 (apply2 (Thm.cterm_of ctxt))) (map2 var_inst vars ys)); |
32284
d8ee8a956f19
retrofit: more precise handling of locally introduced schematic variables (avoid zero_var_indexes);
wenzelm
parents:
32283
diff
changeset
|
99 |
|
d8ee8a956f19
retrofit: more precise handling of locally introduced schematic variables (avoid zero_var_indexes);
wenzelm
parents:
32283
diff
changeset
|
100 |
val th'' = Thm.instantiate ([], inst1) th'; |
d8ee8a956f19
retrofit: more precise handling of locally introduced schematic variables (avoid zero_var_indexes);
wenzelm
parents:
32283
diff
changeset
|
101 |
in ((inst2, th''), ctxt'') end; |
32200
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
102 |
|
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
103 |
(* |
32281
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
104 |
[x, A x] |
32200
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
105 |
: |
32281
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
106 |
B x ==> C |
32200
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
107 |
------------------ |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
108 |
[!!x. A x ==> B x] |
32281
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
109 |
: |
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
110 |
C |
32200
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
111 |
*) |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
112 |
fun lift_subgoals params asms th = |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
113 |
let |
32329 | 114 |
fun lift ct = fold_rev Thm.all_name params (Drule.list_implies (asms, ct)); |
32200
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
115 |
val unlift = |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
116 |
fold (Thm.elim_implies o Thm.assume) asms o |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
117 |
Drule.forall_elim_list (map #2 params) o Thm.assume; |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
118 |
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
|
119 |
val th' = fold (Thm.elim_implies o unlift) subgoals th; |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
120 |
in (subgoals, th') end; |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
121 |
|
32213
f1b166317ae2
added focus_params/FOCUS_PARAMS, which focus on the parameter prefix only;
wenzelm
parents:
32210
diff
changeset
|
122 |
fun retrofit ctxt1 ctxt0 params asms i st1 st0 = |
32200
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
123 |
let |
32284
d8ee8a956f19
retrofit: more precise handling of locally introduced schematic variables (avoid zero_var_indexes);
wenzelm
parents:
32283
diff
changeset
|
124 |
val idx = Thm.maxidx_of st0 + 1; |
32200
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
125 |
val ps = map #2 params; |
32284
d8ee8a956f19
retrofit: more precise handling of locally introduced schematic variables (avoid zero_var_indexes);
wenzelm
parents:
32283
diff
changeset
|
126 |
val ((subgoal_inst, st2), ctxt2) = lift_import idx ps st1 ctxt1; |
32213
f1b166317ae2
added focus_params/FOCUS_PARAMS, which focus on the parameter prefix only;
wenzelm
parents:
32210
diff
changeset
|
127 |
val (subgoals, st3) = lift_subgoals params asms st2; |
f1b166317ae2
added focus_params/FOCUS_PARAMS, which focus on the parameter prefix only;
wenzelm
parents:
32210
diff
changeset
|
128 |
val result = st3 |
f1b166317ae2
added focus_params/FOCUS_PARAMS, which focus on the parameter prefix only;
wenzelm
parents:
32210
diff
changeset
|
129 |
|> Goal.conclude |
32200
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
130 |
|> Drule.implies_intr_list asms |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
131 |
|> Drule.forall_intr_list ps |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
132 |
|> Drule.implies_intr_list subgoals |
32284
d8ee8a956f19
retrofit: more precise handling of locally introduced schematic variables (avoid zero_var_indexes);
wenzelm
parents:
32283
diff
changeset
|
133 |
|> fold_rev (Thm.forall_intr o #1) subgoal_inst |
d8ee8a956f19
retrofit: more precise handling of locally introduced schematic variables (avoid zero_var_indexes);
wenzelm
parents:
32283
diff
changeset
|
134 |
|> fold (Thm.forall_elim o #2) subgoal_inst |
d8ee8a956f19
retrofit: more precise handling of locally introduced schematic variables (avoid zero_var_indexes);
wenzelm
parents:
32283
diff
changeset
|
135 |
|> Thm.adjust_maxidx_thm idx |
d8ee8a956f19
retrofit: more precise handling of locally introduced schematic variables (avoid zero_var_indexes);
wenzelm
parents:
32283
diff
changeset
|
136 |
|> singleton (Variable.export ctxt2 ctxt0); |
52223
5bb6ae8acb87
tuned signature -- more explicit flags for low-level Thm.bicompose;
wenzelm
parents:
49845
diff
changeset
|
137 |
in |
58950
d07464875dd4
optional proof context for unify operations, for the sake of proper local options;
wenzelm
parents:
54883
diff
changeset
|
138 |
Thm.bicompose (SOME ctxt0) {flatten = true, match = false, incremented = false} |
52223
5bb6ae8acb87
tuned signature -- more explicit flags for low-level Thm.bicompose;
wenzelm
parents:
49845
diff
changeset
|
139 |
(false, result, Thm.nprems_of st1) i st0 |
5bb6ae8acb87
tuned signature -- more explicit flags for low-level Thm.bicompose;
wenzelm
parents:
49845
diff
changeset
|
140 |
end; |
32200
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
141 |
|
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
142 |
|
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
143 |
(* tacticals *) |
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
144 |
|
32281
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
145 |
fun GEN_FOCUS flags tac ctxt i st = |
20210
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
146 |
if Thm.nprems_of st < i then Seq.empty |
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
147 |
else |
32329 | 148 |
let val (args as {context = ctxt', params, asms, ...}, st') = gen_focus flags ctxt i st; |
149 |
in Seq.lifts (retrofit ctxt' ctxt params asms i) (tac args st') st end; |
|
32200
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
150 |
|
32281
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
151 |
val FOCUS_PARAMS = GEN_FOCUS (false, false); |
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
152 |
val FOCUS_PREMS = GEN_FOCUS (true, false); |
750101435f60
focus: more precise treatment of schematic variables, only the "visible" part of the text is fixed;
wenzelm
parents:
32213
diff
changeset
|
153 |
val FOCUS = GEN_FOCUS (true, true); |
32213
f1b166317ae2
added focus_params/FOCUS_PARAMS, which focus on the parameter prefix only;
wenzelm
parents:
32210
diff
changeset
|
154 |
|
49845 | 155 |
fun SUBPROOF tac ctxt = FOCUS (Seq.map (Goal.check_finished ctxt) oo tac) ctxt; |
20210
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
156 |
|
60623 | 157 |
|
158 |
(* Isar subgoal command *) |
|
159 |
||
160 |
local |
|
161 |
||
162 |
fun gen_focus prep_atts raw_result_binding raw_prems_binding params state = |
|
163 |
let |
|
164 |
val _ = Proof.assert_backward state; |
|
165 |
val {context = ctxt, facts = facts, goal = st} = Proof.raw_goal state; |
|
166 |
||
167 |
val result_binding = apsnd (map (prep_atts ctxt)) raw_result_binding; |
|
168 |
val (prems_binding, do_prems) = |
|
169 |
(case raw_prems_binding of |
|
170 |
SOME (b, raw_atts) => ((b, map (prep_atts ctxt) raw_atts), true) |
|
171 |
| NONE => ((Binding.empty, []), false)); |
|
172 |
||
173 |
fun check_param (b, mx) = ignore (Proof_Context.cert_var (b, NONE, mx) ctxt); |
|
174 |
val _ = List.app check_param params; |
|
175 |
||
176 |
val _ = if Thm.no_prems st then error "No subgoals!" else (); |
|
177 |
val subgoal_focus = #1 (focus ctxt 1 st); (* FIXME clarify prems/params *) |
|
178 |
||
179 |
fun after_qed (ctxt'', [[result]]) = |
|
180 |
Proof.end_block #> (fn state' => |
|
181 |
let |
|
182 |
val ctxt' = Proof.context_of state'; |
|
183 |
val results' = |
|
184 |
Proof_Context.export ctxt'' ctxt' (Conjunction.elim_conjunctions result); |
|
185 |
in |
|
186 |
state' |
|
187 |
|> Proof.refine_primitive (fn _ => fn _ => |
|
188 |
retrofit ctxt'' ctxt' (#params subgoal_focus) (#asms subgoal_focus) 1 |
|
189 |
(Goal.protect 0 result) st |
|
190 |
|> Seq.hd) |
|
191 |
|> Proof.map_context |
|
192 |
(#2 o Proof_Context.note_thmss "" [(result_binding, [(results', [])])]) |
|
60625 | 193 |
end) |
194 |
#> Proof.reset_facts |
|
195 |
#> Proof.enter_backward; |
|
60623 | 196 |
in |
197 |
state |
|
198 |
|> Proof.enter_forward |
|
199 |
|> Proof.using_facts [] |
|
200 |
|> Proof.begin_block |
|
201 |
|> Proof.map_context (fn _ => |
|
202 |
#context subgoal_focus |
|
203 |
|> Proof_Context.note_thmss "" [(prems_binding, [(#prems subgoal_focus, [])])] |> #2) |
|
204 |
|> Proof.internal_goal (K (K ())) (Proof_Context.get_mode ctxt) true "subgoal" |
|
205 |
NONE after_qed [] [] [(Thm.empty_binding, [(Thm.term_of (#concl subgoal_focus), [])])] |> #2 |
|
206 |
|> Proof.using_facts facts |
|
207 |
|> pair subgoal_focus |
|
208 |
end; |
|
209 |
||
210 |
in |
|
211 |
||
212 |
val subgoal = gen_focus Attrib.attribute; |
|
213 |
val subgoal_cmd = gen_focus Attrib.attribute_cmd; |
|
214 |
||
215 |
end; |
|
216 |
||
20210
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
217 |
end; |
8fe4ae4360eb
Tactical operations depending on local subgoal structure.
wenzelm
parents:
diff
changeset
|
218 |
|
32200
2bd8ab91a426
advanced retrofit, which allows new subgoals and variables;
wenzelm
parents:
31794
diff
changeset
|
219 |
val SUBPROOF = Subgoal.SUBPROOF; |