diff --git a/thys/Girth_Chromatic/Girth_Chromatic.thy b/thys/Girth_Chromatic/Girth_Chromatic.thy --- a/thys/Girth_Chromatic/Girth_Chromatic.thy +++ b/thys/Girth_Chromatic/Girth_Chromatic.thy @@ -1,737 +1,737 @@ theory Girth_Chromatic imports Ugraphs Girth_Chromatic_Misc "HOL-Probability.Probability" "HOL-Decision_Procs.Approximation" begin section \Probability Space on Sets of Edges\ definition cylinder :: "'a set \ 'a set \ 'a set \ 'a set set" where "cylinder S A B = {T \ Pow S. A \ T \ B \ T = {}}" lemma full_sum: fixes p :: real assumes "finite S" shows "(\A\Pow S. p^card A * (1 - p)^card (S - A)) = 1" using assms proof induct case (insert s S) have "inj_on (insert s) (Pow S)" and "\x. S - insert s x = S - x" and "Pow S \ insert s ` Pow S = {}" and "\x. x \ Pow S \ card (insert s S - x) = Suc (card (S - x))" using insert(1-2) by (auto simp: insert_Diff_if intro!: inj_onI) moreover have "\x. x \ S \ card (insert s x) = Suc (card x)" using insert(1-2) by (subst card.insert) (auto dest: finite_subset) ultimately show ?case by (simp add: sum.reindex sum_distrib_left[symmetric] ac_simps insert.hyps sum.union_disjoint Pow_insert) qed simp text \Definition of the probability space on edges:\ locale edge_space = fixes n :: nat and p :: real assumes p_prob: "0 \ p" "p \ 1" begin definition S_verts :: "nat set" where "S_verts \ {1..n}" definition S_edges :: "uedge set" where "S_edges = all_edges S_verts" definition edge_ugraph :: "uedge set \ ugraph" where "edge_ugraph es \ (S_verts, es \ S_edges)" definition "P = point_measure (Pow S_edges) (\s. p^card s * (1 - p)^card (S_edges - s))" lemma finite_verts[intro!]: "finite S_verts" by (auto simp: S_verts_def) lemma finite_edges[intro!]: "finite S_edges" by (auto simp: S_edges_def all_edges_def finite_verts) lemma finite_graph[intro!]: "finite (uverts (edge_ugraph es))" unfolding edge_ugraph_def by auto lemma uverts_edge_ugraph[simp]: "uverts (edge_ugraph es) = S_verts" by (simp add: edge_ugraph_def) lemma uedges_edge_ugraph[simp]: "uedges (edge_ugraph es) = es \ S_edges" unfolding edge_ugraph_def by simp lemma space_eq: "space P = Pow S_edges" by (simp add: P_def space_point_measure) lemma sets_eq: "sets P = Pow (Pow S_edges)" by (simp add: P_def sets_point_measure) lemma emeasure_eq: "emeasure P A = (if A \ Pow S_edges then (\edges\A. p^card edges * (1 - p)^card (S_edges - edges)) else 0)" using finite_edges p_prob by (simp add: P_def space_point_measure emeasure_point_measure_finite sets_point_measure emeasure_notin_sets) lemma integrable_P[intro, simp]: "integrable P (f::_ \ real)" using finite_edges by (simp add: integrable_point_measure_finite P_def) lemma borel_measurable_P[measurable]: "f \ borel_measurable P" unfolding P_def by simp lemma prob_space_P: "prob_space P" proof show "emeasure P (space P) = 1" \ \Sum of probabilities equals 1\ using finite_edges by (simp add: emeasure_eq full_sum one_ereal_def space_eq) qed end sublocale edge_space \ prob_space P by (rule prob_space_P) context edge_space begin lemma prob_eq: "prob A = (if A \ Pow S_edges then (\edges\A. p^card edges * (1 - p)^card (S_edges - edges)) else 0)" using emeasure_eq[of A] p_prob unfolding emeasure_eq_measure by (simp add: sum_nonneg) lemma integral_finite_singleton: "integral\<^sup>L P f = (\x\Pow S_edges. f x * measure P {x})" using p_prob prob_eq unfolding P_def by (subst lebesgue_integral_point_measure_finite) (auto intro!: sum.cong) text \Probability of cylinder sets:\ lemma cylinder_prob: assumes "A \ S_edges" "B \ S_edges" "A \ B = {}" shows "prob (cylinder S_edges A B) = p ^ (card A) * (1 - p) ^ (card B)" (is "_ = ?pp A B") proof - have "Pow S_edges \ cylinder S_edges A B = cylinder S_edges A B" "\x. x \ cylinder S_edges A B \ A \ x = x" "\x. x \ cylinder S_edges A B \ finite x" "\x. x \ cylinder S_edges A B \ B \ (S_edges - B - x) = {}" "\x. x \ cylinder S_edges A B \ B \ (S_edges - B - x) = S_edges - x" "finite A" "finite B" using assms by (auto simp add: cylinder_def intro: finite_subset) then have "(\T\cylinder S_edges A B. ?pp T (S_edges - T)) = (\T \ cylinder S_edges A B. p^(card A + card (T - A)) * (1 - p)^(card B + card ((S_edges - B) - T)))" using finite_edges by (simp add: card_Un_Int) also have "\ = ?pp A B * (\T\cylinder S_edges A B. ?pp (T - A) (S_edges - B - T))" by (simp add: power_add sum_distrib_left ac_simps) also have "\ = ?pp A B" proof - have "\T. T \ cylinder S_edges A B \ S_edges - B - T = (S_edges - A) - B - (T - A)" "Pow (S_edges - A - B) = (\x. x - A) ` cylinder S_edges A B" "inj_on (\x. x - A) (cylinder S_edges A B)" "finite (S_edges - A - B)" using assms by (auto simp: cylinder_def intro!: inj_onI) with full_sum[of "S_edges - A - B"] show ?thesis by (simp add: sum.reindex) qed finally show ?thesis by (auto simp add: prob_eq cylinder_def) qed lemma Markov_inequality: fixes a :: real and X :: "uedge set \ real" assumes "0 < c" "\x. 0 \ f x" shows "prob {x \ space P. c \ f x} \ (\x. f x \ P) / c" proof - from assms have "(\\<^sup>+ x. ennreal (f x) \P) = (\x. f x \P)" by (intro nn_integral_eq_integral) auto with assms show ?thesis using nn_integral_Markov_inequality[of f "space P" P "1 / c"] by (simp cong: nn_integral_cong add: emeasure_eq_measure ennreal_mult[symmetric]) qed end subsection \Graph Probabilities outside of @{term Edge_Space} locale\ text \ These abbreviations allow a compact expression of probabilities about random graphs outside of the @{term Edge_Space} locale. We also transfer a few of the lemmas we need from the locale into the toplevel theory. \ abbreviation MGn :: "(nat \ real) \ nat \ (uedge set) measure" where "MGn p n \ (edge_space.P n (p n))" abbreviation probGn :: "(nat \ real) \ nat \ (uedge set \ bool) \ real" where "probGn p n P \ measure (MGn p n) {es \ space (MGn p n). P es}" lemma probGn_le: assumes p_prob: "0 < p n" "p n < 1" assumes sub: "\n es. es \ space (MGn p n) \ P n es \ Q n es" shows "probGn p n (P n) \ probGn p n (Q n)" proof - from p_prob interpret E: edge_space n "p n" by unfold_locales auto show ?thesis by (auto intro!: E.finite_measure_mono sub simp: E.space_eq E.sets_eq) qed section \Short cycles\ definition short_cycles :: "ugraph \ nat \ uwalk set" where "short_cycles G k \ {p \ ucycles G. uwalk_length p \ k}" text \obtains a vertex in a short cycle:\ definition choose_v :: "ugraph \ nat \ uvert" where "choose_v G k \ SOME u. \p. p \ short_cycles G k \ u \ set p" partial_function (tailrec) kill_short :: "ugraph \ nat \ ugraph" where "kill_short G k = (if short_cycles G k = {} then G else (kill_short (G -- (choose_v G k)) k))" lemma ksc_simps[simp]: "short_cycles G k = {} \ kill_short G k = G" "short_cycles G k \ {} \ kill_short G k = kill_short (G -- (choose_v G k)) k" by (auto simp: kill_short.simps) lemma assumes "short_cycles G k \ {}" shows choose_v__in_uverts: "choose_v G k \ uverts G" (is ?t1) and choose_v__in_short: "\p. p \ short_cycles G k \ choose_v G k \ set p" (is ?t2) proof - from assms obtain p where "p \ ucycles G" "uwalk_length p \ k" unfolding short_cycles_def by auto moreover then obtain u where "u \ set p" unfolding ucycles_def by (cases p) (auto simp: uwalk_length_conv) ultimately have "\u p. p \ short_cycles G k \ u \ set p" by (auto simp: short_cycles_def) then show ?t2 by (auto simp: choose_v_def intro!: someI_ex) then show ?t1 by (auto simp: short_cycles_def ucycles_def uwalks_def) qed lemma kill_step_smaller: assumes "short_cycles G k \ {}" shows "short_cycles (G -- (choose_v G k)) k \ short_cycles G k" proof - let ?cv = "choose_v G k" from assms obtain p where "p \ short_cycles G k" "?cv \ set p" by atomize_elim (rule choose_v__in_short) have "short_cycles (G -- ?cv) k \ short_cycles G k" proof fix p assume "p \ short_cycles (G -- ?cv) k" then show "p \ short_cycles G k" unfolding short_cycles_def ucycles_def uwalks_def using edges_Gu[of G ?cv] by (auto simp: verts_Gu) qed moreover have "p \ short_cycles (G -- ?cv) k" using \?cv \ set p\ by (auto simp: short_cycles_def ucycles_def uwalks_def verts_Gu) ultimately show ?thesis using \p \ short_cycles G k\ by auto qed text \Induction rule for @{term kill_short}:\ lemma kill_short_induct[consumes 1, case_names empty kill_vert]: assumes fin: "finite (uverts G)" assumes a_empty: "\G. short_cycles G k = {} \ P G k" assumes a_kill: "\G. finite (short_cycles G k) \ short_cycles G k \ {} \ P (G -- (choose_v G k)) k \ P G k" shows "P G k" proof - have "finite (short_cycles G k)" using finite_ucycles[OF fin] by (auto simp: short_cycles_def) then show ?thesis by (induct "short_cycles G k" arbitrary: G rule: finite_psubset_induct) (metis kill_step_smaller a_kill a_empty) qed text \Large Girth (after @{term kill_short}):\ lemma kill_short_large_girth: assumes "finite (uverts G)" shows "k < girth (kill_short G k)" using assms proof (induct G k rule: kill_short_induct) case (empty G) then have "\p. p \ ucycles G \ k < enat (uwalk_length p)" by (auto simp: short_cycles_def) with empty show ?case by (auto simp: girth_def intro: enat_less_INF_I) qed simp text \Order of graph (after @{term kill_short}):\ lemma kill_short_order_of_graph: assumes "finite (uverts G)" shows "card (uverts G) - card (short_cycles G k) \ card (uverts (kill_short G k))" using assms assms proof (induct G k rule: kill_short_induct) case (kill_vert G) let ?oG = "G -- (choose_v G k)" have "finite (uverts ?oG)" using kill_vert by (auto simp: remove_vertex_def) moreover have "uverts (kill_short G k) = uverts (kill_short ?oG k)" using kill_vert by simp moreover have "card (uverts G) = Suc (card (uverts ?oG))" using choose_v__in_uverts kill_vert by (simp add: remove_vertex_def card_Suc_Diff1 del: card_Diff_insert) moreover have "card (short_cycles ?oG k) < card (short_cycles G k)" by (intro psubset_card_mono kill_vert.hyps kill_step_smaller) ultimately show ?case using kill_vert.hyps by presburger qed simp text \Independence number (after @{term kill_short}):\ lemma kill_short_\: assumes "finite (uverts G)" shows "\ (kill_short G k) \ \ G" using assms proof (induct G k rule: kill_short_induct) case (kill_vert G) note kill_vert(3) also have "\ (G -- (choose_v G k)) \ \ G" by (rule \_remove_le) finally show ?case using kill_vert by simp qed simp text \Wellformedness (after @{term kill_short}):\ lemma kill_short_uwellformed: assumes "finite (uverts G)" "uwellformed G" shows "uwellformed (kill_short G k)" using assms proof (induct G k rule: kill_short_induct) case (kill_vert G) from kill_vert.prems have "uwellformed (G -- (choose_v G k))" by (auto simp: uwellformed_def remove_vertex_def) with kill_vert.hyps show ?case by simp qed simp section \The Chromatic-Girth Theorem\ text \Probability of Independent Edges:\ lemma (in edge_space) random_prob_independent: assumes "n \ k" "k \ 2" shows "prob {es \ space P. k \ \ (edge_ugraph es)} \ (n choose k)*(1-p)^(k choose 2)" proof - let "?k_sets" = "{vs. vs \ S_verts \ card vs = k}" { fix vs assume A: "vs \ ?k_sets" then have B: "all_edges vs \ S_edges" unfolding all_edges_def S_edges_def by blast have "{es \ space P. vs \ independent_sets (edge_ugraph es)} = cylinder S_edges {} (all_edges vs)" (is "?L = _") using A by (auto simp: independent_sets_def edge_ugraph_def space_eq cylinder_def) then have "prob ?L = (1-p)^(k choose 2)" using A B finite by (auto simp: cylinder_prob card_all_edges dest: finite_subset) } note prob_k_indep = this \ \probability that a fixed set of k vertices is independent in a random graph\ have "{es \ space P. k \ card ` independent_sets (edge_ugraph es)} = (\vs \ ?k_sets. {es \ space P. vs \ independent_sets (edge_ugraph es)})" (is "?L = ?R") unfolding image_def space_eq independent_sets_def by auto then have "prob ?L \ (\vs \ ?k_sets. prob {es \ space P. vs \ independent_sets (edge_ugraph es)})" by (auto intro!: finite_measure_subadditive_finite simp: space_eq sets_eq) also have "\ = (n choose k)*((1 - p) ^ (k choose 2))" by (simp add: prob_k_indep S_verts_def n_subsets) finally show ?thesis using \k \ 2\ by (simp add: le_\_iff) qed text \Almost never many independent edges:\ lemma almost_never_le_\: fixes k :: nat and p :: "nat \ real" assumes p_prob: "\\<^sup>\ n. 0 < p n \ p n < 1" assumes [arith]: "k > 0" assumes N_prop: "\\<^sup>\ n. (6 * k * ln n)/n \ p n" shows "(\n. probGn p n (\es. 1/2*n/k \ \ (edge_space.edge_ugraph n es))) \ 0" (is "(\n. ?prob_fun n) \ 0") proof - let "?prob_fun_raw n" = "probGn p n (\es. nat(ceiling (1/2*n/k)) \ \ (edge_space.edge_ugraph n es))" define r where "r n = 1 / 2 * n / k" for n :: nat let ?nr = "\n. nat(ceiling (r n))" have r_pos: "\n. 0 < n \ 0 < r n " by (auto simp: r_def field_simps) have nr_bounds: "\\<^sup>\ n. 2 \ ?nr n \ ?nr n \ n" by (intro eventually_sequentiallyI[of "4 * k"]) (simp add: r_def nat_ceiling_le_eq le_natceiling_iff field_simps) from nr_bounds p_prob have ev_prob_fun_raw_le: "\\<^sup>\ n. probGn p n (\es. ?nr n\ \ (edge_space.edge_ugraph n es)) \ (n * exp (- p n * (real (?nr n) - 1) / 2)) powr ?nr n" (is "\\<^sup>\ n. ?prob_fun_raw_le n") proof (rule eventually_elim2) fix n :: nat assume A: "2 \ ?nr n \ ?nr n \ n" "0 < p n \p n < 1" then interpret pG: edge_space n "p n" by unfold_locales auto have r: "real (?nr n - Suc 0) = real (?nr n) - Suc 0" using A by auto have [simp]: "n>0" using A by linarith have "probGn p n (\es. ?nr n \ \ (edge_space.edge_ugraph n es)) \ (n choose ?nr n) * (1 - p n)^(?nr n choose 2)" using A by (auto intro: pG.random_prob_independent) also have "\ \ n powr ?nr n * (1 - p n) powr (?nr n choose 2)" using A by (simp add: powr_realpow of_nat_power [symmetric] binomial_le_pow del: of_nat_power) also have "\ = n powr ?nr n * (1 - p n) powr (?nr n * (?nr n - 1) / 2)" by (cases "even (?nr n - 1)") - (auto simp add: n_choose_2_nat real_of_nat_div) + (auto simp add: choose_two real_of_nat_div) also have "\ = n powr ?nr n * ((1 - p n) powr ((?nr n - 1) / 2)) powr ?nr n" by (auto simp add: powr_powr r ac_simps) also have "\ \ (n * exp (- p n * (?nr n - 1) / 2)) powr ?nr n" proof - have "(1 - p n) powr ((?nr n - 1) / 2) \ exp (- p n) powr ((?nr n - 1) / 2)" using A by (auto simp: powr_mono2 diff_conv_add_uminus simp del: add_uminus_conv_diff) also have "\ = exp (- p n * (?nr n - 1) / 2)" by (auto simp: powr_def) finally show ?thesis using A by (auto simp: powr_mono2 powr_mult) qed finally show "probGn p n (\es. ?nr n \ \ (edge_space.edge_ugraph n es)) \ (n * exp (- p n * (real (?nr n) - 1) / 2)) powr ?nr n" using A r by simp qed from p_prob N_prop have ev_expr_bound: "\\<^sup>\ n. n * exp (-p n * (real (?nr n) - 1) / 2) \ (exp 1 / n) powr (1 / 2)" proof (elim eventually_rev_mp, intro eventually_sequentiallyI conjI impI) fix n assume n_bound[arith]: "2 \ n" and p_bound: "0 < p n \ p n < 1" "(6 * k * ln n) / n \ p n" have r_bound: "r n \ ?nr n" by (rule real_nat_ceiling_ge) have "n * exp (-p n * (real (?nr n)- 1) / 2) \ n * exp (- 3 / 2 * ln n + p n / 2)" proof - have "0 < ln n" using "n_bound" by auto then have "(3 / 2) * ln n \ ((6 * k * ln n) / n) * (?nr n / 2)" using r_bound le_of_int_ceiling[of "n/2*k"] by (simp add: r_def field_simps del: le_of_int_ceiling) also have "\ \ p n * (?nr n / 2)" using n_bound p_bound r_bound r_pos[of n] by (auto simp: field_simps) finally show ?thesis using r_bound by (auto simp: field_simps) qed also have "\ \ n * n powr (- 3 / 2) * exp 1 powr (1 / 2)" using p_bound by (simp add: powr_def exp_add [symmetric]) also have "\ \ n powr (-1 / 2) * exp 1 powr (1 / 2)" by (simp add: powr_mult_base) also have "\ = (exp 1 / n) powr (1/2)" by (simp add: powr_divide powr_minus_divide) finally show "n * exp (- p n * (real (?nr n) - 1) / 2) \ (exp 1 / n) powr (1 / 2)" . qed have ceil_bound: "\G n. 1/2*n/k \ \ G \ nat(ceiling (1/2*n/k)) \ \ G" by (case_tac "\ G") (auto simp: nat_ceiling_le_eq) show ?thesis proof (unfold ceil_bound, rule real_tendsto_sandwich) show "(\n. 0) \ 0" "(\n. (exp 1 / n) powr (1 / 2)) \ 0" "\\<^sup>\ n. 0 \ ?prob_fun_raw n" using p_prob by (auto intro: measure_nonneg LIMSEQ_inv_powr elim: eventually_mono) next from nr_bounds ev_expr_bound ev_prob_fun_raw_le show "\\<^sup>\ n. ?prob_fun_raw n \ (exp 1 / n) powr (1 / 2)" proof (elim eventually_rev_mp, intro eventually_sequentiallyI impI conjI) fix n assume A: "3 \ n" and nr_bounds: "2 \ ?nr n \ ?nr n \ n" and prob_fun_raw_le: "?prob_fun_raw_le n" and expr_bound: "n * exp (- p n * (real (nat(ceiling (r n))) - 1) / 2) \ (exp 1 / n) powr (1 / 2)" have "exp 1 < (3 :: real)" by (approximation 6) then have "(exp 1 / n) powr (1 / 2) \ 1 powr (1 / 2)" using A by (intro powr_mono2) (auto simp: field_simps) then have ep_bound: "(exp 1 / n) powr (1 / 2) \ 1" by simp have "?prob_fun_raw n \ (n * exp (- p n * (real (?nr n) - 1) / 2)) powr (?nr n)" using prob_fun_raw_le by (simp add: r_def) also have "\ \ ((exp 1 / n) powr (1 / 2)) powr ?nr n" using expr_bound A by (auto simp: powr_mono2) also have "\ \ ((exp 1 / n) powr (1 / 2))" using nr_bounds ep_bound A by (auto simp: powr_le_one_le) finally show "?prob_fun_raw n \ (exp 1 / n) powr (1 / 2)" . qed qed qed text \Mean number of k-cycles in a graph. (Or rather of paths describing a circle of length @{term k}):\ lemma (in edge_space) mean_k_cycles: assumes "3 \ k" "k < n" shows "(\es. card {c \ ucycles (edge_ugraph es). uwalk_length c = k} \ P) = of_nat (fact n div fact (n - k)) * p ^ k" proof - let ?k_cycle = "\es c k. c \ ucycles (edge_ugraph es) \ uwalk_length c = k" define C where "C k = {c. ?k_cycle S_edges c k}" for k \ \@{term "C k"} is the set of all possible cycles of size @{term k} in @{term "edge_ugraph S_edges"}\ define XG where "XG es = {c. ?k_cycle es c k}" for es \ \@{term "XG es"} is the set of cycles contained in a @{term "edge_ugraph es"}\ define XC where "XC c = {es \ space P. ?k_cycle es c k}" for c \ \"@{term "XC c"} is the set of graphs (edge sets) containing a cycle c"\ then have XC_in_sets: "\c. XC c \ sets P" and XC_cyl: "\c. c \ C k \ XC c = cylinder S_edges (set (uwalk_edges c)) {}" by (auto simp: ucycles_def space_eq uwalks_def C_def cylinder_def sets_eq) have "(\es. card {c \ ucycles (edge_ugraph es). uwalk_length c = k} \ P) = (\x\space P. card (XG x) * prob {x})" by (simp add: XG_def integral_finite_singleton space_eq) also have "\ = (\c\C k. prob (cylinder S_edges (set (uwalk_edges c)) {}))" proof - have XG_Int_C: "\s. s \ space P \ C k \ XG s = XG s" unfolding XG_def C_def ucycles_def uwalks_def edge_ugraph_def by auto have fin_XC: "\k. finite (XC k)" and fin_C: "finite (C k)" unfolding C_def XC_def by (auto simp: finite_edges space_eq intro!: finite_ucycles) have "(\x\space P. card (XG x) * prob {x}) = (\x\space P. (\c \ XG x. prob {x}))" by simp also have "\ = (\x\space P. (\c \ C k. if c \ XG x then prob {x} else 0))" using fin_C by (simp add: sum.If_cases) (simp add: XG_Int_C) also have "\ = (\c \ C k. (\ x \ space P \ XC c. prob {x}))" using finite_edges by (subst sum.swap) (simp add: sum.inter_restrict XG_def XC_def space_eq) also have "\ = (\c \ C k. prob (XC c))" using fin_XC XC_in_sets by (auto simp add: prob_eq sets_eq space_eq intro!: sum.cong) finally show ?thesis by (simp add: XC_cyl) qed also have "\ = (\c\C k. p ^ k)" proof - have "\x. x \ C k \ card (set (uwalk_edges x)) = uwalk_length x" by (auto simp: uwalk_length_def C_def ucycles_distinct_edges intro: distinct_card) then show ?thesis by (auto simp: C_def ucycles_def uwalks_def cylinder_prob) qed also have "\ = of_nat (fact n div fact (n - k)) * p ^ k" proof - have inj_last_Cons: "\A. inj_on (\es. last es # es) A" by (rule inj_onI) simp { fix xs A assume "3 \ length xs - Suc 0" "hd xs = last xs" then have "xs \ (\xs. last xs # xs) ` A \ tl xs \ A" by (cases xs) (auto simp: inj_image_mem_iff[OF inj_last_Cons] split: if_split_asm) } note image_mem_iff_inst = this { fix xs have "xs \ uwalks (edge_ugraph S_edges) \ set (tl xs) \ S_verts" unfolding uwalks_def by (induct xs) auto } moreover { fix xs assume "set xs \ S_verts" "2 \ length xs" "distinct xs" then have "(last xs # xs) \ uwalks (edge_ugraph S_edges)" proof (induct xs rule: uwalk_edges.induct) case (3 x y ys) have S_edges_memI: "\x y. x \ S_verts \ y \ S_verts \ x \ y \ {x, y} \ S_edges" unfolding S_edges_def all_edges_def image_def by auto have "ys \ [] \ set ys \ S_verts \ last ys \ S_verts" by auto with 3 show ?case by (auto simp add: uwalks_def Suc_le_eq intro: S_edges_memI) qed simp_all} moreover note \3 \ k\ ultimately have "C k = (\xs. last xs # xs) ` {xs. length xs = k \ distinct xs \ set xs \ S_verts}" by (auto simp: C_def ucycles_def uwalk_length_conv image_mem_iff_inst) moreover have "card S_verts = n" by (simp add: S_verts_def) ultimately have "card (C k) = fact n div fact (n - k)" using \k < n\ by (simp add: card_image[OF inj_last_Cons] card_lists_distinct_length_eq' fact_div_fact) then show ?thesis by simp qed finally show ?thesis by simp qed text \Girth-Chromatic number theorem:\ theorem girth_chromatic: fixes l :: nat shows "\G. uwellformed G \ l < girth G \ l < chromatic_number G" proof - define k where "k = max 3 l" define \ where "\ = 1 / (2 * k)" define p where "p n = real n powr (\ - 1)" for n :: nat let ?ug = edge_space.edge_ugraph define short_count where "short_count g = card (short_cycles g k)" for g \ \This random variable differs from the one used in the proof of theorem 11.2.2, as we count the number of paths describing a circle, not the circles themselves\ from k_def have "3 \ k" "l \ k" by auto from \3 \ k\ have \_props: "0 < \" "\ < 1 / k" "\ < 1" by (auto simp: \_def field_simps) have ev_p: "\\<^sup>\ n. 0 < p n \ p n < 1" proof (rule eventually_sequentiallyI) fix n :: nat assume "2 \ n" with \\ < 1\ have "n powr (\ - 1) < 1" by (auto intro!: powr_less_one) then show "0 < p n \ p n < 1" using \2 \ n\ by (auto simp: p_def) qed then have prob_short_count_le: "\\<^sup>\ n. probGn p n (\es. (real n/2) \ short_count (?ug n es)) \ 2 * (k - 2) * n powr (\ * k - 1)" (is "\\<^sup>\ n. ?P n") proof (elim eventually_rev_mp, intro eventually_sequentiallyI impI) fix n :: nat assume A: "Suc k \ n" "0 < p n \ p n < 1" then interpret pG: edge_space n "p n" by unfold_locales auto have "1 \ n" using A by auto define mean_short_count where "mean_short_count = (\es. short_count (?ug n es) \ pG.P)" have mean_short_count_le: "mean_short_count \ (k - 2) * n powr (\ * k)" proof - have small_empty: "\es k. k \ 2 \ short_cycles (edge_space.edge_ugraph n es) k = {}" by (auto simp add: short_cycles_def ucycles_def) have short_count_conv: "\es. short_count (?ug n es) = (\i=3..k. real (card {c \ ucycles (?ug n es). uwalk_length c = i}))" proof (unfold short_count_def, induct k) case 0 with small_empty show ?case by auto next case (Suc k) show ?case proof (cases "Suc k \ 2") case True with small_empty show ?thesis by auto next case False have "{c \ ucycles (?ug n es). uwalk_length c \ Suc k} = {c \ ucycles (?ug n es). uwalk_length c \ k} \ {c \ ucycles (?ug n es). uwalk_length c = Suc k}" by auto moreover have "finite (uverts (edge_space.edge_ugraph n es))" by auto ultimately have "card {c \ ucycles (?ug n es). uwalk_length c \ Suc k} = card {c \ ucycles (?ug n es). uwalk_length c \ k} + card {c \ ucycles (?ug n es). uwalk_length c = Suc k}" using finite_ucycles by (subst card_Un_disjoint[symmetric]) auto then show ?thesis using Suc False unfolding short_cycles_def by (auto simp: not_le) qed qed have "mean_short_count = (\i=3..k. \es. card {c \ ucycles (?ug n es). uwalk_length c = i} \ pG.P)" unfolding mean_short_count_def short_count_conv by (subst Bochner_Integration.integral_sum) (auto intro: pG.integral_finite_singleton) also have "\ = (\i\{3..k}. of_nat (fact n div fact (n - i)) * p n ^ i)" using A by (simp add: pG.mean_k_cycles) also have "\ \ (\ i\{3..k}. n ^ i * p n ^ i)" apply (rule sum_mono) by (meson A fact_div_fact_le_pow Suc_leD atLeastAtMost_iff of_nat_le_iff order_trans mult_le_cancel_iff1 zero_less_power) also have "... \ (\ i\{3..k}. n powr (\ * k))" using \1 \ n\ \0 < \\ A by (intro sum_mono) (auto simp: p_def field_simps powr_mult_base powr_powr powr_realpow[symmetric] powr_mult[symmetric] powr_add[symmetric]) finally show ?thesis by simp qed have "pG.prob {es \ space pG.P. n/2 \ short_count (?ug n es)} \ mean_short_count / (n/2)" unfolding mean_short_count_def using \1 \ n\ by (intro pG.Markov_inequality) (auto simp: short_count_def) also have "\ \ 2 * (k - 2) * n powr (\ * k - 1)" proof - have "mean_short_count / (n / 2) \ 2 * (k - 2) * (1 / n powr 1) * n powr (\ * k)" using mean_short_count_le \1 \ n\ by (simp add: field_simps) then show ?thesis by (simp add: powr_diff algebra_simps) qed finally show "?P n" . qed define pf_short_count pf_\ where "pf_short_count n = probGn p n (\es. n/2 \ short_count (?ug n es))" and "pf_\ n = probGn p n (\es. 1/2 * n/k \ \ (edge_space.edge_ugraph n es))" for n have ev_short_count_le: "\\<^sup>\ n. pf_short_count n < 1 / 2" proof - have "\ * k - 1 < 0" using \_props \3 \ k\ by (auto simp: field_simps) then have "(\n. 2 * (k - 2) * n powr (\ * k - 1)) \ 0" (is "?bound \ 0") by (intro tendsto_mult_right_zero LIMSEQ_neg_powr) then have "\\<^sup>\ n. dist (?bound n) 0 < 1 / 2" by (rule tendstoD) simp with prob_short_count_le show ?thesis by (rule eventually_elim2) (auto simp: dist_real_def pf_short_count_def) qed have lim_\: "pf_\ \ 0" proof - have "0 < k" using \3 \ k\ by simp have "\\<^sup>\ n. (6*k) * ln n / n \ p n \ (6*k) * ln n * n powr - \ \ 1" proof (rule eventually_sequentiallyI) fix n :: nat assume "1 \ n" then have "(6 * k) * ln n / n \ p n \ (6*k) * ln n * (n powr - 1) \ n powr (\ - 1)" by (subst powr_minus) (simp add: divide_inverse p_def) also have "\ \ (6*k) * ln n * ((n powr - 1) / (n powr (\ - 1))) \ n powr (\ - 1) / (n powr (\ - 1))" using \1 \ n\ by (auto simp: field_simps) also have "\ \ (6*k) * ln n * n powr - \ \ 1" by (simp add: powr_diff [symmetric] ) finally show "(6*k) * ln n / n \ p n \ (6*k) * ln n * n powr - \ \ 1" . qed then have "(\\<^sup>\ n. (6 * k) * ln n / real n \ p n) \ (\\<^sup>\ n. (6*k) * ln n * n powr - \ \ 1)" by (rule eventually_subst) also have "\\<^sup>\ n. (6*k) * ln n * n powr - \ \ 1" proof - { fix n :: nat assume "0 < n" have "ln (real n) \ n powr (\/2) / (\/2)" using \0 < n\ \0 < \\ by (intro ln_powr_bound) auto also have "\ \ 2/\ * n powr (\/2)" by (auto simp: field_simps) finally have "(6*k) * ln n * (n powr - \) \ (6*k) * (2/\ * n powr (\/2)) * (n powr - \)" using \0 < n\ \0 < k\ by (intro mult_right_mono mult_left_mono) auto also have "\ = 12*k/\ * n powr (-\/2)" unfolding divide_inverse by (auto simp: field_simps powr_minus[symmetric] powr_add[symmetric]) finally have "(6*k) * ln n * (n powr - \) \ 12*k/\ * n powr (-\/2)" . } then have "\\<^sup>\ n. (6*k) * ln n * (n powr - \) \ 12*k/\ * n powr (-\/2)" by (intro eventually_sequentiallyI[of 1]) auto also have "\\<^sup>\ n. 12*k/\ * n powr (-\/2) \ 1" proof - have "(\n. 12*k/\ * n powr (-\/2)) \ 0" using \0 < \\ by (intro tendsto_mult_right_zero LIMSEQ_neg_powr) auto then show ?thesis using \0 < \\ by - (drule tendstoD[where e=1], auto elim: eventually_mono) qed finally (eventually_le_le) show ?thesis . qed finally have "\\<^sup>\ n. real (6 * k) * ln (real n) / real n \ p n" . with ev_p \0 < k\ show ?thesis unfolding pf_\_def by (rule almost_never_le_\) qed from ev_short_count_le lim_\[THEN tendstoD, of "1/2"] ev_p have "\\<^sup>\ n. 0 < p n \ p n < 1 \ pf_short_count n < 1/2 \ pf_\ n < 1/2" by simp (elim eventually_rev_mp, auto simp: eventually_sequentially dist_real_def) then obtain n where "0 < p n" "p n < 1" and [arith]: "0 < n" and probs: "pf_short_count n < 1/2" "pf_\ n < 1/2" by (auto simp: eventually_sequentially) then interpret ES: edge_space n "(p n)" by unfold_locales auto have rest_compl: "\A P. A - {x\A. P x} = {x\A. \P x}" by blast from probs have "ES.prob ({es \ space ES.P. n/2 \ short_count (?ug n es)} \ {es \ space ES.P. 1/2 * n/k \ \ (?ug n es)}) \ pf_short_count n + pf_\ n" unfolding pf_short_count_def pf_\_def by (subst ES.finite_measure_subadditive) auto also have "\ < 1" using probs by auto finally have "0 < ES.prob (space ES.P - ({es \ space ES.P. n/2 \ short_count (?ug n es)} \ {es \ space ES.P. 1/2 * n/k \ \ (?ug n es)}))" (is "0 < ES.prob ?S") by (subst ES.prob_compl) auto also have "?S = {es \ space ES.P. short_count (?ug n es) < n/2 \ \ (?ug n es) < 1/2* n/k}" (is "\ = ?C") by (auto simp: not_less rest_compl) finally have "?C \ {}" by (intro notI) (simp only:, auto) then obtain es where es_props: "es \ space ES.P" "short_count (?ug n es) < n/2" "\ (?ug n es) < 1/2 * n/k" by auto \ \now we obtained a high colored graph (few independent nodes) with almost no short cycles\ define G where "G = ?ug n es" define H where "H = kill_short G k" have G_props: "uverts G = {1..n}" "finite (uverts G)" "short_count G < n/2" "\ G < 1/2 * n/k" unfolding G_def using es_props by (auto simp: ES.S_verts_def) have "uwellformed G" by (auto simp: G_def uwellformed_def all_edges_def ES.S_edges_def) with G_props have T1: "uwellformed H" unfolding H_def by (intro kill_short_uwellformed) have "enat l \ enat k" using \l \ k\ by simp also have "\ < girth H" using G_props by (auto simp: kill_short_large_girth H_def) finally have T2: "l < girth H" . have card_H: "n/2 \ card (uverts H)" using G_props es_props kill_short_order_of_graph[of G k] by (simp add: short_count_def H_def) then have uverts_H: "uverts H \ {}" "0 < card (uverts H)" by auto then have "0 < \ H" using zero_less_\ uverts_H by auto have \_HG: "\ H \ \ G" unfolding H_def G_def by (auto intro: kill_short_\) have "enat l \ ereal k" using \l \ k\ by auto also have "\ < (n/2) / \ G" using G_props \3 \ k\ by (cases "\ G") (auto simp: field_simps) also have "\ \ (n/2) / \ H" using \_HG \0 < \ H\ by (auto simp: ereal_of_enat_pushout intro!: ereal_divide_left_mono) also have "\ \ card (uverts H) / \ H" using card_H \0 < \ H\ by (auto intro!: ereal_divide_right_mono) also have "\ \ chromatic_number H" using uverts_H T1 by (intro chromatic_lb) auto finally have T3: "l < chromatic_number H" by (simp del: ereal_of_enat_simps) from T1 T2 T3 show ?thesis by fast qed end diff --git a/thys/Girth_Chromatic/Girth_Chromatic_Misc.thy b/thys/Girth_Chromatic/Girth_Chromatic_Misc.thy --- a/thys/Girth_Chromatic/Girth_Chromatic_Misc.thy +++ b/thys/Girth_Chromatic/Girth_Chromatic_Misc.thy @@ -1,189 +1,122 @@ theory Girth_Chromatic_Misc imports Main "HOL-Library.Extended_Real" begin section \Auxilliary lemmas and setup\ text \ This section contains facts about general concepts which are not directly connected to the proof of the Chromatic-Girth theorem. At some point in time, most of them could be moved to the Isabelle base library. Also, a little bit of setup happens. \ subsection \Numbers\ lemma enat_in_Inf: fixes S :: "enat set" assumes "Inf S \ top" shows "Inf S \ S" -proof (rule ccontr) - assume A: "~?thesis" - - obtain n where Inf_conv: "Inf S = enat n" using assms by (auto simp: top_enat_def) - { fix s assume "s \ S" - then have "Inf S \ s" by (rule complete_lattice_class.Inf_lower) - moreover have "Inf S \ s" using A \s \ S\ by auto - ultimately have "Inf S < s" by simp - with Inf_conv have "enat (Suc n) \ s" by (cases s) auto - } - then have "enat (Suc n) \ Inf S" by (simp add: le_Inf_iff) - with Inf_conv show False by auto -qed + using assms wellorder_InfI by auto lemma enat_in_INF: fixes f :: "'a \ enat" - assumes "(INF x\ S. f x) \ top" - obtains x where "x \ S" and "(INF x\ S. f x) = f x" -proof - - from assms have "(INF x\ S. f x) \ f ` S" - using enat_in_Inf [of "f ` S"] by auto - then obtain x where "x \ S" "(INF x\ S. f x) = f x" by auto - then show ?thesis .. -qed + assumes "(INF x\S. f x) \ top" + obtains x where "x \ S" and "(INF x\S. f x) = f x" + by (meson assms enat_in_Inf imageE) lemma enat_less_INF_I: fixes f :: "'a \ enat" assumes not_inf: "x \ \" and less: "\y. y \ S \ x < f y" shows "x < (INF y\S. f y)" using assms by (auto simp: Suc_ile_eq[symmetric] INF_greatest) lemma enat_le_Sup_iff: "enat k \ Sup M \ k = 0 \ (\m \ M. enat k \ m)" (is "?L \ ?R") proof cases assume "k = 0" then show ?thesis by (auto simp: enat_0) next assume "k \ 0" show ?thesis proof assume ?L then have "\enat k \ (if finite M then Max M else \); M \ {}\ \ \m\M. enat k \ m" by (metis Max_in Sup_enat_def finite_enat_bounded linorder_linear) with \k \ 0\ and \?L\ show ?R unfolding Sup_enat_def by (cases "M={}") (auto simp add: enat_0[symmetric]) next assume ?R then show ?L by (auto simp: enat_0 intro: complete_lattice_class.Sup_upper2) qed qed lemma enat_neq_zero_cancel_iff[simp]: "0 \ enat n \ 0 \ n" "enat n \ 0 \ n \ 0" by (auto simp: enat_0[symmetric]) lemma natceiling_lessD: "nat(ceiling x) < n \ x < real n" -by linarith + by linarith lemma le_natceiling_iff: fixes n :: nat and r :: real shows "n \ r \ n \ nat(ceiling r)" -by linarith + by linarith lemma natceiling_le_iff: fixes n :: nat and r :: real shows "r \ n \ nat(ceiling r) \ n" -by linarith + by linarith lemma dist_real_noabs_less: fixes a b c :: real assumes "dist a b < c" shows "a - b < c" using assms by (simp add: dist_real_def) -lemma n_choose_2_nat: - fixes n :: nat shows "(n choose 2) = (n * (n - 1)) div 2" -proof - - show ?thesis - proof (cases "2 \ n") - case True - then obtain m where "n = Suc (Suc m)" - by (metis add_Suc le_Suc_ex numeral_2_eq_2) - moreover have "(n choose 2) = (fact n div fact (n - 2)) div 2" - using \2 \ n\ by (simp add: binomial_altdef_nat - div_mult2_eq[symmetric] mult.commute numeral_2_eq_2) - ultimately show ?thesis by (simp add: algebra_simps) - qed (auto simp: binomial_eq_0) -qed - -lemma powr_less_one: - fixes x::real - assumes "1 < x" "y < 0" - shows "x powr y < 1" -using assms less_log_iff by force - -lemma powr_le_one_le: "\x y::real. 0 < x \ x \ 1 \ 1 \ y \ x powr y \ x" -proof - - fix x y :: real - assume "0 < x" "x \ 1" "1 \ y" - have "x powr y = (1 / (1 / x)) powr y" using \0 < x\ by (simp add: field_simps) - also have "\ = 1 / (1 / x) powr y" using \0 < x\ by (simp add: powr_divide) - also have "\ \ 1 / (1 / x) powr 1" proof - - have "1 \ 1 / x" using \0 < x\ \x \ 1\ by (auto simp: field_simps) - then have "(1 / x) powr 1 \ (1 / x) powr y" using \0 < x\ - using \1 \ y\ by ( simp only: powr_mono) - then show ?thesis - by (metis \1 \ 1 / x\ \1 \ y\ neg_le_iff_le powr_minus_divide powr_mono) - qed - also have "\ \ x" using \0 < x\ by (auto simp: field_simps) - finally show "?thesis x y" . -qed - - subsection \Lists and Sets\ lemma list_set_tl: "x \ set (tl xs) \ x \ set xs" -by (cases xs) auto + by (cases xs) auto lemma list_exhaust3: obtains "xs = []" | x where "xs = [x]" | x y ys where "xs = x # y # ys" -by (metis list.exhaust) + by (metis list.exhaust) lemma card_Ex_subset: "k \ card M \ \N. N \ M \ card N = k" -by (induct rule: inc_induct) (auto simp: card_Suc_eq) + by (induct rule: inc_induct) (auto simp: card_Suc_eq) subsection \Limits and eventually\ text \ We employ filters and the @{term eventually} predicate to deal with the @{term "\N. \n\N. P n"} cases. To make this more convenient, introduce a shorter syntax. \ abbreviation evseq :: "(nat \ bool) \ bool" (binder "\\<^sup>\" 10) where "evseq P \ eventually P sequentially" -lemma eventually_le_le: - fixes P :: "'a => ('b :: preorder)" - assumes "eventually (\x. P x \ Q x) net" - assumes "eventually (\x. Q x \ R x) net" - shows "eventually (\x. P x \ R x) net" -using assms by eventually_elim (rule order_trans) - lemma LIMSEQ_neg_powr: assumes s: "s < 0" shows "(%x. (real x) powr s) \ 0" -by (rule tendsto_neg_powr[OF assms filterlim_real_sequentially]) + by (simp add: filterlim_real_sequentially s tendsto_neg_powr) lemma LIMSEQ_inv_powr: assumes "0 < c" "0 < d" shows "(\n :: nat. (c / n) powr d) \ 0" proof (rule tendsto_zero_powrI) from \0 < c\ have "\x. 0 < x \ 0 < c / x" by simp then show "\\<^sup>\n. 0 \ c / real n" using assms(1) by auto show "(\x. c / real x) \ 0" - by (intro tendsto_divide_0[OF tendsto_const] filterlim_at_top_imp_at_infinity - filterlim_real_sequentially tendsto_divide_0) - show "0 < d" by (rule assms) - show "(\x. d) \ d" by auto -qed - + by (simp add: lim_const_over_n) +qed (use assms in force)+ end diff --git a/thys/Girth_Chromatic/Ugraphs.thy b/thys/Girth_Chromatic/Ugraphs.thy --- a/thys/Girth_Chromatic/Ugraphs.thy +++ b/thys/Girth_Chromatic/Ugraphs.thy @@ -1,293 +1,293 @@ theory Ugraphs imports Girth_Chromatic_Misc begin section \Undirected Simple Graphs\ text \ In this section, we define some basics of graph theory needed to formalize the Chromatic-Girth theorem. \ text \ For readability, we introduce synonyms for the types of vertexes, edges, graphs and walks. \ type_synonym uvert = nat type_synonym uedge = "nat set" type_synonym ugraph = "uvert set \ uedge set" type_synonym uwalk = "uvert list" abbreviation uedges :: "ugraph \ uedge set" where "uedges G \ snd G" abbreviation uverts :: "ugraph \ uvert set" where "uverts G \ fst G" fun mk_uedge :: "uvert \ uvert \ uedge" where "mk_uedge (u,v) = {u,v}" text \All edges over a set of vertexes @{term S}:\ definition "all_edges S \ mk_uedge ` {uv \ S \ S. fst uv \ snd uv}" definition uwellformed :: "ugraph \ bool" where "uwellformed G \ (\e\uedges G. card e = 2 \ (\u \ e. u \ uverts G))" fun uwalk_edges :: "uwalk \ uedge list" where "uwalk_edges [] = []" | "uwalk_edges [x] = []" | "uwalk_edges (x # y # ys) = {x,y} # uwalk_edges (y # ys)" definition uwalk_length :: "uwalk \ nat" where "uwalk_length p \ length (uwalk_edges p)" definition uwalks :: "ugraph \ uwalk set" where "uwalks G \ {p. set p \ uverts G \ set (uwalk_edges p) \ uedges G \ p \ []}" definition ucycles :: "ugraph \ uwalk set" where "ucycles G \ {p. uwalk_length p \ 3 \ p \ uwalks G \ distinct (tl p) \ hd p = last p}" definition remove_vertex :: "ugraph \ nat \ ugraph" ("_ -- _" [60,60] 60) where "remove_vertex G u \ (uverts G - {u}, uedges G - {A \ uedges G. u \ A})" subsection \Basic Properties\ lemma uwalk_length_conv: "uwalk_length p = length p - 1" by (induct p rule: uwalk_edges.induct) (auto simp: uwalk_length_def) lemma all_edges_mono: "vs \ ws \ all_edges vs \ all_edges ws" unfolding all_edges_def by auto lemma all_edges_subset_Pow: "all_edges A \ Pow A" by (auto simp: all_edges_def) lemma in_mk_uedge_img: "(a,b) \ A \ (b,a) \ A \ {a,b} \ mk_uedge ` A" by (auto intro: rev_image_eqI) lemma in_mk_uedge_img_iff: "{a,b} \ mk_uedge ` A \ (a,b) \ A \ (b,a) \ A" by (auto simp: doubleton_eq_iff intro: rev_image_eqI) lemma distinct_edgesI: assumes "distinct p" shows "distinct (uwalk_edges p)" proof - from assms have "?thesis" "\u. u \ set p \ (\v. u \ v \ {u,v} \ set (uwalk_edges p))" by (induct p rule: uwalk_edges.induct) auto then show ?thesis by simp qed lemma finite_ucycles: assumes "finite (uverts G)" shows "finite (ucycles G)" proof - have "ucycles G \ {xs. set xs \ uverts G \ length xs \ Suc (card (uverts G))}" proof (rule, simp) fix p assume "p \ ucycles G" then have "distinct (tl p)" and "set p \ uverts G" unfolding ucycles_def uwalks_def by auto moreover then have "set (tl p) \ uverts G" by (auto simp: list_set_tl) with assms have "card (set (tl p)) \ card (uverts G)" by (rule card_mono) then have "length (p) \ 1 + card (uverts G)" using distinct_card[OF \distinct (tl p)\] by auto ultimately show "set p \ uverts G \ length p \ Suc (card (uverts G))" by auto qed moreover have "finite {xs. set xs \ uverts G \ length xs \ Suc (card (uverts G))}" using assms by (rule finite_lists_length_le) ultimately show ?thesis by (rule finite_subset) qed lemma ucycles_distinct_edges: assumes "c \ ucycles G" shows "distinct (uwalk_edges c)" proof - from assms have c_props: "distinct (tl c)" "4 \ length c" "hd c = last c" by (auto simp add: ucycles_def uwalk_length_conv) then have "{hd c, hd (tl c)} \ set (uwalk_edges (tl c))" proof (induct c rule: uwalk_edges.induct) case (3 x y ys) then have "hd ys \ last ys" by (cases ys) auto moreover from 3 have "uwalk_edges (y # ys) = {y, hd ys} # uwalk_edges ys" by (cases ys) auto moreover { fix xs have "set (uwalk_edges xs) \ Pow (set xs)" by (induct xs rule: uwalk_edges.induct) auto } ultimately show ?case using 3 by auto qed simp_all moreover from assms have "distinct (uwalk_edges (tl c))" by (intro distinct_edgesI) (simp add: ucycles_def) ultimately show ?thesis by (cases c rule: list_exhaust3) auto qed lemma card_left_less_pair: fixes A :: "('a :: linorder) set" assumes "finite A" shows "card {(a,b). a \ A \ b \ A \ a < b} = (card A * (card A - 1)) div 2" using assms proof (induct A) case (insert x A) show ?case proof (cases "card A") case (Suc n) have "{(a,b). a \ insert x A \ b \ insert x A \ a < b} = {(a,b). a \ A \ b \ A \ a < b} \ (\a. if a < x then (a,x) else (x,a)) ` A" using \x \ A\ by (auto simp: order_less_le) moreover have "finite {(a,b). a \ A \ b \ A \ a < b}" using insert by (auto intro: finite_subset[of _ "A \ A"]) moreover have "{(a,b). a \ A \ b \ A \ a < b} \ (\a. if a < x then (a,x) else (x,a)) ` A = {}" using \x \ A\ by auto moreover have "inj_on (\a. if a < x then (a, x) else (x, a)) A" by (auto intro: inj_onI split: if_split_asm) ultimately show ?thesis using insert Suc by (simp add: card_Un_disjoint card_image del: if_image_distrib) qed (simp add: card_eq_0_iff insert) qed simp lemma card_all_edges: assumes "finite A" shows "card (all_edges A) = card A choose 2" proof - have inj_on_mk_uedge: "inj_on mk_uedge {(a,b). a < b}" by (rule inj_onI) (auto simp: doubleton_eq_iff) have "all_edges A = mk_uedge ` {(a,b). a \ A \ b \ A \ a < b}" (is "?L = ?R") by (auto simp: all_edges_def intro!: in_mk_uedge_img) then have "card ?L = card ?R" by simp also have "\ = card {(a,b). a \ A \ b \ A \ a < b}" using inj_on_mk_uedge by (blast intro: card_image subset_inj_on) also have "\ = (card A * (card A - 1)) div 2" using card_left_less_pair using assms by simp also have "\ = (card A choose 2)" - by (simp add: n_choose_2_nat) + by (simp add: choose_two) finally show ?thesis . qed lemma verts_Gu: "uverts (G -- u) = uverts G - {u}" unfolding remove_vertex_def by simp lemma edges_Gu: "uedges (G -- u) \ uedges G" unfolding remove_vertex_def by auto subsection \Girth, Independence and Vertex Colorings\ definition girth :: "ugraph \ enat" where "girth G \ INF p\ ucycles G. enat (uwalk_length p)" definition independent_sets :: "ugraph \ uvert set set" where "independent_sets Gr \ {vs. vs \ uverts Gr \ all_edges vs \ uedges Gr = {}}" definition \ :: "ugraph \ enat" where "\ G \ SUP vs \ independent_sets G. enat (card vs)" definition vertex_colorings :: "ugraph \ uvert set set set" where "vertex_colorings G \ {C. \C = uverts G \ (\c1\C. \c2\C. c1 \ c2 \ c1 \ c2 = {}) \ (\c\C. c \ {} \ (\u \ c. \v \ c. {u,v} \ uedges G))}" text \The chromatic number $\chi$:\ definition chromatic_number :: "ugraph \ enat" where "chromatic_number G \ INF c\ (vertex_colorings G). enat (card c)" lemma independent_sets_mono: "vs \ independent_sets G \ us \ vs \ us \ independent_sets G" using Int_mono[OF all_edges_mono, of us vs "uedges G" "uedges G"] unfolding independent_sets_def by auto lemma le_\_iff: assumes "0 < k" shows "k \ \ Gr \ k \ card ` independent_sets Gr" (is "?L \ ?R") proof assume ?L then obtain vs where "vs \ independent_sets Gr" and "k \ card vs" using assms unfolding \_def enat_le_Sup_iff by auto moreover then obtain us where "us \ vs" and "k = card us" using card_Ex_subset by auto ultimately have "us \ independent_sets Gr" by (auto intro: independent_sets_mono) then show ?R using \k = card us\ by auto qed (auto intro: SUP_upper simp: \_def) lemma zero_less_\: assumes "uverts G \ {}" shows "0 < \ G" proof - from assms obtain a where "a \ uverts G" by auto then have "0 < enat (card {a})" "{a} \ independent_sets G" by (auto simp: independent_sets_def all_edges_def) then show ?thesis unfolding \_def less_SUP_iff .. qed lemma \_le_card: assumes "finite (uverts G)" shows "\ G \ card(uverts G)" proof - { fix x assume "x \ independent_sets G" then have "x \ uverts G" by (auto simp: independent_sets_def) } with assms show ?thesis unfolding \_def by (intro SUP_least) (auto intro: card_mono) qed lemma \_fin: "finite (uverts G) \ \ G \ \" using \_le_card[of G] by (cases "\ G") auto lemma \_remove_le: shows "\ (G -- u) \ \ G" proof - have "independent_sets (G -- u) \ independent_sets G" (is "?L \ ?R") using all_edges_subset_Pow by (simp add: independent_sets_def remove_vertex_def) blast then show ?thesis unfolding \_def by (rule SUP_subset_mono) simp qed text \ A lower bound for the chromatic number of a graph can be given in terms of the independence number \ lemma chromatic_lb: assumes wf_G: "uwellformed G" and fin_G: "finite (uverts G)" and neG: "uverts G \ {}" shows "card (uverts G) / \ G \ chromatic_number G" proof - from wf_G have "(\v. {v}) ` uverts G \ vertex_colorings G" by (auto simp: vertex_colorings_def uwellformed_def) then have "chromatic_number G \ top" by (simp add: chromatic_number_def) (auto simp: top_enat_def) then obtain vc where vc_vc: "vc \ vertex_colorings G" and vc_size:"chromatic_number G = card vc" unfolding chromatic_number_def by (rule enat_in_INF) have fin_vc_elems: "\c. c \ vc \ finite c" using vc_vc by (intro finite_subset[OF _ fin_G]) (auto simp: vertex_colorings_def) have sum_vc_card: "(\c \ vc. card c) = card (uverts G)" using fin_vc_elems vc_vc unfolding vertex_colorings_def by (simp add: card_Union_disjoint[symmetric] pairwise_def disjnt_def) have "\c. c \ vc \ c \ independent_sets G" using vc_vc by (auto simp: vertex_colorings_def independent_sets_def all_edges_def) then have "\c. c \ vc \ card c \ \ G" using vc_vc fin_vc_elems by (subst le_\_iff) (auto simp add: vertex_colorings_def) then have "(\c\vc. card c) \ card vc * \ G" using sum_bounded_above[of vc card "\ G"] by (simp add: of_nat_eq_enat[symmetric] of_nat_sum) then have "ereal_of_enat (card (uverts G)) \ ereal_of_enat (\ G) * ereal_of_enat (card vc)" by (simp add: sum_vc_card ereal_of_enat_pushout ac_simps del: ereal_of_enat_simps) with zero_less_\[OF neG] \_fin[OF fin_G] vc_size show ?thesis by (simp add: ereal_divide_le_pos) qed end diff --git a/thys/Turans_Graph_Theorem/Turan.thy b/thys/Turans_Graph_Theorem/Turan.thy --- a/thys/Turans_Graph_Theorem/Turan.thy +++ b/thys/Turans_Graph_Theorem/Turan.thy @@ -1,858 +1,858 @@ theory Turan imports "Girth_Chromatic.Ugraphs" "Random_Graph_Subgraph_Threshold.Ugraph_Lemmas" begin section \Basic facts on graphs\ lemma wellformed_uverts_0 : assumes "uwellformed G" and "uverts G = {}" shows "card (uedges G) = 0" using assms by (metis uwellformed_def card.empty ex_in_conv zero_neq_numeral) lemma finite_verts_edges : assumes "uwellformed G" and "finite (uverts G)" shows "finite (uedges G)" proof - have sub_pow: "uwellformed G \ uedges G \ {S. S \ uverts G}" by (cases G, auto simp add: uwellformed_def) then have "finite {S. S \ uverts G}" using assms by auto with sub_pow assms show "finite (uedges G)" using finite_subset by blast qed lemma ugraph_max_edges : assumes "uwellformed G" and "card (uverts G) = n" and "finite (uverts G)" shows "card (uedges G) \ n * (n-1)/2" using assms wellformed_all_edges [OF assms(1)] card_all_edges [OF assms(3)] Binomial.choose_two [of "card(uverts G)"] by (smt (verit, del_insts) all_edges_finite card_mono dbl_simps(3) dbl_simps(5) div_times_less_eq_dividend le_divide_eq_numeral1(1) le_square nat_mult_1_right numerals(1) of_nat_1 of_nat_diff of_nat_mono of_nat_mult of_nat_numeral right_diff_distrib') lemma subgraph_verts_finite : "\ finite (uverts G); subgraph G' G \ \ finite (uverts G')" using rev_finite_subset subgraph_def by auto section \Cliques\ text \In this section a straightforward definition of cliques for simple, undirected graphs is introduced. Besides fundamental facts about cliques, also more specialized lemmata are proved in subsequent subsections.\ definition uclique :: "ugraph \ ugraph \ nat \ bool" where "uclique C G p \ p = card (uverts C) \ subgraph C G \ C = complete (uverts C)" lemma clique_any_edge : assumes "uclique C G p" and "x \ uverts C" and "y \ uverts C" and "x \ y" shows "{x,y} \ uedges G" using assms apply (simp add: uclique_def complete_def all_edges_def subgraph_def) by (smt (verit, best) SigmaI fst_conv image_iff mem_Collect_eq mk_uedge.simps snd_conv subset_eq) lemma clique_exists : "\ C p. uclique C G p \ p \ card (uverts G)" using bex_imageD card.empty emptyE gr_implies_not0 le_neq_implies_less by (auto simp add: uclique_def complete_def subgraph_def all_edges_def) lemma clique_exists1 : assumes "uverts G \ {}" and "finite (uverts G)" shows "\ C p. uclique C G p \ 0 < p \ p \ card (uverts G)" proof - obtain x where x: "x \ uverts G" using assms by auto show ?thesis apply (rule exI [of _ "({x},{})"], rule exI [of _ 1]) using x assms(2) by (simp add: uclique_def subgraph_def complete_def all_edges_def Suc_leI assms(1) card_gt_0_iff) qed lemma clique_max_size : "uclique C G p \ finite (uverts G) \ p \ card (uverts G)" by (auto simp add: uclique_def subgraph_def Finite_Set.card_mono) lemma clique_exists_gt0 : assumes "finite (uverts G)" "card (uverts G) > 0" shows "\ C p. uclique C G p \ p \ card (uverts G) \ (\C q. uclique C G q \ q \ p)" proof - have 1: "finite (uverts G) \ finite {p. \C. uclique C G p}" using clique_max_size by (smt (verit, best) finite_nat_set_iff_bounded_le mem_Collect_eq) have 2: "\A::nat set. finite A \ \x. x\A \ \x\A.\y\A. y \ x" using Max_ge Max_in by blast have "\C p. uclique C G p \ (\C q. uclique C G q \ q \ p)" using 2 [OF 1 [OF \finite (uverts G)\]] clique_exists [of G] by (smt (z3) mem_Collect_eq) then show ?thesis using \finite (uverts G)\ clique_max_size by blast qed text \If there exists a $(p+1)$-clique @{term C} in a graph @{term G} then we can obtain a $p$-clique in @{term G} by removing an arbitrary vertex from @{term C}\ lemma clique_size_jumpfree : assumes "finite (uverts G)" and "uwellformed G" and "uclique C G (p+1)" shows "\C'. uclique C' G p" proof - have "card(uverts G) > p" using assms by (simp add: uclique_def subgraph_def card_mono less_eq_Suc_le) obtain x where x: "x \ uverts C" using assms by (fastforce simp add: uclique_def) have "mk_uedge ` {uv \ uverts C \ uverts C. fst uv \ snd uv} - {A \ uedges C. x \ A} = mk_uedge ` {uv \ (uverts C - {x}) \ (uverts C - {x}). fst uv \ snd uv}" proof - have "\y. y \ mk_uedge ` {uv \ uverts C \ uverts C. fst uv \ snd uv} - {A \ uedges C. x \ A} \ y \ mk_uedge ` {uv \ (uverts C - {x}) \ (uverts C - {x}). fst uv \ snd uv}" using assms(3) apply (simp add: uclique_def complete_def all_edges_def) by (smt (z3) DiffI SigmaE SigmaI image_iff insertCI mem_Collect_eq mk_uedge.simps singleton_iff snd_conv) moreover have "\y. y \ mk_uedge ` {uv \ (uverts C - {x}) \ (uverts C - {x}). fst uv \ snd uv} \ y \ mk_uedge ` {uv \ uverts C \ uverts C. fst uv \ snd uv} - {A \ uedges C. x \ A}" apply (simp add: uclique_def complete_def all_edges_def) by (smt (z3) DiffE SigmaE SigmaI image_iff insert_iff mem_Collect_eq mk_uedge.simps singleton_iff) ultimately show ?thesis by blast qed then have 1: "(uverts C - {x}, uedges C - {A \ uedges C. x \ A}) = Ugraph_Lemmas.complete (uverts C - {x})" using assms(3) apply (simp add: uclique_def complete_def all_edges_def) by (metis (no_types, lifting) snd_eqD) show ?thesis apply (rule exI [of _ "C -- x"]) using assms x apply (simp add: uclique_def remove_vertex_def subgraph_def) apply (simp add: 1) by (auto simp add: complete_def all_edges_def) qed text \The next lemma generalises the lemma @{thm [source] clique_size_jumpfree} to a proof of the existence of a clique of any size smaller than the size of the original clique.\ lemma clique_size_decr : assumes "finite (uverts G)" and "uwellformed G" and "uclique C G p" shows "q \ p \ \C. uclique C G q" using assms proof (induction q rule: measure_induct [of "\x. p - x"]) case (1 x) then show ?case proof (cases "x = p") case True then show ?thesis using \uclique C G p\ by blast next case False with 1(2) have "x < p" by auto from \x < p\ have "p - Suc x < p - x" by auto then show ?thesis using 1(1) assms(1,2,3) \x < p\ using clique_size_jumpfree [OF \finite (uverts G)\ \uwellformed G\ _] by (metis "1.prems"(4) add.commute linorder_not_le not_less_eq plus_1_eq_Suc) qed qed text \With this lemma we can easily derive by contradiction that if there is no $p$-clique then there cannot exist a clique of a size greater than @{term p}\ corollary clique_size_neg_max : assumes "finite (uverts G)" and "uwellformed G" and "\(\C. uclique C G p)" shows "\C q. uclique C G q \ q < p" proof (rule ccontr) assume 1: "\ (\C q. uclique C G q \ q < p)" show False proof - obtain C q where C: "uclique C G q" and q: "q \ p" using 1 linorder_not_less by blast show ?thesis using assms(3) q clique_size_decr [OF \finite (uverts G)\ \uwellformed G\ C ] using order_less_imp_le by blast qed qed corollary clique_complete : assumes "finite V" and "x \ card V" shows "\C. uclique C (complete V) x" proof - have "uclique (complete V) (complete V) (card V)" by (simp add: uclique_def complete_def subgraph_def) then show ?thesis using clique_size_decr [OF _ complete_wellformed [of V] _ assms(2)] assms(1) by (simp add: complete_def) qed lemma subgraph_clique : assumes "uwellformed G" "subgraph C G" "C = complete (uverts C)" shows "{e \ uedges G. e \ uverts C} = uedges C" proof - from assms complete_wellformed [of "uverts C"] have "uedges C \ {e \ uedges G. e \ uverts C}" by (auto simp add: subgraph_def uwellformed_def) moreover from assms(1) complete_wellformed [of "uverts C"] have "{e \ uedges G. e \ uverts C} \ uedges C" apply (simp add: subgraph_def uwellformed_def complete_def card_2_iff all_edges_def) using assms(3)[unfolded complete_def all_edges_def] in_mk_uedge_img by (smt (verit, ccfv_threshold) SigmaI fst_conv insert_subset mem_Collect_eq snd_conv subsetI) ultimately show ?thesis by auto qed text \Next, we prove that in a graph @{term G} with a $p$-clique @{term C} and some vertex @{term v} outside of this clique, there exists a $(p+1)$-clique in @{term G} if @{term v} is connected to all nodes in @{term C}. The next lemma is an abstracted version that does not explicitly mention cliques: If a vertex @{term n} has as many edges to a set of nodes @{term N} as there are nodes in @{term N} then @{term n} is connected to all vertices in @{term N}.\ lemma card_edges_nodes_all_edges : fixes G :: "ugraph" and N :: "nat set" and E :: "nat set set" and n :: nat assumes "uwellformed G" and "finite N" and "N \ uverts G" and "E \ uedges G" and "n \ uverts G" and "n \ N" and "\e \ E. \x \ N. {n,x} = e" and "card E = card N" shows "\x \ N. {n,x} \ E" proof (rule ccontr) assume "\(\x \ N. {n,x} \ E)" show False proof - obtain x where x: "x \ N" and e: "{n,x} \ E" using \\(\x \ N. {n,x} \ E)\ by auto have "E \ (\y. {n,y}) ` (N - {x})" using Set.image_diff_subset \\e \ E. \x \ N. {n,x} = e\ x e by auto then show ?thesis using \finite N\ \card E = card N\ x using surj_card_le [of "N - {x}" E "(\y. {n,y})"] by (simp, metis card_gt_0_iff diff_less emptyE lessI linorder_not_le) qed qed subsection \Partitioning edges along a clique\ text \Tur\'{a}n's proof partitions the edges of a graph into three partitions for a $(p-1)$-clique @{term C}: All edges within @{term C}, all edges outside of @{term C}, and all edges between a vertex in @{term C} and a vertex not in @{term C}. We prove a generalized lemma that partitions the edges along some arbitrary set of vertices which does not necessarily need to induce a clique. Furthermore, in Tur\'{a}n's graph theorem we only argue about the cardinality of the partitions so that we restrict this proof to showing that the sum of the cardinalities of the partitions is equal to number of all edges.\ lemma graph_partition_edges_card : assumes "finite (uverts G)" and "uwellformed G" and "A \ (uverts G)" shows "card (uedges G) = card {e \ uedges G. e \ A} + card {e \ uedges G. e \ uverts G - A} + card {e \ uedges G. e \ A \ {} \ e \ (uverts G - A) \ {}}" using assms proof - have "uedges G = {e \ uedges G. e \ A} \ {e \ uedges G. e \ (uverts G) - A} \ {e \ uedges G. e \ A \ {} \ e \ ((uverts G) - A) \ {}}" using assms uwellformed_def by blast moreover have "{e \ uedges G. e \ A} \ {e \ uedges G. e \ uverts G - A} = {}" using assms uwellformed_def by (smt (verit, ccfv_SIG) Diff_disjoint Int_subset_iff card.empty disjoint_iff mem_Collect_eq nat.simps(3) nat_1_add_1 plus_1_eq_Suc prod.sel(2) subset_empty) moreover have "({e \ uedges G. e \ A} \ {e \ uedges G. e \ uverts G - A}) \ {e \ uedges G. e \ A \ {} \ e \ (uverts G - A) \ {}} = {}" by blast moreover have "finite {e \ uedges G. e \ A}" using assms by (simp add: finite_subset) moreover have "finite {e \ uedges G. e \ uverts G - A}" using assms by (simp add: finite_subset) moreover have "finite {e \ uedges G. e \ A \ {} \ e \ (uverts G - A) \ {}}" using assms finite_verts_edges by auto ultimately show ?thesis using assms Finite_Set.card_Un_disjoint by (smt (verit, best) finite_UnI) qed text \Now, we turn to the problem of calculating the cardinalities of these partitions when they are induced by the biggest clique in the graph. First, we consider the number of edges in a $p$-clique.\ lemma clique_edges_inside : assumes G1: "uwellformed G" and G2: "finite (uverts G)" and p: "p \ card (uverts G)" and n: "n = card(uverts G)" and C: "uclique C G p" shows "card {e \ uedges G. e \ uverts C} = p * (p-1) / 2" proof - have "2 dvd (card (uverts C) * (p - 1))" using C uclique_def by auto have "2 = real 2" by simp then show ?thesis using C uclique_def [of C G p] complete_def [of "uverts C"] using subgraph_clique [OF G1, of C] subgraph_verts_finite [OF assms(2), of C] using Real.real_of_nat_div [OF \2 dvd (card (uverts C) * (p - 1))\] Binomial.choose_two [of " card (uverts G)"] - by (smt (verit, del_insts) One_nat_def approximation_preproc_nat(5) card_all_edges diff_self_eq_0 eq_imp_le left_diff_distrib' left_diff_distrib' linorder_not_less mult_le_mono2 n_choose_2_nat not_gr0 not_less_eq_eq of_nat_1 of_nat_diff snd_eqD) + by (smt (verit, del_insts) One_nat_def approximation_preproc_nat(5) card_all_edges diff_self_eq_0 eq_imp_le left_diff_distrib' left_diff_distrib' linorder_not_less mult_le_mono2 choose_two not_gr0 not_less_eq_eq of_nat_1 of_nat_diff snd_eqD) qed text \Next, we turn to the number of edges that connect a node inside of the biggest clique with a node outside of said clique. For that we start by calculating a bound for the number of edges from one single node outside of the clique into the clique.\ lemma clique_edges_inside_to_node_outside : assumes "uwellformed G" and "finite (uverts G)" assumes "0 < p" and "p \ card (uverts G)" assumes "uclique C G p" and "(\C p'. uclique C G p' \ p' \ p)" assumes y: "y \ uverts G - uverts C" shows "card {{x,y}| x. x \ uverts C \ {x,y} \ uedges G} \ p - 1" proof (rule ccontr) txt \For effective proof automation we use a local function definition to compute this set of edges into the clique from any node @{term y}:\ define S where "S \ \y. {{x,y}| x. x \ uverts C \ {x,y} \ uedges G}" assume "\ card {{x, y} |x. x \ uverts C \ {x, y} \ uedges G} \ p - 1" then have Sy: "card (S y) > p - 1" using S_def y by auto have "uclique ({y} \ (uverts C),S y \ uedges C) G (Suc p)" proof - have "card ({y} \ uverts C) = Suc p" using assms(3,5,7) uclique_def by (metis DiffD2 card_gt_0_iff card_insert_disjoint insert_is_Un) moreover have "subgraph ({y} \ uverts C, (S y) \ uedges C) G" using assms(5,7) by (auto simp add: uclique_def subgraph_def S_def) moreover have "({y} \ (uverts C),(S y) \ uedges C) = complete ({y} \ (uverts C))" proof - have "(S y) \ uedges C \ all_edges ({y} \ (uverts C))" using y assms(5) S_def all_edges_def uclique_def complete_def by (simp, smt (z3) SigmaE SigmaI fst_conv image_iff in_mk_uedge_img insertCI mem_Collect_eq snd_conv subsetI) moreover have "all_edges ({y} \ (uverts C)) \ (S y) \ uedges C" proof - have "\x\uverts C. {y, x} \ S y" proof - have "card (S y) = card (uverts C)" using Sy assms(2,3,5,7) S_def uclique_def card_gt_0_iff using Finite_Set.surj_card_le [of "uverts C" "S y" "\x. {x, y}"] by (smt (verit, del_insts) Suc_leI Suc_pred' image_iff le_antisym mem_Collect_eq subsetI) then show ?thesis using card_edges_nodes_all_edges [OF assms(1), of "uverts C" "S y" y] assms(1,2,5,7) S_def uclique_def by (smt (verit, ccfv_threshold) DiffE insert_commute mem_Collect_eq subgraph_def subgraph_verts_finite subsetI) qed then show ?thesis using assms(5) all_edges_def S_def uclique_def complete_def mk_uedge.simps in_mk_uedge_img by (smt (z3) insert_commute SigmaI fst_conv mem_Collect_eq snd_conv SigmaE UnCI image_iff insert_iff insert_is_Un subsetI) qed ultimately show ?thesis by (auto simp add: complete_def) qed ultimately show ?thesis by (simp add: uclique_def complete_def) qed then show False using assms(6) by fastforce qed text \Now, that we have this upper bound for the number of edges from a single vertex into the largest clique we can calculate the upper bound for all such vertices and edges:\ lemma clique_edges_inside_to_outside : assumes G1: "uwellformed G" and G2: "finite (uverts G)" and p0: "0 < p" and pn: "p \ card (uverts G)" and "card(uverts G) = n" and C: "uclique C G p" and C_max: "(\C p'. uclique C G p' \ p' \ p)" shows "card {e \ uedges G. e \ uverts C \ {} \ e \ (uverts G - uverts C) \ {}} \ (p - 1) * (n - p)" proof - define S where "S \ \y. {{x,y}| x. x \ uverts C \ {x,y} \ uedges G}" have "card (uverts G - uverts C) = n - p" using pn C \card(uverts G) = n\ G2 apply (simp add: uclique_def) by (meson card_Diff_subset subgraph_def subgraph_verts_finite) moreover have "{e \ uedges G. e \ uverts C \ {} \ e \ (uverts G - uverts C) \ {}} = {{x,y}| x y. x \ uverts C \ y \ (uverts G - uverts C) \ {x,y} \ uedges G}" proof - have "e \ {e \ uedges G. e \ uverts C \ {} \ e \ (uverts G - uverts C) \ {}} \ \x y. e = {x,y} \ x \ uverts C \ y \ uverts G - uverts C" for e using G1 apply (simp add: uwellformed_def) by (smt (z3) DiffD2 card_2_iff disjoint_iff_not_equal insert_Diff insert_Diff_if insert_iff) then show ?thesis by auto qed moreover have "card {{x,y}| x y. x \ uverts C \ y \ (uverts G - uverts C) \ {x,y} \ uedges G} \ card (uverts G - uverts C) * (p-1)" proof - have "card {{x,y}| x y. x \ uverts C \ y \ (uverts G - uverts C) \ {x,y} \ uedges G} \ (\y \ (uverts G - uverts C). card (S y))" proof - have "finite (uverts G - uverts C)" using \finite (uverts G)\ by auto have "{{x,y}| x y. x \ uverts C \ y \ (uverts G - uverts C) \ {x,y} \ uedges G} = (\y \ (uverts G - uverts C). {{x,y}| x. x \ uverts C \ {x,y} \ uedges G})" by auto then show ?thesis using Groups_Big.card_UN_le [OF \finite (uverts G - uverts C)\, of "\y. {{x, y} |x. x \ uverts C \ {x, y} \ uedges G}"] using S_def by auto qed moreover have "(\y\uverts G - uverts C. card (S y)) \ card (uverts G - uverts C) * (p-1)" proof - have "card (S y) \ p - 1" if y: "y \ uverts G - uverts C" for y using clique_edges_inside_to_node_outside [OF assms(1,2,3,4) C C_max y] S_def y by simp then show ?thesis by (metis id_apply of_nat_eq_id sum_bounded_above) qed ultimately show ?thesis using order_trans by blast qed ultimately show ?thesis by (smt (verit, ccfv_SIG) mult.commute) qed text \Lastly, we need to argue about the number of edges which are located entirely outside of the greatest clique. Note that this is in the inductive step case in the overarching proof of Tur\'{a}n's graph theorem. That is why we have access to the inductive hypothesis as an assumption in the following lemma:\ lemma clique_edges_outside : assumes "uwellformed G" and "finite (uverts G)" and p2: "2 \ p" and pn: "p \ card (uverts G)" and n: "n = card(uverts G)" and C: "uclique C G (p-1)" and C_max: "(\C q. uclique C G q \ q \ p-1)" and IH: "\G y. y < n \ finite (uverts G) \ uwellformed G \ \C p'. uclique C G p' \ p' < p \ 2 \ p \ card (uverts G) = y \ real (card (uedges G)) \ (1 - 1 / real (p - 1)) * real (y\<^sup>2) / 2" shows "card {e \ uedges G. e \ uverts G - uverts C} \ (1 - 1 / (p-1)) * (n - p + 1) ^ 2 / 2" proof - have "n - card (uverts C) < n" using C pn p2 n by (metis Suc_pred' diff_less less_2_cases_iff linorder_not_less not_gr0 uclique_def) have GC1: "finite (uverts (uverts G - uverts C, {e \ uedges G. e \ uverts G - uverts C}))" using assms(2) by simp have GC2: "uwellformed (uverts G - uverts C, {e \ uedges G. e \ uverts G - uverts C})" using assms(1) by (auto simp add: uwellformed_def) have GC3: "\C' p'. uclique C' (uverts G - uverts C, {e \ uedges G. e \ uverts G - uverts C}) p' \ p' < p" proof (rule ccontr) assume "\(\C' p'. uclique C' (uverts G - uverts C, {e \ uedges G. e \ uverts G - uverts C}) p' \ p' < p)" then obtain C' p' where C': "uclique C' (uverts G - uverts C, {e \ uedges G. e \ uverts G - uverts C}) p'" and p': "p' \ p" by auto then have "uclique C' G p'" using uclique_def subgraph_def by auto then show False using p' p2 C_max by fastforce qed have GC4: "card (uverts (uverts G - uverts C,{e \ uedges G. e \ uverts G - uverts C})) = n - card (uverts C)" using C n assms(2) uclique_def subgraph_def by (simp, meson card_Diff_subset infinite_super) show ?thesis using C GC3 IH [OF \n - card (uverts C) < n\ GC1 GC2 GC3 \2 \ p\ GC4] assms(2) n uclique_def by (simp, smt (verit, best) C One_nat_def Suc_1 Suc_leD clique_max_size of_nat_1 of_nat_diff p2) qed subsection \Extending the size of the biggest clique\ text_raw \\label{sec:extend_clique}\ text \In this section, we want to prove that we can add edges to a graph so that we augment the biggest clique to some greater clique with a specific number of vertices. For that, we need the following lemma: When too many edges have been added to a graph so that there exists a $(p+1)$-clique then we can remove at least one of the added edges while also retaining a p-clique\ lemma clique_union_size_decr : assumes "finite (uverts G)" and "uwellformed (uverts G, uedges G \ E)" and "uclique C (uverts G, uedges G \ E) (p+1)" and "card E \ 1" shows "\C' E'. card E' < card E \ uclique C' (uverts G, uedges G \ E') p \ uwellformed (uverts G, uedges G \ E')" proof (cases "\x \ uverts C. \e \ E. x \ e") case True then obtain x where x1: "x \ uverts C" and x2: "\e \ E. x \ e" by auto show ?thesis proof (rule exI [of _ "C -- x"], rule exI [of _ "{e \ E. x \ e}"]) have "card {e \ E. x \ e} < card E" using x2 assms(4) by (smt (verit) One_nat_def card.infinite diff_is_0_eq mem_Collect_eq minus_nat.diff_0 not_less_eq psubset_card_mono psubset_eq subset_eq) moreover have "uclique (C -- x) (uverts G, uedges G \ {e \ E. x \ e}) p" proof - have "p = card (uverts (C -- x))" using x1 assms(3) by (auto simp add: uclique_def remove_vertex_def) moreover have "subgraph (C -- x) (uverts G, uedges G \ {e \ E. x \ e})" using assms(3) by (auto simp add: uclique_def subgraph_def remove_vertex_def) moreover have "C -- x = Ugraph_Lemmas.complete (uverts (C -- x))" proof - have 1: "\y. y \ mk_uedge ` {uv \ uverts C \ uverts C. fst uv \ snd uv} - {A \ uedges C. x \ A} \ y \ mk_uedge ` {uv \ (uverts C - {x}) \ (uverts C - {x}). fst uv \ snd uv}" by (smt (z3) DiffE DiffI SigmaE SigmaI Ugraph_Lemmas.complete_def all_edges_def assms(3) empty_iff image_iff insert_iff mem_Collect_eq mk_uedge.simps snd_conv uclique_def) have 2: "\y. y \ mk_uedge ` {uv \ (uverts C - {x}) \ (uverts C - {x}). fst uv \ snd uv} \ y \ mk_uedge ` {uv \ uverts C \ uverts C. fst uv \ snd uv} - {A \ uedges C. x \ A}" by (smt (z3) DiffE DiffI SigmaE SigmaI image_iff insert_iff mem_Collect_eq mk_uedge.simps singleton_iff) show ?thesis using assms(3) apply (simp add: remove_vertex_def complete_def all_edges_def uclique_def) using 1 2 by (smt (verit, ccfv_SIG) split_pairs subset_antisym subset_eq) qed ultimately show ?thesis by (simp add: uclique_def) qed moreover have "uwellformed (uverts G, uedges G \ {e \ E. x \ e})" using assms(2) by (auto simp add: uwellformed_def) ultimately show "card {e \ E. x \ e} < card E \ uclique (C -- x) (uverts G, uedges G \ {e \ E. x \ e}) p \ uwellformed (uverts G, uedges G \ {e \ E. x \ e})" by auto qed next case False then have "\x. x \ uedges C \ x \ E" using assms(2) by (metis assms(3) card_2_iff' complete_wellformed uclique_def uwellformed_def) then have "uclique C G (p+1)" using assms(3) by (auto simp add: uclique_def subgraph_def uwellformed_def) show ?thesis using assms(2,4) clique_size_jumpfree [OF assms(1) _ \uclique C G (p+1)\] apply (simp add: uwellformed_def) by (metis Suc_le_eq UnCI Un_empty_right card.empty prod.exhaust_sel) qed text \We use this preceding lemma to prove the next result. In this lemma we assume that we have added too many edges. The goal is then to remove some of the new edges appropriately so that it is indeed guaranteed that there is no bigger clique. Two proofs of this lemma will be described in the following. Both fundamentally come down to the same core idea: In essence, both proofs apply the well-ordering principle. In the first proof we do so immediately by obtaining the minimum of a set:\ lemma clique_union_make_greatest : fixes p n :: nat assumes "finite (uverts G)" and "uwellformed G" and "uwellformed (uverts G, uedges G \ E)" and "card(uverts G) \ p" and "uclique C (uverts G, uedges G \ E) p" and "\C' q'. uclique C' G q' \ q' < p" and "1 \ card E" shows "\C' E'. uwellformed (uverts G, uedges G \ E') \ (uclique C' (uverts G, uedges G \ E') p) \ (\C'' q'. uclique C'' (uverts G, uedges G \ E') q' \ q' \ p)" using assms proof (induction "card E" arbitrary: C E rule: less_induct) case (less E) then show ?case proof (cases "\A. uclique A (uverts G, uedges G \ E) (p+1)") case True then obtain A where A: "uclique A (uverts G, uedges G \ E) (p+1)" by auto obtain C' E' where E'1: "card E' < card E" and E'2: "uclique C' (uverts G, uedges G \ E') p" and E'3: "uwellformed (uverts G, uedges G \ E')" and E'4: "1 \ card E'" using less(7) using clique_union_size_decr [OF assms(1) \uwellformed (uverts G, uedges G \ E)\ A less(8)] by (metis One_nat_def Suc_le_eq Un_empty_right card_gt_0_iff finite_Un finite_verts_edges fst_conv less.prems(1) less_not_refl prod.collapse snd_conv) show ?thesis using less(1) [OF E'1 assms(1,2) E'3 less(5) E'2 less(7) E'4] using E'1 less(8) by (meson less_or_eq_imp_le order_le_less_trans) next case False show ?thesis apply (rule exI [of _ C], rule exI [of _ E]) using clique_size_neg_max [OF _ less(4) False] using less(2,4,6) by fastforce qed qed text \In this second, alternative proof the well-ordering principle is used through complete induction.\ lemma clique_union_make_greatest_alt : fixes p n :: nat assumes "finite (uverts G)" and "uwellformed G" and "uwellformed (uverts G, uedges G \ E)" and "card(uverts G) \ p" and "uclique C (uverts G, uedges G \ E) p" and "\C' q'. uclique C' G q' \ q' < p" and "1 \ card E" shows "\C' E'. uwellformed (uverts G, uedges G \ E') \ (uclique C' (uverts G, uedges G \ E') p) \ (\C'' q'. uclique C'' (uverts G, uedges G \ E') q' \ q' \ p)" proof - define P where "P \ \E. uwellformed (uverts G, uedges G \ E) \ (\C. uclique C (uverts G, uedges G \ E) p)" have "finite {y. \E. P E \ card E = y}" proof - have "\E. P E \ E \ Pow (uverts G)" by (auto simp add: P_def uwellformed_def) then have "finite {E. P E}" using assms(1) by (metis Collect_mono Pow_def finite_Pow_iff rev_finite_subset) then show ?thesis by simp qed obtain F where F1: "P F" and F2: "card F = Min {y. \E. P E \ card E = y}" and F3: "card F > 0" using assms(1,3,4,5,6) Min_in \finite {y. \E. P E \ card E = y}\ P_def CollectD Collect_empty_eq by (smt (verit, ccfv_threshold) Un_empty_right card_gt_0_iff finite_Un finite_verts_edges fst_conv le_refl linorder_not_le prod.collapse snd_conv) have "p > 0" using assms(6) clique_exists bot_nat_0.not_eq_extremum by blast then show ?thesis proof (cases "\C. uclique C (uverts G, uedges G \ F) (p + 1)") case True then obtain F' where F'1 : "P F'" and F'2: "card F' < card F" using F1 F2 F3 clique_union_size_decr [OF assms(1), of F _ p] P_def by (smt (verit) One_nat_def Suc_eq_plus1 Suc_leI add_2_eq_Suc' assms(1) clique_size_jumpfree fst_conv) then show ?thesis using F2 \finite {y. \F. P F \ card F = y}\ Min_gr_iff by fastforce next case False then show ?thesis using clique_size_neg_max [OF _ _ False] using assms(1) F1 P_def by (smt (verit, ccfv_SIG) Suc_eq_plus1 Suc_leI fst_conv linorder_not_le) qed qed text \Finally, with this lemma we can turn to this section's main challenge of increasing the greatest clique size of a graph by adding edges.\ lemma clique_add_edges_max : fixes p :: nat assumes "finite (uverts G)" and "uwellformed G" and "card(uverts G) > p" and "\C. uclique C G p" and "(\C q'. uclique C G q' \ q' \ p)" and "q \ card(uverts G)" and "p \ q" shows "\E. uwellformed (uverts G, uedges G \ E) \ (\C. uclique C (uverts G, uedges G \ E) q) \ (\C q'. uclique C (uverts G, uedges G \ E) q' \ q' \ q)" proof (cases "p < q") case True then show ?thesis proof - have "\E. uwellformed (uverts G, uedges G \ E) \ (\C. uclique C (uverts G, uedges G \ E) q) \ card E \ 1" apply (rule exI [of _ "all_edges (uverts G)"]) using Set.Un_absorb1 [OF wellformed_all_edges [OF assms(2)]] using complete_wellformed [of "uverts G"] clique_complete [OF assms(1,6)] using all_edges_def assms(1,5) apply (simp add: complete_def) by (metis Suc_leI True Un_empty_right all_edges_finite card_gt_0_iff linorder_not_less prod.collapse) then obtain E C where E1: "uwellformed (uverts G, uedges G \ E)" and E2: "uclique C (uverts G, uedges G \ E) q" and E3: "card E \ 1" by auto show ?thesis using clique_union_make_greatest [OF assms(1,2) E1 assms(6) E2 _ E3] assms(5) True using order_le_less_trans by blast qed next case False show ?thesis apply (rule exI [of _ "{}"]) using False assms(2,4,5,7) by simp qed section \Properties of the upper edge bound\ text \In this section we prove results about the upper edge bound in Tur\'{a}n's theorem. The first lemma proves that upper bounds of the sizes of the partitions sum up exactly to the overall upper bound.\ lemma turan_sum_eq : fixes n p :: nat assumes "p \ 2" and "p \ n" shows "(p-1) * (p-2) / 2 + (1 - 1 / (p-1)) * (n - p + 1) ^ 2 / 2 + (p - 2) * (n - p + 1) = (1 - 1 / (p-1)) * n^2 / 2" proof - have "a * (a-1) / 2 + (1 - 1 / a) * (n - a) ^ 2 / 2 + (a - 1) * (n - a) = (1 - 1 / a) * n^2 / 2" if a1: "a \ 1" and a2: "n \ a" for a :: nat proof - have "a\<^sup>2 + (n - a)\<^sup>2 + a * (n - a) * 2 = n\<^sup>2" using a2 apply (simp flip: Groups.ab_semigroup_mult_class.mult.commute [of 2 "a * (n - a)"]) apply (simp add: Semiring_Normalization.comm_semiring_1_class.semiring_normalization_rules(18) [of 2 a "(n - a)"]) by (simp flip: Power.comm_semiring_1_class.power2_sum [of a "n-a"]) then have "((a - 1) / a) * (a ^ 2 + (n - a) ^ 2 + a * (n - a) * 2) = ((a - 1) / a) * n^2" by presburger then have "(((a - 1) / a) * a ^ 2 + ((a - 1) / a) * (n - a) ^ 2 + ((a - 1) / a) * a * (n - a) * 2) = ..." using Rings.semiring_class.distrib_left [of "(a - 1) / a" "a\<^sup>2 + (n - a)\<^sup>2" "a * (n - a) * 2"] using Rings.semiring_class.distrib_left [of "(a - 1) / a" "a\<^sup>2" "(n - a)\<^sup>2"] by auto moreover have "((a - 1) / a) * a ^ 2 = a * (a-1)" by (simp add: power2_eq_square) ultimately have "a * (a-1) + ((a - 1) / a) * (n - a) ^ 2 + (a - 1) * (n - a) * 2 = ((a - 1) / a) * n^2" using a1 a2 by auto moreover have "1 - 1 / a = (a - 1) / a" by (smt (verit, del_insts) One_nat_def Suc_pred diff_divide_distrib diff_is_0_eq of_nat_1 of_nat_diff of_nat_le_0_iff of_nat_le_iff of_nat_less_iff right_inverse_eq that) ultimately have "a * (a-1) + (1 - 1 / a) * (n - a) ^ 2 + (a - 1) * (n - a) * 2 = (1 - 1 / a) * n^2" by simp then show ?thesis by simp qed moreover have "p - 1 \ 1" using \p \ 2\ by auto moreover have "n \ p - 1" using assms(2) by auto ultimately show ?thesis by (smt (verit) assms Nat.add_diff_assoc2 Nat.diff_diff_right diff_diff_left le_eq_less_or_eq less_Suc_eq_le linorder_not_less nat_1_add_1 plus_1_eq_Suc) qed text \The next fact proves that the upper bound of edges is monotonically increasing with the size of the biggest clique.\ lemma turan_mono : fixes n p q :: nat assumes "0 < q" and "q < p" and "p \ n" shows "(1 - 1 / q) * n^2 / 2 \ (1 - 1 / (p-1)) * n^2 / 2" using assms by (simp add: Extended_Nonnegative_Real.divide_right_mono_ennreal Real.inverse_of_nat_le) section \Tur\'{a}n's Graph Theorem\ text \In this section we turn to the direct adaptation of Tur\'{a}n's original proof as presented by Aigner and Ziegler \cite{Aigner2018}\ theorem turan : fixes p n :: nat assumes "finite (uverts G)" and "uwellformed G" and "\C p'. uclique C G p' \ p' < p" and "p \ 2" and "card(uverts G) = n" shows "card (uedges G) \ (1 - 1 / (p-1)) * n^2 / 2" using assms proof (induction n arbitrary: G rule: less_induct) case (less n) then show ?case proof (cases "n < p") case True show ?thesis proof (cases "n") case 0 with less True show ?thesis by (auto simp add: wellformed_uverts_0) next case (Suc n') with True have "(1 - 1 / real n) \ (1 - 1 / real (p - 1))" by (metis diff_Suc_1 diff_left_mono inverse_of_nat_le less_Suc_eq_le linorder_not_less list_decode.cases not_add_less1 plus_1_eq_Suc) moreover have "real (card (uedges G)) \ (1 - 1 / real n) * real (n\<^sup>2) / 2" using ugraph_max_edges [OF less(3,6,2)] by (smt (verit, ccfv_SIG) left_diff_distrib mult.right_neutral mult_of_nat_commute nonzero_mult_div_cancel_left of_nat_1 of_nat_mult power2_eq_square times_divide_eq_left) ultimately show ?thesis using Rings.ordered_semiring_class.mult_right_mono divide_less_eq_numeral1(1) le_less_trans linorder_not_less of_nat_0_le_iff by (smt (verit, ccfv_threshold) divide_nonneg_nonneg times_divide_eq_right) qed next case False show ?thesis proof - obtain C q where C: "uclique C G q" and C_max: "(\C q'. uclique C G q' \ q' \ q)" and q: "q < card (uverts G)" using clique_exists_gt0 [OF \finite (uverts G)\] False \p \ 2\ less.prems(1,3,5) by (metis card.empty card_gt_0_iff le_eq_less_or_eq order_less_le_trans pos2) obtain E C' where E: "uwellformed (uverts G, uedges G \ E)" and C': "(uclique C' (uverts G, uedges G \ E) (p-1))" and C'_max: "(\C q'. uclique C (uverts G, uedges G \ E) q' \ q' \ p-1)" using clique_add_edges_max [OF \finite (uverts G)\ \uwellformed G\ q _ C_max, of "p-1"] using C less(4) less(5) False \card (uverts G) = n\ by (smt (verit) One_nat_def Suc_leD Suc_pred less_Suc_eq_le linorder_not_less order_less_le_trans pos2) have "card {e \ uedges G \ E. e \ uverts C'} = (p-1) * (p-2) / 2" using clique_edges_inside [OF E _ _ _ C'] False less(2) less.prems(4) C' by (smt (verit, del_insts) Collect_cong Suc_1 add_leD1 clique_max_size fst_conv of_nat_1 of_nat_add of_nat_diff of_nat_mult plus_1_eq_Suc snd_conv) moreover have "card {e \ uedges G \ E. e \ uverts G - uverts C'} \ (1 - 1 / (p-1)) * (n - p + 1) ^ 2 / 2" proof - have "real(card{e \ uedges (uverts G, uedges G \ E). e \ uverts (uverts G, uedges G \ E) - uverts C'}) \ (1 - 1 / (real p - 1)) * (real n - real p + 1)\<^sup>2 / 2" using clique_edges_outside [OF E _ less(5) _ _ C' C'_max, of n] linorder_class.leI [OF False] less(1,2,6) by (metis (no_types, lifting) fst_conv) then show ?thesis by (simp, smt (verit, best) False One_nat_def Suc_1 Suc_leD add.commute leI less.prems(4) of_nat_1 of_nat_diff) qed moreover have "card {e \ uedges G \ E. e \ uverts C' \ {} \ e \ (uverts G - uverts C') \ {}} \ (p - 2) * (n - p + 1)" using clique_edges_inside_to_outside [OF E _ _ _ _ C' C'_max, of n] less(2,5,6) by (simp, metis (no_types, lifting) C' False Nat.add_diff_assoc Nat.add_diff_assoc2 One_nat_def Suc_1 clique_max_size fst_conv leI mult_Suc_right plus_1_eq_Suc) ultimately have "real (card (uedges G \ E)) \ (1 - 1 / real (p - 1)) * real (n\<^sup>2) / 2" using graph_partition_edges_card [OF _ E, of "uverts C'"] using less(2) turan_sum_eq [OF \2 \ p\, of n] False C' uclique_def subgraph_def by (smt (verit) Collect_cong fst_eqD linorder_not_le of_nat_add of_nat_mono snd_eqD) then show ?thesis using less(2) E finite_verts_edges Finite_Set.card_mono [OF _ Set.Un_upper1 [of "uedges G" E]] by force qed qed qed section \A simplified proof of Tur\'{a}n's Graph Theorem\ text \In this section we discuss a simplified proof of Tur\'{a}n's Graph Theorem which uses an idea put forward by the author: Instead of increasing the size of the biggest clique it is also possible to use the fact that the expression in Tur\'{a}n's graph theorem is monotonically increasing in the size of the biggest clique (Lemma @{thm [source] turan_mono}). Hence, it suffices to prove the upper bound for the actual biggest clique size in the graph. Afterwards, the monotonicity provides the desired inequality. The simplifications in the proof are annotated accordingly.\ theorem turan' : fixes p n :: nat assumes "finite (uverts G)" and "uwellformed G" and "\C p'. uclique C G p' \ p' < p" and "p \ 2" and "card(uverts G) = n" shows "card (uedges G) \ (1 - 1 / (p-1)) * n^2 / 2" using assms proof (induction n arbitrary: p G rule: less_induct) txt \In the simplified proof we also need to generalize over the biggest clique size @{term p} so that we can leverage the induction hypothesis in the proof for the already pre-existing biggest clique size which might be smaller than @{term "p-1"}.\ case (less n) then show ?case proof (cases "n < p") case True show ?thesis proof (cases "n") case 0 with less True show ?thesis by (auto simp add: wellformed_uverts_0) next case (Suc n') with True have "(1 - 1 / real n) \ (1 - 1 / real (p - 1))" by (metis diff_Suc_1 diff_left_mono inverse_of_nat_le less_Suc_eq_le linorder_not_less list_decode.cases not_add_less1 plus_1_eq_Suc) moreover have "real (card (uedges G)) \ (1 - 1 / real n) * real (n\<^sup>2) / 2" using ugraph_max_edges [OF less(3,6,2)] by (smt (verit, ccfv_SIG) left_diff_distrib mult.right_neutral mult_of_nat_commute nonzero_mult_div_cancel_left of_nat_1 of_nat_mult power2_eq_square times_divide_eq_left) ultimately show ?thesis using Rings.ordered_semiring_class.mult_right_mono divide_less_eq_numeral1(1) le_less_trans linorder_not_less of_nat_0_le_iff by (smt (verit, ccfv_threshold) divide_nonneg_nonneg times_divide_eq_right) qed next case False show ?thesis proof - from False \p \ 2\ obtain C q where C: "uclique C G q" and C_max: "(\C q'. uclique C G q' \ q' \ q)" and q1: "q < card (uverts G)" and q2: "0 < q" and pq: "q < p" using clique_exists_gt0 [OF \finite (uverts G)\] clique_exists1 less.prems(1,3,5) by (metis card.empty card_gt_0_iff le_eq_less_or_eq order_less_le_trans pos2) txt \In the unsimplified proof we extend this existing greatest clique C to a clique of size @{term "p-1"}. This part is made superfluous in the simplified proof. In particular, also Section \ref{sec:extend_clique} is unneeded for this simplified proof. From here on the proof is analogous to the unsimplified proof with the potentially smaller clique of size @{term q} in place of the extended clique.\ have "card {e \ uedges G. e \ uverts C} = q * (q-1) / 2" using clique_edges_inside [OF less(3,2) _ _ C] q1 less(6) by auto moreover have "card {e \ uedges G. e \ uverts G - uverts C} \ (1 - 1 / q) * (n - q) ^ 2 / 2" proof - have "real (card {e \ uedges G. e \ uverts G - uverts C}) \ (1 - 1 / (real (q + 1) - 1)) * (real n - real (q + 1) + 1)\<^sup>2 / 2" using clique_edges_outside [OF less(3,2) _ _ , of "q+1" n C] C C_max q1 q2 linorder_class.leI [OF False] less(1,6) by (smt (verit, ccfv_threshold) Suc_1 Suc_eq_plus1 Suc_leI diff_add_inverse2 zero_less_diff) then show ?thesis using less.prems(5) q1 by (simp add: of_nat_diff) qed moreover have "card {e \ uedges G. e \ uverts C \ {} \ e \ (uverts G - uverts C) \ {}} \ (q - 1) * (n - q)" using clique_edges_inside_to_outside [OF less(3,2) q2 _ less(6) C C_max] q1 by simp ultimately have "real (card (uedges G)) \ (1 - 1 / real q) * real (n\<^sup>2) / 2" using graph_partition_edges_card [OF less(2,3), of "uverts C"] using C uclique_def subgraph_def q1 q2 less.prems(5) turan_sum_eq [of "Suc q" n] by (smt (verit) Nat.add_diff_assoc Suc_1 Suc_le_eq Suc_le_mono add.commute add.right_neutral diff_Suc_1 diff_Suc_Suc of_nat_add of_nat_mono plus_1_eq_Suc) then show ?thesis txt \The final statement can then easily be derived with the monotonicity (Lemma @{thm [source] turan_mono}).\ using turan_mono [OF q2 pq, of n] False by linarith qed qed qed end