Documentation

CslibFrontier.Algorithms.Lean.Matroid.Greedy

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 #

Main results #

References #

Monadic and pure greedy definitions #

def Cslib.Algorithms.Lean.Matroid.greedyStepM {α : Type} [DecidableEq α] {m : Type → Type u_1} [Monad m] (indep : Finset α → m Bool) (acc : Finset α) (x : α) :
m (Finset α)

One monadic step of the greedy matroid scan: query whether insert x acc is independent and retain x when the test succeeds.

def Cslib.Algorithms.Lean.Matroid.greedySelectM {α : Type} [DecidableEq α] {m : Type → Type u_1} [Monad m] (indep : Finset α → m Bool) (xs : List α) :
m (Finset α)

Monadic greedy matroid scan over a candidate list xs, starting from ∅.

def Cslib.Algorithms.Lean.Matroid.greedyStep {α : Type u_1} [DecidableEq α] (indep : Finset α → Bool) (acc : Finset α) (x : α) :

Pure greedy step over a Boolean independence test indep : Finset α → Bool.

def Cslib.Algorithms.Lean.Matroid.greedySelect {α : Type u_1} [DecidableEq α] (indep : Finset α → Bool) (xs : List α) :

Pure greedy selection over a candidate list xs, starting from ∅.

def Cslib.Algorithms.Lean.Matroid.greedyMaxBasisM {α : Type} {β : Type u_1} [DecidableEq α] [LinearOrder β] {m : Type → Type u_2} [Monad m] (indep : Finset α → m Bool) (w : α → β) (xs : List α) :
m (Finset α)

Monadic maximum-weight basis selection: sort xs by nonincreasing weight w and run greedySelectM.

def Cslib.Algorithms.Lean.Matroid.greedyMaxBasis {α : Type u_1} {β : Type u_2} [DecidableEq α] [LinearOrder β] (indep : Finset α → Bool) (w : α → β) (xs : List α) :

Pure maximum-weight basis selection: sort xs by nonincreasing weight w and run greedySelect.

def Cslib.Algorithms.Lean.Matroid.greedyMinBasisM {α : Type} {β : Type u_1} [DecidableEq α] [LinearOrder β] {m : Type → Type u_2} [Monad m] (indep : Finset α → m Bool) (w : α → β) (xs : List α) :
m (Finset α)

Monadic minimum-weight basis selection (Kruskal order): sort xs by nondecreasing weight w and run greedySelectM.

def Cslib.Algorithms.Lean.Matroid.greedyMinBasis {α : Type u_1} {β : Type u_2} [DecidableEq α] [LinearOrder β] (indep : Finset α → Bool) (w : α → β) (xs : List α) :

Pure minimum-weight basis selection (Kruskal order): sort xs by nondecreasing weight w and run greedySelect.

def Cslib.Algorithms.Lean.Matroid.greedyMaxIndepM {α : Type} {β : Type u_1} [DecidableEq α] [Zero β] [LinearOrder β] {m : Type → Type u_2} [Monad m] (indep : Finset α → m Bool) (w : α → β) (xs : List α) :
m (Finset α)

Monadic maximum-weight independent-set selection under arbitrary signed weights: discard negative-weight elements (¬ 0 ≤ w x) before running greedyMaxBasisM.

def Cslib.Algorithms.Lean.Matroid.greedyMaxIndep {α : Type u_1} {β : Type u_2} [DecidableEq α] [Zero β] [LinearOrder β] (indep : Finset α → Bool) (w : α → β) (xs : List α) :

Pure maximum-weight independent-set selection under arbitrary signed weights: discard negative-weight elements (¬ 0 ≤ w x) before running greedyMaxBasis.

Monad homomorphism laws #

