127 val asms = map fst (Attrib.map_specs (map (prep_att ctxt)) raw_asms) ~~ proppss; |
127 val asms = map fst (Attrib.map_specs (map (prep_att ctxt)) raw_asms) ~~ proppss; |
128 |
128 |
129 (*obtain parms*) |
129 (*obtain parms*) |
130 val (Ts, parms_ctxt) = fold_map Proof_Context.inferred_param xs' asms_ctxt; |
130 val (Ts, parms_ctxt) = fold_map Proof_Context.inferred_param xs' asms_ctxt; |
131 val parms = map Free (xs' ~~ Ts); |
131 val parms = map Free (xs' ~~ Ts); |
132 val cparms = map (Proof_Context.cterm_of ctxt) parms; |
132 val cparms = map (Thm.cterm_of ctxt) parms; |
133 val _ = Variable.warn_extra_tfrees fix_ctxt parms_ctxt; |
133 val _ = Variable.warn_extra_tfrees fix_ctxt parms_ctxt; |
134 |
134 |
135 (*obtain statements*) |
135 (*obtain statements*) |
136 val thesisN = singleton (Name.variant_list xs) Auto_Bind.thesisN; |
136 val thesisN = singleton (Name.variant_list xs) Auto_Bind.thesisN; |
137 val (thesis_var, thesis) = #1 (bind_judgment fix_ctxt thesisN); |
137 val (thesis_var, thesis) = #1 (bind_judgment fix_ctxt thesisN); |
185 | _ => error ("Guess split into several cases:\n" ^ Display.string_of_thm ctxt th)); |
185 | _ => error ("Guess split into several cases:\n" ^ Display.string_of_thm ctxt th)); |
186 |
186 |
187 fun result tac facts ctxt = |
187 fun result tac facts ctxt = |
188 let |
188 let |
189 val ((thesis_var, thesis), thesis_ctxt) = bind_judgment ctxt Auto_Bind.thesisN; |
189 val ((thesis_var, thesis), thesis_ctxt) = bind_judgment ctxt Auto_Bind.thesisN; |
190 val st = Goal.init (Proof_Context.cterm_of ctxt thesis); |
190 val st = Goal.init (Thm.cterm_of ctxt thesis); |
191 val rule = |
191 val rule = |
192 (case SINGLE (Method.insert_tac facts 1 THEN tac thesis_ctxt) st of |
192 (case SINGLE (Method.insert_tac facts 1 THEN tac thesis_ctxt) st of |
193 NONE => raise THM ("Obtain.result: tactic failed", 0, facts) |
193 NONE => raise THM ("Obtain.result: tactic failed", 0, facts) |
194 | SOME th => |
194 | SOME th => |
195 check_result thesis_ctxt thesis (Raw_Simplifier.norm_hhf thesis_ctxt (Goal.conclude th))); |
195 check_result thesis_ctxt thesis (Raw_Simplifier.norm_hhf thesis_ctxt (Goal.conclude th))); |
196 |
196 |
197 val closed_rule = Thm.forall_intr (Proof_Context.cterm_of ctxt (Free thesis_var)) rule; |
197 val closed_rule = Thm.forall_intr (Thm.cterm_of ctxt (Free thesis_var)) rule; |
198 val ((_, [rule']), ctxt') = Variable.import false [closed_rule] ctxt; |
198 val ((_, [rule']), ctxt') = Variable.import false [closed_rule] ctxt; |
199 val obtain_rule = |
199 val obtain_rule = |
200 Thm.forall_elim (Proof_Context.cterm_of ctxt (Logic.varify_global (Free thesis_var))) rule'; |
200 Thm.forall_elim (Thm.cterm_of ctxt (Logic.varify_global (Free thesis_var))) rule'; |
201 val ((params, stmt), fix_ctxt) = Variable.focus_cterm (Thm.cprem_of obtain_rule 1) ctxt'; |
201 val ((params, stmt), fix_ctxt) = Variable.focus_cterm (Thm.cprem_of obtain_rule 1) ctxt'; |
202 val (prems, ctxt'') = |
202 val (prems, ctxt'') = |
203 Assumption.add_assms (obtain_export fix_ctxt obtain_rule (map #2 params)) |
203 Assumption.add_assms (obtain_export fix_ctxt obtain_rule (map #2 params)) |
204 (Drule.strip_imp_prems stmt) fix_ctxt; |
204 (Drule.strip_imp_prems stmt) fix_ctxt; |
205 in ((params, prems), ctxt'') end; |
205 in ((params, prems), ctxt'') end; |
235 val norm_type = Envir.norm_type tyenv; |
235 val norm_type = Envir.norm_type tyenv; |
236 |
236 |
237 val xs = map (apsnd norm_type o fst) vars; |
237 val xs = map (apsnd norm_type o fst) vars; |
238 val ys = map (apsnd norm_type) (drop m params); |
238 val ys = map (apsnd norm_type) (drop m params); |
239 val ys' = map Name.internal (Name.variant_list (map fst xs) (map fst ys)) ~~ map #2 ys; |
239 val ys' = map Name.internal (Name.variant_list (map fst xs) (map fst ys)) ~~ map #2 ys; |
240 val terms = map (Drule.mk_term o Thm.cterm_of thy o Free) (xs @ ys'); |
240 val terms = map (Drule.mk_term o Thm.global_cterm_of thy o Free) (xs @ ys'); |
241 |
241 |
242 val instT = |
242 val instT = |
243 fold (Term.add_tvarsT o #2) params [] |
243 fold (Term.add_tvarsT o #2) params [] |
244 |> map (TVar #> (fn T => (Thm.ctyp_of thy T, Thm.ctyp_of thy (norm_type T)))); |
244 |> map (TVar #> (fn T => (Thm.global_ctyp_of thy T, Thm.global_ctyp_of thy (norm_type T)))); |
245 val closed_rule = rule |
245 val closed_rule = rule |
246 |> Thm.forall_intr (Thm.cterm_of thy (Free thesis_var)) |
246 |> Thm.forall_intr (Thm.global_cterm_of thy (Free thesis_var)) |
247 |> Thm.instantiate (instT, []); |
247 |> Thm.instantiate (instT, []); |
248 |
248 |
249 val ((_, rule' :: terms'), ctxt') = Variable.import false (closed_rule :: terms) ctxt; |
249 val ((_, rule' :: terms'), ctxt') = Variable.import false (closed_rule :: terms) ctxt; |
250 val vars' = |
250 val vars' = |
251 map (dest_Free o Thm.term_of o Drule.dest_term) terms' ~~ |
251 map (dest_Free o Thm.term_of o Drule.dest_term) terms' ~~ |
252 (map snd vars @ replicate (length ys) NoSyn); |
252 (map snd vars @ replicate (length ys) NoSyn); |
253 val rule'' = Thm.forall_elim (Thm.cterm_of thy (Logic.varify_global (Free thesis_var))) rule'; |
253 val rule'' = Thm.forall_elim (Thm.global_cterm_of thy (Logic.varify_global (Free thesis_var))) rule'; |
254 in ((vars', rule''), ctxt') end; |
254 in ((vars', rule''), ctxt') end; |
255 |
255 |
256 fun inferred_type (binding, _, mx) ctxt = |
256 fun inferred_type (binding, _, mx) ctxt = |
257 let |
257 let |
258 val x = Variable.check_name binding; |
258 val x = Variable.check_name binding; |
286 in |
286 in |
287 state' |
287 state' |
288 |> Proof.map_context (K ctxt') |
288 |> Proof.map_context (K ctxt') |
289 |> Proof.fix (map (fn ((x, T), mx) => (Binding.name x, SOME T, mx)) parms) |
289 |> Proof.fix (map (fn ((x, T), mx) => (Binding.name x, SOME T, mx)) parms) |
290 |> `Proof.context_of |-> (fn fix_ctxt => Proof.assm |
290 |> `Proof.context_of |-> (fn fix_ctxt => Proof.assm |
291 (obtain_export fix_ctxt rule (map (Proof_Context.cterm_of ctxt) ts)) |
291 (obtain_export fix_ctxt rule (map (Thm.cterm_of ctxt) ts)) |
292 [(Thm.empty_binding, asms)]) |
292 [(Thm.empty_binding, asms)]) |
293 |> Proof.bind_terms Auto_Bind.no_facts |
293 |> Proof.bind_terms Auto_Bind.no_facts |
294 end; |
294 end; |
295 |
295 |
296 val goal = Var (("guess", 0), propT); |
296 val goal = Var (("guess", 0), propT); |
310 |> Proof.fix [(Binding.name Auto_Bind.thesisN, NONE, NoSyn)] |
310 |> Proof.fix [(Binding.name Auto_Bind.thesisN, NONE, NoSyn)] |
311 |> Proof.chain_facts chain_facts |
311 |> Proof.chain_facts chain_facts |
312 |> Proof.local_goal print_result (K I) (pair o rpair I) |
312 |> Proof.local_goal print_result (K I) (pair o rpair I) |
313 "guess" (SOME before_qed) after_qed [(Thm.empty_binding, [Logic.mk_term goal, goal])] |
313 "guess" (SOME before_qed) after_qed [(Thm.empty_binding, [Logic.mk_term goal, goal])] |
314 |> Proof.refine (Method.primitive_text (fn _ => fn _ => |
314 |> Proof.refine (Method.primitive_text (fn _ => fn _ => |
315 Goal.init (Proof_Context.cterm_of ctxt thesis))) |> Seq.hd |
315 Goal.init (Thm.cterm_of ctxt thesis))) |> Seq.hd |
316 end; |
316 end; |
317 |
317 |
318 in |
318 in |
319 |
319 |
320 val guess = gen_guess Proof_Context.cert_vars; |
320 val guess = gen_guess Proof_Context.cert_vars; |