[STATEMENT]
theorem Youngs_exact:
  fixes f :: "real \<Rightarrow> real"
  assumes sm: "strict_mono_on {0..} f" and cont: "continuous_on {0..} f" and a: "a\<ge>0"
    and f: "f 0 = 0" "f a = b"
    and g: "\<And>x. \<lbrakk>0 \<le> x; x \<le> a\<rbrakk> \<Longrightarrow> g (f x) = x"
  shows "a*b = integral {0..a} f + integral {0..b} g"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. a * b = integral {0..a} f + integral {0..b} g
[PROOF STEP]
proof (cases "a=0")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. a = 0 \<Longrightarrow> a * b = integral {0..a} f + integral {0..b} g
 2. a \<noteq> 0 \<Longrightarrow> a * b = integral {0..a} f + integral {0..b} g
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
a \<noteq> 0

goal (2 subgoals):
 1. a = 0 \<Longrightarrow> a * b = integral {0..a} f + integral {0..b} g
 2. a \<noteq> 0 \<Longrightarrow> a * b = integral {0..a} f + integral {0..b} g
[PROOF STEP]
with \<open>a \<ge> 0\<close>
[PROOF STATE]
proof (chain)
picking this:
0 \<le> a
a \<noteq> 0
[PROOF STEP]
have "a > 0"
[PROOF STATE]
proof (prove)
using this:
0 \<le> a
a \<noteq> 0

goal (1 subgoal):
 1. 0 < a
[PROOF STEP]
by linarith
[PROOF STATE]
proof (state)
this:
0 < a

goal (2 subgoals):
 1. a = 0 \<Longrightarrow> a * b = integral {0..a} f + integral {0..b} g
 2. a \<noteq> 0 \<Longrightarrow> a * b = integral {0..a} f + integral {0..b} g
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
0 < a
[PROOF STEP]
have "b \<ge> 0"
[PROOF STATE]
proof (prove)
using this:
0 < a

goal (1 subgoal):
 1. 0 \<le> b
[PROOF STEP]
by (smt (verit, best) atLeast_iff f sm strict_mono_onD)
[PROOF STATE]
proof (state)
this:
0 \<le> b

goal (2 subgoals):
 1. a = 0 \<Longrightarrow> a * b = integral {0..a} f + integral {0..b} g
 2. a \<noteq> 0 \<Longrightarrow> a * b = integral {0..a} f + integral {0..b} g
[PROOF STEP]
have sm_0a: "strict_mono_on {0..a} f"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. strict_mono_on {0..a} f
[PROOF STEP]
by (metis atLeastAtMost_iff atLeast_iff sm strict_mono_on_def)
[PROOF STATE]
proof (state)
this:
strict_mono_on {0..a} f

goal (2 subgoals):
 1. a = 0 \<Longrightarrow> a * b = integral {0..a} f + integral {0..b} g
 2. a \<noteq> 0 \<Longrightarrow> a * b = integral {0..a} f + integral {0..b} g
[PROOF STEP]
have cont_0a: "continuous_on {0..a} f"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. continuous_on {0..a} f
[PROOF STEP]
using cont continuous_on_subset
[PROOF STATE]
proof (prove)
using this:
continuous_on {0..} f
\<lbrakk>continuous_on ?s ?f; ?t \<subseteq> ?s\<rbrakk> \<Longrightarrow> continuous_on ?t ?f

goal (1 subgoal):
 1. continuous_on {0..a} f
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
continuous_on {0..a} f

goal (2 subgoals):
 1. a = 0 \<Longrightarrow> a * b = integral {0..a} f + integral {0..b} g
 2. a \<noteq> 0 \<Longrightarrow> a * b = integral {0..a} f + integral {0..b} g
[PROOF STEP]
with sm_0a
[PROOF STATE]
proof (chain)
picking this:
strict_mono_on {0..a} f
continuous_on {0..a} f
[PROOF STEP]
have "continuous_on {0..b} g"
[PROOF STATE]
proof (prove)
using this:
strict_mono_on {0..a} f
continuous_on {0..a} f

goal (1 subgoal):
 1. continuous_on {0..b} g
[PROOF STEP]
by (metis a atLeastAtMost_iff compact_Icc continuous_on_inv f g strict_mono_image_endpoints)
[PROOF STATE]
proof (state)
this:
continuous_on {0..b} g

goal (2 subgoals):
 1. a = 0 \<Longrightarrow> a * b = integral {0..a} f + integral {0..b} g
 2. a \<noteq> 0 \<Longrightarrow> a * b = integral {0..a} f + integral {0..b} g
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
continuous_on {0..b} g
[PROOF STEP]
have intgb_g: "g integrable_on {0..b}"
[PROOF STATE]
proof (prove)
using this:
continuous_on {0..b} g

goal (1 subgoal):
 1. g integrable_on {0..b}
[PROOF STEP]
using integrable_continuous_interval
[PROOF STATE]
proof (prove)
using this:
continuous_on {0..b} g
continuous_on {?a..?b} ?f \<Longrightarrow> ?f integrable_on {?a..?b}

goal (1 subgoal):
 1. g integrable_on {0..b}
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
g integrable_on {0..b}

goal (2 subgoals):
 1. a = 0 \<Longrightarrow> a * b = integral {0..a} f + integral {0..b} g
 2. a \<noteq> 0 \<Longrightarrow> a * b = integral {0..a} f + integral {0..b} g
[PROOF STEP]
have intgb_f: "f integrable_on {0..a}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. f integrable_on {0..a}
[PROOF STEP]
using cont_0a integrable_continuous_real
[PROOF STATE]
proof (prove)
using this:
continuous_on {0..a} f
continuous_on {?a..?b} ?f \<Longrightarrow> ?f integrable_on {?a..?b}

goal (1 subgoal):
 1. f integrable_on {0..a}
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
f integrable_on {0..a}

goal (2 subgoals):
 1. a = 0 \<Longrightarrow> a * b = integral {0..a} f + integral {0..b} g
 2. a \<noteq> 0 \<Longrightarrow> a * b = integral {0..a} f + integral {0..b} g
[PROOF STEP]
have f_iff [simp]: "f x < f y \<longleftrightarrow> x < y" "f x \<le> f y \<longleftrightarrow> x \<le> y"
    if "x \<ge> 0" "y \<ge> 0" for x y
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (f x < f y) = (x < y) &&& (f x \<le> f y) = (x \<le> y)
[PROOF STEP]
using that
[PROOF STATE]
proof (prove)
using this:
0 \<le> x
0 \<le> y

goal (1 subgoal):
 1. (f x < f y) = (x < y) &&& (f x \<le> f y) = (x \<le> y)
[PROOF STEP]
by (smt (verit, best) atLeast_iff sm strict_mono_onD)+
[PROOF STATE]
proof (state)
this:
\<lbrakk>0 \<le> ?x; 0 \<le> ?y\<rbrakk> \<Longrightarrow> (f ?x < f ?y) = (?x < ?y)
\<lbrakk>0 \<le> ?x; 0 \<le> ?y\<rbrakk> \<Longrightarrow> (f ?x \<le> f ?y) = (?x \<le> ?y)

goal (2 subgoals):
 1. a = 0 \<Longrightarrow> a * b = integral {0..a} f + integral {0..b} g
 2. a \<noteq> 0 \<Longrightarrow> a * b = integral {0..a} f + integral {0..b} g
[PROOF STEP]
have fim: "f ` {0..a} = {0..b}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. f ` {0..a} = {0..b}
[PROOF STEP]
by (simp add: \<open>a \<ge> 0\<close> cont_0a strict_mono_image_endpoints strict_mono_on_def f)
[PROOF STATE]
proof (state)
this:
f ` {0..a} = {0..b}

goal (2 subgoals):
 1. a = 0 \<Longrightarrow> a * b = integral {0..a} f + integral {0..b} g
 2. a \<noteq> 0 \<Longrightarrow> a * b = integral {0..a} f + integral {0..b} g
[PROOF STEP]
have "uniformly_continuous_on {0..a} f"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. uniformly_continuous_on {0..a} f
[PROOF STEP]
using compact_uniformly_continuous cont_0a
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>continuous_on ?S ?f; compact ?S\<rbrakk> \<Longrightarrow> uniformly_continuous_on ?S ?f
continuous_on {0..a} f

goal (1 subgoal):
 1. uniformly_continuous_on {0..a} f
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
uniformly_continuous_on {0..a} f

goal (2 subgoals):
 1. a = 0 \<Longrightarrow> a * b = integral {0..a} f + integral {0..b} g
 2. a \<noteq> 0 \<Longrightarrow> a * b = integral {0..a} f + integral {0..b} g
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
uniformly_continuous_on {0..a} f
[PROOF STEP]
obtain del where del_gt0: "\<And>e. e>0 \<Longrightarrow> del e > 0"
        and del:  "\<And>e x x'. \<lbrakk>\<bar>x'-x\<bar> < del e; e>0; x \<in> {0..a}; x' \<in> {0..a}\<rbrakk> \<Longrightarrow> \<bar>f x' - f x\<bar> < e"
[PROOF STATE]
proof (prove)
using this:
uniformly_continuous_on {0..a} f

goal (1 subgoal):
 1. (\<And>del. \<lbrakk>\<And>e. 0 < e \<Longrightarrow> 0 < del e; \<And>e x x'. \<lbrakk>\<bar>x' - x\<bar> < del e; 0 < e; x \<in> {0..a}; x' \<in> {0..a}\<rbrakk> \<Longrightarrow> \<bar>f x' - f x\<bar> < e\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
unfolding uniformly_continuous_on_def dist_real_def
[PROOF STATE]
proof (prove)
using this:
\<forall>e>0. \<exists>d>0. \<forall>x\<in>{0..a}. \<forall>x'\<in>{0..a}. \<bar>x' - x\<bar> < d \<longrightarrow> \<bar>f x' - f x\<bar> < e

goal (1 subgoal):
 1. (\<And>del. \<lbrakk>\<And>e. 0 < e \<Longrightarrow> 0 < del e; \<And>e x x'. \<lbrakk>\<bar>x' - x\<bar> < del e; 0 < e; x \<in> {0..a}; x' \<in> {0..a}\<rbrakk> \<Longrightarrow> \<bar>f x' - f x\<bar> < e\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by metis
[PROOF STATE]
proof (state)
this:
0 < ?e \<Longrightarrow> 0 < del ?e
\<lbrakk>\<bar>?x' - ?x\<bar> < del ?e; 0 < ?e; ?x \<in> {0..a}; ?x' \<in> {0..a}\<rbrakk> \<Longrightarrow> \<bar>f ?x' - f ?x\<bar> < ?e

goal (2 subgoals):
 1. a = 0 \<Longrightarrow> a * b = integral {0..a} f + integral {0..b} g
 2. a \<noteq> 0 \<Longrightarrow> a * b = integral {0..a} f + integral {0..b} g
[PROOF STEP]
have *: "\<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2*\<epsilon>" if "\<epsilon> > 0" for \<epsilon>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
define \<delta> where "\<delta> = min a (del (\<epsilon>/a)) / 2"
[PROOF STATE]
proof (state)
this:
\<delta> = min a (del (\<epsilon> / a)) / 2

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have "\<delta> > 0" "\<delta> \<le> a"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 < \<delta> &&& \<delta> \<le> a
[PROOF STEP]
using \<open>a > 0\<close> \<open>\<epsilon> > 0\<close> del_gt0
[PROOF STATE]
proof (prove)
using this:
0 < a
0 < \<epsilon>
0 < ?e \<Longrightarrow> 0 < del ?e

goal (1 subgoal):
 1. 0 < \<delta> &&& \<delta> \<le> a
[PROOF STEP]
by (auto simp: \<delta>_def)
[PROOF STATE]
proof (state)
this:
0 < \<delta>
\<delta> \<le> a

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
define n where "n \<equiv> nat\<lfloor>a / \<delta>\<rfloor>"
[PROOF STATE]
proof (state)
this:
n \<equiv> nat \<lfloor>a / \<delta>\<rfloor>

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
define a_seg where "a_seg \<equiv> \<lambda>u::real. u * a/n"
[PROOF STATE]
proof (state)
this:
a_seg \<equiv> \<lambda>u. u * a / real n

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have "n > 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 < n
[PROOF STEP]
using  \<open>a > 0\<close> \<open>\<delta> > 0\<close> \<open>\<delta> \<le> a\<close>
[PROOF STATE]
proof (prove)
using this:
0 < a
0 < \<delta>
\<delta> \<le> a

goal (1 subgoal):
 1. 0 < n
[PROOF STEP]
by (simp add: n_def)
[PROOF STATE]
proof (state)
this:
0 < n

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have a_seg_ge_0 [simp]: "a_seg x \<ge> 0 \<longleftrightarrow> x \<ge> 0"
     and a_seg_le_a [simp]: "a_seg x \<le> a \<longleftrightarrow> x \<le> n" for x
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (0 \<le> a_seg x) = (0 \<le> x) &&& (a_seg x \<le> a) = (x \<le> real n)
[PROOF STEP]
using \<open>n > 0\<close> \<open>a > 0\<close>
[PROOF STATE]
proof (prove)
using this:
0 < n
0 < a

goal (1 subgoal):
 1. (0 \<le> a_seg x) = (0 \<le> x) &&& (a_seg x \<le> a) = (x \<le> real n)
[PROOF STEP]
by (auto simp: a_seg_def zero_le_mult_iff divide_simps)
[PROOF STATE]
proof (state)
this:
(0 \<le> a_seg ?x) = (0 \<le> ?x)
(a_seg ?x \<le> a) = (?x \<le> real n)

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have a_seg_le_iff [simp]: "a_seg x \<le> a_seg y \<longleftrightarrow> x \<le> y"
      and a_seg_less_iff [simp]: "a_seg x < a_seg y \<longleftrightarrow> x < y" for x y
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (a_seg x \<le> a_seg y) = (x \<le> y) &&& (a_seg x < a_seg y) = (x < y)
[PROOF STEP]
using \<open>n > 0\<close> \<open>a > 0\<close>
[PROOF STATE]
proof (prove)
using this:
0 < n
0 < a

goal (1 subgoal):
 1. (a_seg x \<le> a_seg y) = (x \<le> y) &&& (a_seg x < a_seg y) = (x < y)
[PROOF STEP]
by (auto simp: a_seg_def zero_le_mult_iff divide_simps)
[PROOF STATE]
proof (state)
this:
(a_seg ?x \<le> a_seg ?y) = (?x \<le> ?y)
(a_seg ?x < a_seg ?y) = (?x < ?y)

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have "strict_mono a_seg"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. strict_mono a_seg
[PROOF STEP]
by (simp add: strict_mono_def)
[PROOF STATE]
proof (state)
this:
strict_mono a_seg

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have a_seg_eq_a_iff: "a_seg x = a \<longleftrightarrow> x=n" for x
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (a_seg x = a) = (x = real n)
[PROOF STEP]
using \<open>0 < n\<close> \<open>a > 0\<close>
[PROOF STATE]
proof (prove)
using this:
0 < n
0 < a

goal (1 subgoal):
 1. (a_seg x = a) = (x = real n)
[PROOF STEP]
by (simp add: a_seg_def nonzero_divide_eq_eq)
[PROOF STATE]
proof (state)
this:
(a_seg ?x = a) = (?x = real n)

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have fa_eq_b: "f (a_seg n) = b"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. f (a_seg (real n)) = b
[PROOF STEP]
using a_seg_eq_a_iff f
[PROOF STATE]
proof (prove)
using this:
(a_seg ?x = a) = (?x = real n)
f 0 = 0
f a = b

goal (1 subgoal):
 1. f (a_seg (real n)) = b
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
f (a_seg (real n)) = b

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have "a/d < real_of_int \<lfloor>a * 2 / min a d\<rfloor>" if "d>0" for d
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. a / d < real_of_int \<lfloor>a * 2 / min a d\<rfloor>
[PROOF STEP]
by (smt (verit) \<open>0 < \<delta>\<close> \<open>\<delta> \<le> a\<close> add_divide_distrib divide_less_eq_1_pos floor_eq_iff that)
[PROOF STATE]
proof (state)
this:
0 < ?d \<Longrightarrow> a / ?d < real_of_int \<lfloor>a * 2 / min a ?d\<rfloor>

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
0 < ?d \<Longrightarrow> a / ?d < real_of_int \<lfloor>a * 2 / min a ?d\<rfloor>
[PROOF STEP]
have an_less_del: "a/n < del (\<epsilon>/a)"
[PROOF STATE]
proof (prove)
using this:
0 < ?d \<Longrightarrow> a / ?d < real_of_int \<lfloor>a * 2 / min a ?d\<rfloor>

goal (1 subgoal):
 1. a / real n < del (\<epsilon> / a)
[PROOF STEP]
using \<open>a > 0\<close> \<open>\<epsilon> > 0\<close> del_gt0
[PROOF STATE]
proof (prove)
using this:
0 < ?d \<Longrightarrow> a / ?d < real_of_int \<lfloor>a * 2 / min a ?d\<rfloor>
0 < a
0 < \<epsilon>
0 < ?e \<Longrightarrow> 0 < del ?e

goal (1 subgoal):
 1. a / real n < del (\<epsilon> / a)
[PROOF STEP]
by (simp add: n_def \<delta>_def field_simps)
[PROOF STATE]
proof (state)
this:
a / real n < del (\<epsilon> / a)

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
define lower where "lower \<equiv> \<lambda>x. a_seg\<lfloor>(real n * x) / a\<rfloor>"
[PROOF STATE]
proof (state)
this:
lower \<equiv> \<lambda>x. a_seg (real_of_int \<lfloor>real n * x / a\<rfloor>)

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
define f1 where "f1 \<equiv> f \<circ> lower"
[PROOF STATE]
proof (state)
this:
f1 \<equiv> f \<circ> lower

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have f1_lower: "f1 x \<le> f x" if "0 \<le> x" "x \<le> a" for x
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. f1 x \<le> f x
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. f1 x \<le> f x
[PROOF STEP]
have "lower x \<le> x"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. lower x \<le> x
[PROOF STEP]
using \<open>n > 0\<close> floor_divide_lower [OF \<open>a > 0\<close>]
[PROOF STATE]
proof (prove)
using this:
0 < n
real_of_int \<lfloor>?p / a\<rfloor> * a \<le> ?p

goal (1 subgoal):
 1. lower x \<le> x
[PROOF STEP]
by (auto simp: lower_def a_seg_def field_simps)
[PROOF STATE]
proof (state)
this:
lower x \<le> x

goal (1 subgoal):
 1. f1 x \<le> f x
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
lower x \<le> x

goal (1 subgoal):
 1. f1 x \<le> f x
[PROOF STEP]
have "lower x \<ge> 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 \<le> lower x
[PROOF STEP]
unfolding lower_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 \<le> a_seg (real_of_int \<lfloor>real n * x / a\<rfloor>)
[PROOF STEP]
using \<open>n > 0\<close> \<open>a \<ge> 0\<close> \<open>0 \<le> x\<close>
[PROOF STATE]
proof (prove)
using this:
0 < n
0 \<le> a
0 \<le> x

goal (1 subgoal):
 1. 0 \<le> a_seg (real_of_int \<lfloor>real n * x / a\<rfloor>)
[PROOF STEP]
by force
[PROOF STATE]
proof (state)
this:
0 \<le> lower x

goal (1 subgoal):
 1. f1 x \<le> f x
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
lower x \<le> x
0 \<le> lower x
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
lower x \<le> x
0 \<le> lower x

goal (1 subgoal):
 1. f1 x \<le> f x
[PROOF STEP]
using sm strict_mono_on_leD
[PROOF STATE]
proof (prove)
using this:
lower x \<le> x
0 \<le> lower x
strict_mono_on {0..} f
\<lbrakk>strict_mono_on ?A ?f; ?x \<in> ?A; ?y \<in> ?A; ?x \<le> ?y\<rbrakk> \<Longrightarrow> ?f ?x \<le> ?f ?y

goal (1 subgoal):
 1. f1 x \<le> f x
[PROOF STEP]
by (fastforce simp add: f1_def)
[PROOF STATE]
proof (state)
this:
f1 x \<le> f x

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<lbrakk>0 \<le> ?x; ?x \<le> a\<rbrakk> \<Longrightarrow> f1 ?x \<le> f ?x

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
define upper where "upper \<equiv> \<lambda>x. a_seg\<lceil>real n * x / a\<rceil>"
[PROOF STATE]
proof (state)
this:
upper \<equiv> \<lambda>x. a_seg (real_of_int \<lceil>real n * x / a\<rceil>)

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
define f2 where "f2 \<equiv> f \<circ> upper"
[PROOF STATE]
proof (state)
this:
f2 \<equiv> f \<circ> upper

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have f2_upper: "f2 x \<ge> f x" if "0 \<le> x" "x \<le> a" for x
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. f x \<le> f2 x
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. f x \<le> f2 x
[PROOF STEP]
have "x \<le> upper x"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x \<le> upper x
[PROOF STEP]
using \<open>n > 0\<close> ceiling_divide_upper [OF \<open>a > 0\<close>]
[PROOF STATE]
proof (prove)
using this:
0 < n
?p \<le> real_of_int \<lceil>?p / a\<rceil> * a

goal (1 subgoal):
 1. x \<le> upper x
[PROOF STEP]
by (simp add: upper_def a_seg_def field_simps)
[PROOF STATE]
proof (state)
this:
x \<le> upper x

goal (1 subgoal):
 1. f x \<le> f2 x
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
x \<le> upper x
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
x \<le> upper x

goal (1 subgoal):
 1. f x \<le> f2 x
[PROOF STEP]
using sm strict_mono_on_leD \<open>0 \<le> x\<close>
[PROOF STATE]
proof (prove)
using this:
x \<le> upper x
strict_mono_on {0..} f
\<lbrakk>strict_mono_on ?A ?f; ?x \<in> ?A; ?y \<in> ?A; ?x \<le> ?y\<rbrakk> \<Longrightarrow> ?f ?x \<le> ?f ?y
0 \<le> x

goal (1 subgoal):
 1. f x \<le> f2 x
[PROOF STEP]
by (force simp: f2_def)
[PROOF STATE]
proof (state)
this:
f x \<le> f2 x

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<lbrakk>0 \<le> ?x; ?x \<le> a\<rbrakk> \<Longrightarrow> f ?x \<le> f2 ?x

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
let ?\<D> = "regular_division 0 a n"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have div: "?\<D> division_of {0..a}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. regular_division 0 a n division_of {0..a}
[PROOF STEP]
using \<open>a > 0\<close> \<open>n > 0\<close> regular_division_division_of zero_less_nat_eq
[PROOF STATE]
proof (prove)
using this:
0 < a
0 < n
\<lbrakk>?a < ?b; 0 < ?n\<rbrakk> \<Longrightarrow> regular_division ?a ?b ?n division_of {?a..?b}
(0 < nat ?z) = (0 < ?z)

goal (1 subgoal):
 1. regular_division 0 a n division_of {0..a}
[PROOF STEP]
by presburger
[PROOF STATE]
proof (state)
this:
regular_division 0 a n division_of {0..a}

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have int_f1_D: "(f1 has_integral f(Inf K) * (a/n)) K"
      and int_f2_D: "(f2 has_integral f(Sup K) * (a/n)) K" and less: "\<bar>f(Sup K) - f(Inf K)\<bar> < \<epsilon>/a"
      if "K\<in>?\<D>" for K
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (f1 has_integral f (Inf K) * (a / real n)) K &&& (f2 has_integral f (Sup K) * (a / real n)) K &&& \<bar>f (Sup K) - f (Inf K)\<bar> < \<epsilon> / a
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (3 subgoals):
 1. (f1 has_integral f (Inf K) * (a / real n)) K
 2. (f2 has_integral f (Sup K) * (a / real n)) K
 3. \<bar>f (Sup K) - f (Inf K)\<bar> < \<epsilon> / a
[PROOF STEP]
from regular_divisionE [OF that] \<open>a > 0\<close>
[PROOF STATE]
proof (chain)
picking this:
\<lbrakk>0 < a; \<And>k. \<lbrakk>k < n; K = {0 + (a - 0) * (real k / real n)..0 + (a - 0) * ((1 + real k) / real n)}\<rbrakk> \<Longrightarrow> ?thesis\<rbrakk> \<Longrightarrow> ?thesis
0 < a
[PROOF STEP]
obtain k where "k<n" and k: "K = {a_seg(real k)..a_seg(Suc k)}"
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>0 < a; \<And>k. \<lbrakk>k < n; K = {0 + (a - 0) * (real k / real n)..0 + (a - 0) * ((1 + real k) / real n)}\<rbrakk> \<Longrightarrow> ?thesis\<rbrakk> \<Longrightarrow> ?thesis
0 < a

goal (1 subgoal):
 1. (\<And>k. \<lbrakk>k < n; K = {a_seg (real k)..a_seg (real (Suc k))}\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by (auto simp: a_seg_def mult.commute)
[PROOF STATE]
proof (state)
this:
k < n
K = {a_seg (real k)..a_seg (real (Suc k))}

goal (3 subgoals):
 1. (f1 has_integral f (Inf K) * (a / real n)) K
 2. (f2 has_integral f (Sup K) * (a / real n)) K
 3. \<bar>f (Sup K) - f (Inf K)\<bar> < \<epsilon> / a
[PROOF STEP]
define u where "u \<equiv> a_seg k"
[PROOF STATE]
proof (state)
this:
u \<equiv> a_seg (real k)

goal (3 subgoals):
 1. (f1 has_integral f (Inf K) * (a / real n)) K
 2. (f2 has_integral f (Sup K) * (a / real n)) K
 3. \<bar>f (Sup K) - f (Inf K)\<bar> < \<epsilon> / a
[PROOF STEP]
define v where "v \<equiv> a_seg (Suc k)"
[PROOF STATE]
proof (state)
this:
v \<equiv> a_seg (real (Suc k))

goal (3 subgoals):
 1. (f1 has_integral f (Inf K) * (a / real n)) K
 2. (f2 has_integral f (Sup K) * (a / real n)) K
 3. \<bar>f (Sup K) - f (Inf K)\<bar> < \<epsilon> / a
[PROOF STEP]
have "u < v" "0 \<le> u" "0 \<le> v" "u \<le> a" "v \<le> a" and Kuv: "K = {u..v}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ((u < v &&& 0 \<le> u) &&& 0 \<le> v &&& u \<le> a &&& v \<le> a) &&& K = {u..v}
[PROOF STEP]
using \<open>n > 0\<close> \<open>k < n\<close> \<open>a > 0\<close>
[PROOF STATE]
proof (prove)
using this:
0 < n
k < n
0 < a

goal (1 subgoal):
 1. ((u < v &&& 0 \<le> u) &&& 0 \<le> v &&& u \<le> a &&& v \<le> a) &&& K = {u..v}
[PROOF STEP]
by (auto simp: k u_def v_def divide_simps)
[PROOF STATE]
proof (state)
this:
u < v
0 \<le> u
0 \<le> v
u \<le> a
v \<le> a
K = {u..v}

goal (3 subgoals):
 1. (f1 has_integral f (Inf K) * (a / real n)) K
 2. (f2 has_integral f (Sup K) * (a / real n)) K
 3. \<bar>f (Sup K) - f (Inf K)\<bar> < \<epsilon> / a
[PROOF STEP]
have InfK: "Inf K = u" and SupK: "Sup K = v"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Inf K = u &&& Sup K = v
[PROOF STEP]
using Kuv \<open>u < v\<close>
[PROOF STATE]
proof (prove)
using this:
K = {u..v}
u < v

goal (1 subgoal):
 1. Inf K = u &&& Sup K = v
[PROOF STEP]
apply force
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Sup K = v
[PROOF STEP]
using \<open>n > 0\<close> \<open>a > 0\<close>
[PROOF STATE]
proof (prove)
using this:
0 < n
0 < a

goal (1 subgoal):
 1. Sup K = v
[PROOF STEP]
by (auto simp: divide_right_mono k u_def v_def)
[PROOF STATE]
proof (state)
this:
Inf K = u
Sup K = v

goal (3 subgoals):
 1. (f1 has_integral f (Inf K) * (a / real n)) K
 2. (f2 has_integral f (Sup K) * (a / real n)) K
 3. \<bar>f (Sup K) - f (Inf K)\<bar> < \<epsilon> / a
[PROOF STEP]
have f1: "f1 x = f (Inf K)" if "x \<in> K - {v}" for x
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. f1 x = f (Inf K)
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. f1 x = f (Inf K)
[PROOF STEP]
have "x \<in> {u..<v}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x \<in> {u..<v}
[PROOF STEP]
using that Kuv atLeastLessThan_eq_atLeastAtMost_diff
[PROOF STATE]
proof (prove)
using this:
x \<in> K - {v}
K = {u..v}
{?a..<?b} = {?a..?b} - {?b}

goal (1 subgoal):
 1. x \<in> {u..<v}
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
x \<in> {u..<v}

goal (1 subgoal):
 1. f1 x = f (Inf K)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
x \<in> {u..<v}
[PROOF STEP]
have "\<lfloor>real_of_int n * x / a\<rfloor> = int k"
[PROOF STATE]
proof (prove)
using this:
x \<in> {u..<v}

goal (1 subgoal):
 1. \<lfloor>real_of_int (int n) * x / a\<rfloor> = int k
[PROOF STEP]
using \<open>n > 0\<close> \<open>a > 0\<close>
[PROOF STATE]
proof (prove)
using this:
x \<in> {u..<v}
0 < n
0 < a

goal (1 subgoal):
 1. \<lfloor>real_of_int (int n) * x / a\<rfloor> = int k
[PROOF STEP]
by (simp add: field_simps u_def v_def a_seg_def floor_eq_iff)
[PROOF STATE]
proof (state)
this:
\<lfloor>real_of_int (int n) * x / a\<rfloor> = int k

goal (1 subgoal):
 1. f1 x = f (Inf K)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
\<lfloor>real_of_int (int n) * x / a\<rfloor> = int k
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
\<lfloor>real_of_int (int n) * x / a\<rfloor> = int k

goal (1 subgoal):
 1. f1 x = f (Inf K)
[PROOF STEP]
by (simp add: InfK f1_def lower_def a_seg_def mult.commute u_def)
[PROOF STATE]
proof (state)
this:
f1 x = f (Inf K)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
?x \<in> K - {v} \<Longrightarrow> f1 ?x = f (Inf K)

goal (3 subgoals):
 1. (f1 has_integral f (Inf K) * (a / real n)) K
 2. (f2 has_integral f (Sup K) * (a / real n)) K
 3. \<bar>f (Sup K) - f (Inf K)\<bar> < \<epsilon> / a
[PROOF STEP]
have "((\<lambda>x. f (Inf K)) has_integral (f (Inf K) * (a/n))) K"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ((\<lambda>x. f (Inf K)) has_integral f (Inf K) * (a / real n)) K
[PROOF STEP]
using has_integral_const_real [of "f (Inf K)" u v]
              \<open>n > 0\<close> \<open>a > 0\<close>
[PROOF STATE]
proof (prove)
using this:
((\<lambda>x. f (Inf K)) has_integral content {u..v} *\<^sub>R f (Inf K)) {u..v}
0 < n
0 < a

goal (1 subgoal):
 1. ((\<lambda>x. f (Inf K)) has_integral f (Inf K) * (a / real n)) K
[PROOF STEP]
by (simp add: Kuv field_simps a_seg_def u_def v_def)
[PROOF STATE]
proof (state)
this:
((\<lambda>x. f (Inf K)) has_integral f (Inf K) * (a / real n)) K

goal (3 subgoals):
 1. (f1 has_integral f (Inf K) * (a / real n)) K
 2. (f2 has_integral f (Sup K) * (a / real n)) K
 3. \<bar>f (Sup K) - f (Inf K)\<bar> < \<epsilon> / a
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
((\<lambda>x. f (Inf K)) has_integral f (Inf K) * (a / real n)) K
[PROOF STEP]
show "(f1 has_integral (f (Inf K) * (a/n))) K"
[PROOF STATE]
proof (prove)
using this:
((\<lambda>x. f (Inf K)) has_integral f (Inf K) * (a / real n)) K

goal (1 subgoal):
 1. (f1 has_integral f (Inf K) * (a / real n)) K
[PROOF STEP]
using has_integral_spike_finite_eq [of "{v}" K "\<lambda>x. f (Inf K)" f1] f1
[PROOF STATE]
proof (prove)
using this:
((\<lambda>x. f (Inf K)) has_integral f (Inf K) * (a / real n)) K
\<lbrakk>finite {v}; \<And>x. x \<in> K - {v} \<Longrightarrow> f (Inf K) = f1 x\<rbrakk> \<Longrightarrow> (f1 has_integral ?y) K = ((\<lambda>x. f (Inf K)) has_integral ?y) K
?x \<in> K - {v} \<Longrightarrow> f1 ?x = f (Inf K)

goal (1 subgoal):
 1. (f1 has_integral f (Inf K) * (a / real n)) K
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
(f1 has_integral f (Inf K) * (a / real n)) K

goal (2 subgoals):
 1. (f2 has_integral f (Sup K) * (a / real n)) K
 2. \<bar>f (Sup K) - f (Inf K)\<bar> < \<epsilon> / a
[PROOF STEP]
have f2: "f2 x = f (Sup K)" if "x \<in> K - {u}" for x
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. f2 x = f (Sup K)
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. f2 x = f (Sup K)
[PROOF STEP]
have "x \<in> {u<..v}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. x \<in> {u<..v}
[PROOF STEP]
using that Kuv greaterThanAtMost_eq_atLeastAtMost_diff
[PROOF STATE]
proof (prove)
using this:
x \<in> K - {u}
K = {u..v}
{?a<..?b} = {?a..?b} - {?a}

goal (1 subgoal):
 1. x \<in> {u<..v}
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
x \<in> {u<..v}

goal (1 subgoal):
 1. f2 x = f (Sup K)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
x \<in> {u<..v}
[PROOF STEP]
have "\<lceil>x * real_of_int n / a\<rceil>  = 1 + int k"
[PROOF STATE]
proof (prove)
using this:
x \<in> {u<..v}

goal (1 subgoal):
 1. \<lceil>x * real_of_int (int n) / a\<rceil> = 1 + int k
[PROOF STEP]
using \<open>n > 0\<close> \<open>a > 0\<close>
[PROOF STATE]
proof (prove)
using this:
x \<in> {u<..v}
0 < n
0 < a

goal (1 subgoal):
 1. \<lceil>x * real_of_int (int n) / a\<rceil> = 1 + int k
[PROOF STEP]
by (simp add: field_simps u_def v_def a_seg_def ceiling_eq_iff)
[PROOF STATE]
proof (state)
this:
\<lceil>x * real_of_int (int n) / a\<rceil> = 1 + int k

goal (1 subgoal):
 1. f2 x = f (Sup K)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
\<lceil>x * real_of_int (int n) / a\<rceil> = 1 + int k
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
\<lceil>x * real_of_int (int n) / a\<rceil> = 1 + int k

goal (1 subgoal):
 1. f2 x = f (Sup K)
[PROOF STEP]
by (simp add: mult.commute f2_def upper_def a_seg_def SupK v_def)
[PROOF STATE]
proof (state)
this:
f2 x = f (Sup K)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
?x \<in> K - {u} \<Longrightarrow> f2 ?x = f (Sup K)

goal (2 subgoals):
 1. (f2 has_integral f (Sup K) * (a / real n)) K
 2. \<bar>f (Sup K) - f (Inf K)\<bar> < \<epsilon> / a
[PROOF STEP]
have "((\<lambda>x. f (Sup K)) has_integral (f (Sup K) * (a/n))) K"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ((\<lambda>x. f (Sup K)) has_integral f (Sup K) * (a / real n)) K
[PROOF STEP]
using  \<open>n > 0\<close> \<open>a > 0\<close> has_integral_const_real [of "f (Sup K)" u v]
[PROOF STATE]
proof (prove)
using this:
0 < n
0 < a
((\<lambda>x. f (Sup K)) has_integral content {u..v} *\<^sub>R f (Sup K)) {u..v}

goal (1 subgoal):
 1. ((\<lambda>x. f (Sup K)) has_integral f (Sup K) * (a / real n)) K
[PROOF STEP]
by (simp add: Kuv field_simps u_def v_def a_seg_def)
[PROOF STATE]
proof (state)
this:
((\<lambda>x. f (Sup K)) has_integral f (Sup K) * (a / real n)) K

goal (2 subgoals):
 1. (f2 has_integral f (Sup K) * (a / real n)) K
 2. \<bar>f (Sup K) - f (Inf K)\<bar> < \<epsilon> / a
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
((\<lambda>x. f (Sup K)) has_integral f (Sup K) * (a / real n)) K
[PROOF STEP]
show "(f2 has_integral (f (Sup K) * (a/n))) K"
[PROOF STATE]
proof (prove)
using this:
((\<lambda>x. f (Sup K)) has_integral f (Sup K) * (a / real n)) K

goal (1 subgoal):
 1. (f2 has_integral f (Sup K) * (a / real n)) K
[PROOF STEP]
using has_integral_spike_finite_eq [of "{u}" K "\<lambda>x. f (Sup K)" f2] f2
[PROOF STATE]
proof (prove)
using this:
((\<lambda>x. f (Sup K)) has_integral f (Sup K) * (a / real n)) K
\<lbrakk>finite {u}; \<And>x. x \<in> K - {u} \<Longrightarrow> f (Sup K) = f2 x\<rbrakk> \<Longrightarrow> (f2 has_integral ?y) K = ((\<lambda>x. f (Sup K)) has_integral ?y) K
?x \<in> K - {u} \<Longrightarrow> f2 ?x = f (Sup K)

goal (1 subgoal):
 1. (f2 has_integral f (Sup K) * (a / real n)) K
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
(f2 has_integral f (Sup K) * (a / real n)) K

goal (1 subgoal):
 1. \<bar>f (Sup K) - f (Inf K)\<bar> < \<epsilon> / a
[PROOF STEP]
have "\<bar>v - u\<bar> < del (\<epsilon>/a)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<bar>v - u\<bar> < del (\<epsilon> / a)
[PROOF STEP]
using \<open>n > 0\<close> \<open>a > 0\<close>
[PROOF STATE]
proof (prove)
using this:
0 < n
0 < a

goal (1 subgoal):
 1. \<bar>v - u\<bar> < del (\<epsilon> / a)
[PROOF STEP]
by (simp add: v_def u_def a_seg_def field_simps an_less_del)
[PROOF STATE]
proof (state)
this:
\<bar>v - u\<bar> < del (\<epsilon> / a)

goal (1 subgoal):
 1. \<bar>f (Sup K) - f (Inf K)\<bar> < \<epsilon> / a
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
\<bar>v - u\<bar> < del (\<epsilon> / a)
[PROOF STEP]
have "\<bar>f v - f u\<bar> < \<epsilon>/a"
[PROOF STATE]
proof (prove)
using this:
\<bar>v - u\<bar> < del (\<epsilon> / a)

goal (1 subgoal):
 1. \<bar>f v - f u\<bar> < \<epsilon> / a
[PROOF STEP]
using \<open>\<epsilon> > 0\<close> \<open>a > 0\<close> \<open>0 \<le> u\<close> \<open>u \<le> a\<close> \<open>0 \<le> v\<close> \<open>v \<le> a\<close>
[PROOF STATE]
proof (prove)
using this:
\<bar>v - u\<bar> < del (\<epsilon> / a)
0 < \<epsilon>
0 < a
0 \<le> u
u \<le> a
0 \<le> v
v \<le> a

goal (1 subgoal):
 1. \<bar>f v - f u\<bar> < \<epsilon> / a
[PROOF STEP]
by (intro del) auto
[PROOF STATE]
proof (state)
this:
\<bar>f v - f u\<bar> < \<epsilon> / a

goal (1 subgoal):
 1. \<bar>f (Sup K) - f (Inf K)\<bar> < \<epsilon> / a
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
\<bar>f v - f u\<bar> < \<epsilon> / a
[PROOF STEP]
show "\<bar>f(Sup K) - f(Inf K)\<bar> < \<epsilon>/a"
[PROOF STATE]
proof (prove)
using this:
\<bar>f v - f u\<bar> < \<epsilon> / a

goal (1 subgoal):
 1. \<bar>f (Sup K) - f (Inf K)\<bar> < \<epsilon> / a
[PROOF STEP]
using InfK SupK
[PROOF STATE]
proof (prove)
using this:
\<bar>f v - f u\<bar> < \<epsilon> / a
Inf K = u
Sup K = v

goal (1 subgoal):
 1. \<bar>f (Sup K) - f (Inf K)\<bar> < \<epsilon> / a
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
\<bar>f (Sup K) - f (Inf K)\<bar> < \<epsilon> / a

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
?K \<in> regular_division 0 a n \<Longrightarrow> (f1 has_integral f (Inf ?K) * (a / real n)) ?K
?K \<in> regular_division 0 a n \<Longrightarrow> (f2 has_integral f (Sup ?K) * (a / real n)) ?K
?K \<in> regular_division 0 a n \<Longrightarrow> \<bar>f (Sup ?K) - f (Inf ?K)\<bar> < \<epsilon> / a

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have int_21_D: "((\<lambda>x. f2 x - f1 x) has_integral (f(Sup K) - f(Inf K)) * (a/n)) K" if "K\<in>?\<D>" for K
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ((\<lambda>x. f2 x - f1 x) has_integral (f (Sup K) - f (Inf K)) * (a / real n)) K
[PROOF STEP]
using that has_integral_diff [OF int_f2_D int_f1_D]
[PROOF STATE]
proof (prove)
using this:
K \<in> regular_division 0 a n
\<lbrakk>?S \<in> regular_division 0 a n; ?S \<in> regular_division 0 a n\<rbrakk> \<Longrightarrow> ((\<lambda>x. f2 x - f1 x) has_integral f (Sup ?S) * (a / real n) - f (Inf ?S) * (a / real n)) ?S

goal (1 subgoal):
 1. ((\<lambda>x. f2 x - f1 x) has_integral (f (Sup K) - f (Inf K)) * (a / real n)) K
[PROOF STEP]
by (simp add: algebra_simps)
[PROOF STATE]
proof (state)
this:
?K \<in> regular_division 0 a n \<Longrightarrow> ((\<lambda>x. f2 x - f1 x) has_integral (f (Sup ?K) - f (Inf ?K)) * (a / real n)) ?K

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have D_ne: "?\<D> \<noteq> {}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. regular_division 0 a n \<noteq> {}
[PROOF STEP]
by (metis \<open>0 < a\<close> \<open>n > 0\<close> card_gt_0_iff card_regular_division)
[PROOF STATE]
proof (state)
this:
regular_division 0 a n \<noteq> {}

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have f12: "((\<lambda>x. f2 x - f1 x) has_integral (\<Sum>K\<in>?\<D>. (f(Sup K) - f(Inf K)) * (a/n))) {0..a}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ((\<lambda>x. f2 x - f1 x) has_integral (\<Sum>K\<in>regular_division 0 a n. (f (Sup K) - f (Inf K)) * (a / real n))) {0..a}
[PROOF STEP]
by (intro div int_21_D has_integral_combine_division)
[PROOF STATE]
proof (state)
this:
((\<lambda>x. f2 x - f1 x) has_integral (\<Sum>K\<in>regular_division 0 a n. (f (Sup K) - f (Inf K)) * (a / real n))) {0..a}

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
((\<lambda>x. f2 x - f1 x) has_integral (\<Sum>K\<in>regular_division 0 a n. (f (Sup K) - f (Inf K)) * (a / real n))) {0..a}

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have "(\<Sum>K\<in>?\<D>. (f(Sup K) - f(Inf K)) * (a/n)) < \<epsilon>"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>K\<in>regular_division 0 a n. (f (Sup K) - f (Inf K)) * (a / real n)) < \<epsilon>
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. (\<Sum>K\<in>regular_division 0 a n. (f (Sup K) - f (Inf K)) * (a / real n)) < \<epsilon>
[PROOF STEP]
have "(\<Sum>K\<in>?\<D>. (f(Sup K) - f(Inf K)) * (a/n)) \<le> (\<Sum>K\<in>?\<D>. \<bar>f(Sup K) - f(Inf K)\<bar> * (a/n))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>K\<in>regular_division 0 a n. (f (Sup K) - f (Inf K)) * (a / real n)) \<le> (\<Sum>K\<in>regular_division 0 a n. \<bar>f (Sup K) - f (Inf K)\<bar> * (a / real n))
[PROOF STEP]
using \<open>n > 0\<close> \<open>a > 0\<close>
[PROOF STATE]
proof (prove)
using this:
0 < n
0 < a

goal (1 subgoal):
 1. (\<Sum>K\<in>regular_division 0 a n. (f (Sup K) - f (Inf K)) * (a / real n)) \<le> (\<Sum>K\<in>regular_division 0 a n. \<bar>f (Sup K) - f (Inf K)\<bar> * (a / real n))
[PROOF STEP]
by (smt (verit) divide_pos_pos of_nat_0_less_iff sum_mono zero_le_mult_iff)
[PROOF STATE]
proof (state)
this:
(\<Sum>K\<in>regular_division 0 a n. (f (Sup K) - f (Inf K)) * (a / real n)) \<le> (\<Sum>K\<in>regular_division 0 a n. \<bar>f (Sup K) - f (Inf K)\<bar> * (a / real n))

goal (1 subgoal):
 1. (\<Sum>K\<in>regular_division 0 a n. (f (Sup K) - f (Inf K)) * (a / real n)) < \<epsilon>
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>K\<in>regular_division 0 a n. (f (Sup K) - f (Inf K)) * (a / real n)) \<le> (\<Sum>K\<in>regular_division 0 a n. \<bar>f (Sup K) - f (Inf K)\<bar> * (a / real n))

goal (1 subgoal):
 1. (\<Sum>K\<in>regular_division 0 a n. (f (Sup K) - f (Inf K)) * (a / real n)) < \<epsilon>
[PROOF STEP]
have "\<dots> < (\<Sum>K\<in>?\<D>. \<epsilon>/n)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>K\<in>regular_division 0 a n. \<bar>f (Sup K) - f (Inf K)\<bar> * (a / real n)) < (\<Sum>K\<in>regular_division 0 a n. \<epsilon> / real n)
[PROOF STEP]
using \<open>n > 0\<close> \<open>a > 0\<close> less
[PROOF STATE]
proof (prove)
using this:
0 < n
0 < a
?K \<in> regular_division 0 a n \<Longrightarrow> \<bar>f (Sup ?K) - f (Inf ?K)\<bar> < \<epsilon> / a

goal (1 subgoal):
 1. (\<Sum>K\<in>regular_division 0 a n. \<bar>f (Sup K) - f (Inf K)\<bar> * (a / real n)) < (\<Sum>K\<in>regular_division 0 a n. \<epsilon> / real n)
[PROOF STEP]
by (intro sum_strict_mono finite_regular_division D_ne) (simp add: field_simps)
[PROOF STATE]
proof (state)
this:
(\<Sum>K\<in>regular_division 0 a n. \<bar>f (Sup K) - f (Inf K)\<bar> * (a / real n)) < (\<Sum>K\<in>regular_division 0 a n. \<epsilon> / real n)

goal (1 subgoal):
 1. (\<Sum>K\<in>regular_division 0 a n. (f (Sup K) - f (Inf K)) * (a / real n)) < \<epsilon>
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>K\<in>regular_division 0 a n. \<bar>f (Sup K) - f (Inf K)\<bar> * (a / real n)) < (\<Sum>K\<in>regular_division 0 a n. \<epsilon> / real n)

goal (1 subgoal):
 1. (\<Sum>K\<in>regular_division 0 a n. (f (Sup K) - f (Inf K)) * (a / real n)) < \<epsilon>
[PROOF STEP]
have "\<dots> = \<epsilon>"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>K\<in>regular_division 0 a n. \<epsilon> / real n) = \<epsilon>
[PROOF STEP]
using \<open>n > 0\<close> \<open>a > 0\<close>
[PROOF STATE]
proof (prove)
using this:
0 < n
0 < a

goal (1 subgoal):
 1. (\<Sum>K\<in>regular_division 0 a n. \<epsilon> / real n) = \<epsilon>
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
(\<Sum>K\<in>regular_division 0 a n. \<epsilon> / real n) = \<epsilon>

goal (1 subgoal):
 1. (\<Sum>K\<in>regular_division 0 a n. (f (Sup K) - f (Inf K)) * (a / real n)) < \<epsilon>
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
(\<Sum>K\<in>regular_division 0 a n. (f (Sup K) - f (Inf K)) * (a / real n)) < \<epsilon>
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
(\<Sum>K\<in>regular_division 0 a n. (f (Sup K) - f (Inf K)) * (a / real n)) < \<epsilon>

goal (1 subgoal):
 1. (\<Sum>K\<in>regular_division 0 a n. (f (Sup K) - f (Inf K)) * (a / real n)) < \<epsilon>
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
(\<Sum>K\<in>regular_division 0 a n. (f (Sup K) - f (Inf K)) * (a / real n)) < \<epsilon>

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
(\<Sum>K\<in>regular_division 0 a n. (f (Sup K) - f (Inf K)) * (a / real n)) < \<epsilon>

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
((\<lambda>x. f2 x - f1 x) has_integral (\<Sum>K\<in>regular_division 0 a n. (f (Sup K) - f (Inf K)) * (a / real n))) {0..a}
(\<Sum>K\<in>regular_division 0 a n. (f (Sup K) - f (Inf K)) * (a / real n)) < \<epsilon>
[PROOF STEP]
have f2_near_f1: "integral {0..a} (\<lambda>x. f2 x - f1 x) < \<epsilon>"
[PROOF STATE]
proof (prove)
using this:
((\<lambda>x. f2 x - f1 x) has_integral (\<Sum>K\<in>regular_division 0 a n. (f (Sup K) - f (Inf K)) * (a / real n))) {0..a}
(\<Sum>K\<in>regular_division 0 a n. (f (Sup K) - f (Inf K)) * (a / real n)) < \<epsilon>

goal (1 subgoal):
 1. integral {0..a} (\<lambda>x. f2 x - f1 x) < \<epsilon>
[PROOF STEP]
by (simp add: integral_unique)
[PROOF STATE]
proof (state)
this:
integral {0..a} (\<lambda>x. f2 x - f1 x) < \<epsilon>

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
define yidx where "yidx \<equiv> \<lambda>y. LEAST k. y < f (a_seg (Suc k))"
[PROOF STATE]
proof (state)
this:
yidx \<equiv> \<lambda>y. LEAST k. y < f (a_seg (real (Suc k)))

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have fa_yidx_le: "f (a_seg (yidx y)) \<le> y" and yidx_gt: "y < f (a_seg (Suc (yidx y)))"
      if "y \<in> {0..b}" for y
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. f (a_seg (real (yidx y))) \<le> y &&& y < f (a_seg (real (Suc (yidx y))))
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. f (a_seg (real (yidx y))) \<le> y
 2. y < f (a_seg (real (Suc (yidx y))))
[PROOF STEP]
obtain x where x: "f x = y" "x \<in> {0..a}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<And>x. \<lbrakk>f x = y; x \<in> {0..a}\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
using Topological_Spaces.IVT' [OF _ _ _ cont_0a] assms
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>f 0 \<le> ?y; ?y \<le> f a; 0 \<le> a\<rbrakk> \<Longrightarrow> \<exists>x\<ge>0. x \<le> a \<and> f x = ?y
strict_mono_on {0..} f
continuous_on {0..} f
0 \<le> a
f 0 = 0
f a = b
\<lbrakk>0 \<le> ?x; ?x \<le> a\<rbrakk> \<Longrightarrow> g (f ?x) = ?x

goal (1 subgoal):
 1. (\<And>x. \<lbrakk>f x = y; x \<in> {0..a}\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by (metis \<open>y \<in> {0..b}\<close> atLeastAtMost_iff)
[PROOF STATE]
proof (state)
this:
f x = y
x \<in> {0..a}

goal (2 subgoals):
 1. f (a_seg (real (yidx y))) \<le> y
 2. y < f (a_seg (real (Suc (yidx y))))
[PROOF STEP]
define k where "k \<equiv> nat \<lfloor>x/a * n\<rfloor>"
[PROOF STATE]
proof (state)
this:
k \<equiv> nat \<lfloor>x / a * real n\<rfloor>

goal (2 subgoals):
 1. f (a_seg (real (yidx y))) \<le> y
 2. y < f (a_seg (real (Suc (yidx y))))
[PROOF STEP]
have x_lims: "a_seg k \<le> x" "x < a_seg (Suc k)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. a_seg (real k) \<le> x &&& x < a_seg (real (Suc k))
[PROOF STEP]
using \<open>n > 0\<close> \<open>0 < a\<close> floor_divide_lower floor_divide_upper [of a "x*n"] x
[PROOF STATE]
proof (prove)
using this:
0 < n
0 < a
(0::?'a) < ?q \<Longrightarrow> of_int \<lfloor>?p / ?q\<rfloor> * ?q \<le> ?p
0 < a \<Longrightarrow> x * real n < (real_of_int \<lfloor>x * real n / a\<rfloor> + 1) * a
f x = y
x \<in> {0..a}

goal (1 subgoal):
 1. a_seg (real k) \<le> x &&& x < a_seg (real (Suc k))
[PROOF STEP]
by (auto simp: k_def a_seg_def field_simps)
[PROOF STATE]
proof (state)
this:
a_seg (real k) \<le> x
x < a_seg (real (Suc k))

goal (2 subgoals):
 1. f (a_seg (real (yidx y))) \<le> y
 2. y < f (a_seg (real (Suc (yidx y))))
[PROOF STEP]
with that x
[PROOF STATE]
proof (chain)
picking this:
y \<in> {0..b}
f x = y
x \<in> {0..a}
a_seg (real k) \<le> x
x < a_seg (real (Suc k))
[PROOF STEP]
obtain f_lims: "f (a_seg k) \<le> y" "y < f (a_seg (Suc k))"
[PROOF STATE]
proof (prove)
using this:
y \<in> {0..b}
f x = y
x \<in> {0..a}
a_seg (real k) \<le> x
x < a_seg (real (Suc k))

goal (1 subgoal):
 1. (\<lbrakk>f (a_seg (real k)) \<le> y; y < f (a_seg (real (Suc k)))\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
using strict_mono_onD [OF sm]
[PROOF STATE]
proof (prove)
using this:
y \<in> {0..b}
f x = y
x \<in> {0..a}
a_seg (real k) \<le> x
x < a_seg (real (Suc k))
\<lbrakk>?r \<in> {0..}; ?s \<in> {0..}; ?r < ?s\<rbrakk> \<Longrightarrow> f ?r < f ?s

goal (1 subgoal):
 1. (\<lbrakk>f (a_seg (real k)) \<le> y; y < f (a_seg (real (Suc k)))\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by force
[PROOF STATE]
proof (state)
this:
f (a_seg (real k)) \<le> y
y < f (a_seg (real (Suc k)))

goal (2 subgoals):
 1. f (a_seg (real (yidx y))) \<le> y
 2. y < f (a_seg (real (Suc (yidx y))))
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
f (a_seg (real k)) \<le> y
y < f (a_seg (real (Suc k)))
[PROOF STEP]
have "a_seg (yidx y) \<le> a_seg k"
[PROOF STATE]
proof (prove)
using this:
f (a_seg (real k)) \<le> y
y < f (a_seg (real (Suc k)))

goal (1 subgoal):
 1. a_seg (real (yidx y)) \<le> a_seg (real k)
[PROOF STEP]
by (simp add: Least_le \<open>strict_mono a_seg\<close> strict_mono_less_eq yidx_def)
[PROOF STATE]
proof (state)
this:
a_seg (real (yidx y)) \<le> a_seg (real k)

goal (2 subgoals):
 1. f (a_seg (real (yidx y))) \<le> y
 2. y < f (a_seg (real (Suc (yidx y))))
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
a_seg (real (yidx y)) \<le> a_seg (real k)
[PROOF STEP]
have "f (a_seg (yidx y)) \<le> f (a_seg k)"
[PROOF STATE]
proof (prove)
using this:
a_seg (real (yidx y)) \<le> a_seg (real k)

goal (1 subgoal):
 1. f (a_seg (real (yidx y))) \<le> f (a_seg (real k))
[PROOF STEP]
using strict_mono_onD [OF sm]
[PROOF STATE]
proof (prove)
using this:
a_seg (real (yidx y)) \<le> a_seg (real k)
\<lbrakk>?r \<in> {0..}; ?s \<in> {0..}; ?r < ?s\<rbrakk> \<Longrightarrow> f ?r < f ?s

goal (1 subgoal):
 1. f (a_seg (real (yidx y))) \<le> f (a_seg (real k))
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
f (a_seg (real (yidx y))) \<le> f (a_seg (real k))

goal (2 subgoals):
 1. f (a_seg (real (yidx y))) \<le> y
 2. y < f (a_seg (real (Suc (yidx y))))
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
f (a_seg (real (yidx y))) \<le> f (a_seg (real k))
[PROOF STEP]
show "f (a_seg (yidx y)) \<le> y"
[PROOF STATE]
proof (prove)
using this:
f (a_seg (real (yidx y))) \<le> f (a_seg (real k))

goal (1 subgoal):
 1. f (a_seg (real (yidx y))) \<le> y
[PROOF STEP]
using f_lims
[PROOF STATE]
proof (prove)
using this:
f (a_seg (real (yidx y))) \<le> f (a_seg (real k))
f (a_seg (real k)) \<le> y
y < f (a_seg (real (Suc k)))

goal (1 subgoal):
 1. f (a_seg (real (yidx y))) \<le> y
[PROOF STEP]
by linarith
[PROOF STATE]
proof (state)
this:
f (a_seg (real (yidx y))) \<le> y

goal (1 subgoal):
 1. y < f (a_seg (real (Suc (yidx y))))
[PROOF STEP]
show "y < f (a_seg (Suc (yidx y)))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. y < f (a_seg (real (Suc (yidx y))))
[PROOF STEP]
by (metis LeastI f_lims(2) yidx_def)
[PROOF STATE]
proof (state)
this:
y < f (a_seg (real (Suc (yidx y))))

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
?y \<in> {0..b} \<Longrightarrow> f (a_seg (real (yidx ?y))) \<le> ?y
?y \<in> {0..b} \<Longrightarrow> ?y < f (a_seg (real (Suc (yidx ?y))))

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have yidx_equality: "yidx y = k" if "y \<in> {0..b}" "y \<in> {f (a_seg k)..<f (a_seg (Suc k))}" for y k
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. yidx y = k
[PROOF STEP]
proof (rule antisym)
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. yidx y \<le> k
 2. k \<le> yidx y
[PROOF STEP]
show "yidx y \<le> k"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. yidx y \<le> k
[PROOF STEP]
unfolding yidx_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (LEAST k. y < f (a_seg (real (Suc k)))) \<le> k
[PROOF STEP]
by (metis atLeastLessThan_iff that(2) Least_le)
[PROOF STATE]
proof (state)
this:
yidx y \<le> k

goal (1 subgoal):
 1. k \<le> yidx y
[PROOF STEP]
have "(a_seg (real k)) < a_seg (1 + real (yidx y))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. a_seg (real k) < a_seg (1 + real (yidx y))
[PROOF STEP]
using yidx_gt [OF that(1)] that(2) strict_mono_onD [OF sm] order_le_less_trans
[PROOF STATE]
proof (prove)
using this:
y < f (a_seg (real (Suc (yidx y))))
y \<in> {f (a_seg (real k))..<f (a_seg (real (Suc k)))}
\<lbrakk>?r \<in> {0..}; ?s \<in> {0..}; ?r < ?s\<rbrakk> \<Longrightarrow> f ?r < f ?s
\<lbrakk>?x \<le> ?y; ?y < ?z\<rbrakk> \<Longrightarrow> ?x < ?z

goal (1 subgoal):
 1. a_seg (real k) < a_seg (1 + real (yidx y))
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
a_seg (real k) < a_seg (1 + real (yidx y))

goal (1 subgoal):
 1. k \<le> yidx y
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
a_seg (real k) < a_seg (1 + real (yidx y))
[PROOF STEP]
have "real k < 1 + real (yidx y)"
[PROOF STATE]
proof (prove)
using this:
a_seg (real k) < a_seg (1 + real (yidx y))

goal (1 subgoal):
 1. real k < 1 + real (yidx y)
[PROOF STEP]
by (simp add: \<open>strict_mono a_seg\<close> strict_mono_less)
[PROOF STATE]
proof (state)
this:
real k < 1 + real (yidx y)

goal (1 subgoal):
 1. k \<le> yidx y
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
real k < 1 + real (yidx y)
[PROOF STEP]
show "k \<le> yidx y"
[PROOF STATE]
proof (prove)
using this:
real k < 1 + real (yidx y)

goal (1 subgoal):
 1. k \<le> yidx y
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
k \<le> yidx y

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<lbrakk>?y \<in> {0..b}; ?y \<in> {f (a_seg (real ?k))..<f (a_seg (real (Suc ?k)))}\<rbrakk> \<Longrightarrow> yidx ?y = ?k

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have "yidx b = n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. yidx b = n
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. yidx b = n
[PROOF STEP]
have "a < (1 + real n) * a / real n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. a < (1 + real n) * a / real n
[PROOF STEP]
using \<open>0 < n\<close> \<open>0 < a\<close>
[PROOF STATE]
proof (prove)
using this:
0 < n
0 < a

goal (1 subgoal):
 1. a < (1 + real n) * a / real n
[PROOF STEP]
by (simp add: divide_simps)
[PROOF STATE]
proof (state)
this:
a < (1 + real n) * a / real n

goal (1 subgoal):
 1. yidx b = n
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
a < (1 + real n) * a / real n
[PROOF STEP]
have "b < f (a_seg (1 + real n))"
[PROOF STATE]
proof (prove)
using this:
a < (1 + real n) * a / real n

goal (1 subgoal):
 1. b < f (a_seg (1 + real n))
[PROOF STEP]
using f \<open>a \<ge> 0\<close> a_seg_def sm strict_mono_onD
[PROOF STATE]
proof (prove)
using this:
a < (1 + real n) * a / real n
f 0 = 0
f a = b
0 \<le> a
a_seg \<equiv> \<lambda>u. u * a / real n
strict_mono_on {0..} f
\<lbrakk>strict_mono_on ?A ?f; ?r \<in> ?A; ?s \<in> ?A; ?r < ?s\<rbrakk> \<Longrightarrow> ?f ?r < ?f ?s

goal (1 subgoal):
 1. b < f (a_seg (1 + real n))
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
b < f (a_seg (1 + real n))

goal (1 subgoal):
 1. yidx b = n
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
b < f (a_seg (1 + real n))
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
b < f (a_seg (1 + real n))

goal (1 subgoal):
 1. yidx b = n
[PROOF STEP]
using \<open>0 \<le> b\<close>
[PROOF STATE]
proof (prove)
using this:
b < f (a_seg (1 + real n))
0 \<le> b

goal (1 subgoal):
 1. yidx b = n
[PROOF STEP]
by (auto simp: f a_seg_def yidx_equality)
[PROOF STATE]
proof (state)
this:
yidx b = n

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
yidx b = n

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
yidx b = n

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have yidx_less_n: "yidx y < n" if "y < b" for y
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. yidx y < n
[PROOF STEP]
by (metis \<open>0 < n\<close> fa_eq_b gr0_conv_Suc less_Suc_eq_le that Least_le yidx_def)
[PROOF STATE]
proof (state)
this:
?y < b \<Longrightarrow> yidx ?y < n

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
yidx b = n
?y < b \<Longrightarrow> yidx ?y < n
[PROOF STEP]
have yidx_le_n: "yidx y \<le> n" if "y \<le> b" for y
[PROOF STATE]
proof (prove)
using this:
yidx b = n
?y < b \<Longrightarrow> yidx ?y < n

goal (1 subgoal):
 1. yidx y \<le> n
[PROOF STEP]
by (metis dual_order.order_iff_strict that)
[PROOF STATE]
proof (state)
this:
?y \<le> b \<Longrightarrow> yidx ?y \<le> n

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have zero_to_b_eq: "{0..b} = (\<Union>k<n. {f(a_seg k)..f(a_seg (Suc k))})" (is "?lhs = ?rhs")
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. {0..b} = (\<Union>k<n. {f (a_seg (real k))..f (a_seg (real (Suc k)))})
[PROOF STEP]
proof
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. {0..b} \<subseteq> (\<Union>k<n. {f (a_seg (real k))..f (a_seg (real (Suc k)))})
 2. (\<Union>k<n. {f (a_seg (real k))..f (a_seg (real (Suc k)))}) \<subseteq> {0..b}
[PROOF STEP]
show "?lhs \<subseteq> ?rhs"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. {0..b} \<subseteq> (\<Union>k<n. {f (a_seg (real k))..f (a_seg (real (Suc k)))})
[PROOF STEP]
proof
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>x. x \<in> {0..b} \<Longrightarrow> x \<in> (\<Union>k<n. {f (a_seg (real k))..f (a_seg (real (Suc k)))})
[PROOF STEP]
fix y
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>x. x \<in> {0..b} \<Longrightarrow> x \<in> (\<Union>k<n. {f (a_seg (real k))..f (a_seg (real (Suc k)))})
[PROOF STEP]
assume y: "y \<in> {0..b}"
[PROOF STATE]
proof (state)
this:
y \<in> {0..b}

goal (1 subgoal):
 1. \<And>x. x \<in> {0..b} \<Longrightarrow> x \<in> (\<Union>k<n. {f (a_seg (real k))..f (a_seg (real (Suc k)))})
[PROOF STEP]
have fn: "f (a_seg n) = b"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. f (a_seg (real n)) = b
[PROOF STEP]
using a_seg_eq_a_iff \<open>f a = b\<close>
[PROOF STATE]
proof (prove)
using this:
(a_seg ?x = a) = (?x = real n)
f a = b

goal (1 subgoal):
 1. f (a_seg (real n)) = b
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
f (a_seg (real n)) = b

goal (1 subgoal):
 1. \<And>x. x \<in> {0..b} \<Longrightarrow> x \<in> (\<Union>k<n. {f (a_seg (real k))..f (a_seg (real (Suc k)))})
[PROOF STEP]
show "y \<in> ?rhs"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. y \<in> (\<Union>k<n. {f (a_seg (real k))..f (a_seg (real (Suc k)))})
[PROOF STEP]
proof (cases "y=b")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. y = b \<Longrightarrow> y \<in> (\<Union>k<n. {f (a_seg (real k))..f (a_seg (real (Suc k)))})
 2. y \<noteq> b \<Longrightarrow> y \<in> (\<Union>k<n. {f (a_seg (real k))..f (a_seg (real (Suc k)))})
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
y = b

goal (2 subgoals):
 1. y = b \<Longrightarrow> y \<in> (\<Union>k<n. {f (a_seg (real k))..f (a_seg (real (Suc k)))})
 2. y \<noteq> b \<Longrightarrow> y \<in> (\<Union>k<n. {f (a_seg (real k))..f (a_seg (real (Suc k)))})
[PROOF STEP]
with fn \<open>n>0\<close>
[PROOF STATE]
proof (chain)
picking this:
f (a_seg (real n)) = b
0 < n
y = b
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
f (a_seg (real n)) = b
0 < n
y = b

goal (1 subgoal):
 1. y \<in> (\<Union>k<n. {f (a_seg (real k))..f (a_seg (real (Suc k)))})
[PROOF STEP]
by (rule_tac a="n-1" in UN_I) auto
[PROOF STATE]
proof (state)
this:
y \<in> (\<Union>k<n. {f (a_seg (real k))..f (a_seg (real (Suc k)))})

goal (1 subgoal):
 1. y \<noteq> b \<Longrightarrow> y \<in> (\<Union>k<n. {f (a_seg (real k))..f (a_seg (real (Suc k)))})
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. y \<noteq> b \<Longrightarrow> y \<in> (\<Union>k<n. {f (a_seg (real k))..f (a_seg (real (Suc k)))})
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
y \<noteq> b

goal (1 subgoal):
 1. y \<noteq> b \<Longrightarrow> y \<in> (\<Union>k<n. {f (a_seg (real k))..f (a_seg (real (Suc k)))})
[PROOF STEP]
with y
[PROOF STATE]
proof (chain)
picking this:
y \<in> {0..b}
y \<noteq> b
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
y \<in> {0..b}
y \<noteq> b

goal (1 subgoal):
 1. y \<in> (\<Union>k<n. {f (a_seg (real k))..f (a_seg (real (Suc k)))})
[PROOF STEP]
apply (simp add: subset_iff Bex_def)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>0 \<le> y \<and> y \<le> b; y \<noteq> b\<rbrakk> \<Longrightarrow> \<exists>x<n. f (a_seg (real x)) \<le> y \<and> y \<le> f (a_seg (1 + real x))
[PROOF STEP]
by (metis atLeastAtMost_iff of_nat_Suc order_le_less yidx_gt fa_yidx_le yidx_less_n)
[PROOF STATE]
proof (state)
this:
y \<in> (\<Union>k<n. {f (a_seg (real k))..f (a_seg (real (Suc k)))})

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
y \<in> (\<Union>k<n. {f (a_seg (real k))..f (a_seg (real (Suc k)))})

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
{0..b} \<subseteq> (\<Union>k<n. {f (a_seg (real k))..f (a_seg (real (Suc k)))})

goal (1 subgoal):
 1. (\<Union>k<n. {f (a_seg (real k))..f (a_seg (real (Suc k)))}) \<subseteq> {0..b}
[PROOF STEP]
show "?rhs \<subseteq> ?lhs"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Union>k<n. {f (a_seg (real k))..f (a_seg (real (Suc k)))}) \<subseteq> {0..b}
[PROOF STEP]
apply clarsimp
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>x xa. \<lbrakk>xa < n; f (a_seg (real xa)) \<le> x; x \<le> f (a_seg (1 + real xa))\<rbrakk> \<Longrightarrow> 0 \<le> x \<and> x \<le> b
[PROOF STEP]
by (smt (verit, best) a_seg_ge_0 a_seg_le_a f f_iff(2) nat_less_real_le of_nat_0_le_iff)
[PROOF STATE]
proof (state)
this:
(\<Union>k<n. {f (a_seg (real k))..f (a_seg (real (Suc k)))}) \<subseteq> {0..b}

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
{0..b} = (\<Union>k<n. {f (a_seg (real k))..f (a_seg (real (Suc k)))})

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
define g1 where "g1 \<equiv> \<lambda>y. if y=b then a else a_seg (Suc (yidx y))"
[PROOF STATE]
proof (state)
this:
g1 \<equiv> \<lambda>y. if y = b then a else a_seg (real (Suc (yidx y)))

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
define g2 where "g2 \<equiv> \<lambda>y. if y=0 then 0 else a_seg (yidx y)"
[PROOF STATE]
proof (state)
this:
g2 \<equiv> \<lambda>y. if y = 0 then 0 else a_seg (real (yidx y))

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have g1: "g1 y \<in> {0..a}" if "y \<in> {0..b}" for y
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. g1 y \<in> {0..a}
[PROOF STEP]
using that \<open>a > 0\<close> yidx_less_n [of y]
[PROOF STATE]
proof (prove)
using this:
y \<in> {0..b}
0 < a
y < b \<Longrightarrow> yidx y < n

goal (1 subgoal):
 1. g1 y \<in> {0..a}
[PROOF STEP]
by (auto simp: g1_def a_seg_def divide_simps)
[PROOF STATE]
proof (state)
this:
?y \<in> {0..b} \<Longrightarrow> g1 ?y \<in> {0..a}

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have g2: "g2 y \<in> {0..a}" if "y \<in> {0..b}" for y
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. g2 y \<in> {0..a}
[PROOF STEP]
using that \<open>a > 0\<close> yidx_le_n [of y]
[PROOF STATE]
proof (prove)
using this:
y \<in> {0..b}
0 < a
y \<le> b \<Longrightarrow> yidx y \<le> n

goal (1 subgoal):
 1. g2 y \<in> {0..a}
[PROOF STEP]
by (simp add: g2_def a_seg_def divide_simps)
[PROOF STATE]
proof (state)
this:
?y \<in> {0..b} \<Longrightarrow> g2 ?y \<in> {0..a}

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have g2_le_g: "g2 y \<le> g y" if "y \<in> {0..b}" for y
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. g2 y \<le> g y
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. g2 y \<le> g y
[PROOF STEP]
have "f (g2 y) \<le> y"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. f (g2 y) \<le> y
[PROOF STEP]
using \<open>f 0 = 0\<close> g2_def that fa_yidx_le
[PROOF STATE]
proof (prove)
using this:
f 0 = 0
g2 \<equiv> \<lambda>y. if y = 0 then 0 else a_seg (real (yidx y))
y \<in> {0..b}
?y \<in> {0..b} \<Longrightarrow> f (a_seg (real (yidx ?y))) \<le> ?y

goal (1 subgoal):
 1. f (g2 y) \<le> y
[PROOF STEP]
by presburger
[PROOF STATE]
proof (state)
this:
f (g2 y) \<le> y

goal (1 subgoal):
 1. g2 y \<le> g y
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
f (g2 y) \<le> y
[PROOF STEP]
have "f (g2 y) \<le> f (g y)"
[PROOF STATE]
proof (prove)
using this:
f (g2 y) \<le> y

goal (1 subgoal):
 1. f (g2 y) \<le> f (g y)
[PROOF STEP]
using that g
[PROOF STATE]
proof (prove)
using this:
f (g2 y) \<le> y
y \<in> {0..b}
\<lbrakk>0 \<le> ?x; ?x \<le> a\<rbrakk> \<Longrightarrow> g (f ?x) = ?x

goal (1 subgoal):
 1. f (g2 y) \<le> f (g y)
[PROOF STEP]
by (smt (verit, best) atLeastAtMost_iff fim image_iff)
[PROOF STATE]
proof (state)
this:
f (g2 y) \<le> f (g y)

goal (1 subgoal):
 1. g2 y \<le> g y
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
f (g2 y) \<le> f (g y)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
f (g2 y) \<le> f (g y)

goal (1 subgoal):
 1. g2 y \<le> g y
[PROOF STEP]
by (smt (verit, best) atLeastAtMost_iff fim g g2 imageE sm_0a strict_mono_onD that)
[PROOF STATE]
proof (state)
this:
g2 y \<le> g y

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
?y \<in> {0..b} \<Longrightarrow> g2 ?y \<le> g ?y

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have g_le_g1: "g y \<le> g1 y" if "y \<in> {0..b}" for y
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. g y \<le> g1 y
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. g y \<le> g1 y
[PROOF STEP]
have "y \<le> f (g1 y)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. y \<le> f (g1 y)
[PROOF STEP]
by (smt (verit, best) \<open>f a = b\<close> g1_def that yidx_gt)
[PROOF STATE]
proof (state)
this:
y \<le> f (g1 y)

goal (1 subgoal):
 1. g y \<le> g1 y
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
y \<le> f (g1 y)
[PROOF STEP]
have "f (g y) \<le> f (g1 y)"
[PROOF STATE]
proof (prove)
using this:
y \<le> f (g1 y)

goal (1 subgoal):
 1. f (g y) \<le> f (g1 y)
[PROOF STEP]
using that g
[PROOF STATE]
proof (prove)
using this:
y \<le> f (g1 y)
y \<in> {0..b}
\<lbrakk>0 \<le> ?x; ?x \<le> a\<rbrakk> \<Longrightarrow> g (f ?x) = ?x

goal (1 subgoal):
 1. f (g y) \<le> f (g1 y)
[PROOF STEP]
by (smt (verit, best) atLeastAtMost_iff fim image_iff)
[PROOF STATE]
proof (state)
this:
f (g y) \<le> f (g1 y)

goal (1 subgoal):
 1. g y \<le> g1 y
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
f (g y) \<le> f (g1 y)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
f (g y) \<le> f (g1 y)

goal (1 subgoal):
 1. g y \<le> g1 y
[PROOF STEP]
by (smt (verit, ccfv_threshold) atLeastAtMost_iff f_iff(1) g1 that)
[PROOF STATE]
proof (state)
this:
g y \<le> g1 y

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
?y \<in> {0..b} \<Longrightarrow> g ?y \<le> g1 ?y

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
define DN where "DN \<equiv> \<lambda>K. nat \<lfloor>Inf K * real n / a\<rfloor>"
[PROOF STATE]
proof (state)
this:
DN \<equiv> \<lambda>K. nat \<lfloor>Inf K * real n / a\<rfloor>

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have [simp]: "DN {a * real k / n..a * (1 + real k) / n} = k" for k
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. DN {a * real k / real n..a * (1 + real k) / real n} = k
[PROOF STEP]
using \<open>n > 0\<close> \<open>a > 0\<close>
[PROOF STATE]
proof (prove)
using this:
0 < n
0 < a

goal (1 subgoal):
 1. DN {a * real k / real n..a * (1 + real k) / real n} = k
[PROOF STEP]
by (simp add: DN_def divide_simps)
[PROOF STATE]
proof (state)
this:
DN {a * real ?k / real n..a * (1 + real ?k) / real n} = ?k

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have DN: "bij_betw DN ?\<D> {..<n}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. bij_betw DN (regular_division 0 a n) {..<n}
[PROOF STEP]
proof (intro bij_betw_imageI)
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. inj_on DN (regular_division 0 a n)
 2. DN ` regular_division 0 a n = {..<n}
[PROOF STEP]
show "inj_on DN (regular_division 0 a n)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. inj_on DN (regular_division 0 a n)
[PROOF STEP]
proof
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>x y. \<lbrakk>x \<in> regular_division 0 a n; y \<in> regular_division 0 a n; DN x = DN y\<rbrakk> \<Longrightarrow> x = y
[PROOF STEP]
fix K K'
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>x y. \<lbrakk>x \<in> regular_division 0 a n; y \<in> regular_division 0 a n; DN x = DN y\<rbrakk> \<Longrightarrow> x = y
[PROOF STEP]
assume "K \<in> regular_division 0 a n"
[PROOF STATE]
proof (state)
this:
K \<in> regular_division 0 a n

goal (1 subgoal):
 1. \<And>x y. \<lbrakk>x \<in> regular_division 0 a n; y \<in> regular_division 0 a n; DN x = DN y\<rbrakk> \<Longrightarrow> x = y
[PROOF STEP]
with \<open>a > 0\<close>
[PROOF STATE]
proof (chain)
picking this:
0 < a
K \<in> regular_division 0 a n
[PROOF STEP]
obtain k where k: "K = {a * (real k / n) .. a * (1 + real k) / n}"
[PROOF STATE]
proof (prove)
using this:
0 < a
K \<in> regular_division 0 a n

