equal
deleted
inserted
replaced
71 space_implode " " (map (Syntax.string_of_term ctxt) bads)); |
71 space_implode " " (map (Syntax.string_of_term ctxt) bads)); |
72 in tm end; |
72 in tm end; |
73 |
73 |
74 fun eliminate fix_ctxt rule xs As thm = |
74 fun eliminate fix_ctxt rule xs As thm = |
75 let |
75 let |
76 val thy = ProofContext.theory_of fix_ctxt; |
76 val thy = Proof_Context.theory_of fix_ctxt; |
77 |
77 |
78 val _ = eliminate_term fix_ctxt xs (Thm.full_prop_of thm); |
78 val _ = eliminate_term fix_ctxt xs (Thm.full_prop_of thm); |
79 val _ = Object_Logic.is_judgment thy (Thm.concl_of thm) orelse |
79 val _ = Object_Logic.is_judgment thy (Thm.concl_of thm) orelse |
80 error "Conclusion in obtained context must be object-logic judgment"; |
80 error "Conclusion in obtained context must be object-logic judgment"; |
81 |
81 |
97 |
97 |
98 (** obtain **) |
98 (** obtain **) |
99 |
99 |
100 fun bind_judgment ctxt name = |
100 fun bind_judgment ctxt name = |
101 let |
101 let |
102 val (bind, ctxt') = ProofContext.bind_fixes [name] ctxt; |
102 val (bind, ctxt') = Proof_Context.bind_fixes [name] ctxt; |
103 val (t as _ $ Free v) = bind (Object_Logic.fixed_judgment (ProofContext.theory_of ctxt) name); |
103 val (t as _ $ Free v) = bind (Object_Logic.fixed_judgment (Proof_Context.theory_of ctxt) name); |
104 in ((v, t), ctxt') end; |
104 in ((v, t), ctxt') end; |
105 |
105 |
106 val thatN = "that"; |
106 val thatN = "that"; |
107 |
107 |
108 local |
108 local |
116 val ctxt = Proof.context_of state; |
116 val ctxt = Proof.context_of state; |
117 val chain_facts = if can Proof.assert_chain state then Proof.the_facts state else []; |
117 val chain_facts = if can Proof.assert_chain state then Proof.the_facts state else []; |
118 |
118 |
119 (*obtain vars*) |
119 (*obtain vars*) |
120 val (vars, vars_ctxt) = prep_vars raw_vars ctxt; |
120 val (vars, vars_ctxt) = prep_vars raw_vars ctxt; |
121 val (_, fix_ctxt) = vars_ctxt |> ProofContext.add_fixes vars; |
121 val (_, fix_ctxt) = vars_ctxt |> Proof_Context.add_fixes vars; |
122 val xs = map (Variable.name o #1) vars; |
122 val xs = map (Variable.name o #1) vars; |
123 |
123 |
124 (*obtain asms*) |
124 (*obtain asms*) |
125 val (asms_ctxt, proppss) = prep_propp (fix_ctxt, map snd raw_asms); |
125 val (asms_ctxt, proppss) = prep_propp (fix_ctxt, map snd raw_asms); |
126 val asm_props = maps (map fst) proppss; |
126 val asm_props = maps (map fst) proppss; |
132 val thesisN = Name.variant xs Auto_Bind.thesisN; |
132 val thesisN = Name.variant xs Auto_Bind.thesisN; |
133 val (thesis_var, thesis) = #1 (bind_judgment fix_ctxt thesisN); |
133 val (thesis_var, thesis) = #1 (bind_judgment fix_ctxt thesisN); |
134 |
134 |
135 val asm_frees = fold Term.add_frees asm_props []; |
135 val asm_frees = fold Term.add_frees asm_props []; |
136 val parms = xs |> map (fn x => |
136 val parms = xs |> map (fn x => |
137 let val x' = ProofContext.get_skolem fix_ctxt x |
137 let val x' = Proof_Context.get_skolem fix_ctxt x |
138 in (x', the_default propT (AList.lookup (op =) asm_frees x')) end); |
138 in (x', the_default propT (AList.lookup (op =) asm_frees x')) end); |
139 |
139 |
140 val that_name = if name = "" then thatN else name; |
140 val that_name = if name = "" then thatN else name; |
141 val that_prop = |
141 val that_prop = |
142 Term.list_all_free (parms, Logic.list_implies (asm_props, thesis)) |
142 Term.list_all_free (parms, Logic.list_implies (asm_props, thesis)) |
164 |-> Proof.refine_insert |
164 |-> Proof.refine_insert |
165 end; |
165 end; |
166 |
166 |
167 in |
167 in |
168 |
168 |
169 val obtain = gen_obtain (K I) ProofContext.cert_vars ProofContext.cert_propp; |
169 val obtain = gen_obtain (K I) Proof_Context.cert_vars Proof_Context.cert_propp; |
170 val obtain_cmd = gen_obtain Attrib.attribute ProofContext.read_vars ProofContext.read_propp; |
170 val obtain_cmd = gen_obtain Attrib.attribute Proof_Context.read_vars Proof_Context.read_propp; |
171 |
171 |
172 end; |
172 end; |
173 |
173 |
174 |
174 |
175 |
175 |
184 | [] => error "Goal solved -- nothing guessed" |
184 | [] => error "Goal solved -- nothing guessed" |
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 thy = ProofContext.theory_of ctxt; |
189 val thy = Proof_Context.theory_of ctxt; |
190 val cert = Thm.cterm_of thy; |
190 val cert = Thm.cterm_of thy; |
191 |
191 |
192 val ((thesis_var, thesis), thesis_ctxt) = bind_judgment ctxt Auto_Bind.thesisN; |
192 val ((thesis_var, thesis), thesis_ctxt) = bind_judgment ctxt Auto_Bind.thesisN; |
193 val rule = |
193 val rule = |
194 (case SINGLE (Method.insert_tac facts 1 THEN tac thesis_ctxt) (Goal.init (cert thesis)) of |
194 (case SINGLE (Method.insert_tac facts 1 THEN tac thesis_ctxt) (Goal.init (cert thesis)) of |
210 |
210 |
211 local |
211 local |
212 |
212 |
213 fun unify_params vars thesis_var raw_rule ctxt = |
213 fun unify_params vars thesis_var raw_rule ctxt = |
214 let |
214 let |
215 val thy = ProofContext.theory_of ctxt; |
215 val thy = Proof_Context.theory_of ctxt; |
216 val certT = Thm.ctyp_of thy; |
216 val certT = Thm.ctyp_of thy; |
217 val cert = Thm.cterm_of thy; |
217 val cert = Thm.cterm_of thy; |
218 val string_of_term = Syntax.string_of_term (Config.put show_types true ctxt); |
218 val string_of_term = Syntax.string_of_term (Config.put show_types true ctxt); |
219 |
219 |
220 fun err msg th = error (msg ^ ":\n" ^ Display.string_of_thm ctxt th); |
220 fun err msg th = error (msg ^ ":\n" ^ Display.string_of_thm ctxt th); |
256 in ((vars', rule''), ctxt') end; |
256 in ((vars', rule''), ctxt') end; |
257 |
257 |
258 fun inferred_type (binding, _, mx) ctxt = |
258 fun inferred_type (binding, _, mx) ctxt = |
259 let |
259 let |
260 val x = Variable.name binding; |
260 val x = Variable.name binding; |
261 val (T, ctxt') = ProofContext.inferred_param x ctxt |
261 val (T, ctxt') = Proof_Context.inferred_param x ctxt |
262 in ((x, T, mx), ctxt') end; |
262 in ((x, T, mx), ctxt') end; |
263 |
263 |
264 fun polymorphic ctxt vars = |
264 fun polymorphic ctxt vars = |
265 let val Ts = map Logic.dest_type (Variable.polymorphic ctxt (map (Logic.mk_type o #2) vars)) |
265 let val Ts = map Logic.dest_type (Variable.polymorphic ctxt (map (Logic.mk_type o #2) vars)) |
266 in map2 (fn (x, _, mx) => fn T => ((x, T), mx)) vars Ts end; |
266 in map2 (fn (x, _, mx) => fn T => ((x, T), mx)) vars Ts end; |
278 |
278 |
279 fun guess_context raw_rule state' = |
279 fun guess_context raw_rule state' = |
280 let |
280 let |
281 val ((parms, rule), ctxt') = |
281 val ((parms, rule), ctxt') = |
282 unify_params vars thesis_var raw_rule (Proof.context_of state'); |
282 unify_params vars thesis_var raw_rule (Proof.context_of state'); |
283 val (bind, _) = ProofContext.bind_fixes (map (#1 o #1) parms) ctxt'; |
283 val (bind, _) = Proof_Context.bind_fixes (map (#1 o #1) parms) ctxt'; |
284 val ts = map (bind o Free o #1) parms; |
284 val ts = map (bind o Free o #1) parms; |
285 val ps = map dest_Free ts; |
285 val ps = map dest_Free ts; |
286 val asms = |
286 val asms = |
287 Logic.strip_assums_hyp (Logic.nth_prem (1, Thm.prop_of rule)) |
287 Logic.strip_assums_hyp (Logic.nth_prem (1, Thm.prop_of rule)) |
288 |> map (fn asm => (Term.betapplys (Term.list_abs (ps, asm), ts), [])); |
288 |> map (fn asm => (Term.betapplys (Term.list_abs (ps, asm), ts), [])); |
314 |> Proof.refine (Method.primitive_text (K (Goal.init (cert thesis)))) |> Seq.hd |
314 |> Proof.refine (Method.primitive_text (K (Goal.init (cert thesis)))) |> Seq.hd |
315 end; |
315 end; |
316 |
316 |
317 in |
317 in |
318 |
318 |
319 val guess = gen_guess ProofContext.cert_vars; |
319 val guess = gen_guess Proof_Context.cert_vars; |
320 val guess_cmd = gen_guess ProofContext.read_vars; |
320 val guess_cmd = gen_guess Proof_Context.read_vars; |
321 |
321 |
322 end; |
322 end; |
323 |
323 |
324 end; |
324 end; |