While this submission is a draft, it cannot be used by other submissions.

Bipartite Graphs with a Fixed Bipartition, and Their Encoding

Lax117284.BipartiteGraph · concepts/Lax117284/BipartiteGraph.lean · lax-117284

definition

Loading review…

Sign in with ORCID

Community review

Flags

Each flag is tied to a public ORCID identity and explains why this concept may be incorrect.

No flags have been submitted.

    Community review

    Flag this concept

    State precisely what appears incorrect. This explanation will be public under your ORCID name.

    No source line selected.

    Natural Language Statement

    Definition

    A bipartite graph is a simple graph whose vertices split into two sides such that every edge joins the two sides. A graph on the vertices 0,…,V−10, \ldots, V-1 is split at nn when the first nn vertices form one side, the left side, and the remaining V−nV - n vertices the other, the right side; this is Mathlib's IsBipartiteWithIsBipartiteWith for these two sets, and it makes the graph bipartite in Mathlib's sense.

    Such a graph is handed to the word RAM as the compressed sparse row encoding of lax−271696lax-271696 followed by one entry, the number nn of left vertices. The bipartition is part of the input, as it is in the usual statement of the bipartite matching problem.

    Concept map
    2 concepts; 3 descendants hidden
    100%
    Proven claimDefinitionThis conceptRelated conceptA → B: B builds on A

    Lean source view on GitHub

    1import Lax271696.GraphEncoding
    2import Mathlib.Combinatorics.SimpleGraph.Bipartite
    3
    4/-!
    5---
    6title: Bipartite Graphs with a Fixed Bipartition, and Their Encoding
    7type: definition
    8---
    9A bipartite graph is a simple graph whose vertices split into two sides such that every edge
    10joins the two sides. A graph on the vertices 0,…,V−10, \ldots, V-1 is *split at* nn when the first
    11nn vertices form one side, the *left side*, and the remaining V−nV - n vertices the other, the
    12*right side*; this is Mathlib's `IsBipartiteWith` for these two sets, and it makes the graph
    13bipartite in Mathlib's sense.
    14
    15Such a graph is handed to the word RAM as the compressed sparse row encoding of `lax-271696`
    16followed by one entry, the number nn of left vertices. The bipartition is part of the input, as
    17it is in the usual statement of the bipartite matching problem.
    18
    19# Formalization Notes
    20
    21The graph is a Mathlib `SimpleGraph` on `Fin V`, and both its encoding and the number of
    22vertices come from the archive: `EncodesGraph g V G` of `lax-271696` says that the word `g` is a
    23compressed sparse row encoding of `G`. The word of an instance is `g ++ [n]`. The block `g` is
    24self-delimiting — its header fixes its length — so the split of the word into the block and the
    25appended entry is determined by the word, as in the parameterized instances of the same
    26submission, and the graph block sits at the same offsets as in every statement built on that
    27encoding.
    28
    29The word is required to encode a graph that genuinely is split at `n`: an edge inside a side is
    30not an input the theorems below speak about. The adjacency lists of the right vertices are
    31present in the word, as the encoding lists every edge from both ends; the algorithm reads only the
    32left rows, and pays for the length of the whole word only in the linear factor of its bound.
    33
    34`wordGraph x` is the graph a word denotes, read off its block: two vertices are adjacent when
    35either lists the other. On an encoding of `G` it is `G`. It is what makes the output of the
    36machine a function of the word, as `ComputesInTime` requires, and `leftCount x` is the last
    37entry of the word.
    38-/
    39
    40namespace Lax117284.BipartiteGraph
    41
    42open Lax271696.GraphEncoding
    43
    44/-- The left side of a graph on `Fin V` split at `n`: the vertices below `n`. -/
    45def leftSide (V n : ℕ) : Set (Fin V) := {v | (v : ℕ) < n}
    46
    47/-- The right side: the vertices from `n` on. -/
    48def rightSide (V n : ℕ) : Set (Fin V) := {v | n ≤ (v : ℕ)}
    49
    50/-- **A graph split at `n`**: bipartite with the first `n` vertices on the left and the rest on
    51the right. -/
    52def SplitAt {V : ℕ} (G : SimpleGraph (Fin V)) (n : ℕ) : Prop :=
    53 G.IsBipartiteWith (leftSide V n) (rightSide V n)
    54
    55/-- **The word `x` presents the bipartite graph `G` on `V` vertices split at `n`**: a compressed
    56sparse row block encoding `G`, followed by the single entry `n`, with `n ≤ V`. -/
    57def EncodesBipartite (x : List ℕ) (V : ℕ) (G : SimpleGraph (Fin V)) (n : ℕ) : Prop :=
    58 ∃ g : List ℕ, x = g ++ [n] ∧ EncodesGraph g V G ∧ n ≤ V ∧ SplitAt G n
    59
    60/-- The number of left vertices a word declares: its last entry. -/
    61def leftCount (x : List ℕ) : ℕ := x.getLastD 0
    62
    63/-- Vertex `u` lists vertex `v` in its block. -/
    64def Lists (x : List ℕ) (u v : ℕ) : Prop :=
    65 ∃ j, offset x u ≤ j ∧ j < offset x (u + 1) ∧ target x j = v
    66
    67/-- The graph a word denotes: two distinct vertices are adjacent when either lists the other. -/
    68def wordGraph (x : List ℕ) : SimpleGraph (Fin (vertexCount x)) :=
    69 SimpleGraph.fromRel fun u v : Fin (vertexCount x) => Lists x u v
    70
    71end Lax117284.BipartiteGraph
    72
    Formalization Notes

    The graph is a Mathlib SimpleGraphSimpleGraph on FinVFin V, and both its encoding and the number of vertices come from the archive: EncodesGraphgVGEncodesGraph g V G of lax−271696lax-271696 says that the word gg is a compressed sparse row encoding of GG. The word of an instance is g++[n]g ++ [n]. The block gg is self-delimiting — its header fixes its length — so the split of the word into the block and the appended entry is determined by the word, as in the parameterized instances of the same submission, and the graph block sits at the same offsets as in every statement built on that encoding.

    The word is required to encode a graph that genuinely is split at nn: an edge inside a side is not an input the theorems below speak about. The adjacency lists of the right vertices are present in the word, as the encoding lists every edge from both ends; the algorithm reads only the left rows, and pays for the length of the whole word only in the linear factor of its bound.

    wordGraphxwordGraph x is the graph a word denotes, read off its block: two vertices are adjacent when either lists the other. On an encoding of GG it is GG. It is what makes the output of the machine a function of the word, as ComputesInTimeComputesInTime requires, and leftCountxleftCount x is the last entry of the word.

    Discussion

    Ask a question or add context. Endorsements and structured flags are kept in the review panel above.

    Loading discussion…