src/HOL/Taylor.thy
author wenzelm
Thu, 24 Jul 2014 11:54:15 +0200
changeset 57641 dc59f147b27d
parent 56193 c726ecfb22b6
child 58889 5b7a9633cfa8
permissions -rw-r--r--
more robust notation BNF_Def.convol, which is private to main HOL, but may cause syntax ambiguities nonetheless (e.g. List.thy);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28952
15a4b2cf8c34 made repository layout more coherent with logical distribution structure; stripped some $Id$s
haftmann
parents: 25162
diff changeset
     1
(*  Title:      HOL/Taylor.thy
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
     2
    Author:     Lukas Bulwahn, Bernhard Haeupler, Technische Universitaet Muenchen
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
     3
*)
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
header {* Taylor series *}
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
     6
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
     7
theory Taylor
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
     8
imports MacLaurin
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
     9
begin
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    10
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    11
text {*
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    12
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
    13
to prove Taylor's theorem.
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    14
*}
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
lemma taylor_up: 
25162
ad4d5365d9d8 went back to >0
nipkow
parents: 25134
diff changeset
    17
  assumes INIT: "n>0" "diff 0 = f"
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    18
  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
    19
  and INTERV: "a \<le> c" "c < b" 
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    20
  shows "\<exists> t. c < t & t < b & 
56193
c726ecfb22b6 cleanup Series: sorted according to typeclass hierarchy, use {..<_} instead of {0..<_}
hoelzl
parents: 44890
diff changeset
    21
    f b = (\<Sum>m<n. (diff m c / real (fact m)) * (b - c)^m) + (diff n t / real (fact n)) * (b - c)^n"
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    22
proof -
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    23
  from INTERV have "0 < b-c" by arith
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    24
  moreover 
25162
ad4d5365d9d8 went back to >0
nipkow
parents: 25134
diff changeset
    25
  from INIT have "n>0" "((\<lambda>m x. diff m (x + c)) 0) = (\<lambda>x. f (x + c))" by auto
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    26
  moreover
25162
ad4d5365d9d8 went back to >0
nipkow
parents: 25134
diff changeset
    27
  have "ALL m t. m < n & 0 <= t & t <= b - c --> DERIV (%x. diff m (x + c)) t :> diff (Suc m) (t + c)"
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    28
  proof (intro strip)
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    29
    fix m t
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    30
    assume "m < n & 0 <= t & t <= b - c"
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    31
    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
    32
    moreover
23069
cdfff0241c12 rename lemmas LIM_ident, isCont_ident, DERIV_ident
huffman
parents: 17634
diff changeset
    33
    from DERIV_ident and DERIV_const have "DERIV (%x. x + c) t :> 1+0" by (rule DERIV_add)
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    34
    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
    35
      by (rule DERIV_chain2)
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    36
    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
    37
  qed
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    38
  ultimately 
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    39
  have EX:"EX t>0. t < b - c & 
56193
c726ecfb22b6 cleanup Series: sorted according to typeclass hierarchy, use {..<_} instead of {0..<_}
hoelzl
parents: 44890
diff changeset
    40
    f (b - c + c) = (SUM m<n. diff m (0 + c) / real (fact m) * (b - c) ^ m) +
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    41
      diff n (t + c) / real (fact n) * (b - c) ^ n" 
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    42
    by (rule Maclaurin)
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    43
  show ?thesis
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    44
  proof -
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    45
    from EX obtain x where 
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    46
      X: "0 < x & x < b - c & 
56193
c726ecfb22b6 cleanup Series: sorted according to typeclass hierarchy, use {..<_} instead of {0..<_}
hoelzl
parents: 44890
diff changeset
    47
        f (b - c + c) = (\<Sum>m<n. diff m (0 + c) / real (fact m) * (b - c) ^ m) +
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    48
          diff n (x + c) / real (fact n) * (b - c) ^ n" ..
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    49
    let ?H = "x + c"
56193
c726ecfb22b6 cleanup Series: sorted according to typeclass hierarchy, use {..<_} instead of {0..<_}
hoelzl
parents: 44890
diff changeset
    50
    from X have "c<?H & ?H<b \<and> f b = (\<Sum>m<n. diff m c / real (fact m) * (b - c) ^ m) +
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    51
      diff n ?H / real (fact n) * (b - c) ^ n"
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 28952
diff changeset
    52
      by fastforce
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 28952
diff changeset
    53
    thus ?thesis by fastforce
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    54
  qed
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    55
qed
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    56
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    57
lemma taylor_down:
25162
ad4d5365d9d8 went back to >0
nipkow
parents: 25134
diff changeset
    58
  assumes INIT: "n>0" "diff 0 = f"
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    59
  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
    60
  and INTERV: "a < c" "c \<le> b"
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    61
  shows "\<exists> t. a < t & t < c & 
56193
c726ecfb22b6 cleanup Series: sorted according to typeclass hierarchy, use {..<_} instead of {0..<_}
hoelzl
parents: 44890
diff changeset
    62
    f a = (\<Sum>m<n. (diff m c / real (fact m)) * (a - c)^m) + (diff n t / real (fact n)) * (a - c)^n" 
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    63
proof -
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    64
  from INTERV have "a-c < 0" by arith
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    65
  moreover 
