load_path := "/mnt/Repository/jHOLLight"::(!load_path);;
needs "caml/raw_printer.hl";;
needs "caml/sections.hl";;
needs "caml/ssreflect.hl";;
needs "Examples/ssrbool-compiled.hl";;
needs "Examples/ssrnat-compiled.hl";;
needs "../formal_lp/arith/interval_arith.hl";;
prioritize_real();;
open Interval_arith;;

let bounded_on = new_definition `bounded_on f s f_bounds <=>
	!x. x IN s ==> interval_arith (f x) f_bounds`;;
let bounded_on_int = new_definition `bounded_on_int f int f_bounds <=>
	!x. interval_arith x int ==> interval_arith (f x) f_bounds`;;
let derivative = new_definition `derivative f = \y. @d. (f has_real_derivative d) (atreal y)`;;
let nth_derivative = new_definition `nth_derivative n f = iter n derivative f`;;
let nth_differentiable = define `(nth_differentiable 0 f x <=> f real_continuous atreal x) /\
	(nth_differentiable (SUC n) f x <=> nth_differentiable n f x /\ 
			nth_derivative n f real_differentiable atreal x)`;;
let nth_differentiable_on = new_definition `nth_differentiable_on n s f <=>
	!x. x IN s ==> nth_differentiable n f x`;;
let nth_differentiable_on_int = new_definition `nth_differentiable_on_int n int f <=>
	!x. interval_arith x int ==> nth_differentiable n f x`;;
let nth_diff_weak = new_definition `nth_diff_weak n f x <=> f real_continuous atreal x /\ 
	?F. F 0 = f /\ !i. i < n ==> (F i has_real_derivative F (SUC i) x) (atreal x)`;;
let nth_diff_strong = new_definition `nth_diff_strong n f x <=> 
	?s. real_open s /\ x IN s /\ nth_differentiable_on n s f`;;
let nth_diff_strong_int = new_definition `nth_diff_strong_int n int f <=>
	!x. interval_arith x int ==> nth_diff_strong n f x`;;