@[simp]
theorem Cslib.Algorithms.Lean.Matroid.greedySelectM_nil {α : Type} [DecidableEq α] {m : Type → Type u_1} [Monad m] (indep : Finset α → m Bool) :
@[simp]
theorem Cslib.Algorithms.Lean.Matroid.greedySelectM_pure {α : Type} [DecidableEq α] {m : Type → Type u_1} [Monad m] [LawfulMonad m] (indep : Finset α → Bool) (xs : List α) :
greedySelectM (fun (S : Finset α) => pure (indep S)) xs = pure (greedySelect indep xs)
@[simp]
theorem Cslib.Algorithms.Lean.Matroid.idRun_greedySelectM {α : Type} [DecidableEq α] (indep : Finset α → Id Bool) (xs : List α) :
(greedySelectM indep xs).run = greedySelect (fun (S : Finset α) => (indep S).run) xs
@[simp]
theorem Cslib.Algorithms.Lean.Matroid.greedyMaxBasisM_pure {α : Type} {β : Type u_1} [DecidableEq α] [LinearOrder β] {m : Type → Type u_2} [Monad m] [LawfulMonad m] (indep : Finset α → Bool) (w : α → β) (xs : List α) :
greedyMaxBasisM (fun (S : Finset α) => pure (indep S)) w xs = pure (greedyMaxBasis indep w xs)
@[simp]
theorem Cslib.Algorithms.Lean.Matroid.idRun_greedyMaxBasisM {α : Type} {β : Type u_1} [DecidableEq α] [LinearOrder β] (indep : Finset α → Id Bool) (w : α → β) (xs : List α) :
(greedyMaxBasisM indep w xs).run = greedyMaxBasis (fun (S : Finset α) => (indep S).run) w xs
@[simp]
theorem Cslib.Algorithms.Lean.Matroid.greedyMinBasisM_pure {α : Type} {β : Type u_1} [DecidableEq α] [LinearOrder β] {m : Type → Type u_2} [Monad m] [LawfulMonad m] (indep : Finset α → Bool) (w : α → β) (xs : List α) :
greedyMinBasisM (fun (S : Finset α) => pure (indep S)) w xs = pure (greedyMinBasis indep w xs)
@[simp]
theorem Cslib.Algorithms.Lean.Matroid.idRun_greedyMinBasisM {α : Type} {β : Type u_1} [DecidableEq α] [LinearOrder β] (indep : Finset α → Id Bool) (w : α → β) (xs : List α) :
(greedyMinBasisM indep w xs).run = greedyMinBasis (fun (S : Finset α) => (indep S).run) w xs
@[simp]
theorem Cslib.Algorithms.Lean.Matroid.greedyMaxIndepM_pure {α : Type} {β : Type u_1} [DecidableEq α] [Zero β] [LinearOrder β] {m : Type → Type u_2} [Monad m] [LawfulMonad m] (indep : Finset α → Bool) (w : α → β) (xs : List α) :
greedyMaxIndepM (fun (S : Finset α) => pure (indep S)) w xs = pure (greedyMaxIndep indep w xs)
@[simp]
theorem Cslib.Algorithms.Lean.Matroid.idRun_greedyMaxIndepM {α : Type} {β : Type u_1} [DecidableEq α] [Zero β] [LinearOrder β] (indep : Finset α → Id Bool) (w : α → β) (xs : List α) :
(greedyMaxIndepM indep w xs).run = greedyMaxIndep (fun (S : Finset α) => (indep S).run) w xs
theorem Cslib.IsMonadHom.map_greedySelectM {α : Type} [DecidableEq α] {m : Type → Type u_1} {n : Type → Type u_2} [Monad m] [Monad n] {f : {γ : Type} → m γ → n γ} (hf : IsMonadHom m n fun {α : Type} => f) (indep : Finset α → m Bool) (xs : List α) :
theorem Cslib.IsMonadHom.map_greedyMaxBasisM {α : Type} {β : Type u_1} [DecidableEq α] [LinearOrder β] {m : Type → Type u_2} {n : Type → Type u_3} [Monad m] [Monad n] {f : {γ : Type} → m γ → n γ} (hf : IsMonadHom m n fun {α : Type} => f) (indep : Finset α → m Bool) (w : α → β) (xs : List α) :
theorem Cslib.IsMonadHom.map_greedyMinBasisM {α : Type} {β : Type u_1} [DecidableEq α] [LinearOrder β] {m : Type → Type u_2} {n : Type → Type u_3} [Monad m] [Monad n] {f : {γ : Type} → m γ → n γ} (hf : IsMonadHom m n fun {α : Type} => f) (indep : Finset α → m Bool) (w : α → β) (xs : List α) :
theorem Cslib.IsMonadHom.map_greedyMaxIndepM {α : Type} {β : Type u_1} [DecidableEq α] [Zero β] [LinearOrder β] {m : Type → Type u_2} {n : Type → Type u_3} [Monad m] [Monad n] {f : {γ : Type} → m γ → n γ} (hf : IsMonadHom m n fun {α : Type} => f) (indep : Finset α → m Bool) (w : α → β) (xs : List α) :

