The distance matrix of a partial graph
Lax185574.DistanceMatrix · concepts/Lax185574/DistanceMatrix.lean · lax-185574
No public endorsements yet.
Loading review…
Sign in with ORCIDNatural Language Statement
Definition
The distance matrix of a partial graph G is the |G| × |G| matrix D_G with entries D_G(u, v) = dist^G(u, v) ∈ ℕ ∪ {∞}.
Concept map
In the paper
- page 40 of this submission's paper
Lean source view on GitHub
| 1 | import Lax185574.PartialGraphs |
| 2 | import Mathlib.Combinatorics.SimpleGraph.Metric |
| 3 | |
| 4 | /-! |
| 5 | --- |
| 6 | title: The distance matrix of a partial graph |
| 7 | type: definition |
| 8 | --- |
| 9 | The *distance matrix* of a partial graph G is the |G| × |G| matrix D_G |
| 10 | with entries D_G(u, v) = dist^G(u, v) ∈ ℕ ∪ {∞}. |
| 11 | |
| 12 | # Formalization notes |
| 13 | |
| 14 | The distance is the extended distance `SimpleGraph.edist` of mathlib in |
| 15 | the graph of resolved pairs, a value in `ℕ∞`. So D_G is 0 on the |
| 16 | diagonal, and ∞ for vertices in different components of the graph of |
| 17 | resolved pairs. The matrix of a partial graph on `Fin n` is a function |
| 18 | of two vertices. |
| 19 | |
| 20 | Algorithms receive the matrix in the encoding of `Lax185574.Encodings`. |
| 21 | A distance in ℕ ∪ {∞} is encoded as one entry, 0 for ∞ and d + 1 for a |
| 22 | finite distance d. The matrix is the family of its rows, and each row is |
| 23 | the family of its entries. So the word of D_G is n, followed by every |
| 24 | row in order as n and the n entries of the row. Every row has n + 1 |
| 25 | entries, the word has length 1 + n(n + 1), and the entry at (u, v) is at |
| 26 | position 2 + u(n + 1) + v, counting from 0. The paper does not say how |
| 27 | ∞ is represented. Its bounds O(|G|²) for reading the matrix need entries |
| 28 | of constant size, which this encoding provides. |
| 29 | -/ |
| 30 | |
| 31 | namespace Lax185574.DistanceMatrix |
| 32 | |
| 33 | open Lax185574.PartialGraphs |
| 34 | |
| 35 | /-- The distance matrix `D_G`: `D_G(u, v) = dist^G(u, v)`, the distance |
| 36 | in the graph of resolved pairs, and `∞` if there is no path. -/ |
| 37 | noncomputable def distMatrix {n : ℕ} (G : PartialGraph (Fin n)) : Fin n → Fin n → ℕ∞ := |
| 38 | fun u v => G.resolved.edist u v |
| 39 | |
| 40 | end Lax185574.DistanceMatrix |
| 41 |
Formalization notes
The distance is the extended distance of mathlib in the graph of resolved pairs, a value in . So D_G is 0 on the diagonal, and ∞ for vertices in different components of the graph of resolved pairs. The matrix of a partial graph on is a function of two vertices.
Algorithms receive the matrix in the encoding of . A distance in ℕ ∪ {∞} is encoded as one entry, 0 for ∞ and d + 1 for a finite distance d. The matrix is the family of its rows, and each row is the family of its entries. So the word of D_G is n, followed by every row in order as n and the n entries of the row. Every row has n + 1 entries, the word has length 1 + n(n + 1), and the entry at (u, v) is at position 2 + u(n + 1) + v, counting from 0. The paper does not say how ∞ is represented. Its bounds O(|G|²) for reading the matrix need entries of constant size, which this encoding provides.
Builds on
From Mathlib
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above.
0 comments