[STATEMENT]
theorem triangle_removal_lemma:
  fixes \<epsilon> :: real
  assumes egt: "\<epsilon> > 0"
  shows "\<exists>\<delta>::real > 0. \<forall>G. card(uverts G) > 0 \<longrightarrow> uwellformed G \<longrightarrow>
          card (triangle_set G) \<le> \<delta> * card(uverts G) ^ 3 \<longrightarrow>
          (\<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and>
          card (uedges G - uedges G') \<le> \<epsilon> * (card (uverts G))\<^sup>2)"
    (is "\<exists>\<delta>::real > 0. \<forall>G. _ \<longrightarrow> _ \<longrightarrow> _ \<longrightarrow> (\<exists>Gnew. ?\<Phi> G Gnew)")
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<exists>\<delta>>0. \<forall>G. 0 < card (uverts G) \<longrightarrow> uwellformed G \<longrightarrow> real (card (triangle_set G)) \<le> \<delta> * real (card (uverts G) ^ 3) \<longrightarrow> (\<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2))
[PROOF STEP]
proof (cases "\<epsilon> < 1")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. \<epsilon> < 1 \<Longrightarrow> \<exists>\<delta>>0. \<forall>G. 0 < card (uverts G) \<longrightarrow> uwellformed G \<longrightarrow> real (card (triangle_set G)) \<le> \<delta> * real (card (uverts G) ^ 3) \<longrightarrow> (\<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2))
 2. \<not> \<epsilon> < 1 \<Longrightarrow> \<exists>\<delta>>0. \<forall>G. 0 < card (uverts G) \<longrightarrow> uwellformed G \<longrightarrow> real (card (triangle_set G)) \<le> \<delta> * real (card (uverts G) ^ 3) \<longrightarrow> (\<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2))
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
\<not> \<epsilon> < 1

