AFTD Auto-Formalizing Theoretical Domains

op874_exists_shortest_directed_path

theoremverified

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

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.

  1. 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.

    lines 6–9

      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⟩
  2. 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.

    line 10

    uses Nat.find_spec

      obtain ⟨w, hwlen, hw⟩ := Nat.find_spec hn
  3. The 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.

    lines 11–13

    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'⟩
  4. 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.

    line 14

    uses op874_shortest_directed_walk_is_path

      exact ⟨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).

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

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⟩
See it in the graphDiscuss this resultChallenge it