Stability bridge to List.insertionSort for symbolic proof reduction #

theorem Cslib.Algorithms.Lean.Matroid.greedyMaxBasis_eq_insertionSort {α : Type u_1} {β : Type u_2} [DecidableEq α] [LinearOrder β] (indep : Finset α → Bool) (w : α → β) (xs : List α) :
greedyMaxBasis indep w xs = greedySelect indep (List.insertionSort (fun (a b : α) => w b ≤ w a) xs)

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.

theorem Cslib.Algorithms.Lean.Matroid.greedyMinBasis_eq_insertionSort {α : Type u_1} {β : Type u_2} [DecidableEq α] [LinearOrder β] (indep : Finset α → Bool) (w : α → β) (xs : List α) :
greedyMinBasis indep w xs = greedySelect indep (List.insertionSort (fun (a b : α) => w a ≤ w b) xs)

List.insertionSort rewriting form of greedyMinBasis, preserving ties by stability.

Structural properties of the greedy scan #

theorem Cslib.Algorithms.Lean.Matroid.greedySelect_subset_toFinset {α : Type u_1} [DecidableEq α] (indep : Finset α → Bool) (xs : List α) :
greedySelect indep xs ⊆ xs.toFinset

Every element chosen by greedySelect belongs to xs.toFinset (for any Boolean test).

theorem Cslib.Algorithms.Lean.Matroid.mem_of_mem_greedySelect {α : Type u_1} [DecidableEq α] {indep : Finset α → Bool} {xs : List α} {x : α} (hx : x ∈ greedySelect indep xs) :
x ∈ xs

Every element chosen by greedySelect appears in xs.

theorem Cslib.Algorithms.Lean.Matroid.mem_of_mem_greedyMaxBasis {α : Type u_1} [DecidableEq α] {β : Type u_2} [LinearOrder β] {indep : Finset α → Bool} {w : α → β} {xs : List α} {x : α} (hx : x ∈ greedyMaxBasis indep w xs) :
x ∈ xs

Every element chosen by greedyMaxBasis appears in xs.

theorem Cslib.Algorithms.Lean.Matroid.mem_of_mem_greedyMinBasis {α : Type u_1} [DecidableEq α] {β : Type u_2} [LinearOrder β] {indep : Finset α → Bool} {w : α → β} {xs : List α} {x : α} (hx : x ∈ greedyMinBasis indep w xs) :
x ∈ xs

Every element chosen by greedyMinBasis appears in xs.

theorem Cslib.Algorithms.Lean.Matroid.mem_and_nonneg_of_mem_greedyMaxIndep {α : Type u_1} [DecidableEq α] {β : Type u_2} [Zero β] [LinearOrder β] {indep : Finset α → Bool} {w : α → β} {xs : List α} {x : α} (hx : x ∈ greedyMaxIndep indep w xs) :
x ∈ xs ∧ 0 ≤ w x

Every element chosen by greedyMaxIndep appears in xs and has nonnegative weight.

theorem Cslib.Algorithms.Lean.Matroid.indep_greedySelect {α : Type u_1} [DecidableEq α] {indep : Finset α → Bool} (hempty : indep ∅ = true) (xs : List α) :
indep (greedySelect indep xs) = true

Whenever indep ∅ = true, greedySelect indep xs satisfies indep (even for arbitrary non-matroid predicates).

Matroid independence and basis theorems #

theorem Cslib.Algorithms.Lean.Matroid.greedySelect_indep {α : Type u_1} [DecidableEq α] {M : Matroid α} {indep : Finset α → Bool} (hM : ∀ (S : Finset α), indep S = true ↔ M.Indep ↑S) (xs : List α) :
M.Indep ↑(greedySelect indep xs)

Under an independence test implementing M : Matroid α, greedySelect returns an independent set.

theorem Cslib.Algorithms.Lean.Matroid.greedySelect_insert_not_indep {α : Type u_1} [DecidableEq α] {M : Matroid α} {indep : Finset α → Bool} (hM : ∀ (S : Finset α), indep S = true ↔ M.Indep ↑S) (xs : List α) {e : α} (he : e ∈ xs) (hne : e ∉ greedySelect indep xs) :
¬M.Indep (insert e ↑(greedySelect indep xs))

