src/HOL/Hyperreal/Transcendental.thy
author huffman
Sun May 20 05:27:45 2007 +0200 (2007-05-20)
changeset 23043 5dbfd67516a4
parent 23011 3eae3140b4b2
child 23045 95e04f335940
permissions -rw-r--r--
rearranged sections
paulson@12196
     1
(*  Title       : Transcendental.thy
paulson@12196
     2
    Author      : Jacques D. Fleuriot
paulson@12196
     3
    Copyright   : 1998,1999 University of Cambridge
paulson@13958
     4
                  1999,2001 University of Edinburgh
paulson@15077
     5
    Conversion to Isar and new proofs by Lawrence C Paulson, 2004
paulson@12196
     6
*)
paulson@12196
     7
paulson@15077
     8
header{*Power Series, Transcendental Functions etc.*}
paulson@15077
     9
nipkow@15131
    10
theory Transcendental
huffman@22654
    11
imports NthRoot Fact Series EvenOdd Deriv
nipkow@15131
    12
begin
paulson@15077
    13
huffman@23043
    14
subsection{*Properties of Power Series*}
paulson@15077
    15
paulson@15229
    16
lemma lemma_realpow_diff [rule_format (no_asm)]:
paulson@15229
    17
     "p \<le> n --> y ^ (Suc n - p) = ((y::real) ^ (n - p)) * y"
paulson@15251
    18
apply (induct "n", auto)
paulson@15077
    19
apply (subgoal_tac "p = Suc n")
paulson@15077
    20
apply (simp (no_asm_simp), auto)
paulson@15077
    21
apply (drule sym)
paulson@15077
    22
apply (simp add: Suc_diff_le mult_commute realpow_Suc [symmetric] 
paulson@15077
    23
       del: realpow_Suc)
paulson@15077
    24
done
paulson@15077
    25
paulson@15077
    26
lemma lemma_realpow_diff_sumr:
nipkow@15539
    27
     "(\<Sum>p=0..<Suc n. (x ^ p) * y ^ ((Suc n) - p)) =  
nipkow@15539
    28
      y * (\<Sum>p=0..<Suc n. (x ^ p) * (y ^ (n - p))::real)"
ballarin@19279
    29
by (auto simp add: setsum_right_distrib lemma_realpow_diff mult_ac
berghofe@16641
    30
  simp del: setsum_op_ivl_Suc cong: strong_setsum_cong)
paulson@15077
    31
paulson@15229
    32
lemma lemma_realpow_diff_sumr2:
paulson@15229
    33
     "x ^ (Suc n) - y ^ (Suc n) =  
nipkow@15539
    34
      (x - y) * (\<Sum>p=0..<Suc n. (x ^ p) * (y ^(n - p))::real)"
paulson@15251
    35
apply (induct "n", simp)
nipkow@15561
    36
apply (auto simp del: setsum_op_ivl_Suc)
nipkow@15561
    37
apply (subst setsum_op_ivl_Suc)
paulson@15077
    38
apply (drule sym)
nipkow@15561
    39
apply (auto simp add: lemma_realpow_diff_sumr right_distrib diff_minus mult_ac simp del: setsum_op_ivl_Suc)
paulson@15077
    40
done
paulson@15077
    41
paulson@15229
    42
lemma lemma_realpow_rev_sumr:
nipkow@15539
    43
     "(\<Sum>p=0..<Suc n. (x ^ p) * (y ^ (n - p))) =  
nipkow@15539
    44
      (\<Sum>p=0..<Suc n. (x ^ (n - p)) * (y ^ p)::real)"
paulson@15077
    45
apply (case_tac "x = y")
nipkow@15561
    46
apply (auto simp add: mult_commute power_add [symmetric] simp del: setsum_op_ivl_Suc)
paulson@15077
    47
apply (rule_tac c1 = "x - y" in real_mult_left_cancel [THEN iffD1])
paulson@15077
    48
apply (rule_tac [2] minus_minus [THEN subst], simp)
paulson@15077
    49
apply (subst minus_mult_left)
nipkow@15561
    50
apply (simp add: lemma_realpow_diff_sumr2 [symmetric] del: setsum_op_ivl_Suc)
paulson@15077
    51
done
paulson@15077
    52
paulson@15077
    53
text{*Power series has a `circle` of convergence, i.e. if it sums for @{term
paulson@15077
    54
x}, then it sums absolutely for @{term z} with @{term "\<bar>z\<bar> < \<bar>x\<bar>"}.*}
paulson@15077
    55
paulson@15077
    56
lemma powser_insidea:
huffman@20849
    57
  fixes x z :: real
huffman@20849
    58
  assumes 1: "summable (\<lambda>n. f n * x ^ n)"
huffman@20849
    59
  assumes 2: "\<bar>z\<bar> < \<bar>x\<bar>"
huffman@20849
    60
  shows "summable (\<lambda>n. \<bar>f n\<bar> * z ^ n)"
huffman@20849
    61
proof -
huffman@20849
    62
  from 2 have x_neq_0: "x \<noteq> 0" by clarsimp
huffman@20849
    63
  from 1 have "(\<lambda>n. f n * x ^ n) ----> 0"
huffman@20849
    64
    by (rule summable_LIMSEQ_zero)
huffman@20849
    65
  hence "convergent (\<lambda>n. f n * x ^ n)"
huffman@20849
    66
    by (rule convergentI)
huffman@20849
    67
  hence "Cauchy (\<lambda>n. f n * x ^ n)"
huffman@20849
    68
    by (simp add: Cauchy_convergent_iff)
huffman@20849
    69
  hence "Bseq (\<lambda>n. f n * x ^ n)"
huffman@20849
    70
    by (rule Cauchy_Bseq)
huffman@20849
    71
  then obtain K where 3: "0 < K" and 4: "\<forall>n. \<bar>f n * x ^ n\<bar> \<le> K"
huffman@20849
    72
    by (simp add: Bseq_def, safe)
huffman@20849
    73
  have "\<exists>N. \<forall>n\<ge>N. norm (\<bar>f n\<bar> * z ^ n) \<le> K * \<bar>z ^ n\<bar> * inverse \<bar>x ^ n\<bar>"
huffman@20849
    74
  proof (intro exI allI impI)
huffman@20849
    75
    fix n::nat assume "0 \<le> n"
huffman@20849
    76
    have "norm (\<bar>f n\<bar> * z ^ n) * \<bar>x ^ n\<bar> = \<bar>f n * x ^ n\<bar> * \<bar>z ^ n\<bar>"
huffman@20849
    77
      by (simp add: abs_mult)
huffman@20849
    78
    also have "\<dots> \<le> K * \<bar>z ^ n\<bar>"
huffman@20849
    79
      by (simp only: mult_right_mono 4 abs_ge_zero)
huffman@20849
    80
    also have "\<dots> = K * \<bar>z ^ n\<bar> * (inverse \<bar>x ^ n\<bar> * \<bar>x ^ n\<bar>)"
huffman@20849
    81
      by (simp add: x_neq_0)
huffman@20849
    82
    also have "\<dots> = K * \<bar>z ^ n\<bar> * inverse \<bar>x ^ n\<bar> * \<bar>x ^ n\<bar>"
huffman@20849
    83
      by (simp only: mult_assoc)
huffman@20849
    84
    finally show "norm (\<bar>f n\<bar> * z ^ n) \<le> K * \<bar>z ^ n\<bar> * inverse \<bar>x ^ n\<bar>"
huffman@20849
    85
      by (simp add: mult_le_cancel_right x_neq_0)
huffman@20849
    86
  qed
huffman@20849
    87
  moreover have "summable (\<lambda>n. K * \<bar>z ^ n\<bar> * inverse \<bar>x ^ n\<bar>)"
huffman@20849
    88
  proof -
huffman@20849
    89
    from 2 have "norm \<bar>z * inverse x\<bar> < 1"
huffman@20849
    90
      by (simp add: abs_mult divide_inverse [symmetric])
huffman@20849
    91
    hence "summable (\<lambda>n. \<bar>z * inverse x\<bar> ^ n)"
huffman@20849
    92
      by (rule summable_geometric)
huffman@20849
    93
    hence "summable (\<lambda>n. K * \<bar>z * inverse x\<bar> ^ n)"
huffman@20849
    94
      by (rule summable_mult)
huffman@20849
    95
    thus "summable (\<lambda>n. K * \<bar>z ^ n\<bar> * inverse \<bar>x ^ n\<bar>)"
huffman@20849
    96
      by (simp add: abs_mult power_mult_distrib power_abs
huffman@20849
    97
                    power_inverse mult_assoc)
huffman@20849
    98
  qed
huffman@20849
    99
  ultimately show "summable (\<lambda>n. \<bar>f n\<bar> * z ^ n)"
huffman@20849
   100
    by (rule summable_comparison_test)
huffman@20849
   101
qed
paulson@15077
   102
paulson@15229
   103
lemma powser_inside:
huffman@20849
   104
  fixes f :: "nat \<Rightarrow> real" shows
paulson@15229
   105
     "[| summable (%n. f(n) * (x ^ n)); \<bar>z\<bar> < \<bar>x\<bar> |]  
paulson@15077
   106
      ==> summable (%n. f(n) * (z ^ n))"
huffman@20849
   107
apply (drule_tac z = "\<bar>z\<bar>" in powser_insidea, simp)
huffman@20849
   108
apply (rule summable_rabs_cancel)
huffman@20849
   109
apply (simp add: abs_mult power_abs [symmetric])
paulson@15077
   110
done
paulson@15077
   111
paulson@15077
   112
huffman@23043
   113
subsection{*Term-by-Term Differentiability of Power Series*}
huffman@23043
   114
huffman@23043
   115
definition
huffman@23043
   116
  diffs :: "(nat => real) => nat => real" where
huffman@23043
   117
  "diffs c = (%n. real (Suc n) * c(Suc n))"
paulson@15077
   118
paulson@15077
   119
text{*Lemma about distributing negation over it*}
paulson@15077
   120
lemma diffs_minus: "diffs (%n. - c n) = (%n. - diffs c n)"
paulson@15077
   121
by (simp add: diffs_def)
paulson@15077
   122
paulson@15077
   123
text{*Show that we can shift the terms down one*}
paulson@15077
   124
lemma lemma_diffs:
nipkow@15539
   125
     "(\<Sum>n=0..<n. (diffs c)(n) * (x ^ n)) =  
nipkow@15539
   126
      (\<Sum>n=0..<n. real n * c(n) * (x ^ (n - Suc 0))) +  
paulson@15077
   127
      (real n * c(n) * x ^ (n - Suc 0))"
paulson@15251
   128
apply (induct "n")
paulson@15077
   129
apply (auto simp add: mult_assoc add_assoc [symmetric] diffs_def)
paulson@15077
   130
done
paulson@15077
   131
paulson@15229
   132
lemma lemma_diffs2:
nipkow@15539
   133
     "(\<Sum>n=0..<n. real n * c(n) * (x ^ (n - Suc 0))) =  
nipkow@15539
   134
      (\<Sum>n=0..<n. (diffs c)(n) * (x ^ n)) -  
paulson@15077
   135
      (real n * c(n) * x ^ (n - Suc 0))"
paulson@15077
   136
by (auto simp add: lemma_diffs)
paulson@15077
   137
paulson@15077
   138
paulson@15229
   139
lemma diffs_equiv:
paulson@15229
   140
     "summable (%n. (diffs c)(n) * (x ^ n)) ==>  
paulson@15077
   141
      (%n. real n * c(n) * (x ^ (n - Suc 0))) sums  
nipkow@15546
   142
         (\<Sum>n. (diffs c)(n) * (x ^ n))"
paulson@15077
   143
apply (subgoal_tac " (%n. real n * c (n) * (x ^ (n - Suc 0))) ----> 0")
paulson@15077
   144
apply (rule_tac [2] LIMSEQ_imp_Suc)
paulson@15077
   145
apply (drule summable_sums) 
paulson@15077
   146
apply (auto simp add: sums_def)
paulson@15077
   147
apply (drule_tac X="(\<lambda>n. \<Sum>n = 0..<n. diffs c n * x ^ n)" in LIMSEQ_diff)
paulson@15077
   148
apply (auto simp add: lemma_diffs2 [symmetric] diffs_def [symmetric])
paulson@15077
   149
apply (simp add: diffs_def summable_LIMSEQ_zero)
paulson@15077
   150
done
paulson@15077
   151
paulson@15077
   152
lemma lemma_termdiff1:
nipkow@15539
   153
  "(\<Sum>p=0..<m. (((z + h) ^ (m - p)) * (z ^ p)) - (z ^ m)) =  
nipkow@15539
   154
   (\<Sum>p=0..<m. (z ^ p) * (((z + h) ^ (m - p)) - (z ^ (m - p)))::real)"
berghofe@16641
   155
by (auto simp add: right_distrib diff_minus power_add [symmetric] mult_ac
berghofe@16641
   156
  cong: strong_setsum_cong)
paulson@15077
   157
paulson@15077
   158
lemma less_add_one: "m < n ==> (\<exists>d. n = m + d + Suc 0)"
paulson@15077
   159
by (simp add: less_iff_Suc_add)
paulson@15077
   160
paulson@15077
   161
lemma sumdiff: "a + b - (c + d) = a - c + b - (d::real)"
paulson@15077
   162
by arith
paulson@15077
   163
paulson@15229
   164
lemma lemma_termdiff2:
huffman@20860
   165
  assumes h: "h \<noteq> 0" shows
huffman@20860
   166
  "((z + h) ^ n - z ^ n) / h - real n * z ^ (n - Suc 0) =
huffman@20860
   167
   h * (\<Sum>p=0..< n - Suc 0. \<Sum>q=0..< n - Suc 0 - p.
huffman@20860
   168
        (z + h) ^ q * z ^ (n - 2 - q))"
huffman@20860
   169
apply (rule real_mult_left_cancel [OF h, THEN iffD1])
huffman@20860
   170
apply (simp add: right_diff_distrib diff_divide_distrib h)
paulson@15077
   171
apply (simp add: mult_assoc [symmetric])
huffman@20860
   172
apply (cases "n", simp)
huffman@20860
   173
apply (simp add: lemma_realpow_diff_sumr2 h
huffman@20860
   174
                 right_diff_distrib [symmetric] mult_assoc
huffman@20860
   175
            del: realpow_Suc setsum_op_ivl_Suc)
huffman@20860
   176
apply (subst lemma_realpow_rev_sumr)
huffman@20860
   177
apply (subst sumr_diff_mult_const)
huffman@20860
   178
apply simp
huffman@20860
   179
apply (simp only: lemma_termdiff1 setsum_right_distrib)
huffman@20860
   180
apply (rule setsum_cong [OF refl])
nipkow@15539
   181
apply (simp add: diff_minus [symmetric] less_iff_Suc_add)
huffman@20860
   182
apply (clarify)
huffman@20860
   183
apply (simp add: setsum_right_distrib lemma_realpow_diff_sumr2 mult_ac
huffman@20860
   184
            del: setsum_op_ivl_Suc realpow_Suc)
huffman@20860
   185
apply (subst mult_assoc [symmetric], subst power_add [symmetric])
huffman@20860
   186
apply (simp add: mult_ac)
huffman@20860
   187
done
huffman@20860
   188
huffman@20860
   189
lemma real_setsum_nat_ivl_bounded2:
huffman@20860
   190
  "\<lbrakk>\<And>p::nat. p < n \<Longrightarrow> f p \<le> K; 0 \<le> K\<rbrakk>
huffman@20860
   191
   \<Longrightarrow> setsum f {0..<n-k} \<le> real n * K"
huffman@20860
   192
apply (rule order_trans [OF real_setsum_nat_ivl_bounded mult_right_mono])
huffman@20860
   193
apply simp_all
paulson@15077
   194
done
paulson@15077
   195
paulson@15229
   196
lemma lemma_termdiff3:
huffman@20860
   197
  assumes 1: "h \<noteq> 0"
huffman@20860
   198
  assumes 2: "\<bar>z\<bar> \<le> K"
huffman@20860
   199
  assumes 3: "\<bar>z + h\<bar> \<le> K"
huffman@20860
   200
  shows "\<bar>((z + h) ^ n - z ^ n) / h - real n * z ^ (n - Suc 0)\<bar>
paulson@15077
   201
          \<le> real n * real (n - Suc 0) * K ^ (n - 2) * \<bar>h\<bar>"
huffman@20860
   202
proof -
huffman@20860
   203
  have "\<bar>((z + h) ^ n - z ^ n) / h - real n * z ^ (n - Suc 0)\<bar> =
huffman@20860
   204
        \<bar>\<Sum>p = 0..<n - Suc 0. \<Sum>q = 0..<n - Suc 0 - p.
huffman@20860
   205
          (z + h) ^ q * z ^ (n - 2 - q)\<bar> * \<bar>h\<bar>"
huffman@20860
   206
    apply (subst lemma_termdiff2 [OF 1])
huffman@20860
   207
    apply (subst abs_mult)
huffman@20860
   208
    apply (rule mult_commute)
huffman@20860
   209
    done
huffman@20860
   210
  also have "\<dots> \<le> real n * (real (n - Suc 0) * K ^ (n - 2)) * \<bar>h\<bar>"
huffman@20860
   211
  proof (rule mult_right_mono [OF _ abs_ge_zero])
huffman@20860
   212
    from abs_ge_zero 2 have K: "0 \<le> K" by (rule order_trans)
huffman@20860
   213
    have le_Kn: "\<And>i j n. i + j = n \<Longrightarrow> \<bar>(z + h) ^ i * z ^ j\<bar> \<le> K ^ n"
huffman@20860
   214
      apply (erule subst)
huffman@20860
   215
      apply (simp only: abs_mult power_abs power_add)
huffman@20860
   216
      apply (intro mult_mono power_mono 2 3 abs_ge_zero zero_le_power K)
huffman@20860
   217
      done
huffman@20860
   218
    show "\<bar>\<Sum>p = 0..<n - Suc 0. \<Sum>q = 0..<n - Suc 0 - p.
huffman@20860
   219
              (z + h) ^ q * z ^ (n - 2 - q)\<bar>
huffman@20860
   220
          \<le> real n * (real (n - Suc 0) * K ^ (n - 2))"
huffman@20860
   221
      apply (intro
huffman@20860
   222
         order_trans [OF setsum_abs]
huffman@20860
   223
         real_setsum_nat_ivl_bounded2
huffman@20860
   224
         mult_nonneg_nonneg
huffman@20860
   225
         real_of_nat_ge_zero
huffman@20860
   226
         zero_le_power K)
huffman@20860
   227
      apply (rule le_Kn, simp)
huffman@20860
   228
      done
huffman@20860
   229
  qed
huffman@20860
   230
  also have "\<dots> = real n * real (n - Suc 0) * K ^ (n - 2) * \<bar>h\<bar>"
huffman@20860
   231
    by (simp only: mult_assoc)
huffman@20860
   232
  finally show ?thesis .
huffman@20860
   233
qed
paulson@15077
   234
huffman@20860
   235
lemma lemma_termdiff4:
huffman@20860
   236
  assumes k: "0 < (k::real)"
huffman@20860
   237
  assumes le: "\<And>h. \<lbrakk>h \<noteq> 0; \<bar>h\<bar> < k\<rbrakk> \<Longrightarrow> \<bar>f h\<bar> \<le> K * \<bar>h\<bar>"
huffman@20860
   238
  shows "f -- 0 --> 0"
huffman@20860
   239
proof (simp add: LIM_def, safe)
huffman@20860
   240
  fix r::real assume r: "0 < r"
huffman@20860
   241
  have zero_le_K: "0 \<le> K"
huffman@20860
   242
    apply (cut_tac k)
huffman@20860
   243
    apply (cut_tac h="k/2" in le, simp, simp)
huffman@20860
   244
    apply (subgoal_tac "0 \<le> K*k", simp add: zero_le_mult_iff) 
