src/HOL/Hyperreal/Taylor.thy
author huffman
Wed, 16 May 2007 23:03:45 +0200
changeset 22983 3314057c3b57
parent 17634 e83ce8fe58fa
child 23069 cdfff0241c12
permissions -rw-r--r--
minimize imports
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
     1
(*  Title:      HOL/Hyperreal/Taylor.thy
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
     2
    ID:         $Id$
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
     3
    Author:     Lukas Bulwahn, Bernhard Haeupler, Technische Universitaet Muenchen
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
     4
*)
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
     5
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
     6
header {* Taylor series *}
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
     7
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
     8
theory Taylor
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
     9
imports MacLaurin
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    10
begin
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    11
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    12
text {*
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    13
We use MacLaurin and the translation of the expansion point @{text c} to @{text 0}
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    14
to prove Taylor's theorem.
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    15
*}
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    16
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    17
lemma taylor_up: 
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    18
  assumes INIT: "0 < n" "diff 0 = f"
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    19
  and DERIV: "(\<forall> m t. m < n & a \<le> t & t \<le> b \<longrightarrow> DERIV (diff m) t :> (diff (Suc m) t))"
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    20
  and INTERV: "a \<le> c" "c < b" 
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    21
  shows "\<exists> t. c < t & t < b & 
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    22
    f b = setsum (%m. (diff m c / real (fact m)) * (b - c)^m) {0..<n} +
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    23
      (diff n t / real (fact n)) * (b - c)^n"
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    24
proof -
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    25
  from INTERV have "0 < b-c" by arith
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    26
  moreover 
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    27
  from INIT have "0<n" "((\<lambda>m x. diff m (x + c)) 0) = (\<lambda>x. f (x + c))" by auto
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    28
  moreover
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    29
  have "ALL m t. m < n & 0 <= t & t <= b - c --> DERIV (%x. diff m (x + c)) t :> diff (Suc m) (t + c)"  
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    30
  proof (intro strip)
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    31
    fix m t
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    32
    assume "m < n & 0 <= t & t <= b - c"
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    33
    with DERIV and INTERV have "DERIV (diff m) (t + c) :> diff (Suc m) (t + c)" by auto
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    34
    moreover
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    35
    from DERIV_Id and DERIV_const have "DERIV (%x. x + c) t :> 1+0" by (rule DERIV_add)
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    36
    ultimately have "DERIV (%x. diff m (x + c)) t :> diff (Suc m) (t + c) * (1+0)"
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    37
      by (rule DERIV_chain2)
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    38
    thus "DERIV (%x. diff m (x + c)) t :> diff (Suc m) (t + c)" by simp
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    39
  qed
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    40
  ultimately 
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    41
  have EX:"EX t>0. t < b - c & 
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    42
    f (b - c + c) = (SUM m = 0..<n. diff m (0 + c) / real (fact m) * (b - c) ^ m) +
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    43
      diff n (t + c) / real (fact n) * (b - c) ^ n" 
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    44
    by (rule Maclaurin)
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    45
  show ?thesis
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    46
  proof -
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    47
    from EX obtain x where 
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    48
      X: "0 < x & x < b - c & 
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    49
        f (b - c + c) = (\<Sum>m = 0..<n. diff m (0 + c) / real (fact m) * (b - c) ^ m) +
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    50
          diff n (x + c) / real (fact n) * (b - c) ^ n" ..
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    51
    let ?H = "x + c"
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    52
    from X have "c<?H & ?H<b \<and> f b = (\<Sum>m = 0..<n. diff m c / real (fact m) * (b - c) ^ m) +
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    53
      diff n ?H / real (fact n) * (b - c) ^ n"
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    54
      by fastsimp
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    55
    thus ?thesis by fastsimp
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    56
  qed
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    57
qed
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    58
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    59
lemma taylor_down:
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    60
  assumes INIT: "0 < n" "diff 0 = f"
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    61
  and DERIV: "(\<forall> m t. m < n & a \<le> t & t \<le> b \<longrightarrow> DERIV (diff m) t :> (diff (Suc m) t))"
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    62
  and INTERV: "a < c" "c \<le> b"
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    63
  shows "\<exists> t. a < t & t < c & 
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    64
    f a = setsum (% m. (diff m c / real (fact m)) * (a - c)^m) {0..<n} +
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    65
      (diff n t / real (fact n)) * (a - c)^n" 
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    66
proof -
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    67
  from INTERV have "a-c < 0" by arith
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    68
  moreover 
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    69
  from INIT have "0<n" "((\<lambda>m x. diff m (x + c)) 0) = (\<lambda>x. f (x + c))" by auto
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    70
  moreover
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    71
  have "ALL m t. m < n & a-c <= t & t <= 0 --> DERIV (%x. diff m (x + c)) t :> diff (Suc m) (t + c)"
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    72
  proof (rule allI impI)+
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    73
    fix m t
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    74
    assume "m < n & a-c <= t & t <= 0"
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    75
    with DERIV and INTERV have "DERIV (diff m) (t + c) :> diff (Suc m) (t + c)" by auto 
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    76
    moreover
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    77
    from DERIV_Id and DERIV_const have "DERIV (%x. x + c) t :> 1+0" by (rule DERIV_add)
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    78
    ultimately have "DERIV (%x. diff m (x + c)) t :> diff (Suc m) (t + c) * (1+0)" by (rule DERIV_chain2)
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    79
    thus "DERIV (%x. diff m (x + c)) t :> diff (Suc m) (t + c)" by simp
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    80
  qed
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    81
  ultimately 
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    82
  have EX: "EX t>a - c. t < 0 &
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    83
    f (a - c + c) = (SUM m = 0..<n. diff m (0 + c) / real (fact m) * (a - c) ^ m) +
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    84
      diff n (t + c) / real (fact n) * (a - c) ^ n" 
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    85
    by (rule Maclaurin_minus)
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    86
  show ?thesis
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    87
  proof -
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    88
    from EX obtain x where X: "a - c < x & x < 0 &
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    89
      f (a - c + c) = (SUM m = 0..<n. diff m (0 + c) / real (fact m) * (a - c) ^ m) +
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    90
        diff n (x + c) / real (fact n) * (a - c) ^ n" ..
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    91
    let ?H = "x + c"
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    92
    from X have "a<?H & ?H<c \<and> f a = (\<Sum>m = 0..<n. diff m c / real (fact m) * (a - c) ^ m) +
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    93
      diff n ?H / real (fact n) * (a - c) ^ n"
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    94
      by fastsimp
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    95
    thus ?thesis by fastsimp
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    96
  qed
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    97
qed
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    98
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    99
lemma taylor:
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   100
  assumes INIT: "0 < n" "diff 0 = f"
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   101
  and DERIV: "(\<forall> m t. m < n & a \<le> t & t \<le> b \<longrightarrow> DERIV (diff m) t :> (diff (Suc m) t))"
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   102
  and INTERV: "a \<le> c " "c \<le> b" "a \<le> x" "x \<le> b" "x \<noteq> c" 
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   103
  shows "\<exists> t. (if x<c then (x < t & t < c) else (c < t & t < x)) &
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   104
    f x = setsum (% m. (diff m c / real (fact m)) * (x - c)^m) {0..<n} +
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   105
      (diff n t / real (fact n)) * (x - c)^n" 
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   106
proof (cases "x<c")
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   107
  case True
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   108
  note INIT
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   109
  moreover from DERIV and INTERV
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   110
  have "\<forall>m t. m < n \<and> x \<le> t \<and> t \<le> b \<longrightarrow> DERIV (diff m) t :> diff (Suc m) t"
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   111
    by fastsimp
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   112
  moreover note True
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   113
  moreover from INTERV have "c \<le> b" by simp
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   114
  ultimately have EX: "\<exists>t>x. t < c \<and> f x =
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   115
    (\<Sum>m = 0..<n. diff m c / real (fact m) * (x - c) ^ m) +
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   116
      diff n t / real (fact n) * (x - c) ^ n"
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   117
    by (rule taylor_down)
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   118
  with True show ?thesis by simp
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   119
next
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   120
  case False
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   121
  note INIT
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   122
  moreover from DERIV and INTERV
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   123
  have "\<forall>m t. m < n \<and> a \<le> t \<and> t \<le> x \<longrightarrow> DERIV (diff m) t :> diff (Suc m) t"
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   124
    by fastsimp
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   125
  moreover from INTERV have "a \<le> c" by arith
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   126
  moreover from False and INTERV have "c < x" by arith
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   127
  ultimately have EX: "\<exists>t>c. t < x \<and> f x =
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   128
    (\<Sum>m = 0..<n. diff m c / real (fact m) * (x - c) ^ m) +
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   129
      diff n t / real (fact n) * (x - c) ^ n" 
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   130
    by (rule taylor_up)
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   131
  with False show ?thesis by simp
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   132
qed
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   133
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   134
end