src/HOL/Decision_Procs/Approximation.thy
changeset 31881 eba74a5790d2
parent 31863 e391eee8bf14
child 32212 21d7b4524395
equal deleted inserted replaced
31880:6fb86c61747c 31881:eba74a5790d2
  2668 "DERIV_floatarith x (Power a 0)       = Num 0" |
  2668 "DERIV_floatarith x (Power a 0)       = Num 0" |
  2669 "DERIV_floatarith x (Power a (Suc n)) = Mult (Num (Float (int (Suc n)) 0)) (Mult (Power a n) (DERIV_floatarith x a))" |
  2669 "DERIV_floatarith x (Power a (Suc n)) = Mult (Num (Float (int (Suc n)) 0)) (Mult (Power a n) (DERIV_floatarith x a))" |
  2670 "DERIV_floatarith x (Num f)           = Num 0" |
  2670 "DERIV_floatarith x (Num f)           = Num 0" |
  2671 "DERIV_floatarith x (Atom n)          = (if x = n then Num 1 else Num 0)"
  2671 "DERIV_floatarith x (Atom n)          = (if x = n then Num 1 else Num 0)"
  2672 
  2672 
  2673 lemma DERIV_chain'': "\<lbrakk>DERIV g (f x) :> E ; DERIV f x :> D; x' = E * D \<rbrakk> \<Longrightarrow>
       
  2674   DERIV (\<lambda>x. g (f x)) x :> x'" using DERIV_chain' by auto
       
  2675 
       
  2676 lemma DERIV_cong: "\<lbrakk> DERIV f x :> X ; X = X' \<rbrakk> \<Longrightarrow> DERIV f x :> X'" by simp
       
  2677 
       
  2678 lemma DERIV_floatarith:
  2673 lemma DERIV_floatarith:
  2679   assumes "n < length vs"
  2674   assumes "n < length vs"
  2680   assumes isDERIV: "isDERIV n f (vs[n := x])"
  2675   assumes isDERIV: "isDERIV n f (vs[n := x])"
  2681   shows "DERIV (\<lambda> x'. interpret_floatarith f (vs[n := x'])) x :>
  2676   shows "DERIV (\<lambda> x'. interpret_floatarith f (vs[n := x'])) x :>
  2682                interpret_floatarith (DERIV_floatarith n f) (vs[n := x])"
  2677                interpret_floatarith (DERIV_floatarith n f) (vs[n := x])"
  2683    (is "DERIV (?i f) x :> _")
  2678    (is "DERIV (?i f) x :> _")
  2684 using isDERIV proof (induct f arbitrary: x)
  2679 using isDERIV proof (induct f arbitrary: x)
  2685   case (Add a b) thus ?case by (auto intro: DERIV_add)
  2680      case (Inverse a) thus ?case
  2686 next case (Mult a b) thus ?case by (auto intro!: DERIV_mult[THEN DERIV_cong])
  2681     by (auto intro!: DERIV_intros
  2687 next case (Minus a) thus ?case by (auto intro!: DERIV_minus[THEN DERIV_cong])
       
  2688 next case (Inverse a) thus ?case
       
  2689     by (auto intro!: DERIV_inverse_fun[THEN DERIV_cong] DERIV_inverse[THEN DERIV_cong]
       
  2690              simp add: algebra_simps power2_eq_square)
  2682              simp add: algebra_simps power2_eq_square)
  2691 next case (Cos a) thus ?case
  2683 next case (Cos a) thus ?case
  2692   by (auto intro!: DERIV_chain''[of cos "?i a"]
  2684   by (auto intro!: DERIV_intros
  2693                    DERIV_cos[THEN DERIV_cong]
       
  2694            simp del: interpret_floatarith.simps(5)
  2685            simp del: interpret_floatarith.simps(5)
  2695            simp add: interpret_floatarith_sin interpret_floatarith.simps(5)[of a])
  2686            simp add: interpret_floatarith_sin interpret_floatarith.simps(5)[of a])
  2696 next case (Arctan a) thus ?case
       
  2697   by (auto intro!: DERIV_chain''[of arctan "?i a"] DERIV_arctan[THEN DERIV_cong])
       
  2698 next case (Exp a) thus ?case
       
  2699   by (auto intro!: DERIV_chain''[of exp "?i a"] DERIV_exp[THEN DERIV_cong])
       
  2700 next case (Power a n) thus ?case
  2687 next case (Power a n) thus ?case
  2701   by (cases n, auto intro!: DERIV_power_Suc[THEN DERIV_cong]
  2688   by (cases n, auto intro!: DERIV_intros
  2702                     simp del: power_Suc simp add: real_eq_of_nat)
  2689                     simp del: power_Suc simp add: real_eq_of_nat)
  2703 next case (Sqrt a) thus ?case
       
  2704     by (auto intro!: DERIV_chain''[of sqrt "?i a"] DERIV_real_sqrt[THEN DERIV_cong])
       
  2705 next case (Ln a) thus ?case
  2690 next case (Ln a) thus ?case
  2706     by (auto intro!: DERIV_chain''[of ln "?i a"] DERIV_ln[THEN DERIV_cong]
  2691     by (auto intro!: DERIV_intros simp add: divide_inverse)
  2707                      simp add: divide_inverse)
       
  2708 next case (Atom i) thus ?case using `n < length vs` by auto
  2692 next case (Atom i) thus ?case using `n < length vs` by auto
  2709 qed auto
  2693 qed (auto intro!: DERIV_intros)
  2710 
  2694 
  2711 declare approx.simps[simp del]
  2695 declare approx.simps[simp del]
  2712 
  2696 
  2713 fun isDERIV_approx :: "nat \<Rightarrow> nat \<Rightarrow> floatarith \<Rightarrow> (float * float) option list \<Rightarrow> bool" where
  2697 fun isDERIV_approx :: "nat \<Rightarrow> nat \<Rightarrow> floatarith \<Rightarrow> (float * float) option list \<Rightarrow> bool" where
  2714 "isDERIV_approx prec x (Add a b) vs         = (isDERIV_approx prec x a vs \<and> isDERIV_approx prec x b vs)" |
  2698 "isDERIV_approx prec x (Add a b) vs         = (isDERIV_approx prec x a vs \<and> isDERIV_approx prec x b vs)" |