goal (1 subgoal):
 1. (\<And>k. K = {a * (real k / real n)..a * (1 + real k) / real n} \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by (force elim: regular_divisionE)
[PROOF STATE]
proof (state)
this:
K = {a * (real k / real n)..a * (1 + real k) / real n}

goal (1 subgoal):
 1. \<And>x y. \<lbrakk>x \<in> regular_division 0 a n; y \<in> regular_division 0 a n; DN x = DN y\<rbrakk> \<Longrightarrow> x = y
[PROOF STEP]
assume "K' \<in> regular_division 0 a n"
[PROOF STATE]
proof (state)
this:
K' \<in> regular_division 0 a n

goal (1 subgoal):
 1. \<And>x y. \<lbrakk>x \<in> regular_division 0 a n; y \<in> regular_division 0 a n; DN x = DN y\<rbrakk> \<Longrightarrow> x = y
[PROOF STEP]
with \<open>a > 0\<close>
[PROOF STATE]
proof (chain)
picking this:
0 < a
K' \<in> regular_division 0 a n
[PROOF STEP]
obtain k' where k': "K' = {a * (real k' / n) .. a * (1 + real k') / n}"
[PROOF STATE]
proof (prove)
using this:
0 < a
K' \<in> regular_division 0 a n

goal (1 subgoal):
 1. (\<And>k'. K' = {a * (real k' / real n)..a * (1 + real k') / real n} \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by (force elim: regular_divisionE)
[PROOF STATE]
proof (state)
this:
K' = {a * (real k' / real n)..a * (1 + real k') / real n}

goal (1 subgoal):
 1. \<And>x y. \<lbrakk>x \<in> regular_division 0 a n; y \<in> regular_division 0 a n; DN x = DN y\<rbrakk> \<Longrightarrow> x = y
[PROOF STEP]
assume "DN K = DN K'"
[PROOF STATE]
proof (state)
this:
DN K = DN K'

goal (1 subgoal):
 1. \<And>x y. \<lbrakk>x \<in> regular_division 0 a n; y \<in> regular_division 0 a n; DN x = DN y\<rbrakk> \<Longrightarrow> x = y
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
DN K = DN K'
[PROOF STEP]
show "K = K'"
[PROOF STATE]
proof (prove)
using this:
DN K = DN K'

goal (1 subgoal):
 1. K = K'
[PROOF STEP]
by (simp add: k k')
[PROOF STATE]
proof (state)
this:
K = K'

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
inj_on DN (regular_division 0 a n)

goal (1 subgoal):
 1. DN ` regular_division 0 a n = {..<n}
[PROOF STEP]
have "\<exists>K\<in>regular_division 0 a n. k = nat \<lfloor>Inf K * real n / a\<rfloor>" if "k < n" for k
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<exists>K\<in>regular_division 0 a n. k = nat \<lfloor>Inf K * real n / a\<rfloor>
[PROOF STEP]
using \<open>n > 0\<close> \<open>a > 0\<close> that
[PROOF STATE]
proof (prove)
using this:
0 < n
0 < a
k < n

goal (1 subgoal):
 1. \<exists>K\<in>regular_division 0 a n. k = nat \<lfloor>Inf K * real n / a\<rfloor>
[PROOF STEP]
by (force simp: divide_simps intro: regular_division_eqI [OF refl])
[PROOF STATE]
proof (state)
this:
?k < n \<Longrightarrow> \<exists>K\<in>regular_division 0 a n. ?k = nat \<lfloor>Inf K * real n / a\<rfloor>

goal (1 subgoal):
 1. DN ` regular_division 0 a n = {..<n}
[PROOF STEP]
with \<open>a>0\<close>
[PROOF STATE]
proof (chain)
picking this:
0 < a
?k < n \<Longrightarrow> \<exists>K\<in>regular_division 0 a n. ?k = nat \<lfloor>Inf K * real n / a\<rfloor>
[PROOF STEP]
show "DN ` regular_division 0 a n = {..<n}"
[PROOF STATE]
proof (prove)
using this:
0 < a
?k < n \<Longrightarrow> \<exists>K\<in>regular_division 0 a n. ?k = nat \<lfloor>Inf K * real n / a\<rfloor>

goal (1 subgoal):
 1. DN ` regular_division 0 a n = {..<n}
[PROOF STEP]
by (auto simp: DN_def bij_betw_def image_iff frac_le elim!: regular_divisionE)
[PROOF STATE]
proof (state)
this:
DN ` regular_division 0 a n = {..<n}

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
bij_betw DN (regular_division 0 a n) {..<n}

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have int_f1: "(f1 has_integral (\<Sum>k<n. f(a_seg k)) * (a/n)) {0..a}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (f1 has_integral (\<Sum>k<n. f (a_seg (real k))) * (a / real n)) {0..a}
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. (f1 has_integral (\<Sum>k<n. f (a_seg (real k))) * (a / real n)) {0..a}
[PROOF STEP]
have "a_seg (real (DN K)) = Inf K" if "K \<in> ?\<D>" for K
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. a_seg (real (DN K)) = Inf K
[PROOF STEP]
using that \<open>a>0\<close>
[PROOF STATE]
proof (prove)
using this:
K \<in> regular_division 0 a n
0 < a

goal (1 subgoal):
 1. a_seg (real (DN K)) = Inf K
[PROOF STEP]
by (auto simp: DN_def field_simps a_seg_def elim: regular_divisionE)
[PROOF STATE]
proof (state)
this:
?K \<in> regular_division 0 a n \<Longrightarrow> a_seg (real (DN ?K)) = Inf ?K

goal (1 subgoal):
 1. (f1 has_integral (\<Sum>k<n. f (a_seg (real k))) * (a / real n)) {0..a}
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
?K \<in> regular_division 0 a n \<Longrightarrow> a_seg (real (DN ?K)) = Inf ?K
[PROOF STEP]
have "(\<Sum>K\<in>?\<D>. f(Inf K) * (a/n)) = (\<Sum>k<n. (f(a_seg k)) * (a/n))"
[PROOF STATE]
proof (prove)
using this:
?K \<in> regular_division 0 a n \<Longrightarrow> a_seg (real (DN ?K)) = Inf ?K

goal (1 subgoal):
 1. (\<Sum>K\<in>regular_division 0 a n. f (Inf K) * (a / real n)) = (\<Sum>k<n. f (a_seg (real k)) * (a / real n))
[PROOF STEP]
by (simp flip: sum.reindex_bij_betw [OF DN])
[PROOF STATE]
proof (state)
this:
(\<Sum>K\<in>regular_division 0 a n. f (Inf K) * (a / real n)) = (\<Sum>k<n. f (a_seg (real k)) * (a / real n))

goal (1 subgoal):
 1. (f1 has_integral (\<Sum>k<n. f (a_seg (real k))) * (a / real n)) {0..a}
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
(\<Sum>K\<in>regular_division 0 a n. f (Inf K) * (a / real n)) = (\<Sum>k<n. f (a_seg (real k)) * (a / real n))

goal (1 subgoal):
 1. (f1 has_integral (\<Sum>k<n. f (a_seg (real k))) * (a / real n)) {0..a}
[PROOF STEP]
have "(f1 has_integral (\<Sum>K\<in>?\<D>. f(Inf K) * (a/n))) {0..a}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (f1 has_integral (\<Sum>K\<in>regular_division 0 a n. f (Inf K) * (a / real n))) {0..a}
[PROOF STEP]
by (intro div int_f1_D has_integral_combine_division)
[PROOF STATE]
proof (state)
this:
(f1 has_integral (\<Sum>K\<in>regular_division 0 a n. f (Inf K) * (a / real n))) {0..a}

goal (1 subgoal):
 1. (f1 has_integral (\<Sum>k<n. f (a_seg (real k))) * (a / real n)) {0..a}
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
(\<Sum>K\<in>regular_division 0 a n. f (Inf K) * (a / real n)) = (\<Sum>k<n. f (a_seg (real k)) * (a / real n))
(f1 has_integral (\<Sum>K\<in>regular_division 0 a n. f (Inf K) * (a / real n))) {0..a}
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
(\<Sum>K\<in>regular_division 0 a n. f (Inf K) * (a / real n)) = (\<Sum>k<n. f (a_seg (real k)) * (a / real n))
(f1 has_integral (\<Sum>K\<in>regular_division 0 a n. f (Inf K) * (a / real n))) {0..a}

goal (1 subgoal):
 1. (f1 has_integral (\<Sum>k<n. f (a_seg (real k))) * (a / real n)) {0..a}
[PROOF STEP]
by (metis sum_distrib_right)
[PROOF STATE]
proof (state)
this:
(f1 has_integral (\<Sum>k<n. f (a_seg (real k))) * (a / real n)) {0..a}

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
(f1 has_integral (\<Sum>k<n. f (a_seg (real k))) * (a / real n)) {0..a}

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
text \<open>The claim @{term "(f2 has_integral (\<Sum>k<n. f(a_seg(Suc k))) * (a/n)) {0..a}"} can similarly be proved\<close>
[PROOF STATE]
proof (state)
this:
(f1 has_integral (\<Sum>k<n. f (a_seg (real k))) * (a / real n)) {0..a}

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have int_g1_D: "(g1 has_integral a_seg (Suc k) * (f (a_seg (Suc k)) - f (a_seg k)))
                    {f(a_seg k)..f(a_seg (Suc k))}"
     and int_g2_D: "(g2 has_integral a_seg k * (f (a_seg (Suc k)) - f (a_seg k)))
                    {f(a_seg k)..f(a_seg (Suc k))}"
      if "k < n" for k
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (g1 has_integral a_seg (real (Suc k)) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) {f (a_seg (real k))..f (a_seg (real (Suc k)))} &&& (g2 has_integral a_seg (real k) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) {f (a_seg (real k))..f (a_seg (real (Suc k)))}
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. (g1 has_integral a_seg (real (Suc k)) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) {f (a_seg (real k))..f (a_seg (real (Suc k)))}
 2. (g2 has_integral a_seg (real k) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) {f (a_seg (real k))..f (a_seg (real (Suc k)))}
[PROOF STEP]
define u where "u \<equiv> f (a_seg k)"
[PROOF STATE]
proof (state)
this:
u \<equiv> f (a_seg (real k))

goal (2 subgoals):
 1. (g1 has_integral a_seg (real (Suc k)) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) {f (a_seg (real k))..f (a_seg (real (Suc k)))}
 2. (g2 has_integral a_seg (real k) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) {f (a_seg (real k))..f (a_seg (real (Suc k)))}
[PROOF STEP]
define v where "v \<equiv> f (a_seg (Suc k))"
[PROOF STATE]
proof (state)
this:
v \<equiv> f (a_seg (real (Suc k)))

goal (2 subgoals):
 1. (g1 has_integral a_seg (real (Suc k)) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) {f (a_seg (real k))..f (a_seg (real (Suc k)))}
 2. (g2 has_integral a_seg (real k) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) {f (a_seg (real k))..f (a_seg (real (Suc k)))}
[PROOF STEP]
obtain "u < v" "0 \<le> u" "0 \<le> v"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lbrakk>u < v; 0 \<le> u; 0 \<le> v\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
unfolding u_def v_def assms
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lbrakk>f (a_seg (real k)) < f (a_seg (real (Suc k))); 0 \<le> f (a_seg (real k)); 0 \<le> f (a_seg (real (Suc k)))\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by (smt (verit, best) a_seg_ge_0 a_seg_le_iff f(1) f_iff(1) of_nat_0_le_iff of_nat_Suc)
[PROOF STATE]
proof (state)
this:
u < v
0 \<le> u
0 \<le> v

goal (2 subgoals):
 1. (g1 has_integral a_seg (real (Suc k)) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) {f (a_seg (real k))..f (a_seg (real (Suc k)))}
 2. (g2 has_integral a_seg (real k) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) {f (a_seg (real k))..f (a_seg (real (Suc k)))}
[PROOF STEP]
have "u \<le> b" "v \<le> b"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. u \<le> b &&& v \<le> b
[PROOF STEP]
using \<open>k < n\<close> \<open>a \<ge> 0\<close>
[PROOF STATE]
proof (prove)
using this:
k < n
0 \<le> a

goal (1 subgoal):
 1. u \<le> b &&& v \<le> b
[PROOF STEP]
by (simp_all add: u_def v_def flip: \<open>f a = b\<close>)
[PROOF STATE]
proof (state)
this:
u \<le> b
v \<le> b

goal (2 subgoals):
 1. (g1 has_integral a_seg (real (Suc k)) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) {f (a_seg (real k))..f (a_seg (real (Suc k)))}
 2. (g2 has_integral a_seg (real k) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) {f (a_seg (real k))..f (a_seg (real (Suc k)))}
[PROOF STEP]
have yidx_eq: "yidx x = k" if "x \<in> {u..<v}" for x
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. yidx x = k
[PROOF STEP]
using \<open>0 \<le> u\<close> \<open>v \<le> b\<close> that u_def v_def yidx_equality
[PROOF STATE]
proof (prove)
using this:
0 \<le> u
v \<le> b
x \<in> {u..<v}
u \<equiv> f (a_seg (real k))
v \<equiv> f (a_seg (real (Suc k)))
\<lbrakk>?y \<in> {0..b}; ?y \<in> {f (a_seg (real ?k))..<f (a_seg (real (Suc ?k)))}\<rbrakk> \<Longrightarrow> yidx ?y = ?k

goal (1 subgoal):
 1. yidx x = k
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
?x \<in> {u..<v} \<Longrightarrow> yidx ?x = k

goal (2 subgoals):
 1. (g1 has_integral a_seg (real (Suc k)) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) {f (a_seg (real k))..f (a_seg (real (Suc k)))}
 2. (g2 has_integral a_seg (real k) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) {f (a_seg (real k))..f (a_seg (real (Suc k)))}
[PROOF STEP]
have "g1 x = a_seg (Suc k)" if "x \<in> {u..<v}" for x
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. g1 x = a_seg (real (Suc k))
[PROOF STEP]
using that \<open>v \<le> b\<close>
[PROOF STATE]
proof (prove)
using this:
x \<in> {u..<v}
v \<le> b

goal (1 subgoal):
 1. g1 x = a_seg (real (Suc k))
[PROOF STEP]
by (simp add: g1_def yidx_eq)
[PROOF STATE]
proof (state)
this:
?x \<in> {u..<v} \<Longrightarrow> g1 ?x = a_seg (real (Suc k))

goal (2 subgoals):
 1. (g1 has_integral a_seg (real (Suc k)) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) {f (a_seg (real k))..f (a_seg (real (Suc k)))}
 2. (g2 has_integral a_seg (real k) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) {f (a_seg (real k))..f (a_seg (real (Suc k)))}
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
?x \<in> {u..<v} \<Longrightarrow> g1 ?x = a_seg (real (Suc k))

goal (2 subgoals):
 1. (g1 has_integral a_seg (real (Suc k)) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) {f (a_seg (real k))..f (a_seg (real (Suc k)))}
 2. (g2 has_integral a_seg (real k) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) {f (a_seg (real k))..f (a_seg (real (Suc k)))}
[PROOF STEP]
have "((\<lambda>x. a_seg (Suc k)) has_integral (a_seg (Suc k) * (v-u))) {u..v}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ((\<lambda>x. a_seg (real (Suc k))) has_integral a_seg (real (Suc k)) * (v - u)) {u..v}
[PROOF STEP]
using has_integral_const_real \<open>u < v\<close>
[PROOF STATE]
proof (prove)
using this:
((\<lambda>x. ?c) has_integral content {?a..?b} *\<^sub>R ?c) {?a..?b}
u < v

goal (1 subgoal):
 1. ((\<lambda>x. a_seg (real (Suc k))) has_integral a_seg (real (Suc k)) * (v - u)) {u..v}
[PROOF STEP]
by (metis content_real_if less_eq_real_def mult.commute real_scaleR_def)
[PROOF STATE]
proof (state)
this:
((\<lambda>x. a_seg (real (Suc k))) has_integral a_seg (real (Suc k)) * (v - u)) {u..v}

goal (2 subgoals):
 1. (g1 has_integral a_seg (real (Suc k)) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) {f (a_seg (real k))..f (a_seg (real (Suc k)))}
 2. (g2 has_integral a_seg (real k) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) {f (a_seg (real k))..f (a_seg (real (Suc k)))}
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
?x \<in> {u..<v} \<Longrightarrow> g1 ?x = a_seg (real (Suc k))
((\<lambda>x. a_seg (real (Suc k))) has_integral a_seg (real (Suc k)) * (v - u)) {u..v}
[PROOF STEP]
show "(g1 has_integral (a_seg (Suc k) * (v-u))) {u..v}"
[PROOF STATE]
proof (prove)
using this:
?x \<in> {u..<v} \<Longrightarrow> g1 ?x = a_seg (real (Suc k))
((\<lambda>x. a_seg (real (Suc k))) has_integral a_seg (real (Suc k)) * (v - u)) {u..v}

goal (1 subgoal):
 1. (g1 has_integral a_seg (real (Suc k)) * (v - u)) {u..v}
[PROOF STEP]
using has_integral_spike_finite_eq [of "{v}" "{u..v}" "\<lambda>x. a_seg (Suc k)" g1]
[PROOF STATE]
proof (prove)
using this:
?x \<in> {u..<v} \<Longrightarrow> g1 ?x = a_seg (real (Suc k))
((\<lambda>x. a_seg (real (Suc k))) has_integral a_seg (real (Suc k)) * (v - u)) {u..v}
\<lbrakk>finite {v}; \<And>x. x \<in> {u..v} - {v} \<Longrightarrow> a_seg (real (Suc k)) = g1 x\<rbrakk> \<Longrightarrow> (g1 has_integral ?y) {u..v} = ((\<lambda>x. a_seg (real (Suc k))) has_integral ?y) {u..v}

goal (1 subgoal):
 1. (g1 has_integral a_seg (real (Suc k)) * (v - u)) {u..v}
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
(g1 has_integral a_seg (real (Suc k)) * (v - u)) {u..v}

goal (1 subgoal):
 1. (g2 has_integral a_seg (real k) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) {f (a_seg (real k))..f (a_seg (real (Suc k)))}
[PROOF STEP]
have g2: "g2 x = a_seg k" if "x \<in> {u<..<v}" for x
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. g2 x = a_seg (real k)
[PROOF STEP]
using that \<open>0 \<le> u\<close>
[PROOF STATE]
proof (prove)
using this:
x \<in> {u<..<v}
0 \<le> u

goal (1 subgoal):
 1. g2 x = a_seg (real k)
[PROOF STEP]
by (simp add: g2_def yidx_eq)
[PROOF STATE]
proof (state)
this:
?x \<in> {u<..<v} \<Longrightarrow> g2 ?x = a_seg (real k)

goal (1 subgoal):
 1. (g2 has_integral a_seg (real k) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) {f (a_seg (real k))..f (a_seg (real (Suc k)))}
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
?x \<in> {u<..<v} \<Longrightarrow> g2 ?x = a_seg (real k)

goal (1 subgoal):
 1. (g2 has_integral a_seg (real k) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) {f (a_seg (real k))..f (a_seg (real (Suc k)))}
[PROOF STEP]
have "((\<lambda>x. a_seg k) has_integral (a_seg k * (v-u))) {u..v}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ((\<lambda>x. a_seg (real k)) has_integral a_seg (real k) * (v - u)) {u..v}
[PROOF STEP]
using has_integral_const_real \<open>u < v\<close>
[PROOF STATE]
proof (prove)
using this:
((\<lambda>x. ?c) has_integral content {?a..?b} *\<^sub>R ?c) {?a..?b}
u < v

goal (1 subgoal):
 1. ((\<lambda>x. a_seg (real k)) has_integral a_seg (real k) * (v - u)) {u..v}
[PROOF STEP]
by (metis content_real_if less_eq_real_def mult.commute real_scaleR_def)
[PROOF STATE]
proof (state)
this:
((\<lambda>x. a_seg (real k)) has_integral a_seg (real k) * (v - u)) {u..v}

goal (1 subgoal):
 1. (g2 has_integral a_seg (real k) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) {f (a_seg (real k))..f (a_seg (real (Suc k)))}
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
?x \<in> {u<..<v} \<Longrightarrow> g2 ?x = a_seg (real k)
((\<lambda>x. a_seg (real k)) has_integral a_seg (real k) * (v - u)) {u..v}
[PROOF STEP]
show "(g2 has_integral (a_seg k * (v-u))) {u..v}"
[PROOF STATE]
proof (prove)
using this:
?x \<in> {u<..<v} \<Longrightarrow> g2 ?x = a_seg (real k)
((\<lambda>x. a_seg (real k)) has_integral a_seg (real k) * (v - u)) {u..v}

goal (1 subgoal):
 1. (g2 has_integral a_seg (real k) * (v - u)) {u..v}
[PROOF STEP]
using has_integral_spike_finite_eq [of "{u,v}" "{u..v}" "\<lambda>x. a_seg k" g2]
[PROOF STATE]
proof (prove)
using this:
?x \<in> {u<..<v} \<Longrightarrow> g2 ?x = a_seg (real k)
((\<lambda>x. a_seg (real k)) has_integral a_seg (real k) * (v - u)) {u..v}
\<lbrakk>finite {u, v}; \<And>x. x \<in> {u..v} - {u, v} \<Longrightarrow> a_seg (real k) = g2 x\<rbrakk> \<Longrightarrow> (g2 has_integral ?y) {u..v} = ((\<lambda>x. a_seg (real k)) has_integral ?y) {u..v}

goal (1 subgoal):
 1. (g2 has_integral a_seg (real k) * (v - u)) {u..v}
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
(g2 has_integral a_seg (real k) * (v - u)) {u..v}

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
?k < n \<Longrightarrow> (g1 has_integral a_seg (real (Suc ?k)) * (f (a_seg (real (Suc ?k))) - f (a_seg (real ?k)))) {f (a_seg (real ?k))..f (a_seg (real (Suc ?k)))}
?k < n \<Longrightarrow> (g2 has_integral a_seg (real ?k) * (f (a_seg (real (Suc ?k))) - f (a_seg (real ?k)))) {f (a_seg (real ?k))..f (a_seg (real (Suc ?k)))}

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have int_g1: "(g1 has_integral (\<Sum>k<n. a_seg (Suc k) * (f (a_seg (Suc k)) - f (a_seg k)))) {0..b}"
    and int_g2: "(g2 has_integral (\<Sum>k<n. a_seg k * (f (a_seg (Suc k)) - f (a_seg k)))) {0..b}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (g1 has_integral (\<Sum>k<n. a_seg (real (Suc k)) * (f (a_seg (real (Suc k))) - f (a_seg (real k))))) {0..b} &&& (g2 has_integral (\<Sum>k<n. a_seg (real k) * (f (a_seg (real (Suc k))) - f (a_seg (real k))))) {0..b}
[PROOF STEP]
unfolding zero_to_b_eq
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (g1 has_integral (\<Sum>k<n. a_seg (real (Suc k)) * (f (a_seg (real (Suc k))) - f (a_seg (real k))))) (\<Union>k<n. {f (a_seg (real k))..f (a_seg (real (Suc k)))}) &&& (g2 has_integral (\<Sum>k<n. a_seg (real k) * (f (a_seg (real (Suc k))) - f (a_seg (real k))))) (\<Union>k<n. {f (a_seg (real k))..f (a_seg (real (Suc k)))})
[PROOF STEP]
using int_g1_D int_g2_D
[PROOF STATE]
proof (prove)
using this:
?k < n \<Longrightarrow> (g1 has_integral a_seg (real (Suc ?k)) * (f (a_seg (real (Suc ?k))) - f (a_seg (real ?k)))) {f (a_seg (real ?k))..f (a_seg (real (Suc ?k)))}
?k < n \<Longrightarrow> (g2 has_integral a_seg (real ?k) * (f (a_seg (real (Suc ?k))) - f (a_seg (real ?k)))) {f (a_seg (real ?k))..f (a_seg (real (Suc ?k)))}

goal (1 subgoal):
 1. (g1 has_integral (\<Sum>k<n. a_seg (real (Suc k)) * (f (a_seg (real (Suc k))) - f (a_seg (real k))))) (\<Union>k<n. {f (a_seg (real k))..f (a_seg (real (Suc k)))}) &&& (g2 has_integral (\<Sum>k<n. a_seg (real k) * (f (a_seg (real (Suc k))) - f (a_seg (real k))))) (\<Union>k<n. {f (a_seg (real k))..f (a_seg (real (Suc k)))})
[PROOF STEP]
by (auto simp: min_def pairwise_def intro!: has_integral_UN negligible_atLeastAtMostI)
[PROOF STATE]
proof (state)
this:
(g1 has_integral (\<Sum>k<n. a_seg (real (Suc k)) * (f (a_seg (real (Suc k))) - f (a_seg (real k))))) {0..b}
(g2 has_integral (\<Sum>k<n. a_seg (real k) * (f (a_seg (real (Suc k))) - f (a_seg (real k))))) {0..b}

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have "(\<Sum>k<n. a_seg (Suc k) * (f (a_seg (Suc k)) - f (a_seg k)))
        = (\<Sum>k<n. (Suc k) * (f (a_seg (Suc k)) - f (a_seg k))) * (a/n)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>k<n. a_seg (real (Suc k)) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) = (\<Sum>k<n. real (Suc k) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) * (a / real n)
[PROOF STEP]
unfolding a_seg_def sum_distrib_right sum_divide_distrib
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>k<n. real (Suc k) * a / real n * (f (real (Suc k) * a / real n) - f (real k * a / real n))) = (\<Sum>na<n. real (Suc na) * (f (real (Suc na) * a / real n) - f (real na * a / real n)) * (a / real n))
[PROOF STEP]
by (simp add: mult_ac)
[PROOF STATE]
proof (state)
this:
(\<Sum>k<n. a_seg (real (Suc k)) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) = (\<Sum>k<n. real (Suc k) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) * (a / real n)

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>k<n. a_seg (real (Suc k)) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) = (\<Sum>k<n. real (Suc k) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) * (a / real n)

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have "\<dots> = (n * f (a_seg n) - (\<Sum>k<n. f (a_seg k))) * a / n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>k<n. real (Suc k) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) * (a / real n) = (real n * f (a_seg (real n)) - (\<Sum>k<n. f (a_seg (real k)))) * a / real n
[PROOF STEP]
using weighted_nesting_sum [where g = "f o a_seg"]
[PROOF STATE]
proof (prove)
using this:
(\<Sum>k<?n. (1 + real k) * ((f \<circ> a_seg) (real (Suc k)) - (f \<circ> a_seg) (real k))) = real ?n * (f \<circ> a_seg) (real ?n) - (\<Sum>i<?n. (f \<circ> a_seg) (real i))

