src/HOL/Taylor.thy
author wenzelm
Sun, 31 Jul 2016 17:25:38 +0200
changeset 63569 7e0b0db5e9ac
parent 61954 1d43f86f48be
permissions -rw-r--r--
misc tuning and modernization;
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
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
     5
section \<open>Taylor series\<close>
17634
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
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
    11
text \<open>
63569
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    12
  We use MacLaurin and the translation of the expansion point \<open>c\<close> to \<open>0\<close>
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    13
  to prove Taylor's theorem.
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 59730
diff changeset
    14
\<close>
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    15
63569
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    16
lemma taylor_up:
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    17
  assumes INIT: "n > 0" "diff 0 = f"
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    18
    and DERIV: "\<forall>m t. m < n \<and> a \<le> t \<and> t \<le> b \<longrightarrow> DERIV (diff m) t :> (diff (Suc m) t)"
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    19
    and INTERV: "a \<le> c" "c < b"
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    20
  shows "\<exists>t::real. c < t \<and> t < b \<and>
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    21
    f b = (\<Sum>m<n. (diff m c / fact m) * (b - c)^m) + (diff n t / fact n) * (b - c)^n"
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    22
proof -
63569
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    23
  from INTERV have "0 < b - c" by arith
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    24
  moreover from INIT have "n > 0" "(\<lambda>m x. diff m (x + c)) 0 = (\<lambda>x. f (x + c))"
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    25
    by auto
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    26
  moreover
63569
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    27
  have "\<forall>m t. m < n \<and> 0 \<le> t \<and> t \<le> b - c \<longrightarrow> DERIV (\<lambda>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
63569
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    30
    assume "m < n \<and> 0 \<le> t \<and> t \<le> b - c"
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    31
    with DERIV and INTERV have "DERIV (diff m) (t + c) :> diff (Suc m) (t + c)"
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    32
      by auto
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    33
    moreover from DERIV_ident and DERIV_const have "DERIV (\<lambda>x. x + c) t :> 1 + 0"
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    34
      by (rule DERIV_add)
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    35
    ultimately have "DERIV (\<lambda>x. diff m (x + c)) t :> diff (Suc m) (t + c) * (1 + 0)"
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    36
      by (rule DERIV_chain2)
63569
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    37
    then show "DERIV (\<lambda>x. diff m (x + c)) t :> diff (Suc m) (t + c)"
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    38
      by simp
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    39
  qed
63569
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    40
  ultimately obtain x where
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    41
    "0 < x \<and> x < b - c \<and>
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    42
      f (b - c + c) =
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    43
        (\<Sum>m<n. diff m (0 + c) / fact m * (b - c) ^ m) + diff n (x + c) / fact n * (b - c) ^ n"
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
    44
     by (rule Maclaurin [THEN exE])
63569
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    45
   then have "c < x + c \<and> x + c < b \<and> f b =
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    46
     (\<Sum>m<n. diff m c / fact m * (b - c) ^ m) + diff n (x + c) / fact n * (b - c) ^ n"
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
    47
    by fastforce
63569
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    48
  then show ?thesis by fastforce
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    49
qed
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    50
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    51
lemma taylor_down:
63569
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    52
  fixes a :: real and n :: nat
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    53
  assumes INIT: "n > 0" "diff 0 = f"
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    54
    and DERIV: "(\<forall>m t. m < n \<and> a \<le> t \<and> t \<le> b \<longrightarrow> DERIV (diff m) t :> diff (Suc m) t)"
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    55
    and INTERV: "a < c" "c \<le> b"
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    56
  shows "\<exists>t. a < t \<and> t < c \<and>
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    57
    f a = (\<Sum>m<n. (diff m c / fact m) * (a - c)^m) + (diff n t / fact n) * (a - c)^n"
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    58
proof -
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    59
  from INTERV have "a-c < 0" by arith
63569
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    60
  moreover from INIT have "n > 0" "(\<lambda>m x. diff m (x + c)) 0 = (\<lambda>x. f (x + c))"
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    61
    by auto
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    62
  moreover
63569
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    63
  have "\<forall>m t. m < n \<and> a - c \<le> t \<and> t \<le> 0 \<longrightarrow> DERIV (\<lambda>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
    64
  proof (rule allI impI)+
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    65
    fix m t