(begin_section "NthDerivatives");; (start_section_proof ["f";"x"](`(?d. (f has_real_derivative d) (atreal x)) ==> (f has_real_derivative (derivative f x)) (atreal x)`));; refine (by (VALID ((BETA_TAC THEN (case THEN (move ["d"])) THEN (move ["df"])))));; refine (by (VALID (((THENL_FIRST) (((THENL_ROT 1)) (have_tac (DISCH_THEN(new_rewrite [] [])) (`derivative f x = d`))) (exact_tac)))));; 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)))])))));; 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)))));; let has_derivative_cond = end_section_proof();; (start_section_proof ["f";"x"](`f real_differentiable atreal x ==> (f has_real_derivative (derivative f x)) (atreal x)`));; 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)))));; let has_derivative_alt = end_section_proof();; (start_section_proof ["f";"f'";"x"](`(f has_real_derivative f') (atreal x) ==> derivative f x = f'`));; 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))))));; 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)))));; let derivative_unique = end_section_proof();; (start_section_proof ["s";"f";"f'"](`(!x. x IN s ==> (f has_real_derivative f' x) (atreal x)) ==> (!x. x IN s ==> f' x = derivative f x)`));; refine (by (VALID ((BETA_TAC THEN (move ["df"]) THEN (move ["x"]) THEN (move ["xs"])))));; 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)))));; let derivative_unique_on = end_section_proof();; (start_section_proof ["f";"f'";"x"](`f real_differentiable atreal x /\ derivative f x = f' ==> (f has_real_derivative f') (atreal x)`));; 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)))));; let has_derivative_lemma = end_section_proof();; (start_section_proof ["f"](`nth_derivative 0 f = f`));; refine (by (VALID (((((USE_THM_THEN nth_derivative)(new_rewrite [] [])) THEN ((USE_THM_THEN (GEN_ALL iter))(new_rewrite [] []))) THEN (done_tac)))));; let nth_derivative0 = end_section_proof();; (start_section_proof ["n";"f"](`nth_derivative (SUC n) f = derivative (nth_derivative n f)`));; refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN nth_derivative)(new_rewrite [] []))) THEN ((USE_THM_THEN iterS)(new_rewrite [] []))) THEN (done_tac)))));; let nth_derivativeS = end_section_proof();; (start_section_proof ["n";"f"](`nth_derivative (SUC n) f = nth_derivative n (derivative f)`));; 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)))));; let nth_Sderivative = end_section_proof();; (start_section_proof ["f"](`nth_derivative 1 f = derivative f`));; 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)))));; let nth_derivative1 = end_section_proof();; (start_section_proof ["f"](`nth_derivative 2 f = derivative (derivative f)`));; 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)))));; let nth_derivative2 = end_section_proof();; (start_section_proof ["n";"m";"f"](`nth_derivative n (nth_derivative m f) = nth_derivative (n + m) f`));; 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)))));; let nth_derivative_add = end_section_proof();; (start_section_proof ["n";"f";"x"](`nth_differentiable n f x ==> f real_continuous atreal x`));; 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)))))));; 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)))));; let nth_diff_continuous = end_section_proof();; (start_section_proof ["n";"f";"x"](`nth_differentiable n f x ==> !i. i < n ==> (nth_derivative i f has_real_derivative (nth_derivative (SUC i) f x)) (atreal x)`));; 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))))));; 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"])))));; 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)))])))));; refine (by (VALID (((((USE_THM_THEN nth_derivativeS)(new_rewrite [] [])) THEN ((USE_THM_THEN has_derivative_alt)(new_rewrite [] []))) THEN (done_tac)))));; let nth_differentiable_cond = end_section_proof();; (start_section_proof ["n";"s";"f"](`nth_differentiable_on n s f ==> !x. x IN s ==> !i. i < n ==> (nth_derivative i f has_real_derivative (nth_derivative (SUC i) f x)) (atreal x)`));; refine (by (VALID ((((USE_THM_THEN nth_differentiable_on)(new_rewrite [] [])) THEN (move ["cond"]) THEN (move ["x"])))));; 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)))));; let nth_differentiable_on_cond = end_section_proof();; (start_section_proof ["n";"f";"x"](`nth_differentiable n f x <=> f real_continuous atreal x /\ !i. i < n ==> (nth_derivative i f has_real_derivative (nth_derivative (SUC i) f x)) (atreal x)`));; refine (by (VALID (((split_tac) THENL [(move ["dn_f"]); (case THEN (move ["f_cont"]))]))));; 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)))));; 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"]))))));; 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))))));; refine (by (VALID ((((USE_THM_THEN real_differentiable)(new_rewrite [] [])) THEN (exists_tac (`nth_derivative (SUC n) f x`))))));; refine (by (VALID ((((USE_THEN "cond")MP_TAC) THEN (clear_assumption "cond") THEN (exact_tac)))));; let nth_differentiable_eq = end_section_proof();; (start_section_proof ["f";"int"](`nth_differentiable_on_int 2 int f ==> ?f' f''. f' = derivative f /\ f'' = nth_derivative 2 f /\ !x. interval_arith x int ==> (f has_real_derivative f' x) (atreal x) /\ (f' has_real_derivative f'' x) (atreal x)`));; refine (by (VALID ((((USE_THM_THEN nth_differentiable_on_int)(new_rewrite [] [])) THEN (move ["h"])))));; refine (by (VALID ((((exists_tac (`derivative f`)) THEN (exists_tac (`nth_derivative 2 f`))) THEN (simp_tac) THEN (move ["x"]) THEN (move ["ineq"])))));; 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 [] []))))));; 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)))));; let nth_differentiable_on_int2 = end_section_proof();; (start_section_proof ["n";"m";"f";"x"](`n <= m ==> nth_differentiable m f x ==> nth_differentiable n f x`));; 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"]))))));; 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)))));; let nth_mth_diff = end_section_proof();; (start_section_proof ["f";"x"](`nth_differentiable 1 f x <=> f real_differentiable atreal x`));; 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"])])))));; refine (by (VALID ((((USE_THM_THEN REAL_DIFFERENTIABLE_IMP_CONTINUOUS_ATREAL)(new_rewrite [] [])) THEN (done_tac)))));; let nth_differentiable1 = end_section_proof();; (start_section_proof ["n";"f";"x"](`0 < n ==> nth_differentiable n f x ==> f real_differentiable atreal x`));; 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)))));; let nth_diff_imp_diff = end_section_proof();; (start_section_proof ["n";"f";"x";"i"](`nth_differentiable n f x ==> i < n ==> nth_derivative i f real_continuous atreal x`));; refine (by (VALID ((((USE_THM_THEN nth_differentiable_eq)(new_rewrite [] [])) THEN ALL_TAC THEN (case THEN (move ["_"])) THEN (move ["df"])))));; 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))))));; refine (by (VALID ((((USE_THM_THEN real_differentiable)(new_rewrite [] [])) THEN (exists_tac (`nth_derivative (SUC i) f x`)) THEN (done_tac)))));; let nth_derivative_continuous = end_section_proof();; (start_section_proof ["i";"n";"f";"x"](`nth_differentiable n f x ==> i < n ==> nth_differentiable (n - i) (nth_derivative i f) x`));; refine (by (VALID ((BETA_TAC THEN (move ["dnf"])))));; 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"]))))));; 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"])))));; 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)))));; let ith_derivative_differentiable = end_section_proof();; (start_section_proof ["n";"f";"x"](`nth_diff_strong n f x ==> nth_differentiable n f x`));; 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"]))))));; refine (by (VALID ((((USE_THEN "h")MP_TAC) THEN (clear_assumption "h") THEN (exact_tac)))));; let nth_diff_strong_imp_diff = end_section_proof();; (begin_section "DerivativeArith");; (begin_section "ElementaryDerivatives");; (start_section_proof [](`derivative (\x. x) = (\x. &1)`));; refine (by (VALID ((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN (move ["x"]) THEN (simp_tac)))));; 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)))));; let derivative_x = end_section_proof();; (start_section_proof ["c"](`derivative (\x. c) = (\x. &0)`));; refine (by (VALID ((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN (move ["x"]) THEN (simp_tac)))));; 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)))));; let derivative_const = end_section_proof();; (start_section_proof ["x"](`~(x = &0) ==> derivative inv x = -- inv (x * x)`));; refine (by (VALID ((BETA_TAC THEN (move ["xn0"])))));; 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)))));; let derivative_inv = end_section_proof();; (start_section_proof [](`derivative atn = (\x. inv (&1 + x * x))`));; 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)))));; 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)))));; let derivative_atn = end_section_proof();; (start_section_proof [](`derivative exp = exp`));; refine (by (VALID ((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN (move ["x"]) THEN (simp_tac)))));; 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)))));; let derivative_exp = end_section_proof();; (start_section_proof ["x"](`abs x < &1 ==> derivative acs x = --inv(sqrt(&1 - x * x))`));; refine (by (VALID ((BETA_TAC THEN (move ["x_ineq"])))));; 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)))));; let derivative_acs = end_section_proof();; (start_section_proof ["x"](`&0 < x ==> derivative sqrt x = inv (&2 * sqrt x)`));; refine (by (VALID ((BETA_TAC THEN (move ["xg0"])))));; 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)))));; let derivative_sqrt = end_section_proof();; (start_section_proof ["f";"g";"x"](`f real_differentiable atreal x ==> g real_differentiable atreal (f x) ==> derivative (\x. g (f x)) x = derivative f x * derivative g (f x)`));; 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))))));; 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))))));; refine (by (VALID (((BETA_TAC THEN (case THEN (move ["_"]))) THEN (DISCH_THEN apply_tac) THEN (done_tac)))));; let derivative_composition = end_section_proof();; (begin_section "ElementaryCompose");; (start_section_proof ["x"](`~(x = &0) ==> inv real_differentiable atreal x`));; refine (by (VALID ((BETA_TAC THEN (move ["xn0"])))));; 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))));; 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)))));; let REAL_DIFFERENTIABLE_AT_INV = end_section_proof();; (add_section_var (mk_var ("f", (`:real->real`))));; (add_section_var (mk_var ("x", (`:real`))));; (add_section_hyp "df" (`f real_differentiable atreal x`));; (start_section_proof [](`(\x. atn (f x)) real_differentiable atreal x /\ derivative (\x. atn (f x)) x = derivative f x / (&1 + f x * f x)`));; refine (by (VALID ((split_tac))));; 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))))));; refine (by (VALID (((((USE_THM_THEN REAL_DIFFERENTIABLE_AT_ATN)(new_rewrite [] [])) THEN ((USE_THEN "df")(new_rewrite [] []))) THEN (done_tac)))));; 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))))));; refine (by (VALID (((((USE_THM_THEN derivative_atn)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN real_div)(new_rewrite [] []))) THEN (done_tac)))));; let derivative_compose_atn = end_section_proof();; (start_section_proof [](`(\x. exp (f x)) real_differentiable atreal x /\ derivative (\x. exp (f x)) x = exp (f x) * derivative f x`));; refine (by (VALID ((split_tac))));; 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))))));; refine (by (VALID (((((USE_THM_THEN REAL_DIFFERENTIABLE_AT_EXP)(new_rewrite [] [])) THEN ((USE_THEN "df")(new_rewrite [] []))) THEN (done_tac)))));; 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))))));; refine (by (VALID (((((USE_THM_THEN derivative_exp)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_SYM)(new_rewrite [] []))) THEN (done_tac)))));; let derivative_compose_exp = end_section_proof();; (start_section_proof [](`~(f x = &0) ==> (\x. inv (f x)) real_differentiable atreal x /\ derivative (\x. inv (f x)) x = -- inv (f x * f x) * derivative f x`));; 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))))));; 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)))));; let derivative_compose_inv = end_section_proof();; (start_section_proof [](`&0 < f x ==> (\x. sqrt (f x)) real_differentiable atreal x /\ derivative (\x. sqrt (f x)) x = derivative f x / (&2 * sqrt (f x))`));; refine (by (VALID (((BETA_TAC THEN (move ["f_pos"])) THEN (split_tac)))));; 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))))));; 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)))));; 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))))));; 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)))));; let derivative_compose_sqrt = end_section_proof();; (start_section_proof [](`abs (f x) < &1 ==> (\x. acs (f x)) real_differentiable atreal x /\ derivative (\x. acs (f x)) x = -- (derivative f x / sqrt (&1 - f x * f x))`));; refine (by (VALID (((BETA_TAC THEN (move ["f_abs"])) THEN (split_tac)))));; 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))))));; 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)))));; 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))))));; 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)))));; let derivative_compose_acs = end_section_proof();; let derivative_compose_acs = finalize_theorem derivative_compose_acs;; let derivative_compose_sqrt = finalize_theorem derivative_compose_sqrt;; let derivative_compose_inv = finalize_theorem derivative_compose_inv;; let derivative_compose_exp = finalize_theorem derivative_compose_exp;; let derivative_compose_atn = finalize_theorem derivative_compose_atn;; let REAL_DIFFERENTIABLE_AT_INV = finalize_theorem REAL_DIFFERENTIABLE_AT_INV;; (end_section "ElementaryCompose");; let derivative_compose_acs = finalize_theorem derivative_compose_acs;; let derivative_compose_sqrt = finalize_theorem derivative_compose_sqrt;; let derivative_compose_inv = finalize_theorem derivative_compose_inv;; let derivative_compose_exp = finalize_theorem derivative_compose_exp;; let derivative_compose_atn = finalize_theorem derivative_compose_atn;; let REAL_DIFFERENTIABLE_AT_INV = finalize_theorem REAL_DIFFERENTIABLE_AT_INV;; let derivative_composition = finalize_theorem derivative_composition;; let derivative_sqrt = finalize_theorem derivative_sqrt;; let derivative_acs = finalize_theorem derivative_acs;; let derivative_exp = finalize_theorem derivative_exp;; let derivative_atn = finalize_theorem derivative_atn;; let derivative_inv = finalize_theorem derivative_inv;; let derivative_const = finalize_theorem derivative_const;; let derivative_x = finalize_theorem derivative_x;; (end_section "ElementaryDerivatives");; (add_section_var (mk_var ("f", (`:real -> real`))); add_section_var (mk_var ("g", (`:real -> real`))));; (add_section_var (mk_var ("x", (`:real`))); add_section_var (mk_var ("c", (`:real`))));; (add_section_hyp "df" (`f real_differentiable atreal x`));; (start_section_proof [](`derivative (\x. c * f x) x = c * derivative f x`));; 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)))));; let derivative_scale = end_section_proof();; (start_section_proof [](`derivative (\x. -- f x) x = -- derivative f x`));; 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)))));; let derivative_neg = end_section_proof();; (start_section_proof ["n"](`derivative (\x. f x pow n) x = &n * f x pow (n - 1) * derivative f x`));; 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)))));; let derivative_pow = end_section_proof();; (add_section_hyp "dg" (`g real_differentiable atreal x`));; (start_section_proof [](`derivative (\x. f x + g x) x = derivative f x + derivative g x`));; 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)))));; let derivative_add = end_section_proof();; (start_section_proof [](`derivative (\x. f x * g x) x = f x * derivative g x + derivative f x * g x`));; 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)))));; let derivative_mul = end_section_proof();; (start_section_proof [](`derivative (\x. f x - g x) x = derivative f x - derivative g x`));; 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)))));; let derivative_sub = end_section_proof();; (start_section_proof [](`~(g x = &0) ==> derivative (\x. f x / g x) x = (derivative f x * g x - f x * derivative g x) / (g x * g x)`));; 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)))))));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN has_derivative_alt)(new_rewrite [] []))) THEN (done_tac)))));; let derivative_div = end_section_proof();; let derivative_div = finalize_theorem derivative_div;; let derivative_sub = finalize_theorem derivative_sub;; let derivative_mul = finalize_theorem derivative_mul;; let derivative_add = finalize_theorem derivative_add;; let derivative_pow = finalize_theorem derivative_pow;; let derivative_neg = finalize_theorem derivative_neg;; let derivative_scale = finalize_theorem derivative_scale;; let derivative_compose_acs = finalize_theorem derivative_compose_acs;; let derivative_compose_sqrt = finalize_theorem derivative_compose_sqrt;; let derivative_compose_inv = finalize_theorem derivative_compose_inv;; let derivative_compose_exp = finalize_theorem derivative_compose_exp;; let derivative_compose_atn = finalize_theorem derivative_compose_atn;; let REAL_DIFFERENTIABLE_AT_INV = finalize_theorem REAL_DIFFERENTIABLE_AT_INV;; let derivative_composition = finalize_theorem derivative_composition;; let derivative_sqrt = finalize_theorem derivative_sqrt;; let derivative_acs = finalize_theorem derivative_acs;; let derivative_exp = finalize_theorem derivative_exp;; let derivative_atn = finalize_theorem derivative_atn;; let derivative_inv = finalize_theorem derivative_inv;; let derivative_const = finalize_theorem derivative_const;; let derivative_x = finalize_theorem derivative_x;; (end_section "DerivativeArith");; (begin_section "MoreDerivativeArith");; (start_section_proof ["G";"n";"m";"x"](`(!i. i IN n..m ==> G i real_differentiable atreal x) ==> (\x. sum (n..m) (\i. G i x)) real_differentiable atreal x`));; 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 [] [])))))));; 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)))))));; 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)))));; 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"]))))));; 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))))));; 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)))));; 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)))))));; 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 [] []))))));; refine (by (VALID (((((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; let differentiable_sum_numseg = end_section_proof();; (start_section_proof ["G";"n";"m";"x"](`(!i. i IN n..m ==> G i real_differentiable atreal x) ==> derivative (\x. sum (n..m) (\i. G i x)) x = sum (n..m) (\i. derivative (G i) x)`));; 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 [] [])))))));; 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)))));; 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"]))))));; 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))))));; 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)))));; refine (by (VALID (((USE_THEN "IHm")(GSYM_THEN (new_rewrite [] []))))));; 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))))));; 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)))));; 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)))))));; 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"])))));; 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)))));; let derivative_sum_numseg = end_section_proof();; let derivative_sum_numseg = finalize_theorem derivative_sum_numseg;; let differentiable_sum_numseg = finalize_theorem differentiable_sum_numseg;; (end_section "MoreDerivativeArith");; (start_section_proof ["f";"g";"x";"s"](`g real_differentiable atreal x /\ real_open s /\ x IN s /\ (!y. y IN s ==> f y = g y) ==> f real_differentiable atreal x`));; 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"])))));; 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))))));; 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)))));; let differentiable_local = end_section_proof();; (begin_section "NthDerivativeArith");; (add_section_var (mk_var ("f", (`:real->real`))); add_section_var (mk_var ("g", (`:real->real`))));; (add_section_var (mk_var ("int", (`:real#real`))));; (add_section_var (mk_var ("n", (`:num`))));; (add_section_hyp "df" (`nth_diff_strong_int n int f`));; (start_section_proof ["c";"i";"x"](`interval_arith x int ==> i <= n ==> ?s. real_open s /\ x IN s /\ !y. y IN s ==> nth_derivative i (\y. c * f y) y = c * nth_derivative i f y`));; 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"]))))));; 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"]))))));; 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))))));; refine (by (VALID (((((USE_THM_THEN nth_derivativeS)(new_rewrite [] [])) THEN ((USE_THM_THEN ltE)(GSYM_THEN (new_rewrite [] [])))) THEN (move ["i_lt_n"])))));; 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 ["_"]))))));; 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"]))))))));; refine (by (VALID ((((USE_THM_THEN derivative_unique)MP_TAC) THEN (clear_assumption "derivative_unique") THEN (DISCH_THEN apply_tac)))));; 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)))));; refine (by (VALID ((exists_tac (`\y. c * nth_derivative i f y`)))));; refine (by (VALID ((((USE_THM_THEN HAS_REAL_DERIVATIVE_LMUL_ATREAL)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN andTb)(new_rewrite [] [])))))));; 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)))));; 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))))));; refine (by (VALID ((((USE_THEN "eq")(new_rewrite [] [])) THEN (done_tac)))));; let nth_derivative_scale_strong = end_section_proof();; (start_section_proof ["c";"x"](`interval_arith x int ==> ?s. real_open s /\ x IN s /\ !i y. i <= n /\ y IN s ==> nth_derivative i (\y. c * f y) y = c * nth_derivative i f y`));; 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"])))));; refine (by (VALID ((set_tac "P" (`\i s. real_open s /\ x IN s /\ (!y. y IN s ==> nth_derivative i (\y. c * f y) y = c * nth_derivative i f y)`)))));; refine (by (VALID ((have_tac (move ["sel_P"]) (`!i. i <= n:num ==> P i ((@) (P i))`)))));; refine (by (VALID (((BETA_TAC THEN (move ["i"]) THEN (move ["i_le_n"])) THEN ((USE_THM_THEN SELECT_AX) apply_tac)))));; 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"])))));; 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)))));; refine (by (VALID ((set_tac "S" (`INTERS (IMAGE (\i. (@) (P i)) (0..n))`)))));; refine (by (VALID ((exists_tac (mk_var("S",mk_type("fun",[mk_type("real",[]);mk_type("bool",[])])))))));; 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 [] [])))))));; 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))))))));; refine (by (VALID (((((USE_THEN "P_def")(GSYM_THEN (new_rewrite [1] []))) THEN (simp_tac)) THEN (done_tac)))));; 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)))));; 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))))))));; refine (by (VALID (((((USE_THEN "P_def")(GSYM_THEN (new_rewrite [1] []))) THEN (simp_tac)) THEN (done_tac)))));; refine (by (VALID ((BETA_TAC THEN (move ["i"]) THEN (move ["y"]) THEN (case THEN (move ["i_le_n"]))))));; 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))))));; 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))))));; refine (by (VALID ((((USE_THEN "y_in")MP_TAC) THEN (clear_assumption "y_in") THEN (exact_tac)))));; let nth_derivative_scale_strong_all = end_section_proof();; (start_section_proof ["c";"i";"x"](`interval_arith x int ==> i <= n ==> nth_derivative i (\x. c * f x) x = c * nth_derivative i f x`));; refine (by (VALID ((BETA_TAC THEN (move ["ineq"]) THEN (move ["i_le_n"])))));; 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))));; refine (by (VALID ((BETA_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["_"])) THEN (case THEN (move ["xs"])) THEN (move ["h"])))));; refine (by (VALID ((((USE_THEN "h")MP_TAC) THEN (clear_assumption "h") THEN (exact_tac)))));; let nth_derivative_scale = end_section_proof();; (start_section_proof ["c"](`nth_diff_strong_int n int (\x. c * f x)`));; 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 [] []))))))));; refine (by (VALID ((BETA_TAC THEN (move ["df"]) THEN (move ["x"]) THEN (move ["ineq"])))));; 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))));; refine (by (VALID ((BETA_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["open_s"])) THEN (case THEN (move ["xs"])) THEN (move ["diff"])))));; 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"])))));; 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"]))))))));; 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"])))));; 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))))));; 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)))));; refine (by (VALID ((exists_tac (`(\y. c * nth_derivative i f y)`)))));; 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))))));; 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))))));; 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)))));; let nth_diff_scale = end_section_proof();; (add_section_hyp "dg" (`nth_diff_strong_int n int g`));; (start_section_proof ["i";"x"](`interval_arith x int ==> i <= n ==> ?s. real_open s /\ x IN s /\ !y. y IN s ==> nth_derivative i (\y. f y + g y) y = nth_derivative i f y + nth_derivative i g y`));; 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"]))))));; 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 ["_"]))))));; 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 ["_"]))))));; 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"])))));; 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))))));; refine (by (VALID (((((USE_THM_THEN nth_derivativeS)(new_rewrite [] [])) THEN ((USE_THM_THEN ltE)(GSYM_THEN (new_rewrite [] [])))) THEN (move ["i_lt_n"])))));; 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 ["_"]))))));; refine (by (VALID ((exists_tac (`sf INTER sg INTER t`)))));; 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"])))))));; refine (by (VALID ((((USE_THM_THEN derivative_unique)MP_TAC) THEN (clear_assumption "derivative_unique") THEN (DISCH_THEN apply_tac)))));; 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)))));; refine (by (VALID ((exists_tac (`(\y. nth_derivative i f y + nth_derivative i g y)`)))));; refine (by (VALID ((((USE_THM_THEN HAS_REAL_DERIVATIVE_ADD)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN andTb)(new_rewrite [] [])))))));; 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)))));; 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 [] []))))))));; refine (by (VALID (((BETA_TAC THEN (move ["z"]) THEN (move ["z_in"]) THEN (simp_tac)) THEN ((USE_THEN "eq")(new_rewrite [] [])) THEN (done_tac)))));; let nth_derivative_add_strong = end_section_proof();; (start_section_proof ["x"](`interval_arith x int ==> ?s. real_open s /\ x IN s /\ !i y. i <= n /\ y IN s ==> nth_derivative i (\y. f y + g y) y = nth_derivative i f y + nth_derivative i g y`));; 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"])))));; refine (by (VALID ((set_tac "P" (`\i s. real_open s /\ x IN s /\ (!y. y IN s ==> nth_derivative i (\y. f y + g y) y = nth_derivative i f y + nth_derivative i g y)`)))));; refine (by (VALID ((have_tac (move ["sel_P"]) (`!i. i <= n:num ==> P i ((@) (P i))`)))));; refine (by (VALID (((BETA_TAC THEN (move ["i"]) THEN (move ["i_le_n"])) THEN ((USE_THM_THEN SELECT_AX) apply_tac)))));; 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"])))));; 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)))));; refine (by (VALID ((set_tac "S" (`INTERS (IMAGE (\i. (@) (P i)) (0..n))`)))));; refine (by (VALID ((exists_tac (mk_var("S",mk_type("fun",[mk_type("real",[]);mk_type("bool",[])])))))));; 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 [] [])))))));; 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))))))));; refine (by (VALID (((((USE_THEN "P_def")(GSYM_THEN (new_rewrite [1] []))) THEN (simp_tac)) THEN (done_tac)))));; 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)))));; 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))))))));; refine (by (VALID (((((USE_THEN "P_def")(GSYM_THEN (new_rewrite [1] []))) THEN (simp_tac)) THEN (done_tac)))));; refine (by (VALID ((BETA_TAC THEN (move ["i"]) THEN (move ["y"]) THEN (case THEN (move ["i_le_n"]))))));; 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))))));; 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))))));; refine (by (VALID ((((USE_THEN "y_in")MP_TAC) THEN (clear_assumption "y_in") THEN (exact_tac)))));; let nth_derivative_add_strong_all = end_section_proof();; (start_section_proof ["i";"x"](`interval_arith x int ==> i <= n ==> nth_derivative i (\x. f x + g x) x = nth_derivative i f x + nth_derivative i g x`));; refine (by (VALID ((BETA_TAC THEN (move ["ineq"]) THEN (move ["i_le_n"])))));; 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))));; refine (by (VALID ((BETA_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["_"])) THEN (case THEN (move ["xs"])) THEN (move ["h"])))));; refine (by (VALID ((((USE_THEN "h")MP_TAC) THEN (clear_assumption "h") THEN (exact_tac)))));; let nth_derivative_add = end_section_proof();; (start_section_proof [](`nth_diff_strong_int n int (\x. f x + g x)`));; refine (by (VALID ((((USE_THEN "dg")MP_TAC) THEN ((USE_THEN "df")MP_TAC) THEN BETA_TAC))));; 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 [] [])))))));; refine (by (VALID ((BETA_TAC THEN (move ["df"]) THEN (move ["dg"]) THEN (move ["x"]) THEN (move ["ineq"])))));; 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))));; refine (by (VALID ((BETA_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["open_s"])) THEN (case THEN (move ["xs"])) THEN (move ["diff"])))));; 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"])))));; 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"])))));; 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 [] []))))))));; refine (by (VALID ((BETA_TAC THEN (move ["y"]) THEN (case THEN ((move ["ys"]) THEN (case THEN ((move ["ytf"]) THEN (move ["ytg"])))))))));; 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"])))));; 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))))));; 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)))));; refine (by (VALID ((exists_tac (`(\y. nth_derivative i f y + nth_derivative i g y)`)))));; 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))))));; 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))))));; 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)))));; let nth_diff_add = end_section_proof();; (start_section_proof ["i";"x"](`interval_arith x int ==> i <= n ==> ?s. real_open s /\ x IN s /\ !y. y IN s ==> nth_derivative i (\y. f y - g y) y = nth_derivative i f y - nth_derivative i g y`));; 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"]))))));; 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 ["_"]))))));; 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 ["_"]))))));; 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"])))));; 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))))));; refine (by (VALID (((((USE_THM_THEN nth_derivativeS)(new_rewrite [] [])) THEN ((USE_THM_THEN ltE)(GSYM_THEN (new_rewrite [] [])))) THEN (move ["i_lt_n"])))));; 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 ["_"]))))));; refine (by (VALID ((exists_tac (`sf INTER sg INTER t`)))));; 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"])))))));; refine (by (VALID ((((USE_THM_THEN derivative_unique)MP_TAC) THEN (clear_assumption "derivative_unique") THEN (DISCH_THEN apply_tac)))));; 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)))));; refine (by (VALID ((exists_tac (`(\y. nth_derivative i f y - nth_derivative i g y)`)))));; refine (by (VALID ((((USE_THM_THEN HAS_REAL_DERIVATIVE_SUB)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN andTb)(new_rewrite [] [])))))));; 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)))));; 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 [] []))))))));; refine (by (VALID (((BETA_TAC THEN (move ["z"]) THEN (move ["z_in"]) THEN (simp_tac)) THEN ((USE_THEN "eq")(new_rewrite [] [])) THEN (done_tac)))));; let nth_derivative_sub_strong = end_section_proof();; (start_section_proof ["x"](`interval_arith x int ==> ?s. real_open s /\ x IN s /\ !i y. i <= n /\ y IN s ==> nth_derivative i (\y. f y - g y) y = nth_derivative i f y - nth_derivative i g y`));; 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"])))));; refine (by (VALID ((set_tac "P" (`\i s. real_open s /\ x IN s /\ (!y. y IN s ==> nth_derivative i (\y. f y - g y) y = nth_derivative i f y - nth_derivative i g y)`)))));; refine (by (VALID ((have_tac (move ["sel_P"]) (`!i. i <= n:num ==> P i ((@) (P i))`)))));; refine (by (VALID (((BETA_TAC THEN (move ["i"]) THEN (move ["i_le_n"])) THEN ((USE_THM_THEN SELECT_AX) apply_tac)))));; 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"])))));; 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)))));; refine (by (VALID ((set_tac "S" (`INTERS (IMAGE (\i. (@) (P i)) (0..n))`)))));; refine (by (VALID ((exists_tac (mk_var("S",mk_type("fun",[mk_type("real",[]);mk_type("bool",[])])))))));; 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 [] [])))))));; 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))))))));; refine (by (VALID (((((USE_THEN "P_def")(GSYM_THEN (new_rewrite [1] []))) THEN (simp_tac)) THEN (done_tac)))));; 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)))));; 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))))))));; refine (by (VALID (((((USE_THEN "P_def")(GSYM_THEN (new_rewrite [1] []))) THEN (simp_tac)) THEN (done_tac)))));; refine (by (VALID ((BETA_TAC THEN (move ["i"]) THEN (move ["y"]) THEN (case THEN (move ["i_le_n"]))))));; 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))))));; 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))))));; refine (by (VALID ((((USE_THEN "y_in")MP_TAC) THEN (clear_assumption "y_in") THEN (exact_tac)))));; let nth_derivative_sub_strong_all = end_section_proof();; (start_section_proof ["i";"x"](`interval_arith x int ==> i <= n ==> nth_derivative i (\x. f x - g x) x = nth_derivative i f x - nth_derivative i g x`));; refine (by (VALID ((BETA_TAC THEN (move ["ineq"]) THEN (move ["i_le_n"])))));; 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))));; refine (by (VALID ((BETA_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["_"])) THEN (case THEN (move ["xs"])) THEN (move ["h"])))));; refine (by (VALID ((((USE_THEN "h")MP_TAC) THEN (clear_assumption "h") THEN (exact_tac)))));; let nth_derivative_sub = end_section_proof();; (start_section_proof [](`nth_diff_strong_int n int (\x. f x - g x)`));; refine (by (VALID ((((USE_THEN "dg")MP_TAC) THEN ((USE_THEN "df")MP_TAC) THEN BETA_TAC))));; 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 [] [])))))));; refine (by (VALID ((BETA_TAC THEN (move ["df"]) THEN (move ["dg"]) THEN (move ["x"]) THEN (move ["ineq"])))));; 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))));; refine (by (VALID ((BETA_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["open_s"])) THEN (case THEN (move ["xs"])) THEN (move ["diff"])))));; 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"])))));; 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"])))));; 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 [] []))))))));; refine (by (VALID ((BETA_TAC THEN (move ["y"]) THEN (case THEN ((move ["ys"]) THEN (case THEN ((move ["ytf"]) THEN (move ["ytg"])))))))));; 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"])))));; 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))))));; 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)))));; refine (by (VALID ((exists_tac (`(\y. nth_derivative i f y - nth_derivative i g y)`)))));; 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))))));; 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))))));; 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)))));; let nth_diff_sub = end_section_proof();; (start_section_proof ["i";"x"](`interval_arith x int ==> i <= n ==> ?s. real_open s /\ x IN s /\ !y. y IN s ==> nth_derivative i (\y. f y * g y) y = sum (0..i) (\k. &(binom (i, k)) * nth_derivative k f y * nth_derivative (i - k) g y)`));; 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"]))))));; 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 ["_"]))))));; 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 ["_"]))))));; 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"])))));; 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"]))]))));; 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))))));; 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)))));; refine (by (VALID (((((USE_THM_THEN nth_derivativeS)(new_rewrite [] [])) THEN ((USE_THM_THEN ltE)(GSYM_THEN (new_rewrite [] [])))) THEN (move ["i_lt_n"])))));; 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 ["_"]))))));; refine (by (VALID ((exists_tac (`sf INTER sg INTER t`)))));; 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"])))))));; refine (by (VALID ((((USE_THM_THEN derivative_unique)MP_TAC) THEN (clear_assumption "derivative_unique") THEN (DISCH_THEN apply_tac)))));; 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)))));; refine (by (VALID ((exists_tac (`\y. sum (0..i) (\k. &(binom (i, k)) * nth_derivative k f y * nth_derivative (i - k) g y)`)))));; refine (by (VALID (((THENL_ROT (-1)) (split_tac)))));; 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 [] []))))))));; refine (by (VALID (((BETA_TAC THEN (move ["z"]) THEN (move ["z_in"]) THEN (simp_tac)) THEN ((USE_THEN "eq")(new_rewrite [] [])) THEN (done_tac)))));; refine (by (VALID ((((USE_THM_THEN has_derivative_lemma)MP_TAC) THEN (clear_assumption "has_derivative_lemma") THEN (DISCH_THEN apply_tac)))));; refine (by (VALID ((have_tac (move ["diff_cond"]) (`!k. k IN 0..i ==> nth_derivative k f real_differentiable atreal y /\ nth_derivative (i - k) g real_differentiable atreal y`)))));; 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)))));; 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 [] []))))));; 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)))));; 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 [] []))))));; 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)))));; refine (by (VALID ((have_tac (move ["diff_cond2"]) (`!k. k IN 0..i ==> (\y. &(binom (i, k)) * nth_derivative k f y * nth_derivative (i - k) g y) real_differentiable atreal y`)))));; refine (by (VALID ((BETA_TAC THEN (move ["k"]) THEN (move ["k_in"]) THEN (simp_tac)))));; 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)))));; 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)))))));; refine (by (VALID ((set_tac "lhs" (`sum (0..i) _`)))));; 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)`)))));; 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)`)))));; refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`lhs = sum1 + sum2`)))));; 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 [] []))))));; 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)))));; 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))))));; 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 [] [])))))));; refine (by (VALID ((((USE_THM_THEN SUM_EQ) apply_tac) THEN (move ["k"]) THEN (move ["k_in"]) THEN (simp_tac)))));; 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)))))));; 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)))));; 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)))))));; 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 [] []))))))));; 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))))));; 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)))));; 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))))));; 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 [] []))))));; 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 [] []))))));; refine (by (VALID ((((USE_THM_THEN SUM_EQ) apply_tac) THEN (move ["k"]) THEN (move ["k_in"]) THEN (simp_tac)))));; 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)))));; 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))))));; 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)))));; let nth_derivative_mul_strong = end_section_proof();; (start_section_proof ["x"](`interval_arith x int ==> ?s. real_open s /\ x IN s /\ !i y. i <= n /\ y IN s ==> nth_derivative i (\y. f y * g y) y = sum (0..i) (\k. &(binom (i, k)) * nth_derivative k f y * nth_derivative (i - k) g y)`));; 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"])))));; refine (by (VALID ((set_tac "P" (`\i s. real_open s /\ x IN s /\ (!y. y IN s ==> nth_derivative i (\y. f y * g y) y = sum (0..i) (\k. &(binom (i, k)) * nth_derivative k f y * nth_derivative (i - k) g y))`)))));; refine (by (VALID ((have_tac (move ["sel_P"]) (`!i. i <= n:num ==> P i ((@) (P i))`)))));; refine (by (VALID (((BETA_TAC THEN (move ["i"]) THEN (move ["i_le_n"])) THEN ((USE_THM_THEN SELECT_AX) apply_tac)))));; 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"])))));; 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)))));; refine (by (VALID ((set_tac "S" (`INTERS (IMAGE (\i. (@) (P i)) (0..n))`)))));; refine (by (VALID ((exists_tac (mk_var("S",mk_type("fun",[mk_type("real",[]);mk_type("bool",[])])))))));; 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 [] [])))))));; 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))))))));; refine (by (VALID (((((USE_THEN "P_def")(GSYM_THEN (new_rewrite [1] []))) THEN (simp_tac)) THEN (done_tac)))));; 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)))));; 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))))))));; refine (by (VALID (((((USE_THEN "P_def")(GSYM_THEN (new_rewrite [1] []))) THEN (simp_tac)) THEN (done_tac)))));; refine (by (VALID ((BETA_TAC THEN (move ["i"]) THEN (move ["y"]) THEN (case THEN (move ["i_le_n"]))))));; 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))))));; 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))))));; refine (by (VALID ((((USE_THEN "y_in")MP_TAC) THEN (clear_assumption "y_in") THEN (exact_tac)))));; let nth_derivative_mul_strong_all = end_section_proof();; (start_section_proof ["i";"x"](`interval_arith x int ==> i <= n ==> nth_derivative i (\x. f x * g x) x = sum (0..i) (\k. &(binom (i, k)) * nth_derivative k f x * nth_derivative (i - k) g x)`));; refine (by (VALID ((BETA_TAC THEN (move ["ineq"]) THEN (move ["i_le_n"])))));; 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))));; refine (by (VALID ((BETA_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["_"])) THEN (case THEN (move ["xs"])) THEN (move ["h"])))));; refine (by (VALID ((((USE_THEN "h")MP_TAC) THEN (clear_assumption "h") THEN (exact_tac)))));; let nth_derivative_mul = end_section_proof();; (start_section_proof [](`nth_diff_strong_int n int (\x. f x * g x)`));; refine (by (VALID ((((USE_THEN "dg")MP_TAC) THEN ((USE_THEN "df")MP_TAC) THEN BETA_TAC))));; 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 [] [])))))));; refine (by (VALID ((BETA_TAC THEN (move ["df"]) THEN (move ["dg"]) THEN (move ["x"]) THEN (move ["ineq"])))));; 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))));; refine (by (VALID ((BETA_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["open_s"])) THEN (case THEN (move ["xs"])) THEN (move ["diff"])))));; 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"])))));; 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"])))));; 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 [] []))))))));; refine (by (VALID ((BETA_TAC THEN (move ["y"]) THEN (case THEN ((move ["ys"]) THEN (case THEN ((move ["ytf"]) THEN (move ["ytg"])))))))));; 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"])))));; refine (by (VALID ((((USE_THM_THEN nth_derivativeS)(new_rewrite [] [])) THEN ((USE_THM_THEN has_derivative_alt)(new_rewrite [] []))))));; refine (by (VALID ((((USE_THM_THEN differentiable_local)MP_TAC) THEN (clear_assumption "differentiable_local") THEN (DISCH_THEN apply_tac)))));; 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",[])]))))))));; 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))))));; 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)))));; 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]))))));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN real_differentiable)(new_rewrite [] []))) THEN (split_tac)))));; 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 [] []))))));; 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)))));; 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 [] []))))));; 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)))));; let nth_diff_mul = end_section_proof();; let nth_diff_mul = finalize_theorem nth_diff_mul;; let nth_derivative_mul = finalize_theorem nth_derivative_mul;; let nth_derivative_mul_strong_all = finalize_theorem nth_derivative_mul_strong_all;; let nth_derivative_mul_strong = finalize_theorem nth_derivative_mul_strong;; let nth_diff_sub = finalize_theorem nth_diff_sub;; let nth_derivative_sub = finalize_theorem nth_derivative_sub;; let nth_derivative_sub_strong_all = finalize_theorem nth_derivative_sub_strong_all;; let nth_derivative_sub_strong = finalize_theorem nth_derivative_sub_strong;; let nth_diff_add = finalize_theorem nth_diff_add;; let nth_derivative_add = finalize_theorem nth_derivative_add;; let nth_derivative_add_strong_all = finalize_theorem nth_derivative_add_strong_all;; let nth_derivative_add_strong = finalize_theorem nth_derivative_add_strong;; let nth_diff_scale = finalize_theorem nth_diff_scale;; let nth_derivative_scale = finalize_theorem nth_derivative_scale;; let nth_derivative_scale_strong_all = finalize_theorem nth_derivative_scale_strong_all;; let nth_derivative_scale_strong = finalize_theorem nth_derivative_scale_strong;; (end_section "NthDerivativeArith");; let nth_diff_mul = finalize_theorem nth_diff_mul;; let nth_derivative_mul = finalize_theorem nth_derivative_mul;; let nth_derivative_mul_strong_all = finalize_theorem nth_derivative_mul_strong_all;; let nth_derivative_mul_strong = finalize_theorem nth_derivative_mul_strong;; let nth_diff_sub = finalize_theorem nth_diff_sub;; let nth_derivative_sub = finalize_theorem nth_derivative_sub;; let nth_derivative_sub_strong_all = finalize_theorem nth_derivative_sub_strong_all;; let nth_derivative_sub_strong = finalize_theorem nth_derivative_sub_strong;; let nth_diff_add = finalize_theorem nth_diff_add;; let nth_derivative_add = finalize_theorem nth_derivative_add;; let nth_derivative_add_strong_all = finalize_theorem nth_derivative_add_strong_all;; let nth_derivative_add_strong = finalize_theorem nth_derivative_add_strong;; let nth_diff_scale = finalize_theorem nth_diff_scale;; let nth_derivative_scale = finalize_theorem nth_derivative_scale;; let nth_derivative_scale_strong_all = finalize_theorem nth_derivative_scale_strong_all;; let nth_derivative_scale_strong = finalize_theorem nth_derivative_scale_strong;; let differentiable_local = finalize_theorem differentiable_local;; let derivative_sum_numseg = finalize_theorem derivative_sum_numseg;; let differentiable_sum_numseg = finalize_theorem differentiable_sum_numseg;; let derivative_div = finalize_theorem derivative_div;; let derivative_sub = finalize_theorem derivative_sub;; let derivative_mul = finalize_theorem derivative_mul;; let derivative_add = finalize_theorem derivative_add;; let derivative_pow = finalize_theorem derivative_pow;; let derivative_neg = finalize_theorem derivative_neg;; let derivative_scale = finalize_theorem derivative_scale;; let derivative_compose_acs = finalize_theorem derivative_compose_acs;; let derivative_compose_sqrt = finalize_theorem derivative_compose_sqrt;; let derivative_compose_inv = finalize_theorem derivative_compose_inv;; let derivative_compose_exp = finalize_theorem derivative_compose_exp;; let derivative_compose_atn = finalize_theorem derivative_compose_atn;; let REAL_DIFFERENTIABLE_AT_INV = finalize_theorem REAL_DIFFERENTIABLE_AT_INV;; let derivative_composition = finalize_theorem derivative_composition;; let derivative_sqrt = finalize_theorem derivative_sqrt;; let derivative_acs = finalize_theorem derivative_acs;; let derivative_exp = finalize_theorem derivative_exp;; let derivative_atn = finalize_theorem derivative_atn;; let derivative_inv = finalize_theorem derivative_inv;; let derivative_const = finalize_theorem derivative_const;; let derivative_x = finalize_theorem derivative_x;; let nth_diff_strong_imp_diff = finalize_theorem nth_diff_strong_imp_diff;; let ith_derivative_differentiable = finalize_theorem ith_derivative_differentiable;; let nth_derivative_continuous = finalize_theorem nth_derivative_continuous;; let nth_diff_imp_diff = finalize_theorem nth_diff_imp_diff;; let nth_differentiable1 = finalize_theorem nth_differentiable1;; let nth_mth_diff = finalize_theorem nth_mth_diff;; let nth_differentiable_on_int2 = finalize_theorem nth_differentiable_on_int2;; let nth_differentiable_eq = finalize_theorem nth_differentiable_eq;; let nth_differentiable_on_cond = finalize_theorem nth_differentiable_on_cond;; let nth_differentiable_cond = finalize_theorem nth_differentiable_cond;; let nth_diff_continuous = finalize_theorem nth_diff_continuous;; let nth_derivative_add = finalize_theorem nth_derivative_add;; let nth_derivative2 = finalize_theorem nth_derivative2;; let nth_derivative1 = finalize_theorem nth_derivative1;; let nth_Sderivative = finalize_theorem nth_Sderivative;; let nth_derivativeS = finalize_theorem nth_derivativeS;; let nth_derivative0 = finalize_theorem nth_derivative0;; let has_derivative_lemma = finalize_theorem has_derivative_lemma;; let derivative_unique_on = finalize_theorem derivative_unique_on;; let derivative_unique = finalize_theorem derivative_unique;; let has_derivative_alt = finalize_theorem has_derivative_alt;; let has_derivative_cond = finalize_theorem has_derivative_cond;; (end_section "NthDerivatives");;
let lin_approx = new_definition `lin_approx f x f_bounds df_bounds <=> 
	interval_arith (f x) f_bounds /\
	(?f'. (f has_real_derivative f') (atreal x) /\ interval_arith f' df_bounds)`;;
