Documentation

CslibFrontier.Algorithms.Lean.Query.Matroid.Greedy

Matroid Greedy Selection as an Independence-Oracle Query Program #

This module instantiates the monadic matroid greedy algorithms from CslibFrontier.Algorithms.Lean.Matroid.Greedy in FreeM (IndepQuery α), separating independence oracle queries (charged via FreeM.countQueries and Cslib.Query.UpperBound) from pure host-side sorting and filtering.

Main definitions #

Main results #

Query-monadic matroid greedy programs #

Greedy matroid scan over xs making explicit independence queries via IndepQuery.ask.

def Cslib.Query.matroidGreedyMaxBasis {α : Type} {β : Type u_1} [DecidableEq α] [LinearOrder β] (w : α → β) (xs : List α) :

Maximum-weight matroid basis selection in the independence-oracle query model.

def Cslib.Query.matroidGreedyMinBasis {α : Type} {β : Type u_1} [DecidableEq α] [LinearOrder β] (w : α → β) (xs : List α) :

Minimum-weight matroid basis selection (Kruskal order) in the independence-oracle query model.

def Cslib.Query.matroidGreedyMaxIndep {α : Type} {β : Type u_1} [DecidableEq α] [Zero β] [LinearOrder β] (w : α → β) (xs : List α) :

Maximum-weight independent-set selection under arbitrary signed weights in the independence-oracle query model.

Evaluation agreement with pure greedy algorithms #

@[simp]
theorem Cslib.Query.eval_matroidGreedySelect {α : Type} [DecidableEq α] (oracle : {ι : Type} → IndepQuery α ι → ι) (xs : List α) :
FreeM.eval (fun {ι : Type} => oracle) (matroidGreedySelect xs) = Algorithms.Lean.Matroid.greedySelect (fun (S : Finset α) => oracle (IndepQuery.indep S)) xs
@[simp]
theorem Cslib.Query.eval_matroidGreedyMaxBasis {α : Type} {β : Type u_1} [DecidableEq α] [LinearOrder β] (oracle : {ι : Type} → IndepQuery α ι → ι) (w : α → β) (xs : List α) :
FreeM.eval (fun {ι : Type} => oracle) (matroidGreedyMaxBasis w xs) = Algorithms.Lean.Matroid.greedyMaxBasis (fun (S : Finset α) => oracle (IndepQuery.indep S)) w xs
@[simp]
theorem Cslib.Query.eval_matroidGreedyMinBasis {α : Type} {β : Type u_1} [DecidableEq α] [LinearOrder β] (oracle : {ι : Type} → IndepQuery α ι → ι) (w : α → β) (xs : List α) :
FreeM.eval (fun {ι : Type} => oracle) (matroidGreedyMinBasis w xs) = Algorithms.Lean.Matroid.greedyMinBasis (fun (S : Finset α) => oracle (IndepQuery.indep S)) w xs
@[simp]
theorem Cslib.Query.eval_matroidGreedyMaxIndep {α : Type} {β : Type u_1} [DecidableEq α] [Zero β] [LinearOrder β] (oracle : {ι : Type} → IndepQuery α ι → ι) (w : α → β) (xs : List α) :
FreeM.eval (fun {ι : Type} => oracle) (matroidGreedyMaxIndep w xs) = Algorithms.Lean.Matroid.greedyMaxIndep (fun (S : Finset α) => oracle (IndepQuery.indep S)) w xs

Exact query counts and Cslib.Query.UpperBound certificates #

@[simp]
theorem Cslib.Query.countQueries_matroidGreedySelect {α : Type} [DecidableEq α] (oracle : {ι : Type} → IndepQuery α ι → ι) (xs : List α) :
FreeM.countQueries (fun {ι : Type} => oracle) (matroidGreedySelect xs) = xs.length
@[simp]
theorem Cslib.Query.countQueries_matroidGreedyMaxBasis {α : Type} {β : Type u_1} [DecidableEq α] [LinearOrder β] (oracle : {ι : Type} → IndepQuery α ι → ι) (w : α → β) (xs : List α) :
FreeM.countQueries (fun {ι : Type} => oracle) (matroidGreedyMaxBasis w xs) = xs.length
@[simp]
theorem Cslib.Query.countQueries_matroidGreedyMinBasis {α : Type} {β : Type u_1} [DecidableEq α] [LinearOrder β] (oracle : {ι : Type} → IndepQuery α ι → ι) (w : α → β) (xs : List α) :
FreeM.countQueries (fun {ι : Type} => oracle) (matroidGreedyMinBasis w xs) = xs.length
@[simp]
theorem Cslib.Query.countQueries_matroidGreedyMaxIndep {α : Type} {β : Type u_1} [DecidableEq α] [Zero β] [LinearOrder β] (oracle : {ι : Type} → IndepQuery α ι → ι) (w : α → β) (xs : List α) :
FreeM.countQueries (fun {ι : Type} => oracle) (matroidGreedyMaxIndep w xs) = (List.filter (fun (x : α) => decide (0 ≤ w x)) xs).length
theorem Cslib.Query.countQueries_matroidGreedyMaxIndep_le {α : Type} {β : Type u_1} [DecidableEq α] [Zero β] [LinearOrder β] (oracle : {ι : Type} → IndepQuery α ι → ι) (w : α → β) (xs : List α) :
FreeM.countQueries (fun {ι : Type} => oracle) (matroidGreedyMaxIndep w xs) ≤ xs.length