goal (1 subgoal):
 1. (\<Sum>k<n. real (Suc k) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) * (a / real n) = (real n * f (a_seg (real n)) - (\<Sum>k<n. f (a_seg (real k)))) * a / real n
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
(\<Sum>k<n. real (Suc k) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) * (a / real n) = (real n * f (a_seg (real n)) - (\<Sum>k<n. f (a_seg (real k)))) * a / real n

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>k<n. real (Suc k) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) * (a / real n) = (real n * f (a_seg (real n)) - (\<Sum>k<n. f (a_seg (real k)))) * a / real n

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have "\<dots> = a * b - (\<Sum>k<n. f (a_seg k)) * a / n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (real n * f (a_seg (real n)) - (\<Sum>k<n. f (a_seg (real k)))) * a / real n = a * b - (\<Sum>k<n. f (a_seg (real k))) * a / real n
[PROOF STEP]
using \<open>n > 0\<close>
[PROOF STATE]
proof (prove)
using this:
0 < n

goal (1 subgoal):
 1. (real n * f (a_seg (real n)) - (\<Sum>k<n. f (a_seg (real k)))) * a / real n = a * b - (\<Sum>k<n. f (a_seg (real k))) * a / real n
[PROOF STEP]
by (simp add: fa_eq_b field_simps)
[PROOF STATE]
proof (state)
this:
(real n * f (a_seg (real n)) - (\<Sum>k<n. f (a_seg (real k)))) * a / real n = a * b - (\<Sum>k<n. f (a_seg (real k))) * a / real n

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
(\<Sum>k<n. a_seg (real (Suc k)) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) = a * b - (\<Sum>k<n. f (a_seg (real k))) * a / real n
[PROOF STEP]
have int_g1': "(g1 has_integral a * b - (\<Sum>k<n. f (a_seg k)) * a / n) {0..b}"
[PROOF STATE]
proof (prove)
using this:
(\<Sum>k<n. a_seg (real (Suc k)) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) = a * b - (\<Sum>k<n. f (a_seg (real k))) * a / real n