let has_bounded_second_derivative = new_definition `has_bounded_second_derivative f int dd_bounds <=>
	nth_diff_strong_int 2 int f /\ 
	bounded_on_int (nth_derivative 2 f) int dd_bounds`;;
let taylor_interval = new_definition 
  `taylor_interval f x y z w f_bounds df_bounds ddf_bounds <=>
	x <= y /\ y <= z /\ y - x <= w /\ z - y <= w /\
	lin_approx f y f_bounds df_bounds /\
	has_bounded_second_derivative f (x, z) ddf_bounds`;;
let iabs = new_definition `iabs (x_lo, x_hi) = max x_hi (-- x_lo)`;;
(start_section_proof ["n";"int";"f"](`nth_diff_strong_int n int f ==> nth_differentiable_on_int n int f`));; 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 [] []))))));; refine (by (VALID ((BETA_TAC THEN (move ["h"]) THEN (move ["x"]) THEN (move ["ineq"])))));; 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)))));; let nth_diff_strong_imp_diff_int = end_section_proof();; (start_section_proof ["f";"int";"dd_bounds"](`has_bounded_second_derivative f int dd_bounds ==> ?f' f''. (!x. interval_arith x int ==> (f has_real_derivative f' x) (atreal x) /\ (f' has_real_derivative f'' x) (atreal x) /\ interval_arith (f'' x) dd_bounds)`));; 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))))))));; 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''"]))))));; 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"]))))));; 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"]))))));; 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)))));; let has_bounded_second_derivative_old = end_section_proof();; (start_section_proof ["P";"Q"](`(?x. P x /\ Q x) ==> (?x. P x)`));; refine (by (VALID ((BETA_TAC THEN (case THEN (move ["x"])) THEN (case THEN ((move ["Px"]) THEN (move ["_"])))))));; refine (by (VALID (((exists_tac (mk_var("x",mk_vartype "?1452066"))) THEN (done_tac)))));; let exists_and_left = end_section_proof();; (start_section_proof ["a";"b"](`(!e. &0 < e ==> a <= b + e) <=> (a <= b)`));; refine (by (VALID (((THENL_ROT (-1)) ((split_tac) THENL [ALL_TAC; ((move ["ineq"]) THEN (move ["e"]) THEN (move ["e0"]))])))));; 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)))));; 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"]))))));; 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)))));; let lim_ineq = end_section_proof();; (start_section_proof ["f";"c";"a"](`(?b. a < b /\ !x. x IN real_interval (a, b) ==> f x <= c) /\ f real_continuous atreal a ==> f a <= c`));; refine (by (VALID ((BETA_TAC THEN (case THEN ((case THEN (move ["b"])) THEN (case THEN (move ["ab"])) THEN (move ["ineq"])))))));; refine (by (VALID (((((USE_THM_THEN REAL_CONTINUOUS_ATREAL)(new_rewrite [] [])) THEN ((USE_THM_THEN REALLIM_ATREAL)(new_rewrite [] []))) THEN (move ["f_cont"])))));; 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"])))));; refine (by (VALID ((set_tac "r" (`a + min (b - a) d / &2`)))));; 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))))));; 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))))));; 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)))));; let continuous_leq = end_section_proof();; (start_section_proof ["f";"x"](`f real_continuous atreal x <=> (\x. f (--x)) real_continuous atreal (--x)`));; 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"]))))));; 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"])))));; 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))))));; refine (by (VALID (((((USE_THEN "ineqs")MP_TAC) THEN (clear_assumption "ineqs") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; 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"])))));; 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"]))))));; 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)))));; let continuous_reflection = end_section_proof();; (start_section_proof ["f";"c";"a";"b"](`a < b ==> f real_continuous atreal a ==> f real_continuous atreal b ==> (!x. x IN real_interval (a, b) ==> f x <= c) ==> (!x. x IN real_interval [a, b] ==> f x <= c)`));; refine (by (VALID ((BETA_TAC THEN (move ["ab"]) THEN (move ["f_cont_a"]) THEN (move ["f_cont_b"]) THEN (move ["ineq"]) THEN (move ["x"])))));; 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 [] [])))))));; refine (by (VALID ((case THEN (case THENL [((DISCH_THEN(GSYM_THEN (new_rewrite [] []))) THEN (move ["_"])); (move ["ax"])])))));; 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)))));; 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))))));; refine (by (VALID ((set_tac "g" (`\x. f (--x)`)))));; 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))))));; 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)))));; 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"]))))));; 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)))));; refine (by (VALID (((((USE_THEN "g_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN continuous_reflection)(GSYM_THEN (new_rewrite [] [])))) THEN (done_tac)))));; let continuous_leq_segment = end_section_proof();; (start_section_proof ["p"](`p = (FST p, SND p)`));; refine (by (VALID ((done_tac))));; let pair_eq = end_section_proof();; (begin_section "Taylor");; (start_section_proof ["lo";"hi";"a"](`interval_arith a (lo, hi) ==> iabs (lo, hi) = max (abs lo) (abs hi)`));; refine (by (VALID (((((USE_THM_THEN interval_arith)(new_rewrite [] [])) THEN ((USE_THM_THEN iabs)(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac)))));; let iabs_alt = end_section_proof();; (start_section_proof ["lo";"hi";"a"](`interval_arith a (lo, hi) ==> &0 <= iabs (lo, hi)`));; refine (by (VALID (((((USE_THM_THEN interval_arith)(new_rewrite [] [])) THEN ((USE_THM_THEN iabs)(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac)))));; let iabs_pos = end_section_proof();; (add_section_var (mk_var ("f", (`:real -> real`))));; (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`))));; (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`))));; (add_section_var (mk_var ("dd_bound", (`:real`))));; (add_section_hyp "dd_bound_eq" (`dd_bound = iabs ddf_bounds`));; (add_section_hyp "tif" (`taylor_interval f x y z w f_bounds df_bounds ddf_bounds`));; (start_section_proof [](`!t. t IN real_interval [x, z] ==> f real_continuous atreal t`));; 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"])))));; 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)))));; 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))))))));; refine (by (VALID ((BETA_TAC THEN (case THEN (move ["f'"])) THEN (case THEN (move ["f''"])) THEN (move ["df"])))));; refine (by (VALID (((exists_tac (`f' t`)) THEN ((USE_THEN "df")(new_rewrite [] [])) THEN (done_tac)))));; let f_continuous = end_section_proof();; (start_section_proof ["t"](`x <= t /\ t <= z ==> abs (f t - f y) <= w * iabs df_bounds + w * w * dd_bound / &2`));; refine (by (VALID ((BETA_TAC THEN (move ["t_ineqs"])))));; 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"]))))));; 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"])))));; refine (by (VALID ((have_tac (move ["abs_ty"]) (`abs (t - y) <= w`)))));; 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)))));; 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))))));; refine (by (VALID ((have_tac (move ["dd_prop"]) (`&0 <= dd_bound /\ !p. p IN real_interval [x, z] ==> abs (f'' p) <= dd_bound`)))));; refine (by (VALID ((((USE_THEN "dd_bound_eq")(new_rewrite [] [])) THEN (split_tac)))));; 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)))));; 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)))));; 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`))))));; refine (by (VALID (((set_tac "b1" (`f' y * _`)) THEN ((set_tac "b2" (`dd_bound * _`)) THEN (move ["ineq1"]))))));; 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)))));; 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)))));; 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 [] []))))));; 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 [] []))))));; 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'"])))))));; 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))))));; 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)))));; 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",[]))))))));; 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 [] []))))));; 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))))));; 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 [] []))))));; 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)))));; 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`)))));; refine (by (VALID ((((USE_THM_THEN (ARITH_RULE `0 + 1 = 1 /\ ~(1 = 0) /\ 1 + 1 = 2 /\ ~(2 = 1) /\ ~(2 = 1) /\ ~(2 = 0)`)) MP_TAC) THEN (move ["arith"])))));; 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))));; refine (by (VALID ((ANTS_TAC))));; refine (by (VALID (((((USE_THM_THEN IS_REALINTERVAL_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (split_tac)))));; refine (by (VALID ((((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN interval_arith)(GSYM_THEN (new_rewrite [] [])))))));; 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 [] []))))));; 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)))));; refine (by (VALID (((BETA_TAC THEN (move ["p"]) THEN (move ["p_in"])) THEN (((USE_THEN "Df_def")(GSYM_THEN (new_rewrite [] []))) THEN (simp_tac))))));; 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)))));; 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))))));; 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 [] [])))))));; 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 [] []))))));; 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)))));; let taylor_error = end_section_proof();; (start_section_proof [](`!t. x <= t /\ t <= z ==> f t <= SND f_bounds + (w * iabs df_bounds + w * w * dd_bound / &2)`));; 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"])))));; 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)))))));; 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 ["_"]))))));; 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)))));; let taylor_upper_bound = end_section_proof();; (start_section_proof [](`!t. x <= t /\ t <= z ==> FST f_bounds - (w * iabs df_bounds + w * w * dd_bound / &2) <= f t`));; 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"])))));; 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)))))));; 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 ["_"]))))));; 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)))));; let taylor_lower_bound = end_section_proof();; (start_section_proof [](`!t. x <= t /\ t <= z ==> abs (derivative f t - derivative f y) <= w * dd_bound`));; refine (by (VALID ((BETA_TAC THEN (move ["t"]) THEN (move ["t_ineqs"])))));; 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 ["_"]))))));; 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"])))));; refine (by (VALID ((have_tac (move ["abs_ty"]) (`abs (t - y) <= w`)))));; 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)))));; refine (by (VALID ((have_tac (move ["der_eq"]) (`!p. x <= p /\ p <= z ==> derivative f p = f' p`)))));; 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))))));; 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)))));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THEN "der_eq")(new_rewrite [] []))) THEN ((TRY done_tac))))));; refine (by (VALID ((have_tac (move ["dd_prop"]) (`&0 <= dd_bound /\ !p. p IN real_interval [x, z] ==> abs (f'' p) <= dd_bound`)))));; 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)))));; 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)))));; 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)))));; refine (by (VALID ((set_tac "Df" (`\i. if i = 0 then f' else if i = 1 then f'' else I`)))));; refine (by (VALID ((((USE_THM_THEN (ARITH_RULE `0 + 1 = 1 /\ ~(1 = 0) /\ 1 + 1 = 2 /\ ~(2 = 1) /\ ~(2 = 1) /\ ~(2 = 0)`)) MP_TAC) THEN (move ["arith"])))));; 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))));; refine (by (VALID ((ANTS_TAC))));; refine (by (VALID (((((USE_THM_THEN IS_REALINTERVAL_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (split_tac)))));; 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 [] [])))))));; 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))))));; 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)))));; refine (by (VALID (((BETA_TAC THEN (move ["p"]) THEN (move ["p_in"])) THEN (((USE_THEN "Df_def")(GSYM_THEN (new_rewrite [] []))) THEN (simp_tac))))));; 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)))));; 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))))));; 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 [] [])))))));; 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 [] []))))));; refine (by (VALID ((((USE_THM_THEN REAL_POW_1)(new_rewrite [] [])) THEN (move ["ineq"])))));; 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)`))))));; 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)))));; let taylor_derivative_error = end_section_proof();; (start_section_proof [](`FST df_bounds <= derivative f y /\ derivative f y <= SND df_bounds`));; 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"])))));; 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 ["_"]))))));; 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))))));; 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)))));; 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)))));; let derivative_interval = end_section_proof();; (start_section_proof [](`!t. x <= t /\ t <= z ==> derivative f t <= SND df_bounds + w * dd_bound`));; 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)))));; let taylor_derivative_upper_bound = end_section_proof();; (start_section_proof [](`!t. x <= t /\ t <= z ==> FST df_bounds - w * dd_bound <= derivative f t`));; 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)))));; let taylor_derivative_lower_bound = end_section_proof();; let taylor_derivative_lower_bound = finalize_theorem taylor_derivative_lower_bound;; let taylor_derivative_upper_bound = finalize_theorem taylor_derivative_upper_bound;; let derivative_interval = finalize_theorem derivative_interval;; let taylor_derivative_error = finalize_theorem taylor_derivative_error;; let taylor_lower_bound = finalize_theorem taylor_lower_bound;; let taylor_upper_bound = finalize_theorem taylor_upper_bound;; let taylor_error = finalize_theorem taylor_error;; let f_continuous = finalize_theorem f_continuous;; let iabs_pos = finalize_theorem iabs_pos;; let iabs_alt = finalize_theorem iabs_alt;; (end_section "Taylor");; (begin_section "LinearApproximation");; (add_section_var (mk_var ("f", (`:real->real`))));; (add_section_var (mk_var ("f_bounds", (`:real#real`))); add_section_var (mk_var ("df_bounds", (`:real#real`))));; (add_section_var (mk_var ("x", (`:real`))));; (start_section_proof [](`lin_approx f x f_bounds df_bounds <=> (f real_differentiable atreal x /\ interval_arith (f x) f_bounds /\ interval_arith (derivative f x) df_bounds)`));; 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"]))))])))));; refine (by (VALID (((THENL_FIRST) (split_tac) ((exists_tac (mk_var("f'",mk_type("real",[])))) THEN (done_tac))))));; 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)))));; 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)))));; let lin_approx_eq = end_section_proof();; (add_section_hyp "approx_f" (`lin_approx f x f_bounds df_bounds`));; (start_section_proof [](`interval_arith (f x) f_bounds`));; 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)))));; let lin_approx_imp_f_interval = end_section_proof();; (start_section_proof [](`interval_arith (derivative f x) df_bounds`));; 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)))));; let lin_approx_imp_df_interval = end_section_proof();; (start_section_proof [](`f real_differentiable atreal x`));; 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)))));; let lin_approx_imp_f_diff = end_section_proof();; let lin_approx_imp_f_diff = finalize_theorem lin_approx_imp_f_diff;; let lin_approx_imp_df_interval = finalize_theorem lin_approx_imp_df_interval;; let lin_approx_imp_f_interval = finalize_theorem lin_approx_imp_f_interval;; let lin_approx_eq = finalize_theorem lin_approx_eq;; (end_section "LinearApproximation");; (begin_section "MoreLinearApproximation");; (add_section_var (mk_var ("f", (`:real->real`))); add_section_var (mk_var ("g", (`:real->real`))));; (add_section_var (mk_var ("x", (`:real`))));; (add_section_var (mk_var ("f_bounds", (`:real#real`))); add_section_var (mk_var ("df_bounds", (`:real#real`))));; (add_section_var (mk_var ("g_bounds", (`:real#real`))); add_section_var (mk_var ("dg_bounds", (`:real#real`))));;
let interval_not_zero = new_definition `interval_not_zero (lo, hi) <=> &0 < lo \/ hi < &0`;;
let interval_pos = new_definition `interval_pos (lo, hi) <=> &0 < lo`;;
(start_section_proof ["x";"int"](`interval_arith x int ==> interval_not_zero int ==> ~(x = &0)`));; 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)))));; let interval_arith_not_zero = end_section_proof();; (start_section_proof ["x";"int"](`interval_arith x int ==> interval_pos int ==> &0 < x`));; 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)))));; let interval_arith_pos = end_section_proof();; (start_section_proof ["x";"int";"y"](`interval_arith x int ==> iabs int < y ==> abs x < y`));; 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)))));; let interval_arith_abs = end_section_proof();; (start_section_proof [](`lin_approx (\x. x) x (x, x) (&1, &1)`));; 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)))));; let lin_approx_x = end_section_proof();; (start_section_proof ["c"](`lin_approx (\x. c) x (c, c) (&0, &0)`));; 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 [] []))))));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN REAL_LE_REFL)(new_rewrite [] []))) THEN (done_tac)))));; let lin_approx_const = end_section_proof();; (begin_section "LinearApproxUnivariateComposition");; (add_section_hyp "approx_f" (`lin_approx f x f_bounds df_bounds`));; (start_section_proof [](`(\x. atn (f x)) real_differentiable atreal x /\ derivative (\x. atn (f x)) x = derivative f x / (&1 + f x * f x)`));; 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)))));; let lin_approx_compose_atn = end_section_proof();; (start_section_proof [](`(\x. exp (f x)) real_differentiable atreal x /\ derivative (\x. exp (f x)) x = exp (f x) * derivative f x`));; 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)))));; let lin_approx_compose_exp = end_section_proof();; (start_section_proof [](`interval_not_zero f_bounds ==> (\x. inv (f x)) real_differentiable atreal x /\ derivative (\x. inv (f x)) x = -- inv (f x * f x) * derivative f x`));; 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"]))))));; 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))))));; 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)))));; let lin_approx_compose_inv = end_section_proof();; (start_section_proof [](`interval_pos f_bounds ==> (\x. sqrt (f x)) real_differentiable atreal x /\ derivative (\x. sqrt (f x)) x = derivative f x / (&2 * sqrt (f x))`));; 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"]))))));; 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))))));; 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)))));; let lin_approx_compose_sqrt = end_section_proof();; (start_section_proof [](`iabs f_bounds < &1 ==> (\x. acs (f x)) real_differentiable atreal x /\ derivative (\x. acs (f x)) x = -- (derivative f x / sqrt (&1 - f x * f x))`));; 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"]))))));; 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))))));; 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)))));; let lin_approx_compose_acs = end_section_proof();; let lin_approx_compose_acs = finalize_theorem lin_approx_compose_acs;; let lin_approx_compose_sqrt = finalize_theorem lin_approx_compose_sqrt;; let lin_approx_compose_inv = finalize_theorem lin_approx_compose_inv;; let lin_approx_compose_exp = finalize_theorem lin_approx_compose_exp;; let lin_approx_compose_atn = finalize_theorem lin_approx_compose_atn;; (end_section "LinearApproxUnivariateComposition");; (add_section_hyp "approx_f" (`lin_approx f x f_bounds df_bounds`));; (add_section_hyp "approx_g" (`lin_approx g x g_bounds dg_bounds`));; (start_section_proof [](`(\x. f x + g x) real_differentiable atreal x`));; refine (by (VALID ((((USE_THM_THEN REAL_DIFFERENTIABLE_ADD)MP_TAC) THEN (clear_assumption "REAL_DIFFERENTIABLE_ADD") THEN (DISCH_THEN apply_tac)))));; 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)))));; let lin_approx_imp_add_diff = end_section_proof();; (start_section_proof [](`(\x. f x - g x) real_differentiable atreal x`));; refine (by (VALID ((((USE_THM_THEN REAL_DIFFERENTIABLE_SUB)MP_TAC) THEN (clear_assumption "REAL_DIFFERENTIABLE_SUB") THEN (DISCH_THEN apply_tac)))));; 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)))));; let lin_approx_imp_sub_diff = end_section_proof();; (start_section_proof [](`(\x. f x * g x) real_differentiable atreal x`));; refine (by (VALID ((((USE_THM_THEN REAL_DIFFERENTIABLE_MUL_ATREAL)MP_TAC) THEN (clear_assumption "REAL_DIFFERENTIABLE_MUL_ATREAL") THEN (DISCH_THEN apply_tac)))));; 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)))));; let lin_approx_imp_mul_diff = end_section_proof();; (start_section_proof [](`interval_not_zero g_bounds ==> (\x. f x / g x) real_differentiable atreal x`));; 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))))));; 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 [] [])))))));; 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",[])]))))))));; 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)))));; let lin_approx_imp_div_diff = end_section_proof();; let lin_approx_imp_div_diff = finalize_theorem lin_approx_imp_div_diff;; let lin_approx_imp_mul_diff = finalize_theorem lin_approx_imp_mul_diff;; let lin_approx_imp_sub_diff = finalize_theorem lin_approx_imp_sub_diff;; let lin_approx_imp_add_diff = finalize_theorem lin_approx_imp_add_diff;; let lin_approx_compose_acs = finalize_theorem lin_approx_compose_acs;; let lin_approx_compose_sqrt = finalize_theorem lin_approx_compose_sqrt;; let lin_approx_compose_inv = finalize_theorem lin_approx_compose_inv;; let lin_approx_compose_exp = finalize_theorem lin_approx_compose_exp;; let lin_approx_compose_atn = finalize_theorem lin_approx_compose_atn;; let lin_approx_const = finalize_theorem lin_approx_const;; let lin_approx_x = finalize_theorem lin_approx_x;; let interval_arith_abs = finalize_theorem interval_arith_abs;; let interval_arith_pos = finalize_theorem interval_arith_pos;; let interval_arith_not_zero = finalize_theorem interval_arith_not_zero;; (end_section "MoreLinearApproximation");; (begin_section "LinearApproxArith");; (add_section_var (mk_var ("f1", (`:real->real`))); add_section_var (mk_var ("f2", (`:real->real`))));; (add_section_var (mk_var ("f1_bounds", (`:real#real`))); add_section_var (mk_var ("f2_bounds", (`:real#real`))));; (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`))));; (add_section_var (mk_var ("f_bounds", (`:real#real`))));; (add_section_var (mk_var ("df_lo", (`:real`))); add_section_var (mk_var ("df_hi", (`:real`))));; (add_section_var (mk_var ("x", (`:real`))));; (add_section_hyp "approx1" (`lin_approx f1 x f1_bounds (df1_lo, df1_hi)`));; (start_section_proof ["c"](`&0 <= c ==> interval_arith (c * f1 x) f_bounds /\ df_lo <= c * df1_lo /\ c * df1_hi <= df_hi ==> lin_approx (\x. c * f1 x) x f_bounds (df_lo, df_hi)`));; refine (by (VALID (((((USE_THM_THEN pair_eq)(new_rewrite [] [])) THEN ((USE_THM_THEN interval_arith)(new_rewrite [] []))) THEN (move ["c0"]) THEN (move ["ineqs"])))));; refine (by (VALID (((((USE_THM_THEN lin_approx)(new_rewrite [] [])) THEN (simp_tac)) THEN (split_tac)))));; 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)))));; 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'"]))))))));; 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 [] [])))))));; 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))))));; 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)))));; 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)))));; let lin_approx_scale = end_section_proof();; (add_section_hyp "approx2" (`lin_approx f2 x f2_bounds (df2_lo, df2_hi)`));; (start_section_proof [](`interval_arith (f1 x + f2 x) f_bounds /\ df_lo <= df1_lo + df2_lo /\ df1_hi + df2_hi <= df_hi ==> lin_approx (\x. f1 x + f2 x) x f_bounds (df_lo, df_hi)`));; refine (by (VALID (((((USE_THM_THEN pair_eq)(new_rewrite [] [])) THEN ((USE_THM_THEN interval_arith)(new_rewrite [] []))) THEN (move ["ineqs"])))));; refine (by (VALID (((((USE_THM_THEN lin_approx)(new_rewrite [] [])) THEN (simp_tac)) THEN (split_tac)))));; 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)))));; 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'"]))))))));; 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'"])))))));; 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 [] [])))))));; 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)))));; let lin_approx_add = end_section_proof();; let lin_approx_add = finalize_theorem lin_approx_add;; let lin_approx_scale = finalize_theorem lin_approx_scale;; (end_section "LinearApproxArith");; (begin_section "SecondDerivativeBound");; (add_section_var (mk_var ("f1", (`:real->real`))); add_section_var (mk_var ("f2", (`:real->real`))));; (add_section_var (mk_var ("int", (`:real#real`))));; (add_section_var (mk_var ("dd1", (`:real#real`))); add_section_var (mk_var ("dd2", (`:real#real`))));; (start_section_proof ["f";"x"](`nth_diff_strong 2 f x <=> ?s. real_open s /\ x IN s /\ !y. y IN s ==> (f has_real_derivative derivative f y) (atreal y) /\ (derivative f has_real_derivative nth_derivative 2 f y) (atreal y)`));; 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 [] []))))));; 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"])))));; 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"]))))));; 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)))));; 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"]))))));; refine (by (VALID ((((USE_THM_THEN REAL_DIFFERENTIABLE_IMP_CONTINUOUS_ATREAL)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN andTb)(new_rewrite [] [])))))));; refine (by (VALID ((((USE_THM_THEN real_differentiable)(new_rewrite [] [])) THEN (exists_tac (`derivative f y`)) THEN (done_tac)))));; 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)))));; let nth_diff_strong2_eq_alt = end_section_proof();; (start_section_proof ["f";"x"](`nth_diff_strong 2 f x <=> ?s. real_open s /\ x IN s /\ !y. y IN s ==> f real_differentiable atreal y /\ derivative f real_differentiable atreal y`));; 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 [] [])))))));; 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 [] []))))));; 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"])))));; 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)))));; 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"]))))));; 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)))));; let nth_diff_strong2_eq = end_section_proof();; (start_section_proof ["f";"g";"y";"g_bounds";"f_bounds";"d_bounds"](`nth_diff_strong_int 2 g_bounds f ==> g real_differentiable atreal y ==> interval_arith (g y) g_bounds ==> bounded_on_int f g_bounds f_bounds ==> interval_arith (derivative g y * derivative f (g y)) d_bounds ==> lin_approx (\x. f (g x)) y f_bounds d_bounds`));; 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"])))));; refine (by (VALID ((have_tac (move ["dfgy"]) (`f real_differentiable atreal (g y)`)))));; 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)))));; 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 [] []))))));; 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)))));; let lin_approx_compose = end_section_proof();; (start_section_proof ["x"](`((\x. inv (&1 + x pow 2)) has_real_derivative (-- &2 * x) * inv (&1 + x pow 2) pow 2) (atreal x)`));; 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)))));; 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 [] []))))));; 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 [] []))))));; 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)))));; 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)))));; let second_derivative_atn_eq = end_section_proof();; (start_section_proof [](`derivative (derivative atn) = (\x. (-- &2 * x) * inv (&1 + x pow 2) pow 2)`));; 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))))));; 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)))));; let second_derivative_atn = end_section_proof();; (start_section_proof ["x"](`nth_diff_strong 2 atn x`));; refine (by (VALID ((((USE_THM_THEN nth_diff_strong2_eq_alt)(new_rewrite [] [])) THEN (exists_tac (`(:real)`))))));; 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)))));; 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 [] []))))));; 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)))));; let diff2_atn = end_section_proof();; (start_section_proof ["x"](`~(x = &0) ==> nth_derivative 2 inv x = &2 * inv (x pow 3)`));; refine (by (VALID ((((USE_THM_THEN nth_derivative2)(new_rewrite [] [])) THEN (move ["xn0"])))));; 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))))));; refine (by (VALID (((exists_tac (`(\x. -- inv (x * x))`)) THEN (split_tac)))));; 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))));; 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 [] [])))))));; 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 [] [])))))));; 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)))));; refine (by (VALID ((exists_tac (`real_interval (x - abs x, x + abs x)`)))));; 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"]))])))));; refine (by (VALID (((((USE_THEN "xn0")MP_TAC) THEN (clear_assumption "xn0") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((((USE_THM_THEN derivative_inv)(new_rewrite [] [])) THEN ((simp_tac THEN TRY done_tac))))));; 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)))));; let second_derivative_inv = end_section_proof();; (start_section_proof ["x"](`~(x = &0) ==> nth_diff_strong 2 inv x`));; refine (by (VALID ((((USE_THM_THEN nth_diff_strong2_eq)(new_rewrite [] [])) THEN (move ["xn0"])))));; refine (by (VALID ((exists_tac (`real_interval (x - abs x, x + abs x)`)))));; 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"]))])))));; refine (by (VALID (((((USE_THEN "xn0")MP_TAC) THEN (clear_assumption "xn0") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; 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))))));; 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)`)))))));; 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)))));; refine (by (VALID ((((USE_THM_THEN REAL_DIFFERENTIABLE_NEG)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_DIFFERENTIABLE_INV_ATREAL)(new_rewrite [] []))))));; 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 [] []))))));; 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)))));; refine (by (VALID (((split_tac) THENL [ALL_TAC; ((move ["z"]) THEN (move ["ineq2"]))]))));; 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)))));; 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)))));; let diff2_inv = end_section_proof();; (start_section_proof ["x";"n"](`&0 <= x ==> sqrt x pow n = sqrt (x pow n)`));; 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)))))));; 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)))));; let SQRT_POW = end_section_proof();; (start_section_proof ["x"](`&0 < x ==> nth_derivative 2 sqrt x = -- inv(&4 * sqrt (x pow 3))`));; refine (by (VALID ((((USE_THM_THEN nth_derivative2)(new_rewrite [] [])) THEN (move ["x_pos"])))));; 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))))));; refine (by (VALID (((exists_tac (`(\x. inv (&2 * sqrt x))`)) THEN (split_tac)))));; 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))));; refine (by (VALID ((have_tac (move ["ineq"]) (`~(&2 * sqrt x = &0)`)))));; 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)))));; 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 [] [])))))));; 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))))));; 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 [] []))))));; 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))))));; 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)))));; refine (by (VALID ((exists_tac (`real_interval (&0, x + &1)`)))));; 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"]))])))));; refine (by (VALID (((((USE_THEN "x_pos")MP_TAC) THEN (clear_assumption "x_pos") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((((USE_THM_THEN derivative_sqrt)(new_rewrite [] [])) THEN (done_tac)))));; let second_derivative_sqrt = end_section_proof();; (start_section_proof ["x"](`&0 < x ==> nth_diff_strong 2 sqrt x`));; refine (by (VALID ((((USE_THM_THEN nth_diff_strong2_eq)(new_rewrite [] [])) THEN (move ["x_pos"])))));; refine (by (VALID ((exists_tac (`real_interval (&0, x + &1)`)))));; 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"]))])))));; refine (by (VALID (((((USE_THEN "x_pos")MP_TAC) THEN (clear_assumption "x_pos") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; 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))))));; 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)`)))))));; 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)))));; refine (by (VALID ((((USE_THM_THEN REAL_DIFFERENTIABLE_INV_ATREAL)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_DIFFERENTIABLE_MUL_ATREAL)(new_rewrite [] []))))));; refine (by (VALID (((((USE_THM_THEN REAL_DIFFERENTIABLE_CONST)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_DIFFERENTIABLE_AT_SQRT)(new_rewrite [] []))) THEN (done_tac)))));; 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)))));; 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))))));; refine (by (VALID ((((USE_THM_THEN derivative_sqrt)(new_rewrite [] [])) THEN (done_tac)))));; let diff2_sqrt = end_section_proof();; (start_section_proof ["x";"n"](`x pow (SUC n) = x * x pow n`));; refine (by (VALID ((((USE_THM_THEN real_pow)(new_rewrite [] [])) THEN (done_tac)))));; let real_powS = end_section_proof();; (start_section_proof ["x"](`abs x < &1 ==> nth_derivative 2 acs x = --(x / sqrt ((&1 - x * x) pow 3))`));; refine (by (VALID ((((USE_THM_THEN nth_derivative2)(new_rewrite [] [])) THEN (move ["x_ineq"])))));; 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))))));; refine (by (VALID (((exists_tac (`\x. --inv (sqrt (&1 - x * x))`)) THEN (split_tac)))));; 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))));; refine (by (VALID ((have_tac (move ["ineqs"]) (`&0 < &1 - x * x /\ ~(sqrt(&1 - x * x) = &0)`)))));; refine (by (VALID ((((THENL_ROT 1)) (have_tac (move ["h"]) (`&0 < &1 - x * x`))))));; 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)))));; 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 [] []))))));; refine (by (VALID (((((USE_THEN "x_ineq")MP_TAC) THEN (clear_assumption "x_ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; 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 [] []))))))));; 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))))));; 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 [] [])))))));; 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 [] []))))));; 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)))));; refine (by (VALID ((set_tac "e" (`&1 - abs x`)))));; refine (by (VALID ((exists_tac (`real_interval (x - e, x + e)`)))));; 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"]))])))));; 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)))));; refine (by (VALID ((((USE_THM_THEN derivative_acs)(new_rewrite [] [])) THEN ((simp_tac THEN TRY done_tac))))));; 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)))));; let second_derivative_acs = end_section_proof();; (start_section_proof ["x"](`abs x < &1 ==> nth_diff_strong 2 acs x`));; refine (by (VALID ((((USE_THM_THEN nth_diff_strong2_eq)(new_rewrite [] [])) THEN (move ["x_ineq"])))));; refine (by (VALID ((set_tac "e" (`&1 - abs x`)))));; refine (by (VALID ((exists_tac (`real_interval (x - e, x + e)`)))));; 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"]))])))));; 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)))));; 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))))));; refine (by (VALID ((set_tac "e2" (`&1 - abs y`)))));; 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)`)))))));; 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)))));; refine (by (VALID ((((USE_THM_THEN REAL_DIFFERENTIABLE_NEG)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_DIFFERENTIABLE_INV_ATREAL)(new_rewrite [] []))))));; refine (by (VALID ((have_tac (move ["gt0"]) (`&0 < &1 - y * y`)))));; 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)))));; 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))))));; refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`(\x. sqrt (&1 - x * x)) = sqrt o (\x. &1 - x * x)`)))));; 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)))));; 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))))));; 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))))));; refine (by (VALID ((((USE_THM_THEN REAL_DIFFERENTIABLE_ID)(new_rewrite [] [])) THEN (done_tac)))));; refine (by (VALID (((split_tac) THENL [ALL_TAC; ((move ["z"]) THEN (move ["ineq2"]))]))));; 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)))));; refine (by (VALID ((((USE_THM_THEN derivative_acs)(new_rewrite [] [])) THEN ((simp_tac THEN TRY done_tac))))));; 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)))));; let diff2_acs = end_section_proof();; (begin_section "SecondDerivativeCompose");; (start_section_proof ["f";"s";"t"](`f real_continuous_on s ==> real_open s ==> real_open t ==> real_open {x | x IN s /\ f x IN t}`));; refine (by (VALID ((BETA_TAC THEN (move ["f_cont"]) THEN (move ["open_s"]) THEN (move ["open_t"])))));; refine (by (VALID (((USE_THM_THEN REAL_OPEN)(new_rewrite [] [])))));; refine (by (VALID ((((THENL_ROT 1)) (have_tac (DISCH_THEN(new_rewrite [] [])) (`IMAGE lift {x | x IN s /\ f x IN t} = {x | x IN (IMAGE lift s) /\ (lift o f o drop) x IN (IMAGE lift t)}`))))));; 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)))));; 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)))));; 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`))))));; 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)))));; 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"])))));; refine (by (VALID (((exists_tac (`drop x`)) THEN (done_tac)))));; let REAL_CONTINUOUS_OPEN_PREIMAGE = end_section_proof();; (start_section_proof ["f";"g";"x"](`nth_diff_strong 2 g x ==> nth_diff_strong 2 f (g x) ==> nth_derivative 2 (\x. f (g x)) x = nth_derivative 2 f (g x) * (derivative g x) pow 2 + derivative f (g x) * nth_derivative 2 g x`));; refine (by (VALID ((BETA_TAC THEN (move ["dg"]) THEN (move ["df"])))));; 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))))));; refine (by (VALID (((THENL_ROT (-1)) ((exists_tac (`\x. derivative f (g x) * derivative g x`)) THEN (split_tac))))));; 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"]))))));; refine (by (VALID ((set_tac "s'" (`{z | z IN t /\ g z IN s}`)))));; refine (by (VALID ((have_tac (move ["open_s'"]) (`real_open s'`)))));; 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 [] [])))))));; 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"])))));; refine (by (VALID (((((USE_THM_THEN REAL_DIFFERENTIABLE_IMP_CONTINUOUS_ATREAL)(new_rewrite [] [])) THEN ((USE_THEN "d_g")(new_rewrite [] []))) THEN (done_tac)))));; 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)))));; 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)))));; 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)))))));; 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)))));; 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"]))))));; 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))))));; refine (by (VALID ((((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN ((USE_THEN "d_g")(new_rewrite [] [])) THEN (done_tac)))));; 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 [] []))))));; refine (by (VALID (((((USE_THEN "d_g")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THEN "d_f")(new_rewrite [] []))) THEN (done_tac)))));; let second_derivative_compose = end_section_proof();; (start_section_proof ["f";"g";"x"](`nth_diff_strong 2 g x ==> nth_diff_strong 2 f (g x) ==> nth_diff_strong 2 (\x. f (g x)) x`));; 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"])))));; refine (by (VALID ((set_tac "s'" (`{z | z IN s /\ g z IN t}`)))));; refine (by (VALID ((have_tac (move ["open_s'"]) (`real_open s'`)))));; 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 [] [])))))));; 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"])))));; refine (by (VALID (((((USE_THM_THEN REAL_DIFFERENTIABLE_IMP_CONTINUOUS_ATREAL)(new_rewrite [] [])) THEN ((USE_THEN "dg")(new_rewrite [] []))) THEN (done_tac)))));; 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)))));; 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)))));; refine (by (VALID ((BETA_TAC THEN (move ["y"]) THEN (case THEN ((move ["ys"]) THEN (move ["ys'"])))))));; 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)))))));; 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)))));; refine (by (VALID ((((USE_THM_THEN differentiable_local)MP_TAC) THEN (clear_assumption "differentiable_local") THEN (DISCH_THEN apply_tac)))));; 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))))));; 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"])))));; 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))))));; 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)))));; 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 [] [])))))));; 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)))))));; 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)))));; let diff2_compose = end_section_proof();; (start_section_proof ["f";"x"](`~(f x = &0) ==> f real_continuous atreal x ==> ?s. real_open s /\ x IN s /\ !y. y IN s ==> ~(f y = &0)`));; 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)))));; 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))))));; refine (by (VALID ((BETA_TAC THEN (case THEN (move ["d"])) THEN (case THEN (move ["d0"])) THEN (move ["ineq"])))));; refine (by (VALID ((exists_tac (`real_interval (x - d, x + d)`)))));; 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))))));; 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)))));; let continuous_not0_exists_open = end_section_proof();; (start_section_proof ["a";"f";"x"](`a < f x ==> f real_continuous atreal x ==> ?s. real_open s /\ x IN s /\ !y. y IN s ==> a < f y`));; 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))))));; 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))))));; refine (by (VALID ((BETA_TAC THEN (case THEN (move ["d"])) THEN (case THEN (move ["d0"])) THEN (move ["ineq"])))));; refine (by (VALID ((exists_tac (`real_interval (x - d, x + d)`)))));; 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))))));; 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)))));; let continuous_gt_exists_open = end_section_proof();; (start_section_proof ["a";"f";"x"](`f x < a ==> f real_continuous atreal x ==> ?s. real_open s /\ x IN s /\ !y. y IN s ==> f y < a`));; 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))))));; 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))))));; refine (by (VALID ((BETA_TAC THEN (case THEN (move ["d"])) THEN (case THEN (move ["d0"])) THEN (move ["ineq"])))));; refine (by (VALID ((exists_tac (`real_interval (x - d, x + d)`)))));; 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))))));; 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)))));; let continuous_lt_exists_open = end_section_proof();; (add_section_var (mk_var ("f", (`:real->real`))));; (add_section_var (mk_var ("x", (`:real`))));; (add_section_hyp "df" (`nth_diff_strong 2 f x`));; (start_section_proof [](`nth_derivative 2 (\x. atn (f x)) x = (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`));; 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)))));; 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 [] [])))))));; refine (by (VALID (((set_tac "lhs1" (`_1 * _2`)) THEN (set_tac "lhs2" (`_1 * _2`))))));; 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 [] []))))));; refine (by (VALID (((set_tac "rhs1" (`_1 * _2`)) THEN (set_tac "rhs2" (`_1 * _2`))))));; refine (by (VALID ((((USE_THM_THEN (REAL_ARITH `lhs1 = rhs1 /\ lhs2 = rhs2 ==> lhs1 - lhs2 = rhs1 - rhs2`))MP_TAC) THEN (DISCH_THEN apply_tac)))));; 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)))))));; 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 [] []))))));; 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))))));; 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)))));; let second_derivative_compose_atn = end_section_proof();; (start_section_proof [](`~(f x = &0) ==> nth_derivative 2 (\x. inv (f x)) x = (&2 * derivative f x pow 2 - nth_derivative 2 f x * f x) / (f x pow 3)`));; refine (by (VALID ((BETA_TAC THEN (move ["fn0"])))));; 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))))));; 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 [] []))))));; 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))))));; 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 [] []))))));; 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 [] []))))));; 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)))));; let second_derivative_compose_inv = end_section_proof();; (start_section_proof [](`&0 < f x ==> nth_derivative 2 (\x. sqrt (f x)) x = (&2 * nth_derivative 2 f x * f x - derivative f x pow 2) / (&4 * sqrt (f x pow 3))`));; refine (by (VALID ((BETA_TAC THEN (move ["f_pos"])))));; 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))))));; 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 [] []))))));; 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))))));; refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`sqrt (f x pow 3) = sqrt (f x) * f x`)))));; 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)))));; refine (by (VALID (repeat_tactic 1 9 (((USE_THM_THEN REAL_INV_MUL)(new_rewrite [] []))))));; 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 [] [])))));; 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)))));; let second_derivative_compose_sqrt = end_section_proof();; (start_section_proof [](`abs (f x) < &1 ==> nth_derivative 2 (\x. acs (f x)) x = -- ((nth_derivative 2 f x * (&1 - f x * f x) + f x * derivative f x pow 2) / sqrt ((&1 - f x * f x) pow 3))`));; refine (by (VALID ((BETA_TAC THEN (move ["f_ineq"])))));; 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))))));; 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 [] []))))));; 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))))));; refine (by (VALID ((set_tac "y" (`&1 - f x * f x`)))));; refine (by (VALID ((have_tac (move ["y_ineq"]) (`&0 <= y /\ &0 < y /\ ~(y = &0)`)))));; 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 [] []))))));; 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)))));; refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`sqrt (y pow 3) = sqrt y * y`)))));; 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)))));; 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 [] []))))));; 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)))));; let second_derivative_compose_acs = end_section_proof();; (start_section_proof [](`nth_diff_strong 2 (\x. atn (f x)) x`));; refine (by (VALID (((((USE_THM_THEN diff2_compose)(new_rewrite [] [])) THEN ((USE_THM_THEN diff2_atn)(new_rewrite [] []))) THEN (done_tac)))));; let diff2_compose_atn = end_section_proof();; (start_section_proof [](`~(f x = &0) ==> nth_diff_strong 2 (\x. inv (f x)) x`));; 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)))));; let diff2_compose_inv = end_section_proof();; (start_section_proof [](`&0 < f x ==> nth_diff_strong 2 (\x. sqrt (f x)) x`));; 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)))));; let diff2_compose_sqrt = end_section_proof();; (start_section_proof [](`abs (f x) < &1 ==> nth_diff_strong 2 (\x. acs (f x)) x`));; 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)))));; let diff2_compose_acs = end_section_proof();; let diff2_compose_acs = finalize_theorem diff2_compose_acs;; let diff2_compose_sqrt = finalize_theorem diff2_compose_sqrt;; let diff2_compose_inv = finalize_theorem diff2_compose_inv;; let diff2_compose_atn = finalize_theorem diff2_compose_atn;; let second_derivative_compose_acs = finalize_theorem second_derivative_compose_acs;; let second_derivative_compose_sqrt = finalize_theorem second_derivative_compose_sqrt;; let second_derivative_compose_inv = finalize_theorem second_derivative_compose_inv;; let second_derivative_compose_atn = finalize_theorem second_derivative_compose_atn;; let continuous_lt_exists_open = finalize_theorem continuous_lt_exists_open;; let continuous_gt_exists_open = finalize_theorem continuous_gt_exists_open;; let continuous_not0_exists_open = finalize_theorem continuous_not0_exists_open;; let diff2_compose = finalize_theorem diff2_compose;; let second_derivative_compose = finalize_theorem second_derivative_compose;; let REAL_CONTINUOUS_OPEN_PREIMAGE = finalize_theorem REAL_CONTINUOUS_OPEN_PREIMAGE;; (end_section "SecondDerivativeCompose");; (start_section_proof ["f";"g";"x"](`nth_diff_strong 2 f x ==> nth_diff_strong 2 g x ==> nth_derivative 2 (\x. f x * g x) x = f x * nth_derivative 2 g x + &2 * derivative f x * derivative g x + nth_derivative 2 f x * g x`));; refine (by (VALID (((BETA_TAC THEN (move ["df0"]) THEN (move ["dg0"])) THEN (set_tac "int" (`(x,x)`))))));; 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`)))));; 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 [] []))))));; 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)))));; 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)))))));; 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 [] [])))))));; 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 [] [])))))));; 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)))));; let second_derivative_mul = end_section_proof();; (start_section_proof ["f";"g";"x"](`~(g x = &0) ==> nth_diff_strong 2 f x ==> nth_diff_strong 2 g x ==> nth_derivative 2 (\x. f x / g x) x = ((nth_derivative 2 f x * g x - f x * nth_derivative 2 g x) * g x - &2 * derivative g x * (derivative f x * g x - f x * derivative g x)) / (g x pow 3)`));; refine (by (VALID ((BETA_TAC THEN (move ["gn0"]) THEN (move ["diff_f"]) THEN (move ["diff_g"])))));; refine (by (VALID (((set_tac "dg" (`derivative g x`)) THEN (set_tac "df" (`derivative f x`))))));; refine (by (VALID (((set_tac "ddg" (`nth_derivative 2 g x`)) THEN (set_tac "ddf" (`nth_derivative 2 f x`))))));; 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))))));; refine (by (VALID (((USE_THM_THEN derivative_compose_inv)(new_rewrite [] [])))));; 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)))));; 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 [] [])))))));; refine (by (VALID ((set_tac "lhs" (`_1 + _2`)))));; 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)) * inv (g x pow 3) = f x * (&2 * dg pow 2 - ddg * g x) * inv (g x pow 3) + &2 * df * --(g x * inv (g x pow 3)) * dg + ddf * (g x * g x * inv (g x pow 3))`))(new_rewrite [] [])))));; refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`g x * inv (g x pow 3) = inv (g x pow 2)`)))));; 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)))));; refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`g x * inv (g x pow 2) = inv (g x)`)))));; 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)))));; 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)))));; let second_derivative_div = end_section_proof();; (start_section_proof ["f";"g";"x"](`~(g x = &0) ==> nth_diff_strong 2 f x ==> nth_diff_strong 2 g x ==> nth_diff_strong 2 (\x. f x / g x) x`));; refine (by (VALID (((BETA_TAC THEN (move ["gn0"]) THEN (move ["df0"]) THEN (move ["dg0"])) THEN (set_tac "int" (`(x,x)`))))));; 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`)))));; 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 [] []))))));; 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)))));; 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))));; 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"]))))));; 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 [] [])))))));; refine (by (VALID ((((USE_THM_THEN diff2_compose_inv)(new_rewrite [] [])) THEN (done_tac)))));; let diff2_div = end_section_proof();; (start_section_proof ["f";"c";"x"](`nth_diff_strong 2 f x ==> nth_derivative 2 (\x. c * f x) x = c * nth_derivative 2 f x`));; refine (by (VALID (((BETA_TAC THEN (move ["df0"])) THEN (set_tac "int" (`(x,x)`))))));; 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`)))));; 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 [] []))))));; 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)))));; 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)))));; let second_derivative_scale = end_section_proof();; (start_section_proof ["f";"g";"x"](`nth_diff_strong 2 f x ==> nth_diff_strong 2 g x ==> nth_derivative 2 (\x. f x + g x) x = nth_derivative 2 f x + nth_derivative 2 g x`));; refine (by (VALID (((BETA_TAC THEN (move ["df0"]) THEN (move ["dg0"])) THEN (set_tac "int" (`(x,x)`))))));; 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`)))));; 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 [] []))))));; 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)))));; 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)))));; let second_derivative_add = end_section_proof();; (start_section_proof ["f";"g";"x"](`nth_diff_strong 2 f x ==> nth_diff_strong 2 g x ==> nth_derivative 2 (\x. f x - g x) x = nth_derivative 2 f x - nth_derivative 2 g x`));; refine (by (VALID (((BETA_TAC THEN (move ["df0"]) THEN (move ["dg0"])) THEN (set_tac "int" (`(x,x)`))))));; 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`)))));; 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 [] []))))));; 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)))));; 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)))));; let second_derivative_sub = end_section_proof();; (start_section_proof ["f";"g";"int";"g_bounds";"dd_bounds"](`nth_diff_strong_int 2 int g ==> bounded_on_int g int g_bounds ==> nth_diff_strong_int 2 g_bounds f ==> bounded_on_int (\x. nth_derivative 2 f (g x) * derivative g x pow 2 + derivative f (g x) * nth_derivative 2 g x) int dd_bounds ==> has_bounded_second_derivative (\x. f (g x)) int dd_bounds`));; 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)))));; 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"]))))));; 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)))));; 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)))));; let second_derivative_compose_bounds = end_section_proof();; (start_section_proof ["dd_bounds"](`bounded_on_int (\x. (-- &2 * x) * inv(&1 + x pow 2) pow 2) int dd_bounds ==> has_bounded_second_derivative atn int dd_bounds`));; refine (by (VALID (((((USE_THM_THEN bounded_on_int)(new_rewrite [] [])) THEN ((USE_THM_THEN has_bounded_second_derivative)(new_rewrite [] []))) THEN (move ["ineq"])))));; 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))))));; refine (by (VALID (((((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] [])) THEN ((USE_THM_THEN diff2_atn)(new_rewrite [] []))) THEN (done_tac)))));; let second_derivative_atn_bounds = end_section_proof();; (start_section_proof ["f";"dd_bounds"](`nth_diff_strong_int 2 int f ==> bounded_on_int (\x. (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) int dd_bounds ==> has_bounded_second_derivative (\x. atn (f x)) int dd_bounds`));; 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"]))))));; refine (by (VALID (((((USE_THM_THEN diff2_compose_atn)(new_rewrite [] [])) THEN ((USE_THEN "df")(new_rewrite [] []))) THEN (done_tac)))));; 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)))));; let second_derivative_compose_atn_bounds = end_section_proof();; (start_section_proof ["dd_bounds"](`interval_not_zero int ==> bounded_on_int (\x. &2 * inv (x pow 3)) int dd_bounds ==> has_bounded_second_derivative inv int dd_bounds`));; 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"]))))));; 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)))));; 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)))));; let second_derivative_inv_bounds = end_section_proof();; (start_section_proof ["f";"f_bounds";"dd_bounds"](`bounded_on_int f int f_bounds ==> interval_not_zero f_bounds ==> nth_diff_strong_int 2 int f ==> bounded_on_int (\x. (&2 * derivative f x pow 2 - nth_derivative 2 f x * f x) / f x pow 3) int dd_bounds ==> has_bounded_second_derivative (\x. inv (f x)) int dd_bounds`));; 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"])))));; refine (by (VALID ((have_tac (move ["fn0"]) (`!x. interval_arith x int ==> ~(f x = &0)`)))));; 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)))));; refine (by (VALID (((split_tac) THEN (move ["x"]) THEN (move ["ineq"])))));; 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)))));; 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)))));; let second_derivative_compose_inv_bounds = end_section_proof();; (start_section_proof ["dd_bounds"](`interval_pos int ==> bounded_on_int (\x. --inv (&4 * sqrt (x pow 3))) int dd_bounds ==> has_bounded_second_derivative sqrt int dd_bounds`));; 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"])))));; refine (by (VALID (((split_tac) THEN (move ["x"]) THEN (move ["ineq"])))));; 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)))));; 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)))));; let second_derivative_sqrt_bounds = end_section_proof();; (start_section_proof ["f";"f_bounds";"dd_bounds"](`bounded_on_int f int f_bounds ==> interval_pos f_bounds ==> nth_diff_strong_int 2 int f ==> bounded_on_int (\x. (&2 * nth_derivative 2 f x * f x - derivative f x pow 2) / (&4 * sqrt (f x pow 3))) int dd_bounds ==> has_bounded_second_derivative (\x. sqrt (f x)) int dd_bounds`));; 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"])))));; refine (by (VALID ((have_tac (move ["f_pos"]) (`!x. interval_arith x int ==> &0 < f x`)))));; 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)))));; refine (by (VALID (((split_tac) THEN (move ["x"]) THEN (move ["ineq"])))));; 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)))));; 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)))));; let second_derivative_compose_sqrt_bounds = end_section_proof();; (start_section_proof ["dd_bounds"](`iabs int < &1 ==> bounded_on_int (\x. --(x / sqrt ((&1 - x * x) pow 3))) int dd_bounds ==> has_bounded_second_derivative acs int dd_bounds`));; 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"])))));; refine (by (VALID (((split_tac) THEN (move ["x"]) THEN (move ["ineq"])))));; 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)))));; 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)))));; let second_derivative_acs_bounds = end_section_proof();; (start_section_proof ["f";"f_bounds";"dd_bounds"](`bounded_on_int f int f_bounds ==> iabs f_bounds < &1 ==> nth_diff_strong_int 2 int f ==> bounded_on_int (\x. --((nth_derivative 2 f x * (&1 - f x * f x) + f x * derivative f x pow 2) / sqrt ((&1 - f x * f x) pow 3))) int dd_bounds ==> has_bounded_second_derivative (\x. acs (f x)) int dd_bounds`));; 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"])))));; refine (by (VALID ((have_tac (move ["fabs"]) (`!x. interval_arith x int ==> abs (f x) < &1`)))));; 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)))));; refine (by (VALID (((split_tac) THEN (move ["x"]) THEN (move ["ineq"])))));; 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)))));; 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)))));; let second_derivative_compose_acs_bounds = end_section_proof();; (start_section_proof ["c";"f";"dd_bounds"](`nth_diff_strong_int 2 int f ==> bounded_on_int (\x. c * nth_derivative 2 f x) int dd_bounds ==> has_bounded_second_derivative (\x. c * f x) int dd_bounds`));; 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"])))));; 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"])))));; 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))))));; 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)))));; let second_derivative_scale_bounds = end_section_proof();; (start_section_proof ["f";"g";"dd_bounds"](`nth_diff_strong_int 2 int f ==> nth_diff_strong_int 2 int g ==> bounded_on_int (\x. nth_derivative 2 f x + nth_derivative 2 g x) int dd_bounds ==> has_bounded_second_derivative (\x. f x + g x) int dd_bounds`));; 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"])))));; 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"])))));; 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))))));; 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)))));; let second_derivative_add_bounds = end_section_proof();; (start_section_proof ["f";"g";"dd_bounds"](`nth_diff_strong_int 2 int f ==> nth_diff_strong_int 2 int g ==> bounded_on_int (\x. nth_derivative 2 f x - nth_derivative 2 g x) int dd_bounds ==> has_bounded_second_derivative (\x. f x - g x) int dd_bounds`));; 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"])))));; 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"])))));; 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))))));; 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)))));; let second_derivative_sub_bounds = end_section_proof();; (start_section_proof ["f";"g";"dd_bounds"](`nth_diff_strong_int 2 int f ==> nth_diff_strong_int 2 int g ==> bounded_on_int (\x. f x * nth_derivative 2 g x + &2 * derivative f x * derivative g x + nth_derivative 2 f x * g x) int dd_bounds ==> has_bounded_second_derivative (\x. f x * g x) int dd_bounds`));; 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"])))));; 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"])))));; 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))))));; 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)))));; let second_derivative_mul_bounds = end_section_proof();; (start_section_proof ["f";"g";"g_bounds";"dd_bounds"](`bounded_on_int g int g_bounds ==> interval_not_zero g_bounds ==> nth_diff_strong_int 2 int f ==> nth_diff_strong_int 2 int g ==> bounded_on_int (\x. ((nth_derivative 2 f x * g x - f x * nth_derivative 2 g x) * g x - &2 * derivative g x * (derivative f x * g x - f x * derivative g x)) / g x pow 3) int dd_bounds ==> has_bounded_second_derivative (\x. f x / g x) int dd_bounds`));; 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"])))));; refine (by (VALID ((have_tac (move ["g0"]) (`!x. interval_arith x int ==> ~(g x = &0)`)))));; 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)))));; 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))))));; 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)))));; let second_derivative_div_bounds = end_section_proof();; let second_derivative_div_bounds = finalize_theorem second_derivative_div_bounds;; let second_derivative_mul_bounds = finalize_theorem second_derivative_mul_bounds;; let second_derivative_sub_bounds = finalize_theorem second_derivative_sub_bounds;; let second_derivative_add_bounds = finalize_theorem second_derivative_add_bounds;; let second_derivative_scale_bounds = finalize_theorem second_derivative_scale_bounds;; let second_derivative_compose_acs_bounds = finalize_theorem second_derivative_compose_acs_bounds;; let second_derivative_acs_bounds = finalize_theorem second_derivative_acs_bounds;; let second_derivative_compose_sqrt_bounds = finalize_theorem second_derivative_compose_sqrt_bounds;; let second_derivative_sqrt_bounds = finalize_theorem second_derivative_sqrt_bounds;; let second_derivative_compose_inv_bounds = finalize_theorem second_derivative_compose_inv_bounds;; let second_derivative_inv_bounds = finalize_theorem second_derivative_inv_bounds;; let second_derivative_compose_atn_bounds = finalize_theorem second_derivative_compose_atn_bounds;; let second_derivative_atn_bounds = finalize_theorem second_derivative_atn_bounds;; let second_derivative_compose_bounds = finalize_theorem second_derivative_compose_bounds;; let second_derivative_sub = finalize_theorem second_derivative_sub;; let second_derivative_add = finalize_theorem second_derivative_add;; let second_derivative_scale = finalize_theorem second_derivative_scale;; let diff2_div = finalize_theorem diff2_div;; let second_derivative_div = finalize_theorem second_derivative_div;; let second_derivative_mul = finalize_theorem second_derivative_mul;; let diff2_compose_acs = finalize_theorem diff2_compose_acs;; let diff2_compose_sqrt = finalize_theorem diff2_compose_sqrt;; let diff2_compose_inv = finalize_theorem diff2_compose_inv;; let diff2_compose_atn = finalize_theorem diff2_compose_atn;; let second_derivative_compose_acs = finalize_theorem second_derivative_compose_acs;; let second_derivative_compose_sqrt = finalize_theorem second_derivative_compose_sqrt;; let second_derivative_compose_inv = finalize_theorem second_derivative_compose_inv;; let second_derivative_compose_atn = finalize_theorem second_derivative_compose_atn;; let continuous_lt_exists_open = finalize_theorem continuous_lt_exists_open;; let continuous_gt_exists_open = finalize_theorem continuous_gt_exists_open;; let continuous_not0_exists_open = finalize_theorem continuous_not0_exists_open;; let diff2_compose = finalize_theorem diff2_compose;; let second_derivative_compose = finalize_theorem second_derivative_compose;; let REAL_CONTINUOUS_OPEN_PREIMAGE = finalize_theorem REAL_CONTINUOUS_OPEN_PREIMAGE;; let diff2_acs = finalize_theorem diff2_acs;; let second_derivative_acs = finalize_theorem second_derivative_acs;; let real_powS = finalize_theorem real_powS;; let diff2_sqrt = finalize_theorem diff2_sqrt;; let second_derivative_sqrt = finalize_theorem second_derivative_sqrt;; let SQRT_POW = finalize_theorem SQRT_POW;; let diff2_inv = finalize_theorem diff2_inv;; let second_derivative_inv = finalize_theorem second_derivative_inv;; let diff2_atn = finalize_theorem diff2_atn;; let second_derivative_atn = finalize_theorem second_derivative_atn;; let second_derivative_atn_eq = finalize_theorem second_derivative_atn_eq;; let lin_approx_compose = finalize_theorem lin_approx_compose;; let nth_diff_strong2_eq = finalize_theorem nth_diff_strong2_eq;; let nth_diff_strong2_eq_alt = finalize_theorem nth_diff_strong2_eq_alt;; (end_section "SecondDerivativeBound");; (begin_section "TaylorArith");;
let cell_domain = new_definition `cell_domain x y z w <=> 
	x <= y /\ y <= z /\ y - x <= w /\ z - y <= w`;;
(start_section_proof ["x";"y";"z";"w"](`cell_domain x y z w ==> taylor_interval (\x. x) x y z w (y, y) (&1, &1) (&0, &0)`));; refine (by (VALID ((((USE_THM_THEN cell_domain)(new_rewrite [] [])) THEN (move ["ineqs"])))));; 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 [] [])))))));; refine (by (VALID (((USE_THM_THEN has_bounded_second_derivative)(new_rewrite [] [])))));; 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)))));; 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))))));; refine (by (VALID (((((USE_THM_THEN REAL_CONTINUOUS_AT_ID)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (move ["i"])))));; refine (by (VALID ((((USE_THM_THEN (ARITH_RULE `i < 2 <=> i = 0 \/ i = 1`))(new_rewrite [] [])) THEN (case THEN (DISCH_THEN(new_rewrite [] [])))))));; 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)))));; 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)))));; refine (by (VALID ((((USE_THM_THEN HAS_REAL_DERIVATIVE_CONST)(new_rewrite [] [])) THEN (done_tac)))));; 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)))));; 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)))));; let taylor_x = end_section_proof();; (start_section_proof ["c";"x";"y";"z";"w"](`cell_domain x y z w ==> taylor_interval (\x. c) x y z w (c, c) (&0, &0) (&0, &0)`));; refine (by (VALID ((((USE_THM_THEN cell_domain)(new_rewrite [] [])) THEN (move ["ineqs"])))));; 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 [] [])))))));; refine (by (VALID (((USE_THM_THEN has_bounded_second_derivative)(new_rewrite [] [])))));; 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)))));; 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))))));; refine (by (VALID (((((USE_THM_THEN REAL_CONTINUOUS_CONST)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (move ["i"])))));; refine (by (VALID ((((USE_THM_THEN (ARITH_RULE `i < 2 <=> i = 0 \/ i = 1`))(new_rewrite [] [])) THEN (case THEN (DISCH_THEN(new_rewrite [] [])))))));; 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)))));; 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)))));; 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)))));; 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)))));; let taylor_const = end_section_proof();; (add_section_var (mk_var ("f", (`:real->real`))));; (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`))));; (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`))));; (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`))));; (start_section_proof ["df";"dd";"lo";"hi";"t"](`taylor_interval f x y z w (f_lo, f_hi) df_bounds dd_bounds ==> iabs df_bounds = df ==> iabs dd_bounds = dd ==> w * (df + w * dd * inv(&2)) <= t ==> f_hi + t <= hi ==> lo <= f_lo - t ==> bounded_on_int f (x, z) (lo, hi)`));; 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"])))));; 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"])))));; 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))));; 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"])))));; 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)))));; let taylor_f_bounds = end_section_proof();; (start_section_proof ["dd";"lo";"hi"](`taylor_interval f x y z w f_bounds (df_lo, df_hi) dd_bounds ==> iabs dd_bounds = dd ==> df_hi + w * dd <= hi ==> lo <= df_lo - w * dd ==> bounded_on_int (derivative f) (x, z) (lo, hi)`));; refine (by (VALID ((BETA_TAC THEN (move ["taylor_f"]) THEN (move ["iabs_dd"]) THEN (move ["hi_ineq"]) THEN (move ["lo_ineq"])))));; 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"])))));; 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))));; 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))));; 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)))));; let taylor_df_bounds = end_section_proof();; (start_section_proof ["g";"int";"g_bounds"](`bounded_on_int g int g_bounds ==> bounded_on_int f g_bounds f_bounds ==> bounded_on_int (\x. f (g x)) int f_bounds`));; 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)))));; refine (by (VALID (((((USE_THEN "f_bounded")(new_rewrite [] [])) THEN ((USE_THEN "g_bounded")(new_rewrite [] []))) THEN (done_tac)))));; let bounded_on_int_compose = end_section_proof();; (start_section_proof ["int"](`bounded_on_int f int f_bounds ==> interval_arith y int ==> interval_arith (f y) f_bounds`));; refine (by (VALID ((((USE_THM_THEN bounded_on_int)(new_rewrite [] [])) THEN (move ["bounded_f"]) THEN (move ["int_y"])))));; refine (by (VALID ((((USE_THEN "bounded_f")(new_rewrite [] [])) THEN (done_tac)))));; let bounded_on_int_imp_interval_arith = end_section_proof();; (start_section_proof ["x0";"z0";"w0"](`taylor_interval f x y z w f_bounds df_bounds dd_bounds ==> cell_domain x0 y z0 w0 ==> x <= x0 ==> z0 <= z ==> taylor_interval f x0 y z0 w0 f_bounds df_bounds dd_bounds`));; 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"])))));; 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))))));; 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"]))))));; refine (by (VALID (((split_tac) THEN (move ["p"]) THEN (move ["int_p"])))));; 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)))));; 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)))));; let taylor_interval_narrow = end_section_proof();; let taylor_interval_narrow = finalize_theorem taylor_interval_narrow;; let bounded_on_int_imp_interval_arith = finalize_theorem bounded_on_int_imp_interval_arith;; let bounded_on_int_compose = finalize_theorem bounded_on_int_compose;; let taylor_df_bounds = finalize_theorem taylor_df_bounds;; let taylor_f_bounds = finalize_theorem taylor_f_bounds;; let taylor_const = finalize_theorem taylor_const;; let taylor_x = finalize_theorem taylor_x;; (end_section "TaylorArith");;