src/HOL/Transcendental.thy
changeset 45168 d2a6f9af02f4
parent 45167 6a383003d0a9
child 45182 42c5cbf68052
equal deleted inserted replaced
45167:6a383003d0a9 45168:d2a6f9af02f4
   801   show ?thesis .
   801   show ?thesis .
   802 qed
   802 qed
   803 
   803 
   804 subsection {* Exponential Function *}
   804 subsection {* Exponential Function *}
   805 
   805 
   806 definition
   806 definition exp :: "'a \<Rightarrow> 'a::{real_normed_field,banach}" where
   807   exp :: "'a \<Rightarrow> 'a::{real_normed_field,banach}" where
   807   "exp = (\<lambda>x. \<Sum>n. x ^ n /\<^sub>R real (fact n))"
   808   "exp x = (\<Sum>n. x ^ n /\<^sub>R real (fact n))"
       
   809 
   808 
   810 lemma summable_exp_generic:
   809 lemma summable_exp_generic:
   811   fixes x :: "'a::{real_normed_algebra_1,banach}"
   810   fixes x :: "'a::{real_normed_algebra_1,banach}"
   812   defines S_def: "S \<equiv> \<lambda>n. x ^ n /\<^sub>R real (fact n)"
   811   defines S_def: "S \<equiv> \<lambda>n. x ^ n /\<^sub>R real (fact n)"
   813   shows "summable S"
   812   shows "summable S"
   861          del: mult_Suc of_nat_Suc)
   860          del: mult_Suc of_nat_Suc)
   862 
   861 
   863 lemma diffs_of_real: "diffs (\<lambda>n. of_real (f n)) = (\<lambda>n. of_real (diffs f n))"
   862 lemma diffs_of_real: "diffs (\<lambda>n. of_real (f n)) = (\<lambda>n. of_real (diffs f n))"
   864 by (simp add: diffs_def)
   863 by (simp add: diffs_def)
   865 
   864 
   866 lemma lemma_exp_ext: "exp = (\<lambda>x. \<Sum>n. x ^ n /\<^sub>R real (fact n))"
       
   867 by (auto simp add: exp_def)
       
   868 
       
   869 lemma DERIV_exp [simp]: "DERIV exp x :> exp(x)"
   865 lemma DERIV_exp [simp]: "DERIV exp x :> exp(x)"
   870 apply (simp add: exp_def)
   866 unfolding exp_def scaleR_conv_of_real
   871 apply (subst lemma_exp_ext)
   867 apply (rule DERIV_cong)
   872 apply (subgoal_tac "DERIV (\<lambda>u. \<Sum>n. of_real (inverse (real (fact n))) * u ^ n) x :> (\<Sum>n. diffs (\<lambda>n. of_real (inverse (real (fact n)))) n * x ^ n)")
   868 apply (rule termdiffs [where K="of_real (1 + norm x)"])
   873 apply (rule_tac [2] K = "of_real (1 + norm x)" in termdiffs)
       
   874 apply (simp_all only: diffs_of_real scaleR_conv_of_real exp_fdiffs)
   869 apply (simp_all only: diffs_of_real scaleR_conv_of_real exp_fdiffs)
   875 apply (rule exp_converges [THEN sums_summable, unfolded scaleR_conv_of_real])+
   870 apply (rule exp_converges [THEN sums_summable, unfolded scaleR_conv_of_real])+
   876 apply (simp del: of_real_add)
   871 apply (simp del: of_real_add)
   877 done
   872 done
   878 
   873 
  1081 done
  1076 done
  1082 
  1077 
  1083 
  1078 
  1084 subsection {* Natural Logarithm *}
  1079 subsection {* Natural Logarithm *}
  1085 
  1080 
  1086 definition
  1081 definition ln :: "real \<Rightarrow> real" where
  1087   ln :: "real => real" where
       
  1088   "ln x = (THE u. exp u = x)"
  1082   "ln x = (THE u. exp u = x)"
  1089 
  1083 
  1090 lemma ln_exp [simp]: "ln (exp x) = x"
  1084 lemma ln_exp [simp]: "ln (exp x) = x"
  1091 by (simp add: ln_def)
  1085   by (simp add: ln_def)
  1092 
  1086 
  1093 lemma exp_ln [simp]: "0 < x \<Longrightarrow> exp (ln x) = x"
  1087 lemma exp_ln [simp]: "0 < x \<Longrightarrow> exp (ln x) = x"
  1094 by (auto dest: exp_total)
  1088   by (auto dest: exp_total)
  1095 
  1089 
  1096 lemma exp_ln_iff [simp]: "exp (ln x) = x \<longleftrightarrow> 0 < x"
  1090 lemma exp_ln_iff [simp]: "exp (ln x) = x \<longleftrightarrow> 0 < x"
  1097 apply (rule iffI)
  1091   by (metis exp_gt_zero exp_ln)
  1098 apply (erule subst, rule exp_gt_zero)
       
  1099 apply (erule exp_ln)
       
  1100 done
       
  1101 
  1092 
  1102 lemma ln_unique: "exp y = x \<Longrightarrow> ln x = y"
  1093 lemma ln_unique: "exp y = x \<Longrightarrow> ln x = y"
  1103 by (erule subst, rule ln_exp)
  1094   by (erule subst, rule ln_exp)
  1104 
  1095 
  1105 lemma ln_one [simp]: "ln 1 = 0"
  1096 lemma ln_one [simp]: "ln 1 = 0"
  1106 by (rule ln_unique, simp)
  1097   by (rule ln_unique, simp)
  1107 
  1098 
  1108 lemma ln_mult: "\<lbrakk>0 < x; 0 < y\<rbrakk> \<Longrightarrow> ln (x * y) = ln x + ln y"
  1099 lemma ln_mult: "\<lbrakk>0 < x; 0 < y\<rbrakk> \<Longrightarrow> ln (x * y) = ln x + ln y"
  1109 by (rule ln_unique, simp add: exp_add)
  1100   by (rule ln_unique, simp add: exp_add)
  1110 
  1101 
  1111 lemma ln_inverse: "0 < x \<Longrightarrow> ln (inverse x) = - ln x"
  1102 lemma ln_inverse: "0 < x \<Longrightarrow> ln (inverse x) = - ln x"
  1112 by (rule ln_unique, simp add: exp_minus)
  1103   by (rule ln_unique, simp add: exp_minus)
  1113 
  1104 
  1114 lemma ln_div: "\<lbrakk>0 < x; 0 < y\<rbrakk> \<Longrightarrow> ln (x / y) = ln x - ln y"
  1105 lemma ln_div: "\<lbrakk>0 < x; 0 < y\<rbrakk> \<Longrightarrow> ln (x / y) = ln x - ln y"
  1115 by (rule ln_unique, simp add: exp_diff)
  1106   by (rule ln_unique, simp add: exp_diff)
  1116 
  1107 
  1117 lemma ln_realpow: "0 < x \<Longrightarrow> ln (x ^ n) = real n * ln x"
  1108 lemma ln_realpow: "0 < x \<Longrightarrow> ln (x ^ n) = real n * ln x"
  1118 by (rule ln_unique, simp add: exp_real_of_nat_mult)
  1109   by (rule ln_unique, simp add: exp_real_of_nat_mult)
  1119 
  1110 
  1120 lemma ln_less_cancel_iff [simp]: "\<lbrakk>0 < x; 0 < y\<rbrakk> \<Longrightarrow> ln x < ln y \<longleftrightarrow> x < y"
  1111 lemma ln_less_cancel_iff [simp]: "\<lbrakk>0 < x; 0 < y\<rbrakk> \<Longrightarrow> ln x < ln y \<longleftrightarrow> x < y"
  1121 by (subst exp_less_cancel_iff [symmetric], simp)
  1112   by (subst exp_less_cancel_iff [symmetric], simp)
  1122 
  1113 
  1123 lemma ln_le_cancel_iff [simp]: "\<lbrakk>0 < x; 0 < y\<rbrakk> \<Longrightarrow> ln x \<le> ln y \<longleftrightarrow> x \<le> y"
  1114 lemma ln_le_cancel_iff [simp]: "\<lbrakk>0 < x; 0 < y\<rbrakk> \<Longrightarrow> ln x \<le> ln y \<longleftrightarrow> x \<le> y"
  1124 by (simp add: linorder_not_less [symmetric])
  1115   by (simp add: linorder_not_less [symmetric])
  1125 
  1116 
  1126 lemma ln_inj_iff [simp]: "\<lbrakk>0 < x; 0 < y\<rbrakk> \<Longrightarrow> ln x = ln y \<longleftrightarrow> x = y"
  1117 lemma ln_inj_iff [simp]: "\<lbrakk>0 < x; 0 < y\<rbrakk> \<Longrightarrow> ln x = ln y \<longleftrightarrow> x = y"
  1127 by (simp add: order_eq_iff)
  1118   by (simp add: order_eq_iff)
  1128 
  1119 
  1129 lemma ln_add_one_self_le_self [simp]: "0 \<le> x \<Longrightarrow> ln (1 + x) \<le> x"
  1120 lemma ln_add_one_self_le_self [simp]: "0 \<le> x \<Longrightarrow> ln (1 + x) \<le> x"
  1130 apply (rule exp_le_cancel_iff [THEN iffD1])
  1121   apply (rule exp_le_cancel_iff [THEN iffD1])
  1131 apply (simp add: exp_ge_add_one_self_aux)
  1122   apply (simp add: exp_ge_add_one_self_aux)
  1132 done
  1123   done
  1133 
  1124 
  1134 lemma ln_less_self [simp]: "0 < x \<Longrightarrow> ln x < x"
  1125 lemma ln_less_self [simp]: "0 < x \<Longrightarrow> ln x < x"
  1135 by (rule order_less_le_trans [where y="ln (1 + x)"]) simp_all
  1126   by (rule order_less_le_trans [where y="ln (1 + x)"]) simp_all
  1136 
  1127 
  1137 lemma ln_ge_zero [simp]:
  1128 lemma ln_ge_zero [simp]: "1 \<le> x \<Longrightarrow> 0 \<le> ln x"
  1138   assumes x: "1 \<le> x" shows "0 \<le> ln x"
  1129   using ln_le_cancel_iff [of 1 x] by simp
  1139 proof -
  1130 
  1140   have "0 < x" using x by arith
  1131 lemma ln_ge_zero_imp_ge_one: "\<lbrakk>0 \<le> ln x; 0 < x\<rbrakk> \<Longrightarrow> 1 \<le> x"
  1141   hence "exp 0 \<le> exp (ln x)"
  1132   using ln_le_cancel_iff [of 1 x] by simp
  1142     by (simp add: x)
  1133 
  1143   thus ?thesis by (simp only: exp_le_cancel_iff)
  1134 lemma ln_ge_zero_iff [simp]: "0 < x \<Longrightarrow> (0 \<le> ln x) = (1 \<le> x)"
  1144 qed
  1135   using ln_le_cancel_iff [of 1 x] by simp
  1145 
  1136 
  1146 lemma ln_ge_zero_imp_ge_one:
  1137 lemma ln_less_zero_iff [simp]: "0 < x \<Longrightarrow> (ln x < 0) = (x < 1)"
  1147   assumes ln: "0 \<le> ln x"
  1138   using ln_less_cancel_iff [of x 1] by simp
  1148       and x:  "0 < x"
  1139 
  1149   shows "1 \<le> x"
  1140 lemma ln_gt_zero: "1 < x \<Longrightarrow> 0 < ln x"
  1150 proof -
  1141   using ln_less_cancel_iff [of 1 x] by simp
  1151   from ln have "ln 1 \<le> ln x" by simp
  1142 
  1152   thus ?thesis by (simp add: x del: ln_one)
  1143 lemma ln_gt_zero_imp_gt_one: "\<lbrakk>0 < ln x; 0 < x\<rbrakk> \<Longrightarrow> 1 < x"
  1153 qed
  1144   using ln_less_cancel_iff [of 1 x] by simp
  1154 
  1145 
  1155 lemma ln_ge_zero_iff [simp]: "0 < x ==> (0 \<le> ln x) = (1 \<le> x)"
  1146 lemma ln_gt_zero_iff [simp]: "0 < x \<Longrightarrow> (0 < ln x) = (1 < x)"
  1156 by (blast intro: ln_ge_zero ln_ge_zero_imp_ge_one)
  1147   using ln_less_cancel_iff [of 1 x] by simp
  1157 
  1148 
  1158 lemma ln_less_zero_iff [simp]: "0 < x ==> (ln x < 0) = (x < 1)"
  1149 lemma ln_eq_zero_iff [simp]: "0 < x \<Longrightarrow> (ln x = 0) = (x = 1)"
  1159 by (insert ln_ge_zero_iff [of x], arith)
  1150   using ln_inj_iff [of x 1] by simp
  1160 
  1151 
  1161 lemma ln_gt_zero:
  1152 lemma ln_less_zero: "\<lbrakk>0 < x; x < 1\<rbrakk> \<Longrightarrow> ln x < 0"
  1162   assumes x: "1 < x" shows "0 < ln x"
  1153   by simp
  1163 proof -
       
  1164   have "0 < x" using x by arith
       
  1165   hence "exp 0 < exp (ln x)" by (simp add: x)
       
  1166   thus ?thesis  by (simp only: exp_less_cancel_iff)
       
  1167 qed
       
  1168 
       
  1169 lemma ln_gt_zero_imp_gt_one:
       
  1170   assumes ln: "0 < ln x"
       
  1171       and x:  "0 < x"
       
  1172   shows "1 < x"
       
  1173 proof -
       
  1174   from ln have "ln 1 < ln x" by simp
       
  1175   thus ?thesis by (simp add: x del: ln_one)
       
  1176 qed
       
  1177 
       
  1178 lemma ln_gt_zero_iff [simp]: "0 < x ==> (0 < ln x) = (1 < x)"
       
  1179 by (blast intro: ln_gt_zero ln_gt_zero_imp_gt_one)
       
  1180 
       
  1181 lemma ln_eq_zero_iff [simp]: "0 < x ==> (ln x = 0) = (x = 1)"
       
  1182 by (insert ln_less_zero_iff [of x] ln_gt_zero_iff [of x], arith)
       
  1183 
       
  1184 lemma ln_less_zero: "[| 0 < x; x < 1 |] ==> ln x < 0"
       
  1185 by simp
       
  1186 
  1154 
  1187 lemma exp_ln_eq: "exp u = x ==> ln x = u"
  1155 lemma exp_ln_eq: "exp u = x ==> ln x = u"
  1188 by auto
  1156   by (rule ln_unique) (* TODO: delete *)
  1189 
  1157 
  1190 lemma isCont_ln: "0 < x \<Longrightarrow> isCont ln x"
  1158 lemma isCont_ln: "0 < x \<Longrightarrow> isCont ln x"
  1191 apply (subgoal_tac "isCont ln (exp (ln x))", simp)
  1159   apply (subgoal_tac "isCont ln (exp (ln x))", simp)
  1192 apply (rule isCont_inverse_function [where f=exp], simp_all)
  1160   apply (rule isCont_inverse_function [where f=exp], simp_all)
  1193 done
  1161   done
  1194 
  1162 
  1195 lemma DERIV_ln: "0 < x \<Longrightarrow> DERIV ln x :> inverse x"
  1163 lemma DERIV_ln: "0 < x \<Longrightarrow> DERIV ln x :> inverse x"
  1196 apply (rule DERIV_inverse_function [where f=exp and a=0 and b="x+1"])
  1164   apply (rule DERIV_inverse_function [where f=exp and a=0 and b="x+1"])
  1197 apply (erule lemma_DERIV_subst [OF DERIV_exp exp_ln])
  1165   apply (erule lemma_DERIV_subst [OF DERIV_exp exp_ln])
  1198 apply (simp_all add: abs_if isCont_ln)
  1166   apply (simp_all add: abs_if isCont_ln)
  1199 done
  1167   done
  1200 
  1168 
  1201 lemma DERIV_ln_divide: "0 < x ==> DERIV ln x :> 1 / x"
  1169 lemma DERIV_ln_divide: "0 < x ==> DERIV ln x :> 1 / x"
  1202   by (rule DERIV_ln[THEN DERIV_cong], simp, simp add: divide_inverse)
  1170   by (rule DERIV_ln[THEN DERIV_cong], simp, simp add: divide_inverse)
  1203 
  1171 
  1204 lemma ln_series: assumes "0 < x" and "x < 2"
  1172 lemma ln_series: assumes "0 < x" and "x < 2"
  1234   thus ?thesis by auto
  1202   thus ?thesis by auto
  1235 qed
  1203 qed
  1236 
  1204 
  1237 subsection {* Sine and Cosine *}
  1205 subsection {* Sine and Cosine *}
  1238 
  1206 
  1239 definition
  1207 definition sin_coeff :: "nat \<Rightarrow> real" where
  1240   sin_coeff :: "nat \<Rightarrow> real" where
       
  1241   "sin_coeff = (\<lambda>n. if even n then 0 else -1 ^ ((n - Suc 0) div 2) / real (fact n))"
  1208   "sin_coeff = (\<lambda>n. if even n then 0 else -1 ^ ((n - Suc 0) div 2) / real (fact n))"
  1242 
  1209 
  1243 definition
  1210 definition cos_coeff :: "nat \<Rightarrow> real" where
  1244   cos_coeff :: "nat \<Rightarrow> real" where
       
  1245   "cos_coeff = (\<lambda>n. if even n then (-1 ^ (n div 2)) / real (fact n) else 0)"
  1211   "cos_coeff = (\<lambda>n. if even n then (-1 ^ (n div 2)) / real (fact n) else 0)"
  1246 
  1212 
  1247 definition
  1213 definition sin :: "real \<Rightarrow> real" where
  1248   sin :: "real => real" where
  1214   "sin = (\<lambda>x. \<Sum>n. sin_coeff n * x ^ n)"
  1249   "sin x = (\<Sum>n. sin_coeff n * x ^ n)"
  1215 
  1250 
  1216 definition cos :: "real \<Rightarrow> real" where
  1251 definition
  1217   "cos = (\<lambda>x. \<Sum>n. cos_coeff n * x ^ n)"
  1252   cos :: "real => real" where
       
  1253   "cos x = (\<Sum>n. cos_coeff n * x ^ n)"
       
  1254 
  1218 
  1255 lemma summable_sin: "summable (\<lambda>n. sin_coeff n * x ^ n)"
  1219 lemma summable_sin: "summable (\<lambda>n. sin_coeff n * x ^ n)"
  1256 unfolding sin_coeff_def
  1220 unfolding sin_coeff_def
  1257 apply (rule_tac g = "(%n. inverse (real (fact n)) * \<bar>x\<bar> ^ n)" in summable_comparison_test)
  1221 apply (rule summable_comparison_test [OF _ summable_exp [where x="\<bar>x\<bar>"]])
  1258 apply (rule_tac [2] summable_exp)
       
  1259 apply (rule_tac x = 0 in exI)
       
  1260 apply (auto simp add: divide_inverse abs_mult power_abs [symmetric] zero_le_mult_iff)
  1222 apply (auto simp add: divide_inverse abs_mult power_abs [symmetric] zero_le_mult_iff)
  1261 done
  1223 done
  1262 
  1224 
  1263 lemma summable_cos: "summable (\<lambda>n. cos_coeff n * x ^ n)"
  1225 lemma summable_cos: "summable (\<lambda>n. cos_coeff n * x ^ n)"
  1264 unfolding cos_coeff_def
  1226 unfolding cos_coeff_def
  1265 apply (rule_tac g = "(%n. inverse (real (fact n)) * \<bar>x\<bar> ^ n)" in summable_comparison_test)
  1227 apply (rule summable_comparison_test [OF _ summable_exp [where x="\<bar>x\<bar>"]])
  1266 apply (rule_tac [2] summable_exp)
       
  1267 apply (rule_tac x = 0 in exI)
       
  1268 apply (auto simp add: divide_inverse abs_mult power_abs [symmetric] zero_le_mult_iff)
  1228 apply (auto simp add: divide_inverse abs_mult power_abs [symmetric] zero_le_mult_iff)
  1269 done
  1229 done
  1270 
  1230 
  1271 lemma sin_converges: "(\<lambda>n. sin_coeff n * x ^ n) sums sin(x)"
  1231 lemma sin_converges: "(\<lambda>n. sin_coeff n * x ^ n) sums sin(x)"
  1272 unfolding sin_def by (rule summable_sin [THEN summable_sums])
  1232 unfolding sin_def by (rule summable_sin [THEN summable_sums])
  1295 text{*Now at last we can get the derivatives of exp, sin and cos*}
  1255 text{*Now at last we can get the derivatives of exp, sin and cos*}
  1296 
  1256 
  1297 lemma lemma_sin_minus: "- sin x = (\<Sum>n. - (sin_coeff n * x ^ n))"
  1257 lemma lemma_sin_minus: "- sin x = (\<Sum>n. - (sin_coeff n * x ^ n))"
  1298 by (auto intro!: sums_unique sums_minus sin_converges)
  1258 by (auto intro!: sums_unique sums_minus sin_converges)
  1299 
  1259 
  1300 lemma lemma_sin_ext: "sin = (\<lambda>x. \<Sum>n. sin_coeff n * x ^ n)"
       
  1301   by (auto simp add: sin_def)
       
  1302 
       
  1303 lemma lemma_cos_ext: "cos = (\<lambda>x. \<Sum>n. cos_coeff n * x ^ n)"
       
  1304   by (auto simp add: cos_def)
       
  1305 
       
  1306 lemma DERIV_sin [simp]: "DERIV sin x :> cos(x)"
  1260 lemma DERIV_sin [simp]: "DERIV sin x :> cos(x)"
  1307 apply (simp add: cos_def)
  1261 unfolding sin_def cos_def
  1308 apply (subst lemma_sin_ext)
       
  1309 apply (auto simp add: sin_fdiffs2 [symmetric])
  1262 apply (auto simp add: sin_fdiffs2 [symmetric])
  1310 apply (rule_tac K = "1 + \<bar>x\<bar>" in termdiffs)
  1263 apply (rule_tac K = "1 + \<bar>x\<bar>" in termdiffs)
  1311 apply (auto intro: sin_converges cos_converges sums_summable intro!: sums_minus [THEN sums_summable] simp add: cos_fdiffs sin_fdiffs)
  1264 apply (auto intro: sin_converges cos_converges sums_summable intro!: sums_minus [THEN sums_summable] simp add: cos_fdiffs sin_fdiffs)
  1312 done
  1265 done
  1313 
  1266 
  1314 lemma DERIV_cos [simp]: "DERIV cos x :> -sin(x)"
  1267 lemma DERIV_cos [simp]: "DERIV cos x :> -sin(x)"
  1315 apply (subst lemma_cos_ext)
  1268 unfolding cos_def
  1316 apply (auto simp add: lemma_sin_minus cos_fdiffs2 [symmetric] minus_mult_left)
  1269 apply (auto simp add: lemma_sin_minus cos_fdiffs2 [symmetric] minus_mult_left)
  1317 apply (rule_tac K = "1 + \<bar>x\<bar>" in termdiffs)
  1270 apply (rule_tac K = "1 + \<bar>x\<bar>" in termdiffs)
  1318 apply (auto intro: sin_converges cos_converges sums_summable intro!: sums_minus [THEN sums_summable] simp add: cos_fdiffs sin_fdiffs diffs_minus)
  1271 apply (auto intro: sin_converges cos_converges sums_summable intro!: sums_minus [THEN sums_summable] simp add: cos_fdiffs sin_fdiffs diffs_minus)
  1319 done
  1272 done
  1320 
  1273 
  1337 unfolding sin_def sin_coeff_def by (simp add: powser_zero)
  1290 unfolding sin_def sin_coeff_def by (simp add: powser_zero)
  1338 
  1291 
  1339 lemma cos_zero [simp]: "cos 0 = 1"
  1292 lemma cos_zero [simp]: "cos 0 = 1"
  1340 unfolding cos_def cos_coeff_def by (simp add: powser_zero)
  1293 unfolding cos_def cos_coeff_def by (simp add: powser_zero)
  1341 
  1294 
  1342 lemma DERIV_sin_sin_mult [simp]:
       
  1343      "DERIV (%x. sin(x)*sin(x)) x :> cos(x) * sin(x) + cos(x) * sin(x)"
       
  1344 by (rule DERIV_mult, auto)
       
  1345 
       
  1346 lemma DERIV_sin_sin_mult2 [simp]:
       
  1347      "DERIV (%x. sin(x)*sin(x)) x :> 2 * cos(x) * sin(x)"
       
  1348 apply (cut_tac x = x in DERIV_sin_sin_mult)
       
  1349 apply (auto simp add: mult_assoc)
       
  1350 done
       
  1351 
       
  1352 lemma DERIV_sin_realpow2 [simp]:
       
  1353      "DERIV (%x. (sin x)\<twosuperior>) x :> cos(x) * sin(x) + cos(x) * sin(x)"
       
  1354 by (auto simp add: numeral_2_eq_2 mult_assoc [symmetric])
       
  1355 
       
  1356 lemma DERIV_sin_realpow2a [simp]:
       
  1357      "DERIV (%x. (sin x)\<twosuperior>) x :> 2 * cos(x) * sin(x)"
       
  1358 by (auto simp add: numeral_2_eq_2)
       
  1359 
       
  1360 lemma DERIV_cos_cos_mult [simp]:
       
  1361      "DERIV (%x. cos(x)*cos(x)) x :> -sin(x) * cos(x) + -sin(x) * cos(x)"
       
  1362 by (rule DERIV_mult, auto)
       
  1363 
       
  1364 lemma DERIV_cos_cos_mult2 [simp]:
       
  1365      "DERIV (%x. cos(x)*cos(x)) x :> -2 * cos(x) * sin(x)"
       
  1366 apply (cut_tac x = x in DERIV_cos_cos_mult)
       
  1367 apply (auto simp add: mult_ac)
       
  1368 done
       
  1369 
       
  1370 lemma DERIV_cos_realpow2 [simp]:
       
  1371      "DERIV (%x. (cos x)\<twosuperior>) x :> -sin(x) * cos(x) + -sin(x) * cos(x)"
       
  1372 by (auto simp add: numeral_2_eq_2 mult_assoc [symmetric])
       
  1373 
       
  1374 lemma DERIV_cos_realpow2a [simp]:
       
  1375      "DERIV (%x. (cos x)\<twosuperior>) x :> -2 * cos(x) * sin(x)"
       
  1376 by (auto simp add: numeral_2_eq_2)
       
  1377 
       
  1378 lemma lemma_DERIV_subst: "[| DERIV f x :> D; D = E |] ==> DERIV f x :> E"
  1295 lemma lemma_DERIV_subst: "[| DERIV f x :> D; D = E |] ==> DERIV f x :> E"
  1379 by auto
  1296   by (rule DERIV_cong) (* TODO: delete *)
  1380 
  1297 
  1381 lemma DERIV_cos_realpow2b: "DERIV (%x. (cos x)\<twosuperior>) x :> -(2 * cos(x) * sin(x))"
  1298 lemma sin_cos_squared_add [simp]: "(sin x)\<twosuperior> + (cos x)\<twosuperior> = 1"
  1382   by (auto intro!: DERIV_intros)
  1299 proof -
  1383 
  1300   have "\<forall>x. DERIV (\<lambda>x. (sin x)\<twosuperior> + (cos x)\<twosuperior>) x :> 0"
  1384 (* most useful *)
  1301     by (auto intro!: DERIV_intros)
  1385 lemma DERIV_cos_cos_mult3 [simp]:
  1302   hence "(sin x)\<twosuperior> + (cos x)\<twosuperior> = (sin 0)\<twosuperior> + (cos 0)\<twosuperior>"
  1386      "DERIV (%x. cos(x)*cos(x)) x :> -(2 * cos(x) * sin(x))"
  1303     by (rule DERIV_isconst_all)
  1387   by (auto intro!: DERIV_intros)
  1304   thus "(sin x)\<twosuperior> + (cos x)\<twosuperior> = 1" by simp
  1388 
  1305 qed
  1389 lemma DERIV_sin_circle_all:
  1306 
  1390      "\<forall>x. DERIV (%x. (sin x)\<twosuperior> + (cos x)\<twosuperior>) x :>
  1307 lemma sin_cos_squared_add2 [simp]: "(cos x)\<twosuperior> + (sin x)\<twosuperior> = 1"
  1391              (2*cos(x)*sin(x) - 2*cos(x)*sin(x))"
  1308   by (subst add_commute, rule sin_cos_squared_add)
  1392   by (auto intro!: DERIV_intros)
       
  1393 
       
  1394 lemma DERIV_sin_circle_all_zero [simp]:
       
  1395      "\<forall>x. DERIV (%x. (sin x)\<twosuperior> + (cos x)\<twosuperior>) x :> 0"
       
  1396 by (cut_tac DERIV_sin_circle_all, auto)
       
  1397 
       
  1398 lemma sin_cos_squared_add [simp]: "((sin x)\<twosuperior>) + ((cos x)\<twosuperior>) = 1"
       
  1399 apply (cut_tac x = x and y = 0 in DERIV_sin_circle_all_zero [THEN DERIV_isconst_all])
       
  1400 apply (auto simp add: numeral_2_eq_2)
       
  1401 done
       
  1402 
       
  1403 lemma sin_cos_squared_add2 [simp]: "((cos x)\<twosuperior>) + ((sin x)\<twosuperior>) = 1"
       
  1404 apply (subst add_commute)
       
  1405 apply (rule sin_cos_squared_add)
       
  1406 done
       
  1407 
  1309 
  1408 lemma sin_cos_squared_add3 [simp]: "cos x * cos x + sin x * sin x = 1"
  1310 lemma sin_cos_squared_add3 [simp]: "cos x * cos x + sin x * sin x = 1"
  1409 apply (cut_tac x = x in sin_cos_squared_add2)
  1311   using sin_cos_squared_add2 [unfolded power2_eq_square] .
  1410 apply (simp add: power2_eq_square)
       
  1411 done
       
  1412 
  1312 
  1413 lemma sin_squared_eq: "(sin x)\<twosuperior> = 1 - (cos x)\<twosuperior>"
  1313 lemma sin_squared_eq: "(sin x)\<twosuperior> = 1 - (cos x)\<twosuperior>"
  1414 apply (rule_tac a1 = "(cos x)\<twosuperior>" in add_right_cancel [THEN iffD1])
  1314   unfolding eq_diff_eq by (rule sin_cos_squared_add)
  1415 apply simp
       
  1416 done
       
  1417 
  1315 
  1418 lemma cos_squared_eq: "(cos x)\<twosuperior> = 1 - (sin x)\<twosuperior>"
  1316 lemma cos_squared_eq: "(cos x)\<twosuperior> = 1 - (sin x)\<twosuperior>"
  1419 apply (rule_tac a1 = "(sin x)\<twosuperior>" in add_right_cancel [THEN iffD1])
  1317   unfolding eq_diff_eq by (rule sin_cos_squared_add2)
  1420 apply simp
       
  1421 done
       
  1422 
  1318 
  1423 lemma abs_sin_le_one [simp]: "\<bar>sin x\<bar> \<le> 1"
  1319 lemma abs_sin_le_one [simp]: "\<bar>sin x\<bar> \<le> 1"
  1424 by (rule power2_le_imp_le, simp_all add: sin_squared_eq)
  1320   by (rule power2_le_imp_le, simp_all add: sin_squared_eq)
  1425 
  1321 
  1426 lemma sin_ge_minus_one [simp]: "-1 \<le> sin x"
  1322 lemma sin_ge_minus_one [simp]: "-1 \<le> sin x"
  1427 apply (insert abs_sin_le_one [of x])
  1323   using abs_sin_le_one [of x] unfolding abs_le_iff by simp
  1428 apply (simp add: abs_le_iff del: abs_sin_le_one)
       
  1429 done
       
  1430 
  1324 
  1431 lemma sin_le_one [simp]: "sin x \<le> 1"
  1325 lemma sin_le_one [simp]: "sin x \<le> 1"
  1432 apply (insert abs_sin_le_one [of x])
  1326   using abs_sin_le_one [of x] unfolding abs_le_iff by simp
  1433 apply (simp add: abs_le_iff del: abs_sin_le_one)
       
  1434 done
       
  1435 
  1327 
  1436 lemma abs_cos_le_one [simp]: "\<bar>cos x\<bar> \<le> 1"
  1328 lemma abs_cos_le_one [simp]: "\<bar>cos x\<bar> \<le> 1"
  1437 by (rule power2_le_imp_le, simp_all add: cos_squared_eq)
  1329   by (rule power2_le_imp_le, simp_all add: cos_squared_eq)
  1438 
  1330 
  1439 lemma cos_ge_minus_one [simp]: "-1 \<le> cos x"
  1331 lemma cos_ge_minus_one [simp]: "-1 \<le> cos x"
  1440 apply (insert abs_cos_le_one [of x])
  1332   using abs_cos_le_one [of x] unfolding abs_le_iff by simp
  1441 apply (simp add: abs_le_iff del: abs_cos_le_one)
       
  1442 done
       
  1443 
  1333 
  1444 lemma cos_le_one [simp]: "cos x \<le> 1"
  1334 lemma cos_le_one [simp]: "cos x \<le> 1"
  1445 apply (insert abs_cos_le_one [of x])
  1335   using abs_cos_le_one [of x] unfolding abs_le_iff by simp
  1446 apply (simp add: abs_le_iff del: abs_cos_le_one)
       
  1447 done
       
  1448 
  1336 
  1449 lemma DERIV_fun_pow: "DERIV g x :> m ==>
  1337 lemma DERIV_fun_pow: "DERIV g x :> m ==>
  1450       DERIV (%x. (g x) ^ n) x :> real n * (g x) ^ (n - 1) * m"
  1338       DERIV (%x. (g x) ^ n) x :> real n * (g x) ^ (n - 1) * m"
  1451 unfolding One_nat_def
  1339 unfolding One_nat_def
  1452 apply (rule lemma_DERIV_subst)
  1340 apply (rule DERIV_cong)
  1453 apply (rule_tac f = "(%x. x ^ n)" in DERIV_chain2)
  1341 apply (rule_tac f = "(%x. x ^ n)" in DERIV_chain2)
  1454 apply (rule DERIV_pow, auto)
  1342 apply (rule DERIV_pow, auto)
  1455 done
  1343 done
  1456 
  1344 
  1457 lemma DERIV_fun_exp:
  1345 lemma DERIV_fun_exp:
  1458      "DERIV g x :> m ==> DERIV (%x. exp(g x)) x :> exp(g x) * m"
  1346      "DERIV g x :> m ==> DERIV (%x. exp(g x)) x :> exp(g x) * m"
  1459 apply (rule lemma_DERIV_subst)
  1347 apply (rule DERIV_cong)
  1460 apply (rule_tac f = exp in DERIV_chain2)
  1348 apply (rule_tac f = exp in DERIV_chain2)
  1461 apply (rule DERIV_exp, auto)
  1349 apply (rule DERIV_exp, auto)
  1462 done
  1350 done
  1463 
  1351 
  1464 lemma DERIV_fun_sin:
  1352 lemma DERIV_fun_sin:
  1465      "DERIV g x :> m ==> DERIV (%x. sin(g x)) x :> cos(g x) * m"
  1353      "DERIV g x :> m ==> DERIV (%x. sin(g x)) x :> cos(g x) * m"
  1466 apply (rule lemma_DERIV_subst)
  1354 apply (rule DERIV_cong)
  1467 apply (rule_tac f = sin in DERIV_chain2)
  1355 apply (rule_tac f = sin in DERIV_chain2)
  1468 apply (rule DERIV_sin, auto)
  1356 apply (rule DERIV_sin, auto)
  1469 done
  1357 done
  1470 
  1358 
  1471 lemma DERIV_fun_cos:
  1359 lemma DERIV_fun_cos:
  1472      "DERIV g x :> m ==> DERIV (%x. cos(g x)) x :> -sin(g x) * m"
  1360      "DERIV g x :> m ==> DERIV (%x. cos(g x)) x :> -sin(g x) * m"
  1473 apply (rule lemma_DERIV_subst)
  1361 apply (rule DERIV_cong)
  1474 apply (rule_tac f = cos in DERIV_chain2)
  1362 apply (rule_tac f = cos in DERIV_chain2)
  1475 apply (rule DERIV_cos, auto)
  1363 apply (rule DERIV_cos, auto)
  1476 done
  1364 done
  1477 
  1365 
  1478 (* lemma *)
  1366 lemma sin_cos_add_lemma:
  1479 lemma lemma_DERIV_sin_cos_add:
       
  1480      "\<forall>x.
       
  1481          DERIV (%x. (sin (x + y) - (sin x * cos y + cos x * sin y)) ^ 2 +
       
  1482                (cos (x + y) - (cos x * cos y - sin x * sin y)) ^ 2) x :> 0"
       
  1483   by (auto intro!: DERIV_intros simp add: algebra_simps)
       
  1484 
       
  1485 lemma sin_cos_add [simp]:
       
  1486      "(sin (x + y) - (sin x * cos y + cos x * sin y)) ^ 2 +
  1367      "(sin (x + y) - (sin x * cos y + cos x * sin y)) ^ 2 +
  1487       (cos (x + y) - (cos x * cos y - sin x * sin y)) ^ 2 = 0"
  1368       (cos (x + y) - (cos x * cos y - sin x * sin y)) ^ 2 = 0"
  1488 apply (cut_tac y = 0 and x = x and y7 = y
  1369   (is "?f x = 0")
  1489        in lemma_DERIV_sin_cos_add [THEN DERIV_isconst_all])
  1370 proof -
  1490 apply (auto simp add: numeral_2_eq_2)
  1371   have "\<forall>x. DERIV (\<lambda>x. ?f x) x :> 0"
  1491 done
  1372     by (auto intro!: DERIV_intros simp add: algebra_simps)
       
  1373   hence "?f x = ?f 0"
       
  1374     by (rule DERIV_isconst_all)
       
  1375   thus ?thesis by simp
       
  1376 qed
  1492 
  1377 
  1493 lemma sin_add: "sin (x + y) = sin x * cos y + cos x * sin y"
  1378 lemma sin_add: "sin (x + y) = sin x * cos y + cos x * sin y"
  1494 apply (cut_tac x = x and y = y in sin_cos_add)
  1379   using sin_cos_add_lemma unfolding realpow_two_sum_zero_iff by simp
  1495 apply (simp del: sin_cos_add)
       
  1496 done
       
  1497 
  1380 
  1498 lemma cos_add: "cos (x + y) = cos x * cos y - sin x * sin y"
  1381 lemma cos_add: "cos (x + y) = cos x * cos y - sin x * sin y"
  1499 apply (cut_tac x = x and y = y in sin_cos_add)
  1382   using sin_cos_add_lemma unfolding realpow_two_sum_zero_iff by simp
  1500 apply (simp del: sin_cos_add)
  1383 
  1501 done
  1384 lemma sin_cos_minus_lemma:
  1502 
  1385   "(sin(-x) + sin(x))\<twosuperior> + (cos(-x) - cos(x))\<twosuperior> = 0" (is "?f x = 0")
  1503 lemma lemma_DERIV_sin_cos_minus:
  1386 proof -
  1504     "\<forall>x. DERIV (%x. (sin(-x) + (sin x)) ^ 2 + (cos(-x) - (cos x)) ^ 2) x :> 0"
  1387   have "\<forall>x. DERIV (\<lambda>x. ?f x) x :> 0"
  1505   by (auto intro!: DERIV_intros simp add: algebra_simps)
  1388     by (auto intro!: DERIV_intros simp add: algebra_simps)
  1506 
  1389   hence "?f x = ?f 0"
  1507 
  1390     by (rule DERIV_isconst_all)
  1508 lemma sin_cos_minus:
  1391   thus ?thesis by simp
  1509     "(sin(-x) + (sin x)) ^ 2 + (cos(-x) - (cos x)) ^ 2 = 0"
  1392 qed
  1510 apply (cut_tac y = 0 and x = x
       
  1511        in lemma_DERIV_sin_cos_minus [THEN DERIV_isconst_all])
       
  1512 apply simp
       
  1513 done
       
  1514 
  1393 
  1515 lemma sin_minus [simp]: "sin (-x) = -sin(x)"
  1394 lemma sin_minus [simp]: "sin (-x) = -sin(x)"
  1516   using sin_cos_minus [where x=x] by simp
  1395   using sin_cos_minus_lemma [where x=x] by simp
  1517 
  1396 
  1518 lemma cos_minus [simp]: "cos (-x) = cos(x)"
  1397 lemma cos_minus [simp]: "cos (-x) = cos(x)"
  1519   using sin_cos_minus [where x=x] by simp
  1398   using sin_cos_minus_lemma [where x=x] by simp
  1520 
  1399 
  1521 lemma sin_diff: "sin (x - y) = sin x * cos y - cos x * sin y"
  1400 lemma sin_diff: "sin (x - y) = sin x * cos y - cos x * sin y"
  1522 by (simp add: diff_minus sin_add)
  1401   by (simp add: diff_minus sin_add)
  1523 
  1402 
  1524 lemma sin_diff2: "sin (x - y) = cos y * sin x - sin y * cos x"
  1403 lemma sin_diff2: "sin (x - y) = cos y * sin x - sin y * cos x"
  1525 by (simp add: sin_diff mult_commute)
  1404   by (simp add: sin_diff mult_commute)
  1526 
  1405 
  1527 lemma cos_diff: "cos (x - y) = cos x * cos y + sin x * sin y"
  1406 lemma cos_diff: "cos (x - y) = cos x * cos y + sin x * sin y"
  1528 by (simp add: diff_minus cos_add)
  1407   by (simp add: diff_minus cos_add)
  1529 
  1408 
  1530 lemma cos_diff2: "cos (x - y) = cos y * cos x + sin y * sin x"
  1409 lemma cos_diff2: "cos (x - y) = cos y * cos x + sin y * sin x"
  1531 by (simp add: cos_diff mult_commute)
  1410   by (simp add: cos_diff mult_commute)
  1532 
  1411 
  1533 lemma sin_double [simp]: "sin(2 * x) = 2* sin x * cos x"
  1412 lemma sin_double [simp]: "sin(2 * x) = 2* sin x * cos x"
  1534   using sin_add [where x=x and y=x] by simp
  1413   using sin_add [where x=x and y=x] by simp
  1535 
  1414 
  1536 lemma cos_double: "cos(2* x) = ((cos x)\<twosuperior>) - ((sin x)\<twosuperior>)"
  1415 lemma cos_double: "cos(2* x) = ((cos x)\<twosuperior>) - ((sin x)\<twosuperior>)"
  1538   by (simp add: power2_eq_square)
  1417   by (simp add: power2_eq_square)
  1539 
  1418 
  1540 
  1419 
  1541 subsection {* The Constant Pi *}
  1420 subsection {* The Constant Pi *}
  1542 
  1421 
  1543 definition
  1422 definition pi :: "real" where
  1544   pi :: "real" where
       
  1545   "pi = 2 * (THE x. 0 \<le> (x::real) & x \<le> 2 & cos x = 0)"
  1423   "pi = 2 * (THE x. 0 \<le> (x::real) & x \<le> 2 & cos x = 0)"
  1546 
  1424 
  1547 text{*Show that there's a least positive @{term x} with @{term "cos(x) = 0"};
  1425 text{*Show that there's a least positive @{term x} with @{term "cos(x) = 0"};
  1548    hence define pi.*}
  1426    hence define pi.*}
  1549 
  1427 
  2427 done
  2305 done
  2428 
  2306 
  2429 lemma DERIV_arcsin:
  2307 lemma DERIV_arcsin:
  2430   "\<lbrakk>-1 < x; x < 1\<rbrakk> \<Longrightarrow> DERIV arcsin x :> inverse (sqrt (1 - x\<twosuperior>))"
  2308   "\<lbrakk>-1 < x; x < 1\<rbrakk> \<Longrightarrow> DERIV arcsin x :> inverse (sqrt (1 - x\<twosuperior>))"
  2431 apply (rule DERIV_inverse_function [where f=sin and a="-1" and b="1"])
  2309 apply (rule DERIV_inverse_function [where f=sin and a="-1" and b="1"])
  2432 apply (rule lemma_DERIV_subst [OF DERIV_sin])
  2310 apply (rule DERIV_cong [OF DERIV_sin])
  2433 apply (simp add: cos_arcsin)
  2311 apply (simp add: cos_arcsin)
  2434 apply (subgoal_tac "\<bar>x\<bar>\<twosuperior> < 1\<twosuperior>", simp)
  2312 apply (subgoal_tac "\<bar>x\<bar>\<twosuperior> < 1\<twosuperior>", simp)
  2435 apply (rule power_strict_mono, simp, simp, simp)
  2313 apply (rule power_strict_mono, simp, simp, simp)
  2436 apply assumption
  2314 apply assumption
  2437 apply assumption
  2315 apply assumption
  2440 done
  2318 done
  2441 
  2319 
  2442 lemma DERIV_arccos:
  2320 lemma DERIV_arccos:
  2443   "\<lbrakk>-1 < x; x < 1\<rbrakk> \<Longrightarrow> DERIV arccos x :> inverse (- sqrt (1 - x\<twosuperior>))"
  2321   "\<lbrakk>-1 < x; x < 1\<rbrakk> \<Longrightarrow> DERIV arccos x :> inverse (- sqrt (1 - x\<twosuperior>))"
  2444 apply (rule DERIV_inverse_function [where f=cos and a="-1" and b="1"])
  2322 apply (rule DERIV_inverse_function [where f=cos and a="-1" and b="1"])
  2445 apply (rule lemma_DERIV_subst [OF DERIV_cos])
  2323 apply (rule DERIV_cong [OF DERIV_cos])
  2446 apply (simp add: sin_arccos)
  2324 apply (simp add: sin_arccos)
  2447 apply (subgoal_tac "\<bar>x\<bar>\<twosuperior> < 1\<twosuperior>", simp)
  2325 apply (subgoal_tac "\<bar>x\<bar>\<twosuperior> < 1\<twosuperior>", simp)
  2448 apply (rule power_strict_mono, simp, simp, simp)
  2326 apply (rule power_strict_mono, simp, simp, simp)
  2449 apply assumption
  2327 apply assumption
  2450 apply assumption
  2328 apply assumption
  2452 apply (erule (1) isCont_arccos)
  2330 apply (erule (1) isCont_arccos)
  2453 done
  2331 done
  2454 
  2332 
  2455 lemma DERIV_arctan: "DERIV arctan x :> inverse (1 + x\<twosuperior>)"
  2333 lemma DERIV_arctan: "DERIV arctan x :> inverse (1 + x\<twosuperior>)"
  2456 apply (rule DERIV_inverse_function [where f=tan and a="x - 1" and b="x + 1"])
  2334 apply (rule DERIV_inverse_function [where f=tan and a="x - 1" and b="x + 1"])
  2457 apply (rule lemma_DERIV_subst [OF DERIV_tan])
  2335 apply (rule DERIV_cong [OF DERIV_tan])
  2458 apply (rule cos_arctan_not_zero)
  2336 apply (rule cos_arctan_not_zero)
  2459 apply (simp add: power_inverse tan_sec [symmetric])
  2337 apply (simp add: power_inverse tan_sec [symmetric])
  2460 apply (subgoal_tac "0 < 1 + x\<twosuperior>", simp)
  2338 apply (subgoal_tac "0 < 1 + x\<twosuperior>", simp)
  2461 apply (simp add: add_pos_nonneg)
  2339 apply (simp add: add_pos_nonneg)
  2462 apply (simp, simp, simp, rule isCont_arctan)
  2340 apply (simp, simp, simp, rule isCont_arctan)
  2541 unfolding tan_def by (simp add: sin_45 cos_45)
  2419 unfolding tan_def by (simp add: sin_45 cos_45)
  2542 
  2420 
  2543 lemma tan_60: "tan (pi / 3) = sqrt 3"
  2421 lemma tan_60: "tan (pi / 3) = sqrt 3"
  2544 unfolding tan_def by (simp add: sin_60 cos_60)
  2422 unfolding tan_def by (simp add: sin_60 cos_60)
  2545 
  2423 
  2546 lemma DERIV_sin_add [simp]: "DERIV (%x. sin (x + k)) xa :> cos (xa + k)"
  2424 lemma DERIV_sin_add: "DERIV (%x. sin (x + k)) xa :> cos (xa + k)"
  2547   by (auto intro!: DERIV_intros)
  2425   by (auto intro!: DERIV_intros) (* TODO: delete *)
  2548 
  2426 
  2549 lemma sin_cos_npi [simp]: "sin (real (Suc (2 * n)) * pi / 2) = (-1) ^ n"
  2427 lemma sin_cos_npi [simp]: "sin (real (Suc (2 * n)) * pi / 2) = (-1) ^ n"
  2550 proof -
  2428 proof -
  2551   have "sin ((real n + 1/2) * pi) = cos (real n * pi)"
  2429   have "sin ((real n + 1/2) * pi) = cos (real n * pi)"
  2552     by (auto simp add: algebra_simps sin_add)
  2430     by (auto simp add: algebra_simps sin_add)