goal (2 subgoals):
 1. \<epsilon> < 1 \<Longrightarrow> \<exists>\<delta>>0. \<forall>G. 0 < card (uverts G) \<longrightarrow> uwellformed G \<longrightarrow> real (card (triangle_set G)) \<le> \<delta> * real (card (uverts G) ^ 3) \<longrightarrow> (\<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2))
 2. \<not> \<epsilon> < 1 \<Longrightarrow> \<exists>\<delta>>0. \<forall>G. 0 < card (uverts G) \<longrightarrow> uwellformed G \<longrightarrow> real (card (triangle_set G)) \<le> \<delta> * real (card (uverts G) ^ 3) \<longrightarrow> (\<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2))
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<exists>\<delta>>0. \<forall>G. 0 < card (uverts G) \<longrightarrow> uwellformed G \<longrightarrow> real (card (triangle_set G)) \<le> \<delta> * real (card (uverts G) ^ 3) \<longrightarrow> (\<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2))
[PROOF STEP]
proof (intro exI conjI strip)
[PROOF STATE]
proof (state)
goal (5 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> triangle_free_graph (?G'6 G)
 3. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> uverts (?G'6 G) = uverts G
 4. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> uedges (?G'6 G) \<subseteq> uedges G
 5. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> real (card (uedges G - uedges (?G'6 G))) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
fix G
[PROOF STATE]
proof (state)
goal (5 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> triangle_free_graph (?G'6 G)
 3. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> uverts (?G'6 G) = uverts G
 4. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> uedges (?G'6 G) \<subseteq> uedges G
 5. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> real (card (uedges G - uedges (?G'6 G))) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
define Gnew where "Gnew \<equiv> ((uverts G), {}::uedge set)"
[PROOF STATE]
proof (state)
this:
Gnew \<equiv> (uverts G, {})

goal (5 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> triangle_free_graph (?G'6 G)
 3. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> uverts (?G'6 G) = uverts G
 4. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> uedges (?G'6 G) \<subseteq> uedges G
 5. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> real (card (uedges G - uedges (?G'6 G))) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
assume G: "uwellformed G" "card(uverts G) > 0"
[PROOF STATE]
proof (state)
this:
uwellformed G
0 < card (uverts G)

goal (5 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> triangle_free_graph (?G'6 G)
 3. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> uverts (?G'6 G) = uverts G
 4. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> uedges (?G'6 G) \<subseteq> uedges G
 5. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> real (card (uedges G - uedges (?G'6 G))) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
uwellformed G
0 < card (uverts G)
[PROOF STEP]
show "triangle_free_graph Gnew" "uverts Gnew = uverts G" "uedges Gnew \<subseteq> uedges G"
[PROOF STATE]
proof (prove)
using this:
uwellformed G
0 < card (uverts G)

goal (1 subgoal):
 1. triangle_free_graph Gnew &&& uverts Gnew = uverts G &&& uedges Gnew \<subseteq> uedges G
[PROOF STEP]
by (auto simp: Gnew_def triangle_free_graph_empty)
[PROOF STATE]
proof (state)
this:
triangle_free_graph Gnew
uverts Gnew = uverts G
uedges Gnew \<subseteq> uedges G

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> real (card (uedges G - uedges (uverts G, {}))) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have "real (card (uedges G)) \<le> (card (uverts G))\<^sup>2"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. real (card (uedges G)) \<le> real ((card (uverts G))\<^sup>2)
[PROOF STEP]
by (meson G card_gt_0_iff max_edges_graph of_nat_le_iff)
[PROOF STATE]
proof (state)
this:
real (card (uedges G)) \<le> real ((card (uverts G))\<^sup>2)

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> real (card (uedges G - uedges (uverts G, {}))) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
real (card (uedges G)) \<le> real ((card (uverts G))\<^sup>2)

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> real (card (uedges G - uedges (uverts G, {}))) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have "\<dots> \<le> \<epsilon> * (card (uverts G))\<^sup>2"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. real ((card (uverts G))\<^sup>2) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
using False mult_le_cancel_right1
[PROOF STATE]
proof (prove)
using this:
\<not> \<epsilon> < 1
(?c \<le> ?b * ?c) = (((0::?'a) < ?c \<longrightarrow> (1::?'a) \<le> ?b) \<and> (?c < (0::?'a) \<longrightarrow> ?b \<le> (1::?'a)))

goal (1 subgoal):
 1. real ((card (uverts G))\<^sup>2) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
real ((card (uverts G))\<^sup>2) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> real (card (uedges G - uedges (uverts G, {}))) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
real (card (uedges G)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
show "real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * ((card (uverts G))\<^sup>2)"
[PROOF STATE]
proof (prove)
using this:
real (card (uedges G)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)

goal (1 subgoal):
 1. real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
by (simp add: Gnew_def)
[PROOF STATE]
proof (state)
this:
real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)

goal (1 subgoal):
 1. 0 < ?\<delta>
[PROOF STEP]
qed (rule zero_less_one)
[PROOF STATE]
proof (state)
this:
\<exists>\<delta>>0. \<forall>G. 0 < card (uverts G) \<longrightarrow> uwellformed G \<longrightarrow> real (card (triangle_set G)) \<le> \<delta> * real (card (uverts G) ^ 3) \<longrightarrow> (\<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2))

goal (1 subgoal):
 1. \<epsilon> < 1 \<Longrightarrow> \<exists>\<delta>>0. \<forall>G. 0 < card (uverts G) \<longrightarrow> uwellformed G \<longrightarrow> real (card (triangle_set G)) \<le> \<delta> * real (card (uverts G) ^ 3) \<longrightarrow> (\<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2))
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<epsilon> < 1 \<Longrightarrow> \<exists>\<delta>>0. \<forall>G. 0 < card (uverts G) \<longrightarrow> uwellformed G \<longrightarrow> real (card (triangle_set G)) \<le> \<delta> * real (card (uverts G) ^ 3) \<longrightarrow> (\<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2))
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
\<epsilon> < 1

goal (1 subgoal):
 1. \<epsilon> < 1 \<Longrightarrow> \<exists>\<delta>>0. \<forall>G. 0 < card (uverts G) \<longrightarrow> uwellformed G \<longrightarrow> real (card (triangle_set G)) \<le> \<delta> * real (card (uverts G) ^ 3) \<longrightarrow> (\<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2))
[PROOF STEP]
have e4gt: "\<epsilon>/4 > 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 < \<epsilon> / 4
[PROOF STEP]
using \<open>\<epsilon> > 0\<close>
[PROOF STATE]
proof (prove)
using this:
0 < \<epsilon>

goal (1 subgoal):
 1. 0 < \<epsilon> / 4
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
0 < \<epsilon> / 4

goal (1 subgoal):
 1. \<epsilon> < 1 \<Longrightarrow> \<exists>\<delta>>0. \<forall>G. 0 < card (uverts G) \<longrightarrow> uwellformed G \<longrightarrow> real (card (triangle_set G)) \<le> \<delta> * real (card (uverts G) ^ 3) \<longrightarrow> (\<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2))
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
0 < \<epsilon> / 4
[PROOF STEP]
obtain M0 where
    M0: "\<And>G. card (uverts G) > 0 \<Longrightarrow> \<exists>P. regular_partition (\<epsilon>/4) G P \<and> card P \<le> M0"
    and "M0>0"
[PROOF STATE]
proof (prove)
using this:
0 < \<epsilon> / 4

goal (1 subgoal):
 1. (\<And>M0. \<lbrakk>\<And>G. 0 < card (uverts G) \<Longrightarrow> \<exists>P. regular_partition (\<epsilon> / 4) G P \<and> card P \<le> M0; 0 < M0\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by (metis Szemeredi_Regularity_Lemma le0 neq0_conv not_le not_numeral_le_zero)
[PROOF STATE]
proof (state)
this:
0 < card (uverts ?G) \<Longrightarrow> \<exists>P. regular_partition (\<epsilon> / 4) ?G P \<and> card P \<le> M0
0 < M0

goal (1 subgoal):
 1. \<epsilon> < 1 \<Longrightarrow> \<exists>\<delta>>0. \<forall>G. 0 < card (uverts G) \<longrightarrow> uwellformed G \<longrightarrow> real (card (triangle_set G)) \<le> \<delta> * real (card (uverts G) ^ 3) \<longrightarrow> (\<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2))
[PROOF STEP]
define D0 where "D0 \<equiv> 1/6 *(1-(\<epsilon>/2))*((\<epsilon>/4)^3)*((\<epsilon> /(4*M0))^3)"
[PROOF STATE]
proof (state)
this:
D0 \<equiv> 1 / 6 * (1 - \<epsilon> / 2) * (\<epsilon> / 4) ^ 3 * (\<epsilon> / real (4 * M0)) ^ 3

goal (1 subgoal):
 1. \<epsilon> < 1 \<Longrightarrow> \<exists>\<delta>>0. \<forall>G. 0 < card (uverts G) \<longrightarrow> uwellformed G \<longrightarrow> real (card (triangle_set G)) \<le> \<delta> * real (card (uverts G) ^ 3) \<longrightarrow> (\<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2))
[PROOF STEP]
have "D0 > 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 < D0
[PROOF STEP]
using \<open>0 < \<epsilon>\<close> \<open>\<epsilon> < 1\<close> \<open>M0 > 0\<close>
[PROOF STATE]
proof (prove)
using this:
0 < \<epsilon>
\<epsilon> < 1
0 < M0

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

goal (1 subgoal):
 1. \<epsilon> < 1 \<Longrightarrow> \<exists>\<delta>>0. \<forall>G. 0 < card (uverts G) \<longrightarrow> uwellformed G \<longrightarrow> real (card (triangle_set G)) \<le> \<delta> * real (card (uverts G) ^ 3) \<longrightarrow> (\<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2))
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
0 < D0
[PROOF STEP]
obtain \<delta>:: "real" where \<delta>: "0 < \<delta>" "\<delta> < D0"
[PROOF STATE]
proof (prove)
using this:
0 < D0

goal (1 subgoal):
 1. (\<And>\<delta>. \<lbrakk>0 < \<delta>; \<delta> < D0\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by (meson dense)
[PROOF STATE]
proof (state)
this:
0 < \<delta>
\<delta> < D0

goal (1 subgoal):
 1. \<epsilon> < 1 \<Longrightarrow> \<exists>\<delta>>0. \<forall>G. 0 < card (uverts G) \<longrightarrow> uwellformed G \<longrightarrow> real (card (triangle_set G)) \<le> \<delta> * real (card (uverts G) ^ 3) \<longrightarrow> (\<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2))
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<exists>\<delta>>0. \<forall>G. 0 < card (uverts G) \<longrightarrow> uwellformed G \<longrightarrow> real (card (triangle_set G)) \<le> \<delta> * real (card (uverts G) ^ 3) \<longrightarrow> (\<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2))
[PROOF STEP]
proof (rule exI, intro conjI strip)
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
fix G
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
assume "card(uverts G) > 0" and wf: "uwellformed G"
[PROOF STATE]
proof (state)
this:
0 < card (uverts G)
uwellformed G

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
0 < card (uverts G)
uwellformed G
[PROOF STEP]
have fin: "finite (uverts G)"
[PROOF STATE]
proof (prove)
using this:
0 < card (uverts G)
uwellformed G

goal (1 subgoal):
 1. finite (uverts G)
[PROOF STEP]
by (simp add: card_gt_0_iff)
[PROOF STATE]
proof (state)
this:
finite (uverts G)

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
text\<open>Assume that, for a yet to be determined $\delta$, we have:\<close>
[PROOF STATE]
proof (state)
this:
finite (uverts G)

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
assume ineq: "real (card (triangle_set G)) \<le> \<delta> * card (uverts G) ^ 3"
[PROOF STATE]
proof (state)
this:
real (card (triangle_set G)) \<le> \<delta> * real (card (uverts G) ^ 3)

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
text\<open>Step 1: Partition: Using Szemer\'{e}di's Regularity Lemma, we get an $\epsilon/4$ partition. \<close>
[PROOF STATE]
proof (state)
this:
real (card (triangle_set G)) \<le> \<delta> * real (card (uverts G) ^ 3)

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
let ?n = "card (uverts G)"
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have vne: "uverts G \<noteq> {}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. uverts G \<noteq> {}
[PROOF STEP]
using \<open>0 < card (uverts G)\<close>
[PROOF STATE]
proof (prove)
using this:
0 < card (uverts G)

goal (1 subgoal):
 1. uverts G \<noteq> {}
[PROOF STEP]
by force
[PROOF STATE]
proof (state)
this:
uverts G \<noteq> {}

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
uverts G \<noteq> {}
[PROOF STEP]
have ngt0: "?n > 0"
[PROOF STATE]
proof (prove)
using this:
uverts G \<noteq> {}

goal (1 subgoal):
 1. 0 < card (uverts G)
[PROOF STEP]
by (simp add: fin card_gt_0_iff)
[PROOF STATE]
proof (state)
this:
0 < card (uverts G)

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
with M0
[PROOF STATE]
proof (chain)
picking this:
0 < card (uverts ?G) \<Longrightarrow> \<exists>P. regular_partition (\<epsilon> / 4) ?G P \<and> card P \<le> M0
0 < card (uverts G)
[PROOF STEP]
obtain P where M: "regular_partition (\<epsilon>/4) G P" and "card P \<le> M0"
[PROOF STATE]
proof (prove)
using this:
0 < card (uverts ?G) \<Longrightarrow> \<exists>P. regular_partition (\<epsilon> / 4) ?G P \<and> card P \<le> M0
0 < card (uverts G)

goal (1 subgoal):
 1. (\<And>P. \<lbrakk>regular_partition (\<epsilon> / 4) G P; card P \<le> M0\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
regular_partition (\<epsilon> / 4) G P
card P \<le> M0

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
define M where "M \<equiv> card P"
[PROOF STATE]
proof (state)
this:
M \<equiv> card P

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have "finite P"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. finite P
[PROOF STEP]
by (meson M fin finite_elements regular_partition_def)
[PROOF STATE]
proof (state)
this:
finite P

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
with M0
[PROOF STATE]
proof (chain)
picking this:
0 < card (uverts ?G) \<Longrightarrow> \<exists>P. regular_partition (\<epsilon> / 4) ?G P \<and> card P \<le> M0
finite P
[PROOF STEP]
have "M > 0"
[PROOF STATE]
proof (prove)
using this:
0 < card (uverts ?G) \<Longrightarrow> \<exists>P. regular_partition (\<epsilon> / 4) ?G P \<and> card P \<le> M0
finite P

goal (1 subgoal):
 1. 0 < M
[PROOF STEP]
unfolding M_def
[PROOF STATE]
proof (prove)
using this:
0 < card (uverts ?G) \<Longrightarrow> \<exists>P. regular_partition (\<epsilon> / 4) ?G P \<and> card P \<le> M0
finite P

goal (1 subgoal):
 1. 0 < card P
[PROOF STEP]
by (metis M card_gt_0_iff partition_onD1 partition_on_empty regular_partition_def vne)
[PROOF STATE]
proof (state)
this:
0 < M

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
let ?e4M = "\<epsilon> / (4 * real M)"
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
define D where "D \<equiv> 1/6 *(1-(\<epsilon>/2)) * ((\<epsilon>/4)^3) * ?e4M^3"
[PROOF STATE]
proof (state)
this:
D \<equiv> 1 / 6 * (1 - \<epsilon> / 2) * (\<epsilon> / 4) ^ 3 * (\<epsilon> / (4 * real M)) ^ 3

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have "D > 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 < D
[PROOF STEP]
using \<open>0 < \<epsilon>\<close> \<open>\<epsilon> < 1\<close> \<open>M > 0\<close>
[PROOF STATE]
proof (prove)
using this:
0 < \<epsilon>
\<epsilon> < 1
0 < M

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

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have "D0 \<le> D"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. D0 \<le> D
[PROOF STEP]
unfolding D0_def D_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 1 / 6 * (1 - \<epsilon> / 2) * (\<epsilon> / 4) ^ 3 * (\<epsilon> / real (4 * M0)) ^ 3 \<le> 1 / 6 * (1 - \<epsilon> / 2) * (\<epsilon> / 4) ^ 3 * (\<epsilon> / (4 * real M)) ^ 3
[PROOF STEP]
using \<open>0 < \<epsilon>\<close> \<open>\<epsilon> < 1\<close> \<open>card P \<le> M0\<close> \<open>M > 0\<close>
[PROOF STATE]
proof (prove)
using this:
0 < \<epsilon>
\<epsilon> < 1
card P \<le> M0
0 < M

goal (1 subgoal):
 1. 1 / 6 * (1 - \<epsilon> / 2) * (\<epsilon> / 4) ^ 3 * (\<epsilon> / real (4 * M0)) ^ 3 \<le> 1 / 6 * (1 - \<epsilon> / 2) * (\<epsilon> / 4) ^ 3 * (\<epsilon> / (4 * real M)) ^ 3
[PROOF STEP]
by (intro mult_mono) (auto simp: frac_le M_def)
[PROOF STATE]
proof (state)
this:
D0 \<le> D

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have fin_part: "finite_graph_partition (uverts G) P M"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. finite_graph_partition (uverts G) P M
[PROOF STEP]
using M
[PROOF STATE]
proof (prove)
using this:
regular_partition (\<epsilon> / 4) G P

goal (1 subgoal):
 1. finite_graph_partition (uverts G) P M
[PROOF STEP]
unfolding regular_partition_def finite_graph_partition_def
[PROOF STATE]
proof (prove)
using this:
partition_on (uverts G) P \<and> real (\<Sum>(R, S)\<in>irregular_set (\<epsilon> / 4) G P. card R * card S) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)

goal (1 subgoal):
 1. partition_on (uverts G) P \<and> finite P \<and> card P = M
[PROOF STEP]
by (metis M_def \<open>0 < M\<close> card_gt_0_iff)
[PROOF STATE]
proof (state)
this:
finite_graph_partition (uverts G) P M

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
finite_graph_partition (uverts G) P M
[PROOF STEP]
have fin_P: "finite R" and card_P_gt0: "card R > 0" if "R\<in>P" for R
[PROOF STATE]
proof (prove)
using this:
finite_graph_partition (uverts G) P M

goal (1 subgoal):
 1. finite R &&& 0 < card R
[PROOF STEP]
using fin finite_graph_partition_finite finite_graph_partition_gt0 that
[PROOF STATE]
proof (prove)
using this:
finite_graph_partition (uverts G) P M
finite (uverts G)
\<lbrakk>finite_graph_partition ?V ?P ?k; finite ?V; ?X \<in> ?P\<rbrakk> \<Longrightarrow> finite ?X
\<lbrakk>finite_graph_partition ?V ?P ?k; finite ?V; ?X \<in> ?P\<rbrakk> \<Longrightarrow> 0 < card ?X
R \<in> P

goal (1 subgoal):
 1. finite R &&& 0 < card R
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
?R \<in> P \<Longrightarrow> finite ?R
?R \<in> P \<Longrightarrow> 0 < card ?R

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have card_P_le: "card R \<le> ?n" if "R\<in>P" for R
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. card R \<le> card (uverts G)
[PROOF STEP]
by (meson card_mono fin fin_part finite_graph_partition_subset that)
[PROOF STATE]
proof (state)
this:
?R \<in> P \<Longrightarrow> card ?R \<le> card (uverts G)

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have P_disjnt: "\<And>R S. \<lbrakk>R \<noteq> S; R \<in> P; S \<in> P\<rbrakk> \<Longrightarrow> R \<inter> S = {}"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>R S. \<lbrakk>R \<noteq> S; R \<in> P; S \<in> P\<rbrakk> \<Longrightarrow> R \<inter> S = {}
[PROOF STEP]
using fin_part
[PROOF STATE]
proof (prove)
using this:
finite_graph_partition (uverts G) P M

goal (1 subgoal):
 1. \<And>R S. \<lbrakk>R \<noteq> S; R \<in> P; S \<in> P\<rbrakk> \<Longrightarrow> R \<inter> S = {}
[PROOF STEP]
by (metis disjnt_def finite_graph_partition_def insert_absorb pairwise_insert partition_on_def)
[PROOF STATE]
proof (state)
this:
\<lbrakk>?R \<noteq> ?S; ?R \<in> P; ?S \<in> P\<rbrakk> \<Longrightarrow> ?R \<inter> ?S = {}

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have sum_card_P: "(\<Sum>R\<in>P. card R) = ?n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. sum card P = card (uverts G)
[PROOF STEP]
using card_finite_graph_partition fin fin_part
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>finite_graph_partition ?V ?P ?k; finite ?V\<rbrakk> \<Longrightarrow> sum card ?P = card ?V
finite (uverts G)
finite_graph_partition (uverts G) P M

goal (1 subgoal):
 1. sum card P = card (uverts G)
[PROOF STEP]
by meson
[PROOF STATE]
proof (state)
this:
sum card P = card (uverts G)

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
text\<open>Step 2. Cleaning. For each ordered pair of parts $(P_i,P_j)$, remove all edges between
      $P_i$ and $P_j$ if (a) it is an irregular pair, (b) its edge density ${} < \epsilon/2$,
      (c) either $P_i$ or $P_j$ is small (${}\le(\epsilon/4M)n$)
    Process (a) removes at most $(\epsilon/4)n^2$ edges.
    Process (b) removes at most $(\epsilon/2)n^2$ edges.
    Process (c) removes at most $(\epsilon/4)n^2$ edges.
   The remaining graph is triangle-free for some choice of $\delta$. \<close>
[PROOF STATE]
proof (state)
this:
sum card P = card (uverts G)

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
define edge where "edge \<equiv> \<lambda>R S. mk_uedge ` (all_edges_between R S G)"
[PROOF STATE]
proof (state)
this:
edge \<equiv> \<lambda>R S. mk_uedge ` all_edges_between R S G

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have edge_commute: "edge R S = edge S R" for R S
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. edge R S = edge S R
[PROOF STEP]
by (force simp add: edge_def all_edges_between_swap [of S] split: prod.split)
[PROOF STATE]
proof (state)
this:
edge ?R ?S = edge ?S ?R

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have card_edge_le_card: "card (edge R S) \<le> card (all_edges_between R S G)" for R S
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. card (edge R S) \<le> card (all_edges_between R S G)
[PROOF STEP]
by (simp add: card_image_le edge_def fin finite_all_edges_between' local.wf)
[PROOF STATE]
proof (state)
this:
card (edge ?R ?S) \<le> card (all_edges_between ?R ?S G)

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have card_edge_le: "card (edge R S) \<le> card R * card S" if "R\<in>P" "S\<in>P" for R S
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. card (edge R S) \<le> card R * card S
[PROOF STEP]
by (meson card_edge_le_card fin_P le_trans max_all_edges_between that)
[PROOF STATE]
proof (state)
this:
\<lbrakk>?R \<in> P; ?S \<in> P\<rbrakk> \<Longrightarrow> card (edge ?R ?S) \<le> card ?R * card ?S

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
text \<open>Obtain the set of edges meeting condition (a).\<close>
[PROOF STATE]
proof (state)
this:
\<lbrakk>?R \<in> P; ?S \<in> P\<rbrakk> \<Longrightarrow> card (edge ?R ?S) \<le> card ?R * card ?S

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
define irreg_pairs where "irreg_pairs \<equiv> {(R,S). R \<in> P \<and> S \<in> P \<and> \<not> regular_pair R S G (\<epsilon>/4)}"
[PROOF STATE]
proof (state)
this:
irreg_pairs \<equiv> {(R, S). R \<in> P \<and> S \<in> P \<and> \<not> regular_pair R S G (\<epsilon> / 4)}

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
define Ea where "Ea \<equiv> (\<Union>(R,S) \<in> irreg_pairs. edge R S)"
[PROOF STATE]
proof (state)
this:
Ea \<equiv> \<Union>(R, S)\<in>irreg_pairs. edge R S

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
text \<open>Obtain the set of edges meeting condition (b).\<close>
[PROOF STATE]
proof (state)
this:
Ea \<equiv> \<Union>(R, S)\<in>irreg_pairs. edge R S

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
define low_density_pairs
      where "low_density_pairs \<equiv> {(R,S). R \<in> P \<and> S \<in> P \<and> \<not> edge_dense R S G (\<epsilon>/2)}"
[PROOF STATE]
proof (state)
this:
low_density_pairs \<equiv> {(R, S). R \<in> P \<and> S \<in> P \<and> \<not> edge_dense R S G (\<epsilon> / 2)}

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
define Eb where "Eb \<equiv> (\<Union>(i,j) \<in> low_density_pairs. edge i j)"
[PROOF STATE]
proof (state)
this:
Eb \<equiv> \<Union>(i, j)\<in>low_density_pairs. edge i j

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
text \<open>Obtain the set of edges meeting condition (c).\<close>
[PROOF STATE]
proof (state)
this:
Eb \<equiv> \<Union>(i, j)\<in>low_density_pairs. edge i j

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
define small where "small \<equiv> \<lambda>R. R \<in> P \<and> card R \<le> ?e4M * ?n"
[PROOF STATE]
proof (state)
this:
small \<equiv> \<lambda>R. R \<in> P \<and> real (card R) \<le> \<epsilon> / (4 * real M) * real (card (uverts G))

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
let ?SMALL = "Collect small"
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
define small_pairs where "small_pairs \<equiv> {(R,S). R \<in> P \<and> S \<in> P \<and> (small R \<or> small S)}"
[PROOF STATE]
proof (state)
this:
small_pairs \<equiv> {(R, S). R \<in> P \<and> S \<in> P \<and> (small R \<or> small S)}

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
define Ec where "Ec \<equiv> (\<Union>R \<in> ?SMALL. \<Union>S \<in> P. edge R S)"
[PROOF STATE]
proof (state)
this:
Ec \<equiv> \<Union>R\<in>Collect small. \<Union> (edge R ` P)

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have Ec_def': "Ec = (\<Union>(i,j) \<in> small_pairs. edge i j)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Ec = (\<Union>(i, j)\<in>small_pairs. edge i j)
[PROOF STEP]
by (force simp: edge_commute small_pairs_def small_def Ec_def)
[PROOF STATE]
proof (state)
this:
Ec = (\<Union>(i, j)\<in>small_pairs. edge i j)

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have eabound: "card Ea \<le> (\<epsilon>/4) * ?n^2"  \<comment>\<open>Count the edge bound for @{term Ea}\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. real (card Ea) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. real (card Ea) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have \<section>: "\<And>R S. \<lbrakk>R \<in> P; S \<in> P\<rbrakk> \<Longrightarrow> card (edge R S) \<le> card R * card S"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>R S. \<lbrakk>R \<in> P; S \<in> P\<rbrakk> \<Longrightarrow> card (edge R S) \<le> card R * card S
[PROOF STEP]
unfolding edge_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>R S. \<lbrakk>R \<in> P; S \<in> P\<rbrakk> \<Longrightarrow> card (mk_uedge ` all_edges_between R S G) \<le> card R * card S
[PROOF STEP]
by (meson card_image_le fin_P finite_all_edges_between max_all_edges_between order_trans)
[PROOF STATE]
proof (state)
this:
\<lbrakk>?R \<in> P; ?S \<in> P\<rbrakk> \<Longrightarrow> card (edge ?R ?S) \<le> card ?R * card ?S

goal (1 subgoal):
 1. real (card Ea) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have "irreg_pairs \<subseteq> P \<times> P"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. irreg_pairs \<subseteq> P \<times> P
[PROOF STEP]
by (auto simp: irreg_pairs_def)
[PROOF STATE]
proof (state)
this:
irreg_pairs \<subseteq> P \<times> P

goal (1 subgoal):
 1. real (card Ea) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
irreg_pairs \<subseteq> P \<times> P
[PROOF STEP]
have "finite irreg_pairs"
[PROOF STATE]
proof (prove)
using this:
irreg_pairs \<subseteq> P \<times> P

goal (1 subgoal):
 1. finite irreg_pairs
[PROOF STEP]
by (meson \<open>finite P\<close> finite_SigmaI finite_subset)
[PROOF STATE]
proof (state)
this:
finite irreg_pairs

goal (1 subgoal):
 1. real (card Ea) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have "card Ea \<le> (\<Sum>(R,S)\<in>irreg_pairs. card (edge R S))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. card Ea \<le> (\<Sum>(R, S)\<in>irreg_pairs. card (edge R S))
[PROOF STEP]
by (simp add: Ea_def card_UN_le [OF \<open>finite irreg_pairs\<close>] case_prod_unfold)
[PROOF STATE]
proof (state)
this:
card Ea \<le> (\<Sum>(R, S)\<in>irreg_pairs. card (edge R S))

goal (1 subgoal):
 1. real (card Ea) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
card Ea \<le> (\<Sum>(R, S)\<in>irreg_pairs. card (edge R S))

goal (1 subgoal):
 1. real (card Ea) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have "\<dots> \<le> (\<Sum>(R,S) \<in> {(R,S). R\<in>P \<and> S\<in>P \<and> \<not> regular_pair R S G (\<epsilon>/4)}. card R * card S)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>(R, S)\<in>irreg_pairs. card (edge R S)) \<le> (\<Sum>(R, S)\<in>{(R, S). R \<in> P \<and> S \<in> P \<and> \<not> regular_pair R S G (\<epsilon> / 4)}. card R * card S)
[PROOF STEP]
unfolding irreg_pairs_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>(R, S)\<in>{(R, S). R \<in> P \<and> S \<in> P \<and> \<not> regular_pair R S G (\<epsilon> / 4)}. card (edge R S)) \<le> (\<Sum>(R, S)\<in>{(R, S). R \<in> P \<and> S \<in> P \<and> \<not> regular_pair R S G (\<epsilon> / 4)}. card R * card S)
[PROOF STEP]
using \<section>
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>?R \<in> P; ?S \<in> P\<rbrakk> \<Longrightarrow> card (edge ?R ?S) \<le> card ?R * card ?S

goal (1 subgoal):
 1. (\<Sum>(R, S)\<in>{(R, S). R \<in> P \<and> S \<in> P \<and> \<not> regular_pair R S G (\<epsilon> / 4)}. card (edge R S)) \<le> (\<Sum>(R, S)\<in>{(R, S). R \<in> P \<and> S \<in> P \<and> \<not> regular_pair R S G (\<epsilon> / 4)}. card R * card S)
[PROOF STEP]
by (force intro: sum_mono)
[PROOF STATE]
proof (state)
this:
(\<Sum>(R, S)\<in>irreg_pairs. card (edge R S)) \<le> (\<Sum>(R, S)\<in>{(R, S). R \<in> P \<and> S \<in> P \<and> \<not> regular_pair R S G (\<epsilon> / 4)}. card R * card S)

goal (1 subgoal):
 1. real (card Ea) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>(R, S)\<in>irreg_pairs. card (edge R S)) \<le> (\<Sum>(R, S)\<in>{(R, S). R \<in> P \<and> S \<in> P \<and> \<not> regular_pair R S G (\<epsilon> / 4)}. card R * card S)

goal (1 subgoal):
 1. real (card Ea) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have "\<dots> = (\<Sum>(R,S) \<in> irregular_set (\<epsilon>/4) G P. card R * card S)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>(R, S)\<in>{(R, S). R \<in> P \<and> S \<in> P \<and> \<not> regular_pair R S G (\<epsilon> / 4)}. card R * card S) = (\<Sum>(R, S)\<in>irregular_set (\<epsilon> / 4) G P. card R * card S)
[PROOF STEP]
by (simp add: irregular_set_def)
[PROOF STATE]
proof (state)
this:
(\<Sum>(R, S)\<in>{(R, S). R \<in> P \<and> S \<in> P \<and> \<not> regular_pair R S G (\<epsilon> / 4)}. card R * card S) = (\<Sum>(R, S)\<in>irregular_set (\<epsilon> / 4) G P. card R * card S)

goal (1 subgoal):
 1. real (card Ea) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
card Ea \<le> (\<Sum>(R, S)\<in>irregular_set (\<epsilon> / 4) G P. card R * card S)
[PROOF STEP]
have "card Ea \<le> (\<Sum>(R,S) \<in> irregular_set (\<epsilon>/4) G P. card R * card S)"
[PROOF STATE]
proof (prove)
using this:
card Ea \<le> (\<Sum>(R, S)\<in>irregular_set (\<epsilon> / 4) G P. card R * card S)

goal (1 subgoal):
 1. card Ea \<le> (\<Sum>(R, S)\<in>irregular_set (\<epsilon> / 4) G P. card R * card S)
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
card Ea \<le> (\<Sum>(R, S)\<in>irregular_set (\<epsilon> / 4) G P. card R * card S)

goal (1 subgoal):
 1. real (card Ea) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
with M
[PROOF STATE]
proof (chain)
picking this:
regular_partition (\<epsilon> / 4) G P
card Ea \<le> (\<Sum>(R, S)\<in>irregular_set (\<epsilon> / 4) G P. card R * card S)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
regular_partition (\<epsilon> / 4) G P
card Ea \<le> (\<Sum>(R, S)\<in>irregular_set (\<epsilon> / 4) G P. card R * card S)

goal (1 subgoal):
 1. real (card Ea) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
unfolding regular_partition_def
[PROOF STATE]
proof (prove)
using this:
partition_on (uverts G) P \<and> real (\<Sum>(R, S)\<in>irregular_set (\<epsilon> / 4) G P. card R * card S) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
card Ea \<le> (\<Sum>(R, S)\<in>irregular_set (\<epsilon> / 4) G P. card R * card S)

goal (1 subgoal):
 1. real (card Ea) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
by linarith
[PROOF STATE]
proof (state)
this:
real (card Ea) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
real (card Ea) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have ebbound: "card Eb \<le> (\<epsilon>/2) * (?n^2)"  \<comment>\<open>Count the edge bound for @{term Eb}.\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. real (card Eb) \<le> \<epsilon> / 2 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. real (card Eb) \<le> \<epsilon> / 2 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have \<section>: "\<And>R S. \<lbrakk>R \<in> P; S \<in> P; \<not> edge_dense R S G (\<epsilon> / 2)\<rbrakk>
           \<Longrightarrow> real (card (edge R S)) * 2 \<le> \<epsilon> * real (card R) * real (card S)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>R S. \<lbrakk>R \<in> P; S \<in> P; \<not> edge_dense R S G (\<epsilon> / 2)\<rbrakk> \<Longrightarrow> real (card (edge R S)) * 2 \<le> \<epsilon> * real (card R) * real (card S)
[PROOF STEP]
by (simp add: divide_simps edge_dense_def edge_density_def card_P_gt0)
           (smt (verit, best) card_edge_le_card of_nat_le_iff mult.assoc)
[PROOF STATE]
proof (state)
this:
\<lbrakk>?R \<in> P; ?S \<in> P; \<not> edge_dense ?R ?S G (\<epsilon> / 2)\<rbrakk> \<Longrightarrow> real (card (edge ?R ?S)) * 2 \<le> \<epsilon> * real (card ?R) * real (card ?S)

goal (1 subgoal):
 1. real (card Eb) \<le> \<epsilon> / 2 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have subs: "low_density_pairs \<subseteq> P \<times> P"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. low_density_pairs \<subseteq> P \<times> P
[PROOF STEP]
by (auto simp: low_density_pairs_def)
[PROOF STATE]
proof (state)
this:
low_density_pairs \<subseteq> P \<times> P

goal (1 subgoal):
 1. real (card Eb) \<le> \<epsilon> / 2 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
low_density_pairs \<subseteq> P \<times> P
[PROOF STEP]
have "finite low_density_pairs"
[PROOF STATE]
proof (prove)
using this:
low_density_pairs \<subseteq> P \<times> P

goal (1 subgoal):
 1. finite low_density_pairs
[PROOF STEP]
by (metis \<open>finite P\<close> finite_SigmaI finite_subset)
[PROOF STATE]
proof (state)
this:
finite low_density_pairs

goal (1 subgoal):
 1. real (card Eb) \<le> \<epsilon> / 2 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have "real (card Eb) \<le> (\<Sum>(i,j)\<in>low_density_pairs. real (card (edge i j)))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. real (card Eb) \<le> (\<Sum>(i, j)\<in>low_density_pairs. real (card (edge i j)))
[PROOF STEP]
unfolding Eb_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. real (card (\<Union>(i, j)\<in>low_density_pairs. edge i j)) \<le> (\<Sum>(i, j)\<in>low_density_pairs. real (card (edge i j)))
[PROOF STEP]
by (smt (verit, ccfv_SIG) \<open>finite low_density_pairs\<close> card_UN_le of_nat_mono of_nat_sum
 case_prod_unfold sum_mono)
[PROOF STATE]
proof (state)
this:
real (card Eb) \<le> (\<Sum>(i, j)\<in>low_density_pairs. real (card (edge i j)))

goal (1 subgoal):
 1. real (card Eb) \<le> \<epsilon> / 2 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
real (card Eb) \<le> (\<Sum>(i, j)\<in>low_density_pairs. real (card (edge i j)))

goal (1 subgoal):
 1. real (card Eb) \<le> \<epsilon> / 2 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have "\<dots> \<le> (\<Sum>(R,S)\<in>low_density_pairs. \<epsilon>/2 * card R * card S)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>(i, j)\<in>low_density_pairs. real (card (edge i j))) \<le> (\<Sum>(R, S)\<in>low_density_pairs. \<epsilon> / 2 * real (card R) * real (card S))
[PROOF STEP]
unfolding low_density_pairs_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>(i, j)\<in>{(R, S). R \<in> P \<and> S \<in> P \<and> \<not> edge_dense R S G (\<epsilon> / 2)}. real (card (edge i j))) \<le> (\<Sum>(R, S)\<in>{(R, S). R \<in> P \<and> S \<in> P \<and> \<not> edge_dense R S G (\<epsilon> / 2)}. \<epsilon> / 2 * real (card R) * real (card S))
[PROOF STEP]
by (force intro: sum_mono \<section>)
[PROOF STATE]
proof (state)
this:
(\<Sum>(i, j)\<in>low_density_pairs. real (card (edge i j))) \<le> (\<Sum>(R, S)\<in>low_density_pairs. \<epsilon> / 2 * real (card R) * real (card S))

goal (1 subgoal):
 1. real (card Eb) \<le> \<epsilon> / 2 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>(i, j)\<in>low_density_pairs. real (card (edge i j))) \<le> (\<Sum>(R, S)\<in>low_density_pairs. \<epsilon> / 2 * real (card R) * real (card S))

goal (1 subgoal):
 1. real (card Eb) \<le> \<epsilon> / 2 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have "\<dots> \<le> (\<Sum>(R,S)\<in>P \<times> P. \<epsilon>/2 * card R * card S)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>(R, S)\<in>low_density_pairs. \<epsilon> / 2 * real (card R) * real (card S)) \<le> (\<Sum>(R, S)\<in>P \<times> P. \<epsilon> / 2 * real (card R) * real (card S))
[PROOF STEP]
using subs \<open>\<epsilon> > 0\<close>
[PROOF STATE]
proof (prove)
using this:
low_density_pairs \<subseteq> P \<times> P
0 < \<epsilon>

goal (1 subgoal):
 1. (\<Sum>(R, S)\<in>low_density_pairs. \<epsilon> / 2 * real (card R) * real (card S)) \<le> (\<Sum>(R, S)\<in>P \<times> P. \<epsilon> / 2 * real (card R) * real (card S))
[PROOF STEP]
by (intro sum_mono2) (auto simp: \<open>finite P\<close>)
[PROOF STATE]
proof (state)
this:
(\<Sum>(R, S)\<in>low_density_pairs. \<epsilon> / 2 * real (card R) * real (card S)) \<le> (\<Sum>(R, S)\<in>P \<times> P. \<epsilon> / 2 * real (card R) * real (card S))

goal (1 subgoal):
 1. real (card Eb) \<le> \<epsilon> / 2 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>(R, S)\<in>low_density_pairs. \<epsilon> / 2 * real (card R) * real (card S)) \<le> (\<Sum>(R, S)\<in>P \<times> P. \<epsilon> / 2 * real (card R) * real (card S))

goal (1 subgoal):
 1. real (card Eb) \<le> \<epsilon> / 2 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have "\<dots> = \<epsilon>/2 * (\<Sum>(R,S)\<in>P \<times> P. card R * card S)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>(R, S)\<in>P \<times> P. \<epsilon> / 2 * real (card R) * real (card S)) = \<epsilon> / 2 * real (\<Sum>(R, S)\<in>P \<times> P. card R * card S)
[PROOF STEP]
by (simp add: sum_distrib_left case_prod_unfold mult_ac)
[PROOF STATE]
proof (state)
this:
(\<Sum>(R, S)\<in>P \<times> P. \<epsilon> / 2 * real (card R) * real (card S)) = \<epsilon> / 2 * real (\<Sum>(R, S)\<in>P \<times> P. card R * card S)

goal (1 subgoal):
 1. real (card Eb) \<le> \<epsilon> / 2 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>(R, S)\<in>P \<times> P. \<epsilon> / 2 * real (card R) * real (card S)) = \<epsilon> / 2 * real (\<Sum>(R, S)\<in>P \<times> P. card R * card S)

goal (1 subgoal):
 1. real (card Eb) \<le> \<epsilon> / 2 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have "\<dots> \<le> (\<epsilon>/2) * (?n^2)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<epsilon> / 2 * real (\<Sum>(R, S)\<in>P \<times> P. card R * card S) \<le> \<epsilon> / 2 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
using \<open>\<epsilon>>0\<close> sum_prod_le_prod_sum
[PROOF STATE]
proof (prove)
using this:
0 < \<epsilon>
(\<And>i. i \<in> ?I \<Longrightarrow> (0::?'b) \<le> ?a i \<and> (0::?'b) \<le> ?b i) \<Longrightarrow> (\<Sum>i\<in>?I. \<Sum>j\<in>?I. ?a i * ?b j) \<le> sum ?a ?I * sum ?b ?I

goal (1 subgoal):
 1. \<epsilon> / 2 * real (\<Sum>(R, S)\<in>P \<times> P. card R * card S) \<le> \<epsilon> / 2 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
by (simp add: power2_eq_square sum_product flip: sum.cartesian_product sum_card_P)
[PROOF STATE]
proof (state)
this:
\<epsilon> / 2 * real (\<Sum>(R, S)\<in>P \<times> P. card R * card S) \<le> \<epsilon> / 2 * real ((card (uverts G))\<^sup>2)

goal (1 subgoal):
 1. real (card Eb) \<le> \<epsilon> / 2 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
real (card Eb) \<le> \<epsilon> / 2 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
real (card Eb) \<le> \<epsilon> / 2 * real ((card (uverts G))\<^sup>2)

goal (1 subgoal):
 1. real (card Eb) \<le> \<epsilon> / 2 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
real (card Eb) \<le> \<epsilon> / 2 * real ((card (uverts G))\<^sup>2)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
real (card Eb) \<le> \<epsilon> / 2 * real ((card (uverts G))\<^sup>2)

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have ecbound: "card Ec \<le> (\<epsilon>/4) * (?n^2)"  \<comment>\<open>Count the edge bound for @{term Ec}.\<close>
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. real (card Ec) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. real (card Ec) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have edge_bound: "(card (edge R S)) \<le> ?e4M * ?n^2"
        if "S \<in> P" "small R" for R S
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. real (card (edge R S)) \<le> \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. real (card (edge R S)) \<le> \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have "real (card R) \<le> \<epsilon> * ?n / (4 * real M)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. real (card R) \<le> \<epsilon> * real (card (uverts G)) / (4 * real M)
[PROOF STEP]
using that
[PROOF STATE]
proof (prove)
using this:
S \<in> P
small R

goal (1 subgoal):
 1. real (card R) \<le> \<epsilon> * real (card (uverts G)) / (4 * real M)
[PROOF STEP]
by (simp add: small_def)
[PROOF STATE]
proof (state)
this:
real (card R) \<le> \<epsilon> * real (card (uverts G)) / (4 * real M)

goal (1 subgoal):
 1. real (card (edge R S)) \<le> \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
with card_P_le [OF \<open>S\<in>P\<close>]
[PROOF STATE]
proof (chain)
picking this:
card S \<le> card (uverts G)
real (card R) \<le> \<epsilon> * real (card (uverts G)) / (4 * real M)
[PROOF STEP]
have *: "real (card R) * real (card S) \<le> \<epsilon> * card (uverts G) / (4 * real M) * ?n"
[PROOF STATE]
proof (prove)
using this:
card S \<le> card (uverts G)
real (card R) \<le> \<epsilon> * real (card (uverts G)) / (4 * real M)

goal (1 subgoal):
 1. real (card R) * real (card S) \<le> \<epsilon> * real (card (uverts G)) / (4 * real M) * real (card (uverts G))
[PROOF STEP]
by (meson mult_mono of_nat_0_le_iff of_nat_mono order.trans)
[PROOF STATE]
proof (state)
this:
real (card R) * real (card S) \<le> \<epsilon> * real (card (uverts G)) / (4 * real M) * real (card (uverts G))

goal (1 subgoal):
 1. real (card (edge R S)) \<le> \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
real (card R) * real (card S) \<le> \<epsilon> * real (card (uverts G)) / (4 * real M) * real (card (uverts G))

goal (1 subgoal):
 1. real (card (edge R S)) \<le> \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have "\<dots> = ?e4M * ?n^2"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<epsilon> * real (card (uverts G)) / (4 * real M) * real (card (uverts G)) = \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
by (simp add: power2_eq_square)
[PROOF STATE]
proof (state)
this:
\<epsilon> * real (card (uverts G)) / (4 * real M) * real (card (uverts G)) = \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)

goal (1 subgoal):
 1. real (card (edge R S)) \<le> \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
real (card R) * real (card S) \<le> \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
real (card R) * real (card S) \<le> \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)

goal (1 subgoal):
 1. real (card (edge R S)) \<le> \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
by (smt (verit) card_edge_le of_nat_mono of_nat_mult small_def that)
[PROOF STATE]
proof (state)
this:
real (card (edge R S)) \<le> \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<lbrakk>?S \<in> P; small ?R\<rbrakk> \<Longrightarrow> real (card (edge ?R ?S)) \<le> \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)

goal (1 subgoal):
 1. real (card Ec) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have subs: "?SMALL \<subseteq> P"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Collect small \<subseteq> P
[PROOF STEP]
by (auto simp: small_def)
[PROOF STATE]
proof (state)
this:
Collect small \<subseteq> P

goal (1 subgoal):
 1. real (card Ec) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
Collect small \<subseteq> P
[PROOF STEP]
obtain card_sp: "card (?SMALL) \<le> M" and "finite ?SMALL"
[PROOF STATE]
proof (prove)
using this:
Collect small \<subseteq> P

goal (1 subgoal):
 1. (\<lbrakk>card (Collect small) \<le> M; finite (Collect small)\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
using M_def \<open>finite P\<close> card_mono
[PROOF STATE]
proof (prove)
using this:
Collect small \<subseteq> P
M \<equiv> card P
finite P
\<lbrakk>finite ?B; ?A \<subseteq> ?B\<rbrakk> \<Longrightarrow> card ?A \<le> card ?B

goal (1 subgoal):
 1. (\<lbrakk>card (Collect small) \<le> M; finite (Collect small)\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by (metis finite_subset)
[PROOF STATE]
proof (state)
this:
card (Collect small) \<le> M
finite (Collect small)

goal (1 subgoal):
 1. real (card Ec) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have "real (card Ec) \<le> (\<Sum>R \<in> ?SMALL. real (card (\<Union>S \<in> P. edge R S)))"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. real (card Ec) \<le> (\<Sum>R\<in>Collect small. real (card (\<Union> (edge R ` P))))
[PROOF STEP]
unfolding Ec_def
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. real (card (\<Union>R\<in>Collect small. \<Union> (edge R ` P))) \<le> (\<Sum>R\<in>Collect small. real (card (\<Union> (edge R ` P))))
[PROOF STEP]
by (smt (verit, ccfv_SIG) \<open>finite ?SMALL\<close> card_UN_le of_nat_mono of_nat_sum case_prod_unfold sum_mono)
[PROOF STATE]
proof (state)
this:
real (card Ec) \<le> (\<Sum>R\<in>Collect small. real (card (\<Union> (edge R ` P))))

goal (1 subgoal):
 1. real (card Ec) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
real (card Ec) \<le> (\<Sum>R\<in>Collect small. real (card (\<Union> (edge R ` P))))

goal (1 subgoal):
 1. real (card Ec) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have "\<dots> \<le> (\<Sum>R \<in> ?SMALL. ?e4M * ?n^2)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>R\<in>Collect small. real (card (\<Union> (edge R ` P)))) \<le> (\<Sum>R\<in>Collect small. \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2))
[PROOF STEP]
proof (intro sum_mono)
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>R. R \<in> Collect small \<Longrightarrow> real (card (\<Union> (edge R ` P))) \<le> \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
fix R
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>R. R \<in> Collect small \<Longrightarrow> real (card (\<Union> (edge R ` P))) \<le> \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
assume i: "R \<in> Collect small"
[PROOF STATE]
proof (state)
this:
R \<in> Collect small

goal (1 subgoal):
 1. \<And>R. R \<in> Collect small \<Longrightarrow> real (card (\<Union> (edge R ` P))) \<le> \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
R \<in> Collect small
[PROOF STEP]
have "R\<in>P" and card_Pi: "card R \<le> ?e4M * ?n"
[PROOF STATE]
proof (prove)
using this:
R \<in> Collect small

goal (1 subgoal):
 1. R \<in> P &&& real (card R) \<le> \<epsilon> / (4 * real M) * real (card (uverts G))
[PROOF STEP]
by (auto simp: small_def)
[PROOF STATE]
proof (state)
this:
R \<in> P
real (card R) \<le> \<epsilon> / (4 * real M) * real (card (uverts G))

goal (1 subgoal):
 1. \<And>R. R \<in> Collect small \<Longrightarrow> real (card (\<Union> (edge R ` P))) \<le> \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
let ?UE = "\<Union>(edge R ` (P))"
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<And>R. R \<in> Collect small \<Longrightarrow> real (card (\<Union> (edge R ` P))) \<le> \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have *: "real (card ?UE) \<le> real (card R * ?n)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. real (card (\<Union> (edge R ` P))) \<le> real (card R * card (uverts G))
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. real (card (\<Union> (edge R ` P))) \<le> real (card R * card (uverts G))
[PROOF STEP]
have "?UE \<subseteq> mk_uedge ` (all_edges_between R (uverts G) G)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<Union> (edge R ` P) \<subseteq> mk_uedge ` all_edges_between R (uverts G) G
[PROOF STEP]
apply (simp add: edge_def UN_subset_iff Ball_def)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<forall>x. x \<in> P \<longrightarrow> mk_uedge ` all_edges_between R x G \<subseteq> mk_uedge ` all_edges_between R (uverts G) G
[PROOF STEP]
by (meson all_edges_between_mono2 fin_part finite_graph_partition_subset image_mono)
[PROOF STATE]
proof (state)
this:
\<Union> (edge R ` P) \<subseteq> mk_uedge ` all_edges_between R (uverts G) G

goal (1 subgoal):
 1. real (card (\<Union> (edge R ` P))) \<le> real (card R * card (uverts G))
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
\<Union> (edge R ` P) \<subseteq> mk_uedge ` all_edges_between R (uverts G) G
[PROOF STEP]
have "card ?UE \<le> card (all_edges_between R (uverts G) G)"
[PROOF STATE]
proof (prove)
using this:
\<Union> (edge R ` P) \<subseteq> mk_uedge ` all_edges_between R (uverts G) G

goal (1 subgoal):
 1. card (\<Union> (edge R ` P)) \<le> card (all_edges_between R (uverts G) G)
[PROOF STEP]
by (meson card_image_le card_mono fin finite_all_edges_between' finite_imageI wf le_trans)
[PROOF STATE]
proof (state)
this:
card (\<Union> (edge R ` P)) \<le> card (all_edges_between R (uverts G) G)

goal (1 subgoal):
 1. real (card (\<Union> (edge R ` P))) \<le> real (card R * card (uverts G))
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
card (\<Union> (edge R ` P)) \<le> card (all_edges_between R (uverts G) G)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
card (\<Union> (edge R ` P)) \<le> card (all_edges_between R (uverts G) G)

goal (1 subgoal):
 1. real (card (\<Union> (edge R ` P))) \<le> real (card R * card (uverts G))
[PROOF STEP]
by (meson of_nat_mono fin fin_P max_all_edges_between order.trans \<open>R\<in>P\<close>)
[PROOF STATE]
proof (state)
this:
real (card (\<Union> (edge R ` P))) \<le> real (card R * card (uverts G))

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
real (card (\<Union> (edge R ` P))) \<le> real (card R * card (uverts G))

goal (1 subgoal):
 1. \<And>R. R \<in> Collect small \<Longrightarrow> real (card (\<Union> (edge R ` P))) \<le> \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
real (card (\<Union> (edge R ` P))) \<le> real (card R * card (uverts G))

goal (1 subgoal):
 1. \<And>R. R \<in> Collect small \<Longrightarrow> real (card (\<Union> (edge R ` P))) \<le> \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have "\<dots> \<le> ?e4M * real (?n\<^sup>2)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. real (card R * card (uverts G)) \<le> \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
using card_Pi \<open>M > 0\<close> \<open>?n > 0\<close>
[PROOF STATE]
proof (prove)
using this:
real (card R) \<le> \<epsilon> / (4 * real M) * real (card (uverts G))
0 < M
0 < card (uverts G)

goal (1 subgoal):
 1. real (card R * card (uverts G)) \<le> \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
by (force simp add: divide_simps power2_eq_square)
[PROOF STATE]
proof (state)
this:
real (card R * card (uverts G)) \<le> \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)

goal (1 subgoal):
 1. \<And>R. R \<in> Collect small \<Longrightarrow> real (card (\<Union> (edge R ` P))) \<le> \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
real (card (\<Union> (edge R ` P))) \<le> \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
show "real (card ?UE) \<le> ?e4M * real (?n\<^sup>2)"
[PROOF STATE]
proof (prove)
using this:
real (card (\<Union> (edge R ` P))) \<le> \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)

goal (1 subgoal):
 1. real (card (\<Union> (edge R ` P))) \<le> \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
real (card (\<Union> (edge R ` P))) \<le> \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
(\<Sum>R\<in>Collect small. real (card (\<Union> (edge R ` P)))) \<le> (\<Sum>R\<in>Collect small. \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2))

goal (1 subgoal):
 1. real (card Ec) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>R\<in>Collect small. real (card (\<Union> (edge R ` P)))) \<le> (\<Sum>R\<in>Collect small. \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2))

goal (1 subgoal):
 1. real (card Ec) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have "\<dots> \<le> card ?SMALL * (?e4M * ?n^2)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<Sum>R\<in>Collect small. \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)) \<le> real (card (Collect small)) * (\<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2))
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
(\<Sum>R\<in>Collect small. \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)) \<le> real (card (Collect small)) * (\<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2))

goal (1 subgoal):
 1. real (card Ec) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(\<Sum>R\<in>Collect small. \<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)) \<le> real (card (Collect small)) * (\<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2))

goal (1 subgoal):
 1. real (card Ec) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have "\<dots> \<le> M * (?e4M * ?n^2)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. real (card (Collect small)) * (\<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)) \<le> real M * (\<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2))
[PROOF STEP]
using egt
[PROOF STATE]
proof (prove)
using this:
0 < \<epsilon>

goal (1 subgoal):
 1. real (card (Collect small)) * (\<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)) \<le> real M * (\<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2))
[PROOF STEP]
by (intro mult_right_mono) (auto simp add: card_sp)
[PROOF STATE]
proof (state)
this:
real (card (Collect small)) * (\<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)) \<le> real M * (\<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2))

goal (1 subgoal):
 1. real (card Ec) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
real (card (Collect small)) * (\<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)) \<le> real M * (\<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2))

goal (1 subgoal):
 1. real (card Ec) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have "\<dots> \<le> (\<epsilon>/4) * (?n^2)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. real M * (\<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
using \<open>M > 0\<close>
[PROOF STATE]
proof (prove)
using this:
0 < M

goal (1 subgoal):
 1. real M * (\<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
real M * (\<epsilon> / (4 * real M) * real ((card (uverts G))\<^sup>2)) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)

goal (1 subgoal):
 1. real (card Ec) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
real (card Ec) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
real (card Ec) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)

goal (1 subgoal):
 1. real (card Ec) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
.
[PROOF STATE]
proof (state)
this:
real (card Ec) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)

goal:
No subgoals!
[PROOF STEP]
qed
    \<comment>\<open>total count\<close>
[PROOF STATE]
proof (state)
this:
real (card Ec) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have prev1: "card (Ea \<union> Eb \<union> Ec) \<le> card (Ea \<union> Eb) + card Ec"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. card (Ea \<union> Eb \<union> Ec) \<le> card (Ea \<union> Eb) + card Ec
[PROOF STEP]
by (simp add: card_Un_le)
[PROOF STATE]
proof (state)
this:
card (Ea \<union> Eb \<union> Ec) \<le> card (Ea \<union> Eb) + card Ec

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
card (Ea \<union> Eb \<union> Ec) \<le> card (Ea \<union> Eb) + card Ec

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have "\<dots> \<le> card Ea + card Eb + card Ec"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. card (Ea \<union> Eb) + card Ec \<le> card Ea + card Eb + card Ec
[PROOF STEP]
by (simp add: card_Un_le)
[PROOF STATE]
proof (state)
this:
card (Ea \<union> Eb) + card Ec \<le> card Ea + card Eb + card Ec

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
card (Ea \<union> Eb) + card Ec \<le> card Ea + card Eb + card Ec

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have prev: "\<dots> \<le> (\<epsilon>/4)*(?n^2) + (\<epsilon>/2)*(?n^2) + (\<epsilon>/4)*(?n^2)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. real (card Ea + card Eb + card Ec) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2) + \<epsilon> / 2 * real ((card (uverts G))\<^sup>2) + \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
using eabound ebbound ecbound
[PROOF STATE]
proof (prove)
using this:
real (card Ea) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
real (card Eb) \<le> \<epsilon> / 2 * real ((card (uverts G))\<^sup>2)
real (card Ec) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)

goal (1 subgoal):
 1. real (card Ea + card Eb + card Ec) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2) + \<epsilon> / 2 * real ((card (uverts G))\<^sup>2) + \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
by linarith
[PROOF STATE]
proof (state)
this:
real (card Ea + card Eb + card Ec) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2) + \<epsilon> / 2 * real ((card (uverts G))\<^sup>2) + \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
(\<And>x y. x \<le> y \<Longrightarrow> real x \<le> real y) \<Longrightarrow> real (card (Ea \<union> Eb \<union> Ec)) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2) + \<epsilon> / 2 * real ((card (uverts G))\<^sup>2) + \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have cutedgesbound: "card (Ea \<union> Eb \<union> Ec) \<le> \<epsilon> * (?n^2)"
[PROOF STATE]
proof (prove)
using this:
(\<And>x y. x \<le> y \<Longrightarrow> real x \<le> real y) \<Longrightarrow> real (card (Ea \<union> Eb \<union> Ec)) \<le> \<epsilon> / 4 * real ((card (uverts G))\<^sup>2) + \<epsilon> / 2 * real ((card (uverts G))\<^sup>2) + \<epsilon> / 4 * real ((card (uverts G))\<^sup>2)

goal (1 subgoal):
 1. real (card (Ea \<union> Eb \<union> Ec)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
real (card (Ea \<union> Eb \<union> Ec)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
define Gnew where "Gnew \<equiv> (uverts G, uedges G - (Ea \<union> Eb \<union> Ec))"
[PROOF STATE]
proof (state)
this:
Gnew \<equiv> (uverts G, uedges G - (Ea \<union> Eb \<union> Ec))

goal (2 subgoals):
 1. 0 < ?\<delta>
 2. \<And>G. \<lbrakk>0 < card (uverts G); uwellformed G; real (card (triangle_set G)) \<le> ?\<delta> * real (card (uverts G) ^ 3)\<rbrakk> \<Longrightarrow> \<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
show "\<exists>Gnew. ?\<Phi> G Gnew"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<exists>Gnew. triangle_free_graph Gnew \<and> uverts Gnew = uverts G \<and> uedges Gnew \<subseteq> uedges G \<and> real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
proof (intro exI conjI)
[PROOF STATE]
proof (state)
goal (4 subgoals):
 1. triangle_free_graph ?Gnew
 2. uverts ?Gnew = uverts G
 3. uedges ?Gnew \<subseteq> uedges G
 4. real (card (uedges G - uedges ?Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
show verts: "uverts Gnew = uverts G"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. uverts Gnew = uverts G
[PROOF STEP]
by (simp add: Gnew_def)
[PROOF STATE]
proof (state)
this:
uverts Gnew = uverts G

goal (3 subgoals):
 1. triangle_free_graph Gnew
 2. uedges Gnew \<subseteq> uedges G
 3. real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have diffedges: "(Ea \<union> Eb \<union> Ec) \<subseteq> uedges G"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. Ea \<union> Eb \<union> Ec \<subseteq> uedges G
[PROOF STEP]
by (auto simp: Ea_def Eb_def Ec_def all_edges_between_def edge_def)
[PROOF STATE]
proof (state)
this:
Ea \<union> Eb \<union> Ec \<subseteq> uedges G

goal (3 subgoals):
 1. triangle_free_graph Gnew
 2. uedges Gnew \<subseteq> uedges G
 3. real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
Ea \<union> Eb \<union> Ec \<subseteq> uedges G
[PROOF STEP]
show edges: "uedges Gnew \<subseteq> uedges G"
[PROOF STATE]
proof (prove)
using this:
Ea \<union> Eb \<union> Ec \<subseteq> uedges G

goal (1 subgoal):
 1. uedges Gnew \<subseteq> uedges G
[PROOF STEP]
by (simp add: Gnew_def)
[PROOF STATE]
proof (state)
this:
uedges Gnew \<subseteq> uedges G

goal (2 subgoals):
 1. triangle_free_graph Gnew
 2. real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
uedges Gnew \<subseteq> uedges G
[PROOF STEP]
have "uedges G - (uedges Gnew) = uedges G \<inter> (Ea \<union> Eb \<union> Ec) "
[PROOF STATE]
proof (prove)
using this:
uedges Gnew \<subseteq> uedges G

goal (1 subgoal):
 1. uedges G - uedges Gnew = uedges G \<inter> (Ea \<union> Eb \<union> Ec)
[PROOF STEP]
by (simp add: Gnew_def Diff_Diff_Int)
[PROOF STATE]
proof (state)
this:
uedges G - uedges Gnew = uedges G \<inter> (Ea \<union> Eb \<union> Ec)

goal (2 subgoals):
 1. triangle_free_graph Gnew
 2. real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
uedges G - uedges Gnew = uedges G \<inter> (Ea \<union> Eb \<union> Ec)
[PROOF STEP]
have "uedges G - (uedges Gnew) = (Ea \<union> Eb \<union> Ec)"
[PROOF STATE]
proof (prove)
using this:
uedges G - uedges Gnew = uedges G \<inter> (Ea \<union> Eb \<union> Ec)

goal (1 subgoal):
 1. uedges G - uedges Gnew = Ea \<union> Eb \<union> Ec
[PROOF STEP]
using diffedges
[PROOF STATE]
proof (prove)
using this:
uedges G - uedges Gnew = uedges G \<inter> (Ea \<union> Eb \<union> Ec)
Ea \<union> Eb \<union> Ec \<subseteq> uedges G

goal (1 subgoal):
 1. uedges G - uedges Gnew = Ea \<union> Eb \<union> Ec
[PROOF STEP]
by (simp add: Int_absorb1)
[PROOF STATE]
proof (state)
this:
uedges G - uedges Gnew = Ea \<union> Eb \<union> Ec

goal (2 subgoals):
 1. triangle_free_graph Gnew
 2. real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
uedges G - uedges Gnew = Ea \<union> Eb \<union> Ec
[PROOF STEP]
have cardbound: "card (uedges G - uedges Gnew) \<le> \<epsilon> * (?n^2)"
[PROOF STATE]
proof (prove)
using this:
uedges G - uedges Gnew = Ea \<union> Eb \<union> Ec

goal (1 subgoal):
 1. real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
using cutedgesbound
[PROOF STATE]
proof (prove)
using this:
uedges G - uedges Gnew = Ea \<union> Eb \<union> Ec
real (card (Ea \<union> Eb \<union> Ec)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)

goal (1 subgoal):
 1. real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)

goal (2 subgoals):
 1. triangle_free_graph Gnew
 2. real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have graph_partition_new: "finite_graph_partition (uverts Gnew) P M"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. finite_graph_partition (uverts Gnew) P M
[PROOF STEP]
using verts
[PROOF STATE]
proof (prove)
using this:
uverts Gnew = uverts G

goal (1 subgoal):
 1. finite_graph_partition (uverts Gnew) P M
[PROOF STEP]
by (simp add: fin_part)
[PROOF STATE]
proof (state)
this:
finite_graph_partition (uverts Gnew) P M

goal (2 subgoals):
 1. triangle_free_graph Gnew
 2. real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have new_wf: "uwellformed Gnew"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. uwellformed Gnew
[PROOF STEP]
using subgraph_edge_wf verts edges wf
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>uwellformed ?G; uverts ?H = uverts ?G; uedges ?H \<subseteq> uedges ?G\<rbrakk> \<Longrightarrow> uwellformed ?H
uverts Gnew = uverts G
uedges Gnew \<subseteq> uedges G
uwellformed G

goal (1 subgoal):
 1. uwellformed Gnew
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
uwellformed Gnew

goal (2 subgoals):
 1. triangle_free_graph Gnew
 2. real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have new_fin: "finite (uverts Gnew)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. finite (uverts Gnew)
[PROOF STEP]
using verts fin
[PROOF STATE]
proof (prove)
using this:
uverts Gnew = uverts G
finite (uverts G)

goal (1 subgoal):
 1. finite (uverts Gnew)
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
finite (uverts Gnew)

goal (2 subgoals):
 1. triangle_free_graph Gnew
 2. real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
text\<open> The notes by Bell and Grodzicki are quite useful for understanding the lines below.
         See pg 4 in the middle after the summary of the min edge counts.\<close>
[PROOF STATE]
proof (state)
this:
finite (uverts Gnew)

goal (2 subgoals):
 1. triangle_free_graph Gnew
 2. real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have irreg_pairs_swap: "(R,S) \<in> irreg_pairs \<longleftrightarrow> (S, R) \<in> irreg_pairs" for R S
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ((R, S) \<in> irreg_pairs) = ((S, R) \<in> irreg_pairs)
[PROOF STEP]
by (auto simp: irreg_pairs_def regular_pair_commute)
[PROOF STATE]
proof (state)
this:
((?R, ?S) \<in> irreg_pairs) = ((?S, ?R) \<in> irreg_pairs)

goal (2 subgoals):
 1. triangle_free_graph Gnew
 2. real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have low_density_pairs_swap: "(R,S) \<in> low_density_pairs \<longleftrightarrow> (S,R) \<in> low_density_pairs" for R S
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ((R, S) \<in> low_density_pairs) = ((S, R) \<in> low_density_pairs)
[PROOF STEP]
by (simp add: low_density_pairs_def edge_density_commute edge_dense_def)
           (use all_edges_between_swap in blast)
[PROOF STATE]
proof (state)
this:
((?R, ?S) \<in> low_density_pairs) = ((?S, ?R) \<in> low_density_pairs)

goal (2 subgoals):
 1. triangle_free_graph Gnew
 2. real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have small_pairs_swap: "(R,S) \<in> small_pairs \<longleftrightarrow> (S,R) \<in> small_pairs" for R S
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. ((R, S) \<in> small_pairs) = ((S, R) \<in> small_pairs)
[PROOF STEP]
by (auto simp: small_pairs_def)
[PROOF STATE]
proof (state)
this:
((?R, ?S) \<in> small_pairs) = ((?S, ?R) \<in> small_pairs)

goal (2 subgoals):
 1. triangle_free_graph Gnew
 2. real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have all_edges_if:
        "all_edges_between R S Gnew
         = (if (R,S) \<in> irreg_pairs \<union> low_density_pairs \<union> small_pairs then {}
            else all_edges_between R S G)"
        (is "?lhs = ?rhs")
        if ij: "R \<in> P" "S \<in> P" for R S
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. all_edges_between R S Gnew = (if (R, S) \<in> irreg_pairs \<union> low_density_pairs \<union> small_pairs then {} else all_edges_between R S G)
[PROOF STEP]
proof
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. all_edges_between R S Gnew \<subseteq> (if (R, S) \<in> irreg_pairs \<union> low_density_pairs \<union> small_pairs then {} else all_edges_between R S G)
 2. (if (R, S) \<in> irreg_pairs \<union> low_density_pairs \<union> small_pairs then {} else all_edges_between R S G) \<subseteq> all_edges_between R S Gnew
[PROOF STEP]
show "?lhs \<subseteq> ?rhs"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. all_edges_between R S Gnew \<subseteq> (if (R, S) \<in> irreg_pairs \<union> low_density_pairs \<union> small_pairs then {} else all_edges_between R S G)
[PROOF STEP]
using that fin_part
[PROOF STATE]
proof (prove)
using this:
R \<in> P
S \<in> P
finite_graph_partition (uverts G) P M

goal (1 subgoal):
 1. all_edges_between R S Gnew \<subseteq> (if (R, S) \<in> irreg_pairs \<union> low_density_pairs \<union> small_pairs then {} else all_edges_between R S G)
[PROOF STEP]
unfolding Gnew_def Ea_def Eb_def Ec_def'
[PROOF STATE]
proof (prove)
using this:
R \<in> P
S \<in> P
finite_graph_partition (uverts G) P M

goal (1 subgoal):
 1. all_edges_between R S (uverts G, uedges G - ((\<Union>(R, S)\<in>irreg_pairs. edge R S) \<union> (\<Union>(i, j)\<in>low_density_pairs. edge i j) \<union> (\<Union>(x, y)\<in>small_pairs. edge x y))) \<subseteq> (if (R, S) \<in> irreg_pairs \<union> low_density_pairs \<union> small_pairs then {} else all_edges_between R S G)
[PROOF STEP]
apply (simp add: all_edges_between_E_diff all_edges_between_E_Un all_edges_between_E_UN)
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<lbrakk>R \<in> P; S \<in> P; finite_graph_partition (uverts G) P M\<rbrakk> \<Longrightarrow> ((R, S) \<in> irreg_pairs \<longrightarrow> all_edges_between R S G \<subseteq> (\<Union>i\<in>irreg_pairs. all_edges_between R S (uverts G, case i of (x, xa) \<Rightarrow> edge x xa)) \<union> (\<Union>i\<in>low_density_pairs. all_edges_between R S (uverts G, case i of (x, xa) \<Rightarrow> edge x xa)) \<union> (\<Union>i\<in>small_pairs. all_edges_between R S (uverts G, case i of (x, xa) \<Rightarrow> edge x xa))) \<and> ((R, S) \<in> low_density_pairs \<longrightarrow> all_edges_between R S G \<subseteq> (\<Union>i\<in>irreg_pairs. all_edges_between R S (uverts G, case i of (x, xa) \<Rightarrow> edge x xa)) \<union> (\<Union>i\<in>low_density_pairs. all_edges_between R S (uverts G, case i of (x, xa) \<Rightarrow> edge x xa)) \<union> (\<Union>i\<in>small_pairs. all_edges_between R S (uverts G, case i of (x, xa) \<Rightarrow> edge x xa))) \<and> ((R, S) \<in> small_pairs \<longrightarrow> all_edges_between R S G \<subseteq> (\<Union>i\<in>irreg_pairs. all_edges_between R S (uverts G, case i of (x, xa) \<Rightarrow> edge x xa)) \<union> (\<Union>i\<in>low_density_pairs. all_edges_between R S (uverts G, case i of (x, xa) \<Rightarrow> edge x xa)) \<union> (\<Union>i\<in>small_pairs. all_edges_between R S (uverts G, case i of (x, xa) \<Rightarrow> edge x xa)))
[PROOF STEP]
apply (auto simp: edge_def in_mk_uedge_img_iff all_edges_between_def)
[PROOF STATE]
proof (prove)
goal:
No subgoals!
[PROOF STEP]
done
[PROOF STATE]
proof (state)
this:
all_edges_between R S Gnew \<subseteq> (if (R, S) \<in> irreg_pairs \<union> low_density_pairs \<union> small_pairs then {} else all_edges_between R S G)

goal (1 subgoal):
 1. (if (R, S) \<in> irreg_pairs \<union> low_density_pairs \<union> small_pairs then {} else all_edges_between R S G) \<subseteq> all_edges_between R S Gnew
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. (if (R, S) \<in> irreg_pairs \<union> low_density_pairs \<union> small_pairs then {} else all_edges_between R S G) \<subseteq> all_edges_between R S Gnew
[PROOF STEP]
have Ea: "all_edges_between R S (V, Ea) = {}"
          if "(R,S) \<notin> irreg_pairs" for V
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. all_edges_between R S (V, Ea) = {}
[PROOF STEP]
using ij that P_disjnt
[PROOF STATE]
proof (prove)
using this:
R \<in> P
S \<in> P
(R, S) \<notin> irreg_pairs
\<lbrakk>?R \<noteq> ?S; ?R \<in> P; ?S \<in> P\<rbrakk> \<Longrightarrow> ?R \<inter> ?S = {}

goal (1 subgoal):
 1. all_edges_between R S (V, Ea) = {}
[PROOF STEP]
by (auto simp: Ea_def doubleton_eq_iff edge_def all_edges_between_def irreg_pairs_def;
              metis regular_pair_commute disjoint_iff_not_equal)
[PROOF STATE]
proof (state)
this:
(R, S) \<notin> irreg_pairs \<Longrightarrow> all_edges_between R S (?V, Ea) = {}

goal (1 subgoal):
 1. (if (R, S) \<in> irreg_pairs \<union> low_density_pairs \<union> small_pairs then {} else all_edges_between R S G) \<subseteq> all_edges_between R S Gnew
[PROOF STEP]
have Eb: "all_edges_between R S (V, Eb) = {}"
          if "(R,S) \<notin> low_density_pairs" for V
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. all_edges_between R S (V, Eb) = {}
[PROOF STEP]
using ij that
[PROOF STATE]
proof (prove)
using this:
R \<in> P
S \<in> P
(R, S) \<notin> low_density_pairs

goal (1 subgoal):
 1. all_edges_between R S (V, Eb) = {}
[PROOF STEP]
apply (auto simp: Eb_def edge_def all_edges_between_def low_density_pairs_def edge_dense_def)
[PROOF STATE]
proof (prove)
goal (2 subgoals):
 1. \<And>a b aa ba ab bb ac bc. \<lbrakk>R \<in> P; S \<in> P; b \<in> S; a \<in> R; aa \<in> P; ba \<in> P; \<not> \<epsilon> \<le> edge_density aa ba G * 2; ab \<in> aa; bb \<in> ba; {a, b} = {ac, bc}; ac \<in> aa; bc \<in> ba; {ac, bc} \<in> uedges G; {ab, bb} \<in> uedges G; \<forall>a. a \<in> R \<longrightarrow> (\<forall>b. b \<in> S \<longrightarrow> {a, b} \<notin> uedges G)\<rbrakk> \<Longrightarrow> False
 2. \<And>a b aa ba ab bb ac bc. \<lbrakk>R \<in> P; S \<in> P; b \<in> S; a \<in> R; aa \<in> P; ba \<in> P; \<not> \<epsilon> \<le> edge_density aa ba G * 2; ab \<in> aa; bb \<in> ba; {a, b} = {ac, bc}; ac \<in> aa; bc \<in> ba; {ac, bc} \<in> uedges G; {ab, bb} \<in> uedges G; \<epsilon> \<le> edge_density R S G * 2\<rbrakk> \<Longrightarrow> False
[PROOF STEP]
apply metis
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<And>a b aa ba ab bb ac bc. \<lbrakk>R \<in> P; S \<in> P; b \<in> S; a \<in> R; aa \<in> P; ba \<in> P; \<not> \<epsilon> \<le> edge_density aa ba G * 2; ab \<in> aa; bb \<in> ba; {a, b} = {ac, bc}; ac \<in> aa; bc \<in> ba; {ac, bc} \<in> uedges G; {ab, bb} \<in> uedges G; \<epsilon> \<le> edge_density R S G * 2\<rbrakk> \<Longrightarrow> False
[PROOF STEP]
by (metis IntI P_disjnt doubleton_eq_iff edge_density_commute equals0D)
[PROOF STATE]
proof (state)
this:
(R, S) \<notin> low_density_pairs \<Longrightarrow> all_edges_between R S (?V, Eb) = {}

goal (1 subgoal):
 1. (if (R, S) \<in> irreg_pairs \<union> low_density_pairs \<union> small_pairs then {} else all_edges_between R S G) \<subseteq> all_edges_between R S Gnew
[PROOF STEP]
have Ec: "all_edges_between R S (V, Ec) = {}"
          if "(R,S) \<notin> small_pairs" for V
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. all_edges_between R S (V, Ec) = {}
[PROOF STEP]
using ij that
[PROOF STATE]
proof (prove)
using this:
R \<in> P
S \<in> P
(R, S) \<notin> small_pairs

goal (1 subgoal):
 1. all_edges_between R S (V, Ec) = {}
[PROOF STEP]
by (auto simp: Ec_def' doubleton_eq_iff edge_def all_edges_between_def small_pairs_def;
              metis P_disjnt disjoint_iff)
[PROOF STATE]
proof (state)
this:
(R, S) \<notin> small_pairs \<Longrightarrow> all_edges_between R S (?V, Ec) = {}

goal (1 subgoal):
 1. (if (R, S) \<in> irreg_pairs \<union> low_density_pairs \<union> small_pairs then {} else all_edges_between R S G) \<subseteq> all_edges_between R S Gnew
[PROOF STEP]
show "?rhs \<subseteq> ?lhs"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (if (R, S) \<in> irreg_pairs \<union> low_density_pairs \<union> small_pairs then {} else all_edges_between R S G) \<subseteq> all_edges_between R S Gnew
[PROOF STEP]
by (auto simp add: Gnew_def Ea Eb Ec all_edges_between_E_diff all_edges_between_E_Un)
[PROOF STATE]
proof (state)
this:
(if (R, S) \<in> irreg_pairs \<union> low_density_pairs \<union> small_pairs then {} else all_edges_between R S G) \<subseteq> all_edges_between R S Gnew

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<lbrakk>?R \<in> P; ?S \<in> P\<rbrakk> \<Longrightarrow> all_edges_between ?R ?S Gnew = (if (?R, ?S) \<in> irreg_pairs \<union> low_density_pairs \<union> small_pairs then {} else all_edges_between ?R ?S G)

goal (2 subgoals):
 1. triangle_free_graph Gnew
 2. real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have rp: "regular_pair R S Gnew (\<epsilon>/4)" if ij: "R \<in> P" "S \<in> P"  for R S
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. regular_pair R S Gnew (\<epsilon> / 4)
[PROOF STEP]
proof (cases "(R,S) \<in> irreg_pairs")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. (R, S) \<in> irreg_pairs \<Longrightarrow> regular_pair R S Gnew (\<epsilon> / 4)
 2. (R, S) \<notin> irreg_pairs \<Longrightarrow> regular_pair R S Gnew (\<epsilon> / 4)
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
(R, S) \<notin> irreg_pairs

goal (2 subgoals):
 1. (R, S) \<in> irreg_pairs \<Longrightarrow> regular_pair R S Gnew (\<epsilon> / 4)
 2. (R, S) \<notin> irreg_pairs \<Longrightarrow> regular_pair R S Gnew (\<epsilon> / 4)
[PROOF STEP]
have ed: "edge_density X Y Gnew =
            (if (R,S) \<in> irreg_pairs \<union> low_density_pairs \<union> small_pairs then 0
             else edge_density X Y G)"
          if "X \<subseteq> R" "Y \<subseteq> S" for X Y
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. edge_density X Y Gnew = (if (R, S) \<in> irreg_pairs \<union> low_density_pairs \<union> small_pairs then 0 else edge_density X Y G)
[PROOF STEP]
using all_edges_if that ij False
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>?R \<in> P; ?S \<in> P\<rbrakk> \<Longrightarrow> all_edges_between ?R ?S Gnew = (if (?R, ?S) \<in> irreg_pairs \<union> low_density_pairs \<union> small_pairs then {} else all_edges_between ?R ?S G)
X \<subseteq> R
Y \<subseteq> S
R \<in> P
S \<in> P
(R, S) \<notin> irreg_pairs

goal (1 subgoal):
 1. edge_density X Y Gnew = (if (R, S) \<in> irreg_pairs \<union> low_density_pairs \<union> small_pairs then 0 else edge_density X Y G)
[PROOF STEP]
by (smt (verit) all_edges_preserved edge_density_eq0 edge_density_def)
[PROOF STATE]
proof (state)
this:
\<lbrakk>?X \<subseteq> R; ?Y \<subseteq> S\<rbrakk> \<Longrightarrow> edge_density ?X ?Y Gnew = (if (R, S) \<in> irreg_pairs \<union> low_density_pairs \<union> small_pairs then 0 else edge_density ?X ?Y G)

goal (2 subgoals):
 1. (R, S) \<in> irreg_pairs \<Longrightarrow> regular_pair R S Gnew (\<epsilon> / 4)
 2. (R, S) \<notin> irreg_pairs \<Longrightarrow> regular_pair R S Gnew (\<epsilon> / 4)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. regular_pair R S Gnew (\<epsilon> / 4)
[PROOF STEP]
using that False \<open>\<epsilon> > 0\<close>
[PROOF STATE]
proof (prove)
using this:
R \<in> P
S \<in> P
(R, S) \<notin> irreg_pairs
0 < \<epsilon>

goal (1 subgoal):
 1. regular_pair R S Gnew (\<epsilon> / 4)
[PROOF STEP]
by (auto simp add: irreg_pairs_def regular_pair_def less_le ed)
[PROOF STATE]
proof (state)
this:
regular_pair R S Gnew (\<epsilon> / 4)

goal (1 subgoal):
 1. (R, S) \<in> irreg_pairs \<Longrightarrow> regular_pair R S Gnew (\<epsilon> / 4)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. (R, S) \<in> irreg_pairs \<Longrightarrow> regular_pair R S Gnew (\<epsilon> / 4)
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
(R, S) \<in> irreg_pairs

goal (1 subgoal):
 1. (R, S) \<in> irreg_pairs \<Longrightarrow> regular_pair R S Gnew (\<epsilon> / 4)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
(R, S) \<in> irreg_pairs
[PROOF STEP]
have ed: "edge_density X Y Gnew = 0"  if "X \<subseteq> R" "Y \<subseteq> S" for X Y
[PROOF STATE]
proof (prove)
using this:
(R, S) \<in> irreg_pairs

goal (1 subgoal):
 1. edge_density X Y Gnew = 0
[PROOF STEP]
by (meson edge_density_eq0 all_edges_if that \<open>R \<in> P\<close> \<open>S \<in> P\<close> UnCI)
[PROOF STATE]
proof (state)
this:
\<lbrakk>?X \<subseteq> R; ?Y \<subseteq> S\<rbrakk> \<Longrightarrow> edge_density ?X ?Y Gnew = 0

goal (1 subgoal):
 1. (R, S) \<in> irreg_pairs \<Longrightarrow> regular_pair R S Gnew (\<epsilon> / 4)
[PROOF STEP]
with egt that
[PROOF STATE]
proof (chain)
picking this:
0 < \<epsilon>
R \<in> P
S \<in> P
\<lbrakk>?X \<subseteq> R; ?Y \<subseteq> S\<rbrakk> \<Longrightarrow> edge_density ?X ?Y Gnew = 0
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
0 < \<epsilon>
R \<in> P
S \<in> P
\<lbrakk>?X \<subseteq> R; ?Y \<subseteq> S\<rbrakk> \<Longrightarrow> edge_density ?X ?Y Gnew = 0

goal (1 subgoal):
 1. regular_pair R S Gnew (\<epsilon> / 4)
[PROOF STEP]
by (auto simp: regular_pair_def ed)
[PROOF STATE]
proof (state)
this:
regular_pair R S Gnew (\<epsilon> / 4)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<lbrakk>?R \<in> P; ?S \<in> P\<rbrakk> \<Longrightarrow> regular_pair ?R ?S Gnew (\<epsilon> / 4)

goal (2 subgoals):
 1. triangle_free_graph Gnew
 2. real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
\<lbrakk>?R \<in> P; ?S \<in> P\<rbrakk> \<Longrightarrow> regular_pair ?R ?S Gnew (\<epsilon> / 4)
[PROOF STEP]
have reg_pairs: "regular_graph P Gnew (\<epsilon>/4)"
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>?R \<in> P; ?S \<in> P\<rbrakk> \<Longrightarrow> regular_pair ?R ?S Gnew (\<epsilon> / 4)

goal (1 subgoal):
 1. regular_graph P Gnew (\<epsilon> / 4)
[PROOF STEP]
by (meson regular_graph_def)
[PROOF STATE]
proof (state)
this:
regular_graph P Gnew (\<epsilon> / 4)

goal (2 subgoals):
 1. triangle_free_graph Gnew
 2. real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have "edge_dense R S Gnew (\<epsilon>/2)"
        if "R \<in> P" "S \<in> P" for R S
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. edge_dense R S Gnew (\<epsilon> / 2)
[PROOF STEP]
proof (cases "(R,S) \<in> low_density_pairs")
[PROOF STATE]
proof (state)
goal (2 subgoals):
 1. (R, S) \<in> low_density_pairs \<Longrightarrow> edge_dense R S Gnew (\<epsilon> / 2)
 2. (R, S) \<notin> low_density_pairs \<Longrightarrow> edge_dense R S Gnew (\<epsilon> / 2)
[PROOF STEP]
case False
[PROOF STATE]
proof (state)
this:
(R, S) \<notin> low_density_pairs

goal (2 subgoals):
 1. (R, S) \<in> low_density_pairs \<Longrightarrow> edge_dense R S Gnew (\<epsilon> / 2)
 2. (R, S) \<notin> low_density_pairs \<Longrightarrow> edge_dense R S Gnew (\<epsilon> / 2)
[PROOF STEP]
have ed: "edge_density R S Gnew =
            (if (R,S) \<in> irreg_pairs \<union> low_density_pairs \<union> small_pairs then 0
             else edge_density R S G)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. edge_density R S Gnew = (if (R, S) \<in> irreg_pairs \<union> low_density_pairs \<union> small_pairs then 0 else edge_density R S G)
[PROOF STEP]
using all_edges_if that that
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>?R \<in> P; ?S \<in> P\<rbrakk> \<Longrightarrow> all_edges_between ?R ?S Gnew = (if (?R, ?S) \<in> irreg_pairs \<union> low_density_pairs \<union> small_pairs then {} else all_edges_between ?R ?S G)
R \<in> P
S \<in> P
R \<in> P
S \<in> P

goal (1 subgoal):
 1. edge_density R S Gnew = (if (R, S) \<in> irreg_pairs \<union> low_density_pairs \<union> small_pairs then 0 else edge_density R S G)
[PROOF STEP]
by (simp add: edge_density_def)
[PROOF STATE]
proof (state)
this:
edge_density R S Gnew = (if (R, S) \<in> irreg_pairs \<union> low_density_pairs \<union> small_pairs then 0 else edge_density R S G)

goal (2 subgoals):
 1. (R, S) \<in> low_density_pairs \<Longrightarrow> edge_dense R S Gnew (\<epsilon> / 2)
 2. (R, S) \<notin> low_density_pairs \<Longrightarrow> edge_dense R S Gnew (\<epsilon> / 2)
[PROOF STEP]
with that \<open>\<epsilon> > 0\<close> False
[PROOF STATE]
proof (chain)
picking this:
R \<in> P
S \<in> P
0 < \<epsilon>
(R, S) \<notin> low_density_pairs
edge_density R S Gnew = (if (R, S) \<in> irreg_pairs \<union> low_density_pairs \<union> small_pairs then 0 else edge_density R S G)
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
R \<in> P
S \<in> P
0 < \<epsilon>
(R, S) \<notin> low_density_pairs
edge_density R S Gnew = (if (R, S) \<in> irreg_pairs \<union> low_density_pairs \<union> small_pairs then 0 else edge_density R S G)

goal (1 subgoal):
 1. edge_dense R S Gnew (\<epsilon> / 2)
[PROOF STEP]
by (auto simp: low_density_pairs_def edge_dense_def all_edges_if)
[PROOF STATE]
proof (state)
this:
edge_dense R S Gnew (\<epsilon> / 2)

goal (1 subgoal):
 1. (R, S) \<in> low_density_pairs \<Longrightarrow> edge_dense R S Gnew (\<epsilon> / 2)
[PROOF STEP]
next
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. (R, S) \<in> low_density_pairs \<Longrightarrow> edge_dense R S Gnew (\<epsilon> / 2)
[PROOF STEP]
case True
[PROOF STATE]
proof (state)
this:
(R, S) \<in> low_density_pairs

goal (1 subgoal):
 1. (R, S) \<in> low_density_pairs \<Longrightarrow> edge_dense R S Gnew (\<epsilon> / 2)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
(R, S) \<in> low_density_pairs
[PROOF STEP]
have "edge_density R S Gnew = 0"
[PROOF STATE]
proof (prove)
using this:
(R, S) \<in> low_density_pairs

goal (1 subgoal):
 1. edge_density R S Gnew = 0
[PROOF STEP]
by (simp add: all_edges_if edge_density_def that)
[PROOF STATE]
proof (state)
this:
edge_density R S Gnew = 0

goal (1 subgoal):
 1. (R, S) \<in> low_density_pairs \<Longrightarrow> edge_dense R S Gnew (\<epsilon> / 2)
[PROOF STEP]
with \<open>\<epsilon> > 0\<close> that
[PROOF STATE]
proof (chain)
picking this:
0 < \<epsilon>
R \<in> P
S \<in> P
edge_density R S Gnew = 0
[PROOF STEP]
show ?thesis
[PROOF STATE]
proof (prove)
using this:
0 < \<epsilon>
R \<in> P
S \<in> P
edge_density R S Gnew = 0

goal (1 subgoal):
 1. edge_dense R S Gnew (\<epsilon> / 2)
[PROOF STEP]
by (simp add: True all_edges_if edge_dense_def)
[PROOF STATE]
proof (state)
this:
edge_dense R S Gnew (\<epsilon> / 2)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<lbrakk>?R \<in> P; ?S \<in> P\<rbrakk> \<Longrightarrow> edge_dense ?R ?S Gnew (\<epsilon> / 2)

goal (2 subgoals):
 1. triangle_free_graph Gnew
 2. real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
\<lbrakk>?R \<in> P; ?S \<in> P\<rbrakk> \<Longrightarrow> edge_dense ?R ?S Gnew (\<epsilon> / 2)
[PROOF STEP]
have density_bound: "dense_graph P Gnew (\<epsilon>/2)"
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>?R \<in> P; ?S \<in> P\<rbrakk> \<Longrightarrow> edge_dense ?R ?S Gnew (\<epsilon> / 2)

goal (1 subgoal):
 1. dense_graph P Gnew (\<epsilon> / 2)
[PROOF STEP]
by (meson dense_graph_def)
[PROOF STATE]
proof (state)
this:
dense_graph P Gnew (\<epsilon> / 2)

goal (2 subgoals):
 1. triangle_free_graph Gnew
 2. real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
have min_subset_size: "decent_graph P Gnew (?e4M * ?n)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. decent_graph P Gnew (\<epsilon> / (4 * real M) * real (card (uverts G)))
[PROOF STEP]
using \<open>\<epsilon> > 0\<close>
[PROOF STATE]
proof (prove)
using this:
0 < \<epsilon>

goal (1 subgoal):
 1. decent_graph P Gnew (\<epsilon> / (4 * real M) * real (card (uverts G)))
[PROOF STEP]
by (auto simp: decent_graph_def small_pairs_def small_def decent_def all_edges_if)
[PROOF STATE]
proof (state)
this:
decent_graph P Gnew (\<epsilon> / (4 * real M) * real (card (uverts G)))

goal (2 subgoals):
 1. triangle_free_graph Gnew
 2. real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
show "triangle_free_graph Gnew"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. triangle_free_graph Gnew
[PROOF STEP]
proof (rule ccontr)
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<not> triangle_free_graph Gnew \<Longrightarrow> False
[PROOF STEP]
assume non: "\<not>?thesis"
[PROOF STATE]
proof (state)
this:
\<not> triangle_free_graph Gnew

goal (1 subgoal):
 1. \<not> triangle_free_graph Gnew \<Longrightarrow> False
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
\<not> triangle_free_graph Gnew
[PROOF STEP]
obtain x y z where trig_ex: "triangle_in_graph x y z Gnew"
[PROOF STATE]
proof (prove)
using this:
\<not> triangle_free_graph Gnew

goal (1 subgoal):
 1. (\<And>x y z. triangle_in_graph x y z Gnew \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
using triangle_free_graph_def non
[PROOF STATE]
proof (prove)
using this:
\<not> triangle_free_graph Gnew
triangle_free_graph ?G \<equiv> \<nexists>x y z. triangle_in_graph x y z ?G
\<not> triangle_free_graph Gnew

goal (1 subgoal):
 1. (\<And>x y z. triangle_in_graph x y z Gnew \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
triangle_in_graph x y z Gnew

goal (1 subgoal):
 1. \<not> triangle_free_graph Gnew \<Longrightarrow> False
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
triangle_in_graph x y z Gnew
[PROOF STEP]
have xin: "x \<in> (uverts Gnew)" and yin: "y \<in> (uverts Gnew)" and zin: "z \<in> (uverts Gnew)"
[PROOF STATE]
proof (prove)
using this:
triangle_in_graph x y z Gnew

goal (1 subgoal):
 1. x \<in> uverts Gnew &&& y \<in> uverts Gnew &&& z \<in> uverts Gnew
[PROOF STEP]
using triangle_in_graph_verts new_wf
[PROOF STATE]
proof (prove)
using this:
triangle_in_graph x y z Gnew
\<lbrakk>uwellformed ?G; triangle_in_graph ?x ?y ?z ?G\<rbrakk> \<Longrightarrow> ?x \<in> uverts ?G
\<lbrakk>uwellformed ?G; triangle_in_graph ?x ?y ?z ?G\<rbrakk> \<Longrightarrow> ?y \<in> uverts ?G
\<lbrakk>uwellformed ?G; triangle_in_graph ?x ?y ?z ?G\<rbrakk> \<Longrightarrow> ?z \<in> uverts ?G
uwellformed Gnew

goal (1 subgoal):
 1. x \<in> uverts Gnew &&& y \<in> uverts Gnew &&& z \<in> uverts Gnew
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
x \<in> uverts Gnew
y \<in> uverts Gnew
z \<in> uverts Gnew

goal (1 subgoal):
 1. \<not> triangle_free_graph Gnew \<Longrightarrow> False
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
x \<in> uverts Gnew
y \<in> uverts Gnew
z \<in> uverts Gnew
[PROOF STEP]
obtain R S T where xinp: "x \<in> R" and ilt: "R\<in>P" and yinp: "y \<in> S" and jlt: "S\<in>P"
                          and zinp: "z \<in> T" and klt: "T\<in>P"
[PROOF STATE]
proof (prove)
using this:
x \<in> uverts Gnew
y \<in> uverts Gnew
z \<in> uverts Gnew

goal (1 subgoal):
 1. (\<And>R S T. \<lbrakk>x \<in> R; R \<in> P; y \<in> S; S \<in> P; z \<in> T; T \<in> P\<rbrakk> \<Longrightarrow> thesis) \<Longrightarrow> thesis
[PROOF STEP]
by (metis graph_partition_new xin Union_iff finite_graph_partition_equals)
[PROOF STATE]
proof (state)
this:
x \<in> R
R \<in> P
y \<in> S
S \<in> P
z \<in> T
T \<in> P

goal (1 subgoal):
 1. \<not> triangle_free_graph Gnew \<Longrightarrow> False
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
x \<in> R
R \<in> P
y \<in> S
S \<in> P
z \<in> T
T \<in> P
[PROOF STEP]
have finitesubsets: "finite R" "finite S" "finite T"
[PROOF STATE]
proof (prove)
using this:
x \<in> R
R \<in> P
y \<in> S
S \<in> P
z \<in> T
T \<in> P

goal (1 subgoal):
 1. finite R &&& finite S &&& finite T
[PROOF STEP]
using new_fin fin_part finite_graph_partition_finite fin
[PROOF STATE]
proof (prove)
using this:
x \<in> R
R \<in> P
y \<in> S
S \<in> P
z \<in> T
T \<in> P
finite (uverts Gnew)
finite_graph_partition (uverts G) P M
\<lbrakk>finite_graph_partition ?V ?P ?k; finite ?V; ?X \<in> ?P\<rbrakk> \<Longrightarrow> finite ?X
finite (uverts G)

goal (1 subgoal):
 1. finite R &&& finite S &&& finite T
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
finite R
finite S
finite T

goal (1 subgoal):
 1. \<not> triangle_free_graph Gnew \<Longrightarrow> False
[PROOF STEP]
have subsets: "R \<subseteq> uverts Gnew" "S \<subseteq> uverts Gnew" "T \<subseteq> uverts Gnew"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. R \<subseteq> uverts Gnew &&& S \<subseteq> uverts Gnew &&& T \<subseteq> uverts Gnew
[PROOF STEP]
using finite_graph_partition_subset ilt jlt klt graph_partition_new
[PROOF STATE]
proof (prove)
using this:
\<lbrakk>finite_graph_partition ?V ?P ?n; ?X \<in> ?P\<rbrakk> \<Longrightarrow> ?X \<subseteq> ?V
R \<in> P
S \<in> P
T \<in> P
finite_graph_partition (uverts Gnew) P M

goal (1 subgoal):
 1. R \<subseteq> uverts Gnew &&& S \<subseteq> uverts Gnew &&& T \<subseteq> uverts Gnew
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
R \<subseteq> uverts Gnew
S \<subseteq> uverts Gnew
T \<subseteq> uverts Gnew

goal (1 subgoal):
 1. \<not> triangle_free_graph Gnew \<Longrightarrow> False
[PROOF STEP]
have min_sizes: "card R \<ge> ?e4M*?n" "card S \<ge> ?e4M*?n" "card T \<ge> ?e4M*?n"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<epsilon> / (4 * real M) * real (card (uverts G)) \<le> real (card R) &&& \<epsilon> / (4 * real M) * real (card (uverts G)) \<le> real (card S) &&& \<epsilon> / (4 * real M) * real (card (uverts G)) \<le> real (card T)
[PROOF STEP]
using trig_ex min_subset_size xinp yinp zinp ilt jlt klt
[PROOF STATE]
proof (prove)
using this:
triangle_in_graph x y z Gnew
decent_graph P Gnew (\<epsilon> / (4 * real M) * real (card (uverts G)))
x \<in> R
y \<in> S
z \<in> T
R \<in> P
S \<in> P
T \<in> P

goal (1 subgoal):
 1. \<epsilon> / (4 * real M) * real (card (uverts G)) \<le> real (card R) &&& \<epsilon> / (4 * real M) * real (card (uverts G)) \<le> real (card S) &&& \<epsilon> / (4 * real M) * real (card (uverts G)) \<le> real (card T)
[PROOF STEP]
by (auto simp: triangle_in_graph_def decent_graph_def decent_def all_edges_between_def)
[PROOF STATE]
proof (state)
this:
\<epsilon> / (4 * real M) * real (card (uverts G)) \<le> real (card R)
\<epsilon> / (4 * real M) * real (card (uverts G)) \<le> real (card S)
\<epsilon> / (4 * real M) * real (card (uverts G)) \<le> real (card T)

goal (1 subgoal):
 1. \<not> triangle_free_graph Gnew \<Longrightarrow> False
[PROOF STEP]
have min_dens: "edge_density R S Gnew \<ge> \<epsilon>/2" "edge_density R T Gnew \<ge> \<epsilon>/2" "edge_density S T Gnew \<ge> \<epsilon>/2"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<epsilon> / 2 \<le> edge_density R S Gnew &&& \<epsilon> / 2 \<le> edge_density R T Gnew &&& \<epsilon> / 2 \<le> edge_density S T Gnew
[PROOF STEP]
using density_bound ilt jlt klt xinp yinp zinp trig_ex
[PROOF STATE]
proof (prove)
using this:
dense_graph P Gnew (\<epsilon> / 2)
R \<in> P
S \<in> P
T \<in> P
x \<in> R
y \<in> S
z \<in> T
triangle_in_graph x y z Gnew

goal (1 subgoal):
 1. \<epsilon> / 2 \<le> edge_density R S Gnew &&& \<epsilon> / 2 \<le> edge_density R T Gnew &&& \<epsilon> / 2 \<le> edge_density S T Gnew
[PROOF STEP]
by (auto simp: dense_graph_def edge_dense_def all_edges_between_def triangle_in_graph_def)
[PROOF STATE]
proof (state)
this:
\<epsilon> / 2 \<le> edge_density R S Gnew
\<epsilon> / 2 \<le> edge_density R T Gnew
\<epsilon> / 2 \<le> edge_density S T Gnew

goal (1 subgoal):
 1. \<not> triangle_free_graph Gnew \<Longrightarrow> False
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
\<epsilon> / 2 \<le> edge_density R S Gnew
\<epsilon> / 2 \<le> edge_density R T Gnew
\<epsilon> / 2 \<le> edge_density S T Gnew
[PROOF STEP]
have min_dens_diff:
          "edge_density R S Gnew - \<epsilon>/4 \<ge> \<epsilon>/4" "edge_density R T Gnew - \<epsilon>/4 \<ge> \<epsilon>/4" "edge_density S T Gnew - \<epsilon>/4 \<ge> \<epsilon>/4"
[PROOF STATE]
proof (prove)
using this:
\<epsilon> / 2 \<le> edge_density R S Gnew
\<epsilon> / 2 \<le> edge_density R T Gnew
\<epsilon> / 2 \<le> edge_density S T Gnew

goal (1 subgoal):
 1. \<epsilon> / 4 \<le> edge_density R S Gnew - \<epsilon> / 4 &&& \<epsilon> / 4 \<le> edge_density R T Gnew - \<epsilon> / 4 &&& \<epsilon> / 4 \<le> edge_density S T Gnew - \<epsilon> / 4
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
\<epsilon> / 4 \<le> edge_density R S Gnew - \<epsilon> / 4
\<epsilon> / 4 \<le> edge_density R T Gnew - \<epsilon> / 4
\<epsilon> / 4 \<le> edge_density S T Gnew - \<epsilon> / 4

goal (1 subgoal):
 1. \<not> triangle_free_graph Gnew \<Longrightarrow> False
[PROOF STEP]
have mincard0: "(card R) * (card S) * (card T) \<ge> 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 \<le> card R * card S * card T
[PROOF STEP]
by simp
[PROOF STATE]
proof (state)
this:
0 \<le> card R * card S * card T

goal (1 subgoal):
 1. \<not> triangle_free_graph Gnew \<Longrightarrow> False
[PROOF STEP]
have gtcube: "((edge_density R S Gnew) - \<epsilon>/4)*((edge_density R T Gnew) - \<epsilon>/4) *((edge_density S T Gnew) - \<epsilon>/4) \<ge> (\<epsilon>/4)^3"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (\<epsilon> / 4) ^ 3 \<le> (edge_density R S Gnew - \<epsilon> / 4) * (edge_density R T Gnew - \<epsilon> / 4) * (edge_density S T Gnew - \<epsilon> / 4)
[PROOF STEP]
using min_dens_diff e4gt real_mult_gt_cube
[PROOF STATE]
proof (prove)
using this:
\<epsilon> / 4 \<le> edge_density R S Gnew - \<epsilon> / 4
\<epsilon> / 4 \<le> edge_density R T Gnew - \<epsilon> / 4
\<epsilon> / 4 \<le> edge_density S T Gnew - \<epsilon> / 4
0 < \<epsilon> / 4
\<lbrakk>?X \<le> ?A; ?X \<le> ?B; ?X \<le> ?C; 0 \<le> ?X\<rbrakk> \<Longrightarrow> ?X ^ 3 \<le> ?A * ?B * ?C

goal (1 subgoal):
 1. (\<epsilon> / 4) ^ 3 \<le> (edge_density R S Gnew - \<epsilon> / 4) * (edge_density R T Gnew - \<epsilon> / 4) * (edge_density S T Gnew - \<epsilon> / 4)
[PROOF STEP]
by auto
[PROOF STATE]
proof (state)
this:
(\<epsilon> / 4) ^ 3 \<le> (edge_density R S Gnew - \<epsilon> / 4) * (edge_density R T Gnew - \<epsilon> / 4) * (edge_density S T Gnew - \<epsilon> / 4)

goal (1 subgoal):
 1. \<not> triangle_free_graph Gnew \<Longrightarrow> False
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
(\<epsilon> / 4) ^ 3 \<le> (edge_density R S Gnew - \<epsilon> / 4) * (edge_density R T Gnew - \<epsilon> / 4) * (edge_density S T Gnew - \<epsilon> / 4)
[PROOF STEP]
have c1: "((edge_density R S Gnew) - \<epsilon>/4)*((edge_density R T Gnew) - \<epsilon>/4) *((edge_density S T Gnew) - \<epsilon>/4) \<ge> 0"
[PROOF STATE]
proof (prove)
using this:
(\<epsilon> / 4) ^ 3 \<le> (edge_density R S Gnew - \<epsilon> / 4) * (edge_density R T Gnew - \<epsilon> / 4) * (edge_density S T Gnew - \<epsilon> / 4)

goal (1 subgoal):
 1. 0 \<le> (edge_density R S Gnew - \<epsilon> / 4) * (edge_density R T Gnew - \<epsilon> / 4) * (edge_density S T Gnew - \<epsilon> / 4)
[PROOF STEP]
by (smt (verit) e4gt zero_less_power)
[PROOF STATE]
proof (state)
this:
0 \<le> (edge_density R S Gnew - \<epsilon> / 4) * (edge_density R T Gnew - \<epsilon> / 4) * (edge_density S T Gnew - \<epsilon> / 4)

goal (1 subgoal):
 1. \<not> triangle_free_graph Gnew \<Longrightarrow> False
[PROOF STEP]
have "?e4M * ?n \<ge> 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 \<le> \<epsilon> / (4 * real M) * real (card (uverts G))
[PROOF STEP]
using egt
[PROOF STATE]
proof (prove)
using this:
0 < \<epsilon>

goal (1 subgoal):
 1. 0 \<le> \<epsilon> / (4 * real M) * real (card (uverts G))
[PROOF STEP]
by force
[PROOF STATE]
proof (state)
this:
0 \<le> \<epsilon> / (4 * real M) * real (card (uverts G))

goal (1 subgoal):
 1. \<not> triangle_free_graph Gnew \<Longrightarrow> False
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
0 \<le> \<epsilon> / (4 * real M) * real (card (uverts G))
[PROOF STEP]
have "card R * card S * card T \<ge> (?e4M * ?n)^3"
[PROOF STATE]
proof (prove)
using this:
0 \<le> \<epsilon> / (4 * real M) * real (card (uverts G))

goal (1 subgoal):
 1. (\<epsilon> / (4 * real M) * real (card (uverts G))) ^ 3 \<le> real (card R * card S * card T)
[PROOF STEP]
by (metis min_sizes of_nat_mult real_mult_gt_cube)
[PROOF STATE]
proof (state)
this:
(\<epsilon> / (4 * real M) * real (card (uverts G))) ^ 3 \<le> real (card R * card S * card T)

goal (1 subgoal):
 1. \<not> triangle_free_graph Gnew \<Longrightarrow> False
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
(\<epsilon> / (4 * real M) * real (card (uverts G))) ^ 3 \<le> real (card R * card S * card T)
[PROOF STEP]
have cardgtbound:"card R * card S * card T \<ge> ?e4M^ 3 * ?n^3"
[PROOF STATE]
proof (prove)
using this:
(\<epsilon> / (4 * real M) * real (card (uverts G))) ^ 3 \<le> real (card R * card S * card T)

goal (1 subgoal):
 1. (\<epsilon> / (4 * real M)) ^ 3 * real (card (uverts G) ^ 3) \<le> real (card R * card S * card T)
[PROOF STEP]
by (metis of_nat_power power_mult_distrib)
[PROOF STATE]
proof (state)
this:
(\<epsilon> / (4 * real M)) ^ 3 * real (card (uverts G) ^ 3) \<le> real (card R * card S * card T)

goal (1 subgoal):
 1. \<not> triangle_free_graph Gnew \<Longrightarrow> False
[PROOF STEP]
have "(1-\<epsilon>/2) * (\<epsilon>/4)^3 * (\<epsilon>/(4*M))^3 * ?n^3 \<le> (1-\<epsilon>/2) * (\<epsilon>/4)^3 * card R * card S * card T"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (1 - \<epsilon> / 2) * (\<epsilon> / 4) ^ 3 * (\<epsilon> / real (4 * M)) ^ 3 * real (card (uverts G) ^ 3) \<le> (1 - \<epsilon> / 2) * (\<epsilon> / 4) ^ 3 * real (card R) * real (card S) * real (card T)
[PROOF STEP]
using cardgtbound ordered_comm_semiring_class.comm_mult_left_mono True e4gt
[PROOF STATE]
proof (prove)
using this:
(\<epsilon> / (4 * real M)) ^ 3 * real (card (uverts G) ^ 3) \<le> real (card R * card S * card T)
\<lbrakk>?a \<le> ?b; (0::?'a) \<le> ?c\<rbrakk> \<Longrightarrow> ?c * ?a \<le> ?c * ?b
\<epsilon> < 1
0 < \<epsilon> / 4

goal (1 subgoal):
 1. (1 - \<epsilon> / 2) * (\<epsilon> / 4) ^ 3 * (\<epsilon> / real (4 * M)) ^ 3 * real (card (uverts G) ^ 3) \<le> (1 - \<epsilon> / 2) * (\<epsilon> / 4) ^ 3 * real (card R) * real (card S) * real (card T)
[PROOF STEP]
by fastforce
[PROOF STATE]
proof (state)
this:
(1 - \<epsilon> / 2) * (\<epsilon> / 4) ^ 3 * (\<epsilon> / real (4 * M)) ^ 3 * real (card (uverts G) ^ 3) \<le> (1 - \<epsilon> / 2) * (\<epsilon> / 4) ^ 3 * real (card R) * real (card S) * real (card T)

goal (1 subgoal):
 1. \<not> triangle_free_graph Gnew \<Longrightarrow> False
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(1 - \<epsilon> / 2) * (\<epsilon> / 4) ^ 3 * (\<epsilon> / real (4 * M)) ^ 3 * real (card (uverts G) ^ 3) \<le> (1 - \<epsilon> / 2) * (\<epsilon> / 4) ^ 3 * real (card R) * real (card S) * real (card T)

goal (1 subgoal):
 1. \<not> triangle_free_graph Gnew \<Longrightarrow> False
[PROOF STEP]
have "... \<le> (1-2*(\<epsilon>/4)) * (edge_density R S Gnew - \<epsilon>/4) * (edge_density R T Gnew - \<epsilon>/4)
                        * (edge_density S T Gnew - \<epsilon>/4) * card R * card S * card T"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (1 - \<epsilon> / 2) * (\<epsilon> / 4) ^ 3 * real (card R) * real (card S) * real (card T) \<le> (1 - 2 * (\<epsilon> / 4)) * (edge_density R S Gnew - \<epsilon> / 4) * (edge_density R T Gnew - \<epsilon> / 4) * (edge_density S T Gnew - \<epsilon> / 4) * real (card R) * real (card S) * real (card T)
[PROOF STEP]
using gtcube c1 \<open>\<epsilon> < 1\<close> mincard0
[PROOF STATE]
proof (prove)
using this:
(\<epsilon> / 4) ^ 3 \<le> (edge_density R S Gnew - \<epsilon> / 4) * (edge_density R T Gnew - \<epsilon> / 4) * (edge_density S T Gnew - \<epsilon> / 4)
0 \<le> (edge_density R S Gnew - \<epsilon> / 4) * (edge_density R T Gnew - \<epsilon> / 4) * (edge_density S T Gnew - \<epsilon> / 4)
\<epsilon> < 1
0 \<le> card R * card S * card T

goal (1 subgoal):
 1. (1 - \<epsilon> / 2) * (\<epsilon> / 4) ^ 3 * real (card R) * real (card S) * real (card T) \<le> (1 - 2 * (\<epsilon> / 4)) * (edge_density R S Gnew - \<epsilon> / 4) * (edge_density R T Gnew - \<epsilon> / 4) * (edge_density S T Gnew - \<epsilon> / 4) * real (card R) * real (card S) * real (card T)
[PROOF STEP]
by (simp add: mult.commute mult.left_commute mult_left_mono)
[PROOF STATE]
proof (state)
this:
(1 - \<epsilon> / 2) * (\<epsilon> / 4) ^ 3 * real (card R) * real (card S) * real (card T) \<le> (1 - 2 * (\<epsilon> / 4)) * (edge_density R S Gnew - \<epsilon> / 4) * (edge_density R T Gnew - \<epsilon> / 4) * (edge_density S T Gnew - \<epsilon> / 4) * real (card R) * real (card S) * real (card T)

goal (1 subgoal):
 1. \<not> triangle_free_graph Gnew \<Longrightarrow> False
[PROOF STEP]
also
[PROOF STATE]
proof (state)
this:
(1 - \<epsilon> / 2) * (\<epsilon> / 4) ^ 3 * real (card R) * real (card S) * real (card T) \<le> (1 - 2 * (\<epsilon> / 4)) * (edge_density R S Gnew - \<epsilon> / 4) * (edge_density R T Gnew - \<epsilon> / 4) * (edge_density S T Gnew - \<epsilon> / 4) * real (card R) * real (card S) * real (card T)

goal (1 subgoal):
 1. \<not> triangle_free_graph Gnew \<Longrightarrow> False
[PROOF STEP]
have "... \<le> card (triangle_triples R S T Gnew)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. (1 - 2 * (\<epsilon> / 4)) * (edge_density R S Gnew - \<epsilon> / 4) * (edge_density R T Gnew - \<epsilon> / 4) * (edge_density S T Gnew - \<epsilon> / 4) * real (card R) * real (card S) * real (card T) \<le> real (card (triangle_triples R S T Gnew))
[PROOF STEP]
by (smt (verit, best) e4gt ilt jlt klt min_dens_diff new_fin new_wf rp subsets triangle_counting_lemma)
[PROOF STATE]
proof (state)
this:
(1 - 2 * (\<epsilon> / 4)) * (edge_density R S Gnew - \<epsilon> / 4) * (edge_density R T Gnew - \<epsilon> / 4) * (edge_density S T Gnew - \<epsilon> / 4) * real (card R) * real (card S) * real (card T) \<le> real (card (triangle_triples R S T Gnew))

goal (1 subgoal):
 1. \<not> triangle_free_graph Gnew \<Longrightarrow> False
[PROOF STEP]
finally
[PROOF STATE]
proof (chain)
picking this:
(1 - \<epsilon> / 2) * (\<epsilon> / 4) ^ 3 * (\<epsilon> / real (4 * M)) ^ 3 * real (card (uverts G) ^ 3) \<le> real (card (triangle_triples R S T Gnew))
[PROOF STEP]
have "card (triangle_set Gnew) \<ge> D * ?n^3"
[PROOF STATE]
proof (prove)
using this:
(1 - \<epsilon> / 2) * (\<epsilon> / 4) ^ 3 * (\<epsilon> / real (4 * M)) ^ 3 * real (card (uverts G) ^ 3) \<le> real (card (triangle_triples R S T Gnew))

goal (1 subgoal):
 1. D * real (card (uverts G) ^ 3) \<le> real (card (triangle_set Gnew))
[PROOF STEP]
using card_convert_triangle_rep_bound new_wf new_fin subsets
[PROOF STATE]
proof (prove)
using this:
(1 - \<epsilon> / 2) * (\<epsilon> / 4) ^ 3 * (\<epsilon> / real (4 * M)) ^ 3 * real (card (uverts G) ^ 3) \<le> real (card (triangle_triples R S T Gnew))
\<lbrakk>?X \<subseteq> uverts ?G; ?Y \<subseteq> uverts ?G; ?Z \<subseteq> uverts ?G; finite (uverts ?G); uwellformed ?G; ?t \<le> real (card {(x, y, z). (x, y, z) \<in> ?X \<times> ?Y \<times> ?Z \<and> triangle_in_graph x y z ?G})\<rbrakk> \<Longrightarrow> 1 / 6 * ?t \<le> real (card (triangle_set ?G))
uwellformed Gnew
finite (uverts Gnew)
R \<subseteq> uverts Gnew
S \<subseteq> uverts Gnew
T \<subseteq> uverts Gnew

goal (1 subgoal):
 1. D * real (card (uverts G) ^ 3) \<le> real (card (triangle_set Gnew))
[PROOF STEP]
by (auto simp: triangle_triples_def D_def)
[PROOF STATE]
proof (state)
this:
D * real (card (uverts G) ^ 3) \<le> real (card (triangle_set Gnew))

goal (1 subgoal):
 1. \<not> triangle_free_graph Gnew \<Longrightarrow> False
[PROOF STEP]
then
[PROOF STATE]
proof (chain)
picking this:
D * real (card (uverts G) ^ 3) \<le> real (card (triangle_set Gnew))
[PROOF STEP]
have g_tset_bound: "card (triangle_set G) \<ge> D * ?n^3"
[PROOF STATE]
proof (prove)
using this:
D * real (card (uverts G) ^ 3) \<le> real (card (triangle_set Gnew))

goal (1 subgoal):
 1. D * real (card (uverts G) ^ 3) \<le> real (card (triangle_set G))
[PROOF STEP]
using triangle_set_graph_edge_ss_bound
[PROOF STATE]
proof (prove)
using this:
D * real (card (uverts G) ^ 3) \<le> real (card (triangle_set Gnew))
\<lbrakk>uwellformed ?G; finite (uverts ?G); uedges ?Gnew \<subseteq> uedges ?G; uverts ?Gnew = uverts ?G\<rbrakk> \<Longrightarrow> card (triangle_set ?Gnew) \<le> card (triangle_set ?G)

goal (1 subgoal):
 1. D * real (card (uverts G) ^ 3) \<le> real (card (triangle_set G))
[PROOF STEP]
by (smt (verit) edges fin local.wf of_nat_mono verts)
[PROOF STATE]
proof (state)
this:
D * real (card (uverts G) ^ 3) \<le> real (card (triangle_set G))

goal (1 subgoal):
 1. \<not> triangle_free_graph Gnew \<Longrightarrow> False
[PROOF STEP]
have "card (triangle_set G) > \<delta> * ?n^3"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. \<delta> * real (card (uverts G) ^ 3) < real (card (triangle_set G))
[PROOF STEP]
proof -
[PROOF STATE]
proof (state)
goal (1 subgoal):
 1. \<delta> * real (card (uverts G) ^ 3) < real (card (triangle_set G))
[PROOF STEP]
have "?n^3 > 0"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. 0 < card (uverts G) ^ 3
[PROOF STEP]
by (simp add: \<open>uverts G \<noteq> {}\<close> card_gt_0_iff fin)
[PROOF STATE]
proof (state)
this:
0 < card (uverts G) ^ 3

goal (1 subgoal):
 1. \<delta> * real (card (uverts G) ^ 3) < real (card (triangle_set G))
[PROOF STEP]
with \<delta> \<open>D0 \<le> D\<close>
[PROOF STATE]
proof (chain)
picking this:
0 < \<delta>
\<delta> < D0
D0 \<le> D
0 < card (uverts G) ^ 3
[PROOF STEP]
have "D * ?n^3 > \<delta> * ?n^3"
[PROOF STATE]
proof (prove)
using this:
0 < \<delta>
\<delta> < D0
D0 \<le> D
0 < card (uverts G) ^ 3

goal (1 subgoal):
 1. \<delta> * real (card (uverts G) ^ 3) < D * real (card (uverts G) ^ 3)
[PROOF STEP]
by force
[PROOF STATE]
proof (state)
this:
\<delta> * real (card (uverts G) ^ 3) < D * real (card (uverts G) ^ 3)

goal (1 subgoal):
 1. \<delta> * real (card (uverts G) ^ 3) < real (card (triangle_set G))
[PROOF STEP]
thus "card (triangle_set G) > \<delta> * ?n ^3"
[PROOF STATE]
proof (prove)
using this:
\<delta> * real (card (uverts G) ^ 3) < D * real (card (uverts G) ^ 3)

goal (1 subgoal):
 1. \<delta> * real (card (uverts G) ^ 3) < real (card (triangle_set G))
[PROOF STEP]
using g_tset_bound
[PROOF STATE]
proof (prove)
using this:
\<delta> * real (card (uverts G) ^ 3) < D * real (card (uverts G) ^ 3)
D * real (card (uverts G) ^ 3) \<le> real (card (triangle_set G))

goal (1 subgoal):
 1. \<delta> * real (card (uverts G) ^ 3) < real (card (triangle_set G))
[PROOF STEP]
unfolding D_def
[PROOF STATE]
proof (prove)
using this:
\<delta> * real (card (uverts G) ^ 3) < 1 / 6 * (1 - \<epsilon> / 2) * (\<epsilon> / 4) ^ 3 * (\<epsilon> / (4 * real M)) ^ 3 * real (card (uverts G) ^ 3)
1 / 6 * (1 - \<epsilon> / 2) * (\<epsilon> / 4) ^ 3 * (\<epsilon> / (4 * real M)) ^ 3 * real (card (uverts G) ^ 3) \<le> real (card (triangle_set G))

goal (1 subgoal):
 1. \<delta> * real (card (uverts G) ^ 3) < real (card (triangle_set G))
[PROOF STEP]
by linarith
[PROOF STATE]
proof (state)
this:
\<delta> * real (card (uverts G) ^ 3) < real (card (triangle_set G))

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<delta> * real (card (uverts G) ^ 3) < real (card (triangle_set G))

goal (1 subgoal):
 1. \<not> triangle_free_graph Gnew \<Longrightarrow> False
[PROOF STEP]
thus False
[PROOF STATE]
proof (prove)
using this:
\<delta> * real (card (uverts G) ^ 3) < real (card (triangle_set G))

goal (1 subgoal):
 1. False
[PROOF STEP]
using ineq
[PROOF STATE]
proof (prove)
using this:
\<delta> * real (card (uverts G) ^ 3) < real (card (triangle_set G))
real (card (triangle_set G)) \<le> \<delta> * real (card (uverts G) ^ 3)

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

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
triangle_free_graph Gnew

goal (1 subgoal):
 1. real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
show "real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)"
[PROOF STATE]
proof (prove)
goal (1 subgoal):
 1. real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
using cardbound edges verts
[PROOF STATE]
proof (prove)
using this:
real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
uedges Gnew \<subseteq> uedges G
uverts Gnew = uverts G

goal (1 subgoal):
 1. real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)
[PROOF STEP]
by blast
[PROOF STATE]
proof (state)
this:
real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)

goal:
No subgoals!
[PROOF STEP]
qed
[PROOF STATE]
proof (state)
this:
\<exists>Gnew. triangle_free_graph Gnew \<and> uverts Gnew = uverts G \<and> uedges Gnew \<subseteq> uedges G \<and> real (card (uedges G - uedges Gnew)) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2)

goal (1 subgoal):
 1. 0 < \<delta>
[PROOF STEP]
qed (rule \<open>0 < \<delta>\<close>)
[PROOF STATE]
proof (state)
this:
\<exists>\<delta>>0. \<forall>G. 0 < card (uverts G) \<longrightarrow> uwellformed G \<longrightarrow> real (card (triangle_set G)) \<le> \<delta> * real (card (uverts G) ^ 3) \<longrightarrow> (\<exists>G'. triangle_free_graph G' \<and> uverts G' = uverts G \<and> uedges G' \<subseteq> uedges G \<and> real (card (uedges G - uedges G')) \<le> \<epsilon> * real ((card (uverts G))\<^sup>2))

goal:
No subgoals!
[PROOF STEP]
qed