Any candidate e ∈ xs rejected by greedySelect cannot be added to the greedy output while preserving independence in M.

theorem Cslib.Algorithms.Lean.Matroid.greedySelect_isBasis' {α : Type u_1} [DecidableEq α] {M : Matroid α} {indep : Finset α → Bool} (hM : ∀ (S : Finset α), indep S = true ↔ M.Indep ↑S) (xs : List α) :
M.IsBasis' ↑(greedySelect indep xs) {x : α | x ∈ xs}

greedySelect computes a basis (Matroid.IsBasis') of {x | x ∈ xs} in M, without requiring xs to be duplicate-free or contained in M.E.

theorem Cslib.Algorithms.Lean.Matroid.greedySelect_isBasis {α : Type u_1} [DecidableEq α] {M : Matroid α} {indep : Finset α → Bool} (hM : ∀ (S : Finset α), indep S = true ↔ M.Indep ↑S) (xs : List α) (hE : {x : α | x ∈ xs} ⊆ M.E) :
M.IsBasis ↑(greedySelect indep xs) {x : α | x ∈ xs}

When all elements of xs lie in M.E, greedySelect computes a Matroid.IsBasis of {x | x ∈ xs}.

theorem Cslib.Algorithms.Lean.Matroid.greedySelect_isBase {α : Type u_1} [DecidableEq α] {M : Matroid α} {indep : Finset α → Bool} (hM : ∀ (S : Finset α), indep S = true ↔ M.Indep ↑S) (xs : List α) (hE : {x : α | x ∈ xs} = M.E) :
M.IsBase ↑(greedySelect indep xs)

When xs enumerates the entire ground set M.E, greedySelect computes a base (Matroid.IsBase) of M.

theorem Cslib.Algorithms.Lean.Matroid.card_le_greedySelect_card {α : Type u_1} [DecidableEq α] {M : Matroid α} {indep : Finset α → Bool} (hM : ∀ (S : Finset α), indep S = true ↔ M.Indep ↑S) (xs : List α) {I : Finset α} (hI : M.Indep ↑I) (hIsub : ↑I ⊆ {x : α | x ∈ xs}) :
I.card ≤ (greedySelect indep xs).card

Every independent finite subset I of {x | x ∈ xs} has cardinality at most (greedySelect indep xs).card.

theorem Cslib.Algorithms.Lean.Matroid.card_eq_greedySelect_card_of_isBasis' {α : Type u_1} [DecidableEq α] {M : Matroid α} {indep : Finset α → Bool} (hM : ∀ (S : Finset α), indep S = true ↔ M.Indep ↑S) (xs : List α) {I : Finset α} (hI : M.IsBasis' ↑I {x : α | x ∈ xs}) :
I.card = (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 #

theorem Cslib.Algorithms.Lean.Matroid.gale_dominance_nodup {α : Type u_1} [DecidableEq α] {M : Matroid α} {indep : Finset α → Bool} (hM : ∀ (S : Finset α), indep S = true ↔ M.Indep ↑S) {R : α → α → Prop} [Std.Refl R] {xs : List α} (hnodup : xs.Nodup) (hsorted : List.Pairwise R xs) {I : Finset α} (hI : M.Indep ↑I) (hIsub : ↑I ⊆ {x : α | x ∈ xs}) :
have G := greedySelect indep xs; have G_list := List.filter (fun (x : α) => decide (x ∈ G)) xs; have I_list := List.filter (fun (x : α) => decide (x ∈ I)) xs; ∃ (hlen : I_list.length ≤ G_list.length), ∀ (j : ℕ) (hj : j < I_list.length), R G_list[j] I_list[j]

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:

  1. I_list.length ≤ G_list.length, and
  2. for every index j < I_list.length, R G_list[j] I_list[j].

Rado–Edmonds and CLRS weighted optimality theorems #

theorem Cslib.Algorithms.Lean.Matroid.sum_le_greedySelect_of_isBasis' {α : Type u_1} {β : Type u_2} [DecidableEq α] [AddCommMonoid β] [Preorder β] [IsOrderedAddMonoid β] {M : Matroid α} {indep : Finset α → Bool} (hM : ∀ (S : Finset α), indep S = true ↔ M.Indep ↑S) (w : α → β) {xs : List α} (hsorted : List.Pairwise (fun (a b : α) => w b ≤ w a) xs) {I : Finset α} (hI : M.IsBasis' ↑I {x : α | x ∈ xs}) :
∑ x ∈ I, w x ≤ ∑ x ∈ greedySelect indep xs, w x

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