huffman@20860
   245
    apply (force intro: order_trans [of _ "\<bar>f (k / 2)\<bar> * 2"]) 
huffman@20860
   246
    done
huffman@20860
   247
  show "\<exists>s. 0 < s \<and> (\<forall>x. x \<noteq> 0 \<and> \<bar>x\<bar> < s \<longrightarrow> \<bar>f x\<bar> < r)"
huffman@20860
   248
  proof (cases)
huffman@20860
   249
    assume "K = 0"
huffman@20860
   250
    with k r le have "0 < k \<and> (\<forall>x. x \<noteq> 0 \<and> \<bar>x\<bar> < k \<longrightarrow> \<bar>f x\<bar> < r)"
huffman@20860
   251
      by simp
huffman@20860
   252
    thus "\<exists>s. 0 < s \<and> (\<forall>x. x \<noteq> 0 \<and> \<bar>x\<bar> < s \<longrightarrow> \<bar>f x\<bar> < r)" ..
huffman@20860
   253
  next
huffman@20860
   254
    assume K_neq_zero: "K \<noteq> 0"
huffman@20860
   255
    with zero_le_K have K: "0 < K" by simp
huffman@20860
   256
    show "\<exists>s. 0 < s \<and> (\<forall>x. x \<noteq> 0 \<and> \<bar>x\<bar> < s \<longrightarrow> \<bar>f x\<bar> < r)"
huffman@20860
   257
    proof (rule exI, safe)
huffman@20860
   258
      from k r K show "0 < min k (r * inverse K / 2)"
huffman@20860
   259
        by (simp add: mult_pos_pos positive_imp_inverse_positive)
huffman@20860
   260
    next
huffman@20860
   261
      fix x::real
huffman@20860
   262
      assume x1: "x \<noteq> 0" and x2: "\<bar>x\<bar> < min k (r * inverse K / 2)"
huffman@20860
   263
      from x2 have x3: "\<bar>x\<bar> < k" and x4: "\<bar>x\<bar> < r * inverse K / 2"
huffman@20860
   264
        by simp_all
huffman@20860
   265
      from x1 x3 le have "\<bar>f x\<bar> \<le> K * \<bar>x\<bar>" by simp
huffman@20860
   266
      also from x4 K have "K * \<bar>x\<bar> < K * (r * inverse K / 2)"
huffman@20860
   267
        by (rule mult_strict_left_mono)
huffman@20860
   268
      also have "\<dots> = r / 2"
huffman@20860
   269
        using K_neq_zero by simp
huffman@20860
   270
      also have "r / 2 < r"
huffman@20860
   271
        using r by simp
huffman@20860
   272
      finally show "\<bar>f x\<bar> < r" .
huffman@20860
   273
    qed
huffman@20860
   274
  qed
huffman@20860
   275
qed
paulson@15077
   276
paulson@15229
   277
lemma lemma_termdiff5:
huffman@20860
   278
  assumes k: "0 < (k::real)"
huffman@20860
   279
  assumes f: "summable f"
huffman@20860
   280
  assumes le: "\<And>h n. \<lbrakk>h \<noteq> 0; \<bar>h\<bar> < k\<rbrakk> \<Longrightarrow> \<bar>g h n\<bar> \<le> f n * \<bar>h\<bar>"
huffman@20860
   281
  shows "(\<lambda>h. suminf (g h)) -- 0 --> 0"
huffman@20860
   282
proof (rule lemma_termdiff4 [OF k])
huffman@20860
   283
  fix h assume "h \<noteq> 0" and "\<bar>h\<bar> < k"
huffman@20860
   284
  hence A: "\<forall>n. \<bar>g h n\<bar> \<le> f n * \<bar>h\<bar>"
huffman@20860
   285
    by (simp add: le)
huffman@20860
   286
  hence "\<exists>N. \<forall>n\<ge>N. norm \<bar>g h n\<bar> \<le> f n * \<bar>h\<bar>"
huffman@20860
   287
    by simp
huffman@20860
   288
  moreover from f have B: "summable (\<lambda>n. f n * \<bar>h\<bar>)"
huffman@20860
   289
    by (rule summable_mult2)
huffman@20860
   290
  ultimately have C: "summable (\<lambda>n. \<bar>g h n\<bar>)"
huffman@20860
   291
    by (rule summable_comparison_test)
huffman@20860
   292
  hence "\<bar>suminf (g h)\<bar> \<le> (\<Sum>n. \<bar>g h n\<bar>)"
huffman@20860
   293
    by (rule summable_rabs)
huffman@20860
   294
  also from A C B have "(\<Sum>n. \<bar>g h n\<bar>) \<le> (\<Sum>n. f n * \<bar>h\<bar>)"
huffman@20860
   295
    by (rule summable_le)
huffman@20860
   296
  also from f have "(\<Sum>n. f n * \<bar>h\<bar>) = suminf f * \<bar>h\<bar>"
huffman@20860
   297
    by (rule suminf_mult2 [symmetric])
huffman@20860
   298
  finally show "\<bar>suminf (g h)\<bar> \<le> suminf f * \<bar>h\<bar>" .
huffman@20860
   299
qed
paulson@15077
   300
paulson@15077
   301
paulson@15077
   302
text{* FIXME: Long proofs*}
paulson@15077
   303
paulson@15077
   304
lemma termdiffs_aux:
huffman@20849
   305
  assumes 1: "summable (\<lambda>n. diffs (diffs c) n * K ^ n)"
huffman@20849
   306
  assumes 2: "\<bar>x\<bar> < \<bar>K\<bar>"
huffman@20860
   307
  shows "(\<lambda>h. \<Sum>n. c n * (((x + h) ^ n - x ^ n) / h
huffman@20860
   308
             - real n * x ^ (n - Suc 0))) -- 0 --> 0"
huffman@20849
   309
proof -
huffman@20860
   310
  from dense [OF 2]
huffman@20860
   311
  obtain r where r1: "\<bar>x\<bar> < r" and r2: "r < \<bar>K\<bar>" by fast
huffman@20860
   312
  from abs_ge_zero r1 have r: "0 < r"
huffman@20860
   313
    by (rule order_le_less_trans)
huffman@20860
   314
  hence r_neq_0: "r \<noteq> 0" by simp
huffman@20860
   315
  show ?thesis
huffman@20849
   316
  proof (rule lemma_termdiff5)
huffman@20860
   317
    show "0 < r - \<bar>x\<bar>" using r1 by simp
huffman@20849
   318
  next
huffman@20860
   319
    from r r2 have "\<bar>r\<bar> < \<bar>K\<bar>"
huffman@20860
   320
      by (simp only: abs_of_nonneg order_less_imp_le)
huffman@20860
   321
    with 1 have "summable (\<lambda>n. \<bar>diffs (diffs c) n\<bar> * (r ^ n))"
huffman@20860
   322
      by (rule powser_insidea)
huffman@20860
   323
    hence "summable (\<lambda>n. diffs (diffs (\<lambda>n. \<bar>c n\<bar>)) n * r ^ n)"
huffman@20860
   324
      by (simp only: diffs_def abs_mult abs_real_of_nat_cancel)
huffman@20860
   325
    hence "summable (\<lambda>n. real n * diffs (\<lambda>n. \<bar>c n\<bar>) n * r ^ (n - Suc 0))"
huffman@20860
   326
      by (rule diffs_equiv [THEN sums_summable])
huffman@20860
   327
    also have "(\<lambda>n. real n * diffs (\<lambda>n. \<bar>c n\<bar>) n * r ^ (n - Suc 0))
huffman@20860
   328
      = (\<lambda>n. diffs (%m. real (m - Suc 0) * \<bar>c m\<bar> * inverse r) n * (r ^ n))"
huffman@20849
   329
      apply (rule ext)
huffman@20849
   330
      apply (simp add: diffs_def)
huffman@20849
   331
      apply (case_tac n, simp_all add: r_neq_0)
huffman@20849
   332
      done
huffman@20860
   333
    finally have "summable 
huffman@20860
   334
      (\<lambda>n. real n * (real (n - Suc 0) * \<bar>c n\<bar> * inverse r) * r ^ (n - Suc 0))"
huffman@20860
   335
      by (rule diffs_equiv [THEN sums_summable])
huffman@20860
   336
    also have
huffman@20860
   337
      "(\<lambda>n. real n * (real (n - Suc 0) * \<bar>c n\<bar> * inverse r) *
huffman@20860
   338
           r ^ (n - Suc 0)) =
huffman@20860
   339
       (\<lambda>n. \<bar>c n\<bar> * real n * real (n - Suc 0) * r ^ (n - 2))"
huffman@20849
   340
      apply (rule ext)
huffman@20849
   341
      apply (case_tac "n", simp)
huffman@20849
   342
      apply (case_tac "nat", simp)
huffman@20849
   343
      apply (simp add: r_neq_0)
huffman@20849
   344
      done
huffman@20860
   345
    finally show
huffman@20860
   346
      "summable (\<lambda>n. \<bar>c n\<bar> * real n * real (n - Suc 0) * r ^ (n - 2))" .
huffman@20849
   347
  next
huffman@20860
   348
    fix h::real and n::nat
huffman@20860
   349
    assume h: "h \<noteq> 0"
huffman@20860
   350
    assume "\<bar>h\<bar> < r - \<bar>x\<bar>"
huffman@20860
   351
    hence "\<bar>x\<bar> + \<bar>h\<bar> < r" by simp
huffman@20860
   352
    with abs_triangle_ineq have xh: "\<bar>x + h\<bar> < r"
huffman@20860
   353
      by (rule order_le_less_trans)
huffman@20860
   354
    show "\<bar>c n * (((x + h) ^ n - x ^ n) / h - real n * x ^ (n - Suc 0))\<bar>
huffman@20860
   355
          \<le> \<bar>c n\<bar> * real n * real (n - Suc 0) * r ^ (n - 2) * \<bar>h\<bar>"
huffman@20860
   356
      apply (simp only: abs_mult mult_assoc)
huffman@20860
   357
      apply (rule mult_left_mono [OF _ abs_ge_zero])
huffman@20860
   358
      apply (simp (no_asm) add: mult_assoc [symmetric])
huffman@20860
   359
      apply (rule lemma_termdiff3)
huffman@20860
   360
      apply (rule h)
huffman@20860
   361
      apply (rule r1 [THEN order_less_imp_le])
huffman@20860
   362
      apply (rule xh [THEN order_less_imp_le])
huffman@20860
   363
      done
huffman@20849
   364
  qed
huffman@20849
   365
qed
webertj@20217
   366
huffman@20860
   367
lemma termdiffs:
huffman@20860
   368
  assumes 1: "summable (\<lambda>n. c n * K ^ n)"
huffman@20860
   369
  assumes 2: "summable (\<lambda>n. (diffs c) n * K ^ n)"
huffman@20860
   370
  assumes 3: "summable (\<lambda>n. (diffs (diffs c)) n * K ^ n)"
huffman@20860
   371
  assumes 4: "\<bar>x\<bar> < \<bar>K\<bar>"
huffman@20860
   372
  shows "DERIV (\<lambda>x. \<Sum>n. c n * x ^ n) x :> (\<Sum>n. (diffs c) n * x ^ n)"
huffman@20860
   373
proof (simp add: deriv_def, rule LIM_zero_cancel)
huffman@20860
   374
  show "(\<lambda>h. (suminf (\<lambda>n. c n * (x + h) ^ n) - suminf (\<lambda>n. c n * x ^ n)) / h
huffman@20860
   375
            - suminf (\<lambda>n. diffs c n * x ^ n)) -- 0 --> 0"
huffman@20860
   376
  proof (rule LIM_equal2)
huffman@20860
   377
    show "0 < \<bar>K\<bar> - \<bar>x\<bar>" by (simp add: less_diff_eq 4)
huffman@20860
   378
  next
huffman@20860
   379
    fix h :: real
huffman@20860
   380
    assume "h \<noteq> 0"
huffman@20860
   381
    assume "norm (h - 0) < \<bar>K\<bar> - \<bar>x\<bar>"
huffman@20860
   382
    hence "\<bar>x\<bar> + \<bar>h\<bar> < \<bar>K\<bar>" by simp
huffman@20860
   383
    hence 5: "\<bar>x + h\<bar> < \<bar>K\<bar>"
huffman@20860
   384
      by (rule abs_triangle_ineq [THEN order_le_less_trans])
huffman@20860
   385
    have A: "summable (\<lambda>n. c n * x ^ n)"
huffman@20860
   386
      by (rule powser_inside [OF 1 4])
huffman@20860
   387
    have B: "summable (\<lambda>n. c n * (x + h) ^ n)"
huffman@20860
   388
      by (rule powser_inside [OF 1 5])
huffman@20860
   389
    have C: "summable (\<lambda>n. diffs c n * x ^ n)"
huffman@20860
   390
      by (rule powser_inside [OF 2 4])
huffman@20860
   391
    show "((\<Sum>n. c n * (x + h) ^ n) - (\<Sum>n. c n * x ^ n)) / h
huffman@20860
   392
             - (\<Sum>n. diffs c n * x ^ n) = 
huffman@20860
   393
          (\<Sum>n. c n * (((x + h) ^ n - x ^ n) / h - real n * x ^ (n - Suc 0)))"
huffman@20860
   394
      apply (subst sums_unique [OF diffs_equiv [OF C]])
huffman@20860
   395
      apply (subst suminf_diff [OF B A])
huffman@20860
   396
      apply (subst suminf_divide [symmetric])
huffman@20860
   397
      apply (rule summable_diff [OF B A])
huffman@20860
   398
      apply (subst suminf_diff)
huffman@20860
   399
      apply (rule summable_divide)
huffman@20860
   400
      apply (rule summable_diff [OF B A])
huffman@20860
   401
      apply (rule sums_summable [OF diffs_equiv [OF C]])
huffman@20860
   402
      apply (rule_tac f="suminf" in arg_cong)
huffman@20860
   403
      apply (rule ext)
huffman@20860
   404
      apply (simp add: ring_eq_simps)
huffman@20860
   405
      done
huffman@20860
   406
  next
huffman@20860
   407
    show "(\<lambda>h. \<Sum>n. c n * (((x + h) ^ n - x ^ n) / h -
huffman@20860
   408
               real n * x ^ (n - Suc 0))) -- 0 --> 0"
huffman@20860
   409
        by (rule termdiffs_aux [OF 3 4])
huffman@20860
   410
  qed
huffman@20860
   411
qed
huffman@20860
   412
paulson@15077
   413
huffman@23043
   414
subsection{*Exponential Function*}
huffman@23043
   415
huffman@23043
   416
definition
huffman@23043
   417
  exp :: "real => real" where
huffman@23043
   418
  "exp x = (\<Sum>n. inverse(real (fact n)) * (x ^ n))"
huffman@23043
   419
huffman@23043
   420
definition
huffman@23043
   421
  sin :: "real => real" where
huffman@23043
   422
  "sin x = (\<Sum>n. (if even(n) then 0 else
huffman@23043
   423
             ((- 1) ^ ((n - Suc 0) div 2))/(real (fact n))) * x ^ n)"
huffman@23043
   424
 
huffman@23043
   425
definition
huffman@23043
   426
  cos :: "real => real" where
huffman@23043
   427
  "cos x = (\<Sum>n. (if even(n) then ((- 1) ^ (n div 2))/(real (fact n)) 
huffman@23043
   428
                            else 0) * x ^ n)"
huffman@23043
   429
  
huffman@23043
   430
lemma summable_exp: "summable (%n. inverse (real (fact n)) * x ^ n)"
huffman@23043
   431
apply (cut_tac 'a = real in zero_less_one [THEN dense], safe)
huffman@23043
   432
apply (cut_tac x = r in reals_Archimedean3, auto)
huffman@23043
   433
apply (drule_tac x = "\<bar>x\<bar>" in spec, safe)
huffman@23043
   434
apply (rule_tac N = n and c = r in ratio_test)
huffman@23043
   435
apply (safe, simp add: abs_mult mult_assoc [symmetric] del: fact_Suc)
huffman@23043
   436
apply (rule mult_right_mono)
huffman@23043
   437
apply (rule_tac b1 = "\<bar>x\<bar>" in mult_commute [THEN ssubst])
huffman@23043
   438
apply (subst fact_Suc)
huffman@23043
   439
apply (subst real_of_nat_mult)
huffman@23043
   440
apply (auto)
huffman@23043
   441
apply (simp add: mult_assoc [symmetric] positive_imp_inverse_positive)
huffman@23043
   442
apply (rule order_less_imp_le)
huffman@23043
   443
apply (rule_tac z1 = "real (Suc na)" in real_mult_less_iff1 [THEN iffD1])
huffman@23043
   444
apply (auto simp add: mult_assoc)
huffman@23043
   445
apply (erule order_less_trans)
huffman@23043
   446
apply (auto simp add: mult_less_cancel_left mult_ac)
huffman@23043
   447
done
huffman@23043
   448
huffman@23043
   449
lemma summable_sin: 
huffman@23043
   450
     "summable (%n.  
huffman@23043
   451
           (if even n then 0  
huffman@23043
   452
           else (- 1) ^ ((n - Suc 0) div 2)/(real (fact n))) *  
huffman@23043
   453
                x ^ n)"
huffman@23043
   454
apply (rule_tac g = "(%n. inverse (real (fact n)) * \<bar>x\<bar> ^ n)" in summable_comparison_test)
huffman@23043
   455
apply (rule_tac [2] summable_exp)
huffman@23043
   456
apply (rule_tac x = 0 in exI)
huffman@23043
   457
apply (auto simp add: divide_inverse abs_mult power_abs [symmetric] zero_le_mult_iff)
huffman@23043
   458
done
huffman@23043
   459
huffman@23043
   460
lemma summable_cos: 
huffman@23043
   461
      "summable (%n.  
huffman@23043
   462
           (if even n then  
huffman@23043
   463
           (- 1) ^ (n div 2)/(real (fact n)) else 0) * x ^ n)"
huffman@23043
   464
apply (rule_tac g = "(%n. inverse (real (fact n)) * \<bar>x\<bar> ^ n)" in summable_comparison_test)
huffman@23043
   465
apply (rule_tac [2] summable_exp)
huffman@23043
   466
apply (rule_tac x = 0 in exI)
huffman@23043
   467
apply (auto simp add: divide_inverse abs_mult power_abs [symmetric] zero_le_mult_iff)
huffman@23043
   468
done
huffman@23043
   469
huffman@23043
   470
lemma lemma_STAR_sin [simp]:
huffman@23043
   471
     "(if even n then 0  
huffman@23043
   472
       else (- 1) ^ ((n - Suc 0) div 2)/(real (fact n))) * 0 ^ n = 0"
huffman@23043
   473
by (induct "n", auto)
huffman@23043
   474
huffman@23043
   475
lemma lemma_STAR_cos [simp]:
huffman@23043
   476
     "0 < n -->  
huffman@23043
   477
      (- 1) ^ (n div 2)/(real (fact n)) * 0 ^ n = 0"
huffman@23043
   478
by (induct "n", auto)
huffman@23043
   479
huffman@23043
   480
lemma lemma_STAR_cos1 [simp]:
huffman@23043
   481
     "0 < n -->  
huffman@23043
   482
      (-1) ^ (n div 2)/(real (fact n)) * 0 ^ n = 0"
huffman@23043
   483
by (induct "n", auto)
huffman@23043
   484
huffman@23043
   485
lemma lemma_STAR_cos2 [simp]:
huffman@23043
   486
  "(\<Sum>n=1..<n. if even n then (- 1) ^ (n div 2)/(real (fact n)) *  0 ^ n 
huffman@23043
   487
                         else 0) = 0"
huffman@23043
   488
apply (induct "n")
huffman@23043
   489
apply (case_tac [2] "n", auto)
huffman@23043
   490
done
huffman@23043
   491
huffman@23043
   492
lemma exp_converges: "(%n. inverse (real (fact n)) * x ^ n) sums exp(x)"
huffman@23043
   493
