definition
No public endorsements yet.
Loading review…
Sign in with ORCIDConcept map
Definition
A directed graph on vertices is given by its Boolean adjacency matrix. A walk may repeat vertices. The recursive reachability test divides the length bound in two and enumerates possible middle vertices.
Lean source view on GitHub
| 1 | import Mathlib.Data.List.FinRange |
| 2 | import Mathlib.Logic.Relation |
| 3 | |
| 4 | /-! |
| 5 | --- |
| 6 | title: Bounded reachability |
| 7 | type: definition |
| 8 | --- |
| 9 | A directed graph on vertices is given by its Boolean adjacency matrix. |
| 10 | A walk may repeat vertices. The recursive reachability test divides the |
| 11 | length bound in two and enumerates possible middle vertices. |
| 12 | -/ |
| 13 | |
| 14 | namespace Lax307052.Reachability |
| 15 | |
| 16 | abbrev Graph (N : ℕ) := Fin N → Fin N → Bool |
| 17 | |
| 18 | inductive Walk {α : Type} (R : α → α → Prop) : ℕ → α → α → Prop |
| 19 | | nil (a : α) : Walk R 0 a a |
| 20 | | tail {n : ℕ} {a b c : α} : Walk R n a b → R b c → Walk R (n + 1) a c |
| 21 | |
| 22 | def Within {α : Type} (R : α → α → Prop) (n : ℕ) (a b : α) : Prop := |
| 23 | ∃ k ≤ n, Walk R k a b |
| 24 | |
| 25 | def Reachable {N : ℕ} (G : Graph N) (a b : Fin N) : Prop := |
| 26 | Relation.ReflTransGen (fun u v => G u v = true) a b |
| 27 | |
| 28 | def search {N : ℕ} (G : Graph N) : ℕ → Fin N → Fin N → Bool |
| 29 | | 0, a, b => decide (a = b) || G a b |
| 30 | | k + 1, a, b => (List.finRange N).any fun m => search G k a m && search G k m b |
| 31 | |
| 32 | end Lax307052.Reachability |
| 33 |
Builds on
none
From Mathlib
Community review
Discussion
Ask a question or add context. Endorsements and structured flags are kept in the review panel above; your ORCID profile must share a public name.
0 comments