25162
ad4d5365d9d8 went back to >0
nipkow
parents: 25134
diff changeset
    66
  from INIT have "n>0" "((\<lambda>m x. diff m (x + c)) 0) = (\<lambda>x. f (x + c))" by auto
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    67
  moreover
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    68
  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
    69
  proof (rule allI impI)+
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    70
    fix m t
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    71
    assume "m < n & a-c <= t & t <= 0"
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    72
    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
    73
    moreover
23069
cdfff0241c12 rename lemmas LIM_ident, isCont_ident, DERIV_ident
huffman
parents: 17634
diff changeset
    74
    from DERIV_ident and DERIV_const have "DERIV (%x. x + c) t :> 1+0" by (rule DERIV_add)
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    75
    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
    76
    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
    77
  qed
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    78
  ultimately 
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    79
  have EX: "EX t>a - c. t < 0 &
56193
c726ecfb22b6 cleanup Series: sorted according to typeclass hierarchy, use {..<_} instead of {0..<_}
hoelzl
parents: 44890
diff changeset
    80
    f (a - c + c) = (SUM m<n. diff m (0 + c) / real (fact m) * (a - c) ^ m) +
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    81
      diff n (t + c) / real (fact n) * (a - c) ^ n" 
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    82
    by (rule Maclaurin_minus)
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    83
  show ?thesis
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    84
  proof -
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    85
    from EX obtain x where X: "a - c < x & x < 0 &
56193
c726ecfb22b6 cleanup Series: sorted according to typeclass hierarchy, use {..<_} instead of {0..<_}
hoelzl
parents: 44890
diff changeset
    86
      f (a - c + c) = (SUM m<n. diff m (0 + c) / real (fact m) * (a - c) ^ m) +
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    87
        diff n (x + c) / real (fact n) * (a - c) ^ n" ..
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    88
    let ?H = "x + c"
56193
c726ecfb22b6 cleanup Series: sorted according to typeclass hierarchy, use {..<_} instead of {0..<_}
hoelzl
parents: 44890
diff changeset
    89
    from X have "a<?H & ?H<c \<and> f a = (\<Sum>m<n. diff m c / real (fact m) * (a - c) ^ m) +
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    90
      diff n ?H / real (fact n) * (a - c) ^ n"
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 28952
diff changeset
    91
      by fastforce
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 28952
diff changeset
    92
    thus ?thesis by fastforce
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    93
  qed
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    94
qed
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    95
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    96
lemma taylor:
25162
ad4d5365d9d8 went back to >0
nipkow
parents: 25134
diff changeset
    97
  assumes INIT: "n>0" "diff 0 = f"
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    98
  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
    99
  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
   100
  shows "\<exists> t. (if x<c then (x < t & t < c) else (c < t & t < x)) &
56193
c726ecfb22b6 cleanup Series: sorted according to typeclass hierarchy, use {..<_} instead of {0..<_}
hoelzl
parents: 44890
diff changeset
   101
    f x = (\<Sum>m<n. (diff m c / real (fact m)) * (x - c)^m) + (diff n t / real (fact n)) * (x - c)^n" 
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   102
proof (cases "x<c")
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   103
  case True
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   104
  note INIT
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   105
  moreover from DERIV and INTERV
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   106
  have "\<forall>m t. m < n \<and> x \<le> t \<and> t \<le> b \<longrightarrow> DERIV (diff m) t :> diff (Suc m) t"
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 28952
diff changeset
   107
    by fastforce
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   108
  moreover note True
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   109
  moreover from INTERV have "c \<le> b" by simp
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   110
  ultimately have EX: "\<exists>t>x. t < c \<and> f x =
56193
c726ecfb22b6 cleanup Series: sorted according to typeclass hierarchy, use {..<_} instead of {0..<_}
hoelzl
parents: 44890
diff changeset
   111
    (\<Sum>m<n. diff m c / real (fact m) * (x - c) ^ m) + diff n t / real (fact n) * (x - c) ^ n"
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   112
    by (rule taylor_down)
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   113
  with True show ?thesis by simp
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   114
next
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   115
  case False
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   116
  note INIT
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   117
  moreover from DERIV and INTERV
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   118
  have "\<forall>m t. m < n \<and> a \<le> t \<and> t \<le> x \<longrightarrow> DERIV (diff m) t :> diff (Suc m) t"
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 28952
diff changeset
   119
    by fastforce
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   120
  moreover from INTERV have "a \<le> c" by arith
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   121
  moreover from False and INTERV have "c < x" by arith
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   122
  ultimately have EX: "\<exists>t>c. t < x \<and> f x =
56193
c726ecfb22b6 cleanup Series: sorted according to typeclass hierarchy, use {..<_} instead of {0..<_}
hoelzl
parents: 44890
diff changeset
   123
    (\<Sum>m<n. diff m c / real (fact m) * (x - c) ^ m) + diff n t / real (fact n) * (x - c) ^ n" 
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   124
    by (rule taylor_up)
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   125
  with False show ?thesis by simp
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   126
qed
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   127
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   128
end