src/HOL/Decision_Procs/Approximation.thy
changeset 63929 b673e7221b16
parent 63918 6bf55e6e0b75
child 63931 f17a1c60ac39
equal deleted inserted replaced
63928:d81fb5b46a5c 63929:b673e7221b16
  2861     sin (interpret_floatarith a vs)"
  2861     sin (interpret_floatarith a vs)"
  2862   unfolding sin_cos_eq interpret_floatarith.simps
  2862   unfolding sin_cos_eq interpret_floatarith.simps
  2863     interpret_floatarith_divide interpret_floatarith_diff
  2863     interpret_floatarith_divide interpret_floatarith_diff
  2864   by auto
  2864   by auto
  2865 
  2865 
  2866 lemma interpret_floatarith_tan:
       
  2867   "interpret_floatarith (Mult (Cos (Add (Mult Pi (Num (Float 1 (- 1)))) (Minus a))) (Inverse (Cos a))) vs =
       
  2868      tan (interpret_floatarith a vs)"
       
  2869   unfolding interpret_floatarith.simps(3,4) interpret_floatarith_sin tan_def divide_inverse
       
  2870   by auto
       
  2871 
       
  2872 lemma interpret_floatarith_log:
       
  2873   "interpret_floatarith ((Mult (Ln x) (Inverse (Ln b)))) vs =
       
  2874     log (interpret_floatarith b vs) (interpret_floatarith x vs)"
       
  2875   unfolding log_def interpret_floatarith.simps divide_inverse ..
       
  2876 
       
  2877 lemma interpret_floatarith_num:
       
  2878   shows "interpret_floatarith (Num (Float 0 0)) vs = 0"
       
  2879     and "interpret_floatarith (Num (Float 1 0)) vs = 1"
       
  2880     and "interpret_floatarith (Num (Float (- 1) 0)) vs = - 1"
       
  2881     and "interpret_floatarith (Num (Float (numeral a) 0)) vs = numeral a"
       
  2882     and "interpret_floatarith (Num (Float (- numeral a) 0)) vs = - numeral a"
       
  2883   by auto
       
  2884 
       
  2885 lemma interpret_floatarith_ceiling:
       
  2886   "interpret_floatarith (Minus (Floor (Minus a))) vs = ceiling (interpret_floatarith a vs)"
       
  2887   unfolding ceiling_def interpret_floatarith.simps of_int_minus ..
       
  2888 
       
  2889 
  2866 
  2890 subsection "Implement approximation function"
  2867 subsection "Implement approximation function"
  2891 
  2868 
  2892 fun lift_bin :: "(float * float) option \<Rightarrow> (float * float) option \<Rightarrow> (float \<Rightarrow> float \<Rightarrow> float \<Rightarrow> float \<Rightarrow> (float * float) option) \<Rightarrow> (float * float) option" where
  2869 fun lift_bin :: "(float * float) option \<Rightarrow> (float * float) option \<Rightarrow> (float \<Rightarrow> float \<Rightarrow> float \<Rightarrow> float \<Rightarrow> (float * float) option) \<Rightarrow> (float * float) option" where
  2893 "lift_bin (Some (l1, u1)) (Some (l2, u2)) f = f l1 u1 l2 u2" |
  2870 "lift_bin (Some (l1, u1)) (Some (l2, u2)) f = f l1 u1 l2 u2" |
  4287 "approx_form_eval _ _ bs = bs"
  4264 "approx_form_eval _ _ bs = bs"
  4288 
  4265 
  4289 
  4266 
  4290 subsection \<open>Implement proof method \texttt{approximation}\<close>
  4267 subsection \<open>Implement proof method \texttt{approximation}\<close>
  4291 
  4268 
  4292 lemmas interpret_form_equations = interpret_form.simps interpret_floatarith.simps interpret_floatarith_num
       
  4293   interpret_floatarith_divide interpret_floatarith_diff interpret_floatarith_tan interpret_floatarith_log
       
  4294   interpret_floatarith_sin interpret_floatarith_ceiling
       
  4295 
       
  4296 oracle approximation_oracle = \<open>fn (thy, t) =>
  4269 oracle approximation_oracle = \<open>fn (thy, t) =>
  4297 let
  4270 let
  4298   fun bad t = error ("Bad term: " ^ Syntax.string_of_term_global thy t);
  4271   fun bad t = error ("Bad term: " ^ Syntax.string_of_term_global thy t);
  4299 
  4272 
  4300   fun term_of_bool true = @{term True}
  4273   fun term_of_bool true = @{term True}
  4398   by auto
  4371   by auto
  4399 
  4372 
  4400 lemma meta_eqE: "x \<equiv> a \<Longrightarrow> \<lbrakk> x = a \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P"
  4373 lemma meta_eqE: "x \<equiv> a \<Longrightarrow> \<lbrakk> x = a \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P"
  4401   by auto
  4374   by auto
  4402 
  4375 
       
  4376 named_theorems approximation_preproc
       
  4377 
       
  4378 lemma approximation_preproc_floatarith[approximation_preproc]:
       
  4379   "0 = real_of_float 0"
       
  4380   "1 = real_of_float 1"
       
  4381   "0 = Float 0 0"
       
  4382   "1 = Float 1 0"
       
  4383   "numeral a = Float (numeral a) 0"
       
  4384   "numeral a = real_of_float (numeral a)"
       
  4385   "x - y = x + - y"
       
  4386   "x / y = x * inverse y"
       
  4387   "ceiling x = - floor (- x)"
       
  4388   "log x y = ln y * inverse (ln x)"
       
  4389   "sin x = cos (pi / 2 - x)"
       
  4390   "tan x = sin x / cos x"
       
  4391   "real_of_int (- i) = - real_of_int i"
       
  4392   by (simp_all add: inverse_eq_divide ceiling_def log_def sin_cos_eq tan_def real_of_float_eq)
       
  4393 
  4403 ML_file "approximation.ML"
  4394 ML_file "approximation.ML"
  4404 
  4395 
  4405 method_setup approximation = \<open>
  4396 method_setup approximation = \<open>
  4406   let
  4397   let
  4407     val free =
  4398     val free =
  4419 \<close> "real number approximation"
  4410 \<close> "real number approximation"
  4420 
  4411 
  4421 
  4412 
  4422 section "Quickcheck Generator"
  4413 section "Quickcheck Generator"
  4423 
  4414 
       
  4415 lemma approximation_preproc_push_neg[approximation_preproc]:
       
  4416   fixes a b::real
       
  4417   shows
       
  4418     "\<not> (a < b) \<longleftrightarrow> b \<le> a"
       
  4419     "\<not> (a \<le> b) \<longleftrightarrow> b < a"
       
  4420     "\<not> (a = b) \<longleftrightarrow> b < a \<or> a < b"
       
  4421     "\<not> (p \<and> q) \<longleftrightarrow> \<not> p \<or> \<not> q"
       
  4422     "\<not> (p \<or> q) \<longleftrightarrow> \<not> p \<and> \<not> q"
       
  4423     "\<not> \<not> q \<longleftrightarrow> q"
       
  4424   by auto
       
  4425 
  4424 ML_file "approximation_generator.ML"
  4426 ML_file "approximation_generator.ML"
  4425 setup "Approximation_Generator.setup"
  4427 setup "Approximation_Generator.setup"
  4426 
  4428 
  4427 end
  4429 end