Documentation

VCVio.OracleComp.QueryTracking.QueryRuntime

Bundled Query Runtimes #

This file packages concrete query implementations as explicit runtime objects.

HasQuery spec m is the right capability interface for constructions that only need to issue queries. When we want to instrument, transport, or otherwise analyze that capability, we also need an explicit QueryImpl spec m to work with. QueryRuntime spec m is the thin bundle that stores that implementation without changing the capability layer.

The main use cases are:

structure QueryRuntime {ι : Type} (spec : OracleSpec ι) (m : TypeType u_1) :
Type u_1

Bundled implementation of the oracle family spec in the ambient monad m.

  • impl : QueryImpl spec m

    Concrete implementation of each query in the family spec.

Instances For
    @[reducible, inline]
    abbrev QueryRuntime.toHasQuery {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} (runtime : QueryRuntime spec m) :
    HasQuery spec m

    View a bundled query runtime as the corresponding HasQuery capability.

    Instances For
      @[simp]
      theorem QueryRuntime.toHasQuery_query {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} (runtime : QueryRuntime spec m) (t : spec.Domain) :
      HasQuery.query t = runtime.impl t
      def QueryRuntime.ofHasQuery {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} [HasQuery spec m] :

      Repackage an existing HasQuery capability as an explicit query runtime.

      Instances For
        @[simp]
        theorem QueryRuntime.ofHasQuery_impl {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} [HasQuery spec m] (t : spec.Domain) :
        @[reducible, inline]

        The canonical bundled runtime for the free oracle monad OracleComp spec.

        Instances For
          def QueryRuntime.withCost {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} [Monad m] {ω : Type} [Monoid ω] (runtime : QueryRuntime spec m) (costFn : spec.Domainω) :
          QueryRuntime spec (WriterT ω m)

          Instrument a query runtime with multiplicative/monoidal cost accumulation in a WriterT layer.

          Instances For
            @[simp]
            theorem QueryRuntime.withCost_impl {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} [Monad m] {ω : Type} [Monoid ω] (runtime : QueryRuntime spec m) (costFn : spec.Domainω) (t : spec.Domain) :
            (runtime.withCost costFn).impl t = do tell (costFn t) liftM (runtime.impl t)
            def QueryRuntime.withAddCost {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} [Monad m] {ω : Type} [AddMonoid ω] (runtime : QueryRuntime spec m) (costFn : spec.Domainω) :

            Instrument a query runtime with additive cost accumulation in an AddWriterT layer.

            Instances For
              @[simp]
              theorem QueryRuntime.withAddCost_impl {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} [Monad m] {ω : Type} [AddMonoid ω] (runtime : QueryRuntime spec m) (costFn : spec.Domainω) (t : spec.Domain) :
              (runtime.withAddCost costFn).impl t = do AddWriterT.addTell (costFn t) liftM (runtime.impl t)
              def QueryRuntime.withUnitCost {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} [Monad m] (runtime : QueryRuntime spec m) :

              Instrument a query runtime with unit additive cost for every query.

              Instances For
                @[simp]
                theorem QueryRuntime.withUnitCost_impl {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} [Monad m] (runtime : QueryRuntime spec m) (t : spec.Domain) :
                runtime.withUnitCost.impl t = do AddWriterT.addTell 1 liftM (runtime.impl t)
                def AddWriterT.PathwiseCostAtMost {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] {ω : Type} [AddMonoid ω] [Preorder ω] (oa : AddWriterT ω m α) (w : ω) :

                Pathwise upper bound for an AddWriterT computation: every reachable execution result carries additive cost at most w.

                Instances For
                  def AddWriterT.PathwiseCostAtLeast {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] {ω : Type} [AddMonoid ω] [Preorder ω] (oa : AddWriterT ω m α) (w : ω) :

                  Pathwise lower bound for an AddWriterT computation: every reachable execution result carries additive cost at least w.

                  Instances For
                    def AddWriterT.PathwiseCostEqOnSupport {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] {ω : Type} [AddMonoid ω] [Preorder ω] (oa : AddWriterT ω m α) (w : ω) :

                    Pathwise exactness on support for an AddWriterT computation: every reachable execution result carries exactly the additive cost w.

                    This is the weak extensional notion of pathwise exactness. If oa.run has empty support, it holds vacuously for every w. Use [AddWriterT.PathwiseHasCost] when the intended meaning is that oa has an exact pathwise cost and admits at least one reachable execution.

                    Instances For
                      @[simp]
                      theorem AddWriterT.pathwiseCostEqOnSupport_iff {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] {ω : Type} [AddMonoid ω] [Preorder ω] (oa : AddWriterT ω m α) (w : ω) :
                      def AddWriterT.PathwiseHasCost {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] {ω : Type} [AddMonoid ω] [Preorder ω] (oa : AddWriterT ω m α) (w : ω) :

                      Pathwise exact cost for an AddWriterT computation: oa has at least one reachable execution, and every reachable execution result carries exactly the additive cost w.

                      This is the strong semantic notion of exact cost over execution paths. Unlike [AddWriterT.HasCost], it does not require cost to be recoverable from the final output alone. Unlike [AddWriterT.PathwiseCostEqOnSupport], it is not vacuous on computations with empty support.

                      Instances For
                        @[simp]
                        theorem AddWriterT.pathwiseHasCost_iff {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] {ω : Type} [AddMonoid ω] [Preorder ω] (oa : AddWriterT ω m α) (w : ω) :
                        theorem AddWriterT.PathwiseHasCost.nonempty {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] {ω : Type} [AddMonoid ω] [Preorder ω] {oa : AddWriterT ω m α} {w : ω} (h : oa.PathwiseHasCost w) :
                        theorem AddWriterT.PathwiseCostEqOnSupport.atMost {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] {ω : Type} [AddMonoid ω] [Preorder ω] {oa : AddWriterT ω m α} {w : ω} (h : oa.PathwiseCostEqOnSupport w) :
                        theorem AddWriterT.PathwiseCostEqOnSupport.atLeast {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] {ω : Type} [AddMonoid ω] [Preorder ω] {oa : AddWriterT ω m α} {w : ω} (h : oa.PathwiseCostEqOnSupport w) :
                        theorem AddWriterT.PathwiseHasCost.eqOnSupport {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] {ω : Type} [AddMonoid ω] [Preorder ω] {oa : AddWriterT ω m α} {w : ω} (h : oa.PathwiseHasCost w) :
                        theorem AddWriterT.PathwiseHasCost.atMost {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] {ω : Type} [AddMonoid ω] [Preorder ω] {oa : AddWriterT ω m α} {w : ω} (h : oa.PathwiseHasCost w) :
                        theorem AddWriterT.PathwiseHasCost.atLeast {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] {ω : Type} [AddMonoid ω] [Preorder ω] {oa : AddWriterT ω m α} {w : ω} (h : oa.PathwiseHasCost w) :
                        theorem AddWriterT.PathwiseHasCost.unique {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] {ω : Type} [AddMonoid ω] [PartialOrder ω] {oa : AddWriterT ω m α} {w₁ w₂ : ω} (h₁ : oa.PathwiseHasCost w₁) (h₂ : oa.PathwiseHasCost w₂) :
                        w₁ = w₂
                        theorem AddWriterT.pathwiseCostAtMost_of_hasCost {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] {ω : Type} [AddMonoid ω] [Preorder ω] [LawfulMonad m] {oa : AddWriterT ω m α} {w b : ω} (h : oa.HasCost w) (hwb : w b) :
                        theorem AddWriterT.pathwiseCostAtLeast_of_hasCost {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] {ω : Type} [AddMonoid ω] [Preorder ω] [LawfulMonad m] {oa : AddWriterT ω m α} {w b : ω} (h : oa.HasCost w) (hbw : b w) :
                        noncomputable def AddWriterT.expectedCost {m : TypeType u_1} [Monad m] {α ω : Type} [HasEvalSPMF m] (oa : AddWriterT ω m α) (val : ωENNReal) :

                        The expected additive cost of an AddWriterT computation, obtained by taking the expectation of its cost marginal.

                        This expectation is computed over the base monad's subdistribution semantics on oa.costs. In particular, if the underlying computation can fail, the missing mass contributes 0, exactly as for other wp-style expectations in VCV-io.

                        Instances For
                          @[reducible, inline]
                          noncomputable abbrev AddWriterT.expectedCostNat {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSPMF m] (oa : AddWriterT m α) :

                          Convenience specialization of [AddWriterT.expectedCost] to natural-valued additive costs.

                          Instances For
                            theorem AddWriterT.expectedCostNat_eq_tsum_tail_probs {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSPMF m] (oa : AddWriterT m α) :
                            oa.expectedCostNat = ∑' (i : ), probEvent oa.costs fun (c : ) => i < c

                            Tail-sum formula for the natural-valued expected cost of an AddWriterT computation:

                            E[cost] = ∑ i, Pr[i < cost].

                            This is the standard discrete expectation identity specialized to the writer-cost marginal.

                            theorem AddWriterT.expectedCostNat_le_tsum_of_tail_probs_le {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSPMF m] (oa : AddWriterT m α) {a : ENNReal} (h : ∀ (i : ), (probEvent oa.costs fun (c : ) => i < c) a i) :

                            Tail domination bounds the expected natural-valued writer cost.

                            If the tail probability Pr[i < cost] is bounded by a i for every i, then E[cost] ≤ ∑ i, a i.

                            theorem AddWriterT.expectedCostNat_eq_sum_tail_probs_of_pathwiseCostAtMost {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSPMF m] [LawfulMonad m] {oa : AddWriterT m α} {n : } (h : oa.PathwiseCostAtMost n) :
                            oa.expectedCostNat = iFinset.range n, probEvent oa.costs fun (c : ) => i < c

                            Finite tail-sum formula for natural-valued writer cost under a pathwise upper bound.

                            If every execution path of oa incurs cost at most n, then the tail probabilities vanish above n, so the infinite tail sum truncates to Finset.range n.

                            theorem AddWriterT.expectedCost_le_of_support_bound {m : TypeType u_1} [Monad m] {α ω : Type} [HasEvalSPMF m] (oa : AddWriterT ω m α) (val : ωENNReal) (c : ENNReal) (h : wsupport oa.costs, val w c) :
                            oa.expectedCost val c
                            theorem AddWriterT.expectedCost_le_of_pathwiseCostAtMost {m : TypeType u_1} [Monad m] {α ω : Type} [AddMonoid ω] [HasEvalSPMF m] [LawfulMonad m] [Preorder ω] {oa : AddWriterT ω m α} {w : ω} {val : ωENNReal} (h : oa.PathwiseCostAtMost w) (hval : Monotone val) :
                            oa.expectedCost val val w
                            theorem AddWriterT.expectedCost_ge_of_pathwiseCostAtLeast {m : TypeType u_1} [Monad m] {α ω : Type} [AddMonoid ω] [LawfulMonad m] [Preorder ω] [HasEvalPMF m] {oa : AddWriterT ω m α} {w : ω} {val : ωENNReal} (h : oa.PathwiseCostAtLeast w) (hval : Monotone val) :
                            val w oa.expectedCost val
                            theorem AddWriterT.expectedCost_eq_tsum_outputs_of_costsAs {m : TypeType u_1} [Monad m] {α ω : Type} [HasEvalSPMF m] [LawfulMonad m] {oa : AddWriterT ω m α} {f : αω} {val : ωENNReal} (h : oa.CostsAs f) :
                            oa.expectedCost val = ∑' (a : α), Pr[= a | oa.outputs] * val (f a)
                            theorem AddWriterT.pathwiseHasCost_pure {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] {ω : Type} [AddCommMonoid ω] [PartialOrder ω] [LawfulMonad m] (x : α) :
                            theorem AddWriterT.pathwiseCostAtMost_mono {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] {ω : Type} [AddCommMonoid ω] [PartialOrder ω] {oa : AddWriterT ω m α} {w₁ w₂ : ω} (h : oa.PathwiseCostAtMost w₁) (hw : w₁ w₂) :
                            theorem AddWriterT.pathwiseCostAtLeast_mono {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] {ω : Type} [AddCommMonoid ω] [PartialOrder ω] {oa : AddWriterT ω m α} {w₁ w₂ : ω} (h : oa.PathwiseCostAtLeast w₂) (hw : w₁ w₂) :
                            theorem AddWriterT.pathwiseCostAtMost_map {m : TypeType u_1} [Monad m] {α β : Type} [HasEvalSet m] {ω : Type} [AddCommMonoid ω] [PartialOrder ω] [LawfulMonad m] {oa : AddWriterT ω m α} {w : ω} (f : αβ) (h : oa.PathwiseCostAtMost w) :
                            theorem AddWriterT.pathwiseCostAtLeast_map {m : TypeType u_1} [Monad m] {α β : Type} [HasEvalSet m] {ω : Type} [AddCommMonoid ω] [PartialOrder ω] [LawfulMonad m] {oa : AddWriterT ω m α} {w : ω} (f : αβ) (h : oa.PathwiseCostAtLeast w) :
                            theorem AddWriterT.pathwiseCostEqOnSupport_map {m : TypeType u_1} [Monad m] {α β : Type} [HasEvalSet m] {ω : Type} [AddCommMonoid ω] [PartialOrder ω] [LawfulMonad m] {oa : AddWriterT ω m α} {w : ω} (f : αβ) (h : oa.PathwiseCostEqOnSupport w) :
                            theorem AddWriterT.pathwiseHasCost_map {m : TypeType u_1} [Monad m] {α β : Type} [HasEvalSet m] {ω : Type} [AddCommMonoid ω] [PartialOrder ω] [LawfulMonad m] {oa : AddWriterT ω m α} {w : ω} (f : αβ) (h : oa.PathwiseHasCost w) :
                            theorem AddWriterT.pathwiseCostAtMost_bind {m : TypeType u_1} [Monad m] {α β : Type} [HasEvalSet m] {ω : Type} [AddCommMonoid ω] [PartialOrder ω] [LawfulMonad m] [IsOrderedAddMonoid ω] {oa : AddWriterT ω m α} {f : αAddWriterT ω m β} {w₁ w₂ : ω} (h₁ : oa.PathwiseCostAtMost w₁) (h₂ : ∀ (a : α), (f a).PathwiseCostAtMost w₂) :
                            (oa >>= f).PathwiseCostAtMost (w₁ + w₂)
                            theorem AddWriterT.pathwiseCostAtLeast_bind {m : TypeType u_1} [Monad m] {α β : Type} [HasEvalSet m] {ω : Type} [AddCommMonoid ω] [PartialOrder ω] [LawfulMonad m] [IsOrderedAddMonoid ω] {oa : AddWriterT ω m α} {f : αAddWriterT ω m β} {w₁ w₂ : ω} (h₁ : oa.PathwiseCostAtLeast w₁) (h₂ : ∀ (a : α), (f a).PathwiseCostAtLeast w₂) :
                            (oa >>= f).PathwiseCostAtLeast (w₁ + w₂)
                            theorem AddWriterT.pathwiseCostEqOnSupport_bind {m : TypeType u_1} [Monad m] {α β : Type} [HasEvalSet m] {ω : Type} [AddCommMonoid ω] [PartialOrder ω] [LawfulMonad m] [IsOrderedAddMonoid ω] {oa : AddWriterT ω m α} {f : αAddWriterT ω m β} {w₁ w₂ : ω} (h₁ : oa.PathwiseCostEqOnSupport w₁) (h₂ : ∀ (a : α), (f a).PathwiseCostEqOnSupport w₂) :
                            (oa >>= f).PathwiseCostEqOnSupport (w₁ + w₂)
                            theorem AddWriterT.pathwiseHasCost_bind {m : TypeType u_1} [Monad m] {α β : Type} [HasEvalSet m] {ω : Type} [AddCommMonoid ω] [PartialOrder ω] [LawfulMonad m] [IsOrderedAddMonoid ω] {oa : AddWriterT ω m α} {f : αAddWriterT ω m β} {w₁ w₂ : ω} (h₁ : oa.PathwiseHasCost w₁) (h₂ : ∀ (a : α), (f a).PathwiseHasCost w₂) :
                            (oa >>= f).PathwiseHasCost (w₁ + w₂)
                            theorem AddWriterT.pathwiseHasCost_bind_zero_left {m : TypeType u_1} [Monad m] {α β : Type} [HasEvalSet m] {ω : Type} [AddCommMonoid ω] [PartialOrder ω] [LawfulMonad m] [IsOrderedAddMonoid ω] {oa : AddWriterT ω m α} {f : αAddWriterT ω m β} {w : ω} (h₁ : oa.PathwiseHasCost 0) (h₂ : ∀ (a : α), (f a).PathwiseHasCost w) :
                            theorem AddWriterT.pathwiseHasCost_bind_zero_right {m : TypeType u_1} [Monad m] {α β : Type} [HasEvalSet m] {ω : Type} [AddCommMonoid ω] [PartialOrder ω] [LawfulMonad m] [IsOrderedAddMonoid ω] {oa : AddWriterT ω m α} {f : αAddWriterT ω m β} {w : ω} (h₁ : oa.PathwiseHasCost w) (h₂ : ∀ (a : α), (f a).PathwiseHasCost 0) :
                            theorem AddWriterT.pathwiseCostEqOnSupport_bind_zero_left {m : TypeType u_1} [Monad m] {α β : Type} [HasEvalSet m] {ω : Type} [AddCommMonoid ω] [PartialOrder ω] [LawfulMonad m] [IsOrderedAddMonoid ω] {oa : AddWriterT ω m α} {f : αAddWriterT ω m β} {w : ω} (h₁ : oa.PathwiseCostEqOnSupport 0) (h₂ : ∀ (a : α), (f a).PathwiseCostEqOnSupport w) :
                            theorem AddWriterT.pathwiseCostEqOnSupport_bind_zero_right {m : TypeType u_1} [Monad m] {α β : Type} [HasEvalSet m] {ω : Type} [AddCommMonoid ω] [PartialOrder ω] [LawfulMonad m] [IsOrderedAddMonoid ω] {oa : AddWriterT ω m α} {f : αAddWriterT ω m β} {w : ω} (h₁ : oa.PathwiseCostEqOnSupport w) (h₂ : ∀ (a : α), (f a).PathwiseCostEqOnSupport 0) :
                            theorem AddWriterT.pathwiseCostAtMost_fin_mOfFn {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] {ω : Type} [AddCommMonoid ω] [PartialOrder ω] [LawfulMonad m] [IsOrderedAddMonoid ω] {n : } {k : ω} {f : Fin nAddWriterT ω m α} (h : ∀ (i : Fin n), (f i).PathwiseCostAtMost k) :
                            theorem AddWriterT.pathwiseCostAtLeast_fin_mOfFn {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] {ω : Type} [AddCommMonoid ω] [PartialOrder ω] [LawfulMonad m] [IsOrderedAddMonoid ω] {n : } {k : ω} {f : Fin nAddWriterT ω m α} (h : ∀ (i : Fin n), (f i).PathwiseCostAtLeast k) :
                            theorem AddWriterT.pathwiseHasCost_fin_mOfFn {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] {ω : Type} [AddCommMonoid ω] [PartialOrder ω] [LawfulMonad m] [IsOrderedAddMonoid ω] {n : } {k : ω} {f : Fin nAddWriterT ω m α} (h : ∀ (i : Fin n), (f i).PathwiseHasCost k) :
                            def AddWriterT.QueryBoundedAboveBy {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] (oa : AddWriterT m α) (n : ) :

                            Pathwise upper bound for a unit-cost AddWriterT computation.

                            Instances For
                              def AddWriterT.QueryBoundedBelowBy {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] (oa : AddWriterT m α) (n : ) :

                              Pathwise lower bound for a unit-cost AddWriterT computation.

                              Instances For
                                theorem AddWriterT.queryBoundedAboveBy_mono {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] {oa : AddWriterT m α} {n₁ n₂ : } (h : oa.QueryBoundedAboveBy n₁) (hn : n₁ n₂) :
                                theorem AddWriterT.queryBoundedBelowBy_mono {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] {oa : AddWriterT m α} {n₁ n₂ : } (h : oa.QueryBoundedBelowBy n₂) (hn : n₁ n₂) :
                                theorem AddWriterT.queryBoundedAboveBy_map {m : TypeType u_1} [Monad m] {α β : Type} [HasEvalSet m] [LawfulMonad m] {oa : AddWriterT m α} {n : } (f : αβ) (h : oa.QueryBoundedAboveBy n) :
                                theorem AddWriterT.queryBoundedBelowBy_map {m : TypeType u_1} [Monad m] {α β : Type} [HasEvalSet m] [LawfulMonad m] {oa : AddWriterT m α} {n : } (f : αβ) (h : oa.QueryBoundedBelowBy n) :
                                theorem AddWriterT.queryBoundedAboveBy_bind {m : TypeType u_1} [Monad m] {α β : Type} [HasEvalSet m] [LawfulMonad m] {oa : AddWriterT m α} {f : αAddWriterT m β} {n₁ n₂ : } (h₁ : oa.QueryBoundedAboveBy n₁) (h₂ : ∀ (a : α), (f a).QueryBoundedAboveBy n₂) :
                                (oa >>= f).QueryBoundedAboveBy (n₁ + n₂)
                                theorem AddWriterT.queryBoundedBelowBy_bind {m : TypeType u_1} [Monad m] {α β : Type} [HasEvalSet m] [LawfulMonad m] {oa : AddWriterT m α} {f : αAddWriterT m β} {n₁ n₂ : } (h₁ : oa.QueryBoundedBelowBy n₁) (h₂ : ∀ (a : α), (f a).QueryBoundedBelowBy n₂) :
                                (oa >>= f).QueryBoundedBelowBy (n₁ + n₂)
                                theorem AddWriterT.queryBoundedAboveBy_fin_mOfFn {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] [LawfulMonad m] {n k : } {f : Fin nAddWriterT m α} (h : ∀ (i : Fin n), (f i).QueryBoundedAboveBy k) :
                                theorem AddWriterT.queryBoundedBelowBy_fin_mOfFn {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] [LawfulMonad m] {n k : } {f : Fin nAddWriterT m α} (h : ∀ (i : Fin n), (f i).QueryBoundedBelowBy k) :
                                def AddWriterT.QueryCostExactly {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] (oa : AddWriterT m α) (n : ) :

                                Pathwise exact cost for a unit-cost AddWriterT computation: every reachable execution carries exactly n unit queries.

                                Instances For
                                  theorem AddWriterT.QueryCostExactly.toAbove {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] {oa : AddWriterT m α} {n : } (h : oa.QueryCostExactly n) :
                                  theorem AddWriterT.QueryCostExactly.toBelow {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] {oa : AddWriterT m α} {n : } (h : oa.QueryCostExactly n) :
                                  theorem AddWriterT.queryCostExactly_pure {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] [LawfulMonad m] (x : α) :
                                  theorem AddWriterT.queryCostExactly_map {m : TypeType u_1} [Monad m] {α β : Type} [HasEvalSet m] [LawfulMonad m] {oa : AddWriterT m α} {n : } (f : αβ) (h : oa.QueryCostExactly n) :
                                  theorem AddWriterT.queryCostExactly_bind {m : TypeType u_1} [Monad m] {α β : Type} [HasEvalSet m] [LawfulMonad m] {oa : AddWriterT m α} {f : αAddWriterT m β} {n₁ n₂ : } (h₁ : oa.QueryCostExactly n₁) (h₂ : ∀ (a : α), (f a).QueryCostExactly n₂) :
                                  (oa >>= f).QueryCostExactly (n₁ + n₂)
                                  theorem AddWriterT.queryCostExactly_fin_mOfFn {m : TypeType u_1} [Monad m] {α : Type} [HasEvalSet m] [LawfulMonad m] {n k : } {f : Fin nAddWriterT m α} (h : ∀ (i : Fin n), (f i).QueryCostExactly k) :
                                  def HasQuery.inRuntime {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} {α : Type} (oa : [HasQuery spec m] → m α) (runtime : QueryRuntime spec m) :
                                  m α

                                  Instantiate a generic HasQuery computation in the concrete runtime runtime.

                                  Instances For
                                    def HasQuery.withAddCost {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} {α : Type} [Monad m] {ω : Type} [AddMonoid ω] (oa : [HasQuery spec (AddWriterT ω m)] → AddWriterT ω m α) (runtime : QueryRuntime spec m) (costFn : spec.Domainω) :
                                    AddWriterT ω m α

                                    Instantiate a generic HasQuery computation in the additive-cost instrumented runtime obtained from runtime.

                                    Instances For
                                      def HasQuery.withUnitCost {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} {α : Type} [Monad m] (oa : [HasQuery spec (AddWriterT m)] → AddWriterT m α) (runtime : QueryRuntime spec m) :

                                      Instantiate a generic HasQuery computation in the unit-cost instrumented runtime obtained from runtime.

                                      Instances For
                                        theorem HasQuery.hasCost_withAddCost_query {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} [Monad m] [LawfulMonad m] {ω : Type} [AddMonoid ω] (runtime : QueryRuntime spec m) (costFn : spec.Domainω) (t : spec.Domain) :
                                        (withAddCost (fun [HasQuery spec (AddWriterT ω m)] => query t) runtime costFn).HasCost (costFn t)
                                        theorem HasQuery.queryBoundedAboveBy_withUnitCost_query {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} [Monad m] [LawfulMonad m] [HasEvalSet m] (runtime : QueryRuntime spec m) (t : spec.Domain) :
                                        (withUnitCost (fun [HasQuery spec (AddWriterT m)] => query t) runtime).QueryBoundedAboveBy 1
                                        theorem HasQuery.queryBoundedBelowBy_withUnitCost_query {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} [Monad m] [LawfulMonad m] [HasEvalSet m] (runtime : QueryRuntime spec m) (t : spec.Domain) :
                                        (withUnitCost (fun [HasQuery spec (AddWriterT m)] => query t) runtime).QueryBoundedBelowBy 1
                                        theorem HasQuery.queryCostExactly_withUnitCost_query {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} [Monad m] [LawfulMonad m] [HasEvalSet m] (runtime : QueryRuntime spec m) (t : spec.Domain) :
                                        (withUnitCost (fun [HasQuery spec (AddWriterT m)] => query t) runtime).QueryCostExactly 1
                                        @[reducible, inline]
                                        abbrev HasQuery.Computation {ι : Type} (spec : OracleSpec ι) (m : TypeType u_2) (α : Type) :
                                        Type u_2

                                        A computation generic over a HasQuery spec m capability.

                                        Instances For
                                          def HasQuery.UsesCostAs {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} {α : Type} [Monad m] {ω : Type} [AddMonoid ω] (oa : Computation spec (AddWriterT ω m) α) (runtime : QueryRuntime spec m) (costFn : spec.Domainω) (f : αω) :

                                          Running oa in the additive-cost instrumentation of runtime yields an output-dependent cost described by f.

                                          Instances For
                                            def HasQuery.UsesCostExactly {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} {α : Type} [Monad m] {ω : Type} [AddMonoid ω] (oa : Computation spec (AddWriterT ω m) α) (runtime : QueryRuntime spec m) (costFn : spec.Domainω) (w : ω) :

                                            Running oa in the additive-cost instrumentation of runtime incurs constant cost w.

                                            Instances For
                                              def HasQuery.UsesCostAtMost {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} {α : Type} [Monad m] {ω : Type} [AddMonoid ω] [Preorder ω] [HasEvalSet m] (oa : Computation spec (AddWriterT ω m) α) (runtime : QueryRuntime spec m) (costFn : spec.Domainω) (w : ω) :

                                              Running oa in the additive-cost instrumentation of runtime incurs cost at most w on every execution path. This is a semantic support bound, not merely an output-indexed cost description.

                                              Instances For
                                                def HasQuery.UsesCostAtLeast {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} {α : Type} [Monad m] {ω : Type} [AddMonoid ω] [Preorder ω] [HasEvalSet m] (oa : Computation spec (AddWriterT ω m) α) (runtime : QueryRuntime spec m) (costFn : spec.Domainω) (w : ω) :

                                                Running oa in the additive-cost instrumentation of runtime incurs cost at least w on every execution path.

                                                Instances For
                                                  theorem HasQuery.usesCostAtMost_of_usesCostExactly {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} {α : Type} [Monad m] {ω : Type} [AddMonoid ω] [Preorder ω] [LawfulMonad m] [HasEvalSet m] {oa : Computation spec (AddWriterT ω m) α} {runtime : QueryRuntime spec m} {costFn : spec.Domainω} {w b : ω} (h : UsesCostExactly (fun [HasQuery spec (AddWriterT ω m)] => oa) runtime costFn w) (hwb : w b) :
                                                  UsesCostAtMost (fun [HasQuery spec (AddWriterT ω m)] => oa) runtime costFn b
                                                  theorem HasQuery.usesCostAtLeast_of_usesCostExactly {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} {α : Type} [Monad m] {ω : Type} [AddMonoid ω] [Preorder ω] [LawfulMonad m] [HasEvalSet m] {oa : Computation spec (AddWriterT ω m) α} {runtime : QueryRuntime spec m} {costFn : spec.Domainω} {w b : ω} (h : UsesCostExactly (fun [HasQuery spec (AddWriterT ω m)] => oa) runtime costFn w) (hbw : b w) :
                                                  UsesCostAtLeast (fun [HasQuery spec (AddWriterT ω m)] => oa) runtime costFn b
                                                  theorem HasQuery.usesCostAtMost_query_of_le {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} [Monad m] {ω : Type} [AddMonoid ω] [Preorder ω] [LawfulMonad m] [HasEvalSet m] (runtime : QueryRuntime spec m) (costFn : spec.Domainω) (t : spec.Domain) {b : ω} (ht : costFn t b) :
                                                  UsesCostAtMost (fun [HasQuery spec (AddWriterT ω m)] => query t) runtime costFn b
                                                  def HasQuery.UsesExactlyQueries {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} {α : Type} [Monad m] (oa : Computation spec (AddWriterT m) α) (runtime : QueryRuntime spec m) (n : ) :

                                                  Unit-cost specialization: every query contributes cost 1.

                                                  Instances For
                                                    def HasQuery.UsesAtMostQueries {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} {α : Type} [Monad m] [HasEvalSet m] (oa : Computation spec (AddWriterT m) α) (runtime : QueryRuntime spec m) (n : ) :

                                                    Unit-cost specialization: every query contributes cost 1, with an upper bound.

                                                    Instances For
                                                      def HasQuery.UsesAtLeastQueries {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} {α : Type} [Monad m] [HasEvalSet m] (oa : Computation spec (AddWriterT m) α) (runtime : QueryRuntime spec m) (n : ) :

                                                      Unit-cost specialization: every query contributes cost 1, with a lower bound.

                                                      Instances For
                                                        theorem HasQuery.usesAtMostQueries_of_usesExactlyQueries {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} {α : Type} [Monad m] [LawfulMonad m] [HasEvalSet m] {oa : Computation spec (AddWriterT m) α} {runtime : QueryRuntime spec m} {n b : } (h : UsesExactlyQueries (fun [HasQuery spec (AddWriterT m)] => oa) runtime n) (hnb : n b) :
                                                        UsesAtMostQueries (fun [HasQuery spec (AddWriterT m)] => oa) runtime b
                                                        theorem HasQuery.usesAtLeastQueries_of_usesExactlyQueries {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} {α : Type} [Monad m] [LawfulMonad m] [HasEvalSet m] {oa : Computation spec (AddWriterT m) α} {runtime : QueryRuntime spec m} {n b : } (h : UsesExactlyQueries (fun [HasQuery spec (AddWriterT m)] => oa) runtime n) (hbn : b n) :
                                                        UsesAtLeastQueries (fun [HasQuery spec (AddWriterT m)] => oa) runtime b
                                                        noncomputable def HasQuery.expectedQueryCost {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} {α : Type} [Monad m] [HasEvalSPMF m] {ω : Type} [AddMonoid ω] (oa : Computation spec (AddWriterT ω m) α) (runtime : QueryRuntime spec m) (costFn : spec.Domainω) (val : ωENNReal) :

                                                        The expected weighted query cost of oa, instantiated in runtime and instrumented by costFn.

                                                        This is the primary expectation notion for generic HasQuery computations. It is computed from the additive cost marginal in the base monad's subdistribution semantics, valued by val.

                                                        The unit-cost query-counting notion [HasQuery.expectedQueries] is a specialization of this definition with costFn := fun _ ↦ 1 and val := fun n ↦ (n : ENNReal).

                                                        Instances For
                                                          def HasQuery.queryCostDist {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} {α : Type} [Monad m] {ω : Type} [AddMonoid ω] (oa : Computation spec (AddWriterT ω m) α) (runtime : QueryRuntime spec m) (costFn : spec.Domainω) :
                                                          m ω

                                                          The marginal distribution of weighted query costs induced by running oa in runtime with query-cost function costFn.

                                                          Instances For
                                                            @[reducible, inline]
                                                            abbrev HasQuery.queryCountDist {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} {α : Type} [Monad m] (oa : Computation spec (AddWriterT m) α) (runtime : QueryRuntime spec m) :
                                                            m

                                                            The marginal distribution of the unit-cost query count induced by running oa in runtime.

                                                            Instances For
                                                              @[reducible, inline]
                                                              noncomputable abbrev HasQuery.expectedQueries {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} {α : Type} [Monad m] [HasEvalSPMF m] (oa : Computation spec (AddWriterT m) α) (runtime : QueryRuntime spec m) :

                                                              Expected number of oracle queries made by oa when run in runtime, counting each query with unit additive cost.

                                                              Instances For
                                                                theorem HasQuery.expectedQueries_eq_tsum_tail_probs {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} {α : Type} [Monad m] [HasEvalSPMF m] (oa : Computation spec (AddWriterT m) α) (runtime : QueryRuntime spec m) :
                                                                expectedQueries (fun [HasQuery spec (AddWriterT m)] => oa) runtime = ∑' (i : ), probEvent (queryCountDist (fun [HasQuery spec (AddWriterT m)] => oa) runtime) fun (c : ) => i < c

                                                                Tail-sum formula for the expected number of oracle queries made by oa in runtime:

                                                                E[number of queries] = ∑ i, Pr[i < number of queries].

                                                                This is the generic HasQuery version of [AddWriterT.expectedCostNat_eq_tsum_tail_probs].

                                                                theorem HasQuery.expectedQueries_le_tsum_of_tail_probs_le {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} {α : Type} [Monad m] [HasEvalSPMF m] (oa : Computation spec (AddWriterT m) α) (runtime : QueryRuntime spec m) {a : ENNReal} (h : ∀ (i : ), (probEvent (queryCountDist (fun [HasQuery spec (AddWriterT m)] => oa) runtime) fun (c : ) => i < c) a i) :
                                                                expectedQueries (fun [HasQuery spec (AddWriterT m)] => oa) runtime ∑' (i : ), a i

                                                                Tail domination bounds expected query count.

                                                                If Pr[i < number of queries] ≤ a i for every i, then ExpectedQueries[ oa in runtime ] ≤ ∑ i, a i.

                                                                theorem HasQuery.expectedQueries_eq_sum_tail_probs_of_usesAtMostQueries {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} {α : Type} [Monad m] [HasEvalSPMF m] [LawfulMonad m] {oa : Computation spec (AddWriterT m) α} {runtime : QueryRuntime spec m} {n : } (h : UsesAtMostQueries (fun [HasQuery spec (AddWriterT m)] => oa) runtime n) :
                                                                expectedQueries (fun [HasQuery spec (AddWriterT m)] => oa) runtime = iFinset.range n, probEvent (queryCountDist (fun [HasQuery spec (AddWriterT m)] => oa) runtime) fun (c : ) => i < c

                                                                Finite tail-sum formula for expected query count under a pathwise upper bound.

                                                                If oa uses at most n oracle queries in every execution, then its expected query count is the finite sum of the probabilities that the query count exceeds i, for i < n.

                                                                theorem HasQuery.expectedQueryCost_le_of_usesCostAtMost {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} {α : Type} [Monad m] [HasEvalSPMF m] {ω : Type} [AddMonoid ω] [Preorder ω] [LawfulMonad m] {oa : Computation spec (AddWriterT ω m) α} {runtime : QueryRuntime spec m} {costFn : spec.Domainω} {w : ω} {val : ωENNReal} (h : UsesCostAtMost (fun [HasQuery spec (AddWriterT ω m)] => oa) runtime costFn w) (hval : Monotone val) :
                                                                expectedQueryCost (fun [HasQuery spec (AddWriterT ω m)] => oa) runtime costFn val val w
                                                                theorem HasQuery.expectedQueryCost_eq_tsum_outputs_of_usesCostAs {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} {α : Type} [Monad m] [HasEvalSPMF m] {ω : Type} [AddMonoid ω] [LawfulMonad m] {oa : Computation spec (AddWriterT ω m) α} {runtime : QueryRuntime spec m} {costFn : spec.Domainω} {f : αω} {val : ωENNReal} (h : UsesCostAs (fun [HasQuery spec (AddWriterT ω m)] => oa) runtime costFn f) :
                                                                expectedQueryCost (fun [HasQuery spec (AddWriterT ω m)] => oa) runtime costFn val = ∑' (a : α), Pr[= a | (withAddCost (fun [HasQuery spec (AddWriterT ω m)] => oa) runtime costFn).outputs] * val (f a)
                                                                theorem HasQuery.expectedQueries_le_of_usesAtMostQueries {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} {α : Type} [Monad m] [HasEvalSPMF m] [LawfulMonad m] {oa : Computation spec (AddWriterT m) α} {runtime : QueryRuntime spec m} {n : } (h : UsesAtMostQueries (fun [HasQuery spec (AddWriterT m)] => oa) runtime n) :
                                                                expectedQueries (fun [HasQuery spec (AddWriterT m)] => oa) runtime n
                                                                theorem HasQuery.expectedQueryCost_ge_of_usesCostAtLeast {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} {α : Type} [Monad m] [HasEvalPMF m] {ω : Type} [AddMonoid ω] [Preorder ω] [LawfulMonad m] {oa : Computation spec (AddWriterT ω m) α} {runtime : QueryRuntime spec m} {costFn : spec.Domainω} {w : ω} {val : ωENNReal} (h : UsesCostAtLeast (fun [HasQuery spec (AddWriterT ω m)] => oa) runtime costFn w) (hval : Monotone val) :
                                                                val w expectedQueryCost (fun [HasQuery spec (AddWriterT ω m)] => oa) runtime costFn val
                                                                theorem HasQuery.expectedQueryCost_eq_of_usesCostExactly {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} {α : Type} [Monad m] [HasEvalPMF m] {ω : Type} [AddMonoid ω] [Preorder ω] [LawfulMonad m] {oa : Computation spec (AddWriterT ω m) α} {runtime : QueryRuntime spec m} {costFn : spec.Domainω} {w : ω} {val : ωENNReal} (h : UsesCostExactly (fun [HasQuery spec (AddWriterT ω m)] => oa) runtime costFn w) (hval : Monotone val) :
                                                                expectedQueryCost (fun [HasQuery spec (AddWriterT ω m)] => oa) runtime costFn val = val w
                                                                theorem HasQuery.expectedQueries_ge_of_usesAtLeastQueries {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} {α : Type} [Monad m] [HasEvalPMF m] [LawfulMonad m] {oa : Computation spec (AddWriterT m) α} {runtime : QueryRuntime spec m} {n : } (h : UsesAtLeastQueries (fun [HasQuery spec (AddWriterT m)] => oa) runtime n) :
                                                                n expectedQueries (fun [HasQuery spec (AddWriterT m)] => oa) runtime
                                                                theorem HasQuery.expectedQueries_eq_of_usesAtMostQueries_of_usesAtLeastQueries {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} {α : Type} [Monad m] [HasEvalPMF m] [LawfulMonad m] {oa : Computation spec (AddWriterT m) α} {runtime : QueryRuntime spec m} {n : } (hUpper : UsesAtMostQueries (fun [HasQuery spec (AddWriterT m)] => oa) runtime n) (hLower : UsesAtLeastQueries (fun [HasQuery spec (AddWriterT m)] => oa) runtime n) :
                                                                expectedQueries (fun [HasQuery spec (AddWriterT m)] => oa) runtime = n
                                                                theorem HasQuery.expectedQueries_eq_of_usesExactlyQueries {ι : Type} {spec : OracleSpec ι} {m : TypeType u_1} {α : Type} [Monad m] [HasEvalPMF m] [LawfulMonad m] {oa : Computation spec (AddWriterT m) α} {runtime : QueryRuntime spec m} {n : } (h : UsesExactlyQueries (fun [HasQuery spec (AddWriterT m)] => oa) runtime n) :
                                                                expectedQueries (fun [HasQuery spec (AddWriterT m)] => oa) runtime = n

                                                                Queries[ oa in runtime ] = n means that the generic HasQuery computation oa makes exactly n oracle queries when instantiated in runtime and instrumented with unit additive cost per query.

                                                                The computation oa is written in direct HasQuery style. The notation elaborates it against the unit-cost analysis monad induced by runtime, so statements can usually be written without explicit monad annotations such as m := AddWriterT ℕ m.

                                                                Instances For

                                                                  Queries[ oa in runtime ] ≤ n means that every execution path of oa makes at most n oracle queries when run in the unit-cost instrumentation of runtime.

                                                                  This packages the common cryptographic statement “the construction uses at most n queries” on top of [HasQuery.UsesAtMostQueries].

                                                                  Instances For

                                                                    Queries[ oa in runtime ] ≥ n means that every execution of oa in the unit-cost instrumentation of runtime incurs at least n query-cost units.

                                                                    This is less common than the exact and upper-bound forms, but it is useful for statements saying that a construction must query the oracle at least a certain number of times.

                                                                    Instances For

                                                                      QueryCost[ oa in runtime ] = n is the unit-cost specialization of weighted query cost: each oracle query contributes additive cost 1, so the total query cost is just the number of queries made by oa.

                                                                      Instances For

                                                                        QueryCost[ oa in runtime by costFn ] = w means that oa, instantiated in runtime and instrumented so that each query t contributes cost costFn t, has constant total query cost w.

                                                                        Use this when the cost model is not unit cost, for example when different query families or different query shapes carry different weights.

                                                                        Instances For

                                                                          QueryCost[ oa in runtime ] ≤ n is the unit-cost specialization of pathwise query-cost upper bounds. It says that every execution of oa makes at most n oracle queries.

                                                                          Instances For

                                                                            QueryCost[ oa in runtime by costFn ] ≤ w means that every execution path of oa has total query cost bounded above by w under the weighting function costFn.

                                                                            This is the weighted analogue of [Queries[ oa in runtime ] ≤ n].

                                                                            Instances For

                                                                              QueryCost[ oa in runtime ] ≥ n is the unit-cost specialization of pathwise query-cost lower bounds. It says that every execution of oa makes at least n oracle queries.

                                                                              Instances For

                                                                                QueryCost[ oa in runtime by costFn ] ≥ w means that every execution path of oa has total query cost bounded below by w under the weighting function costFn.

                                                                                This is the weighted analogue of [Queries[ oa in runtime ] ≥ n].

                                                                                Instances For

                                                                                  ExpectedQueryCost[ oa in runtime ] is the expected number of oracle queries made by oa when run in runtime, viewed as the unit-cost specialization of weighted expected query cost.

                                                                                  Instances For

                                                                                    ExpectedQueryCost[ oa in runtime by costFn via val ] is the expected weighted query cost of oa when instantiated in runtime.

                                                                                    Each query t contributes additive cost costFn t, and the total cost is then valued by val : ω → ENNReal before taking expectation. This is the primary expected-cost term for generic HasQuery constructions.

                                                                                    Instances For

                                                                                      ExpectedQueries[ oa in runtime ] is the expected number of oracle queries made by oa when run in runtime, with each query carrying unit additive cost.

                                                                                      The result is an ℝ≥0∞ expectation, so it can be compared directly against natural-number bounds such as ExpectedQueries[ oa in runtime ] ≤ n.

                                                                                      This is the unit-cost specialization of [ExpectedQueryCost[ oa in runtime by costFn via val ]], with costFn := fun _ ↦ 1 and val := fun n ↦ (n : ENNReal).

                                                                                      Instances For