apply (simp add: exp_def)
huffman@23043
   494
apply (rule summable_exp [THEN summable_sums])
huffman@23043
   495
done
huffman@23043
   496
huffman@23043
   497
lemma sin_converges: 
huffman@23043
   498
      "(%n. (if even n then 0  
huffman@23043
   499
            else (- 1) ^ ((n - Suc 0) div 2)/(real (fact n))) *  
huffman@23043
   500
                 x ^ n) sums sin(x)"
huffman@23043
   501
apply (simp add: sin_def)
huffman@23043
   502
apply (rule summable_sin [THEN summable_sums])
huffman@23043
   503
done
huffman@23043
   504
huffman@23043
   505
lemma cos_converges: 
huffman@23043
   506
      "(%n. (if even n then  
huffman@23043
   507
           (- 1) ^ (n div 2)/(real (fact n))  
huffman@23043
   508
           else 0) * x ^ n) sums cos(x)"
huffman@23043
   509
apply (simp add: cos_def)
huffman@23043
   510
apply (rule summable_cos [THEN summable_sums])
huffman@23043
   511
done
huffman@23043
   512
huffman@23043
   513
lemma lemma_realpow_diff [rule_format (no_asm)]:
huffman@23043
   514
     "p \<le> n --> y ^ (Suc n - p) = ((y::real) ^ (n - p)) * y"
huffman@23043
   515
apply (induct "n", auto)
huffman@23043
   516
apply (subgoal_tac "p = Suc n")
huffman@23043
   517
apply (simp (no_asm_simp), auto)
huffman@23043
   518
apply (drule sym)
huffman@23043
   519
apply (simp add: Suc_diff_le mult_commute realpow_Suc [symmetric] 
huffman@23043
   520
       del: realpow_Suc)
huffman@23043
   521
done
huffman@23043
   522
huffman@23043
   523
paulson@15077
   524
subsection{*Formal Derivatives of Exp, Sin, and Cos Series*} 
paulson@15077
   525
paulson@15077
   526
lemma exp_fdiffs: 
paulson@15077
   527
      "diffs (%n. inverse(real (fact n))) = (%n. inverse(real (fact n)))"
paulson@15229
   528
by (simp add: diffs_def mult_assoc [symmetric] del: mult_Suc)
paulson@15077
   529
paulson@15077
   530
lemma sin_fdiffs: 
paulson@15077
   531
      "diffs(%n. if even n then 0  
paulson@15077
   532
           else (- 1) ^ ((n - Suc 0) div 2)/(real (fact n)))  
paulson@15077
   533
       = (%n. if even n then  
paulson@15077
   534
                 (- 1) ^ (n div 2)/(real (fact n))  
paulson@15077
   535
              else 0)"
paulson@15229
   536
by (auto intro!: ext 
paulson@15229
   537
         simp add: diffs_def divide_inverse simp del: mult_Suc)
paulson@15077
   538
paulson@15077
   539
lemma sin_fdiffs2: 
paulson@15077
   540
       "diffs(%n. if even n then 0  
paulson@15077
   541
           else (- 1) ^ ((n - Suc 0) div 2)/(real (fact n))) n  
paulson@15077
   542
       = (if even n then  
paulson@15077
   543
                 (- 1) ^ (n div 2)/(real (fact n))  
paulson@15077
   544
              else 0)"
paulson@15229
   545
by (auto intro!: ext 
paulson@15229
   546
         simp add: diffs_def divide_inverse simp del: mult_Suc)
paulson@15077
   547
paulson@15077
   548
lemma cos_fdiffs: 
paulson@15077
   549
      "diffs(%n. if even n then  
paulson@15077
   550
                 (- 1) ^ (n div 2)/(real (fact n)) else 0)  
paulson@15077
   551
       = (%n. - (if even n then 0  
paulson@15077
   552
           else (- 1) ^ ((n - Suc 0)div 2)/(real (fact n))))"
paulson@15229
   553
by (auto intro!: ext 
paulson@15229
   554
         simp add: diffs_def divide_inverse odd_Suc_mult_two_ex
paulson@15229
   555
         simp del: mult_Suc)
paulson@15077
   556
paulson@15077
   557
paulson@15077
   558
lemma cos_fdiffs2: 
paulson@15077
   559
      "diffs(%n. if even n then  
paulson@15077
   560
                 (- 1) ^ (n div 2)/(real (fact n)) else 0) n 
paulson@15077
   561
       = - (if even n then 0  
paulson@15077
   562
           else (- 1) ^ ((n - Suc 0)div 2)/(real (fact n)))"
paulson@15229
   563
by (auto intro!: ext 
paulson@15229
   564
         simp add: diffs_def divide_inverse odd_Suc_mult_two_ex
paulson@15229
   565
         simp del: mult_Suc)
paulson@15077
   566
paulson@15077
   567
text{*Now at last we can get the derivatives of exp, sin and cos*}
paulson@15077
   568
paulson@15077
   569
lemma lemma_sin_minus:
nipkow@15546
   570
     "- sin x = (\<Sum>n. - ((if even n then 0 
paulson@15077
   571
                  else (- 1) ^ ((n - Suc 0) div 2)/(real (fact n))) * x ^ n))"
paulson@15077
   572
by (auto intro!: sums_unique sums_minus sin_converges)
paulson@15077
   573
nipkow@15546
   574
lemma lemma_exp_ext: "exp = (%x. \<Sum>n. inverse (real (fact n)) * x ^ n)"
paulson@15077
   575
by (auto intro!: ext simp add: exp_def)
paulson@15077
   576
paulson@15077
   577
lemma DERIV_exp [simp]: "DERIV exp x :> exp(x)"
paulson@15229
   578
apply (simp add: exp_def)
paulson@15077
   579
apply (subst lemma_exp_ext)
nipkow@15546
   580
apply (subgoal_tac "DERIV (%u. \<Sum>n. inverse (real (fact n)) * u ^ n) x :> (\<Sum>n. diffs (%n. inverse (real (fact n))) n * x ^ n)")
paulson@15229
   581
apply (rule_tac [2] K = "1 + \<bar>x\<bar>" in termdiffs)
webertj@20217
   582
apply (auto intro: exp_converges [THEN sums_summable] simp add: exp_fdiffs)
paulson@15077
   583
done
paulson@15077
   584
paulson@15077
   585
lemma lemma_sin_ext:
nipkow@15546
   586
     "sin = (%x. \<Sum>n. 
paulson@15077
   587
                   (if even n then 0  
paulson@15077
   588
                       else (- 1) ^ ((n - Suc 0) div 2)/(real (fact n))) *  
nipkow@15546
   589
                   x ^ n)"
paulson@15077
   590
by (auto intro!: ext simp add: sin_def)
paulson@15077
   591
paulson@15077
   592
lemma lemma_cos_ext:
nipkow@15546
   593
     "cos = (%x. \<Sum>n. 
paulson@15077
   594
                   (if even n then (- 1) ^ (n div 2)/(real (fact n)) else 0) *
nipkow@15546
   595
                   x ^ n)"
paulson@15077
   596
by (auto intro!: ext simp add: cos_def)
paulson@15077
   597
paulson@15077
   598
lemma DERIV_sin [simp]: "DERIV sin x :> cos(x)"
paulson@15229
   599
apply (simp add: cos_def)
paulson@15077
   600
apply (subst lemma_sin_ext)
paulson@15077
   601
apply (auto simp add: sin_fdiffs2 [symmetric])
paulson@15229
   602
apply (rule_tac K = "1 + \<bar>x\<bar>" in termdiffs)
webertj@20217
   603
apply (auto intro: sin_converges cos_converges sums_summable intro!: sums_minus [THEN sums_summable] simp add: cos_fdiffs sin_fdiffs)
paulson@15077
   604
done
paulson@15077
   605
paulson@15077
   606
lemma DERIV_cos [simp]: "DERIV cos x :> -sin(x)"
paulson@15077
   607
apply (subst lemma_cos_ext)
paulson@15077
   608
apply (auto simp add: lemma_sin_minus cos_fdiffs2 [symmetric] minus_mult_left)
paulson@15229
   609
apply (rule_tac K = "1 + \<bar>x\<bar>" in termdiffs)
webertj@20217
   610
apply (auto intro: sin_converges cos_converges sums_summable intro!: sums_minus [THEN sums_summable] simp add: cos_fdiffs sin_fdiffs diffs_minus)
paulson@15077
   611
done
paulson@15077
   612
paulson@15077
   613
paulson@15077
   614
subsection{*Properties of the Exponential Function*}
paulson@15077
   615
paulson@15077
   616
lemma exp_zero [simp]: "exp 0 = 1"
paulson@15077
   617
proof -
paulson@15077
   618
  have "(\<Sum>n = 0..<1. inverse (real (fact n)) * 0 ^ n) =
nipkow@15546
   619
        (\<Sum>n. inverse (real (fact n)) * 0 ^ n)"
paulson@15077
   620
    by (rule series_zero [rule_format, THEN sums_unique],
paulson@15077
   621
        case_tac "m", auto)
paulson@15077
   622
  thus ?thesis by (simp add:  exp_def) 
paulson@15077
   623
qed
paulson@15077
   624
avigad@17014
   625
lemma exp_ge_add_one_self_aux: "0 \<le> x ==> (1 + x) \<le> exp(x)"
huffman@22998
   626
apply (drule order_le_imp_less_or_eq, auto)
paulson@15229
   627
apply (simp add: exp_def)
paulson@15077
   628
apply (rule real_le_trans)
paulson@15229
   629
apply (rule_tac [2] n = 2 and f = "(%n. inverse (real (fact n)) * x ^ n)" in series_pos_le)
paulson@15077
   630
apply (auto intro: summable_exp simp add: numeral_2_eq_2 zero_le_power zero_le_mult_iff)
paulson@15077
   631
done
paulson@15077
   632
paulson@15077
   633
lemma exp_gt_one [simp]: "0 < x ==> 1 < exp x"
paulson@15077
   634
apply (rule order_less_le_trans)
avigad@17014
   635
apply (rule_tac [2] exp_ge_add_one_self_aux, auto)
paulson@15077
   636
done
paulson@15077
   637
paulson@15077
   638
lemma DERIV_exp_add_const: "DERIV (%x. exp (x + y)) x :> exp(x + y)"
paulson@15077
   639
proof -
paulson@15077
   640
  have "DERIV (exp \<circ> (\<lambda>x. x + y)) x :> exp (x + y) * (1+0)"
paulson@15077
   641
    by (fast intro: DERIV_chain DERIV_add DERIV_exp DERIV_Id DERIV_const) 
paulson@15077
   642
  thus ?thesis by (simp add: o_def)
paulson@15077
   643
qed
paulson@15077
   644
paulson@15077
   645
lemma DERIV_exp_minus [simp]: "DERIV (%x. exp (-x)) x :> - exp(-x)"
paulson@15077
   646
proof -
paulson@15077
   647
  have "DERIV (exp \<circ> uminus) x :> exp (- x) * - 1"
paulson@15077
   648
    by (fast intro: DERIV_chain DERIV_minus DERIV_exp DERIV_Id) 
paulson@15077
   649
  thus ?thesis by (simp add: o_def)
paulson@15077
   650
qed
paulson@15077
   651
paulson@15077
   652
lemma DERIV_exp_exp_zero [simp]: "DERIV (%x. exp (x + y) * exp (- x)) x :> 0"
paulson@15077
   653
proof -
paulson@15077
   654
  have "DERIV (\<lambda>x. exp (x + y) * exp (- x)) x
paulson@15077
   655
       :> exp (x + y) * exp (- x) + - exp (- x) * exp (x + y)"
paulson@15077
   656
    by (fast intro: DERIV_exp_add_const DERIV_exp_minus DERIV_mult) 
paulson@15077
   657
  thus ?thesis by simp
paulson@15077
   658
qed
paulson@15077
   659
paulson@15077
   660
lemma exp_add_mult_minus [simp]: "exp(x + y)*exp(-x) = exp(y)"
paulson@15077
   661
proof -
paulson@15077
   662
  have "\<forall>x. DERIV (%x. exp (x + y) * exp (- x)) x :> 0" by simp
paulson@15077
   663
  hence "exp (x + y) * exp (- x) = exp (0 + y) * exp (- 0)" 
paulson@15077
   664
    by (rule DERIV_isconst_all) 
paulson@15077
   665
  thus ?thesis by simp
paulson@15077
   666
qed
paulson@15077
   667
paulson@15077
   668
lemma exp_mult_minus [simp]: "exp x * exp(-x) = 1"
paulson@15077
   669
proof -
paulson@15077
   670
  have "exp (x + 0) * exp (- x) = exp 0" by (rule exp_add_mult_minus) 
paulson@15077
   671
  thus ?thesis by simp
paulson@15077
   672
qed
paulson@15077
   673
paulson@15077
   674
lemma exp_mult_minus2 [simp]: "exp(-x)*exp(x) = 1"
paulson@15077
   675
by (simp add: mult_commute)
paulson@15077
   676
paulson@15077
   677
paulson@15077
   678
lemma exp_minus: "exp(-x) = inverse(exp(x))"
paulson@15077
   679
by (auto intro: inverse_unique [symmetric])
paulson@15077
   680
paulson@15077
   681
lemma exp_add: "exp(x + y) = exp(x) * exp(y)"
paulson@15077
   682
proof -
paulson@15077
   683
  have "exp x * exp y = exp x * (exp (x + y) * exp (- x))" by simp
paulson@15077
   684
  thus ?thesis by (simp (no_asm_simp) add: mult_ac)
paulson@15077
   685
qed
paulson@15077
   686
paulson@15077
   687
text{*Proof: because every exponential can be seen as a square.*}
paulson@15077
   688
lemma exp_ge_zero [simp]: "0 \<le> exp x"
paulson@15077
   689
apply (rule_tac t = x in real_sum_of_halves [THEN subst])
paulson@15077
   690
apply (subst exp_add, auto)
paulson@15077
   691
done
paulson@15077
   692
paulson@15077
   693
lemma exp_not_eq_zero [simp]: "exp x \<noteq> 0"
paulson@15077
   694
apply (cut_tac x = x in exp_mult_minus2)
paulson@15077
   695
apply (auto simp del: exp_mult_minus2)
paulson@15077
   696
done
paulson@15077
   697
paulson@15077
   698
lemma exp_gt_zero [simp]: "0 < exp x"
paulson@15077
   699
by (simp add: order_less_le)
paulson@15077
   700
paulson@15077
   701
lemma inv_exp_gt_zero [simp]: "0 < inverse(exp x)"
paulson@15077
   702
by (auto intro: positive_imp_inverse_positive)
paulson@15077
   703
paulson@15081
   704
lemma abs_exp_cancel [simp]: "\<bar>exp x\<bar> = exp x"
paulson@15229
   705
by auto
paulson@15077
   706
paulson@15077
   707
lemma exp_real_of_nat_mult: "exp(real n * x) = exp(x) ^ n"
paulson@15251
   708
apply (induct "n")
paulson@15077
   709
apply (auto simp add: real_of_nat_Suc right_distrib exp_add mult_commute)
paulson@15077
   710
done
paulson@15077
   711
paulson@15077
   712
lemma exp_diff: "exp(x - y) = exp(x)/(exp y)"
paulson@15229
   713
apply (simp add: diff_minus divide_inverse)
paulson@15077
   714
apply (simp (no_asm) add: exp_add exp_minus)
paulson@15077
   715
done
paulson@15077
   716
paulson@15077
   717
paulson@15077
   718
lemma exp_less_mono:
paulson@15077
   719
  assumes xy: "x < y" shows "exp x < exp y"
paulson@15077
   720
proof -
paulson@15077
   721
  have "1 < exp (y + - x)"
paulson@15077
   722
    by (rule real_less_sum_gt_zero [THEN exp_gt_one])
paulson@15077
   723
  hence "exp x * inverse (exp x) < exp y * inverse (exp x)"
paulson@15077
   724
    by (auto simp add: exp_add exp_minus)
paulson@15077
   725
  thus ?thesis
nipkow@15539
   726
    by (simp add: divide_inverse [symmetric] pos_less_divide_eq
paulson@15228
   727
             del: divide_self_if)
paulson@15077
   728
qed
paulson@15077
   729
paulson@15077
   730
lemma exp_less_cancel: "exp x < exp y ==> x < y"
paulson@15228
   731
apply (simp add: linorder_not_le [symmetric]) 
paulson@15228
   732
apply (auto simp add: order_le_less exp_less_mono) 
paulson@15077
   733
done
paulson@15077
   734
paulson@15077
   735
lemma exp_less_cancel_iff [iff]: "(exp(x) < exp(y)) = (x < y)"
paulson@15077
   736
by (auto intro: exp_less_mono exp_less_cancel)
paulson@15077
   737
paulson@15077
   738
lemma exp_le_cancel_iff [iff]: "(exp(x) \<le> exp(y)) = (x \<le> y)"
paulson@15077
   739
by (auto simp add: linorder_not_less [symmetric])
paulson@15077
   740
paulson@15077
   741
lemma exp_inj_iff [iff]: "(exp x = exp y) = (x = y)"
paulson@15077
   742
by (simp add: order_eq_iff)
paulson@15077
   743
paulson@15077
   744
lemma lemma_exp_total: "1 \<le> y ==> \<exists>x. 0 \<le> x & x \<le> y - 1 & exp(x) = y"
paulson@15077
   745
apply (rule IVT)
paulson@15077
   746
apply (auto intro: DERIV_exp [THEN DERIV_isCont] simp add: le_diff_eq)
paulson@15077
   747
apply (subgoal_tac "1 + (y - 1) \<le> exp (y - 1)") 
paulson@15077
   748
apply simp 
avigad@17014
   749
apply (rule exp_ge_add_one_self_aux, simp)
paulson@15077
   750
done
paulson@15077
   751
paulson@15077
   752
lemma exp_total: "0 < y ==> \<exists>x. exp x = y"
paulson@15077
   753
apply (rule_tac x = 1 and y = y in linorder_cases)
paulson@15077
   754
apply (drule order_less_imp_le [THEN lemma_exp_total])
paulson@15077
   755
apply (rule_tac [2] x = 0 in exI)
paulson@15077
   756
apply (frule_tac [3] real_inverse_gt_one)
paulson@15077
   757
apply (drule_tac [4] order_less_imp_le [THEN lemma_exp_total], auto)
paulson@15077
   758
apply (rule_tac x = "-x" in exI)
paulson@15077
   759
apply (simp add: exp_minus)
paulson@15077
   760
done
paulson@15077
   761
paulson@15077
   762
paulson@15077
   763
subsection{*Properties of the Logarithmic Function*}
paulson@15077
   764
huffman@23043
   765
definition
huffman@23043
   766
  ln :: "real => real" where
huffman@23043
   767
  "ln x = (THE u. exp u = x)"
huffman@23043
   768
huffman@23043
   769
lemma ln_exp [simp]: "ln (exp x) = x"
paulson@15077
   770
by (simp add: ln_def)
paulson@15077
   771
huffman@22654
   772
lemma exp_ln [simp]: "0 < x \<Longrightarrow> exp (ln x) = x"
huffman@22654
   773
by (auto dest: exp_total)
huffman@22654
   774
huffman@23043
   775
lemma exp_ln_iff [simp]: "(exp (ln x) = x) = (0 < x)"
paulson@15077
   776
apply (auto dest: exp_total)
paulson@15077
   777
apply (erule subst, simp) 
paulson@15077
   778
done
paulson@15077
   779
paulson@15077
   780
lemma ln_mult: "[| 0 < x; 0 < y |] ==> ln(x * y) = ln(x) + ln(y)"
paulson@15077
   781
apply (rule exp_inj_iff [THEN iffD1])
huffman@22654
   782
apply (simp add: exp_add exp_ln mult_pos_pos)
paulson@15077
   783
done
paulson@15077
   784
paulson@15077
   785
lemma ln_inj_iff[simp]: "[| 0 < x; 0 < y |] ==> (ln x = ln y) = (x = y)"
paulson@15077
   786
