Documentation

CslibFrontier.Languages.Probabilistic.Traverse.SupportWith

Traversing a list with an oracle program #

Running an oracle program on each entry of a list with ordinary List.mapM makes the calls of the entries one after the other. When each call q may be answered by any element of possible q, the possible results of the traversal are exactly the lists whose entries are possible results of the corresponding programs (OracleComp.mem_supportWith_mapM_iff), and the traversal of k entries each costing at most n costs at most k * n (OracleComp.IsCostBounded.mapM). Folding a list xs with List.foldlM whose step costs at most k costs at most xs.length * k (OracleComp.IsCostBounded.foldlM). This is the oracle analogue of Cslib.ProbComp.mem_support_mapM_iff.

Main results #

theorem Cslib.ProbOracleComp.run_mapM {Q I R : Type} {spec : Q → Type} (program : I → ProbOracleComp spec R) (xs : List I) (oracle : (q : Q) → ProbComp (spec q)) :
(List.mapM program xs).run oracle = List.mapM (fun (x : I) => (program x).run oracle) xs

Running a traversal runs each step with the same oracle.

theorem Cslib.ProbOracleComp.run_mapM_query {Q R : Type} (f : Q → R) (xs : List Q) :
((List.mapM query xs).run fun (x : Q) => pure (f x)) = pure (List.map f xs)

Against a fixed function, a list of external queries returns the list of its values.

theorem Cslib.OracleComp.mem_supportWith_mapM_iff {ι α β : Type} {spec : OracleSpec ι} (possible : (q : ι) → Set (spec q)) (program : α → OracleComp spec β) (inputs : List α) (outputs : List β) :
outputs ∈ supportWith possible (List.mapM program inputs) ↔ List.Forall₂ (fun (a : α) (b : β) => b ∈ supportWith possible (program a)) inputs outputs

The possible results of a list traversal are the lists whose entries are possible results of the corresponding programs.

theorem Cslib.OracleComp.IsCostBounded.mapM {ι α β : Type} {spec : OracleSpec ι} {cost : ι → ℕ} {program : α → OracleComp spec β} {n : ℕ} {inputs : List α} (h : ∀ a ∈ inputs, IsCostBounded cost (program a) n) :
IsCostBounded cost (List.mapM program inputs) (inputs.length * n)

A traversal of inputs whose entries each cost at most n costs at most inputs.length * n.

theorem Cslib.OracleComp.QueriesSatisfy.mapM {ι α β : Type} {spec : OracleSpec ι} {p : ι → Prop} {program : α → OracleComp spec β} {inputs : List α} (h : ∀ a ∈ inputs, QueriesSatisfy p (program a)) :
QueriesSatisfy p (List.mapM program inputs)

A traversal whose entries' calls all satisfy p makes only calls satisfying p.

theorem Cslib.OracleComp.IsCostBounded.foldlM {ι : Type u} {spec : OracleSpec ι} {α : Type v} {β : Type w} {cost : ι → ℕ} {f : α → β → OracleComp spec α} {k : ℕ} (hf : ∀ (a : α) (b : β), IsCostBounded cost (f a b) k) (init : α) (xs : List β) :
IsCostBounded cost (List.foldlM f init xs) (xs.length * k)

Folding xs by steps that each cost at most k costs at most xs.length * k.