theorem Cslib.Algorithms.Lean.Matroid.greedySelect_le_sum_of_isBasis' {α : Type u_1} {β : Type u_2} [DecidableEq α] [AddCommMonoid β] [Preorder β] [IsOrderedAddMonoid β] {M : Matroid α} {indep : Finset α → Bool} (hM : ∀ (S : Finset α), indep S = true ↔ M.Indep ↑S) (w : α → β) {xs : List α} (hsorted : List.Pairwise (fun (a b : α) => w a ≤ w b) xs) {I : Finset α} (hI : M.IsBasis' ↑I {x : α | x ∈ xs}) :
∑ x ∈ greedySelect indep xs, w x ≤ ∑ x ∈ I, w x

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

theorem Cslib.Algorithms.Lean.Matroid.sum_le_greedySelect_of_indep {α : Type u_1} {β : Type u_2} [DecidableEq α] [AddCommMonoid β] [Preorder β] [IsOrderedAddMonoid β] {M : Matroid α} {indep : Finset α → Bool} (hM : ∀ (S : Finset α), indep S = true ↔ M.Indep ↑S) (w : α → β) {xs : List α} (hsorted : List.Pairwise (fun (a b : α) => w b ≤ w a) xs) (hnonneg : ∀ x ∈ xs, 0 ≤ w x) {I : Finset α} (hI : M.Indep ↑I) (hIsub : ↑I ⊆ {x : α | x ∈ xs}) :
∑ x ∈ I, w x ≤ ∑ x ∈ greedySelect indep xs, w x

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) #

theorem Cslib.Algorithms.Lean.Matroid.greedyMaxBasis_isBasis' {α : Type u_1} {β : Type u_2} [DecidableEq α] [LinearOrder β] {M : Matroid α} {indep : Finset α → Bool} (hM : ∀ (S : Finset α), indep S = true ↔ M.Indep ↑S) (w : α → β) (xs : List α) :
M.IsBasis' ↑(greedyMaxBasis indep w xs) {x : α | x ∈ xs}

