src/HOL/Hyperreal/Lim.thy
changeset 15360 300e09825d8b
parent 15251 bb6f072c8d10
child 15539 333a88244569
equal deleted inserted replaced
15359:8bad1f42fec0 15360:300e09825d8b
     6 *)
     6 *)
     7 
     7 
     8 header{*Limits, Continuity and Differentiation*}
     8 header{*Limits, Continuity and Differentiation*}
     9 
     9 
    10 theory Lim
    10 theory Lim
    11 imports SEQ RealDef
    11 imports SEQ
    12 begin
    12 begin
    13 
    13 
    14 text{*Standard and Nonstandard Definitions*}
    14 text{*Standard and Nonstandard Definitions*}
    15 
    15 
    16 constdefs
    16 constdefs
    17   LIM :: "[real=>real,real,real] => bool"
    17   LIM :: "[real=>real,real,real] => bool"
    18 				("((_)/ -- (_)/ --> (_))" [60, 0, 60] 60)
    18 				("((_)/ -- (_)/ --> (_))" [60, 0, 60] 60)
    19   "f -- a --> L ==
    19   "f -- a --> L ==
    20      \<forall>r. 0 < r -->
    20      \<forall>r > 0. \<exists>s > 0. \<forall>x. x \<noteq> a & \<bar>x + -a\<bar> < s
    21 	     (\<exists>s. 0 < s & (\<forall>x. (x \<noteq> a & (\<bar>x + -a\<bar> < s)
    21 			  --> \<bar>f x + -L\<bar> < r"
    22 			  --> \<bar>f x + -L\<bar> < r)))"
       
    23 
    22 
    24   NSLIM :: "[real=>real,real,real] => bool"
    23   NSLIM :: "[real=>real,real,real] => bool"
    25 			      ("((_)/ -- (_)/ --NS> (_))" [60, 0, 60] 60)
    24 			      ("((_)/ -- (_)/ --NS> (_))" [60, 0, 60] 60)
    26   "f -- a --NS> L == (\<forall>x. (x \<noteq> hypreal_of_real a &
    25   "f -- a --NS> L == (\<forall>x. (x \<noteq> hypreal_of_real a &
    27 		      x @= hypreal_of_real a -->
    26 		      x @= hypreal_of_real a -->
    56   increment :: "[real=>real,real,hypreal] => hypreal"
    55   increment :: "[real=>real,real,hypreal] => hypreal"
    57   "increment f x h == (@inc. f NSdifferentiable x &
    56   "increment f x h == (@inc. f NSdifferentiable x &
    58 		       inc = ( *f* f)(hypreal_of_real x + h) + -hypreal_of_real (f x))"
    57 		       inc = ( *f* f)(hypreal_of_real x + h) + -hypreal_of_real (f x))"
    59 
    58 
    60   isUCont :: "(real=>real) => bool"
    59   isUCont :: "(real=>real) => bool"
    61   "isUCont f ==  (\<forall>r. 0 < r -->
    60   "isUCont f ==  \<forall>r > 0. \<exists>s > 0. \<forall>x y. \<bar>x + -y\<bar> < s --> \<bar>f x + -f y\<bar> < r"
    62 		      (\<exists>s. 0 < s & (\<forall>x y. \<bar>x + -y\<bar> < s
       
    63 			    --> \<bar>f x + -f y\<bar> < r)))"
       
    64 
    61 
    65   isNSUCont :: "(real=>real) => bool"
    62   isNSUCont :: "(real=>real) => bool"
    66   "isNSUCont f == (\<forall>x y. x @= y --> ( *f* f) x @= ( *f* f) y)"
    63   "isNSUCont f == (\<forall>x y. x @= y --> ( *f* f) x @= ( *f* f) y)"
    67 
    64 
    68 
    65 
    82 
    79 
    83 section{*Some Purely Standard Proofs*}
    80 section{*Some Purely Standard Proofs*}
    84 
    81 
    85 lemma LIM_eq:
    82 lemma LIM_eq:
    86      "f -- a --> L =
    83      "f -- a --> L =
    87      (\<forall>r. 0<r --> (\<exists>s. 0 < s & (\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < s --> \<bar>f x - L\<bar> < r)))"
    84      (\<forall>r>0.\<exists>s>0.\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < s --> \<bar>f x - L\<bar> < r)"
    88 by (simp add: LIM_def diff_minus)
    85 by (simp add: LIM_def diff_minus)
    89 
    86 
    90 lemma LIM_D:
    87 lemma LIM_D:
    91      "[| f -- a --> L; 0<r |]
    88      "[| f -- a --> L; 0<r |]
    92       ==> \<exists>s. 0 < s & (\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < s --> \<bar>f x - L\<bar> < r)"
    89       ==> \<exists>s>0.\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < s --> \<bar>f x - L\<bar> < r"
    93 by (simp add: LIM_eq)
    90 by (simp add: LIM_eq)
    94 
    91 
    95 lemma LIM_const [simp]: "(%x. k) -- x --> k"
    92 lemma LIM_const [simp]: "(%x. k) -- x --> k"
    96 by (simp add: LIM_def)
    93 by (simp add: LIM_def)
    97 
    94 
   109   from LIM_D [OF g half_gt_zero [OF r]]
   106   from LIM_D [OF g half_gt_zero [OF r]]
   110   obtain gs
   107   obtain gs
   111     where gs:    "0 < gs"
   108     where gs:    "0 < gs"
   112       and gs_lt: "\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < gs --> \<bar>g x - M\<bar> < r/2"
   109       and gs_lt: "\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < gs --> \<bar>g x - M\<bar> < r/2"
   113   by blast
   110   by blast
   114   show "\<exists>s. 0 < s \<and>
   111   show "\<exists>s>0.\<forall>x. x \<noteq> a \<and> \<bar>x-a\<bar> < s \<longrightarrow> \<bar>f x + g x - (L + M)\<bar> < r"
   115             (\<forall>x. x \<noteq> a \<and> \<bar>x-a\<bar> < s \<longrightarrow> \<bar>f x + g x - (L + M)\<bar> < r)"
       
   116   proof (intro exI conjI strip)
   112   proof (intro exI conjI strip)
   117     show "0 < min fs gs"  by (simp add: fs gs)
   113     show "0 < min fs gs"  by (simp add: fs gs)
   118     fix x :: real
   114     fix x :: real
   119     assume "x \<noteq> a \<and> \<bar>x-a\<bar> < min fs gs"
   115     assume "x \<noteq> a \<and> \<bar>x-a\<bar> < min fs gs"
   120     with fs_lt gs_lt
   116     with fs_lt gs_lt
   141 
   137 
   142 
   138 
   143 lemma LIM_const_not_eq: "k \<noteq> L ==> ~ ((%x. k) -- a --> L)"
   139 lemma LIM_const_not_eq: "k \<noteq> L ==> ~ ((%x. k) -- a --> L)"
   144 proof (simp add: linorder_neq_iff LIM_eq, elim disjE)
   140 proof (simp add: linorder_neq_iff LIM_eq, elim disjE)
   145   assume k: "k < L"
   141   assume k: "k < L"
   146   show "\<exists>r. 0 < r \<and>
   142   show "\<exists>r>0. \<forall>s>0. (\<exists>x. (x < a \<or> a < x) \<and> \<bar>x-a\<bar> < s) \<and> \<not> \<bar>k-L\<bar> < r"
   147         (\<forall>s. 0 < s \<longrightarrow> (\<exists>x. (x < a \<or> a < x) \<and> \<bar>x-a\<bar> < s) \<and> \<not> \<bar>k-L\<bar> < r)"
       
   148   proof (intro exI conjI strip)
   143   proof (intro exI conjI strip)
   149     show "0 < L-k" by (simp add: k compare_rls)
   144     show "0 < L-k" by (simp add: k compare_rls)
   150     fix s :: real
   145     fix s :: real
   151     assume s: "0<s"
   146     assume s: "0<s"
   152     { from s show "s/2 + a < a \<or> a < s/2 + a" by arith
   147     { from s show "s/2 + a < a \<or> a < s/2 + a" by arith
   155      next
   150      next
   156       from s show "~ \<bar>k-L\<bar> < L-k" by (simp add: abs_if) }
   151       from s show "~ \<bar>k-L\<bar> < L-k" by (simp add: abs_if) }
   157   qed
   152   qed
   158 next
   153 next
   159   assume k: "L < k"
   154   assume k: "L < k"
   160   show "\<exists>r. 0 < r \<and>
   155   show "\<exists>r>0.\<forall>s>0. (\<exists>x. (x < a \<or> a < x) \<and> \<bar>x-a\<bar> < s) \<and> \<not> \<bar>k-L\<bar> < r"
   161         (\<forall>s. 0 < s \<longrightarrow> (\<exists>x. (x < a \<or> a < x) \<and> \<bar>x-a\<bar> < s) \<and> \<not> \<bar>k-L\<bar> < r)"
       
   162   proof (intro exI conjI strip)
   156   proof (intro exI conjI strip)
   163     show "0 < k-L" by (simp add: k compare_rls)
   157     show "0 < k-L" by (simp add: k compare_rls)
   164     fix s :: real
   158     fix s :: real
   165     assume s: "0<s"
   159     assume s: "0<s"
   166     { from s show "s/2 + a < a \<or> a < s/2 + a" by arith
   160     { from s show "s/2 + a < a \<or> a < s/2 + a" by arith
   243 done
   237 done
   244 
   238 
   245 
   239 
   246 subsubsection{*Limit: The NS definition implies the standard definition.*}
   240 subsubsection{*Limit: The NS definition implies the standard definition.*}
   247 
   241 
   248 lemma lemma_LIM: "\<forall>s. 0 < s --> (\<exists>xa.  xa \<noteq> x &
   242 lemma lemma_LIM: "\<forall>s>0.\<exists>xa.  xa \<noteq> x &
   249          \<bar>xa + - x\<bar> < s  & r \<le> \<bar>f xa + -L\<bar>)
   243          \<bar>xa + - x\<bar> < s  & r \<le> \<bar>f xa + -L\<bar>
   250       ==> \<forall>n::nat. \<exists>xa.  xa \<noteq> x &
   244       ==> \<forall>n::nat. \<exists>xa.  xa \<noteq> x &
   251               \<bar>xa + -x\<bar> < inverse(real(Suc n)) & r \<le> \<bar>f xa + -L\<bar>"
   245               \<bar>xa + -x\<bar> < inverse(real(Suc n)) & r \<le> \<bar>f xa + -L\<bar>"
   252 apply clarify
   246 apply clarify
   253 apply (cut_tac n1 = n in real_of_nat_Suc_gt_zero [THEN positive_imp_inverse_positive], auto)
   247 apply (cut_tac n1 = n in real_of_nat_Suc_gt_zero [THEN positive_imp_inverse_positive], auto)
   254 done
   248 done
   255 
   249 
   256 lemma lemma_skolemize_LIM2:
   250 lemma lemma_skolemize_LIM2:
   257      "\<forall>s. 0 < s --> (\<exists>xa.  xa \<noteq> x &
   251      "\<forall>s>0.\<exists>xa.  xa \<noteq> x & \<bar>xa + - x\<bar> < s  & r \<le> \<bar>f xa + -L\<bar>
   258          \<bar>xa + - x\<bar> < s  & r \<le> \<bar>f xa + -L\<bar>)
       
   259       ==> \<exists>X. \<forall>n::nat. X n \<noteq> x &
   252       ==> \<exists>X. \<forall>n::nat. X n \<noteq> x &
   260                 \<bar>X n + -x\<bar> < inverse(real(Suc n)) & r \<le> abs(f (X n) + -L)"
   253                 \<bar>X n + -x\<bar> < inverse(real(Suc n)) & r \<le> abs(f (X n) + -L)"
   261 apply (drule lemma_LIM)
   254 apply (drule lemma_LIM)
   262 apply (drule choice, blast)
   255 apply (drule choice, blast)
   263 done
   256 done
   596 prefer 2 apply blast
   589 prefer 2 apply blast
   597 apply (erule_tac V = "\<forall>x y. \<bar>x + - y\<bar> < s --> \<bar>f x + - f y\<bar> < u" in thin_rl)
   590 apply (erule_tac V = "\<forall>x y. \<bar>x + - y\<bar> < s --> \<bar>f x + - f y\<bar> < u" in thin_rl)
   598 apply (drule FreeUltrafilterNat_all, ultra)
   591 apply (drule FreeUltrafilterNat_all, ultra)
   599 done
   592 done
   600 
   593 
   601 lemma lemma_LIMu: "\<forall>s. 0 < s --> (\<exists>z y. \<bar>z + - y\<bar> < s & r \<le> \<bar>f z + -f y\<bar>)
   594 lemma lemma_LIMu: "\<forall>s>0.\<exists>z y. \<bar>z + - y\<bar> < s & r \<le> \<bar>f z + -f y\<bar>
   602       ==> \<forall>n::nat. \<exists>z y.
   595       ==> \<forall>n::nat. \<exists>z y. \<bar>z + -y\<bar> < inverse(real(Suc n)) & r \<le> \<bar>f z + -f y\<bar>"
   603                \<bar>z + -y\<bar> < inverse(real(Suc n)) &
       
   604                r \<le> \<bar>f z + -f y\<bar>"
       
   605 apply clarify
   596 apply clarify
   606 apply (cut_tac n1 = n 
   597 apply (cut_tac n1 = n 
   607        in real_of_nat_Suc_gt_zero [THEN positive_imp_inverse_positive], auto)
   598        in real_of_nat_Suc_gt_zero [THEN positive_imp_inverse_positive], auto)
   608 done
   599 done
   609 
   600 
   610 lemma lemma_skolemize_LIM2u:
   601 lemma lemma_skolemize_LIM2u:
   611      "\<forall>s. 0 < s --> (\<exists>z y. \<bar>z + - y\<bar> < s  & r \<le> \<bar>f z + -f y\<bar>)
   602      "\<forall>s>0.\<exists>z y. \<bar>z + - y\<bar> < s  & r \<le> \<bar>f z + -f y\<bar>
   612       ==> \<exists>X Y. \<forall>n::nat.
   603       ==> \<exists>X Y. \<forall>n::nat.
   613                abs(X n + -(Y n)) < inverse(real(Suc n)) &
   604                abs(X n + -(Y n)) < inverse(real(Suc n)) &
   614                r \<le> abs(f (X n) + -f (Y n))"
   605                r \<le> abs(f (X n) + -f (Y n))"
   615 apply (drule lemma_LIMu)
   606 apply (drule lemma_LIMu)
   616 apply (drule choice, safe)
   607 apply (drule choice, safe)
   685 by (force simp add: NSdifferentiable_def)
   676 by (force simp add: NSdifferentiable_def)
   686 
   677 
   687 subsubsection{*Alternative definition for differentiability*}
   678 subsubsection{*Alternative definition for differentiability*}
   688 
   679 
   689 lemma LIM_I:
   680 lemma LIM_I:
   690      "(!!r. 0<r ==> (\<exists>s. 0 < s & (\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < s --> \<bar>f x - L\<bar> < r)))
   681      "(!!r. 0<r ==> \<exists>s>0.\<forall>x. x \<noteq> a & \<bar>x-a\<bar> < s --> \<bar>f x - L\<bar> < r)
   691       ==> f -- a --> L"
   682       ==> f -- a --> L"
   692 by (simp add: LIM_eq)
   683 by (simp add: LIM_eq)
   693 
   684 
   694 lemma DERIV_LIM_iff:
   685 lemma DERIV_LIM_iff:
   695      "((%h. (f(a + h) - f(a)) / h) -- 0 --> D) =
   686      "((%h. (f(a + h) - f(a)) / h) -- 0 --> D) =
  1436  prefer 2
  1427  prefer 2
  1437  apply simp
  1428  apply simp
  1438  apply (drule_tac P = "%d. 0<d --> ?P d" and x = 1 in spec, arith)
  1429  apply (drule_tac P = "%d. 0<d --> ?P d" and x = 1 in spec, arith)
  1439 apply (drule_tac x = x in spec)+
  1430 apply (drule_tac x = x in spec)+
  1440 apply simp
  1431 apply simp
  1441 apply (drule_tac P = "%r. ?P r --> (\<exists>s. 0<s & ?Q r s) " and x = "\<bar>y - f x\<bar>" in spec)
  1432 apply (drule_tac P = "%r. ?P r --> (\<exists>s>0. ?Q r s) " and x = "\<bar>y - f x\<bar>" in spec)
  1442 apply safe
  1433 apply safe
  1443 apply simp
  1434 apply simp
  1444 apply (drule_tac x = s in spec, clarify)
  1435 apply (drule_tac x = s in spec, clarify)
  1445 apply (cut_tac x = "f x" and y = y in linorder_less_linear, safe)
  1436 apply (cut_tac x = "f x" and y = y in linorder_less_linear, safe)
  1446 apply (drule_tac x = "ba-x" in spec)
  1437 apply (drule_tac x = "ba-x" in spec)
  1592 subsection{*If @{term "0 < f'(x)"} then @{term x} is Locally Strictly Increasing At The Right*}
  1583 subsection{*If @{term "0 < f'(x)"} then @{term x} is Locally Strictly Increasing At The Right*}
  1593 
  1584 
  1594 lemma DERIV_left_inc:
  1585 lemma DERIV_left_inc:
  1595   assumes der: "DERIV f x :> l"
  1586   assumes der: "DERIV f x :> l"
  1596       and l:   "0 < l"
  1587       and l:   "0 < l"
  1597   shows "\<exists>d. 0 < d & (\<forall>h. 0 < h & h < d --> f(x) < f(x + h))"
  1588   shows "\<exists>d > 0. \<forall>h > 0. h < d --> f(x) < f(x + h)"
  1598 proof -
  1589 proof -
  1599   from l der [THEN DERIV_D, THEN LIM_D [where r = "l"]]
  1590   from l der [THEN DERIV_D, THEN LIM_D [where r = "l"]]
  1600   have "\<exists>s. 0 < s \<and>
  1591   have "\<exists>s > 0. (\<forall>z. z \<noteq> 0 \<and> \<bar>z\<bar> < s \<longrightarrow> \<bar>(f(x+z) - f x) / z - l\<bar> < l)"
  1601               (\<forall>z. z \<noteq> 0 \<and> \<bar>z\<bar> < s \<longrightarrow> \<bar>(f(x+z) - f x) / z - l\<bar> < l)"
       
  1602     by (simp add: diff_minus)
  1592     by (simp add: diff_minus)
  1603   then obtain s
  1593   then obtain s
  1604         where s:   "0 < s"
  1594         where s:   "0 < s"
  1605           and all: "!!z. z \<noteq> 0 \<and> \<bar>z\<bar> < s \<longrightarrow> \<bar>(f(x+z) - f x) / z - l\<bar> < l"
  1595           and all: "!!z. z \<noteq> 0 \<and> \<bar>z\<bar> < s \<longrightarrow> \<bar>(f(x+z) - f x) / z - l\<bar> < l"
  1606     by auto
  1596     by auto
  1607   thus ?thesis
  1597   thus ?thesis
  1608   proof (intro exI conjI strip)
  1598   proof (intro exI conjI strip)
  1609     show "0<s" .
  1599     show "0<s" .
  1610     fix h::real
  1600     fix h::real
  1611     assume "0 < h \<and> h < s"
  1601     assume "0 < h" "h < s"
  1612     with all [of h] show "f x < f (x+h)"
  1602     with all [of h] show "f x < f (x+h)"
  1613     proof (simp add: abs_if pos_less_divide_eq diff_minus [symmetric]
  1603     proof (simp add: abs_if pos_less_divide_eq diff_minus [symmetric]
  1614 		split add: split_if_asm)
  1604 		split add: split_if_asm)
  1615       assume "~ (f (x+h) - f x) / h < l" and h: "0 < h"
  1605       assume "~ (f (x+h) - f x) / h < l" and h: "0 < h"
  1616       with l
  1606       with l
  1622 qed
  1612 qed
  1623 
  1613 
  1624 lemma DERIV_left_dec:
  1614 lemma DERIV_left_dec:
  1625   assumes der: "DERIV f x :> l"
  1615   assumes der: "DERIV f x :> l"
  1626       and l:   "l < 0"
  1616       and l:   "l < 0"
  1627   shows "\<exists>d. 0 < d & (\<forall>h. 0 < h & h < d --> f(x) < f(x-h))"
  1617   shows "\<exists>d > 0. \<forall>h > 0. h < d --> f(x) < f(x-h)"
  1628 proof -
  1618 proof -
  1629   from l der [THEN DERIV_D, THEN LIM_D [where r = "-l"]]
  1619   from l der [THEN DERIV_D, THEN LIM_D [where r = "-l"]]
  1630   have "\<exists>s. 0 < s \<and>
  1620   have "\<exists>s > 0. (\<forall>z. z \<noteq> 0 \<and> \<bar>z\<bar> < s \<longrightarrow> \<bar>(f(x+z) - f x) / z - l\<bar> < -l)"
  1631               (\<forall>z. z \<noteq> 0 \<and> \<bar>z\<bar> < s \<longrightarrow> \<bar>(f(x+z) - f x) / z - l\<bar> < -l)"
       
  1632     by (simp add: diff_minus)
  1621     by (simp add: diff_minus)
  1633   then obtain s
  1622   then obtain s
  1634         where s:   "0 < s"
  1623         where s:   "0 < s"
  1635           and all: "!!z. z \<noteq> 0 \<and> \<bar>z\<bar> < s \<longrightarrow> \<bar>(f(x+z) - f x) / z - l\<bar> < -l"
  1624           and all: "!!z. z \<noteq> 0 \<and> \<bar>z\<bar> < s \<longrightarrow> \<bar>(f(x+z) - f x) / z - l\<bar> < -l"
  1636     by auto
  1625     by auto
  1637   thus ?thesis
  1626   thus ?thesis
  1638   proof (intro exI conjI strip)
  1627   proof (intro exI conjI strip)
  1639     show "0<s" .
  1628     show "0<s" .
  1640     fix h::real
  1629     fix h::real
  1641     assume "0 < h \<and> h < s"
  1630     assume "0 < h" "h < s"
  1642     with all [of "-h"] show "f x < f (x-h)"
  1631     with all [of "-h"] show "f x < f (x-h)"
  1643     proof (simp add: abs_if pos_less_divide_eq diff_minus [symmetric]
  1632     proof (simp add: abs_if pos_less_divide_eq diff_minus [symmetric]
  1644 		split add: split_if_asm)
  1633 		split add: split_if_asm)
  1645       assume " - ((f (x-h) - f x) / h) < l" and h: "0 < h"
  1634       assume " - ((f (x-h) - f x) / h) < l" and h: "0 < h"
  1646       with l
  1635       with l
  1660   case equal show ?thesis .
  1649   case equal show ?thesis .
  1661 next
  1650 next
  1662   case less
  1651   case less
  1663   from DERIV_left_dec [OF der less]
  1652   from DERIV_left_dec [OF der less]
  1664   obtain d' where d': "0 < d'"
  1653   obtain d' where d': "0 < d'"
  1665              and lt: "\<forall>h. 0 < h \<and> h < d' \<longrightarrow> f x < f (x-h)" by blast
  1654              and lt: "\<forall>h > 0. h < d' \<longrightarrow> f x < f (x-h)" by blast
  1666   from real_lbound_gt_zero [OF d d']
  1655   from real_lbound_gt_zero [OF d d']
  1667   obtain e where "0 < e \<and> e < d \<and> e < d'" ..
  1656   obtain e where "0 < e \<and> e < d \<and> e < d'" ..
  1668   with lt le [THEN spec [where x="x-e"]]
  1657   with lt le [THEN spec [where x="x-e"]]
  1669   show ?thesis by (auto simp add: abs_if)
  1658   show ?thesis by (auto simp add: abs_if)
  1670 next
  1659 next
  1671   case greater
  1660   case greater
  1672   from DERIV_left_inc [OF der greater]
  1661   from DERIV_left_inc [OF der greater]
  1673   obtain d' where d': "0 < d'"
  1662   obtain d' where d': "0 < d'"
  1674              and lt: "\<forall>h. 0 < h \<and> h < d' \<longrightarrow> f x < f (x + h)" by blast
  1663              and lt: "\<forall>h > 0. h < d' \<longrightarrow> f x < f (x + h)" by blast
  1675   from real_lbound_gt_zero [OF d d']
  1664   from real_lbound_gt_zero [OF d d']
  1676   obtain e where "0 < e \<and> e < d \<and> e < d'" ..
  1665   obtain e where "0 < e \<and> e < d \<and> e < d'" ..
  1677   with lt le [THEN spec [where x="x+e"]]
  1666   with lt le [THEN spec [where x="x+e"]]
  1678   show ?thesis by (auto simp add: abs_if)
  1667   show ?thesis by (auto simp add: abs_if)
  1679 qed
  1668 qed
  1855 text{*A function is constant if its derivative is 0 over an interval.*}
  1844 text{*A function is constant if its derivative is 0 over an interval.*}
  1856 
  1845 
  1857 lemma DERIV_isconst_end: "[| a < b;
  1846 lemma DERIV_isconst_end: "[| a < b;
  1858          \<forall>x. a \<le> x & x \<le> b --> isCont f x;
  1847          \<forall>x. a \<le> x & x \<le> b --> isCont f x;
  1859          \<forall>x. a < x & x < b --> DERIV f x :> 0 |]
  1848          \<forall>x. a < x & x < b --> DERIV f x :> 0 |]
  1860         ==> (f b = f a)"
  1849         ==> f b = f a"
  1861 apply (drule MVT, assumption)
  1850 apply (drule MVT, assumption)
  1862 apply (blast intro: differentiableI)
  1851 apply (blast intro: differentiableI)
  1863 apply (auto dest!: DERIV_unique simp add: diff_eq_eq)
  1852 apply (auto dest!: DERIV_unique simp add: diff_eq_eq)
  1864 done
  1853 done
  1865 
  1854 
  1990 
  1979 
  1991 lemma isCont_inj_range:
  1980 lemma isCont_inj_range:
  1992   assumes d: "0 < d"
  1981   assumes d: "0 < d"
  1993       and inj: "\<forall>z. \<bar>z-x\<bar> \<le> d --> g(f z) = z"
  1982       and inj: "\<forall>z. \<bar>z-x\<bar> \<le> d --> g(f z) = z"
  1994       and cont: "\<forall>z. \<bar>z-x\<bar> \<le> d --> isCont f z"
  1983       and cont: "\<forall>z. \<bar>z-x\<bar> \<le> d --> isCont f z"
  1995   shows "\<exists>e. 0<e & (\<forall>y. \<bar>y - f x\<bar> \<le> e --> (\<exists>z. \<bar>z-x\<bar> \<le> d & f z = y))"
  1984   shows "\<exists>e>0. \<forall>y. \<bar>y - f x\<bar> \<le> e --> (\<exists>z. \<bar>z-x\<bar> \<le> d & f z = y)"
  1996 proof -
  1985 proof -
  1997   have "x-d \<le> x+d" "\<forall>z. x-d \<le> z \<and> z \<le> x+d \<longrightarrow> isCont f z" using cont d
  1986   have "x-d \<le> x+d" "\<forall>z. x-d \<le> z \<and> z \<le> x+d \<longrightarrow> isCont f z" using cont d
  1998     by (auto simp add: abs_le_interval_iff)
  1987     by (auto simp add: abs_le_interval_iff)
  1999   from isCont_Lb_Ub [OF this]
  1988   from isCont_Lb_Ub [OF this]
  2000   obtain L M
  1989   obtain L M
  2043       and inj: "\<forall>z. \<bar>z-x\<bar> \<le> d --> g(f z) = z"
  2032       and inj: "\<forall>z. \<bar>z-x\<bar> \<le> d --> g(f z) = z"
  2044       and cont: "\<forall>z. \<bar>z-x\<bar> \<le> d --> isCont f z"
  2033       and cont: "\<forall>z. \<bar>z-x\<bar> \<le> d --> isCont f z"
  2045   shows "isCont g (f x)"
  2034   shows "isCont g (f x)"
  2046 proof (simp add: isCont_iff LIM_eq)
  2035 proof (simp add: isCont_iff LIM_eq)
  2047   show "\<forall>r. 0 < r \<longrightarrow>
  2036   show "\<forall>r. 0 < r \<longrightarrow>
  2048          (\<exists>s. 0<s \<and> (\<forall>z. z\<noteq>0 \<and> \<bar>z\<bar> < s \<longrightarrow> \<bar>g(f x + z) - g(f x)\<bar> < r))"
  2037          (\<exists>s>0. \<forall>z. z\<noteq>0 \<and> \<bar>z\<bar> < s \<longrightarrow> \<bar>g(f x + z) - g(f x)\<bar> < r)"
  2049   proof (intro strip)
  2038   proof (intro strip)
  2050     fix r::real
  2039     fix r::real
  2051     assume r: "0<r"
  2040     assume r: "0<r"
  2052     from real_lbound_gt_zero [OF r d]
  2041     from real_lbound_gt_zero [OF r d]
  2053     obtain e where e: "0 < e" and e_lt: "e < r \<and> e < d" by blast
  2042     obtain e where e: "0 < e" and e_lt: "e < r \<and> e < d" by blast
  2056                   "\<forall>z. \<bar>z-x\<bar> \<le> e --> isCont f z"   by auto
  2045                   "\<forall>z. \<bar>z-x\<bar> \<le> e --> isCont f z"   by auto
  2057     from isCont_inj_range [OF e this]
  2046     from isCont_inj_range [OF e this]
  2058     obtain e' where e': "0 < e'"
  2047     obtain e' where e': "0 < e'"
  2059         and all: "\<forall>y. \<bar>y - f x\<bar> \<le> e' \<longrightarrow> (\<exists>z. \<bar>z - x\<bar> \<le> e \<and> f z = y)"
  2048         and all: "\<forall>y. \<bar>y - f x\<bar> \<le> e' \<longrightarrow> (\<exists>z. \<bar>z - x\<bar> \<le> e \<and> f z = y)"
  2060           by blast
  2049           by blast
  2061     show "\<exists>s. 0<s \<and> (\<forall>z. z\<noteq>0 \<and> \<bar>z\<bar> < s \<longrightarrow> \<bar>g(f x + z) - g(f x)\<bar> < r)"
  2050     show "\<exists>s>0. \<forall>z. z\<noteq>0 \<and> \<bar>z\<bar> < s \<longrightarrow> \<bar>g(f x + z) - g(f x)\<bar> < r"
  2062     proof (intro exI conjI)
  2051     proof (intro exI conjI)
  2063       show "0<e'" .
  2052       show "0<e'" .
  2064       show "\<forall>z. z \<noteq> 0 \<and> \<bar>z\<bar> < e' \<longrightarrow> \<bar>g (f x + z) - g (f x)\<bar> < r"
  2053       show "\<forall>z. z \<noteq> 0 \<and> \<bar>z\<bar> < e' \<longrightarrow> \<bar>g (f x + z) - g (f x)\<bar> < r"
  2065       proof (intro strip)
  2054       proof (intro strip)
  2066         fix z::real
  2055         fix z::real
  2267 val isCont_inverse_function = thm "isCont_inverse_function";
  2256 val isCont_inverse_function = thm "isCont_inverse_function";
  2268 *}
  2257 *}
  2269 
  2258 
  2270 
  2259 
  2271 end
  2260 end
  2272