File: Mathlib/Combinatorics/SimpleGraph/Triangle/Counting.lean

full_name: _private.Mathlib.Combinatorics.SimpleGraph.Triangle.Counting.0.SimpleGraph.badVertices
code: /-- The vertices of `s` whose density in `t` is `ε` less than expected. -/
private noncomputable def badVertices (ε : ℝ) (s t : Finset α) : Finset α 
goal: Finset α

full_name: _private.Mathlib.Combinatorics.SimpleGraph.Triangle.Counting.0.SimpleGraph.card_interedges_badVertices_le
code: private lemma card_interedges_badVertices_le :
    (Rel.interedges G.Adj (badVertices G ε s t) t).card ≤
      (badVertices G ε s t).card * t.card * (G.edgeDensity s t - ε) 
goal: ↑(Rel.interedges G.Adj (SimpleGraph.badVertices G ε s t) t).card ≤
  ↑(SimpleGraph.badVertices G ε s t).card * ↑t.card * (↑(G.edgeDensity s t) - ε)

full_name: _private.Mathlib.Combinatorics.SimpleGraph.Triangle.Counting.0.SimpleGraph.edgeDensity_badVertices_le
code: private lemma edgeDensity_badVertices_le (hε : 0 ≤ ε) (dst : 2 * ε ≤ G.edgeDensity s t) :
    G.edgeDensity (badVertices G ε s t) t ≤ G.edgeDensity s t - ε 
goal: ↑(G.edgeDensity (SimpleGraph.badVertices G ε s t) t) ≤ ↑(G.edgeDensity s t) - ε

full_name: _private.Mathlib.Combinatorics.SimpleGraph.Triangle.Counting.0.SimpleGraph.card_badVertices_le
code: private lemma card_badVertices_le (dst : 2 * ε ≤ G.edgeDensity s t) (hst : G.IsUniform ε s t) :
    (badVertices G ε s t).card ≤ s.card * ε 
goal: ↑(SimpleGraph.badVertices G ε s t).card ≤ ↑s.card * ε

full_name: _private.Mathlib.Combinatorics.SimpleGraph.Triangle.Counting.0.SimpleGraph.triangle_split_helper
code: /-- A subset of the triangles constructed in a weird way to make them easy to count. -/
private lemma triangle_split_helper [DecidableEq α] :
    (s \ (badVertices G ε s t ∪ badVertices G ε s u)).biUnion
      (fun x ↦ (G.interedges (t.filter $ G.Adj x) (u.filter $ G.Adj x)).image (x, ·)) ⊆
      (s ×ˢ t ×ˢ u).filter (fun (x, y, z) ↦ G.Adj x y ∧ G.Adj x z ∧ G.Adj y z) 
goal: ((s \ (SimpleGraph.badVertices G ε s t ∪ SimpleGraph.badVertices G ε s u)).biUnion fun x =>
    Finset.image (fun x_1 => (x, x_1)) (G.interedges (Finset.filter (G.Adj x) t) (Finset.filter (G.Adj x) u))) ⊆
  Finset.filter
    (fun x =>
      match x with
      | (x, y, z) => G.Adj x y ∧ G.Adj x z ∧ G.Adj y z)
    (s ×ˢ t ×ˢ u)

full_name: _private.Mathlib.Combinatorics.SimpleGraph.Triangle.Counting.0.SimpleGraph.good_vertices_triangle_card
code: private lemma good_vertices_triangle_card [DecidableEq α] (dst : 2 * ε ≤ G.edgeDensity s t)
    (dsu : 2 * ε ≤ G.edgeDensity s u) (dtu : 2 * ε ≤ G.edgeDensity t u) (utu : G.IsUniform ε t u)
    (x : α) (hx : x ∈ s \ (badVertices G ε s t ∪ badVertices G ε s u)) :
    ε ^ 3 * t.card * u.card ≤ (((t.filter (G.Adj x) ×ˢ u.filter (G.Adj x)).filter
        fun (y, z) ↦ G.Adj y z).image (x, ·)).card 
goal: ε ^ 3 * ↑t.card * ↑u.card ≤
  ↑(Finset.image (fun x_1 => (x, x_1))
        (Finset.filter
          (fun x =>
            match x with
            | (y, z) => G.Adj y z)
          (Finset.filter (G.Adj x) t ×ˢ Finset.filter (G.Adj x) u))).card

full_name: SimpleGraph.triangle_counting'
code: /-- The **Triangle Counting Lemma**. If `G` is a graph and `s`, `t`, `u` are sets of vertices such
that each pair is `ε`-uniform and `2 * ε`-dense, then a proportion of at least
`(1 - 2 * ε) * ε ^ 3` of the triples `(a, b, c) ∈ s × t × u` are triangles. -/
lemma triangle_counting'
    (dst : 2 * ε ≤ G.edgeDensity s t) (hst : G.IsUniform ε s t)
    (dsu : 2 * ε ≤ G.edgeDensity s u) (usu : G.IsUniform ε s u)
    (dtu : 2 * ε ≤ G.edgeDensity t u) (utu : G.IsUniform ε t u) :
    (1 - 2 * ε) * ε ^ 3 * s.card * t.card * u.card ≤
      ((s ×ˢ t ×ˢ u).filter fun (a, b, c) ↦ G.Adj a b ∧ G.Adj a c ∧ G.Adj b c).card 
goal: (1 - 2 * ε) * ε ^ 3 * ↑s.card * ↑t.card * ↑u.card ≤
  ↑(Finset.filter
        (fun x =>
          match x with
          | (a, b, c) => G.Adj a b ∧ G.Adj a c ∧ G.Adj b c)
        (s ×ˢ t ×ˢ u)).card

full_name: _private.Mathlib.Combinatorics.SimpleGraph.Triangle.Counting.0.SimpleGraph.triple_eq_triple_of_mem
code: private lemma triple_eq_triple_of_mem (hst : Disjoint s t) (hsu : Disjoint s u) (htu : Disjoint t u)
    {x₁ x₂ y₁ y₂ z₁ z₂ : α} (h : ({x₁, y₁, z₁} : Finset α) = {x₂, y₂, z₂})
    (hx₁ : x₁ ∈ s) (hx₂ : x₂ ∈ s) (hy₁ : y₁ ∈ t) (hy₂ : y₂ ∈ t) (hz₁ : z₁ ∈ u) (hz₂ : z₂ ∈ u) :
    (x₁, y₁, z₁) = (x₂, y₂, z₂) 
goal: (x₁, y₁, z₁) = (x₂, y₂, z₂)

full_name: SimpleGraph.triangle_counting
code: /-- The **Triangle Counting Lemma**. If `G` is a graph and `s`, `t`, `u` are disjoint sets of
vertices such that each pair is `ε`-uniform and `2 * ε`-dense, then `G` contains at least
`(1 - 2 * ε) * ε ^ 3 * |s| * |t| * |u|` triangles. -/
lemma triangle_counting
    (dst : 2 * ε ≤ G.edgeDensity s t) (ust : G.IsUniform ε s t) (hst : Disjoint s t)
    (dsu : 2 * ε ≤ G.edgeDensity s u) (usu : G.IsUniform ε s u) (hsu : Disjoint s u)
    (dtu : 2 * ε ≤ G.edgeDensity t u) (utu : G.IsUniform ε t u) (htu : Disjoint t u) :
    (1 - 2 * ε) * ε ^ 3 * s.card * t.card * u.card ≤ (G.cliqueFinset 3).card 
goal: (1 - 2 * ε) * ε ^ 3 * ↑s.card * ↑t.card * ↑u.card ≤ ↑(G.cliqueFinset 3).card