greedyMaxBasis always returns a basis (Matroid.IsBasis') of {x | x ∈ xs}.

theorem Cslib.Algorithms.Lean.Matroid.greedyMinBasis_isBasis' {α : Type u_1} {β : Type u_2} [DecidableEq α] [LinearOrder β] {M : Matroid α} {indep : Finset α → Bool} (hM : ∀ (S : Finset α), indep S = true ↔ M.Indep ↑S) (w : α → β) (xs : List α) :
M.IsBasis' ↑(greedyMinBasis indep w xs) {x : α | x ∈ xs}

greedyMinBasis always returns a basis (Matroid.IsBasis') of {x | x ∈ xs}.

theorem Cslib.Algorithms.Lean.Matroid.sum_le_greedyMaxBasis {α : Type u_1} {β : Type u_2} [DecidableEq α] [AddCommMonoid β] [LinearOrder β] [IsOrderedAddMonoid β] {M : Matroid α} {indep : Finset α → Bool} (hM : ∀ (S : Finset α), indep S = true ↔ M.Indep ↑S) (w : α → β) (xs : List α) {I : Finset α} (hI : M.IsBasis' ↑I {x : α | x ∈ xs}) :
∑ x ∈ I, w x ≤ ∑ x ∈ greedyMaxBasis indep w xs, w x

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.

theorem Cslib.Algorithms.Lean.Matroid.greedyMinBasis_le_sum {α : Type u_1} {β : Type u_2} [DecidableEq α] [AddCommMonoid β] [LinearOrder β] [IsOrderedAddMonoid β] {M : Matroid α} {indep : Finset α → Bool} (hM : ∀ (S : Finset α), indep S = true ↔ M.Indep ↑S) (w : α → β) (xs : List α) {I : Finset α} (hI : M.IsBasis' ↑I {x : α | x ∈ xs}) :
∑ x ∈ greedyMinBasis indep w xs, w x ≤ ∑ x ∈ I, w x

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 ℕ).

theorem Cslib.Algorithms.Lean.Matroid.sum_le_greedyMaxBasis_of_indep {α : Type u_1} {β : Type u_2} [DecidableEq α] [AddCommMonoid β] [LinearOrder β] [IsOrderedAddMonoid β] {M : Matroid α} {indep : Finset α → Bool} (hM : ∀ (S : Finset α), indep S = true ↔ M.Indep ↑S) (w : α → β) (xs : List α) (hnonneg : ∀ x ∈ xs, 0 ≤ w x) {I : Finset α} (hI : M.Indep ↑I) (hIsub : ↑I ⊆ {x : α | x ∈ xs}) :
∑ x ∈ I, w x ≤ ∑ x ∈ greedyMaxBasis indep w xs, w x

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

theorem Cslib.Algorithms.Lean.Matroid.greedyMaxIndep_indep {α : Type u_1} {β : Type u_2} [DecidableEq α] [Zero β] [LinearOrder β] {M : Matroid α} {indep : Finset α → Bool} (hM : ∀ (S : Finset α), indep S = true ↔ M.Indep ↑S) (w : α → β) (xs : List α) :
M.Indep ↑(greedyMaxIndep indep w xs)

greedyMaxIndep returns an independent subset of {x | x ∈ xs}.

theorem Cslib.Algorithms.Lean.Matroid.sum_le_greedyMaxIndep {α : Type u_1} {β : Type u_2} [DecidableEq α] [AddCommMonoid β] [LinearOrder β] [IsOrderedAddMonoid β] {M : Matroid α} {indep : Finset α → Bool} (hM : ∀ (S : Finset α), indep S = true ↔ M.Indep ↑S) (w : α → β) (xs : List α) {I : Finset α} (hI : M.Indep ↑I) (hIsub : ↑I ⊆ {x : α | x ∈ xs}) :
∑ x ∈ I, w x ≤ ∑ x ∈ greedyMaxIndep indep w xs, w x

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 #

theorem Cslib.Algorithms.Lean.Matroid.augment_of_forall_sum_le_greedyMaxBasis {α : Type u_1} [DecidableEq α] {xs : List α} {indep : Finset α → Bool} (hhered : ∀ ⦃A B : Finset α⦄, indep B = true → A ⊆ B → indep A = true) (hsupp : ∀ ⦃A : Finset α⦄, indep A = true → ∀ x ∈ A, x ∈ xs) (hopt : ∀ (w : α → ℕ) (J : Finset α), indep J = true → ∑ x ∈ J, w x ≤ ∑ x ∈ greedyMaxBasis indep w xs, w x) ⦃I J : Finset α⦄ (hI : indep I = true) (hJ : indep J = true) (hlt : I.card < J.card) :
∃ e ∈ J, e ∉ I ∧ indep (insert e I) = true

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.

theorem Cslib.Algorithms.Lean.Matroid.exists_matroid_iff_forall_sum_le_greedyMaxBasis {α : Type u_1} [DecidableEq α] (xs : List α) (indep : Finset α → Bool) (hempty : indep ∅ = true) (hhered : ∀ ⦃A B : Finset α⦄, indep B = true → A ⊆ B → indep A = true) (hsupp : ∀ ⦃A : Finset α⦄, indep A = true → ∀ x ∈ A, x ∈ xs) :
(∃ (M : Matroid α), M.E = {x : α | x ∈ xs} ∧ ∀ (S : Finset α), indep S = true ↔ M.Indep ↑S) ↔ ∀ (w : α → ℕ) (J : Finset α), indep J = true → ∑ x ∈ J, w x ≤ ∑ x ∈ greedyMaxBasis indep w xs, w x

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.

theorem Cslib.Algorithms.Lean.Matroid.exists_matroid_finset_iff_forall_sum_le_greedyMaxBasis {α : Type u_1} [DecidableEq α] (E : Finset α) (indep : Finset α → Bool) (hempty : indep ∅ = true) (hhered : ∀ ⦃A B : Finset α⦄, indep B = true → A ⊆ B → indep A = true) (hsupp : ∀ ⦃A : Finset α⦄, indep A = true → A ⊆ E) :
(∃ (M : Matroid α), M.E = ↑E ∧ ∀ (S : Finset α), indep S = true ↔ M.Indep ↑S) ↔ ∀ (w : α → ℕ) (J : Finset α), indep J = true → ∑ x ∈ J, w x ≤ ∑ x ∈ greedyMaxBasis indep w E.toList, w x

Finset-ground-set form of the Rado–Edmonds Characterization (exists_matroid_iff_forall_sum_le_greedyMaxBasis instantiated at E.toList).