apply (simp only: exp_ln_iff [symmetric])
paulson@15077
   787
apply (erule subst)+
paulson@15077
   788
apply simp 
paulson@15077
   789
done
paulson@15077
   790
paulson@15077
   791
lemma ln_one[simp]: "ln 1 = 0"
paulson@15077
   792
by (rule exp_inj_iff [THEN iffD1], auto)
paulson@15077
   793
paulson@15077
   794
lemma ln_inverse: "0 < x ==> ln(inverse x) = - ln x"
paulson@15077
   795
apply (rule_tac a1 = "ln x" in add_left_cancel [THEN iffD1])
paulson@15077
   796
apply (auto simp add: positive_imp_inverse_positive ln_mult [symmetric])
paulson@15077
   797
done
paulson@15077
   798
paulson@15077
   799
lemma ln_div: 
paulson@15077
   800
    "[|0 < x; 0 < y|] ==> ln(x/y) = ln x - ln y"
paulson@15229
   801
apply (simp add: divide_inverse)
paulson@15077
   802
apply (auto simp add: positive_imp_inverse_positive ln_mult ln_inverse)
paulson@15077
   803
done
paulson@15077
   804
paulson@15077
   805
lemma ln_less_cancel_iff[simp]: "[| 0 < x; 0 < y|] ==> (ln x < ln y) = (x < y)"
paulson@15077
   806
apply (simp only: exp_ln_iff [symmetric])
paulson@15077
   807
apply (erule subst)+
paulson@15077
   808
apply simp 
paulson@15077
   809
done
paulson@15077
   810
paulson@15077
   811
lemma ln_le_cancel_iff[simp]: "[| 0 < x; 0 < y|] ==> (ln x \<le> ln y) = (x \<le> y)"
paulson@15077
   812
by (auto simp add: linorder_not_less [symmetric])
paulson@15077
   813
paulson@15077
   814
lemma ln_realpow: "0 < x ==> ln(x ^ n) = real n * ln(x)"
paulson@15077
   815
by (auto dest!: exp_total simp add: exp_real_of_nat_mult [symmetric])
paulson@15077
   816
paulson@15077
   817
lemma ln_add_one_self_le_self [simp]: "0 \<le> x ==> ln(1 + x) \<le> x"
paulson@15077
   818
apply (rule ln_exp [THEN subst])
avigad@17014
   819
apply (rule ln_le_cancel_iff [THEN iffD2]) 
avigad@17014
   820
apply (auto simp add: exp_ge_add_one_self_aux)
paulson@15077
   821
done
paulson@15077
   822
paulson@15077
   823
lemma ln_less_self [simp]: "0 < x ==> ln x < x"
paulson@15077
   824
apply (rule order_less_le_trans)
paulson@15077
   825
apply (rule_tac [2] ln_add_one_self_le_self)
paulson@15077
   826
apply (rule ln_less_cancel_iff [THEN iffD2], auto)
paulson@15077
   827
done
paulson@15077
   828
paulson@15234
   829
lemma ln_ge_zero [simp]:
paulson@15077
   830
  assumes x: "1 \<le> x" shows "0 \<le> ln x"
paulson@15077
   831
proof -
paulson@15077
   832
  have "0 < x" using x by arith
paulson@15077
   833
  hence "exp 0 \<le> exp (ln x)"
huffman@22915
   834
    by (simp add: x)
paulson@15077
   835
  thus ?thesis by (simp only: exp_le_cancel_iff)
paulson@15077
   836
qed
paulson@15077
   837
paulson@15077
   838
lemma ln_ge_zero_imp_ge_one:
paulson@15077
   839
  assumes ln: "0 \<le> ln x" 
paulson@15077
   840
      and x:  "0 < x"
paulson@15077
   841
  shows "1 \<le> x"
paulson@15077
   842
proof -
paulson@15077
   843
  from ln have "ln 1 \<le> ln x" by simp
paulson@15077
   844
  thus ?thesis by (simp add: x del: ln_one) 
paulson@15077
   845
qed
paulson@15077
   846
paulson@15077
   847
lemma ln_ge_zero_iff [simp]: "0 < x ==> (0 \<le> ln x) = (1 \<le> x)"
paulson@15077
   848
by (blast intro: ln_ge_zero ln_ge_zero_imp_ge_one)
paulson@15077
   849
paulson@15234
   850
lemma ln_less_zero_iff [simp]: "0 < x ==> (ln x < 0) = (x < 1)"
paulson@15234
   851
by (insert ln_ge_zero_iff [of x], arith)
paulson@15234
   852
paulson@15077
   853
lemma ln_gt_zero:
paulson@15077
   854
  assumes x: "1 < x" shows "0 < ln x"
paulson@15077
   855
proof -
paulson@15077
   856
  have "0 < x" using x by arith
huffman@22915
   857
  hence "exp 0 < exp (ln x)" by (simp add: x)
paulson@15077
   858
  thus ?thesis  by (simp only: exp_less_cancel_iff)
paulson@15077
   859
qed
paulson@15077
   860
paulson@15077
   861
lemma ln_gt_zero_imp_gt_one:
paulson@15077
   862
  assumes ln: "0 < ln x" 
paulson@15077
   863
      and x:  "0 < x"
paulson@15077
   864
  shows "1 < x"
paulson@15077
   865
proof -
paulson@15077
   866
  from ln have "ln 1 < ln x" by simp
paulson@15077
   867
  thus ?thesis by (simp add: x del: ln_one) 
paulson@15077
   868
qed
paulson@15077
   869
paulson@15077
   870
lemma ln_gt_zero_iff [simp]: "0 < x ==> (0 < ln x) = (1 < x)"
paulson@15077
   871
by (blast intro: ln_gt_zero ln_gt_zero_imp_gt_one)
paulson@15077
   872
paulson@15234
   873
lemma ln_eq_zero_iff [simp]: "0 < x ==> (ln x = 0) = (x = 1)"
paulson@15234
   874
by (insert ln_less_zero_iff [of x] ln_gt_zero_iff [of x], arith)
paulson@15077
   875
paulson@15077
   876
lemma ln_less_zero: "[| 0 < x; x < 1 |] ==> ln x < 0"
paulson@15234
   877
by simp
paulson@15077
   878
paulson@15077
   879
lemma exp_ln_eq: "exp u = x ==> ln x = u"
paulson@15077
   880
by auto
paulson@15077
   881
paulson@15077
   882
paulson@15077
   883
subsection{*Basic Properties of the Trigonometric Functions*}
paulson@15077
   884
paulson@15077
   885
lemma sin_zero [simp]: "sin 0 = 0"
paulson@15077
   886
by (auto intro!: sums_unique [symmetric] LIMSEQ_const 
paulson@15077
   887
         simp add: sin_def sums_def simp del: power_0_left)
paulson@15077
   888
nipkow@15539
   889
lemma lemma_series_zero2:
nipkow@15539
   890
 "(\<forall>m. n \<le> m --> f m = 0) --> f sums setsum f {0..<n}"
paulson@15077
   891
by (auto intro: series_zero)
paulson@15077
   892
paulson@15077
   893
lemma cos_zero [simp]: "cos 0 = 1"
paulson@15229
   894
apply (simp add: cos_def)
paulson@15077
   895
apply (rule sums_unique [symmetric])
paulson@15229
   896
apply (cut_tac n = 1 and f = "(%n. (if even n then (- 1) ^ (n div 2) / (real (fact n)) else 0) * 0 ^ n)" in lemma_series_zero2)
paulson@15077
   897
apply auto
paulson@15077
   898
done
paulson@15077
   899
paulson@15077
   900
lemma DERIV_sin_sin_mult [simp]:
paulson@15077
   901
     "DERIV (%x. sin(x)*sin(x)) x :> cos(x) * sin(x) + cos(x) * sin(x)"
paulson@15077
   902
by (rule DERIV_mult, auto)
paulson@15077
   903
paulson@15077
   904
lemma DERIV_sin_sin_mult2 [simp]:
paulson@15077
   905
     "DERIV (%x. sin(x)*sin(x)) x :> 2 * cos(x) * sin(x)"
paulson@15077
   906
apply (cut_tac x = x in DERIV_sin_sin_mult)
paulson@15077
   907
apply (auto simp add: mult_assoc)
paulson@15077
   908
done
paulson@15077
   909
paulson@15077
   910
lemma DERIV_sin_realpow2 [simp]:
paulson@15077
   911
     "DERIV (%x. (sin x)\<twosuperior>) x :> cos(x) * sin(x) + cos(x) * sin(x)"
paulson@15077
   912
by (auto simp add: numeral_2_eq_2 real_mult_assoc [symmetric])
paulson@15077
   913
paulson@15077
   914
lemma DERIV_sin_realpow2a [simp]:
paulson@15077
   915
     "DERIV (%x. (sin x)\<twosuperior>) x :> 2 * cos(x) * sin(x)"
paulson@15077
   916
by (auto simp add: numeral_2_eq_2)
paulson@15077
   917
paulson@15077
   918
lemma DERIV_cos_cos_mult [simp]:
paulson@15077
   919
     "DERIV (%x. cos(x)*cos(x)) x :> -sin(x) * cos(x) + -sin(x) * cos(x)"
paulson@15077
   920
by (rule DERIV_mult, auto)
paulson@15077
   921
paulson@15077
   922
lemma DERIV_cos_cos_mult2 [simp]:
paulson@15077
   923
     "DERIV (%x. cos(x)*cos(x)) x :> -2 * cos(x) * sin(x)"
paulson@15077
   924
apply (cut_tac x = x in DERIV_cos_cos_mult)
paulson@15077
   925
apply (auto simp add: mult_ac)
paulson@15077
   926
done
paulson@15077
   927
paulson@15077
   928
lemma DERIV_cos_realpow2 [simp]:
paulson@15077
   929
     "DERIV (%x. (cos x)\<twosuperior>) x :> -sin(x) * cos(x) + -sin(x) * cos(x)"
paulson@15077
   930
by (auto simp add: numeral_2_eq_2 real_mult_assoc [symmetric])
paulson@15077
   931
paulson@15077
   932
lemma DERIV_cos_realpow2a [simp]:
paulson@15077
   933
     "DERIV (%x. (cos x)\<twosuperior>) x :> -2 * cos(x) * sin(x)"
paulson@15077
   934
by (auto simp add: numeral_2_eq_2)
paulson@15077
   935
paulson@15077
   936
lemma lemma_DERIV_subst: "[| DERIV f x :> D; D = E |] ==> DERIV f x :> E"
paulson@15077
   937
by auto
paulson@15077
   938
paulson@15077
   939
lemma DERIV_cos_realpow2b: "DERIV (%x. (cos x)\<twosuperior>) x :> -(2 * cos(x) * sin(x))"
paulson@15077
   940
apply (rule lemma_DERIV_subst)
paulson@15077
   941
apply (rule DERIV_cos_realpow2a, auto)
paulson@15077
   942
done
paulson@15077
   943
paulson@15077
   944
(* most useful *)
paulson@15229
   945
lemma DERIV_cos_cos_mult3 [simp]:
paulson@15229
   946
     "DERIV (%x. cos(x)*cos(x)) x :> -(2 * cos(x) * sin(x))"
paulson@15077
   947
apply (rule lemma_DERIV_subst)
paulson@15077
   948
apply (rule DERIV_cos_cos_mult2, auto)
paulson@15077
   949
done
paulson@15077
   950
paulson@15077
   951
lemma DERIV_sin_circle_all: 
paulson@15077
   952
     "\<forall>x. DERIV (%x. (sin x)\<twosuperior> + (cos x)\<twosuperior>) x :>  
paulson@15077
   953
             (2*cos(x)*sin(x) - 2*cos(x)*sin(x))"
paulson@15229
   954
apply (simp only: diff_minus, safe)
paulson@15229
   955
apply (rule DERIV_add) 
paulson@15077
   956
apply (auto simp add: numeral_2_eq_2)
paulson@15077
   957
done
paulson@15077
   958
paulson@15229
   959
lemma DERIV_sin_circle_all_zero [simp]:
paulson@15229
   960
     "\<forall>x. DERIV (%x. (sin x)\<twosuperior> + (cos x)\<twosuperior>) x :> 0"
paulson@15077
   961
by (cut_tac DERIV_sin_circle_all, auto)
paulson@15077
   962
paulson@15077
   963
lemma sin_cos_squared_add [simp]: "((sin x)\<twosuperior>) + ((cos x)\<twosuperior>) = 1"
paulson@15077
   964
apply (cut_tac x = x and y = 0 in DERIV_sin_circle_all_zero [THEN DERIV_isconst_all])
paulson@15077
   965
apply (auto simp add: numeral_2_eq_2)
paulson@15077
   966
done
paulson@15077
   967
paulson@15077
   968
lemma sin_cos_squared_add2 [simp]: "((cos x)\<twosuperior>) + ((sin x)\<twosuperior>) = 1"
paulson@15077
   969
apply (subst real_add_commute)
paulson@15077
   970
apply (simp (no_asm) del: realpow_Suc)
paulson@15077
   971
done
paulson@15077
   972
paulson@15077
   973
lemma sin_cos_squared_add3 [simp]: "cos x * cos x + sin x * sin x = 1"
paulson@15077
   974
apply (cut_tac x = x in sin_cos_squared_add2)
paulson@15077
   975
apply (auto simp add: numeral_2_eq_2)
paulson@15077
   976
done
paulson@15077
   977
paulson@15077
   978
lemma sin_squared_eq: "(sin x)\<twosuperior> = 1 - (cos x)\<twosuperior>"
paulson@15229
   979
apply (rule_tac a1 = "(cos x)\<twosuperior>" in add_right_cancel [THEN iffD1])
paulson@15077
   980
apply (simp del: realpow_Suc)
paulson@15077
   981
done
paulson@15077
   982
paulson@15077
   983
lemma cos_squared_eq: "(cos x)\<twosuperior> = 1 - (sin x)\<twosuperior>"
paulson@15077
   984
apply (rule_tac a1 = "(sin x)\<twosuperior>" in add_right_cancel [THEN iffD1])
paulson@15077
   985
apply (simp del: realpow_Suc)
paulson@15077
   986
done
paulson@15077
   987
paulson@15077
   988
lemma real_gt_one_ge_zero_add_less: "[| 1 < x; 0 \<le> y |] ==> 1 < x + (y::real)"
paulson@15077
   989
by arith
paulson@15077
   990
paulson@15081
   991
lemma abs_sin_le_one [simp]: "\<bar>sin x\<bar> \<le> 1"
paulson@15077
   992
apply (auto simp add: linorder_not_less [symmetric])
paulson@15077
   993
apply (drule_tac n = "Suc 0" in power_gt1)
paulson@15077
   994
apply (auto simp del: realpow_Suc)
paulson@15077
   995
apply (drule_tac r1 = "cos x" in realpow_two_le [THEN [2] real_gt_one_ge_zero_add_less])
paulson@15077
   996
apply (simp add: numeral_2_eq_2 [symmetric] del: realpow_Suc)
paulson@15077
   997
done
paulson@15077
   998
paulson@15077
   999
lemma sin_ge_minus_one [simp]: "-1 \<le> sin x"
paulson@15077
  1000
apply (insert abs_sin_le_one [of x]) 
huffman@22998
  1001
apply (simp add: abs_le_iff del: abs_sin_le_one) 
paulson@15077
  1002
done
paulson@15077
  1003
paulson@15077
  1004
lemma sin_le_one [simp]: "sin x \<le> 1"
paulson@15077
  1005
apply (insert abs_sin_le_one [of x]) 
huffman@22998
  1006
apply (simp add: abs_le_iff del: abs_sin_le_one) 
paulson@15077
  1007
done
paulson@15077
  1008
paulson@15081
  1009
lemma abs_cos_le_one [simp]: "\<bar>cos x\<bar> \<le> 1"
paulson@15077
  1010
apply (auto simp add: linorder_not_less [symmetric])
paulson@15077
  1011
apply (drule_tac n = "Suc 0" in power_gt1)
paulson@15077
  1012
apply (auto simp del: realpow_Suc)
paulson@15077
  1013
apply (drule_tac r1 = "sin x" in realpow_two_le [THEN [2] real_gt_one_ge_zero_add_less])
paulson@15077
  1014
apply (simp add: numeral_2_eq_2 [symmetric] del: realpow_Suc)
paulson@15077
  1015
done
paulson@15077
  1016
paulson@15077
  1017
lemma cos_ge_minus_one [simp]: "-1 \<le> cos x"
paulson@15077
  1018
apply (insert abs_cos_le_one [of x]) 
huffman@22998
  1019
apply (simp add: abs_le_iff del: abs_cos_le_one) 
paulson@15077
  1020
done
paulson@15077
  1021
paulson@15077
  1022
lemma cos_le_one [simp]: "cos x \<le> 1"
paulson@15077
  1023
apply (insert abs_cos_le_one [of x]) 
huffman@22998
  1024
apply (simp add: abs_le_iff del: abs_cos_le_one)
paulson@15077
  1025
done
paulson@15077
  1026
paulson@15077
  1027
lemma DERIV_fun_pow: "DERIV g x :> m ==>  
paulson@15077
  1028
      DERIV (%x. (g x) ^ n) x :> real n * (g x) ^ (n - 1) * m"
paulson@15077
  1029
apply (rule lemma_DERIV_subst)
paulson@15229
  1030
apply (rule_tac f = "(%x. x ^ n)" in DERIV_chain2)
paulson@15077
  1031
apply (rule DERIV_pow, auto)
paulson@15077
  1032
done
paulson@15077
  1033
paulson@15229
  1034
lemma DERIV_fun_exp:
paulson@15229
  1035
     "DERIV g x :> m ==> DERIV (%x. exp(g x)) x :> exp(g x) * m"
paulson@15077
  1036
apply (rule lemma_DERIV_subst)
paulson@15077
  1037
apply (rule_tac f = exp in DERIV_chain2)
paulson@15077
  1038
apply (rule DERIV_exp, auto)
paulson@15077
  1039
done
paulson@15077
  1040
paulson@15229
  1041
lemma DERIV_fun_sin:
paulson@15229
  1042
     "DERIV g x :> m ==> DERIV (%x. sin(g x)) x :> cos(g x) * m"
paulson@15077
  1043
apply (rule lemma_DERIV_subst)
paulson@15077
  1044
apply (rule_tac f = sin in DERIV_chain2)
paulson@15077
  1045
apply (rule DERIV_sin, auto)
paulson@15077
  1046
done
paulson@15077
  1047
paulson@15229
  1048
lemma DERIV_fun_cos:
paulson@15229
  1049
     "DERIV g x :> m ==> DERIV (%x. cos(g x)) x :> -sin(g x) * m"
paulson@15077
  1050
apply (rule lemma_DERIV_subst)
paulson@15077
  1051
apply (rule_tac f = cos in DERIV_chain2)
paulson@15077
  1052
apply (rule DERIV_cos, auto)
paulson@15077
  1053
done
paulson@15077
  1054
paulson@15077
  1055
lemmas DERIV_intros = DERIV_Id DERIV_const DERIV_cos DERIV_cmult 
paulson@15077
  1056
                    DERIV_sin  DERIV_exp  DERIV_inverse DERIV_pow 
paulson@15077
  1057
                    DERIV_add  DERIV_diff  DERIV_mult  DERIV_minus 
paulson@15077
  1058
                    DERIV_inverse_fun DERIV_quotient DERIV_fun_pow 
paulson@15077
  1059
                    DERIV_fun_exp DERIV_fun_sin DERIV_fun_cos 
paulson@15077
  1060
paulson@15077
  1061
(* lemma *)
paulson@15229
  1062
lemma lemma_DERIV_sin_cos_add:
paulson@15229
  1063
     "\<forall>x.  
