Finite graphs and their binary encoding
Lax253009.Graphs · concepts/Lax253009/Graphs.lean · lax-253009
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 Lax253009.Graphs |
| 19 | |
| 20 | structure Graph (n : ℕ) where |
| 21 | adjacent : Fin n → Fin n → Bool |
| 22 | loopless : ∀ v, adjacent v v = false |
| 23 | symmetric : ∀ u v, adjacent u v = adjacent v u |
| 24 | |
| 25 | def Graph.simpleGraph {n : ℕ} (G : Graph n) : SimpleGraph (Fin n) where |
| 26 | Adj u v := G.adjacent u v = true |
| 27 | symm := ⟨fun u v h ↦ by rw [← G.symmetric]; exact h⟩ |
| 28 | loopless := ⟨fun v ↦ by simp [G.loopless]⟩ |
| 29 | |
| 30 | def Graph.encode {n : ℕ} (G : Graph n) : List Bool := |
| 31 | List.replicate n true ++ [false] ++ |
| 32 | (List.finRange n).flatMap (fun u ↦ (List.finRange n).map (G.adjacent u)) |
| 33 | |
| 34 | noncomputable def Graph.cliqueNumber {n : ℕ} (G : Graph n) : ℕ := |
| 35 | G.simpleGraph.cliqueNum |
| 36 | |
| 37 | end Lax253009.Graphs |
| 38 |
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments