Matroid Greedy Algorithm and Weighted Optimality #
This module defines the greedy matroid algorithm (both monadically over an arbitrary effectful
independence test Finset α → m Bool and purely over Finset α → Bool) and proves its structural
and weighted optimality guarantees against Mathlib.Combinatorics.Matroid.
The monadic formulation greedySelectM instantiates with Id to recover the pure algorithm
greedySelect, and with FreeM (IndepQuery α) in
CslibFrontier.Algorithms.Lean.Query.Matroid.Greedy to count independence-oracle queries
explicitly.
Main definitions #
Cslib.Algorithms.Lean.Matroid.greedyStepM,greedySelectM: monadic greedy scan over a list of candidate elements, augmenting the current independentFinset αwhenever the oracle accepts.Cslib.Algorithms.Lean.Matroid.greedyStep,greedySelect: pure specializations.Cslib.Algorithms.Lean.Matroid.greedyMaxBasisM,greedyMaxBasis: sort candidates by nonincreasing weightwviaList.mergeSortand run greedy selection.Cslib.Algorithms.Lean.Matroid.greedyMinBasisM,greedyMinBasis: sort candidates by nondecreasing weightw(Kruskal order) and run greedy selection.Cslib.Algorithms.Lean.Matroid.greedyMaxIndepM,greedyMaxIndep: filter candidates with0 ≤ w xbefore runninggreedyMaxBasis, handling arbitrary signed weights.
Main results #
greedyMaxBasis_eq_insertionSort,greedyMinBasis_eq_insertionSort: stability bridge showing thatList.mergeSort-based weighted selection agrees withList.insertionSort, enabling direct kerneldecidereduction on concrete inputs even when weights have ties.greedySelect_isBasis',greedySelect_isBasis,greedySelect_isBase: for anyMatroid αand candidate listxs : List α(possibly containing duplicates),greedySelectcomputes a basis of{x | x ∈ xs}.gale_dominance_nodup: Gale's pointwise dominance theorem ([Gal68], Theorem, p. 177): whenxsis duplicate-free and sorted with respect to a reflexive relationR, thej-th greedy element dominates thej-th element of any independent subsetIofxsunderR.sum_le_greedySelect_of_isBasis',greedySelect_le_sum_of_isBasis',sum_le_greedyMaxBasis,greedyMinBasis_le_sum: Rado–Edmonds weighted basis optimality ([Rad57]; [Edm71], Section 2) for both maximum-weight and minimum-weight bases under arbitrary weights in an ordered commutative additive monoid (including unsignedℕweights for minimum-weight bases without negation).sum_le_greedySelect_of_indep,sum_le_greedyMaxBasis_of_indep: maximum-weight independent subset optimality for nonnegative weights (generalizing [CLRS09], Section 16.4, Theorem 16.11 from strictly positive to nonnegative weights).sum_le_greedyMaxIndep: maximum-weight independent subset optimality for arbitrary signed weights via nonnegative pre-filtering ([Edm71], Section 2).augment_of_forall_sum_le_greedyMaxBasis,exists_matroid_iff_forall_sum_le_greedyMaxBasis,exists_matroid_finset_iff_forall_sum_le_greedyMaxBasis: converse and full Rado–Edmonds characterization ([Rad57]; [Edm71], Section 2): a finite hereditary system is a matroid if and only ifgreedyMaxBasisis optimal for allℕ-valued weight functions.
References #
- [Rad57] Richard Rado, Note on Independence Functions, 1957.
- [Gal68] David Gale, Optimal Assignments in an Ordered Set: An Application of Matroid Theory, 1968.
- [Edm71] Jack Edmonds, Matroids and the Greedy Algorithm, 1971.
- [CLRS09] Cormen, Leiserson, Rivest, and Stein, Introduction to Algorithms (3rd ed.), Section 16.4, Theorem 16.11.
Monadic and pure greedy definitions #
One monadic step of the greedy matroid scan: query whether insert x acc is independent and
retain x when the test succeeds.
Pure greedy step over a Boolean independence test indep : Finset α → Bool.
Pure greedy selection over a candidate list xs, starting from ∅.
Monadic maximum-weight basis selection: sort xs by nonincreasing weight w and run
greedySelectM.
Pure maximum-weight basis selection: sort xs by nonincreasing weight w and run
greedySelect.
Monadic minimum-weight basis selection (Kruskal order): sort xs by nondecreasing weight w
and run greedySelectM.
Pure minimum-weight basis selection (Kruskal order): sort xs by nondecreasing weight w and
run greedySelect.
Monadic maximum-weight independent-set selection under arbitrary signed weights: discard
negative-weight elements (¬ 0 ≤ w x) before running greedyMaxBasisM.
Pure maximum-weight independent-set selection under arbitrary signed weights: discard
negative-weight elements (¬ 0 ≤ w x) before running greedyMaxBasis.
Monad homomorphism laws #
Stability bridge to List.insertionSort for symbolic proof reduction #
List.mergeSort and List.insertionSort are both stable, so greedyMaxBasis equals
greedySelect over xs.insertionSort (fun a b => w b ≤ w a) even when distinct elements share a
weight. This allows simp to evaluate greedyMaxBasis symbolically on concrete lists without
exposing List.mergeSort's internal splitter.
List.insertionSort rewriting form of greedyMinBasis, preserving ties by stability.
Structural properties of the greedy scan #
Every element chosen by greedySelect belongs to xs.toFinset (for any Boolean test).
Every element chosen by greedySelect appears in xs.
Every element chosen by greedyMaxBasis appears in xs.
Every element chosen by greedyMinBasis appears in xs.
Every element chosen by greedyMaxIndep appears in xs and has nonnegative weight.
Whenever indep ∅ = true, greedySelect indep xs satisfies indep (even for arbitrary
non-matroid predicates).
Matroid independence and basis theorems #
Under an independence test implementing M : Matroid α, greedySelect returns an independent
set.
Any candidate e ∈ xs rejected by greedySelect cannot be added to the greedy output while
preserving independence in M.
greedySelect computes a basis (Matroid.IsBasis') of {x | x ∈ xs} in M, without
requiring xs to be duplicate-free or contained in M.E.
When all elements of xs lie in M.E, greedySelect computes a Matroid.IsBasis of
{x | x ∈ xs}.
When xs enumerates the entire ground set M.E, greedySelect computes a base
(Matroid.IsBase) of M.
Every independent finite subset I of {x | x ∈ xs} has cardinality at most
(greedySelect indep xs).card.
Every basis I of {x | x ∈ xs} has the same cardinality as greedySelect indep xs.
Deduplication invariance (retaining first occurrences) #
Gale's pointwise dominance theorem #
Gale's Pointwise Dominance Theorem ([Gal68], Theorem, p. 177):
Let xs be a duplicate-free list sorted with respect to a reflexive relation R, and let
G := greedySelect indep xs be the greedy output for M : Matroid α. For every independent set
I : Finset α contained in {x | x ∈ xs}, listing G and I in the order of xs as
G_list := xs.filter (· ∈ G) and I_list := xs.filter (· ∈ I) yields:
I_list.length ≤ G_list.length, and- for every index
j < I_list.length,R G_list[j] I_list[j].
Rado–Edmonds and CLRS weighted optimality theorems #
Rado–Edmonds Maximum-Weight Basis Theorem (pre-sorted candidate list, [Rad57];
[Edm71], Section 2): if xs is ordered by nonincreasing weight w b ≤ w a, then
greedySelect indep xs maximizes total weight ∑ x ∈ I, w x among all bases I of
{x | x ∈ xs} in M (under arbitrary signed or unsigned weights).
Rado–Edmonds Minimum-Weight Basis Theorem (pre-sorted candidate list, Kruskal order):
if xs is ordered by nondecreasing weight w a ≤ w b, then greedySelect indep xs minimizes
total weight ∑ x ∈ I, w x among all bases I of {x | x ∈ xs} in M (valid even over ℕ
without negation or subtraction).
Weighted Independent-Set Optimality for pre-sorted nonnegative weights (generalizing
[CLRS09], Section 16.4, Theorem 16.11 from strictly positive to nonnegative weights): if xs is
ordered by nonincreasing weight w b ≤ w a and 0 ≤ w x for every x ∈ xs, then
greedySelect indep xs maximizes ∑ x ∈ I, w x over all independent finite subsets I of
{x | x ∈ xs}.
Unsorted weighted entrypoints (greedyMaxBasis, greedyMinBasis, greedyMaxIndep) #
greedyMaxBasis always returns a basis (Matroid.IsBasis') of {x | x ∈ xs}.
greedyMinBasis always returns a basis (Matroid.IsBasis') of {x | x ∈ xs}.
Maximum-Weight Basis Optimality ([Edm71], Section 2): greedyMaxBasis indep w xs
maximizes ∑ x ∈ I, w x among all bases I of {x | x ∈ xs}, under arbitrary weights.
Minimum-Weight Basis Optimality (Kruskal order): greedyMinBasis indep w xs minimizes
∑ x ∈ I, w x among all bases I of {x | x ∈ xs} (including over ℕ).
Maximum-Weight Independent-Set Optimality for nonnegative weights (generalizing [CLRS09],
Section 16.4, Theorem 16.11 from strictly positive to nonnegative weights): when 0 ≤ w x for all
x ∈ xs, greedyMaxBasis indep w xs maximizes ∑ x ∈ I, w x over all independent finite subsets
I of {x | x ∈ xs}.
greedyMaxIndep returns an independent subset of {x | x ∈ xs}.
Maximum-Weight Independent-Set Optimality for arbitrary signed weights ([Edm71],
Section 2): greedyMaxIndep indep w xs maximizes ∑ x ∈ I, w x over all independent finite
subsets I of {x | x ∈ xs} without any nonnegativity restriction on w.
Converse and full Rado–Edmonds matroid characterization #
Converse of Rado–Edmonds ([Rad57]; [Edm71], Section 2): if indep is hereditary
and supported on {x | x ∈ xs}, and greedyMaxBasis indep w xs achieves weight at least
∑ x ∈ J, w x for every ℕ-valued weight function w and every indep-set J, then indep
satisfies the matroid augmentation axiom.
Rado–Edmonds Characterization of Matroids ([Rad57]; [Edm71], Section 2):
Let xs : List α enumerate a finite ground set and let indep : Finset α → Bool be a nonempty
hereditary Boolean predicate supported on {x | x ∈ xs}. Then indep is the finite-set
independence predicate of a matroid M : Matroid α with ground set M.E = {x | x ∈ xs} if and
only if for every nonnegative integer weight function w : α → ℕ and every indep-set J,
greedyMaxBasis indep w xs returns a set of weight at least ∑ x ∈ J, w x.
Finset-ground-set form of the Rado–Edmonds Characterization
(exists_matroid_iff_forall_sum_le_greedyMaxBasis instantiated at E.toList).