18 val init: cterm -> thm |
18 val init: cterm -> thm |
19 val protect: thm -> thm |
19 val protect: thm -> thm |
20 val conclude: thm -> thm |
20 val conclude: thm -> thm |
21 val finish: thm -> thm |
21 val finish: thm -> thm |
22 val norm_result: thm -> thm |
22 val norm_result: thm -> thm |
|
23 val promise_result: Proof.context -> (unit -> thm) -> term -> thm |
23 val prove_internal: cterm list -> cterm -> (thm list -> tactic) -> thm |
24 val prove_internal: cterm list -> cterm -> (thm list -> tactic) -> thm |
24 val prove_multi: Proof.context -> string list -> term list -> term list -> |
25 val prove_multi: Proof.context -> string list -> term list -> term list -> |
25 ({prems: thm list, context: Proof.context} -> tactic) -> thm list |
26 ({prems: thm list, context: Proof.context} -> tactic) -> thm list |
|
27 val prove_promise: Proof.context -> string list -> term list -> term -> |
|
28 ({prems: thm list, context: Proof.context} -> tactic) -> thm |
26 val prove: Proof.context -> string list -> term list -> term -> |
29 val prove: Proof.context -> string list -> term list -> term -> |
27 ({prems: thm list, context: Proof.context} -> tactic) -> thm |
30 ({prems: thm list, context: Proof.context} -> tactic) -> thm |
28 val prove_global: theory -> string list -> term list -> term -> |
31 val prove_global: theory -> string list -> term list -> term -> |
29 ({prems: thm list, context: Proof.context} -> tactic) -> thm |
32 ({prems: thm list, context: Proof.context} -> tactic) -> thm |
30 val extract: int -> int -> thm -> thm Seq.seq |
33 val extract: int -> int -> thm -> thm Seq.seq |
82 |
85 |
83 |
86 |
84 |
87 |
85 (** results **) |
88 (** results **) |
86 |
89 |
|
90 (* normal form *) |
|
91 |
87 val norm_result = |
92 val norm_result = |
88 Drule.flexflex_unique |
93 Drule.flexflex_unique |
89 #> MetaSimplifier.norm_hhf_protect |
94 #> MetaSimplifier.norm_hhf_protect |
90 #> Thm.strip_shyps |
95 #> Thm.strip_shyps |
91 #> Drule.zero_var_indexes; |
96 #> Drule.zero_var_indexes; |
92 |
97 |
93 |
98 |
|
99 (* promise *) |
|
100 |
|
101 fun promise_result ctxt result prop = |
|
102 let |
|
103 val thy = ProofContext.theory_of ctxt; |
|
104 val _ = Context.reject_draft thy; |
|
105 val cert = Thm.cterm_of thy; |
|
106 val certT = Thm.ctyp_of thy; |
|
107 |
|
108 val assms = Assumption.assms_of ctxt; |
|
109 val As = map Thm.term_of assms; |
|
110 |
|
111 val xs = map Free (fold Term.add_frees (prop :: As) []); |
|
112 val fixes = map cert xs; |
|
113 |
|
114 val tfrees = fold Term.add_tfrees (prop :: As) []; |
|
115 val instT = map (fn (a, S) => (certT (TVar ((a, 0), S)), certT (TFree (a, S)))) tfrees; |
|
116 |
|
117 val global_prop = |
|
118 Term.map_types Logic.varifyT (fold_rev Logic.all xs (Logic.list_implies (As, prop))); |
|
119 val global_result = |
|
120 Thm.generalize (map #1 tfrees, []) 0 o |
|
121 Drule.forall_intr_list fixes o |
|
122 Drule.implies_intr_list assms o |
|
123 Thm.adjust_maxidx_thm ~1 o result; |
|
124 val local_result = |
|
125 Thm.promise (Future.fork_irrelevant global_result) (cert global_prop) |
|
126 |> Thm.instantiate (instT, []) |
|
127 |> Drule.forall_elim_list fixes |
|
128 |> fold (Thm.elim_implies o Thm.assume) assms; |
|
129 in local_result end; |
|
130 |
|
131 |
94 |
132 |
95 (** tactical theorem proving **) |
133 (** tactical theorem proving **) |
96 |
134 |
97 (* prove_internal -- minimal checks, no normalization of result! *) |
135 (* prove_internal -- minimal checks, no normalization of result! *) |
98 |
136 |
100 (case SINGLE (tac (map Assumption.assume casms)) (init cprop) of |
138 (case SINGLE (tac (map Assumption.assume casms)) (init cprop) of |
101 SOME th => Drule.implies_intr_list casms (finish th) |
139 SOME th => Drule.implies_intr_list casms (finish th) |
102 | NONE => error "Tactic failed."); |
140 | NONE => error "Tactic failed."); |
103 |
141 |
104 |
142 |
105 (* prove_multi *) |
143 (* prove_common etc. *) |
106 |
144 |
107 fun prove_multi ctxt xs asms props tac = |
145 fun prove_common immediate ctxt xs asms props tac = |
108 let |
146 let |
109 val thy = ProofContext.theory_of ctxt; |
147 val thy = ProofContext.theory_of ctxt; |
110 val string_of_term = Syntax.string_of_term ctxt; |
148 val string_of_term = Syntax.string_of_term ctxt; |
111 |
149 |
112 fun err msg = cat_error msg |
150 fun err msg = cat_error msg |
122 |> Variable.add_fixes_direct xs |
160 |> Variable.add_fixes_direct xs |
123 |> fold Variable.declare_term (asms @ props) |
161 |> fold Variable.declare_term (asms @ props) |
124 |> Assumption.add_assumes casms |
162 |> Assumption.add_assumes casms |
125 ||> Variable.set_body true; |
163 ||> Variable.set_body true; |
126 |
164 |
127 val goal = init (Conjunction.mk_conjunction_balanced cprops); |
165 val stmt = Conjunction.mk_conjunction_balanced cprops; |
|
166 |
|
167 fun result () = |
|
168 (case SINGLE (tac {prems = prems, context = ctxt'}) (init stmt) of |
|
169 NONE => err "Tactic failed." |
|
170 | SOME st => |
|
171 let val res = finish st handle THM (msg, _, _) => err msg in |
|
172 if Unify.matches_list thy [Thm.term_of stmt] [Thm.prop_of res] then res |
|
173 else err ("Proved a different theorem: " ^ string_of_term (Thm.prop_of res)) |
|
174 end); |
128 val res = |
175 val res = |
129 (case SINGLE (tac {prems = prems, context = ctxt'}) goal of |
176 if immediate orelse #maxidx (Thm.rep_cterm stmt) >= 0 then result () |
130 NONE => err "Tactic failed." |
177 else promise_result ctxt result (Thm.term_of stmt); |
131 | SOME res => res); |
|
132 val results = Conjunction.elim_balanced (length props) (finish res) |
|
133 handle THM (msg, _, _) => err msg; |
|
134 val _ = Unify.matches_list thy (map Thm.term_of cprops) (map Thm.prop_of results) |
|
135 orelse err ("Proved a different theorem: " ^ string_of_term (Thm.prop_of res)); |
|
136 in |
178 in |
137 results |
179 Conjunction.elim_balanced (length props) res |
138 |> map (Assumption.export false ctxt' ctxt) |
180 |> map (Assumption.export false ctxt' ctxt) |
139 |> Variable.export ctxt' ctxt |
181 |> Variable.export ctxt' ctxt |
140 |> map Drule.zero_var_indexes |
182 |> map Drule.zero_var_indexes |
141 end; |
183 end; |
142 |
184 |
143 |
185 val prove_multi = prove_common false; |
144 (* prove *) |
186 |
145 |
187 fun prove_promise ctxt xs asms prop tac = hd (prove_common false ctxt xs asms [prop] tac); |
146 fun prove ctxt xs asms prop tac = hd (prove_multi ctxt xs asms [prop] tac); |
188 fun prove ctxt xs asms prop tac = hd (prove_common true ctxt xs asms [prop] tac); |
147 |
189 |
148 fun prove_global thy xs asms prop tac = |
190 fun prove_global thy xs asms prop tac = |
149 Drule.standard (prove (ProofContext.init thy) xs asms prop tac); |
191 Drule.standard (prove (ProofContext.init thy) xs asms prop tac); |
150 |
192 |
151 |
193 |