paulson@15077
  1064
         DERIV (%x. (sin (x + y) - (sin x * cos y + cos x * sin y)) ^ 2 +  
paulson@15077
  1065
               (cos (x + y) - (cos x * cos y - sin x * sin y)) ^ 2) x :> 0"
paulson@15077
  1066
apply (safe, rule lemma_DERIV_subst)
paulson@15077
  1067
apply (best intro!: DERIV_intros intro: DERIV_chain2) 
paulson@15077
  1068
  --{*replaces the old @{text DERIV_tac}*}
paulson@15229
  1069
apply (auto simp add: diff_minus left_distrib right_distrib mult_ac add_ac)
paulson@15077
  1070
done
paulson@15077
  1071
paulson@15077
  1072
lemma sin_cos_add [simp]:
paulson@15077
  1073
     "(sin (x + y) - (sin x * cos y + cos x * sin y)) ^ 2 +  
paulson@15077
  1074
      (cos (x + y) - (cos x * cos y - sin x * sin y)) ^ 2 = 0"
paulson@15077
  1075
apply (cut_tac y = 0 and x = x and y7 = y 
paulson@15077
  1076
       in lemma_DERIV_sin_cos_add [THEN DERIV_isconst_all])
paulson@15077
  1077
apply (auto simp add: numeral_2_eq_2)
paulson@15077
  1078
done
paulson@15077
  1079
paulson@15077
  1080
lemma sin_add: "sin (x + y) = sin x * cos y + cos x * sin y"
paulson@15077
  1081
apply (cut_tac x = x and y = y in sin_cos_add)
huffman@22969
  1082
apply (simp del: sin_cos_add)
paulson@15077
  1083
done
paulson@15077
  1084
paulson@15077
  1085
lemma cos_add: "cos (x + y) = cos x * cos y - sin x * sin y"
paulson@15077
  1086
apply (cut_tac x = x and y = y in sin_cos_add)
huffman@22969
  1087
apply (simp del: sin_cos_add)
paulson@15077
  1088
done
paulson@15077
  1089
paulson@15085
  1090
lemma lemma_DERIV_sin_cos_minus:
paulson@15085
  1091
    "\<forall>x. DERIV (%x. (sin(-x) + (sin x)) ^ 2 + (cos(-x) - (cos x)) ^ 2) x :> 0"
paulson@15077
  1092
apply (safe, rule lemma_DERIV_subst)
paulson@15077
  1093
apply (best intro!: DERIV_intros intro: DERIV_chain2) 
paulson@15229
  1094
apply (auto simp add: diff_minus left_distrib right_distrib mult_ac add_ac)
paulson@15077
  1095
done
paulson@15077
  1096
paulson@15085
  1097
lemma sin_cos_minus [simp]: 
paulson@15085
  1098
    "(sin(-x) + (sin x)) ^ 2 + (cos(-x) - (cos x)) ^ 2 = 0"
paulson@15085
  1099
apply (cut_tac y = 0 and x = x 
paulson@15085
  1100
       in lemma_DERIV_sin_cos_minus [THEN DERIV_isconst_all])
huffman@22969
  1101
apply simp
paulson@15077
  1102
done
paulson@15077
  1103
paulson@15077
  1104
lemma sin_minus [simp]: "sin (-x) = -sin(x)"
paulson@15077
  1105
apply (cut_tac x = x in sin_cos_minus)
huffman@22969
  1106
apply (simp del: sin_cos_minus)
paulson@15077
  1107
done
paulson@15077
  1108
paulson@15077
  1109
lemma cos_minus [simp]: "cos (-x) = cos(x)"
paulson@15077
  1110
apply (cut_tac x = x in sin_cos_minus)
huffman@22969
  1111
apply (simp del: sin_cos_minus)
paulson@15077
  1112
done
paulson@15077
  1113
paulson@15077
  1114
lemma sin_diff: "sin (x - y) = sin x * cos y - cos x * sin y"
huffman@22969
  1115
by (simp add: diff_minus sin_add)
paulson@15077
  1116
paulson@15077
  1117
lemma sin_diff2: "sin (x - y) = cos y * sin x - sin y * cos x"
paulson@15077
  1118
by (simp add: sin_diff mult_commute)
paulson@15077
  1119
paulson@15077
  1120
lemma cos_diff: "cos (x - y) = cos x * cos y + sin x * sin y"
huffman@22969
  1121
by (simp add: diff_minus cos_add)
paulson@15077
  1122
paulson@15077
  1123
lemma cos_diff2: "cos (x - y) = cos y * cos x + sin y * sin x"
paulson@15077
  1124
by (simp add: cos_diff mult_commute)
paulson@15077
  1125
paulson@15077
  1126
lemma sin_double [simp]: "sin(2 * x) = 2* sin x * cos x"
paulson@15077
  1127
by (cut_tac x = x and y = x in sin_add, auto)
paulson@15077
  1128
paulson@15077
  1129
paulson@15077
  1130
lemma cos_double: "cos(2* x) = ((cos x)\<twosuperior>) - ((sin x)\<twosuperior>)"
paulson@15077
  1131
apply (cut_tac x = x and y = x in cos_add)
huffman@22969
  1132
apply (simp add: power2_eq_square)
paulson@15077
  1133
done
paulson@15077
  1134
paulson@15077
  1135
paulson@15077
  1136
subsection{*The Constant Pi*}
paulson@15077
  1137
huffman@23043
  1138
definition
huffman@23043
  1139
  pi :: "real" where
huffman@23043
  1140
  "pi = 2 * (@x. 0 \<le> (x::real) & x \<le> 2 & cos x = 0)"
huffman@23043
  1141
paulson@15077
  1142
text{*Show that there's a least positive @{term x} with @{term "cos(x) = 0"}; 
paulson@15077
  1143
   hence define pi.*}
paulson@15077
  1144
paulson@15077
  1145
lemma sin_paired:
paulson@15077
  1146
     "(%n. (- 1) ^ n /(real (fact (2 * n + 1))) * x ^ (2 * n + 1)) 
paulson@15077
  1147
      sums  sin x"
paulson@15077
  1148
proof -
paulson@15077
  1149
  have "(\<lambda>n. \<Sum>k = n * 2..<n * 2 + 2.
paulson@15077
  1150
            (if even k then 0
paulson@15077
  1151
             else (- 1) ^ ((k - Suc 0) div 2) / real (fact k)) *
paulson@15077
  1152
            x ^ k) 
paulson@15077
  1153
	sums
nipkow@15546
  1154
	(\<Sum>n. (if even n then 0
paulson@15077
  1155
		     else (- 1) ^ ((n - Suc 0) div 2) / real (fact n)) *
paulson@15077
  1156
	            x ^ n)" 
paulson@15077
  1157
    by (rule sin_converges [THEN sums_summable, THEN sums_group], simp) 
paulson@15077
  1158
  thus ?thesis by (simp add: mult_ac sin_def)
paulson@15077
  1159
qed
paulson@15077
  1160
paulson@15077
  1161
lemma sin_gt_zero: "[|0 < x; x < 2 |] ==> 0 < sin x"
paulson@15077
  1162
apply (subgoal_tac 
paulson@15077
  1163
       "(\<lambda>n. \<Sum>k = n * 2..<n * 2 + 2.
paulson@15077
  1164
              (- 1) ^ k / real (fact (2 * k + 1)) * x ^ (2 * k + 1)) 
nipkow@15546
  1165
     sums (\<Sum>n. (- 1) ^ n / real (fact (2 * n + 1)) * x ^ (2 * n + 1))")
paulson@15077
  1166
 prefer 2
paulson@15077
  1167
 apply (rule sin_paired [THEN sums_summable, THEN sums_group], simp) 
paulson@15077
  1168
apply (rotate_tac 2)
paulson@15077
  1169
apply (drule sin_paired [THEN sums_unique, THEN ssubst])
paulson@15077
  1170
apply (auto simp del: fact_Suc realpow_Suc)
paulson@15077
  1171
apply (frule sums_unique)
paulson@15077
  1172
apply (auto simp del: fact_Suc realpow_Suc)
paulson@15077
  1173
apply (rule_tac n1 = 0 in series_pos_less [THEN [2] order_le_less_trans])
paulson@15077
  1174
apply (auto simp del: fact_Suc realpow_Suc)
paulson@15077
  1175
apply (erule sums_summable)
paulson@15077
  1176
apply (case_tac "m=0")
paulson@15077
  1177
apply (simp (no_asm_simp))
paulson@15234
  1178
apply (subgoal_tac "6 * (x * (x * x) / real (Suc (Suc (Suc (Suc (Suc (Suc 0))))))) < 6 * x") 
nipkow@15539
  1179
apply (simp only: mult_less_cancel_left, simp)  
nipkow@15539
  1180
apply (simp (no_asm_simp) add: numeral_2_eq_2 [symmetric] mult_assoc [symmetric])
paulson@15077
  1181
apply (subgoal_tac "x*x < 2*3", simp) 
paulson@15077
  1182
apply (rule mult_strict_mono)
paulson@15085
  1183
apply (auto simp add: real_0_less_add_iff real_of_nat_Suc simp del: fact_Suc)
paulson@15077
  1184
apply (subst fact_Suc)
paulson@15077
  1185
apply (subst fact_Suc)
paulson@15077
  1186
apply (subst fact_Suc)
paulson@15077
  1187
apply (subst fact_Suc)
paulson@15077
  1188
apply (subst real_of_nat_mult)
paulson@15077
  1189
apply (subst real_of_nat_mult)
paulson@15077
  1190
apply (subst real_of_nat_mult)
paulson@15077
  1191
apply (subst real_of_nat_mult)
nipkow@15539
  1192
apply (simp (no_asm) add: divide_inverse del: fact_Suc)
paulson@15077
  1193
apply (auto simp add: mult_assoc [symmetric] simp del: fact_Suc)
paulson@15077
  1194
apply (rule_tac c="real (Suc (Suc (4*m)))" in mult_less_imp_less_right) 
paulson@15077
  1195
apply (auto simp add: mult_assoc simp del: fact_Suc)
paulson@15077
  1196
apply (rule_tac c="real (Suc (Suc (Suc (4*m))))" in mult_less_imp_less_right) 
paulson@15077
  1197
apply (auto simp add: mult_assoc mult_less_cancel_left simp del: fact_Suc)
paulson@15077
  1198
apply (subgoal_tac "x * (x * x ^ (4*m)) = (x ^ (4*m)) * (x * x)") 
paulson@15077
  1199
apply (erule ssubst)+
paulson@15077
  1200
apply (auto simp del: fact_Suc)
paulson@15077
  1201
apply (subgoal_tac "0 < x ^ (4 * m) ")
paulson@15077
  1202
 prefer 2 apply (simp only: zero_less_power) 
paulson@15077
  1203
apply (simp (no_asm_simp) add: mult_less_cancel_left)
paulson@15077
  1204
apply (rule mult_strict_mono)
paulson@15077
  1205
apply (simp_all (no_asm_simp))
paulson@15077
  1206
done
paulson@15077
  1207
paulson@15077
  1208
lemma sin_gt_zero1: "[|0 < x; x < 2 |] ==> 0 < sin x"
paulson@15077
  1209
by (auto intro: sin_gt_zero)
paulson@15077
  1210
paulson@15077
  1211
lemma cos_double_less_one: "[| 0 < x; x < 2 |] ==> cos (2 * x) < 1"
paulson@15077
  1212
apply (cut_tac x = x in sin_gt_zero1)
paulson@15077
  1213
apply (auto simp add: cos_squared_eq cos_double)
paulson@15077
  1214
done
paulson@15077
  1215
paulson@15077
  1216
lemma cos_paired:
paulson@15077
  1217
     "(%n. (- 1) ^ n /(real (fact (2 * n))) * x ^ (2 * n)) sums cos x"
paulson@15077
  1218
proof -
paulson@15077
  1219
  have "(\<lambda>n. \<Sum>k = n * 2..<n * 2 + 2.
paulson@15077
  1220
            (if even k then (- 1) ^ (k div 2) / real (fact k) else 0) *
paulson@15077
  1221
            x ^ k) 
paulson@15077
  1222
        sums
nipkow@15546
  1223
	(\<Sum>n. (if even n then (- 1) ^ (n div 2) / real (fact n) else 0) *
paulson@15077
  1224
	      x ^ n)" 
paulson@15077
  1225
    by (rule cos_converges [THEN sums_summable, THEN sums_group], simp) 
paulson@15077
  1226
  thus ?thesis by (simp add: mult_ac cos_def)
paulson@15077
  1227
qed
paulson@15077
  1228
paulson@15077
  1229
declare zero_less_power [simp]
paulson@15077
  1230
paulson@15077
  1231
lemma fact_lemma: "real (n::nat) * 4 = real (4 * n)"
paulson@15077
  1232
by simp
paulson@15077
  1233
paulson@15077
  1234
lemma cos_two_less_zero: "cos (2) < 0"
paulson@15077
  1235
apply (cut_tac x = 2 in cos_paired)
paulson@15077
  1236
apply (drule sums_minus)
paulson@15077
  1237
apply (rule neg_less_iff_less [THEN iffD1]) 
nipkow@15539
  1238
apply (frule sums_unique, auto)
nipkow@15539
  1239
apply (rule_tac y =
nipkow@15539
  1240
 "\<Sum>n=0..< Suc(Suc(Suc 0)). - ((- 1) ^ n / (real(fact (2*n))) * 2 ^ (2*n))"
paulson@15481
  1241
       in order_less_trans)
paulson@15077
  1242
apply (simp (no_asm) add: fact_num_eq_if realpow_num_eq_if del: fact_Suc realpow_Suc)
nipkow@15561
  1243
apply (simp (no_asm) add: mult_assoc del: setsum_op_ivl_Suc)
paulson@15077
  1244
apply (rule sumr_pos_lt_pair)
paulson@15077
  1245
apply (erule sums_summable, safe)
paulson@15085
  1246
apply (simp (no_asm) add: divide_inverse real_0_less_add_iff mult_assoc [symmetric] 
paulson@15085
  1247
            del: fact_Suc)
paulson@15077
  1248
apply (rule real_mult_inverse_cancel2)
paulson@15077
  1249
apply (rule real_of_nat_fact_gt_zero)+
paulson@15077
  1250
apply (simp (no_asm) add: mult_assoc [symmetric] del: fact_Suc)
paulson@15077
  1251
apply (subst fact_lemma) 
paulson@15481
  1252
apply (subst fact_Suc [of "Suc (Suc (Suc (Suc (Suc (Suc (Suc (4 * d)))))))"])
paulson@15481
  1253
apply (simp only: real_of_nat_mult)
huffman@23007
  1254
apply (rule mult_strict_mono, force)
huffman@23007
  1255
  apply (rule_tac [3] real_of_nat_fact_ge_zero)
paulson@15481
  1256
 prefer 2 apply force
paulson@15077
  1257
apply (rule real_of_nat_less_iff [THEN iffD2])
paulson@15077
  1258
apply (rule fact_less_mono, auto)
paulson@15077
  1259
done
paulson@15077
  1260
declare cos_two_less_zero [simp]
huffman@22998
  1261
declare cos_two_less_zero [THEN less_imp_neq, simp]
paulson@15077
  1262
declare cos_two_less_zero [THEN order_less_imp_le, simp]
paulson@15077
  1263
paulson@15077
  1264
lemma cos_is_zero: "EX! x. 0 \<le> x & x \<le> 2 & cos x = 0"
paulson@15077
  1265
apply (subgoal_tac "\<exists>x. 0 \<le> x & x \<le> 2 & cos x = 0")
paulson@15077
  1266
apply (rule_tac [2] IVT2)
paulson@15077
  1267
apply (auto intro: DERIV_isCont DERIV_cos)
paulson@15077
  1268
apply (cut_tac x = xa and y = y in linorder_less_linear)
paulson@15077
  1269
apply (rule ccontr)
paulson@15077
  1270
apply (subgoal_tac " (\<forall>x. cos differentiable x) & (\<forall>x. isCont cos x) ")
paulson@15077
  1271
apply (auto intro: DERIV_cos DERIV_isCont simp add: differentiable_def)
paulson@15077
  1272
apply (drule_tac f = cos in Rolle)
paulson@15077
  1273
apply (drule_tac [5] f = cos in Rolle)
paulson@15077
  1274
apply (auto dest!: DERIV_cos [THEN DERIV_unique] simp add: differentiable_def)
paulson@15077
  1275
apply (drule_tac y1 = xa in order_le_less_trans [THEN sin_gt_zero])
paulson@15077
  1276
apply (assumption, rule_tac y=y in order_less_le_trans, simp_all) 
paulson@15077
  1277
apply (drule_tac y1 = y in order_le_less_trans [THEN sin_gt_zero], assumption, simp_all) 
paulson@15077
  1278
done
paulson@15077
  1279
    
paulson@15077
  1280
lemma pi_half: "pi/2 = (@x. 0 \<le> x & x \<le> 2 & cos x = 0)"
paulson@15077
  1281
by (simp add: pi_def)
paulson@15077
  1282
paulson@15077
  1283
lemma cos_pi_half [simp]: "cos (pi / 2) = 0"
paulson@15077
  1284
apply (rule cos_is_zero [THEN ex1E])
paulson@15077
  1285
apply (auto intro!: someI2 simp add: pi_half)
paulson@15077
  1286
done
paulson@15077
  1287
paulson@15077
  1288
lemma pi_half_gt_zero: "0 < pi / 2"
paulson@15077
  1289
apply (rule cos_is_zero [THEN ex1E])
paulson@15077
  1290
apply (auto simp add: pi_half)
paulson@15077
  1291
apply (rule someI2, blast, safe)
huffman@22998
  1292
apply (drule_tac y = xa in order_le_imp_less_or_eq)
paulson@15077
  1293
apply (safe, simp)
paulson@15077
  1294
done
paulson@15077
  1295
declare pi_half_gt_zero [simp]
huffman@22998
  1296
declare pi_half_gt_zero [THEN less_imp_neq, THEN not_sym, simp]
paulson@15077
  1297
declare pi_half_gt_zero [THEN order_less_imp_le, simp]
paulson@15077
  1298
paulson@15077
  1299
lemma pi_half_less_two: "pi / 2 < 2"
paulson@15077
  1300
apply (rule cos_is_zero [THEN ex1E])
paulson@15077
  1301
apply (auto simp add: pi_half)
paulson@15077
  1302
apply (rule someI2, blast, safe)
paulson@15077
  1303
apply (drule_tac x = xa in order_le_imp_less_or_eq)
paulson@15077
  1304
apply (safe, simp)
paulson@15077
  1305
done
paulson@15077
  1306
declare pi_half_less_two [simp]
huffman@22998
  1307
declare pi_half_less_two [THEN less_imp_neq, simp]
paulson@15077
  1308
declare pi_half_less_two [THEN order_less_imp_le, simp]
paulson@15077
  1309
paulson@15077
  1310
lemma pi_gt_zero [simp]: "0 < pi"
paulson@15229
  1311
apply (insert pi_half_gt_zero) 
paulson@15229
  1312
apply (simp add: ); 
paulson@15077
  1313
done
paulson@15077
  1314
paulson@15077
  1315
lemma pi_neq_zero [simp]: "pi \<noteq> 0"
huffman@22998
  1316
by (rule pi_gt_zero [THEN less_imp_neq, THEN not_sym])
paulson@15077
  1317
paulson@15077
  1318
lemma pi_not_less_zero [simp]: "~ (pi < 0)"
paulson@15077
  1319
apply (insert pi_gt_zero)
paulson@15077
  1320
apply (blast elim: order_less_asym) 
paulson@15077
  1321
done
paulson@15077
  1322
paulson@15077
  1323
lemma pi_ge_zero [simp]: "0 \<le> pi"
paulson@15077
  1324
by (auto intro: order_less_imp_le)
paulson@15077
  1325
paulson@15077
  1326
lemma minus_pi_half_less_zero [simp]: "-(pi/2) < 0"
paulson@15077
  1327
by auto
paulson@15077
  1328
paulson@15077
  1329
