Computations with Oracle Access #
A value oa : OracleComp spec α
represents a computation with return type α
,
with access to any of the oracles specified by spec : OracleSpec
.
Returning a value x
corresponds to the computation pure' α x
.
The computation queryBind' i t α ou
represents querying the oracle corresponding to index i
on input t
, getting a result u : spec.range i
, and then running ou u
.
We also allow for a failure'
operation for quitting out.
These operations induce Monad
and Alternative
instances on OracleComp spec
.
pure' α a
gives a monadic pure
operation, while a more general >>=
operator
is derived by induction on the first computation (see OracleComp.bind
).
This importantly allows us to define a LawfulMonad
instance on OracleComp spec
,
which isn't possible if a general bind operator is included in the main syntax.
We also define simple operations like coin : OracleComp coinSpec Bool
for flipping a fair coin,
and $[0..n] : ProbComp (Fin (n + 1))
for selecting from an inclusive range.
Note that the monadic structure on OracleComp
exists only for a fixed OracleSpec
,
so it isn't possible to combine computations where one has a superset of oracles of the other.
We later introduce a set of type coercions that mitigate this for most common cases,
such as calling a computation with spec
as part of a computation with spec ++ spec'
.
An OracleQuery
to one of the oracles in spec
, bundling an index and the input to
use for querying that oracle, implemented as a dependent pair.
Implemented as a functor with the oracle output type as the constructor result.
- query {ι : Type u} {spec : OracleSpec ι} (i : ι) (t : spec.domain i) : spec.OracleQuery (spec.range i)
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
Instances For
Equations
OracleComp spec α
represents computations with oracle access to oracles in spec
,
where the final return value has type α
.
The basic computation is just an OracleQuery
, augmented with pure
and bind
by FreeMonad
,
and failure
is also added after by the OptionT
transformer.
In practive computations in OracleComp spec α
have have one of three forms:
return x
to succeed with somex : α
as the result.do u ← query i t; oa u
whereoa
is a continutation to run with the query resultfailure
which terminates the computation early SeeOracleComp.inductionOn
for an explicit induction principle.
Equations
Instances For
Equations
Equations
Lift a query by first lifting to the free moand and then to the option.
Equations
Instances For
Automatically coerce an OracleQuery spec α
to an OracleComp spec α
.
Equations
Lift a function on oracle queries to one on oracle computations.
Equations
Alias of OracleComp.liftM_def
.
coin
is the computation representing a coin flip, given a coin flipping oracle.
Equations
Instances For
Equations
Instances For
Nicer induction rule for OracleComp
that uses monad notation.
Allows inductive definitions on compuations by considering the three cases:
return x
/pure x
for anyx
do let u ← query i t; oa u
(with inductive results foroa u
)failure
SeeoracleComp_emptySpec_equiv
for an example of using this in a proof. If the final result needs to be aType
and not aProp
, seeOracleComp.construct
.
Equations
Instances For
Equations
Instances For
NOTE: if inductionOn
could work with Sort u
instead of Prop
we wouldn't need this,
not clear to me why lean doesn't like unifying the Prop
and Type
cases.
If the output type of C
is a monad then OracleComp.mapM
is usually preferable.
Equations
Instances For
Version of construct
with automatic induction on the query
in when defining the
query_bind
case. Can be useful with spec.DecidableEq
and spec.FiniteRange
.
NOTE: may be better to just use this universally in all cases? avoids duplicating lemmas below.
Equations
Instances For
Alias of OracleComp.construct_query
.
Returns true
for computations that don't query any oracles or fail, else false
.
Equations
Instances For
Returns true
for computations that fail else false
.
Equations
Instances For
Implement all queries in a computation using some other monad m
,
preserving the pure and bind operations, giving a computation in the new monad.
The function qm
specifies how to replace the queries in the computation,
and fail
is used whenever failure
is encountered.
If the final output type has an Alternative
instance then simulate
is usually preffered.
Equations
Instances For
Given a computation oa : OracleComp spec α
, construct a value x : α
,
by assuming each query returns the default
value given by the Inhabited
instance.
Returns none
if the default path would lead to failure.
Equations
Instances For
Total number of queries in a computation across all possible execution paths.
Can be a helpful alternative to sizeOf
when proving recursive calls terminate.
Equations
Instances For
Alias of the reverse direction of OracleComp.bind_eq_pure_iff
.
Alias of the reverse direction of OracleComp.pure_eq_bind_iff
.
If the oracle indexing-type ι
, output type α
, and domains of all oracles have DecidableEq
then OracleComp spec α
also has DecidableEq
.