goal (1 subgoal):
 1. (g1 has_integral a * b - (\<Sum>k<n. f (a_seg (real k))) * a / real n) {0..b}
[PROOF STEP]
using int_g1
[PROOF STATE]
proof (prove)
using this:
(\<Sum>k<n. a_seg (real (Suc k)) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) = a * b - (\<Sum>k<n. f (a_seg (real k))) * a / real n
(g1 has_integral (\<Sum>k<n. a_seg (real (Suc k)) * (f (a_seg (real (Suc k))) - f (a_seg (real k))))) {0..b}

goal (1 subgoal):
 1. (g1 has_integral a * b - (\<Sum>k<n. f (a_seg (real k))) * a / real n) {0..b}
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
(g1 has_integral a * b - (\<Sum>k<n. f (a_seg (real k))) * a / real n) {0..b}

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
text \<open>The claim @{term "(g2 has_integral a * b - (\<Sum>k<n. f (a_seg (Suc k))) * a / n) {0..b}"} can similarly be proved.\<close>
[PROOF STATE]
proof (state)
this:
(g1 has_integral a * b - (\<Sum>k<n. f (a_seg (real k))) * a / real n) {0..b}

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have a_seg_diff: "a_seg (Suc k) - a_seg k = a/n" for k
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. a_seg (real (Suc k)) - a_seg (real k) = a / real n
[PROOF STEP]
by (simp add: a_seg_def field_split_simps)
[PROOF STATE]
proof (state)
this:
a_seg (real (Suc ?k)) - a_seg (real ?k) = a / real n

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have f_a_seg_diff: "\<bar>f (a_seg (Suc k)) - f (a_seg k)\<bar> < \<epsilon>/a" if "k<n" for k
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<bar>f (a_seg (real (Suc k))) - f (a_seg (real k))\<bar> < \<epsilon> / a
[PROOF STEP]
using that \<open>a > 0\<close> a_seg_diff an_less_del \<open>\<epsilon> > 0\<close>
[PROOF STATE]
proof (prove)
using this:
k < n
0 < a
a_seg (real (Suc ?k)) - a_seg (real ?k) = a / real n
a / real n < del (\<epsilon> / a)
0 < \<epsilon>

