Documentation

VCVio.OracleComp.QueryTracking.CachingOracle

Caching Queries Made by a Computation #

This file defines a modifier QueryImpl.withCaching that modifies a query implementation to cache results to return to the same query in the future.

We also define a plain caching oracle and random oracles as special cases of this.

def QueryImpl.withCaching {ι : Type u} [DecidableEq ι] {spec : OracleSpec ι} {m : Type u → Type v} [Monad m] (so : QueryImpl spec m) :

Modify a query implementation to cache previous call and return that output in the future.

Equations
    Instances For
      @[simp]
      theorem QueryImpl.withCaching_apply {ι : Type u} [DecidableEq ι] {spec : OracleSpec ι} {m : Type u → Type v} [Monad m] (so : QueryImpl spec m) (t : spec.Domain) :
      so.withCaching t = do let __do_liftget match __do_lift t with | some u => pure u | none => do let uliftM (so t) modifyGet fun (cache : spec.QueryCache) => (u, cache.cacheQuery t u)
      @[reducible, inline]
      def randomOracle {ι : Type} [DecidableEq ι] {spec : OracleSpec ι} [(t : spec.Domain) → SampleableType (spec.Range t)] :
      Equations
        Instances For
          @[reducible, inline]
          def cachingOracle {ι : Type u} [DecidableEq ι] {spec : OracleSpec ι} :

          Oracle for caching queries to the oracles in spec, querying fresh values if needed.

          Equations
            Instances For
              theorem cachingOracle.apply_eq {ι : Type u} [DecidableEq ι] {spec : OracleSpec ι} (t : spec.Domain) :
              cachingOracle t = do let __do_liftget match __do_lift t with | some u => pure u | none => do let uliftM (OracleQuery.query t) modifyGet fun (cache : spec.QueryCache) => (u, cache.cacheQuery t u)