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/formal_interval/theory/taylor_interval.hl";; section_stack := [];; prioritize_overload `:real^K`;; prioritize_overload `:real^N`;; prioritize_real();; let partial = new_definition `partial i f x = derivative (f o (\t. (x:real^N) + t % basis i)) (&0)`;; let all_n = define `(all_n n [] s <=> T) /\ (all_n n (CONS h t) s <=> s n h /\ all_n (SUC n) t s)`;; let m_lin_approx = new_definition `m_lin_approx (f:real^N->real) x f_bounds df_bounds_list <=> (lift o f) differentiable at x /\ interval_arith (f x) f_bounds /\ all_n 1 df_bounds_list (\i int. interval_arith (partial i f x) int)`;; (begin_section "Misc");; (start_section_proof ["f"](`lift o (\x. --f x) = (\x. --(lift o f) x)`));; refine (by (VALID (((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN LIFT_NEG)(new_rewrite [] []))) THEN (done_tac)))));; let f_lift_neg = end_section_proof();; (start_section_proof ["f";"c"](`lift o (\x. c * f x) = (\x. c % (lift o f) x)`));; refine (by (VALID (((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN LIFT_CMUL)(new_rewrite [] []))) THEN (done_tac)))));; let f_lift_scale = end_section_proof();; (start_section_proof ["f";"g"](`lift o (\x. f x + g x) = (\x. (lift o f) x + (lift o g) x)`));; refine (by (VALID (((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN LIFT_ADD)(new_rewrite [] []))) THEN (done_tac)))));; let f_lift_add = end_section_proof();; (start_section_proof ["f";"g"](`lift o (\x. f x - g x) = (\x. (lift o f) x - (lift o g) x)`));; refine (by (VALID (((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN LIFT_SUB)(new_rewrite [] []))) THEN (done_tac)))));; let f_lift_sub = end_section_proof();; (start_section_proof ["op";"f";"g"](`(\t. op (f t) (g t)) o drop = (\x. op (f (drop x)) (g (drop x)))`));; refine (by (VALID (((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] [])))) THEN (done_tac)))));; let f_binary_drop = end_section_proof();; (start_section_proof ["op";"f"](`(\t. op (f t)) o drop = (\x. op (f (drop x)))`));; refine (by (VALID (((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] [])))) THEN (done_tac)))));; let f_unary_drop = end_section_proof();; (begin_section "MoreFrechet");; (add_section_var (mk_var ("f", (`:real^N -> real^M`))); add_section_var (mk_var ("g", (`:real^N -> real^M`))));; (add_section_var (mk_var ("x", (`:real^N`))); add_section_var (mk_var ("y", (`:real^N`))));; (start_section_proof ["f";"g";"x"](`f differentiable at (g x) ==> g differentiable at x ==> frechet_derivative (f o g) (at x) = frechet_derivative f (at (g x)) o frechet_derivative g (at x)`));; refine (by (VALID (((BETA_TAC THEN (move ["df"]) THEN (move ["dg"])) THEN ((USE_THM_THEN EQ_SYM_EQ)(new_rewrite [] [])) THEN ((USE_THM_THEN FRECHET_DERIVATIVE_AT) apply_tac)))));; refine (by (VALID ((((USE_THM_THEN DIFF_CHAIN_AT) apply_tac) THEN repeat_tactic 1 9 (((USE_THM_THEN FRECHET_DERIVATIVE_WORKS)(GSYM_THEN (new_rewrite [] [])))) THEN (done_tac)))));; let frechet_compose = end_section_proof();; (start_section_proof ["z"](`frechet_derivative (\x. y) (at z) = (\x. vec 0)`));; refine (by (VALID ((((USE_THM_THEN EQ_SYM_EQ)(new_rewrite [] [])) THEN ((USE_THM_THEN FRECHET_DERIVATIVE_AT) apply_tac) THEN ((USE_THM_THEN HAS_DERIVATIVE_CONST)(new_rewrite [] [])) THEN (done_tac)))));; let frechet_const = end_section_proof();; (start_section_proof [](`frechet_derivative (\x. x) (at y) = (\x. x)`));; refine (by (VALID ((((USE_THM_THEN EQ_SYM_EQ)(new_rewrite [] [])) THEN ((USE_THM_THEN FRECHET_DERIVATIVE_AT) apply_tac) THEN ((USE_THM_THEN HAS_DERIVATIVE_ID)(new_rewrite [] [])) THEN (done_tac)))));; let frechet_id = end_section_proof();; (start_section_proof ["z"](`frechet_derivative (\x. drop x % y) (at z) = (\x. drop x % y)`));; refine (by (VALID ((((USE_THM_THEN EQ_SYM_EQ)(new_rewrite [] [])) THEN ((USE_THM_THEN FRECHET_DERIVATIVE_AT) apply_tac) THEN ((USE_THM_THEN HAS_DERIVATIVE_VMUL_DROP) apply_tac)))));; refine (by (VALID (((USE_THM_THEN HAS_DERIVATIVE_ID)(new_rewrite [] [])))));; let frechet_vmul = end_section_proof();; (add_section_hyp "df" (`f differentiable at x`));; (start_section_proof [](`frechet_derivative (\x. --f x) (at x) = (\y. --frechet_derivative f (at x) y)`));; refine (by (VALID ((((USE_THM_THEN EQ_SYM_EQ)(new_rewrite [] [])) THEN ((USE_THM_THEN FRECHET_DERIVATIVE_AT) apply_tac) THEN ((USE_THM_THEN HAS_DERIVATIVE_NEG) apply_tac)))));; refine (by (VALID ((((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN ((USE_THM_THEN FRECHET_DERIVATIVE_WORKS)(GSYM_THEN (new_rewrite [] []))) THEN (done_tac)))));; let frechet_neg = end_section_proof();; (start_section_proof ["c"](`frechet_derivative (\x. c % f x) (at x) = (\y. c % frechet_derivative f (at x) y)`));; refine (by (VALID ((((USE_THM_THEN EQ_SYM_EQ)(new_rewrite [] [])) THEN ((USE_THM_THEN FRECHET_DERIVATIVE_AT) apply_tac) THEN ((USE_THM_THEN HAS_DERIVATIVE_CMUL) apply_tac)))));; refine (by (VALID ((((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN ((USE_THM_THEN FRECHET_DERIVATIVE_WORKS)(GSYM_THEN (new_rewrite [] []))) THEN (done_tac)))));; let frechet_scale = end_section_proof();; (add_section_hyp "dg" (`g differentiable at x`));; (start_section_proof [](`frechet_derivative (\x. f x + g x) (at x) = (\y. frechet_derivative f (at x) y + frechet_derivative g (at x) y)`));; refine (by (VALID ((((USE_THM_THEN EQ_SYM_EQ)(new_rewrite [] [])) THEN ((USE_THM_THEN FRECHET_DERIVATIVE_AT) apply_tac) THEN ((USE_THM_THEN HAS_DERIVATIVE_ADD) apply_tac)))));; refine (by (VALID ((((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN repeat_tactic 1 9 (((USE_THM_THEN FRECHET_DERIVATIVE_WORKS)(GSYM_THEN (new_rewrite [] [])))) THEN (done_tac)))));; let frechet_add = end_section_proof();; (start_section_proof [](`frechet_derivative (\x. f x - g x) (at x) = (\y. frechet_derivative f (at x) y - frechet_derivative g (at x) y)`));; refine (by (VALID ((((USE_THM_THEN EQ_SYM_EQ)(new_rewrite [] [])) THEN ((USE_THM_THEN FRECHET_DERIVATIVE_AT) apply_tac) THEN ((USE_THM_THEN HAS_DERIVATIVE_SUB) apply_tac)))));; refine (by (VALID ((((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN repeat_tactic 1 9 (((USE_THM_THEN FRECHET_DERIVATIVE_WORKS)(GSYM_THEN (new_rewrite [] [])))) THEN (done_tac)))));; let frechet_sub = end_section_proof();; let frechet_sub = finalize_theorem frechet_sub;; let frechet_add = finalize_theorem frechet_add;; let frechet_scale = finalize_theorem frechet_scale;; let frechet_neg = finalize_theorem frechet_neg;; let frechet_vmul = finalize_theorem frechet_vmul;; let frechet_id = finalize_theorem frechet_id;; let frechet_const = finalize_theorem frechet_const;; let frechet_compose = finalize_theorem frechet_compose;; (end_section "MoreFrechet");; (start_section_proof ["f";"g";"x"](`f differentiable at (g x) ==> g differentiable at x ==> (f o g) differentiable at x`));; refine (by (VALID (((BETA_TAC THEN (move ["df"]) THEN (move ["dg"])) THEN ((USE_THM_THEN FRECHET_DERIVATIVE_WORKS)(new_rewrite [] []))))));; refine (by (VALID (((((USE_THM_THEN frechet_compose)(new_rewrite [] [])) THEN ((TRY done_tac))) THEN ((USE_THM_THEN DIFF_CHAIN_AT) apply_tac) THEN repeat_tactic 1 9 (((USE_THM_THEN FRECHET_DERIVATIVE_WORKS)(GSYM_THEN (new_rewrite [] [])))) THEN (done_tac)))));; let differentiable_compose_at = end_section_proof();; (start_section_proof ["f";"g";"x"](`f differentiable at (g x) ==> g differentiable at x ==> jacobian (f o g) (at x) = jacobian f (at (g x)) ** jacobian g (at x)`));; refine (by (VALID ((BETA_TAC THEN (move ["df"]) THEN (move ["dg"])))));; refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN jacobian)(new_rewrite [] []))) THEN ((USE_THM_THEN frechet_compose)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN MATRIX_COMPOSE)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN repeat_tactic 1 9 (((USE_THM_THEN LINEAR_FRECHET_DERIVATIVE)(new_rewrite [] [])))) THEN (done_tac)))));; let jacobian_compose = end_section_proof();; (start_section_proof ["f";"x"](`f differentiable at x ==> frechet_derivative f (at x) = (\h. jacobian f (at x) ** h)`));; refine (by (VALID ((BETA_TAC THEN (move ["df"])))));; refine (by (VALID (((((USE_THM_THEN EQ_SYM_EQ)(new_rewrite [] [])) THEN ((USE_THM_THEN FRECHET_DERIVATIVE_AT)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN JACOBIAN_WORKS)(GSYM_THEN (new_rewrite [] [])))) THEN (done_tac)))));; let frechet_eq_jacobian = end_section_proof();; (begin_section "Product");; (start_section_proof ["w";"x";"y";"z"](`&0 < w /\ w <= x /\ &0 <= y /\ y < z ==> w * y < x * z`));; refine (by (VALID ((BETA_TAC THEN (move ["ineq"])))));; refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN EXCLUDED_MIDDLE)(ISPEC_THEN (`w = x`) thm_tac))MP_TAC) THEN case THENL [(move ["w_eq_x"]); (move ["wnx"])]))));; refine (by (VALID (((((USE_THEN "w_eq_x")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN REAL_LT_LMUL)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((((USE_THM_THEN REAL_LT_MUL2)(new_rewrite [] [])) THEN (((USE_THEN "wnx")MP_TAC) THEN (clear_assumption "wnx") THEN ((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; let REAL_LET_MUL2 = end_section_proof();; (start_section_proof ["y"](`(lift o (\x:real^2. x$1 * x$2) has_derivative lift o (\x. y$2 * x$1 + y$1 * x$2)) (at y)`));; refine (by (VALID ((((USE_THM_THEN has_derivative_at)(new_rewrite [] [])) THEN (split_tac)))));; refine (by (VALID ((((USE_THM_THEN linear)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (simp_tac) THEN repeat_tactic 1 9 (((USE_THM_THEN VECTOR_ADD_COMPONENT)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN VECTOR_MUL_COMPONENT)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN LIFT_ADD)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN LIFT_CMUL)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN LIFT_ADD)(new_rewrite [] [])))))));; refine (by (VALID (((VECTOR_ARITH_TAC) THEN (done_tac)))));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN LIFT_ADD)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN LIFT_SUB)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN LIFT_CMUL)(GSYM_THEN (new_rewrite [] [])))))));; refine (by (VALID (((((USE_THM_THEN LIM_AT)(new_rewrite [] [])) THEN (simp_tac) THEN repeat_tactic 1 9 (((USE_THM_THEN dist)(new_rewrite [] []))) THEN ((USE_THM_THEN (GEN_ALL VECTOR_SUB_RZERO))(new_rewrite [] [])) THEN ((USE_THM_THEN NORM_LIFT)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN VECTOR_SUB_COMPONENT)(new_rewrite [] [])))) THEN (move ["e"]) THEN (move ["e0"])))));; refine (by (VALID (((USE_THM_THEN (REAL_ARITH `(x:real^2)$1 * x$2 - ((y:real^2)$1 * y$2 + y$2 * (x$1 - y$1) + y$1 * (x$2 - y$2)) = (x$2 - y$2) * (x$1 - y$1)`))(new_rewrite [] [])))));; refine (by (VALID (((exists_tac (mk_var("e",mk_type("real",[])))) THEN ((((USE_THEN "e0")(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (move ["x"]) THEN (case THEN ((move ["norm0"]) THEN (move ["norm_e"]))))))));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN REAL_ABS_MUL)(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_ABS_INV)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_ABS_NORM)(new_rewrite [] []))))));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN VECTOR_SUB_COMPONENT)(GSYM_THEN (new_rewrite [] [])))) THEN (set_tac "p" (`x - y:real^2`))))));; refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN NORM_BOUND_COMPONENT_LT)(fun fst_th ->(USE_THEN "norm_e")(fun th -> MATCH_MP_THEN th thm_tac fst_th))) MP_TAC) THEN (move ["ineq"])))));; refine (by (VALID (((((USE_THM_THEN REAL_LTE_TRANS)MP_TAC) THEN (clear_assumption "REAL_LTE_TRANS") THEN (DISCH_THEN apply_tac)) THEN (exists_tac (`inv (infnorm p) * infnorm p * e`))))));; refine (by (VALID (((THENL_FIRST) (have_tac (move ["infnorm_0"]) (`&0 < infnorm p`)) ((((USE_THM_THEN INFNORM_POS_LT)(new_rewrite [] [])) THEN ((USE_THM_THEN NORM_POS_LT)(GSYM_THEN (new_rewrite [] [])))) THEN (done_tac))))));; refine (by (VALID (((THENL_ROT (-1)) (split_tac)))));; refine (by (VALID (((((USE_THM_THEN REAL_MUL_ASSOC)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_LINV)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_MUL_LID)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_LE_REFL)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN INFNORM_EQ_0)(new_rewrite [] [])) THEN ((USE_THM_THEN NORM_POS_LT)(GSYM_THEN (new_rewrite [] [])))) THEN (done_tac)))));; refine (by (VALID ((((USE_THM_THEN REAL_LET_MUL2)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LT_INV)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN REAL_LE_INV2)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN INFNORM_LE_NORM)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] [])))))));; refine (by (VALID ((((USE_THM_THEN REAL_LE_MUL)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_ABS_POS)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))))));; refine (by (VALID ((have_tac ALL_TAC (`infnorm p = abs (p$1) \/ infnorm p = abs (p$2)`)))));; refine (by (VALID ((((USE_THM_THEN (GEN_ALL INFNORM_2))(new_rewrite [] [])) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((((THENL_FIRST) (case THEN (DISCH_THEN(GSYM_THEN (new_rewrite [] [])))) ((USE_THM_THEN REAL_MUL_SYM)(new_rewrite [] []))) THEN (((USE_THM_THEN REAL_LT_LMUL)(new_rewrite [] [])) THEN ((USE_THEN "ineq")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN DIMINDEX_2)(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac)))));; let has_derivative_x12 = end_section_proof();; (start_section_proof ["f"](`(\x:A. lambda i. f i x) = (\x. vsum (1..dimindex (:N)) (\i. f i x % (basis i:real^N)))`));; refine (by (VALID (((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN (simp_tac)) THEN (move ["x"])))));; refine (by (VALID (((((USE_THM_THEN CART_EQ)(new_rewrite [] [])) THEN (move ["i"]) THEN (move ["ineq"])) THEN (((USE_THM_THEN (GEN_ALL LAMBDA_BETA))(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN VSUM_COMPONENT)(new_rewrite [] [])) THEN ((simp_tac THEN TRY done_tac)))))));; refine (by (VALID (((set_tac "A" (`1.. _`)) THEN (set_tac "B" (`A DIFF {i}`))))));; refine (by (VALID ((have_tac (move ["cond"]) (`DISJOINT B {i} /\ A = B UNION {i}`)))));; refine (by (VALID ((((USE_THM_THEN DISJOINT)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN EXTENSION)(new_rewrite [] []))) THEN ((USE_THEN "B_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THEN "A_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN IN_INTER)(new_rewrite [] [])) THEN ((USE_THM_THEN IN_DIFF)(new_rewrite [] [])) THEN ((USE_THM_THEN IN_SING)(new_rewrite [] [])) THEN ((USE_THM_THEN NOT_IN_EMPTY)(new_rewrite [] [])) THEN (simp_tac)))));; refine (by (VALID (((THENL_FIRST) ((split_tac) THEN (move ["x"])) ((repeat_tactic 1 9 (((USE_THM_THEN negb_and)(new_rewrite [] []))) THEN ((USE_THM_THEN negbK)(new_rewrite [] [])) THEN ((USE_THM_THEN orbA)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN EXCLUDED_MIDDLE)(new_rewrite [] []))) THEN (done_tac))))));; refine (by (VALID ((((USE_THM_THEN IN_UNION)(new_rewrite [] [])) THEN ((USE_THM_THEN IN_DIFF)(new_rewrite [] [])) THEN ((USE_THM_THEN IN_SING)(new_rewrite [] []))))));; refine (by (VALID (((((fun thm_tac -> (USE_THM_THEN EXCLUDED_MIDDLE)(ISPEC_THEN (`x = i`) thm_tac))MP_TAC) THEN case THEN (DISCH_THEN(new_rewrite [] [])) THEN ((TRY done_tac))) THEN ((simp_tac) THEN ((USE_THM_THEN IN_NUMSEG)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((((USE_THEN "cond")(new_rewrite [] [])) THEN ((USE_THM_THEN SUM_UNION)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "cond")(new_rewrite [] []))) THEN ((USE_THEN "B_def")(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN FINITE_DIFF)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "A_def")(GSYM_THEN (new_rewrite [] [])))) THEN repeat_tactic 0 10 (((USE_THM_THEN FINITE_NUMSEG)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN FINITE_SING)(new_rewrite [] []))) THEN ((TRY done_tac))))));; refine (by (VALID ((((USE_THM_THEN SUM_SING)(new_rewrite [] [])) THEN (simp_tac) THEN repeat_tactic 1 9 (((USE_THM_THEN VECTOR_MUL_COMPONENT)(new_rewrite [] []))) THEN ((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN BASIS_COMPONENT)(ISPEC_THEN (mk_var("i",mk_type("num",[]))) thm_tac))(ISPEC_THEN (mk_var("i",mk_type("num",[]))) thm_tac))(new_rewrite [] [])) THEN ((simp_tac THEN TRY done_tac))))));; refine (by (VALID (((((USE_THM_THEN (REAL_ARITH `!a b. a = b + a * &1 <=> b = &0`))(new_rewrite [] [])) THEN ((USE_THM_THEN SUM_EQ_0)(new_rewrite [] [])) THEN ((TRY done_tac))) THEN (move ["j"])))));; refine (by (VALID ((((((USE_THM_THEN IN_DIFF)(new_rewrite [] [])) THEN ((USE_THM_THEN IN_SING)(new_rewrite [] []))) THEN (move ["ineq_j"]) THEN (simp_tac)) THEN (((USE_THM_THEN BASIS_COMPONENT)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((fun thm_tac -> (USE_THM_THEN EQ_SYM_EQ)(ISPEC_THEN (mk_var("i",mk_type("num",[]))) thm_tac))(new_rewrite [] [])))))));; refine (by (VALID (((((USE_THEN "ineq_j")(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN REAL_MUL_RZERO)(new_rewrite [] []))) THEN (done_tac)))));; let lambda_eq_vsum = end_section_proof();; (start_section_proof ["f";"f'";"y"](`(!i. i IN 1..dimindex (:M) ==> (lift o (f i) has_derivative lift o (f' i)) (at (y:real^N))) ==> (((\x. lambda i. f i x):real^N->real^M) has_derivative (\x. lambda i. f' i x) ) (at y)`));; refine (by (VALID (((BETA_TAC THEN (move ["df"])) THEN repeat_tactic 1 9 (((USE_THM_THEN lambda_eq_vsum)(new_rewrite [] []))) THEN ((USE_THM_THEN HAS_DERIVATIVE_VSUM) apply_tac)))));; refine (by (VALID (((((USE_THM_THEN FINITE_NUMSEG)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (move ["i"]) THEN (move ["ineq"]) THEN (simp_tac)))));; refine (by (VALID ((have_tac (move ["eq"]) (`!f. (\x:real^N. f i x % (basis i:real^M)) = (\x. drop ((lift o f i) x) % basis i)`)))));; refine (by (VALID (((BETA_TAC THEN (move ["g"])) THEN (((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN o_THM)(new_rewrite [] [])) THEN ((USE_THM_THEN LIFT_DROP)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((((fun thm_tac -> (USE_THEN "eq")(ISPEC_THEN (mk_var("f",mk_type("fun",[mk_type("num",[]);mk_type("fun",[mk_type("cart",[mk_type("real",[]);mk_vartype "N"]);mk_type("real",[])])]))) thm_tac))(new_rewrite [] [])) THEN ((fun thm_tac -> (USE_THEN "eq")(ISPEC_THEN (mk_var("f'",mk_type("fun",[mk_type("num",[]);mk_type("fun",[mk_type("cart",[mk_type("real",[]);mk_vartype "N"]);mk_type("real",[])])]))) thm_tac))(new_rewrite [] [])) THEN ((USE_THM_THEN (GEN_ALL HAS_DERIVATIVE_VMUL_DROP))(new_rewrite [] []))) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN ((USE_THEN "df")(new_rewrite [] [])) THEN (done_tac)))));; let has_derivative_lambda = end_section_proof();; (start_section_proof ["x";"y"](`(vector [x; y]:real^2) = (lambda i. if i = 1 then x else y)`));; refine (by (VALID ((((((USE_THM_THEN CART_EQ)(new_rewrite [] [])) THEN ((USE_THM_THEN DIMINDEX_2)(new_rewrite [] []))) THEN (move ["i"])) THEN ((USE_THM_THEN (ARITH_RULE `1 <= i /\ i <= 2 <=> i = 1 \/ i = 2`))(new_rewrite [] []))))));; refine (by (VALID (((case THEN (DISCH_THEN(new_rewrite [1; 3] []))) THEN (((USE_THM_THEN (GEN_ALL VECTOR_2))(new_rewrite [] [])) THEN ((USE_THM_THEN (GEN_ALL LAMBDA_BETA))(new_rewrite [] [])) THEN (simp_tac) THEN repeat_tactic 0 10 (((USE_THM_THEN DIMINDEX_2)(new_rewrite [] [])))) THEN (arith_tac) THEN (done_tac)))));; let vector2_eq_lambda = end_section_proof();; (start_section_proof ["f";"g";"f'";"g'";"y"](`(lift o f has_derivative lift o f') (at y) ==> (lift o g has_derivative lift o g') (at y) ==> ((\x. vector [f x; g x]:real^2) has_derivative (\x. vector [f' x; g' x]:real^2)) (at y)`));; refine (by (VALID (((BETA_TAC THEN (move ["df"]) THEN (move ["dg"])) THEN repeat_tactic 1 9 (((USE_THM_THEN vector2_eq_lambda)(new_rewrite [] [])))))));; refine (by (VALID ((((USE_THM_THEN has_derivative_lambda) apply_tac) THEN ((((USE_THM_THEN DIMINDEX_2)(new_rewrite [] [])) THEN ((USE_THM_THEN IN_NUMSEG)(new_rewrite [] []))) THEN (move ["i"]))))));; refine (by (VALID ((((USE_THM_THEN (ARITH_RULE `1 <= i /\ i <= 2 <=> i = 1 \/ i = 2`))(new_rewrite [] [])) THEN (case THEN (DISCH_THEN(new_rewrite [2; 4] [])) THEN (simp_tac)) THEN (((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN ((TRY done_tac)))))));; refine (by (VALID (((((USE_THM_THEN (ARITH_RULE `~(2 = 1)`))(new_rewrite [] [])) THEN (simp_tac)) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN (done_tac)))));; let has_derivative_vector2 = end_section_proof();; (start_section_proof ["f";"g";"f'";"g'";"y"](`(lift o f has_derivative lift o f') (at y) ==> (lift o g has_derivative lift o g') (at y) ==> (lift o (\x. f x * g x) has_derivative lift o (\x. f' x * g y + f y * g' x)) (at y)`));; refine (by (VALID ((BETA_TAC THEN (move ["df"]) THEN (move ["dg"])))));; refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`lift o (\x. f x * g x) = (lift o (\p. p$1 * p$2)) o (\x. vector [f x; g x]:real^2)`)))));; refine (by (VALID ((((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (simp_tac)) THEN (move ["x"])) THEN repeat_tactic 1 9 (((USE_THM_THEN (GEN_ALL VECTOR_2))(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((set_tac "q" (`vector [f y; g y]:real^2`)))));; refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`lift o (\x. f' x * g y + f y * g' x) = (lift o (\x:real^2. q$2 * x$1 + q$1 * x$2)) o (\x. vector [f' x; g' x])`)))));; refine (by (VALID (((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THEN "q_def")(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN (GEN_ALL VECTOR_2))(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_MUL_SYM)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((((USE_THM_THEN DIFF_CHAIN_AT) apply_tac) THEN (simp_tac)) THEN (((USE_THEN "q_def")(new_rewrite [] [])) THEN ((USE_THM_THEN has_derivative_x12)(new_rewrite [] [])) THEN ((USE_THM_THEN has_derivative_vector2)(new_rewrite [] []))) THEN (done_tac)))));; let has_derivative_mul = end_section_proof();; (start_section_proof ["f"](`f = lift o (drop o f)`));; refine (by (VALID (((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN ((USE_THM_THEN LIFT_DROP)(new_rewrite [] []))) THEN (done_tac)))));; let f_eq_lift_drop = end_section_proof();; (start_section_proof ["f";"g";"y"](`lift o f differentiable (at y) ==> lift o g differentiable (at y) ==> lift o (\x. f x * g x) differentiable (at y)`));; refine (by (VALID ((repeat_tactic 2 0 (((USE_THM_THEN differentiable)(new_rewrite [] []))) THEN ALL_TAC THEN (case THEN (move ["f'"])) THEN (move ["df"]) THEN (case THEN (move ["g'"])) THEN (move ["dg"])))));; 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 ((((fun thm_tac -> (USE_THM_THEN f_eq_lift_drop)(ISPEC_THEN (mk_var("f'",mk_type("fun",[mk_type("cart",[mk_type("real",[]);mk_vartype "?1451210"]);mk_type("cart",[mk_type("real",[]);mk_type("1",[])])]))) thm_tac))(new_rewrite [] [])) THEN ((fun thm_tac -> (USE_THM_THEN f_eq_lift_drop)(ISPEC_THEN (mk_var("g'",mk_type("fun",[mk_type("cart",[mk_type("real",[]);mk_vartype "?1451210"]);mk_type("cart",[mk_type("real",[]);mk_type("1",[])])]))) thm_tac))(new_rewrite [] []))) THEN (move ["df"]) THEN (move ["dg"]))))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN has_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))) MP_TAC) THEN ALL_TAC))));; refine (by (VALID ((((USE_THM_THEN HAS_DERIVATIVE_IMP_DIFFERENTIABLE) apply_tac) THEN (done_tac)))));; let differentiable_mul = end_section_proof();; (start_section_proof ["f";"g";"y"](`lift o f differentiable at y ==> lift o g differentiable at y ==> frechet_derivative (lift o (\x. f x * g x)) (at y) = (\x. g y % frechet_derivative (lift o f) (at y) x + f y % frechet_derivative (lift o g) (at y) x)`));; refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN FRECHET_DERIVATIVE_WORKS)(new_rewrite [] []))) THEN ((USE_THM_THEN f_eq_lift_drop)(new_rewrite [] [(`frechet_derivative _1 _2`)]))) THEN (move ["df"])))));; refine (by (VALID ((((USE_THM_THEN f_eq_lift_drop)(new_rewrite [] [(`frechet_derivative _1 _2`)])) THEN (move ["dg"])))));; refine (by (VALID (((((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN has_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))) MP_TAC) THEN ALL_TAC) THEN ((DISCH_THEN (fun snd_th -> (USE_THM_THEN FRECHET_DERIVATIVE_AT)(MATCH_MP_THEN snd_th MP_TAC))) THEN BETA_TAC THEN (DISCH_THEN(GSYM_THEN (new_rewrite [] []))))))));; refine (by (VALID (((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (simp_tac) THEN repeat_tactic 1 9 (((USE_THM_THEN LIFT_DROP)(new_rewrite [] [])))) THEN (move ["x"])))));; refine (by (VALID (((((USE_THM_THEN LIFT_ADD)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_SYM)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN LIFT_CMUL)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN LIFT_DROP)(new_rewrite [] [])))) THEN (done_tac)))));; let frechet_mul = end_section_proof();; let frechet_mul = finalize_theorem frechet_mul;; let differentiable_mul = finalize_theorem differentiable_mul;; let f_eq_lift_drop = finalize_theorem f_eq_lift_drop;; let has_derivative_mul = finalize_theorem has_derivative_mul;; let has_derivative_vector2 = finalize_theorem has_derivative_vector2;; let vector2_eq_lambda = finalize_theorem vector2_eq_lambda;; let has_derivative_lambda = finalize_theorem has_derivative_lambda;; let lambda_eq_vsum = finalize_theorem lambda_eq_vsum;; let has_derivative_x12 = finalize_theorem has_derivative_x12;; let REAL_LET_MUL2 = finalize_theorem REAL_LET_MUL2;; (end_section "Product");; let frechet_mul = finalize_theorem frechet_mul;; let differentiable_mul = finalize_theorem differentiable_mul;; let f_eq_lift_drop = finalize_theorem f_eq_lift_drop;; let has_derivative_mul = finalize_theorem has_derivative_mul;; let has_derivative_vector2 = finalize_theorem has_derivative_vector2;; let vector2_eq_lambda = finalize_theorem vector2_eq_lambda;; let has_derivative_lambda = finalize_theorem has_derivative_lambda;; let lambda_eq_vsum = finalize_theorem lambda_eq_vsum;; let has_derivative_x12 = finalize_theorem has_derivative_x12;; let REAL_LET_MUL2 = finalize_theorem REAL_LET_MUL2;; let frechet_eq_jacobian = finalize_theorem frechet_eq_jacobian;; let jacobian_compose = finalize_theorem jacobian_compose;; let differentiable_compose_at = finalize_theorem differentiable_compose_at;; let frechet_sub = finalize_theorem frechet_sub;; let frechet_add = finalize_theorem frechet_add;; let frechet_scale = finalize_theorem frechet_scale;; let frechet_neg = finalize_theorem frechet_neg;; let frechet_vmul = finalize_theorem frechet_vmul;; let frechet_id = finalize_theorem frechet_id;; let frechet_const = finalize_theorem frechet_const;; let frechet_compose = finalize_theorem frechet_compose;; let f_unary_drop = finalize_theorem f_unary_drop;; let f_binary_drop = finalize_theorem f_binary_drop;; let f_lift_sub = finalize_theorem f_lift_sub;; let f_lift_add = finalize_theorem f_lift_add;; let f_lift_scale = finalize_theorem f_lift_scale;; let f_lift_neg = finalize_theorem f_lift_neg;; (end_section "Misc");; (begin_section "Partial");; (start_section_proof ["f";"h";"t"](`(lift o f) differentiable at (h t) ==> (h o drop) differentiable at (lift t) ==> ((f o h) has_real_derivative (drop o (frechet_derivative (lift o f) (at (h t)) o frechet_derivative (h o drop) (at (lift t))) o lift) (&1)) (atreal t)`));; refine (by (VALID ((BETA_TAC THEN (move ["diff_f"]) THEN (move ["diff_h"])))));; refine (by (VALID (((((USE_THEN "diff_h")MP_TAC) THEN ((USE_THEN "diff_f")MP_TAC) THEN BETA_TAC) THEN repeat_tactic 1 9 (((USE_THM_THEN FRECHET_DERIVATIVE_WORKS)(new_rewrite [] [])))))));; refine (by (VALID ((set_tac "f'" (`frechet_derivative _1 _2`)))));; refine (by (VALID ((set_tac "h'" (`frechet_derivative _1 _2`)))));; refine (by (VALID ((BETA_TAC THEN (move ["df"]) THEN (move ["dh"])))));; refine (by (VALID (((USE_THM_THEN (GEN_ALL HAS_REAL_FRECHET_DERIVATIVE_AT))(new_rewrite [] [])))));; refine (by (VALID (((THENL_FIRST) (have_tac (DISCH_THEN(new_rewrite [] [])) (`lift o (f o h) o drop = (lift o f) o (h o drop)`)) (repeat_tactic 1 9 (((USE_THM_THEN o_ASSOC)(new_rewrite [] []))) THEN (done_tac))))));; refine (by (VALID ((((THENL_ROT 1)) (have_tac (DISCH_THEN(new_rewrite [] [])) (`(\x. (drop o (f' o h') o lift) (&1) % x) = f' o h'`))))));; refine (by (VALID (((((USE_THM_THEN DIFF_CHAIN_AT)(new_rewrite [] [])) THEN ((USE_THEN "dh")(new_rewrite [] [])) THEN ((USE_THM_THEN o_THM)(new_rewrite [] [])) THEN ((USE_THM_THEN LIFT_DROP)(new_rewrite [] [])) THEN ((USE_THEN "df")(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] [])))) THEN (move ["x"]) THEN (simp_tac)))));; refine (by (VALID ((have_tac (move ["lin"]) (`linear f' /\ linear h'`)))));; refine (by (VALID (((((USE_THEN "h'_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THEN "f'_def")(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN LINEAR_FRECHET_DERIVATIVE)(new_rewrite [] [])))) THEN (done_tac)))));; refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [2] [])) (`x = drop x % lift (&1)`)))));; refine (by (VALID (((((USE_THM_THEN DROP_EQ)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN DROP_CMUL)(new_rewrite [] [])) THEN ((USE_THM_THEN LIFT_DROP)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_RID)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN LINEAR_CMUL)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN DROP_EQ)(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN DROP_CMUL)(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_MUL_SYM)(new_rewrite [] []))) THEN (done_tac)))));; let real_derivative_compose_frechet = end_section_proof();; (start_section_proof ["f";"h";"t"](`(lift o f) differentiable at (h t) ==> (h o drop) differentiable at (lift t) ==> ((f o h) has_real_derivative (jacobian (lift o f) (at (h t)) ** jacobian (h o drop) (at (lift t)))$1$1) (atreal t)`));; refine (by (VALID ((BETA_TAC THEN (move ["df"]) THEN (move ["dh"])))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN real_derivative_compose_frechet)(fun fst_th ->(USE_THEN "df")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "dh")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC))));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN frechet_eq_jacobian)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (simp_tac)))));; refine (by (VALID ((((USE_THM_THEN MATRIX_VECTOR_MUL_ASSOC)(new_rewrite [] [])) THEN ((USE_THM_THEN matrix_vector_mul)(new_rewrite [] [])) THEN ((USE_THM_THEN DROP_LAMBDA)(new_rewrite [] [])) THEN ((USE_THM_THEN DIMINDEX_1)(new_rewrite [] [])) THEN ((USE_THM_THEN SUM_SING_NUMSEG)(new_rewrite [] [])) THEN (simp_tac)))));; refine (by (VALID (((((USE_THM_THEN LIFT_COMPONENT)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_RID)(new_rewrite [] []))) THEN (done_tac)))));; let real_derivative_compose_jacobian = end_section_proof();; (start_section_proof ["f";"h";"t"](`(lift o f) differentiable at (h t) ==> (h o drop) differentiable at (lift t) ==> (f o h) real_differentiable atreal t`));; refine (by (VALID ((BETA_TAC THEN (move ["diff_f"]) THEN (move ["diff_h"])))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN real_derivative_compose_frechet)(fun fst_th ->(USE_THEN "diff_f")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "diff_h")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC))));; refine (by (VALID ((set_tac "fh'" (`(drop o _ o lift) (&1)`)))));; refine (by (VALID (((((USE_THM_THEN real_differentiable)(new_rewrite [] [])) THEN (move ["dfh"])) THEN (exists_tac (mk_var("fh'",mk_type("real",[])))) THEN (done_tac)))));; let diff_imp_real_diff = end_section_proof();; (start_section_proof ["y";"e";"net"](`((\t. y + t % e) o drop) differentiable net`));; refine (by (VALID (((THENL_FIRST) (have_tac (DISCH_THEN(new_rewrite [] [])) (`(\t. y + t % e) o drop = (\x. y + drop x % e)`)) ((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (done_tac))))));; refine (by (VALID ((((USE_THM_THEN DIFFERENTIABLE_ADD)(new_rewrite [] [])) THEN ((USE_THM_THEN DIFFERENTIABLE_CONST)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))))));; refine (by (VALID (((USE_THM_THEN HAS_DERIVATIVE_IMP_DIFFERENTIABLE) apply_tac))));; refine (by (VALID (((exists_tac (`\x. drop x % e`)) THEN ((USE_THM_THEN HAS_DERIVATIVE_VMUL_DROP) apply_tac) THEN ((USE_THM_THEN HAS_DERIVATIVE_ID)(new_rewrite [] [])) THEN (done_tac)))));; let diff_direction = end_section_proof();; (start_section_proof ["y";"e";"t"](`frechet_derivative ((\t. y + t % e) o drop) (at (lift t)) = (\x. drop x % e)`));; refine (by (VALID ((((USE_THM_THEN f_unary_drop)(new_rewrite [] [])) THEN ((USE_THM_THEN frechet_add)(new_rewrite [] []))))));; refine (by (VALID (((((USE_THM_THEN DIFFERENTIABLE_CONST)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN ((USE_THM_THEN HAS_DERIVATIVE_IMP_DIFFERENTIABLE) apply_tac)))));; refine (by (VALID (((exists_tac (`\x. drop x % e`)) THEN ((USE_THM_THEN HAS_DERIVATIVE_VMUL_DROP) apply_tac) THEN ((USE_THM_THEN HAS_DERIVATIVE_ID)(new_rewrite [] []))))));; refine (by (VALID (((((USE_THM_THEN frechet_vmul)(new_rewrite [] [])) THEN ((USE_THM_THEN frechet_const)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN VECTOR_ADD_LID)(new_rewrite [] []))) THEN (done_tac)))));; let frechet_direction = end_section_proof();; (start_section_proof ["f";"y";"e";"t"](`(lift o f) differentiable at (y + t % e) ==> ((f o (\t. y + t % e)) has_real_derivative (drop (frechet_derivative (lift o f) (at (y + t % e)) e))) (atreal t)`));; refine (by (VALID ((BETA_TAC THEN (move ["df"])))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN real_derivative_compose_frechet)(ISPEC_THEN (mk_var("f",mk_type("fun",[mk_type("cart",[mk_type("real",[]);mk_vartype "?1451778"]);mk_type("real",[])]))) thm_tac))(ISPEC_THEN (`\t. y + t % e`) thm_tac))(ISPEC_THEN (mk_var("t",mk_type("real",[]))) thm_tac))MP_TAC) THEN BETA_TAC))));; refine (by (VALID (((((USE_THEN "df")(new_rewrite [] [])) THEN ((USE_THM_THEN diff_direction)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN frechet_direction)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN LIFT_DROP)(new_rewrite [] [])) THEN ((USE_THM_THEN VECTOR_MUL_LID)(new_rewrite [] []))) THEN (done_tac)))));; let real_dir_derivative_frechet = end_section_proof();; (start_section_proof ["f";"y";"e";"t"](`(lift o f) differentiable at (y + t % e) ==> ((f o (\t. y + t % e)) has_real_derivative drop (jacobian (lift o f) (at (y + t % e)) ** e)) (atreal t)`));; refine (by (VALID ((BETA_TAC THEN (move ["df"])))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN real_dir_derivative_frechet)(ISPEC_THEN (mk_var("f",mk_type("fun",[mk_type("cart",[mk_type("real",[]);mk_vartype "?1451859"]);mk_type("real",[])]))) thm_tac))(ISPEC_THEN (mk_var("e",mk_type("cart",[mk_type("real",[]);mk_vartype "?1451859"]))) thm_tac))(fun fst_th ->(USE_THEN "df")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC))));; refine (by (VALID ((((USE_THM_THEN frechet_eq_jacobian)(new_rewrite [] [])) THEN (done_tac)))));; let real_dir_derivative_jacobian = end_section_proof();; (start_section_proof ["f";"y";"i"](`(lift o f) differentiable at (y:real^N) ==> partial i f y = drop (frechet_derivative (lift o f) (at y) (basis i))`));; refine (by (VALID (((BETA_TAC THEN (move ["df"])) THEN ((USE_THM_THEN partial)(new_rewrite [] []))))));; refine (by (VALID (((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN real_dir_derivative_frechet)(ISPEC_THEN (mk_var("f",mk_type("fun",[mk_type("cart",[mk_type("real",[]);mk_vartype "N"]);mk_type("real",[])]))) thm_tac))(ISPEC_THEN (mk_var("y",mk_type("cart",[mk_type("real",[]);mk_vartype "N"]))) thm_tac))(ISPEC_THEN (`basis i:real^N`) thm_tac))(ISPEC_THEN (`&0`) thm_tac))MP_TAC) THEN BETA_TAC) THEN (((USE_THM_THEN VECTOR_MUL_LZERO)(new_rewrite [] [])) THEN ((USE_THM_THEN VECTOR_ADD_RID)(new_rewrite [] [])))))));; refine (by (VALID (((BETA_TAC THEN ((fun thm_tac -> DISCH_THEN (fun fst_th ->(USE_THEN "df")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN (DISCH_THEN (fun snd_th -> (USE_THM_THEN derivative_unique)(MATCH_MP_THEN snd_th MP_TAC)))) THEN (done_tac)))));; let partial_eq_frechet = end_section_proof();; (start_section_proof ["f";"y";"i"](`(lift o f) differentiable at y ==> partial i f y = drop (jacobian (lift o f) (at y) ** basis i)`));; refine (by (VALID ((BETA_TAC THEN (move ["df"])))));; refine (by (VALID (((((USE_THEN "df")MP_TAC) THEN BETA_TAC) THEN ((((USE_THM_THEN partial_eq_frechet)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN JACOBIAN_WORKS)(new_rewrite [] []))) THEN (DISCH_THEN (fun snd_th -> (USE_THM_THEN FRECHET_DERIVATIVE_AT)(MATCH_MP_THEN snd_th MP_TAC))) THEN (DISCH_THEN(GSYM_THEN (new_rewrite [] [])))) THEN (done_tac)))));; let partial_eq_jacobian = end_section_proof();; (start_section_proof ["f";"y";"i"](`(lift o (f:real^N->real)) differentiable at y ==> i IN 1..dimindex (:N) ==> partial i f y = drop (column i (jacobian (lift o f) (at y)))`));; refine (by (VALID ((((USE_THM_THEN IN_NUMSEG)(new_rewrite [] [])) THEN (move ["df"]) THEN (move ["ineq"])))));; refine (by (VALID (((((USE_THM_THEN partial_eq_jacobian)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN MATRIX_VECTOR_MUL_BASIS)(new_rewrite [] []))) THEN (done_tac)))));; let partial_eq_jacobian_column = end_section_proof();; (start_section_proof ["f";"y";"i"](`(lift o (f:real^N->real)) differentiable at y ==> i IN 1..dimindex (:N) ==> partial i f y = (jacobian (lift o f) (at y))$1$i`));; refine (by (VALID (((BETA_TAC THEN (move ["df"]) THEN (move ["ineq"])) THEN (((USE_THM_THEN partial_eq_jacobian_column)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN column)(new_rewrite [] [])) THEN ((USE_THM_THEN DROP_LAMBDA)(new_rewrite [] []))) THEN (done_tac)))));; let partial_eq_jacobian_entry = end_section_proof();; (add_section_var (mk_var ("y", (`:real^N`))));; (add_section_var (mk_var ("i", (`:num`))));; (start_section_proof ["f"](`~(i IN 1..dimindex (:N)) ==> partial i f y = &0`));; refine (by (VALID (((BETA_TAC THEN (move ["ineq"])) THEN ((USE_THM_THEN partial)(new_rewrite [] []))))));; refine (by (VALID (((THENL_FIRST) (have_tac (DISCH_THEN(new_rewrite [] [])) (`basis i = (vec 0):real^N`)) (((USE_THM_THEN BASIS_EQ_0)(new_rewrite [] [])) THEN (done_tac))))));; refine (by (VALID ((((USE_THM_THEN VECTOR_MUL_RZERO)(fun th -> ONCE_REWRITE_TAC[th])) THEN ((USE_THM_THEN VECTOR_ADD_RID)(fun th -> ONCE_REWRITE_TAC[th]))))));; refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`derivative (f o (\t. y)) = derivative (\t. f y)`)))));; refine (by (VALID (((AP_TERM_TAC) THEN (((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((((USE_THM_THEN derivative_const)(new_rewrite [] [])) THEN (done_tac)))));; let partial_eq0 = end_section_proof();; (start_section_proof ["f";"g";"x"](`f real_differentiable atreal (g x) ==> g real_differentiable atreal x ==> derivative (f o g) x = derivative f (g x) * derivative g x`));; refine (by (VALID ((BETA_TAC THEN (move ["df"]) THEN (move ["dg"])))));; refine (by (VALID (((THENL_FIRST) (have_tac (DISCH_THEN(new_rewrite [] [])) (`f o g = \x. f (g x)`)) ((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (done_tac))))));; refine (by (VALID (((((USE_THM_THEN derivative_composition)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN REAL_MUL_SYM)(new_rewrite [] []))) THEN (done_tac)))));; let derivative_compose = end_section_proof();; (start_section_proof ["i";"net"](`i IN 1..dimindex (:N) ==> (lift o (\x:real^N. x$i) has_derivative lift o (\x. x$i)) net`));; refine (by (VALID ((((USE_THM_THEN IN_NUMSEG)(new_rewrite [] [])) THEN (move ["ineq"])))));; refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`lift o (\x:real^N. x$i) = (\x. x$i % vec 1)`)))));; refine (by (VALID ((((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN o_THM)(new_rewrite [] [])) THEN (simp_tac)) THEN (move ["x"])) THEN (((USE_THM_THEN DROP_EQ)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN LIFT_DROP)(new_rewrite [] [])) THEN ((USE_THM_THEN DROP_CMUL)(new_rewrite [] [])) THEN ((USE_THM_THEN DROP_VEC)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_RID)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((((USE_THM_THEN (GEN_ALL HAS_DERIVATIVE_VMUL_COMPONENT))(new_rewrite [] [])) THEN ((USE_THM_THEN HAS_DERIVATIVE_ID)(new_rewrite [] []))) THEN (done_tac)))));; let projection_has_derivative = end_section_proof();; (start_section_proof ["i";"net"](`i IN 1..dimindex (:N) ==> (lift o (\x:real^N. x$i)) differentiable net`));; refine (by (VALID ((((USE_THM_THEN differentiable)(new_rewrite [] [])) THEN (DISCH_THEN (fun snd_th -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN projection_has_derivative)(ISPEC_THEN (mk_var("i",mk_type("num",[]))) thm_tac))(ISPEC_THEN (mk_var("net",mk_type("net",[mk_type("cart",[mk_type("real",[]);mk_vartype "N"])]))) thm_tac))(MATCH_MP_THEN snd_th MP_TAC))) THEN (move ["h"])))));; refine (by (VALID (((exists_tac (`lift o \x:real^N. x$i`)) THEN (done_tac)))));; let projection_diff = end_section_proof();; (start_section_proof ["i";"x"](`i IN 1..dimindex (:N) ==> frechet_derivative (lift o (\x:real^N. x$i)) (at x) = lift o (\x:real^N. x$i)`));; refine (by (VALID (((BETA_TAC THEN (move ["ineq"])) THEN ((USE_THM_THEN EQ_SYM_EQ)(new_rewrite [] [])) THEN ((USE_THM_THEN FRECHET_DERIVATIVE_AT) apply_tac)))));; refine (by (VALID ((((USE_THM_THEN projection_has_derivative)(new_rewrite [] [])) THEN (done_tac)))));; let frechet_projection = end_section_proof();; (start_section_proof ["h";"t";"i"](`i IN 1..dimindex (:N) ==> (h o drop) differentiable at (lift t) ==> ((\s. (h:real->real^N) s$i) has_real_derivative (frechet_derivative (h o drop) (at (lift t)) (lift (&1)))$i) (atreal t)`));; refine (by (VALID ((BETA_TAC THEN (move ["ineq"]) THEN (move ["dh"])))));; refine (by (VALID (((THENL_FIRST) (have_tac (DISCH_THEN(new_rewrite [] [])) (`(\s. h s$i) = (\x. x$i) o h`)) ((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (done_tac))))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN real_derivative_compose_frechet)(ISPEC_THEN (`\x:real^N. x$i`) thm_tac))(ISPEC_THEN (mk_var("h",mk_type("fun",[mk_type("real",[]);mk_type("cart",[mk_type("real",[]);mk_vartype "N"])]))) thm_tac))(ISPEC_THEN (mk_var("t",mk_type("real",[]))) thm_tac))MP_TAC) THEN BETA_TAC))));; refine (by (VALID ((((USE_THEN "dh")(new_rewrite [] [])) THEN ((USE_THM_THEN projection_diff)(new_rewrite [] [])) THEN ((simp_tac THEN TRY done_tac))))));; refine (by (VALID ((set_tac "lhs" (`(drop o _ o lift) (&1)`)))));; refine (by (VALID ((set_tac "rhs" (`(frechet_derivative _1 _2 _3)$i`)))));; refine (by (VALID (((THENL_FIRST) (((THENL_ROT 1)) (have_tac (DISCH_THEN(new_rewrite [] [])) (`lhs = rhs`))) ((done_tac) THEN (done_tac))))));; refine (by (VALID (((((USE_THEN "lhs_def")(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN frechet_projection)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN o_THM)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THEN "rhs_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN LIFT_DROP)(new_rewrite [] []))) THEN (done_tac)))));; let has_derivative_vector_frechet = end_section_proof();; (start_section_proof ["h";"t";"i"](`i IN 1..dimindex (:N) ==> (h o drop) differentiable at (lift t) ==> ((\s. (h:real->real^N) s$i) has_real_derivative (jacobian (h o drop) (at (lift t)))$i$1) (atreal t)`));; refine (by (VALID ((BETA_TAC THEN (move ["ineq"]) THEN (move ["dh"])))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN has_derivative_vector_frechet)(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "dh")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC))));; refine (by (VALID ((set_tac "lhs" (`(frechet_derivative _1 _2 _3)$i`)))));; refine (by (VALID ((set_tac "rhs" (`jacobian _1 _2$i$1`)))));; refine (by (VALID (((THENL_FIRST) (((THENL_ROT 1)) (have_tac (DISCH_THEN(new_rewrite [] [])) (`lhs = rhs`))) ((done_tac) THEN (done_tac))))));; refine (by (VALID ((((USE_THEN "lhs_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN frechet_eq_jacobian)(new_rewrite [] [])) THEN ((simp_tac THEN TRY done_tac))))));; refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`lift (&1) = basis 1`)))));; refine (by (VALID (((((USE_THM_THEN DROP_EQ)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN LIFT_DROP)(new_rewrite [] [])) THEN ((USE_THM_THEN basis)(new_rewrite [] [])) THEN ((USE_THM_THEN DROP_LAMBDA)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((((USE_THM_THEN MATRIX_VECTOR_MUL_BASIS)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN DIMINDEX_GE_1)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN leqnn)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN column)(new_rewrite [] [])) THEN ((USE_THM_THEN (GEN_ALL LAMBDA_BETA))(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN IN_NUMSEG)(GSYM_THEN (new_rewrite [] []))))) THEN (done_tac)))));; let has_derivative_vector_jacobian = end_section_proof();; (start_section_proof ["h";"t";"i"](`i IN 1..dimindex (:N) ==> ((h:real->real^N) o drop) differentiable at (lift t) ==> derivative (\s. h s$i) t = jacobian (h o drop) (at (lift t))$i$1`));; refine (by (VALID (((BETA_TAC THEN (move ["ineq"]) THEN (move ["dh"])) THEN ((USE_THM_THEN derivative_unique) apply_tac) THEN ((USE_THM_THEN has_derivative_vector_jacobian)(new_rewrite [] [])) THEN (done_tac)))));; let derivative_vector_jacobian = end_section_proof();; (start_section_proof ["f";"h";"t"](`(lift o (f:real^N -> real)) differentiable at (h t) ==> (h o drop) differentiable at (lift t) ==> ((f o h) has_real_derivative sum (1..dimindex (:N)) (\i. partial i f (h t) * derivative (\s. h s$i) t)) (atreal t)`));; refine (by (VALID ((BETA_TAC THEN (move ["df"]) THEN (move ["dh"])))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN real_derivative_compose_jacobian)(fun fst_th ->(USE_THEN "df")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "dh")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC))));; refine (by (VALID (((set_tac "lhs" (`_$1$1`)) THEN (set_tac "rhs" (`sum _ _2`))))));; refine (by (VALID (((THENL_FIRST) (((THENL_ROT 1)) (have_tac (DISCH_THEN(new_rewrite [] [])) (`lhs = rhs`))) ((done_tac) THEN (done_tac))))));; refine (by (VALID (((USE_THEN "lhs_def")(GSYM_THEN (new_rewrite [] []))))));; refine (by (VALID ((((USE_THM_THEN matrix_mul)(new_rewrite [] [])) THEN ((USE_THM_THEN (GEN_ALL LAMBDA_BETA))(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN DIMINDEX_GE_1)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN leqnn)(new_rewrite [] []))) THEN ((simp_tac THEN TRY done_tac))))));; refine (by (VALID ((((USE_THM_THEN (GEN_ALL LAMBDA_BETA))(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN DIMINDEX_GE_1)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN leqnn)(new_rewrite [] []))) THEN ((simp_tac THEN TRY done_tac)) THEN ((USE_THEN "rhs_def")(GSYM_THEN (new_rewrite [] [])))))));; refine (by (VALID ((((USE_THM_THEN SUM_EQ) apply_tac) THEN (move ["i"]) THEN (move ["ineq"]) THEN (simp_tac)))));; refine (by (VALID (((((USE_THM_THEN partial_eq_jacobian_entry)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN REAL_EQ_MUL_LCANCEL)(new_rewrite [] [])) THEN ((USE_THM_THEN derivative_vector_jacobian)(new_rewrite [] []))) THEN (done_tac)))));; let real_derivative_compose_partial = end_section_proof();; (start_section_proof ["f";"e";"t"](`(lift o f) differentiable at (y + t % e) ==> ((f o (\t. y + t % e)) has_real_derivative sum (1..dimindex (:N)) (\i. e$i * (partial i f o (\t. y + t % e)) t)) (atreal t)`));; refine (by (VALID ((BETA_TAC THEN (move ["df"])))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN real_dir_derivative_jacobian)(ISPEC_THEN (mk_var("f",mk_type("fun",[mk_type("cart",[mk_type("real",[]);mk_vartype "N"]);mk_type("real",[])]))) thm_tac))(ISPEC_THEN (mk_var("y",mk_type("cart",[mk_type("real",[]);mk_vartype "N"]))) thm_tac))(ISPEC_THEN (mk_var("e",mk_type("cart",[mk_type("real",[]);mk_vartype "N"]))) thm_tac))(fun fst_th ->(USE_THEN "df")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC))));; refine (by (VALID ((((USE_THM_THEN matrix_vector_mul)(new_rewrite [] [])) THEN ((USE_THM_THEN DROP_LAMBDA)(new_rewrite [] []))))));; refine (by (VALID (((set_tac "lhs" (`sum _1 _2`)) THEN (set_tac "rhs" (`sum _1 _2`))))));; refine (by (VALID (((THENL_FIRST) (((THENL_ROT 1)) (have_tac (DISCH_THEN(new_rewrite [] [])) (`lhs = rhs`))) ((done_tac) THEN (done_tac))))));; refine (by (VALID (((((USE_THEN "lhs_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THEN "rhs_def")(GSYM_THEN (new_rewrite [] [])))) THEN (((USE_THM_THEN SUM_EQ) apply_tac) THEN (move ["i"]) THEN (move ["ineq"]) THEN (simp_tac))))));; refine (by (VALID (((((USE_THM_THEN o_THM)(new_rewrite [] [])) THEN ((USE_THM_THEN partial_eq_jacobian_entry)(new_rewrite [] [])) THEN ((simp_tac THEN TRY done_tac)) THEN ((USE_THM_THEN REAL_MUL_SYM)(new_rewrite [] []))) THEN (done_tac)))));; let real_dir_derivative_partial = end_section_proof();; (add_section_var (mk_var ("f", (`:real^N -> real`))); add_section_var (mk_var ("g", (`:real^N -> real`))));; (add_section_hyp "df" (`(lift o f) differentiable at y`));; (start_section_proof ["u"](`u real_differentiable atreal (f y) ==> partial i (u o f) y = derivative u (f y) * partial i f y`));; refine (by (VALID (((BETA_TAC THEN (move ["du"])) THEN (repeat_tactic 1 9 (((USE_THM_THEN partial)(new_rewrite [] []))) THEN ((USE_THM_THEN o_ASSOC)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN derivative_compose)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (simp_tac))))));; refine (by (VALID (((((USE_THM_THEN diff_imp_real_diff)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN VECTOR_MUL_LZERO)(new_rewrite [] [])) THEN ((USE_THM_THEN VECTOR_ADD_RID)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THEN "df")(new_rewrite [] [])) THEN ((USE_THM_THEN diff_direction)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((((USE_THM_THEN VECTOR_MUL_LZERO)(new_rewrite [] [])) THEN ((USE_THM_THEN VECTOR_ADD_RID)(new_rewrite [] []))) THEN (done_tac)))));; let partial_uni_compose = end_section_proof();; (start_section_proof [](`partial i (\x. --f x) y = --partial i f y`));; refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN partial_eq_frechet)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN f_lift_neg)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN DIFFERENTIABLE_NEG)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN repeat_tactic 0 10 (((USE_THM_THEN frechet_neg)(new_rewrite [] [])))) THEN (repeat_tactic 1 9 (((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th]))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN DROP_NEG)(fun th -> ONCE_REWRITE_TAC[th]))) THEN (done_tac)))));; let partial_neg = end_section_proof();; (start_section_proof ["c"](`partial i (\x. c * f x) y = c * partial i f y`));; refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN partial_eq_frechet)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN f_lift_scale)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN DIFFERENTIABLE_CMUL)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN repeat_tactic 0 10 (((USE_THM_THEN frechet_scale)(new_rewrite [] [])))) THEN (repeat_tactic 1 9 (((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th]))) THEN ((TRY done_tac)))))));; refine (by (VALID ((((USE_THM_THEN DROP_CMUL)(new_rewrite [] [])) THEN (done_tac)))));; let partial_scale = end_section_proof();; (add_section_hyp "dg" (`(lift o g) differentiable at y`));; (start_section_proof [](`partial i (\x. f x + g x) y = partial i f y + partial i g y`));; refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN partial_eq_frechet)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN f_lift_add)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN DIFFERENTIABLE_ADD)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN repeat_tactic 0 10 (((USE_THM_THEN frechet_add)(new_rewrite [] [])))) THEN (repeat_tactic 1 9 (((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th]))) THEN ((TRY done_tac)))))));; refine (by (VALID ((((USE_THM_THEN DROP_ADD)(new_rewrite [] [])) THEN (done_tac)))));; let partial_add = end_section_proof();; (start_section_proof [](`partial i (\x. f x - g x) y = partial i f y - partial i g y`));; refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN partial_eq_frechet)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN f_lift_sub)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN DIFFERENTIABLE_SUB)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN repeat_tactic 0 10 (((USE_THM_THEN frechet_sub)(new_rewrite [] [])))) THEN (repeat_tactic 1 9 (((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th]))) THEN ((TRY done_tac)))))));; refine (by (VALID ((((USE_THM_THEN DROP_SUB)(new_rewrite [] [])) THEN (done_tac)))));; let partial_sub = end_section_proof();; (start_section_proof [](`partial i (\x. f x * g x) y = partial i f y * g y + f y * partial i g y`));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN partial)(new_rewrite [] []))) THEN (set_tac "h" (`\t. y + t % basis i`))))));; refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`(\x. f x * g x) o h = (\t. (f o h) t * (g o h) t)`)))));; refine (by (VALID (((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] [])))) THEN (done_tac)))));; refine (by (VALID (((THENL_ROT (-1)) ((USE_THM_THEN derivative_mul)(new_rewrite [] []))))));; refine (by (VALID ((((USE_THEN "h_def")(GSYM_THEN (new_rewrite [1; 4] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN VECTOR_MUL_LZERO)(new_rewrite [] [])) THEN ((USE_THM_THEN VECTOR_ADD_RID)(new_rewrite [] [])) THEN ((fun thm_tac -> (USE_THM_THEN o_THM)(ISPEC_THEN (mk_var("f",mk_type("fun",[mk_type("cart",[mk_type("real",[]);mk_vartype "N"]);mk_type("real",[])]))) thm_tac))(GSYM_THEN (new_rewrite [] []))) THEN ((fun thm_tac -> (USE_THM_THEN o_THM)(ISPEC_THEN (mk_var("g",mk_type("fun",[mk_type("cart",[mk_type("real",[]);mk_vartype "N"]);mk_type("real",[])]))) thm_tac))(GSYM_THEN (new_rewrite [] [])))))));; refine (by (VALID ((((USE_THM_THEN REAL_ADD_SYM)(new_rewrite [] [])) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN (done_tac)))));; refine (by (VALID (((THENL_FIRST) (have_tac (move ["h0"]) (`h (&0) = y`)) ((((USE_THEN "h_def")(GSYM_THEN (new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN VECTOR_MUL_LZERO)(new_rewrite [] [])) THEN ((USE_THM_THEN VECTOR_ADD_RID)(new_rewrite [] []))) THEN (done_tac))))));; refine (by (VALID (((THENL_FIRST) (have_tac (move ["dh"]) (`(h o drop) differentiable at (lift (&0))`)) ((((USE_THEN "h_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN diff_direction)(new_rewrite [] []))) THEN (done_tac))))));; refine (by (VALID ((((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN (repeat_tactic 1 9 (((USE_THM_THEN diff_imp_real_diff)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "h0")(new_rewrite [] [])))) THEN (done_tac)))));; let partial_mul = end_section_proof();; let partial_mul = finalize_theorem partial_mul;; let partial_sub = finalize_theorem partial_sub;; let partial_add = finalize_theorem partial_add;; let partial_scale = finalize_theorem partial_scale;; let partial_neg = finalize_theorem partial_neg;; let partial_uni_compose = finalize_theorem partial_uni_compose;; let real_dir_derivative_partial = finalize_theorem real_dir_derivative_partial;; let real_derivative_compose_partial = finalize_theorem real_derivative_compose_partial;; let derivative_vector_jacobian = finalize_theorem derivative_vector_jacobian;; let has_derivative_vector_jacobian = finalize_theorem has_derivative_vector_jacobian;; let has_derivative_vector_frechet = finalize_theorem has_derivative_vector_frechet;; let frechet_projection = finalize_theorem frechet_projection;; let projection_diff = finalize_theorem projection_diff;; let projection_has_derivative = finalize_theorem projection_has_derivative;; let derivative_compose = finalize_theorem derivative_compose;; let partial_eq0 = finalize_theorem partial_eq0;; let partial_eq_jacobian_entry = finalize_theorem partial_eq_jacobian_entry;; let partial_eq_jacobian_column = finalize_theorem partial_eq_jacobian_column;; let partial_eq_jacobian = finalize_theorem partial_eq_jacobian;; let partial_eq_frechet = finalize_theorem partial_eq_frechet;; let real_dir_derivative_jacobian = finalize_theorem real_dir_derivative_jacobian;; let real_dir_derivative_frechet = finalize_theorem real_dir_derivative_frechet;; let frechet_direction = finalize_theorem frechet_direction;; let diff_direction = finalize_theorem diff_direction;; let diff_imp_real_diff = finalize_theorem diff_imp_real_diff;; let real_derivative_compose_jacobian = finalize_theorem real_derivative_compose_jacobian;; let real_derivative_compose_frechet = finalize_theorem real_derivative_compose_frechet;; (end_section "Partial");; (begin_section "PartialMonotone");; (start_section_proof ["f";"x"](`f real_differentiable atreal x ==> derivative f x = derivative (f o (\t. x + t)) (&0)`));; refine (by (VALID ((BETA_TAC THEN (move ["diff_f"])))));; refine (by (VALID ((((USE_THM_THEN derivative_compose)(new_rewrite [] [])) THEN (simp_tac) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_ADD_RID)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "diff_f")(new_rewrite [] [])))))));; refine (by (VALID (((((USE_THM_THEN REAL_DIFFERENTIABLE_ADD)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_DIFFERENTIABLE_CONST)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_DIFFERENTIABLE_ID)(new_rewrite [] [])))) THEN (done_tac)))));; refine (by (VALID ((((USE_THM_THEN derivative_add)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_DIFFERENTIABLE_CONST)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_DIFFERENTIABLE_ID)(new_rewrite [] []))) THEN ((TRY done_tac))))));; refine (by (VALID (((((USE_THM_THEN derivative_const)(new_rewrite [] [])) THEN ((USE_THM_THEN derivative_x)(new_rewrite [] [])) THEN (simp_tac)) THEN (arith_tac) THEN (done_tac)))));; let derivative_translation = end_section_proof();; (add_section_type (mk_var ("f", (`:real^N->real`))));; (start_section_proof ["f";"j";"u";"x";"z";"lo"](`(!i. i IN 1..dimindex (:N) ==> ~(i = j) ==> u$i = z$i) ==> u$j = x$j ==> (!y. y IN interval [x,z] ==> (lift o f) differentiable at y) ==> (!y. y IN interval [x,z] ==> &0 <= partial j f y) ==> (!y. y IN interval [x,u] ==> lo <= f y) ==> (!y. y IN interval [x,z] ==> lo <= f y)`));; refine (by (VALID (((((USE_THM_THEN IN_NUMSEG)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN (GEN_ALL IN_INTERVAL))(new_rewrite [] [])))) THEN (move ["uz_eq"]) THEN (move ["ux_eq"]) THEN (move ["diff_f"]) THEN (move ["partial_pos"]) THEN (move ["f_bound"]) THEN (move ["y"]) THEN (move ["y_in"])))));; refine (by (VALID (((((USE_THEN "partial_pos")MP_TAC) THEN (clear_assumption "partial_pos") THEN ((USE_THEN "diff_f")MP_TAC) THEN (clear_assumption "diff_f") THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN (GEN_ALL IN_INTERVAL))(GSYM_THEN (new_rewrite [] [])))) THEN (move ["diff_f"]) THEN (move ["partial_pos"]))))));; refine (by (VALID ((set_tac "y'" (`(lambda i. if i = j then x$j else y$i):real^N`)))));; refine (by (VALID ((((THENL_ROT 1)) (have_tac ALL_TAC (`f y' <= f y`))))));; refine (by (VALID (((((USE_THM_THEN (REWRITE_RULE[GSYM IMP_IMP] REAL_LE_TRANS))MP_TAC) THEN (DISCH_THEN apply_tac)) THEN (((USE_THEN "f_bound")MP_TAC) THEN (clear_assumption "f_bound") THEN (DISCH_THEN apply_tac) THEN (move ["i"]) THEN (move ["i_in"]))))));; refine (by (VALID ((((USE_THEN "y'_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN (GEN_ALL LAMBDA_BETA))(new_rewrite [] [])) THEN ((simp_tac THEN TRY done_tac))))));; refine (by (VALID (((THENL_FIRST) (((fun thm_tac -> (USE_THM_THEN EXCLUDED_MIDDLE)(ISPEC_THEN (`i = j`) thm_tac))MP_TAC) THEN case THEN (simp_tac) THEN (move ["ij"])) ((((USE_THEN "ux_eq")(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LE_REFL)(new_rewrite [] []))) THEN (done_tac))))));; refine (by (VALID (((((USE_THEN "uz_eq")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN repeat_tactic 1 9 (((USE_THEN "y_in")(new_rewrite [] [])))) THEN (done_tac)))));; refine (by (VALID ((((THENL_ROT (-1)) (((fun thm_tac -> (USE_THM_THEN EXCLUDED_MIDDLE)(ISPEC_THEN (`j IN 1..dimindex (:N)`) thm_tac))MP_TAC) THEN case)) THEN (((USE_THM_THEN IN_NUMSEG)(new_rewrite [] [])) THEN (move ["j_in"]))))));; refine (by (VALID (((THENL_FIRST) (((THENL_ROT 1)) (have_tac ALL_TAC (`y' = y`))) ((BETA_TAC THEN (DISCH_THEN(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_LE_REFL)(new_rewrite [] [])) THEN (done_tac))))));; refine (by (VALID ((((USE_THM_THEN CART_EQ)(new_rewrite [] [])) THEN (move ["i"]) THEN (move ["i_in"])))));; refine (by (VALID (((THENL_FIRST) (have_tac (move ["inj"]) (`~(i = j)`)) ((((USE_THEN "i_in")MP_TAC) THEN (clear_assumption "i_in") THEN ((USE_THEN "j_in")MP_TAC) THEN (clear_assumption "j_in") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac))))));; refine (by (VALID (((((USE_THEN "y'_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN (GEN_ALL LAMBDA_BETA))(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((set_tac "g" (`f o (\t. y' + t % basis j)`)))));; refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`f y' = g (&0)`)))));; refine (by (VALID (((((USE_THEN "g_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN o_THM)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN VECTOR_MUL_LZERO)(new_rewrite [] [])) THEN ((USE_THM_THEN VECTOR_ADD_RID)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`f y = g (y$j - x$j)`)))));; refine (by (VALID (((((USE_THEN "g_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN o_THM)(new_rewrite [] [])) THEN (simp_tac)) THEN (AP_TERM_TAC)))));; refine (by (VALID ((((USE_THM_THEN CART_EQ)(new_rewrite [] [])) THEN (move ["i"]) THEN (move ["i_in"])))));; refine (by (VALID ((((USE_THM_THEN VECTOR_ADD_COMPONENT)(new_rewrite [] [])) THEN ((USE_THM_THEN VECTOR_MUL_COMPONENT)(new_rewrite [] [])) THEN ((USE_THM_THEN BASIS_COMPONENT)(new_rewrite [] [])) THEN ((TRY done_tac))))));; refine (by (VALID (((((fun thm_tac -> (USE_THM_THEN EXCLUDED_MIDDLE)(ISPEC_THEN (`i = j`) thm_tac))MP_TAC) THEN case THEN (simp_tac) THEN (move ["ij"])) THEN (((USE_THEN "y'_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN (GEN_ALL LAMBDA_BETA))(new_rewrite [] [])) THEN ((TRY done_tac)))))));; refine (by (VALID (((arith_tac) THEN (done_tac)))));; refine (by (VALID ((((simp_tac) THEN ((USE_THEN "ij")(new_rewrite [] [])) THEN (simp_tac)) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((set_tac "s" (`real_interval [&0, y$j - x$j]`)))));; refine (by (VALID ((have_tac (move ["in_s"]) (`!t. t IN s ==> y' + t % basis j IN interval [x,z]`)))));; refine (by (VALID (((((USE_THEN "s_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN (GEN_ALL IN_INTERVAL))(new_rewrite [] []))) THEN (move ["t"]) THEN (move ["t_ineq"]) THEN (move ["i"]) THEN (move ["i_ineq"])))));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN VECTOR_ADD_COMPONENT)(new_rewrite [] []))) THEN ((USE_THM_THEN VECTOR_MUL_COMPONENT)(new_rewrite [] [])) THEN ((USE_THM_THEN BASIS_COMPONENT)(new_rewrite [] [])) THEN ((TRY done_tac))))));; refine (by (VALID ((((USE_THEN "y'_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN (GEN_ALL LAMBDA_BETA))(new_rewrite [] [])) THEN ((simp_tac THEN TRY done_tac))))));; refine (by (VALID (((THENL_ROT (-1)) (((fun thm_tac -> (USE_THM_THEN EXCLUDED_MIDDLE)(ISPEC_THEN (`i = j`) thm_tac))MP_TAC) THEN case THEN (simp_tac) THEN (move ["ij"]))))));; refine (by (VALID (((((USE_THM_THEN REAL_MUL_RZERO)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_ADD_RID)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THEN "y_in")(new_rewrite [] [])))) THEN (done_tac)))));; refine (by (VALID (((((USE_THEN "t_ineq")MP_TAC) THEN (clear_assumption "t_ineq") THEN ((fun thm_tac -> (USE_THEN "y_in")(fun fst_th ->(USE_THEN "i_ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC) THEN ((USE_THEN "ij")(new_rewrite [] [])) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((have_tac (move ["ds"]) (`!t. t IN s ==> (g has_real_derivative (partial j f (y' + t % basis j))) (atreal t within s)`)))));; refine (by (VALID (((BETA_TAC THEN (move ["t"]) THEN (DISCH_THEN (fun snd_th -> (USE_THEN "in_s")(MATCH_MP_THEN snd_th MP_TAC))) THEN (move ["p_in"])) THEN (((USE_THM_THEN HAS_REAL_DERIVATIVE_ATREAL_WITHIN)MP_TAC) THEN (clear_assumption "HAS_REAL_DERIVATIVE_ATREAL_WITHIN") THEN (DISCH_THEN apply_tac)) THEN ((USE_THM_THEN partial)(new_rewrite [] []))))));; refine (by (VALID ((set_tac "h" (`f o _`)))));; refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`h = g o (\t'. t + t')`)))));; refine (by (VALID ((((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THEN "h_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THEN "g_def")(GSYM_THEN (new_rewrite [] [])))) THEN (move ["r"])) THEN (repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (simp_tac))))));; refine (by (VALID (((((USE_THM_THEN (GEN_ALL VECTOR_ADD_RDISTRIB))(new_rewrite [] [])) THEN ((USE_THM_THEN (GEN_ALL VECTOR_ADD_ASSOC))(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((((USE_THM_THEN derivative_translation)(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN has_derivative_alt)(new_rewrite [] []))) THEN ((USE_THEN "g_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN diff_imp_real_diff)(new_rewrite [] []))) THEN (((USE_THEN "diff_f")(new_rewrite [] [])) THEN ((simp_tac THEN TRY done_tac)) THEN ((USE_THM_THEN diff_direction)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((THENL_FIRST) (have_tac (move ["pos"]) (`&0 <= y$j - x$j`)) ((((fun thm_tac -> (USE_THEN "y_in")(fun fst_th ->(USE_THEN "j_in")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC) THEN (arith_tac) THEN (done_tac))))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN HAS_REAL_DERIVATIVE_INCREASING_IMP)(ISPEC_THEN (mk_var("g",mk_type("fun",[mk_type("real",[]);mk_type("real",[])]))) thm_tac))(ISPEC_THEN (`\t. partial j f (y' + t % basis j)`) thm_tac))(ISPEC_THEN (mk_var("s",mk_type("fun",[mk_type("real",[]);mk_type("bool",[])]))) thm_tac))(ISPEC_THEN (`&0`) thm_tac))(ISPEC_THEN (`y$j - x$j`) thm_tac)) MP_TAC) THEN ALL_TAC))));; refine (by (VALID (((((USE_THEN "s_def")(GSYM_THEN (new_rewrite [1] []))) THEN ((USE_THM_THEN IS_REALINTERVAL_INTERVAL)(new_rewrite [] [])) THEN (simp_tac)) THEN (((USE_THEN "ds")(fun th -> ONCE_REWRITE_TAC[th])) THEN (simp_tac)) THEN (DISCH_THEN apply_tac)))));; refine (by (VALID ((((USE_THEN "s_def")(GSYM_THEN (new_rewrite [2; 3] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] []))) THEN ((USE_THEN "pos")(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_LE_REFL)(new_rewrite [] []))) THEN (simp_tac)))));; refine (by (VALID (((BETA_TAC THEN (move ["t"]) THEN (DISCH_THEN (fun snd_th -> (USE_THEN "in_s")(MATCH_MP_THEN snd_th MP_TAC))) THEN (DISCH_THEN (fun snd_th -> (USE_THEN "partial_pos")(MATCH_MP_THEN snd_th MP_TAC)))) THEN (done_tac)))));; let partial_increasing_left = end_section_proof();; (start_section_proof ["f";"j";"u";"x";"z";"hi"](`(!i. i IN 1..dimindex (:N) ==> ~(i = j) ==> u$i = z$i) ==> u$j = x$j ==> (!y. y IN interval [x,z] ==> (lift o f) differentiable at y) ==> (!y. y IN interval [x,z] ==> partial j f y <= &0) ==> (!y. y IN interval [x,u] ==> f y <= hi) ==> (!y. y IN interval [x,z] ==> f y <= hi)`));; refine (by (VALID ((BETA_TAC THEN (move ["u_eq_i"]) THEN (move ["u_eq_j"]) THEN (move ["diff_f"]) THEN (move ["partial_f"]) THEN (move ["f_bound"]) THEN (move ["y"]) THEN (move ["y_in"])))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN partial_increasing_left)(ISPEC_THEN (`(\p. -- f p)`) thm_tac))(ISPEC_THEN (mk_var("j",mk_type("num",[]))) thm_tac))(ISPEC_THEN (mk_var("u",mk_type("cart",[mk_type("real",[]);mk_vartype "N"]))) thm_tac))(ISPEC_THEN (mk_var("x",mk_type("cart",[mk_type("real",[]);mk_vartype "N"]))) thm_tac))(ISPEC_THEN (mk_var("z",mk_type("cart",[mk_type("real",[]);mk_vartype "N"]))) thm_tac))(ISPEC_THEN (`--hi`) thm_tac))(fun fst_th ->(USE_THEN "u_eq_i")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "u_eq_j")(fun th -> MATCH_MP_THEN th thm_tac fst_th))) MP_TAC) THEN ALL_TAC))));; refine (by (VALID (((THENL_FIRST) (ANTS_TAC) ((BETA_TAC THEN (move ["p"]) THEN (DISCH_THEN (fun snd_th -> (USE_THEN "diff_f")(MATCH_MP_THEN snd_th MP_TAC))) THEN (DISCH_THEN (fun snd_th -> (USE_THM_THEN DIFFERENTIABLE_NEG)(MATCH_MP_THEN snd_th MP_TAC)))) THEN ((USE_THM_THEN f_lift_neg)(new_rewrite [] [])) THEN (done_tac))))));; refine (by (VALID ((ANTS_TAC))));; refine (by (VALID (((BETA_TAC THEN (move ["p"]) THEN (move ["p_in"])) THEN (((USE_THM_THEN partial_neg)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "diff_f")(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN REAL_NEG_GE0)(new_rewrite [] [])) THEN ((USE_THEN "partial_f")(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((THENL_FIRST) (ANTS_TAC) ((BETA_TAC THEN (move ["p"]) THEN (DISCH_THEN (fun snd_th -> (USE_THEN "f_bound")(MATCH_MP_THEN snd_th MP_TAC)))) THEN (arith_tac) THEN (done_tac))))));; refine (by (VALID (((((fun thm_tac -> DISCH_THEN (fun fst_th ->(USE_THEN "y_in")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; let partial_decreasing_left = end_section_proof();; (start_section_proof ["f";"i";"p";"y"](`lift o f differentiable at (p + y) ==> partial i (f o (\x. p + x)) y = partial i f (p + y)`));; refine (by (VALID ((BETA_TAC THEN (move ["diff"])))));; refine (by (VALID ((have_tac (move ["diff_p"]) (`!net. (\x. p + x) differentiable net`)))));; refine (by (VALID (((BETA_TAC THEN (move ["net"])) THEN (((USE_THM_THEN DIFFERENTIABLE_ADD)(new_rewrite [] [])) THEN ((USE_THM_THEN DIFFERENTIABLE_CONST)(new_rewrite [] [])) THEN ((USE_THM_THEN DIFFERENTIABLE_ID)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((((USE_THM_THEN partial_eq_frechet)(new_rewrite [] [])) THEN repeat_tactic 0 1 (((USE_THM_THEN o_ASSOC)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN DIFFERENTIABLE_CHAIN_AT)(new_rewrite [] []))) THEN ((TRY done_tac))))));; refine (by (VALID ((((USE_THM_THEN frechet_compose)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN frechet_add)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN DIFFERENTIABLE_ID)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN DIFFERENTIABLE_CONST)(new_rewrite [] []))) THEN ((TRY done_tac))))));; refine (by (VALID ((((USE_THM_THEN frechet_const)(new_rewrite [] [])) THEN ((USE_THM_THEN frechet_id)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN VECTOR_ADD_LID)(new_rewrite [] [])) THEN ((USE_THM_THEN I_DEF)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN I_O_ID)(new_rewrite [] []))))));; refine (by (VALID ((((USE_THM_THEN partial_eq_frechet)(new_rewrite [] [])) THEN (done_tac)))));; let partial_translation = end_section_proof();; (start_section_proof ["f";"i";"p";"y"](`lift o f differentiable at (p - y) ==> partial i (f o (\x. p - x)) y = --partial i f (p - y)`));; refine (by (VALID ((BETA_TAC THEN (move ["diff"])))));; refine (by (VALID ((have_tac (move ["diff_p"]) (`!net. (\x. p - x) differentiable net`)))));; refine (by (VALID (((BETA_TAC THEN (move ["net"])) THEN (((USE_THM_THEN DIFFERENTIABLE_SUB)(new_rewrite [] [])) THEN ((USE_THM_THEN DIFFERENTIABLE_CONST)(new_rewrite [] [])) THEN ((USE_THM_THEN DIFFERENTIABLE_ID)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((((USE_THM_THEN partial_eq_frechet)(new_rewrite [] [])) THEN repeat_tactic 0 1 (((USE_THM_THEN o_ASSOC)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN DIFFERENTIABLE_CHAIN_AT)(new_rewrite [] []))) THEN ((TRY done_tac))))));; refine (by (VALID ((((USE_THM_THEN frechet_compose)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN frechet_sub)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN DIFFERENTIABLE_ID)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN DIFFERENTIABLE_CONST)(new_rewrite [] []))) THEN ((TRY done_tac))))));; refine (by (VALID ((((USE_THM_THEN frechet_const)(new_rewrite [] [])) THEN ((USE_THM_THEN frechet_id)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN (GEN_ALL VECTOR_SUB_LZERO))(new_rewrite [] []))))));; refine (by (VALID ((((USE_THM_THEN partial_eq_frechet)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (simp_tac)))));; refine (by (VALID (((((USE_THM_THEN LINEAR_NEG)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN LINEAR_FRECHET_DERIVATIVE)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN DROP_NEG)(new_rewrite [] []))) THEN (done_tac)))));; let partial_rev_translation = end_section_proof();; (start_section_proof ["f";"j";"u";"x";"z";"hi"](`(!i. i IN 1..dimindex (:N) ==> ~(i = j) ==> u$i = x$i) ==> u$j = z$j ==> (!y. y IN interval [x,z] ==> (lift o f) differentiable at y) ==> (!y. y IN interval [x,z] ==> &0 <= partial j f y) ==> (!y. y IN interval [u,z] ==> f y <= hi) ==> (!y. y IN interval [x,z] ==> f y <= hi)`));; refine (by (VALID ((BETA_TAC THEN (move ["u_eq_i"]) THEN (move ["u_eq_j"]) THEN (move ["diff_f"]) THEN (move ["partial_f"]) THEN (move ["f_bound"]) THEN (move ["y"]) THEN (move ["y_in"])))));; refine (by (VALID ((((THENL_ROT (-1)) (((fun thm_tac -> (USE_THM_THEN EXCLUDED_MIDDLE)(ISPEC_THEN (`j IN 1..dimindex (:N)`) thm_tac))MP_TAC) THEN case)) THEN (((USE_THM_THEN IN_NUMSEG)(new_rewrite [] [])) THEN (move ["j_in"]))))));; refine (by (VALID (((((USE_THEN "f_bound")MP_TAC) THEN (clear_assumption "f_bound") THEN (DISCH_THEN apply_tac)) THEN (((USE_THEN "y_in")MP_TAC) THEN (clear_assumption "y_in") THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN (GEN_ALL IN_INTERVAL))(new_rewrite [] []))) THEN (move ["y_ineq"]) THEN (move ["i"]) THEN (move ["i_in"]))))));; refine (by (VALID (((THENL_FIRST) (have_tac (move ["inj"]) (`~(i = j)`)) ((((USE_THEN "i_in")MP_TAC) THEN (clear_assumption "i_in") THEN ((USE_THEN "j_in")MP_TAC) THEN (clear_assumption "j_in") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac))))));; refine (by (VALID (((((USE_THEN "u_eq_i")(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN IN_NUMSEG)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN repeat_tactic 1 9 (((USE_THEN "y_ineq")(new_rewrite [] [])))) THEN (done_tac)))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN partial_decreasing_left)(ISPEC_THEN (`f o (\p:real^N. x + (z - p))`) thm_tac))(ISPEC_THEN (mk_var("j",mk_type("num",[]))) thm_tac))(ISPEC_THEN (`x + (z - u):real^N`) thm_tac))(ISPEC_THEN (mk_var("x",mk_type("cart",[mk_type("real",[]);mk_vartype "N"]))) thm_tac))(ISPEC_THEN (mk_var("z",mk_type("cart",[mk_type("real",[]);mk_vartype "N"]))) thm_tac))(ISPEC_THEN (mk_var("hi",mk_type("real",[]))) thm_tac)) MP_TAC) THEN ALL_TAC))));; refine (by (VALID ((ANTS_TAC))));; refine (by (VALID (((BETA_TAC THEN (move ["i"]) THEN (DISCH_THEN (fun snd_th -> (USE_THEN "u_eq_i")(MATCH_MP_THEN snd_th MP_TAC))) THEN (move ["eq1"]) THEN (move ["inj"])) THEN (((USE_THM_THEN VECTOR_ADD_COMPONENT)(new_rewrite [] [])) THEN ((USE_THM_THEN VECTOR_SUB_COMPONENT)(new_rewrite [] [])))))));; refine (by (VALID (((((USE_THEN "eq1")(new_rewrite [] [])) THEN ((TRY done_tac))) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID (((THENL_FIRST) (ANTS_TAC) ((((USE_THM_THEN VECTOR_ADD_COMPONENT)(new_rewrite [] [])) THEN ((USE_THM_THEN VECTOR_SUB_COMPONENT)(new_rewrite [] [])) THEN ((USE_THEN "u_eq_j")(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac))))));; refine (by (VALID ((have_tac (move ["Hp"]) (`!p. p IN interval [x,z] ==> x + (z - p) IN interval [x,z]`)))));; refine (by (VALID (((BETA_TAC THEN (move ["p"])) THEN (repeat_tactic 1 9 (((USE_THM_THEN (GEN_ALL IN_INTERVAL))(new_rewrite [] []))) THEN (move ["p_in"]) THEN (move ["i"]) THEN (move ["ineq"]))))));; refine (by (VALID (((((fun thm_tac -> (USE_THEN "p_in")(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC) THEN (((USE_THM_THEN VECTOR_ADD_COMPONENT)(new_rewrite [] [])) THEN ((USE_THM_THEN VECTOR_SUB_COMPONENT)(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((set_tac "dP" (`!y. _ y`)))));; refine (by (VALID ((have_tac (move ["P"]) (mk_var("dP",mk_type("bool",[])))))));; refine (by (VALID ((((USE_THEN "dP_def")(GSYM_THEN (new_rewrite [] []))) THEN (BETA_TAC THEN (move ["p"]) THEN (move ["p_in"]))))));; refine (by (VALID (((((USE_THM_THEN o_ASSOC)(new_rewrite [] [])) THEN ((USE_THM_THEN DIFFERENTIABLE_CHAIN_AT)(new_rewrite [] [])) THEN ((USE_THM_THEN DIFFERENTIABLE_ADD)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN DIFFERENTIABLE_SUB)(new_rewrite [] [])))) THEN (repeat_tactic 0 10 (((USE_THM_THEN DIFFERENTIABLE_ID)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN DIFFERENTIABLE_CONST)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THEN "diff_f")(new_rewrite [] [])) THEN ((simp_tac THEN TRY done_tac)) THEN ((USE_THEN "Hp")(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((((USE_THEN "P")MP_TAC) THEN (clear_assumption "P") THEN BETA_TAC THEN (simp_tac)) THEN (((USE_THEN "dP_def")(GSYM_THEN (new_rewrite [] []))) THEN (move ["diff"]))))));; refine (by (VALID ((ANTS_TAC))));; refine (by (VALID ((BETA_TAC THEN (move ["p"]) THEN (move ["p_in"])))));; refine (by (VALID ((((USE_THM_THEN (VECTOR_ARITH `!x z p. x + z - p = (x + z) - p:real^N`)) MP_TAC) THEN (move ["assoc"])))));; refine (by (VALID ((((USE_THEN "assoc")(new_rewrite [] [])) THEN ((USE_THM_THEN partial_rev_translation)(new_rewrite [] [])) THEN ((USE_THEN "assoc")(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "diff_f")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "Hp")(new_rewrite [] []))) THEN ((TRY done_tac))))));; refine (by (VALID (((((USE_THM_THEN REAL_NEG_LE0)(new_rewrite [] [])) THEN ((USE_THEN "partial_f")(new_rewrite [] [])) THEN ((USE_THEN "Hp")(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((ANTS_TAC))));; refine (by (VALID (((BETA_TAC THEN (move ["p"]) THEN (move ["p_in"])) THEN (((USE_THM_THEN o_THM)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THEN "f_bound")(new_rewrite [] [])))))));; refine (by (VALID (((((USE_THEN "p_in")MP_TAC) THEN (clear_assumption "p_in") THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN (GEN_ALL IN_INTERVAL))(new_rewrite [] []))) THEN (move ["ineq"]) THEN (move ["i"]) THEN (move ["i_ineq"]))))));; refine (by (VALID (((((fun thm_tac -> (USE_THEN "ineq")(fun fst_th ->(USE_THEN "i_ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN VECTOR_ADD_COMPONENT)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN VECTOR_SUB_COMPONENT)(new_rewrite [] [])))) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID (((((fun thm_tac -> DISCH_THEN (ISPEC_THEN (`x + z - y:real^N`) thm_tac))MP_TAC) THEN BETA_TAC) THEN (((USE_THM_THEN o_THM)(new_rewrite [] [])) THEN (simp_tac))))));; refine (by (VALID ((((USE_THM_THEN (VECTOR_ARITH `!x z y:real^N. x + z - (x + z - y) = y`))(new_rewrite [] [])) THEN (DISCH_THEN apply_tac)))));; refine (by (VALID ((((USE_THEN "Hp")(new_rewrite [] [])) THEN (done_tac)))));; let partial_increasing_right = end_section_proof();; let partial_increasing_right = finalize_theorem partial_increasing_right;; let partial_rev_translation = finalize_theorem partial_rev_translation;; let partial_translation = finalize_theorem partial_translation;; let partial_decreasing_left = finalize_theorem partial_decreasing_left;; let partial_increasing_left = finalize_theorem partial_increasing_left;; let derivative_translation = finalize_theorem derivative_translation;; (end_section "PartialMonotone");; (begin_section "Taylor");; (start_section_proof ["f";"dd_bound"](`nth_diff_strong_int 2 (&0, &1) f ==> (!t. interval_arith t (&0, &1) ==> abs (nth_derivative 2 f t) <= dd_bound) ==> abs (f (&1) - (f (&0) + derivative f (&0))) <= dd_bound / &2`));; refine (by (VALID (((((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] [])) THEN ((USE_THM_THEN nth_diff_strong2_eq_alt)(new_rewrite [] []))) THEN (move ["df"]) THEN (move ["dd"])))));; refine (by (VALID ((set_tac "R" (`\i. if i = 0 then f else if i = 1 then derivative f else nth_derivative 2 f`)))));; refine (by (VALID ((((USE_THM_THEN (ARITH_RULE `0 + 1 = 1 /\ ~(1 = 0) /\ 1 + 1 = 2 /\ ~(2 = 1) /\ ~(2 = 0)`)) MP_TAC) THEN (move ["arithH"])))));; refine (by (VALID (((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN REAL_TAYLOR)(ISPEC_THEN (mk_var("R",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 [&0, &1]`) thm_tac))(ISPEC_THEN (mk_var("dd_bound",mk_type("real",[]))) thm_tac))MP_TAC) THEN BETA_TAC) THEN (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 ["x"])) THEN (((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN interval_arith)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN (ARITH_RULE `i <= 1 <=> i = 0 \/ i = 1`))(new_rewrite [] [])))))));; refine (by (VALID ((BETA_TAC THEN (case THEN ALL_TAC) THEN (DISCH_THEN (fun snd_th -> (USE_THEN "df")(MATCH_MP_THEN snd_th MP_TAC))) THEN (case THEN (move ["s"])) THEN (move ["d_f"])))));; refine (by (VALID (((case THEN (DISCH_THEN(new_rewrite [] []))) THEN (((USE_THEN "R_def")(GSYM_THEN (new_rewrite [] []))) THEN (simp_tac) THEN repeat_tactic 1 9 (((USE_THEN "arithH")(new_rewrite [] []))) THEN (simp_tac)) THEN ((USE_THM_THEN HAS_REAL_DERIVATIVE_ATREAL_WITHIN) apply_tac) THEN ((USE_THEN "d_f")(new_rewrite [] [])) THEN (done_tac)))));; refine (by (VALID (((BETA_TAC THEN (move ["x"])) THEN ((((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN interval_arith)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THEN "arithH")(new_rewrite [] []))) 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 ["s"])) THEN (move ["d_f"])) THEN (((USE_THEN "R_def")(GSYM_THEN (new_rewrite [] []))) THEN (simp_tac) THEN repeat_tactic 1 9 (((USE_THEN "arithH")(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THEN "dd")(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((((fun thm_tac -> (fun thm_tac -> DISCH_THEN (ISPEC_THEN (`&0`) thm_tac))(ISPEC_THEN (`&1`) thm_tac))MP_TAC) THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_LE_REFL)(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_LE_01)(new_rewrite [] [])) THEN (simp_tac))))));; refine (by (VALID ((((USE_THM_THEN REAL_SUB_RZERO)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_ABS_1)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_POW_ONE)(new_rewrite [] []))) THEN ((USE_THM_THEN (ARITH_RULE `FACT (1 + 1) = 2`))(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN real_div)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_MUL_LID)(new_rewrite [] [])))))));; refine (by (VALID ((((USE_THM_THEN ONE)(new_rewrite [2] [])) THEN ((USE_THM_THEN (GEN_ALL SUM_CLAUSES_NUMSEG))(new_rewrite [] [])) THEN ((USE_THM_THEN SUM_SING_NUMSEG)(new_rewrite [] [])) THEN ((USE_THM_THEN ONE)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN (ARITH_RULE `0 <= 1`))(new_rewrite [] [])) THEN (simp_tac)))));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN (ARITH_RULE `FACT 0 = 1 /\ FACT 1 = 1`))(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_INV_1)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_MUL_RID)(new_rewrite [] [])))))));; refine (by (VALID (((((USE_THEN "R_def")(GSYM_THEN (new_rewrite [] []))) THEN (simp_tac) THEN repeat_tactic 1 9 (((USE_THEN "arithH")(new_rewrite [] [])))) THEN (done_tac)))));; let real_taylor2_bound = end_section_proof();; (start_section_proof ["f";"d_bound"](`(!t. interval_arith t (&0, &1) ==> f real_differentiable atreal t /\ abs (derivative f t) <= d_bound) ==> abs (f (&1) - f (&0)) <= d_bound`));; refine (by (VALID ((BETA_TAC THEN (move ["df"])))));; refine (by (VALID ((set_tac "R" (`\i. if i = 0 then f else derivative f`)))));; refine (by (VALID ((((USE_THM_THEN (ARITH_RULE `0 + 1 = 1 /\ ~(1 = 0)`)) MP_TAC) THEN (move ["arithH"])))));; refine (by (VALID (((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN REAL_TAYLOR)(ISPEC_THEN (mk_var("R",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 [&0, &1]`) thm_tac))(ISPEC_THEN (mk_var("d_bound",mk_type("real",[]))) thm_tac))MP_TAC) THEN BETA_TAC) THEN (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 ["x"])) THEN (((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN interval_arith)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN leqn0)(new_rewrite [] [])))))));; refine (by (VALID ((BETA_TAC THEN (case THEN ALL_TAC) THEN (DISCH_THEN (fun snd_th -> (USE_THEN "df")(MATCH_MP_THEN snd_th MP_TAC))) THEN (case THEN ((move ["diff_f"]) THEN (move ["df_bound"]))) THEN (DISCH_THEN(new_rewrite [] []))))));; refine (by (VALID (((((USE_THEN "R_def")(GSYM_THEN (new_rewrite [] []))) THEN (simp_tac) THEN repeat_tactic 1 9 (((USE_THEN "arithH")(new_rewrite [] []))) THEN (simp_tac)) THEN ((USE_THM_THEN HAS_REAL_DERIVATIVE_ATREAL_WITHIN) apply_tac) THEN ((USE_THM_THEN has_derivative_alt)(new_rewrite [] [])) THEN (done_tac)))));; refine (by (VALID (((BETA_TAC THEN (move ["x"])) THEN ((((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN interval_arith)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THEN "arithH")(new_rewrite [] []))) 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 ["s"])) THEN (move ["d_f"])) THEN (((USE_THEN "R_def")(GSYM_THEN (new_rewrite [] []))) THEN (simp_tac) THEN repeat_tactic 1 9 (((USE_THEN "arithH")(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THEN "df")(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((((fun thm_tac -> (fun thm_tac -> DISCH_THEN (ISPEC_THEN (`&0`) thm_tac))(ISPEC_THEN (`&1`) thm_tac))MP_TAC) THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_LE_REFL)(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_LE_01)(new_rewrite [] [])) THEN (simp_tac))))));; refine (by (VALID ((((USE_THM_THEN SUM_SING_NUMSEG)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN REAL_SUB_RZERO)(new_rewrite [] [])) THEN ((USE_THEN "arithH")(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_ABS_1)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_POW_ONE)(new_rewrite [] [])))))));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN (ARITH_RULE `FACT 1 = 1 /\ FACT 0 = 1`))(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_DIV_1)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_MUL_RID)(new_rewrite [] [])))))));; refine (by (VALID (((((USE_THEN "R_def")(GSYM_THEN (new_rewrite [] []))) THEN (simp_tac) THEN repeat_tactic 1 9 (((USE_THEN "arithH")(new_rewrite [] [])))) THEN (done_tac)))));; let real_taylor1_bound = end_section_proof();; let m_taylor_error = new_definition `m_taylor_error f domain (w:real^N) error <=> !x:real^N. x IN interval [domain] ==> sum (1..dimindex (:N)) (\i. w$i * sum (1..dimindex (:N)) (\j. w$j * abs (partial j (partial i f) x))) <= error`;; let m_taylor_partial_error = new_definition `m_taylor_partial_error f i domain (w:real^N) error <=> (!x:real^N. x IN interval[domain] ==> sum (1..dimindex (:N)) (\j. w$j * abs (partial j (partial i f) x)) <= error)`;; (start_section_proof ["f";"domain";"w";"p_error";"error"](`(!i. i IN 1..dimindex (:N) ==> m_taylor_partial_error f i domain w (p_error i) /\ &0 <= w$i) ==> sum (1..dimindex (:N)) (\i. w$i * p_error i) <= error ==> m_taylor_error f domain (w:real^N) error`));; refine (by (VALID (((((USE_THM_THEN m_taylor_partial_error)(new_rewrite [] [])) THEN ((USE_THM_THEN m_taylor_error)(new_rewrite [] []))) THEN (move ["partialH"]) THEN (move ["ineq"]) THEN (move ["p"]) THEN (move ["p_in"])))));; refine (by (VALID ((((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN ((USE_THM_THEN (REWRITE_RULE[GSYM IMP_IMP] REAL_LE_TRANS))MP_TAC) THEN (DISCH_THEN apply_tac)))));; refine (by (VALID ((((USE_THM_THEN SUM_LE) apply_tac) THEN ((((USE_THM_THEN FINITE_NUMSEG)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (move ["i"]) THEN (move ["i_ineq"]) THEN (simp_tac))))));; refine (by (VALID (((((USE_THM_THEN REAL_LE_LMUL)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((fun thm_tac -> (USE_THEN "partialH")(fun fst_th ->(USE_THEN "i_ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] [])))) THEN (done_tac)))));; let taylor_error_eq_sum_partial_errors = end_section_proof();; let partial2 = new_definition `partial2 j i f = partial j (partial i f)`;; let diff2 = new_definition `diff2 f x <=> ?s. open s /\ x IN s /\ (!y. y IN s ==> (lift o f) differentiable at y /\ (!i. (lift o partial i f) differentiable at y))`;; let diff2c = new_definition `diff2c f x <=> diff2 f x /\ (!i j. (lift o partial2 j i f) continuous at x)`;; (start_section_proof ["f";"x"](`diff2c f x ==> diff2 f x`));; refine (by (VALID (((((USE_THM_THEN diff2c)(new_rewrite [] [])) THEN (simp_tac)) THEN (done_tac)))));; let diff2c_imp_diff2 = end_section_proof();; (start_section_proof ["f";"x"](`diff2 f x <=> ?s. open s /\ x IN s /\ (!y. y IN s ==> diff2 f y)`));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN diff2)(new_rewrite [] []))) THEN ((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("cart",[mk_type("real",[]);mk_vartype "?1454959"]);mk_type("bool",[])])))) THEN ((((USE_THEN "open_s")(new_rewrite [1] [])) THEN ((USE_THEN "xs")(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] [])))) THEN (move ["y"]) THEN (move ["ys"])) THEN (exists_tac (mk_var("s",mk_type("fun",[mk_type("cart",[mk_type("real",[]);mk_vartype "?1454959"]);mk_type("bool",[])])))) THEN (done_tac)))));; refine (by (VALID (((((fun thm_tac -> (USE_THEN "df")(fun fst_th ->(USE_THEN "xs")(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 ["df2"])) THEN (((USE_THEN "df")MP_TAC) THEN (clear_assumption "df") THEN BETA_TAC THEN (move ["_"]))))));; refine (by (VALID (((exists_tac (mk_var("t",mk_type("fun",[mk_type("cart",[mk_type("real",[]);mk_vartype "?1454959"]);mk_type("bool",[])])))) THEN (done_tac)))));; let diff2_eq_diff2_on_open = end_section_proof();; (start_section_proof ["f";"x";"e";"t"](`diff2 f (x + t % e) ==> f o (\t. x + t % e) real_differentiable atreal t`));; refine (by (VALID ((((USE_THM_THEN diff2)(new_rewrite [] [])) 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 ((((USE_THM_THEN diff_imp_real_diff) apply_tac) THEN ((simp_tac) THEN ((USE_THEN "df")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN diff_direction)(new_rewrite [] []))) THEN (done_tac)))));; let diff2_imp_real_diff = end_section_proof();; (start_section_proof ["f";"x";"e";"t"](`diff2 f (x + t % e:real^N) ==> derivative (f o (\t. x + t % e)) t = sum (1..dimindex (:N)) (\i. e$i * (partial i f o (\t. x + t % e)) t)`));; refine (by (VALID ((((USE_THM_THEN diff2)(new_rewrite [] [])) 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 (((((USE_THM_THEN derivative_unique)MP_TAC) THEN (clear_assumption "derivative_unique") THEN (DISCH_THEN apply_tac)) THEN (((USE_THM_THEN real_dir_derivative_partial)(new_rewrite [] [])) THEN ((USE_THEN "df")(new_rewrite [] []))) THEN (done_tac)))));; let diff2_dir_derivative = end_section_proof();; (start_section_proof ["f";"i";"x";"e";"t"](`diff2 f (x + t % e:real^N) ==> partial i f o (\t. x + t % e) real_differentiable atreal t`));; refine (by (VALID ((((USE_THM_THEN diff2)(new_rewrite [] [])) 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 (((((USE_THM_THEN diff_imp_real_diff)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THEN "df")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN diff_direction)(new_rewrite [] []))) THEN (done_tac)))));; let diff2_partial_real_diff = end_section_proof();; (start_section_proof ["x";"s";"t"](`t SUBSET s ==> x IN t ==> x IN s`));; refine (by (VALID ((((USE_THM_THEN SUBSET)(new_rewrite [] [])) THEN (move ["sub"]) THEN (move ["xt"])))));; refine (by (VALID ((((USE_THEN "sub")MP_TAC) THEN (clear_assumption "sub") THEN (exact_tac)))));; let in_trans = end_section_proof();; (start_section_proof ["e";"s";"x"](`open s ==> x IN s ==> ?a b. &0 IN real_interval (a, b) /\ IMAGE (\t. x + t % e) (real_interval (a, b)) SUBSET s`));; refine (by (VALID ((((USE_THM_THEN OPEN_CONTAINS_BALL)(new_rewrite [] [])) THEN (move ["open_s"])))));; refine (by (VALID ((((DISCH_THEN (fun snd_th -> (USE_THEN "open_s")(MATCH_MP_THEN snd_th MP_TAC))) THEN BETA_TAC THEN (case THEN (move ["d"])) THEN (case THEN (move ["d0"])) THEN (move ["ball_s"])) THEN (((USE_THEN "open_s")MP_TAC) THEN (clear_assumption "open_s") THEN BETA_TAC THEN (move ["_"]))))));; refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN EXCLUDED_MIDDLE)(ISPEC_THEN (`norm e = &0`) thm_tac))MP_TAC) THEN case THENL [ALL_TAC; (move ["n0"])]))));; refine (by (VALID (((((USE_THM_THEN NORM_EQ_0)(new_rewrite [] [])) THEN (DISCH_THEN(new_rewrite [] []))) THEN ((exists_tac (`--d`)) THEN (exists_tac (mk_var("d",mk_type("real",[])))))))));; refine (by (VALID (((THENL_FIRST) (split_tac) (((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] [])) THEN (((USE_THEN "d0")MP_TAC) THEN (clear_assumption "d0") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac))))));; refine (by (VALID ((((((USE_THM_THEN SUBSET)(new_rewrite [] [])) THEN ((USE_THM_THEN IN_IMAGE)(new_rewrite [] []))) THEN (move ["y"]) THEN (case THEN (move ["t"])) THEN (DISCH_THEN(new_rewrite [] [])) THEN (simp_tac)) THEN (((USE_THM_THEN (GEN_ALL VECTOR_MUL_RZERO))(new_rewrite [] [])) THEN ((USE_THM_THEN VECTOR_ADD_RID)(new_rewrite [] [])))))));; refine (by (VALID (((((fun thm_tac -> (USE_THM_THEN in_trans)(fun fst_th ->(USE_THEN "ball_s")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] [])) THEN ((USE_THM_THEN CENTRE_IN_BALL)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((set_tac "y" (`((d / &2) * inv(norm e)) % e`)))));; refine (by (VALID ((have_tac (move ["norm_y"]) (`norm y = d / &2`)))));; refine (by (VALID ((((USE_THEN "y_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN VECTOR_MUL_ASSOC)(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN NORM_MUL)(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_ABS_INV)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_ABS_NORM)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_LINV)(new_rewrite [] [])) THEN ((TRY done_tac))))));; refine (by (VALID (((((USE_THEN "d0")MP_TAC) THEN (clear_assumption "d0") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((((exists_tac (`-- (d / &2 * inv (norm e))`)) THEN (exists_tac (`d / &2 * inv (norm e)`))) THEN (split_tac)))));; refine (by (VALID ((((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_NEG_LT0)(new_rewrite [] [])) THEN ((USE_THM_THEN andbb)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LT_MUL)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LT_INV)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN NORM_POS_LT)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN NORM_EQ_0)(GSYM_THEN (new_rewrite [] [])))) THEN ((TRY done_tac))))));; refine (by (VALID (((((USE_THEN "d0")MP_TAC) THEN (clear_assumption "d0") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((((USE_THM_THEN SUBSET_TRANS) apply_tac) THEN (exists_tac (`ball (x, d)`)) THEN ((((USE_THEN "ball_s")(new_rewrite [] [])) THEN ((USE_THM_THEN andbT)(new_rewrite [] [])) THEN ((USE_THM_THEN SUBSET)(new_rewrite [] [])) THEN ((USE_THM_THEN IN_IMAGE)(new_rewrite [] []))) THEN (move ["p"]) THEN (case THEN (move ["t"])) THEN (case THEN (DISCH_THEN(new_rewrite [] []))) THEN (move ["t_in"]) THEN (simp_tac))))));; refine (by (VALID ((((USE_THM_THEN IN_BALL)(new_rewrite [] [])) THEN ((USE_THM_THEN dist)(new_rewrite [] [])) THEN ((USE_THM_THEN VECTOR_SUB_RADD)(new_rewrite [] [])) THEN ((USE_THM_THEN NORM_NEG)(new_rewrite [] [])) THEN ((USE_THM_THEN NORM_MUL)(new_rewrite [] []))))));; refine (by (VALID (((THENL_LAST) ((((USE_THM_THEN REAL_LET_TRANS)MP_TAC) THEN (clear_assumption "REAL_LET_TRANS") THEN (DISCH_THEN apply_tac)) THEN (exists_tac (`d / &2`)) THEN (split_tac)) ((((USE_THEN "d0")MP_TAC) THEN (clear_assumption "d0") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac))))));; refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN REAL_MUL_RID)(ISPEC_THEN (`d / &2`) thm_tac))(GSYM_THEN (new_rewrite [] []))) THEN ((fun thm_tac -> (USE_THM_THEN REAL_MUL_LINV)(fun fst_th ->(USE_THEN "n0")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN REAL_MUL_ASSOC)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LE_RMUL)(new_rewrite [] [])) THEN ((USE_THM_THEN NORM_POS_LE)(new_rewrite [] [])) THEN ((USE_THM_THEN andbT)(new_rewrite [] []))))));; refine (by (VALID (((((USE_THEN "t_in")MP_TAC) THEN (clear_assumption "t_in") THEN BETA_TAC) THEN ((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] [])) THEN (arith_tac) THEN (done_tac)))));; let open_contains_open_interval = end_section_proof();; (start_section_proof ["f";"x";"e";"t"](`diff2 f (x + t % e:real^N) ==> nth_diff_strong 2 (f o (\t. x + t % e)) t`));; refine (by (VALID (((((USE_THM_THEN diff2_eq_diff2_on_open)(new_rewrite [] [])) 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 (move ["df"])))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN open_contains_open_interval)(ISPEC_THEN (mk_var("e",mk_type("cart",[mk_type("real",[]);mk_vartype "N"]))) thm_tac))(fun fst_th ->(USE_THEN "open_s")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "xs")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["a"])) THEN (case THEN (move ["b"])) THEN (case THEN (move ["in0"])) THEN (move ["sub"])))));; refine (by (VALID (((exists_tac (`real_interval (a + t, b + t)`)) THEN (((USE_THM_THEN REAL_OPEN_REAL_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (split_tac)))));; refine (by (VALID (((((USE_THEN "in0")MP_TAC) THEN (clear_assumption "in0") THEN BETA_TAC) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((BETA_TAC THEN (move ["p"]) THEN (move ["p_int"])))));; refine (by (VALID ((have_tac (move ["xp_in"]) (`x + p % e IN s`)))));; refine (by (VALID (((((USE_THEN "sub")MP_TAC) THEN (clear_assumption "sub") THEN BETA_TAC) THEN ((USE_THM_THEN SUBSET)(new_rewrite [] [])) THEN (DISCH_THEN apply_tac) THEN (((USE_THM_THEN IN_IMAGE)(new_rewrite [] [])) THEN (simp_tac)) THEN (exists_tac (`p - t`))))));; refine (by (VALID (((split_tac) THENL [(VECTOR_ARITH_TAC); ((((USE_THEN "p_int")MP_TAC) THEN (clear_assumption "p_int") THEN BETA_TAC) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] []))) THEN (arith_tac))] THEN (done_tac)))));; refine (by (VALID ((((USE_THM_THEN diff2_imp_real_diff)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))))));; refine (by (VALID (((USE_THM_THEN differentiable_local) apply_tac))));; refine (by (VALID ((exists_tac (`\t. sum (1..dimindex(:N)) (\i. e$i * (partial i f o (\t. x + t % e)) t)`)))));; refine (by (VALID ((set_tac "d" (`min (p - (a + t)) (b + t - p)`)))));; refine (by (VALID (((THENL_FIRST) (have_tac (move ["d0"]) (`&0 < d`)) ((((USE_THEN "p_int")MP_TAC) THEN (clear_assumption "p_int") THEN BETA_TAC) THEN (((USE_THEN "d_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac))))));; refine (by (VALID (((exists_tac (`real_interval (p - d, p + d)`)) THEN (split_tac)))));; refine (by (VALID ((((USE_THM_THEN differentiable_sum_numseg)(new_rewrite [] [])) THEN (move ["i"]) THEN (move ["ineq"]) THEN (simp_tac)))));; refine (by (VALID (((((USE_THM_THEN REAL_DIFFERENTIABLE_MUL_ATREAL)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_DIFFERENTIABLE_CONST)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th]))))));; refine (by (VALID (((((USE_THM_THEN diff2_partial_real_diff)(new_rewrite [] [])) THEN ((USE_THEN "df")(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((((USE_THM_THEN REAL_OPEN_REAL_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_THEN "d0")MP_TAC) THEN (clear_assumption "d0") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID (((BETA_TAC THEN (move ["y"]) THEN (move ["y_in"])) THEN (((USE_THM_THEN diff2_dir_derivative)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THEN "df")(new_rewrite [] [])))))));; refine (by (VALID (((((USE_THEN "sub")MP_TAC) THEN (clear_assumption "sub") THEN BETA_TAC) THEN ((USE_THM_THEN SUBSET)(new_rewrite [] [])) THEN (DISCH_THEN apply_tac) THEN (((USE_THM_THEN IN_IMAGE)(new_rewrite [] [])) THEN (simp_tac)) THEN (exists_tac (`y - t`))))));; refine (by (VALID (((THENL_FIRST) (split_tac) ((VECTOR_ARITH_TAC) THEN (done_tac))))));; refine (by (VALID (((((USE_THEN "p_int")MP_TAC) THEN (clear_assumption "p_int") THEN ((USE_THEN "d_def")MP_TAC) THEN (clear_assumption "d_def") THEN ((USE_THEN "y_in")MP_TAC) THEN (clear_assumption "y_in") THEN BETA_TAC) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac)))));; let diff2_dir = end_section_proof();; (start_section_proof ["f";"x";"e";"t"](`diff2 f (x + t % e:real^N) ==> nth_derivative 2 (f o (\t. x + t % e)) t = sum (1..dimindex (:N)) (\i. sum (1..dimindex (:N)) (\j. e$i * e$j * (partial j (partial i f) o (\t. x + t % e)) t))`));; refine (by (VALID ((((USE_THM_THEN diff2_eq_diff2_on_open)(new_rewrite [] [])) 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 ((((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))))));; 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 (`\t. sum (1..dimindex(:N)) (\i. e$i * (partial i f o (\t. x + t % e)) t)`)) THEN (split_tac)))));; refine (by (VALID ((((USE_THM_THEN HAS_REAL_DERIVATIVE_SUM) apply_tac) THEN ((((USE_THM_THEN FINITE_NUMSEG)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (move ["i"]) THEN (move ["ineq"]) THEN (simp_tac))))));; refine (by (VALID (((((USE_THM_THEN SUM_LMUL)(new_rewrite [] [])) THEN ((USE_THM_THEN HAS_REAL_DERIVATIVE_LMUL_ATREAL)(new_rewrite [] []))) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th]))))));; refine (by (VALID (((USE_THM_THEN real_dir_derivative_partial)(new_rewrite [] [])))));; refine (by (VALID (((((fun thm_tac -> (USE_THEN "df")(fun fst_th ->(USE_THEN "xs")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC) THEN (((USE_THM_THEN diff2)(new_rewrite [] [])) THEN ALL_TAC THEN (case THEN (move ["r"])) THEN (case THEN (move ["_"])) THEN (case THEN (move ["xr"])) THEN (DISCH_THEN(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN open_contains_open_interval)(ISPEC_THEN (mk_var("e",mk_type("cart",[mk_type("real",[]);mk_vartype "N"]))) thm_tac))(fun fst_th ->(USE_THEN "open_s")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "xs")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["a"])) THEN (case THEN (move ["b"])) THEN (case THEN (move ["in0"])) THEN (move ["sub"])))));; refine (by (VALID (((exists_tac (`real_interval (a + t, b + t)`)) THEN (((USE_THM_THEN REAL_OPEN_REAL_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (split_tac)))));; refine (by (VALID (((((USE_THEN "in0")MP_TAC) THEN (clear_assumption "in0") THEN BETA_TAC) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID (((BETA_TAC THEN (move ["p"]) THEN (move ["p_in"])) THEN (((USE_THM_THEN diff2_dir_derivative)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THEN "df")(new_rewrite [] [])))))));; refine (by (VALID (((((USE_THEN "sub")MP_TAC) THEN (clear_assumption "sub") THEN BETA_TAC) THEN ((USE_THM_THEN SUBSET)(new_rewrite [] [])) THEN (DISCH_THEN apply_tac) THEN (((USE_THM_THEN IN_IMAGE)(new_rewrite [] [])) THEN (simp_tac)) THEN (exists_tac (`p - t`))))));; refine (by (VALID (((THENL_FIRST) (split_tac) ((VECTOR_ARITH_TAC) THEN (done_tac))))));; refine (by (VALID (((((USE_THEN "p_in")MP_TAC) THEN (clear_assumption "p_in") THEN BETA_TAC) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac)))));; let diff2_dir_derivative2 = end_section_proof();; (start_section_proof ["f";"i";"x";"e";"t"](`diff2 f (x + t % e:real^N) ==> (partial i f o (\t. x + t % e) has_real_derivative sum (1..dimindex (:N)) (\j. e$j * (partial j (partial i f) o (\t. x + t % e)) t)) (atreal t)`));; refine (by (VALID ((((USE_THM_THEN diff2)(new_rewrite [] [])) 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 (((((USE_THM_THEN real_dir_derivative_partial)(new_rewrite [] [])) THEN ((USE_THEN "df")(new_rewrite [] []))) THEN (done_tac)))));; let diff2_has_derivative_partial = end_section_proof();; (start_section_proof ["f";"i";"x";"e";"t"](`diff2 f (x + t % e:real^N) ==> derivative (partial i f o (\t. x + t % e)) t = sum (1..dimindex (:N)) (\j. e$j * (partial j (partial i f) o (\t. x + t % e)) t)`));; refine (by (VALID (((BETA_TAC THEN (move ["df"])) THEN (((USE_THM_THEN derivative_unique)MP_TAC) THEN (clear_assumption "derivative_unique") THEN (DISCH_THEN apply_tac)) THEN (((USE_THM_THEN diff2_has_derivative_partial)MP_TAC) THEN (clear_assumption "diff2_has_derivative_partial") THEN (exact_tac)) THEN (done_tac)))));; let diff2_derivative_partial = end_section_proof();; (start_section_proof ["f";"i";"x";"e";"t"](`diff2 f (x + t % e:real^N) ==> partial i f o (\t. x + t % e) real_differentiable atreal t`));; refine (by (VALID ((BETA_TAC THEN (move ["df2"])))));; refine (by (VALID (((((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN diff2_has_derivative_partial)(fun fst_th ->(USE_THEN "df2")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(ISPEC_THEN (mk_var("i",mk_type("num",[]))) thm_tac))MP_TAC) THEN BETA_TAC) THEN (set_tac "s" (`sum _1 _2`))))));; refine (by (VALID (((((USE_THM_THEN real_differentiable)(new_rewrite [] [])) THEN (move ["df"])) THEN (exists_tac (mk_var("s",mk_type("real",[])))) THEN (done_tac)))));; let diff2_real_diff_partial = end_section_proof();; (start_section_proof ["i";"c"](`partial i (\x:real^N. c) = (\x. &0)`));; refine (by (VALID (((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN partial)(new_rewrite [] []))) THEN (move ["x"]) THEN (simp_tac)))));; refine (by (VALID ((((THENL_ROT 1)) (have_tac (DISCH_THEN(new_rewrite [] [])) (`(\x. c) o (\t. x + t % basis i) = (\x. c)`))))));; refine (by (VALID ((((USE_THM_THEN derivative_const)(new_rewrite [] [])) THEN (done_tac)))));; refine (by (VALID (((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (done_tac)))));; let partial_const = end_section_proof();; (start_section_proof ["i";"f"](`~(i IN 1..dimindex (:N)) ==> partial i f = (\x:real^N. &0)`));; refine (by (VALID (((BETA_TAC THEN (move ["ih"])) THEN (((USE_THM_THEN FUN_EQ_THM)(new_rewrite [] [])) THEN (move ["x"])) THEN ((USE_THM_THEN partial_eq0)(new_rewrite [] [])) THEN (done_tac)))));; let partial_eq0_alt = end_section_proof();; (start_section_proof [](`!f f' a. (!x. abs x <= abs a ==> (f has_real_derivative f' x) (atreal x)) ==> (?t. abs t <= abs a /\ f a - f (&0) = f' t * a)`));; refine (by (VALID ((BETA_TAC THEN (move ["f"]) THEN (move ["f'"]) THEN (move ["a"]) THEN (move ["h"])))));; refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN EXCLUDED_MIDDLE)(ISPEC_THEN (`&0 <= a`) thm_tac))MP_TAC) THEN case THEN (move ["a_ineq"])))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN REAL_MVT_VERY_SIMPLE)(ISPEC_THEN (mk_var("f",mk_type("fun",[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 (`&0`) thm_tac))(ISPEC_THEN (mk_var("a",mk_type("real",[]))) thm_tac)) MP_TAC) THEN ALL_TAC))));; refine (by (VALID (((((USE_THEN "a_ineq")(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] [])))) THEN (ANTS_TAC)))));; refine (by (VALID ((BETA_TAC THEN (move ["x"]) THEN (move ["x_ineq"])))));; refine (by (VALID (((((USE_THM_THEN HAS_REAL_DERIVATIVE_ATREAL_WITHIN)(new_rewrite [] [])) THEN ((USE_THEN "h")(new_rewrite [] []))) THEN (((USE_THEN "x_ineq")MP_TAC) THEN (clear_assumption "x_ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((BETA_TAC THEN (case THEN (move ["t"])) THEN (case THEN (move ["t_ineq"])) THEN (move ["eq"])))));; refine (by (VALID (((exists_tac (mk_var("t",mk_type("real",[])))) THEN ((USE_THEN "eq")(new_rewrite [] [])) THEN (((USE_THEN "t_ineq")MP_TAC) THEN (clear_assumption "t_ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN REAL_MVT_VERY_SIMPLE)(ISPEC_THEN (mk_var("f",mk_type("fun",[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 (mk_var("a",mk_type("real",[]))) thm_tac))(ISPEC_THEN (`&0`) thm_tac)) MP_TAC) THEN ALL_TAC))));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] []))) THEN (ANTS_TAC)))));; refine (by (VALID (((THENL_FIRST) (split_tac) ((((USE_THEN "a_ineq")MP_TAC) THEN (clear_assumption "a_ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac))))));; refine (by (VALID (((BETA_TAC THEN (move ["x"]) THEN (move ["x_ineq"])) THEN (((USE_THM_THEN HAS_REAL_DERIVATIVE_ATREAL_WITHIN)(new_rewrite [] [])) THEN ((USE_THEN "h")(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 ((BETA_TAC THEN (case THEN (move ["t"])) THEN (case THEN (move ["t_ineq"])) THEN (move ["eq"])))));; refine (by (VALID (((exists_tac (mk_var("t",mk_type("real",[])))) THEN (((USE_THM_THEN REAL_NEG_SUB)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THEN "eq")(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_NEG_RMUL)(new_rewrite [] []))) THEN (((USE_THEN "t_ineq")MP_TAC) THEN (clear_assumption "t_ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; let real_mvt0 = end_section_proof();; (start_section_proof ["f";"x";"i";"j"](`diff2c f x ==> partial2 i j f x = partial2 j i f (x:real^N)`));; refine (by (VALID (((((USE_THM_THEN diff2c)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN partial2)(new_rewrite [] [])))) THEN ALL_TAC THEN (case THEN ((move ["d2f"]) THEN (move ["pc"])))))));; refine (by (VALID (((THENL_ROT (-1)) (((fun thm_tac -> (USE_THM_THEN EXCLUDED_MIDDLE)(ISPEC_THEN (`i IN 1..dimindex (:N)`) thm_tac))MP_TAC) THEN case THEN (move ["ih"]))))));; refine (by (VALID (((repeat_tactic 1 9 (((fun thm_tac -> (USE_THM_THEN partial_eq0_alt)(ISPEC_THEN (mk_var("i",mk_type("num",[]))) thm_tac))(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN partial_const)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((THENL_ROT (-1)) (((fun thm_tac -> (USE_THM_THEN EXCLUDED_MIDDLE)(ISPEC_THEN (`j IN 1..dimindex (:N)`) thm_tac))MP_TAC) THEN case THEN (move ["jh"]))))));; refine (by (VALID (((repeat_tactic 1 9 (((fun thm_tac -> (USE_THM_THEN partial_eq0_alt)(ISPEC_THEN (mk_var("j",mk_type("num",[]))) thm_tac))(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN partial_const)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((((USE_THEN "jh")MP_TAC) THEN (clear_assumption "jh") THEN ((USE_THEN "ih")MP_TAC) THEN (clear_assumption "ih") THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN IN_NUMSEG)(new_rewrite [] []))) THEN (move ["ih"]) THEN (move ["jh"]))))));; refine (by (VALID (((((USE_THEN "d2f")MP_TAC) THEN (clear_assumption "d2f") THEN BETA_TAC) THEN (((USE_THM_THEN diff2_eq_diff2_on_open)(new_rewrite [] [])) THEN ALL_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["open_s"])) THEN (case THEN (move ["xs"])) THEN (move ["d2f"]))))));; refine (by (VALID ((set_tac "F1" (`\h k. f ((x + k % basis j) + h % basis i) - f (x + k % basis j)`)))));; refine (by (VALID ((set_tac "F2" (`\k h. f ((x + h % basis i) + k % basis j) - f (x + h % basis i)`)))));; refine (by (VALID ((set_tac "G" (`\h k. F1 h k - F1 h (&0)`)))));; refine (by (VALID (((THENL_FIRST) (have_tac (move ["v_eq"]) (`!h k. (x + k % basis j) + h % basis i = (x + h % basis i) + k % basis j`)) ((VECTOR_ARITH_TAC) THEN (done_tac))))));; refine (by (VALID ((have_tac (move ["G_eq"]) (`G = \h k. F2 k h - F2 k (&0)`)))));; refine (by (VALID ((repeat_tactic 2 0 (((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] [])))) THEN (move ["h"]) THEN (move ["k"])))));; refine (by (VALID (((((USE_THEN "G_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THEN "F2_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THEN "F1_def")(GSYM_THEN (new_rewrite [] []))) THEN (simp_tac) THEN repeat_tactic 1 9 (((USE_THM_THEN VECTOR_MUL_LZERO)(new_rewrite [] []))) THEN ((USE_THM_THEN VECTOR_ADD_RID)(new_rewrite [] [])) THEN ((USE_THEN "v_eq")(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((have_tac (ALL_TAC THEN (case THEN ((move ["r"]) THEN (case THEN ((move ["r0"]) THEN (move ["rs"])))))) (`?r. &0 < r /\ (!h k. abs h <= r /\ abs k <= r ==> (x + h % basis i) + k % basis j IN s)`)))));; refine (by (VALID (((((USE_THEN "open_s")MP_TAC) THEN (clear_assumption "open_s") THEN BETA_TAC) THEN ((((USE_THM_THEN OPEN_CONTAINS_BALL)(new_rewrite [] [])) THEN ((USE_THM_THEN SUBSET)(new_rewrite [] [])) THEN ((USE_THM_THEN IN_BALL)(new_rewrite [] [])) THEN ((USE_THM_THEN dist)(new_rewrite [] []))) THEN ((fun thm_tac -> DISCH_THEN (fun fst_th ->(USE_THEN "xs")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN (case THEN (move ["e"])) THEN (case THEN ((move ["e0"]) THEN (move ["de"]))))))));; refine (by (VALID (((THENL_FIRST) ((exists_tac (`e / &3`)) THEN (split_tac)) ((((USE_THEN "e0")MP_TAC) THEN (clear_assumption "e0") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac))))));; refine (by (VALID ((BETA_TAC THEN (move ["h"]) THEN (move ["k"]) THEN (move ["ineq"])))));; refine (by (VALID ((((USE_THEN "de")(new_rewrite [] [])) THEN ((USE_THM_THEN (GEN_ALL VECTOR_ADD_ASSOC))(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN VECTOR_SUB_RADD)(new_rewrite [] [])) THEN ((USE_THM_THEN NORM_NEG)(new_rewrite [] []))))));; refine (by (VALID (((THENL_LAST) ((((USE_THM_THEN REAL_LET_TRANS)MP_TAC) THEN (clear_assumption "REAL_LET_TRANS") THEN (DISCH_THEN apply_tac)) THEN (exists_tac (`e / &3 + e / &3`)) THEN (split_tac)) ((((USE_THEN "e0")MP_TAC) THEN (clear_assumption "e0") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac))))));; refine (by (VALID (((THENL_LAST) ((((USE_THM_THEN REAL_LE_TRANS)MP_TAC) THEN (clear_assumption "REAL_LE_TRANS") THEN (DISCH_THEN apply_tac)) THEN (exists_tac (`abs h + abs k`)) THEN (split_tac)) ((((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac))))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN NORM_TRIANGLE)(ISPEC_THEN (`h % basis i:real^N`) thm_tac))(ISPEC_THEN (`k % basis j:real^N`) thm_tac)) MP_TAC) THEN ALL_TAC))));; refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN NORM_MUL)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN NORM_BASIS)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_MUL_RID)(new_rewrite [] [])))) THEN (done_tac)))));; refine (by (VALID ((have_tac (move ["in_s"]) (`(!h. abs h <= r ==> x + h % basis i IN s) /\ (!k. abs k <= r ==> x + k % basis j IN s)`)))));; refine (by (VALID (((split_tac) THENL [((move ["h"]) THEN (move ["h_ineq"])); ((move ["k"]) THEN (move ["k_ineq"]))]))));; refine (by (VALID (((((fun thm_tac -> (fun thm_tac -> (USE_THEN "rs")(ISPEC_THEN (mk_var("h",mk_type("real",[]))) thm_tac))(ISPEC_THEN (`&0`) thm_tac))MP_TAC) THEN BETA_TAC) THEN ((((USE_THM_THEN VECTOR_MUL_LZERO)(new_rewrite [] [])) THEN ((USE_THM_THEN VECTOR_ADD_RID)(new_rewrite [] [])) THEN ((USE_THEN "h_ineq")(new_rewrite [] []))) THEN (DISCH_THEN(new_rewrite [] []))) THEN (((USE_THEN "r0")MP_TAC) THEN (clear_assumption "r0") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID (((((fun thm_tac -> (fun thm_tac -> (USE_THEN "rs")(ISPEC_THEN (`&0`) thm_tac))(ISPEC_THEN (mk_var("k",mk_type("real",[]))) thm_tac))MP_TAC) THEN BETA_TAC) THEN ((((USE_THM_THEN VECTOR_MUL_LZERO)(new_rewrite [] [])) THEN ((USE_THM_THEN VECTOR_ADD_RID)(new_rewrite [] [])) THEN ((USE_THEN "k_ineq")(new_rewrite [] []))) THEN (DISCH_THEN(new_rewrite [] []))) THEN (((USE_THEN "r0")MP_TAC) THEN (clear_assumption "r0") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((have_tac (move ["F1h"]) (`!h. F1 h = (\k. (f o (\k. (x + h % basis i) + k % basis j)) k - (f o (\k. x + k % basis j)) k)`)))));; refine (by (VALID (((((USE_THEN "F1_def")(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THEN "v_eq")(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((have_tac (move ["dF1"]) (`!h. abs h <= r ==> !k. abs k <= r ==> (F1 h) real_differentiable atreal k`)))));; refine (by (VALID ((BETA_TAC THEN (move ["h"]) THEN (move ["h_ineq"]) THEN (move ["k"]) THEN (move ["k_ineq"])))));; refine (by (VALID (((((USE_THEN "F1h")(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_DIFFERENTIABLE_SUB)(new_rewrite [] []))) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th]))))));; refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN diff2_imp_real_diff)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "d2f")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "rs")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "in_s")(new_rewrite [] [])))) THEN (done_tac)))));; refine (by (VALID ((have_tac (move ["F1_der"]) (`!h k. abs h <= r /\ abs k <= r ==> derivative (F1 h) k = partial j f ((x + h % basis i) + k % basis j) - partial j f (x + k % basis j)`)))));; refine (by (VALID (((BETA_TAC THEN (move ["h"]) THEN (move ["k"]) THEN (move ["ineq"])) THEN (((USE_THEN "F1h")(new_rewrite [] [])) THEN ((USE_THM_THEN derivative_sub)(new_rewrite [] []))) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN (repeat_tactic 0 10 (((USE_THM_THEN diff2_imp_real_diff)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "d2f")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "rs")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "in_s")(new_rewrite [] []))) THEN ((TRY done_tac)))))));; refine (by (VALID (((((USE_THM_THEN derivative_translation)(new_rewrite [] [(`derivative (f o (\k. x + k % basis j)) k`)])) THEN repeat_tactic 0 1 (((USE_THM_THEN derivative_translation)(new_rewrite [] [])))) THEN (repeat_tactic 0 10 (((USE_THM_THEN diff2_imp_real_diff)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "d2f")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "rs")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "in_s")(new_rewrite [] []))) THEN ((TRY done_tac)))))));; refine (by (VALID ((have_tac (move ["eq"]) (`!y e. (f o (\k. y + k % e)) o (\t. k + t) = f o (\t. (y + k % e) + t % e)`)))));; refine (by (VALID (((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN (GEN_ALL VECTOR_ADD_RDISTRIB))(new_rewrite [] [])) THEN ((USE_THM_THEN (GEN_ALL VECTOR_ADD_ASSOC))(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((repeat_tactic 1 9 (((USE_THEN "eq")(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN partial)(GSYM_THEN (new_rewrite [] []))))) THEN (done_tac)))));; refine (by (VALID ((have_tac (move ["Gh"]) (`!h k. abs h <= r /\ abs k <= r ==> (?t1. G h k = k * derivative (F1 h) t1 /\ abs t1 <= abs k)`)))));; refine (by (VALID (((BETA_TAC THEN (move ["h"]) THEN (move ["k"]) THEN (move ["ineq"])) THEN (((USE_THEN "G_def")(GSYM_THEN (new_rewrite [] []))) THEN (simp_tac))))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN real_mvt0)(ISPEC_THEN (`F1 h`) thm_tac))(ISPEC_THEN (`derivative (F1 h)`) thm_tac))(ISPEC_THEN (mk_var("k",mk_type("real",[]))) thm_tac)) MP_TAC) THEN ALL_TAC))));; refine (by (VALID ((ANTS_TAC))));; refine (by (VALID (((BETA_TAC THEN (move ["t"]) THEN (move ["t_ineq"])) THEN (((USE_THM_THEN has_derivative_alt)(new_rewrite [] [])) THEN ((USE_THEN "dF1")(new_rewrite [] [])))))));; refine (by (VALID (((((USE_THEN "t_ineq")MP_TAC) THEN (clear_assumption "t_ineq") THEN ((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((BETA_TAC THEN (case THEN (move ["t1"])) THEN (case THEN (move ["t1_ineq"])) THEN (move ["eq"])))));; refine (by (VALID (((exists_tac (mk_var("t1",mk_type("real",[])))) THEN ((USE_THEN "eq")(new_rewrite [] [])) THEN (((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN ((USE_THEN "t1_ineq")MP_TAC) THEN (clear_assumption "t1_ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((have_tac (move ["Ghk"]) (`!h k. abs h <= r /\ abs k <= r ==> (?t1 t2. G h k = h * k * partial i (partial j f) (x + t1 % basis j + t2 % basis i) /\ abs t1 <= abs k /\ abs t2 <= abs h)`)))));; refine (by (VALID ((BETA_TAC THEN (move ["h"]) THEN (move ["k"]) THEN (move ["ineq"])))));; refine (by (VALID (((((fun thm_tac -> (fun thm_tac -> (USE_THEN "Gh")(ISPEC_THEN (mk_var("h",mk_type("real",[]))) thm_tac))(ISPEC_THEN (mk_var("k",mk_type("real",[]))) thm_tac))MP_TAC) THEN BETA_TAC) THEN ((repeat_tactic 1 9 (((USE_THEN "ineq")(new_rewrite [] []))) THEN (simp_tac)) THEN ALL_TAC THEN (case THEN (move ["t1"])) THEN (case THEN ((move ["eq"]) THEN (move ["t1k"]))))))));; refine (by (VALID (((((USE_THEN "eq")MP_TAC) THEN (clear_assumption "eq") THEN BETA_TAC) THEN ((USE_THEN "F1_der")(new_rewrite [] [])) THENL [((((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN ((USE_THEN "t1k")MP_TAC) THEN (clear_assumption "t1k") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)); (BETA_TAC THEN (move ["eq"]))]))));; refine (by (VALID ((set_tac "g" (`partial j f o (\h. (x + t1 % basis j) + h % basis i)`)))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN real_mvt0)(ISPEC_THEN (mk_var("g",mk_type("fun",[mk_type("real",[]);mk_type("real",[])]))) thm_tac))(ISPEC_THEN (`derivative g`) thm_tac))(ISPEC_THEN (mk_var("h",mk_type("real",[]))) thm_tac)) MP_TAC) THEN ALL_TAC))));; refine (by (VALID ((ANTS_TAC))));; refine (by (VALID (((BETA_TAC THEN (move ["t"]) THEN (move ["t_ineq"])) THEN ((USE_THM_THEN has_derivative_alt)(new_rewrite [] []))))));; refine (by (VALID ((((USE_THEN "g_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN diff2_partial_real_diff)(new_rewrite [] [])) THEN ((USE_THEN "d2f")(new_rewrite [] [])) THEN ((USE_THEN "v_eq")(new_rewrite [] [])) THEN ((USE_THEN "rs")(new_rewrite [] []))))));; refine (by (VALID (((((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN ((USE_THEN "t_ineq")MP_TAC) THEN (clear_assumption "t_ineq") THEN ((USE_THEN "t1k")MP_TAC) THEN (clear_assumption "t1k") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((BETA_TAC THEN (case THEN (move ["t2"])) THEN (case THEN (move ["t2_ineq"])) THEN (move ["g_eq"])))));; refine (by (VALID (((THENL_LAST) (((exists_tac (mk_var("t1",mk_type("real",[])))) THEN (exists_tac (mk_var("t2",mk_type("real",[]))))) THEN ((USE_THEN "eq")(new_rewrite [] [])) THEN (split_tac)) ((((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN ((USE_THEN "t2_ineq")MP_TAC) THEN (clear_assumption "t2_ineq") THEN ((USE_THEN "t1k")MP_TAC) THEN (clear_assumption "t1k") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac))))));; refine (by (VALID ((set_tac "p" (`_1 - _2`)))));; refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`p = g h - g (&0)`)))));; refine (by (VALID (((((USE_THEN "p_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THEN "g_def")(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN VECTOR_MUL_LZERO)(new_rewrite [] [])) THEN ((USE_THM_THEN VECTOR_ADD_RID)(new_rewrite [] [])) THEN ((USE_THEN "v_eq")(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((((USE_THEN "g_eq")(new_rewrite [] [])) THEN ((USE_THM_THEN (REAL_ARITH `!a. k * a * h = h * k * a`))(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_MUL_ASSOC)(new_rewrite [] [])))))));; refine (by (VALID (((((USE_THM_THEN REAL_EQ_MUL_LCANCEL)(new_rewrite [] [])) THEN ((USE_THEN "g_def")(GSYM_THEN (new_rewrite [] [])))) THEN (DISJ2_TAC)))));; refine (by (VALID (((USE_THM_THEN derivative_translation)(new_rewrite [] [])))));; refine (by (VALID (((((USE_THM_THEN diff2_partial_real_diff)(new_rewrite [] [])) THEN ((USE_THEN "d2f")(new_rewrite [] [])) THEN ((USE_THEN "v_eq")(new_rewrite [] [])) THEN ((USE_THEN "rs")(new_rewrite [] []))) THEN (((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN ((USE_THEN "t2_ineq")MP_TAC) THEN (clear_assumption "t2_ineq") THEN ((USE_THEN "t1k")MP_TAC) THEN (clear_assumption "t1k") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((((USE_THM_THEN partial)(new_rewrite [] [])) THEN (AP_THM_TAC) THEN (AP_TERM_TAC)))));; refine (by (VALID (((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN (GEN_ALL VECTOR_ADD_RDISTRIB))(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN (GEN_ALL VECTOR_ADD_ASSOC))(GSYM_THEN (new_rewrite [] []))))) THEN (done_tac)))));; refine (by (VALID ((((USE_THEN "F1_def")MP_TAC) THEN (clear_assumption "F1_def") THEN ((USE_THEN "G_def")MP_TAC) THEN (clear_assumption "G_def") THEN ((USE_THEN "F1h")MP_TAC) THEN (clear_assumption "F1h") THEN ((USE_THEN "dF1")MP_TAC) THEN (clear_assumption "dF1") THEN ((USE_THEN "F1_der")MP_TAC) THEN (clear_assumption "F1_der") THEN ((USE_THEN "Gh")MP_TAC) THEN (clear_assumption "Gh") THEN BETA_TAC THEN (move ["_"]) THEN (move ["_"]) THEN (move ["_"]) THEN (move ["_"]) THEN (move ["_"]) THEN (move ["_"])))));; refine (by (VALID ((have_tac (move ["F2h"]) (`!k. F2 k = (\h. (f o (\h. (x + k % basis j) + h % basis i)) h - (f o (\h. x + h % basis i)) h)`)))));; refine (by (VALID (((((USE_THEN "F2_def")(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THEN "v_eq")(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((have_tac (move ["dF2"]) (`!k. abs k <= r ==> !h. abs h <= r ==> (F2 k) real_differentiable atreal h`)))));; refine (by (VALID ((BETA_TAC THEN (move ["k"]) THEN (move ["k_ineq"]) THEN (move ["h"]) THEN (move ["h_ineq"])))));; refine (by (VALID (((((USE_THEN "F2h")(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_DIFFERENTIABLE_SUB)(new_rewrite [] []))) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th]))))));; refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN diff2_imp_real_diff)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "d2f")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "v_eq")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "rs")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "in_s")(new_rewrite [] [])))) THEN (done_tac)))));; refine (by (VALID ((have_tac (move ["F2_der"]) (`!h k. abs h <= r /\ abs k <= r ==> derivative (F2 k) h = partial i f ((x + k % basis j) + h % basis i) - partial i f (x + h % basis i)`)))));; refine (by (VALID (((BETA_TAC THEN (move ["h"]) THEN (move ["k"]) THEN (move ["ineq"])) THEN (((USE_THEN "F2h")(new_rewrite [] [])) THEN ((USE_THM_THEN derivative_sub)(new_rewrite [] []))) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN (repeat_tactic 0 10 (((USE_THM_THEN diff2_imp_real_diff)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "d2f")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "v_eq")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "rs")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "in_s")(new_rewrite [] []))) THEN ((TRY done_tac)))))));; refine (by (VALID (((((USE_THEN "v_eq")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN derivative_translation)(new_rewrite [] [(`derivative (f o (\h. x + h % basis i)) h`)])) THEN repeat_tactic 0 1 (((USE_THM_THEN derivative_translation)(new_rewrite [] [])))) THEN (repeat_tactic 0 10 (((USE_THM_THEN diff2_imp_real_diff)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "d2f")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "v_eq")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "rs")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "in_s")(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THEN "v_eq")(GSYM_THEN (new_rewrite [] []))))))));; refine (by (VALID ((have_tac (move ["eq"]) (`!y e. (f o (\h. y + h % e)) o (\t. h + t) = f o (\t. (y + h % e) + t % e)`)))));; refine (by (VALID (((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN (GEN_ALL VECTOR_ADD_RDISTRIB))(new_rewrite [] [])) THEN ((USE_THM_THEN (GEN_ALL VECTOR_ADD_ASSOC))(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((repeat_tactic 1 9 (((USE_THEN "eq")(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN partial)(GSYM_THEN (new_rewrite [] []))))) THEN (done_tac)))));; refine (by (VALID ((have_tac (move ["Gk"]) (`!h k. abs h <= r /\ abs k <= r ==> (?t3. G h k = h * derivative (F2 k) t3 /\ abs t3 <= abs h)`)))));; refine (by (VALID (((BETA_TAC THEN (move ["h"]) THEN (move ["k"]) THEN (move ["ineq"])) THEN (((USE_THEN "G_eq")(new_rewrite [] [])) THEN (simp_tac))))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN real_mvt0)(ISPEC_THEN (`F2 k`) thm_tac))(ISPEC_THEN (`derivative (F2 k)`) thm_tac))(ISPEC_THEN (mk_var("h",mk_type("real",[]))) thm_tac)) MP_TAC) THEN ALL_TAC))));; refine (by (VALID ((ANTS_TAC))));; refine (by (VALID (((BETA_TAC THEN (move ["t"]) THEN (move ["t_ineq"])) THEN (((USE_THM_THEN has_derivative_alt)(new_rewrite [] [])) THEN ((USE_THEN "dF2")(new_rewrite [] [])))))));; refine (by (VALID (((((USE_THEN "t_ineq")MP_TAC) THEN (clear_assumption "t_ineq") THEN ((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((BETA_TAC THEN (case THEN (move ["t3"])) THEN (case THEN (move ["t3_ineq"])) THEN (move ["eq"])))));; refine (by (VALID (((exists_tac (mk_var("t3",mk_type("real",[])))) THEN ((USE_THEN "eq")(new_rewrite [] [])) THEN (((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN ((USE_THEN "t3_ineq")MP_TAC) THEN (clear_assumption "t3_ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((have_tac (move ["Gkh"]) (`!h k. abs h <= r /\ abs k <= r ==> (?t3 t4. G h k = h * k * partial j (partial i f) (x + t4 % basis j + t3 % basis i) /\ abs t3 <= abs h /\ abs t4 <= abs k)`)))));; refine (by (VALID ((BETA_TAC THEN (move ["h"]) THEN (move ["k"]) THEN (move ["ineq"])))));; refine (by (VALID (((((fun thm_tac -> (fun thm_tac -> (USE_THEN "Gk")(ISPEC_THEN (mk_var("h",mk_type("real",[]))) thm_tac))(ISPEC_THEN (mk_var("k",mk_type("real",[]))) thm_tac))MP_TAC) THEN BETA_TAC) THEN ((repeat_tactic 1 9 (((USE_THEN "ineq")(new_rewrite [] []))) THEN (simp_tac)) THEN ALL_TAC THEN (case THEN (move ["t3"])) THEN (case THEN ((move ["eq"]) THEN (move ["t3h"]))))))));; refine (by (VALID (((((USE_THEN "eq")MP_TAC) THEN (clear_assumption "eq") THEN BETA_TAC) THEN ((USE_THEN "F2_der")(new_rewrite [] [])) THENL [((((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN ((USE_THEN "t3h")MP_TAC) THEN (clear_assumption "t3h") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)); (BETA_TAC THEN (move ["eq"]))]))));; refine (by (VALID ((set_tac "g" (`partial i f o (\k. (x + t3 % basis i) + k % basis j)`)))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN real_mvt0)(ISPEC_THEN (mk_var("g",mk_type("fun",[mk_type("real",[]);mk_type("real",[])]))) thm_tac))(ISPEC_THEN (`derivative g`) thm_tac))(ISPEC_THEN (mk_var("k",mk_type("real",[]))) thm_tac)) MP_TAC) THEN ALL_TAC))));; refine (by (VALID ((ANTS_TAC))));; refine (by (VALID (((BETA_TAC THEN (move ["t"]) THEN (move ["t_ineq"])) THEN ((USE_THM_THEN has_derivative_alt)(new_rewrite [] []))))));; refine (by (VALID ((((USE_THEN "g_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN diff2_partial_real_diff)(new_rewrite [] [])) THEN ((USE_THEN "d2f")(new_rewrite [] [])) THEN ((USE_THEN "rs")(new_rewrite [] []))))));; refine (by (VALID (((((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN ((USE_THEN "t_ineq")MP_TAC) THEN (clear_assumption "t_ineq") THEN ((USE_THEN "t3h")MP_TAC) THEN (clear_assumption "t3h") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((BETA_TAC THEN (case THEN (move ["t4"])) THEN (case THEN (move ["t4_ineq"])) THEN (move ["g_eq"])))));; refine (by (VALID (((THENL_LAST) (((exists_tac (mk_var("t3",mk_type("real",[])))) THEN (exists_tac (mk_var("t4",mk_type("real",[]))))) THEN ((USE_THEN "eq")(new_rewrite [] [])) THEN (split_tac)) ((((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN ((USE_THEN "t4_ineq")MP_TAC) THEN (clear_assumption "t4_ineq") THEN ((USE_THEN "t3h")MP_TAC) THEN (clear_assumption "t3h") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac))))));; refine (by (VALID ((set_tac "p" (`_1 - _2`)))));; refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`p = g k - g (&0)`)))));; refine (by (VALID (((((USE_THEN "p_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THEN "g_def")(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN VECTOR_MUL_LZERO)(new_rewrite [] [])) THEN ((USE_THM_THEN VECTOR_ADD_RID)(new_rewrite [] [])) THEN ((USE_THEN "v_eq")(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((((USE_THEN "g_eq")(new_rewrite [] [])) THEN ((USE_THM_THEN (REAL_ARITH `!a. h * a * k = h * k * a`))(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_MUL_ASSOC)(new_rewrite [] [])))))));; refine (by (VALID (((((USE_THM_THEN REAL_EQ_MUL_LCANCEL)(new_rewrite [] [])) THEN ((USE_THEN "g_def")(GSYM_THEN (new_rewrite [] [])))) THEN (DISJ2_TAC)))));; refine (by (VALID (((USE_THM_THEN derivative_translation)(new_rewrite [] [])))));; refine (by (VALID (((((USE_THM_THEN diff2_partial_real_diff)(new_rewrite [] [])) THEN ((USE_THEN "d2f")(new_rewrite [] [])) THEN ((USE_THEN "rs")(new_rewrite [] []))) THEN (((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN ((USE_THEN "t4_ineq")MP_TAC) THEN (clear_assumption "t4_ineq") THEN ((USE_THEN "t3h")MP_TAC) THEN (clear_assumption "t3h") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((((USE_THM_THEN partial)(new_rewrite [] [])) THEN (AP_THM_TAC) THEN (AP_TERM_TAC)))));; refine (by (VALID (((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN (GEN_ALL VECTOR_ADD_RDISTRIB))(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN (GEN_ALL VECTOR_ADD_ASSOC))(GSYM_THEN (new_rewrite [] []))))) THEN (move ["y"])))));; refine (by (VALID (((AP_TERM_TAC) THEN (VECTOR_ARITH_TAC) THEN (done_tac)))));; refine (by (VALID ((((USE_THEN "F2_def")MP_TAC) THEN (clear_assumption "F2_def") THEN ((USE_THEN "G_eq")MP_TAC) THEN (clear_assumption "G_eq") THEN ((USE_THEN "F2h")MP_TAC) THEN (clear_assumption "F2h") THEN ((USE_THEN "dF2")MP_TAC) THEN (clear_assumption "dF2") THEN ((USE_THEN "F2_der")MP_TAC) THEN (clear_assumption "F2_der") THEN ((USE_THEN "Gk")MP_TAC) THEN (clear_assumption "Gk") THEN BETA_TAC THEN (move ["_"]) THEN (move ["_"]) THEN (move ["_"]) THEN (move ["_"]) THEN (move ["_"]) THEN (move ["_"])))));; refine (by (VALID ((have_tac (move ["lim0"]) (`(vec 0:real^2) limit_point_of {y | &0 < y$1 /\ &0 < y$2}`)))));; refine (by (VALID (((((USE_THM_THEN limit_point_of)(new_rewrite [] [])) THEN ((USE_THM_THEN OPEN_CONTAINS_BALL)(new_rewrite [] [])) THEN ((USE_THM_THEN SUBSET)(new_rewrite [] [])) THEN ((USE_THM_THEN IN_BALL)(new_rewrite [] [])) THEN ((USE_THM_THEN dist)(new_rewrite [] []))) THEN (move ["t"]) THEN (case THEN (move ["v0t"]))))));; refine (by (VALID ((((fun thm_tac -> DISCH_THEN (fun fst_th ->(USE_THEN "v0t")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["e"])) THEN (case THEN (move ["e0"])) THEN (move ["in_t"])))));; refine (by (VALID ((set_tac "y" (`e / &2 % (vec 1:real^2)`)))));; refine (by (VALID (((THENL_FIRST) (have_tac (move ["yc"]) (`!i. y$i = e / (&2)`)) ((((USE_THEN "y_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN VECTOR_MUL_COMPONENT)(new_rewrite [] [])) THEN ((USE_THM_THEN VEC_COMPONENT)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_RID)(new_rewrite [] []))) THEN (done_tac))))));; refine (by (VALID (((THENL_FIRST) (have_tac (move ["ineq"]) (`&0 < e / (&2)`)) ((((USE_THM_THEN REAL_LT_DIV)(new_rewrite [] [])) THEN ((USE_THEN "e0")(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac))))));; refine (by (VALID ((have_tac (move ["inf_y"]) (`infnorm y = e / &2`)))));; refine (by (VALID (((((USE_THM_THEN (GEN_ALL INFNORM_2))(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THEN "yc")(new_rewrite [] []))) THEN ((USE_THM_THEN (GEN_ALL (CONJUNCT2 REAL_MAX_ACI)))(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_ABS_REFL)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LE_LT)(new_rewrite [] [])) THEN ((USE_THEN "ineq")(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((THENL_FIRST) ((exists_tac (mk_var("y",mk_type("cart",[mk_type("real",[]);mk_type("2",[])])))) THEN (split_tac)) ((((USE_THM_THEN INFNORM_EQ_0)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THEN "inf_y")(new_rewrite [] []))) 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) ((((USE_THM_THEN IN_ELIM_THM)(new_rewrite [] [])) THEN (simp_tac)) THEN (exists_tac (mk_var("y",mk_type("cart",[mk_type("real",[]);mk_type("2",[])])))) THEN (repeat_tactic 1 9 (((USE_THEN "yc")(new_rewrite [] []))) THEN ((USE_THEN "ineq")(new_rewrite [] []))) THEN (done_tac))))));; refine (by (VALID ((((USE_THEN "in_t")(new_rewrite [] [])) THEN (((USE_THM_THEN REAL_LET_TRANS)MP_TAC) THEN (clear_assumption "REAL_LET_TRANS") THEN (DISCH_THEN apply_tac)) THEN (exists_tac (`e * inv(&2) * sqrt(&2)`)) THEN (split_tac)))));; 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 (`infnorm y * sqrt (&2)`)) THEN (split_tac)))));; refine (by (VALID (((((USE_THM_THEN (GEN_ALL REAL_MUL_AC))(new_rewrite [] [])) THEN ((USE_THM_THEN NORM_SUB)(new_rewrite [] [])) THEN ((USE_THM_THEN (GEN_ALL VECTOR_SUB_RZERO))(new_rewrite [] [])) THEN ((USE_THM_THEN DIMINDEX_2)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN NORM_LE_INFNORM)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((((USE_THEN "inf_y")(new_rewrite [] [])) THEN ((USE_THM_THEN real_div)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_ASSOC)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN REAL_LE_REFL)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN REAL_MUL_RID)(ISPEC_THEN (mk_var("e",mk_type("real",[]))) thm_tac))(GSYM_THEN (new_rewrite [2] []))) THEN ((USE_THM_THEN REAL_LT_LMUL)(new_rewrite [] [])) THEN ((USE_THEN "e0")(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))))));; refine (by (VALID (((((fun thm_tac -> (USE_THM_THEN REAL_MUL_LINV)(ISPEC_THEN (`&2`) thm_tac))(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_LT_LMUL)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_LT_INV)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN andTb)(new_rewrite [] [])))) THEN ((TRY) (arith_tac))))));; refine (by (VALID (((THENL_FIRST) (have_tac (DISCH_THEN(new_rewrite [2] [])) (`&2 = sqrt (&2 * &2)`)) ((((USE_THM_THEN REAL_POW_2)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN POW_2_SQRT_ABS)(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac))))));; refine (by (VALID ((((USE_THM_THEN SQRT_MONO_LT)(new_rewrite [] [])) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((have_tac (move ["lim_ji"]) (`((\y:real^2. lift (G (y$1) (y$2) / (y$1 * y$2))) --> lift (partial j (partial i f) x)) (at (vec 0) within {y | &0 < y$1 /\ &0 < y$2})`)))));; refine (by (VALID ((((USE_THM_THEN LIM_WITHIN)(new_rewrite [] [])) THEN (move ["e"]) THEN (move ["e_gt0"])))));; refine (by (VALID (((((fun thm_tac -> (fun thm_tac -> (USE_THEN "pc")(ISPEC_THEN (mk_var("i",mk_type("num",[]))) thm_tac))(ISPEC_THEN (mk_var("j",mk_type("num",[]))) thm_tac))MP_TAC) THEN BETA_TAC) THEN ((((USE_THM_THEN (GEN_ALL continuous_at))(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN dist)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] [])))) THEN ((fun thm_tac -> DISCH_THEN (fun fst_th ->(USE_THEN "e_gt0")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN (case THEN (move ["d"])) THEN (case THEN (move ["d0"])) THEN (move ["e_ineq"]))))));; refine (by (VALID (((THENL_FIRST) ((exists_tac (`min r (d / &2)`)) THEN ((USE_THM_THEN REAL_LT_MIN)(new_rewrite [] [])) THEN (split_tac)) ((((USE_THEN "d0")MP_TAC) THEN (clear_assumption "d0") THEN ((USE_THEN "r0")MP_TAC) THEN (clear_assumption "r0") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac))))));; refine (by (VALID ((((simp_tac) THEN ((USE_THM_THEN (GEN_ALL VECTOR_SUB_RZERO))(new_rewrite [] []))) THEN (move ["y"]) THEN (move ["ineq"])))));; refine (by (VALID ((have_tac (move ["y0"]) (`&0 < abs (y$1) /\ &0 < abs (y$2)`)))));; refine (by (VALID (((((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN BETA_TAC) THEN ((((USE_THM_THEN IN_ELIM_THM)(new_rewrite [] [])) THEN (simp_tac)) THEN ALL_TAC THEN (case THEN ALL_TAC) THEN (case THEN (move ["z"])) THEN (case THEN (move ["z_ineq"])) THEN (DISCH_THEN(new_rewrite [] [])) THEN (move ["_"]))))));; refine (by (VALID (((((USE_THEN "z_ineq")MP_TAC) THEN (clear_assumption "z_ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((have_tac (move ["yr"]) (`abs (y$1) <= r /\ abs (y$2) <= r /\ abs (y$1) < d / &2 /\ abs (y$2) < d / &2`)))));; refine (by (VALID (((THENL_FIRST) (((THENL_ROT 1)) (have_tac ALL_TAC (`infnorm y < min r (d / &2)`))) (((USE_THM_THEN (GEN_ALL INFNORM_2))(new_rewrite [] [])) THEN (arith_tac) THEN (done_tac))))));; refine (by (VALID (((((USE_THM_THEN REAL_LET_TRANS)MP_TAC) THEN (clear_assumption "REAL_LET_TRANS") THEN (DISCH_THEN apply_tac)) THEN (exists_tac (`norm y`)) THEN ((USE_THM_THEN INFNORM_LE_NORM)(new_rewrite [] [])) THEN (done_tac)))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (USE_THEN "Gkh")(ISPEC_THEN (`y$1`) thm_tac))(ISPEC_THEN (`y$2`) thm_tac)) MP_TAC) THEN ALL_TAC))));; refine (by (VALID (((repeat_tactic 1 9 (((USE_THEN "yr")(new_rewrite [] []))) THEN (simp_tac)) THEN ALL_TAC THEN (case THEN (move ["t1"])) THEN (case THEN (move ["t2"])) THEN (case THEN (move ["G_eq"])) THEN (move ["t_ineq"])))));; refine (by (VALID ((((USE_THEN "G_eq")(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_ASSOC)(new_rewrite [] [])) THEN ((USE_THM_THEN (GEN_ALL REAL_MUL_AC))(new_rewrite [] [])) THEN ((USE_THM_THEN real_div)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_ASSOC)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN REAL_MUL_RINV)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_MUL_RID)(new_rewrite [] [])))))));; refine (by (VALID ((((USE_THM_THEN REAL_ENTIRE)(new_rewrite [] [])) THEN (((USE_THEN "y0")MP_TAC) THEN (clear_assumption "y0") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID (((((USE_THEN "e_ineq")MP_TAC) THEN (clear_assumption "e_ineq") THEN (DISCH_THEN apply_tac)) THEN ((USE_THM_THEN (GEN_ALL VECTOR_ADD_SUB))(new_rewrite [] []))))));; refine (by (VALID (((((USE_THM_THEN REAL_LET_TRANS)MP_TAC) THEN (clear_assumption "REAL_LET_TRANS") THEN (DISCH_THEN apply_tac)) THEN (exists_tac (`norm (t2 % basis j:real^N) + norm (t1 % basis i:real^N)`))))));; refine (by (VALID ((((USE_THM_THEN NORM_TRIANGLE)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN NORM_MUL)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN NORM_BASIS)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_MUL_RID)(new_rewrite [] [])))))));; refine (by (VALID (((((USE_THEN "yr")MP_TAC) THEN (clear_assumption "yr") THEN ((USE_THEN "t_ineq")MP_TAC) THEN (clear_assumption "t_ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((have_tac (move ["lim_ij"]) (`((\y:real^2. lift (G (y$1) (y$2) / (y$1 * y$2))) --> lift (partial i (partial j f) x)) (at (vec 0) within {y | &0 < y$1 /\ &0 < y$2})`)))));; refine (by (VALID ((((USE_THM_THEN LIM_WITHIN)(new_rewrite [] [])) THEN (move ["e"]) THEN (move ["e_gt0"])))));; refine (by (VALID (((((fun thm_tac -> (fun thm_tac -> (USE_THEN "pc")(ISPEC_THEN (mk_var("j",mk_type("num",[]))) thm_tac))(ISPEC_THEN (mk_var("i",mk_type("num",[]))) thm_tac))MP_TAC) THEN BETA_TAC) THEN ((((USE_THM_THEN (GEN_ALL continuous_at))(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN dist)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] [])))) THEN ((fun thm_tac -> DISCH_THEN (fun fst_th ->(USE_THEN "e_gt0")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN (case THEN (move ["d"])) THEN (case THEN (move ["d0"])) THEN (move ["e_ineq"]))))));; refine (by (VALID (((THENL_FIRST) ((exists_tac (`min r (d / &2)`)) THEN ((USE_THM_THEN REAL_LT_MIN)(new_rewrite [] [])) THEN (split_tac)) ((((USE_THEN "d0")MP_TAC) THEN (clear_assumption "d0") THEN ((USE_THEN "r0")MP_TAC) THEN (clear_assumption "r0") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac))))));; refine (by (VALID ((((simp_tac) THEN ((USE_THM_THEN (GEN_ALL VECTOR_SUB_RZERO))(new_rewrite [] []))) THEN (move ["y"]) THEN (move ["ineq"])))));; refine (by (VALID ((have_tac (move ["y0"]) (`&0 < abs (y$1) /\ &0 < abs (y$2)`)))));; refine (by (VALID (((((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN BETA_TAC) THEN ((((USE_THM_THEN IN_ELIM_THM)(new_rewrite [] [])) THEN (simp_tac)) THEN ALL_TAC THEN (case THEN ALL_TAC) THEN (case THEN (move ["z"])) THEN (case THEN (move ["z_ineq"])) THEN (DISCH_THEN(new_rewrite [] [])) THEN (move ["_"]))))));; refine (by (VALID (((((USE_THEN "z_ineq")MP_TAC) THEN (clear_assumption "z_ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((have_tac (move ["yr"]) (`abs (y$1) <= r /\ abs (y$2) <= r /\ abs (y$1) < d / &2 /\ abs (y$2) < d / &2`)))));; refine (by (VALID (((THENL_FIRST) (((THENL_ROT 1)) (have_tac ALL_TAC (`infnorm y < min r (d / &2)`))) (((USE_THM_THEN (GEN_ALL INFNORM_2))(new_rewrite [] [])) THEN (arith_tac) THEN (done_tac))))));; refine (by (VALID (((((USE_THM_THEN REAL_LET_TRANS)MP_TAC) THEN (clear_assumption "REAL_LET_TRANS") THEN (DISCH_THEN apply_tac)) THEN (exists_tac (`norm y`)) THEN ((USE_THM_THEN INFNORM_LE_NORM)(new_rewrite [] [])) THEN (done_tac)))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (USE_THEN "Ghk")(ISPEC_THEN (`y$1`) thm_tac))(ISPEC_THEN (`y$2`) thm_tac)) MP_TAC) THEN ALL_TAC))));; refine (by (VALID (((repeat_tactic 1 9 (((USE_THEN "yr")(new_rewrite [] []))) THEN (simp_tac)) THEN ALL_TAC THEN (case THEN (move ["t1"])) THEN (case THEN (move ["t2"])) THEN (case THEN (move ["G_eq"])) THEN (move ["t_ineq"])))));; refine (by (VALID ((((USE_THEN "G_eq")(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_ASSOC)(new_rewrite [] [])) THEN ((USE_THM_THEN (GEN_ALL REAL_MUL_AC))(new_rewrite [] [])) THEN ((USE_THM_THEN real_div)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_MUL_ASSOC)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN REAL_MUL_RINV)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_MUL_RID)(new_rewrite [] [])))))));; refine (by (VALID ((((USE_THM_THEN REAL_ENTIRE)(new_rewrite [] [])) THEN (((USE_THEN "y0")MP_TAC) THEN (clear_assumption "y0") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID (((((USE_THEN "e_ineq")MP_TAC) THEN (clear_assumption "e_ineq") THEN (DISCH_THEN apply_tac)) THEN ((USE_THM_THEN (GEN_ALL VECTOR_ADD_SUB))(new_rewrite [] []))))));; refine (by (VALID (((((USE_THM_THEN REAL_LET_TRANS)MP_TAC) THEN (clear_assumption "REAL_LET_TRANS") THEN (DISCH_THEN apply_tac)) THEN (exists_tac (`norm (t1 % basis j:real^N) + norm (t2 % basis i:real^N)`))))));; refine (by (VALID ((((USE_THM_THEN NORM_TRIANGLE)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN NORM_MUL)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN NORM_BASIS)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_MUL_RID)(new_rewrite [] [])))))));; refine (by (VALID (((((USE_THEN "yr")MP_TAC) THEN (clear_assumption "yr") THEN ((USE_THEN "t_ineq")MP_TAC) THEN (clear_assumption "t_ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((((USE_THM_THEN LIFT_EQ)(GSYM_THEN (new_rewrite [] []))) THEN ((fun thm_tac -> (USE_THM_THEN LIM_UNIQUE)(ISPEC_THEN (`at (vec 0:real^2) within {y:real^2 | &0 < y$1 /\ &0 < y$2}`) thm_tac)) apply_tac)))));; refine (by (VALID ((exists_tac (`\y:real^2. lift (G (y$1) (y$2) / (y$1 * y$2))`)))));; refine (by (VALID (((((USE_THM_THEN (GEN_ALL TRIVIAL_LIMIT_WITHIN))(new_rewrite [] [])) THEN ((USE_THM_THEN negbK)(new_rewrite [] [])) THEN ((USE_THEN "lim0")(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (done_tac)))));; let mixed_second_partials = end_section_proof();; let m_cell_domain = new_definition `m_cell_domain (x:real^N, z:real^N) (y:real^N) (w:real^N) <=> !i. i IN 1..dimindex (:N) ==> x$i <= y$i /\ y$i <= z$i /\ max (y$i - x$i) (z$i - y$i) <= w$i`;; let m_bounded_on_int = new_definition `m_bounded_on_int (f:real^N->real) domain f_bounds <=> !x. x IN interval [domain] ==> interval_arith (f x) f_bounds`;; let diff2_domain = new_definition `diff2_domain domain f <=> !x. x IN interval [domain] ==> diff2 f x`;; let diff2c_domain = new_definition `diff2c_domain domain f <=> !x. x IN interval [domain] ==> diff2c f x`;; (start_section_proof ["f";"domain"](`diff2c_domain domain f <=> diff2_domain domain f /\ (!x. x IN interval [domain] ==> !i j. (lift o partial2 j i f) continuous at x)`));; refine (by (VALID (((((USE_THM_THEN diff2c_domain)(new_rewrite [] [])) THEN ((USE_THM_THEN diff2c)(new_rewrite [] [])) THEN ((USE_THM_THEN diff2_domain)(new_rewrite [] []))) THEN ((split_tac) THENL [(move ["h1"]); ((case THEN ((move ["h1"]) THEN (move ["h2"]))) THEN (move ["x"]) THEN (move ["h3"]))])))));; refine (by (VALID ((((split_tac) THEN (move ["x"]) THEN (DISCH_THEN (fun snd_th -> (USE_THEN "h1")(MATCH_MP_THEN snd_th MP_TAC))) THEN (simp_tac)) THEN (done_tac)))));; refine (by (VALID (((((fun thm_tac -> (USE_THEN "h1")(fun fst_th ->(USE_THEN "h3")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN ((fun thm_tac -> (USE_THEN "h2")(fun fst_th ->(USE_THEN "h3")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (simp_tac)) THEN (done_tac)))));; let diff2c_domain_alt = end_section_proof();; (start_section_proof ["domain";"y";"w"](`m_cell_domain domain y w ==> y IN interval [domain]`));; refine (by (VALID ((((disch_tm_tac [](mk_var("domain",mk_type("prod",[mk_type("cart",[mk_type("real",[]);mk_vartype "?1457984"]);mk_type("cart",[mk_type("real",[]);mk_vartype "?1457984"])])))) THEN (clear_assumption "domain") THEN case THEN (move ["x"]) THEN (move ["z"])) THEN ((((USE_THM_THEN m_cell_domain)(new_rewrite [] [])) THEN ((USE_THM_THEN (GEN_ALL IN_INTERVAL))(new_rewrite [] [])) THEN ((USE_THM_THEN IN_NUMSEG)(new_rewrite [] []))) THEN (move ["ineqs"]) THEN (move ["i"]))))));; refine (by (VALID ((((DISCH_THEN (fun snd_th -> (USE_THEN "ineqs")(MATCH_MP_THEN snd_th MP_TAC))) THEN BETA_TAC THEN (simp_tac)) THEN (done_tac)))));; let y_in_domain = end_section_proof();; (start_section_proof ["p";"domain";"y";"w"](`m_cell_domain domain y (w:real^N) ==> p IN interval [domain] ==> !i. i IN 1..dimindex (:N) ==> abs (p$i - y$i) <= w$i`));; refine (by (VALID ((((disch_tm_tac [](mk_var("domain",mk_type("prod",[mk_type("cart",[mk_type("real",[]);mk_vartype "N"]);mk_type("cart",[mk_type("real",[]);mk_vartype "N"])])))) THEN (clear_assumption "domain") THEN case THEN (move ["x"]) THEN (move ["z"])) THEN (((USE_THM_THEN m_cell_domain)(new_rewrite [] [])) THEN (move ["ineqs"]) THEN (move ["p_in"]) THEN (move ["i"]) THEN (move ["i_in"]))))));; refine (by (VALID (((((fun thm_tac -> (USE_THEN "ineqs")(fun fst_th ->(USE_THEN "i_in")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN ((USE_THEN "p_in")MP_TAC) THEN (clear_assumption "p_in") THEN BETA_TAC) THEN ((((USE_THM_THEN (GEN_ALL IN_INTERVAL))(new_rewrite [] [])) THEN ((USE_THM_THEN IN_NUMSEG)(GSYM_THEN (new_rewrite [] [])))) THEN ((fun thm_tac -> DISCH_THEN (fun fst_th ->(USE_THEN "i_in")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC)) THEN (arith_tac) THEN (done_tac)))));; let domain_width = end_section_proof();; (start_section_proof ["g";"n"](`sum (1..n) (\i. sum (i + 1..n) (\j. g i j)) = sum (1..n) (\i. sum (1..i - 1) (\j. g j i))`));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN SUM_SUM_PRODUCT)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN FINITE_NUMSEG)(new_rewrite [] []))) THEN ((simp_tac THEN TRY done_tac)) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_NUMSEG)(new_rewrite [] [])))))));; refine (by (VALID ((set_tac "s1" (`{i, j | (1 <= i /\ i <= n) /\ i + 1 <= j /\ j <= n}`)))));; refine (by (VALID ((set_tac "s2" (`{i, j | (1 <= i /\ i <= n) /\ 1 <= j /\ j <= i - 1}`)))));; refine (by (VALID ((set_tac "f" (`\(i,j):num#num. j, i`)))));; refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`s1 = IMAGE f s2`)))));; refine (by (VALID ((((((USE_THEN "s1_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THEN "s2_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THEN "f_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN EXTENSION)(new_rewrite [] [])) THEN ((USE_THM_THEN IN_IMAGE)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_ELIM_THM)(new_rewrite [] []))) THEN (simp_tac)) THEN (move ["p"])) THEN (split_tac)))));; refine (by (VALID ((BETA_TAC THEN (case THEN (move ["i"])) THEN (case THEN (move ["j"])) THEN (case THEN (move ["ineq"])) THEN (move ["p_eq"])))));; refine (by (VALID (((exists_tac (`j, i`)) THEN (((USE_THEN "p_eq")(new_rewrite [] [])) THEN (simp_tac)) THEN ((exists_tac (mk_var("j",mk_type("num",[])))) THEN (exists_tac (mk_var("i",mk_type("num",[]))))) THEN (((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((BETA_TAC THEN (case THEN (move ["p1"])) THEN (case THEN (move ["p_eq"])) THEN (case THEN (move ["i"])) THEN (case THEN (move ["j"])) THEN (case THEN (move ["ineq"])) THEN (move ["p1_eq"])))));; refine (by (VALID ((((exists_tac (mk_var("j",mk_type("num",[])))) THEN (exists_tac (mk_var("i",mk_type("num",[]))))) THEN (((USE_THEN "p_eq")(new_rewrite [] [])) THEN ((USE_THEN "p1_eq")(new_rewrite [] [])) THEN (simp_tac)) THEN (((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`(\(i,j). g j i) = (\(i,j). g i j) o f`)))));; refine (by (VALID (((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN o_THM)(new_rewrite [] [])) THEN ((USE_THEN "f_def")(GSYM_THEN (new_rewrite [] [])))) THEN case THEN (done_tac)))));; refine (by (VALID ((((USE_THM_THEN SUM_IMAGE) apply_tac) THEN (case THEN (move ["i1"]) THEN (move ["j1"])) THEN (case THEN (move ["i2"]) THEN (move ["j2"]))))));; refine (by (VALID ((((((USE_THEN "f_def")(GSYM_THEN (new_rewrite [] []))) THEN (simp_tac) THEN repeat_tactic 1 9 (((USE_THM_THEN PAIR_EQ)(new_rewrite [] [])))) THEN ALL_TAC THEN (case THEN (move ["_"])) THEN (case THEN (move ["_"])) THEN (case THEN ((DISCH_THEN(new_rewrite [] [])) THEN (DISCH_THEN(new_rewrite [] []))))) THEN (done_tac)))));; let sum_swap1 = end_section_proof();; (start_section_proof ["f";"domain";"w";"error"](`diff2c_domain domain f ==> (m_taylor_error f domain (w:real^N) error <=> (!x. x IN interval [domain] ==> sum (1..dimindex (:N)) (\i. w$i * (w$i * abs (partial2 i i f x) + &2 * sum (1..i - 1) (\j. w$j * abs (partial2 j i f x)))) <= error))`));; refine (by (VALID (((((USE_THM_THEN diff2c_domain)(new_rewrite [] [])) THEN ((USE_THM_THEN m_taylor_error)(new_rewrite [] []))) THEN (move ["d2f"])))));; refine (by (VALID ((have_tac (move ["eq"]) (`!g1 g2. (!x. x IN interval [domain] ==> g1 x = g2 x) ==> ((!x. x IN interval [domain] ==> g1 x <= error) <=> (!x. x IN interval [domain] ==> g2 x <= error))`)))));; refine (by (VALID (((BETA_TAC THEN (move ["g1"]) THEN (move ["g2"]) THEN (move ["eq"])) THEN ((split_tac) THEN (move ["cond"]) THEN (move ["x"]) THEN (move ["Px"]))))));; refine (by (VALID (((((USE_THEN "eq")(GSYM_THEN (new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THEN "cond")(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((((USE_THEN "eq")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THEN "cond")(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((((USE_THEN "eq")MP_TAC) THEN (clear_assumption "eq") THEN (DISCH_THEN apply_tac) THEN (move ["x"]) THEN (DISCH_THEN (fun snd_th -> (USE_THEN "d2f")(MATCH_MP_THEN snd_th MP_TAC))) THEN (move ["d2fx"])))));; refine (by (VALID ((set_tac "g" (`\i j. w$i * w$j * abs (partial2 j i f x)`)))));; refine (by (VALID ((set_tac "n" (`dimindex (:N)`)))));; refine (by (VALID ((set_tac "s1" (`sum _1 _2`)))));; refine (by (VALID ((have_tac (move ["s1_eq"]) (`s1 = sum (1..n) (\i. sum (1..n) (\j. g i j))`)))));; refine (by (VALID ((((USE_THEN "s1_def")(GSYM_THEN (new_rewrite [] []))) THEN (((USE_THM_THEN SUM_EQ) apply_tac) THEN (move ["i"]) THEN (simp_tac) THEN (move ["i_in"]))))));; refine (by (VALID (((((USE_THM_THEN SUM_LMUL)(GSYM_THEN (new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THEN "g_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN partial2)(new_rewrite [] []))) THEN ((USE_THM_THEN SUM_EQ) apply_tac) THEN (done_tac)))));; refine (by (VALID ((((USE_THM_THEN REAL_MUL_2)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_ADD_LDISTRIB)(new_rewrite [] []))) THEN ((USE_THM_THEN SUM_LMUL)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN REAL_ADD_ASSOC)(new_rewrite [] [])) THEN ((USE_THM_THEN SUM_ADD_NUMSEG)(new_rewrite [] [])) THEN (simp_tac)))));; refine (by (VALID ((set_tac "s2" (`sum _1 _2`)))));; refine (by (VALID (((THENL_FIRST) (have_tac (move ["s2_eq"]) (`s2 = sum (1..n) (\i. g i i + sum (1..i - 1) (\j. g i j))`)) ((((USE_THEN "s2_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THEN "g_def")(GSYM_THEN (new_rewrite [] [])))) THEN (done_tac))))));; refine (by (VALID ((set_tac "s3" (`sum _1 _2`)))));; refine (by (VALID (((THENL_FIRST) (have_tac (move ["s3_eq"]) (`s3 = sum (1..n) (\i. sum (1..i - 1) (\j. g i j))`)) ((((USE_THEN "s3_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THEN "g_def")(GSYM_THEN (new_rewrite [] [])))) THEN (done_tac))))));; refine (by (VALID ((((USE_THEN "s3_def")MP_TAC) THEN (clear_assumption "s3_def") THEN ((USE_THEN "s2_def")MP_TAC) THEN (clear_assumption "s2_def") THEN ((USE_THEN "s1_def")MP_TAC) THEN (clear_assumption "s1_def") THEN BETA_TAC THEN (move ["_"]) THEN (move ["_"]) THEN (move ["_"])))));; refine (by (VALID ((((THENL_ROT 1)) (have_tac (DISCH_THEN(new_rewrite [] [])) (`s3 = sum (1..n) (\i. sum (i + 1..n) (\j. g i j))`))))));; refine (by (VALID (((((USE_THEN "s2_eq")(new_rewrite [] [])) THEN ((USE_THM_THEN SUM_ADD_NUMSEG)(GSYM_THEN (new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THEN "s1_eq")(new_rewrite [] []))) THEN (((USE_THM_THEN SUM_EQ) apply_tac) THEN (move ["i"]) THEN (simp_tac)) THEN (((USE_THM_THEN IN_NUMSEG)(new_rewrite [] [])) THEN (move ["i_ineq"]))))));; refine (by (VALID (((((USE_THM_THEN (REAL_ARITH `!a b c. (a + b) + c = (a + c) + b`))(new_rewrite [] [])) THEN ((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN SUM_SING_NUMSEG)(ISPEC_THEN (`g i`) thm_tac))(ISPEC_THEN (mk_var("i",mk_type("num",[]))) thm_tac))(GSYM_THEN (new_rewrite [] [])))) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th]))))));; refine (by (VALID (((THENL_FIRST) (((USE_THM_THEN SUM_COMBINE_R)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "i_ineq")(new_rewrite [] [])))) ((arith_tac) THEN (done_tac))))));; refine (by (VALID (((((USE_THM_THEN (GEN_ALL REAL_ADD_AC))(new_rewrite [] [])) THEN ((USE_THM_THEN SUM_COMBINE_L)(new_rewrite [] [])) THEN ((TRY done_tac))) THEN (((USE_THEN "i_ineq")MP_TAC) THEN (clear_assumption "i_ineq") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID (((((USE_THEN "s3_eq")(new_rewrite [] [])) THEN ((USE_THM_THEN sum_swap1)(new_rewrite [] []))) THEN (((USE_THM_THEN SUM_EQ) apply_tac) THEN (move ["i"]) THEN (move ["_"]) THEN (simp_tac)) THEN (((USE_THM_THEN SUM_EQ) apply_tac) THEN (move ["j"]) THEN (move ["_"]) THEN (simp_tac))))));; refine (by (VALID (((((USE_THEN "g_def")(GSYM_THEN (new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN (REAL_ARITH `!a b c. a * b * c = b * a * c`))(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_EQ_MUL_LCANCEL)(new_rewrite [] [])))) THEN (DISJ2_TAC) THEN (DISJ2_TAC)))));; refine (by (VALID ((((USE_THM_THEN mixed_second_partials)(new_rewrite [] [])) THEN (done_tac)))));; let m_taylor_error_eq = end_section_proof();; (start_section_proof ["domain";"y";"w";"p";"f";"dd_bound"](`m_cell_domain domain y (w:real^N) ==> p IN interval [domain] ==> diff2_domain domain f ==> m_taylor_error f domain w dd_bound ==> (!t. interval_arith t (&0, &1) ==> abs (nth_derivative 2 (f o (\t. y + t % (p - y))) t) <= dd_bound)`));; refine (by (VALID (((((USE_THM_THEN diff2_domain)(new_rewrite [] [])) THEN ((USE_THM_THEN m_taylor_error)(new_rewrite [] []))) THEN (move ["domainH"]) THEN (move ["p_in"]) THEN (move ["df"]) THEN (move ["boundedH"]) THEN (move ["t"]) THEN (move ["t_in"])))));; refine (by (VALID ((have_tac (move ["pt_in"]) (`y + t % (p - y) IN interval [domain]`)))));; refine (by (VALID ((((USE_THM_THEN (VECTOR_ARITH `y + t % (p - y) = (&1 - t) % y + t % p:real^N`))(new_rewrite [] [])) THEN ((USE_THM_THEN IN_CONVEX_SET)(new_rewrite [] []))))));; refine (by (VALID (((((fun thm_tac -> (USE_THM_THEN y_in_domain)(fun fst_th ->(USE_THEN "domainH")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] [])) THEN ((USE_THEN "p_in")(new_rewrite [] [])) THEN ((USE_THM_THEN interval_arith)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THEN "t_in")(new_rewrite [] [])) THEN ((USE_THM_THEN pair_eq)(new_rewrite [] [])) THEN ((USE_THM_THEN CONVEX_INTERVAL)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((((USE_THM_THEN diff2_dir_derivative2)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] []))) THEN ((TRY done_tac))))));; refine (by (VALID (((((USE_THM_THEN o_THM)(new_rewrite [] [])) THEN (simp_tac)) THEN (((fun thm_tac -> (USE_THEN "boundedH")(fun fst_th ->(USE_THEN "pt_in")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC)))));; refine (by (VALID (((set_tac "s1" (`sum _1 _2`)) THEN ((set_tac "s2" (`sum _1 _2`)) THEN (move ["i1"]))))));; 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 (mk_var("s1",mk_type("real",[])))) THEN (((USE_THEN "i1")(new_rewrite [] [])) THEN ((USE_THM_THEN andbT)(new_rewrite [] [])) THEN ((USE_THEN "s1_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THEN "s2_def")(GSYM_THEN (new_rewrite [] []))))))));; refine (by (VALID (((((USE_THM_THEN SUM_ABS_LE)(new_rewrite [] [])) THEN ((USE_THM_THEN FINITE_NUMSEG)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (move ["i"]) THEN (move ["i_ineq"]) THEN (simp_tac)))));; refine (by (VALID (((((USE_THM_THEN SUM_LMUL)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN SUM_ABS_LE)(new_rewrite [] [])) THEN ((USE_THM_THEN FINITE_NUMSEG)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (move ["j"]) THEN (move ["j_ineq"]) THEN (simp_tac)))));; refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN REAL_ABS_MUL)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_LE_MUL2)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_LE_MUL)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_ABS_POS)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN VECTOR_SUB_COMPONENT)(new_rewrite [] []))) THEN (((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN domain_width)(fun fst_th ->(USE_THEN "domainH")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "p_in")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN REAL_LE_REFL)(new_rewrite [] []))) THEN (done_tac)))));; let diff2_derivative2_bound = end_section_proof();; (start_section_proof ["domain";"y";"w";"p";"f";"dd_bound"](`m_cell_domain domain y (w:real^N) ==> p IN interval [domain] ==> diff2_domain domain f ==> m_taylor_error f domain w dd_bound ==> abs (f p - (f y + sum (1..dimindex (:N)) (\i. (p - y)$i * partial i f y))) <= dd_bound / &2`));; refine (by (VALID ((((USE_THM_THEN diff2_domain)(new_rewrite [] [])) THEN (BETA_TAC THEN (move ["domainH"]) THEN (move ["p_in"]) THEN (move ["df"]) THEN (move ["taylor_error"]))))));; refine (by (VALID ((have_tac (move ["pt_in"]) (`!t. interval_arith t (&0, &1) ==> y + t % (p - y) IN interval [domain]`)))));; refine (by (VALID (((BETA_TAC THEN (move ["t"]) THEN (move ["t_in"])) THEN (((USE_THM_THEN (VECTOR_ARITH `y + t % (p - y) = (&1 - t) % y + t % p:real^N`))(new_rewrite [] [])) THEN ((USE_THM_THEN IN_CONVEX_SET)(new_rewrite [] [])))))));; refine (by (VALID (((((fun thm_tac -> (USE_THM_THEN y_in_domain)(fun fst_th ->(USE_THEN "domainH")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] [])) THEN ((USE_THEN "p_in")(new_rewrite [] [])) THEN ((USE_THM_THEN interval_arith)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THEN "t_in")(new_rewrite [] [])) THEN ((USE_THM_THEN pair_eq)(new_rewrite [] [])) THEN ((USE_THM_THEN CONVEX_INTERVAL)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN real_taylor2_bound)(ISPEC_THEN (`f o (\t. y + t % (p - y))`) thm_tac))(ISPEC_THEN (mk_var("dd_bound",mk_type("real",[]))) thm_tac))MP_TAC) THEN BETA_TAC))));; refine (by (VALID (((THENL_FIRST) (ANTS_TAC) ((((USE_THM_THEN nth_diff_strong_int)(new_rewrite [] [])) THEN (move ["t"]) THEN (move ["t_in"])) THEN (((USE_THM_THEN diff2_dir)(new_rewrite [] [])) THEN ((USE_THEN "df")(new_rewrite [] [])) THEN ((USE_THEN "pt_in")(new_rewrite [] []))) THEN (done_tac))))));; refine (by (VALID (((THENL_FIRST) (ANTS_TAC) ((((fun thm_tac -> (USE_THM_THEN diff2_derivative2_bound)(fun fst_th ->(USE_THEN "domainH")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN (DISCH_THEN apply_tac)) THEN ((USE_THM_THEN diff2_domain)(new_rewrite [] [])) THEN (done_tac))))));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN VECTOR_MUL_LID)(new_rewrite [] [])) THEN ((USE_THM_THEN VECTOR_MUL_LZERO)(new_rewrite [] [])) THEN ((USE_THM_THEN VECTOR_ADD_RID)(new_rewrite [] [])) THEN ((USE_THM_THEN (GEN_ALL VECTOR_SUB_ADD2))(new_rewrite [] []))))));; refine (by (VALID (((THENL_FIRST) (((USE_THM_THEN diff2_dir_derivative)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "pt_in")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN interval_arith)(new_rewrite [] [])))) ((arith_tac) THEN (done_tac))))));; refine (by (VALID (((((USE_THM_THEN o_THM)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN VECTOR_MUL_LZERO)(new_rewrite [] [])) THEN ((USE_THM_THEN VECTOR_ADD_RID)(new_rewrite [] []))) THEN (done_tac)))));; let m_taylor_error_lemma = end_section_proof();; (start_section_proof ["domain";"y";"w";"f";"dd_bound";"hi";"hi_bound"](`m_cell_domain domain y (w:real^N) ==> diff2_domain domain f ==> m_taylor_error f domain w dd_bound ==> f y <= hi ==> hi + sum(1..dimindex (:N)) (\i. w$i * abs (partial i f y)) + dd_bound / &2 <= hi_bound ==> !p. p IN interval [domain] ==> f p <= hi_bound`));; refine (by (VALID ((BETA_TAC THEN (move ["domainH"]) THEN (move ["df"]) THEN (move ["errorH"]) THEN (move ["f_bound"]) THEN (move ["total_bound"]) THEN (move ["p"]) THEN (move ["p_in"])))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN m_taylor_error_lemma)(fun fst_th ->(USE_THEN "domainH")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "p_in")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "df")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "errorH")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC))));; refine (by (VALID (((DISCH_THEN (fun snd_th -> (USE_THM_THEN (REAL_ARITH `!x y e. abs (x - y) <= e ==> x <= y + e`))(MATCH_MP_THEN snd_th MP_TAC))) THEN BETA_TAC))));; refine (by (VALID (((set_tac "s" (`sum _1 _2`)) 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 (`(f y + s) + dd_bound / &2`)) THEN (((USE_THEN "ineq")(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] [])))))));; refine (by (VALID ((((USE_THEN "total_bound")MP_TAC) THEN (clear_assumption "total_bound") THEN ((USE_THM_THEN (REWRITE_RULE[GSYM IMP_IMP] REAL_LE_TRANS))MP_TAC) THEN (DISCH_THEN apply_tac)))));; refine (by (VALID ((((USE_THM_THEN REAL_ADD_ASSOC)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LE_RADD)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LE_ADD2)(new_rewrite [] [])) THEN ((USE_THEN "f_bound")(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))))));; 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 s`)) THEN (((USE_THM_THEN REAL_ABS_LE)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] [])))))));; refine (by (VALID (((((USE_THEN "s_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN SUM_ABS_LE)(new_rewrite [] [])) THEN ((USE_THM_THEN FINITE_NUMSEG)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (move ["i"]) THEN (move ["i_ineq"]) THEN (simp_tac)))));; refine (by (VALID (((((USE_THM_THEN REAL_ABS_MUL)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LE_MUL2)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_ABS_POS)(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_LE_REFL)(new_rewrite [] [])) THEN ((USE_THM_THEN VECTOR_SUB_COMPONENT)(new_rewrite [] [])) THEN ((fun thm_tac -> (USE_THM_THEN domain_width)(fun fst_th ->(USE_THEN "domainH")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] []))) THEN (done_tac)))));; let m_taylor_upper_bound = end_section_proof();; (start_section_proof ["domain";"y";"w";"f";"dd_bound";"lo";"lo_bound"](`m_cell_domain domain y (w:real^N) ==> diff2_domain domain f ==> m_taylor_error f domain w dd_bound ==> lo <= f y ==> lo_bound <= lo - (sum(1..dimindex (:N)) (\i. w$i * abs (partial i f y)) + dd_bound / &2) ==> !p. p IN interval [domain] ==> lo_bound <= f p`));; refine (by (VALID ((BETA_TAC THEN (move ["domainH"]) THEN (move ["df"]) THEN (move ["errorH"]) THEN (move ["f_bound"]) THEN (move ["total_bound"]) THEN (move ["p"]) THEN (move ["p_in"])))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN m_taylor_error_lemma)(fun fst_th ->(USE_THEN "domainH")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "p_in")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "df")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "errorH")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC))));; refine (by (VALID (((DISCH_THEN (fun snd_th -> (USE_THM_THEN (REAL_ARITH `!x y e. abs (x - y) <= e ==> y - e <= x`))(MATCH_MP_THEN snd_th MP_TAC))) THEN BETA_TAC))));; refine (by (VALID (((set_tac "s" (`sum _1 _2`)) 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 (`(f y + s) - dd_bound / &2`)) THEN (((USE_THEN "ineq")(new_rewrite [] [])) THEN ((USE_THM_THEN andbT)(new_rewrite [] [])))))));; refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN (REWRITE_RULE[GSYM IMP_IMP] REAL_LE_TRANS))(fun fst_th ->(USE_THEN "total_bound")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN (DISCH_THEN apply_tac)))));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN real_sub)(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_NEG_ADD)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_ADD_ASSOC)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LE_RADD)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LE_ADD2)(new_rewrite [] [])) THEN ((USE_THEN "f_bound")(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))))));; refine (by (VALID (((THENL_LAST) ((((USE_THM_THEN REAL_LE_TRANS)MP_TAC) THEN (clear_assumption "REAL_LE_TRANS") THEN (DISCH_THEN apply_tac)) THEN (exists_tac (`--abs s`)) THEN ((USE_THM_THEN REAL_LE_NEG)(new_rewrite [] [])) THEN (split_tac)) ((arith_tac) THEN (done_tac))))));; refine (by (VALID (((((USE_THEN "s_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN SUM_ABS_LE)(new_rewrite [] [])) THEN ((USE_THM_THEN FINITE_NUMSEG)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (move ["i"]) THEN (move ["i_ineq"]) THEN (simp_tac)))));; refine (by (VALID (((((USE_THM_THEN REAL_ABS_MUL)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LE_MUL2)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_ABS_POS)(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_LE_REFL)(new_rewrite [] [])) THEN ((USE_THM_THEN VECTOR_SUB_COMPONENT)(new_rewrite [] [])) THEN ((fun thm_tac -> (USE_THM_THEN domain_width)(fun fst_th ->(USE_THEN "domainH")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] []))) THEN (done_tac)))));; let m_taylor_lower_bound = end_section_proof();; (start_section_proof ["domain";"y";"w";"f";"dd_bound";"lo";"hi";"err_bound";"lo_bound";"hi_bound"](`m_cell_domain domain y (w:real^N) ==> diff2_domain domain f ==> m_taylor_error f domain w dd_bound ==> interval_arith (f y) (lo, hi) ==> sum(1..dimindex (:N)) (\i. w$i * abs(partial i f y)) + dd_bound / &2 <= err_bound ==> lo_bound <= lo - err_bound ==> hi + err_bound <= hi_bound ==> m_bounded_on_int f domain (lo_bound, hi_bound)`));; refine (by (VALID (((((USE_THM_THEN m_bounded_on_int)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN interval_arith)(new_rewrite [] [])))) THEN (move ["domainH"]) THEN (move ["df"]) THEN (move ["errorH"]) THEN (case THEN ((move ["f_lo"]) THEN (move ["f_hi"]))) THEN (move ["err"]) THEN (move ["lo_ineq"]) THEN (move ["hi_ineq"]) THEN (move ["p"]) THEN (move ["p_in"])))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN m_taylor_lower_bound)(fun fst_th ->(USE_THEN "domainH")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "df")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "errorH")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "f_lo")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(ISPEC_THEN (mk_var("lo_bound",mk_type("real",[]))) thm_tac))MP_TAC) THEN BETA_TAC THEN (DISCH_THEN(new_rewrite [] []))))));; refine (by (VALID (((((USE_THEN "p_in")(new_rewrite [] [])) THEN ((USE_THM_THEN andbT)(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 (`lo - err_bound`))))));; refine (by (VALID (((((USE_THEN "lo_ineq")(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN real_sub)(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_LE_ADD2)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LE_REFL)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LE_NEG)(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 m_taylor_upper_bound)(fun fst_th ->(USE_THEN "domainH")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "df")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "errorH")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "f_hi")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(ISPEC_THEN (mk_var("hi_bound",mk_type("real",[]))) thm_tac))MP_TAC) THEN BETA_TAC THEN (DISCH_THEN(new_rewrite [] [])) THEN ((TRY done_tac))))));; refine (by (VALID (((((USE_THEN "p_in")(new_rewrite [] [])) THEN ((USE_THM_THEN andbT)(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 (`hi + err_bound`))))));; refine (by (VALID (((((USE_THEN "hi_ineq")(new_rewrite [] [])) THEN ((USE_THM_THEN andbT)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LE_LADD)(new_rewrite [] []))) THEN (done_tac)))));; let m_taylor_bounds = end_section_proof();; (start_section_proof ["domain";"y";"w";"p";"f";"i";"d_bound"](`m_cell_domain domain y (w:real^N) ==> p IN interval [domain] ==> diff2_domain domain f ==> m_taylor_partial_error f i domain w d_bound ==> (!t. interval_arith t (&0, &1) ==> abs (derivative (partial i f o (\t. y + t % (p - y))) t) <= d_bound)`));; refine (by (VALID (((((USE_THM_THEN diff2_domain)(new_rewrite [] [])) THEN ((USE_THM_THEN m_taylor_partial_error)(new_rewrite [] []))) THEN (move ["domainH"]) THEN (move ["p_in"]) THEN (move ["df"]) THEN (move ["boundedH"]) THEN (move ["t"]) THEN (move ["t_in"])))));; refine (by (VALID ((have_tac (move ["pt_in"]) (`y + t % (p - y) IN interval [domain]`)))));; refine (by (VALID ((((USE_THM_THEN (VECTOR_ARITH `y + t % (p - y) = (&1 - t) % y + t % p:real^N`))(new_rewrite [] [])) THEN ((USE_THM_THEN IN_CONVEX_SET)(new_rewrite [] []))))));; refine (by (VALID (((((fun thm_tac -> (USE_THM_THEN y_in_domain)(fun fst_th ->(USE_THEN "domainH")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] [])) THEN ((USE_THEN "p_in")(new_rewrite [] [])) THEN ((USE_THM_THEN interval_arith)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THEN "t_in")(new_rewrite [] [])) THEN ((USE_THM_THEN pair_eq)(new_rewrite [] [])) THEN ((USE_THM_THEN CONVEX_INTERVAL)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((((USE_THM_THEN diff2_derivative_partial)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] []))) THEN ((TRY done_tac))))));; refine (by (VALID ((((fun thm_tac -> (USE_THEN "boundedH")(fun fst_th ->(USE_THEN "pt_in")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN ((USE_THM_THEN (REWRITE_RULE[GSYM IMP_IMP] REAL_LE_TRANS))MP_TAC) THEN (DISCH_THEN apply_tac)))));; refine (by (VALID (((((USE_THM_THEN SUM_ABS_LE)(new_rewrite [] [])) THEN ((USE_THM_THEN FINITE_NUMSEG)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (move ["j"]) THEN (move ["j_ineq"]) THEN (simp_tac)))));; refine (by (VALID ((((USE_THM_THEN REAL_ABS_MUL)(new_rewrite [] [])) THEN ((USE_THM_THEN o_THM)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN REAL_LE_MUL2)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_ABS_POS)(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_LE_REFL)(new_rewrite [] [])) THEN ((USE_THM_THEN VECTOR_SUB_COMPONENT)(new_rewrite [] []))))));; refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN domain_width)(fun fst_th ->(USE_THEN "domainH")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] [])) THEN (done_tac)))));; let diff2_derivative_partial_bound = end_section_proof();; (start_section_proof ["domain";"y";"w";"p";"f";"i";"dd_bound"](`m_cell_domain domain y (w:real^N) ==> p IN interval [domain] ==> diff2_domain domain f ==> m_taylor_partial_error f i domain w dd_bound ==> abs (partial i f p - partial i f y) <= dd_bound`));; refine (by (VALID ((((USE_THM_THEN diff2_domain)(new_rewrite [] [])) THEN (BETA_TAC THEN (move ["domainH"]) THEN (move ["p_in"]) THEN (move ["df"]) THEN (move ["partial_error"]))))));; refine (by (VALID ((have_tac (move ["pt_in"]) (`!t. interval_arith t (&0, &1) ==> y + t % (p - y) IN interval [domain]`)))));; refine (by (VALID (((BETA_TAC THEN (move ["t"]) THEN (move ["t_in"])) THEN (((USE_THM_THEN (VECTOR_ARITH `y + t % (p - y) = (&1 - t) % y + t % p:real^N`))(new_rewrite [] [])) THEN ((USE_THM_THEN IN_CONVEX_SET)(new_rewrite [] [])))))));; refine (by (VALID (((((fun thm_tac -> (USE_THM_THEN y_in_domain)(fun fst_th ->(USE_THEN "domainH")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] [])) THEN ((USE_THEN "p_in")(new_rewrite [] [])) THEN ((USE_THM_THEN interval_arith)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THEN "t_in")(new_rewrite [] [])) THEN ((USE_THM_THEN pair_eq)(new_rewrite [] [])) THEN ((USE_THM_THEN CONVEX_INTERVAL)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN real_taylor1_bound)(ISPEC_THEN (`partial i f o (\t. y + t % (p - y))`) thm_tac))(ISPEC_THEN (mk_var("dd_bound",mk_type("real",[]))) thm_tac))MP_TAC) THEN BETA_TAC))));; refine (by (VALID ((ANTS_TAC))));; refine (by (VALID (((BETA_TAC THEN (move ["t"]) THEN (move ["t_in"])) THEN (((USE_THM_THEN diff2_real_diff_partial)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "pt_in")(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((fun thm_tac -> (USE_THM_THEN diff2_derivative_partial_bound)(fun fst_th ->(USE_THEN "domainH")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] [])) THEN ((TRY done_tac)))))));; refine (by (VALID ((((USE_THM_THEN diff2_domain)(new_rewrite [] [])) THEN (done_tac)))));; refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN VECTOR_MUL_LID)(new_rewrite [] [])) THEN ((USE_THM_THEN VECTOR_MUL_LZERO)(new_rewrite [] [])) THEN ((USE_THM_THEN VECTOR_ADD_RID)(new_rewrite [] [])) THEN ((USE_THM_THEN (GEN_ALL VECTOR_SUB_ADD2))(new_rewrite [] []))) THEN (done_tac)))));; let m_taylor_partial_error_lemma = end_section_proof();; (start_section_proof ["domain";"y";"w";"f";"i";"dd_bound";"hi";"hi_bound"](`m_cell_domain domain y (w:real^N) ==> diff2_domain domain f ==> m_taylor_partial_error f i domain w dd_bound ==> partial i f y <= hi ==> hi + dd_bound <= hi_bound ==> !p. p IN interval [domain] ==> partial i f p <= hi_bound`));; refine (by (VALID ((BETA_TAC THEN (move ["domainH"]) THEN (move ["df"]) THEN (move ["errorH"]) THEN (move ["df_bound"]) THEN (move ["total_bound"]) THEN (move ["p"]) THEN (move ["p_in"])))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN m_taylor_partial_error_lemma)(fun fst_th ->(USE_THEN "domainH")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "p_in")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "df")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "errorH")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC))));; refine (by (VALID (((DISCH_THEN (fun snd_th -> (USE_THM_THEN (REAL_ARITH `!x y e. abs (x - y) <= e ==> x <= y + e`))(MATCH_MP_THEN snd_th MP_TAC))) THEN BETA_TAC THEN (move ["ineq"])))));; refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN (REWRITE_RULE[GSYM IMP_IMP] REAL_LE_TRANS))(fun fst_th ->(USE_THEN "ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN (DISCH_THEN apply_tac)))));; refine (by (VALID ((((USE_THEN "total_bound")MP_TAC) THEN (clear_assumption "total_bound") THEN ((USE_THM_THEN (REWRITE_RULE[GSYM IMP_IMP] REAL_LE_TRANS))MP_TAC) THEN (DISCH_THEN apply_tac)))));; refine (by (VALID (((((USE_THM_THEN REAL_LE_ADD2)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LE_REFL)(new_rewrite [] []))) THEN (done_tac)))));; let m_taylor_upper_partial_bound = end_section_proof();; (start_section_proof ["domain";"y";"w";"f";"i";"dd_bound";"lo";"lo_bound"](`m_cell_domain domain y (w:real^N) ==> diff2_domain domain f ==> m_taylor_partial_error f i domain w dd_bound ==> lo <= partial i f y ==> lo_bound <= lo - dd_bound ==> !p. p IN interval [domain] ==> lo_bound <= partial i f p`));; refine (by (VALID ((BETA_TAC THEN (move ["domainH"]) THEN (move ["df"]) THEN (move ["errorH"]) THEN (move ["df_bound"]) THEN (move ["total_bound"]) THEN (move ["p"]) THEN (move ["p_in"])))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN m_taylor_partial_error_lemma)(fun fst_th ->(USE_THEN "domainH")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "p_in")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "df")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "errorH")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC))));; refine (by (VALID (((DISCH_THEN (fun snd_th -> (USE_THM_THEN (REAL_ARITH `!x y e. abs (x - y) <= e ==> y - e <= x`))(MATCH_MP_THEN snd_th MP_TAC))) THEN BETA_TAC THEN (move ["ineq"])))));; refine (by (VALID ((((USE_THEN "ineq")MP_TAC) THEN (clear_assumption "ineq") THEN ((USE_THM_THEN (REWRITE_RULE[GSYM IMP_IMP] REAL_LE_TRANS))MP_TAC) THEN (DISCH_THEN apply_tac)))));; refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN (REWRITE_RULE[GSYM IMP_IMP] REAL_LE_TRANS))(fun fst_th ->(USE_THEN "total_bound")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN (DISCH_THEN apply_tac)))));; refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN real_sub)(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_LE_ADD2)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LE_REFL)(new_rewrite [] []))) THEN (done_tac)))));; let m_taylor_lower_partial_bound = end_section_proof();; (start_section_proof ["domain";"y";"w";"f";"i";"dd_bound";"lo";"hi";"lo_bound";"hi_bound"](`m_cell_domain domain y (w:real^N) ==> diff2_domain domain f ==> m_taylor_partial_error f i domain w dd_bound ==> interval_arith (partial i f y) (lo, hi) ==> lo_bound <= lo - dd_bound ==> hi + dd_bound <= hi_bound ==> m_bounded_on_int (partial i f) domain (lo_bound, hi_bound)`));; refine (by (VALID (((((USE_THM_THEN m_bounded_on_int)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN interval_arith)(new_rewrite [] [])))) THEN (move ["domainH"]) THEN (move ["df"]) THEN (move ["errorH"]) THEN (case THEN ((move ["df_lo"]) THEN (move ["df_hi"]))) THEN (move ["lo_ineq"]) THEN (move ["hi_ineq"]) THEN (move ["p"]) THEN (move ["p_in"])))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN m_taylor_lower_partial_bound)(fun fst_th ->(USE_THEN "domainH")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "df")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "errorH")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "df_lo")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(ISPEC_THEN (mk_var("lo_bound",mk_type("real",[]))) thm_tac))MP_TAC) THEN BETA_TAC THEN (DISCH_THEN(new_rewrite [] [])) THEN ((TRY done_tac))))));; refine (by (VALID (((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN m_taylor_upper_partial_bound)(fun fst_th ->(USE_THEN "domainH")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "df")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "errorH")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "df_hi")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(ISPEC_THEN (mk_var("hi_bound",mk_type("real",[]))) thm_tac))MP_TAC) THEN BETA_TAC THEN (DISCH_THEN(new_rewrite [] []))) THEN (done_tac)))));; let m_taylor_partial_bounds = end_section_proof();; let m_taylor_partial_bounds = finalize_theorem m_taylor_partial_bounds;; let m_taylor_lower_partial_bound = finalize_theorem m_taylor_lower_partial_bound;; let m_taylor_upper_partial_bound = finalize_theorem m_taylor_upper_partial_bound;; let m_taylor_partial_error_lemma = finalize_theorem m_taylor_partial_error_lemma;; let diff2_derivative_partial_bound = finalize_theorem diff2_derivative_partial_bound;; let m_taylor_bounds = finalize_theorem m_taylor_bounds;; let m_taylor_lower_bound = finalize_theorem m_taylor_lower_bound;; let m_taylor_upper_bound = finalize_theorem m_taylor_upper_bound;; let m_taylor_error_lemma = finalize_theorem m_taylor_error_lemma;; let diff2_derivative2_bound = finalize_theorem diff2_derivative2_bound;; let m_taylor_error_eq = finalize_theorem m_taylor_error_eq;; let sum_swap1 = finalize_theorem sum_swap1;; let domain_width = finalize_theorem domain_width;; let y_in_domain = finalize_theorem y_in_domain;; let diff2c_domain_alt = finalize_theorem diff2c_domain_alt;; let mixed_second_partials = finalize_theorem mixed_second_partials;; let real_mvt0 = finalize_theorem real_mvt0;; let partial_eq0_alt = finalize_theorem partial_eq0_alt;; let partial_const = finalize_theorem partial_const;; let diff2_real_diff_partial = finalize_theorem diff2_real_diff_partial;; let diff2_derivative_partial = finalize_theorem diff2_derivative_partial;; let diff2_has_derivative_partial = finalize_theorem diff2_has_derivative_partial;; let diff2_dir_derivative2 = finalize_theorem diff2_dir_derivative2;; let diff2_dir = finalize_theorem diff2_dir;; let open_contains_open_interval = finalize_theorem open_contains_open_interval;; let in_trans = finalize_theorem in_trans;; let diff2_partial_real_diff = finalize_theorem diff2_partial_real_diff;; let diff2_dir_derivative = finalize_theorem diff2_dir_derivative;; let diff2_imp_real_diff = finalize_theorem diff2_imp_real_diff;; let diff2_eq_diff2_on_open = finalize_theorem diff2_eq_diff2_on_open;; let diff2c_imp_diff2 = finalize_theorem diff2c_imp_diff2;; let taylor_error_eq_sum_partial_errors = finalize_theorem taylor_error_eq_sum_partial_errors;; let real_taylor1_bound = finalize_theorem real_taylor1_bound;; let real_taylor2_bound = finalize_theorem real_taylor2_bound;; (end_section "Taylor");; (begin_section "Diff2Arith");; (add_section_var (mk_var ("f", (`:real^N -> real`))); add_section_var (mk_var ("g", (`:real^N -> real`))));; (add_section_var (mk_var ("x", (`:real^N`))));; (add_section_var (mk_var ("domain", (`:real^N#real^N`))));; (start_section_proof ["s";"f";"g";"x"](`f differentiable at x ==> open s ==> x IN s ==> (!y. y IN s ==> g y = f y) ==> g differentiable at x`));; refine (by (VALID ((((USE_THM_THEN OPEN_CONTAINS_BALL)(new_rewrite [] [])) THEN (move ["df"]) THEN (move ["open_s"]) THEN (move ["xs"]) THEN (move ["eq"])))));; refine (by (VALID (((((fun thm_tac -> (USE_THEN "open_s")(fun fst_th ->(USE_THEN "xs")(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 ((((USE_THM_THEN SUBSET)(new_rewrite [] [])) THEN ((USE_THM_THEN IN_BALL)(new_rewrite [] []))) THEN (move ["in_ball"]))))));; refine (by (VALID (((((fun thm_tac -> (USE_THM_THEN DIFFERENTIABLE_TRANSFORM_AT)(ISPEC_THEN (mk_var("f",mk_type("fun",[mk_type("cart",[mk_type("real",[]);mk_vartype "?1459839"]);mk_type("cart",[mk_type("real",[]);mk_vartype "?1459836"])]))) thm_tac))MP_TAC) THEN (DISCH_THEN apply_tac)) THEN (((USE_THEN "df")(new_rewrite [] [])) THEN ((USE_THM_THEN andbT)(new_rewrite [] [])))))));; 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 ["z"]) THEN (move ["dzx"])) THEN (((USE_THEN "eq")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THEN "in_ball")(new_rewrite [] [])) THEN ((USE_THM_THEN DIST_SYM)(new_rewrite [] []))) THEN (done_tac)))));; let differentiable_local_at = end_section_proof();; (begin_section "Point");; (start_section_proof ["f";"c"](`diff2 f x ==> diff2 (\x. c * f x) x`));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN diff2)(new_rewrite [] []))) 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("cart",[mk_type("real",[]);mk_vartype "N"]);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 ["z"]) THEN (move ["zs"]))))));; refine (by (VALID (((THENL_FIRST) (((USE_THM_THEN f_lift_scale)(new_rewrite [] [])) THEN ((USE_THM_THEN DIFFERENTIABLE_CMUL)(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 ((USE_THEN "df")(new_rewrite [] [])) THEN (done_tac))))));; refine (by (VALID (((BETA_TAC THEN (move ["i"])) THEN (((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN differentiable_local_at)(ISPEC_THEN (mk_var("s",mk_type("fun",[mk_type("cart",[mk_type("real",[]);mk_vartype "N"]);mk_type("bool",[])]))) thm_tac))(ISPEC_THEN (`lift o (\x. c * partial i f x)`) thm_tac))MP_TAC) THEN (DISCH_THEN apply_tac))))));; refine (by (VALID (((THENL_FIRST) (((USE_THEN "open_s")(new_rewrite [] [])) THEN ((USE_THEN "zs")(new_rewrite [] [])) THEN ((USE_THM_THEN f_lift_scale)(new_rewrite [] [])) THEN ((USE_THM_THEN DIFFERENTIABLE_CMUL)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN andTb)(new_rewrite [] [])))) (repeat_tactic 1 9 (((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th]))) THEN ((USE_THEN "df")(new_rewrite [] [])) THEN (done_tac))))));; refine (by (VALID (((BETA_TAC THEN (move ["y"]) THEN (move ["ys"])) THEN (repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN ((USE_THM_THEN partial_scale)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN LIFT_CMUL)(new_rewrite [] []))) THEN (done_tac)))));; let diff2_scale = end_section_proof();; (start_section_proof ["f"](`diff2 f x ==> diff2 (\x. --f x) x`));; refine (by (VALID ((((DISCH_THEN (fun snd_th -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN diff2_scale)(ISPEC_THEN (mk_var("f",mk_type("fun",[mk_type("cart",[mk_type("real",[]);mk_vartype "N"]);mk_type("real",[])]))) thm_tac))(ISPEC_THEN (`--(&1)`) thm_tac))(MATCH_MP_THEN snd_th MP_TAC))) THEN BETA_TAC) THEN ((USE_THM_THEN REAL_NEG_MINUS1)(GSYM_THEN (new_rewrite [] []))) THEN (done_tac)))));; let diff2_neg = end_section_proof();; (begin_section "Composite");; (start_section_proof ["u";"f";"u'";"f'";"x"](`(lift o f has_derivative f') (at x) ==> (u has_real_derivative u') (atreal (f x)) ==> (lift o u o f has_derivative (\x. u' % f' x)) (at x)`));; refine (by (VALID ((BETA_TAC THEN (move ["df"]) THEN (move ["du"])))));; refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`lift o u o f = (lift o u o drop) o (lift o f)`)))));; refine (by (VALID (((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN ((USE_THM_THEN LIFT_DROP)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((THENL_FIRST) (have_tac (DISCH_THEN(new_rewrite [] [])) (`(\x. u' % f' x) = (\x. u' % x) o f'`)) ((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (simp_tac)) THEN (done_tac))))));; refine (by (VALID (((((USE_THM_THEN DIFF_CHAIN_AT)(new_rewrite [] [])) THEN ((USE_THM_THEN o_THM)(new_rewrite [] [])) THEN ((USE_THM_THEN (GEN_ALL HAS_REAL_FRECHET_DERIVATIVE_AT))(GSYM_THEN (new_rewrite [] [])))) THEN (done_tac)))));; let has_derivative_uni_compose = end_section_proof();; (start_section_proof ["u";"f";"x"](`lift o f differentiable at x ==> u real_differentiable atreal (f x) ==> lift o u o f differentiable at x`));; refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN differentiable)(new_rewrite [] []))) THEN ((USE_THM_THEN real_differentiable)(new_rewrite [] []))) THEN ALL_TAC THEN (case THEN (move ["f'"])) THEN (move ["df"]) THEN (case THEN (move ["u'"])) THEN (move ["du"])))));; refine (by (VALID (((exists_tac (`\x. u' % f' x`)) THEN ((USE_THM_THEN has_derivative_uni_compose) apply_tac) THEN (done_tac)))));; let diff_uni_compose = end_section_proof();; (start_section_proof ["u";"f"](`diff2 f x ==> nth_diff_strong 2 u (f x) ==> diff2 (u o f) x`));; refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN diff2)(new_rewrite [] []))) 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 (move ["df"]) THEN (case THEN (move ["t"])) THEN (case THEN (move ["open_t"])) THEN (case THEN (move ["fxt"])) THEN (move ["du"])))));; refine (by (VALID ((set_tac "r" (`{z | z IN s /\ (lift o f) z IN (IMAGE lift t)}`)))));; refine (by (VALID ((have_tac (move ["open_r"]) (`open r`)))));; refine (by (VALID ((((USE_THEN "r_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN CONTINUOUS_OPEN_PREIMAGE)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_OPEN)(GSYM_THEN (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 DIFFERENTIABLE_IMP_CONTINUOUS_ON) apply_tac) THEN (((USE_THM_THEN differentiable_on)(new_rewrite [] [])) THEN (move ["y"]) THEN (move ["ys"])) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th]))))));; refine (by (VALID (((((USE_THM_THEN DIFFERENTIABLE_AT_WITHIN)(new_rewrite [] [])) THEN ((USE_THEN "df")(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((THENL_FIRST) ((exists_tac (mk_var("r",mk_type("fun",[mk_type("cart",[mk_type("real",[]);mk_vartype "N"]);mk_type("bool",[])])))) THEN (((USE_THEN "open_r")(new_rewrite [] [])) THEN ((USE_THEN "r_def")(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_ELIM_THM)(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN o_THM)(new_rewrite [] [])) THEN ((USE_THM_THEN LIFT_IN_IMAGE_LIFT)(new_rewrite [] []))) THEN (split_tac)) ((exists_tac (mk_var("x",mk_type("cart",[mk_type("real",[]);mk_vartype "N"])))) THEN (done_tac))))));; refine (by (VALID ((BETA_TAC THEN (move ["y"]) THEN (case THEN (move ["z"])) THEN (case THEN ((case THEN (move ["zs"])) THEN (move ["fzt"]))) THEN (DISCH_THEN(new_rewrite [] []))))));; refine (by (VALID (((((USE_THM_THEN diff_uni_compose)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "du")(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (move ["i"])))));; refine (by (VALID ((((USE_THM_THEN differentiable_local_at) apply_tac) THEN ((exists_tac (mk_var("r",mk_type("fun",[mk_type("cart",[mk_type("real",[]);mk_vartype "N"]);mk_type("bool",[])])))) THEN (exists_tac (`lift o (\y. derivative u (f y) * partial i f y)`)))))));; refine (by (VALID ((((USE_THEN "open_r")(new_rewrite [] [])) THEN ((USE_THM_THEN differentiable_mul)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN andTb)(new_rewrite [] [])))))));; refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN o_THM)(ISPEC_THEN (`derivative u`) thm_tac))(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th]))) THEN (((USE_THM_THEN diff_uni_compose)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THEN "du")(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((THENL_FIRST) ((((USE_THEN "r_def")(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_ELIM_THM)(new_rewrite [] []))) THEN (simp_tac) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN LIFT_IN_IMAGE_LIFT)(new_rewrite [] [])))) THEN (split_tac)) ((exists_tac (mk_var("z",mk_type("cart",[mk_type("real",[]);mk_vartype "N"])))) THEN (done_tac))))));; refine (by (VALID ((BETA_TAC THEN (move ["y"]) THEN (case THEN (move ["p"])) THEN (case THEN ((case THEN (move ["ps"])) THEN (move ["fpt"]))) THEN (DISCH_THEN(new_rewrite [] []))))));; refine (by (VALID (((((USE_THM_THEN partial_uni_compose)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "du")(new_rewrite [] [])))) THEN (done_tac)))));; let diff2_uni_compose = end_section_proof();; (start_section_proof [](`~(f x = &0) ==> diff2 f x ==> diff2 (inv o f) x`));; refine (by (VALID (((BETA_TAC THEN (DISCH_THEN (fun snd_th -> (USE_THM_THEN diff2_inv)(MATCH_MP_THEN snd_th MP_TAC))) THEN (move ["du"]) THEN (move ["df"])) THEN ((USE_THM_THEN diff2_uni_compose)(new_rewrite [] [])) THEN (done_tac)))));; let diff2_inv_compose = end_section_proof();; (start_section_proof [](`&0 < f x ==> diff2 f x ==> diff2 (sqrt o f) x`));; refine (by (VALID (((BETA_TAC THEN (DISCH_THEN (fun snd_th -> (USE_THM_THEN diff2_sqrt)(MATCH_MP_THEN snd_th MP_TAC))) THEN (move ["du"]) THEN (move ["df"])) THEN ((USE_THM_THEN diff2_uni_compose)(new_rewrite [] [])) THEN (done_tac)))));; let diff2_sqrt_compose = end_section_proof();; (start_section_proof [](`diff2 f x ==> diff2 (atn o f) x`));; refine (by (VALID (((BETA_TAC THEN (move ["df"])) THEN (((USE_THM_THEN diff2_uni_compose)(new_rewrite [] [])) THEN ((USE_THM_THEN diff2_atn)(new_rewrite [] []))) THEN (done_tac)))));; let diff2_atn_compose = end_section_proof();; (start_section_proof [](`abs (f x) < &1 ==> diff2 f x ==> diff2 (acs o f) x`));; refine (by (VALID (((BETA_TAC THEN (DISCH_THEN (fun snd_th -> (USE_THM_THEN diff2_acs)(MATCH_MP_THEN snd_th MP_TAC))) THEN (move ["du"]) THEN (move ["df"])) THEN ((USE_THM_THEN diff2_uni_compose)(new_rewrite [] [])) THEN (done_tac)))));; let diff2_acs_compose = end_section_proof();; let diff2_acs_compose = finalize_theorem diff2_acs_compose;; let diff2_atn_compose = finalize_theorem diff2_atn_compose;; let diff2_sqrt_compose = finalize_theorem diff2_sqrt_compose;; let diff2_inv_compose = finalize_theorem diff2_inv_compose;; let diff2_uni_compose = finalize_theorem diff2_uni_compose;; let diff_uni_compose = finalize_theorem diff_uni_compose;; let has_derivative_uni_compose = finalize_theorem has_derivative_uni_compose;; (end_section "Composite");; (start_section_proof ["f";"g"](`diff2 f x ==> diff2 g x ==> diff2 (\x. f x + g x) x`));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN diff2)(new_rewrite [] []))) THEN ALL_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["open_s"])) THEN (case THEN (move ["xs"])) THEN (move ["df"]) THEN (case THEN (move ["t"])) THEN (case THEN (move ["open_t"])) THEN (case THEN (move ["ys"])) THEN (move ["dg"])))));; refine (by (VALID (((exists_tac (`s INTER t`)) THEN ((((USE_THM_THEN 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 [] [])) THEN ((USE_THEN "ys")(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] [])))) THEN (move ["z"]) THEN (case THEN ((move ["zs"]) THEN (move ["zt"]))))))));; refine (by (VALID ((((USE_THM_THEN f_lift_add)(new_rewrite [] [])) THEN ((USE_THM_THEN DIFFERENTIABLE_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 (((USE_THEN "df")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THEN "dg")(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((BETA_TAC THEN (move ["i"])) THEN (((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN differentiable_local_at)(ISPEC_THEN (`s INTER t`) thm_tac))(ISPEC_THEN (`lift o (\x. partial i f x + partial i g x)`) thm_tac))MP_TAC) THEN (DISCH_THEN apply_tac))))));; refine (by (VALID ((((USE_THM_THEN OPEN_INTER)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_INTER)(new_rewrite [] []))) THEN ((USE_THEN "zt")(new_rewrite [] [])) THEN ((USE_THEN "zs")(new_rewrite [] [])) THEN ((USE_THM_THEN f_lift_add)(new_rewrite [] [])) THEN ((USE_THM_THEN DIFFERENTIABLE_ADD)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN andTb)(new_rewrite [] [])))))));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th]))) THEN (((USE_THEN "df")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THEN "dg")(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((BETA_TAC THEN (move ["y"]) THEN (case THEN ((move ["ys"]) THEN (move ["yt"])))) THEN (repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN ((USE_THM_THEN partial_add)(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_THM_THEN LIFT_ADD)(new_rewrite [] []))) THEN (done_tac)))));; let diff2_add = end_section_proof();; (start_section_proof ["f";"g"](`diff2 f x ==> diff2 g x ==> diff2 (\x. f x - g x) x`));; refine (by (VALID (((BETA_TAC THEN (move ["d2f"]) THEN (move ["d2g"])) THEN (((USE_THM_THEN real_sub)(new_rewrite [] [])) THEN ((USE_THM_THEN diff2_add)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN diff2_neg)(new_rewrite [] []))) THEN (done_tac)))));; let diff2_sub = end_section_proof();; (start_section_proof ["f";"g"](`diff2 f x ==> diff2 g x ==> diff2 (\x. f x * g x) x`));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN diff2)(new_rewrite [] []))) THEN ALL_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["open_s"])) THEN (case THEN (move ["xs"])) THEN (move ["df"]) THEN (case THEN (move ["t"])) THEN (case THEN (move ["open_t"])) THEN (case THEN (move ["ys"])) THEN (move ["dg"])))));; refine (by (VALID (((exists_tac (`s INTER t`)) THEN ((((USE_THM_THEN 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 [] [])) THEN ((USE_THEN "ys")(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] [])))) THEN (move ["z"]) THEN (case THEN ((move ["zs"]) THEN (move ["zt"]))))))));; refine (by (VALID (((((USE_THM_THEN differentiable_mul)(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_THM_THEN andTb)(new_rewrite [] []))) THEN (move ["i"])))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN differentiable_local_at)(ISPEC_THEN (`s INTER t`) thm_tac))(ISPEC_THEN (`lift o (\x. partial i f x * g x + f x * partial i g x)`) thm_tac))MP_TAC) THEN (DISCH_THEN apply_tac)))));; refine (by (VALID ((((USE_THM_THEN OPEN_INTER)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_INTER)(new_rewrite [] []))) THEN ((USE_THEN "zt")(new_rewrite [] [])) THEN ((USE_THEN "zs")(new_rewrite [] [])) THEN ((USE_THM_THEN f_lift_add)(new_rewrite [] [])) THEN ((USE_THM_THEN DIFFERENTIABLE_ADD)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN andTb)(new_rewrite [] [])))))));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th]))) THEN repeat_tactic 1 9 (((USE_THM_THEN differentiable_mul)(new_rewrite [] []))) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN (repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "dg")(new_rewrite [] [])))) THEN (done_tac)))));; refine (by (VALID (((BETA_TAC THEN (move ["y"]) THEN (case THEN ((move ["ys"]) THEN (move ["yt"])))) THEN (repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN ((USE_THM_THEN partial_mul)(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_THM_THEN LIFT_ADD)(new_rewrite [] []))) THEN (done_tac)))));; let diff2_mul = end_section_proof();; let diff2_mul = finalize_theorem diff2_mul;; let diff2_sub = finalize_theorem diff2_sub;; let diff2_add = finalize_theorem diff2_add;; let diff2_acs_compose = finalize_theorem diff2_acs_compose;; let diff2_atn_compose = finalize_theorem diff2_atn_compose;; let diff2_sqrt_compose = finalize_theorem diff2_sqrt_compose;; let diff2_inv_compose = finalize_theorem diff2_inv_compose;; let diff2_uni_compose = finalize_theorem diff2_uni_compose;; let diff_uni_compose = finalize_theorem diff_uni_compose;; let has_derivative_uni_compose = finalize_theorem has_derivative_uni_compose;; let diff2_neg = finalize_theorem diff2_neg;; let diff2_scale = finalize_theorem diff2_scale;; (end_section "Point");; (begin_section "Domain");; (add_section_hyp "d2f" (`diff2_domain domain f`));; (start_section_proof ["c"](`diff2_domain domain (\x. c * f x)`));; refine (by (VALID (((((USE_THEN "d2f")MP_TAC) THEN (clear_assumption "d2f") THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN diff2_domain)(new_rewrite [] []))) THEN (move ["d2f"]) THEN (move ["x"]) THEN (move ["x_in"])) THEN (((USE_THM_THEN diff2_scale)(new_rewrite [] [])) THEN ((USE_THEN "d2f")(new_rewrite [] []))) THEN (done_tac)))));; let diff2_domain_scale = end_section_proof();; (start_section_proof [](`diff2_domain domain (\x. --f x)`));; refine (by (VALID (((((USE_THEN "d2f")MP_TAC) THEN (clear_assumption "d2f") THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN diff2_domain)(new_rewrite [] []))) THEN (move ["d2f"]) THEN (move ["x"]) THEN (move ["x_in"])) THEN (((USE_THM_THEN diff2_neg)(new_rewrite [] [])) THEN ((USE_THEN "d2f")(new_rewrite [] []))) THEN (done_tac)))));; let diff2_domain_neg = end_section_proof();; (add_section_var (mk_var ("bounds", (`:real#real`))));; (start_section_proof [](`m_bounded_on_int f domain bounds ==> interval_not_zero bounds ==> diff2_domain domain (inv o f)`));; refine (by (VALID (((((USE_THEN "d2f")MP_TAC) THEN (clear_assumption "d2f") THEN BETA_TAC) THEN ((((USE_THM_THEN m_bounded_on_int)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN diff2_domain)(new_rewrite [] [])))) THEN (move ["d2f"]) THEN (move ["ineq"]) THEN (move ["n0"]) THEN (move ["x"]) THEN (move ["x_in"]))))));; refine (by (VALID (((((USE_THM_THEN diff2_inv_compose)(new_rewrite [] [])) THEN ((USE_THEN "d2f")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andbT)(new_rewrite [] [])) THEN ((fun thm_tac -> (USE_THM_THEN interval_arith_not_zero)(fun fst_th ->(fun thm_tac -> (USE_THEN "ineq")(fun fst_th ->(USE_THEN "x_in")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] []))) THEN (done_tac)))));; let diff2_domain_inv_compose = end_section_proof();; (start_section_proof [](`m_bounded_on_int f domain bounds ==> interval_pos bounds ==> diff2_domain domain (sqrt o f)`));; refine (by (VALID (((((USE_THEN "d2f")MP_TAC) THEN (clear_assumption "d2f") THEN BETA_TAC) THEN ((((USE_THM_THEN m_bounded_on_int)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN diff2_domain)(new_rewrite [] [])))) THEN (move ["d2f"]) THEN (move ["ineq"]) THEN (move ["n0"]) THEN (move ["x"]) THEN (move ["x_in"]))))));; refine (by (VALID (((((USE_THM_THEN diff2_sqrt_compose)(new_rewrite [] [])) THEN ((USE_THEN "d2f")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andbT)(new_rewrite [] [])) THEN ((fun thm_tac -> (USE_THM_THEN interval_arith_pos)(fun fst_th ->(fun thm_tac -> (USE_THEN "ineq")(fun fst_th ->(USE_THEN "x_in")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] []))) THEN (done_tac)))));; let diff2_domain_sqrt_compose = end_section_proof();; (start_section_proof [](`diff2_domain domain (atn o f)`));; refine (by (VALID (((((USE_THEN "d2f")MP_TAC) THEN (clear_assumption "d2f") THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN diff2_domain)(new_rewrite [] []))) THEN (move ["d2f"]) THEN (move ["x"]) THEN (move ["x_in"])) THEN (((USE_THM_THEN diff2_atn_compose)(new_rewrite [] [])) THEN ((USE_THEN "d2f")(new_rewrite [] []))) THEN (done_tac)))));; let diff2_domain_atn_compose = end_section_proof();; (start_section_proof [](`m_bounded_on_int f domain bounds ==> iabs bounds < &1 ==> diff2_domain domain (acs o f)`));; refine (by (VALID (((((USE_THEN "d2f")MP_TAC) THEN (clear_assumption "d2f") THEN BETA_TAC) THEN ((((USE_THM_THEN m_bounded_on_int)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN diff2_domain)(new_rewrite [] [])))) THEN (move ["d2f"]) THEN (move ["ineq"]) THEN (move ["n0"]) THEN (move ["x"]) THEN (move ["x_in"]))))));; refine (by (VALID (((((USE_THM_THEN diff2_acs_compose)(new_rewrite [] [])) THEN ((USE_THEN "d2f")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andbT)(new_rewrite [] [])) THEN ((fun thm_tac -> (USE_THM_THEN interval_arith_abs)(fun fst_th ->(fun thm_tac -> (USE_THEN "ineq")(fun fst_th ->(USE_THEN "x_in")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] []))) THEN (done_tac)))));; let diff2_domain_acs_compose = end_section_proof();; (add_section_hyp "d2g" (`diff2_domain domain g`));; (start_section_proof [](`diff2_domain domain (\x. f x + g x)`));; refine (by (VALID (((((USE_THEN "d2g")MP_TAC) THEN (clear_assumption "d2g") THEN ((USE_THEN "d2f")MP_TAC) THEN (clear_assumption "d2f") THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN diff2_domain)(new_rewrite [] []))) THEN (move ["d2f"]) THEN (move ["d2g"]) THEN (move ["x"]) THEN (move ["x_in"])) THEN (((USE_THM_THEN diff2_add)(new_rewrite [] [])) THEN ((USE_THEN "d2f")(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "d2g")(new_rewrite [] [])))) THEN (done_tac)))));; let diff2_domain_add = end_section_proof();; (start_section_proof [](`diff2_domain domain (\x. f x - g x)`));; refine (by (VALID (((((USE_THEN "d2g")MP_TAC) THEN (clear_assumption "d2g") THEN ((USE_THEN "d2f")MP_TAC) THEN (clear_assumption "d2f") THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN diff2_domain)(new_rewrite [] []))) THEN (move ["d2f"]) THEN (move ["d2g"]) THEN (move ["x"]) THEN (move ["x_in"])) THEN (((USE_THM_THEN diff2_sub)(new_rewrite [] [])) THEN ((USE_THEN "d2f")(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "d2g")(new_rewrite [] [])))) THEN (done_tac)))));; let diff2_domain_sub = end_section_proof();; (start_section_proof [](`diff2_domain domain (\x. f x * g x)`));; refine (by (VALID (((((USE_THEN "d2g")MP_TAC) THEN (clear_assumption "d2g") THEN ((USE_THEN "d2f")MP_TAC) THEN (clear_assumption "d2f") THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN diff2_domain)(new_rewrite [] []))) THEN (move ["d2f"]) THEN (move ["d2g"]) THEN (move ["x"]) THEN (move ["x_in"])) THEN (((USE_THM_THEN diff2_mul)(new_rewrite [] [])) THEN ((USE_THEN "d2f")(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "d2g")(new_rewrite [] [])))) THEN (done_tac)))));; let diff2_domain_mul = end_section_proof();; let diff2_domain_mul = finalize_theorem diff2_domain_mul;; let diff2_domain_sub = finalize_theorem diff2_domain_sub;; let diff2_domain_add = finalize_theorem diff2_domain_add;; let diff2_domain_acs_compose = finalize_theorem diff2_domain_acs_compose;; let diff2_domain_atn_compose = finalize_theorem diff2_domain_atn_compose;; let diff2_domain_sqrt_compose = finalize_theorem diff2_domain_sqrt_compose;; let diff2_domain_inv_compose = finalize_theorem diff2_domain_inv_compose;; let diff2_domain_neg = finalize_theorem diff2_domain_neg;; let diff2_domain_scale = finalize_theorem diff2_domain_scale;; (end_section "Domain");; (begin_section "SecondPartial");; (start_section_proof ["f";"x"](`diff2 f x ==> (lift o f) differentiable at x`));; refine (by (VALID (((((USE_THM_THEN diff2)(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 (done_tac)))));; let diff2_imp_diff = end_section_proof();; (start_section_proof ["f";"i";"x"](`diff2 f x ==> (lift o partial i f) differentiable at x`));; refine (by (VALID (((((USE_THM_THEN diff2)(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 (done_tac)))));; let diff2_imp_partial_diff = end_section_proof();; (start_section_proof ["s";"f";"g";"i";"x"](`(lift o f) differentiable at x ==> open s ==> x IN s ==> (!y:real^N. y IN s ==> f y = g y) ==> partial i f x = partial i g x`));; refine (by (VALID (((BETA_TAC THEN (move ["df"]) THEN (move ["open_s"]) THEN (move ["xs"]) THEN (move ["eq"])) THEN repeat_tactic 1 9 (((USE_THM_THEN partial)(new_rewrite [] [])))))));; 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 (`g o (\t. x + t % basis i)`)) THEN (split_tac)))));; refine (by (VALID (((((USE_THM_THEN has_derivative_alt)MP_TAC) THEN (clear_assumption "has_derivative_alt") THEN (DISCH_THEN apply_tac)) THEN ((USE_THM_THEN diff_imp_real_diff) apply_tac) THEN (((USE_THM_THEN diff_direction)(new_rewrite [] [])) THEN ((USE_THM_THEN andbT)(new_rewrite [] [])))))));; refine (by (VALID (((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN differentiable_local_at)(ISPEC_THEN (mk_var("s",mk_type("fun",[mk_type("cart",[mk_type("real",[]);mk_vartype "N"]);mk_type("bool",[])]))) thm_tac))(ISPEC_THEN (`lift o f`) thm_tac)) apply_tac))));; refine (by (VALID ((((simp_tac) THEN ((USE_THM_THEN VECTOR_MUL_LZERO)(new_rewrite [] [])) THEN ((USE_THM_THEN VECTOR_ADD_RID)(new_rewrite [] [])) THEN ((USE_THEN "df")(new_rewrite [] [])) 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 (move ["ys"])))));; refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN ((USE_THEN "eq")(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN open_contains_open_interval)(fun fst_th ->(USE_THEN "open_s")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "xs")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(ISPEC_THEN (`basis i:real^N`) thm_tac))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["a"])) THEN (case THEN (move ["b"])) THEN (case THEN (move ["ab0"]))) THEN (((USE_THM_THEN SUBSET)(new_rewrite [] [])) THEN (move ["sub"]))))));; refine (by (VALID (((exists_tac (`real_interval (a, b)`)) THEN ((((USE_THEN "ab0")(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_OPEN_REAL_INTERVAL)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] [])))) THEN (move ["y"]) THEN (move ["y_in"]))))));; refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THEN "eq")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THEN "sub")(new_rewrite [] [])) THEN ((USE_THM_THEN IN_IMAGE)(new_rewrite [] [])) THEN (simp_tac)) THEN (exists_tac (mk_var("y",mk_type("real",[])))) THEN (done_tac)))));; let partial_local = end_section_proof();; (add_section_var (mk_var ("i", (`:num`))); add_section_var (mk_var ("j", (`:num`))));; (start_section_proof ["f";"c"](`diff2 f x ==> partial2 i j (\x. c * f x) x = c * partial2 i j f x`));; refine (by (VALID (((BETA_TAC THEN (move ["d2f"])) THEN (repeat_tactic 1 9 (((USE_THM_THEN partial2)(new_rewrite [] []))) THEN ((USE_THM_THEN partial_scale)(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN diff2_imp_partial_diff)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN EQ_SYM_EQ)(new_rewrite [] [])))))));; refine (by (VALID (((((USE_THEN "d2f")MP_TAC) THEN (clear_assumption "d2f") THEN BETA_TAC) THEN (((USE_THM_THEN diff2)(new_rewrite [] [])) 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 ((((USE_THM_THEN partial_local) apply_tac) THEN (exists_tac (mk_var("s",mk_type("fun",[mk_type("cart",[mk_type("real",[]);mk_vartype "N"]);mk_type("bool",[])])))) THEN (((USE_THEN "open_s")(new_rewrite [] [])) THEN ((USE_THEN "xs")(new_rewrite [] [])) THEN ((USE_THM_THEN f_lift_scale)(new_rewrite [] [])) THEN ((USE_THM_THEN DIFFERENTIABLE_CMUL)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN andTb)(new_rewrite [] []))))))));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th]))) THEN ((USE_THEN "df")(new_rewrite [] [])) THEN (done_tac)))));; refine (by (VALID (((BETA_TAC THEN (move ["y"]) THEN (move ["ys"])) THEN (((USE_THM_THEN partial_scale)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] [])))) THEN (done_tac)))));; let second_partial_scale = end_section_proof();; (start_section_proof ["f"](`diff2 f x ==> partial2 i j (\x. --f x) x = --partial2 i j f x`));; refine (by (VALID ((((DISCH_THEN (fun snd_th -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN second_partial_scale)(ISPEC_THEN (mk_var("f",mk_type("fun",[mk_type("cart",[mk_type("real",[]);mk_vartype "N"]);mk_type("real",[])]))) thm_tac))(ISPEC_THEN (`--(&1)`) thm_tac))(MATCH_MP_THEN snd_th MP_TAC))) THEN BETA_TAC) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_NEG_MINUS1)(GSYM_THEN (new_rewrite [] [])))) THEN (done_tac)))));; let second_partial_neg = end_section_proof();; (start_section_proof ["f";"g"](`diff2 f x ==> diff2 g x ==> partial2 i j (\x. f x + g x) x = partial2 i j f x + partial2 i j g x`));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN diff2)(new_rewrite [] []))) THEN ALL_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["open_s"])) THEN (case THEN (move ["xs"])) THEN (move ["df"]) THEN (case THEN (move ["t"])) THEN (case THEN (move ["open_t"])) THEN (case THEN (move ["ys"])) THEN (move ["dg"])))));; refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN partial2)(new_rewrite [] []))) THEN ((USE_THM_THEN partial_add)(GSYM_THEN (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_THM_THEN EQ_SYM_EQ)(new_rewrite [] []))) THEN ((USE_THM_THEN partial_local) apply_tac)))));; refine (by (VALID (((exists_tac (`s INTER t`)) THEN (((USE_THM_THEN 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 [] [])) THEN ((USE_THEN "ys")(new_rewrite [] [])))))));; refine (by (VALID ((((USE_THM_THEN f_lift_add)(new_rewrite [] [])) THEN ((USE_THM_THEN DIFFERENTIABLE_ADD)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN andTb)(new_rewrite [] [])))))));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th]))) THEN (((USE_THEN "df")(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "dg")(new_rewrite [] [])))) THEN (done_tac)))));; refine (by (VALID (((BETA_TAC THEN (move ["z"]) THEN (case THEN ((move ["zs"]) THEN (move ["zt"])))) THEN (((USE_THM_THEN partial_add)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "dg")(new_rewrite [] [])))) THEN (done_tac)))));; let second_partial_add = end_section_proof();; (start_section_proof ["f";"g"](`diff2 f x ==> diff2 g x ==> partial2 i j (\x. f x - g x) x = partial2 i j f x - partial2 i j g x`));; refine (by (VALID (((BETA_TAC THEN (move ["d2f"]) THEN (move ["d2g"])) THEN (((USE_THM_THEN real_sub)(new_rewrite [] [])) THEN ((USE_THM_THEN second_partial_add)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN diff2_neg)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN second_partial_neg)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN real_sub)(GSYM_THEN (new_rewrite [] [])))) THEN (done_tac)))));; let second_partial_sub = end_section_proof();; (start_section_proof ["f";"g"](`diff2 f x ==> diff2 g x ==> partial2 i j (\x. f x * g x) x = (partial2 i j f x * g x + partial j f x * partial i g x) + (partial i f x * partial j g x + f x * partial2 i j g x)`));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN diff2)(new_rewrite [] []))) THEN ALL_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["open_s"])) THEN (case THEN (move ["xs"])) THEN (move ["df"]) THEN (case THEN (move ["t"])) THEN (case THEN (move ["open_t"])) THEN (case THEN (move ["ys"])) THEN (move ["dg"])))));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN partial2)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN partial_mul)(GSYM_THEN (new_rewrite [] [])))) THEN repeat_tactic 0 10 (((USE_THM_THEN partial_add)(GSYM_THEN (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 repeat_tactic 0 1 (((USE_THM_THEN EQ_SYM_EQ)(new_rewrite [] [])))))));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN differentiable_mul)(new_rewrite [] []))) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN (repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "dg")(new_rewrite [] [])))) THEN (done_tac)))));; refine (by (VALID (((USE_THM_THEN partial_local) apply_tac))));; refine (by (VALID (((exists_tac (`s INTER t`)) THEN (((USE_THM_THEN 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 [] [])) THEN ((USE_THEN "ys")(new_rewrite [] [])))))));; refine (by (VALID ((((USE_THM_THEN f_lift_add)(new_rewrite [] [])) THEN ((USE_THM_THEN DIFFERENTIABLE_ADD)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN andTb)(new_rewrite [] [])))))));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th]))) THEN repeat_tactic 1 9 (((USE_THM_THEN differentiable_mul)(new_rewrite [] []))) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN (repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "dg")(new_rewrite [] [])))) THEN (done_tac)))));; refine (by (VALID (((BETA_TAC THEN (move ["z"]) THEN (case THEN ((move ["zs"]) THEN (move ["zt"])))) THEN (((USE_THM_THEN partial_mul)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "dg")(new_rewrite [] [])))) THEN (done_tac)))));; let second_partial_mul = end_section_proof();; (start_section_proof ["f";"u"](`diff2 f x ==> nth_diff_strong 2 u (f x) ==> partial2 i j (u o f) x = (nth_derivative 2 u (f x) * partial i f x) * partial j f x + derivative u (f x) * partial2 i j f x`));; refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN diff2)(new_rewrite [] []))) 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 (move ["df"]) THEN (case THEN (move ["t"])) THEN (case THEN (move ["open_t"])) THEN (case THEN (move ["fxt"])) THEN (move ["du"])))));; refine (by (VALID ((set_tac "r" (`{z | z IN s /\ (lift o f) z IN (IMAGE lift t)}`)))));; refine (by (VALID ((have_tac (move ["open_r"]) (`open r`)))));; refine (by (VALID ((((USE_THEN "r_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN CONTINUOUS_OPEN_PREIMAGE)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_OPEN)(GSYM_THEN (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 DIFFERENTIABLE_IMP_CONTINUOUS_ON) apply_tac) THEN (((USE_THM_THEN differentiable_on)(new_rewrite [] [])) THEN (move ["y"]) THEN (move ["ys"])) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th]))))));; refine (by (VALID (((((USE_THM_THEN DIFFERENTIABLE_AT_WITHIN)(new_rewrite [] [])) THEN ((USE_THEN "df")(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN partial2)(new_rewrite [] []))) THEN ((USE_THM_THEN nth_derivative2)(new_rewrite [] []))))));; refine (by (VALID ((((USE_THM_THEN partial_uni_compose)(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "du")(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((fun thm_tac -> (USE_THM_THEN o_THM)(ISPEC_THEN (`derivative u`) thm_tac))(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN partial_mul)(GSYM_THEN (new_rewrite [] [])))))));; refine (by (VALID (((((USE_THM_THEN diff_uni_compose)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "du")(new_rewrite [] [])))) THEN (done_tac)))));; refine (by (VALID ((((USE_THM_THEN partial_local) apply_tac) THEN (exists_tac (mk_var("r",mk_type("fun",[mk_type("cart",[mk_type("real",[]);mk_vartype "N"]);mk_type("bool",[])])))) THEN (((USE_THEN "open_r")(new_rewrite [] [])) THEN ((USE_THM_THEN andbT)(new_rewrite [] [])))))));; refine (by (VALID (((THENL_ROT (-1)) ((((USE_THEN "r_def")(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_ELIM_THM)(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN o_THM)(new_rewrite [] [])) THEN ((USE_THM_THEN LIFT_IN_IMAGE_LIFT)(new_rewrite [] []))) THEN (split_tac))))));; refine (by (VALID (((BETA_TAC THEN (move ["y"]) THEN (case THEN (move ["z"])) THEN (case THEN ((case THEN (move ["zs"])) THEN (move ["fpz"]))) THEN (DISCH_THEN(new_rewrite [] []))) THEN (((USE_THM_THEN partial_uni_compose)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "du")(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((THENL_LAST) (split_tac) ((exists_tac (mk_var("x",mk_type("cart",[mk_type("real",[]);mk_vartype "N"])))) THEN (done_tac))))));; refine (by (VALID ((((USE_THM_THEN differentiable_local_at) apply_tac) THEN ((exists_tac (mk_var("r",mk_type("fun",[mk_type("cart",[mk_type("real",[]);mk_vartype "N"]);mk_type("bool",[])])))) THEN (exists_tac (`lift o (\y. derivative u (f y) * partial j f y)`)))))));; refine (by (VALID ((((USE_THEN "open_r")(new_rewrite [] [])) THEN ((USE_THM_THEN differentiable_mul)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN andTb)(new_rewrite [] [])))))));; refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN o_THM)(ISPEC_THEN (`derivative u`) thm_tac))(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th]))) THEN (((USE_THM_THEN diff_uni_compose)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THEN "du")(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((THENL_FIRST) ((((USE_THEN "r_def")(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_ELIM_THM)(new_rewrite [] []))) THEN (simp_tac) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN LIFT_IN_IMAGE_LIFT)(new_rewrite [] [])))) THEN (split_tac)) ((exists_tac (mk_var("x",mk_type("cart",[mk_type("real",[]);mk_vartype "N"])))) THEN (done_tac))))));; refine (by (VALID (((BETA_TAC THEN (move ["y"]) THEN (case THEN (move ["p"])) THEN (case THEN ((case THEN (move ["ps"])) THEN (move ["fpt"]))) THEN (DISCH_THEN(new_rewrite [] []))) THEN (((USE_THM_THEN partial_uni_compose)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "df")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "du")(new_rewrite [] [])))) THEN (done_tac)))));; let second_partial_uni_compose = end_section_proof();; let second_partial_uni_compose = finalize_theorem second_partial_uni_compose;; let second_partial_mul = finalize_theorem second_partial_mul;; let second_partial_sub = finalize_theorem second_partial_sub;; let second_partial_add = finalize_theorem second_partial_add;; let second_partial_neg = finalize_theorem second_partial_neg;; let second_partial_scale = finalize_theorem second_partial_scale;; let partial_local = finalize_theorem partial_local;; let diff2_imp_partial_diff = finalize_theorem diff2_imp_partial_diff;; let diff2_imp_diff = finalize_theorem diff2_imp_diff;; (end_section "SecondPartial");; let second_partial_uni_compose = finalize_theorem second_partial_uni_compose;; let second_partial_mul = finalize_theorem second_partial_mul;; let second_partial_sub = finalize_theorem second_partial_sub;; let second_partial_add = finalize_theorem second_partial_add;; let second_partial_neg = finalize_theorem second_partial_neg;; let second_partial_scale = finalize_theorem second_partial_scale;; let partial_local = finalize_theorem partial_local;; let diff2_imp_partial_diff = finalize_theorem diff2_imp_partial_diff;; let diff2_imp_diff = finalize_theorem diff2_imp_diff;; let diff2_domain_mul = finalize_theorem diff2_domain_mul;; let diff2_domain_sub = finalize_theorem diff2_domain_sub;; let diff2_domain_add = finalize_theorem diff2_domain_add;; let diff2_domain_acs_compose = finalize_theorem diff2_domain_acs_compose;; let diff2_domain_atn_compose = finalize_theorem diff2_domain_atn_compose;; let diff2_domain_sqrt_compose = finalize_theorem diff2_domain_sqrt_compose;; let diff2_domain_inv_compose = finalize_theorem diff2_domain_inv_compose;; let diff2_domain_neg = finalize_theorem diff2_domain_neg;; let diff2_domain_scale = finalize_theorem diff2_domain_scale;; let diff2_mul = finalize_theorem diff2_mul;; let diff2_sub = finalize_theorem diff2_sub;; let diff2_add = finalize_theorem diff2_add;; let diff2_acs_compose = finalize_theorem diff2_acs_compose;; let diff2_atn_compose = finalize_theorem diff2_atn_compose;; let diff2_sqrt_compose = finalize_theorem diff2_sqrt_compose;; let diff2_inv_compose = finalize_theorem diff2_inv_compose;; let diff2_uni_compose = finalize_theorem diff2_uni_compose;; let diff_uni_compose = finalize_theorem diff_uni_compose;; let has_derivative_uni_compose = finalize_theorem has_derivative_uni_compose;; let diff2_neg = finalize_theorem diff2_neg;; let diff2_scale = finalize_theorem diff2_scale;; let differentiable_local_at = finalize_theorem differentiable_local_at;; (end_section "Diff2Arith");; (begin_section "Diff2c");; (start_section_proof ["f";"g";"x";"s"](`g real_continuous at x ==> open s ==> x IN s ==> (!y. y IN s ==> f y = g y) ==> f real_continuous at x`));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN (GEN_ALL real_continuous_at))(new_rewrite [] []))) THEN (move ["g_cont"]) THEN (move ["open_s"]) THEN (move ["xs"]) THEN (move ["f_eq_g"]) THEN (move ["e"]) THEN (move ["e_gt0"])))));; refine (by (VALID (((((fun thm_tac -> (USE_THM_THEN OPEN_CONTAINS_BALL)(ISPEC_THEN (mk_var("s",mk_type("fun",[mk_type("cart",[mk_type("real",[]);mk_vartype "?1460941"]);mk_type("bool",[])]))) thm_tac)) MP_TAC) THEN ALL_TAC) THEN (((USE_THEN "open_s")(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN ball)(new_rewrite [] [])) THEN ((USE_THM_THEN SUBSET)(new_rewrite [] [])) THEN ((USE_THM_THEN IN_ELIM_THM)(new_rewrite [] [])) THEN (simp_tac))))));; refine (by (VALID ((((fun thm_tac -> DISCH_THEN (fun fst_th ->(USE_THEN "xs")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["d0"])) THEN (case THEN (move ["d0_gt0"])) THEN (move ["sub_s"])))));; refine (by (VALID ((((fun thm_tac -> (USE_THEN "g_cont")(fun fst_th ->(USE_THEN "e_gt0")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (case THEN (move ["d1"])) THEN (case THEN (move ["d1_gt0"])) THEN (move ["dist_cond"])))));; refine (by (VALID ((exists_tac (`min d0 d1`)))));; refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN REAL_LT_MIN)(new_rewrite [] []))) THEN ((USE_THEN "d1_gt0")(new_rewrite [] [])) THEN ((USE_THEN "d0_gt0")(new_rewrite [] [])) THEN (simp_tac)) THEN (move ["y"]) THEN (case THEN ((move ["yd0"]) THEN (move ["yd1"])))))));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THEN "f_eq_g")(new_rewrite [] []))) THEN ((TRY done_tac))))));; refine (by (VALID (((((USE_THEN "sub_s")(new_rewrite [] [])) THEN ((USE_THM_THEN DIST_SYM)(new_rewrite [] []))) THEN (exists_tac (mk_var("y",mk_type("cart",[mk_type("real",[]);mk_vartype "?1460941"])))) THEN (done_tac)))));; refine (by (VALID ((((USE_THEN "dist_cond")MP_TAC) THEN (clear_assumption "dist_cond") THEN (exact_tac)))));; let real_cont_at_local = end_section_proof();; (start_section_proof ["v";"u";"t";"x"](`v real_continuous atreal x ==> real_open t ==> x IN t ==> (!y. y IN t ==> u y = v y) ==> u real_continuous atreal x`));; refine (by (VALID (repeat_tactic 1 9 (((USE_THM_THEN (GEN_ALL REAL_CONTINUOUS_CONTINUOUS_ATREAL))(new_rewrite [] []))))));; refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN (GEN_ALL REAL_CONTINUOUS_CONTINUOUS1))(GSYM_THEN (new_rewrite [] [])))) THEN ((USE_THM_THEN REAL_OPEN)(new_rewrite [] []))) THEN (move ["vc"]) THEN (move ["open_t"]) THEN (move ["xt"]) THEN (move ["v_eq_u"])))));; refine (by (VALID (((USE_THM_THEN real_cont_at_local) apply_tac))));; refine (by (VALID (((exists_tac (`v o drop`)) THEN (exists_tac (`IMAGE lift t`))))));; refine (by (VALID ((((((USE_THEN "open_t")(new_rewrite [] [])) THEN ((USE_THEN "vc")(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN LIFT_IN_IMAGE_LIFT)(new_rewrite [] [])) THEN ((USE_THEN "xt")(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN IN_IMAGE_LIFT_DROP)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] [])))) THEN (move ["y"]) THEN (DISCH_THEN (fun snd_th -> (USE_THEN "v_eq_u")(MATCH_MP_THEN snd_th MP_TAC)))) THEN (done_tac)))));; let real_cont_atreal_local = end_section_proof();; (add_section_type (mk_var ("f", (`:real^N -> real`))); add_section_type (mk_var ("g", (`:real^N -> real`))));; (add_section_var (mk_var ("x", (`:real^N`))));; (add_section_var (mk_var ("domain", (`:real^N#real^N`))));; (begin_section "Point");; (start_section_proof ["f";"c"](`diff2c f x ==> diff2c (\x. c * f x) x`));; refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN diff2c)(new_rewrite [] []))) THEN ALL_TAC THEN (case THEN ((move ["d2f"]) THEN (move ["p2c"])))) THEN ((((USE_THM_THEN diff2_scale)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (move ["i"]) THEN (move ["j"]))))));; refine (by (VALID (((((fun thm_tac -> (fun thm_tac -> (USE_THEN "p2c")(ISPEC_THEN (mk_var("i",mk_type("num",[]))) thm_tac))(ISPEC_THEN (mk_var("j",mk_type("num",[]))) thm_tac))MP_TAC) THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN (GEN_ALL REAL_CONTINUOUS_CONTINUOUS1))(GSYM_THEN (new_rewrite [] [])))) THEN (move ["p2ij"]))))));; refine (by (VALID (((USE_THM_THEN real_cont_at_local) apply_tac))));; refine (by (VALID (((((USE_THEN "d2f")MP_TAC) THEN (clear_assumption "d2f") THEN BETA_TAC) THEN (((USE_THM_THEN diff2_eq_diff2_on_open)(new_rewrite [] [])) THEN ALL_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["open_s"])) THEN (case THEN (move ["xs"])) THEN (move ["d2s"]))))));; refine (by (VALID (((exists_tac (`(\x. c * partial2 j i f x)`)) THEN (exists_tac (mk_var("s",mk_type("fun",[mk_type("cart",[mk_type("real",[]);mk_vartype "N"]);mk_type("bool",[])]))))))));; refine (by (VALID (((THENL_FIRST) ((USE_THM_THEN REAL_CONTINUOUS_LMUL)(new_rewrite [] [])) (((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN (done_tac))))));; refine (by (VALID (((((USE_THEN "open_s")(new_rewrite [] [])) THEN ((USE_THEN "xs")(new_rewrite [] [])) THEN (simp_tac)) THEN (move ["y"]) THEN (DISCH_THEN (fun snd_th -> (USE_THEN "d2s")(MATCH_MP_THEN snd_th MP_TAC))) THEN (move ["d2y"])))));; refine (by (VALID ((((USE_THM_THEN second_partial_scale)(new_rewrite [] [])) THEN (done_tac)))));; let diff2c_scale = end_section_proof();; (start_section_proof ["f"](`diff2c f x ==> diff2c (\x. --f x) x`));; refine (by (VALID ((((DISCH_THEN (fun snd_th -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN diff2c_scale)(ISPEC_THEN (mk_var("f",mk_type("fun",[mk_type("cart",[mk_type("real",[]);mk_vartype "N"]);mk_type("real",[])]))) thm_tac))(ISPEC_THEN (`--(&1)`) thm_tac))(MATCH_MP_THEN snd_th MP_TAC))) THEN BETA_TAC) THEN ((USE_THM_THEN REAL_NEG_MINUS1)(GSYM_THEN (new_rewrite [] []))) THEN (done_tac)))));; let diff2c_neg = end_section_proof();; (begin_section "Composite");; (start_section_proof ["n";"u";"x"](`nth_diff_strong n u x ==> ?s. real_open s /\ x IN s /\ (!y. y IN s ==> nth_diff_strong n u y)`));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN nth_diff_strong)(new_rewrite [] []))) THEN ALL_TAC THEN (case THEN (move ["t"])) THEN (case THEN (move ["open_t"])) THEN (case THEN (move ["xt"])) THEN (move ["dt"])))));; refine (by (VALID (((exists_tac (mk_var("t",mk_type("fun",[mk_type("real",[]);mk_type("bool",[])])))) THEN ((((USE_THEN "xt")(new_rewrite [] [])) THEN ((USE_THEN "open_t")(new_rewrite [] [])) THEN (simp_tac)) THEN (move ["y"]) THEN (move ["yt"]))))));; refine (by (VALID (((exists_tac (mk_var("t",mk_type("fun",[mk_type("real",[]);mk_type("bool",[])])))) THEN (done_tac)))));; let nth_diff_strong_eq_on_open = end_section_proof();; (start_section_proof ["f";"x"](`diff2 f x ==> f real_continuous at x`));; refine (by (VALID ((((USE_THM_THEN diff2)(new_rewrite [] [])) 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 (((((USE_THM_THEN (GEN_ALL REAL_CONTINUOUS_CONTINUOUS1))(new_rewrite [] [])) THEN ((USE_THM_THEN DIFFERENTIABLE_IMP_CONTINUOUS_AT)(new_rewrite [] [])) THEN ((USE_THEN "df")(new_rewrite [] []))) THEN (done_tac)))));; let diff2_imp_cont = end_section_proof();; (start_section_proof ["f";"i";"x"](`diff2 f x ==> (partial i f) real_continuous at x`));; refine (by (VALID ((((USE_THM_THEN diff2)(new_rewrite [] [])) 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 (((((USE_THM_THEN (GEN_ALL REAL_CONTINUOUS_CONTINUOUS1))(new_rewrite [] [])) THEN ((USE_THM_THEN DIFFERENTIABLE_IMP_CONTINUOUS_AT)(new_rewrite [] [])) THEN ((USE_THEN "df")(new_rewrite [] []))) THEN (done_tac)))));; let diff2_imp_partial_cont = end_section_proof();; (start_section_proof ["u";"f";"x"](`diff2c f x ==> nth_diff_strong 2 u (f x) ==> (nth_derivative 2 u) real_continuous atreal (f x) ==> diff2c (u o f) x`));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN diff2c)(new_rewrite [] []))) THEN ALL_TAC THEN (case THEN (move ["d2f"])) THEN (move ["p2c"]) THEN (move ["d2u"]) THEN (move ["u2c"])))));; refine (by (VALID (((((USE_THM_THEN diff2_uni_compose)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "d2f")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "d2u")(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (move ["i"]) THEN (move ["j"])))));; refine (by (VALID (((((fun thm_tac -> (fun thm_tac -> (USE_THEN "p2c")(ISPEC_THEN (mk_var("i",mk_type("num",[]))) thm_tac))(ISPEC_THEN (mk_var("j",mk_type("num",[]))) thm_tac))MP_TAC) THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN (GEN_ALL REAL_CONTINUOUS_CONTINUOUS1))(GSYM_THEN (new_rewrite [] [])))) THEN (move ["p2ij"]))))));; refine (by (VALID (((USE_THM_THEN real_cont_at_local) apply_tac))));; refine (by (VALID (((((USE_THEN "d2f")MP_TAC) THEN (clear_assumption "d2f") THEN BETA_TAC) THEN (((USE_THM_THEN diff2_eq_diff2_on_open)(new_rewrite [] [])) THEN ALL_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["open_s"])) THEN (case THEN (move ["xs"])) THEN (move ["d2s"]))))));; refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN nth_diff_strong_eq_on_open)(fun fst_th ->(USE_THEN "d2u")(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 ["fxt"])) THEN (move ["d2t"])))));; refine (by (VALID ((set_tac "r" (`{z | z IN s /\ (lift o f) z IN (IMAGE lift t)}`)))));; refine (by (VALID ((have_tac (move ["open_r"]) (`open r`)))));; refine (by (VALID ((((USE_THEN "r_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN CONTINUOUS_OPEN_PREIMAGE)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_OPEN)(GSYM_THEN (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 DIFFERENTIABLE_IMP_CONTINUOUS_ON) apply_tac) THEN (((USE_THM_THEN differentiable_on)(new_rewrite [] [])) THEN (move ["y"]) THEN (move ["ys"])) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th]))))));; refine (by (VALID (((USE_THM_THEN DIFFERENTIABLE_AT_WITHIN)(new_rewrite [] [])))));; refine (by (VALID (((((fun thm_tac -> (USE_THEN "d2s")(fun fst_th ->(USE_THEN "ys")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC) THEN (((USE_THM_THEN diff2)(new_rewrite [] [])) THEN ALL_TAC THEN (case THEN (move ["s'"])) THEN (case THEN (move ["_"])) THEN (case THEN (move ["ys'"])))))));; refine (by (VALID (((((fun thm_tac -> DISCH_THEN (fun fst_th ->(USE_THEN "ys'")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (simp_tac)) THEN (done_tac)))));; refine (by (VALID (((exists_tac (`(\x. (nth_derivative 2 u (f x) * partial j f x) * partial i f x + derivative u (f x) * partial2 j i f x)`)) THEN (exists_tac (mk_var("r",mk_type("fun",[mk_type("cart",[mk_type("real",[]);mk_vartype "N"]);mk_type("bool",[])]))))))));; refine (by (VALID (((THENL_ROT (-1)) ((((USE_THEN "open_r")(new_rewrite [] [])) THEN ((USE_THEN "r_def")(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_ELIM_THM)(new_rewrite [] []))) THEN (simp_tac) THEN ((USE_THM_THEN o_THM)(new_rewrite [] [])) THEN ((USE_THM_THEN LIFT_IN_IMAGE_LIFT)(new_rewrite [] []))) THEN (split_tac))))));; refine (by (VALID ((BETA_TAC THEN (move ["y"]) THEN (case THEN (move ["z"])) THEN (case THEN ALL_TAC) THEN (case THEN (move ["zs"])) THEN (move ["fzt"]) THEN (move ["yz"])))));; refine (by (VALID (((((USE_THM_THEN second_partial_uni_compose)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THEN "yz")(new_rewrite [] [])) THEN ((USE_THEN "d2s")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THEN "d2t")(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((THENL_LAST) (split_tac) ((exists_tac (mk_var("x",mk_type("cart",[mk_type("real",[]);mk_vartype "N"])))) THEN (done_tac))))));; refine (by (VALID (((((USE_THM_THEN REAL_CONTINUOUS_ADD)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_CONTINUOUS_MUL)(new_rewrite [] []))) THEN ((simp_tac THEN TRY done_tac))) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN (repeat_tactic 0 10 (((fun thm_tac ->(USE_THM_THEN diff2_imp_partial_cont)(fun tmp_th1 -> (USE_THEN "d2s")(fun tmp_th2 -> thm_tac (CONJ tmp_th1 tmp_th2))))(new_rewrite [] []))) THEN ((TRY done_tac)))))));; refine (by (VALID (((((USE_THM_THEN andbT)(new_rewrite [] [])) THEN ((USE_THM_THEN o_THM)(GSYM_THEN (new_rewrite [] [(`nth_derivative 2 u _1`)])))) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th]))))));; refine (by (VALID (((USE_THM_THEN (GEN_ALL REAL_CONTINUOUS_CONTINUOUS1))(new_rewrite [] [])))));; refine (by (VALID ((((USE_THM_THEN o_ASSOC)(new_rewrite [] [])) THEN ((USE_THM_THEN CONTINUOUS_REAL_CONTINUOUS_AT_COMPOSE)(new_rewrite [] [])) THEN ((USE_THM_THEN diff2_imp_cont)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "d2s")(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))))));; refine (by (VALID (((((USE_THM_THEN (GEN_ALL REAL_CONTINUOUS_CONTINUOUS1))(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN REAL_CONTINUOUS_ATREAL_WITHINREAL)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((((USE_THEN "p2ij")(new_rewrite [] [])) THEN ((USE_THM_THEN andbT)(new_rewrite [] [])) THEN ((USE_THM_THEN o_THM)(GSYM_THEN (new_rewrite [] [(`derivative u _`)])))) THEN ((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th]))))));; refine (by (VALID (((USE_THM_THEN (GEN_ALL REAL_CONTINUOUS_CONTINUOUS1))(new_rewrite [] [])))));; refine (by (VALID ((((USE_THM_THEN o_ASSOC)(new_rewrite [] [])) THEN ((USE_THM_THEN CONTINUOUS_REAL_CONTINUOUS_AT_COMPOSE)(new_rewrite [] [])) THEN ((USE_THM_THEN diff2_imp_cont)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "d2s")(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))))));; refine (by (VALID ((((USE_THM_THEN (GEN_ALL REAL_CONTINUOUS_CONTINUOUS1))(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN REAL_CONTINUOUS_ATREAL_WITHINREAL)(new_rewrite [] []))))));; refine (by (VALID ((((USE_THM_THEN nth_derivative1)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN nth_derivative_continuous) apply_tac)))));; refine (by (VALID (((THENL_LAST) ((exists_tac (`2`)) THEN (split_tac)) ((arith_tac) THEN (done_tac))))));; refine (by (VALID (((((fun thm_tac -> (USE_THEN "d2t")(fun fst_th ->(USE_THEN "fxt")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC) THEN ((((USE_THM_THEN nth_diff_strong)(new_rewrite [] [])) THEN ((USE_THM_THEN nth_differentiable_on)(new_rewrite [] []))) THEN ALL_TAC THEN (case THEN (move ["t'"])) THEN (case THEN (move ["_"])) THEN (case THEN (move ["fxt'"])) THEN (DISCH_THEN(new_rewrite [] []))) THEN (done_tac)))));; let diff2c_uni_compose = end_section_proof();; (start_section_proof ["s";"x"](`real_open s ==> real_open (s DELETE x)`));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN REAL_OPEN)(new_rewrite [] []))) THEN (DISCH_THEN (fun snd_th -> (USE_THM_THEN OPEN_DELETE)(MATCH_MP_THEN snd_th MP_TAC))) THEN ((fun thm_tac -> DISCH_THEN (ISPEC_THEN (`lift x`) thm_tac))MP_TAC)))));; refine (by (VALID (((((USE_THM_THEN IMAGE_DELETE_INJ)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN LIFT_EQ)(new_rewrite [] [])))) THEN (done_tac)))));; let real_open_delete = end_section_proof();; (start_section_proof ["f"](`~(f x = &0) ==> diff2c f x ==> diff2c (inv o f) x`));; refine (by (VALID (((BETA_TAC THEN (move ["fn0"]) THEN (move ["d2f"])) THEN ((USE_THM_THEN diff2c_uni_compose)(new_rewrite [] []))))));; refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN diff2_inv)(fun fst_th ->(USE_THEN "fn0")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] [])) THEN ((USE_THEN "d2f")(new_rewrite [] [])) THEN (simp_tac)))));; refine (by (VALID ((((USE_THM_THEN real_cont_atreal_local)MP_TAC) THEN (clear_assumption "real_cont_atreal_local") THEN (DISCH_THEN apply_tac)))));; refine (by (VALID (((exists_tac (`\x. &2 * inv (x pow 3)`)) THEN (exists_tac (`UNIV DELETE (&0)`))))));; refine (by (VALID (((THENL_ROT (-1)) ((((USE_THM_THEN real_open_delete)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_OPEN_UNIV)(new_rewrite [] []))) THEN (simp_tac) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_DELETE)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_UNIV)(new_rewrite [] []))) THEN ((USE_THEN "fn0")(new_rewrite [] [])) THEN (simp_tac)) THEN (split_tac))))));; refine (by (VALID (((BETA_TAC THEN (move ["y"]) THEN (move ["yn0"])) THEN ((USE_THM_THEN second_derivative_inv)(new_rewrite [] [])) THEN (done_tac)))));; refine (by (VALID ((((USE_THM_THEN REAL_CONTINUOUS_LMUL)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_CONTINUOUS_INV_ATREAL)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_CONTINUOUS_POW)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_CONTINUOUS_AT_ID)(new_rewrite [] [])))))));; refine (by (VALID ((((USE_THM_THEN REAL_POW_NZ)(new_rewrite [] [])) THEN (done_tac)))));; let diff2c_inv_compose = end_section_proof();; (start_section_proof ["f"](`&0 < f x ==> diff2c f x ==> diff2c (sqrt o f) x`));; refine (by (VALID (((BETA_TAC THEN (move ["fn0"]) THEN (move ["d2f"])) THEN ((USE_THM_THEN diff2c_uni_compose)(new_rewrite [] []))))));; refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN diff2_sqrt)(fun fst_th ->(USE_THEN "fn0")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] [])) THEN ((USE_THEN "d2f")(new_rewrite [] [])) THEN (simp_tac)))));; refine (by (VALID ((((USE_THM_THEN real_cont_atreal_local)MP_TAC) THEN (clear_assumption "real_cont_atreal_local") THEN (DISCH_THEN apply_tac)))));; refine (by (VALID (((exists_tac (`\x. -- inv (&4 * sqrt (x pow 3))`)) THEN (exists_tac (`{x | x > &0}`))))));; refine (by (VALID (((THENL_ROT (-1)) ((((USE_THM_THEN REAL_OPEN_HALFSPACE_GT)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_ELIM_THM)(new_rewrite [] []))) THEN (simp_tac) THEN repeat_tactic 1 9 (((USE_THM_THEN real_gt)(new_rewrite [] [])))) THEN (split_tac))))));; refine (by (VALID (((BETA_TAC THEN (move ["y"]) THEN (case THEN (move ["z"])) THEN (case THEN (move ["z0"])) THEN (DISCH_THEN(new_rewrite [] []))) THEN ((USE_THM_THEN second_derivative_sqrt)(new_rewrite [] [])) THEN (done_tac)))));; refine (by (VALID (((THENL_LAST) (split_tac) ((exists_tac (`f x`)) THEN (done_tac))))));; refine (by (VALID (((THENL_ROT (-1)) (((USE_THM_THEN REAL_CONTINUOUS_NEG)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_CONTINUOUS_INV_ATREAL)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_CONTINUOUS_LMUL)(new_rewrite [] [])))))));; refine (by (VALID (((THENL_FIRST) ((((USE_THM_THEN REAL_ENTIRE)(new_rewrite [] [])) THEN ((USE_THM_THEN negb_or)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (split_tac)) ((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_POW_NZ)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_POS_NZ)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN REAL_POW_LE)(new_rewrite [] []))))));; refine (by (VALID (((((USE_THEN "fn0")MP_TAC) THEN (clear_assumption "fn0") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`(\x. sqrt (x pow 3)) = (sqrt o (\x. x pow 3))`)))));; refine (by (VALID (((((USE_THM_THEN FUN_EQ_THM)(new_rewrite [] [])) THEN ((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((((USE_THM_THEN REAL_CONTINUOUS_ATREAL_COMPOSE)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN REAL_CONTINUOUS_POW)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_CONTINUOUS_AT_ID)(new_rewrite [] []))) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))))));; refine (by (VALID (((((USE_THM_THEN REAL_CONTINUOUS_AT_SQRT)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_POW_LT)(new_rewrite [] []))) THEN (done_tac)))));; let diff2c_sqrt_compose = end_section_proof();; (start_section_proof ["f"](`diff2c f x ==> diff2c (atn o f) x`));; refine (by (VALID (((BETA_TAC THEN (move ["d2f"])) THEN ((USE_THM_THEN diff2c_uni_compose)(new_rewrite [] []))))));; refine (by (VALID ((((USE_THM_THEN diff2_atn)(new_rewrite [] [])) THEN ((USE_THEN "d2f")(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN nth_derivative2)(new_rewrite [] [])) THEN ((USE_THM_THEN second_derivative_atn)(new_rewrite [] []))))));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN REAL_CONTINUOUS_MUL)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_CONTINUOUS_CONST)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_CONTINUOUS_AT_ID)(new_rewrite [] []))) THEN ((simp_tac THEN TRY done_tac))))));; refine (by (VALID ((((USE_THM_THEN REAL_CONTINUOUS_POW)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_CONTINUOUS_INV_ATREAL)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_CONTINUOUS_ADD)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN andTb)(new_rewrite [] [])))))));; refine (by (VALID (((((USE_THM_THEN REAL_CONTINUOUS_CONST)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_CONTINUOUS_POW)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_CONTINUOUS_AT_ID)(new_rewrite [] [])))) THEN (done_tac)))));; refine (by (VALID (((USE_THM_THEN REAL_RNEG_UNIQ)(new_rewrite [] [])))));; refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN REAL_LE_POW_2)(ISPEC_THEN (`f x`) thm_tac)) MP_TAC) THEN ALL_TAC))));; refine (by (VALID (((arith_tac) THEN (done_tac)))));; let diff2c_atn_compose = end_section_proof();; (start_section_proof ["f"](`abs (f x) < &1 ==> diff2c f x ==> diff2c (acs o f) x`));; refine (by (VALID (((BETA_TAC THEN (move ["fn1"]) THEN (move ["d2f"])) THEN ((USE_THM_THEN diff2c_uni_compose)(new_rewrite [] []))))));; refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN diff2_acs)(fun fst_th ->(USE_THEN "fn1")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] [])) THEN ((USE_THEN "d2f")(new_rewrite [] [])) THEN (simp_tac)))));; refine (by (VALID ((((USE_THM_THEN real_cont_atreal_local)MP_TAC) THEN (clear_assumption "real_cont_atreal_local") THEN (DISCH_THEN apply_tac)))));; refine (by (VALID (((exists_tac (`\x. --(x / sqrt ((&1 - x * x) pow 3))`)) THEN (exists_tac (`{x | x < &1} INTER {x | x > -- &1}`))))));; refine (by (VALID ((((USE_THM_THEN REAL_OPEN_INTER)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_OPEN_HALFSPACE_GT)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_OPEN_HALFSPACE_LT)(new_rewrite [] []))) THEN ((TRY done_tac))))));; refine (by (VALID (((THENL_ROT (-1)) ((repeat_tactic 1 9 (((USE_THM_THEN IN_INTER)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_ELIM_THM)(new_rewrite [] []))) THEN (simp_tac) THEN repeat_tactic 1 9 (((USE_THM_THEN real_gt)(new_rewrite [] [])))) THEN (split_tac))))));; refine (by (VALID (((BETA_TAC THEN (move ["y"]) THEN (case THEN ALL_TAC) THEN (case THEN (move ["a"])) THEN (case THEN (move ["a1"])) THEN (DISCH_THEN(new_rewrite [] [])) THEN (case THEN (move ["b"])) THEN (case THEN (move ["b1"])) THEN (move ["ab"])) THEN (((USE_THM_THEN second_derivative_acs)(new_rewrite [] [])) THEN ((TRY done_tac)))))));; refine (by (VALID (((((USE_THEN "a1")MP_TAC) THEN (clear_assumption "a1") THEN ((USE_THEN "b1")MP_TAC) THEN (clear_assumption "b1") THEN ((USE_THEN "ab")MP_TAC) THEN (clear_assumption "ab") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID (((THENL_LAST) (split_tac) ((split_tac) THEN (exists_tac (`f x`)) THEN (((USE_THEN "fn1")MP_TAC) THEN (clear_assumption "fn1") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac))))));; refine (by (VALID (((USE_THM_THEN REAL_CONTINUOUS_NEG)(new_rewrite [] [])))));; refine (by (VALID (((USE_THM_THEN REAL_CONTINUOUS_DIV_ATREAL) apply_tac))));; refine (by (VALID ((have_tac (move ["h"]) (`&0 < (&1 - f x * f x) pow 3`)))));; refine (by (VALID (((USE_THM_THEN REAL_POW_LT)(new_rewrite [] [])))));; refine (by (VALID ((((USE_THM_THEN (REAL_ARITH `!a. &1 - a * a = (&1 - a) * (&1 + a)`))(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LT_MUL)(new_rewrite [] []))))));; refine (by (VALID (((((USE_THEN "fn1")MP_TAC) THEN (clear_assumption "fn1") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID (((THENL_ROT (-1)) ((((USE_THM_THEN REAL_CONTINUOUS_AT_ID)(new_rewrite [] [])) THEN (simp_tac)) THEN (split_tac))))));; refine (by (VALID (((((USE_THM_THEN SQRT_EQ_0)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_LE_LT)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN REAL_LT_IMP_NZ)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`(\x. sqrt ((&1 - x * x) pow 3)) = sqrt o (\x. (&1 - x * x) pow 3)`)))));; refine (by (VALID (((((USE_THM_THEN FUN_EQ_THM)(new_rewrite [] [])) THEN ((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((((USE_THM_THEN REAL_CONTINUOUS_ATREAL_COMPOSE)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_CONTINUOUS_AT_SQRT)(new_rewrite [] [])) THEN ((simp_tac THEN TRY done_tac))))));; refine (by (VALID ((((USE_THM_THEN REAL_CONTINUOUS_POW)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_CONTINUOUS_SUB)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_CONTINUOUS_CONST)(new_rewrite [] []))))));; refine (by (VALID (((((USE_THM_THEN REAL_CONTINUOUS_MUL)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_CONTINUOUS_AT_ID)(new_rewrite [] [])))) THEN (done_tac)))));; let diff2c_acs_compose = end_section_proof();; let diff2c_acs_compose = finalize_theorem diff2c_acs_compose;; let diff2c_atn_compose = finalize_theorem diff2c_atn_compose;; let diff2c_sqrt_compose = finalize_theorem diff2c_sqrt_compose;; let diff2c_inv_compose = finalize_theorem diff2c_inv_compose;; let real_open_delete = finalize_theorem real_open_delete;; let diff2c_uni_compose = finalize_theorem diff2c_uni_compose;; let diff2_imp_partial_cont = finalize_theorem diff2_imp_partial_cont;; let diff2_imp_cont = finalize_theorem diff2_imp_cont;; let nth_diff_strong_eq_on_open = finalize_theorem nth_diff_strong_eq_on_open;; (end_section "Composite");; (start_section_proof ["f";"g"](`diff2c f x ==> diff2c g x ==> diff2c (\x. f x + g x) x`));; refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN diff2c)(new_rewrite [] []))) THEN ALL_TAC THEN (case THEN ((move ["d2f"]) THEN (move ["p2f"]))) THEN (case THEN ((move ["d2g"]) THEN (move ["p2g"])))) THEN ((((USE_THM_THEN diff2_add)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (move ["i"]) THEN (move ["j"]))))));; refine (by (VALID (((((fun thm_tac -> (fun thm_tac -> (USE_THEN "p2g")(ISPEC_THEN (mk_var("i",mk_type("num",[]))) thm_tac))(ISPEC_THEN (mk_var("j",mk_type("num",[]))) thm_tac))MP_TAC) THEN ((fun thm_tac -> (fun thm_tac -> (USE_THEN "p2f")(ISPEC_THEN (mk_var("i",mk_type("num",[]))) thm_tac))(ISPEC_THEN (mk_var("j",mk_type("num",[]))) thm_tac))MP_TAC) THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN (GEN_ALL REAL_CONTINUOUS_CONTINUOUS1))(GSYM_THEN (new_rewrite [] [])))) THEN (move ["p2fij"]) THEN (move ["p2gij"]))))));; refine (by (VALID (((USE_THM_THEN real_cont_at_local) apply_tac))));; refine (by (VALID (((((USE_THEN "d2g")MP_TAC) THEN (clear_assumption "d2g") THEN ((USE_THEN "d2f")MP_TAC) THEN (clear_assumption "d2f") THEN BETA_TAC) THEN (((USE_THM_THEN diff2_eq_diff2_on_open)(new_rewrite [] [])) THEN ALL_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["open_s"])) THEN (case THEN (move ["xs"])) THEN (move ["d2f"]))))));; refine (by (VALID ((((USE_THM_THEN diff2_eq_diff2_on_open)(new_rewrite [] [])) THEN ALL_TAC THEN (case THEN (move ["t"])) THEN (case THEN (move ["open_t"])) THEN (case THEN (move ["xt"])) THEN (move ["d2g"])))));; refine (by (VALID (((exists_tac (`(\x. partial2 j i f x + partial2 j i g x)`)) THEN (exists_tac (`s INTER t`))))));; refine (by (VALID (((THENL_FIRST) (repeat_tactic 1 9 (((USE_THM_THEN IN_INTER)(new_rewrite [] []))) THEN ((USE_THEN "xs")(new_rewrite [] [])) THEN ((USE_THEN "xt")(new_rewrite [] [])) THEN ((USE_THM_THEN OPEN_INTER)(new_rewrite [] [])) THEN ((simp_tac THEN TRY done_tac)) THEN ((USE_THM_THEN REAL_CONTINUOUS_ADD)(new_rewrite [] [])) THEN (simp_tac)) (((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN (done_tac))))));; refine (by (VALID (((BETA_TAC THEN (move ["y"]) THEN (case THEN ((move ["ys"]) THEN (move ["yt"])))) THEN (((USE_THM_THEN second_partial_add)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "d2f")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "d2g")(new_rewrite [] [])))) THEN (done_tac)))));; let diff2c_add = end_section_proof();; (start_section_proof ["f";"g"](`diff2c f x ==> diff2c g x ==> diff2c (\x. f x - g x) x`));; refine (by (VALID (((BETA_TAC THEN (move ["d2f"]) THEN (move ["d2g"])) THEN (((USE_THM_THEN real_sub)(new_rewrite [] [])) THEN ((USE_THM_THEN diff2c_add)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN diff2c_neg)(new_rewrite [] []))) THEN (done_tac)))));; let diff2c_sub = end_section_proof();; (start_section_proof ["f";"g"](`diff2c f x ==> diff2c g x ==> diff2c (\x. f x * g x) x`));; refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN diff2c)(new_rewrite [] []))) THEN ALL_TAC THEN (case THEN ((move ["d2f"]) THEN (move ["p2f"]))) THEN (case THEN ((move ["d2g"]) THEN (move ["p2g"])))) THEN ((((USE_THM_THEN diff2_mul)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andTb)(new_rewrite [] []))) THEN (move ["i"]) THEN (move ["j"]))))));; refine (by (VALID (((((fun thm_tac -> (fun thm_tac -> (USE_THEN "p2g")(ISPEC_THEN (mk_var("i",mk_type("num",[]))) thm_tac))(ISPEC_THEN (mk_var("j",mk_type("num",[]))) thm_tac))MP_TAC) THEN ((fun thm_tac -> (fun thm_tac -> (USE_THEN "p2f")(ISPEC_THEN (mk_var("i",mk_type("num",[]))) thm_tac))(ISPEC_THEN (mk_var("j",mk_type("num",[]))) thm_tac))MP_TAC) THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN (GEN_ALL REAL_CONTINUOUS_CONTINUOUS1))(GSYM_THEN (new_rewrite [] [])))) THEN (move ["p2fij"]) THEN (move ["p2gij"]))))));; refine (by (VALID (((USE_THM_THEN real_cont_at_local) apply_tac))));; refine (by (VALID (((((USE_THEN "d2g")MP_TAC) THEN (clear_assumption "d2g") THEN ((USE_THEN "d2f")MP_TAC) THEN (clear_assumption "d2f") THEN BETA_TAC) THEN (((USE_THM_THEN diff2_eq_diff2_on_open)(new_rewrite [] [])) THEN ALL_TAC THEN (case THEN (move ["s"])) THEN (case THEN (move ["open_s"])) THEN (case THEN (move ["xs"])) THEN (move ["d2f"]))))));; refine (by (VALID ((((USE_THM_THEN diff2_eq_diff2_on_open)(new_rewrite [] [])) THEN ALL_TAC THEN (case THEN (move ["t"])) THEN (case THEN (move ["open_t"])) THEN (case THEN (move ["xt"])) THEN (move ["d2g"])))));; refine (by (VALID (((exists_tac (`(\x. (partial2 j i f x * g x + partial i f x * partial j g x) + partial j f x * partial i g x + f x * partial2 j i g x)`)) THEN (exists_tac (`s INTER t`))))));; refine (by (VALID (((THENL_ROT (-1)) ((repeat_tactic 1 9 (((USE_THM_THEN IN_INTER)(new_rewrite [] []))) THEN ((USE_THEN "xs")(new_rewrite [] [])) THEN ((USE_THEN "xt")(new_rewrite [] [])) THEN ((USE_THM_THEN OPEN_INTER)(new_rewrite [] [])) THEN ((simp_tac THEN TRY done_tac))) THEN (split_tac))))));; refine (by (VALID (((BETA_TAC THEN (move ["y"]) THEN (case THEN ((move ["ys"]) THEN (move ["yt"])))) THEN (((USE_THM_THEN second_partial_mul)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "d2f")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "d2g")(new_rewrite [] [])))) THEN (done_tac)))));; refine (by (VALID (((repeat_tactic 1 9 (((USE_THM_THEN REAL_CONTINUOUS_ADD)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_CONTINUOUS_MUL)(new_rewrite [] [])))) THEN (((USE_THM_THEN ETA_AX)(fun th -> ONCE_REWRITE_TAC[th])) THEN ((TRY done_tac))) THEN (repeat_tactic 0 10 (((USE_THEN "p2gij")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "p2fij")(new_rewrite [] []))) THEN (simp_tac) THEN repeat_tactic 0 10 (((USE_THM_THEN diff2_imp_partial_cont)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN diff2_imp_cont)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "d2f")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "d2g")(new_rewrite [] [])))) THEN (done_tac)))));; let diff2c_mul = end_section_proof();; let diff2c_mul = finalize_theorem diff2c_mul;; let diff2c_sub = finalize_theorem diff2c_sub;; let diff2c_add = finalize_theorem diff2c_add;; let diff2c_acs_compose = finalize_theorem diff2c_acs_compose;; let diff2c_atn_compose = finalize_theorem diff2c_atn_compose;; let diff2c_sqrt_compose = finalize_theorem diff2c_sqrt_compose;; let diff2c_inv_compose = finalize_theorem diff2c_inv_compose;; let real_open_delete = finalize_theorem real_open_delete;; let diff2c_uni_compose = finalize_theorem diff2c_uni_compose;; let diff2_imp_partial_cont = finalize_theorem diff2_imp_partial_cont;; let diff2_imp_cont = finalize_theorem diff2_imp_cont;; let nth_diff_strong_eq_on_open = finalize_theorem nth_diff_strong_eq_on_open;; let diff2c_neg = finalize_theorem diff2c_neg;; let diff2c_scale = finalize_theorem diff2c_scale;; (end_section "Point");; (begin_section "Domain");; (add_section_var (mk_var ("f", (`:real^N -> real`))); add_section_var (mk_var ("g", (`:real^N -> real`))));; (add_section_hyp "d2f" (`diff2c_domain domain f`));; (start_section_proof ["c"](`diff2c_domain domain (\x. c * f x)`));; refine (by (VALID (((((USE_THEN "d2f")MP_TAC) THEN (clear_assumption "d2f") THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN diff2c_domain)(new_rewrite [] []))) THEN (move ["d2f"]) THEN (move ["x"]) THEN (move ["x_in"])) THEN (((USE_THM_THEN diff2c_scale)(new_rewrite [] [])) THEN ((USE_THEN "d2f")(new_rewrite [] []))) THEN (done_tac)))));; let diff2c_domain_scale = end_section_proof();; (start_section_proof [](`diff2c_domain domain (\x. --f x)`));; refine (by (VALID (((((USE_THEN "d2f")MP_TAC) THEN (clear_assumption "d2f") THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN diff2c_domain)(new_rewrite [] []))) THEN (move ["d2f"]) THEN (move ["x"]) THEN (move ["x_in"])) THEN (((USE_THM_THEN diff2c_neg)(new_rewrite [] [])) THEN ((USE_THEN "d2f")(new_rewrite [] []))) THEN (done_tac)))));; let diff2c_domain_neg = end_section_proof();; (add_section_var (mk_var ("bounds", (`:real#real`))));; (start_section_proof [](`m_bounded_on_int f domain bounds ==> interval_not_zero bounds ==> diff2c_domain domain (inv o f)`));; refine (by (VALID (((((USE_THEN "d2f")MP_TAC) THEN (clear_assumption "d2f") THEN BETA_TAC) THEN ((((USE_THM_THEN m_bounded_on_int)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN diff2c_domain)(new_rewrite [] [])))) THEN (move ["d2f"]) THEN (move ["ineq"]) THEN (move ["n0"]) THEN (move ["x"]) THEN (move ["x_in"]))))));; refine (by (VALID (((((USE_THM_THEN diff2c_inv_compose)(new_rewrite [] [])) THEN ((USE_THEN "d2f")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andbT)(new_rewrite [] [])) THEN ((fun thm_tac -> (USE_THM_THEN interval_arith_not_zero)(fun fst_th ->(fun thm_tac -> (USE_THEN "ineq")(fun fst_th ->(USE_THEN "x_in")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] []))) THEN (done_tac)))));; let diff2c_domain_inv_compose = end_section_proof();; (start_section_proof [](`m_bounded_on_int f domain bounds ==> interval_pos bounds ==> diff2c_domain domain (sqrt o f)`));; refine (by (VALID (((((USE_THEN "d2f")MP_TAC) THEN (clear_assumption "d2f") THEN BETA_TAC) THEN ((((USE_THM_THEN m_bounded_on_int)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN diff2c_domain)(new_rewrite [] [])))) THEN (move ["d2f"]) THEN (move ["ineq"]) THEN (move ["n0"]) THEN (move ["x"]) THEN (move ["x_in"]))))));; refine (by (VALID (((((USE_THM_THEN diff2c_sqrt_compose)(new_rewrite [] [])) THEN ((USE_THEN "d2f")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andbT)(new_rewrite [] [])) THEN ((fun thm_tac -> (USE_THM_THEN interval_arith_pos)(fun fst_th ->(fun thm_tac -> (USE_THEN "ineq")(fun fst_th ->(USE_THEN "x_in")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] []))) THEN (done_tac)))));; let diff2c_domain_sqrt_compose = end_section_proof();; (start_section_proof [](`diff2c_domain domain (atn o f)`));; refine (by (VALID (((((USE_THEN "d2f")MP_TAC) THEN (clear_assumption "d2f") THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN diff2c_domain)(new_rewrite [] []))) THEN (move ["d2f"]) THEN (move ["x"]) THEN (move ["x_in"])) THEN (((USE_THM_THEN diff2c_atn_compose)(new_rewrite [] [])) THEN ((USE_THEN "d2f")(new_rewrite [] []))) THEN (done_tac)))));; let diff2c_domain_atn_compose = end_section_proof();; (start_section_proof [](`m_bounded_on_int f domain bounds ==> iabs bounds < &1 ==> diff2c_domain domain (acs o f)`));; refine (by (VALID (((((USE_THEN "d2f")MP_TAC) THEN (clear_assumption "d2f") THEN BETA_TAC) THEN ((((USE_THM_THEN m_bounded_on_int)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN diff2c_domain)(new_rewrite [] [])))) THEN (move ["d2f"]) THEN (move ["ineq"]) THEN (move ["n0"]) THEN (move ["x"]) THEN (move ["x_in"]))))));; refine (by (VALID (((((USE_THM_THEN diff2c_acs_compose)(new_rewrite [] [])) THEN ((USE_THEN "d2f")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andbT)(new_rewrite [] [])) THEN ((fun thm_tac -> (USE_THM_THEN interval_arith_abs)(fun fst_th ->(fun thm_tac -> (USE_THEN "ineq")(fun fst_th ->(USE_THEN "x_in")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] []))) THEN (done_tac)))));; let diff2c_domain_acs_compose = end_section_proof();; (add_section_hyp "d2g" (`diff2c_domain domain g`));; (start_section_proof [](`diff2c_domain domain (\x. f x + g x)`));; refine (by (VALID (((((USE_THEN "d2g")MP_TAC) THEN (clear_assumption "d2g") THEN ((USE_THEN "d2f")MP_TAC) THEN (clear_assumption "d2f") THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN diff2c_domain)(new_rewrite [] []))) THEN (move ["d2f"]) THEN (move ["d2g"]) THEN (move ["x"]) THEN (move ["x_in"])) THEN (((USE_THM_THEN diff2c_add)(new_rewrite [] [])) THEN ((USE_THEN "d2f")(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "d2g")(new_rewrite [] [])))) THEN (done_tac)))));; let diff2c_domain_add = end_section_proof();; (start_section_proof [](`diff2c_domain domain (\x. f x - g x)`));; refine (by (VALID (((((USE_THEN "d2g")MP_TAC) THEN (clear_assumption "d2g") THEN ((USE_THEN "d2f")MP_TAC) THEN (clear_assumption "d2f") THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN diff2c_domain)(new_rewrite [] []))) THEN (move ["d2f"]) THEN (move ["d2g"]) THEN (move ["x"]) THEN (move ["x_in"])) THEN (((USE_THM_THEN diff2c_sub)(new_rewrite [] [])) THEN ((USE_THEN "d2f")(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "d2g")(new_rewrite [] [])))) THEN (done_tac)))));; let diff2c_domain_sub = end_section_proof();; (start_section_proof [](`diff2c_domain domain (\x. f x * g x)`));; refine (by (VALID (((((USE_THEN "d2g")MP_TAC) THEN (clear_assumption "d2g") THEN ((USE_THEN "d2f")MP_TAC) THEN (clear_assumption "d2f") THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN diff2c_domain)(new_rewrite [] []))) THEN (move ["d2f"]) THEN (move ["d2g"]) THEN (move ["x"]) THEN (move ["x_in"])) THEN (((USE_THM_THEN diff2c_mul)(new_rewrite [] [])) THEN ((USE_THEN "d2f")(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "d2g")(new_rewrite [] [])))) THEN (done_tac)))));; let diff2c_domain_mul = end_section_proof();; let diff2c_domain_mul = finalize_theorem diff2c_domain_mul;; let diff2c_domain_sub = finalize_theorem diff2c_domain_sub;; let diff2c_domain_add = finalize_theorem diff2c_domain_add;; let diff2c_domain_acs_compose = finalize_theorem diff2c_domain_acs_compose;; let diff2c_domain_atn_compose = finalize_theorem diff2c_domain_atn_compose;; let diff2c_domain_sqrt_compose = finalize_theorem diff2c_domain_sqrt_compose;; let diff2c_domain_inv_compose = finalize_theorem diff2c_domain_inv_compose;; let diff2c_domain_neg = finalize_theorem diff2c_domain_neg;; let diff2c_domain_scale = finalize_theorem diff2c_domain_scale;; (end_section "Domain");; let diff2c_domain_mul = finalize_theorem diff2c_domain_mul;; let diff2c_domain_sub = finalize_theorem diff2c_domain_sub;; let diff2c_domain_add = finalize_theorem diff2c_domain_add;; let diff2c_domain_acs_compose = finalize_theorem diff2c_domain_acs_compose;; let diff2c_domain_atn_compose = finalize_theorem diff2c_domain_atn_compose;; let diff2c_domain_sqrt_compose = finalize_theorem diff2c_domain_sqrt_compose;; let diff2c_domain_inv_compose = finalize_theorem diff2c_domain_inv_compose;; let diff2c_domain_neg = finalize_theorem diff2c_domain_neg;; let diff2c_domain_scale = finalize_theorem diff2c_domain_scale;; let diff2c_mul = finalize_theorem diff2c_mul;; let diff2c_sub = finalize_theorem diff2c_sub;; let diff2c_add = finalize_theorem diff2c_add;; let diff2c_acs_compose = finalize_theorem diff2c_acs_compose;; let diff2c_atn_compose = finalize_theorem diff2c_atn_compose;; let diff2c_sqrt_compose = finalize_theorem diff2c_sqrt_compose;; let diff2c_inv_compose = finalize_theorem diff2c_inv_compose;; let real_open_delete = finalize_theorem real_open_delete;; let diff2c_uni_compose = finalize_theorem diff2c_uni_compose;; let diff2_imp_partial_cont = finalize_theorem diff2_imp_partial_cont;; let diff2_imp_cont = finalize_theorem diff2_imp_cont;; let nth_diff_strong_eq_on_open = finalize_theorem nth_diff_strong_eq_on_open;; let diff2c_neg = finalize_theorem diff2c_neg;; let diff2c_scale = finalize_theorem diff2c_scale;; let real_cont_atreal_local = finalize_theorem real_cont_atreal_local;; let real_cont_at_local = finalize_theorem real_cont_at_local;; (end_section "Diff2c");; (begin_section "M_LinApprox");; (add_section_var (mk_var ("f", (`:real^N -> real`))); add_section_var (mk_var ("g", (`:real^N -> real`))));; (add_section_var (mk_var ("bounds", (`:real#real`))));; (add_section_var (mk_var ("d_bounds_list", (`:(real#real)list`))));; (add_section_var (mk_var ("x", (`:real^N`))));; (start_section_proof [](`(lift o f) differentiable at x ==> interval_arith (--f x) bounds ==> all_n 1 d_bounds_list (\i int. interval_arith (--partial i f x) int) ==> m_lin_approx (\x. --f x) x bounds d_bounds_list`));; refine (by (VALID ((BETA_TAC THEN (move ["df"]) THEN (move ["b"]) THEN (move ["db"])))));; refine (by (VALID (((THENL_FIRST) (((USE_THM_THEN m_lin_approx)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THEN "b")(new_rewrite [] [])) THEN ((USE_THM_THEN f_lift_neg)(new_rewrite [] [])) THEN ((USE_THM_THEN DIFFERENTIABLE_NEG)(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 (done_tac))))));; refine (by (VALID (((ASM_SIMP_TAC[partial_neg]) THEN (done_tac)))));; let m_lin_approx_neg = end_section_proof();; (start_section_proof ["c"](`(lift o f) differentiable at x ==> interval_arith (c * f x) bounds ==> all_n 1 d_bounds_list (\i int. interval_arith (c * partial i f x) int) ==> m_lin_approx (\x. c * f x) x bounds d_bounds_list`));; refine (by (VALID ((BETA_TAC THEN (move ["df"]) THEN (move ["bH"]) THEN (move ["dbH"])))));; refine (by (VALID (((THENL_FIRST) (((USE_THM_THEN m_lin_approx)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THEN "bH")(new_rewrite [] [])) THEN ((USE_THM_THEN f_lift_scale)(new_rewrite [] [])) THEN ((USE_THM_THEN DIFFERENTIABLE_CMUL)(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 (done_tac))))));; refine (by (VALID (((ASM_SIMP_TAC[partial_scale]) THEN (done_tac)))));; let m_lin_approx_scale = end_section_proof();; (start_section_proof [](`(lift o f) differentiable at x ==> (lift o g) differentiable at x ==> interval_arith (f x + g x) bounds ==> all_n 1 d_bounds_list (\i int. interval_arith (partial i f x + partial i g x) int) ==> m_lin_approx (\x. f x + g x) x bounds d_bounds_list`));; refine (by (VALID ((BETA_TAC THEN (move ["df"]) THEN (move ["dg"]) THEN (move ["bH"]) THEN (move ["dbH"])))));; refine (by (VALID (((THENL_FIRST) (((USE_THM_THEN m_lin_approx)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THEN "bH")(new_rewrite [] [])) THEN ((USE_THM_THEN f_lift_add)(new_rewrite [] [])) THEN ((USE_THM_THEN DIFFERENTIABLE_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 (done_tac))))));; refine (by (VALID (((ASM_SIMP_TAC[partial_add]) THEN (done_tac)))));; let m_lin_approx_add = end_section_proof();; (start_section_proof [](`(lift o f) differentiable at x ==> (lift o g) differentiable at x ==> interval_arith (f x - g x) bounds ==> all_n 1 d_bounds_list (\i int. interval_arith (partial i f x - partial i g x) int) ==> m_lin_approx (\x. f x - g x) x bounds d_bounds_list`));; refine (by (VALID ((BETA_TAC THEN (move ["df"]) THEN (move ["dg"]) THEN (move ["bH"]) THEN (move ["dbH"])))));; refine (by (VALID (((THENL_FIRST) (((USE_THM_THEN m_lin_approx)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THEN "bH")(new_rewrite [] [])) THEN ((USE_THM_THEN f_lift_sub)(new_rewrite [] [])) THEN ((USE_THM_THEN DIFFERENTIABLE_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 (done_tac))))));; refine (by (VALID (((ASM_SIMP_TAC[partial_sub]) THEN (done_tac)))));; let m_lin_approx_sub = end_section_proof();; (start_section_proof [](`(lift o f) differentiable at x ==> (lift o g) differentiable at x ==> interval_arith (f x * g x) bounds ==> all_n 1 d_bounds_list (\i int. interval_arith (partial i f x * g x + f x * partial i g x) int) ==> m_lin_approx (\x. f x * g x) x bounds d_bounds_list`));; refine (by (VALID ((BETA_TAC THEN (move ["df"]) THEN (move ["dg"]) THEN (move ["bH"]) THEN (move ["dbH"])))));; refine (by (VALID ((((USE_THM_THEN m_lin_approx)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THEN "bH")(new_rewrite [] [])) THEN ((USE_THM_THEN differentiable_mul)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] [])))))));; refine (by (VALID (((ASM_SIMP_TAC[partial_mul]) THEN (done_tac)))));; let m_lin_approx_mul = end_section_proof();; let m_lin_approx_mul = finalize_theorem m_lin_approx_mul;; let m_lin_approx_sub = finalize_theorem m_lin_approx_sub;; let m_lin_approx_add = finalize_theorem m_lin_approx_add;; let m_lin_approx_scale = finalize_theorem m_lin_approx_scale;; let m_lin_approx_neg = finalize_theorem m_lin_approx_neg;; (end_section "M_LinApprox");; let second_bounded = new_definition `second_bounded f domain dd_bounds_list <=> !x. x IN interval [domain] ==> all_n 1 dd_bounds_list (\i list_i. all_n 1 list_i (\j int. interval_arith (partial2 j i f x) int))`;; let m_taylor_interval = new_definition `m_taylor_interval f domain y w f_bounds d_bounds_list dd_bounds_list <=> m_cell_domain domain y w /\ diff2c_domain domain f /\ m_lin_approx f y f_bounds d_bounds_list /\ second_bounded f domain dd_bounds_list`;; (begin_section "M_TaylorIntervalArith");; (add_section_var (mk_var ("f", (`:real^N -> real`))); add_section_var (mk_var ("g", (`:real^N -> real`))));; (add_section_var (mk_var ("x", (`:real^N`))); add_section_var (mk_var ("z", (`:real^N`))); add_section_var (mk_var ("y", (`:real^N`))); add_section_var (mk_var ("w", (`:real^N`))));; (add_section_var (mk_var ("domain", (`:real^N#real^N`))));; (add_section_var (mk_var ("f_bounds", (`:real#real`))); add_section_var (mk_var ("g_bounds", (`:real#real`))); add_section_var (mk_var ("bounds", (`:real#real`))));; (add_section_var (mk_var ("df_bounds_list", (`:(real#real)list`))); add_section_var (mk_var ("dg_bounds_list", (`:(real#real)list`))); add_section_var (mk_var ("d_bounds_list", (`:(real#real)list`))));; (add_section_var (mk_var ("ddf_bounds_list", (`:((real#real)list)list`))); add_section_var (mk_var ("ddg_bounds_list", (`:((real#real)list)list`))); add_section_var (mk_var ("dd_bounds_list", (`:((real#real)list)list`))));; (add_section_hyp "domainH" (`m_cell_domain domain y w`));; (add_section_hyp "d2f" (`diff2c_domain domain f`));; (start_section_proof [](`m_bounded_on_int f domain f_bounds ==> interval_not_zero f_bounds ==> m_lin_approx (inv o f) y bounds d_bounds_list ==> second_bounded (inv o f) domain dd_bounds_list ==> m_taylor_interval (inv o f) domain y w bounds d_bounds_list dd_bounds_list`));; refine (by (VALID (((BETA_TAC THEN (move ["bf"]) THEN (move ["fn0"]) THEN (move ["lin"]) THEN (move ["second"])) THEN ((USE_THM_THEN m_taylor_interval)(new_rewrite [] []))))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN diff2c_domain_inv_compose)(fun fst_th ->(USE_THEN "d2f")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "bf")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] [])) THEN (done_tac)))));; let m_taylor_inv_compose = end_section_proof();; (start_section_proof [](`m_bounded_on_int f domain f_bounds ==> interval_pos f_bounds ==> m_lin_approx (sqrt o f) y bounds d_bounds_list ==> second_bounded (sqrt o f) domain dd_bounds_list ==> m_taylor_interval (sqrt o f) domain y w bounds d_bounds_list dd_bounds_list`));; refine (by (VALID (((BETA_TAC THEN (move ["bf"]) THEN (move ["fn0"]) THEN (move ["lin"]) THEN (move ["second"])) THEN ((USE_THM_THEN m_taylor_interval)(new_rewrite [] []))))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN diff2c_domain_sqrt_compose)(fun fst_th ->(USE_THEN "d2f")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "bf")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] [])) THEN (done_tac)))));; let m_taylor_sqrt_compose = end_section_proof();; (start_section_proof [](`m_lin_approx (atn o f) y bounds d_bounds_list ==> second_bounded (atn o f) domain dd_bounds_list ==> m_taylor_interval (atn o f) domain y w bounds d_bounds_list dd_bounds_list`));; refine (by (VALID (((BETA_TAC THEN (move ["lin"]) THEN (move ["second"])) THEN (((USE_THM_THEN m_taylor_interval)(new_rewrite [] [])) THEN ((USE_THM_THEN diff2c_domain_atn_compose)(new_rewrite [] []))) THEN (done_tac)))));; let m_taylor_atn_compose = end_section_proof();; (start_section_proof [](`m_bounded_on_int f domain f_bounds ==> iabs f_bounds < &1 ==> m_lin_approx (acs o f) y bounds d_bounds_list ==> second_bounded (acs o f) domain dd_bounds_list ==> m_taylor_interval (acs o f) domain y w bounds d_bounds_list dd_bounds_list`));; refine (by (VALID (((BETA_TAC THEN (move ["bf"]) THEN (move ["fn0"]) THEN (move ["lin"]) THEN (move ["second"])) THEN ((USE_THM_THEN m_taylor_interval)(new_rewrite [] []))))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (USE_THM_THEN diff2c_domain_acs_compose)(fun fst_th ->(USE_THEN "d2f")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(fun fst_th ->(USE_THEN "bf")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))(new_rewrite [] [])) THEN (done_tac)))));; let m_taylor_acs_compose = end_section_proof();; (start_section_proof [](`m_lin_approx (\x. --f x) y bounds d_bounds_list ==> second_bounded (\x. --f x) domain dd_bounds_list ==> m_taylor_interval (\x. --f x) domain y w bounds d_bounds_list dd_bounds_list`));; refine (by (VALID (((BETA_TAC THEN (move ["lin"]) THEN (move ["second"])) THEN (((USE_THM_THEN m_taylor_interval)(new_rewrite [] [])) THEN ((USE_THM_THEN diff2c_domain_neg)(new_rewrite [] []))) THEN (done_tac)))));; let m_taylor_neg = end_section_proof();; (start_section_proof ["c"](`m_lin_approx (\x. c * f x) y bounds d_bounds_list ==> second_bounded (\x. c * f x) domain dd_bounds_list ==> m_taylor_interval (\x. c * f x) domain y w bounds d_bounds_list dd_bounds_list`));; refine (by (VALID (((BETA_TAC THEN (move ["lin"]) THEN (move ["second"])) THEN (((USE_THM_THEN m_taylor_interval)(new_rewrite [] [])) THEN ((USE_THM_THEN diff2c_domain_scale)(new_rewrite [] []))) THEN (done_tac)))));; let m_taylor_scale = end_section_proof();; (add_section_hyp "d2g" (`diff2c_domain domain g`));; (start_section_proof [](`m_lin_approx (\x. f x + g x) y bounds d_bounds_list ==> second_bounded (\x. f x + g x) domain dd_bounds_list ==> m_taylor_interval (\x. f x + g x) domain y w bounds d_bounds_list dd_bounds_list`));; refine (by (VALID (((BETA_TAC THEN (move ["lin"]) THEN (move ["second"])) THEN (((USE_THM_THEN m_taylor_interval)(new_rewrite [] [])) THEN ((USE_THM_THEN diff2c_domain_add)(new_rewrite [] []))) THEN (done_tac)))));; let m_taylor_add = end_section_proof();; (start_section_proof [](`m_lin_approx (\x. f x - g x) y bounds d_bounds_list ==> second_bounded (\x. f x - g x) domain dd_bounds_list ==> m_taylor_interval (\x. f x - g x) domain y w bounds d_bounds_list dd_bounds_list`));; refine (by (VALID (((BETA_TAC THEN (move ["lin"]) THEN (move ["second"])) THEN (((USE_THM_THEN m_taylor_interval)(new_rewrite [] [])) THEN ((USE_THM_THEN diff2c_domain_sub)(new_rewrite [] []))) THEN (done_tac)))));; let m_taylor_sub = end_section_proof();; (start_section_proof [](`m_lin_approx (\x. f x * g x) y bounds d_bounds_list ==> second_bounded (\x. f x * g x) domain dd_bounds_list ==> m_taylor_interval (\x. f x * g x) domain y w bounds d_bounds_list dd_bounds_list`));; refine (by (VALID (((BETA_TAC THEN (move ["lin"]) THEN (move ["second"])) THEN (((USE_THM_THEN m_taylor_interval)(new_rewrite [] [])) THEN ((USE_THM_THEN diff2c_domain_mul)(new_rewrite [] []))) THEN (done_tac)))));; let m_taylor_mul = end_section_proof();; let m_taylor_mul = finalize_theorem m_taylor_mul;; let m_taylor_sub = finalize_theorem m_taylor_sub;; let m_taylor_add = finalize_theorem m_taylor_add;; let m_taylor_scale = finalize_theorem m_taylor_scale;; let m_taylor_neg = finalize_theorem m_taylor_neg;; let m_taylor_acs_compose = finalize_theorem m_taylor_acs_compose;; let m_taylor_atn_compose = finalize_theorem m_taylor_atn_compose;; let m_taylor_sqrt_compose = finalize_theorem m_taylor_sqrt_compose;; let m_taylor_inv_compose = finalize_theorem m_taylor_inv_compose;; (end_section "M_TaylorIntervalArith");; (begin_section "PartialConvex");; (add_section_type (mk_var ("f", (`:real^N->real`))));; (start_section_proof ["f";"j";"x";"z";"u";"v";"hi"](`(!i. i IN 1..dimindex (:N) ==> ~(i = j) ==> u$i = z$i /\ v$i = x$i) ==> u$j = x$j ==> v$j = z$j ==> diff2_domain (x,z) f ==> (!y. y IN interval [x,z] ==> &0 <= partial2 j j f y) ==> (!y. y IN interval [x,u] ==> f y <= hi) ==> (!y. y IN interval [v,z] ==> f y <= hi) ==> (!y. y IN interval [x,z] ==> f y <= hi)`));; refine (by (VALID ((((USE_THM_THEN IN_NUMSEG)(new_rewrite [] [])) THEN (move ["uv_eq"]) THEN (move ["ux_eq"]) THEN (move ["vz_eq"])))));; refine (by (VALID ((((USE_THM_THEN diff2_domain)(new_rewrite [] [])) THEN (move ["diff2_f"]) THEN (move ["partial2_pos"]) THEN (move ["bound1"]) THEN (move ["bound2"]) THEN (move ["y"]) THEN (move ["y_in"])))));; refine (by (VALID ((set_tac "y1" (`(lambda i. if i = j then x$j else y$i):real^N`)))));; refine (by (VALID ((set_tac "y2" (`(lambda i. if i = j then z$j else y$i):real^N`)))));; refine (by (VALID (((((USE_THEN "y_in")MP_TAC) THEN (clear_assumption "y_in") THEN BETA_TAC) THEN (((USE_THM_THEN (GEN_ALL IN_INTERVAL))(new_rewrite [] [])) THEN (move ["y_in"]))))));; refine (by (VALID ((have_tac (ALL_TAC THEN (case THEN ((move ["y1_in"]) THEN (move ["y2_in"])))) (`y1 IN interval [x,u] /\ y2 IN interval [v,z]`)))));; refine (by (VALID ((((USE_THEN "y1_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THEN "y2_def")(GSYM_THEN (new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN (GEN_ALL IN_INTERVAL))(new_rewrite [] [])))))));; refine (by (VALID ((((split_tac) THEN (move ["i"]) THEN (move ["i_ineq"])) THEN (((USE_THM_THEN (GEN_ALL LAMBDA_BETA))(new_rewrite [] [])) THEN ((TRY done_tac))) THEN (((fun thm_tac -> (USE_THM_THEN EXCLUDED_MIDDLE)(ISPEC_THEN (`i = j`) thm_tac))MP_TAC) THEN case THEN (simp_tac) THEN (move ["ij"])) THEN (repeat_tactic 0 10 (((fun thm_tac ->(USE_THEN "ux_eq")(fun tmp_th1 -> (USE_THEN "vz_eq")(fun tmp_th2 -> thm_tac (CONJ tmp_th1 tmp_th2))))(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_LE_REFL)(new_rewrite [] []))) THEN ((TRY done_tac))) THEN (((USE_THEN "uv_eq")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN repeat_tactic 1 9 (((USE_THEN "y_in")(new_rewrite [] [])))) THEN (done_tac)))));; refine (by (VALID ((((THENL_ROT (-1)) (((fun thm_tac -> (USE_THM_THEN EXCLUDED_MIDDLE)(ISPEC_THEN (`j IN 1..dimindex (:N)`) thm_tac))MP_TAC) THEN case)) THEN (((USE_THM_THEN IN_NUMSEG)(new_rewrite [] [])) THEN (move ["j_in"]))))));; refine (by (VALID (((THENL_FIRST) (((THENL_ROT 1)) (have_tac ALL_TAC (`y1 = y`))) ((BETA_TAC THEN (DISCH_THEN(GSYM_THEN (new_rewrite [] [])))) THEN (((USE_THEN "bound1")MP_TAC) THEN (clear_assumption "bound1") THEN (DISCH_THEN apply_tac)) THEN (done_tac))))));; refine (by (VALID ((((USE_THM_THEN CART_EQ)(new_rewrite [] [])) THEN (move ["i"]) THEN (move ["i_in"])))));; refine (by (VALID (((THENL_FIRST) (have_tac (move ["inj"]) (`~(i = j)`)) ((((USE_THEN "i_in")MP_TAC) THEN (clear_assumption "i_in") THEN ((USE_THEN "j_in")MP_TAC) THEN (clear_assumption "j_in") THEN BETA_TAC) THEN (arith_tac) THEN (done_tac))))));; refine (by (VALID (((((USE_THEN "y1_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN (GEN_ALL LAMBDA_BETA))(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((((THENL_ROT 1)) (have_tac ALL_TAC (`f y <= max (f y1) (f y2)`))))));; refine (by (VALID ((BETA_TAC THEN (move ["cond"])))));; refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN (REWRITE_RULE[GSYM IMP_IMP] REAL_LE_TRANS))(fun fst_th ->(USE_THEN "cond")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN (DISCH_THEN apply_tac)))));; refine (by (VALID (((((fun thm_tac -> (USE_THEN "bound2")(fun fst_th ->(USE_THEN "y2_in")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN ((fun thm_tac -> (USE_THEN "bound1")(fun fst_th ->(USE_THEN "y1_in")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((set_tac "g" (`f o (\t. y1 + t % basis j)`)))));; refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`f y1 = g (&0)`)))));; refine (by (VALID (((((USE_THEN "g_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN o_THM)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN VECTOR_MUL_LZERO)(new_rewrite [] [])) THEN ((USE_THM_THEN VECTOR_ADD_RID)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((have_tac (move ["y_eq"]) (`y = y1 + (y$j - x$j) % basis j /\ y2 = y1 + (z$j - x$j) % basis j`)))));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN CART_EQ)(new_rewrite [] []))) THEN ((split_tac) THEN (move ["i"]) THEN (move ["i_in"])) THEN (((USE_THM_THEN VECTOR_ADD_COMPONENT)(new_rewrite [] [])) THEN ((USE_THM_THEN VECTOR_MUL_COMPONENT)(new_rewrite [] [])) THEN ((USE_THM_THEN BASIS_COMPONENT)(new_rewrite [] [])) THEN ((TRY done_tac))) THEN (((fun thm_tac -> (USE_THM_THEN EXCLUDED_MIDDLE)(ISPEC_THEN (`i = j`) thm_tac))MP_TAC) THEN case THEN (simp_tac) THEN (move ["ij"])) THEN (repeat_tactic 0 10 (((fun thm_tac ->(USE_THEN "y1_def")(fun tmp_th1 -> (USE_THEN "y2_def")(fun tmp_th2 -> thm_tac (CONJ tmp_th1 tmp_th2))))(GSYM_THEN (new_rewrite [] [])))) THEN repeat_tactic 1 9 (((USE_THM_THEN (GEN_ALL LAMBDA_BETA))(new_rewrite [] []))) THEN ((simp_tac THEN TRY done_tac)) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_MUL_RID)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_SUB_ADD2)(new_rewrite [] []))) THEN ((TRY done_tac)))))));; refine (by (VALID (((((USE_THEN "ij")(new_rewrite [] [])) THEN (simp_tac)) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID (((((USE_THEN "ij")(new_rewrite [] [])) THEN (simp_tac)) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID (((THENL_FIRST) (have_tac (DISCH_THEN(new_rewrite [] [])) (`f y = g (y$j - x$j)`)) ((((USE_THEN "g_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN o_THM)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THEN "y_eq")(GSYM_THEN (new_rewrite [] [])))) THEN (done_tac))))));; refine (by (VALID (((THENL_FIRST) (have_tac (DISCH_THEN(new_rewrite [] [])) (`f y2 = g (z$j - x$j)`)) ((((USE_THEN "g_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN o_THM)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THEN "y_eq")(GSYM_THEN (new_rewrite [] [])))) THEN (done_tac))))));; refine (by (VALID ((((fun thm_tac -> (USE_THM_THEN EXCLUDED_MIDDLE)(ISPEC_THEN (`z$j = x$j`) thm_tac))MP_TAC) THEN case THEN (move ["zx_j"])))));; refine (by (VALID (((THENL_FIRST) (((THENL_ROT 1)) (have_tac ALL_TAC (`y$j = x$j`))) ((BETA_TAC THEN (DISCH_THEN(new_rewrite [] []))) THEN (((USE_THEN "zx_j")(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_SUB_REFL)(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac))))));; refine (by (VALID (((((fun thm_tac -> (USE_THEN "y_in")(fun fst_th ->(USE_THEN "j_in")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC) THEN ((USE_THEN "zx_j")(new_rewrite [] [])) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((set_tac "t" (`(y$j - x$j) / (z$j - x$j)`)))));; refine (by (VALID ((have_tac (move ["zx_pos"]) (`&0 < z$j - x$j`)))));; refine (by (VALID ((((USE_THM_THEN (REAL_ARITH `!a b. &0 < a - b <=> ~(a = b) /\ b <= a`))(new_rewrite [] [])) THEN ((USE_THEN "zx_j")(new_rewrite [] [])) THEN (simp_tac)))));; 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 (`y$j`)) THEN repeat_tactic 1 9 (((USE_THEN "y_in")(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((have_tac (move ["t_props"]) (`&0 <= t /\ t <= &1 /\ y$j - x$j = (&1 - t) * &0 + t * (z$j - x$j)`)))));; refine (by (VALID ((((USE_THEN "t_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN Packing3.REAL_DIV_LE_1)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN REAL_MUL_RZERO)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_ADD_LID)(new_rewrite [] []))))));; refine (by (VALID ((((USE_THM_THEN real_div)(new_rewrite [] [])) THEN ((USE_THM_THEN (GEN_ALL REAL_MUL_ASSOC))(GSYM_THEN (new_rewrite [] [])))))));; refine (by (VALID ((((USE_THM_THEN REAL_MUL_LINV)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_SUB_0)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN REAL_MUL_RID)(new_rewrite [] [])) THEN (simp_tac)))));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN real_sub)(new_rewrite [] []))) THEN ((USE_THM_THEN REAL_LE_RADD)(new_rewrite [] [])) THEN ((USE_THEN "y_in")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andbT)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN real_sub)(GSYM_THEN (new_rewrite [] []))))))));; refine (by (VALID (((THENL_FIRST) (((USE_THM_THEN REAL_LE_MUL)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_LE_INV)(new_rewrite [] []))) (((USE_THM_THEN (REAL_ARITH `!a. &0 < a ==> &0 <= a`))(new_rewrite [] [])) THEN (done_tac))))));; refine (by (VALID (((((USE_THM_THEN REAL_SUB_LE)(new_rewrite [] [])) THEN ((USE_THEN "y_in")(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((((USE_THEN "t_props")(new_rewrite [] [])) THEN (((USE_THM_THEN (GEN_ALL REAL_CONVEX_LOWER))MP_TAC) THEN (DISCH_THEN apply_tac))))));; refine (by (VALID ((exists_tac (`real_interval [&0, z$j - x$j]`)))));; refine (by (VALID ((((USE_THM_THEN REAL_SUB_ADD)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_SUB_LE)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THEN "t_props")(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_LE_REFL)(new_rewrite [] []))) THEN (simp_tac)))));; refine (by (VALID ((((USE_THM_THEN (REAL_ARITH `!a. &0 < a ==> &0 <= a`))(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN andbT)(new_rewrite [] []))))));; refine (by (VALID (((set_tac "s" (`real_interval _`)) THEN (((USE_THEN "t_props")MP_TAC) THEN (clear_assumption "t_props") THEN ((USE_THEN "t_def")MP_TAC) THEN (clear_assumption "t_def") THEN BETA_TAC THEN (move ["_"]) THEN (move ["_"]))))));; refine (by (VALID ((have_tac (move ["in_s"]) (`!t. t IN s ==> y1 + t % basis j IN interval [x,z]`)))));; refine (by (VALID (((((USE_THEN "s_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN (GEN_ALL IN_INTERVAL))(new_rewrite [] []))) THEN (move ["t"]) THEN (move ["t_ineq"]) THEN (move ["i"]) THEN (move ["i_ineq"])))));; refine (by (VALID ((repeat_tactic 1 9 (((USE_THM_THEN VECTOR_ADD_COMPONENT)(new_rewrite [] []))) THEN ((USE_THM_THEN VECTOR_MUL_COMPONENT)(new_rewrite [] [])) THEN ((USE_THM_THEN BASIS_COMPONENT)(new_rewrite [] [])) THEN ((TRY done_tac))))));; refine (by (VALID ((((USE_THEN "y1_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN (GEN_ALL LAMBDA_BETA))(new_rewrite [] [])) THEN ((simp_tac THEN TRY done_tac))))));; refine (by (VALID (((THENL_ROT (-1)) (((fun thm_tac -> (USE_THM_THEN EXCLUDED_MIDDLE)(ISPEC_THEN (`i = j`) thm_tac))MP_TAC) THEN case THEN (simp_tac) THEN (move ["ij"]))))));; refine (by (VALID (((((USE_THM_THEN REAL_MUL_RZERO)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_ADD_RID)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THEN "y_in")(new_rewrite [] [])))) THEN (done_tac)))));; refine (by (VALID (((((USE_THEN "t_ineq")MP_TAC) THEN (clear_assumption "t_ineq") THEN ((fun thm_tac -> (USE_THEN "y_in")(fun fst_th ->(USE_THEN "i_ineq")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC) THEN ((USE_THEN "ij")(new_rewrite [] [])) THEN (arith_tac) THEN (done_tac)))));; refine (by (VALID ((have_tac (move ["diff2_g"]) (`!t. t IN s ==> nth_diff_strong 2 g t`)))));; refine (by (VALID (((BETA_TAC THEN (move ["t"]) THEN (move ["ts"])) THEN ((USE_THEN "g_def")(GSYM_THEN (new_rewrite [] []))) THEN (((USE_THM_THEN diff2_dir)(new_rewrite [] [])) THEN ((USE_THEN "diff2_f")(new_rewrite [] [])) THEN ((USE_THEN "in_s")(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((have_tac (move ["dg"]) (`!t. t IN s ==> derivative g t = partial j f (y1 + t % basis j)`)))));; refine (by (VALID (((BETA_TAC THEN (move ["t"]) THEN (move ["ts"])) THEN ((USE_THM_THEN partial)(new_rewrite [] []))))));; refine (by (VALID (((((fun thm_tac -> (USE_THEN "in_s")(fun fst_th ->(USE_THEN "ts")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC THEN (move ["p_in"])) THEN (set_tac "h" (`f o _`))))));; refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`h = g o (\t'. t + t')`)))));; refine (by (VALID ((((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THEN "h_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THEN "g_def")(GSYM_THEN (new_rewrite [] [])))) THEN (move ["r"])) THEN (repeat_tactic 1 9 (((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (simp_tac))))));; refine (by (VALID (((((USE_THM_THEN (GEN_ALL VECTOR_ADD_RDISTRIB))(new_rewrite [] [])) THEN ((USE_THM_THEN (GEN_ALL VECTOR_ADD_ASSOC))(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((((USE_THM_THEN derivative_translation)(GSYM_THEN (new_rewrite [] []))) THEN ((TRY done_tac))))));; refine (by (VALID (((((fun thm_tac -> (USE_THEN "diff2_g")(fun fst_th ->(USE_THEN "ts")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC) THEN (((USE_THM_THEN nth_diff_strong2_eq)(new_rewrite [] [])) THEN ALL_TAC THEN (case THEN (move ["e"])) THEN (case THEN (move ["_"])) THEN (case THEN (move ["te"])) THEN (DISCH_THEN(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((have_tac (move ["d2g"]) (`!t. t IN s ==> nth_derivative 2 g t = partial2 j j f (y1 + t % basis j)`)))));; refine (by (VALID (((BETA_TAC THEN (move ["t"]) THEN (move ["ts"])) THEN (((USE_THEN "g_def")(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN diff2_dir_derivative2)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "diff2_f")(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THEN "in_s")(new_rewrite [] []))) THEN ((TRY done_tac)))))));; refine (by (VALID ((have_tac (move ["s_eq"]) (`1..dimindex (:N) = ((1..dimindex (:N)) DELETE j) UNION {j}`)))));; refine (by (VALID ((((((USE_THM_THEN EXTENSION)(new_rewrite [] [])) THEN ((USE_THM_THEN IN_UNION)(new_rewrite [] [])) THEN ((USE_THM_THEN IN_SING)(new_rewrite [] [])) THEN ((USE_THM_THEN IN_DELETE)(new_rewrite [] []))) THEN (move ["i"])) THEN (split_tac)))));; refine (by (VALID (((BETA_TAC THEN (DISCH_THEN(new_rewrite [] []))) THEN (((USE_THM_THEN andTb)(new_rewrite [] [])) THEN ((USE_THM_THEN orNb)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((case THEN (simp_tac)) THEN ((USE_THM_THEN IN_NUMSEG)(new_rewrite [] [])) THEN (done_tac)))));; refine (by (VALID ((have_tac (move ["disj"]) (`DISJOINT ((1..dimindex (:N)) DELETE j) {j}`)))));; refine (by (VALID (((((USE_THM_THEN DISJOINT)(new_rewrite [] [])) THEN ((USE_THM_THEN EXTENSION)(new_rewrite [] [])) THEN ((USE_THM_THEN IN_INTER)(new_rewrite [] [])) THEN ((USE_THM_THEN IN_SING)(new_rewrite [] [])) THEN ((USE_THM_THEN NOT_IN_EMPTY)(new_rewrite [] [])) THEN ((USE_THM_THEN IN_DELETE)(new_rewrite [] []))) THEN (move ["i"])))));; refine (by (VALID (((((USE_THM_THEN andbA)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN andNb)(new_rewrite [] [])) THEN ((USE_THM_THEN andbF)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((((USE_THEN "s_eq")(new_rewrite [1] [])) THEN ((USE_THM_THEN SUM_UNION)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN FINITE_DELETE)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN FINITE_NUMSEG)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN FINITE_SING)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN SUM_SING)(new_rewrite [] [])) THEN (simp_tac)))));; refine (by (VALID ((((USE_THM_THEN SUM_EQ_0)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN IN_DELETE)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_ADD_LID)(new_rewrite [] [])))))));; refine (by (VALID (((BETA_TAC THEN (move ["i"]) THEN (move ["i_in"])) THEN (((USE_THM_THEN SUM_EQ_0) apply_tac) THEN (move ["k"]) THEN (move ["k_in"]) THEN (simp_tac))))));; refine (by (VALID (((((USE_THM_THEN BASIS_COMPONENT)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN IN_NUMSEG)(GSYM_THEN (new_rewrite [] [])))) THEN ((TRY done_tac)) THEN ((USE_THEN "i_in")(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN REAL_MUL_LZERO)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((((USE_THEN "s_eq")(new_rewrite [] [])) THEN ((USE_THM_THEN SUM_UNION)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN FINITE_DELETE)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN FINITE_NUMSEG)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN FINITE_SING)(new_rewrite [] []))) THEN ((TRY done_tac)) THEN ((USE_THM_THEN SUM_SING)(new_rewrite [] [])) THEN (simp_tac)))));; refine (by (VALID ((((USE_THM_THEN SUM_EQ_0)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN IN_DELETE)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_ADD_LID)(new_rewrite [] [])))))));; refine (by (VALID (((BETA_TAC THEN (move ["i"]) THEN (move ["i_in"]) THEN (simp_tac)) THEN ((USE_THM_THEN REAL_ENTIRE)(new_rewrite [] [])) THEN (DISJ2_TAC)))));; refine (by (VALID (((((USE_THM_THEN BASIS_COMPONENT)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN IN_NUMSEG)(GSYM_THEN (new_rewrite [] [])))) THEN ((TRY done_tac)) THEN ((USE_THEN "i_in")(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN REAL_MUL_LZERO)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((((USE_THM_THEN BASIS_COMPONENT)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THEN "j_in")(new_rewrite [] []))) THEN ((simp_tac THEN TRY done_tac)) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_MUL_LID)(new_rewrite [] []))) THEN ((USE_THM_THEN partial2)(new_rewrite [] [])) THEN ((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((((fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (fun thm_tac -> (USE_THM_THEN REAL_CONVEX_ON_SECOND_DERIVATIVE)(ISPEC_THEN (mk_var("g",mk_type("fun",[mk_type("real",[]);mk_type("real",[])]))) thm_tac))(ISPEC_THEN (`derivative g`) thm_tac))(ISPEC_THEN (`nth_derivative 2 g`) thm_tac))(ISPEC_THEN (mk_var("s",mk_type("fun",[mk_type("real",[]);mk_type("bool",[])]))) thm_tac)) MP_TAC) THEN ALL_TAC))));; refine (by (VALID (((THENL_ROT (-1)) ((((USE_THEN "s_def")(GSYM_THEN (new_rewrite [1; 2] []))) THEN ((USE_THM_THEN IS_REALINTERVAL_INTERVAL)(new_rewrite [] [])) THEN ((USE_THM_THEN andTb)(new_rewrite [] [])) THEN ((USE_THM_THEN NOT_EXISTS_THM)(new_rewrite [] []))) THEN (DISCH_THEN(new_rewrite [] [])))))));; refine (by (VALID (((BETA_TAC THEN (move ["t"]) THEN (move ["ts"])) THEN (((USE_THEN "d2g")(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THEN "partial2_pos")(new_rewrite [] [])) THEN ((USE_THEN "in_s")(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((split_tac))));; refine (by (VALID (((BETA_TAC THEN (move ["t"])) THEN (((USE_THM_THEN contraT)MP_TAC) THEN (clear_assumption "contraT") THEN (DISCH_THEN apply_tac)) THEN ((((USE_THM_THEN negbK)(new_rewrite [] [])) THEN ((USE_THM_THEN EXTENSION)(new_rewrite [] [])) THEN ((USE_THM_THEN IN_SING)(new_rewrite [] []))) THEN (move ["eq"]))))));; refine (by (VALID (((((USE_THEN "zx_pos")MP_TAC) THEN (clear_assumption "zx_pos") THEN ((fun thm_tac -> (USE_THEN "eq")(ISPEC_THEN (`z$j - x$j`) thm_tac))MP_TAC) THEN ((fun thm_tac -> (USE_THEN "eq")(ISPEC_THEN (`&0`) thm_tac))MP_TAC) THEN BETA_TAC) THEN (repeat_tactic 1 9 (((USE_THM_THEN IN_REAL_INTERVAL)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN REAL_LE_REFL)(new_rewrite [] []))))))));; refine (by (VALID (((arith_tac) THEN (done_tac)))));; refine (by (VALID (((split_tac) THEN (move ["t"]) THEN (move ["ts"])))));; refine (by (VALID (((((fun thm_tac -> (USE_THEN "diff2_g")(fun fst_th ->(USE_THEN "ts")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC) THEN (((USE_THM_THEN nth_diff_strong2_eq_alt)(new_rewrite [] [])) THEN ALL_TAC THEN (case THEN (move ["e"])) THEN (case THEN (move ["_"])) THEN (case THEN (move ["te"])) THEN (move ["H"]))))));; refine (by (VALID (((((USE_THM_THEN HAS_REAL_DERIVATIVE_ATREAL_WITHIN)(new_rewrite [] [])) THEN ((USE_THEN "H")(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID (((((fun thm_tac -> (USE_THEN "diff2_g")(fun fst_th ->(USE_THEN "ts")(fun th -> MATCH_MP_THEN th thm_tac fst_th)))MP_TAC) THEN BETA_TAC) THEN (((USE_THM_THEN nth_diff_strong2_eq_alt)(new_rewrite [] [])) THEN ALL_TAC THEN (case THEN (move ["e"])) THEN (case THEN (move ["_"])) THEN (case THEN (move ["te"])) THEN (move ["H"]))))));; refine (by (VALID (((((USE_THM_THEN HAS_REAL_DERIVATIVE_ATREAL_WITHIN)(new_rewrite [] [])) THEN ((USE_THEN "H")(new_rewrite [] []))) THEN (done_tac)))));; let partial_convex_max = end_section_proof();; let partial_convex_max = finalize_theorem partial_convex_max;; (end_section "PartialConvex");; (begin_section "ElementaryFunctions");; (start_section_proof ["c"](`lift o (\x. c) = (\x. lift c)`));; refine (by (VALID (((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (done_tac)))));; let f_lift_const = end_section_proof();; (start_section_proof ["f"](`lift o (\x. f x) = (\x. lift (f x))`));; refine (by (VALID (((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN o_THM)(new_rewrite [] []))) THEN (done_tac)))));; let f_lift_unary = end_section_proof();; (start_section_proof ["c";"x"](`diff2 (\x:real^N. c) x`));; refine (by (VALID ((((USE_THM_THEN diff2)(new_rewrite [] [])) THEN (exists_tac (`(:real^N)`)) THEN ((((USE_THM_THEN OPEN_UNIV)(new_rewrite [] [])) THEN ((USE_THM_THEN IN_UNIV)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] [])))) THEN (move ["y"]) THEN (move ["_"]))))));; refine (by (VALID (((((USE_THM_THEN partial_const)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN f_lift_const)(new_rewrite [] []))) THEN repeat_tactic 1 9 (((USE_THM_THEN DIFFERENTIABLE_CONST)(new_rewrite [] [])))) THEN (done_tac)))));; let diff2_const = end_section_proof();; (start_section_proof ["c";"domain"](`diff2_domain domain (\x:real^N. c)`));; refine (by (VALID (((((USE_THM_THEN diff2_domain)(new_rewrite [] [])) THEN ((USE_THM_THEN diff2_const)(new_rewrite [] []))) THEN (done_tac)))));; let diff2_domain_const = end_section_proof();; (start_section_proof ["i";"j";"c"](`partial2 i j (\x:real^N. c) = (\x. &0)`));; refine (by (VALID (((((USE_THM_THEN partial2)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN partial_const)(new_rewrite [] [])))) THEN (done_tac)))));; let partial2_const = end_section_proof();; (start_section_proof ["c";"x"](`diff2c (\x:real^N. c) x`));; refine (by (VALID (((((USE_THM_THEN diff2c)(new_rewrite [] [])) THEN ((USE_THM_THEN diff2_const)(new_rewrite [] [])) THEN ((USE_THM_THEN partial2_const)(new_rewrite [] [])) THEN ((USE_THM_THEN (GEN_ALL REAL_CONTINUOUS_CONTINUOUS1))(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN REAL_CONTINUOUS_CONST)(new_rewrite [] []))) THEN (done_tac)))));; let diff2c_const = end_section_proof();; (start_section_proof ["c";"domain"](`diff2c_domain domain (\x:real^N. c)`));; refine (by (VALID (((((USE_THM_THEN diff2c_domain)(new_rewrite [] [])) THEN ((USE_THM_THEN diff2c_const)(new_rewrite [] []))) THEN (done_tac)))));; let diff2c_domain_const = end_section_proof();; (start_section_proof ["k";"i"](`partial i (\x:real^N. x$k) = (\x. (basis i:real^N)$k)`));; refine (by (VALID (((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN partial)(new_rewrite [] []))) THEN (move ["x"]) THEN (simp_tac)))));; refine (by (VALID ((have_tac (DISCH_THEN(new_rewrite [] [])) (`(\x. x$k) o (\t. x + t % basis i) = (\t. x$k + t * (basis i:real^N)$k)`)))));; refine (by (VALID (((((USE_THM_THEN eq_ext)(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN o_THM)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN VECTOR_ADD_COMPONENT)(new_rewrite [] [])) THEN ((USE_THM_THEN VECTOR_MUL_COMPONENT)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((((USE_THM_THEN derivative_add)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((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))))));; refine (by (VALID (((((USE_THM_THEN REAL_DIFFERENTIABLE_ID)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_DIFFERENTIABLE_CONST)(new_rewrite [] []))) THEN (done_tac)))));; refine (by (VALID ((((USE_THM_THEN derivative_const)(new_rewrite [] [])) THEN (simp_tac) THEN ((USE_THM_THEN derivative_mul)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_DIFFERENTIABLE_ID)(new_rewrite [] []))) THEN repeat_tactic 0 10 (((USE_THM_THEN REAL_DIFFERENTIABLE_CONST)(new_rewrite [] []))) THEN ((TRY done_tac))))));; refine (by (VALID (((((USE_THM_THEN derivative_x)(new_rewrite [] [])) THEN ((USE_THM_THEN derivative_const)(new_rewrite [] []))) THEN (arith_tac) THEN (done_tac)))));; let partial_x_lemma = end_section_proof();; (start_section_proof ["k";"i"](`k IN 1..dimindex (:N) ==> partial i (\x:real^N. x$k) = (\x. if i = k then &1 else &0)`));; refine (by (VALID (((BETA_TAC THEN (move ["k_ineq"])) THEN (((USE_THM_THEN partial_x_lemma)(new_rewrite [] [])) THEN ((USE_THM_THEN BASIS_COMPONENT)(new_rewrite [] [])) THEN repeat_tactic 0 10 (((USE_THM_THEN IN_NUMSEG)(GSYM_THEN (new_rewrite [] [])))) THEN ((TRY done_tac))) THEN (arith_tac) THEN (done_tac)))));; let partial_x = end_section_proof();; (start_section_proof ["k";"i";"j"](`partial2 i j (\x:real^N. x$k) = (\x. &0)`));; refine (by (VALID (((((USE_THM_THEN partial2)(new_rewrite [] [])) THEN ((USE_THM_THEN partial_x_lemma)(new_rewrite [] [])) THEN ((USE_THM_THEN partial_const)(new_rewrite [] []))) THEN (done_tac)))));; let partial2_x = end_section_proof();; (start_section_proof ["k";"x"](`k IN 1..dimindex (:N) ==> diff2 (\x:real^N. x$k) x`));; refine (by (VALID (((BETA_TAC THEN (move ["k_ineq"])) THEN ((USE_THM_THEN diff2)(new_rewrite [] [])) THEN (exists_tac (`(:real^N)`)) THEN ((((USE_THM_THEN OPEN_UNIV)(new_rewrite [] [])) THEN ((USE_THM_THEN IN_UNIV)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN andTb)(new_rewrite [] [])))) THEN (move ["y"]) THEN (move ["_"]))))));; refine (by (VALID (((((USE_THM_THEN projection_diff)(new_rewrite [] [])) THEN ((TRY done_tac)) THEN ((USE_THM_THEN partial_x_lemma)(new_rewrite [] [])) THEN repeat_tactic 1 9 (((USE_THM_THEN f_lift_unary)(new_rewrite [] []))) THEN ((USE_THM_THEN DIFFERENTIABLE_CONST)(new_rewrite [] []))) THEN (done_tac)))));; let diff2_x = end_section_proof();; (start_section_proof ["k";"domain"](`k IN 1..dimindex (:N) ==> diff2_domain domain (\x:real^N. x$k)`));; refine (by (VALID ((((DISCH_THEN (fun snd_th -> (USE_THM_THEN diff2_x)(MATCH_MP_THEN snd_th MP_TAC))) THEN BETA_TAC) THEN (((USE_THM_THEN diff2_domain)(new_rewrite [] [])) THEN (DISCH_THEN(new_rewrite [] []))) THEN (done_tac)))));; let diff2_domain_x = end_section_proof();; (start_section_proof ["k";"x"](`k IN 1..dimindex (:N) ==> diff2c (\x:real^N. x$k) x`));; refine (by (VALID (((BETA_TAC THEN (move ["k_ineq"])) THEN (((USE_THM_THEN diff2c)(new_rewrite [] [])) THEN ((USE_THM_THEN diff2_x)(new_rewrite [] [])) THEN ((TRY done_tac)))))));; refine (by (VALID (((((USE_THM_THEN (GEN_ALL REAL_CONTINUOUS_CONTINUOUS1))(GSYM_THEN (new_rewrite [] []))) THEN ((USE_THM_THEN partial2_x)(new_rewrite [] [])) THEN ((USE_THM_THEN REAL_CONTINUOUS_CONST)(new_rewrite [] []))) THEN (done_tac)))));; let diff2c_x = end_section_proof();; (start_section_proof ["k";"domain"](`k IN 1..dimindex (:N) ==> diff2c_domain domain (\x:real^N. x$k)`));; refine (by (VALID ((((DISCH_THEN (fun snd_th -> (USE_THM_THEN diff2c_x)(MATCH_MP_THEN snd_th MP_TAC))) THEN BETA_TAC) THEN (((USE_THM_THEN diff2c_domain)(new_rewrite [] [])) THEN (DISCH_THEN(new_rewrite [] []))) THEN (done_tac)))));; let diff2c_domain_x = end_section_proof();; let diff2c_domain_x = finalize_theorem diff2c_domain_x;; let diff2c_x = finalize_theorem diff2c_x;; let diff2_domain_x = finalize_theorem diff2_domain_x;; let diff2_x = finalize_theorem diff2_x;; let partial2_x = finalize_theorem partial2_x;; let partial_x = finalize_theorem partial_x;; let partial_x_lemma = finalize_theorem partial_x_lemma;; let diff2c_domain_const = finalize_theorem diff2c_domain_const;; let diff2c_const = finalize_theorem diff2c_const;; let partial2_const = finalize_theorem partial2_const;; let diff2_domain_const = finalize_theorem diff2_domain_const;; let diff2_const = finalize_theorem diff2_const;; let f_lift_unary = finalize_theorem f_lift_unary;; let f_lift_const = finalize_theorem f_lift_const;; (end_section "ElementaryFunctions");;