matroidGreedySelect makes at most n independence queries on inputs of length at most n.

matroidGreedyMaxBasis w makes at most n independence queries on inputs of length at most n (sorting uses only pure weight comparisons).

matroidGreedyMinBasis w makes at most n independence queries on inputs of length at most n.

matroidGreedyMaxIndep w makes at most n independence queries on inputs of length at most n.

End-to-end correctness and weighted optimality in the oracle model #

theorem Cslib.Query.eval_matroidGreedySelect_isBasis' {α : Type} [DecidableEq α] {M : Matroid α} {oracle : {ι : Type} → IndepQuery α ι → ι} (horacle : IndepQuery.ImplementsMatroid (fun {ι : Type} => oracle) M) (xs : List α) :
M.IsBasis' ↑(FreeM.eval (fun {ι : Type} => oracle) (matroidGreedySelect xs)) {x : α | x ∈ xs}
theorem Cslib.Query.eval_matroidGreedyMaxBasis_isBasis' {α : Type} {β : Type u_1} [DecidableEq α] [LinearOrder β] {M : Matroid α} {oracle : {ι : Type} → IndepQuery α ι → ι} (horacle : IndepQuery.ImplementsMatroid (fun {ι : Type} => oracle) M) (w : α → β) (xs : List α) :
M.IsBasis' ↑(FreeM.eval (fun {ι : Type} => oracle) (matroidGreedyMaxBasis w xs)) {x : α | x ∈ xs}
theorem Cslib.Query.eval_matroidGreedyMinBasis_isBasis' {α : Type} {β : Type u_1} [DecidableEq α] [LinearOrder β] {M : Matroid α} {oracle : {ι : Type} → IndepQuery α ι → ι} (horacle : IndepQuery.ImplementsMatroid (fun {ι : Type} => oracle) M) (w : α → β) (xs : List α) :
M.IsBasis' ↑(FreeM.eval (fun {ι : Type} => oracle) (matroidGreedyMinBasis w xs)) {x : α | x ∈ xs}
theorem Cslib.Query.sum_le_eval_matroidGreedyMaxBasis {α : Type} {β : Type u_1} [DecidableEq α] [AddCommMonoid β] [LinearOrder β] [IsOrderedAddMonoid β] {M : Matroid α} {oracle : {ι : Type} → IndepQuery α ι → ι} (horacle : IndepQuery.ImplementsMatroid (fun {ι : Type} => oracle) M) (w : α → β) (xs : List α) {I : Finset α} (hI : M.IsBasis' ↑I {x : α | x ∈ xs}) :
∑ x ∈ I, w x ≤ ∑ x ∈ FreeM.eval (fun {ι : Type} => oracle) (matroidGreedyMaxBasis w xs), w x
theorem Cslib.Query.eval_matroidGreedyMinBasis_le_sum {α : Type} {β : Type u_1} [DecidableEq α] [AddCommMonoid β] [LinearOrder β] [IsOrderedAddMonoid β] {M : Matroid α} {oracle : {ι : Type} → IndepQuery α ι → ι} (horacle : IndepQuery.ImplementsMatroid (fun {ι : Type} => oracle) M) (w : α → β) (xs : List α) {I : Finset α} (hI : M.IsBasis' ↑I {x : α | x ∈ xs}) :
∑ x ∈ FreeM.eval (fun {ι : Type} => oracle) (matroidGreedyMinBasis w xs), w x ≤ ∑ x ∈ I, w x
theorem Cslib.Query.sum_le_eval_matroidGreedyMaxBasis_of_indep {α : Type} {β : Type u_1} [DecidableEq α] [AddCommMonoid β] [LinearOrder β] [IsOrderedAddMonoid β] {M : Matroid α} {oracle : {ι : Type} → IndepQuery α ι → ι} (horacle : IndepQuery.ImplementsMatroid (fun {ι : Type} => oracle) M) (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 ∈ FreeM.eval (fun {ι : Type} => oracle) (matroidGreedyMaxBasis w xs), w x
theorem Cslib.Query.eval_matroidGreedyMaxIndep_indep {α : Type} {β : Type u_1} [DecidableEq α] [Zero β] [LinearOrder β] {M : Matroid α} {oracle : {ι : Type} → IndepQuery α ι → ι} (horacle : IndepQuery.ImplementsMatroid (fun {ι : Type} => oracle) M) (w : α → β) (xs : List α) :
M.Indep ↑(FreeM.eval (fun {ι : Type} => oracle) (matroidGreedyMaxIndep w xs))
theorem Cslib.Query.sum_le_eval_matroidGreedyMaxIndep {α : Type} {β : Type u_1} [DecidableEq α] [AddCommMonoid β] [LinearOrder β] [IsOrderedAddMonoid β] {M : Matroid α} {oracle : {ι : Type} → IndepQuery α ι → ι} (horacle : IndepQuery.ImplementsMatroid (fun {ι : Type} => oracle) M) (w : α → β) (xs : List α) {I : Finset α} (hI : M.Indep ↑I) (hIsub : ↑I ⊆ {x : α | x ∈ xs}) :
∑ x ∈ I, w x ≤ ∑ x ∈ FreeM.eval (fun {ι : Type} => oracle) (matroidGreedyMaxIndep w xs), w x