lemma sin_pi_half [simp]: "sin(pi/2) = 1"
paulson@15077
  1330
apply (cut_tac x = "pi/2" in sin_cos_squared_add2)
paulson@15077
  1331
apply (cut_tac sin_gt_zero [OF pi_half_gt_zero pi_half_less_two])
paulson@15077
  1332
apply (auto simp add: numeral_2_eq_2)
paulson@15077
  1333
done
paulson@15077
  1334
paulson@15077
  1335
lemma cos_pi [simp]: "cos pi = -1"
nipkow@15539
  1336
by (cut_tac x = "pi/2" and y = "pi/2" in cos_add, simp)
paulson@15077
  1337
paulson@15077
  1338
lemma sin_pi [simp]: "sin pi = 0"
nipkow@15539
  1339
by (cut_tac x = "pi/2" and y = "pi/2" in sin_add, simp)
paulson@15077
  1340
paulson@15077
  1341
lemma sin_cos_eq: "sin x = cos (pi/2 - x)"
paulson@15229
  1342
by (simp add: diff_minus cos_add)
paulson@15077
  1343
paulson@15077
  1344
lemma minus_sin_cos_eq: "-sin x = cos (x + pi/2)"
paulson@15229
  1345
by (simp add: cos_add)
paulson@15077
  1346
declare minus_sin_cos_eq [symmetric, simp]
paulson@15077
  1347
paulson@15077
  1348
lemma cos_sin_eq: "cos x = sin (pi/2 - x)"
paulson@15229
  1349
by (simp add: diff_minus sin_add)
paulson@15077
  1350
declare sin_cos_eq [symmetric, simp] cos_sin_eq [symmetric, simp]
paulson@15077
  1351
paulson@15077
  1352
lemma sin_periodic_pi [simp]: "sin (x + pi) = - sin x"
paulson@15229
  1353
by (simp add: sin_add)
paulson@15077
  1354
paulson@15077
  1355
lemma sin_periodic_pi2 [simp]: "sin (pi + x) = - sin x"
paulson@15229
  1356
by (simp add: sin_add)
paulson@15077
  1357
paulson@15077
  1358
lemma cos_periodic_pi [simp]: "cos (x + pi) = - cos x"
paulson@15229
  1359
by (simp add: cos_add)
paulson@15077
  1360
paulson@15077
  1361
lemma sin_periodic [simp]: "sin (x + 2*pi) = sin x"
paulson@15077
  1362
by (simp add: sin_add cos_double)
paulson@15077
  1363
paulson@15077
  1364
lemma cos_periodic [simp]: "cos (x + 2*pi) = cos x"
paulson@15077
  1365
by (simp add: cos_add cos_double)
paulson@15077
  1366
paulson@15077
  1367
lemma cos_npi [simp]: "cos (real n * pi) = -1 ^ n"
paulson@15251
  1368
apply (induct "n")
paulson@15077
  1369
apply (auto simp add: real_of_nat_Suc left_distrib)
paulson@15077
  1370
done
paulson@15077
  1371
paulson@15383
  1372
lemma cos_npi2 [simp]: "cos (pi * real n) = -1 ^ n"
paulson@15383
  1373
proof -
paulson@15383
  1374
  have "cos (pi * real n) = cos (real n * pi)" by (simp only: mult_commute)
paulson@15383
  1375
  also have "... = -1 ^ n" by (rule cos_npi) 
paulson@15383
  1376
  finally show ?thesis .
paulson@15383
  1377
qed
paulson@15383
  1378
paulson@15077
  1379
lemma sin_npi [simp]: "sin (real (n::nat) * pi) = 0"
paulson@15251
  1380
apply (induct "n")
paulson@15077
  1381
apply (auto simp add: real_of_nat_Suc left_distrib)
paulson@15077
  1382
done
paulson@15077
  1383
paulson@15077
  1384
lemma sin_npi2 [simp]: "sin (pi * real (n::nat)) = 0"
paulson@15383
  1385
by (simp add: mult_commute [of pi]) 
paulson@15077
  1386
paulson@15077
  1387
lemma cos_two_pi [simp]: "cos (2 * pi) = 1"
paulson@15077
  1388
by (simp add: cos_double)
paulson@15077
  1389
paulson@15077
  1390
lemma sin_two_pi [simp]: "sin (2 * pi) = 0"
paulson@15229
  1391
by simp
paulson@15077
  1392
paulson@15077
  1393
lemma sin_gt_zero2: "[| 0 < x; x < pi/2 |] ==> 0 < sin x"
paulson@15077
  1394
apply (rule sin_gt_zero, assumption)
paulson@15077
  1395
apply (rule order_less_trans, assumption)
paulson@15077
  1396
apply (rule pi_half_less_two)
paulson@15077
  1397
done
paulson@15077
  1398
paulson@15077
  1399
lemma sin_less_zero: 
paulson@15077
  1400
  assumes lb: "- pi/2 < x" and "x < 0" shows "sin x < 0"
paulson@15077
  1401
proof -
paulson@15077
  1402
  have "0 < sin (- x)" using prems by (simp only: sin_gt_zero2) 
paulson@15077
  1403
  thus ?thesis by simp
paulson@15077
  1404
qed
paulson@15077
  1405
paulson@15077
  1406
lemma pi_less_4: "pi < 4"
paulson@15077
  1407
by (cut_tac pi_half_less_two, auto)
paulson@15077
  1408
paulson@15077
  1409
lemma cos_gt_zero: "[| 0 < x; x < pi/2 |] ==> 0 < cos x"
paulson@15077
  1410
apply (cut_tac pi_less_4)
paulson@15077
  1411
apply (cut_tac f = cos and a = 0 and b = x and y = 0 in IVT2_objl, safe, simp_all)
paulson@15077
  1412
apply (force intro: DERIV_isCont DERIV_cos)
paulson@15077
  1413
apply (cut_tac cos_is_zero, safe)
paulson@15077
  1414
apply (rename_tac y z)
paulson@15077
  1415
apply (drule_tac x = y in spec)
paulson@15077
  1416
apply (drule_tac x = "pi/2" in spec, simp) 
paulson@15077
  1417
done
paulson@15077
  1418
paulson@15077
  1419
lemma cos_gt_zero_pi: "[| -(pi/2) < x; x < pi/2 |] ==> 0 < cos x"
paulson@15077
  1420
apply (rule_tac x = x and y = 0 in linorder_cases)
paulson@15077
  1421
apply (rule cos_minus [THEN subst])
paulson@15077
  1422
apply (rule cos_gt_zero)
paulson@15077
  1423
apply (auto intro: cos_gt_zero)
paulson@15077
  1424
done
paulson@15077
  1425
 
paulson@15077
  1426
lemma cos_ge_zero: "[| -(pi/2) \<le> x; x \<le> pi/2 |] ==> 0 \<le> cos x"
paulson@15077
  1427
apply (auto simp add: order_le_less cos_gt_zero_pi)
paulson@15077
  1428
apply (subgoal_tac "x = pi/2", auto) 
paulson@15077
  1429
done
paulson@15077
  1430
paulson@15077
  1431
lemma sin_gt_zero_pi: "[| 0 < x; x < pi  |] ==> 0 < sin x"
paulson@15077
  1432
apply (subst sin_cos_eq)
paulson@15077
  1433
apply (rotate_tac 1)
paulson@15077
  1434
apply (drule real_sum_of_halves [THEN ssubst])
paulson@15077
  1435
apply (auto intro!: cos_gt_zero_pi simp del: sin_cos_eq [symmetric])
paulson@15077
  1436
done
paulson@15077
  1437
paulson@15077
  1438
lemma sin_ge_zero: "[| 0 \<le> x; x \<le> pi |] ==> 0 \<le> sin x"
paulson@15077
  1439
by (auto simp add: order_le_less sin_gt_zero_pi)
paulson@15077
  1440
paulson@15077
  1441
lemma cos_total: "[| -1 \<le> y; y \<le> 1 |] ==> EX! x. 0 \<le> x & x \<le> pi & (cos x = y)"
paulson@15077
  1442
apply (subgoal_tac "\<exists>x. 0 \<le> x & x \<le> pi & cos x = y")
paulson@15077
  1443
apply (rule_tac [2] IVT2)
paulson@15077
  1444
apply (auto intro: order_less_imp_le DERIV_isCont DERIV_cos)
paulson@15077
  1445
apply (cut_tac x = xa and y = y in linorder_less_linear)
paulson@15077
  1446
apply (rule ccontr, auto)
paulson@15077
  1447
apply (drule_tac f = cos in Rolle)
paulson@15077
  1448
apply (drule_tac [5] f = cos in Rolle)
paulson@15077
  1449
apply (auto intro: order_less_imp_le DERIV_isCont DERIV_cos
paulson@15077
  1450
            dest!: DERIV_cos [THEN DERIV_unique] 
paulson@15077
  1451
            simp add: differentiable_def)
paulson@15077
  1452
apply (auto dest: sin_gt_zero_pi [OF order_le_less_trans order_less_le_trans])
paulson@15077
  1453
done
paulson@15077
  1454
paulson@15077
  1455
lemma sin_total:
paulson@15077
  1456
     "[| -1 \<le> y; y \<le> 1 |] ==> EX! x. -(pi/2) \<le> x & x \<le> pi/2 & (sin x = y)"
paulson@15077
  1457
apply (rule ccontr)
paulson@15077
  1458
apply (subgoal_tac "\<forall>x. (- (pi/2) \<le> x & x \<le> pi/2 & (sin x = y)) = (0 \<le> (x + pi/2) & (x + pi/2) \<le> pi & (cos (x + pi/2) = -y))")
wenzelm@18585
  1459
apply (erule contrapos_np)
paulson@15077
  1460
apply (simp del: minus_sin_cos_eq [symmetric])
paulson@15077
  1461
apply (cut_tac y="-y" in cos_total, simp) apply simp 
paulson@15077
  1462
apply (erule ex1E)
paulson@15229
  1463
apply (rule_tac a = "x - (pi/2)" in ex1I)
paulson@15077
  1464
apply (simp (no_asm) add: real_add_assoc)
paulson@15077
  1465
apply (rotate_tac 3)
paulson@15077
  1466
apply (drule_tac x = "xa + pi/2" in spec, safe, simp_all) 
paulson@15077
  1467
done
paulson@15077
  1468
paulson@15077
  1469
lemma reals_Archimedean4:
paulson@15077
  1470
     "[| 0 < y; 0 \<le> x |] ==> \<exists>n. real n * y \<le> x & x < real (Suc n) * y"
paulson@15077
  1471
apply (auto dest!: reals_Archimedean3)
paulson@15077
  1472
apply (drule_tac x = x in spec, clarify) 
paulson@15077
  1473
apply (subgoal_tac "x < real(LEAST m::nat. x < real m * y) * y")
paulson@15077
  1474
 prefer 2 apply (erule LeastI) 
paulson@15077
  1475
apply (case_tac "LEAST m::nat. x < real m * y", simp) 
paulson@15077
  1476
apply (subgoal_tac "~ x < real nat * y")
paulson@15077
  1477
 prefer 2 apply (rule not_less_Least, simp, force)  
paulson@15077
  1478
done
paulson@15077
  1479
paulson@15077
  1480
(* Pre Isabelle99-2 proof was simpler- numerals arithmetic 
paulson@15077
  1481
   now causes some unwanted re-arrangements of literals!   *)
paulson@15229
  1482
lemma cos_zero_lemma:
paulson@15229
  1483
     "[| 0 \<le> x; cos x = 0 |] ==>  
paulson@15077
  1484
      \<exists>n::nat. ~even n & x = real n * (pi/2)"
paulson@15077
  1485
apply (drule pi_gt_zero [THEN reals_Archimedean4], safe)
paulson@15086
  1486