goal (1 subgoal):
 1. \<bar>f (a_seg (real (Suc k))) - f (a_seg (real k))\<bar> < \<epsilon> / a
[PROOF STEP]
by (intro del) auto
[PROOF STATE]
proof (state)
this:
?k < n \<Longrightarrow> \<bar>f (a_seg (real (Suc ?k))) - f (a_seg (real ?k))\<bar> < \<epsilon> / a

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have "((\<lambda>x. g1 x - g2 x) has_integral (\<Sum>k<n. (f (a_seg (Suc k)) - f (a_seg k)) * (a/n))) {0..b}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ((\<lambda>x. g1 x - g2 x) has_integral (\<Sum>k<n. (f (a_seg (real (Suc k))) - f (a_seg (real k))) * (a / real n))) {0..b}
[PROOF STEP]
using has_integral_diff [OF int_g1 int_g2] a_seg_diff
[PROOF STATE]
proof (prove)
using this:
((\<lambda>x. g1 x - g2 x) has_integral (\<Sum>k<n. a_seg (real (Suc k)) * (f (a_seg (real (Suc k))) - f (a_seg (real k)))) - (\<Sum>k<n. a_seg (real k) * (f (a_seg (real (Suc k))) - f (a_seg (real k))))) {0..b}
a_seg (real (Suc ?k)) - a_seg (real ?k) = a / real n

goal (1 subgoal):
 1. ((\<lambda>x. g1 x - g2 x) has_integral (\<Sum>k<n. (f (a_seg (real (Suc k))) - f (a_seg (real k))) * (a / real n))) {0..b}
[PROOF STEP]
apply (simp flip: sum_subtractf left_diff_distrib)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>((\<lambda>x. g1 x - g2 x) has_integral (\<Sum>k<n. a * (f (a_seg (1 + real k)) - f (a_seg (real k))) / real n)) {0..b}; \<And>k. a_seg (1 + real k) - a_seg (real k) = a / real n\<rbrakk> \<Longrightarrow> ((\<lambda>x. g1 x - g2 x) has_integral (\<Sum>k<n. (f (a_seg (1 + real k)) - f (a_seg (real k))) * a / real n)) {0..b}
[PROOF STEP]
apply (simp add: field_simps)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done
[PROOF STATE]
proof (state)
this:
((\<lambda>x. g1 x - g2 x) has_integral (\<Sum>k<n. (f (a_seg (real (Suc k))) - f (a_seg (real k))) * (a / real n))) {0..b}

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
((\<lambda>x. g1 x - g2 x) has_integral (\<Sum>k<n. (f (a_seg (real (Suc k))) - f (a_seg (real k))) * (a / real n))) {0..b}

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have "(\<Sum>k<n. (f (a_seg (Suc k)) - f (a_seg k)) * (a/n)) < \<epsilon>"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>k<n. (f (a_seg (real (Suc k))) - f (a_seg (real k))) * (a / real n)) < \<epsilon>
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. (\<Sum>k<n. (f (a_seg (real (Suc k))) - f (a_seg (real k))) * (a / real n)) < \<epsilon>
[PROOF STEP]
have "(\<Sum>k<n. (f (a_seg (Suc k)) - f (a_seg k)) * (a/n))
         \<le> (\<Sum>k<n. \<bar>f (a_seg (Suc k)) - f (a_seg k)\<bar> * (a/n))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>k<n. (f (a_seg (real (Suc k))) - f (a_seg (real k))) * (a / real n)) \<le> (\<Sum>k<n. \<bar>f (a_seg (real (Suc k))) - f (a_seg (real k))\<bar> * (a / real n))
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
(\<Sum>k<n. (f (a_seg (real (Suc k))) - f (a_seg (real k))) * (a / real n)) \<le> (\<Sum>k<n. \<bar>f (a_seg (real (Suc k))) - f (a_seg (real k))\<bar> * (a / real n))

goal (1 subgoal):
 1. (\<Sum>k<n. (f (a_seg (real (Suc k))) - f (a_seg (real k))) * (a / real n)) < \<epsilon>
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>k<n. (f (a_seg (real (Suc k))) - f (a_seg (real k))) * (a / real n)) \<le> (\<Sum>k<n. \<bar>f (a_seg (real (Suc k))) - f (a_seg (real k))\<bar> * (a / real n))

goal (1 subgoal):
 1. (\<Sum>k<n. (f (a_seg (real (Suc k))) - f (a_seg (real k))) * (a / real n)) < \<epsilon>
[PROOF STEP]
have "\<dots> < (\<Sum>k<n. (\<epsilon>/a) * (a/n))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>k<n. \<bar>f (a_seg (real (Suc k))) - f (a_seg (real k))\<bar> * (a / real n)) < (\<Sum>k<n. \<epsilon> / a * (a / real n))
[PROOF STEP]
proof (rule sum_strict_mono)
[PROOF STATE]
proof (state)
goal (3 subgoals):
 1. finite {..<n}
 2. {..<n} \<noteq> {}
 3. \<And>x. x \<in> {..<n} \<Longrightarrow> \<bar>f (a_seg (real (Suc x))) - f (a_seg (real x))\<bar> * (a / real n) < \<epsilon> / a * (a / real n)
[PROOF STEP]
fix k
[PROOF STATE]
proof (state)
goal (3 subgoals):
 1. finite {..<n}
 2. {..<n} \<noteq> {}
 3. \<And>x. x \<in> {..<n} \<Longrightarrow> \<bar>f (a_seg (real (Suc x))) - f (a_seg (real x))\<bar> * (a / real n) < \<epsilon> / a * (a / real n)
[PROOF STEP]
assume "k \<in> {..<n}"
[PROOF STATE]
proof (state)
this:
k \<in> {..<n}

goal (3 subgoals):
 1. finite {..<n}
 2. {..<n} \<noteq> {}
 3. \<And>x. x \<in> {..<n} \<Longrightarrow> \<bar>f (a_seg (real (Suc x))) - f (a_seg (real x))\<bar> * (a / real n) < \<epsilon> / a * (a / real n)
