Kuhn Matching #
Executable augmenting-path matching #
This file implements the polynomial augmenting-path algorithm for the positive support of a square rational matrix. A state maps each column to its currently matched row. Failed recursive searches return the enlarged set of visited columns, so a single root search examines each column at most once; this detail is essential for the polynomial bound.
A table assigning each column either a matched row or no match.
Equations
- BeyondBethe.ColumnMate n = (Fin n → Option (Fin n))
Instances For
The column-mate table with every column unmatched.
Equations
Instances For
A column-to-row table represents a partial matching in the positive
support of A.
Instances For
No column in the mate table is assigned to the given row.
Equations
- BeyondBethe.RowUnmatched mate row = ∀ (col : Fin n), mate col ≠ some row
Instances For
Some column in the mate table is assigned to the given row.
Equations
- BeyondBethe.MatchesRow mate row = ∃ (col : Fin n), mate col = some row
Instances For
Result of one augmenting-path search. mate? = some m records success;
either way, seen contains every column examined by the search.
- mate? : Option (ColumnMate n)
The updated mate table on successful augmentation, or
nonewhen the search fails. The set of columns visited by the search, retained even when augmentation fails.
Instances For
Depth-first augmenting-path search with a shared visited-column set. The first natural-number argument bounds alternating-path depth; the column list is the part of the current row that remains to be scanned. A failed recursive call threads its enlarged visited set into the rest of the scan. The lexicographic recursion makes both sources of progress explicit.
Equations
Instances For
Number of column inspections made by kuhnSearch. Recursive work is
charged only on the branch actually taken by the executable search.
Equations
- One or more equations did not get rendered due to their size.
- BeyondBethe.kuhnSearchWork A 0 x✝³ x✝² x✝¹ x✝ = 0
- BeyondBethe.kuhnSearchWork A _fuel.succ [] x✝² x✝¹ x✝ = 0
Instances For
Search all columns from scratch for an augmenting path rooted at row.
Equations
- BeyondBethe.kuhnAugment A fuel row seen mate = BeyondBethe.kuhnSearch A fuel (List.finRange n) row seen mate
Instances For
Amortized work bound. Scanning the current suffix is charged directly; each newly visited column pays for at most one fresh full row scan.
The work count for an augmenting-path search over the full ordered column list.
Equations
- BeyondBethe.kuhnAugmentWork A fuel row seen mate = BeyondBethe.kuhnSearchWork A fuel (List.finRange n) row seen mate
Instances For
A search never changes a column that was already marked as visited when the search began.
On success, augmenting adds exactly the root row to the set of matched rows, and it preserves the support and injectivity invariants.
Every nonzero support neighbor of the row lies in the specified column set.
Equations
- BeyondBethe.AllSupportNeighborsIn A row cols = ∀ (col : Fin n), A row col ≠ 0 → col ∈ cols
Instances For
A failed search has explored every remaining support edge of its root. Every newly explored column was occupied, and the old row at that column has all of its support neighbors in the final explored set.
- seen_subset : initialSeen ⊆ finalSeen
Instances For
The precise failure certificate returned by the executable search. The
strict fuel-plus-visited inequality is preserved by every recursive descent;
at zero fuel it contradicts the fact that there are only n columns.
If a full search from an unmatched row fails, its alternating-closure certificate contradicts any perfect matching. The contradiction is a finite pigeonhole argument: the root together with the old rows at the explored columns would inject into the explored columns.
Insert the listed rows one at a time, augmenting whenever possible.
Equations
- BeyondBethe.kuhnBuild A [] x✝ = x✝
- BeyondBethe.kuhnBuild A (row :: rows) x✝ = BeyondBethe.kuhnBuild A rows ((BeyondBethe.kuhnAugment A (n + 1) row ∅ x✝).mate?.getD x✝)
Instances For
The cumulative augmenting-search work for the row list, retaining the previous mate table when a search fails.
Equations
- BeyondBethe.kuhnBuildWork A [] x✝ = 0
- BeyondBethe.kuhnBuildWork A (row :: rows) x✝ = BeyondBethe.kuhnAugmentWork A (n + 1) row ∅ x✝ + BeyondBethe.kuhnBuildWork A rows ((BeyondBethe.kuhnAugment A (n + 1) row ∅ x✝).mate?.getD x✝)
Instances For
If a perfect matching exists, inserting a duplicate-free list of initially unmatched rows succeeds at every step and adds exactly those rows.
Support and injectivity are preserved even when some augmenting searches fail.
The mate table produced by inserting all rows in order, starting from the empty matching.
Equations
Instances For
Decide whether any column is matched to the given row.
Equations
- BeyondBethe.matchedRowDecision mate row = (List.finRange n).any fun (col : Fin n) => mate col == some row
Instances For
The executable support-perfect-matching decision.
Equations
- BeyondBethe.kuhnSupportMatchingDecision A = (List.finRange n).all fun (row : Fin n) => BeyondBethe.matchedRowDecision (BeyondBethe.kuhnColumnMate A) row
Instances For
Coordinate inspections in matching construction plus the final n by
n row-coverage check.