63569
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    66
    assume "m < n \<and> a - c \<le> t \<and> t \<le> 0"
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    67
    with DERIV and INTERV have "DERIV (diff m) (t + c) :> diff (Suc m) (t + c)"
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    68
      by auto
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    69
    moreover from DERIV_ident and DERIV_const have "DERIV (\<lambda>x. x + c) t :> 1 + 0"
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    70
      by (rule DERIV_add)
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    71
    ultimately have "DERIV (\<lambda>x. diff m (x + c)) t :> diff (Suc m) (t + c) * (1 + 0)"
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    72
      by (rule DERIV_chain2)
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    73
    then show "DERIV (\<lambda>x. diff m (x + c)) t :> diff (Suc m) (t + c)"
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    74
      by simp
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    75
  qed
63569
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    76
  ultimately obtain x where
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    77
    "a - c < x \<and> x < 0 \<and>
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    78
      f (a - c + c) =
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    79
        (\<Sum>m<n. diff m (0 + c) / fact m * (a - c) ^ m) + diff n (x + c) / fact n * (a - c) ^ n"
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    80
    by (rule Maclaurin_minus [THEN exE])
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    81
  then have "a < x + c \<and> x + c < c \<and>
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    82
    f a = (\<Sum>m<n. diff m c / fact m * (a - c) ^ m) + diff n (x + c) / fact n * (a - c) ^ n"
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
    83
    by fastforce
63569
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    84
  then show ?thesis by fastforce
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    85
qed
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    86
63569
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    87
theorem taylor:
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    88
  fixes a :: real and n :: nat
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    89
  assumes INIT: "n > 0" "diff 0 = f"
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    90
    and DERIV: "\<forall>m t. m < n \<and> a \<le> t \<and> t \<le> b \<longrightarrow> DERIV (diff m) t :> diff (Suc m) t"
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    91
    and INTERV: "a \<le> c " "c \<le> b" "a \<le> x" "x \<le> b" "x \<noteq> c"
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    92
  shows "\<exists>t.
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    93
    (if x < c then x < t \<and> t < c else c < t \<and> t < x) \<and>
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    94
    f x = (\<Sum>m<n. (diff m c / fact m) * (x - c)^m) + (diff n t / fact n) * (x - c)^n"
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    95
proof (cases "x < c")
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    96
  case True
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
    97
  note INIT
63569
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    98
  moreover have "\<forall>m t. m < n \<and> x \<le> t \<and> t \<le> b \<longrightarrow> DERIV (diff m) t :> diff (Suc m) t"
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
    99
    using DERIV and INTERV by fastforce
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   100
  moreover note True
63569
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
   101
  moreover from INTERV have "c \<le> b"
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
   102
    by simp
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   103
  ultimately have "\<exists>t>x. t < c \<and> f x =
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   104
    (\<Sum>m<n. diff m c / (fact m) * (x - c) ^ m) + diff n t / (fact n) * (x - c) ^ n"
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   105
    by (rule taylor_down)
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   106
  with True show ?thesis by simp
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   107
next
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   108
  case False
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   109
  note INIT
63569
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
   110
  moreover have "\<forall>m t. m < n \<and> a \<le> t \<and> t \<le> x \<longrightarrow> DERIV (diff m) t :> diff (Suc m) t"
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
   111
    using DERIV and INTERV by fastforce
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
   112
  moreover from INTERV have "a \<le> c"
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
   113
    by arith
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
   114
  moreover from False and INTERV have "c < x"
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
   115
    by arith
59730
b7c394c7a619 The factorial function, "fact", now has type "nat => 'a"
paulson <lp15@cam.ac.uk>
parents: 58889
diff changeset
   116
  ultimately have "\<exists>t>c. t < x \<and> f x =
63569
7e0b0db5e9ac misc tuning and modernization;
wenzelm
parents: 61954
diff changeset
   117
    (\<Sum>m<n. diff m c / (fact m) * (x - c) ^ m) + diff n t / (fact n) * (x - c) ^ n"
17634
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   118
    by (rule taylor_up)
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   119
  with False show ?thesis by simp
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   120
qed
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   121
e83ce8fe58fa Formalization of Taylor series by Lukas Bulwahn and
berghofe
parents:
diff changeset
   122
end