apply (subgoal_tac "0 \<le> x - real n * pi & 
paulson@15086
  1487
                    (x - real n * pi) \<le> pi & (cos (x - real n * pi) = 0) ")
paulson@15086
  1488
apply (auto simp add: compare_rls) 
paulson@15077
  1489
  prefer 3 apply (simp add: cos_diff) 
paulson@15077
  1490
 prefer 2 apply (simp add: real_of_nat_Suc left_distrib) 
paulson@15077
  1491
apply (simp add: cos_diff)
paulson@15077
  1492
apply (subgoal_tac "EX! x. 0 \<le> x & x \<le> pi & cos x = 0")
paulson@15077
  1493
apply (rule_tac [2] cos_total, safe)
paulson@15077
  1494
apply (drule_tac x = "x - real n * pi" in spec)
paulson@15077
  1495
apply (drule_tac x = "pi/2" in spec)
paulson@15077
  1496
apply (simp add: cos_diff)
paulson@15229
  1497
apply (rule_tac x = "Suc (2 * n)" in exI)
paulson@15077
  1498
apply (simp add: real_of_nat_Suc left_distrib, auto)
paulson@15077
  1499
done
paulson@15077
  1500
paulson@15229
  1501
lemma sin_zero_lemma:
paulson@15229
  1502
     "[| 0 \<le> x; sin x = 0 |] ==>  
paulson@15077
  1503
      \<exists>n::nat. even n & x = real n * (pi/2)"
paulson@15077
  1504
apply (subgoal_tac "\<exists>n::nat. ~ even n & x + pi/2 = real n * (pi/2) ")
paulson@15077
  1505
 apply (clarify, rule_tac x = "n - 1" in exI)
paulson@15077
  1506
 apply (force simp add: odd_Suc_mult_two_ex real_of_nat_Suc left_distrib)
paulson@15085
  1507
apply (rule cos_zero_lemma)
paulson@15085
  1508
apply (simp_all add: add_increasing)  
paulson@15077
  1509
done
paulson@15077
  1510
paulson@15077
  1511
paulson@15229
  1512
lemma cos_zero_iff:
paulson@15229
  1513
     "(cos x = 0) =  
paulson@15077
  1514
      ((\<exists>n::nat. ~even n & (x = real n * (pi/2))) |    
paulson@15077
  1515
       (\<exists>n::nat. ~even n & (x = -(real n * (pi/2)))))"
paulson@15077
  1516
apply (rule iffI)
paulson@15077
  1517
apply (cut_tac linorder_linear [of 0 x], safe)
paulson@15077
  1518
apply (drule cos_zero_lemma, assumption+)
paulson@15077
  1519
apply (cut_tac x="-x" in cos_zero_lemma, simp, simp) 
paulson@15077
  1520
apply (force simp add: minus_equation_iff [of x]) 
paulson@15077
  1521
apply (auto simp only: odd_Suc_mult_two_ex real_of_nat_Suc left_distrib) 
nipkow@15539
  1522
apply (auto simp add: cos_add)
paulson@15077
  1523
done
paulson@15077
  1524
paulson@15077
  1525
(* ditto: but to a lesser extent *)
paulson@15229
  1526
lemma sin_zero_iff:
paulson@15229
  1527
     "(sin x = 0) =  
paulson@15077
  1528
      ((\<exists>n::nat. even n & (x = real n * (pi/2))) |    
paulson@15077
  1529
       (\<exists>n::nat. even n & (x = -(real n * (pi/2)))))"
paulson@15077
  1530
apply (rule iffI)
paulson@15077
  1531
apply (cut_tac linorder_linear [of 0 x], safe)
paulson@15077
  1532
apply (drule sin_zero_lemma, assumption+)
paulson@15077
  1533
apply (cut_tac x="-x" in sin_zero_lemma, simp, simp, safe)
paulson@15077
  1534
apply (force simp add: minus_equation_iff [of x]) 
nipkow@15539
  1535
apply (auto simp add: even_mult_two_ex)
paulson@15077
  1536
done
paulson@15077
  1537
paulson@15077
  1538
paulson@15077
  1539
subsection{*Tangent*}
paulson@15077
  1540
huffman@23043
  1541
definition
huffman@23043
  1542
  tan :: "real => real" where
huffman@23043
  1543
  "tan x = (sin x)/(cos x)"
huffman@23043
  1544
paulson@15077
  1545
lemma tan_zero [simp]: "tan 0 = 0"
paulson@15077
  1546
by (simp add: tan_def)
paulson@15077
  1547
paulson@15077
  1548
lemma tan_pi [simp]: "tan pi = 0"
paulson@15077
  1549
by (simp add: tan_def)
paulson@15077
  1550
paulson@15077
  1551
lemma tan_npi [simp]: "tan (real (n::nat) * pi) = 0"
paulson@15077
  1552
by (simp add: tan_def)
paulson@15077
  1553
paulson@15077
  1554
lemma tan_minus [simp]: "tan (-x) = - tan x"
paulson@15077
  1555
by (simp add: tan_def minus_mult_left)
paulson@15077
  1556
paulson@15077
  1557
lemma tan_periodic [simp]: "tan (x + 2*pi) = tan x"
paulson@15077
  1558
by (simp add: tan_def)
paulson@15077
  1559
paulson@15077
  1560
lemma lemma_tan_add1: 
paulson@15077
  1561
      "[| cos x \<noteq> 0; cos y \<noteq> 0 |]  
paulson@15077
  1562
        ==> 1 - tan(x)*tan(y) = cos (x + y)/(cos x * cos y)"
paulson@15229
  1563
apply (simp add: tan_def divide_inverse)
paulson@15229
  1564
apply (auto simp del: inverse_mult_distrib 
paulson@15229
  1565
            simp add: inverse_mult_distrib [symmetric] mult_ac)
paulson@15077
  1566
apply (rule_tac c1 = "cos x * cos y" in real_mult_right_cancel [THEN subst])
paulson@15229
  1567
apply (auto simp del: inverse_mult_distrib 
paulson@15229
  1568
            simp add: mult_assoc left_diff_distrib cos_add)
paulson@15234
  1569
done  
paulson@15077
  1570
paulson@15077
  1571
lemma add_tan_eq: 
paulson@15077
  1572
      "[| cos x \<noteq> 0; cos y \<noteq> 0 |]  
paulson@15077
  1573
       ==> tan x + tan y = sin(x + y)/(cos x * cos y)"
paulson@15229
  1574
apply (simp add: tan_def)
paulson@15077
  1575
apply (rule_tac c1 = "cos x * cos y" in real_mult_right_cancel [THEN subst])
paulson@15077
  1576
apply (auto simp add: mult_assoc left_distrib)
nipkow@15539
  1577
apply (simp add: sin_add)
paulson@15077
  1578
done
paulson@15077
  1579
paulson@15229
  1580
lemma tan_add:
paulson@15229
  1581
     "[| cos x \<noteq> 0; cos y \<noteq> 0; cos (x + y) \<noteq> 0 |]  
paulson@15077
  1582
      ==> tan(x + y) = (tan(x) + tan(y))/(1 - tan(x) * tan(y))"
paulson@15077
  1583
apply (simp (no_asm_simp) add: add_tan_eq lemma_tan_add1)
paulson@15077
  1584
apply (simp add: tan_def)
paulson@15077
  1585
done
paulson@15077
  1586
paulson@15229
  1587
lemma tan_double:
paulson@15229
  1588
     "[| cos x \<noteq> 0; cos (2 * x) \<noteq> 0 |]  
paulson@15077
  1589
      ==> tan (2 * x) = (2 * tan x)/(1 - (tan(x) ^ 2))"
paulson@15077
  1590
apply (insert tan_add [of x x]) 
paulson@15077
  1591
apply (simp add: mult_2 [symmetric])  
paulson@15077
  1592
apply (auto simp add: numeral_2_eq_2)
paulson@15077
  1593
done
paulson@15077
  1594
paulson@15077
  1595
lemma tan_gt_zero: "[| 0 < x; x < pi/2 |] ==> 0 < tan x"
paulson@15229
  1596
by (simp add: tan_def zero_less_divide_iff sin_gt_zero2 cos_gt_zero_pi) 
paulson@15077
  1597
paulson@15077
  1598
lemma tan_less_zero: 
paulson@15077
  1599
  assumes lb: "- pi/2 < x" and "x < 0" shows "tan x < 0"
paulson@15077
  1600
proof -
paulson@15077
  1601
  have "0 < tan (- x)" using prems by (simp only: tan_gt_zero) 
paulson@15077
  1602
  thus ?thesis by simp
paulson@15077
  1603
qed
paulson@15077
  1604
paulson@15077
  1605
lemma lemma_DERIV_tan:
paulson@15077
  1606
     "cos x \<noteq> 0 ==> DERIV (%x. sin(x)/cos(x)) x :> inverse((cos x)\<twosuperior>)"
paulson@15077
  1607
apply (rule lemma_DERIV_subst)
paulson@15077
  1608
apply (best intro!: DERIV_intros intro: DERIV_chain2) 
paulson@15079
  1609
apply (auto simp add: divide_inverse numeral_2_eq_2)
paulson@15077
  1610
done
paulson@15077
  1611
paulson@15077
  1612
lemma DERIV_tan [simp]: "cos x \<noteq> 0 ==> DERIV tan x :> inverse((cos x)\<twosuperior>)"
paulson@15077
  1613
by (auto dest: lemma_DERIV_tan simp add: tan_def [symmetric])
paulson@15077
  1614
paulson@15077
  1615
lemma LIM_cos_div_sin [simp]: "(%x. cos(x)/sin(x)) -- pi/2 --> 0"
paulson@15077
  1616
apply (subgoal_tac "(\<lambda>x. cos x * inverse (sin x)) -- pi * inverse 2 --> 0*1")
paulson@15229
  1617
apply (simp add: divide_inverse [symmetric])
huffman@22613
  1618
apply (rule LIM_mult)
paulson@15077
  1619
apply (rule_tac [2] inverse_1 [THEN subst])
paulson@15077
  1620
apply (rule_tac [2] LIM_inverse)
paulson@15077
  1621
apply (simp_all add: divide_inverse [symmetric]) 
paulson@15077
  1622
apply (simp_all only: isCont_def [symmetric] cos_pi_half [symmetric] sin_pi_half [symmetric]) 
paulson@15077
  1623
apply (blast intro!: DERIV_isCont DERIV_sin DERIV_cos)+
paulson@15077
  1624
done
paulson@15077
  1625
paulson@15077
  1626
lemma lemma_tan_total: "0 < y ==> \<exists>x. 0 < x & x < pi/2 & y < tan x"
paulson@15077
  1627
apply (cut_tac LIM_cos_div_sin)
paulson@15077
  1628
apply (simp only: LIM_def)
paulson@15077
  1629
apply (drule_tac x = "inverse y" in spec, safe, force)
paulson@15077
  1630
apply (drule_tac ?d1.0 = s in pi_half_gt_zero [THEN [2] real_lbound_gt_zero], safe)
paulson@15229
  1631
apply (rule_tac x = "(pi/2) - e" in exI)
paulson@15077
  1632
apply (simp (no_asm_simp))
paulson@15229
  1633
apply (drule_tac x = "(pi/2) - e" in spec)
paulson@15229
  1634
apply (auto simp add: tan_def)
paulson@15077
  1635
apply (rule inverse_less_iff_less [THEN iffD1])
paulson@15079
  1636
apply (auto simp add: divide_inverse)
paulson@15229
  1637
apply (rule real_mult_order) 
paulson@15229
  1638
apply (subgoal_tac [3] "0 < sin e & 0 < cos e")
paulson@15229
  1639
apply (auto intro: cos_gt_zero sin_gt_zero2 simp add: mult_commute) 
paulson@15077
  1640
done
paulson@15077
  1641
paulson@15077
  1642
lemma tan_total_pos: "0 \<le> y ==> \<exists>x. 0 \<le> x & x < pi/2 & tan x = y"
huffman@22998
  1643
apply (frule order_le_imp_less_or_eq, safe)
paulson@15077
  1644
 prefer 2 apply force
paulson@15077
  1645
apply (drule lemma_tan_total, safe)
paulson@15077
  1646
apply (cut_tac f = tan and a = 0 and b = x and y = y in IVT_objl)
paulson@15077
  1647
apply (auto intro!: DERIV_tan [THEN DERIV_isCont])
paulson@15077
  1648
apply (drule_tac y = xa in order_le_imp_less_or_eq)
paulson@15077
  1649
apply (auto dest: cos_gt_zero)
paulson@15077
  1650
done
paulson@15077
  1651
paulson@15077
  1652
lemma lemma_tan_total1: "\<exists>x. -(pi/2) < x & x < (pi/2) & tan x = y"
paulson@15077
  1653
apply (cut_tac linorder_linear [of 0 y], safe)
paulson@15077
  1654
apply (drule tan_total_pos)
paulson@15077
  1655
apply (cut_tac [2] y="-y" in tan_total_pos, safe)
paulson@15077
  1656
apply (rule_tac [3] x = "-x" in exI)
paulson@15077
  1657
apply (auto intro!: exI)
paulson@15077
  1658
done
paulson@15077
  1659
paulson@15077
  1660
lemma tan_total: "EX! x. -(pi/2) < x & x < (pi/2) & tan x = y"
paulson@15077
  1661
apply (cut_tac y = y in lemma_tan_total1, auto)
paulson@15077
  1662
apply (cut_tac x = xa and y = y in linorder_less_linear, auto)
paulson@15077
  1663
apply (subgoal_tac [2] "\<exists>z. y < z & z < xa & DERIV tan z :> 0")
paulson@15077
  1664
apply (subgoal_tac "\<exists>z. xa < z & z < y & DERIV tan z :> 0")
paulson@15077
  1665
apply (rule_tac [4] Rolle)
paulson@15077
  1666
apply (rule_tac [2] Rolle)
paulson@15077
  1667
apply (auto intro!: DERIV_tan DERIV_isCont exI 
paulson@15077
  1668
            simp add: differentiable_def)
paulson@15077
  1669
txt{*Now, simulate TRYALL*}
paulson@15077
  1670
apply (rule_tac [!] DERIV_tan asm_rl)
paulson@15077
  1671
apply (auto dest!: DERIV_unique [OF _ DERIV_tan]
huffman@22998
  1672
	    simp add: cos_gt_zero_pi [THEN less_imp_neq, THEN not_sym]) 
paulson@15077
  1673
done
paulson@15077
  1674
huffman@23043
  1675
huffman@23043
  1676
subsection {* Inverse Trigonometric Functions *}
huffman@23043
  1677
huffman@23043
  1678
definition
huffman@23043
  1679
  arcsin :: "real => real" where
huffman@23043
  1680
  "arcsin y = (THE x. -(pi/2) \<le> x & x \<le> pi/2 & sin x = y)"
huffman@23043
  1681
huffman@23043
  1682
definition
huffman@23043
  1683
  arccos :: "real => real" where
huffman@23043
  1684
  "arccos y = (THE x. 0 \<le> x & x \<le> pi & cos x = y)"
huffman@23043
  1685
huffman@23043
  1686
definition     
huffman@23043
  1687
  arctan :: "real => real" where
huffman@23043
  1688
  "arctan y = (THE x. -(pi/2) < x & x < pi/2 & tan x = y)"
huffman@23043
  1689
paulson@15229
  1690
lemma arcsin:
paulson@15229
  1691
     "[| -1 \<le> y; y \<le> 1 |]  
paulson@15077
  1692
      ==> -(pi/2) \<le> arcsin y &  
paulson@15077
  1693
           arcsin y \<le> pi/2 & sin(arcsin y) = y"
huffman@23011
  1694
unfolding arcsin_def by (rule theI' [OF sin_total])
huffman@23011
  1695
huffman@23011
  1696
lemma arcsin_pi:
huffman@23011
  1697
     "[| -1 \<le> y; y \<le> 1 |]  
huffman@23011
  1698
      ==> -(pi/2) \<le> arcsin y & arcsin y \<le> pi & sin(arcsin y) = y"
huffman@23011
  1699
apply (drule (1) arcsin)
huffman@23011
  1700
apply (force intro: order_trans)
paulson@15077
  1701
done
paulson@15077
  1702
paulson@15077
  1703
lemma sin_arcsin [simp]: "[| -1 \<le> y; y \<le> 1 |] ==> sin(arcsin y) = y"
paulson@15077
  1704
by (blast dest: arcsin)
paulson@15077
  1705
      
paulson@15077
  1706
lemma arcsin_bounded:
paulson@15077
  1707
     "[| -1 \<le> y; y \<le> 1 |] ==> -(pi/2) \<le> arcsin y & arcsin y \<le> pi/2"
paulson@15077
  1708
by (blast dest: arcsin)
paulson@15077
  1709
paulson@15077
  1710
lemma arcsin_lbound: "[| -1 \<le> y; y \<le> 1 |] ==> -(pi/2) \<le> arcsin y"
paulson@15077
  1711
by (blast dest: arcsin)
paulson@15077
  1712
paulson@15077
  1713
lemma arcsin_ubound: "[| -1 \<le> y; y \<le> 1 |] ==> arcsin y \<le> pi/2"
paulson@15077
  1714
by (blast dest: arcsin)
paulson@15077
  1715
paulson@15077
  1716
lemma arcsin_lt_bounded:
paulson@15077
  1717
     "[| -1 < y; y < 1 |] ==> -(pi/2) < arcsin y & arcsin y < pi/2"
paulson@15077
  1718
apply (frule order_less_imp_le)
paulson@15077
  1719
apply (frule_tac y = y in order_less_imp_le)
paulson@15077
  1720
apply (frule arcsin_bounded)
paulson@15077
  1721
apply (safe, simp)
paulson@15077
  1722
apply (drule_tac y = "arcsin y" in order_le_imp_less_or_eq)
paulson@15077
  1723
apply (drule_tac [2] y = "pi/2" in order_le_imp_less_or_eq, safe)
paulson@15077
  1724
apply (drule_tac [!] f = sin in arg_cong, auto)
paulson@15077
  1725
done
paulson@15077
  1726
paulson@15077
  1727
lemma arcsin_sin: "[|-(pi/2) \<le> x; x \<le> pi/2 |] ==> arcsin(sin x) = x"
paulson@15077
  1728
apply (unfold arcsin_def)
huffman@23011
  1729
apply (rule the1_equality)
paulson@15077
  1730
apply (rule sin_total, auto)
paulson@15077
  1731
done
paulson@15077
  1732
huffman@22975
  1733
lemma arccos:
paulson@15229
  1734
     "[| -1 \<le> y; y \<le> 1 |]  
huffman@22975
  1735
      ==> 0 \<le> arccos y & arccos y \<le> pi & cos(arccos y) = y"
huffman@23011
  1736
unfolding arccos_def by (rule theI' [OF cos_total])
paulson@15077
  1737
huffman@22975
  1738
lemma cos_arccos [simp]: "[| -1 \<le> y; y \<le> 1 |] ==> cos(arccos y) = y"
huffman@22975
  1739
by (blast dest: arccos)
paulson@15077
  1740
      
huffman@22975
  1741
lemma arccos_bounded: "[| -1 \<le> y; y \<le> 1 |] ==> 0 \<le> arccos y & arccos y \<le> pi"
huffman@22975
  1742
by (blast dest: arccos)
paulson@15077
  1743
huffman@22975
  1744
lemma arccos_lbound: "[| -1 \<le> y; y \<le> 1 |] ==> 0 \<le> arccos y"
huffman@22975
  1745
by (blast dest: arccos)
paulson@15077
  1746
huffman@22975
  1747
lemma arccos_ubound: "[| -1 \<le> y; y \<le> 1 |] ==> arccos y \<le> pi"
huffman@22975
  1748
by (blast dest: arccos)
paulson@15077
  1749
huffman@22975
  1750
lemma arccos_lt_bounded:
paulson@15229
  1751
     "[| -1 < y; y < 1 |]  
huffman@22975
  1752
      ==> 0 < arccos y & arccos y < pi"
paulson@15077
  1753
apply (frule order_less_imp_le)
paulson@15077
  1754
apply (frule_tac y = y in order_less_imp_le)
huffman@22975
  1755
apply (frule arccos_bounded, auto)
huffman@22975
  1756
apply (drule_tac y = "arccos y" in order_le_imp_less_or_eq)
paulson@15077
  1757
apply (drule_tac [2] y = pi in order_le_imp_less_or_eq, auto)
paulson@15077
  1758
apply (drule_tac [!] f = cos in arg_cong, auto)
paulson@15077
  1759
done
paulson@15077
  1760
huffman@22975
  1761
lemma arccos_cos: "[|0 \<le> x; x \<le> pi |] ==> arccos(cos x) = x"
huffman@22975
  1762
apply (simp add: arccos_def)
huffman@23011
  1763
apply (auto intro!: the1_equality cos_total)
paulson@15077
  1764
done
paulson@15077
  1765
huffman@22975
  1766
lemma arccos_cos2: "[|x \<le> 0; -pi \<le> x |] ==> arccos(cos x) = -x"
huffman@22975
  1767
apply (simp add: arccos_def)
huffman@23011
  1768
apply (auto intro!: the1_equality cos_total)
paulson@15077
  1769
done
paulson@15077
  1770
paulson@15077
  1771
lemma arctan [simp]:
paulson@15077
  1772
     "- (pi/2) < arctan y  & arctan y < pi/2 & tan (arctan y) = y"
huffman@23011
  1773
unfolding arctan_def by (rule theI' [OF tan_total])
paulson@15077
  1774
paulson@15077
  1775
lemma tan_arctan: "tan(arctan y) = y"
paulson@15077
  1776
by auto
paulson@15077
  1777
paulson@15077
  1778
lemma arctan_bounded: "- (pi/2) < arctan y  & arctan y < pi/2"
paulson@15077
  1779
by (auto simp only: arctan)
paulson@15077
  1780
paulson@15077
  1781
lemma arctan_lbound: "- (pi/2) < arctan y"
paulson@15077
  1782
by auto
paulson@15077
  1783
paulson@15077
  1784
lemma arctan_ubound: "arctan y < pi/2"
paulson@15077
  1785
by (auto simp only: arctan)
paulson@15077
  1786
paulson@15077
  1787
lemma arctan_tan: 
paulson@15077
  1788
      "[|-(pi/2) < x; x < pi/2 |] ==> arctan(tan x) = x"
paulson@15077
  1789
apply (unfold arctan_def)
huffman@23011
  1790
apply (rule the1_equality)
paulson@15077
  1791
apply (rule tan_total, auto)
paulson@15077
  1792
done
paulson@15077
  1793
paulson@15077
  1794
lemma arctan_zero_zero [simp]: "arctan 0 = 0"
paulson@15077
  1795
by (insert arctan_tan [of 0], simp)
paulson@15077
  1796
paulson@15077
  1797
lemma cos_arctan_not_zero [simp]: "cos(arctan x) \<noteq> 0"
paulson@15077
  1798
apply (auto simp add: cos_zero_iff)
paulson@15077
  1799
apply (case_tac "n")
paulson@15077
  1800
apply (case_tac [3] "n")
paulson@15077
  1801
apply (cut_tac [2] y = x in arctan_ubound)
paulson@15077
  1802
apply (cut_tac [4] y = x in arctan_lbound) 
paulson@15077
  1803
apply (auto simp add: real_of_nat_Suc left_distrib mult_less_0_iff)
paulson@15077
  1804
done
paulson@15077
  1805
paulson@15077
  1806
lemma tan_sec: "cos x \<noteq> 0 ==> 1 + tan(x) ^ 2 = inverse(cos x) ^ 2"
paulson@15077
  1807
apply (rule power_inverse [THEN subst])
paulson@15077
  1808
apply (rule_tac c1 = "(cos x)\<twosuperior>" in real_mult_right_cancel [THEN iffD1])
huffman@22960
  1809
apply (auto dest: field_power_not_zero
huffman@20516
  1810
        simp add: power_mult_distrib left_distrib power_divide tan_def 
paulson@15077
  1811
                  mult_assoc power_inverse [symmetric] 
paulson@15077
  1812
        simp del: realpow_Suc)
paulson@15077
  1813
done
paulson@15077
  1814
huffman@23043
  1815
subsection {* More Theorems about Sin and Cos *}
huffman@23043
  1816
paulson@15085
  1817
text{*NEEDED??*}
paulson@15229
  1818
lemma [simp]:
paulson@15229
  1819
     "sin (x + 1 / 2 * real (Suc m) * pi) =  
paulson@15229
  1820
      cos (x + 1 / 2 * real  (m) * pi)"
paulson@15229
  1821
by (simp only: cos_add sin_add real_of_nat_Suc left_distrib right_distrib, auto)
paulson@15077
  1822
paulson@15085
  1823
text{*NEEDED??*}
paulson@15229
  1824
lemma [simp]:
paulson@15229
  1825
     "sin (x + real (Suc m) * pi / 2) =  
paulson@15229
  1826
      cos (x + real (m) * pi / 2)"
paulson@15229
  1827
by (simp only: cos_add sin_add real_of_nat_Suc add_divide_distrib left_distrib, auto)
paulson@15077
  1828
paulson@15077
  1829
lemma DERIV_sin_add [simp]: "DERIV (%x. sin (x + k)) xa :> cos (xa + k)"
paulson@15077
  1830
apply (rule lemma_DERIV_subst)
paulson@15077
  1831
apply (rule_tac f = sin and g = "%x. x + k" in DERIV_chain2)
paulson@15077
  1832
apply (best intro!: DERIV_intros intro: DERIV_chain2)+
paulson@15077
  1833
apply (simp (no_asm))
paulson@15077
  1834
done
paulson@15077
  1835
paulson@15383
  1836
lemma sin_cos_npi [simp]: "sin (real (Suc (2 * n)) * pi / 2) = (-1) ^ n"
paulson@15383
  1837
proof -
paulson@15383
  1838
  have "sin ((real n + 1/2) * pi) = cos (real n * pi)"
paulson@15383
  1839
    by (auto simp add: right_distrib sin_add left_distrib mult_ac)
paulson@15383
  1840
  thus ?thesis
paulson@15383
  1841
    by (simp add: real_of_nat_Suc left_distrib add_divide_distrib 
paulson@15383
  1842
                  mult_commute [of pi])
paulson@15383
  1843
qed
paulson@15077
  1844
paulson@15077
  1845
lemma cos_2npi [simp]: "cos (2 * real (n::nat) * pi) = 1"
paulson@15077
  1846
by (simp add: cos_double mult_assoc power_add [symmetric] numeral_2_eq_2)
paulson@15077
  1847
paulson@15077
  1848
lemma cos_3over2_pi [simp]: "cos (3 / 2 * pi) = 0"
paulson@15077
  1849
apply (subgoal_tac "3/2 = (1+1 / 2::real)")
paulson@15077
  1850
apply (simp only: left_distrib) 
paulson@15077
  1851
apply (auto simp add: cos_add mult_ac)
paulson@15077
  1852
done
paulson@15077
  1853
paulson@15077
  1854
lemma sin_2npi [simp]: "sin (2 * real (n::nat) * pi) = 0"
paulson@15077
  1855
by (auto simp add: mult_assoc)
paulson@15077
  1856
paulson@15077
  1857
lemma sin_3over2_pi [simp]: "sin (3 / 2 * pi) = - 1"
paulson@15077
  1858
apply (subgoal_tac "3/2 = (1+1 / 2::real)")
paulson@15077
  1859
apply (simp only: left_distrib) 
paulson@15077
  1860
apply (auto simp add: sin_add mult_ac)
paulson@15077
  1861
done
paulson@15077
  1862
paulson@15077
  1863
(*NEEDED??*)
paulson@15229
  1864
lemma [simp]:
paulson@15229
  1865
     "cos(x + 1 / 2 * real(Suc m) * pi) = -sin (x + 1 / 2 * real m * pi)"
paulson@15077
  1866
apply (simp only: cos_add sin_add real_of_nat_Suc right_distrib left_distrib minus_mult_right, auto)
paulson@15077
  1867
done
paulson@15077
  1868
paulson@15077
  1869
(*NEEDED??*)
paulson@15077
  1870
lemma [simp]: "cos (x + real(Suc m) * pi / 2) = -sin (x + real m * pi / 2)"
paulson@15229
  1871
by (simp only: cos_add sin_add real_of_nat_Suc left_distrib add_divide_distrib, auto)
paulson@15077
  1872
paulson@15077
  1873
lemma cos_pi_eq_zero [simp]: "cos (pi * real (Suc (2 * m)) / 2) = 0"
paulson@15229
  1874
by (simp only: cos_add sin_add real_of_nat_Suc left_distrib right_distrib add_divide_distrib, auto)
paulson@15077
  1875
paulson@15077
  1876
lemma DERIV_cos_add [simp]: "DERIV (%x. cos (x + k)) xa :> - sin (xa + k)"
paulson@15077
  1877
apply (rule lemma_DERIV_subst)
paulson@15077
  1878
apply (rule_tac f = cos and g = "%x. x + k" in DERIV_chain2)
paulson@15077
  1879
apply (best intro!: DERIV_intros intro: DERIV_chain2)+
paulson@15077
  1880
apply (simp (no_asm))
paulson@15077
  1881
done
paulson@15077
  1882
paulson@15077
  1883
lemma isCont_cos [simp]: "isCont cos x"
paulson@15077
  1884
by (rule DERIV_cos [THEN DERIV_isCont])
paulson@15077
  1885
paulson@15077
  1886
lemma isCont_sin [simp]: "isCont sin x"
paulson@15077
  1887
by (rule DERIV_sin [THEN DERIV_isCont])
paulson@15077
  1888
paulson@15077
  1889
lemma isCont_exp [simp]: "isCont exp x"
paulson@15077
  1890
by (rule DERIV_exp [THEN DERIV_isCont])
paulson@15077
  1891
paulson@15081
  1892
lemma sin_zero_abs_cos_one: "sin x = 0 ==> \<bar>cos x\<bar> = 1"
nipkow@15539
  1893
by (auto simp add: sin_zero_iff even_mult_two_ex)
paulson@15077
  1894
paulson@15077
  1895
lemma exp_eq_one_iff [simp]: "(exp x = 1) = (x = 0)"
paulson@15077
  1896
apply auto
paulson@15077
  1897
apply (drule_tac f = ln in arg_cong, auto)
paulson@15077
  1898
done
paulson@15077
  1899
paulson@15077
  1900
lemma cos_one_sin_zero: "cos x = 1 ==> sin x = 0"
paulson@15077
  1901
by (cut_tac x = x in sin_cos_squared_add3, auto)
paulson@15077
  1902
paulson@15077
  1903
huffman@22978
  1904
subsection {* Existence of Polar Coordinates *}
paulson@15077
  1905
huffman@22978
  1906
lemma cos_x_y_le_one: "\<bar>x / sqrt (x\<twosuperior> + y\<twosuperior>)\<bar> \<le> 1"
huffman@22978
  1907
apply (rule power2_le_imp_le [OF _ zero_le_one])
huffman@22978
  1908
apply (simp add: abs_divide power_divide divide_le_eq not_sum_power2_lt_zero)
paulson@15077
  1909
done
paulson@15077
  1910
huffman@22978
  1911
lemma cos_arccos_abs: "\<bar>y\<bar> \<le> 1 \<Longrightarrow> cos (arccos y) = y"
huffman@22978
  1912
by (simp add: abs_le_iff)
paulson@15077
  1913
huffman@22978
  1914
lemma cos_total_abs: "\<bar>y\<bar> \<le> 1 \<Longrightarrow> \<exists>!x. 0 \<le> x \<and> x \<le> pi \<and> cos x = y"
huffman@22978
  1915
by (simp add: abs_le_iff cos_total)
paulson@15077
  1916
huffman@22978
  1917
lemmas cos_arccos_lemma1 = cos_arccos_abs [OF cos_x_y_le_one]
paulson@15228
  1918
huffman@22978
  1919
lemmas cos_total_lemma1 = cos_total_abs [OF cos_x_y_le_one]
paulson@15077
  1920
paulson@15077
  1921
(* How tedious! *)
paulson@15077
  1922
lemma lemma_divide_rearrange:
paulson@15077
  1923
     "[| x + (y::real) \<noteq> 0; 1 - z = x/(x + y) |] ==> z = y/(x + y)"
paulson@15077
  1924
apply (rule_tac c1 = "x + y" in real_mult_right_cancel [THEN iffD1])
paulson@15077
  1925
apply (frule_tac [2] c1 = "x + y" in real_mult_right_cancel [THEN iffD2])
paulson@15077
  1926
prefer 2 apply assumption
paulson@15077
  1927
apply (rotate_tac [2] 2)
paulson@15077
  1928
apply (drule_tac [2] mult_assoc [THEN subst])
paulson@15077
  1929
apply (rotate_tac [2] 2)
paulson@15077
  1930
apply (frule_tac [2] left_inverse [THEN subst])
paulson@15077
  1931
prefer 2 apply assumption
paulson@15229
  1932
apply (erule_tac [2] V = "(1 - z) * (x + y) = x / (x + y) * (x + y)" in thin_rl)
paulson@15229
  1933
apply (erule_tac [2] V = "1 - z = x / (x + y)" in thin_rl)
paulson@15077
  1934
apply (auto simp add: mult_assoc)
paulson@15077
  1935
apply (auto simp add: right_distrib left_diff_distrib)
paulson@15077
  1936
done
paulson@15077
  1937
paulson@15077
  1938
lemma lemma_cos_sin_eq:
huffman@22978
  1939
     "[| 0 < x\<twosuperior> + y\<twosuperior>;  
huffman@22978
  1940
         1 - (sin xa)\<twosuperior> = (x / sqrt (x\<twosuperior> + y\<twosuperior>))\<twosuperior> |] 
huffman@22978
  1941
      ==> (sin xa)\<twosuperior> = (y / sqrt (x\<twosuperior> + y\<twosuperior>))\<twosuperior>"
huffman@22978
  1942
by (auto intro: lemma_divide_rearrange simp add: power_divide)
paulson@15077
  1943
paulson@15077
  1944
lemma sin_x_y_disj:
huffman@22978
  1945
     "[| 0 < y;
huffman@22978
  1946
         cos xa = x / sqrt (x\<twosuperior> + y\<twosuperior>)  
huffman@22978
  1947
      |] ==>  sin xa = y / sqrt (x\<twosuperior> + y\<twosuperior>) |  
huffman@22978
  1948
              sin xa = - y / sqrt (x\<twosuperior> + y\<twosuperior>)"
paulson@15077
  1949
apply (drule_tac f = "%x. x\<twosuperior>" in arg_cong)
huffman@22978
  1950
apply (subgoal_tac "0 < x\<twosuperior> + y\<twosuperior>")
paulson@15077
  1951
apply (simp add: cos_squared_eq)
huffman@22978
  1952
apply (subgoal_tac "(sin xa)\<twosuperior> = (y / sqrt (x\<twosuperior> + y\<twosuperior>))\<twosuperior>")
paulson@15077
  1953
apply (rule_tac [2] lemma_cos_sin_eq)
paulson@15077
  1954
apply (auto simp add: realpow_two_disj numeral_2_eq_2 simp del: realpow_Suc)
huffman@22969
  1955
apply (auto simp add: sum_squares_gt_zero_iff)
paulson@15077
  1956
done
paulson@15077
  1957
huffman@22978
  1958
lemma real_sqrt_divide_less_zero: "0 < y ==> - y / sqrt (x\<twosuperior> + y\<twosuperior>) < 0"
huffman@22978
  1959
by (simp add: divide_pos_pos sum_power2_gt_zero_iff)
paulson@15077
  1960
paulson@15229
  1961
lemma polar_ex1:
huffman@22978
  1962
     "0 < y ==> \<exists>r a. x = r * cos a & y = r * sin a"
paulson@15229
  1963
apply (rule_tac x = "sqrt (x\<twosuperior> + y\<twosuperior>)" in exI)
huffman@22978
  1964
apply (rule_tac x = "arccos (x / sqrt (x\<twosuperior> + y\<twosuperior>))" in exI)
huffman@22978
  1965
apply (simp add: cos_arccos_lemma1)
huffman@22975
  1966
apply (simp add: arccos_def)
huffman@22978
  1967
apply (cut_tac x1 = x and y1 = y in cos_total_lemma1)
huffman@23011
  1968
apply (drule theI')
paulson@15077
  1969
apply (frule sin_x_y_disj, blast)
huffman@22978
  1970
apply (auto)
paulson@15077
  1971
apply (drule sin_ge_zero, assumption)
paulson@15077
  1972
apply (drule_tac x = x in real_sqrt_divide_less_zero, auto)
paulson@15077
  1973
done
paulson@15077
  1974
paulson@15229
  1975
lemma polar_ex2:
huffman@22978
  1976
     "y < 0 ==> \<exists>r a. x = r * cos a & y = r * sin a"
huffman@22978
  1977
apply (insert polar_ex1 [where x=x and y="-y"], simp, clarify)
paulson@15077
  1978
apply (rule_tac x = r in exI)
huffman@22978
  1979
apply (rule_tac x = "-a" in exI, simp)
paulson@15077
  1980
done
paulson@15077
  1981
paulson@15077
  1982
lemma polar_Ex: "\<exists>r a. x = r * cos a & y = r * sin a"
huffman@22978
  1983
apply (rule_tac x=0 and y=y in linorder_cases)
huffman@22978
  1984
apply (erule polar_ex1)
huffman@22978
  1985
apply (rule_tac x=x in exI, rule_tac x=0 in exI, simp)
huffman@22978
  1986
apply (erule polar_ex2)
paulson@15077
  1987
done
paulson@15077
  1988
huffman@22978
  1989
subsection {* Theorems About Sqrt *}
huffman@22978
  1990
huffman@22978
  1991
lemma le_real_sqrt_sumsq [simp]: "x \<le> sqrt (x * x + y * y)"
huffman@22978
  1992
by (simp add: power2_eq_square [symmetric])
huffman@22978
  1993
huffman@22978
  1994
lemma real_sqrt_sum_squares_eq_cancel: "sqrt(x\<twosuperior> + y\<twosuperior>) = x ==> y = 0"
huffman@22978
  1995
by (drule_tac f = "%x. x\<twosuperior>" in arg_cong, simp)
huffman@22978
  1996
huffman@22978
  1997
lemma real_sqrt_sum_squares_eq_cancel2: "sqrt(x\<twosuperior> + y\<twosuperior>) = y ==> x = 0"
huffman@22978
  1998
by (drule_tac f = "%x. x\<twosuperior>" in arg_cong, simp)
huffman@22978
  1999
paulson@15077
  2000
lemma real_sqrt_ge_abs1 [simp]: "\<bar>x\<bar> \<le> sqrt (x\<twosuperior> + y\<twosuperior>)"
huffman@22960
  2001
by (rule power2_le_imp_le, simp_all)
paulson@15077
  2002
paulson@15077
  2003
lemma real_sqrt_ge_abs2 [simp]: "\<bar>y\<bar> \<le> sqrt (x\<twosuperior> + y\<twosuperior>)"
huffman@22960
  2004
by (rule power2_le_imp_le, simp_all)
paulson@15077
  2005
paulson@15077
  2006
lemma real_sqrt_two_gt_zero [simp]: "0 < sqrt 2"
huffman@22956
  2007
by simp
paulson@15077
  2008
paulson@15077
  2009
lemma real_sqrt_two_ge_zero [simp]: "0 \<le> sqrt 2"
huffman@22956
  2010
by simp
paulson@15077
  2011
paulson@15077
  2012
lemma real_sqrt_two_gt_one [simp]: "1 < sqrt 2"
huffman@22956
  2013
by simp
paulson@15077
  2014
paulson@15077
  2015
lemma lemma_real_divide_sqrt_less: "0 < u ==> u / sqrt 2 < u"
huffman@22969
  2016
by (simp add: divide_less_eq mult_compare_simps)
paulson@15077
  2017
paulson@15077
  2018
lemma four_x_squared: 
paulson@15077
  2019
  fixes x::real
paulson@15077
  2020
  shows "4 * x\<twosuperior> = (2 * x)\<twosuperior>"
paulson@15077
  2021
by (simp add: power2_eq_square)
paulson@15077
  2022
paulson@15077
  2023
paulson@15077
  2024
text{*Needed for the infinitely close relation over the nonstandard
paulson@15077
  2025
    complex numbers*}
paulson@15077
  2026
lemma lemma_sqrt_hcomplex_capprox:
paulson@15077
  2027
     "[| 0 < u; x < u/2; y < u/2; 0 \<le> x; 0 \<le> y |] ==> sqrt (x\<twosuperior> + y\<twosuperior>) < u"
paulson@15077
  2028
apply (rule_tac y = "u/sqrt 2" in order_le_less_trans)
paulson@15077
  2029
apply (erule_tac [2] lemma_real_divide_sqrt_less)
huffman@22960
  2030
apply (rule power2_le_imp_le)
huffman@22960
  2031
apply (auto simp add: real_0_le_divide_iff power_divide)
paulson@15077
  2032
apply (rule_tac t = "u\<twosuperior>" in real_sum_of_halves [THEN subst])
paulson@15077
  2033
apply (rule add_mono)
paulson@15077
  2034
apply (auto simp add: four_x_squared simp del: realpow_Suc intro: power_mono)
paulson@15077
  2035
done
paulson@15077
  2036
avigad@16775
  2037
declare real_sqrt_sum_squares_ge_zero [THEN abs_of_nonneg, simp]
paulson@15077
  2038
paulson@15077
  2039
paulson@15077
  2040
subsection{*A Few Theorems Involving Ln, Derivatives, etc.*}
paulson@15077
  2041
paulson@15077
  2042
lemma lemma_DERIV_ln:
paulson@15077
  2043
     "DERIV ln z :> l ==> DERIV (%x. exp (ln x)) z :> exp (ln z) * l"
paulson@15077
  2044
by (erule DERIV_fun_exp)
paulson@15077
  2045
huffman@22654
  2046
lemma DERIV_exp_ln_one: "0 < z ==> DERIV (%x. exp (ln x)) z :> 1"
huffman@22654
  2047
apply (simp add: deriv_def)
huffman@22654
  2048
apply (rule LIM_equal2 [OF _ _ LIM_const], assumption)
huffman@22654
  2049
apply simp
paulson@15077
  2050
done
paulson@15077
  2051
paulson@15229
  2052
lemma lemma_DERIV_ln2:
paulson@15229
  2053
     "[| 0 < z; DERIV ln z :> l |] ==>  exp (ln z) * l = 1"
paulson@15077
  2054
apply (rule DERIV_unique)
paulson@15077
  2055
apply (rule lemma_DERIV_ln)
paulson@15077
  2056
apply (rule_tac [2] DERIV_exp_ln_one, auto)
paulson@15077
  2057
done
paulson@15077
  2058
paulson@15229
  2059
lemma lemma_DERIV_ln3:
paulson@15229
  2060
     "[| 0 < z; DERIV ln z :> l |] ==>  l = 1/(exp (ln z))"
paulson@15229
  2061
apply (rule_tac c1 = "exp (ln z)" in real_mult_left_cancel [THEN iffD1])
huffman@22654
  2062
apply (auto intro: lemma_DERIV_ln2 simp del: exp_ln)
paulson@15077
  2063
done
paulson@15077
  2064
paulson@15077
  2065
lemma lemma_DERIV_ln4: "[| 0 < z; DERIV ln z :> l |] ==>  l = 1/z"
paulson@15077
  2066
apply (rule_tac t = z in exp_ln_iff [THEN iffD2, THEN subst])
huffman@22654
  2067
apply (auto intro: lemma_DERIV_ln3 simp del: exp_ln)
paulson@15077
  2068
done
paulson@15077
  2069
huffman@23043
  2070
subsection {* Theorems about Limits *}
huffman@23043
  2071
paulson@15077
  2072
(* need to rename second isCont_inverse *)
paulson@15077
  2073
paulson@15229
  2074
lemma isCont_inv_fun:
huffman@20561
  2075
  fixes f g :: "real \<Rightarrow> real"
huffman@20561
  2076
  shows "[| 0 < d; \<forall>z. \<bar>z - x\<bar> \<le> d --> g(f(z)) = z;  
paulson@15077
  2077
         \<forall>z. \<bar>z - x\<bar> \<le> d --> isCont f z |]  
paulson@15077
  2078
      ==> isCont g (f x)"
huffman@22722
  2079
by (rule isCont_inverse_function)
paulson@15077
  2080
paulson@15077
  2081
lemma isCont_inv_fun_inv:
huffman@20552
  2082
  fixes f g :: "real \<Rightarrow> real"
huffman@20552
  2083
  shows "[| 0 < d;  
paulson@15077
  2084
         \<forall>z. \<bar>z - x\<bar> \<le> d --> g(f(z)) = z;  
paulson@15077
  2085
         \<forall>z. \<bar>z - x\<bar> \<le> d --> isCont f z |]  
paulson@15077
  2086
       ==> \<exists>e. 0 < e &  
paulson@15081
  2087
             (\<forall>y. 0 < \<bar>y - f(x)\<bar> & \<bar>y - f(x)\<bar> < e --> f(g(y)) = y)"
paulson@15077
  2088
apply (drule isCont_inj_range)
paulson@15077
  2089
prefer 2 apply (assumption, assumption, auto)
paulson@15077
  2090
apply (rule_tac x = e in exI, auto)
paulson@15077
  2091
apply (rotate_tac 2)
paulson@15077
  2092
apply (drule_tac x = y in spec, auto)
paulson@15077
  2093
done
paulson@15077
  2094
paulson@15077
  2095
paulson@15077
  2096
text{*Bartle/Sherbert: Introduction to Real Analysis, Theorem 4.2.9, p. 110*}
paulson@15229
  2097
lemma LIM_fun_gt_zero:
huffman@20552
  2098
     "[| f -- c --> (l::real); 0 < l |]  
huffman@20561
  2099
         ==> \<exists>r. 0 < r & (\<forall>x::real. x \<noteq> c & \<bar>c - x\<bar> < r --> 0 < f x)"
paulson@15077
  2100
apply (auto simp add: LIM_def)
paulson@15077
  2101
apply (drule_tac x = "l/2" in spec, safe, force)
paulson@15077
  2102
apply (rule_tac x = s in exI)
huffman@22998
  2103
apply (auto simp only: abs_less_iff)
paulson@15077
  2104
done
paulson@15077
  2105
paulson@15229
  2106
lemma LIM_fun_less_zero:
huffman@20552
  2107
     "[| f -- c --> (l::real); l < 0 |]  
huffman@20561
  2108
      ==> \<exists>r. 0 < r & (\<forall>x::real. x \<noteq> c & \<bar>c - x\<bar> < r --> f x < 0)"
paulson@15077
  2109
apply (auto simp add: LIM_def)
paulson@15077
  2110
apply (drule_tac x = "-l/2" in spec, safe, force)
paulson@15077
  2111
apply (rule_tac x = s in exI)
huffman@22998
  2112
apply (auto simp only: abs_less_iff)
paulson@15077
  2113
done
paulson@15077
  2114
paulson@15077
  2115
paulson@15077
  2116
lemma LIM_fun_not_zero:
huffman@20552
  2117
     "[| f -- c --> (l::real); l \<noteq> 0 |] 
huffman@20561
  2118
      ==> \<exists>r. 0 < r & (\<forall>x::real. x \<noteq> c & \<bar>c - x\<bar> < r --> f x \<noteq> 0)"
paulson@15077
  2119
apply (cut_tac x = l and y = 0 in linorder_less_linear, auto)
paulson@15077
  2120
apply (drule LIM_fun_less_zero)
paulson@15241
  2121
apply (drule_tac [3] LIM_fun_gt_zero)
paulson@15241
  2122
apply force+
paulson@15077
  2123
done
webertj@20432
  2124
  
paulson@12196
  2125
end