Update from HH
[Flyspeck/.git] / formal_lp / old / formal_interval / theory / taylor_interval.hl
1 load_path := "/mnt/Repository/jHOLLight"::(!load_path);;
2 needs "caml/raw_printer.hl";;
3 needs "caml/sections.hl";;
4 needs "caml/ssreflect.hl";;
5 needs "Examples/ssrbool-compiled.hl";;
6 needs "Examples/ssrnat-compiled.hl";;
7 needs "../formal_lp/arith/interval_arith.hl";;
8 prioritize_real();;
9 open Interval_arith;;
10
11 let bounded_on = new_definition `bounded_on f s f_bounds <=>
12         !x. x IN s ==> interval_arith (f x) f_bounds`;;
13 let bounded_on_int = new_definition `bounded_on_int f int f_bounds <=>
14         !x. interval_arith x int ==> interval_arith (f x) f_bounds`;;
15 let derivative = new_definition `derivative f = \y. @d. (f has_real_derivative d) (atreal y)`;;
16 let nth_derivative = new_definition `nth_derivative n f = iter n derivative f`;;
17 let nth_differentiable = define `(nth_differentiable 0 f x <=> f real_continuous atreal x) /\
18         (nth_differentiable (SUC n) f x <=> nth_differentiable n f x /\ 
19                         nth_derivative n f real_differentiable atreal x)`;;
20 let nth_differentiable_on = new_definition `nth_differentiable_on n s f <=>
21         !x. x IN s ==> nth_differentiable n f x`;;
22 let nth_differentiable_on_int = new_definition `nth_differentiable_on_int n int f <=>
23         !x. interval_arith x int ==> nth_differentiable n f x`;;
24 let nth_diff_weak = new_definition `nth_diff_weak n f x <=> f real_continuous atreal x /\ 
25         ?F. F 0 = f /\ !i. i < n ==> (F i has_real_derivative F (SUC i) x) (atreal x)`;;
26 let nth_diff_strong = new_definition `nth_diff_strong n f x <=> 
27         ?s. real_open s /\ x IN s /\ nth_differentiable_on n s f`;;
28 let nth_diff_strong_int = new_definition `nth_diff_strong_int n int f <=>
29         !x. interval_arith x int ==> nth_diff_strong n f x`;;
30 (begin_section "NthDerivatives");;
31 (start_section_proof ["f";"x"](`(?d. (f has_real_derivative d) (atreal x)) ==>
32         (f has_real_derivative (derivative f x)) (atreal x)`));;
33 refine (by (VALID ((BETA_TAC THEN (case THEN (move ["d"])) THEN (move ["df"])))));;
34 refine (by (VALID (((THENL_FIRST) (((THENL_ROT 1)) (have_tac (DISCH_THEN(new_rewrite [] [])) (`derivative f x = d`))) (exact_tac)))));;
35 refine (by (VALID (((((USE_THM_THEN derivative)(new_rewrite [] [])) THEN (simp_tac)) THEN (((USE_THM_THEN SELECT_UNIQUE) apply_tac) THEN (simp_tac) THEN (move ["y"])) THEN ((split_tac) THENL [(move ["df2"]); ((DISCH_THEN(new_rewrite [] [])) THEN ((TRY done_tac)))])))));;
36 refine (by (VALID (((((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN REAL_DERIVATIVE_UNIQUE_ATREAL)(ISPEC_THEN (mk_var("f",mk_type("fun",[mk_type("real",[]);mk_type("real",[])]))) thm_tac))(ISPEC_THEN (mk_var("x",mk_type("real",[]))) thm_tac))MP_TAC) THEN (DISCH_THEN apply_tac)) THEN (done_tac)))));;
37 let has_derivative_cond = end_section_proof();;
38 (start_section_proof ["f";"x"](`f real_differentiable atreal x ==>
39         (f has_real_derivative (derivative f x)) (atreal x)`));;
40 refine (by (VALID (((((USE_THM_THEN real_differentiable)(new_rewrite [] [])) THEN (DISCH_THEN (fun snd_th -> (USE_THM_THEN has_derivative_cond)(MATCH_MP_THEN snd_th MP_TAC)))) THEN (done_tac)))));;
41 let has_derivative_alt = end_section_proof();;
42 (start_section_proof ["f";"f'";"x"](`(f has_real_derivative f') (atreal x) ==> derivative f x = f'`));;
43 refine (by (VALID (((BETA_TAC THEN (move ["df"])) THEN (((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN REAL_DERIVATIVE_UNIQUE_ATREAL)(ISPEC_THEN (mk_var("f",mk_type("fun",[mk_type("real",[]);mk_type("real",[])]))) thm_tac))(ISPEC_THEN (mk_var("x",mk_type("real",[]))) thm_tac))MP_TAC) THEN (DISCH_THEN apply_tac))))));;
44 refine (by (VALID (((((USE_THEN "df")(new_rewrite [] [])) THEN ((USE_THM_THEN has_derivative_cond)(new_rewrite [] [])) THEN ((TRY done_tac))) THEN (exists_tac (mk_var("f'",mk_type("real",[])))) THEN (done_tac)))));;
45 let derivative_unique = end_section_proof();;
46 (start_section_proof ["s";"f";"f'"](`(!x. x IN s ==> (f has_real_derivative f' x) (atreal x)) ==>
47         (!x. x IN s ==> f' x = derivative f x)`));;
48 refine (by (VALID ((BETA_TAC THEN (move ["df"]) THEN (move ["x"]) THEN (move ["xs"])))));;
49 refine (by (VALID (((((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN derivative_unique)(ISPEC_THEN (mk_var("f",mk_type("fun",[mk_type("real",[]);mk_type("real",[])]))) thm_tac))(ISPEC_THEN (`f' x`) thm_tac))(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THEN "df")(new_rewrite [] []))) THEN (done_tac)))));;
50 let derivative_unique_on = end_section_proof();;
51 (start_section_proof ["f";"f'";"x"](`f real_differentiable atreal x /\
52         derivative f x = f' ==>
53         (f has_real_derivative f') (atreal x)`));;
54 refine (by (VALID (((BETA_TAC THEN (case THEN ((move ["diff"]) THEN (DISCH_THEN(GSYM_THEN (new_rewrite [] [])))))) THEN ((USE_THM_THEN has_derivative_alt)(new_rewrite [] [])) THEN (done_tac)))));;
55 let has_derivative_lemma = end_section_proof();;
56 (start_section_proof ["f"](`nth_derivative 0 f = f`));;
57 refine (by (VALID (((((USE_THM_THEN nth_derivative)(new_rewrite [] [])) THEN ((USE_THM_THEN (GEN_ALL iter))(new_rewrite [] []))) THEN (done_tac)))));;
58 let nth_derivative0 = end_section_proof();;
59 (start_section_proof ["n";"f"](`nth_derivative (SUC n) f = derivative (nth_derivative n f)`));;
60 refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN nth_derivative)(new_rewrite [] []))) THEN ((USE_THM_THEN iterS)(new_rewrite [] []))) THEN (done_tac)))));;
61 let nth_derivativeS = end_section_proof();;
62 (start_section_proof ["n";"f"](`nth_derivative (SUC n) f = nth_derivative n (derivative f)`));;
63 refine (by (VALID (((((USE_THM_THEN nth_derivative)(new_rewrite [] [])) THEN ((USE_THM_THEN iterSr)(new_rewrite [] [])) THEN ((USE_THM_THEN nth_derivative)(GSYM_THEN (new_rewrite [] [])))) THEN (done_tac)))));;
64 let nth_Sderivative = end_section_proof();;
65 (start_section_proof ["f"](`nth_derivative 1 f = derivative f`));;
66 refine (by (VALID (((((USE_THM_THEN ONE)(new_rewrite [] [])) THEN ((USE_THM_THEN nth_derivativeS)(new_rewrite [] [])) THEN ((USE_THM_THEN nth_derivative0)(new_rewrite [] []))) THEN (done_tac)))));;
67 let nth_derivative1 = end_section_proof();;
68 (start_section_proof ["f"](`nth_derivative 2 f = derivative (derivative f)`));;
69 refine (by (VALID (((((USE_THM_THEN (ARITH_RULE `2 = SUC(SUC 0)`))(new_rewrite [] [])) THEN ((USE_THM_THEN nth_derivative)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN iterS)(new_rewrite [] []))) THEN ((USE_THM_THEN (GEN_ALL iter))(new_rewrite [] []))) THEN (done_tac)))));;
70 let nth_derivative2 = end_section_proof();;
71 (start_section_proof ["n";"m";"f"](`nth_derivative n (nth_derivative m f) = nth_derivative (n + m) f`));;
72 refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN nth_derivative)(new_rewrite [] []))) THEN ((USE_THM_THEN iter_add)(new_rewrite [] []))) THEN (done_tac)))));;
73 let nth_derivative_add = end_section_proof();;
74 (start_section_proof ["n";"f";"x"](`nth_differentiable n f x ==>
75         f real_continuous atreal x`));;
76 refine (by (VALID ((((disch_tm_tac [](mk_var("n",mk_type("num",[])))) THEN (clear_assumption "n") THEN elim THENL [ALL_TAC; ((move ["n"]) THEN (move ["IHn"]))]) THEN (((USE_THM_THEN nth_differentiable)(new_rewrite [] [])) THEN ((TRY done_tac)))))));;
77 refine (by (VALID (((BETA_TAC THEN (case THEN (DISCH_THEN (fun snd_th -> (USE_THEN "IHn")(MATCH_MP_THEN snd_th MP_TAC)))) THEN (simp_tac)) THEN (done_tac)))));;
78 let nth_diff_continuous = end_section_proof();;
79 (start_section_proof ["n";"f";"x"](`nth_differentiable n f x ==>
80    !i. i < n ==> (nth_derivative i f has_real_derivative (nth_derivative (SUC i) f x)) (atreal x)`));;
81 refine (by (VALID (((THENL_FIRST) ((disch_tm_tac [](mk_var("n",mk_type("num",[])))) THEN (clear_assumption "n") THEN elim THENL [ALL_TAC; ((move ["n"]) THEN (move ["IHn"]))]) (((USE_THM_THEN ltn0)(new_rewrite [] [])) THEN (done_tac))))));;
82 refine (by (VALID ((((USE_THM_THEN nth_differentiable)(new_rewrite [] [])) THEN ALL_TAC THEN (case THEN ((DISCH_THEN (fun snd_th -> (USE_THEN "IHn")(MATCH_MP_THEN snd_th MP_TAC))) THEN (move ["df_n"]) THEN (move ["dfn"]))) THEN (move ["i"])))));;
83 refine (by (VALID (((((USE_THM_THEN ltE)(new_rewrite [] [])) THEN ((USE_THM_THEN leqSS)(new_rewrite [] [])) THEN ((USE_THM_THEN leq_eqVlt)(new_rewrite [] []))) THEN (case THENL [(DISCH_THEN(new_rewrite [] [])); ((DISCH_THEN (fun snd_th -> (USE_THEN "df_n")(MATCH_MP_THEN snd_th MP_TAC))) THEN ((TRY done_tac)))])))));;
84 refine (by (VALID (((((USE_THM_THEN nth_derivativeS)(new_rewrite [] [])) THEN ((USE_THM_THEN has_derivative_alt)(new_rewrite [] []))) THEN (done_tac)))));;
85 let nth_differentiable_cond = end_section_proof();;
86 (start_section_proof ["n";"s";"f"](`nth_differentiable_on n s f ==>
87  !x. x IN s ==> 
88   !i. i < n ==> (nth_derivative i f has_real_derivative (nth_derivative (SUC i) f x)) (atreal x)`));;
89 refine (by (VALID ((((USE_THM_THEN nth_differentiable_on)(new_rewrite [] [])) THEN (move ["cond"]) THEN (move ["x"])))));;
90 refine (by (VALID ((((DISCH_THEN (fun snd_th -> (USE_THEN "cond")(MATCH_MP_THEN snd_th MP_TAC))) THEN BETA_TAC THEN (DISCH_THEN (fun snd_th -> (USE_THM_THEN nth_differentiable_cond)(MATCH_MP_THEN snd_th MP_TAC)))) THEN (done_tac)))));;
91 let nth_differentiable_on_cond = end_section_proof();;
92 (start_section_proof ["n";"f";"x"](`nth_differentiable n f x <=>
93   f real_continuous atreal x /\
94   !i. i < n ==> (nth_derivative i f has_real_derivative (nth_derivative (SUC i) f x)) (atreal x)`));;
95 refine (by (VALID (((split_tac) THENL [(move ["dn_f"]); (case THEN (move ["f_cont"]))]))));;
96 refine (by (VALID (((((fun thm_tac -> (USE_THM_THEN nth_diff_continuous)(fun fst_th ->(USE_THEN "dn_f")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (((USE_THM_THEN nth_differentiable_cond)MP_TAC) THEN (clear_assumption "nth_differentiable_cond") THEN (exact_tac)) THEN (done_tac)))));;
97 refine (by (VALID ((((disch_tm_tac [](mk_var("n",mk_type("num",[])))) THEN (clear_assumption "n") THEN elim THENL [ALL_TAC; ((move ["n"]) THEN (move ["IHn"]))]) THEN ((((USE_THM_THEN nth_differentiable)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN ltE)(new_rewrite [] [])) THEN ((USE_THM_THEN leqSS)(new_rewrite [] [])) THEN ((USE_THM_THEN leq_eqVlt)(new_rewrite [] []))) THEN (move ["cond"]))))));;
98 refine (by (VALID (((THENL_FIRST) (((USE_THEN "IHn")(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN andTb)(new_rewrite [] [])))) ((BETA_TAC THEN (move ["i"]) THEN (move ["i_lt_n"])) THEN (((USE_THEN "cond")MP_TAC) THEN (clear_assumption "cond") THEN (DISCH_THEN apply_tac)) THEN (done_tac))))));;
99 refine (by (VALID ((((USE_THM_THEN real_differentiable)(new_rewrite [] [])) THEN (exists_tac (`nth_derivative (SUC n) f x`))))));;
100 refine (by (VALID ((((USE_THEN "cond")MP_TAC) THEN (clear_assumption "cond") THEN (exact_tac)))));;
101 let nth_differentiable_eq = end_section_proof();;
102 (start_section_proof ["f";"int"](`nth_differentiable_on_int 2 int f ==>
103         ?f' f''. f' = derivative f /\ f'' = nth_derivative 2 f /\
104                 !x. interval_arith x int ==> (f has_real_derivative f' x) (atreal x) /\
105                                         (f' has_real_derivative f'' x) (atreal x)`));;
106 refine (by (VALID ((((USE_THM_THEN nth_differentiable_on_int)(new_rewrite [] [])) THEN (move ["h"])))));;
107 refine (by (VALID ((((exists_tac (`derivative f`)) THEN (exists_tac (`nth_derivative 2 f`))) THEN (simp_tac) THEN (move ["x"]) THEN (move ["ineq"])))));;
108 refine (by (VALID ((((USE_THM_THEN nth_derivative1)(GSYM_THEN (new_rewrite [] []))) THEN ((fun thm_tac -> (USE_THM_THEN nth_derivative0)(ISPEC_THEN (mk_var("f",mk_type("fun",[mk_type("real",[]);mk_type("real",[])]))) thm_tac))(GSYM_THEN (new_rewrite [1] []))) THEN ((USE_THM_THEN ONE)(new_rewrite [1] [])) THEN ((USE_THM_THEN (ARITH_RULE `2 = SUC 1`))(new_rewrite [] []))))));;
109 refine (by (VALID (((repeat_tactic 1 9 (((fun thm_tac -> (USE_THM_THEN nth_differentiable_cond)(ISPEC_THEN (`2`) thm_tac))(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THEN "h")(new_rewrite [] [])) THEN ((TRY done_tac))) THEN (arith_tac) THEN (done_tac)))));;
110 let nth_differentiable_on_int2 = end_section_proof();;
111 (start_section_proof ["n";"m";"f";"x"](`n <= m ==> nth_differentiable m f x ==> nth_differentiable n f x`));;
112 refine (by (VALID (((BETA_TAC THEN (move ["n_le_m"])) THEN (repeat_tactic 1 9 (((USE_THM_THEN nth_differentiable_eq)(new_rewrite [] []))) THEN ALL_TAC THEN (case THEN ((DISCH_THEN(new_rewrite [] [])) THEN (move ["cond"])))) THEN (((USE_THM_THEN andTb)(new_rewrite [] [])) THEN (move ["i"]) THEN (move ["in"]))))));;
113 refine (by (VALID (((((USE_THEN "cond")MP_TAC) THEN (clear_assumption "cond") THEN (DISCH_THEN apply_tac)) THEN (((USE_THEN "n_le_m")MP_TAC) THEN (clear_assumption "n_le_m") THEN ((USE_THM_THEN ltn_leq_trans)MP_TAC) THEN (clear_assumption "ltn_leq_trans") THEN (DISCH_THEN apply_tac)) THEN (done_tac)))));;
114 let nth_mth_diff = end_section_proof();;
115 (start_section_proof ["f";"x"](`nth_differentiable 1 f x <=> f real_differentiable atreal x`));;
116 refine (by (VALID (((((USE_THM_THEN ONE)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN (GEN_ALL nth_differentiable))(new_rewrite [] []))) THEN ((USE_THM_THEN nth_derivative0)(new_rewrite [] []))) THEN ((split_tac) THENL [(DISCH_THEN(new_rewrite [] [])); (move ["df"])])))));;
117 refine (by (VALID ((((USE_THM_THEN REAL_DIFFERENTIABLE_IMP_CONTINUOUS_ATREAL)(new_rewrite [] [])) THEN (done_tac)))));;
118 let nth_differentiable1 = end_section_proof();;
119 (start_section_proof ["n";"f";"x"](`0 < n ==> nth_differentiable n f x ==>
120         f real_differentiable atreal x`));;
121 refine (by (VALID ((((((USE_THM_THEN ltE)(new_rewrite [] [])) THEN ((USE_THM_THEN ONE)(GSYM_THEN (new_rewrite [] [])))) THEN (move ["ineq"]) THEN (move ["df"])) THEN ((USE_THM_THEN nth_differentiable1)(GSYM_THEN (new_rewrite [] []))) THEN (((USE_THM_THEN nth_mth_diff)MP_TAC) THEN (clear_assumption "nth_mth_diff") THEN (DISCH_THEN apply_tac)) THEN (exists_tac (mk_var("n",mk_type("num",[])))) THEN (done_tac)))));;
122 let nth_diff_imp_diff = end_section_proof();;
123 (start_section_proof ["n";"f";"x";"i"](`nth_differentiable n f x ==> i < n ==>
124         nth_derivative i f real_continuous atreal x`));;
125 refine (by (VALID ((((USE_THM_THEN nth_differentiable_eq)(new_rewrite [] [])) THEN ALL_TAC THEN (case THEN (move ["_"])) THEN (move ["df"])))));;
126 refine (by (VALID ((((DISCH_THEN (fun snd_th -> (USE_THEN "df")(MATCH_MP_THEN snd_th MP_TAC))) THEN BETA_TAC THEN (move ["cond"])) THEN (((USE_THM_THEN REAL_DIFFERENTIABLE_IMP_CONTINUOUS_ATREAL)MP_TAC) THEN (clear_assumption "REAL_DIFFERENTIABLE_IMP_CONTINUOUS_ATREAL") THEN (DISCH_THEN apply_tac))))));;
127 refine (by (VALID ((((USE_THM_THEN real_differentiable)(new_rewrite [] [])) THEN (exists_tac (`nth_derivative (SUC i) f x`)) THEN (done_tac)))));;
128 let nth_derivative_continuous = end_section_proof();;
129 (start_section_proof ["i";"n";"f";"x"](`nth_differentiable n f x ==> i < n ==>
130         nth_differentiable (n - i) (nth_derivative i f) x`));;
131 refine (by (VALID ((BETA_TAC THEN (move ["dnf"])))));;
132 refine (by (VALID (((((USE_THEN "dnf")MP_TAC) THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN nth_differentiable_eq)(new_rewrite [] []))) THEN ALL_TAC THEN (case THEN (move ["_"])) THEN (move ["cond"]) THEN (move ["i_lt_n"]))))));;
133 refine (by (VALID (((((fun thm_tac -> (USE_THM_THEN nth_derivative_continuous)(fun fst_th ->(USE_THEN "dnf")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (move ["j"]) THEN (move ["j_lt_ni"])))));;
134 refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN nth_derivative_add)(new_rewrite [] []))) THEN ((USE_THM_THEN addSn)(new_rewrite [] [])) THEN ((USE_THEN "cond")(new_rewrite [] []))) THEN (((USE_THEN "j_lt_ni")MP_TAC) THEN (clear_assumption "j_lt_ni") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
135 let ith_derivative_differentiable = end_section_proof();;
136 (start_section_proof ["n";"f";"x"](`nth_diff_strong n f x ==>   nth_differentiable n f x`));;
137 refine (by (VALID (((((USE_THM_THEN nth_diff_strong)(new_rewrite [] [])) THEN ALL_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["_"])) THEN (case THEN (move ["xs"]))) THEN (((USE_THM_THEN nth_differentiable_on)(new_rewrite [] [])) THEN (move ["h"]))))));;
138 refine (by (VALID ((((USE_THEN "h")MP_TAC) THEN (clear_assumption "h") THEN (exact_tac)))));;
139 let nth_diff_strong_imp_diff = end_section_proof();;
140 (begin_section "DerivativeArith");;
141 (begin_section "ElementaryDerivatives");;
142 (start_section_proof [](`derivative (\x. x) = (\x. &1)`));;
143 refine (by (VALID ((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN (move ["x"]) THEN (simp_tac)))));;
144 refine (by (VALID (((((USE_THM_THEN derivative_unique)MP_TAC) THEN (clear_assumption "derivative_unique") THEN (DISCH_THEN apply_tac)) THEN ((USE_THM_THEN HAS_REAL_DERIVATIVE_ID)(new_rewrite [] [])) THEN (done_tac)))));;
145 let derivative_x = end_section_proof();;
146 (start_section_proof ["c"](`derivative (\x. c) = (\x. &0)`));;
147 refine (by (VALID ((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN (move ["x"]) THEN (simp_tac)))));;
148 refine (by (VALID (((((USE_THM_THEN derivative_unique)MP_TAC) THEN (clear_assumption "derivative_unique") THEN (DISCH_THEN apply_tac)) THEN ((USE_THM_THEN HAS_REAL_DERIVATIVE_CONST)(new_rewrite [] [])) THEN (done_tac)))));;
149 let derivative_const = end_section_proof();;
150 (start_section_proof ["x"](`~(x = &0) ==> derivative inv x = -- inv (x * x)`));;
151 refine (by (VALID ((BETA_TAC THEN (move ["xn0"])))));;
152 refine (by (VALID (((((USE_THM_THEN derivative_unique)MP_TAC) THEN (clear_assumption "derivative_unique") THEN (DISCH_THEN apply_tac)) THEN (((USE_THM_THEN REAL_POW_2)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN HAS_REAL_DERIVATIVE_INV_BASIC)(new_rewrite [] []))) THEN (done_tac)))));;
153 let derivative_inv = end_section_proof();;
154 (start_section_proof [](`derivative atn = (\x. inv (&1 + x * x))`));;
155 refine (by (VALID (((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN REAL_POW_2)(GSYM_THEN (new_rewrite [] [])))) THEN (move ["x"]) THEN (simp_tac)))));;
156 refine (by (VALID (((((USE_THM_THEN derivative_unique)MP_TAC) THEN (clear_assumption "derivative_unique") THEN (DISCH_THEN apply_tac)) THEN ((USE_THM_THEN HAS_REAL_DERIVATIVE_ATN)(new_rewrite [] [])) THEN (done_tac)))));;
157 let derivative_atn = end_section_proof();;
158 (start_section_proof [](`derivative exp = exp`));;
159 refine (by (VALID ((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN (move ["x"]) THEN (simp_tac)))));;
160 refine (by (VALID (((((USE_THM_THEN derivative_unique)MP_TAC) THEN (clear_assumption "derivative_unique") THEN (DISCH_THEN apply_tac)) THEN ((USE_THM_THEN HAS_REAL_DERIVATIVE_EXP)(new_rewrite [] [])) THEN (done_tac)))));;
161 let derivative_exp = end_section_proof();;
162 (start_section_proof ["x"](`abs x < &1 ==> derivative acs x = --inv(sqrt(&1 - x * x))`));;
163 refine (by (VALID ((BETA_TAC THEN (move ["x_ineq"])))));;
164 refine (by (VALID (((((USE_THM_THEN derivative_unique)MP_TAC) THEN (clear_assumption "derivative_unique") THEN (DISCH_THEN apply_tac)) THEN (((USE_THM_THEN REAL_POW_2)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN HAS_REAL_DERIVATIVE_ACS)(new_rewrite [] []))) THEN (done_tac)))));;
165 let derivative_acs = end_section_proof();;
166 (start_section_proof ["x"](`&0 < x ==> derivative sqrt x = inv (&2 * sqrt x)`));;
167 refine (by (VALID ((BETA_TAC THEN (move ["xg0"])))));;
168 refine (by (VALID (((((USE_THM_THEN derivative_unique)MP_TAC) THEN (clear_assumption "derivative_unique") THEN (DISCH_THEN apply_tac)) THEN ((USE_THM_THEN HAS_REAL_DERIVATIVE_SQRT)(new_rewrite [] [])) THEN (done_tac)))));;
169 let derivative_sqrt = end_section_proof();;
170 (start_section_proof ["f";"g";"x"](`f real_differentiable atreal x ==>
171         g real_differentiable atreal (f x) ==>
172         derivative (\x. g (f x)) x = derivative f x * derivative g (f x)`));;
173 refine (by (VALID (((BETA_TAC THEN (DISCH_THEN (fun snd_th -> (USE_THM_THEN has_derivative_alt)(MATCH_MP_THEN snd_th MP_TAC))) THEN (move ["df"]) THEN (DISCH_THEN (fun snd_th -> (USE_THM_THEN has_derivative_alt)(MATCH_MP_THEN snd_th MP_TAC))) THEN (move ["dg"])) THEN (((USE_THM_THEN derivative_unique)MP_TAC) THEN (clear_assumption "derivative_unique") THEN (DISCH_THEN apply_tac))))));;
174 refine (by (VALID (((THENL_FIRST) ((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN (GEN_ALL HAS_REAL_DERIVATIVE_CHAIN))(ISPEC_THEN (`derivative f x`) thm_tac))(ISPEC_THEN (`derivative g`) thm_tac))(ISPEC_THEN (`\y. y = f x`) thm_tac))(ISPEC_THEN (mk_var("f",mk_type("fun",[mk_type("real",[]);mk_type("real",[])]))) thm_tac))(ISPEC_THEN (mk_var("g",mk_type("fun",[mk_type("real",[]);mk_type("real",[])]))) thm_tac)) MP_TAC) THEN ALL_TAC) THEN (ANTS_TAC)) ((BETA_TAC THEN (move ["y"]) THEN (DISCH_THEN(new_rewrite [] []))) THEN (done_tac))))));;
175 refine (by (VALID (((BETA_TAC THEN (case THEN (move ["_"]))) THEN (DISCH_THEN apply_tac) THEN (done_tac)))));;
176 let derivative_composition = end_section_proof();;
177 (begin_section "ElementaryCompose");;
178 (start_section_proof ["x"](`~(x = &0) ==> inv real_differentiable atreal x`));;
179 refine (by (VALID ((BETA_TAC THEN (move ["xn0"])))));;
180 refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN REAL_DIFFERENTIABLE_INV_ATREAL)(ISPEC_THEN (`(\x. x:real)`) thm_tac))(ISPEC_THEN (mk_var("x",mk_type("real",[]))) thm_tac)) MP_TAC) THEN ALL_TAC))));;
181 refine (by (VALID ((((simp_tac) THEN ((USE_THM_THEN REAL_DIFFERENTIABLE_ID)(new_rewrite [] [])) THEN ((USE_THEN "xn0")(new_rewrite [] [])) THEN (simp_tac)) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN (done_tac)))));;
182 let REAL_DIFFERENTIABLE_AT_INV = end_section_proof();;
183 (add_section_var (mk_var ("f", (`:real->real`))));;
184 (add_section_var (mk_var ("x", (`:real`))));;
185 (add_section_hyp "df" (`f real_differentiable atreal x`));;
186 (start_section_proof [](`(\x. atn (f x)) real_differentiable atreal x /\
187         derivative (\x. atn (f x)) x = derivative f x / (&1 + f x * f x)`));;
188 refine (by (VALID ((split_tac))));;
189 refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN o_THM)(ISPEC_THEN (`atn`) thm_tac))(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN (((USE_THM_THEN REAL_DIFFERENTIABLE_COMPOSE_ATREAL)MP_TAC) THEN (clear_assumption "REAL_DIFFERENTIABLE_COMPOSE_ATREAL") THEN (DISCH_THEN apply_tac))))));;
190 refine (by (VALID (((((USE_THM_THEN REAL_DIFFERENTIABLE_AT_ATN)(new_rewrite [] [])) THEN ((USE_THEN "df")(new_rewrite [] []))) THEN (done_tac)))));;
191 refine (by (VALID ((((USE_THM_THEN derivative_composition)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_DIFFERENTIABLE_AT_ATN)(new_rewrite [] []))) THEN ((TRY done_tac))))));;
192 refine (by (VALID (((((USE_THM_THEN derivative_atn)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN real_div)(new_rewrite [] []))) THEN (done_tac)))));;
193 let derivative_compose_atn = end_section_proof();;
194 (start_section_proof [](`(\x. exp (f x)) real_differentiable atreal x /\
195         derivative (\x. exp (f x)) x = exp (f x) * derivative f x`));;
196 refine (by (VALID ((split_tac))));;
197 refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN o_THM)(ISPEC_THEN (`exp`) thm_tac))(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN (((USE_THM_THEN REAL_DIFFERENTIABLE_COMPOSE_ATREAL)MP_TAC) THEN (clear_assumption "REAL_DIFFERENTIABLE_COMPOSE_ATREAL") THEN (DISCH_THEN apply_tac))))));;
198 refine (by (VALID (((((USE_THM_THEN REAL_DIFFERENTIABLE_AT_EXP)(new_rewrite [] [])) THEN ((USE_THEN "df")(new_rewrite [] []))) THEN (done_tac)))));;
199 refine (by (VALID ((((USE_THM_THEN derivative_composition)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_DIFFERENTIABLE_AT_EXP)(new_rewrite [] []))) THEN ((TRY done_tac))))));;
200 refine (by (VALID (((((USE_THM_THEN derivative_exp)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_SYM)(new_rewrite [] []))) THEN (done_tac)))));;
201 let derivative_compose_exp = end_section_proof();;
202 (start_section_proof [](`~(f x = &0) ==>
203         (\x. inv (f x)) real_differentiable atreal x /\
204         derivative (\x. inv (f x)) x = -- inv (f x * f x) * derivative f x`));;
205 refine (by (VALID (((THENL_FIRST) ((BETA_TAC THEN (move ["fn0"])) THEN (split_tac)) ((((USE_THM_THEN REAL_DIFFERENTIABLE_INV_ATREAL)MP_TAC) THEN (clear_assumption "REAL_DIFFERENTIABLE_INV_ATREAL") THEN (DISCH_THEN apply_tac)) THEN (done_tac))))));;
206 refine (by (VALID (((((USE_THM_THEN derivative_composition)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN derivative_inv)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_MUL_SYM)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THEN "df")(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_DIFFERENTIABLE_AT_INV)(new_rewrite [] []))) THEN (done_tac)))));;
207 let derivative_compose_inv = end_section_proof();;
208 (start_section_proof [](`&0 < f x ==>
209         (\x. sqrt (f x)) real_differentiable atreal x /\
210         derivative (\x. sqrt (f x)) x = derivative f x / (&2 * sqrt (f x))`));;
211 refine (by (VALID (((BETA_TAC THEN (move ["f_pos"])) THEN (split_tac)))));;
212 refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN o_THM)(ISPEC_THEN (`sqrt`) thm_tac))(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN (((USE_THM_THEN REAL_DIFFERENTIABLE_COMPOSE_ATREAL)MP_TAC) THEN (clear_assumption "REAL_DIFFERENTIABLE_COMPOSE_ATREAL") THEN (DISCH_THEN apply_tac))))));;
213 refine (by (VALID (((((USE_THEN "df")(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (((USE_THM_THEN REAL_DIFFERENTIABLE_AT_SQRT)MP_TAC) THEN (clear_assumption "REAL_DIFFERENTIABLE_AT_SQRT") THEN (DISCH_THEN apply_tac)) THEN (done_tac)))));;
214 refine (by (VALID ((((USE_THM_THEN derivative_composition)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_DIFFERENTIABLE_AT_SQRT)(new_rewrite [] []))) THEN ((TRY done_tac))))));;
215 refine (by (VALID (((((USE_THM_THEN derivative_sqrt)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN real_div)(new_rewrite [] []))) THEN (done_tac)))));;
216 let derivative_compose_sqrt = end_section_proof();;
217 (start_section_proof [](`abs (f x) < &1 ==>
218         (\x. acs (f x)) real_differentiable atreal x /\
219         derivative (\x. acs (f x)) x = -- (derivative f x / sqrt (&1 - f x * f x))`));;
220 refine (by (VALID (((BETA_TAC THEN (move ["f_abs"])) THEN (split_tac)))));;
221 refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN o_THM)(ISPEC_THEN (`acs`) thm_tac))(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN (((USE_THM_THEN REAL_DIFFERENTIABLE_COMPOSE_ATREAL)MP_TAC) THEN (clear_assumption "REAL_DIFFERENTIABLE_COMPOSE_ATREAL") THEN (DISCH_THEN apply_tac))))));;
222 refine (by (VALID (((((USE_THEN "df")(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_DIFFERENTIABLE_AT_ACS)(new_rewrite [] []))) THEN (done_tac)))));;
223 refine (by (VALID ((((USE_THM_THEN derivative_composition)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_DIFFERENTIABLE_AT_ACS)(new_rewrite [] []))) THEN ((TRY done_tac))))));;
224 refine (by (VALID (((((USE_THM_THEN derivative_acs)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN REAL_MUL_RNEG)(new_rewrite [] [])) THEN ((USE_THM_THEN real_div)(new_rewrite [] []))) THEN (done_tac)))));;
225 let derivative_compose_acs = end_section_proof();;
226 let derivative_compose_acs = finalize_theorem derivative_compose_acs;;
227 let derivative_compose_sqrt = finalize_theorem derivative_compose_sqrt;;
228 let derivative_compose_inv = finalize_theorem derivative_compose_inv;;
229 let derivative_compose_exp = finalize_theorem derivative_compose_exp;;
230 let derivative_compose_atn = finalize_theorem derivative_compose_atn;;
231 let REAL_DIFFERENTIABLE_AT_INV = finalize_theorem REAL_DIFFERENTIABLE_AT_INV;;
232 (end_section "ElementaryCompose");;
233 let derivative_compose_acs = finalize_theorem derivative_compose_acs;;
234 let derivative_compose_sqrt = finalize_theorem derivative_compose_sqrt;;
235 let derivative_compose_inv = finalize_theorem derivative_compose_inv;;
236 let derivative_compose_exp = finalize_theorem derivative_compose_exp;;
237 let derivative_compose_atn = finalize_theorem derivative_compose_atn;;
238 let REAL_DIFFERENTIABLE_AT_INV = finalize_theorem REAL_DIFFERENTIABLE_AT_INV;;
239 let derivative_composition = finalize_theorem derivative_composition;;
240 let derivative_sqrt = finalize_theorem derivative_sqrt;;
241 let derivative_acs = finalize_theorem derivative_acs;;
242 let derivative_exp = finalize_theorem derivative_exp;;
243 let derivative_atn = finalize_theorem derivative_atn;;
244 let derivative_inv = finalize_theorem derivative_inv;;
245 let derivative_const = finalize_theorem derivative_const;;
246 let derivative_x = finalize_theorem derivative_x;;
247 (end_section "ElementaryDerivatives");;
248 (add_section_var (mk_var ("f", (`:real -> real`))); add_section_var (mk_var ("g", (`:real -> real`))));;
249 (add_section_var (mk_var ("x", (`:real`))); add_section_var (mk_var ("c", (`:real`))));;
250 (add_section_hyp "df" (`f real_differentiable atreal x`));;
251 (start_section_proof [](`derivative (\x. c * f x) x = c * derivative f x`));;
252 refine (by (VALID (((((USE_THM_THEN derivative_unique)MP_TAC) THEN (clear_assumption "derivative_unique") THEN (DISCH_THEN apply_tac)) THEN (((USE_THM_THEN HAS_REAL_DERIVATIVE_LMUL_ATREAL)(new_rewrite [] [])) THEN ((USE_THM_THEN has_derivative_alt)(new_rewrite [] []))) THEN (done_tac)))));;
253 let derivative_scale = end_section_proof();;
254 (start_section_proof [](`derivative (\x. -- f x) x = -- derivative f x`));;
255 refine (by (VALID (((((USE_THM_THEN derivative_unique)MP_TAC) THEN (clear_assumption "derivative_unique") THEN (DISCH_THEN apply_tac)) THEN (((USE_THM_THEN HAS_REAL_DERIVATIVE_NEG)(new_rewrite [] [])) THEN ((USE_THM_THEN has_derivative_alt)(new_rewrite [] []))) THEN (done_tac)))));;
256 let derivative_neg = end_section_proof();;
257 (start_section_proof ["n"](`derivative (\x. f x pow n) x = &n * f x pow (n - 1) * derivative f x`));;
258 refine (by (VALID (((((USE_THM_THEN derivative_unique)MP_TAC) THEN (clear_assumption "derivative_unique") THEN (DISCH_THEN apply_tac)) THEN (((USE_THM_THEN HAS_REAL_DERIVATIVE_POW_ATREAL)(new_rewrite [] [])) THEN ((USE_THM_THEN has_derivative_alt)(new_rewrite [] []))) THEN (done_tac)))));;
259 let derivative_pow = end_section_proof();;
260 (add_section_hyp "dg" (`g real_differentiable atreal x`));;
261 (start_section_proof [](`derivative (\x. f x + g x) x = derivative f x + derivative g x`));;
262 refine (by (VALID (((((USE_THM_THEN derivative_unique)MP_TAC) THEN (clear_assumption "derivative_unique") THEN (DISCH_THEN apply_tac)) THEN (((USE_THM_THEN HAS_REAL_DERIVATIVE_ADD)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN has_derivative_alt)(new_rewrite [] [])))) THEN (done_tac)))));;
263 let derivative_add = end_section_proof();;
264 (start_section_proof [](`derivative (\x. f x * g x) x = f x * derivative g x + derivative f x * g x`));;
265 refine (by (VALID (((((USE_THM_THEN derivative_unique)MP_TAC) THEN (clear_assumption "derivative_unique") THEN (DISCH_THEN apply_tac)) THEN (((USE_THM_THEN HAS_REAL_DERIVATIVE_MUL_ATREAL)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN has_derivative_alt)(new_rewrite [] [])))) THEN (done_tac)))));;
266 let derivative_mul = end_section_proof();;
267 (start_section_proof [](`derivative (\x. f x - g x) x = derivative f x - derivative g x`));;
268 refine (by (VALID (((((USE_THM_THEN derivative_unique)MP_TAC) THEN (clear_assumption "derivative_unique") THEN (DISCH_THEN apply_tac)) THEN (((USE_THM_THEN HAS_REAL_DERIVATIVE_SUB)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN has_derivative_alt)(new_rewrite [] [])))) THEN (done_tac)))));;
269 let derivative_sub = end_section_proof();;
270 (start_section_proof [](`~(g x = &0) ==> 
271   derivative (\x. f x / g x) x = (derivative f x * g x - f x * derivative g x) / (g x * g x)`));;
272 refine (by (VALID (((BETA_TAC THEN (move ["gn0"])) THEN (((USE_THM_THEN derivative_unique)MP_TAC) THEN (clear_assumption "derivative_unique") THEN (DISCH_THEN apply_tac)) THEN (((USE_THM_THEN REAL_POW_2)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN HAS_REAL_DERIVATIVE_DIV_ATREAL)(new_rewrite [] [])) THEN ((TRY done_tac)))))));;
273 refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN has_derivative_alt)(new_rewrite [] []))) THEN (done_tac)))));;
274 let derivative_div = end_section_proof();;
275 let derivative_div = finalize_theorem derivative_div;;
276 let derivative_sub = finalize_theorem derivative_sub;;
277 let derivative_mul = finalize_theorem derivative_mul;;
278 let derivative_add = finalize_theorem derivative_add;;
279 let derivative_pow = finalize_theorem derivative_pow;;
280 let derivative_neg = finalize_theorem derivative_neg;;
281 let derivative_scale = finalize_theorem derivative_scale;;
282 let derivative_compose_acs = finalize_theorem derivative_compose_acs;;
283 let derivative_compose_sqrt = finalize_theorem derivative_compose_sqrt;;
284 let derivative_compose_inv = finalize_theorem derivative_compose_inv;;
285 let derivative_compose_exp = finalize_theorem derivative_compose_exp;;
286 let derivative_compose_atn = finalize_theorem derivative_compose_atn;;
287 let REAL_DIFFERENTIABLE_AT_INV = finalize_theorem REAL_DIFFERENTIABLE_AT_INV;;
288 let derivative_composition = finalize_theorem derivative_composition;;
289 let derivative_sqrt = finalize_theorem derivative_sqrt;;
290 let derivative_acs = finalize_theorem derivative_acs;;
291 let derivative_exp = finalize_theorem derivative_exp;;
292 let derivative_atn = finalize_theorem derivative_atn;;
293 let derivative_inv = finalize_theorem derivative_inv;;
294 let derivative_const = finalize_theorem derivative_const;;
295 let derivative_x = finalize_theorem derivative_x;;
296 (end_section "DerivativeArith");;
297 (begin_section "MoreDerivativeArith");;
298 (start_section_proof ["G";"n";"m";"x"](`(!i. i IN n..m ==> G i real_differentiable atreal x) ==>
299         (\x. sum (n..m) (\i. G i x)) real_differentiable atreal x`));;
300 refine (by (VALID ((((disch_tm_tac [](mk_var("m",mk_type("num",[])))) THEN (clear_assumption "m") THEN elim THENL [ALL_TAC; ((move ["m"]) THEN (move ["IHm"]))] THEN (move ["dG"])) THEN repeat_tactic 1 9 (((USE_THM_THEN (GEN_ALL SUM_CLAUSES_NUMSEG))(new_rewrite [] [])))))));;
301 refine (by (VALID (((((fun thm_tac -> (USE_THM_THEN EXCLUDED_MIDDLE)(ISPEC_THEN (`n = 0`) thm_tac))MP_TAC) THEN case THEN (simp_tac) THEN (move ["n_eq_0"])) THEN (((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN ((USE_THM_THEN REAL_DIFFERENTIABLE_CONST)(fun th -> ONCE_REWRITE_TAC[th])) THEN ((TRY done_tac)))))));;
302 refine (by (VALID (((((USE_THEN "dG")(new_rewrite [] [])) THEN ((USE_THM_THEN IN_NUMSEG)(new_rewrite [] [])) THEN ((USE_THEN "n_eq_0")(new_rewrite [] [])) THEN ((USE_THM_THEN leqnn)(new_rewrite [] []))) THEN (done_tac)))));;
303 refine (by (VALID (((THENL_ROT (-1)) (((fun thm_tac -> (USE_THM_THEN EXCLUDED_MIDDLE)(ISPEC_THEN (`n <= SUC m`) thm_tac))MP_TAC) THEN case THEN (simp_tac) THEN (move ["n_le_Sm"]))))));;
304 refine (by (VALID (((((USE_THEN "IHm")MP_TAC) THEN (clear_assumption "IHm") THEN (DISCH_THEN apply_tac) THEN (move ["i"]) THEN (move ["i_in"])) THEN (((USE_THEN "dG")MP_TAC) THEN (clear_assumption "dG") THEN (DISCH_THEN apply_tac))))));;
305 refine (by (VALID (((((USE_THEN "i_in")MP_TAC) THEN (clear_assumption "i_in") THEN BETA_TAC) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_NUMSEG)(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac)))));;
306 refine (by (VALID ((((USE_THM_THEN REAL_DIFFERENTIABLE_ADD)(new_rewrite [] [])) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN (((USE_THEN "dG")(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "IHm")(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN IN_NUMSEG)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "n_le_Sm")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN leqnn)(new_rewrite [] []))) THEN ((TRY done_tac)))))));;
307 refine (by (VALID (((BETA_TAC THEN (move ["i"]) THEN (move ["ineq"])) THEN (((USE_THEN "dG")MP_TAC) THEN (clear_assumption "dG") THEN (DISCH_THEN apply_tac)) THEN ((USE_THM_THEN IN_NUMSEG)(new_rewrite [] []))))));;
308 refine (by (VALID (((((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
309 let differentiable_sum_numseg = end_section_proof();;
310 (start_section_proof ["G";"n";"m";"x"](`(!i. i IN n..m ==> G i real_differentiable atreal x) ==>
311         derivative (\x. sum (n..m) (\i. G i x)) x = sum (n..m) (\i. derivative (G i) x)`));;
312 refine (by (VALID ((((disch_tm_tac [](mk_var("m",mk_type("num",[])))) THEN (clear_assumption "m") THEN elim THENL [ALL_TAC; ((move ["m"]) THEN (move ["IHm"]))] THEN (move ["dG"])) THEN repeat_tactic 1 9 (((USE_THM_THEN (GEN_ALL SUM_CLAUSES_NUMSEG))(new_rewrite [] [])))))));;
313 refine (by (VALID ((((disch_tm_tac [](`n = 0`)) THEN case THEN (simp_tac)) THEN (((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN derivative_const)(fun th -> ONCE_REWRITE_TAC[th]))) THEN (done_tac)))));;
314 refine (by (VALID (((THENL_ROT (-1)) (((fun thm_tac -> (USE_THM_THEN EXCLUDED_MIDDLE)(ISPEC_THEN (`n <= SUC m`) thm_tac))MP_TAC) THEN case THEN (simp_tac) THEN (move ["n_le_Sm"]))))));;
315 refine (by (VALID (((((USE_THEN "IHm")MP_TAC) THEN (clear_assumption "IHm") THEN (DISCH_THEN apply_tac) THEN (move ["i"]) THEN (move ["i_in"])) THEN (((USE_THEN "dG")MP_TAC) THEN (clear_assumption "dG") THEN (DISCH_THEN apply_tac))))));;
316 refine (by (VALID (((((USE_THEN "i_in")MP_TAC) THEN (clear_assumption "i_in") THEN BETA_TAC) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_NUMSEG)(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac)))));;
317 refine (by (VALID (((USE_THEN "IHm")(GSYM_THEN (new_rewrite [] []))))));;
318 refine (by (VALID (((BETA_TAC THEN (move ["i"]) THEN (move ["i_in"])) THEN (((USE_THEN "dG")MP_TAC) THEN (clear_assumption "dG") THEN (DISCH_THEN apply_tac))))));;
319 refine (by (VALID (((((USE_THEN "i_in")MP_TAC) THEN (clear_assumption "i_in") THEN BETA_TAC) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_NUMSEG)(new_rewrite [] []))) THEN (arith_tac)))));;
320 refine (by (VALID ((((USE_THM_THEN derivative_add)(new_rewrite [] [])) THEN (((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN ((TRY done_tac)))))));;
321 refine (by (VALID (((((USE_THEN "dG")(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN IN_NUMSEG)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN leqnn)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andbT)(new_rewrite [] [])) THEN ((USE_THM_THEN differentiable_sum_numseg)(new_rewrite [] []))) THEN (move ["i"]) THEN (move ["i_in"])))));;
322 refine (by (VALID (((((USE_THEN "dG")MP_TAC) THEN (clear_assumption "dG") THEN (DISCH_THEN apply_tac)) THEN (((USE_THEN "i_in")MP_TAC) THEN (clear_assumption "i_in") THEN BETA_TAC) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_NUMSEG)(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac)))));;
323 let derivative_sum_numseg = end_section_proof();;
324 let derivative_sum_numseg = finalize_theorem derivative_sum_numseg;;
325 let differentiable_sum_numseg = finalize_theorem differentiable_sum_numseg;;
326 (end_section "MoreDerivativeArith");;
327 (start_section_proof ["f";"g";"x";"s"](`g real_differentiable atreal x /\ real_open s /\ x IN s /\
328         (!y. y IN s ==> f y = g y) ==> f real_differentiable atreal x`));;
329 refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN real_differentiable)(new_rewrite [] []))) THEN ALL_TAC THEN (case THEN ALL_TAC) THEN (case THEN (move ["f'"])) THEN (move ["dg"]) THEN (case THEN (move ["open_s"])) THEN (case THEN (move ["xs"])) THEN (move ["eq"])))));;
330 refine (by (VALID (((exists_tac (mk_var("f'",mk_type("real",[])))) THEN (((USE_THM_THEN Arc_properties.HAS_REAL_DERIVATIVE_LOCAL)MP_TAC) THEN (clear_assumption "Arc_properties.HAS_REAL_DERIVATIVE_LOCAL") THEN (DISCH_THEN apply_tac))))));;
331 refine (by (VALID (((exists_tac (mk_var("g",mk_type("fun",[mk_type("real",[]);mk_type("real",[])])))) THEN (((USE_THEN "dg")(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (exists_tac (mk_var("s",mk_type("fun",[mk_type("real",[]);mk_type("bool",[])])))) THEN (done_tac)))));;
332 let differentiable_local = end_section_proof();;
333 (begin_section "NthDerivativeArith");;
334 (add_section_var (mk_var ("f", (`:real->real`))); add_section_var (mk_var ("g", (`:real->real`))));;
335 (add_section_var (mk_var ("int", (`:real#real`))));;
336 (add_section_var (mk_var ("n", (`:num`))));;
337 (add_section_hyp "df" (`nth_diff_strong_int n int f`));;
338 (start_section_proof ["c";"i";"x"](`interval_arith x int ==> i <= n ==>
339         ?s. real_open s /\ x IN s /\ 
340         !y. y IN s ==> nth_derivative i (\y. c * f y) y = c * nth_derivative i f y`));;
341 refine (by (VALID (((((USE_THEN "df")MP_TAC) THEN (clear_assumption "df") THEN BETA_TAC) THEN ((((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] [])) THEN ((USE_THM_THEN nth_diff_strong)(new_rewrite [] []))) THEN (move ["df"]))))));;
342 refine (by (VALID ((((DISCH_THEN (fun snd_th -> (USE_THEN "df")(MATCH_MP_THEN snd_th MP_TAC))) THEN BETA_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["open_s"])) THEN (case THEN (move ["xs"]))) THEN ((((USE_THM_THEN nth_differentiable_on)(new_rewrite [] [])) THEN ((USE_THM_THEN nth_differentiable_eq)(new_rewrite [] []))) THEN (move ["diff"]))))));;
343 refine (by (VALID (((THENL_FIRST) ((disch_tm_tac [](mk_var("i",mk_type("num",[])))) THEN (clear_assumption "i") THEN elim THENL [(move ["_"]); ((move ["i"]) THEN (move ["IHi"]))]) (repeat_tactic 1 9 (((USE_THM_THEN nth_derivative0)(new_rewrite [] []))) THEN (exists_tac (mk_var("s",mk_type("fun",[mk_type("real",[]);mk_type("bool",[])])))) THEN (done_tac))))));;
344 refine (by (VALID (((((USE_THM_THEN nth_derivativeS)(new_rewrite [] [])) THEN ((USE_THM_THEN ltE)(GSYM_THEN (new_rewrite [] [])))) THEN (move ["i_lt_n"])))));;
345 refine (by (VALID (((((fun thm_tac -> (USE_THEN "IHi")(fun fst_th ->(fun thm_tac -> (USE_THM_THEN ltnW)(fun fst_th ->(USE_THEN "i_lt_n")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["t"])) THEN (case THEN (move ["open_t"])) THEN (case THEN (move ["xt"])) THEN (move ["eq"])) THEN (((USE_THEN "IHi")MP_TAC) THEN (clear_assumption "IHi") THEN BETA_TAC THEN (move ["_"]))))));;
346 refine (by (VALID (((exists_tac (`s INTER t`)) THEN ((((USE_THM_THEN REAL_OPEN_INTER)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_INTER)(new_rewrite [] []))) THEN ((USE_THEN "xt")(new_rewrite [] [])) THEN ((USE_THEN "xs")(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] [])))) THEN (move ["y"]) THEN (case THEN ((move ["ys"]) THEN (move ["yt"]))))))));;
347 refine (by (VALID ((((USE_THM_THEN derivative_unique)MP_TAC) THEN (clear_assumption "derivative_unique") THEN (DISCH_THEN apply_tac)))));;
348 refine (by (VALID ((((USE_THM_THEN Arc_properties.HAS_REAL_DERIVATIVE_LOCAL)MP_TAC) THEN (clear_assumption "Arc_properties.HAS_REAL_DERIVATIVE_LOCAL") THEN (DISCH_THEN apply_tac)))));;
349 refine (by (VALID ((exists_tac (`\y. c * nth_derivative i f y`)))));;
350 refine (by (VALID ((((USE_THM_THEN HAS_REAL_DERIVATIVE_LMUL_ATREAL)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN andTb)(new_rewrite [] [])))))));;
351 refine (by (VALID ((((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN ((fun thm_tac -> (USE_THEN "diff")(fun fst_th ->(USE_THEN "ys")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] [])) THEN (done_tac)))));;
352 refine (by (VALID (((exists_tac (`s INTER t`)) THEN ((((USE_THM_THEN REAL_OPEN_INTER)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_INTER)(new_rewrite [] []))) THEN ((USE_THEN "yt")(new_rewrite [1] [])) THEN ((USE_THEN "ys")(new_rewrite [1] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] [])))) THEN (move ["z"]) THEN (move ["z_in"]) THEN (simp_tac))))));;
353 refine (by (VALID ((((USE_THEN "eq")(new_rewrite [] [])) THEN (done_tac)))));;
354 let nth_derivative_scale_strong = end_section_proof();;
355 (start_section_proof ["c";"x"](`interval_arith x int ==>
356         ?s. real_open s /\ x IN s /\ 
357         !i y. i <= n /\ y IN s ==> nth_derivative i (\y. c * f y) y = c * nth_derivative i f y`));;
358 refine (by (VALID ((BETA_TAC THEN (DISCH_THEN (fun snd_th -> (fun thm_tac -> (USE_THM_THEN nth_derivative_scale_strong)(ISPEC_THEN (mk_var("c",mk_type("real",[]))) thm_tac))(MATCH_MP_THEN snd_th MP_TAC))) THEN (move ["h"])))));;
359 refine (by (VALID ((set_tac "P" (`\i s. real_open s /\ x IN s /\ 
360         (!y. y IN s ==> nth_derivative i (\y. c * f y) y = c * nth_derivative i f y)`)))));;
361 refine (by (VALID ((have_tac (move ["sel_P"]) (`!i. i <= n:num ==> P i ((@) (P i))`)))));;
362 refine (by (VALID (((BETA_TAC THEN (move ["i"]) THEN (move ["i_le_n"])) THEN ((USE_THM_THEN SELECT_AX) apply_tac)))));;
363 refine (by (VALID ((((fun thm_tac -> (USE_THEN "h")(fun fst_th ->(USE_THEN "i_le_n")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["s"])) THEN (move ["cond"])))));;
364 refine (by (VALID (((exists_tac (mk_var("s",mk_type("fun",[mk_type("real",[]);mk_type("bool",[])])))) THEN (((USE_THEN "P_def")(GSYM_THEN (new_rewrite [] []))) THEN (simp_tac)) THEN (done_tac)))));;
365 refine (by (VALID ((set_tac "S" (`INTERS (IMAGE (\i. (@) (P i)) (0..n))`)))));;
366 refine (by (VALID ((exists_tac (mk_var("S",mk_type("fun",[mk_type("real",[]);mk_type("bool",[])])))))));;
367 refine (by (VALID ((((USE_THEN "S_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN REAL_OPEN_INTERS)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN FINITE_IMAGE)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN FINITE_NUMSEG)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN IN_IMAGE)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN andTb)(new_rewrite [] [])))))));;
368 refine (by (VALID (((BETA_TAC THEN (move ["t"]) THEN (case THEN (move ["i"])) THEN (case THEN (DISCH_THEN(new_rewrite [] [])))) THEN (((USE_THM_THEN IN_NUMSEG_0)(new_rewrite [] [])) THEN (DISCH_THEN (fun snd_th -> (USE_THEN "sel_P")(MATCH_MP_THEN snd_th MP_TAC))))))));;
369 refine (by (VALID (((((USE_THEN "P_def")(GSYM_THEN (new_rewrite [1] []))) THEN (simp_tac)) THEN (done_tac)))));;
370 refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN IN_INTERS)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_IMAGE)(new_rewrite [] [])))) THEN (split_tac)))));;
371 refine (by (VALID (((BETA_TAC THEN (move ["t"]) THEN (case THEN (move ["i"])) THEN (case THEN (DISCH_THEN(new_rewrite [] [])))) THEN (((USE_THM_THEN IN_NUMSEG_0)(new_rewrite [] [])) THEN (DISCH_THEN (fun snd_th -> (USE_THEN "sel_P")(MATCH_MP_THEN snd_th MP_TAC))))))));;
372 refine (by (VALID (((((USE_THEN "P_def")(GSYM_THEN (new_rewrite [1] []))) THEN (simp_tac)) THEN (done_tac)))));;
373 refine (by (VALID ((BETA_TAC THEN (move ["i"]) THEN (move ["y"]) THEN (case THEN (move ["i_le_n"]))))));;
374 refine (by (VALID (((((fun thm_tac -> (USE_THEN "sel_P")(fun fst_th ->(USE_THEN "i_le_n")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC) THEN ((((USE_THEN "P_def")(GSYM_THEN (new_rewrite [1] []))) THEN (simp_tac)) THEN ALL_TAC THEN (case THEN (move ["_"])) THEN (case THEN (move ["_"])) THEN (move ["y_in"]) THEN ((fun thm_tac -> DISCH_THEN (ISPEC_THEN (`(@) (P i)`) thm_tac))MP_TAC))))));;
375 refine (by (VALID (((THENL_FIRST) (ANTS_TAC) ((exists_tac (mk_var("i",mk_type("num",[])))) THEN ((USE_THM_THEN IN_NUMSEG_0)(new_rewrite [] [])) THEN (done_tac))))));;
376 refine (by (VALID ((((USE_THEN "y_in")MP_TAC) THEN (clear_assumption "y_in") THEN (exact_tac)))));;
377 let nth_derivative_scale_strong_all = end_section_proof();;
378 (start_section_proof ["c";"i";"x"](`interval_arith x int ==> i <= n ==>
379         nth_derivative i (\x. c * f x) x = c * nth_derivative i f x`));;
380 refine (by (VALID ((BETA_TAC THEN (move ["ineq"]) THEN (move ["i_le_n"])))));;
381 refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN nth_derivative_scale_strong)(ISPEC_THEN (mk_var("c",mk_type("real",[]))) thm_tac))(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "i_le_n")(fun th -> MATCH_MP_THEN th thm_tac fst_th))) MP_TAC) THEN ALL_TAC))));;
382 refine (by (VALID ((BETA_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["_"])) THEN (case THEN (move ["xs"])) THEN (move ["h"])))));;
383 refine (by (VALID ((((USE_THEN "h")MP_TAC) THEN (clear_assumption "h") THEN (exact_tac)))));;
384 let nth_derivative_scale = end_section_proof();;
385 (start_section_proof ["c"](`nth_diff_strong_int n int (\x. c * f x)`));;
386 refine (by (VALID (((((USE_THEN "df")MP_TAC) THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_differentiable_on)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_differentiable_eq)(new_rewrite [] []))))))));;
387 refine (by (VALID ((BETA_TAC THEN (move ["df"]) THEN (move ["x"]) THEN (move ["ineq"])))));;
388 refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN nth_derivative_scale_strong_all)(ISPEC_THEN (mk_var("c",mk_type("real",[]))) thm_tac))(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th))) MP_TAC) THEN ALL_TAC))));;
389 refine (by (VALID ((BETA_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["open_s"])) THEN (case THEN (move ["xs"])) THEN (move ["diff"])))));;
390 refine (by (VALID ((((fun thm_tac -> (USE_THEN "df")(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["t"])) THEN (case THEN (move ["open_t"])) THEN (case THEN (move ["xt"])) THEN (move ["diff2"])))));;
391 refine (by (VALID (((exists_tac (`s INTER t`)) THEN ((((USE_THM_THEN REAL_OPEN_INTER)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN IN_INTER)(new_rewrite [] [])) THEN ((USE_THEN "xs")(new_rewrite [1] [])) THEN ((USE_THEN "xt")(new_rewrite [1] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] [])))) THEN (move ["y"]) THEN (case THEN ((move ["ys"]) THEN (move ["yt"]))))))));;
392 refine (by (VALID (((((USE_THM_THEN REAL_CONTINUOUS_LMUL)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "diff2")(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (move ["i"]) THEN (move ["i_lt_n"])))));;
393 refine (by (VALID ((((USE_THEN "diff")(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "ys")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN ltE)(GSYM_THEN (new_rewrite [] [])))) THEN ((TRY done_tac))))));;
394 refine (by (VALID ((((USE_THM_THEN Arc_properties.HAS_REAL_DERIVATIVE_LOCAL)MP_TAC) THEN (clear_assumption "Arc_properties.HAS_REAL_DERIVATIVE_LOCAL") THEN (DISCH_THEN apply_tac)))));;
395 refine (by (VALID ((exists_tac (`(\y. c * nth_derivative i f y)`)))));;
396 refine (by (VALID (((THENL_FIRST) (((USE_THM_THEN HAS_REAL_DERIVATIVE_LMUL_ATREAL)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN andTb)(new_rewrite [] [])))) (((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN ((fun thm_tac -> (USE_THEN "diff2")(fun fst_th ->(USE_THEN "yt")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] [])) THEN (done_tac))))));;
397 refine (by (VALID (((exists_tac (mk_var("s",mk_type("fun",[mk_type("real",[]);mk_type("bool",[])])))) THEN ((((USE_THEN "open_s")(new_rewrite [] [])) THEN ((USE_THEN "ys")(new_rewrite [1] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] [])))) THEN (move ["z"]) THEN (move ["zs"]) THEN (simp_tac))))));;
398 refine (by (VALID (((((USE_THEN "diff")MP_TAC) THEN (clear_assumption "diff") THEN (DISCH_THEN apply_tac)) THEN ((USE_THM_THEN ltnW)(new_rewrite [] [])) THEN (done_tac)))));;
399 let nth_diff_scale = end_section_proof();;
400 (add_section_hyp "dg" (`nth_diff_strong_int n int g`));;
401 (start_section_proof ["i";"x"](`interval_arith x int ==> i <= n ==>
402    ?s. real_open s /\ x IN s /\ 
403       !y. y IN s ==> nth_derivative i (\y. f y + g y) y = nth_derivative i f y + nth_derivative i g y`));;
404 refine (by (VALID (((((USE_THEN "dg")MP_TAC) THEN (clear_assumption "dg") THEN ((USE_THEN "df")MP_TAC) THEN (clear_assumption "df") THEN BETA_TAC) THEN ((repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong)(new_rewrite [] [])))) THEN (move ["df"]) THEN (move ["dg"]) THEN (move ["ineq"]))))));;
405 refine (by (VALID (((((fun thm_tac -> (USE_THEN "df")(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["sf"])) THEN (case THEN (move ["open_sf"])) THEN (case THEN (move ["xsf"]))) THEN (((USE_THEN "df")MP_TAC) THEN (clear_assumption "df") THEN BETA_TAC THEN (move ["_"]))))));;
406 refine (by (VALID (((((fun thm_tac -> (USE_THEN "dg")(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["sg"])) THEN (case THEN (move ["open_sg"])) THEN (case THEN (move ["xsg"]))) THEN (((USE_THEN "dg")MP_TAC) THEN (clear_assumption "dg") THEN BETA_TAC THEN (move ["_"]))))));;
407 refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN nth_differentiable_on)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_differentiable_eq)(new_rewrite [] [])))) THEN (move ["diff_g"]) THEN (move ["diff_f"])))));;
408 refine (by (VALID (((THENL_FIRST) ((disch_tm_tac [](mk_var("i",mk_type("num",[])))) THEN (clear_assumption "i") THEN elim THENL [(move ["_"]); ((move ["i"]) THEN (move ["IHi"]))]) (repeat_tactic 1 9 (((USE_THM_THEN nth_derivative0)(new_rewrite [] []))) THEN (exists_tac (mk_var("sf",mk_type("fun",[mk_type("real",[]);mk_type("bool",[])])))) THEN (done_tac))))));;
409 refine (by (VALID (((((USE_THM_THEN nth_derivativeS)(new_rewrite [] [])) THEN ((USE_THM_THEN ltE)(GSYM_THEN (new_rewrite [] [])))) THEN (move ["i_lt_n"])))));;
410 refine (by (VALID (((((fun thm_tac -> (USE_THEN "IHi")(fun fst_th ->(fun thm_tac -> (USE_THM_THEN ltnW)(fun fst_th ->(USE_THEN "i_lt_n")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["t"])) THEN (case THEN (move ["open_t"])) THEN (case THEN (move ["xt"])) THEN (move ["eq"])) THEN (((USE_THEN "IHi")MP_TAC) THEN (clear_assumption "IHi") THEN BETA_TAC THEN (move ["_"]))))));;
411 refine (by (VALID ((exists_tac (`sf INTER sg INTER t`)))));;
412 refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN REAL_OPEN_INTER)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_INTER)(new_rewrite [] []))) THEN ((USE_THEN "xt")(new_rewrite [] [])) THEN ((USE_THEN "xsf")(new_rewrite [] [])) THEN ((USE_THEN "xsg")(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] [])))) THEN (move ["y"]) THEN (case THEN (move ["ysf"])) THEN (case THEN ((move ["ysg"]) THEN (move ["yt"])))))));;
413 refine (by (VALID ((((USE_THM_THEN derivative_unique)MP_TAC) THEN (clear_assumption "derivative_unique") THEN (DISCH_THEN apply_tac)))));;
414 refine (by (VALID ((((USE_THM_THEN Arc_properties.HAS_REAL_DERIVATIVE_LOCAL)MP_TAC) THEN (clear_assumption "Arc_properties.HAS_REAL_DERIVATIVE_LOCAL") THEN (DISCH_THEN apply_tac)))));;
415 refine (by (VALID ((exists_tac (`(\y. nth_derivative i f y + nth_derivative i g y)`)))));;
416 refine (by (VALID ((((USE_THM_THEN HAS_REAL_DERIVATIVE_ADD)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN andTb)(new_rewrite [] [])))))));;
417 refine (by (VALID ((((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN (((fun thm_tac -> (USE_THEN "diff_f")(fun fst_th ->(USE_THEN "ysf")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((fun thm_tac -> (USE_THEN "diff_g")(fun fst_th ->(USE_THEN "ysg")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] []))) THEN (done_tac)))));;
418 refine (by (VALID (((exists_tac (`sf INTER sg INTER t`)) THEN (repeat_tactic 1 9 (((USE_THM_THEN REAL_OPEN_INTER)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_INTER)(new_rewrite [] []))) THEN ((USE_THEN "yt")(new_rewrite [1] [])) THEN ((USE_THEN "ysf")(new_rewrite [1] [])) THEN ((USE_THEN "ysg")(new_rewrite [1] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] []))))))));;
419 refine (by (VALID (((BETA_TAC THEN (move ["z"]) THEN (move ["z_in"]) THEN (simp_tac)) THEN ((USE_THEN "eq")(new_rewrite [] [])) THEN (done_tac)))));;
420 let nth_derivative_add_strong = end_section_proof();;
421 (start_section_proof ["x"](`interval_arith x int ==>
422         ?s. real_open s /\ x IN s /\ 
423         !i y. i <= n /\ y IN s ==> 
424                 nth_derivative i (\y. f y + g y) y = nth_derivative i f y + nth_derivative i g y`));;
425 refine (by (VALID ((BETA_TAC THEN (DISCH_THEN (fun snd_th -> (USE_THM_THEN nth_derivative_add_strong)(MATCH_MP_THEN snd_th MP_TAC))) THEN (move ["h"])))));;
426 refine (by (VALID ((set_tac "P" (`\i s. real_open s /\ x IN s /\ 
427    (!y. y IN s ==> nth_derivative i (\y. f y + g y) y = nth_derivative i f y + nth_derivative i g y)`)))));;
428 refine (by (VALID ((have_tac (move ["sel_P"]) (`!i. i <= n:num ==> P i ((@) (P i))`)))));;
429 refine (by (VALID (((BETA_TAC THEN (move ["i"]) THEN (move ["i_le_n"])) THEN ((USE_THM_THEN SELECT_AX) apply_tac)))));;
430 refine (by (VALID ((((fun thm_tac -> (USE_THEN "h")(fun fst_th ->(USE_THEN "i_le_n")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["s"])) THEN (move ["cond"])))));;
431 refine (by (VALID (((exists_tac (mk_var("s",mk_type("fun",[mk_type("real",[]);mk_type("bool",[])])))) THEN (((USE_THEN "P_def")(GSYM_THEN (new_rewrite [] []))) THEN (simp_tac)) THEN (done_tac)))));;
432 refine (by (VALID ((set_tac "S" (`INTERS (IMAGE (\i. (@) (P i)) (0..n))`)))));;
433 refine (by (VALID ((exists_tac (mk_var("S",mk_type("fun",[mk_type("real",[]);mk_type("bool",[])])))))));;
434 refine (by (VALID ((((USE_THEN "S_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN REAL_OPEN_INTERS)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN FINITE_IMAGE)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN FINITE_NUMSEG)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN IN_IMAGE)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN andTb)(new_rewrite [] [])))))));;
435 refine (by (VALID (((BETA_TAC THEN (move ["t"]) THEN (case THEN (move ["i"])) THEN (case THEN (DISCH_THEN(new_rewrite [] [])))) THEN (((USE_THM_THEN IN_NUMSEG_0)(new_rewrite [] [])) THEN (DISCH_THEN (fun snd_th -> (USE_THEN "sel_P")(MATCH_MP_THEN snd_th MP_TAC))))))));;
436 refine (by (VALID (((((USE_THEN "P_def")(GSYM_THEN (new_rewrite [1] []))) THEN (simp_tac)) THEN (done_tac)))));;
437 refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN IN_INTERS)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_IMAGE)(new_rewrite [] [])))) THEN (split_tac)))));;
438 refine (by (VALID (((BETA_TAC THEN (move ["t"]) THEN (case THEN (move ["i"])) THEN (case THEN (DISCH_THEN(new_rewrite [] [])))) THEN (((USE_THM_THEN IN_NUMSEG_0)(new_rewrite [] [])) THEN (DISCH_THEN (fun snd_th -> (USE_THEN "sel_P")(MATCH_MP_THEN snd_th MP_TAC))))))));;
439 refine (by (VALID (((((USE_THEN "P_def")(GSYM_THEN (new_rewrite [1] []))) THEN (simp_tac)) THEN (done_tac)))));;
440 refine (by (VALID ((BETA_TAC THEN (move ["i"]) THEN (move ["y"]) THEN (case THEN (move ["i_le_n"]))))));;
441 refine (by (VALID (((((fun thm_tac -> (USE_THEN "sel_P")(fun fst_th ->(USE_THEN "i_le_n")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC) THEN ((((USE_THEN "P_def")(GSYM_THEN (new_rewrite [1] []))) THEN (simp_tac)) THEN ALL_TAC THEN (case THEN (move ["_"])) THEN (case THEN (move ["_"])) THEN (move ["y_in"]) THEN ((fun thm_tac -> DISCH_THEN (ISPEC_THEN (`(@) (P i)`) thm_tac))MP_TAC))))));;
442 refine (by (VALID (((THENL_FIRST) (ANTS_TAC) ((exists_tac (mk_var("i",mk_type("num",[])))) THEN ((USE_THM_THEN IN_NUMSEG_0)(new_rewrite [] [])) THEN (done_tac))))));;
443 refine (by (VALID ((((USE_THEN "y_in")MP_TAC) THEN (clear_assumption "y_in") THEN (exact_tac)))));;
444 let nth_derivative_add_strong_all = end_section_proof();;
445 (start_section_proof ["i";"x"](`interval_arith x int ==> i <= n ==>
446         nth_derivative i (\x. f x + g x) x = nth_derivative i f x + nth_derivative i g x`));;
447 refine (by (VALID ((BETA_TAC THEN (move ["ineq"]) THEN (move ["i_le_n"])))));;
448 refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN nth_derivative_add_strong)(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "i_le_n")(fun th -> MATCH_MP_THEN th thm_tac fst_th))) MP_TAC) THEN ALL_TAC))));;
449 refine (by (VALID ((BETA_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["_"])) THEN (case THEN (move ["xs"])) THEN (move ["h"])))));;
450 refine (by (VALID ((((USE_THEN "h")MP_TAC) THEN (clear_assumption "h") THEN (exact_tac)))));;
451 let nth_derivative_add = end_section_proof();;
452 (start_section_proof [](`nth_diff_strong_int n int (\x. f x + g x)`));;
453 refine (by (VALID ((((USE_THEN "dg")MP_TAC) THEN ((USE_THEN "df")MP_TAC) THEN BETA_TAC))));;
454 refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_differentiable_on)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_differentiable_eq)(new_rewrite [] [])))))));;
455 refine (by (VALID ((BETA_TAC THEN (move ["df"]) THEN (move ["dg"]) THEN (move ["x"]) THEN (move ["ineq"])))));;
456 refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN nth_derivative_add_strong_all)(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th))) MP_TAC) THEN ALL_TAC))));;
457 refine (by (VALID ((BETA_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["open_s"])) THEN (case THEN (move ["xs"])) THEN (move ["diff"])))));;
458 refine (by (VALID ((((fun thm_tac -> (USE_THEN "df")(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["tf"])) THEN (case THEN (move ["open_tf"])) THEN (case THEN (move ["xtf"])) THEN (move ["diff_f"])))));;
459 refine (by (VALID ((((fun thm_tac -> (USE_THEN "dg")(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["tg"])) THEN (case THEN (move ["open_tg"])) THEN (case THEN (move ["xtg"])) THEN (move ["diff_g"])))));;
460 refine (by (VALID (((exists_tac (`s INTER tf INTER tg`)) THEN (repeat_tactic 1 9 (((USE_THM_THEN REAL_OPEN_INTER)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_INTER)(new_rewrite [] []))) THEN ((USE_THEN "xs")(new_rewrite [1] [])) THEN ((USE_THEN "xtf")(new_rewrite [1] [])) THEN ((USE_THEN "xtg")(new_rewrite [1] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] []))))))));;
461 refine (by (VALID ((BETA_TAC THEN (move ["y"]) THEN (case THEN ((move ["ys"]) THEN (case THEN ((move ["ytf"]) THEN (move ["ytg"])))))))));;
462 refine (by (VALID (((((USE_THM_THEN REAL_CONTINUOUS_ADD)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "diff_f")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "diff_g")(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (move ["i"]) THEN (move ["i_lt_n"])))));;
463 refine (by (VALID ((((USE_THEN "diff")(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "ys")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN ltE)(GSYM_THEN (new_rewrite [] [])))) THEN ((TRY done_tac))))));;
464 refine (by (VALID ((((USE_THM_THEN Arc_properties.HAS_REAL_DERIVATIVE_LOCAL)MP_TAC) THEN (clear_assumption "Arc_properties.HAS_REAL_DERIVATIVE_LOCAL") THEN (DISCH_THEN apply_tac)))));;
465 refine (by (VALID ((exists_tac (`(\y. nth_derivative i f y + nth_derivative i g y)`)))));;
466 refine (by (VALID (((THENL_FIRST) (((USE_THM_THEN HAS_REAL_DERIVATIVE_ADD)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN andTb)(new_rewrite [] [])))) (((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN (((fun thm_tac -> (USE_THEN "diff_f")(fun fst_th ->(USE_THEN "ytf")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((fun thm_tac -> (USE_THEN "diff_g")(fun fst_th ->(USE_THEN "ytg")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] []))) THEN (done_tac))))));;
467 refine (by (VALID (((exists_tac (mk_var("s",mk_type("fun",[mk_type("real",[]);mk_type("bool",[])])))) THEN ((((USE_THEN "open_s")(new_rewrite [] [])) THEN ((USE_THEN "ys")(new_rewrite [1] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] [])))) THEN (move ["z"]) THEN (move ["zs"]) THEN (simp_tac))))));;
468 refine (by (VALID (((((USE_THEN "diff")MP_TAC) THEN (clear_assumption "diff") THEN (DISCH_THEN apply_tac)) THEN ((USE_THM_THEN ltnW)(new_rewrite [] [])) THEN (done_tac)))));;
469 let nth_diff_add = end_section_proof();;
470 (start_section_proof ["i";"x"](`interval_arith x int ==> i <= n ==>
471    ?s. real_open s /\ x IN s /\ 
472       !y. y IN s ==> nth_derivative i (\y. f y - g y) y = nth_derivative i f y - nth_derivative i g y`));;
473 refine (by (VALID (((((USE_THEN "dg")MP_TAC) THEN (clear_assumption "dg") THEN ((USE_THEN "df")MP_TAC) THEN (clear_assumption "df") THEN BETA_TAC) THEN ((repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong)(new_rewrite [] [])))) THEN (move ["df"]) THEN (move ["dg"]) THEN (move ["ineq"]))))));;
474 refine (by (VALID (((((fun thm_tac -> (USE_THEN "df")(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["sf"])) THEN (case THEN (move ["open_sf"])) THEN (case THEN (move ["xsf"]))) THEN (((USE_THEN "df")MP_TAC) THEN (clear_assumption "df") THEN BETA_TAC THEN (move ["_"]))))));;
475 refine (by (VALID (((((fun thm_tac -> (USE_THEN "dg")(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["sg"])) THEN (case THEN (move ["open_sg"])) THEN (case THEN (move ["xsg"]))) THEN (((USE_THEN "dg")MP_TAC) THEN (clear_assumption "dg") THEN BETA_TAC THEN (move ["_"]))))));;
476 refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN nth_differentiable_on)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_differentiable_eq)(new_rewrite [] [])))) THEN (move ["diff_g"]) THEN (move ["diff_f"])))));;
477 refine (by (VALID (((THENL_FIRST) ((disch_tm_tac [](mk_var("i",mk_type("num",[])))) THEN (clear_assumption "i") THEN elim THENL [(move ["_"]); ((move ["i"]) THEN (move ["IHi"]))]) (repeat_tactic 1 9 (((USE_THM_THEN nth_derivative0)(new_rewrite [] []))) THEN (exists_tac (mk_var("sf",mk_type("fun",[mk_type("real",[]);mk_type("bool",[])])))) THEN (done_tac))))));;
478 refine (by (VALID (((((USE_THM_THEN nth_derivativeS)(new_rewrite [] [])) THEN ((USE_THM_THEN ltE)(GSYM_THEN (new_rewrite [] [])))) THEN (move ["i_lt_n"])))));;
479 refine (by (VALID (((((fun thm_tac -> (USE_THEN "IHi")(fun fst_th ->(fun thm_tac -> (USE_THM_THEN ltnW)(fun fst_th ->(USE_THEN "i_lt_n")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["t"])) THEN (case THEN (move ["open_t"])) THEN (case THEN (move ["xt"])) THEN (move ["eq"])) THEN (((USE_THEN "IHi")MP_TAC) THEN (clear_assumption "IHi") THEN BETA_TAC THEN (move ["_"]))))));;
480 refine (by (VALID ((exists_tac (`sf INTER sg INTER t`)))));;
481 refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN REAL_OPEN_INTER)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_INTER)(new_rewrite [] []))) THEN ((USE_THEN "xt")(new_rewrite [] [])) THEN ((USE_THEN "xsf")(new_rewrite [] [])) THEN ((USE_THEN "xsg")(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] [])))) THEN (move ["y"]) THEN (case THEN (move ["ysf"])) THEN (case THEN ((move ["ysg"]) THEN (move ["yt"])))))));;
482 refine (by (VALID ((((USE_THM_THEN derivative_unique)MP_TAC) THEN (clear_assumption "derivative_unique") THEN (DISCH_THEN apply_tac)))));;
483 refine (by (VALID ((((USE_THM_THEN Arc_properties.HAS_REAL_DERIVATIVE_LOCAL)MP_TAC) THEN (clear_assumption "Arc_properties.HAS_REAL_DERIVATIVE_LOCAL") THEN (DISCH_THEN apply_tac)))));;
484 refine (by (VALID ((exists_tac (`(\y. nth_derivative i f y - nth_derivative i g y)`)))));;
485 refine (by (VALID ((((USE_THM_THEN HAS_REAL_DERIVATIVE_SUB)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN andTb)(new_rewrite [] [])))))));;
486 refine (by (VALID ((((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN (((fun thm_tac -> (USE_THEN "diff_f")(fun fst_th ->(USE_THEN "ysf")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((fun thm_tac -> (USE_THEN "diff_g")(fun fst_th ->(USE_THEN "ysg")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] []))) THEN (done_tac)))));;
487 refine (by (VALID (((exists_tac (`sf INTER sg INTER t`)) THEN (repeat_tactic 1 9 (((USE_THM_THEN REAL_OPEN_INTER)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_INTER)(new_rewrite [] []))) THEN ((USE_THEN "yt")(new_rewrite [1] [])) THEN ((USE_THEN "ysf")(new_rewrite [1] [])) THEN ((USE_THEN "ysg")(new_rewrite [1] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] []))))))));;
488 refine (by (VALID (((BETA_TAC THEN (move ["z"]) THEN (move ["z_in"]) THEN (simp_tac)) THEN ((USE_THEN "eq")(new_rewrite [] [])) THEN (done_tac)))));;
489 let nth_derivative_sub_strong = end_section_proof();;
490 (start_section_proof ["x"](`interval_arith x int ==>
491         ?s. real_open s /\ x IN s /\ 
492         !i y. i <= n /\ y IN s ==> 
493                 nth_derivative i (\y. f y - g y) y = nth_derivative i f y - nth_derivative i g y`));;
494 refine (by (VALID ((BETA_TAC THEN (DISCH_THEN (fun snd_th -> (USE_THM_THEN nth_derivative_sub_strong)(MATCH_MP_THEN snd_th MP_TAC))) THEN (move ["h"])))));;
495 refine (by (VALID ((set_tac "P" (`\i s. real_open s /\ x IN s /\ 
496    (!y. y IN s ==> nth_derivative i (\y. f y - g y) y = nth_derivative i f y - nth_derivative i g y)`)))));;
497 refine (by (VALID ((have_tac (move ["sel_P"]) (`!i. i <= n:num ==> P i ((@) (P i))`)))));;
498 refine (by (VALID (((BETA_TAC THEN (move ["i"]) THEN (move ["i_le_n"])) THEN ((USE_THM_THEN SELECT_AX) apply_tac)))));;
499 refine (by (VALID ((((fun thm_tac -> (USE_THEN "h")(fun fst_th ->(USE_THEN "i_le_n")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["s"])) THEN (move ["cond"])))));;
500 refine (by (VALID (((exists_tac (mk_var("s",mk_type("fun",[mk_type("real",[]);mk_type("bool",[])])))) THEN (((USE_THEN "P_def")(GSYM_THEN (new_rewrite [] []))) THEN (simp_tac)) THEN (done_tac)))));;
501 refine (by (VALID ((set_tac "S" (`INTERS (IMAGE (\i. (@) (P i)) (0..n))`)))));;
502 refine (by (VALID ((exists_tac (mk_var("S",mk_type("fun",[mk_type("real",[]);mk_type("bool",[])])))))));;
503 refine (by (VALID ((((USE_THEN "S_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN REAL_OPEN_INTERS)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN FINITE_IMAGE)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN FINITE_NUMSEG)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN IN_IMAGE)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN andTb)(new_rewrite [] [])))))));;
504 refine (by (VALID (((BETA_TAC THEN (move ["t"]) THEN (case THEN (move ["i"])) THEN (case THEN (DISCH_THEN(new_rewrite [] [])))) THEN (((USE_THM_THEN IN_NUMSEG_0)(new_rewrite [] [])) THEN (DISCH_THEN (fun snd_th -> (USE_THEN "sel_P")(MATCH_MP_THEN snd_th MP_TAC))))))));;
505 refine (by (VALID (((((USE_THEN "P_def")(GSYM_THEN (new_rewrite [1] []))) THEN (simp_tac)) THEN (done_tac)))));;
506 refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN IN_INTERS)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_IMAGE)(new_rewrite [] [])))) THEN (split_tac)))));;
507 refine (by (VALID (((BETA_TAC THEN (move ["t"]) THEN (case THEN (move ["i"])) THEN (case THEN (DISCH_THEN(new_rewrite [] [])))) THEN (((USE_THM_THEN IN_NUMSEG_0)(new_rewrite [] [])) THEN (DISCH_THEN (fun snd_th -> (USE_THEN "sel_P")(MATCH_MP_THEN snd_th MP_TAC))))))));;
508 refine (by (VALID (((((USE_THEN "P_def")(GSYM_THEN (new_rewrite [1] []))) THEN (simp_tac)) THEN (done_tac)))));;
509 refine (by (VALID ((BETA_TAC THEN (move ["i"]) THEN (move ["y"]) THEN (case THEN (move ["i_le_n"]))))));;
510 refine (by (VALID (((((fun thm_tac -> (USE_THEN "sel_P")(fun fst_th ->(USE_THEN "i_le_n")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC) THEN ((((USE_THEN "P_def")(GSYM_THEN (new_rewrite [1] []))) THEN (simp_tac)) THEN ALL_TAC THEN (case THEN (move ["_"])) THEN (case THEN (move ["_"])) THEN (move ["y_in"]) THEN ((fun thm_tac -> DISCH_THEN (ISPEC_THEN (`(@) (P i)`) thm_tac))MP_TAC))))));;
511 refine (by (VALID (((THENL_FIRST) (ANTS_TAC) ((exists_tac (mk_var("i",mk_type("num",[])))) THEN ((USE_THM_THEN IN_NUMSEG_0)(new_rewrite [] [])) THEN (done_tac))))));;
512 refine (by (VALID ((((USE_THEN "y_in")MP_TAC) THEN (clear_assumption "y_in") THEN (exact_tac)))));;
513 let nth_derivative_sub_strong_all = end_section_proof();;
514 (start_section_proof ["i";"x"](`interval_arith x int ==> i <= n ==>
515         nth_derivative i (\x. f x - g x) x = nth_derivative i f x - nth_derivative i g x`));;
516 refine (by (VALID ((BETA_TAC THEN (move ["ineq"]) THEN (move ["i_le_n"])))));;
517 refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN nth_derivative_sub_strong)(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "i_le_n")(fun th -> MATCH_MP_THEN th thm_tac fst_th))) MP_TAC) THEN ALL_TAC))));;
518 refine (by (VALID ((BETA_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["_"])) THEN (case THEN (move ["xs"])) THEN (move ["h"])))));;
519 refine (by (VALID ((((USE_THEN "h")MP_TAC) THEN (clear_assumption "h") THEN (exact_tac)))));;
520 let nth_derivative_sub = end_section_proof();;
521 (start_section_proof [](`nth_diff_strong_int n int (\x. f x - g x)`));;
522 refine (by (VALID ((((USE_THEN "dg")MP_TAC) THEN ((USE_THEN "df")MP_TAC) THEN BETA_TAC))));;
523 refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_differentiable_on)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_differentiable_eq)(new_rewrite [] [])))))));;
524 refine (by (VALID ((BETA_TAC THEN (move ["df"]) THEN (move ["dg"]) THEN (move ["x"]) THEN (move ["ineq"])))));;
525 refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN nth_derivative_sub_strong_all)(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th))) MP_TAC) THEN ALL_TAC))));;
526 refine (by (VALID ((BETA_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["open_s"])) THEN (case THEN (move ["xs"])) THEN (move ["diff"])))));;
527 refine (by (VALID ((((fun thm_tac -> (USE_THEN "df")(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["tf"])) THEN (case THEN (move ["open_tf"])) THEN (case THEN (move ["xtf"])) THEN (move ["diff_f"])))));;
528 refine (by (VALID ((((fun thm_tac -> (USE_THEN "dg")(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["tg"])) THEN (case THEN (move ["open_tg"])) THEN (case THEN (move ["xtg"])) THEN (move ["diff_g"])))));;
529 refine (by (VALID (((exists_tac (`s INTER tf INTER tg`)) THEN (repeat_tactic 1 9 (((USE_THM_THEN REAL_OPEN_INTER)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_INTER)(new_rewrite [] []))) THEN ((USE_THEN "xs")(new_rewrite [1] [])) THEN ((USE_THEN "xtf")(new_rewrite [1] [])) THEN ((USE_THEN "xtg")(new_rewrite [1] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] []))))))));;
530 refine (by (VALID ((BETA_TAC THEN (move ["y"]) THEN (case THEN ((move ["ys"]) THEN (case THEN ((move ["ytf"]) THEN (move ["ytg"])))))))));;
531 refine (by (VALID (((((USE_THM_THEN REAL_CONTINUOUS_SUB)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "diff_f")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "diff_g")(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (move ["i"]) THEN (move ["i_lt_n"])))));;
532 refine (by (VALID ((((USE_THEN "diff")(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "ys")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN ltE)(GSYM_THEN (new_rewrite [] [])))) THEN ((TRY done_tac))))));;
533 refine (by (VALID ((((USE_THM_THEN Arc_properties.HAS_REAL_DERIVATIVE_LOCAL)MP_TAC) THEN (clear_assumption "Arc_properties.HAS_REAL_DERIVATIVE_LOCAL") THEN (DISCH_THEN apply_tac)))));;
534 refine (by (VALID ((exists_tac (`(\y. nth_derivative i f y - nth_derivative i g y)`)))));;
535 refine (by (VALID (((THENL_FIRST) (((USE_THM_THEN HAS_REAL_DERIVATIVE_SUB)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN andTb)(new_rewrite [] [])))) (((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN (((fun thm_tac -> (USE_THEN "diff_f")(fun fst_th ->(USE_THEN "ytf")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((fun thm_tac -> (USE_THEN "diff_g")(fun fst_th ->(USE_THEN "ytg")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] []))) THEN (done_tac))))));;
536 refine (by (VALID (((exists_tac (mk_var("s",mk_type("fun",[mk_type("real",[]);mk_type("bool",[])])))) THEN ((((USE_THEN "open_s")(new_rewrite [] [])) THEN ((USE_THEN "ys")(new_rewrite [1] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] [])))) THEN (move ["z"]) THEN (move ["zs"]) THEN (simp_tac))))));;
537 refine (by (VALID (((((USE_THEN "diff")MP_TAC) THEN (clear_assumption "diff") THEN (DISCH_THEN apply_tac)) THEN ((USE_THM_THEN ltnW)(new_rewrite [] [])) THEN (done_tac)))));;
538 let nth_diff_sub = end_section_proof();;
539 (start_section_proof ["i";"x"](`interval_arith x int ==> i <= n ==>
540    ?s. real_open s /\ x IN s /\ 
541       !y. y IN s ==> nth_derivative i (\y. f y * g y) y = 
542         sum (0..i) (\k. &(binom (i, k)) * nth_derivative k f y * nth_derivative (i - k) g y)`));;
543 refine (by (VALID (((((USE_THEN "dg")MP_TAC) THEN (clear_assumption "dg") THEN ((USE_THEN "df")MP_TAC) THEN (clear_assumption "df") THEN BETA_TAC) THEN ((repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong)(new_rewrite [] [])))) THEN (move ["df"]) THEN (move ["dg"]) THEN (move ["ineq"]))))));;
544 refine (by (VALID (((((fun thm_tac -> (USE_THEN "df")(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["sf"])) THEN (case THEN (move ["open_sf"])) THEN (case THEN (move ["xsf"]))) THEN (((USE_THEN "df")MP_TAC) THEN (clear_assumption "df") THEN BETA_TAC THEN (move ["_"]))))));;
545 refine (by (VALID (((((fun thm_tac -> (USE_THEN "dg")(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["sg"])) THEN (case THEN (move ["open_sg"])) THEN (case THEN (move ["xsg"]))) THEN (((USE_THEN "dg")MP_TAC) THEN (clear_assumption "dg") THEN BETA_TAC THEN (move ["_"]))))));;
546 refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN nth_differentiable_on)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_differentiable_eq)(new_rewrite [] [])))) THEN (move ["diff_g"]) THEN (move ["diff_f"])))));;
547 refine (by (VALID (((disch_tm_tac [](mk_var("i",mk_type("num",[])))) THEN (clear_assumption "i") THEN elim THENL [(move ["_"]); ((move ["i"]) THEN (move ["IHi"]))]))));;
548 refine (by (VALID (((exists_tac (mk_var("sf",mk_type("fun",[mk_type("real",[]);mk_type("bool",[])])))) THEN ((((USE_THEN "open_sf")(new_rewrite [] [])) THEN ((USE_THEN "xsf")(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_derivative0)(new_rewrite [] []))) THEN ((USE_THM_THEN SUM_SING_NUMSEG)(new_rewrite [] []))) THEN (move ["y"]) THEN (move ["_"]) THEN (simp_tac))))));;
549 refine (by (VALID (((((USE_THM_THEN subn0)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_derivative0)(new_rewrite [] []))) THEN ((USE_THM_THEN binom)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_LID)(new_rewrite [] []))) THEN (done_tac)))));;
550 refine (by (VALID (((((USE_THM_THEN nth_derivativeS)(new_rewrite [] [])) THEN ((USE_THM_THEN ltE)(GSYM_THEN (new_rewrite [] [])))) THEN (move ["i_lt_n"])))));;
551 refine (by (VALID (((((fun thm_tac -> (USE_THEN "IHi")(fun fst_th ->(fun thm_tac -> (USE_THM_THEN ltnW)(fun fst_th ->(USE_THEN "i_lt_n")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["t"])) THEN (case THEN (move ["open_t"])) THEN (case THEN (move ["xt"])) THEN (move ["eq"])) THEN (((USE_THEN "IHi")MP_TAC) THEN (clear_assumption "IHi") THEN BETA_TAC THEN (move ["_"]))))));;
552 refine (by (VALID ((exists_tac (`sf INTER sg INTER t`)))));;
553 refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN REAL_OPEN_INTER)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_INTER)(new_rewrite [] []))) THEN ((USE_THEN "xt")(new_rewrite [] [])) THEN ((USE_THEN "xsf")(new_rewrite [] [])) THEN ((USE_THEN "xsg")(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] [])))) THEN (move ["y"]) THEN (case THEN (move ["ysf"])) THEN (case THEN ((move ["ysg"]) THEN (move ["yt"])))))));;
554 refine (by (VALID ((((USE_THM_THEN derivative_unique)MP_TAC) THEN (clear_assumption "derivative_unique") THEN (DISCH_THEN apply_tac)))));;
555 refine (by (VALID ((((USE_THM_THEN Arc_properties.HAS_REAL_DERIVATIVE_LOCAL)MP_TAC) THEN (clear_assumption "Arc_properties.HAS_REAL_DERIVATIVE_LOCAL") THEN (DISCH_THEN apply_tac)))));;
556 refine (by (VALID ((exists_tac (`\y. sum (0..i) (\k. &(binom (i, k)) * nth_derivative k f y * nth_derivative (i - k) g y)`)))));;
557 refine (by (VALID (((THENL_ROT (-1)) (split_tac)))));;
558 refine (by (VALID (((exists_tac (`sf INTER sg INTER t`)) THEN (repeat_tactic 1 9 (((USE_THM_THEN REAL_OPEN_INTER)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_INTER)(new_rewrite [] []))) THEN ((USE_THEN "yt")(new_rewrite [1] [])) THEN ((USE_THEN "ysf")(new_rewrite [1] [])) THEN ((USE_THEN "ysg")(new_rewrite [1] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] []))))))));;
559 refine (by (VALID (((BETA_TAC THEN (move ["z"]) THEN (move ["z_in"]) THEN (simp_tac)) THEN ((USE_THEN "eq")(new_rewrite [] [])) THEN (done_tac)))));;
560 refine (by (VALID ((((USE_THM_THEN has_derivative_lemma)MP_TAC) THEN (clear_assumption "has_derivative_lemma") THEN (DISCH_THEN apply_tac)))));;
561 refine (by (VALID ((have_tac (move ["diff_cond"]) (`!k. k IN 0..i ==>
562         nth_derivative k f real_differentiable atreal y /\
563         nth_derivative (i - k) g real_differentiable atreal y`)))));;
564 refine (by (VALID (((((USE_THM_THEN IN_NUMSEG)(new_rewrite [] [])) THEN (move ["k"]) THEN (move ["ineq"]) THEN (simp_tac)) THEN repeat_tactic 1 9 (((USE_THM_THEN real_differentiable)(new_rewrite [] []))) THEN (split_tac)))));;
565 refine (by (VALID (((exists_tac (`nth_derivative (SUC k) f y`)) THEN ((fun thm_tac -> (USE_THEN "diff_f")(fun fst_th ->(USE_THEN "ysf")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] []))))));;
566 refine (by (VALID (((((USE_THEN "i_lt_n")MP_TAC) THEN (clear_assumption "i_lt_n") THEN ((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
567 refine (by (VALID (((exists_tac (`nth_derivative (SUC (i - k)) g y`)) THEN ((fun thm_tac -> (USE_THEN "diff_g")(fun fst_th ->(USE_THEN "ysg")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] []))))));;
568 refine (by (VALID (((((USE_THEN "i_lt_n")MP_TAC) THEN (clear_assumption "i_lt_n") THEN ((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
569 refine (by (VALID ((have_tac (move ["diff_cond2"]) (`!k. k IN 0..i ==> 
570         (\y. &(binom (i, k)) * nth_derivative k f y * nth_derivative (i - k) g y)
571                 real_differentiable atreal y`)))));;
572 refine (by (VALID ((BETA_TAC THEN (move ["k"]) THEN (move ["k_in"]) THEN (simp_tac)))));;
573 refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN REAL_DIFFERENTIABLE_MUL_ATREAL)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_DIFFERENTIABLE_CONST)(new_rewrite [] [])))) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN (repeat_tactic 1 9 (((USE_THEN "diff_cond")(new_rewrite [] []))) THEN ((TRY done_tac))) THEN (done_tac)))));;
574 refine (by (VALID (((((USE_THM_THEN differentiable_sum_numseg)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN derivative_sum_numseg)(new_rewrite [] [])))) THEN ((simp_tac) THEN ((USE_THEN "diff_cond2")(fun th -> ONCE_REWRITE_TAC[th])) THEN ((TRY done_tac)))))));;
575 refine (by (VALID ((set_tac "lhs" (`sum (0..i) _`)))));;
576 refine (by (VALID ((set_tac "sum1" (`sum (0 + 1..i + 1) (\k. &(binom (i, k - 1)) * nth_derivative k f y * nth_derivative (SUC i - k) g y)`)))));;
577 refine (by (VALID ((set_tac "sum2" (`sum (0..i + 1) (\k. &(binom (i, k)) * nth_derivative k f y * nth_derivative (SUC i - k) g y)`)))));;
578 refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`lhs = sum1 + sum2`)))));;
579 refine (by (VALID ((((USE_THEN "sum1_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN SUM_OFFSET)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN addn1)(new_rewrite [] [])) THEN ((USE_THM_THEN succnK)(new_rewrite [] [])) THEN ((USE_THM_THEN subSS)(new_rewrite [] []))))));;
580 refine (by (VALID ((((USE_THEN "sum2_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN addn1)(new_rewrite [] [])) THEN ((USE_THM_THEN (GEN_ALL SUM_CLAUSES_NUMSEG))(new_rewrite [] [])) THEN ((USE_THM_THEN (ARITH_RULE `0 <= SUC i`))(new_rewrite [] [])) THEN (simp_tac)))));;
581 refine (by (VALID (((THENL_FIRST) (have_tac (DISCH_THEN(new_rewrite [] [])) (`binom(i, SUC i) = 0`)) (((USE_THM_THEN BINOM_EQ_0)(new_rewrite [] [])) THEN (arith_tac) THEN (done_tac))))));;
582 refine (by (VALID ((((USE_THM_THEN REAL_MUL_LZERO)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_ADD_RID)(new_rewrite [] [])) THEN ((USE_THM_THEN SUM_ADD_NUMSEG)(GSYM_THEN (new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THEN "lhs_def")(GSYM_THEN (new_rewrite [] [])))))));;
583 refine (by (VALID ((((USE_THM_THEN SUM_EQ) apply_tac) THEN (move ["k"]) THEN (move ["k_in"]) THEN (simp_tac)))));;
584 refine (by (VALID (((((USE_THM_THEN derivative_scale)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_DIFFERENTIABLE_MUL_ATREAL)(new_rewrite [] [])))) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN (repeat_tactic 0 10 (((USE_THEN "diff_cond")(new_rewrite [] []))) THEN ((TRY done_tac)))))));;
585 refine (by (VALID (((((USE_THM_THEN REAL_ADD_LDISTRIB)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN REAL_EQ_MUL_LCANCEL)(new_rewrite [] []))) THEN (DISJ2_TAC)))));;
586 refine (by (VALID ((((USE_THM_THEN derivative_mul)(new_rewrite [] [])) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN (repeat_tactic 0 10 (((USE_THEN "diff_cond")(new_rewrite [] []))) THEN ((TRY done_tac)))))));;
587 refine (by (VALID ((((USE_THM_THEN REAL_ADD_SYM)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_derivativeS)(GSYM_THEN (new_rewrite [] []))))))));;
588 refine (by (VALID (((THENL_FIRST) (((THENL_ROT 1)) (have_tac (DISCH_THEN(new_rewrite [] [])) (`SUC (i - k) = SUC i - k`))) ((done_tac) THEN (done_tac))))));;
589 refine (by (VALID (((((USE_THEN "k_in")MP_TAC) THEN (clear_assumption "k_in") THEN BETA_TAC) THEN ((USE_THM_THEN IN_NUMSEG)(new_rewrite [] [])) THEN (arith_tac) THEN (done_tac)))));;
590 refine (by (VALID (((((USE_THM_THEN REAL_ADD_SYM)(new_rewrite [] [])) THEN ((USE_THM_THEN SUM_CLAUSES_LEFT)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "sum2_def")(GSYM_THEN (new_rewrite [] [])))) THEN repeat_tactic 0 1 (((USE_THM_THEN SUM_CLAUSES_LEFT)(new_rewrite [] []))) THEN (simp_tac)) THEN ((TRY) (arith_tac))))));;
591 refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN binom)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_MUL_LID)(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_ADD_ASSOC)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN REAL_EQ_ADD_LCANCEL)(new_rewrite [] []))))));;
592 refine (by (VALID ((((USE_THEN "sum1_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN SUM_ADD_NUMSEG)(GSYM_THEN (new_rewrite [] []))) THEN ((fun thm_tac -> (USE_THM_THEN addn1)(ISPEC_THEN (mk_var("i",mk_type("num",[]))) thm_tac))(new_rewrite [] []))))));;
593 refine (by (VALID ((((USE_THM_THEN SUM_EQ) apply_tac) THEN (move ["k"]) THEN (move ["k_in"]) THEN (simp_tac)))));;
594 refine (by (VALID (((((USE_THM_THEN REAL_ADD_RDISTRIB)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN REAL_EQ_MUL_RCANCEL)(new_rewrite [] []))) THEN (DISJ1_TAC)))));;
595 refine (by (VALID (((THENL_FIRST) ((((USE_THEN "k_in")MP_TAC) THEN (clear_assumption "k_in") THEN (disch_tm_tac [](mk_var("k",mk_type("num",[])))) THEN (clear_assumption "k") THEN case THENL [ALL_TAC; (move ["k"])]) THEN ((USE_THM_THEN IN_NUMSEG)(new_rewrite [] []))) ((arith_tac) THEN (done_tac))))));;
596 refine (by (VALID (((((USE_THM_THEN binom)(new_rewrite [] [])) THEN ((USE_THM_THEN ONE)(new_rewrite [] [])) THEN ((USE_THM_THEN subSS)(new_rewrite [] [])) THEN ((USE_THM_THEN subn0)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_OF_NUM_ADD)(new_rewrite [] []))) THEN (done_tac)))));;
597 let nth_derivative_mul_strong = end_section_proof();;
598 (start_section_proof ["x"](`interval_arith x int ==>
599         ?s. real_open s /\ x IN s /\ 
600         !i y. i <= n /\ y IN s ==> 
601           nth_derivative i (\y. f y * g y) y = 
602                 sum (0..i) (\k. &(binom (i, k)) * nth_derivative k f y * nth_derivative (i - k) g y)`));;
603 refine (by (VALID ((BETA_TAC THEN (DISCH_THEN (fun snd_th -> (USE_THM_THEN nth_derivative_mul_strong)(MATCH_MP_THEN snd_th MP_TAC))) THEN (move ["h"])))));;
604 refine (by (VALID ((set_tac "P" (`\i s. real_open s /\ x IN s /\ 
605    (!y. y IN s ==> nth_derivative i (\y. f y * g y) y = 
606         sum (0..i) (\k. &(binom (i, k)) * nth_derivative k f y * nth_derivative (i - k) g y))`)))));;
607 refine (by (VALID ((have_tac (move ["sel_P"]) (`!i. i <= n:num ==> P i ((@) (P i))`)))));;
608 refine (by (VALID (((BETA_TAC THEN (move ["i"]) THEN (move ["i_le_n"])) THEN ((USE_THM_THEN SELECT_AX) apply_tac)))));;
609 refine (by (VALID ((((fun thm_tac -> (USE_THEN "h")(fun fst_th ->(USE_THEN "i_le_n")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["s"])) THEN (move ["cond"])))));;
610 refine (by (VALID (((exists_tac (mk_var("s",mk_type("fun",[mk_type("real",[]);mk_type("bool",[])])))) THEN (((USE_THEN "P_def")(GSYM_THEN (new_rewrite [] []))) THEN (simp_tac)) THEN (done_tac)))));;
611 refine (by (VALID ((set_tac "S" (`INTERS (IMAGE (\i. (@) (P i)) (0..n))`)))));;
612 refine (by (VALID ((exists_tac (mk_var("S",mk_type("fun",[mk_type("real",[]);mk_type("bool",[])])))))));;
613 refine (by (VALID ((((USE_THEN "S_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN REAL_OPEN_INTERS)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN FINITE_IMAGE)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN FINITE_NUMSEG)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN IN_IMAGE)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN andTb)(new_rewrite [] [])))))));;
614 refine (by (VALID (((BETA_TAC THEN (move ["t"]) THEN (case THEN (move ["i"])) THEN (case THEN (DISCH_THEN(new_rewrite [] [])))) THEN (((USE_THM_THEN IN_NUMSEG_0)(new_rewrite [] [])) THEN (DISCH_THEN (fun snd_th -> (USE_THEN "sel_P")(MATCH_MP_THEN snd_th MP_TAC))))))));;
615 refine (by (VALID (((((USE_THEN "P_def")(GSYM_THEN (new_rewrite [1] []))) THEN (simp_tac)) THEN (done_tac)))));;
616 refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN IN_INTERS)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_IMAGE)(new_rewrite [] [])))) THEN (split_tac)))));;
617 refine (by (VALID (((BETA_TAC THEN (move ["t"]) THEN (case THEN (move ["i"])) THEN (case THEN (DISCH_THEN(new_rewrite [] [])))) THEN (((USE_THM_THEN IN_NUMSEG_0)(new_rewrite [] [])) THEN (DISCH_THEN (fun snd_th -> (USE_THEN "sel_P")(MATCH_MP_THEN snd_th MP_TAC))))))));;
618 refine (by (VALID (((((USE_THEN "P_def")(GSYM_THEN (new_rewrite [1] []))) THEN (simp_tac)) THEN (done_tac)))));;
619 refine (by (VALID ((BETA_TAC THEN (move ["i"]) THEN (move ["y"]) THEN (case THEN (move ["i_le_n"]))))));;
620 refine (by (VALID (((((fun thm_tac -> (USE_THEN "sel_P")(fun fst_th ->(USE_THEN "i_le_n")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC) THEN ((((USE_THEN "P_def")(GSYM_THEN (new_rewrite [1] []))) THEN (simp_tac)) THEN ALL_TAC THEN (case THEN (move ["_"])) THEN (case THEN (move ["_"])) THEN (move ["y_in"]) THEN ((fun thm_tac -> DISCH_THEN (ISPEC_THEN (`(@) (P i)`) thm_tac))MP_TAC))))));;
621 refine (by (VALID (((THENL_FIRST) (ANTS_TAC) ((exists_tac (mk_var("i",mk_type("num",[])))) THEN ((USE_THM_THEN IN_NUMSEG_0)(new_rewrite [] [])) THEN (done_tac))))));;
622 refine (by (VALID ((((USE_THEN "y_in")MP_TAC) THEN (clear_assumption "y_in") THEN (exact_tac)))));;
623 let nth_derivative_mul_strong_all = end_section_proof();;
624 (start_section_proof ["i";"x"](`interval_arith x int ==> i <= n ==>
625         nth_derivative i (\x. f x * g x) x = 
626           sum (0..i) (\k. &(binom (i, k)) * nth_derivative k f x * nth_derivative (i - k) g x)`));;
627 refine (by (VALID ((BETA_TAC THEN (move ["ineq"]) THEN (move ["i_le_n"])))));;
628 refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN nth_derivative_mul_strong)(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "i_le_n")(fun th -> MATCH_MP_THEN th thm_tac fst_th))) MP_TAC) THEN ALL_TAC))));;
629 refine (by (VALID ((BETA_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["_"])) THEN (case THEN (move ["xs"])) THEN (move ["h"])))));;
630 refine (by (VALID ((((USE_THEN "h")MP_TAC) THEN (clear_assumption "h") THEN (exact_tac)))));;
631 let nth_derivative_mul = end_section_proof();;
632 (start_section_proof [](`nth_diff_strong_int n int (\x. f x * g x)`));;
633 refine (by (VALID ((((USE_THEN "dg")MP_TAC) THEN ((USE_THEN "df")MP_TAC) THEN BETA_TAC))));;
634 refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_differentiable_on)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_differentiable_eq)(new_rewrite [] [])))))));;
635 refine (by (VALID ((BETA_TAC THEN (move ["df"]) THEN (move ["dg"]) THEN (move ["x"]) THEN (move ["ineq"])))));;
636 refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN nth_derivative_mul_strong_all)(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th))) MP_TAC) THEN ALL_TAC))));;
637 refine (by (VALID ((BETA_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["open_s"])) THEN (case THEN (move ["xs"])) THEN (move ["diff"])))));;
638 refine (by (VALID ((((fun thm_tac -> (USE_THEN "df")(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["tf"])) THEN (case THEN (move ["open_tf"])) THEN (case THEN (move ["xtf"])) THEN (move ["diff_f"])))));;
639 refine (by (VALID ((((fun thm_tac -> (USE_THEN "dg")(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["tg"])) THEN (case THEN (move ["open_tg"])) THEN (case THEN (move ["xtg"])) THEN (move ["diff_g"])))));;
640 refine (by (VALID (((exists_tac (`s INTER tf INTER tg`)) THEN (repeat_tactic 1 9 (((USE_THM_THEN REAL_OPEN_INTER)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_INTER)(new_rewrite [] []))) THEN ((USE_THEN "xs")(new_rewrite [1] [])) THEN ((USE_THEN "xtf")(new_rewrite [1] [])) THEN ((USE_THEN "xtg")(new_rewrite [1] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] []))))))));;
641 refine (by (VALID ((BETA_TAC THEN (move ["y"]) THEN (case THEN ((move ["ys"]) THEN (case THEN ((move ["ytf"]) THEN (move ["ytg"])))))))));;
642 refine (by (VALID (((((USE_THM_THEN REAL_CONTINUOUS_MUL)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "diff_f")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "diff_g")(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (move ["i"]) THEN (move ["i_lt_n"])))));;
643 refine (by (VALID ((((USE_THM_THEN nth_derivativeS)(new_rewrite [] [])) THEN ((USE_THM_THEN has_derivative_alt)(new_rewrite [] []))))));;
644 refine (by (VALID ((((USE_THM_THEN differentiable_local)MP_TAC) THEN (clear_assumption "differentiable_local") THEN (DISCH_THEN apply_tac)))));;
645 refine (by (VALID (((exists_tac (`\y. sum (0..i) (\k. &(binom(i, k)) * nth_derivative k f y * nth_derivative (i - k) g y)`)) THEN (exists_tac (mk_var("s",mk_type("fun",[mk_type("real",[]);mk_type("bool",[])]))))))));;
646 refine (by (VALID (((THENL_LAST) ((((USE_THEN "open_s")(new_rewrite [] [])) THEN ((USE_THEN "ys")(new_rewrite [1] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] [])))) THEN (split_tac)) ((BETA_TAC THEN (move ["z"]) THEN (move ["zs"])) THEN (((USE_THEN "diff")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN ltnW)(new_rewrite [] []))) THEN (done_tac))))));;
647 refine (by (VALID (((((USE_THM_THEN differentiable_sum_numseg)(new_rewrite [] [])) THEN ((USE_THM_THEN IN_NUMSEG)(new_rewrite [] []))) THEN (move ["k"]) THEN (move ["k_in"]) THEN (simp_tac)))));;
648 refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN REAL_DIFFERENTIABLE_MUL_ATREAL)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_DIFFERENTIABLE_CONST)(new_rewrite [] []))) THEN ((TRY done_tac))) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th]))))));;
649 refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN real_differentiable)(new_rewrite [] []))) THEN (split_tac)))));;
650 refine (by (VALID (((exists_tac (`nth_derivative (SUC k) f y`)) THEN ((fun thm_tac -> (USE_THEN "diff_f")(fun fst_th ->(USE_THEN "ytf")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] []))))));;
651 refine (by (VALID (((((USE_THEN "i_lt_n")MP_TAC) THEN (clear_assumption "i_lt_n") THEN ((USE_THEN "k_in")MP_TAC) THEN (clear_assumption "k_in") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
652 refine (by (VALID (((exists_tac (`nth_derivative (SUC (i - k)) g y`)) THEN ((fun thm_tac -> (USE_THEN "diff_g")(fun fst_th ->(USE_THEN "ytg")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] []))))));;
653 refine (by (VALID (((((USE_THEN "i_lt_n")MP_TAC) THEN (clear_assumption "i_lt_n") THEN ((USE_THEN "k_in")MP_TAC) THEN (clear_assumption "k_in") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
654 let nth_diff_mul = end_section_proof();;
655 let nth_diff_mul = finalize_theorem nth_diff_mul;;
656 let nth_derivative_mul = finalize_theorem nth_derivative_mul;;
657 let nth_derivative_mul_strong_all = finalize_theorem nth_derivative_mul_strong_all;;
658 let nth_derivative_mul_strong = finalize_theorem nth_derivative_mul_strong;;
659 let nth_diff_sub = finalize_theorem nth_diff_sub;;
660 let nth_derivative_sub = finalize_theorem nth_derivative_sub;;
661 let nth_derivative_sub_strong_all = finalize_theorem nth_derivative_sub_strong_all;;
662 let nth_derivative_sub_strong = finalize_theorem nth_derivative_sub_strong;;
663 let nth_diff_add = finalize_theorem nth_diff_add;;
664 let nth_derivative_add = finalize_theorem nth_derivative_add;;
665 let nth_derivative_add_strong_all = finalize_theorem nth_derivative_add_strong_all;;
666 let nth_derivative_add_strong = finalize_theorem nth_derivative_add_strong;;
667 let nth_diff_scale = finalize_theorem nth_diff_scale;;
668 let nth_derivative_scale = finalize_theorem nth_derivative_scale;;
669 let nth_derivative_scale_strong_all = finalize_theorem nth_derivative_scale_strong_all;;
670 let nth_derivative_scale_strong = finalize_theorem nth_derivative_scale_strong;;
671 (end_section "NthDerivativeArith");;
672 let nth_diff_mul = finalize_theorem nth_diff_mul;;
673 let nth_derivative_mul = finalize_theorem nth_derivative_mul;;
674 let nth_derivative_mul_strong_all = finalize_theorem nth_derivative_mul_strong_all;;
675 let nth_derivative_mul_strong = finalize_theorem nth_derivative_mul_strong;;
676 let nth_diff_sub = finalize_theorem nth_diff_sub;;
677 let nth_derivative_sub = finalize_theorem nth_derivative_sub;;
678 let nth_derivative_sub_strong_all = finalize_theorem nth_derivative_sub_strong_all;;
679 let nth_derivative_sub_strong = finalize_theorem nth_derivative_sub_strong;;
680 let nth_diff_add = finalize_theorem nth_diff_add;;
681 let nth_derivative_add = finalize_theorem nth_derivative_add;;
682 let nth_derivative_add_strong_all = finalize_theorem nth_derivative_add_strong_all;;
683 let nth_derivative_add_strong = finalize_theorem nth_derivative_add_strong;;
684 let nth_diff_scale = finalize_theorem nth_diff_scale;;
685 let nth_derivative_scale = finalize_theorem nth_derivative_scale;;
686 let nth_derivative_scale_strong_all = finalize_theorem nth_derivative_scale_strong_all;;
687 let nth_derivative_scale_strong = finalize_theorem nth_derivative_scale_strong;;
688 let differentiable_local = finalize_theorem differentiable_local;;
689 let derivative_sum_numseg = finalize_theorem derivative_sum_numseg;;
690 let differentiable_sum_numseg = finalize_theorem differentiable_sum_numseg;;
691 let derivative_div = finalize_theorem derivative_div;;
692 let derivative_sub = finalize_theorem derivative_sub;;
693 let derivative_mul = finalize_theorem derivative_mul;;
694 let derivative_add = finalize_theorem derivative_add;;
695 let derivative_pow = finalize_theorem derivative_pow;;
696 let derivative_neg = finalize_theorem derivative_neg;;
697 let derivative_scale = finalize_theorem derivative_scale;;
698 let derivative_compose_acs = finalize_theorem derivative_compose_acs;;
699 let derivative_compose_sqrt = finalize_theorem derivative_compose_sqrt;;
700 let derivative_compose_inv = finalize_theorem derivative_compose_inv;;
701 let derivative_compose_exp = finalize_theorem derivative_compose_exp;;
702 let derivative_compose_atn = finalize_theorem derivative_compose_atn;;
703 let REAL_DIFFERENTIABLE_AT_INV = finalize_theorem REAL_DIFFERENTIABLE_AT_INV;;
704 let derivative_composition = finalize_theorem derivative_composition;;
705 let derivative_sqrt = finalize_theorem derivative_sqrt;;
706 let derivative_acs = finalize_theorem derivative_acs;;
707 let derivative_exp = finalize_theorem derivative_exp;;
708 let derivative_atn = finalize_theorem derivative_atn;;
709 let derivative_inv = finalize_theorem derivative_inv;;
710 let derivative_const = finalize_theorem derivative_const;;
711 let derivative_x = finalize_theorem derivative_x;;
712 let nth_diff_strong_imp_diff = finalize_theorem nth_diff_strong_imp_diff;;
713 let ith_derivative_differentiable = finalize_theorem ith_derivative_differentiable;;
714 let nth_derivative_continuous = finalize_theorem nth_derivative_continuous;;
715 let nth_diff_imp_diff = finalize_theorem nth_diff_imp_diff;;
716 let nth_differentiable1 = finalize_theorem nth_differentiable1;;
717 let nth_mth_diff = finalize_theorem nth_mth_diff;;
718 let nth_differentiable_on_int2 = finalize_theorem nth_differentiable_on_int2;;
719 let nth_differentiable_eq = finalize_theorem nth_differentiable_eq;;
720 let nth_differentiable_on_cond = finalize_theorem nth_differentiable_on_cond;;
721 let nth_differentiable_cond = finalize_theorem nth_differentiable_cond;;
722 let nth_diff_continuous = finalize_theorem nth_diff_continuous;;
723 let nth_derivative_add = finalize_theorem nth_derivative_add;;
724 let nth_derivative2 = finalize_theorem nth_derivative2;;
725 let nth_derivative1 = finalize_theorem nth_derivative1;;
726 let nth_Sderivative = finalize_theorem nth_Sderivative;;
727 let nth_derivativeS = finalize_theorem nth_derivativeS;;
728 let nth_derivative0 = finalize_theorem nth_derivative0;;
729 let has_derivative_lemma = finalize_theorem has_derivative_lemma;;
730 let derivative_unique_on = finalize_theorem derivative_unique_on;;
731 let derivative_unique = finalize_theorem derivative_unique;;
732 let has_derivative_alt = finalize_theorem has_derivative_alt;;
733 let has_derivative_cond = finalize_theorem has_derivative_cond;;
734 (end_section "NthDerivatives");;
735 let lin_approx = new_definition `lin_approx f x f_bounds df_bounds <=> 
736         interval_arith (f x) f_bounds /\
737         (?f'. (f has_real_derivative f') (atreal x) /\ interval_arith f' df_bounds)`;;
738 let has_bounded_second_derivative = new_definition `has_bounded_second_derivative f int dd_bounds <=>
739         nth_diff_strong_int 2 int f /\ 
740         bounded_on_int (nth_derivative 2 f) int dd_bounds`;;
741 let taylor_interval = new_definition 
742   `taylor_interval f x y z w f_bounds df_bounds ddf_bounds <=>
743         x <= y /\ y <= z /\ y - x <= w /\ z - y <= w /\
744         lin_approx f y f_bounds df_bounds /\
745         has_bounded_second_derivative f (x, z) ddf_bounds`;;
746 let iabs = new_definition `iabs (x_lo, x_hi) = max x_hi (-- x_lo)`;;
747 (start_section_proof ["n";"int";"f"](`nth_diff_strong_int n int f ==>
748         nth_differentiable_on_int n int f`));;
749 refine (by (VALID ((((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] [])) THEN ((USE_THM_THEN nth_differentiable_on_int)(new_rewrite [] [])) THEN ((USE_THM_THEN nth_diff_strong)(new_rewrite [] [])) THEN ((USE_THM_THEN nth_differentiable_on)(new_rewrite [] []))))));;
750 refine (by (VALID ((BETA_TAC THEN (move ["h"]) THEN (move ["x"]) THEN (move ["ineq"])))));;
751 refine (by (VALID (((((fun thm_tac -> (USE_THEN "h")(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["_"])) THEN (case THEN (move ["xs"]))) THEN (exact_tac) THEN (done_tac)))));;
752 let nth_diff_strong_imp_diff_int = end_section_proof();;
753 (start_section_proof ["f";"int";"dd_bounds"](`has_bounded_second_derivative f int dd_bounds ==>
754         ?f' f''. (!x. interval_arith x int ==> (f has_real_derivative f' x) (atreal x) /\
755                 (f' has_real_derivative f'' x) (atreal x) /\    interval_arith (f'' x) dd_bounds)`));;
756 refine (by (VALID ((((USE_THM_THEN has_bounded_second_derivative)(new_rewrite [] [])) THEN ALL_TAC THEN (case THEN (DISCH_THEN (fun snd_th -> (USE_THM_THEN nth_diff_strong_imp_diff_int)(MATCH_MP_THEN snd_th MP_TAC))))))));;
757 refine (by (VALID (((DISCH_THEN (fun snd_th -> (USE_THM_THEN nth_differentiable_on_int2)(MATCH_MP_THEN snd_th MP_TAC))) THEN BETA_TAC THEN (case THEN (move ["f'"])) THEN (case THEN (move ["f''"]))))));;
758 refine (by (VALID (((BETA_TAC THEN (case THEN (move ["eq1"])) THEN (case THEN (move ["eq2"])) THEN (move ["h"]) THEN (move ["b"])) THEN (((exists_tac (mk_var("f'",mk_type("fun",[mk_type("real",[]);mk_type("real",[])])))) THEN (exists_tac (mk_var("f''",mk_type("fun",[mk_type("real",[]);mk_type("real",[])]))))) THEN (move ["x"]) THEN (move ["ineq"]))))));;
759 refine (by (VALID (((((USE_THEN "b")MP_TAC) THEN (clear_assumption "b") THEN BETA_TAC) THEN ((((USE_THM_THEN bounded_on_int)(new_rewrite [] [])) THEN ((USE_THEN "eq2")(GSYM_THEN (new_rewrite [] [])))) THEN (move ["b"]))))));;
760 refine (by (VALID (((repeat_tactic 1 9 (((USE_THEN "h")(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THEN "b")(new_rewrite [] []))) THEN (done_tac)))));;
761 let has_bounded_second_derivative_old = end_section_proof();;
762 (start_section_proof ["P";"Q"](`(?x. P x /\ Q x) ==> (?x. P x)`));;
763 refine (by (VALID ((BETA_TAC THEN (case THEN (move ["x"])) THEN (case THEN ((move ["Px"]) THEN (move ["_"])))))));;
764 refine (by (VALID (((exists_tac (mk_var("x",mk_vartype "?1452066"))) THEN (done_tac)))));;
765 let exists_and_left = end_section_proof();;
766 (start_section_proof ["a";"b"](`(!e. &0 < e ==> a <= b + e) <=> (a <= b)`));;
767 refine (by (VALID (((THENL_ROT (-1)) ((split_tac) THENL [ALL_TAC; ((move ["ineq"]) THEN (move ["e"]) THEN (move ["e0"]))])))));;
768 refine (by (VALID (((((fun thm_tac -> (USE_THM_THEN REAL_ADD_RID)(ISPEC_THEN (mk_var("a",mk_type("real",[]))) thm_tac))(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN REAL_LE_ADD2)(new_rewrite [] [])) THEN ((USE_THEN "ineq")(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LT_IMP_LE)(new_rewrite [] []))) THEN (done_tac)))));;
769 refine (by (VALID (((((USE_THM_THEN contraLR)MP_TAC) THEN (clear_assumption "contraLR") THEN (DISCH_THEN apply_tac)) THEN ((((USE_THM_THEN NOT_FORALL_THM)(new_rewrite [] [])) THEN ((USE_THM_THEN NOT_IMP)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_NOT_LE)(new_rewrite [] [])))) THEN (move ["ba"]))))));;
770 refine (by (VALID (((exists_tac (`(a - b) / &2`)) THEN (((USE_THEN "ba")MP_TAC) THEN (clear_assumption "ba") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
771 let lim_ineq = end_section_proof();;
772 (start_section_proof ["f";"c";"a"](`(?b. a < b /\ !x. x IN real_interval (a, b) ==> f x <= c) /\
773         f real_continuous atreal a ==> f a <= c`));;
774 refine (by (VALID ((BETA_TAC THEN (case THEN ((case THEN (move ["b"])) THEN (case THEN (move ["ab"])) THEN (move ["ineq"])))))));;
775 refine (by (VALID (((((USE_THM_THEN REAL_CONTINUOUS_ATREAL)(new_rewrite [] [])) THEN ((USE_THM_THEN REALLIM_ATREAL)(new_rewrite [] []))) THEN (move ["f_cont"])))));;
776 refine (by (VALID ((((USE_THM_THEN lim_ineq)(GSYM_THEN (new_rewrite [] []))) THEN (move ["e"]) THEN (DISCH_THEN (fun snd_th -> (USE_THEN "f_cont")(MATCH_MP_THEN snd_th MP_TAC))) THEN (case THEN (move ["d"])) THEN (case THEN (move ["d0"])) THEN (move ["cond"])))));;
777 refine (by (VALID ((set_tac "r" (`a + min (b - a) d / &2`)))));;
778 refine (by (VALID (((THENL_FIRST) ((((fun thm_tac -> (USE_THEN "cond")(ISPEC_THEN (mk_var("r",mk_type("real",[]))) thm_tac))MP_TAC) THEN BETA_TAC) THEN (ANTS_TAC)) ((((USE_THEN "ab")MP_TAC) THEN (clear_assumption "ab") THEN ((USE_THEN "d0")MP_TAC) THEN (clear_assumption "d0") THEN ((USE_THEN "r_def")MP_TAC) THEN (clear_assumption "r_def") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac))))));;
779 refine (by (VALID (((THENL_LAST) ((((fun thm_tac -> (USE_THEN "ineq")(ISPEC_THEN (mk_var("r",mk_type("real",[]))) thm_tac))MP_TAC) THEN BETA_TAC) THEN (ANTS_TAC)) ((arith_tac) THEN (done_tac))))));;
780 refine (by (VALID ((((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] [])) THEN (((USE_THEN "ab")MP_TAC) THEN (clear_assumption "ab") THEN ((USE_THEN "d0")MP_TAC) THEN (clear_assumption "d0") THEN ((USE_THEN "r_def")MP_TAC) THEN (clear_assumption "r_def") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
781 let continuous_leq = end_section_proof();;
782 (start_section_proof ["f";"x"](`f real_continuous atreal x <=>
783         (\x. f (--x)) real_continuous atreal (--x)`));;
784 refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN REAL_CONTINUOUS_ATREAL)(new_rewrite [] []))) THEN (simp_tac) THEN repeat_tactic 1 9 (((USE_THM_THEN REALLIM_ATREAL)(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_NEG_NEG)(new_rewrite [] [])) THEN (simp_tac)) THEN ((split_tac) THEN (move ["h"]) THEN (move ["e"]) THEN (move ["e0"]))))));;
785 refine (by (VALID ((((fun thm_tac -> (USE_THEN "h")(fun fst_th ->(USE_THEN "e0")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["d"])) THEN (case THEN (move ["d0"])) THEN (move ["cond"])))));;
786 refine (by (VALID (((exists_tac (mk_var("d",mk_type("real",[])))) THEN ((((USE_THEN "d0")(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (move ["y"]) THEN (move ["ineqs"])) THEN (((USE_THEN "cond")MP_TAC) THEN (clear_assumption "cond") THEN (DISCH_THEN apply_tac))))));;
787 refine (by (VALID (((((USE_THEN "ineqs")MP_TAC) THEN (clear_assumption "ineqs") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
788 refine (by (VALID ((((fun thm_tac -> (USE_THEN "h")(fun fst_th ->(USE_THEN "e0")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["d"])) THEN (case THEN (move ["d0"])) THEN (move ["cond"])))));;
789 refine (by (VALID (((exists_tac (mk_var("d",mk_type("real",[])))) THEN ((((USE_THEN "d0")(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (move ["y"]) THEN (move ["ineqs"]))))));;
790 refine (by (VALID (((((fun thm_tac -> (USE_THEN "cond")(ISPEC_THEN (`--y`) thm_tac))MP_TAC) THEN BETA_TAC) THEN ((USE_THM_THEN REAL_NEG_NEG)(new_rewrite [] [])) THEN (DISCH_THEN apply_tac) THEN (((USE_THEN "ineqs")MP_TAC) THEN (clear_assumption "ineqs") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
791 let continuous_reflection = end_section_proof();;
792 (start_section_proof ["f";"c";"a";"b"](`a < b ==> f real_continuous atreal a ==> f real_continuous atreal b ==>
793         (!x. x IN real_interval (a, b) ==> f x <= c) ==>
794         (!x. x IN real_interval [a, b] ==> f x <= c)`));;
795 refine (by (VALID ((BETA_TAC THEN (move ["ab"]) THEN (move ["f_cont_a"]) THEN (move ["f_cont_b"]) THEN (move ["ineq"]) THEN (move ["x"])))));;
796 refine (by (VALID ((((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] [])) THEN repeat_tactic 2 0 (((USE_THM_THEN (REAL_ARITH `!a b. a <= b <=> (a = b \/ a < b)`))(new_rewrite [] [])))))));;
797 refine (by (VALID ((case THEN (case THENL [((DISCH_THEN(GSYM_THEN (new_rewrite [] []))) THEN (move ["_"])); (move ["ax"])])))));;
798 refine (by (VALID (((((USE_THM_THEN continuous_leq)MP_TAC) THEN (clear_assumption "continuous_leq") THEN (DISCH_THEN apply_tac)) THEN (((USE_THEN "f_cont_a")(new_rewrite [] [])) THEN ((USE_THM_THEN andbT)(new_rewrite [] []))) THEN (exists_tac (mk_var("b",mk_type("real",[])))) THEN (done_tac)))));;
799 refine (by (VALID (((THENL_LAST) (case THENL [(DISCH_THEN(new_rewrite [] [])); (move ["xb"])]) ((((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN (DISCH_THEN apply_tac)) THEN ((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] [])) THEN (done_tac))))));;
800 refine (by (VALID ((set_tac "g" (`\x. f (--x)`)))));;
801 refine (by (VALID (((THENL_FIRST) (have_tac (move ["fg"]) (`!x. f x = g (--x)`)) ((((USE_THEN "g_def")(GSYM_THEN (new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN REAL_NEG_NEG)(new_rewrite [] []))) THEN (done_tac))))));;
802 refine (by (VALID ((((USE_THEN "fg")(new_rewrite [] [])) THEN (((USE_THM_THEN continuous_leq)MP_TAC) THEN (clear_assumption "continuous_leq") THEN (DISCH_THEN apply_tac)) THEN (split_tac)))));;
803 refine (by (VALID (((exists_tac (`--a`)) THEN ((((USE_THM_THEN REAL_LT_NEG)(new_rewrite [] [])) THEN ((USE_THEN "ab")(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] [])) THEN ((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] []))) THEN (move ["y"]))))));;
804 refine (by (VALID (((((fun thm_tac -> (USE_THEN "ineq")(ISPEC_THEN (`--y`) thm_tac))MP_TAC) THEN BETA_TAC) THEN (((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] [])) THEN ((USE_THEN "fg")(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_NEG_NEG)(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac)))));;
805 refine (by (VALID (((((USE_THEN "g_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN continuous_reflection)(GSYM_THEN (new_rewrite [] [])))) THEN (done_tac)))));;
806 let continuous_leq_segment = end_section_proof();;
807 (start_section_proof ["p"](`p = (FST p, SND p)`));;
808 refine (by (VALID ((done_tac))));;
809 let pair_eq = end_section_proof();;
810 (begin_section "Taylor");;
811 (start_section_proof ["lo";"hi";"a"](`interval_arith a (lo, hi) ==> iabs (lo, hi) = max (abs lo) (abs hi)`));;
812 refine (by (VALID (((((USE_THM_THEN interval_arith)(new_rewrite [] [])) THEN ((USE_THM_THEN iabs)(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac)))));;
813 let iabs_alt = end_section_proof();;
814 (start_section_proof ["lo";"hi";"a"](`interval_arith a (lo, hi) ==> &0 <= iabs (lo, hi)`));;
815 refine (by (VALID (((((USE_THM_THEN interval_arith)(new_rewrite [] [])) THEN ((USE_THM_THEN iabs)(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac)))));;
816 let iabs_pos = end_section_proof();;
817 (add_section_var (mk_var ("f", (`:real -> real`))));;
818 (add_section_var (mk_var ("x", (`:real`))); add_section_var (mk_var ("y", (`:real`))); add_section_var (mk_var ("z", (`:real`))); add_section_var (mk_var ("w", (`:real`))));;
819 (add_section_var (mk_var ("f_bounds", (`:real#real`))); add_section_var (mk_var ("df_bounds", (`:real#real`))); add_section_var (mk_var ("ddf_bounds", (`:real#real`))));;
820 (add_section_var (mk_var ("dd_bound", (`:real`))));;
821 (add_section_hyp "dd_bound_eq" (`dd_bound = iabs ddf_bounds`));;
822 (add_section_hyp "tif" (`taylor_interval f x y z w f_bounds df_bounds ddf_bounds`));;
823 (start_section_proof [](`!t. t IN real_interval [x, z] ==> f real_continuous atreal t`));;
824 refine (by (VALID (((((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN interval_arith)(GSYM_THEN (new_rewrite [] [])))) THEN (move ["t"]) THEN (move ["t_in"])))));;
825 refine (by (VALID ((((USE_THM_THEN HAS_REAL_DERIVATIVE_IMP_CONTINUOUS_ATREAL)MP_TAC) THEN (clear_assumption "HAS_REAL_DERIVATIVE_IMP_CONTINUOUS_ATREAL") THEN (DISCH_THEN apply_tac)))));;
826 refine (by (VALID (((((USE_THEN "tif")MP_TAC) THEN (clear_assumption "tif") THEN BETA_TAC) THEN ((((USE_THM_THEN taylor_interval)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andbA)(new_rewrite [] [])))) THEN ALL_TAC THEN (case THEN (move ["_"])) THEN (DISCH_THEN (fun snd_th -> (USE_THM_THEN has_bounded_second_derivative_old)(MATCH_MP_THEN snd_th MP_TAC))))))));;
827 refine (by (VALID ((BETA_TAC THEN (case THEN (move ["f'"])) THEN (case THEN (move ["f''"])) THEN (move ["df"])))));;
828 refine (by (VALID (((exists_tac (`f' t`)) THEN ((USE_THEN "df")(new_rewrite [] [])) THEN (done_tac)))));;
829 let f_continuous = end_section_proof();;
830 (start_section_proof ["t"](`x <= t /\ t <= z ==> 
831         abs (f t - f y) <= w * iabs df_bounds + w * w * dd_bound / &2`));;
832 refine (by (VALID ((BETA_TAC THEN (move ["t_ineqs"])))));;
833 refine (by (VALID (((((USE_THEN "tif") MP_TAC) THEN ALL_TAC) THEN ((((USE_THM_THEN taylor_interval)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andbA)(new_rewrite [] [])))) THEN ALL_TAC THEN (case THEN ALL_TAC) THEN (case THEN (move ["domain_ineqs"])) THEN (move ["lin_app"]))))));;
834 refine (by (VALID (((DISCH_THEN (fun snd_th -> (USE_THM_THEN has_bounded_second_derivative_old)(MATCH_MP_THEN snd_th MP_TAC))) THEN BETA_TAC THEN (case THEN (move ["f'"])) THEN (case THEN (move ["f''"])) THEN (move ["df"])))));;
835 refine (by (VALID ((have_tac (move ["abs_ty"]) (`abs (t - y) <= w`)))));;
836 refine (by (VALID (((((USE_THEN "t_ineqs")MP_TAC) THEN (clear_assumption "t_ineqs") THEN ((USE_THEN "domain_ineqs")MP_TAC) THEN (clear_assumption "domain_ineqs") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
837 refine (by (VALID (((THENL_FIRST) (have_tac (move ["y_in"]) (`interval_arith y (x, z)`)) (((USE_THM_THEN interval_arith)(new_rewrite [] [])) THEN (done_tac))))));;
838 refine (by (VALID ((have_tac (move ["dd_prop"]) (`&0 <= dd_bound /\ !p. p IN real_interval [x, z] ==> abs (f'' p) <= dd_bound`)))));;
839 refine (by (VALID ((((USE_THEN "dd_bound_eq")(new_rewrite [] [])) THEN (split_tac)))));;
840 refine (by (VALID (((((fun thm_tac -> (USE_THEN "df")(fun fst_th ->(USE_THEN "y_in")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC) THEN (((USE_THM_THEN pair_eq)(new_rewrite [] [])) THEN ((USE_THM_THEN interval_arith)(new_rewrite [] [])) THEN ((USE_THM_THEN iabs)(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac)))));;
841 refine (by (VALID (((((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN interval_arith)(GSYM_THEN (new_rewrite [] [])))) THEN (BETA_TAC THEN (move ["p"]) THEN (DISCH_THEN (fun snd_th -> (USE_THEN "df")(MATCH_MP_THEN snd_th MP_TAC)))) THEN (((USE_THM_THEN pair_eq)(new_rewrite [] [])) THEN ((USE_THM_THEN interval_arith)(new_rewrite [] [])) THEN ((USE_THM_THEN iabs)(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac)))));;
842 refine (by (VALID ((((THENL_ROT 1)) (have_tac ALL_TAC (`abs (f t - (f y + f' y * (t - y) pow 1)) <= dd_bound * abs (t - y) pow (1 + 1) / &2`))))));;
843 refine (by (VALID (((set_tac "b1" (`f' y * _`)) THEN ((set_tac "b2" (`dd_bound * _`)) THEN (move ["ineq1"]))))));;
844 refine (by (VALID (((((USE_THM_THEN REAL_LE_TRANS)MP_TAC) THEN (clear_assumption "REAL_LE_TRANS") THEN (DISCH_THEN apply_tac)) THEN (exists_tac (`abs (f t - (f y + b1)) + abs b1`)) THEN (split_tac)))));;
845 refine (by (VALID (((((USE_THM_THEN (REAL_ARITH `!a b. a - b = (a - (b + b1)) + b1`))(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_ABS_TRIANGLE)(new_rewrite [] []))) THEN (done_tac)))));;
846 refine (by (VALID ((((USE_THM_THEN REAL_ADD_SYM)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LE_ADD2)(new_rewrite [] [])) THEN ((USE_THEN "b1_def")(GSYM_THEN (new_rewrite [1] []))) THEN ((USE_THM_THEN REAL_POW_1)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_ABS_MUL)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_SYM)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LE_MUL2)(new_rewrite [] []))))));;
847 refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN REAL_ABS_POS)(new_rewrite [] []))) THEN ((USE_THEN "abs_ty")(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] []))) THEN ((USE_THM_THEN pair_eq)(new_rewrite [] [])) THEN ((USE_THM_THEN iabs)(new_rewrite [] []))))));;
848 refine (by (VALID (((((USE_THEN "lin_app")MP_TAC) THEN (clear_assumption "lin_app") THEN BETA_TAC) THEN (((USE_THM_THEN lin_approx)(new_rewrite [] [])) THEN ALL_TAC THEN (case THEN (move ["_"])) THEN (case THEN (move ["ff"])) THEN (case THEN (move ["df'"])))))));;
849 refine (by (VALID (((THENL_FIRST) (((THENL_ROT 1)) (have_tac (DISCH_THEN(new_rewrite [] [])) (`ff = f' y`))) ((((USE_THM_THEN pair_eq)(new_rewrite [] [])) THEN ((USE_THM_THEN interval_arith)(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac))))));;
850 refine (by (VALID (((((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN REAL_DERIVATIVE_UNIQUE_ATREAL)(ISPEC_THEN (mk_var("f",mk_type("fun",[mk_type("real",[]);mk_type("real",[])]))) thm_tac))(ISPEC_THEN (mk_var("y",mk_type("real",[]))) thm_tac))MP_TAC) THEN (DISCH_THEN apply_tac)) THEN (((USE_THEN "df'")(new_rewrite [] [])) THEN ((USE_THEN "df")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] []))) THEN (done_tac)))));;
851 refine (by (VALID ((((USE_THM_THEN andTb)(new_rewrite [] [])) THEN (((USE_THM_THEN REAL_LE_TRANS)MP_TAC) THEN (clear_assumption "REAL_LE_TRANS") THEN (DISCH_THEN apply_tac)) THEN (exists_tac (mk_var("b2",mk_type("real",[]))))))));;
852 refine (by (VALID ((((USE_THEN "ineq1")(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] [])) THEN ((USE_THEN "b2_def")(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN real_div)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_MUL_ASSOC)(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_LE_MUL2)(new_rewrite [] [])) THEN ((USE_THM_THEN (ARITH_RULE `1 + 1 = 2`))(new_rewrite [] []))))));;
853 refine (by (VALID (((((USE_THM_THEN REAL_LE_REFL)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LE_INV)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_LE_MUL)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "dd_prop")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_LE_POW_2)(new_rewrite [] [])))) THEN ((TRY) (arith_tac))))));;
854 refine (by (VALID ((((USE_THM_THEN andTb)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andbT)(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_MUL_SYM)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_POW_2)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN REAL_LE_MUL2)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LE_REFL)(new_rewrite [] [])) THEN ((USE_THEN "dd_prop")(new_rewrite [] []))))));;
855 refine (by (VALID (((((USE_THM_THEN REAL_LE_POW_2)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andbT)(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_LE_SQUARE_ABS)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN REAL_ABS_ABS)(new_rewrite [] []))) THEN (((USE_THEN "abs_ty")MP_TAC) THEN (clear_assumption "abs_ty") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
856 refine (by (VALID ((set_tac "Df" (`\i. if i = 0 then f else if i = 1 then f' else if i = 2 then f'' else I`)))));;
857 refine (by (VALID ((((USE_THM_THEN (ARITH_RULE `0 + 1 = 1 /\ ~(1 = 0) /\ 1 + 1 = 2 /\ 
858         ~(2 = 1) /\ ~(2 = 1) /\ ~(2 = 0)`)) MP_TAC) THEN (move ["arith"])))));;
859 refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN REAL_TAYLOR)(ISPEC_THEN (mk_var("Df",mk_type("fun",[mk_type("num",[]);mk_type("fun",[mk_type("real",[]);mk_type("real",[])])]))) thm_tac))(ISPEC_THEN (`1`) thm_tac))(ISPEC_THEN (`real_interval [x, z]`) thm_tac))(ISPEC_THEN (mk_var("dd_bound",mk_type("real",[]))) thm_tac)) MP_TAC) THEN ALL_TAC))));;
860 refine (by (VALID ((ANTS_TAC))));;
861 refine (by (VALID (((((USE_THM_THEN IS_REALINTERVAL_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (split_tac)))));;
862 refine (by (VALID ((((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN interval_arith)(GSYM_THEN (new_rewrite [] [])))))));;
863 refine (by (VALID (((BETA_TAC THEN (move ["i"]) THEN (move ["p"]) THEN (case THEN (move ["p_in"]))) THEN ((USE_THM_THEN (ARITH_RULE `i <= 1 <=> i = 0 \/ i = 1`))(new_rewrite [] []))))));;
864 refine (by (VALID (((case THEN (DISCH_THEN(new_rewrite [] []))) THEN (((USE_THEN "Df_def")(GSYM_THEN (new_rewrite [] []))) THEN (simp_tac)) THEN ((USE_THM_THEN HAS_REAL_DERIVATIVE_ATREAL_WITHIN) apply_tac) THEN (repeat_tactic 1 9 (((USE_THEN "arith")(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THEN "df")(new_rewrite [] []))) THEN (done_tac)))));;
865 refine (by (VALID (((BETA_TAC THEN (move ["p"]) THEN (move ["p_in"])) THEN (((USE_THEN "Df_def")(GSYM_THEN (new_rewrite [] []))) THEN (simp_tac))))));;
866 refine (by (VALID (((repeat_tactic 1 9 (((USE_THEN "arith")(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THEN "dd_prop")(new_rewrite [] []))) THEN (done_tac)))));;
867 refine (by (VALID (((BETA_TAC THEN ((fun thm_tac -> (fun thm_tac -> DISCH_THEN (ISPEC_THEN (mk_var("y",mk_type("real",[]))) thm_tac))(ISPEC_THEN (mk_var("t",mk_type("real",[]))) thm_tac))MP_TAC)) THEN (repeat_tactic 1 9 (((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THEN "domain_ineqs")(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THEN "t_ineqs")(new_rewrite [] []))) THEN (simp_tac))))));;
868 refine (by (VALID ((((USE_THM_THEN ONE)(new_rewrite [1] [])) THEN ((USE_THM_THEN (GEN_ALL SUM_CLAUSES_NUMSEG))(new_rewrite [] [])) THEN ((USE_THM_THEN SUM_SING_NUMSEG)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THEN "Df_def")(GSYM_THEN (new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN ONE)(GSYM_THEN (new_rewrite [] [])))))));;
869 refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN (ARITH_RULE `0 <= 1 /\ ~(1 = 0)`))(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN (GEN_ALL real_pow))(new_rewrite [] [])) THEN ((USE_THM_THEN FACT)(new_rewrite [] []))))));;
870 refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN (ARITH_RULE `FACT 1 = 1 /\ FACT (1 + 1) = 2`))(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_DIV_1)(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_MUL_RID)(new_rewrite [] []))) THEN (done_tac)))));;
871 let taylor_error = end_section_proof();;
872 (start_section_proof [](`!t. x <= t /\ t <= z ==>
873         f t <= SND f_bounds + (w * iabs df_bounds + w * w * dd_bound / &2)`));;
874 refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN pair_eq)(ISPEC_THEN (mk_var("f_bounds",mk_type("prod",[mk_type("real",[]);mk_type("real",[])]))) thm_tac))MP_TAC) THEN BETA_TAC THEN (move ["eq"])))));;
875 refine (by (VALID ((BETA_TAC THEN (move ["t"]) THEN (DISCH_THEN (fun snd_th -> (USE_THM_THEN taylor_error)(MATCH_MP_THEN snd_th MP_TAC)))))));;
876 refine (by (VALID (((((USE_THEN "tif")MP_TAC) THEN (clear_assumption "tif") THEN BETA_TAC) THEN ((((USE_THM_THEN taylor_interval)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andbA)(new_rewrite [] []))) THEN ((USE_THM_THEN lin_approx)(new_rewrite [] []))) THEN ALL_TAC THEN (case THEN ALL_TAC) THEN (case THEN (move ["_"])) THEN (case THEN (move ["f_int"])) THEN (move ["_"]) THEN (move ["_"]))))));;
877 refine (by (VALID (((((USE_THEN "f_int")MP_TAC) THEN (clear_assumption "f_int") THEN BETA_TAC) THEN (((USE_THEN "eq")(new_rewrite [1] [])) THEN ((USE_THM_THEN interval_arith)(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac)))));;
878 let taylor_upper_bound = end_section_proof();;
879 (start_section_proof [](`!t. x <= t /\ t <= z ==>
880         FST f_bounds - (w * iabs df_bounds + w * w * dd_bound / &2) <= f t`));;
881 refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN pair_eq)(ISPEC_THEN (mk_var("f_bounds",mk_type("prod",[mk_type("real",[]);mk_type("real",[])]))) thm_tac)) MP_TAC) THEN (move ["eq"])))));;
882 refine (by (VALID ((BETA_TAC THEN (move ["t"]) THEN (DISCH_THEN (fun snd_th -> (USE_THM_THEN taylor_error)(MATCH_MP_THEN snd_th MP_TAC)))))));;
883 refine (by (VALID (((((USE_THEN "tif")MP_TAC) THEN (clear_assumption "tif") THEN BETA_TAC) THEN ((((USE_THEN "eq")(new_rewrite [1] [])) THEN ((USE_THM_THEN taylor_interval)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andbA)(new_rewrite [] []))) THEN ((USE_THM_THEN lin_approx)(new_rewrite [] []))) THEN ALL_TAC THEN (case THEN ALL_TAC) THEN (case THEN (move ["_"])) THEN (case THEN (move ["f_int"])) THEN (move ["_"]) THEN (move ["_"]))))));;
884 refine (by (VALID (((((USE_THEN "f_int")MP_TAC) THEN (clear_assumption "f_int") THEN BETA_TAC) THEN ((USE_THM_THEN interval_arith)(new_rewrite [] [])) THEN (arith_tac)))));;
885 let taylor_lower_bound = end_section_proof();;
886 (start_section_proof [](`!t. x <= t /\ t <= z ==> 
887         abs (derivative f t - derivative f y) <= w * dd_bound`));;
888 refine (by (VALID ((BETA_TAC THEN (move ["t"]) THEN (move ["t_ineqs"])))));;
889 refine (by (VALID (((((USE_THEN "tif") MP_TAC) THEN ALL_TAC) THEN ((((USE_THM_THEN taylor_interval)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andbA)(new_rewrite [] [])))) THEN ALL_TAC THEN (case THEN ALL_TAC) THEN (case THEN (move ["domain_ineqs"])) THEN (move ["_"]))))));;
890 refine (by (VALID (((DISCH_THEN (fun snd_th -> (USE_THM_THEN has_bounded_second_derivative_old)(MATCH_MP_THEN snd_th MP_TAC))) THEN BETA_TAC THEN (case THEN (move ["f'"])) THEN (case THEN (move ["f''"])) THEN (move ["df"])))));;
891 refine (by (VALID ((have_tac (move ["abs_ty"]) (`abs (t - y) <= w`)))));;
892 refine (by (VALID (((((USE_THEN "t_ineqs")MP_TAC) THEN (clear_assumption "t_ineqs") THEN ((USE_THEN "domain_ineqs")MP_TAC) THEN (clear_assumption "domain_ineqs") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
893 refine (by (VALID ((have_tac (move ["der_eq"]) (`!p. x <= p /\ p <= z ==> derivative f p = f' p`)))));;
894 refine (by (VALID (((((USE_THM_THEN IN_REAL_INTERVAL)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN EQ_SYM_EQ)(new_rewrite [] []))) THEN (((USE_THM_THEN derivative_unique_on)MP_TAC) THEN (clear_assumption "derivative_unique_on") THEN (DISCH_THEN apply_tac))))));;
895 refine (by (VALID ((((((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN interval_arith)(GSYM_THEN (new_rewrite [] [])))) THEN (move ["p"]) THEN (DISCH_THEN (fun snd_th -> (USE_THEN "df")(MATCH_MP_THEN snd_th MP_TAC))) THEN (simp_tac)) THEN (done_tac)))));;
896 refine (by (VALID ((repeat_tactic 1 9 (((USE_THEN "der_eq")(new_rewrite [] []))) THEN ((TRY done_tac))))));;
897 refine (by (VALID ((have_tac (move ["dd_prop"]) (`&0 <= dd_bound /\ !p. p IN real_interval [x, z] ==> abs (f'' p) <= dd_bound`)))));;
898 refine (by (VALID (((((USE_THEN "dd_bound_eq")(new_rewrite [] [])) THEN ((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN interval_arith)(GSYM_THEN (new_rewrite [] [])))) THEN (split_tac)))));;
899 refine (by (VALID (((((fun thm_tac -> (USE_THEN "df")(ISPEC_THEN (mk_var("y",mk_type("real",[]))) thm_tac))MP_TAC) THEN BETA_TAC) THEN (((fun thm_tac -> (USE_THM_THEN pair_eq)(ISPEC_THEN (mk_var("ddf_bounds",mk_type("prod",[mk_type("real",[]);mk_type("real",[])]))) thm_tac))(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN interval_arith)(new_rewrite [] []))) THEN ((USE_THM_THEN iabs)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THEN "domain_ineqs")(new_rewrite [] [])))) THEN (arith_tac) THEN (done_tac)))));;
900 refine (by (VALID (((BETA_TAC THEN (move ["p"]) THEN (DISCH_THEN (fun snd_th -> (USE_THEN "df")(MATCH_MP_THEN snd_th MP_TAC)))) THEN (((USE_THM_THEN pair_eq)(new_rewrite [] [])) THEN ((USE_THM_THEN interval_arith)(new_rewrite [] [])) THEN ((USE_THM_THEN iabs)(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac)))));;
901 refine (by (VALID ((set_tac "Df" (`\i. if i = 0 then f' else if i = 1 then f'' else I`)))));;
902 refine (by (VALID ((((USE_THM_THEN (ARITH_RULE `0 + 1 = 1 /\ ~(1 = 0) /\ 1 + 1 = 2 /\ 
903         ~(2 = 1) /\ ~(2 = 1) /\ ~(2 = 0)`)) MP_TAC) THEN (move ["arith"])))));;
904 refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN REAL_TAYLOR)(ISPEC_THEN (mk_var("Df",mk_type("fun",[mk_type("num",[]);mk_type("fun",[mk_type("real",[]);mk_type("real",[])])]))) thm_tac))(ISPEC_THEN (`0`) thm_tac))(ISPEC_THEN (`real_interval [x, z]`) thm_tac))(ISPEC_THEN (mk_var("dd_bound",mk_type("real",[]))) thm_tac)) MP_TAC) THEN ALL_TAC))));;
905 refine (by (VALID ((ANTS_TAC))));;
906 refine (by (VALID (((((USE_THM_THEN IS_REALINTERVAL_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (split_tac)))));;
907 refine (by (VALID (((BETA_TAC THEN (move ["i"]) THEN (move ["p"]) THEN (case THEN (move ["p_in"]))) THEN (((USE_THM_THEN (ARITH_RULE `i <= 0 <=> i = 0`))(new_rewrite [] [])) THEN (DISCH_THEN(new_rewrite [] [])))))));;
908 refine (by (VALID (((((USE_THEN "Df_def")(GSYM_THEN (new_rewrite [] []))) THEN (simp_tac) THEN repeat_tactic 1 9 (((USE_THEN "arith")(new_rewrite [] []))) THEN (simp_tac)) THEN (((USE_THM_THEN HAS_REAL_DERIVATIVE_ATREAL_WITHIN)MP_TAC) THEN (clear_assumption "HAS_REAL_DERIVATIVE_ATREAL_WITHIN") THEN (DISCH_THEN apply_tac))))));;
909 refine (by (VALID (((((USE_THEN "df")(new_rewrite [] [])) THEN ((USE_THM_THEN interval_arith)(new_rewrite [] [])) THEN ((USE_THM_THEN IN_REAL_INTERVAL)(GSYM_THEN (new_rewrite [] [])))) THEN (done_tac)))));;
910 refine (by (VALID (((BETA_TAC THEN (move ["p"]) THEN (move ["p_in"])) THEN (((USE_THEN "Df_def")(GSYM_THEN (new_rewrite [] []))) THEN (simp_tac))))));;
911 refine (by (VALID (((repeat_tactic 1 9 (((USE_THEN "arith")(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THEN "dd_prop")(new_rewrite [] []))) THEN (done_tac)))));;
912 refine (by (VALID (((BETA_TAC THEN ((fun thm_tac -> (fun thm_tac -> DISCH_THEN (ISPEC_THEN (mk_var("y",mk_type("real",[]))) thm_tac))(ISPEC_THEN (mk_var("t",mk_type("real",[]))) thm_tac))MP_TAC)) THEN (repeat_tactic 1 9 (((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THEN "domain_ineqs")(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THEN "t_ineqs")(new_rewrite [] []))) THEN (simp_tac))))));;
913 refine (by (VALID ((((USE_THM_THEN ONE)(new_rewrite [1] [])) THEN ((USE_THM_THEN SUM_SING_NUMSEG)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THEN "Df_def")(GSYM_THEN (new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN ONE)(GSYM_THEN (new_rewrite [] [])))))));;
914 refine (by (VALID ((((USE_THM_THEN (GEN_ALL real_pow))(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THEN "arith")(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN FACT)(new_rewrite [] []))) THEN ((USE_THM_THEN (ARITH_RULE `FACT 1 = 1`))(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_DIV_1)(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_MUL_RID)(new_rewrite [] []))))));;
915 refine (by (VALID ((((USE_THM_THEN REAL_POW_1)(new_rewrite [] [])) THEN (move ["ineq"])))));;
916 refine (by (VALID (((((USE_THM_THEN REAL_LE_TRANS)MP_TAC) THEN (clear_assumption "REAL_LE_TRANS") THEN (DISCH_THEN apply_tac)) THEN (exists_tac (`dd_bound * abs (t - y)`))))));;
917 refine (by (VALID (((((USE_THEN "ineq")(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_SYM)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LE_RMUL)(new_rewrite [] [])) THEN ((USE_THEN "dd_prop")(new_rewrite [] [])) THEN ((USE_THEN "abs_ty")(new_rewrite [] []))) THEN (done_tac)))));;
918 let taylor_derivative_error = end_section_proof();;
919 (start_section_proof [](`FST df_bounds <= derivative f y /\ derivative f y <= SND df_bounds`));;
920 refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN pair_eq)(ISPEC_THEN (mk_var("df_bounds",mk_type("prod",[mk_type("real",[]);mk_type("real",[])]))) thm_tac)) MP_TAC) THEN (move ["eq"])))));;
921 refine (by (VALID (((((USE_THEN "tif")MP_TAC) THEN (clear_assumption "tif") THEN BETA_TAC) THEN ((((USE_THM_THEN taylor_interval)(new_rewrite [] [])) THEN ((USE_THM_THEN lin_approx)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andbA)(new_rewrite [] [])))) THEN ALL_TAC THEN (case THEN ALL_TAC) THEN (case THEN (move ["ineqs"])) THEN (case THEN (move ["g"])) THEN (case THEN ((move ["fg"]) THEN (move ["g_int"]))) THEN (move ["_"]))))));;
922 refine (by (VALID (((THENL_FIRST) (((THENL_ROT 1)) (have_tac (DISCH_THEN(new_rewrite [] [])) (`derivative f y = g`))) ((((USE_THEN "g_int")MP_TAC) THEN (clear_assumption "g_int") THEN BETA_TAC) THEN (((USE_THEN "eq")(new_rewrite [] [])) THEN ((USE_THM_THEN interval_arith)(new_rewrite [] []))) THEN (done_tac))))));;
923 refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN REAL_DERIVATIVE_UNIQUE_ATREAL)(ISPEC_THEN (mk_var("f",mk_type("fun",[mk_type("real",[]);mk_type("real",[])]))) thm_tac))(ISPEC_THEN (mk_var("y",mk_type("real",[]))) thm_tac))MP_TAC) THEN (DISCH_THEN apply_tac)))));;
924 refine (by (VALID (((((USE_THEN "fg")(new_rewrite [] [])) THEN ((USE_THM_THEN has_derivative_cond)(new_rewrite [] [])) THEN ((TRY done_tac))) THEN (exists_tac (mk_var("g",mk_type("real",[])))) THEN (done_tac)))));;
925 let derivative_interval = end_section_proof();;
926 (start_section_proof [](`!t. x <= t /\ t <= z ==>
927         derivative f t <= SND df_bounds + w * dd_bound`));;
928 refine (by (VALID (((BETA_TAC THEN (move ["t"]) THEN (DISCH_THEN (fun snd_th -> (USE_THM_THEN taylor_derivative_error)(MATCH_MP_THEN snd_th MP_TAC)))) THEN (((USE_THM_THEN derivative_interval)MP_TAC) THEN (clear_assumption "derivative_interval") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
929 let taylor_derivative_upper_bound = end_section_proof();;
930 (start_section_proof [](`!t. x <= t /\ t <= z ==>
931         FST df_bounds - w * dd_bound <= derivative f t`));;
932 refine (by (VALID (((BETA_TAC THEN (move ["t"]) THEN (DISCH_THEN (fun snd_th -> (USE_THM_THEN taylor_derivative_error)(MATCH_MP_THEN snd_th MP_TAC)))) THEN (((USE_THM_THEN derivative_interval)MP_TAC) THEN (clear_assumption "derivative_interval") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
933 let taylor_derivative_lower_bound = end_section_proof();;
934 let taylor_derivative_lower_bound = finalize_theorem taylor_derivative_lower_bound;;
935 let taylor_derivative_upper_bound = finalize_theorem taylor_derivative_upper_bound;;
936 let derivative_interval = finalize_theorem derivative_interval;;
937 let taylor_derivative_error = finalize_theorem taylor_derivative_error;;
938 let taylor_lower_bound = finalize_theorem taylor_lower_bound;;
939 let taylor_upper_bound = finalize_theorem taylor_upper_bound;;
940 let taylor_error = finalize_theorem taylor_error;;
941 let f_continuous = finalize_theorem f_continuous;;
942 let iabs_pos = finalize_theorem iabs_pos;;
943 let iabs_alt = finalize_theorem iabs_alt;;
944 (end_section "Taylor");;
945 (begin_section "LinearApproximation");;
946 (add_section_var (mk_var ("f", (`:real->real`))));;
947 (add_section_var (mk_var ("f_bounds", (`:real#real`))); add_section_var (mk_var ("df_bounds", (`:real#real`))));;
948 (add_section_var (mk_var ("x", (`:real`))));;
949 (start_section_proof [](`lin_approx f x f_bounds df_bounds <=>
950         (f real_differentiable atreal x /\ interval_arith (f x) f_bounds /\
951         interval_arith (derivative f x) df_bounds)`));;
952 refine (by (VALID (((((USE_THM_THEN lin_approx)(new_rewrite [] [])) THEN ((USE_THM_THEN real_differentiable)(new_rewrite [] []))) THEN ((split_tac) THENL [(case THEN ((DISCH_THEN(new_rewrite [] [])) THEN (case THEN (move ["f'"])) THEN (case THEN ((move ["df'"]) THEN (move ["int_f'"]))))); ((case THEN ((case THEN (move ["f'"])) THEN (move ["df"]))) THEN (case THEN ((DISCH_THEN(new_rewrite [] [])) THEN (move ["df_int"]))))])))));;
953 refine (by (VALID (((THENL_FIRST) (split_tac) ((exists_tac (mk_var("f'",mk_type("real",[])))) THEN (done_tac))))));;
954 refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN derivative_unique)(ISPEC_THEN (mk_var("f",mk_type("fun",[mk_type("real",[]);mk_type("real",[])]))) thm_tac))(ISPEC_THEN (mk_var("f'",mk_type("real",[]))) thm_tac))(new_rewrite [] [])) THEN (done_tac)))));;
955 refine (by (VALID ((((USE_THM_THEN andTb)(new_rewrite [] [])) THEN (exists_tac (mk_var("f'",mk_type("real",[])))) THEN (((USE_THEN "df")(new_rewrite [] [])) THEN ((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN derivative_unique)(ISPEC_THEN (mk_var("f",mk_type("fun",[mk_type("real",[]);mk_type("real",[])]))) thm_tac))(ISPEC_THEN (mk_var("f'",mk_type("real",[]))) thm_tac))(ISPEC_THEN (mk_var("x",mk_type("real",[]))) thm_tac))(GSYM_THEN (new_rewrite [] [])))) THEN (done_tac)))));;
956 let lin_approx_eq = end_section_proof();;
957 (add_section_hyp "approx_f" (`lin_approx f x f_bounds df_bounds`));;
958 (start_section_proof [](`interval_arith (f x) f_bounds`));;
959 refine (by (VALID (((((USE_THEN "approx_f")MP_TAC) THEN (clear_assumption "approx_f") THEN BETA_TAC) THEN (((USE_THM_THEN lin_approx_eq)(new_rewrite [] [])) THEN (simp_tac)) THEN (done_tac)))));;
960 let lin_approx_imp_f_interval = end_section_proof();;
961 (start_section_proof [](`interval_arith (derivative f x) df_bounds`));;
962 refine (by (VALID (((((USE_THEN "approx_f")MP_TAC) THEN (clear_assumption "approx_f") THEN BETA_TAC) THEN (((USE_THM_THEN lin_approx_eq)(new_rewrite [] [])) THEN (simp_tac)) THEN (done_tac)))));;
963 let lin_approx_imp_df_interval = end_section_proof();;
964 (start_section_proof [](`f real_differentiable atreal x`));;
965 refine (by (VALID (((((USE_THEN "approx_f")MP_TAC) THEN (clear_assumption "approx_f") THEN BETA_TAC) THEN (((USE_THM_THEN lin_approx_eq)(new_rewrite [] [])) THEN (simp_tac)) THEN (done_tac)))));;
966 let lin_approx_imp_f_diff = end_section_proof();;
967 let lin_approx_imp_f_diff = finalize_theorem lin_approx_imp_f_diff;;
968 let lin_approx_imp_df_interval = finalize_theorem lin_approx_imp_df_interval;;
969 let lin_approx_imp_f_interval = finalize_theorem lin_approx_imp_f_interval;;
970 let lin_approx_eq = finalize_theorem lin_approx_eq;;
971 (end_section "LinearApproximation");;
972 (begin_section "MoreLinearApproximation");;
973 (add_section_var (mk_var ("f", (`:real->real`))); add_section_var (mk_var ("g", (`:real->real`))));;
974 (add_section_var (mk_var ("x", (`:real`))));;
975 (add_section_var (mk_var ("f_bounds", (`:real#real`))); add_section_var (mk_var ("df_bounds", (`:real#real`))));;
976 (add_section_var (mk_var ("g_bounds", (`:real#real`))); add_section_var (mk_var ("dg_bounds", (`:real#real`))));;
977 let interval_not_zero = new_definition `interval_not_zero (lo, hi) <=> &0 < lo \/ hi < &0`;;
978 let interval_pos = new_definition `interval_pos (lo, hi) <=> &0 < lo`;;
979 (start_section_proof ["x";"int"](`interval_arith x int ==> interval_not_zero int ==>
980         ~(x = &0)`));;
981 refine (by (VALID (((((fun thm_tac -> (USE_THM_THEN PAIR)(ISPEC_THEN (mk_var("int",mk_type("prod",[mk_type("real",[]);mk_type("real",[])]))) thm_tac))(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN interval_arith)(new_rewrite [] [])) THEN ((USE_THM_THEN interval_not_zero)(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac)))));;
982 let interval_arith_not_zero = end_section_proof();;
983 (start_section_proof ["x";"int"](`interval_arith x int ==> interval_pos int ==> &0 < x`));;
984 refine (by (VALID ((((disch_tm_tac [](mk_var("int",mk_type("prod",[mk_type("real",[]);mk_type("real",[])])))) THEN (clear_assumption "int") THEN case) THEN (((USE_THM_THEN interval_arith)(new_rewrite [] [])) THEN ((USE_THM_THEN interval_pos)(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac)))));;
985 let interval_arith_pos = end_section_proof();;
986 (start_section_proof ["x";"int";"y"](`interval_arith x int ==> iabs int < y ==> abs x < y`));;
987 refine (by (VALID (((((fun thm_tac -> (USE_THM_THEN PAIR)(ISPEC_THEN (mk_var("int",mk_type("prod",[mk_type("real",[]);mk_type("real",[])]))) thm_tac))(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN interval_arith)(new_rewrite [] [])) THEN ((USE_THM_THEN iabs)(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac)))));;
988 let interval_arith_abs = end_section_proof();;
989 (start_section_proof [](`lin_approx (\x. x) x (x, x) (&1, &1)`));;
990 refine (by (VALID (((((USE_THM_THEN lin_approx_eq)(new_rewrite [] [])) THEN ((USE_THM_THEN derivative_x)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN interval_arith)(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN REAL_DIFFERENTIABLE_ID)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_LE_REFL)(new_rewrite [] [])))) THEN (done_tac)))));;
991 let lin_approx_x = end_section_proof();;
992 (start_section_proof ["c"](`lin_approx (\x. c) x (c, c) (&0, &0)`));;
993 refine (by (VALID ((((USE_THM_THEN lin_approx_eq)(new_rewrite [] [])) THEN ((USE_THM_THEN derivative_const)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN interval_arith)(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN REAL_DIFFERENTIABLE_CONST)(new_rewrite [] []))))));;
994 refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN REAL_LE_REFL)(new_rewrite [] []))) THEN (done_tac)))));;
995 let lin_approx_const = end_section_proof();;
996 (begin_section "LinearApproxUnivariateComposition");;
997 (add_section_hyp "approx_f" (`lin_approx f x f_bounds df_bounds`));;
998 (start_section_proof [](`(\x. atn (f x)) real_differentiable atreal x /\
999         derivative (\x. atn (f x)) x = derivative f x / (&1 + f x * f x)`));;
1000 refine (by (VALID (((((USE_THM_THEN derivative_compose_atn)MP_TAC) THEN (clear_assumption "derivative_compose_atn") THEN (DISCH_THEN apply_tac)) THEN (((USE_THEN "approx_f")MP_TAC) THEN (clear_assumption "approx_f") THEN BETA_TAC) THEN (((USE_THM_THEN lin_approx_eq)(new_rewrite [] [])) THEN (DISCH_THEN(new_rewrite [] []))) THEN (done_tac)))));;
1001 let lin_approx_compose_atn = end_section_proof();;
1002 (start_section_proof [](`(\x. exp (f x)) real_differentiable atreal x /\
1003         derivative (\x. exp (f x)) x = exp (f x) * derivative f x`));;
1004 refine (by (VALID (((((USE_THM_THEN derivative_compose_exp)MP_TAC) THEN (clear_assumption "derivative_compose_exp") THEN (DISCH_THEN apply_tac)) THEN (((USE_THEN "approx_f")MP_TAC) THEN (clear_assumption "approx_f") THEN BETA_TAC) THEN (((USE_THM_THEN lin_approx_eq)(new_rewrite [] [])) THEN (DISCH_THEN(new_rewrite [] []))) THEN (done_tac)))));;
1005 let lin_approx_compose_exp = end_section_proof();;
1006 (start_section_proof [](`interval_not_zero f_bounds ==>
1007         (\x. inv (f x)) real_differentiable atreal x /\
1008         derivative (\x. inv (f x)) x = -- inv (f x * f x) * derivative f x`));;
1009 refine (by (VALID (((((USE_THEN "approx_f")MP_TAC) THEN (clear_assumption "approx_f") THEN BETA_TAC) THEN (((USE_THM_THEN lin_approx_eq)(new_rewrite [] [])) THEN ALL_TAC THEN (case THEN ((move ["df"]) THEN (move ["h"]))) THEN (move ["f0"]))))));;
1010 refine (by (VALID (((THENL_FIRST) (have_tac (move ["fn0"]) (`~(f x = &0)`)) ((((USE_THM_THEN interval_arith_not_zero)MP_TAC) THEN (clear_assumption "interval_arith_not_zero") THEN (DISCH_THEN apply_tac)) THEN (exists_tac (mk_var("f_bounds",mk_type("prod",[mk_type("real",[]);mk_type("real",[])])))) THEN (done_tac))))));;
1011 refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN derivative_compose_inv)(fun fst_th ->(USE_THEN "df")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "fn0")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN (exact_tac)))));;
1012 let lin_approx_compose_inv = end_section_proof();;
1013 (start_section_proof [](`interval_pos f_bounds ==>
1014         (\x. sqrt (f x)) real_differentiable atreal x /\
1015         derivative (\x. sqrt (f x)) x = derivative f x / (&2 * sqrt (f x))`));;
1016 refine (by (VALID (((((USE_THEN "approx_f")MP_TAC) THEN (clear_assumption "approx_f") THEN BETA_TAC) THEN (((USE_THM_THEN lin_approx_eq)(new_rewrite [] [])) THEN ALL_TAC THEN (case THEN ((move ["df"]) THEN (move ["h"]))) THEN (move ["f_ineq"]))))));;
1017 refine (by (VALID (((THENL_FIRST) (have_tac (move ["f_pos"]) (`&0 < f x`)) ((((USE_THM_THEN interval_arith_pos)MP_TAC) THEN (clear_assumption "interval_arith_pos") THEN (DISCH_THEN apply_tac)) THEN (exists_tac (mk_var("f_bounds",mk_type("prod",[mk_type("real",[]);mk_type("real",[])])))) THEN (done_tac))))));;
1018 refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN derivative_compose_sqrt)(fun fst_th ->(USE_THEN "df")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "f_pos")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN (exact_tac)))));;
1019 let lin_approx_compose_sqrt = end_section_proof();;
1020 (start_section_proof [](`iabs f_bounds < &1 ==>
1021         (\x. acs (f x)) real_differentiable atreal x /\
1022         derivative (\x. acs (f x)) x = -- (derivative f x / sqrt (&1 - f x * f x))`));;
1023 refine (by (VALID (((((USE_THEN "approx_f")MP_TAC) THEN (clear_assumption "approx_f") THEN BETA_TAC) THEN (((USE_THM_THEN lin_approx_eq)(new_rewrite [] [])) THEN ALL_TAC THEN (case THEN ((move ["df"]) THEN (move ["h"]))) THEN (move ["f_ineq"]))))));;
1024 refine (by (VALID (((THENL_FIRST) (have_tac (move ["f_abs"]) (`abs (f x) < &1`)) ((((USE_THM_THEN interval_arith_abs)MP_TAC) THEN (clear_assumption "interval_arith_abs") THEN (DISCH_THEN apply_tac)) THEN (exists_tac (mk_var("f_bounds",mk_type("prod",[mk_type("real",[]);mk_type("real",[])])))) THEN (done_tac))))));;
1025 refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN derivative_compose_acs)(fun fst_th ->(USE_THEN "df")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "f_abs")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN (exact_tac)))));;
1026 let lin_approx_compose_acs = end_section_proof();;
1027 let lin_approx_compose_acs = finalize_theorem lin_approx_compose_acs;;
1028 let lin_approx_compose_sqrt = finalize_theorem lin_approx_compose_sqrt;;
1029 let lin_approx_compose_inv = finalize_theorem lin_approx_compose_inv;;
1030 let lin_approx_compose_exp = finalize_theorem lin_approx_compose_exp;;
1031 let lin_approx_compose_atn = finalize_theorem lin_approx_compose_atn;;
1032 (end_section "LinearApproxUnivariateComposition");;
1033 (add_section_hyp "approx_f" (`lin_approx f x f_bounds df_bounds`));;
1034 (add_section_hyp "approx_g" (`lin_approx g x g_bounds dg_bounds`));;
1035 (start_section_proof [](`(\x. f x + g x) real_differentiable atreal x`));;
1036 refine (by (VALID ((((USE_THM_THEN REAL_DIFFERENTIABLE_ADD)MP_TAC) THEN (clear_assumption "REAL_DIFFERENTIABLE_ADD") THEN (DISCH_THEN apply_tac)))));;
1037 refine (by (VALID (((((fun thm_tac -> (USE_THM_THEN lin_approx_imp_f_diff)(fun fst_th ->(USE_THEN "approx_f")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] [])) THEN ((fun thm_tac -> (USE_THM_THEN lin_approx_imp_f_diff)(fun fst_th ->(USE_THEN "approx_g")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] []))) THEN (done_tac)))));;
1038 let lin_approx_imp_add_diff = end_section_proof();;
1039 (start_section_proof [](`(\x. f x - g x) real_differentiable atreal x`));;
1040 refine (by (VALID ((((USE_THM_THEN REAL_DIFFERENTIABLE_SUB)MP_TAC) THEN (clear_assumption "REAL_DIFFERENTIABLE_SUB") THEN (DISCH_THEN apply_tac)))));;
1041 refine (by (VALID (((((fun thm_tac -> (USE_THM_THEN lin_approx_imp_f_diff)(fun fst_th ->(USE_THEN "approx_f")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] [])) THEN ((fun thm_tac -> (USE_THM_THEN lin_approx_imp_f_diff)(fun fst_th ->(USE_THEN "approx_g")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] []))) THEN (done_tac)))));;
1042 let lin_approx_imp_sub_diff = end_section_proof();;
1043 (start_section_proof [](`(\x. f x * g x) real_differentiable atreal x`));;
1044 refine (by (VALID ((((USE_THM_THEN REAL_DIFFERENTIABLE_MUL_ATREAL)MP_TAC) THEN (clear_assumption "REAL_DIFFERENTIABLE_MUL_ATREAL") THEN (DISCH_THEN apply_tac)))));;
1045 refine (by (VALID (((((fun thm_tac -> (USE_THM_THEN lin_approx_imp_f_diff)(fun fst_th ->(USE_THEN "approx_f")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] [])) THEN ((fun thm_tac -> (USE_THM_THEN lin_approx_imp_f_diff)(fun fst_th ->(USE_THEN "approx_g")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] []))) THEN (done_tac)))));;
1046 let lin_approx_imp_mul_diff = end_section_proof();;
1047 (start_section_proof [](`interval_not_zero g_bounds ==> (\x. f x / g x) real_differentiable atreal x`));;
1048 refine (by (VALID (((BETA_TAC THEN (move ["gn0"])) THEN (((USE_THM_THEN REAL_DIFFERENTIABLE_DIV_ATREAL)MP_TAC) THEN (clear_assumption "REAL_DIFFERENTIABLE_DIV_ATREAL") THEN (DISCH_THEN apply_tac))))));;
1049 refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN lin_approx_imp_f_diff)(fun fst_th ->(USE_THEN "approx_f")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] [])) THEN ((fun thm_tac -> (USE_THM_THEN lin_approx_imp_f_diff)(fun fst_th ->(USE_THEN "approx_g")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] [])))))));;
1050 refine (by (VALID (((((USE_THM_THEN interval_arith_not_zero)MP_TAC) THEN (clear_assumption "interval_arith_not_zero") THEN (DISCH_THEN apply_tac)) THEN (exists_tac (mk_var("g_bounds",mk_type("prod",[mk_type("real",[]);mk_type("real",[])]))))))));;
1051 refine (by (VALID (((((USE_THEN "approx_g")MP_TAC) THEN (clear_assumption "approx_g") THEN BETA_TAC) THEN (((USE_THM_THEN lin_approx_eq)(new_rewrite [] [])) THEN (DISCH_THEN(new_rewrite [] []))) THEN (done_tac)))));;
1052 let lin_approx_imp_div_diff = end_section_proof();;
1053 let lin_approx_imp_div_diff = finalize_theorem lin_approx_imp_div_diff;;
1054 let lin_approx_imp_mul_diff = finalize_theorem lin_approx_imp_mul_diff;;
1055 let lin_approx_imp_sub_diff = finalize_theorem lin_approx_imp_sub_diff;;
1056 let lin_approx_imp_add_diff = finalize_theorem lin_approx_imp_add_diff;;
1057 let lin_approx_compose_acs = finalize_theorem lin_approx_compose_acs;;
1058 let lin_approx_compose_sqrt = finalize_theorem lin_approx_compose_sqrt;;
1059 let lin_approx_compose_inv = finalize_theorem lin_approx_compose_inv;;
1060 let lin_approx_compose_exp = finalize_theorem lin_approx_compose_exp;;
1061 let lin_approx_compose_atn = finalize_theorem lin_approx_compose_atn;;
1062 let lin_approx_const = finalize_theorem lin_approx_const;;
1063 let lin_approx_x = finalize_theorem lin_approx_x;;
1064 let interval_arith_abs = finalize_theorem interval_arith_abs;;
1065 let interval_arith_pos = finalize_theorem interval_arith_pos;;
1066 let interval_arith_not_zero = finalize_theorem interval_arith_not_zero;;
1067 (end_section "MoreLinearApproximation");;
1068 (begin_section "LinearApproxArith");;
1069 (add_section_var (mk_var ("f1", (`:real->real`))); add_section_var (mk_var ("f2", (`:real->real`))));;
1070 (add_section_var (mk_var ("f1_bounds", (`:real#real`))); add_section_var (mk_var ("f2_bounds", (`:real#real`))));;
1071 (add_section_var (mk_var ("df1_lo", (`:real`))); add_section_var (mk_var ("df1_hi", (`:real`))); add_section_var (mk_var ("df2_lo", (`:real`))); add_section_var (mk_var ("df2_hi", (`:real`))));;
1072 (add_section_var (mk_var ("f_bounds", (`:real#real`))));;
1073 (add_section_var (mk_var ("df_lo", (`:real`))); add_section_var (mk_var ("df_hi", (`:real`))));;
1074 (add_section_var (mk_var ("x", (`:real`))));;
1075 (add_section_hyp "approx1" (`lin_approx f1 x f1_bounds (df1_lo, df1_hi)`));;
1076 (start_section_proof ["c"](`&0 <= c ==> interval_arith (c * f1 x) f_bounds /\
1077         df_lo <= c * df1_lo /\ c * df1_hi <= df_hi ==>
1078         lin_approx (\x. c * f1 x) x f_bounds (df_lo, df_hi)`));;
1079 refine (by (VALID (((((USE_THM_THEN pair_eq)(new_rewrite [] [])) THEN ((USE_THM_THEN interval_arith)(new_rewrite [] []))) THEN (move ["c0"]) THEN (move ["ineqs"])))));;
1080 refine (by (VALID (((((USE_THM_THEN lin_approx)(new_rewrite [] [])) THEN (simp_tac)) THEN (split_tac)))));;
1081 refine (by (VALID ((((USE_THM_THEN pair_eq)(new_rewrite [] [])) THEN (((USE_THEN "ineqs")MP_TAC) THEN (clear_assumption "ineqs") THEN ((USE_THEN "approx1")MP_TAC) THEN (clear_assumption "approx1") THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN lin_approx)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN interval_arith)(new_rewrite [] [])))) THEN (arith_tac) THEN (done_tac)))));;
1082 refine (by (VALID (((((USE_THEN "approx1")MP_TAC) THEN (clear_assumption "approx1") THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN lin_approx)(new_rewrite [] []))) THEN ALL_TAC THEN (case THEN (move ["int_f1"])) THEN (case THEN (move ["f1'"])) THEN (case THEN ((move ["df1"]) THEN (move ["int_f1'"]))))))));;
1083 refine (by (VALID (((exists_tac (`c * f1'`)) THEN (((USE_THM_THEN HAS_REAL_DERIVATIVE_LMUL_ATREAL)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andTb)(new_rewrite [] [])))))));;
1084 refine (by (VALID (((((USE_THEN "int_f1'")MP_TAC) THEN (clear_assumption "int_f1'") THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN interval_arith)(new_rewrite [] []))) THEN (move ["ineqs2"])) THEN (split_tac) THEN (((USE_THM_THEN REAL_LE_TRANS)MP_TAC) THEN (clear_assumption "REAL_LE_TRANS") THEN (DISCH_THEN apply_tac))))));;
1085 refine (by (VALID (((exists_tac (`c * df1_lo`)) THEN (((USE_THEN "ineqs")(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LE_LMUL)(new_rewrite [] []))) THEN (done_tac)))));;
1086 refine (by (VALID (((exists_tac (`c * df1_hi`)) THEN (((USE_THEN "ineqs")(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LE_LMUL)(new_rewrite [] []))) THEN (done_tac)))));;
1087 let lin_approx_scale = end_section_proof();;
1088 (add_section_hyp "approx2" (`lin_approx f2 x f2_bounds (df2_lo, df2_hi)`));;
1089 (start_section_proof [](`interval_arith (f1 x + f2 x) f_bounds /\
1090         df_lo <= df1_lo + df2_lo /\ df1_hi + df2_hi <= df_hi ==>
1091         lin_approx (\x. f1 x + f2 x) x f_bounds (df_lo, df_hi)`));;
1092 refine (by (VALID (((((USE_THM_THEN pair_eq)(new_rewrite [] [])) THEN ((USE_THM_THEN interval_arith)(new_rewrite [] []))) THEN (move ["ineqs"])))));;
1093 refine (by (VALID (((((USE_THM_THEN lin_approx)(new_rewrite [] [])) THEN (simp_tac)) THEN (split_tac)))));;
1094 refine (by (VALID ((((USE_THM_THEN pair_eq)(new_rewrite [] [])) THEN (((USE_THEN "ineqs")MP_TAC) THEN (clear_assumption "ineqs") THEN ((USE_THEN "approx2")MP_TAC) THEN (clear_assumption "approx2") THEN ((USE_THEN "approx1")MP_TAC) THEN (clear_assumption "approx1") THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN lin_approx)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN interval_arith)(new_rewrite [] [])))) THEN (arith_tac) THEN (done_tac)))));;
1095 refine (by (VALID (((((USE_THEN "approx2")MP_TAC) THEN (clear_assumption "approx2") THEN ((USE_THEN "approx1")MP_TAC) THEN (clear_assumption "approx1") THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN lin_approx)(new_rewrite [] []))) THEN ALL_TAC THEN (case THEN (move ["int_f1"])) THEN (case THEN (move ["f1'"])) THEN (case THEN ((move ["df1"]) THEN (move ["int_f1'"]))))))));;
1096 refine (by (VALID ((BETA_TAC THEN (case THEN (move ["int_f2"])) THEN (case THEN (move ["f2'"])) THEN (case THEN ((move ["df2"]) THEN (move ["int_f2'"])))))));;
1097 refine (by (VALID (((exists_tac (`f1' + f2':real`)) THEN (((USE_THM_THEN HAS_REAL_DERIVATIVE_ADD)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andTb)(new_rewrite [] [])))))));;
1098 refine (by (VALID (((((USE_THEN "int_f2'")MP_TAC) THEN (clear_assumption "int_f2'") THEN ((USE_THEN "int_f1'")MP_TAC) THEN (clear_assumption "int_f1'") THEN ((USE_THEN "ineqs")MP_TAC) THEN (clear_assumption "ineqs") THEN BETA_TAC) THEN repeat_tactic 1 9 (((USE_THM_THEN interval_arith)(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac)))));;
1099 let lin_approx_add = end_section_proof();;
1100 let lin_approx_add = finalize_theorem lin_approx_add;;
1101 let lin_approx_scale = finalize_theorem lin_approx_scale;;
1102 (end_section "LinearApproxArith");;
1103 (begin_section "SecondDerivativeBound");;
1104 (add_section_var (mk_var ("f1", (`:real->real`))); add_section_var (mk_var ("f2", (`:real->real`))));;
1105 (add_section_var (mk_var ("int", (`:real#real`))));;
1106 (add_section_var (mk_var ("dd1", (`:real#real`))); add_section_var (mk_var ("dd2", (`:real#real`))));;
1107 (start_section_proof ["f";"x"](`nth_diff_strong 2 f x <=> ?s. real_open s /\ x IN s /\
1108         !y. y IN s ==> (f has_real_derivative derivative f y) (atreal y) /\
1109         (derivative f has_real_derivative nth_derivative 2 f y) (atreal y)`));;
1110 refine (by (VALID ((((USE_THM_THEN nth_diff_strong)(new_rewrite [] [])) THEN ((USE_THM_THEN nth_differentiable_on)(new_rewrite [] [])) THEN ((USE_THM_THEN nth_differentiable_eq)(new_rewrite [] [])) THEN ((USE_THM_THEN (ARITH_RULE `i < 2 <=> i = 0 \/ i = 1`))(new_rewrite [] []))))));;
1111 refine (by (VALID (((split_tac) THEN ALL_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["open_s"])) THEN (case THEN (move ["xs"])) THEN (move ["df"])))));;
1112 refine (by (VALID (((exists_tac (mk_var("s",mk_type("fun",[mk_type("real",[]);mk_type("bool",[])])))) THEN ((((USE_THEN "open_s")(new_rewrite [] [])) THEN ((USE_THEN "xs")(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] [])))) THEN (move ["y"]) THEN (DISCH_THEN (fun snd_th -> (USE_THEN "df")(MATCH_MP_THEN snd_th MP_TAC))) THEN (case THEN (move ["_"])) THEN (move ["h"]))))));;
1113 refine (by (VALID (((((fun thm_tac -> (USE_THEN "h")(ISPEC_THEN (`1`) thm_tac))MP_TAC) THEN ((fun thm_tac -> (USE_THEN "h")(ISPEC_THEN (`0`) thm_tac))MP_TAC) THEN BETA_TAC THEN (simp_tac)) THEN ((((USE_THM_THEN ONE)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN nth_derivative1)(new_rewrite [] [])) THEN ((USE_THM_THEN nth_derivative0)(new_rewrite [] [])) THEN ((USE_THM_THEN TWO)(GSYM_THEN (new_rewrite [] [])))) THEN (DISCH_THEN(new_rewrite [] [])) THEN (DISCH_THEN(new_rewrite [] []))) THEN (done_tac)))));;
1114 refine (by (VALID (((exists_tac (mk_var("s",mk_type("fun",[mk_type("real",[]);mk_type("bool",[])])))) THEN ((((USE_THEN "open_s")(new_rewrite [] [])) THEN ((USE_THEN "xs")(new_rewrite [1] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] [])))) THEN (move ["y"]) THEN (DISCH_THEN (fun snd_th -> (USE_THEN "df")(MATCH_MP_THEN snd_th MP_TAC))) THEN (move ["h"]))))));;
1115 refine (by (VALID ((((USE_THM_THEN REAL_DIFFERENTIABLE_IMP_CONTINUOUS_ATREAL)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN andTb)(new_rewrite [] [])))))));;
1116 refine (by (VALID ((((USE_THM_THEN real_differentiable)(new_rewrite [] [])) THEN (exists_tac (`derivative f y`)) THEN (done_tac)))));;
1117 refine (by (VALID (((BETA_TAC THEN (move ["i"])) THEN (case THEN (DISCH_THEN(new_rewrite [] []))) THEN (repeat_tactic 0 10 (((USE_THM_THEN ONE)(GSYM_THEN (new_rewrite [] [])))) THEN repeat_tactic 0 10 (((USE_THM_THEN TWO)(GSYM_THEN (new_rewrite [] [])))) THEN repeat_tactic 1 9 (((fun thm_tac ->(USE_THM_THEN nth_derivative0)(fun tmp_th1 -> (USE_THM_THEN nth_derivative1)(fun tmp_th2 -> thm_tac (CONJ tmp_th1 tmp_th2))))(new_rewrite [] [])))) THEN (done_tac)))));;
1118 let nth_diff_strong2_eq_alt = end_section_proof();;
1119 (start_section_proof ["f";"x"](`nth_diff_strong 2 f x <=> ?s. real_open s /\ x IN s /\
1120         !y. y IN s ==> f real_differentiable atreal y /\ derivative f real_differentiable atreal y`));;
1121 refine (by (VALID ((((USE_THM_THEN nth_diff_strong)(new_rewrite [] [])) THEN ((USE_THM_THEN nth_differentiable_on)(new_rewrite [] [])) THEN ((USE_THM_THEN TWO)(new_rewrite [] [])) THEN ((USE_THM_THEN ONE)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN (GEN_ALL nth_differentiable))(new_rewrite [] [])))))));;
1122 refine (by (VALID ((((USE_THM_THEN ONE)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN nth_derivative0)(new_rewrite [] [])) THEN ((USE_THM_THEN nth_derivative1)(new_rewrite [] []))))));;
1123 refine (by (VALID (((split_tac) THEN ALL_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["open_s"])) THEN (case THEN (move ["xs"])) THEN (move ["df"])))));;
1124 refine (by (VALID (((exists_tac (mk_var("s",mk_type("fun",[mk_type("real",[]);mk_type("bool",[])])))) THEN ((((USE_THEN "open_s")(new_rewrite [] [])) THEN ((USE_THEN "xs")(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] [])))) THEN (move ["y"]) THEN (DISCH_THEN (fun snd_th -> (USE_THEN "df")(MATCH_MP_THEN snd_th MP_TAC))) THEN (move ["h"])) THEN (done_tac)))));;
1125 refine (by (VALID (((exists_tac (mk_var("s",mk_type("fun",[mk_type("real",[]);mk_type("bool",[])])))) THEN ((((USE_THEN "open_s")(new_rewrite [] [])) THEN ((USE_THEN "xs")(new_rewrite [1] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] [])))) THEN (move ["y"]) THEN (DISCH_THEN (fun snd_th -> (USE_THEN "df")(MATCH_MP_THEN snd_th MP_TAC))) THEN (move ["h"]))))));;
1126 refine (by (VALID (((repeat_tactic 1 9 (((USE_THEN "h")(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_DIFFERENTIABLE_IMP_CONTINUOUS_ATREAL)(new_rewrite [] []))) THEN (done_tac)))));;
1127 let nth_diff_strong2_eq = end_section_proof();;
1128 (start_section_proof ["f";"g";"y";"g_bounds";"f_bounds";"d_bounds"](`nth_diff_strong_int 2 g_bounds f ==>
1129           g real_differentiable atreal y ==>
1130           interval_arith (g y) g_bounds ==>
1131           bounded_on_int f g_bounds f_bounds ==>
1132           interval_arith (derivative g y * derivative f (g y)) d_bounds ==>
1133           lin_approx (\x. f (g x)) y f_bounds d_bounds`));;
1134 refine (by (VALID (((((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] [])) THEN ((USE_THM_THEN nth_diff_strong2_eq)(new_rewrite [] [])) THEN ((USE_THM_THEN bounded_on_int)(new_rewrite [] []))) THEN (move ["df"]) THEN (move ["dg"]) THEN (move ["g_int"]) THEN (move ["f_int"]) THEN (move ["dfg_int"])))));;
1135 refine (by (VALID ((have_tac (move ["dfgy"]) (`f real_differentiable atreal (g y)`)))));;
1136 refine (by (VALID (((((fun thm_tac -> (USE_THEN "df")(fun fst_th ->(USE_THEN "g_int")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["open_s"])) THEN (case THEN (move ["ys"])) THEN (DISCH_THEN(new_rewrite [] []))) THEN (done_tac)))));;
1137 refine (by (VALID ((((USE_THM_THEN lin_approx_eq)(new_rewrite [] [])) THEN ((USE_THM_THEN derivative_composition)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THEN "dfg_int")(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THEN "f_int")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andbT)(new_rewrite [] []))))));;
1138 refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN o_THM)(ISPEC_THEN (mk_var("f",mk_type("fun",[mk_type("real",[]);mk_type("real",[])]))) thm_tac))(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN (((USE_THM_THEN REAL_DIFFERENTIABLE_COMPOSE_ATREAL)MP_TAC) THEN (clear_assumption "REAL_DIFFERENTIABLE_COMPOSE_ATREAL") THEN (exact_tac)) THEN (done_tac)))));;
1139 let lin_approx_compose = end_section_proof();;
1140 (start_section_proof ["x"](`((\x. inv (&1 + x pow 2)) has_real_derivative 
1141         (-- &2 * x) * inv (&1 + x pow 2) pow 2) (atreal x)`));;
1142 refine (by (VALID (((((USE_THM_THEN REAL_POW_INV)(new_rewrite [] [])) THEN ((USE_THM_THEN real_div)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN REAL_NEG_LMUL)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN HAS_REAL_DERIVATIVE_INV_ATREAL)(new_rewrite [] []))) THEN (split_tac)))));;
1143 refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN REAL_ADD_LID)(ISPEC_THEN (`&2 * x`) thm_tac))(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN HAS_REAL_DERIVATIVE_ADD)(new_rewrite [] [])) THEN ((USE_THM_THEN HAS_REAL_DERIVATIVE_CONST)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))))));;
1144 refine (by (VALID ((((USE_THM_THEN REAL_POW_2)(new_rewrite [] [])) THEN ((USE_THM_THEN (REAL_ARITH `&2 * x = x * &1 + &1 * x`))(new_rewrite [] []))))));;
1145 refine (by (VALID (((((USE_THM_THEN HAS_REAL_DERIVATIVE_MUL_ATREAL)(new_rewrite [] [])) THEN ((USE_THM_THEN HAS_REAL_DERIVATIVE_ID)(new_rewrite [] []))) THEN (done_tac)))));;
1146 refine (by (VALID (((((USE_THM_THEN REAL_POS_NZ)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN REAL_ADD_SYM)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LT_ADD1)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LE_POW_2)(new_rewrite [] []))) THEN (done_tac)))));;
1147 let second_derivative_atn_eq = end_section_proof();;
1148 (start_section_proof [](`derivative (derivative atn) = (\x. (-- &2 * x) * inv (&1 + x pow 2) pow 2)`));;
1149 refine (by (VALID ((((((USE_THM_THEN derivative_atn)(new_rewrite [] [])) THEN ((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] [])))) THEN (move ["x"]) THEN (simp_tac)) THEN (((USE_THM_THEN derivative_unique)MP_TAC) THEN (clear_assumption "derivative_unique") THEN (DISCH_THEN apply_tac))))));;
1150 refine (by (VALID (((((USE_THM_THEN REAL_POW_2)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN second_derivative_atn_eq)(new_rewrite [] []))) THEN (done_tac)))));;
1151 let second_derivative_atn = end_section_proof();;
1152 (start_section_proof ["x"](`nth_diff_strong 2 atn x`));;
1153 refine (by (VALID ((((USE_THM_THEN nth_diff_strong2_eq_alt)(new_rewrite [] [])) THEN (exists_tac (`(:real)`))))));;
1154 refine (by (VALID (((((USE_THM_THEN IN_UNIV)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_OPEN_UNIV)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] []))) THEN ((USE_THM_THEN IN_UNIV)(new_rewrite [] []))) THEN (move ["y"]) THEN (simp_tac)))));;
1155 refine (by (VALID ((((USE_THM_THEN derivative_atn)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_POW_2)(GSYM_THEN (new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN HAS_REAL_DERIVATIVE_ATN)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))))));;
1156 refine (by (VALID (((((USE_THM_THEN nth_derivative2)(new_rewrite [] [])) THEN ((USE_THM_THEN second_derivative_atn)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN second_derivative_atn_eq)(new_rewrite [] []))) THEN (done_tac)))));;
1157 let diff2_atn = end_section_proof();;
1158 (start_section_proof ["x"](`~(x = &0) ==> nth_derivative 2 inv x = &2 * inv (x pow 3)`));;
1159 refine (by (VALID ((((USE_THM_THEN nth_derivative2)(new_rewrite [] [])) THEN (move ["xn0"])))));;
1160 refine (by (VALID (((((USE_THM_THEN derivative_unique)MP_TAC) THEN (clear_assumption "derivative_unique") THEN (DISCH_THEN apply_tac)) THEN (((USE_THM_THEN Arc_properties.HAS_REAL_DERIVATIVE_LOCAL)MP_TAC) THEN (clear_assumption "Arc_properties.HAS_REAL_DERIVATIVE_LOCAL") THEN (DISCH_THEN apply_tac))))));;
1161 refine (by (VALID (((exists_tac (`(\x. -- inv (x * x))`)) THEN (split_tac)))));;
1162 refine (by (VALID ((((USE_THM_THEN ((DISCH_ALL o REAL_DIFF_CONV) `((\x. -- inv(x * x)) has_real_derivative f) (atreal x)`))MP_TAC) THEN BETA_TAC))));;
1163 refine (by (VALID ((((USE_THM_THEN REAL_ENTIRE)(new_rewrite [] [])) THEN ((USE_THEN "xn0")(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN real_div)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_LNEG)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_NEG_NEG)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_LID)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_RID)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_2)(GSYM_THEN (new_rewrite [] [])))))));;
1164 refine (by (VALID ((((USE_THM_THEN (REAL_ARITH `(x * x) pow 2 = x * x pow 3`))(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_INV_MUL)(new_rewrite [] [])))))));;
1165 refine (by (VALID (((((USE_THM_THEN (REAL_ARITH `!a. (&2 * x) * inv x * a = &2 * (x * inv x) * a`))(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_RINV)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_MUL_LID)(new_rewrite [] [])))) THEN (done_tac)))));;
1166 refine (by (VALID ((exists_tac (`real_interval (x - abs x, x + abs x)`)))));;
1167 refine (by (VALID (((((USE_THM_THEN REAL_OPEN_REAL_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] [])))) THEN ((split_tac) THENL [ALL_TAC; ((move ["y"]) THEN (move ["ineq"]))])))));;
1168 refine (by (VALID (((((USE_THEN "xn0")MP_TAC) THEN (clear_assumption "xn0") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
1169 refine (by (VALID ((((USE_THM_THEN derivative_inv)(new_rewrite [] [])) THEN ((simp_tac THEN TRY done_tac))))));;
1170 refine (by (VALID (((((USE_THEN "xn0")MP_TAC) THEN (clear_assumption "xn0") THEN ((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
1171 let second_derivative_inv = end_section_proof();;
1172 (start_section_proof ["x"](`~(x = &0) ==> nth_diff_strong 2 inv x`));;
1173 refine (by (VALID ((((USE_THM_THEN nth_diff_strong2_eq)(new_rewrite [] [])) THEN (move ["xn0"])))));;
1174 refine (by (VALID ((exists_tac (`real_interval (x - abs x, x + abs x)`)))));;
1175 refine (by (VALID (((((USE_THM_THEN REAL_OPEN_REAL_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] [])))) THEN ((split_tac) THENL [ALL_TAC; ((move ["y"]) THEN (move ["ineq"]))])))));;
1176 refine (by (VALID (((((USE_THEN "xn0")MP_TAC) THEN (clear_assumption "xn0") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
1177 refine (by (VALID (((THENL_FIRST) (((USE_THM_THEN REAL_DIFFERENTIABLE_AT_INV)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN andTb)(new_rewrite [] [])))) ((((USE_THEN "xn0")MP_TAC) THEN (clear_assumption "xn0") THEN ((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac))))));;
1178 refine (by (VALID (((((USE_THM_THEN differentiable_local)MP_TAC) THEN (clear_assumption "differentiable_local") THEN (DISCH_THEN apply_tac)) THEN ((exists_tac (`\x. --inv (x * x)`)) THEN (exists_tac (`real_interval (y - abs y, y + abs y)`)))))));;
1179 refine (by (VALID (((((USE_THM_THEN REAL_OPEN_REAL_INTERVAL)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] []))) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (split_tac)))));;
1180 refine (by (VALID ((((USE_THM_THEN REAL_DIFFERENTIABLE_NEG)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_DIFFERENTIABLE_INV_ATREAL)(new_rewrite [] []))))));;
1181 refine (by (VALID ((((USE_THM_THEN REAL_DIFFERENTIABLE_MUL_ATREAL)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_DIFFERENTIABLE_ID)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN REAL_ENTIRE)(new_rewrite [] []))))));;
1182 refine (by (VALID (((((USE_THEN "xn0")MP_TAC) THEN (clear_assumption "xn0") THEN ((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
1183 refine (by (VALID (((split_tac) THENL [ALL_TAC; ((move ["z"]) THEN (move ["ineq2"]))]))));;
1184 refine (by (VALID (((((USE_THEN "xn0")MP_TAC) THEN (clear_assumption "xn0") THEN ((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
1185 refine (by (VALID (((((USE_THM_THEN derivative_inv)(new_rewrite [] [])) THEN ((TRY done_tac))) THEN (((USE_THEN "xn0")MP_TAC) THEN (clear_assumption "xn0") THEN ((USE_THEN "ineq2")MP_TAC) THEN (clear_assumption "ineq2") THEN ((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
1186 let diff2_inv = end_section_proof();;
1187 (start_section_proof ["x";"n"](`&0 <= x ==> sqrt x pow n = sqrt (x pow n)`));;
1188 refine (by (VALID (((BETA_TAC THEN (move ["ineq"])) THEN ((disch_tm_tac [](mk_var("n",mk_type("num",[])))) THEN (clear_assumption "n") THEN elim THENL [ALL_TAC; ((move ["n"]) THEN (move ["IHn"]))]) THEN (repeat_tactic 1 9 (((USE_THM_THEN (GEN_ALL real_pow))(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN SQRT_1)(new_rewrite [] []))) THEN ((TRY done_tac)))))));;
1189 refine (by (VALID (((((USE_THEN "IHn")(new_rewrite [] [])) THEN ((USE_THM_THEN SQRT_MUL)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN REAL_POW_LE)(new_rewrite [] []))) THEN (done_tac)))));;
1190 let SQRT_POW = end_section_proof();;
1191 (start_section_proof ["x"](`&0 < x ==> nth_derivative 2 sqrt x = -- inv(&4 * sqrt (x pow 3))`));;
1192 refine (by (VALID ((((USE_THM_THEN nth_derivative2)(new_rewrite [] [])) THEN (move ["x_pos"])))));;
1193 refine (by (VALID (((((USE_THM_THEN derivative_unique)MP_TAC) THEN (clear_assumption "derivative_unique") THEN (DISCH_THEN apply_tac)) THEN (((USE_THM_THEN Arc_properties.HAS_REAL_DERIVATIVE_LOCAL)MP_TAC) THEN (clear_assumption "Arc_properties.HAS_REAL_DERIVATIVE_LOCAL") THEN (DISCH_THEN apply_tac))))));;
1194 refine (by (VALID (((exists_tac (`(\x. inv (&2 * sqrt x))`)) THEN (split_tac)))));;
1195 refine (by (VALID ((((USE_THM_THEN ((DISCH_ALL o REAL_DIFF_CONV) `((\x. inv(&2 * sqrt x)) has_real_derivative f) (atreal x)`))MP_TAC) THEN BETA_TAC))));;
1196 refine (by (VALID ((have_tac (move ["ineq"]) (`~(&2 * sqrt x = &0)`)))));;
1197 refine (by (VALID (((((USE_THM_THEN REAL_ENTIRE)(new_rewrite [] [])) THEN ((USE_THM_THEN negb_or)(new_rewrite [] [])) THEN ((USE_THM_THEN SQRT_EQ_0)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_LT_IMP_LE)(new_rewrite [] []))) THEN ((TRY done_tac))) THEN (((USE_THEN "x_pos")MP_TAC) THEN (clear_assumption "x_pos") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
1198 refine (by (VALID ((((USE_THEN "x_pos")(new_rewrite [] [])) THEN ((USE_THEN "ineq")(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN real_div)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_INV_POW)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_LID)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_LNEG)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN REAL_MUL_ASSOC)(GSYM_THEN (new_rewrite [] [])))))));;
1199 refine (by (VALID ((((USE_THM_THEN (GEN_ALL real_pow))(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN REAL_INV_POW)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN REAL_POW_MUL)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_INV_MUL)(new_rewrite [] []))) THEN ((USE_THM_THEN SQRT_POW)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_LT_IMP_LE)(new_rewrite [] []))) THEN ((TRY done_tac))))));;
1200 refine (by (VALID ((((USE_THM_THEN REAL_MUL_ASSOC)(new_rewrite [] [])) THEN ((USE_THM_THEN (GEN_ALL real_pow))(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_LNEG)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_INV_MUL)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_ASSOC)(new_rewrite [] []))))));;
1201 refine (by (VALID (((THENL_FIRST) (((USE_THM_THEN REAL_MUL_RINV)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_MUL_LID)(new_rewrite [] [])))) ((arith_tac) THEN (done_tac))))));;
1202 refine (by (VALID (((((USE_THM_THEN REAL_MUL_LNEG)(new_rewrite [] [])) THEN ((USE_THM_THEN (REAL_ARITH `&2 pow 2 = &4`))(new_rewrite [] [])) THEN ((USE_THM_THEN (ARITH_RULE `SUC 2 = 3`))(new_rewrite [] []))) THEN (done_tac)))));;
1203 refine (by (VALID ((exists_tac (`real_interval (&0, x + &1)`)))));;
1204 refine (by (VALID (((((USE_THM_THEN REAL_OPEN_REAL_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] [])))) THEN ((split_tac) THENL [ALL_TAC; ((move ["y"]) THEN (move ["ineq"]))])))));;
1205 refine (by (VALID (((((USE_THEN "x_pos")MP_TAC) THEN (clear_assumption "x_pos") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
1206 refine (by (VALID ((((USE_THM_THEN derivative_sqrt)(new_rewrite [] [])) THEN (done_tac)))));;
1207 let second_derivative_sqrt = end_section_proof();;
1208 (start_section_proof ["x"](`&0 < x ==> nth_diff_strong 2 sqrt x`));;
1209 refine (by (VALID ((((USE_THM_THEN nth_diff_strong2_eq)(new_rewrite [] [])) THEN (move ["x_pos"])))));;
1210 refine (by (VALID ((exists_tac (`real_interval (&0, x + &1)`)))));;
1211 refine (by (VALID (((((USE_THM_THEN REAL_OPEN_REAL_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] [])))) THEN ((split_tac) THENL [ALL_TAC; ((move ["y"]) THEN (move ["ineq"]))])))));;
1212 refine (by (VALID (((((USE_THEN "x_pos")MP_TAC) THEN (clear_assumption "x_pos") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
1213 refine (by (VALID (((THENL_FIRST) (((USE_THM_THEN REAL_DIFFERENTIABLE_AT_SQRT)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN andTb)(new_rewrite [] [])))) ((((USE_THEN "x_pos")MP_TAC) THEN (clear_assumption "x_pos") THEN ((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac))))));;
1214 refine (by (VALID (((((USE_THM_THEN differentiable_local)MP_TAC) THEN (clear_assumption "differentiable_local") THEN (DISCH_THEN apply_tac)) THEN ((exists_tac (`\x. inv (&2 * sqrt x)`)) THEN (exists_tac (`real_interval (&0, y + &1)`)))))));;
1215 refine (by (VALID (((((USE_THM_THEN REAL_OPEN_REAL_INTERVAL)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] []))) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (split_tac)))));;
1216 refine (by (VALID ((((USE_THM_THEN REAL_DIFFERENTIABLE_INV_ATREAL)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_DIFFERENTIABLE_MUL_ATREAL)(new_rewrite [] []))))));;
1217 refine (by (VALID (((((USE_THM_THEN REAL_DIFFERENTIABLE_CONST)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_DIFFERENTIABLE_AT_SQRT)(new_rewrite [] []))) THEN (done_tac)))));;
1218 refine (by (VALID (((((USE_THM_THEN REAL_ENTIRE)(new_rewrite [] [])) THEN ((USE_THM_THEN SQRT_EQ_0)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_LT_IMP_LE)(new_rewrite [] []))) THEN ((TRY done_tac))) THEN (((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
1219 refine (by (VALID (((THENL_FIRST) ((split_tac) THENL [ALL_TAC; ((move ["z"]) THEN (move ["ineq2"]))]) ((((USE_THEN "x_pos")MP_TAC) THEN (clear_assumption "x_pos") THEN ((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac))))));;
1220 refine (by (VALID ((((USE_THM_THEN derivative_sqrt)(new_rewrite [] [])) THEN (done_tac)))));;
1221 let diff2_sqrt = end_section_proof();;
1222 (start_section_proof ["x";"n"](`x pow (SUC n) = x * x pow n`));;
1223 refine (by (VALID ((((USE_THM_THEN real_pow)(new_rewrite [] [])) THEN (done_tac)))));;
1224 let real_powS = end_section_proof();;
1225 (start_section_proof ["x"](`abs x < &1 ==> 
1226         nth_derivative 2 acs x = --(x / sqrt ((&1 - x * x) pow 3))`));;
1227 refine (by (VALID ((((USE_THM_THEN nth_derivative2)(new_rewrite [] [])) THEN (move ["x_ineq"])))));;
1228 refine (by (VALID (((((USE_THM_THEN derivative_unique)MP_TAC) THEN (clear_assumption "derivative_unique") THEN (DISCH_THEN apply_tac)) THEN (((USE_THM_THEN Arc_properties.HAS_REAL_DERIVATIVE_LOCAL)MP_TAC) THEN (clear_assumption "Arc_properties.HAS_REAL_DERIVATIVE_LOCAL") THEN (DISCH_THEN apply_tac))))));;
1229 refine (by (VALID (((exists_tac (`\x. --inv (sqrt (&1 - x * x))`)) THEN (split_tac)))));;
1230 refine (by (VALID ((((USE_THM_THEN ((DISCH_ALL o REAL_DIFF_CONV) `((\x. --inv (sqrt (&1 - x * x))) has_real_derivative f) (atreal x)`))MP_TAC) THEN BETA_TAC))));;
1231 refine (by (VALID ((have_tac (move ["ineqs"]) (`&0 < &1 - x * x /\ ~(sqrt(&1 - x * x) = &0)`)))));;
1232 refine (by (VALID ((((THENL_ROT 1)) (have_tac (move ["h"]) (`&0 < &1 - x * x`))))));;
1233 refine (by (VALID (((((USE_THM_THEN SQRT_EQ_0)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_LT_IMP_LE)(new_rewrite [] []))) THEN ((TRY done_tac))) THEN (((USE_THEN "h")MP_TAC) THEN (clear_assumption "h") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
1234 refine (by (VALID ((((USE_THM_THEN (REAL_ARITH `&1 - x * x = (&1 - x) * (&1 + x)`))(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LT_MUL)(new_rewrite [] []))))));;
1235 refine (by (VALID (((((USE_THEN "x_ineq")MP_TAC) THEN (clear_assumption "x_ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
1236 refine (by (VALID ((repeat_tactic 1 9 (((USE_THEN "ineqs")(new_rewrite [] []))) THEN (simp_tac) THEN repeat_tactic 1 9 (((USE_THM_THEN real_div)(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_INV_MUL)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_SUB_LZERO)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_MUL_LNEG)(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_NEG_NEG)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_MUL_ASSOC)(GSYM_THEN (new_rewrite [] []))))))));;
1237 refine (by (VALID ((((USE_THM_THEN REAL_INV_MUL)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN real_powS)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN SQRT_POW)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_LT_IMP_LE)(new_rewrite [] []))) THEN ((TRY done_tac))))));;
1238 refine (by (VALID ((((USE_THM_THEN REAL_MUL_LID)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_RID)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_2)(GSYM_THEN (new_rewrite [] [])))))));;
1239 refine (by (VALID ((((USE_THM_THEN (REAL_ARITH `!a. (&2 * x) * inv (&2) * a = (&2 * inv (&2)) * x * a`))(new_rewrite [] [])) THEN ((USE_THM_THEN (ARITH_RULE `SUC 2 = 3`))(new_rewrite [] []))))));;
1240 refine (by (VALID (((((USE_THM_THEN REAL_MUL_RINV)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_MUL_LID)(new_rewrite [] [])))) THEN (arith_tac) THEN (done_tac)))));;
1241 refine (by (VALID ((set_tac "e" (`&1 - abs x`)))));;
1242 refine (by (VALID ((exists_tac (`real_interval (x - e, x + e)`)))));;
1243 refine (by (VALID (((((USE_THM_THEN REAL_OPEN_REAL_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] [])))) THEN ((split_tac) THENL [ALL_TAC; ((move ["y"]) THEN (move ["ineq"]))])))));;
1244 refine (by (VALID (((((USE_THEN "e_def")MP_TAC) THEN (clear_assumption "e_def") THEN ((USE_THEN "x_ineq")MP_TAC) THEN (clear_assumption "x_ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
1245 refine (by (VALID ((((USE_THM_THEN derivative_acs)(new_rewrite [] [])) THEN ((simp_tac THEN TRY done_tac))))));;
1246 refine (by (VALID (((((USE_THEN "e_def")MP_TAC) THEN (clear_assumption "e_def") THEN ((USE_THEN "x_ineq")MP_TAC) THEN (clear_assumption "x_ineq") THEN ((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
1247 let second_derivative_acs = end_section_proof();;
1248 (start_section_proof ["x"](`abs x < &1 ==> nth_diff_strong 2 acs x`));;
1249 refine (by (VALID ((((USE_THM_THEN nth_diff_strong2_eq)(new_rewrite [] [])) THEN (move ["x_ineq"])))));;
1250 refine (by (VALID ((set_tac "e" (`&1 - abs x`)))));;
1251 refine (by (VALID ((exists_tac (`real_interval (x - e, x + e)`)))));;
1252 refine (by (VALID (((((USE_THM_THEN REAL_OPEN_REAL_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] [])))) THEN ((split_tac) THENL [ALL_TAC; ((move ["y"]) THEN (move ["ineq"]))])))));;
1253 refine (by (VALID (((((USE_THEN "e_def")MP_TAC) THEN (clear_assumption "e_def") THEN ((USE_THEN "x_ineq")MP_TAC) THEN (clear_assumption "x_ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
1254 refine (by (VALID (((THENL_FIRST) (((USE_THM_THEN REAL_DIFFERENTIABLE_AT_ACS)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN andTb)(new_rewrite [] [])))) ((((USE_THEN "e_def")MP_TAC) THEN (clear_assumption "e_def") THEN ((USE_THEN "x_ineq")MP_TAC) THEN (clear_assumption "x_ineq") THEN ((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac))))));;
1255 refine (by (VALID ((set_tac "e2" (`&1 - abs y`)))));;
1256 refine (by (VALID (((((USE_THM_THEN differentiable_local)MP_TAC) THEN (clear_assumption "differentiable_local") THEN (DISCH_THEN apply_tac)) THEN ((exists_tac (`\x. --inv (sqrt (&1 - x * x))`)) THEN (exists_tac (`real_interval (y - e2, y + e2)`)))))));;
1257 refine (by (VALID (((((USE_THM_THEN REAL_OPEN_REAL_INTERVAL)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] []))) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (split_tac)))));;
1258 refine (by (VALID ((((USE_THM_THEN REAL_DIFFERENTIABLE_NEG)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_DIFFERENTIABLE_INV_ATREAL)(new_rewrite [] []))))));;
1259 refine (by (VALID ((have_tac (move ["gt0"]) (`&0 < &1 - y * y`)))));;
1260 refine (by (VALID (((((USE_THM_THEN (REAL_ARITH `&1 - y * y = (&1 - y) * (&1 + y)`))(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LT_MUL)(new_rewrite [] []))) THEN (((USE_THEN "e_def")MP_TAC) THEN (clear_assumption "e_def") THEN ((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
1261 refine (by (VALID ((((USE_THM_THEN SQRT_EQ_0)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_LT_IMP_LE)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN REAL_LT_IMP_NZ)(new_rewrite [] [])) THEN ((simp_tac THEN TRY done_tac))))));;
1262 refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`(\x. sqrt (&1 - x * x)) = sqrt o (\x. &1 - x * x)`)))));;
1263 refine (by (VALID (((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN o_THM)(new_rewrite [] [])) THEN (simp_tac)) THEN (done_tac)))));;
1264 refine (by (VALID ((((USE_THM_THEN REAL_DIFFERENTIABLE_COMPOSE_ATREAL)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_DIFFERENTIABLE_AT_SQRT)(new_rewrite [] [])) THEN ((TRY done_tac))))));;
1265 refine (by (VALID ((((USE_THM_THEN REAL_DIFFERENTIABLE_SUB)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN REAL_DIFFERENTIABLE_CONST)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_DIFFERENTIABLE_MUL_ATREAL)(new_rewrite [] [])) THEN ((TRY done_tac))))));;
1266 refine (by (VALID ((((USE_THM_THEN REAL_DIFFERENTIABLE_ID)(new_rewrite [] [])) THEN (done_tac)))));;
1267 refine (by (VALID (((split_tac) THENL [ALL_TAC; ((move ["z"]) THEN (move ["ineq2"]))]))));;
1268 refine (by (VALID (((((USE_THEN "e2_def")MP_TAC) THEN (clear_assumption "e2_def") THEN ((USE_THEN "e_def")MP_TAC) THEN (clear_assumption "e_def") THEN ((USE_THEN "x_ineq")MP_TAC) THEN (clear_assumption "x_ineq") THEN ((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
1269 refine (by (VALID ((((USE_THM_THEN derivative_acs)(new_rewrite [] [])) THEN ((simp_tac THEN TRY done_tac))))));;
1270 refine (by (VALID (((((USE_THEN "ineq2")MP_TAC) THEN (clear_assumption "ineq2") THEN ((USE_THEN "e2_def")MP_TAC) THEN (clear_assumption "e2_def") THEN ((USE_THEN "e_def")MP_TAC) THEN (clear_assumption "e_def") THEN ((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN ((USE_THEN "x_ineq")MP_TAC) THEN (clear_assumption "x_ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
1271 let diff2_acs = end_section_proof();;
1272 (begin_section "SecondDerivativeCompose");;
1273 (start_section_proof ["f";"s";"t"](`f real_continuous_on s ==> real_open s ==> real_open t ==>
1274         real_open {x | x IN s /\ f x IN t}`));;
1275 refine (by (VALID ((BETA_TAC THEN (move ["f_cont"]) THEN (move ["open_s"]) THEN (move ["open_t"])))));;
1276 refine (by (VALID (((USE_THM_THEN REAL_OPEN)(new_rewrite [] [])))));;
1277 refine (by (VALID ((((THENL_ROT 1)) (have_tac (DISCH_THEN(new_rewrite [] [])) (`IMAGE lift {x | x IN s /\ f x IN t} = 
1278         {x | x IN (IMAGE lift s) /\ (lift o f o drop) x IN (IMAGE lift t)}`))))));;
1279 refine (by (VALID (((((USE_THM_THEN CONTINUOUS_OPEN_PREIMAGE)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_OPEN)(GSYM_THEN (new_rewrite [] []))))) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN ((USE_THM_THEN REAL_CONTINUOUS_ON)(GSYM_THEN (new_rewrite [] []))) THEN (done_tac)))));;
1280 refine (by (VALID ((((((USE_THM_THEN EXTENSION)(new_rewrite [] [])) THEN ((USE_THM_THEN IN_IMAGE_LIFT_DROP)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_ELIM_THM)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_IMAGE_LIFT_DROP)(new_rewrite [] [])))) THEN (move ["z"]) THEN (simp_tac)) THEN (split_tac)))));;
1281 refine (by (VALID (((BETA_TAC THEN (case THEN (move ["x"])) THEN (case THEN (move ["x_in"])) THEN (move ["x_eq"])) THEN (exists_tac (`lift x`))))));;
1282 refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN LIFT_DROP)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THEN "x_in")(new_rewrite [] []))) THEN ((USE_THEN "x_eq")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN LIFT_DROP)(new_rewrite [] []))) THEN (done_tac)))));;
1283 refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN ((USE_THM_THEN LIFT_DROP)(new_rewrite [] []))) THEN ALL_TAC THEN (case THEN (move ["x"])) THEN (case THEN (move ["x_in"])) THEN (move ["x_eq"])))));;
1284 refine (by (VALID (((exists_tac (`drop x`)) THEN (done_tac)))));;
1285 let REAL_CONTINUOUS_OPEN_PREIMAGE = end_section_proof();;
1286 (start_section_proof ["f";"g";"x"](`nth_diff_strong 2 g x ==> nth_diff_strong 2 f (g x) ==>
1287         nth_derivative 2 (\x. f (g x)) x = 
1288         nth_derivative 2 f (g x) * (derivative g x) pow 2 + derivative f (g x) * nth_derivative 2 g x`));;
1289 refine (by (VALID ((BETA_TAC THEN (move ["dg"]) THEN (move ["df"])))));;
1290 refine (by (VALID ((((USE_THM_THEN nth_derivative2)(new_rewrite [] [])) THEN (((USE_THM_THEN derivative_unique)MP_TAC) THEN (clear_assumption "derivative_unique") THEN (DISCH_THEN apply_tac)) THEN (((USE_THM_THEN Arc_properties.HAS_REAL_DERIVATIVE_LOCAL)MP_TAC) THEN (clear_assumption "Arc_properties.HAS_REAL_DERIVATIVE_LOCAL") THEN (DISCH_THEN apply_tac))))));;
1291 refine (by (VALID (((THENL_ROT (-1)) ((exists_tac (`\x. derivative f (g x) * derivative g x`)) THEN (split_tac))))));;
1292 refine (by (VALID (((((USE_THEN "dg")MP_TAC) THEN ((USE_THEN "df")MP_TAC) THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong2_eq)(new_rewrite [] []))) THEN ALL_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["open_s"])) THEN (case THEN (move ["gxs"])) THEN (move ["d_f"]) THEN (case THEN (move ["t"])) THEN (case THEN (move ["open_t"])) THEN (case THEN (move ["xt"])) THEN (move ["d_g"]))))));;
1293 refine (by (VALID ((set_tac "s'" (`{z | z IN t /\ g z IN s}`)))));;
1294 refine (by (VALID ((have_tac (move ["open_s'"]) (`real_open s'`)))));;
1295 refine (by (VALID ((((USE_THEN "s'_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN REAL_CONTINUOUS_OPEN_PREIMAGE)(new_rewrite [] [])) THEN ((USE_THEN "open_t")(new_rewrite [] [])) THEN ((USE_THEN "open_s")(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andbT)(new_rewrite [] [])))))));;
1296 refine (by (VALID (((((USE_THM_THEN REAL_CONTINUOUS_ON_EQ_REAL_CONTINUOUS_AT)(new_rewrite [] [])) THEN ((TRY done_tac))) THEN (move ["y"]) THEN (move ["yt"])))));;
1297 refine (by (VALID (((((USE_THM_THEN REAL_DIFFERENTIABLE_IMP_CONTINUOUS_ATREAL)(new_rewrite [] [])) THEN ((USE_THEN "d_g")(new_rewrite [] []))) THEN (done_tac)))));;
1298 refine (by (VALID (((exists_tac (`t INTER s'`)) THEN (((USE_THM_THEN REAL_OPEN_INTER)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_INTER)(new_rewrite [] []))) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (split_tac)))));;
1299 refine (by (VALID (((((USE_THEN "s'_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN IN_ELIM_THM)(new_rewrite [] [])) THEN ((USE_THEN "xt")(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] [])) THEN (simp_tac)) THEN (exists_tac (mk_var("x",mk_type("real",[])))) THEN (done_tac)))));;
1300 refine (by (VALID (((BETA_TAC THEN (move ["y"]) THEN (case THEN ((move ["yt"]) THEN (move ["ys'"])))) THEN (((USE_THM_THEN derivative_composition)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_MUL_SYM)(new_rewrite [] []))) THEN ((TRY done_tac)))))));;
1301 refine (by (VALID (((((USE_THEN "d_g")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THEN "d_f")(new_rewrite [] [])) THEN ((TRY done_tac))) THEN (((USE_THEN "ys'")MP_TAC) THEN (clear_assumption "ys'") THEN BETA_TAC) THEN ((((USE_THEN "s'_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN IN_ELIM_THM)(new_rewrite [] []))) THEN ALL_TAC THEN (case THEN (move ["z"])) THEN (simp_tac)) THEN (done_tac)))));;
1302 refine (by (VALID (((((USE_THEN "dg")MP_TAC) THEN (clear_assumption "dg") THEN ((USE_THEN "df")MP_TAC) THEN (clear_assumption "df") THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong2_eq_alt)(new_rewrite [] []))) THEN ALL_TAC THEN (case THEN (move ["_"])) THEN (move ["d_f"]) THEN (case THEN (move ["_"])) THEN (move ["d_g"]))))));;
1303 refine (by (VALID (((THENL_ROT (-1)) ((((USE_THM_THEN REAL_ADD_SYM)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_POW_2)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_ASSOC)(new_rewrite [] [])) THEN ((USE_THM_THEN HAS_REAL_DERIVATIVE_MUL_ATREAL)(new_rewrite [] []))) THEN (split_tac))))));;
1304 refine (by (VALID ((((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN ((USE_THEN "d_g")(new_rewrite [] [])) THEN (done_tac)))));;
1305 refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN o_THM)(ISPEC_THEN (`derivative f`) thm_tac))(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN ((USE_THM_THEN REAL_DIFF_CHAIN_ATREAL)(new_rewrite [] []))))));;
1306 refine (by (VALID (((((USE_THEN "d_g")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THEN "d_f")(new_rewrite [] []))) THEN (done_tac)))));;
1307 let second_derivative_compose = end_section_proof();;
1308 (start_section_proof ["f";"g";"x"](`nth_diff_strong 2 g x ==> nth_diff_strong 2 f (g x) ==>
1309         nth_diff_strong 2 (\x. f (g x)) x`));;
1310 refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong2_eq)(new_rewrite [] []))) THEN ALL_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["open_s"])) THEN (case THEN (move ["xs"])) THEN (move ["dg"]) THEN (case THEN (move ["t"])) THEN (case THEN (move ["open_t"])) THEN (case THEN (move ["gxt"])) THEN (move ["df"])))));;
1311 refine (by (VALID ((set_tac "s'" (`{z | z IN s /\ g z IN t}`)))));;
1312 refine (by (VALID ((have_tac (move ["open_s'"]) (`real_open s'`)))));;
1313 refine (by (VALID ((((USE_THEN "s'_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN REAL_CONTINUOUS_OPEN_PREIMAGE)(new_rewrite [] [])) THEN ((USE_THEN "open_t")(new_rewrite [] [])) THEN ((USE_THEN "open_s")(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andbT)(new_rewrite [] [])))))));;
1314 refine (by (VALID (((((USE_THM_THEN REAL_CONTINUOUS_ON_EQ_REAL_CONTINUOUS_AT)(new_rewrite [] [])) THEN ((TRY done_tac))) THEN (move ["y"]) THEN (move ["yt"])))));;
1315 refine (by (VALID (((((USE_THM_THEN REAL_DIFFERENTIABLE_IMP_CONTINUOUS_ATREAL)(new_rewrite [] [])) THEN ((USE_THEN "dg")(new_rewrite [] []))) THEN (done_tac)))));;
1316 refine (by (VALID (((exists_tac (`s INTER s'`)) THEN (((USE_THM_THEN REAL_OPEN_INTER)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_INTER)(new_rewrite [] []))) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (split_tac)))));;
1317 refine (by (VALID (((((USE_THEN "s'_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN IN_ELIM_THM)(new_rewrite [] [])) THEN ((USE_THEN "xs")(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN ((exists_tac (mk_var("x",mk_type("real",[])))) THEN (simp_tac)) THEN (done_tac)))));;
1318 refine (by (VALID ((BETA_TAC THEN (move ["y"]) THEN (case THEN ((move ["ys"]) THEN (move ["ys'"])))))));;
1319 refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN o_THM)(ISPEC_THEN (mk_var("f",mk_type("fun",[mk_type("real",[]);mk_type("real",[])]))) thm_tac))(GSYM_THEN (new_rewrite [1] []))) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN (((USE_THM_THEN REAL_DIFFERENTIABLE_COMPOSE_ATREAL)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "dg")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN andTb)(new_rewrite [] []))) THEN ((TRY done_tac)))))));;
1320 refine (by (VALID (((((USE_THEN "ys'")MP_TAC) THEN (clear_assumption "ys'") THEN BETA_TAC) THEN ((USE_THEN "s'_def")(GSYM_THEN (new_rewrite [] []))) THEN (((USE_THM_THEN IN_ELIM_THM)(new_rewrite [] [])) THEN ALL_TAC THEN (case THEN (move ["z"])) THEN (simp_tac)) THEN (done_tac)))));;
1321 refine (by (VALID ((((USE_THM_THEN differentiable_local)MP_TAC) THEN (clear_assumption "differentiable_local") THEN (DISCH_THEN apply_tac)))));;
1322 refine (by (VALID (((THENL_ROT (-1)) (((exists_tac (`\x. derivative g x * derivative f (g x)`)) THEN (exists_tac (`s INTER s'`))) THEN (split_tac))))));;
1323 refine (by (VALID (((((USE_THM_THEN REAL_OPEN_INTER)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_INTER)(new_rewrite [] []))) THEN ((USE_THEN "ys")(new_rewrite [1] [])) THEN ((USE_THEN "ys'")(new_rewrite [1] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] [])))) THEN (move ["z"]) THEN (move ["z_in"])))));;
1324 refine (by (VALID ((((USE_THM_THEN derivative_composition)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THEN "dg")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THEN "df")(new_rewrite [] [])) THEN ((TRY done_tac))))));;
1325 refine (by (VALID (((((USE_THEN "z_in")MP_TAC) THEN (clear_assumption "z_in") THEN BETA_TAC) THEN ((USE_THEN "s'_def")(GSYM_THEN (new_rewrite [] []))) THEN (((USE_THM_THEN IN_ELIM_THM)(new_rewrite [] [])) THEN ALL_TAC THEN (case THEN (move ["_"])) THEN (case THEN (move ["_"])) THEN (simp_tac)) THEN (done_tac)))));;
1326 refine (by (VALID ((((USE_THM_THEN REAL_DIFFERENTIABLE_MUL_ATREAL)(new_rewrite [] [])) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN (((USE_THEN "dg")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andTb)(new_rewrite [] [])))))));;
1327 refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN o_THM)(ISPEC_THEN (`derivative f`) thm_tac))(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN (((USE_THM_THEN REAL_DIFFERENTIABLE_COMPOSE_ATREAL)(new_rewrite [] [])) THEN ((USE_THEN "dg")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THEN "df")(new_rewrite [] [])) THEN ((TRY done_tac)))))));;
1328 refine (by (VALID (((((USE_THEN "ys'")MP_TAC) THEN (clear_assumption "ys'") THEN BETA_TAC) THEN ((USE_THEN "s'_def")(GSYM_THEN (new_rewrite [] []))) THEN (((USE_THM_THEN IN_ELIM_THM)(new_rewrite [] [])) THEN ALL_TAC THEN (case THEN (move ["z"])) THEN (simp_tac)) THEN (done_tac)))));;
1329 let diff2_compose = end_section_proof();;
1330 (start_section_proof ["f";"x"](`~(f x = &0) ==> f real_continuous atreal x ==>
1331         ?s. real_open s /\ x IN s /\ !y. y IN s ==> ~(f y = &0)`));;
1332 refine (by (VALID ((((USE_THM_THEN real_continuous_atreal)(new_rewrite [] [])) THEN (move ["fn0"]) THEN ((fun thm_tac -> DISCH_THEN (ISPEC_THEN (`abs (f x)`) thm_tac))MP_TAC)))));;
1333 refine (by (VALID (((THENL_FIRST) (ANTS_TAC) ((((USE_THEN "fn0")MP_TAC) THEN (clear_assumption "fn0") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac))))));;
1334 refine (by (VALID ((BETA_TAC THEN (case THEN (move ["d"])) THEN (case THEN (move ["d0"])) THEN (move ["ineq"])))));;
1335 refine (by (VALID ((exists_tac (`real_interval (x - d, x + d)`)))));;
1336 refine (by (VALID (((THENL_FIRST) ((((USE_THM_THEN REAL_OPEN_REAL_INTERVAL)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] []))) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN ((split_tac) THENL [ALL_TAC; (move ["y"])])) ((((USE_THEN "d0")MP_TAC) THEN (clear_assumption "d0") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac))))));;
1337 refine (by (VALID (((((USE_THEN "fn0")MP_TAC) THEN (clear_assumption "fn0") THEN ((USE_THEN "d0")MP_TAC) THEN (clear_assumption "d0") THEN ((fun thm_tac -> (USE_THEN "ineq")(ISPEC_THEN (mk_var("y",mk_type("real",[]))) thm_tac))MP_TAC) THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
1338 let continuous_not0_exists_open = end_section_proof();;
1339 (start_section_proof ["a";"f";"x"](`a < f x ==> f real_continuous atreal x ==>
1340         ?s. real_open s /\ x IN s /\ !y. y IN s ==> a < f y`));;
1341 refine (by (VALID (((BETA_TAC THEN (move ["f_ineq"])) THEN (((USE_THM_THEN real_continuous_atreal)(new_rewrite [] [])) THEN ((fun thm_tac -> DISCH_THEN (ISPEC_THEN (`f x - a`) thm_tac))MP_TAC))))));;
1342 refine (by (VALID (((THENL_FIRST) (ANTS_TAC) ((((USE_THEN "f_ineq")MP_TAC) THEN (clear_assumption "f_ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac))))));;
1343 refine (by (VALID ((BETA_TAC THEN (case THEN (move ["d"])) THEN (case THEN (move ["d0"])) THEN (move ["ineq"])))));;
1344 refine (by (VALID ((exists_tac (`real_interval (x - d, x + d)`)))));;
1345 refine (by (VALID (((THENL_FIRST) ((((USE_THM_THEN REAL_OPEN_REAL_INTERVAL)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] []))) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN ((split_tac) THENL [ALL_TAC; (move ["y"])])) ((((USE_THEN "d0")MP_TAC) THEN (clear_assumption "d0") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac))))));;
1346 refine (by (VALID (((((USE_THEN "f_ineq")MP_TAC) THEN (clear_assumption "f_ineq") THEN ((USE_THEN "d0")MP_TAC) THEN (clear_assumption "d0") THEN ((fun thm_tac -> (USE_THEN "ineq")(ISPEC_THEN (mk_var("y",mk_type("real",[]))) thm_tac))MP_TAC) THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
1347 let continuous_gt_exists_open = end_section_proof();;
1348 (start_section_proof ["a";"f";"x"](`f x < a ==> f real_continuous atreal x ==>
1349         ?s. real_open s /\ x IN s /\ !y. y IN s ==> f y < a`));;
1350 refine (by (VALID (((BETA_TAC THEN (move ["f_ineq"])) THEN (((USE_THM_THEN real_continuous_atreal)(new_rewrite [] [])) THEN ((fun thm_tac -> DISCH_THEN (ISPEC_THEN (`a - f x`) thm_tac))MP_TAC))))));;
1351 refine (by (VALID (((THENL_FIRST) (ANTS_TAC) ((((USE_THEN "f_ineq")MP_TAC) THEN (clear_assumption "f_ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac))))));;
1352 refine (by (VALID ((BETA_TAC THEN (case THEN (move ["d"])) THEN (case THEN (move ["d0"])) THEN (move ["ineq"])))));;
1353 refine (by (VALID ((exists_tac (`real_interval (x - d, x + d)`)))));;
1354 refine (by (VALID (((THENL_FIRST) ((((USE_THM_THEN REAL_OPEN_REAL_INTERVAL)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] []))) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN ((split_tac) THENL [ALL_TAC; (move ["y"])])) ((((USE_THEN "d0")MP_TAC) THEN (clear_assumption "d0") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac))))));;
1355 refine (by (VALID (((((USE_THEN "f_ineq")MP_TAC) THEN (clear_assumption "f_ineq") THEN ((USE_THEN "d0")MP_TAC) THEN (clear_assumption "d0") THEN ((fun thm_tac -> (USE_THEN "ineq")(ISPEC_THEN (mk_var("y",mk_type("real",[]))) thm_tac))MP_TAC) THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
1356 let continuous_lt_exists_open = end_section_proof();;
1357 (add_section_var (mk_var ("f", (`:real->real`))));;
1358 (add_section_var (mk_var ("x", (`:real`))));;
1359 (add_section_hyp "df" (`nth_diff_strong 2 f x`));;
1360 (start_section_proof [](`nth_derivative 2 (\x. atn (f x)) x = 
1361         (nth_derivative 2 f x * (&1 + f x * f x) - &2 * f x * derivative f x pow 2) / (&1 + f x * f x) pow 2`));;
1362 refine (by (VALID ((((USE_THM_THEN second_derivative_compose)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN diff2_atn)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN nth_derivative2)(new_rewrite [] [])) THEN ((USE_THM_THEN second_derivative_atn)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN derivative_atn)(new_rewrite [] [])) THEN (simp_tac)))));;
1363 refine (by (VALID ((((USE_THM_THEN REAL_ADD_SYM)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_MUL_LNEG)(new_rewrite [] []))) THEN ((USE_THM_THEN real_sub)(GSYM_THEN (new_rewrite [] [])))))));;
1364 refine (by (VALID (((set_tac "lhs1" (`_1 * _2`)) THEN (set_tac "lhs2" (`_1 * _2`))))));;
1365 refine (by (VALID ((((USE_THM_THEN real_div)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_INV_POW)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_SUB_RDISTRIB)(new_rewrite [] []))))));;
1366 refine (by (VALID (((set_tac "rhs1" (`_1 * _2`)) THEN (set_tac "rhs2" (`_1 * _2`))))));;
1367 refine (by (VALID ((((USE_THM_THEN (REAL_ARITH `lhs1 = rhs1 /\ lhs2 = rhs2 ==> lhs1 - lhs2 = rhs1 - rhs2`))MP_TAC) THEN (DISCH_THEN apply_tac)))));;
1368 refine (by (VALID (((((USE_THEN "lhs2_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THEN "rhs2_def")(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_MUL_ASSOC)(GSYM_THEN (new_rewrite [] [])))) THEN ((USE_THM_THEN REAL_MUL_SYM)(new_rewrite [] [(`_1 * _2 pow 2`)])) THEN ((USE_THM_THEN REAL_POW_2)(GSYM_THEN (new_rewrite [] [])))) THEN ((split_tac) THEN ((TRY done_tac)))))));;
1369 refine (by (VALID ((((USE_THEN "rhs1_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN REAL_POW_2)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_MUL_ASSOC)(GSYM_THEN (new_rewrite [] [])))) THEN ((USE_THM_THEN (REAL_ARITH `!a b c d. a * b * c * d = a * (b * c) * d`))(new_rewrite [] []))))));;
1370 refine (by (VALID ((((USE_THM_THEN REAL_MUL_RINV)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "lhs1_def")(GSYM_THEN (new_rewrite [] [])))) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_MUL_LID)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_MUL_SYM)(new_rewrite [] []))) THEN ((TRY done_tac))))));;
1371 refine (by (VALID (((((fun thm_tac -> (USE_THM_THEN REAL_LE_SQUARE)(ISPEC_THEN (`f x`) thm_tac))MP_TAC) THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
1372 let second_derivative_compose_atn = end_section_proof();;
1373 (start_section_proof [](`~(f x = &0) ==>
1374         nth_derivative 2 (\x. inv (f x)) x =
1375         (&2 * derivative f x pow 2 - nth_derivative 2 f x * f x) / (f x pow 3)`));;
1376 refine (by (VALID ((BETA_TAC THEN (move ["fn0"])))));;
1377 refine (by (VALID ((((USE_THM_THEN second_derivative_compose)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN diff2_inv)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN second_derivative_inv)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN derivative_inv)(new_rewrite [] [])) THEN ((TRY done_tac))))));;
1378 refine (by (VALID ((((USE_THM_THEN REAL_MUL_LNEG)(new_rewrite [] [])) THEN ((USE_THM_THEN real_sub)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN real_div)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_SUB_RDISTRIB)(new_rewrite [] []))))));;
1379 refine (by (VALID (((THENL_FIRST) ((((USE_THM_THEN (REAL_ARITH `!a b c d. a = c /\ b = d ==> a - b = c - d`))MP_TAC) THEN (DISCH_THEN apply_tac)) THEN (split_tac)) ((arith_tac) THEN (done_tac))))));;
1380 refine (by (VALID ((((USE_THM_THEN REAL_INV_POW)(new_rewrite [] [])) THEN ((USE_THM_THEN (ARITH_RULE `3 = SUC 2`))(new_rewrite [] [])) THEN ((USE_THM_THEN real_powS)(new_rewrite [] []))))));;
1381 refine (by (VALID ((((USE_THM_THEN (REAL_ARITH `!a b c d. (a * b) * c * d = a * (b * c) * d`))(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_RINV)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN REAL_MUL_LID)(new_rewrite [] []))))));;
1382 refine (by (VALID (((((USE_THM_THEN REAL_INV_MUL)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_POW_2)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN REAL_MUL_SYM)(new_rewrite [] []))) THEN (done_tac)))));;
1383 let second_derivative_compose_inv = end_section_proof();;
1384 (start_section_proof [](`&0 < f x ==>
1385         nth_derivative 2 (\x. sqrt (f x)) x =
1386         (&2 * nth_derivative 2 f x * f x - derivative f x pow 2) / (&4 * sqrt (f x pow 3))`));;
1387 refine (by (VALID ((BETA_TAC THEN (move ["f_pos"])))));;
1388 refine (by (VALID ((((USE_THM_THEN second_derivative_compose)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN diff2_sqrt)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN second_derivative_sqrt)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN derivative_sqrt)(new_rewrite [] [])) THEN ((TRY done_tac))))));;
1389 refine (by (VALID ((((USE_THM_THEN REAL_MUL_LNEG)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_ADD_SYM)(new_rewrite [] [])) THEN ((USE_THM_THEN real_sub)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN real_div)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_SUB_RDISTRIB)(new_rewrite [] []))))));;
1390 refine (by (VALID (((THENL_LAST) ((((USE_THM_THEN (REAL_ARITH `!a b c d. a = c /\ b = d ==> a - b = c - d`))MP_TAC) THEN (DISCH_THEN apply_tac)) THEN (split_tac)) ((arith_tac) THEN (done_tac))))));;
1391 refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`sqrt (f x pow 3) = sqrt (f x) * f x`)))));;
1392 refine (by (VALID (((((USE_THM_THEN SQRT_POW)(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_LT_IMP_LE)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN (ARITH_RULE `3 = SUC 2`))(new_rewrite [] [])) THEN ((USE_THM_THEN real_powS)(new_rewrite [] [])) THEN ((USE_THM_THEN SQRT_POW_2)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_LT_IMP_LE)(new_rewrite [] [])))) THEN (done_tac)))));;
1393 refine (by (VALID (repeat_tactic 1 9 (((USE_THM_THEN REAL_INV_MUL)(new_rewrite [] []))))));;
1394 refine (by (VALID (((USE_THM_THEN (REAL_ARITH `!a b c d. (&2 * a * b) * inv (&4) * c * d = (inv (&2) * c) * a * (b * d)`))(new_rewrite [] [])))));;
1395 refine (by (VALID (((((USE_THM_THEN REAL_MUL_RINV)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_POS_NZ)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN REAL_MUL_RID)(new_rewrite [] []))) THEN (done_tac)))));;
1396 let second_derivative_compose_sqrt = end_section_proof();;
1397 (start_section_proof [](`abs (f x) < &1 ==>
1398         nth_derivative 2 (\x. acs (f x)) x =
1399         -- ((nth_derivative 2 f x * (&1 - f x * f x) + f x * derivative f x pow 2) / 
1400         sqrt ((&1 - f x * f x) pow 3))`));;
1401 refine (by (VALID ((BETA_TAC THEN (move ["f_ineq"])))));;
1402 refine (by (VALID ((((USE_THM_THEN second_derivative_compose)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN diff2_acs)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN second_derivative_acs)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN derivative_acs)(new_rewrite [] [])) THEN ((TRY done_tac))))));;
1403 refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN REAL_MUL_LNEG)(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_NEG_ADD)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN REAL_EQ_NEG2)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN real_div)(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_ADD_RDISTRIB)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_ADD_SYM)(new_rewrite [] []))))));;
1404 refine (by (VALID (((THENL_LAST) ((((USE_THM_THEN (REAL_ARITH `!a b c d. a = c /\ b = d ==> a + b = c + d`))MP_TAC) THEN (DISCH_THEN apply_tac)) THEN (split_tac)) ((arith_tac) THEN (done_tac))))));;
1405 refine (by (VALID ((set_tac "y" (`&1 - f x * f x`)))));;
1406 refine (by (VALID ((have_tac (move ["y_ineq"]) (`&0 <= y /\ &0 < y /\ ~(y = &0)`)))));;
1407 refine (by (VALID ((((USE_THEN "y_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN (REAL_ARITH `!a. &1 - a * a = (&1 - a) * (&1 + a)`))(new_rewrite [] []))))));;
1408 refine (by (VALID (((((USE_THM_THEN REAL_ENTIRE)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LE_MUL)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_LT_MUL)(new_rewrite [] [])))) THEN (((USE_THEN "f_ineq")MP_TAC) THEN (clear_assumption "f_ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
1409 refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`sqrt (y pow 3) = sqrt y * y`)))));;
1410 refine (by (VALID (((((USE_THM_THEN SQRT_POW)(GSYM_THEN (new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN (ARITH_RULE `3 = SUC 2`))(new_rewrite [] [])) THEN ((USE_THM_THEN real_powS)(new_rewrite [] [])) THEN ((USE_THM_THEN SQRT_POW_2)(new_rewrite [] []))) THEN (done_tac)))));;
1411 refine (by (VALID ((((USE_THM_THEN REAL_INV_MUL)(new_rewrite [] [])) THEN ((USE_THM_THEN (REAL_ARITH `!a b c d. (a * b) * c * d = c * a * (b * d)`))(new_rewrite [] []))))));;
1412 refine (by (VALID (((((USE_THM_THEN REAL_MUL_RINV)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN REAL_MUL_RID)(new_rewrite [] []))) THEN (done_tac)))));;
1413 let second_derivative_compose_acs = end_section_proof();;
1414 (start_section_proof [](`nth_diff_strong 2 (\x. atn (f x)) x`));;
1415 refine (by (VALID (((((USE_THM_THEN diff2_compose)(new_rewrite [] [])) THEN ((USE_THM_THEN diff2_atn)(new_rewrite [] []))) THEN (done_tac)))));;
1416 let diff2_compose_atn = end_section_proof();;
1417 (start_section_proof [](`~(f x = &0) ==> nth_diff_strong 2 (\x. inv (f x)) x`));;
1418 refine (by (VALID (((BETA_TAC THEN (move ["fn0"])) THEN (((USE_THM_THEN diff2_compose)(new_rewrite [] [])) THEN ((USE_THM_THEN diff2_inv)(new_rewrite [] []))) THEN (done_tac)))));;
1419 let diff2_compose_inv = end_section_proof();;
1420 (start_section_proof [](`&0 < f x ==> nth_diff_strong 2 (\x. sqrt (f x)) x`));;
1421 refine (by (VALID (((BETA_TAC THEN (move ["f_pos"])) THEN (((USE_THM_THEN diff2_compose)(new_rewrite [] [])) THEN ((USE_THM_THEN diff2_sqrt)(new_rewrite [] []))) THEN (done_tac)))));;
1422 let diff2_compose_sqrt = end_section_proof();;
1423 (start_section_proof [](`abs (f x) < &1 ==> nth_diff_strong 2 (\x. acs (f x)) x`));;
1424 refine (by (VALID (((BETA_TAC THEN (move ["f_abs"])) THEN (((USE_THM_THEN diff2_compose)(new_rewrite [] [])) THEN ((USE_THM_THEN diff2_acs)(new_rewrite [] []))) THEN (done_tac)))));;
1425 let diff2_compose_acs = end_section_proof();;
1426 let diff2_compose_acs = finalize_theorem diff2_compose_acs;;
1427 let diff2_compose_sqrt = finalize_theorem diff2_compose_sqrt;;
1428 let diff2_compose_inv = finalize_theorem diff2_compose_inv;;
1429 let diff2_compose_atn = finalize_theorem diff2_compose_atn;;
1430 let second_derivative_compose_acs = finalize_theorem second_derivative_compose_acs;;
1431 let second_derivative_compose_sqrt = finalize_theorem second_derivative_compose_sqrt;;
1432 let second_derivative_compose_inv = finalize_theorem second_derivative_compose_inv;;
1433 let second_derivative_compose_atn = finalize_theorem second_derivative_compose_atn;;
1434 let continuous_lt_exists_open = finalize_theorem continuous_lt_exists_open;;
1435 let continuous_gt_exists_open = finalize_theorem continuous_gt_exists_open;;
1436 let continuous_not0_exists_open = finalize_theorem continuous_not0_exists_open;;
1437 let diff2_compose = finalize_theorem diff2_compose;;
1438 let second_derivative_compose = finalize_theorem second_derivative_compose;;
1439 let REAL_CONTINUOUS_OPEN_PREIMAGE = finalize_theorem REAL_CONTINUOUS_OPEN_PREIMAGE;;
1440 (end_section "SecondDerivativeCompose");;
1441 (start_section_proof ["f";"g";"x"](`nth_diff_strong 2 f x ==>
1442   nth_diff_strong 2 g x ==>
1443   nth_derivative 2 (\x. f x * g x) x =
1444   f x * nth_derivative 2 g x + &2 * derivative f x * derivative g x + nth_derivative 2 f x * g x`));;
1445 refine (by (VALID (((BETA_TAC THEN (move ["df0"]) THEN (move ["dg0"])) THEN (set_tac "int" (`(x,x)`))))));;
1446 refine (by (VALID ((have_tac (ALL_TAC THEN (case THEN (move ["ineq"])) THEN (case THEN ((move ["df"]) THEN (move ["dg"])))) (`interval_arith x int /\ nth_diff_strong_int 2 int f /\ nth_diff_strong_int 2 int g`)))));;
1447 refine (by (VALID ((repeat_tactic 1 9 (((USE_THEN "int_def")(GSYM_THEN (new_rewrite [] [])))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] []))) THEN ((USE_THM_THEN CONST_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))))));;
1448 refine (by (VALID ((((split_tac) THEN (move ["y"])) THEN ((((USE_THM_THEN interval_arith)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LE_ANTISYM)(new_rewrite [] []))) THEN (DISCH_THEN(GSYM_THEN (new_rewrite [] [])))) THEN (done_tac)))));;
1449 refine (by (VALID (((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN nth_derivative_mul)(fun fst_th ->(USE_THEN "df")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "dg")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(ISPEC_THEN (`2`) thm_tac))(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th))) MP_TAC) THEN ALL_TAC) THEN (((USE_THM_THEN leqnn)(new_rewrite [] [])) THEN (DISCH_THEN(new_rewrite [] [])) THEN ((TRY done_tac)))))));;
1450 refine (by (VALID ((((USE_THM_THEN TWO)(new_rewrite [1] [])) THEN ((USE_THM_THEN ONE)(new_rewrite [1] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN (GEN_ALL SUM_CLAUSES_NUMSEG))(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN (ARITH_RULE `!n. 0 <= SUC n`))(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN ONE)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN TWO)(GSYM_THEN (new_rewrite [] [])))))));;
1451 refine (by (VALID ((((USE_THM_THEN subnn)(new_rewrite [] [])) THEN ((USE_THM_THEN subn0)(new_rewrite [] [])) THEN ((USE_THM_THEN (ARITH_RULE `2 - 1 = 1`))(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_derivative0)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_derivative1)(new_rewrite [] [])))))));;
1452 refine (by (VALID (((((USE_THM_THEN binom)(new_rewrite [] [])) THEN ((USE_THM_THEN BINOM_1)(new_rewrite [] [])) THEN ((USE_THM_THEN BINOM_REFL)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_MUL_LID)(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_ADD_ASSOC)(new_rewrite [] []))) THEN (done_tac)))));;
1453 let second_derivative_mul = end_section_proof();;
1454 (start_section_proof ["f";"g";"x"](`~(g x = &0) ==>
1455         nth_diff_strong 2 f x ==>
1456         nth_diff_strong 2 g x ==>
1457         nth_derivative 2 (\x. f x / g x) x = 
1458         ((nth_derivative 2 f x * g x - f x * nth_derivative 2 g x) * g x -
1459         &2 * derivative g x * (derivative f x * g x - f x * derivative g x)) / (g x pow 3)`));;
1460 refine (by (VALID ((BETA_TAC THEN (move ["gn0"]) THEN (move ["diff_f"]) THEN (move ["diff_g"])))));;
1461 refine (by (VALID (((set_tac "dg" (`derivative g x`)) THEN (set_tac "df" (`derivative f x`))))));;
1462 refine (by (VALID (((set_tac "ddg" (`nth_derivative 2 g x`)) THEN (set_tac "ddf" (`nth_derivative 2 f x`))))));;
1463 refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN real_div)(new_rewrite [] []))) THEN ((USE_THM_THEN second_derivative_mul)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN second_derivative_compose_inv)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN diff2_compose_inv)(new_rewrite [] []))) THEN ((TRY done_tac))))));;
1464 refine (by (VALID (((USE_THM_THEN derivative_compose_inv)(new_rewrite [] [])))));;
1465 refine (by (VALID (((((USE_THEN "diff_g")MP_TAC) THEN (clear_assumption "diff_g") THEN BETA_TAC) THEN (((USE_THM_THEN nth_diff_strong2_eq)(new_rewrite [] [])) THEN ALL_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["open_s"])) THEN (case THEN (move ["xs"])) THEN (DISCH_THEN(new_rewrite [] [])) THEN ((TRY done_tac))) THEN (done_tac)))));;
1466 refine (by (VALID ((((USE_THEN "ddf_def")(new_rewrite [] [])) THEN ((USE_THEN "ddg_def")(new_rewrite [] [])) THEN ((USE_THEN "df_def")(new_rewrite [] [])) THEN ((USE_THEN "dg_def")(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN real_div)(new_rewrite [] [])))))));;
1467 refine (by (VALID ((set_tac "lhs" (`_1 + _2`)))));;
1468 refine (by (VALID (((USE_THM_THEN (REAL_RING `!f g x. ((ddf * g x - f x * ddg) * g x - &2 * dg * (df * g x - f x * dg)) * 
1469                                                 inv (g x pow 3) =
1470                         f x * (&2 * dg pow 2 - ddg * g x) * inv (g x pow 3) +
1471                         &2 * df * --(g x * inv (g x pow 3)) * dg +
1472                         ddf * (g x * g x * inv (g x pow 3))`))(new_rewrite [] [])))));;
1473 refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`g x * inv (g x pow 3) = inv (g x pow 2)`)))));;
1474 refine (by (VALID (((((USE_THM_THEN (ARITH_RULE `3 = SUC 2`))(new_rewrite [] [])) THEN ((USE_THM_THEN real_powS)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_INV_MUL)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_ASSOC)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_RINV)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN REAL_MUL_LID)(new_rewrite [] []))) THEN (done_tac)))));;
1475 refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`g x * inv (g x pow 2) = inv (g x)`)))));;
1476 refine (by (VALID (((((USE_THM_THEN TWO)(new_rewrite [] [])) THEN ((USE_THM_THEN real_powS)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_INV_MUL)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_ASSOC)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_RINV)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN REAL_MUL_LID)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_POW_1)(new_rewrite [] []))) THEN (done_tac)))));;
1477 refine (by (VALID (((((fun thm_tac -> (USE_THM_THEN REAL_POW_2)(ISPEC_THEN (`g x`) thm_tac))(new_rewrite [] [])) THEN ((USE_THEN "lhs_def")(new_rewrite [] []))) THEN (done_tac)))));;
1478 let second_derivative_div = end_section_proof();;
1479 (start_section_proof ["f";"g";"x"](`~(g x = &0) ==> nth_diff_strong 2 f x ==> nth_diff_strong 2 g x ==>
1480         nth_diff_strong 2 (\x. f x / g x) x`));;
1481 refine (by (VALID (((BETA_TAC THEN (move ["gn0"]) THEN (move ["df0"]) THEN (move ["dg0"])) THEN (set_tac "int" (`(x,x)`))))));;
1482 refine (by (VALID ((have_tac (ALL_TAC THEN (case THEN (move ["ineq"])) THEN (case THEN ((move ["df"]) THEN (move ["dg"])))) (`interval_arith x int /\ nth_diff_strong_int 2 int f /\ nth_diff_strong_int 2 int g`)))));;
1483 refine (by (VALID ((repeat_tactic 1 9 (((USE_THEN "int_def")(GSYM_THEN (new_rewrite [] [])))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] []))) THEN ((USE_THM_THEN CONST_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))))));;
1484 refine (by (VALID ((((split_tac) THEN (move ["y"])) THEN ((((USE_THM_THEN interval_arith)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LE_ANTISYM)(new_rewrite [] []))) THEN (DISCH_THEN(GSYM_THEN (new_rewrite [] [])))) THEN (done_tac)))));;
1485 refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN nth_diff_mul)(ISPEC_THEN (`2`) thm_tac))(ISPEC_THEN (mk_var("int",mk_type("prod",[mk_type("real",[]);mk_type("real",[])]))) thm_tac))(ISPEC_THEN (mk_var("f",mk_type("fun",[mk_type("real",[]);mk_type("real",[])]))) thm_tac))(ISPEC_THEN (`\x. inv (g x)`) thm_tac))(fun fst_th ->(USE_THEN "df")(fun th -> MATCH_MP_THEN th thm_tac fst_th))) MP_TAC) THEN ALL_TAC))));;
1486 refine (by (VALID ((((repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN real_div)(new_rewrite [] []))) THEN (DISCH_THEN(new_rewrite [] []))) THEN ((split_tac) THEN ((TRY done_tac)) THEN (move ["y"]))))));;
1487 refine (by (VALID (((((USE_THEN "int_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN interval_arith)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LE_ANTISYM)(new_rewrite [] []))) THEN (DISCH_THEN(GSYM_THEN (new_rewrite [] [])))))));;
1488 refine (by (VALID ((((USE_THM_THEN diff2_compose_inv)(new_rewrite [] [])) THEN (done_tac)))));;
1489 let diff2_div = end_section_proof();;
1490 (start_section_proof ["f";"c";"x"](`nth_diff_strong 2 f x ==>
1491         nth_derivative 2 (\x. c * f x) x = c * nth_derivative 2 f x`));;
1492 refine (by (VALID (((BETA_TAC THEN (move ["df0"])) THEN (set_tac "int" (`(x,x)`))))));;
1493 refine (by (VALID ((have_tac (ALL_TAC THEN (case THEN (move ["ineq"])) THEN (move ["df"])) (`interval_arith x int /\ nth_diff_strong_int 2 int f`)))));;
1494 refine (by (VALID ((repeat_tactic 1 9 (((USE_THEN "int_def")(GSYM_THEN (new_rewrite [] [])))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] []))) THEN ((USE_THM_THEN CONST_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))))));;
1495 refine (by (VALID (((BETA_TAC THEN (move ["y"])) THEN ((((USE_THM_THEN interval_arith)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LE_ANTISYM)(new_rewrite [] []))) THEN (DISCH_THEN(GSYM_THEN (new_rewrite [] [])))) THEN (done_tac)))));;
1496 refine (by (VALID (((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN nth_derivative_scale)(fun fst_th ->(USE_THEN "df")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(ISPEC_THEN (mk_var("c",mk_type("real",[]))) thm_tac))(ISPEC_THEN (`2`) thm_tac))(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th))) MP_TAC) THEN ALL_TAC) THEN (((USE_THM_THEN leqnn)(new_rewrite [] [])) THEN (DISCH_THEN(new_rewrite [] []))) THEN (done_tac)))));;
1497 let second_derivative_scale = end_section_proof();;
1498 (start_section_proof ["f";"g";"x"](`nth_diff_strong 2 f x ==>
1499         nth_diff_strong 2 g x ==>
1500         nth_derivative 2 (\x. f x + g x) x = nth_derivative 2 f x + nth_derivative 2 g x`));;
1501 refine (by (VALID (((BETA_TAC THEN (move ["df0"]) THEN (move ["dg0"])) THEN (set_tac "int" (`(x,x)`))))));;
1502 refine (by (VALID ((have_tac (ALL_TAC THEN (case THEN (move ["ineq"])) THEN (case THEN ((move ["df"]) THEN (move ["dg"])))) (`interval_arith x int /\ nth_diff_strong_int 2 int f /\ nth_diff_strong_int 2 int g`)))));;
1503 refine (by (VALID ((repeat_tactic 1 9 (((USE_THEN "int_def")(GSYM_THEN (new_rewrite [] [])))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] []))) THEN ((USE_THM_THEN CONST_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))))));;
1504 refine (by (VALID ((((split_tac) THEN (move ["y"])) THEN ((((USE_THM_THEN interval_arith)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LE_ANTISYM)(new_rewrite [] []))) THEN (DISCH_THEN(GSYM_THEN (new_rewrite [] [])))) THEN (done_tac)))));;
1505 refine (by (VALID (((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN nth_derivative_add)(fun fst_th ->(USE_THEN "df")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "dg")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(ISPEC_THEN (`2`) thm_tac))(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th))) MP_TAC) THEN ALL_TAC) THEN (((USE_THM_THEN leqnn)(new_rewrite [] [])) THEN (DISCH_THEN(new_rewrite [] []))) THEN (done_tac)))));;
1506 let second_derivative_add = end_section_proof();;
1507 (start_section_proof ["f";"g";"x"](`nth_diff_strong 2 f x ==>
1508         nth_diff_strong 2 g x ==>
1509         nth_derivative 2 (\x. f x - g x) x = nth_derivative 2 f x - nth_derivative 2 g x`));;
1510 refine (by (VALID (((BETA_TAC THEN (move ["df0"]) THEN (move ["dg0"])) THEN (set_tac "int" (`(x,x)`))))));;
1511 refine (by (VALID ((have_tac (ALL_TAC THEN (case THEN (move ["ineq"])) THEN (case THEN ((move ["df"]) THEN (move ["dg"])))) (`interval_arith x int /\ nth_diff_strong_int 2 int f /\ nth_diff_strong_int 2 int g`)))));;
1512 refine (by (VALID ((repeat_tactic 1 9 (((USE_THEN "int_def")(GSYM_THEN (new_rewrite [] [])))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] []))) THEN ((USE_THM_THEN CONST_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))))));;
1513 refine (by (VALID ((((split_tac) THEN (move ["y"])) THEN ((((USE_THM_THEN interval_arith)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LE_ANTISYM)(new_rewrite [] []))) THEN (DISCH_THEN(GSYM_THEN (new_rewrite [] [])))) THEN (done_tac)))));;
1514 refine (by (VALID (((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN nth_derivative_sub)(fun fst_th ->(USE_THEN "df")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "dg")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(ISPEC_THEN (`2`) thm_tac))(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th))) MP_TAC) THEN ALL_TAC) THEN (((USE_THM_THEN leqnn)(new_rewrite [] [])) THEN (DISCH_THEN(new_rewrite [] []))) THEN (done_tac)))));;
1515 let second_derivative_sub = end_section_proof();;
1516 (start_section_proof ["f";"g";"int";"g_bounds";"dd_bounds"](`nth_diff_strong_int 2 int g ==>
1517         bounded_on_int g int g_bounds ==>
1518         nth_diff_strong_int 2 g_bounds f ==>
1519         bounded_on_int (\x. nth_derivative 2 f (g x) * derivative g x pow 2 + 
1520                         derivative f (g x) * nth_derivative 2 g x) int dd_bounds ==>
1521         has_bounded_second_derivative (\x. f (g x)) int dd_bounds`));;
1522 refine (by (VALID ((((USE_THM_THEN has_bounded_second_derivative)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN bounded_on_int)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] []))) THEN (simp_tac)))));;
1523 refine (by (VALID (((BETA_TAC THEN (move ["dg"]) THEN (move ["g_bounded"]) THEN (move ["df"]) THEN (move ["bounded"])) THEN ((split_tac) THEN (move ["x"]) THEN (move ["ineq"]))))));;
1524 refine (by (VALID (((((USE_THM_THEN diff2_compose)(new_rewrite [] [])) THEN ((USE_THEN "dg")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THEN "df")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THEN "g_bounded")(new_rewrite [] []))) THEN (done_tac)))));;
1525 refine (by (VALID (((((USE_THM_THEN second_derivative_compose)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "dg")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "g_bounded")(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THEN "bounded")(new_rewrite [] []))) THEN (done_tac)))));;
1526 let second_derivative_compose_bounds = end_section_proof();;
1527 (start_section_proof ["dd_bounds"](`bounded_on_int (\x. (-- &2 * x) * inv(&1 + x pow 2) pow 2) int dd_bounds ==>
1528         has_bounded_second_derivative atn int dd_bounds`));;
1529 refine (by (VALID (((((USE_THM_THEN bounded_on_int)(new_rewrite [] [])) THEN ((USE_THM_THEN has_bounded_second_derivative)(new_rewrite [] []))) THEN (move ["ineq"])))));;
1530 refine (by (VALID (((THENL_LAST) (split_tac) ((((USE_THM_THEN nth_derivative2)(new_rewrite [] [])) THEN ((USE_THM_THEN second_derivative_atn)(new_rewrite [] [])) THEN ((USE_THM_THEN bounded_on_int)(new_rewrite [] []))) THEN (done_tac))))));;
1531 refine (by (VALID (((((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] [])) THEN ((USE_THM_THEN diff2_atn)(new_rewrite [] []))) THEN (done_tac)))));;
1532 let second_derivative_atn_bounds = end_section_proof();;
1533 (start_section_proof ["f";"dd_bounds"](`nth_diff_strong_int 2 int f ==>
1534         bounded_on_int (\x. (nth_derivative 2 f x * (&1 + f x * f x) - &2 * f x * derivative f x pow 2) /
1535                         (&1 + f x * f x) pow 2) int dd_bounds ==>
1536         has_bounded_second_derivative (\x. atn (f x)) int dd_bounds`));;
1537 refine (by (VALID ((((((USE_THM_THEN has_bounded_second_derivative)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN bounded_on_int)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] []))) THEN (simp_tac)) THEN (move ["df"]) THEN (move ["bounded"])) THEN ((split_tac) THEN (move ["x"]) THEN (move ["ineq"]))))));;
1538 refine (by (VALID (((((USE_THM_THEN diff2_compose_atn)(new_rewrite [] [])) THEN ((USE_THEN "df")(new_rewrite [] []))) THEN (done_tac)))));;
1539 refine (by (VALID (((((USE_THM_THEN second_derivative_compose_atn)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THEN "bounded")(new_rewrite [] []))) THEN (done_tac)))));;
1540 let second_derivative_compose_atn_bounds = end_section_proof();;
1541 (start_section_proof ["dd_bounds"](`interval_not_zero int ==>
1542         bounded_on_int (\x. &2 * inv (x pow 3)) int dd_bounds ==>
1543         has_bounded_second_derivative inv int dd_bounds`));;
1544 refine (by (VALID ((((((USE_THM_THEN has_bounded_second_derivative)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN bounded_on_int)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] []))) THEN (simp_tac)) THEN (move ["int0"]) THEN (move ["bounded"])) THEN ((split_tac) THEN (move ["x"]) THEN (move ["ineq"]))))));;
1545 refine (by (VALID (((((USE_THM_THEN diff2_inv)(new_rewrite [] [])) THEN ((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN interval_arith_not_zero)(ISPEC_THEN (mk_var("x",mk_type("real",[]))) thm_tac))(ISPEC_THEN (mk_var("int",mk_type("prod",[mk_type("real",[]);mk_type("real",[])]))) thm_tac))(new_rewrite [] []))) THEN (done_tac)))));;
1546 refine (by (VALID (((((USE_THM_THEN second_derivative_inv)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN interval_arith_not_zero)(ISPEC_THEN (mk_var("x",mk_type("real",[]))) thm_tac))(ISPEC_THEN (mk_var("int",mk_type("prod",[mk_type("real",[]);mk_type("real",[])]))) thm_tac))(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THEN "bounded")(new_rewrite [] []))) THEN (done_tac)))));;
1547 let second_derivative_inv_bounds = end_section_proof();;
1548 (start_section_proof ["f";"f_bounds";"dd_bounds"](`bounded_on_int f int f_bounds ==> interval_not_zero f_bounds ==>
1549         nth_diff_strong_int 2 int f ==>
1550         bounded_on_int (\x. (&2 * derivative f x pow 2 - nth_derivative 2 f x * f x) / f x pow 3) 
1551                         int dd_bounds ==>
1552         has_bounded_second_derivative (\x. inv (f x)) int dd_bounds`));;
1553 refine (by (VALID (((((USE_THM_THEN has_bounded_second_derivative)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN bounded_on_int)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] []))) THEN (simp_tac)) THEN (move ["f_bounded"]) THEN (move ["f0"]) THEN (move ["df"]) THEN (move ["bounded"])))));;
1554 refine (by (VALID ((have_tac (move ["fn0"]) (`!x. interval_arith x int ==> ~(f x = &0)`)))));;
1555 refine (by (VALID (((BETA_TAC THEN (move ["x"]) THEN (move ["ineq"])) THEN (((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN interval_arith_not_zero)(ISPEC_THEN (`f x`) thm_tac))(ISPEC_THEN (mk_var("f_bounds",mk_type("prod",[mk_type("real",[]);mk_type("real",[])]))) thm_tac))(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THEN "f_bounded")(new_rewrite [] []))) THEN (done_tac)))));;
1556 refine (by (VALID (((split_tac) THEN (move ["x"]) THEN (move ["ineq"])))));;
1557 refine (by (VALID (((((USE_THM_THEN diff2_compose_inv)(new_rewrite [] [])) THEN ((USE_THEN "df")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THEN "fn0")(new_rewrite [] []))) THEN (done_tac)))));;
1558 refine (by (VALID (((((USE_THM_THEN second_derivative_compose_inv)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "fn0")(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THEN "bounded")(new_rewrite [] []))) THEN (done_tac)))));;
1559 let second_derivative_compose_inv_bounds = end_section_proof();;
1560 (start_section_proof ["dd_bounds"](`interval_pos int ==>
1561         bounded_on_int (\x. --inv (&4 * sqrt (x pow 3))) int dd_bounds ==>
1562         has_bounded_second_derivative sqrt int dd_bounds`));;
1563 refine (by (VALID (((((USE_THM_THEN has_bounded_second_derivative)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN bounded_on_int)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] []))) THEN (simp_tac)) THEN (move ["int_pos"]) THEN (move ["bounded"])))));;
1564 refine (by (VALID (((split_tac) THEN (move ["x"]) THEN (move ["ineq"])))));;
1565 refine (by (VALID (((((USE_THM_THEN diff2_sqrt)(new_rewrite [] [])) THEN ((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN interval_arith_pos)(ISPEC_THEN (mk_var("x",mk_type("real",[]))) thm_tac))(ISPEC_THEN (mk_var("int",mk_type("prod",[mk_type("real",[]);mk_type("real",[])]))) thm_tac))(new_rewrite [] []))) THEN (done_tac)))));;
1566 refine (by (VALID (((((USE_THM_THEN second_derivative_sqrt)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN interval_arith_pos)(ISPEC_THEN (mk_var("x",mk_type("real",[]))) thm_tac))(ISPEC_THEN (mk_var("int",mk_type("prod",[mk_type("real",[]);mk_type("real",[])]))) thm_tac))(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THEN "bounded")(new_rewrite [] []))) THEN (done_tac)))));;
1567 let second_derivative_sqrt_bounds = end_section_proof();;
1568 (start_section_proof ["f";"f_bounds";"dd_bounds"](`bounded_on_int f int f_bounds ==> interval_pos f_bounds ==>
1569         nth_diff_strong_int 2 int f ==>
1570         bounded_on_int (\x. (&2 * nth_derivative 2 f x * f x - derivative f x pow 2) /
1571                         (&4 * sqrt (f x pow 3))) 
1572                         int dd_bounds ==>
1573         has_bounded_second_derivative (\x. sqrt (f x)) int dd_bounds`));;
1574 refine (by (VALID (((((USE_THM_THEN has_bounded_second_derivative)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN bounded_on_int)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] []))) THEN (simp_tac)) THEN (move ["f_bounded"]) THEN (move ["f_int"]) THEN (move ["df"]) THEN (move ["bounded"])))));;
1575 refine (by (VALID ((have_tac (move ["f_pos"]) (`!x. interval_arith x int ==> &0 < f x`)))));;
1576 refine (by (VALID (((BETA_TAC THEN (move ["x"]) THEN (move ["ineq"])) THEN (((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN interval_arith_pos)(ISPEC_THEN (`f x`) thm_tac))(ISPEC_THEN (mk_var("f_bounds",mk_type("prod",[mk_type("real",[]);mk_type("real",[])]))) thm_tac))(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THEN "f_bounded")(new_rewrite [] []))) THEN (done_tac)))));;
1577 refine (by (VALID (((split_tac) THEN (move ["x"]) THEN (move ["ineq"])))));;
1578 refine (by (VALID (((((USE_THM_THEN diff2_compose_sqrt)(new_rewrite [] [])) THEN ((USE_THEN "df")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THEN "f_pos")(new_rewrite [] []))) THEN (done_tac)))));;
1579 refine (by (VALID (((((USE_THM_THEN second_derivative_compose_sqrt)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "f_pos")(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THEN "bounded")(new_rewrite [] []))) THEN (done_tac)))));;
1580 let second_derivative_compose_sqrt_bounds = end_section_proof();;
1581 (start_section_proof ["dd_bounds"](`iabs int < &1 ==>
1582         bounded_on_int (\x. --(x / sqrt ((&1 - x * x) pow 3))) int dd_bounds ==>
1583         has_bounded_second_derivative acs int dd_bounds`));;
1584 refine (by (VALID (((((USE_THM_THEN has_bounded_second_derivative)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN bounded_on_int)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] []))) THEN (simp_tac)) THEN (move ["int_abs"]) THEN (move ["bounded"])))));;
1585 refine (by (VALID (((split_tac) THEN (move ["x"]) THEN (move ["ineq"])))));;
1586 refine (by (VALID (((((USE_THM_THEN diff2_acs)(new_rewrite [] [])) THEN ((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN interval_arith_abs)(ISPEC_THEN (mk_var("x",mk_type("real",[]))) thm_tac))(ISPEC_THEN (mk_var("int",mk_type("prod",[mk_type("real",[]);mk_type("real",[])]))) thm_tac))(new_rewrite [] []))) THEN (done_tac)))));;
1587 refine (by (VALID (((((USE_THM_THEN second_derivative_acs)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN interval_arith_abs)(ISPEC_THEN (mk_var("x",mk_type("real",[]))) thm_tac))(ISPEC_THEN (mk_var("int",mk_type("prod",[mk_type("real",[]);mk_type("real",[])]))) thm_tac))(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THEN "bounded")(new_rewrite [] []))) THEN (done_tac)))));;
1588 let second_derivative_acs_bounds = end_section_proof();;
1589 (start_section_proof ["f";"f_bounds";"dd_bounds"](`bounded_on_int f int f_bounds ==> iabs f_bounds < &1 ==>
1590         nth_diff_strong_int 2 int f ==>
1591         bounded_on_int (\x. --((nth_derivative 2 f x * (&1 - f x * f x) + f x * derivative f x pow 2) /
1592                                 sqrt ((&1 - f x * f x) pow 3))) int dd_bounds ==>
1593         has_bounded_second_derivative (\x. acs (f x)) int dd_bounds`));;
1594 refine (by (VALID (((((USE_THM_THEN has_bounded_second_derivative)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN bounded_on_int)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] []))) THEN (simp_tac)) THEN (move ["f_bounded"]) THEN (move ["f_abs"]) THEN (move ["df"]) THEN (move ["bounded"])))));;
1595 refine (by (VALID ((have_tac (move ["fabs"]) (`!x. interval_arith x int ==> abs (f x) < &1`)))));;
1596 refine (by (VALID (((BETA_TAC THEN (move ["x"]) THEN (move ["ineq"])) THEN (((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN interval_arith_abs)(ISPEC_THEN (`f x`) thm_tac))(ISPEC_THEN (mk_var("f_bounds",mk_type("prod",[mk_type("real",[]);mk_type("real",[])]))) thm_tac))(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THEN "f_bounded")(new_rewrite [] []))) THEN (done_tac)))));;
1597 refine (by (VALID (((split_tac) THEN (move ["x"]) THEN (move ["ineq"])))));;
1598 refine (by (VALID (((((USE_THM_THEN diff2_compose_acs)(new_rewrite [] [])) THEN ((USE_THEN "df")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THEN "fabs")(new_rewrite [] []))) THEN (done_tac)))));;
1599 refine (by (VALID (((((USE_THM_THEN second_derivative_compose_acs)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "fabs")(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THEN "bounded")(new_rewrite [] []))) THEN (done_tac)))));;
1600 let second_derivative_compose_acs_bounds = end_section_proof();;
1601 (start_section_proof ["c";"f";"dd_bounds"](`nth_diff_strong_int 2 int f ==>
1602         bounded_on_int (\x. c * nth_derivative 2 f x) int dd_bounds ==>
1603         has_bounded_second_derivative (\x. c * f x) int dd_bounds`));;
1604 refine (by (VALID (((((USE_THM_THEN has_bounded_second_derivative)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN bounded_on_int)(new_rewrite [] [])))) THEN (simp_tac) THEN (move ["df"]) THEN (move ["b"])))));;
1605 refine (by (VALID (((((USE_THM_THEN nth_diff_scale)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (move ["x"]) THEN (move ["ineq"])))));;
1606 refine (by (VALID ((((USE_THM_THEN second_derivative_scale)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "b")(new_rewrite [] []))) THEN ((TRY done_tac))))));;
1607 refine (by (VALID (((((USE_THEN "df")MP_TAC) THEN (clear_assumption "df") THEN BETA_TAC) THEN ((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] [])) THEN (exact_tac) THEN (done_tac)))));;
1608 let second_derivative_scale_bounds = end_section_proof();;
1609 (start_section_proof ["f";"g";"dd_bounds"](`nth_diff_strong_int 2 int f ==>
1610         nth_diff_strong_int 2 int g ==>
1611         bounded_on_int (\x. nth_derivative 2 f x + nth_derivative 2 g x) int dd_bounds ==>
1612         has_bounded_second_derivative (\x. f x + g x) int dd_bounds`));;
1613 refine (by (VALID (((((USE_THM_THEN has_bounded_second_derivative)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN bounded_on_int)(new_rewrite [] [])))) THEN (simp_tac) THEN (move ["df"]) THEN (move ["dg"]) THEN (move ["b"])))));;
1614 refine (by (VALID (((((USE_THM_THEN nth_diff_add)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (move ["x"]) THEN (move ["ineq"])))));;
1615 refine (by (VALID ((((USE_THM_THEN second_derivative_add)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "b")(new_rewrite [] []))) THEN ((TRY done_tac))))));;
1616 refine (by (VALID (((((USE_THEN "dg")MP_TAC) THEN (clear_assumption "dg") THEN ((USE_THEN "df")MP_TAC) THEN (clear_assumption "df") THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] []))) THEN (DISCH_THEN(new_rewrite [] [])) THEN ((TRY done_tac)) THEN (DISCH_THEN(new_rewrite [] []))) THEN (done_tac)))));;
1617 let second_derivative_add_bounds = end_section_proof();;
1618 (start_section_proof ["f";"g";"dd_bounds"](`nth_diff_strong_int 2 int f ==>
1619         nth_diff_strong_int 2 int g ==>
1620         bounded_on_int (\x. nth_derivative 2 f x - nth_derivative 2 g x) int dd_bounds ==>
1621         has_bounded_second_derivative (\x. f x - g x) int dd_bounds`));;
1622 refine (by (VALID (((((USE_THM_THEN has_bounded_second_derivative)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN bounded_on_int)(new_rewrite [] [])))) THEN (simp_tac) THEN (move ["df"]) THEN (move ["dg"]) THEN (move ["b"])))));;
1623 refine (by (VALID (((((USE_THM_THEN nth_diff_sub)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (move ["x"]) THEN (move ["ineq"])))));;
1624 refine (by (VALID ((((USE_THM_THEN second_derivative_sub)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "b")(new_rewrite [] []))) THEN ((TRY done_tac))))));;
1625 refine (by (VALID (((((USE_THEN "dg")MP_TAC) THEN (clear_assumption "dg") THEN ((USE_THEN "df")MP_TAC) THEN (clear_assumption "df") THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] []))) THEN (DISCH_THEN(new_rewrite [] [])) THEN ((TRY done_tac)) THEN (DISCH_THEN(new_rewrite [] []))) THEN (done_tac)))));;
1626 let second_derivative_sub_bounds = end_section_proof();;
1627 (start_section_proof ["f";"g";"dd_bounds"](`nth_diff_strong_int 2 int f ==>
1628         nth_diff_strong_int 2 int g ==>
1629         bounded_on_int (\x. f x * nth_derivative 2 g x + &2 * derivative f x * derivative g x +
1630                         nth_derivative 2 f x * g x) int dd_bounds ==>
1631         has_bounded_second_derivative (\x. f x * g x) int dd_bounds`));;
1632 refine (by (VALID (((((USE_THM_THEN has_bounded_second_derivative)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN bounded_on_int)(new_rewrite [] [])))) THEN (simp_tac) THEN (move ["df"]) THEN (move ["dg"]) THEN (move ["b"])))));;
1633 refine (by (VALID (((((USE_THM_THEN nth_diff_mul)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (move ["x"]) THEN (move ["ineq"])))));;
1634 refine (by (VALID ((((USE_THM_THEN second_derivative_mul)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "b")(new_rewrite [] []))) THEN ((TRY done_tac))))));;
1635 refine (by (VALID (((((USE_THEN "dg")MP_TAC) THEN (clear_assumption "dg") THEN ((USE_THEN "df")MP_TAC) THEN (clear_assumption "df") THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] []))) THEN (DISCH_THEN(new_rewrite [] [])) THEN ((TRY done_tac)) THEN (DISCH_THEN(new_rewrite [] []))) THEN (done_tac)))));;
1636 let second_derivative_mul_bounds = end_section_proof();;
1637 (start_section_proof ["f";"g";"g_bounds";"dd_bounds"](`bounded_on_int g int g_bounds ==> interval_not_zero g_bounds ==>
1638         nth_diff_strong_int 2 int f ==>
1639         nth_diff_strong_int 2 int g ==>
1640         bounded_on_int (\x. ((nth_derivative 2 f x * g x - f x * nth_derivative 2 g x) * g x -
1641           &2 * derivative g x * (derivative f x * g x - f x * derivative g x)) / g x pow 3) int dd_bounds ==>
1642         has_bounded_second_derivative (\x. f x / g x) int dd_bounds`));;
1643 refine (by (VALID (((((USE_THM_THEN has_bounded_second_derivative)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN bounded_on_int)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] [])))) THEN (move ["bg"]) THEN (move ["gn0"]) THEN (simp_tac) THEN (move ["df"]) THEN (move ["dg"]) THEN (move ["b"])))));;
1644 refine (by (VALID ((have_tac (move ["g0"]) (`!x. interval_arith x int ==> ~(g x = &0)`)))));;
1645 refine (by (VALID (((BETA_TAC THEN (move ["x"]) THEN (move ["ineq"])) THEN (((USE_THM_THEN interval_arith_not_zero)MP_TAC) THEN (clear_assumption "interval_arith_not_zero") THEN (DISCH_THEN apply_tac)) THEN (exists_tac (`g_bounds`)) THEN ((USE_THEN "bg")(new_rewrite [] [])) THEN (done_tac)))));;
1646 refine (by (VALID (((THENL_FIRST) ((split_tac) THEN (move ["x"]) THEN (move ["ineq"])) ((((USE_THM_THEN diff2_div)(new_rewrite [] [])) THEN ((USE_THEN "g0")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THEN "df")(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "dg")(new_rewrite [] [])))) THEN (done_tac))))));;
1647 refine (by (VALID (((((USE_THM_THEN second_derivative_div)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "g0")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "dg")(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THEN "b")(new_rewrite [] []))) THEN (done_tac)))));;
1648 let second_derivative_div_bounds = end_section_proof();;
1649 let second_derivative_div_bounds = finalize_theorem second_derivative_div_bounds;;
1650 let second_derivative_mul_bounds = finalize_theorem second_derivative_mul_bounds;;
1651 let second_derivative_sub_bounds = finalize_theorem second_derivative_sub_bounds;;
1652 let second_derivative_add_bounds = finalize_theorem second_derivative_add_bounds;;
1653 let second_derivative_scale_bounds = finalize_theorem second_derivative_scale_bounds;;
1654 let second_derivative_compose_acs_bounds = finalize_theorem second_derivative_compose_acs_bounds;;
1655 let second_derivative_acs_bounds = finalize_theorem second_derivative_acs_bounds;;
1656 let second_derivative_compose_sqrt_bounds = finalize_theorem second_derivative_compose_sqrt_bounds;;
1657 let second_derivative_sqrt_bounds = finalize_theorem second_derivative_sqrt_bounds;;
1658 let second_derivative_compose_inv_bounds = finalize_theorem second_derivative_compose_inv_bounds;;
1659 let second_derivative_inv_bounds = finalize_theorem second_derivative_inv_bounds;;
1660 let second_derivative_compose_atn_bounds = finalize_theorem second_derivative_compose_atn_bounds;;
1661 let second_derivative_atn_bounds = finalize_theorem second_derivative_atn_bounds;;
1662 let second_derivative_compose_bounds = finalize_theorem second_derivative_compose_bounds;;
1663 let second_derivative_sub = finalize_theorem second_derivative_sub;;
1664 let second_derivative_add = finalize_theorem second_derivative_add;;
1665 let second_derivative_scale = finalize_theorem second_derivative_scale;;
1666 let diff2_div = finalize_theorem diff2_div;;
1667 let second_derivative_div = finalize_theorem second_derivative_div;;
1668 let second_derivative_mul = finalize_theorem second_derivative_mul;;
1669 let diff2_compose_acs = finalize_theorem diff2_compose_acs;;
1670 let diff2_compose_sqrt = finalize_theorem diff2_compose_sqrt;;
1671 let diff2_compose_inv = finalize_theorem diff2_compose_inv;;
1672 let diff2_compose_atn = finalize_theorem diff2_compose_atn;;
1673 let second_derivative_compose_acs = finalize_theorem second_derivative_compose_acs;;
1674 let second_derivative_compose_sqrt = finalize_theorem second_derivative_compose_sqrt;;
1675 let second_derivative_compose_inv = finalize_theorem second_derivative_compose_inv;;
1676 let second_derivative_compose_atn = finalize_theorem second_derivative_compose_atn;;
1677 let continuous_lt_exists_open = finalize_theorem continuous_lt_exists_open;;
1678 let continuous_gt_exists_open = finalize_theorem continuous_gt_exists_open;;
1679 let continuous_not0_exists_open = finalize_theorem continuous_not0_exists_open;;
1680 let diff2_compose = finalize_theorem diff2_compose;;
1681 let second_derivative_compose = finalize_theorem second_derivative_compose;;
1682 let REAL_CONTINUOUS_OPEN_PREIMAGE = finalize_theorem REAL_CONTINUOUS_OPEN_PREIMAGE;;
1683 let diff2_acs = finalize_theorem diff2_acs;;
1684 let second_derivative_acs = finalize_theorem second_derivative_acs;;
1685 let real_powS = finalize_theorem real_powS;;
1686 let diff2_sqrt = finalize_theorem diff2_sqrt;;
1687 let second_derivative_sqrt = finalize_theorem second_derivative_sqrt;;
1688 let SQRT_POW = finalize_theorem SQRT_POW;;
1689 let diff2_inv = finalize_theorem diff2_inv;;
1690 let second_derivative_inv = finalize_theorem second_derivative_inv;;
1691 let diff2_atn = finalize_theorem diff2_atn;;
1692 let second_derivative_atn = finalize_theorem second_derivative_atn;;
1693 let second_derivative_atn_eq = finalize_theorem second_derivative_atn_eq;;
1694 let lin_approx_compose = finalize_theorem lin_approx_compose;;
1695 let nth_diff_strong2_eq = finalize_theorem nth_diff_strong2_eq;;
1696 let nth_diff_strong2_eq_alt = finalize_theorem nth_diff_strong2_eq_alt;;
1697 (end_section "SecondDerivativeBound");;
1698 (begin_section "TaylorArith");;
1699 let cell_domain = new_definition `cell_domain x y z w <=> 
1700         x <= y /\ y <= z /\ y - x <= w /\ z - y <= w`;;
1701 (start_section_proof ["x";"y";"z";"w"](`cell_domain x y z w ==>
1702         taylor_interval (\x. x) x y z w (y, y) (&1, &1) (&0, &0)`));;
1703 refine (by (VALID ((((USE_THM_THEN cell_domain)(new_rewrite [] [])) THEN (move ["ineqs"])))));;
1704 refine (by (VALID ((((USE_THM_THEN taylor_interval)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THEN "ineqs")(new_rewrite [] []))) THEN ((USE_THM_THEN lin_approx_x)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] [])))))));;
1705 refine (by (VALID (((USE_THM_THEN has_bounded_second_derivative)(new_rewrite [] [])))));;
1706 refine (by (VALID (((((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] [])) THEN ((USE_THM_THEN nth_diff_strong)(new_rewrite [] [])) THEN ((USE_THM_THEN nth_differentiable_on)(new_rewrite [] [])) THEN ((USE_THM_THEN nth_differentiable_eq)(new_rewrite [] []))) THEN (split_tac)))));;
1707 refine (by (VALID (((BETA_TAC THEN (move ["p"]) THEN (move ["_"])) THEN (exists_tac (`(:real)`)) THEN ((((USE_THM_THEN REAL_OPEN_UNIV)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_UNIV)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] [])))) THEN (move ["q"]) THEN (simp_tac))))));;
1708 refine (by (VALID (((((USE_THM_THEN REAL_CONTINUOUS_AT_ID)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (move ["i"])))));;
1709 refine (by (VALID ((((USE_THM_THEN (ARITH_RULE `i < 2 <=> i = 0 \/ i = 1`))(new_rewrite [] [])) THEN (case THEN (DISCH_THEN(new_rewrite [] [])))))));;
1710 refine (by (VALID (((((USE_THM_THEN nth_derivative0)(new_rewrite [] [])) THEN ((USE_THM_THEN ONE)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN nth_derivative1)(new_rewrite [] [])) THEN ((USE_THM_THEN derivative_x)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN HAS_REAL_DERIVATIVE_ID)(new_rewrite [] []))) THEN (done_tac)))));;
1711 refine (by (VALID ((((USE_THM_THEN nth_derivative1)(new_rewrite [] [])) THEN ((USE_THM_THEN TWO)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN nth_derivative2)(new_rewrite [] [])) THEN ((USE_THM_THEN derivative_x)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN derivative_const)(new_rewrite [] [])) THEN (simp_tac)))));;
1712 refine (by (VALID ((((USE_THM_THEN HAS_REAL_DERIVATIVE_CONST)(new_rewrite [] [])) THEN (done_tac)))));;
1713 refine (by (VALID ((((USE_THM_THEN nth_derivative2)(new_rewrite [] [])) THEN ((USE_THM_THEN derivative_x)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN derivative_const)(new_rewrite [] [])) THEN ((USE_THM_THEN bounded_on_int)(new_rewrite [] [])) THEN (simp_tac)))));;
1714 refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN interval_arith)(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_LE_REFL)(new_rewrite [] []))) THEN (done_tac)))));;
1715 let taylor_x = end_section_proof();;
1716 (start_section_proof ["c";"x";"y";"z";"w"](`cell_domain x y z w ==>
1717         taylor_interval (\x. c) x y z w (c, c) (&0, &0) (&0, &0)`));;
1718 refine (by (VALID ((((USE_THM_THEN cell_domain)(new_rewrite [] [])) THEN (move ["ineqs"])))));;
1719 refine (by (VALID ((((USE_THM_THEN taylor_interval)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THEN "ineqs")(new_rewrite [] []))) THEN ((USE_THM_THEN lin_approx_const)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] [])))))));;
1720 refine (by (VALID (((USE_THM_THEN has_bounded_second_derivative)(new_rewrite [] [])))));;
1721 refine (by (VALID (((((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] [])) THEN ((USE_THM_THEN nth_diff_strong)(new_rewrite [] [])) THEN ((USE_THM_THEN nth_differentiable_on)(new_rewrite [] [])) THEN ((USE_THM_THEN nth_differentiable_eq)(new_rewrite [] []))) THEN (split_tac)))));;
1722 refine (by (VALID (((BETA_TAC THEN (move ["p"]) THEN (move ["_"])) THEN (exists_tac (`(:real)`)) THEN ((((USE_THM_THEN REAL_OPEN_UNIV)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_UNIV)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] [])))) THEN (move ["q"]) THEN (simp_tac))))));;
1723 refine (by (VALID (((((USE_THM_THEN REAL_CONTINUOUS_CONST)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (move ["i"])))));;
1724 refine (by (VALID ((((USE_THM_THEN (ARITH_RULE `i < 2 <=> i = 0 \/ i = 1`))(new_rewrite [] [])) THEN (case THEN (DISCH_THEN(new_rewrite [] [])))))));;
1725 refine (by (VALID (((((USE_THM_THEN nth_derivative0)(new_rewrite [] [])) THEN ((USE_THM_THEN ONE)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN nth_derivative1)(new_rewrite [] [])) THEN ((USE_THM_THEN derivative_const)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN HAS_REAL_DERIVATIVE_CONST)(new_rewrite [] []))) THEN (done_tac)))));;
1726 refine (by (VALID (((((USE_THM_THEN nth_derivative1)(new_rewrite [] [])) THEN ((USE_THM_THEN TWO)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN nth_derivative2)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN derivative_const)(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN HAS_REAL_DERIVATIVE_CONST)(new_rewrite [] []))) THEN (done_tac)))));;
1727 refine (by (VALID ((((USE_THM_THEN nth_derivative2)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN derivative_const)(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN bounded_on_int)(new_rewrite [] [])) THEN (simp_tac)))));;
1728 refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN interval_arith)(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_LE_REFL)(new_rewrite [] []))) THEN (done_tac)))));;
1729 let taylor_const = end_section_proof();;
1730 (add_section_var (mk_var ("f", (`:real->real`))));;
1731 (add_section_var (mk_var ("x", (`:real`))); add_section_var (mk_var ("y", (`:real`))); add_section_var (mk_var ("z", (`:real`))); add_section_var (mk_var ("w", (`:real`))));;
1732 (add_section_var (mk_var ("f_bounds", (`:real#real`))); add_section_var (mk_var ("df_bounds", (`:real#real`))); add_section_var (mk_var ("dd_bounds", (`:real#real`))));;
1733 (add_section_var (mk_var ("f_lo", (`:real`))); add_section_var (mk_var ("f_hi", (`:real`))); add_section_var (mk_var ("df_lo", (`:real`))); add_section_var (mk_var ("df_hi", (`:real`))));;
1734 (start_section_proof ["df";"dd";"lo";"hi";"t"](`taylor_interval f x y z w (f_lo, f_hi) df_bounds dd_bounds ==>
1735         iabs df_bounds = df ==>
1736         iabs dd_bounds = dd ==>
1737         w * (df + w * dd * inv(&2)) <= t ==>
1738         f_hi + t <= hi ==> lo <= f_lo - t ==>
1739         bounded_on_int f (x, z) (lo, hi)`));;
1740 refine (by (VALID ((BETA_TAC THEN (move ["taylor_f"]) THEN (move ["iabs_df"]) THEN (move ["iabs_dd"]) THEN (move ["t_ineq"]) THEN (move ["hi_ineq"]) THEN (move ["lo_ineq"])))));;
1741 refine (by (VALID (((((USE_THM_THEN bounded_on_int)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN interval_arith)(new_rewrite [] [])))) THEN (move ["p"]) THEN (move ["ineq"])))));;
1742 refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN taylor_upper_bound)(fun fst_th ->(fun thm_tac -> (USE_THM_THEN EQ_SYM)(fun fst_th ->(USE_THEN "iabs_dd")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "taylor_f")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN ((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN taylor_lower_bound)(fun fst_th ->(fun thm_tac -> (USE_THM_THEN EQ_SYM)(fun fst_th ->(USE_THEN "iabs_dd")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "taylor_f")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC))));;
1743 refine (by (VALID ((((simp_tac) THEN repeat_tactic 1 9 (((USE_THM_THEN real_div)(new_rewrite [] []))) THEN ((USE_THEN "iabs_df")(new_rewrite [] []))) THEN ((fun thm_tac -> DISCH_THEN (fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN (move ["ineq1"]) THEN ((fun thm_tac -> DISCH_THEN (fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN (move ["ineq2"])))));;
1744 refine (by (VALID (((((USE_THEN "t_ineq")MP_TAC) THEN (clear_assumption "t_ineq") THEN ((USE_THEN "hi_ineq")MP_TAC) THEN (clear_assumption "hi_ineq") THEN ((USE_THEN "lo_ineq")MP_TAC) THEN (clear_assumption "lo_ineq") THEN ((USE_THEN "ineq2")MP_TAC) THEN (clear_assumption "ineq2") THEN ((USE_THEN "ineq1")MP_TAC) THEN (clear_assumption "ineq1") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
1745 let taylor_f_bounds = end_section_proof();;
1746 (start_section_proof ["dd";"lo";"hi"](`taylor_interval f x y z w f_bounds (df_lo, df_hi) dd_bounds ==>
1747         iabs dd_bounds = dd ==>
1748         df_hi + w * dd <= hi ==>
1749         lo <= df_lo - w * dd ==>
1750         bounded_on_int (derivative f) (x, z) (lo, hi)`));;
1751 refine (by (VALID ((BETA_TAC THEN (move ["taylor_f"]) THEN (move ["iabs_dd"]) THEN (move ["hi_ineq"]) THEN (move ["lo_ineq"])))));;
1752 refine (by (VALID (((((USE_THM_THEN bounded_on_int)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN interval_arith)(new_rewrite [] [])))) THEN (move ["p"]) THEN (move ["ineq"])))));;
1753 refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN taylor_derivative_lower_bound)(fun fst_th ->(fun thm_tac -> (USE_THM_THEN EQ_SYM)(fun fst_th ->(USE_THEN "iabs_dd")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "taylor_f")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC))));;
1754 refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN taylor_derivative_upper_bound)(fun fst_th ->(fun thm_tac -> (USE_THM_THEN EQ_SYM)(fun fst_th ->(USE_THEN "iabs_dd")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "taylor_f")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC))));;
1755 refine (by (VALID (((((USE_THEN "hi_ineq")MP_TAC) THEN (clear_assumption "hi_ineq") THEN ((USE_THEN "lo_ineq")MP_TAC) THEN (clear_assumption "lo_ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));;
1756 let taylor_df_bounds = end_section_proof();;
1757 (start_section_proof ["g";"int";"g_bounds"](`bounded_on_int g int g_bounds ==>
1758         bounded_on_int f g_bounds f_bounds ==>
1759         bounded_on_int (\x. f (g x)) int f_bounds`));;
1760 refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN bounded_on_int)(new_rewrite [] []))) THEN (move ["g_bounded"]) THEN (move ["f_bounded"]) THEN (move ["x"]) THEN (move ["ineq"]) THEN (simp_tac)))));;
1761 refine (by (VALID (((((USE_THEN "f_bounded")(new_rewrite [] [])) THEN ((USE_THEN "g_bounded")(new_rewrite [] []))) THEN (done_tac)))));;
1762 let bounded_on_int_compose = end_section_proof();;
1763 (start_section_proof ["int"](`bounded_on_int f int f_bounds ==>
1764         interval_arith y int ==> interval_arith (f y) f_bounds`));;
1765 refine (by (VALID ((((USE_THM_THEN bounded_on_int)(new_rewrite [] [])) THEN (move ["bounded_f"]) THEN (move ["int_y"])))));;
1766 refine (by (VALID ((((USE_THEN "bounded_f")(new_rewrite [] [])) THEN (done_tac)))));;
1767 let bounded_on_int_imp_interval_arith = end_section_proof();;
1768 (start_section_proof ["x0";"z0";"w0"](`taylor_interval f x y z w f_bounds df_bounds dd_bounds ==>
1769         cell_domain x0 y z0 w0 ==>
1770         x <= x0 ==> z0 <= z ==>
1771         taylor_interval f x0 y z0 w0 f_bounds df_bounds dd_bounds`));;
1772 refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN taylor_interval)(new_rewrite [] []))) THEN ((USE_THM_THEN cell_domain)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andbA)(new_rewrite [] [])))) THEN ALL_TAC THEN (case THEN ((case THEN ((move ["ineq"]) THEN (move ["lin"]))) THEN (move ["dd"]))) THEN (move ["c"]) THEN (move ["i1"]) THEN (move ["i2"])))));;
1773 refine (by (VALID (((THENL_FIRST) ((((USE_THEN "lin")(new_rewrite [] [])) THEN ((USE_THM_THEN andbT)(new_rewrite [] []))) THEN (split_tac)) ((((USE_THEN "i2")MP_TAC) THEN (clear_assumption "i2") THEN ((USE_THEN "i1")MP_TAC) THEN (clear_assumption "i1") THEN ((USE_THEN "c")MP_TAC) THEN (clear_assumption "c") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac))))));;
1774 refine (by (VALID (((((USE_THEN "dd")MP_TAC) THEN (clear_assumption "dd") THEN BETA_TAC) THEN ((repeat_tactic 1 9 (((USE_THM_THEN has_bounded_second_derivative)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN bounded_on_int)(new_rewrite [] [])))) THEN (move ["df"]))))));;
1775 refine (by (VALID (((split_tac) THEN (move ["p"]) THEN (move ["int_p"])))));;
1776 refine (by (VALID ((((USE_THEN "df")(new_rewrite [] [])) THEN (((USE_THEN "i2")MP_TAC) THEN (clear_assumption "i2") THEN ((USE_THEN "i1")MP_TAC) THEN (clear_assumption "i1") THEN ((USE_THEN "int_p")MP_TAC) THEN (clear_assumption "int_p") THEN BETA_TAC) THEN repeat_tactic 1 9 (((USE_THM_THEN (GEN_ALL interval_arith))(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac)))));;
1777 refine (by (VALID ((((USE_THEN "df")(new_rewrite [] [])) THEN (((USE_THEN "i2")MP_TAC) THEN (clear_assumption "i2") THEN ((USE_THEN "i1")MP_TAC) THEN (clear_assumption "i1") THEN ((USE_THEN "int_p")MP_TAC) THEN (clear_assumption "int_p") THEN BETA_TAC) THEN repeat_tactic 1 9 (((USE_THM_THEN (GEN_ALL interval_arith))(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac)))));;
1778 let taylor_interval_narrow = end_section_proof();;
1779 let taylor_interval_narrow = finalize_theorem taylor_interval_narrow;;
1780 let bounded_on_int_imp_interval_arith = finalize_theorem bounded_on_int_imp_interval_arith;;
1781 let bounded_on_int_compose = finalize_theorem bounded_on_int_compose;;
1782 let taylor_df_bounds = finalize_theorem taylor_df_bounds;;
1783 let taylor_f_bounds = finalize_theorem taylor_f_bounds;;
1784 let taylor_const = finalize_theorem taylor_const;;
1785 let taylor_x = finalize_theorem taylor_x;;
1786 (end_section "TaylorArith");;