[PROOF STEP]
with \<open>n > 0\<close> \<open>a > 0\<close> divide_strict_right_mono f_a_seg_diff pos_less_divide_eq
[PROOF STATE]
proof (chain)
picking this:
0 < n
0 < a
\<lbrakk>?a < ?b; (0::?'a) < ?c\<rbrakk> \<Longrightarrow> ?a / ?c < ?b / ?c
?k < n \<Longrightarrow> \<bar>f (a_seg (real (Suc ?k))) - f (a_seg (real ?k))\<bar> < \<epsilon> / a
(0::?'a) < ?c \<Longrightarrow> (?a < ?b / ?c) = (?a * ?c < ?b)
k \<in> {..<n}
[PROOF STEP]
show "\<bar>f (a_seg (Suc k)) - f (a_seg k)\<bar> * (a/n) < \<epsilon>/a * (a/n)"
[PROOF STATE]
proof (prove)
using this:
0 < n
0 < a
\<lbrakk>?a < ?b; (0::?'a) < ?c\<rbrakk> \<Longrightarrow> ?a / ?c < ?b / ?c
?k < n \<Longrightarrow> \<bar>f (a_seg (real (Suc ?k))) - f (a_seg (real ?k))\<bar> < \<epsilon> / a
(0::?'a) < ?c \<Longrightarrow> (?a < ?b / ?c) = (?a * ?c < ?b)
k \<in> {..<n}

goal (1 subgoal):
 1. \<bar>f (a_seg (real (Suc k))) - f (a_seg (real k))\<bar> * (a / real n) < \<epsilon> / a * (a / real n)
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
\<bar>f (a_seg (real (Suc k))) - f (a_seg (real k))\<bar> * (a / real n) < \<epsilon> / a * (a / real n)

goal (2 subgoals):
 1. finite {..<n}
 2. {..<n} \<noteq> {}
[PROOF STEP]
qed (use \<open>n > 0\<close> in auto)
[PROOF STATE]
proof (state)
this:
(\<Sum>k<n. \<bar>f (a_seg (real (Suc k))) - f (a_seg (real k))\<bar> * (a / real n)) < (\<Sum>k<n. \<epsilon> / a * (a / real n))

goal (1 subgoal):
 1. (\<Sum>k<n. (f (a_seg (real (Suc k))) - f (a_seg (real k))) * (a / real n)) < \<epsilon>
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>k<n. \<bar>f (a_seg (real (Suc k))) - f (a_seg (real k))\<bar> * (a / real n)) < (\<Sum>k<n. \<epsilon> / a * (a / real n))

goal (1 subgoal):
 1. (\<Sum>k<n. (f (a_seg (real (Suc k))) - f (a_seg (real k))) * (a / real n)) < \<epsilon>
[PROOF STEP]
have "\<dots> = \<epsilon>"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>k<n. \<epsilon> / a * (a / real n)) = \<epsilon>
[PROOF STEP]
using \<open>n > 0\<close> \<open>a > 0\<close>
[PROOF STATE]
proof (prove)
using this:
0 < n
0 < a

goal (1 subgoal):
 1. (\<Sum>k<n. \<epsilon> / a * (a / real n)) = \<epsilon>
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
(\<Sum>k<n. \<epsilon> / a * (a / real n)) = \<epsilon>

goal (1 subgoal):
 1. (\<Sum>k<n. (f (a_seg (real (Suc k))) - f (a_seg (real k))) * (a / real n)) < \<epsilon>
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
(\<Sum>k<n. (f (a_seg (real (Suc k))) - f (a_seg (real k))) * (a / real n)) < \<epsilon>
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
(\<Sum>k<n. (f (a_seg (real (Suc k))) - f (a_seg (real k))) * (a / real n)) < \<epsilon>

goal (1 subgoal):
 1. (\<Sum>k<n. (f (a_seg (real (Suc k))) - f (a_seg (real k))) * (a / real n)) < \<epsilon>
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
(\<Sum>k<n. (f (a_seg (real (Suc k))) - f (a_seg (real k))) * (a / real n)) < \<epsilon>

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
(\<Sum>k<n. (f (a_seg (real (Suc k))) - f (a_seg (real k))) * (a / real n)) < \<epsilon>

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
((\<lambda>x. g1 x - g2 x) has_integral (\<Sum>k<n. (f (a_seg (real (Suc k))) - f (a_seg (real k))) * (a / real n))) {0..b}
(\<Sum>k<n. (f (a_seg (real (Suc k))) - f (a_seg (real k))) * (a / real n)) < \<epsilon>
[PROOF STEP]
have g2_near_g1: "integral {0..b} (\<lambda>x. g1 x - g2 x) < \<epsilon>"
[PROOF STATE]
proof (prove)
using this:
((\<lambda>x. g1 x - g2 x) has_integral (\<Sum>k<n. (f (a_seg (real (Suc k))) - f (a_seg (real k))) * (a / real n))) {0..b}
(\<Sum>k<n. (f (a_seg (real (Suc k))) - f (a_seg (real k))) * (a / real n)) < \<epsilon>

goal (1 subgoal):
 1. integral {0..b} (\<lambda>x. g1 x - g2 x) < \<epsilon>
[PROOF STEP]
by (simp add: integral_unique)
[PROOF STATE]
proof (state)
this:
integral {0..b} (\<lambda>x. g1 x - g2 x) < \<epsilon>

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have ab1: "integral {0..a} f1 + integral {0..b} g1 = a*b"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. integral {0..a} f1 + integral {0..b} g1 = a * b
[PROOF STEP]
using int_f1 int_g1'
[PROOF STATE]
proof (prove)
using this:
(f1 has_integral (\<Sum>k<n. f (a_seg (real k))) * (a / real n)) {0..a}
(g1 has_integral a * b - (\<Sum>k<n. f (a_seg (real k))) * a / real n) {0..b}

goal (1 subgoal):
 1. integral {0..a} f1 + integral {0..b} g1 = a * b
[PROOF STEP]
by (simp add: integral_unique)
[PROOF STATE]
proof (state)
this:
integral {0..a} f1 + integral {0..b} g1 = a * b

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have "integral {0..a} (\<lambda>x. f x - f1 x) \<le> integral {0..a} (\<lambda>x. f2 x - f1 x)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. integral {0..a} (\<lambda>x. f x - f1 x) \<le> integral {0..a} (\<lambda>x. f2 x - f1 x)
[PROOF STEP]
proof (rule integral_le)
[PROOF STATE]
proof (state)
goal (3 subgoals):
 1. (\<lambda>x. f x - f1 x) integrable_on {0..a}
 2. (\<lambda>x. f2 x - f1 x) integrable_on {0..a}
 3. \<And>x. x \<in> {0..a} \<Longrightarrow> f x - f1 x \<le> f2 x - f1 x
[PROOF STEP]
show "(\<lambda>x. f x - f1 x) integrable_on {0..a}" "(\<lambda>x. f2 x - f1 x) integrable_on {0..a}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lambda>x. f x - f1 x) integrable_on {0..a} &&& (\<lambda>x. f2 x - f1 x) integrable_on {0..a}
[PROOF STEP]
using Henstock_Kurzweil_Integration.integrable_diff int_f1 intgb_f f12
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>?f integrable_on ?S; ?g integrable_on ?S\<rbrakk> \<Longrightarrow> (\<lambda>x. ?f x - ?g x) integrable_on ?S
(f1 has_integral (\<Sum>k<n. f (a_seg (real k))) * (a / real n)) {0..a}
f integrable_on {0..a}
((\<lambda>x. f2 x - f1 x) has_integral (\<Sum>K\<in>regular_division 0 a n. (f (Sup K) - f (Inf K)) * (a / real n))) {0..a}

goal (1 subgoal):
 1. (\<lambda>x. f x - f1 x) integrable_on {0..a} &&& (\<lambda>x. f2 x - f1 x) integrable_on {0..a}
[PROOF STEP]
by blast+
[PROOF STATE]
proof (state)
this:
(\<lambda>x. f x - f1 x) integrable_on {0..a}
(\<lambda>x. f2 x - f1 x) integrable_on {0..a}

goal (1 subgoal):
 1. \<And>x. x \<in> {0..a} \<Longrightarrow> f x - f1 x \<le> f2 x - f1 x
[PROOF STEP]
qed (auto simp: f2_upper)
[PROOF STATE]
proof (state)
this:
integral {0..a} (\<lambda>x. f x - f1 x) \<le> integral {0..a} (\<lambda>x. f2 x - f1 x)

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
with f2_near_f1
[PROOF STATE]
proof (chain)
picking this:
integral {0..a} (\<lambda>x. f2 x - f1 x) < \<epsilon>
integral {0..a} (\<lambda>x. f x - f1 x) \<le> integral {0..a} (\<lambda>x. f2 x - f1 x)
[PROOF STEP]
have "integral {0..a} (\<lambda>x. f x - f1 x) < \<epsilon>"
[PROOF STATE]
proof (prove)
using this:
integral {0..a} (\<lambda>x. f2 x - f1 x) < \<epsilon>
integral {0..a} (\<lambda>x. f x - f1 x) \<le> integral {0..a} (\<lambda>x. f2 x - f1 x)

goal (1 subgoal):
 1. integral {0..a} (\<lambda>x. f x - f1 x) < \<epsilon>
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
integral {0..a} (\<lambda>x. f x - f1 x) < \<epsilon>

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
integral {0..a} (\<lambda>x. f x - f1 x) < \<epsilon>

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have "integral {0..a} f1 \<le> integral {0..a} f"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. integral {0..a} f1 \<le> integral {0..a} f
[PROOF STEP]
by (intro integral_le has_integral_integral intgb_f has_integral_integrable [OF int_f1])
         (simp add: f1_lower)
[PROOF STATE]
proof (state)
this:
integral {0..a} f1 \<le> integral {0..a} f

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
integral {0..a} (\<lambda>x. f x - f1 x) < \<epsilon>
integral {0..a} f1 \<le> integral {0..a} f
[PROOF STEP]
have f_error: "\<bar>integral {0..a} f - integral {0..a} f1\<bar> < \<epsilon>"
[PROOF STATE]
proof (prove)
using this:
integral {0..a} (\<lambda>x. f x - f1 x) < \<epsilon>
integral {0..a} f1 \<le> integral {0..a} f

goal (1 subgoal):
 1. \<bar>integral {0..a} f - integral {0..a} f1\<bar> < \<epsilon>
[PROOF STEP]
using Henstock_Kurzweil_Integration.integral_diff int_f1 intgb_f
[PROOF STATE]
proof (prove)
using this:
integral {0..a} (\<lambda>x. f x - f1 x) < \<epsilon>
integral {0..a} f1 \<le> integral {0..a} f
\<lbrakk>?f integrable_on ?S; ?g integrable_on ?S\<rbrakk> \<Longrightarrow> integral ?S (\<lambda>x. ?f x - ?g x) = integral ?S ?f - integral ?S ?g
(f1 has_integral (\<Sum>k<n. f (a_seg (real k))) * (a / real n)) {0..a}
f integrable_on {0..a}

goal (1 subgoal):
 1. \<bar>integral {0..a} f - integral {0..a} f1\<bar> < \<epsilon>
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
\<bar>integral {0..a} f - integral {0..a} f1\<bar> < \<epsilon>

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have "integral {0..b} (\<lambda>x. g1 x - g x) \<le> integral {0..b} (\<lambda>x. g1 x - g2 x)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. integral {0..b} (\<lambda>x. g1 x - g x) \<le> integral {0..b} (\<lambda>x. g1 x - g2 x)
[PROOF STEP]
proof (rule integral_le)
[PROOF STATE]
proof (state)
goal (3 subgoals):
 1. (\<lambda>x. g1 x - g x) integrable_on {0..b}
 2. (\<lambda>x. g1 x - g2 x) integrable_on {0..b}
 3. \<And>x. x \<in> {0..b} \<Longrightarrow> g1 x - g x \<le> g1 x - g2 x
[PROOF STEP]
show "(\<lambda>x. g1 x - g x) integrable_on {0..b}" "(\<lambda>x. g1 x - g2 x) integrable_on {0..b}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<lambda>x. g1 x - g x) integrable_on {0..b} &&& (\<lambda>x. g1 x - g2 x) integrable_on {0..b}
[PROOF STEP]
using Henstock_Kurzweil_Integration.integrable_diff int_g1 int_g2 intgb_g
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>?f integrable_on ?S; ?g integrable_on ?S\<rbrakk> \<Longrightarrow> (\<lambda>x. ?f x - ?g x) integrable_on ?S
(g1 has_integral (\<Sum>k<n. a_seg (real (Suc k)) * (f (a_seg (real (Suc k))) - f (a_seg (real k))))) {0..b}
(g2 has_integral (\<Sum>k<n. a_seg (real k) * (f (a_seg (real (Suc k))) - f (a_seg (real k))))) {0..b}
g integrable_on {0..b}

goal (1 subgoal):
 1. (\<lambda>x. g1 x - g x) integrable_on {0..b} &&& (\<lambda>x. g1 x - g2 x) integrable_on {0..b}
[PROOF STEP]
by blast+
[PROOF STATE]
proof (state)
this:
(\<lambda>x. g1 x - g x) integrable_on {0..b}
(\<lambda>x. g1 x - g2 x) integrable_on {0..b}

goal (1 subgoal):
 1. \<And>x. x \<in> {0..b} \<Longrightarrow> g1 x - g x \<le> g1 x - g2 x
[PROOF STEP]
qed (auto simp: g2_le_g)
[PROOF STATE]
proof (state)
this:
integral {0..b} (\<lambda>x. g1 x - g x) \<le> integral {0..b} (\<lambda>x. g1 x - g2 x)

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
with g2_near_g1
[PROOF STATE]
proof (chain)
picking this:
integral {0..b} (\<lambda>x. g1 x - g2 x) < \<epsilon>
integral {0..b} (\<lambda>x. g1 x - g x) \<le> integral {0..b} (\<lambda>x. g1 x - g2 x)
[PROOF STEP]
have "integral {0..b} (\<lambda>x. g1 x - g x) < \<epsilon>"
[PROOF STATE]
proof (prove)
using this:
integral {0..b} (\<lambda>x. g1 x - g2 x) < \<epsilon>
integral {0..b} (\<lambda>x. g1 x - g x) \<le> integral {0..b} (\<lambda>x. g1 x - g2 x)

goal (1 subgoal):
 1. integral {0..b} (\<lambda>x. g1 x - g x) < \<epsilon>
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
integral {0..b} (\<lambda>x. g1 x - g x) < \<epsilon>

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
moreover
[PROOF STATE]
proof (state)
this:
integral {0..b} (\<lambda>x. g1 x - g x) < \<epsilon>

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
have "integral {0..b} g \<le> integral {0..b} g1"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. integral {0..b} g \<le> integral {0..b} g1
[PROOF STEP]
by (intro integral_le has_integral_integral intgb_g has_integral_integrable [OF int_g1])
         (simp add: g_le_g1)
[PROOF STATE]
proof (state)
this:
integral {0..b} g \<le> integral {0..b} g1

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
ultimately
[PROOF STATE]
proof (chain)
picking this:
integral {0..b} (\<lambda>x. g1 x - g x) < \<epsilon>
integral {0..b} g \<le> integral {0..b} g1
[PROOF STEP]
have g_error: "\<bar>integral {0..b} g1 - integral {0..b} g\<bar> < \<epsilon>"
[PROOF STATE]
proof (prove)
using this:
integral {0..b} (\<lambda>x. g1 x - g x) < \<epsilon>
integral {0..b} g \<le> integral {0..b} g1

goal (1 subgoal):
 1. \<bar>integral {0..b} g1 - integral {0..b} g\<bar> < \<epsilon>
[PROOF STEP]
using integral_diff int_g1 intgb_g
[PROOF STATE]
proof (prove)
using this:
integral {0..b} (\<lambda>x. g1 x - g x) < \<epsilon>
integral {0..b} g \<le> integral {0..b} g1
\<lbrakk>?f integrable_on ?S; ?g integrable_on ?S\<rbrakk> \<Longrightarrow> integral ?S (\<lambda>x. ?f x - ?g x) = integral ?S ?f - integral ?S ?g
(g1 has_integral (\<Sum>k<n. a_seg (real (Suc k)) * (f (a_seg (real (Suc k))) - f (a_seg (real k))))) {0..b}
g integrable_on {0..b}

goal (1 subgoal):
 1. \<bar>integral {0..b} g1 - integral {0..b} g\<bar> < \<epsilon>
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
\<bar>integral {0..b} g1 - integral {0..b} g\<bar> < \<epsilon>

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
using f_error g_error ab1
[PROOF STATE]
proof (prove)
using this:
\<bar>integral {0..a} f - integral {0..a} f1\<bar> < \<epsilon>
\<bar>integral {0..b} g1 - integral {0..b} g\<bar> < \<epsilon>
integral {0..a} f1 + integral {0..b} g1 = a * b

goal (1 subgoal):
 1. \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>
[PROOF STEP]
by linarith
[PROOF STATE]
proof (state)
this:
\<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * \<epsilon>

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
0 < ?\<epsilon> \<Longrightarrow> \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * ?\<epsilon>

goal (2 subgoals):
 1. a = 0 \<Longrightarrow> a * b = integral {0..a} f + integral {0..b} g
 2. a \<noteq> 0 \<Longrightarrow> a * b = integral {0..a} f + integral {0..b} g
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. a * b = integral {0..a} f + integral {0..b} g
[PROOF STEP]
using * [of "\<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> / 2"]
[PROOF STATE]
proof (prove)
using this:
0 < \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> / 2 \<Longrightarrow> \<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> < 2 * (\<bar>a * b - integral {0..a} f - integral {0..b} g\<bar> / 2)

goal (1 subgoal):
 1. a * b = integral {0..a} f + integral {0..b} g
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
a * b = integral {0..a} f + integral {0..b} g

goal (1 subgoal):
 1. a = 0 \<Longrightarrow> a * b = integral {0..a} f + integral {0..b} g
[PROOF STEP]
qed (use assms in force)