op874_exists_shortest_directed_path
If a directed walk obeying a dart predicate exists, a shortest one exists and is simple.
Statement
theorem op874_exists_shortest_directed_path {V : Type*} [DecidableEq V] (G : SimpleGraph V) (P : G.Dart → Prop) {u v : V} (h : ∃ w : G.Walk u v, ∀ e ∈ w.darts, P e) : ∃ w : G.Walk u v, w.IsPath ∧ (∀ e ∈ w.darts, P e) ∧ ∀ w' : G.Walk u v, (∀ e ∈ w'.darts, P e) → w.length ≤ w'.length
- Source
- Choose a minimal length walk; bypass preserves directed darts.
- Verified
- 22 Nov 2026
- Axioms
Classical.choiceQuot.soundpropext- Built on 1
- op874_shortest_directed_walk_is_pathA shortest walk subject to a predicate on its oriented darts has no repeated vertices.
The proof, explained
Given the existence of a walk between two vertices whose darts satisfy P, the set of lengths of all such walks is non-empty. By the well-ordering of the natural numbers, there exists a walk w realizing the minimum length among all walks satisfying P. A helper theorem (op874_shortest_directed_walk_is_path) shows that any such minimal-length walk contains no repeated vertices, and is therefore a simple path. Thus, w is the desired shortest simple path.
There exists a natural number that is the length of some walk from u to v whose darts satisfy P.
We unpack the hypothesis giving an existing walk from u to v whose darts satisfy P. Its length provides a natural number witnessing that the set of lengths of such walks is non-empty.
classical have hn : ∃ n : ℕ, ∃ w : G.Walk u v, w.length = n ∧ ∀ e ∈ w.darts, P e := by obtain ⟨w, hw⟩ := h exact ⟨w.length, w, rfl, hw⟩
There exists a walk w whose darts satisfy P and whose length is the minimal possible length Nat.find hn.
By the well-ordering principle of the natural numbers (via `Nat.find_spec`), the non-empty set of lengths of valid walks has a least element. We obtain a walk w whose length equals this minimum and whose darts all satisfy P.
uses
Nat.find_specobtain ⟨w, hwlen, hw⟩ := Nat.find_spec hnThe length of w is less than or equal to the length of any other walk w' whose darts satisfy P.
For any walk w' whose darts satisfy P, its length is an element of the set of valid walk lengths. By `Nat.find_min'`, the minimal length Nat.find hn is at most w'.length; substituting w.length for Nat.find hn shows w.length ≤ w'.length.
uses
Nat.find_min'have hmin (w' : G.Walk u v) (hw' : ∀ e ∈ w'.darts, P e) : w.length ≤ w'.length := by rw [hwlen] exact Nat.find_min' hn ⟨w', rfl, hw'⟩
The walk w is a simple path whose darts satisfy P and whose length is minimal among all such walks.
By the lemma `op874_shortest_directed_walk_is_path`, any walk whose darts satisfy P and whose length is minimal cannot repeat vertices and must be a simple path (w.IsPath). Providing w together with this path property, its dart condition, and its minimality concludes the proof.
uses
op874_shortest_directed_walk_is_pathexact ⟨w, op874_shortest_directed_walk_is_path G P w hw hmin, hw, hmin⟩
Nat.find_spec- If there exists a natural number satisfying a predicate, then the least such natural number (produced by `Nat.find`) satisfies the predicate.
Nat.find_min'- The least natural number satisfying a predicate is less than or equal to any natural number that satisfies the predicate.
op874_shortest_directed_walk_is_path- In a simple graph, a walk between two vertices whose darts satisfy a predicate P and whose length is minimal among all such walks is a simple path (has no repeated vertices).
- The invocation of `classical` on line 6 provides decidability for arbitrary propositions, a formal prerequisite for applying Lean's `Nat.find` operator to find the minimum natural number satisfying a predicate.
Written by a model (gemini-3.8-flash) from the Lean proof and the goal states Lean reported at each step. Lean verified the proof; this explanation is a reading aid and is not itself machine-checked.
Lean source view module on GitHub
Choose a tactic — a marked line — to see the goals Lean had before and after it, as in Lean’s infoview. Step with ← → or j k.
theorem op874_exists_shortest_directed_path {V : Type*} [DecidableEq V] (G : SimpleGraph V) (P : G.Dart → Prop) {u v : V} (h : ∃ w : G.Walk u v, ∀ e ∈ w.darts, P e) : ∃ w : G.Walk u v, w.IsPath ∧ (∀ e ∈ w.darts, P e) ∧ ∀ w' : G.Walk u v, (∀ e ∈ w'.darts, P e) → w.length ≤ w'.length := by classical have hn : ∃ n : ℕ, ∃ w : G.Walk u v, w.length = n ∧ ∀ e ∈ w.darts, P e := by obtain ⟨w, hw⟩ := h exact ⟨w.length, w, rfl, hw⟩ obtain ⟨w, hwlen, hw⟩ := Nat.find_spec hn have hmin (w' : G.Walk u v) (hw' : ∀ e ∈ w'.darts, P e) : w.length ≤ w'.length := by rw [hwlen] exact Nat.find_min' hn ⟨w', rfl, hw'⟩ exact ⟨w, op874_shortest_directed_walk_is_path G P w hw hmin, hw, hmin⟩