2 Author: Johannes Hoelzl, TU Muenchen |
2 Author: Johannes Hoelzl, TU Muenchen |
3 *) |
3 *) |
4 |
4 |
5 signature APPROXIMATION = |
5 signature APPROXIMATION = |
6 sig |
6 sig |
|
7 val reify_form: Proof.context -> term -> term |
7 val approx: int -> Proof.context -> term -> term |
8 val approx: int -> Proof.context -> term -> term |
8 val approximate: Proof.context -> term -> term |
9 val approximate: Proof.context -> term -> term |
9 val approximation_tac : int -> (string * int) list -> int option -> Proof.context -> int -> tactic |
10 val approximation_tac : int -> (string * int) list -> int option -> Proof.context -> int -> tactic |
10 end |
11 end |
11 |
12 |
51 (* Should be in HOL.thy ? *) |
52 (* Should be in HOL.thy ? *) |
52 fun gen_eval_tac conv ctxt = |
53 fun gen_eval_tac conv ctxt = |
53 CONVERSION |
54 CONVERSION |
54 (Object_Logic.judgment_conv ctxt (Conv.params_conv (~1) (K (Conv.concl_conv (~1) conv)) ctxt)) |
55 (Object_Logic.judgment_conv ctxt (Conv.params_conv (~1) (K (Conv.concl_conv (~1) conv)) ctxt)) |
55 THEN' resolve_tac ctxt [TrueI] |
56 THEN' resolve_tac ctxt [TrueI] |
56 |
|
57 val form_equations = @{thms interpret_form_equations}; |
|
58 |
57 |
59 fun rewrite_interpret_form_tac ctxt prec splitting taylor i st = let |
58 fun rewrite_interpret_form_tac ctxt prec splitting taylor i st = let |
60 fun lookup_splitting (Free (name, _)) |
59 fun lookup_splitting (Free (name, _)) |
61 = case AList.lookup (op =) splitting name |
60 = case AList.lookup (op =) splitting name |
62 of SOME s => HOLogic.mk_number @{typ nat} s |
61 of SOME s => HOLogic.mk_number @{typ nat} s |
188 Thm.cterm_of ctxt term |
187 Thm.cterm_of ctxt term |
189 |> Goal.init |
188 |> Goal.init |
190 |> SINGLE tactic |
189 |> SINGLE tactic |
191 |> the |> Thm.prems_of |> hd |
190 |> the |> Thm.prems_of |> hd |
192 |
191 |
193 fun prepare_form ctxt term = apply_tactic ctxt term ( |
192 fun preproc_form_conv ctxt = |
194 REPEAT (FIRST' [eresolve_tac ctxt @{thms intervalE}, |
193 Simplifier.rewrite |
195 eresolve_tac ctxt @{thms meta_eqE}, |
194 (put_simpset HOL_basic_ss ctxt addsimps |
196 resolve_tac ctxt @{thms impI}] 1) |
195 (Named_Theorems.get ctxt @{named_theorems approximation_preproc})) |
197 THEN Subgoal.FOCUS (fn {prems, context = ctxt', ...} => reorder_bounds_tac ctxt' prems 1) ctxt 1 |
196 |
198 THEN DETERM (TRY (filter_prems_tac ctxt (K false) 1))) |
197 fun reify_form_conv ctxt = |
199 |
198 (Reification.conv ctxt @{thms interpret_form.simps interpret_floatarith.simps}) |
200 fun reify_form ctxt term = apply_tactic ctxt term |
199 |
201 (Reification.tac ctxt form_equations NONE 1) |
200 fun reify_form_tac ctxt i = CONVERSION (Conv.arg_conv (reify_form_conv ctxt)) i |
|
201 |
|
202 fun prepare_form_tac ctxt i = |
|
203 REPEAT (FIRST' [eresolve_tac ctxt @{thms intervalE}, |
|
204 eresolve_tac ctxt @{thms meta_eqE}, |
|
205 resolve_tac ctxt @{thms impI}] i) |
|
206 THEN Subgoal.FOCUS (fn {prems, context = ctxt', ...} => reorder_bounds_tac ctxt' prems i) ctxt i |
|
207 THEN DETERM (TRY (filter_prems_tac ctxt (K false) i)) |
|
208 THEN CONVERSION (Conv.arg_conv (preproc_form_conv ctxt)) i |
|
209 |
|
210 fun prepare_form ctxt term = apply_tactic ctxt term (prepare_form_tac ctxt 1) |
|
211 |
|
212 fun apply_reify_form ctxt t = apply_tactic ctxt t (reify_form_tac ctxt 1) |
|
213 |
|
214 fun reify_form ctxt t = HOLogic.mk_Trueprop t |
|
215 |> prepare_form ctxt |
|
216 |> apply_reify_form ctxt |
|
217 |> HOLogic.dest_Trueprop |
202 |
218 |
203 fun approx_form prec ctxt t = |
219 fun approx_form prec ctxt t = |
204 realify t |
220 realify t |
205 |> prepare_form ctxt |
221 |> prepare_form ctxt |
206 |> (fn arith_term => reify_form ctxt arith_term |
222 |> (fn arith_term => apply_reify_form ctxt arith_term |
207 |> HOLogic.dest_Trueprop |> dest_interpret_form |
223 |> HOLogic.dest_Trueprop |
|
224 |> dest_interpret_form |
208 |> (fn (data, xs) => |
225 |> (fn (data, xs) => |
209 mk_approx_form_eval prec data (HOLogic.mk_list @{typ "(float * float) option"} |
226 mk_approx_form_eval prec data (HOLogic.mk_list @{typ "(float * float) option"} |
210 (map (fn _ => @{term "None :: (float * float) option"}) (HOLogic.dest_list xs))) |
227 (map (fn _ => @{term "None :: (float * float) option"}) (HOLogic.dest_list xs))) |
211 |> approximate ctxt |
228 |> approximate ctxt |
212 |> HOLogic.dest_list |
229 |> HOLogic.dest_list |
214 |> map (fn (elem, s) => @{term "op : :: real \<Rightarrow> real set \<Rightarrow> bool"} $ elem $ mk_result prec (dest_ivl s)) |
231 |> map (fn (elem, s) => @{term "op : :: real \<Rightarrow> real set \<Rightarrow> bool"} $ elem $ mk_result prec (dest_ivl s)) |
215 |> foldr1 HOLogic.mk_conj)) |
232 |> foldr1 HOLogic.mk_conj)) |
216 |
233 |
217 fun approx_arith prec ctxt t = realify t |
234 fun approx_arith prec ctxt t = realify t |
218 |> Thm.cterm_of ctxt |
235 |> Thm.cterm_of ctxt |
219 |> Reification.conv ctxt form_equations |
236 |> (preproc_form_conv ctxt then_conv reify_form_conv ctxt) |
220 |> Thm.prop_of |
237 |> Thm.prop_of |
221 |> Logic.dest_equals |> snd |
238 |> Logic.dest_equals |> snd |
222 |> dest_interpret |> fst |
239 |> dest_interpret |> fst |
223 |> mk_approx' prec |
240 |> mk_approx' prec |
224 |> approximate ctxt |
241 |> approximate ctxt |
250 Outer_Syntax.command @{command_keyword approximate} "print approximation of term" |
267 Outer_Syntax.command @{command_keyword approximate} "print approximation of term" |
251 (opt_modes -- Parse.term |
268 (opt_modes -- Parse.term |
252 >> (fn (modes, t) => Toplevel.keep (approximate_cmd modes t))); |
269 >> (fn (modes, t) => Toplevel.keep (approximate_cmd modes t))); |
253 |
270 |
254 fun approximation_tac prec splitting taylor ctxt i = |
271 fun approximation_tac prec splitting taylor ctxt i = |
255 REPEAT (FIRST' [eresolve_tac ctxt @{thms intervalE}, |
272 prepare_form_tac ctxt i |
256 eresolve_tac ctxt @{thms meta_eqE}, |
273 THEN reify_form_tac ctxt i |
257 resolve_tac ctxt @{thms impI}] i) |
|
258 THEN Subgoal.FOCUS (fn {prems, context = ctxt', ...} => reorder_bounds_tac ctxt' prems i) ctxt i |
|
259 THEN DETERM (TRY (filter_prems_tac ctxt (K false) i)) |
|
260 THEN DETERM (Reification.tac ctxt form_equations NONE i) |
|
261 THEN rewrite_interpret_form_tac ctxt prec splitting taylor i |
274 THEN rewrite_interpret_form_tac ctxt prec splitting taylor i |
262 THEN gen_eval_tac (approximation_conv ctxt) ctxt i |
275 THEN gen_eval_tac (approximation_conv ctxt) ctxt i |
263 |
276 |
264 end; |
277 end; |