src/HOL/Transcendental.thy
changeset 31271 0237e5e40b71
parent 31148 7ba7c1f8bc22
child 31338 d41a8ba25b67
equal deleted inserted replaced
31269:dcbe1f9fe2cd 31271:0237e5e40b71
  1250 qed
  1250 qed
  1251 
  1251 
  1252 subsection {* Sine and Cosine *}
  1252 subsection {* Sine and Cosine *}
  1253 
  1253 
  1254 definition
  1254 definition
       
  1255   sin_coeff :: "nat \<Rightarrow> real" where
       
  1256   "sin_coeff = (\<lambda>n. if even n then 0 else -1 ^ ((n - Suc 0) div 2) / real (fact n))"
       
  1257 
       
  1258 definition
       
  1259   cos_coeff :: "nat \<Rightarrow> real" where
       
  1260   "cos_coeff = (\<lambda>n. if even n then (-1 ^ (n div 2)) / real (fact n) else 0)"
       
  1261 
       
  1262 definition
  1255   sin :: "real => real" where
  1263   sin :: "real => real" where
  1256   "sin x = (\<Sum>n. (if even(n) then 0 else
  1264   "sin x = (\<Sum>n. sin_coeff n * x ^ n)"
  1257              (-1 ^ ((n - Suc 0) div 2))/(real (fact n))) * x ^ n)"
  1265 
  1258  
       
  1259 definition
  1266 definition
  1260   cos :: "real => real" where
  1267   cos :: "real => real" where
  1261   "cos x = (\<Sum>n. (if even(n) then (-1 ^ (n div 2))/(real (fact n)) 
  1268   "cos x = (\<Sum>n. cos_coeff n * x ^ n)"
  1262                             else 0) * x ^ n)"
  1269 
  1263 
  1270 lemma summable_sin: "summable (\<lambda>n. sin_coeff n * x ^ n)"
  1264 lemma summable_sin: 
  1271 unfolding sin_coeff_def
  1265      "summable (%n.  
       
  1266            (if even n then 0  
       
  1267            else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) *  
       
  1268                 x ^ n)"
       
  1269 apply (rule_tac g = "(%n. inverse (real (fact n)) * \<bar>x\<bar> ^ n)" in summable_comparison_test)
  1272 apply (rule_tac g = "(%n. inverse (real (fact n)) * \<bar>x\<bar> ^ n)" in summable_comparison_test)
  1270 apply (rule_tac [2] summable_exp)
  1273 apply (rule_tac [2] summable_exp)
  1271 apply (rule_tac x = 0 in exI)
  1274 apply (rule_tac x = 0 in exI)
  1272 apply (auto simp add: divide_inverse abs_mult power_abs [symmetric] zero_le_mult_iff)
  1275 apply (auto simp add: divide_inverse abs_mult power_abs [symmetric] zero_le_mult_iff)
  1273 done
  1276 done
  1274 
  1277 
  1275 lemma summable_cos: 
  1278 lemma summable_cos: "summable (\<lambda>n. cos_coeff n * x ^ n)"
  1276       "summable (%n.  
  1279 unfolding cos_coeff_def
  1277            (if even n then  
       
  1278            -1 ^ (n div 2)/(real (fact n)) else 0) * x ^ n)"
       
  1279 apply (rule_tac g = "(%n. inverse (real (fact n)) * \<bar>x\<bar> ^ n)" in summable_comparison_test)
  1280 apply (rule_tac g = "(%n. inverse (real (fact n)) * \<bar>x\<bar> ^ n)" in summable_comparison_test)
  1280 apply (rule_tac [2] summable_exp)
  1281 apply (rule_tac [2] summable_exp)
  1281 apply (rule_tac x = 0 in exI)
  1282 apply (rule_tac x = 0 in exI)
  1282 apply (auto simp add: divide_inverse abs_mult power_abs [symmetric] zero_le_mult_iff)
  1283 apply (auto simp add: divide_inverse abs_mult power_abs [symmetric] zero_le_mult_iff)
  1283 done
  1284 done
  1302                          else 0) = 0"
  1303                          else 0) = 0"
  1303 apply (induct "n")
  1304 apply (induct "n")
  1304 apply (case_tac [2] "n", auto)
  1305 apply (case_tac [2] "n", auto)
  1305 done
  1306 done
  1306 
  1307 
  1307 lemma sin_converges: 
  1308 lemma sin_converges: "(\<lambda>n. sin_coeff n * x ^ n) sums sin(x)"
  1308       "(%n. (if even n then 0  
       
  1309             else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) *  
       
  1310                  x ^ n) sums sin(x)"
       
  1311 unfolding sin_def by (rule summable_sin [THEN summable_sums])
  1309 unfolding sin_def by (rule summable_sin [THEN summable_sums])
  1312 
  1310 
  1313 lemma cos_converges: 
  1311 lemma cos_converges: "(\<lambda>n. cos_coeff n * x ^ n) sums cos(x)"
  1314       "(%n. (if even n then  
       
  1315            -1 ^ (n div 2)/(real (fact n))  
       
  1316            else 0) * x ^ n) sums cos(x)"
       
  1317 unfolding cos_def by (rule summable_cos [THEN summable_sums])
  1312 unfolding cos_def by (rule summable_cos [THEN summable_sums])
  1318 
  1313 
  1319 lemma sin_fdiffs: 
  1314 lemma sin_fdiffs: "diffs sin_coeff = cos_coeff"
  1320       "diffs(%n. if even n then 0  
  1315 unfolding sin_coeff_def cos_coeff_def
  1321            else -1 ^ ((n - Suc 0) div 2)/(real (fact n)))  
       
  1322        = (%n. if even n then  
       
  1323                  -1 ^ (n div 2)/(real (fact n))  
       
  1324               else 0)"
       
  1325 by (auto intro!: ext 
  1316 by (auto intro!: ext 
  1326          simp add: diffs_def divide_inverse real_of_nat_def of_nat_mult
  1317          simp add: diffs_def divide_inverse real_of_nat_def of_nat_mult
  1327          simp del: mult_Suc of_nat_Suc)
  1318          simp del: mult_Suc of_nat_Suc)
  1328 
  1319 
  1329 lemma sin_fdiffs2: 
  1320 lemma sin_fdiffs2: "diffs sin_coeff n = cos_coeff n"
  1330        "diffs(%n. if even n then 0  
       
  1331            else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) n  
       
  1332        = (if even n then  
       
  1333                  -1 ^ (n div 2)/(real (fact n))  
       
  1334               else 0)"
       
  1335 by (simp only: sin_fdiffs)
  1321 by (simp only: sin_fdiffs)
  1336 
  1322 
  1337 lemma cos_fdiffs: 
  1323 lemma cos_fdiffs: "diffs cos_coeff = (\<lambda>n. - sin_coeff n)"
  1338       "diffs(%n. if even n then  
  1324 unfolding sin_coeff_def cos_coeff_def
  1339                  -1 ^ (n div 2)/(real (fact n)) else 0)  
       
  1340        = (%n. - (if even n then 0  
       
  1341            else -1 ^ ((n - Suc 0)div 2)/(real (fact n))))"
       
  1342 by (auto intro!: ext 
  1325 by (auto intro!: ext 
  1343          simp add: diffs_def divide_inverse odd_Suc_mult_two_ex real_of_nat_def of_nat_mult
  1326          simp add: diffs_def divide_inverse odd_Suc_mult_two_ex real_of_nat_def of_nat_mult
  1344          simp del: mult_Suc of_nat_Suc)
  1327          simp del: mult_Suc of_nat_Suc)
  1345 
  1328 
  1346 
  1329 lemma cos_fdiffs2: "diffs cos_coeff n = - sin_coeff n"
  1347 lemma cos_fdiffs2: 
       
  1348       "diffs(%n. if even n then  
       
  1349                  -1 ^ (n div 2)/(real (fact n)) else 0) n 
       
  1350        = - (if even n then 0  
       
  1351            else -1 ^ ((n - Suc 0)div 2)/(real (fact n)))"
       
  1352 by (simp only: cos_fdiffs)
  1330 by (simp only: cos_fdiffs)
  1353 
  1331 
  1354 text{*Now at last we can get the derivatives of exp, sin and cos*}
  1332 text{*Now at last we can get the derivatives of exp, sin and cos*}
  1355 
  1333 
  1356 lemma lemma_sin_minus:
  1334 lemma lemma_sin_minus: "- sin x = (\<Sum>n. - (sin_coeff n * x ^ n))"
  1357      "- sin x = (\<Sum>n. - ((if even n then 0 
       
  1358                   else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) * x ^ n))"
       
  1359 by (auto intro!: sums_unique sums_minus sin_converges)
  1335 by (auto intro!: sums_unique sums_minus sin_converges)
  1360 
  1336 
  1361 lemma lemma_sin_ext:
  1337 lemma lemma_sin_ext: "sin = (\<lambda>x. \<Sum>n. sin_coeff n * x ^ n)"
  1362      "sin = (%x. \<Sum>n. 
       
  1363                    (if even n then 0  
       
  1364                        else -1 ^ ((n - Suc 0) div 2)/(real (fact n))) *  
       
  1365                    x ^ n)"
       
  1366 by (auto intro!: ext simp add: sin_def)
  1338 by (auto intro!: ext simp add: sin_def)
  1367 
  1339 
  1368 lemma lemma_cos_ext:
  1340 lemma lemma_cos_ext: "cos = (\<lambda>x. \<Sum>n. cos_coeff n * x ^ n)"
  1369      "cos = (%x. \<Sum>n. 
       
  1370                    (if even n then -1 ^ (n div 2)/(real (fact n)) else 0) *
       
  1371                    x ^ n)"
       
  1372 by (auto intro!: ext simp add: cos_def)
  1341 by (auto intro!: ext simp add: cos_def)
  1373 
  1342 
  1374 lemma DERIV_sin [simp]: "DERIV sin x :> cos(x)"
  1343 lemma DERIV_sin [simp]: "DERIV sin x :> cos(x)"
  1375 apply (simp add: cos_def)
  1344 apply (simp add: cos_def)
  1376 apply (subst lemma_sin_ext)
  1345 apply (subst lemma_sin_ext)
  1394 
  1363 
  1395 
  1364 
  1396 subsection {* Properties of Sine and Cosine *}
  1365 subsection {* Properties of Sine and Cosine *}
  1397 
  1366 
  1398 lemma sin_zero [simp]: "sin 0 = 0"
  1367 lemma sin_zero [simp]: "sin 0 = 0"
  1399 unfolding sin_def by (simp add: powser_zero)
  1368 unfolding sin_def sin_coeff_def by (simp add: powser_zero)
  1400 
  1369 
  1401 lemma cos_zero [simp]: "cos 0 = 1"
  1370 lemma cos_zero [simp]: "cos 0 = 1"
  1402 unfolding cos_def by (simp add: powser_zero)
  1371 unfolding cos_def cos_coeff_def by (simp add: powser_zero)
  1403 
  1372 
  1404 lemma DERIV_sin_sin_mult [simp]:
  1373 lemma DERIV_sin_sin_mult [simp]:
  1405      "DERIV (%x. sin(x)*sin(x)) x :> cos(x) * sin(x) + cos(x) * sin(x)"
  1374      "DERIV (%x. sin(x)*sin(x)) x :> cos(x) * sin(x) + cos(x) * sin(x)"
  1406 by (rule DERIV_mult, auto)
  1375 by (rule DERIV_mult, auto)
  1407 
  1376 
  1630 
  1599 
  1631 lemma sin_paired:
  1600 lemma sin_paired:
  1632      "(%n. -1 ^ n /(real (fact (2 * n + 1))) * x ^ (2 * n + 1)) 
  1601      "(%n. -1 ^ n /(real (fact (2 * n + 1))) * x ^ (2 * n + 1)) 
  1633       sums  sin x"
  1602       sums  sin x"
  1634 proof -
  1603 proof -
  1635   have "(\<lambda>n. \<Sum>k = n * 2..<n * 2 + 2.
  1604   have "(\<lambda>n. \<Sum>k = n * 2..<n * 2 + 2. sin_coeff k * x ^ k) sums sin x"
  1636             (if even k then 0
       
  1637              else -1 ^ ((k - Suc 0) div 2) / real (fact k)) *
       
  1638             x ^ k) 
       
  1639 	sums sin x"
       
  1640     unfolding sin_def
  1605     unfolding sin_def
  1641     by (rule sin_converges [THEN sums_summable, THEN sums_group], simp) 
  1606     by (rule sin_converges [THEN sums_summable, THEN sums_group], simp) 
  1642   thus ?thesis unfolding One_nat_def by (simp add: mult_ac)
  1607   thus ?thesis unfolding One_nat_def sin_coeff_def by (simp add: mult_ac)
  1643 qed
  1608 qed
  1644 
  1609 
  1645 text {* FIXME: This is a long, ugly proof! *}
  1610 text {* FIXME: This is a long, ugly proof! *}
  1646 lemma sin_gt_zero: "[|0 < x; x < 2 |] ==> 0 < sin x"
  1611 lemma sin_gt_zero: "[|0 < x; x < 2 |] ==> 0 < sin x"
  1647 apply (subgoal_tac 
  1612 apply (subgoal_tac 
  1700 done
  1665 done
  1701 
  1666 
  1702 lemma cos_paired:
  1667 lemma cos_paired:
  1703      "(%n. -1 ^ n /(real (fact (2 * n))) * x ^ (2 * n)) sums cos x"
  1668      "(%n. -1 ^ n /(real (fact (2 * n))) * x ^ (2 * n)) sums cos x"
  1704 proof -
  1669 proof -
  1705   have "(\<lambda>n. \<Sum>k = n * 2..<n * 2 + 2.
  1670   have "(\<lambda>n. \<Sum>k = n * 2..<n * 2 + 2. cos_coeff k * x ^ k) sums cos x"
  1706             (if even k then -1 ^ (k div 2) / real (fact k) else 0) *
       
  1707             x ^ k) 
       
  1708         sums cos x"
       
  1709     unfolding cos_def
  1671     unfolding cos_def
  1710     by (rule cos_converges [THEN sums_summable, THEN sums_group], simp) 
  1672     by (rule cos_converges [THEN sums_summable, THEN sums_group], simp) 
  1711   thus ?thesis by (simp add: mult_ac)
  1673   thus ?thesis unfolding cos_coeff_def by (simp add: mult_ac)
  1712 qed
  1674 qed
  1713 
  1675 
  1714 lemma fact_lemma: "real (n::nat) * 4 = real (4 * n)"
  1676 lemma fact_lemma: "real (n::nat) * 4 = real (4 * n)"
  1715 by simp
  1677 by simp
  1716 
  1678