Representing functor modules by procedures with holes #
The abstract call rule needs an adversary D as code: a procedure with holes p that D,
applied to oracles O, behaves like when filled with ext O (Module.RepresentedBy,
Logic/AbstractCall.lean). Exception E2 of the SHA-3 port takes this as a hypothesis. Every
module is code, though: a closed normal module expression. This file works towards extracting the
representation from that normal form, for functors over first-order oracle types (products of
procedures), with the full list of the oracle's procedures as ext.
- Substituting procedures with holes for holes (
StmtWithHoles.substHoles,ProcedureWithHoles.substHoles): each hole call becomes the flattened call of the substituted procedure, everything else is re-targeted alongFlatten.trafo. Sound (ProcedureWithHoles.procedureDenotation_substHoles), from the inliner's term-level lemmas (StmtWithHoles.equivInLens_flattenCall,StmtWithHoles.applyLens, theEquivInLenscongruences). This is the extraction step for a procedure with holes applied to a tuple. - First-order normal forms (
ModuleExpression.FONormal,foNormal_of_hasType,Module.expression_shape): over first-order parameters a normal term of first-order type is a procedure, a tuple, a component of a parameter, or a procedure with holes applied to such a tuple. These are the cases the extraction recurses on. - The footprint of a substitution (
FVP.fvP_proc_substHoles_le): no more than the procedure's own and the substituted procedures'.fvPsees a procedure's globals only (Lens.reduceFootprint ProgramState.globalL), and the renamings of the locals are invisible there: a kernel on the globals commutes withzoom l ponce it commutes withp, forlkeeping the globals (Footprint.GlobalsCommute.zoom, byLens.reduceFootprint_alt_def). The callee frame's reset and parameter writes are on the locals alone (footprint_zoom_localL_le). - The pieces of the extraction: instantiations from families (
HoleSigs.Instantiation.ofFun), congruence of instantiation in the denotations (ProcedureWithHoles.procedureDenotation_instantiate_congr), components of a literal oracle (ModuleExpression.FOProj.reduce_substitute), the wrapper of a hole (ProcedureWithHoles.ofHole, which needs nonempty parameter and result types: they live in local slots) and closed procedures in a hole context (ProcedureWithHoles.ofProc). - The extraction (
FONormal.extract, by induction over first-order normal forms) and its module form,Module.exists_representation: every first-order functor module is represented by a procedure with holes over the full list of the oracle's procedures, with at most the footprint of its own normal form. - Module types (
Module.exists_representation_of_firstOrder,Module.representable_of_firstOrder): amoduletypeis a tree of products without the trailingunit. Its procedures in order areT.holesApp .empty, a literal module's areT.extOf O;ModuleExpression.rebuildrebuilds the module from the tuple (ModuleTypeRep.rebuild_extOfApp), which reduces a functor overTto one over the tuple, at no cost in footprint. SoModule.Representable D extholds for every functor moduleDover a first-order module type whoseextis the full list of its procedures: exception E2 is a theorem there.
Write the arguments into the parameter slots names of a fresh callee frame emb (all its
other locals init).
Equations
- One or more equations did not get rendered due to their size.
Instances For
The call of a procedure with holes q, flattened into the caller: reset the callee frame,
write the arguments, run q's body in the frame emb, store the return value.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Flattening the call of a procedure with holes: calling q filled with inst is
equivalent, along trafo, to q's flattened call filled with inst. This is
StmtWithHoles.equivInLens_flattenCall at the instantiated body, with applyLens commuted past
the instantiation.
Substituting procedures with holes for the holes of a statement: each hole n becomes
the flattened call of q n; everything else is re-targeted along trafo, which makes room for
the callee frames.
Equations
- One or more equations did not get rendered due to their size.
- GaudisCrypt.StmtWithHoles.substHoles q (GaudiProg[ skip; ]) = GaudiProg[ skip; ]
- GaudisCrypt.StmtWithHoles.substHoles q (GaudiProg[ x_1 <$ §e; ]) = GaudiProg[ (GaudisCrypt.Flatten.trafo.chainSetter x_1) <$ §(GaudisCrypt.Flatten.trafo.chainGetter e); ]
- GaudisCrypt.StmtWithHoles.substHoles q (GaudiProg[ x_1 <- holecall n (§p); ]) = GaudisCrypt.StmtWithHoles.flattenedCall x_1 (q n) p
Instances For
The substitution is sound: filling the holes of s with the q n filled with inst' is
equivalent, along trafo, to filling the substituted statement with inst'.
A slot update on both sides of the renaming ι: slot n on the right, slot ι n on the
left.
setParams commutes with renaming the slots by ι.
trafo sees the parameters written into the escaped slots in the original ones.
procedureDenotation_congr with the parameters renamed: the renaming l sees the entry state
of names' as that of names.
A procedure with its holes substituted (StmtWithHoles.substHoles).
Equations
- One or more equations did not get rendered due to their size.
Instances For
The substitution is sound for procedures: p with its holes substituted by the q n,
filled with inst', computes what p filled with the q n filled with inst' computes.
First-order module types: products of procedures (and unit), no functors.
Equations
- (GaudisCrypt.ModuleTypeRep.proc a).FirstOrder = True
- GaudisCrypt.ModuleTypeRep.unit.FirstOrder = True
- (a.prod b).FirstOrder = (a.FirstOrder ∧ b.FirstOrder)
- (a.arr a_1).FirstOrder = False
Instances For
A chain of projections of a variable: a component of a module parameter.
- var (n : ℕ) : (ModuleExpression.var n).FOProj
- fst {e : ModuleExpression} : e.FOProj → e.fst.FOProj
- snd {e : ModuleExpression} : e.FOProj → e.snd.FOProj
Instances For
The normal forms of first-order type over first-order parameters: procedures, tuples, components of parameters, and procedures with holes applied to such (not literal) tuples.
- proc {sig : ProcedureSignature} (p : Procedure sig) : (ModuleExpression.proc p).FONormal
- unit : ModuleExpression.unit.FONormal
- pair {a b : ModuleExpression} : a.FONormal → b.FONormal → (a.pair b).FONormal
- proj {e : ModuleExpression} : e.FOProj → e.FONormal
- appProcHoles {holes : HoleSigs} {sig : ProcedureSignature} (ne : holes.NonEmpty) (p : ProcedureWithHoles holes sig) {arg : ModuleExpression} : arg.FONormal → ¬arg.IsProcTuple → ((procHoles ne p).app arg).FONormal
Instances For
Inversion of first-order normal forms: over first-order parameters, a normal term of
first-order type is an FONormal; a neutral term has first-order type, and is a component of a
parameter unless it has procedure type.
The shape of a first-order functor module: a closed normal module of type
T →ₘ procmod …, T first-order, is a procedure with holes, or an abstraction whose body is a
first-order normal form over the parameter.
The footprint of a substitution #
A kernel f on the globals, lifted to program states, commutes with every update of R:
the condition Lens.reduceFootprint_alt_def characterizes R's share of the globals by.
Equations
Instances For
Comparing the globals' shares of two footprints by the kernels commuting with them.
Commuting with a join: with each joinand (the updates of a join are the bicommutant of the union).
A zoomed program commutes with what the original commutes with, along a lens of program
states that keeps the globals: a kernel on the globals commutes with every generator of
zoom l p once it commutes with those of p, at the zoomed state.
The globals' share of a read through l.chainGetter.
The globals' share of a write through l.chainSetter.
fvP's statement-level footprint, spelled out.
Re-targeting a statement along l does not add to its globals' share.
A program on the locals alone, zoomed into the program state, is outside the globals.
A write that changes only the locals, as a function of the locals, is outside the globals.
A read of a constant is nothing.
An assignment reads its expression as a point mass: no more than reading the expression.
The globals' share of a substituted statement: the statement's own, plus a bound Q on the
substituted procedures'.
The footprint of a substituted procedure: the procedure's own, plus a bound on the substituted procedures'.
The pieces of the extraction #
An instantiation from a family of procedures, one per hole.
Equations
- One or more equations did not get rendered due to their size.
- GaudisCrypt.HoleSigs.Instantiation.ofFun x_2 = PUnit.unit
- GaudisCrypt.HoleSigs.Instantiation.ofFun f = f GaudisCrypt.HoleIndex.zero
Instances For
Filling the holes with procedures of the same denotations gives the same denotation.
Components of the oracle, on a literal oracle: a projection chain of the parameter of
type H's tuple, the parameter replaced by a tuple of procedures, reduces to one of them (at
procedure type) or to the tuple of a selection of them (at tuple type).
The name of the wrapper's parameter i: x…x (i+1 times).
Equations
- GaudisCrypt.Wrapper.wName i = String.ofList (List.replicate (i + 1) 'x')
Instances For
The wrapper's parameter names, for the parameter types tys, from index i on.
Equations
- GaudisCrypt.Wrapper.wNames [] x✝ = []
- GaudisCrypt.Wrapper.wNames (head :: Ts) x✝ = GaudisCrypt.Wrapper.wName x✝ :: GaudisCrypt.Wrapper.wNames Ts (x✝ + 1)
Instances For
Read the parameters back from their slots.
Equations
Instances For
The wrapper of a hole: the procedure that calls hole n with its arguments and returns
what it returns. Its parameters and result live in local slots, so their types must be
nonempty.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The wrapper of hole n, filled, computes what the procedure in hole n computes.
A read of the locals alone is outside the globals.
The wrapper of a hole touches no globals.
A procedure without holes, in a context of holes it does not use.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The extraction #
A family over the holes of cons s h: a at the first, f at the others.
Equations
Instances For
The δ-step on an argument that reduces to a literal tuple.
The extraction: over the oracle parameter of type H's tuple, a first-order normal form of
procedure type is represented by a procedure with holes, and one of tuple type by a family of
them: the substituted term, for a literal oracle, reduces to procedures computing the same, and
the representation's footprint is at most the term's.
The procedure of a proc-typed module whose expression is a given .proc.
Every first-order functor module is represented by a procedure with holes, over the full list of the oracle's procedures, with the footprint of its own normal form.
Module types #
The procedures of a first-order module type, in order, in front of R.
Equations
- (GaudisCrypt.ModuleTypeRep.proc s).holesApp x✝ = GaudisCrypt.HoleSigs.cons s x✝
- GaudisCrypt.ModuleTypeRep.unit.holesApp x✝ = x✝
- (a.prod b).holesApp x✝ = a.holesApp (b.holesApp x✝)
- (a.arr a_1).holesApp x✝ = x✝
Instances For
One procedure in front of an instantiation.
Equations
- GaudisCrypt.HoleSigs.Instantiation.consInst x✝ x_3 = x✝
- GaudisCrypt.HoleSigs.Instantiation.consInst x✝ rest = (x✝, rest)
Instances For
The procedures of a literal module O of first-order type T, in front of rest.
Equations
- (GaudisCrypt.ModuleTypeRep.proc a).extOfApp O x✝ = GaudisCrypt.HoleSigs.Instantiation.consInst (GaudisCrypt.Module.Proc.procedure O) x✝
- GaudisCrypt.ModuleTypeRep.unit.extOfApp x_5 x✝ = x✝
- (a.prod b).extOfApp O x✝ = a.extOfApp O.fst' (b.extOfApp O.snd' x✝)
- (a.arr a_1).extOfApp x_5 x✝ = x✝
Instances For
Rebuild a value of type T from the front of a tuple x; the rest of the tuple second.
Equations
- One or more equations did not get rendered due to their size.
- GaudisCrypt.ModuleExpression.rebuild (GaudisCrypt.ModuleTypeRep.proc a) x✝ = (x✝.fst, x✝.snd)
- GaudisCrypt.ModuleExpression.rebuild GaudisCrypt.ModuleTypeRep.unit x✝ = (GaudisCrypt.ModuleExpression.unit, x✝)
- GaudisCrypt.ModuleExpression.rebuild (a.arr a_1) x✝ = (GaudisCrypt.ModuleExpression.unit, x✝)
Instances For
A literal module of a product type is the pair of its projections.
Rebuilding a literal module from the tuple of its procedures gives it back.
The procedures of a literal module O of first-order type T, in order.
Equations
- T.extOf O = T.extOfApp O PUnit.unit
Instances For
Every functor module over a first-order module type is represented by a procedure with
holes over the list of the type's procedures (T.holesApp .empty), filled with those of the
oracle (T.extOfApp), with at most the footprint of its own normal form. The module type may be
any tree of products (as moduletype builds them, without a trailing unit).
Removing exception E2 for full oracle lists: a functor module over a first-order module type
M is representable (Module.Representable) with the list of all of M's procedures as ext,
provided their parameter and result types are nonempty.