Finite graphs and their binary encoding
Lax323828.Graphs · concepts/Lax323828/Graphs.lean · lax-323828
No public endorsements yet.
Loading review…
Sign in with ORCIDNatural Language Statement
Definition
A graph on vertices is a symmetric Boolean adjacency matrix with zero diagonal. Its vertices are . We encode it by one-bits, one zero-bit, and its complete adjacency matrix in row-major order. The encoding has length , so polynomial time in its length is equivalent to polynomial time in the number of vertices.
The clique number is the maximum cardinality of a clique.
Concept map
Lean source view on GitHub
| 1 | import Mathlib.Combinatorics.SimpleGraph.Clique |
| 2 | import Mathlib.Data.List.FinRange |
| 3 | |
| 4 | /-! |
| 5 | --- |
| 6 | title: Finite graphs and their binary encoding |
| 7 | type: definition |
| 8 | --- |
| 9 | A graph on vertices is a symmetric Boolean adjacency matrix with zero |
| 10 | diagonal. Its vertices are . We encode it by one-bits, |
| 11 | one zero-bit, and its complete adjacency matrix in row-major order. |
| 12 | The encoding has length , so polynomial time in its length is |
| 13 | equivalent to polynomial time in the number of vertices. |
| 14 | |
| 15 | The clique number is the maximum cardinality of a clique. |
| 16 | -/ |
| 17 | |
| 18 | namespace Lax323828.Graphs |
| 19 | |
| 20 | /-- A simple graph represented by a symmetric Boolean adjacency matrix with zero diagonal. -/ |
| 21 | structure Graph (n : ℕ) where |
| 22 | /-- Whether the two labeled vertices are adjacent. -/ |
| 23 | adjacent : Fin n → Fin n → Bool |
| 24 | /-- No vertex is adjacent to itself. -/ |
| 25 | loopless : ∀ v, adjacent v v = false |
| 26 | /-- Adjacency is unchanged when the endpoints are exchanged. -/ |
| 27 | symmetric : ∀ u v, adjacent u v = adjacent v u |
| 28 | |
| 29 | /-- Read the Boolean matrix as a mathematical simple graph. -/ |
| 30 | def Graph.simpleGraph {n : ℕ} (G : Graph n) : SimpleGraph (Fin n) where |
| 31 | Adj u v := G.adjacent u v = true |
| 32 | symm := ⟨fun u v h ↦ (G.symmetric u v).symm.trans h⟩ |
| 33 | loopless := ⟨fun v h ↦ Bool.noConfusion ((G.loopless v).symm.trans h)⟩ |
| 34 | |
| 35 | /-- The vertex count in unary, a separator, and the adjacency matrix in row order. -/ |
| 36 | def Graph.encode {n : ℕ} (G : Graph n) : List Bool := |
| 37 | List.replicate n true ++ [false] ++ |
| 38 | (List.finRange n).flatMap (fun u ↦ (List.finRange n).map (G.adjacent u)) |
| 39 | |
| 40 | /-- The maximum number of pairwise adjacent vertices. -/ |
| 41 | noncomputable def Graph.cliqueNumber {n : ℕ} (G : Graph n) : ℕ := |
| 42 | G.simpleGraph.cliqueNum |
| 43 | |
| 44 | end Lax323828.Graphs |
| 45 |
Builds on
none
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments