Documentation

CslibFrontier.Algorithms.Lean.Query.SumQuery

Sums of Query Signatures #

SumQuery F G is the disjoint sum of two query signatures F G : Type → Type: a program in FreeM (SumQuery F G) may ask queries of either kind, and an oracle for the sum is a pair of oracles (SumQuery.combine). The counters countInl and countInr charge the two kinds of queries separately, and add up to FreeM.countQueries. This is used, for example, to charge value-oracle and independence-oracle calls of constrained submodular maximization separately.

Main definitions #

Main results #

inductive Cslib.Query.SumQuery (F G : Type → Type) :

The sum of two query signatures: a query is either an F-query or a G-query.

def Cslib.Query.SumQuery.combine {F G : Type → Type} (o₁ : {ι : Type} → F ι → ι) (o₂ : {ι : Type} → G ι → ι) {ι : Type} :
SumQuery F G ι → ι

The oracle for SumQuery F G answering F-queries with o₁ and G-queries with o₂.

@[simp]
theorem Cslib.Query.SumQuery.combine_inl {F G : Type → Type} (o₁ : {ι : Type} → F ι → ι) (o₂ : {ι : Type} → G ι → ι) {ι : Type} (q : F ι) :
combine (fun {ι : Type} => o₁) (fun {ι : Type} => o₂) (inl q) = o₁ q
@[simp]
theorem Cslib.Query.SumQuery.combine_inr {F G : Type → Type} (o₁ : {ι : Type} → F ι → ι) (o₂ : {ι : Type} → G ι → ι) {ι : Type} (q : G ι) :
combine (fun {ι : Type} => o₁) (fun {ι : Type} => o₂) (inr q) = o₂ q
@[reducible, inline]
abbrev Cslib.Query.SumQuery.liftInl {F G : Type → Type} {ι : Type} (q : F ι) :
FreeM (SumQuery F G) ι

Lift an F-query into FreeM (SumQuery F G).

@[reducible, inline]
abbrev Cslib.Query.SumQuery.liftInr {F G : Type → Type} {ι : Type} (q : G ι) :
FreeM (SumQuery F G) ι

Lift a G-query into FreeM (SumQuery F G).

def Cslib.Query.SumQuery.weightInl {F G : Type → Type} {ι : Type} :
SumQuery F G ι → ℕ

Unit weight on F-queries.

def Cslib.Query.SumQuery.weightInr {F G : Type → Type} {ι : Type} :
SumQuery F G ι → ℕ

Unit weight on G-queries.

def Cslib.Query.SumQuery.countInl {F G : Type → Type} {α : Type} (oracle : {ι : Type} → SumQuery F G ι → ι) (p : FreeM (SumQuery F G) α) :

The number of F-queries along the path of p determined by oracle.

def Cslib.Query.SumQuery.countInr {F G : Type → Type} {α : Type} (oracle : {ι : Type} → SumQuery F G ι → ι) (p : FreeM (SumQuery F G) α) :

The number of G-queries along the path of p determined by oracle.

@[simp]
theorem Cslib.Query.SumQuery.countInl_pure {F G : Type → Type} {α : Type} (oracle : {ι : Type} → SumQuery F G ι → ι) (a : α) :
countInl (fun {ι : Type} => oracle) (pure a) = 0
@[simp]
theorem Cslib.Query.SumQuery.countInr_pure {F G : Type → Type} {α : Type} (oracle : {ι : Type} → SumQuery F G ι → ι) (a : α) :
countInr (fun {ι : Type} => oracle) (pure a) = 0
@[simp]
theorem Cslib.Query.SumQuery.countInl_bind {F G : Type → Type} {α β : Type} (oracle : {ι : Type} → SumQuery F G ι → ι) (p : FreeM (SumQuery F G) α) (k : α → FreeM (SumQuery F G) β) :
countInl (fun {ι : Type} => oracle) (p >>= k) = countInl (fun {ι : Type} => oracle) p + countInl (fun {ι : Type} => oracle) (k (FreeM.eval (fun {ι : Type} => oracle) p))
@[simp]
theorem Cslib.Query.SumQuery.countInr_bind {F G : Type → Type} {α β : Type} (oracle : {ι : Type} → SumQuery F G ι → ι) (p : FreeM (SumQuery F G) α) (k : α → FreeM (SumQuery F G) β) :
countInr (fun {ι : Type} => oracle) (p >>= k) = countInr (fun {ι : Type} => oracle) p + countInr (fun {ι : Type} => oracle) (k (FreeM.eval (fun {ι : Type} => oracle) p))
@[simp]
theorem Cslib.Query.SumQuery.countInl_map {F G : Type → Type} {α β : Type} (oracle : {ι : Type} → SumQuery F G ι → ι) (p : FreeM (SumQuery F G) α) (g : α → β) :
countInl (fun {ι : Type} => oracle) (g <$> p) = countInl (fun {ι : Type} => oracle) p
@[simp]
theorem Cslib.Query.SumQuery.countInr_map {F G : Type → Type} {α β : Type} (oracle : {ι : Type} → SumQuery F G ι → ι) (p : FreeM (SumQuery F G) α) (g : α → β) :
countInr (fun {ι : Type} => oracle) (g <$> p) = countInr (fun {ι : Type} => oracle) p
@[simp]
theorem Cslib.Query.SumQuery.countInl_liftInl {F G : Type → Type} (oracle : {ι : Type} → SumQuery F G ι → ι) {ι : Type} (q : F ι) :
countInl (fun {ι : Type} => oracle) (liftInl q) = 1
@[simp]
theorem Cslib.Query.SumQuery.countInl_liftInr {F G : Type → Type} (oracle : {ι : Type} → SumQuery F G ι → ι) {ι : Type} (q : G ι) :
countInl (fun {ι : Type} => oracle) (liftInr q) = 0
@[simp]
theorem Cslib.Query.SumQuery.countInr_liftInl {F G : Type → Type} (oracle : {ι : Type} → SumQuery F G ι → ι) {ι : Type} (q : F ι) :
countInr (fun {ι : Type} => oracle) (liftInl q) = 0
@[simp]
theorem Cslib.Query.SumQuery.countInr_liftInr {F G : Type → Type} (oracle : {ι : Type} → SumQuery F G ι → ι) {ι : Type} (q : G ι) :
countInr (fun {ι : Type} => oracle) (liftInr q) = 1
theorem Cslib.Query.SumQuery.countInl_add_countInr {F G : Type → Type} {α : Type} (oracle : {ι : Type} → SumQuery F G ι → ι) (p : FreeM (SumQuery F G) α) :
countInl (fun {ι : Type} => oracle) p + countInr (fun {ι : Type} => oracle) p = FreeM.countQueries (fun {ι : Type} => oracle) p

The two counters split the total query count.