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