Equations
- sig.ParamType = GaudisCrypt.typeListToTuple sig.params
Instances For
A sequence of procedure signatures, describing the holes of a program.
A cons list, head first: .cons X (.cons Y .empty) is the context of a body that calls X
and then Y. Everything indexed by it agrees on that order — HoleIndex.zero is the head,
HoleSigs.Instantiation is the tuple with the head's procedure first, toList,
toModuleTypeRepTuple and toModuleExpr all put the head first, and the uses (…) display lists
it first. So "hole 0" means one thing throughout: the first hole the body declares.
- empty : HoleSigs
- cons : ProcedureSignature → HoleSigs → HoleSigs
Instances For
Equations
Instances For
Equations
Instances For
- zero {a : ProcedureSignature} {Γ : HoleSigs} : HoleIndex (HoleSigs.cons a Γ) a
- succ {Γ : HoleSigs} {a b : ProcedureSignature} : HoleIndex Γ a → HoleIndex (HoleSigs.cons b Γ) a
Instances For
Equations
- GaudisCrypt.instDecidableEqHoleIndex.decEq GaudisCrypt.HoleIndex.zero GaudisCrypt.HoleIndex.zero = isTrue ⋯
- GaudisCrypt.instDecidableEqHoleIndex.decEq GaudisCrypt.HoleIndex.zero a_3.succ = isFalse ⋯
- GaudisCrypt.instDecidableEqHoleIndex.decEq a_3.succ GaudisCrypt.HoleIndex.zero = isFalse ⋯
- GaudisCrypt.instDecidableEqHoleIndex.decEq a_5.succ b.succ = if h : a_5 = b then h ▸ have inst := GaudisCrypt.instDecidableEqHoleIndex.decEq a_5 a_5; isTrue ⋯ else isFalse ⋯
Instances For
Equations
Instances For
Instances For
Syntactic program (with arbitrary Lean terms as expressions). Every statement runs on a
ProgramState: the globals, and the locals of the running procedure (its parameters among
them).
- skip {h : HoleSigs} : StmtWithHoles h
- sample {h : HoleSigs} {a : Type} : Setter a ProgramState → Getter (SubProbability a) ProgramState → StmtWithHoles h
- call' {h : HoleSigs} {sig : ProcedureSignature} : Setter sig.ret ProgramState → (parameterNames : List String) → parameterNames.length = sig.params.length → parameterNames.Nodup → StmtWithHoles HoleSigs.empty → Getter sig.ret ProgramState → Getter sig.ParamType ProgramState → StmtWithHoles h
- hole {h : HoleSigs} {sig : ProcedureSignature} (n : HoleIndex h sig) : Setter sig.ret ProgramState → Getter sig.ParamType ProgramState → StmtWithHoles h
- seq {h : HoleSigs} : StmtWithHoles h → StmtWithHoles h → StmtWithHoles h
- ifThenElse {h : HoleSigs} : Getter Bool ProgramState → StmtWithHoles h → StmtWithHoles h → StmtWithHoles h
- while {h : HoleSigs} : Getter Bool ProgramState → StmtWithHoles h → StmtWithHoles h
Instances For
Instances For
A procedure: its body and return value run on a ProgramState, and on a call the arguments
are written into the local slots named parameterNames (with the types sig.params), see
ProcedureWithHoles.initLocals.
- parameterNames_nodup : self.parameterNames.Nodup
- body : StmtWithHoles holeSigs
- return_val : Getter sig.ret ProgramState
Instances For
Equations
Instances For
The signature of a procedure-with-holes as a term — sig is otherwise only reachable as
an implicit argument of the type, which makes it awkward to name in generated code.
Instances For
The locals a call of p with arguments args starts with: the arguments in the parameter
slots, everything else at VariableAssignment.init.
Equations
Instances For
Equations
- GaudisCrypt.StmtWithHoles.call x proc params = GaudisCrypt.StmtWithHoles.call' x proc.parameterNames ⋯ ⋯ proc.body proc.return_val params
Instances For
Equations
- GaudisCrypt.StmtWithHoles.assign x e = GaudisCrypt.StmtWithHoles.sample x { get := fun (st : GaudisCrypt.ProgramState) => pure (e.get st) }
Instances For
The setter that puts the local variables with a name in S (of every type) back to
VariableAssignment.init, the value every local has when a procedure starts, and leaves every
other one alone; the value written, (), is ignored. The values put back form a
VariableAssignment, which lives in Type 1, so they cannot themselves be the value of an
assign; assign (resetSetter S) ⟨fun _ => ()⟩ is the reset, reset_vars S; in the surface
syntax. Flattening (Logic/Inline.lean)
emits it for the frame of the callee it inlines.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- GaudisCrypt.Stmt.call x proc params = GaudisCrypt.StmtWithHoles.call x proc params
Instances For
The procedures filling the holes holes, as a tuple: right-nested, with HoleIndex.zero
— the last-appended hole — as the first component, the same order as
HoleSigs.Instantiation.toList and HoleSigs.Instantiation.toModuleExpr. No holes at all is
PUnit, so what one writes is
p.instantiate (c₁, c₂, c₃) -- three holes, in the order the body declares them
p.instantiate c -- one hole: the tuple is its element
and nothing else is needed to build one: Prod.mk is the only constructor involved. Reading a
hole out is HoleSigs.Instantiation.lookup.
A one-hole instantiation is the procedure itself rather than a pair with PUnit, which is what
keeps the written form free of a trailing ⟨⟩. The cost is that knowing Instantiation (cons sig holes) is a pair takes two constructors, not one — so every function that recurses on holes
and takes an instantiation apart splits on both levels, cons _ .empty beside cons _ (.cons ..).
Do that split in the function itself; routing it through head/tail helpers instead makes them
stuck at a variable holes, and then nothing about them is rfl any more.
It is a tuple rather than the function ∀ {sig}, HoleIndex holes sig → Procedure sig it used to
be so that instantiations can be written and read as ordinary Lean tuples — the function form
made every instantiation an implicit-lambda chain, in the source and in every goal that mentioned
one. The price is that holes has to be concrete for the type to reduce: an instantiation at a
symbolic holes can still be taken as a hypothesis and looked up (lookup recurses on the index,
which refines holes), but not built or taken apart without recursing on holes in step.
The universe is written out only because PUnit would otherwise take one of its own: nothing in the
.empty branch constrains its level, so Type _ gives the definition a universe parameter that no
argument determines, and a use site inside an inductive (ModuleExpression.ReductionStep) then has
nothing to infer it from.
Equations
Instances For
The procedure filling hole idx. Recursion is on the index, which refines holes as it goes
— which is what lets this work at a holes that is still a variable.
Equations
- inst.lookup GaudisCrypt.HoleIndex.zero = inst
- inst.lookup GaudisCrypt.HoleIndex.zero = inst.1
- inst.lookup j.succ = inst.2.lookup j
Instances For
The only hole of a one-hole instantiation is the instantiation itself.
The first hole of a tuple of two or more: its first component.
Any later hole: the rest of the tuple.
Convert an instantiation into a plain list of procedures (tagged by their signature),
in the same right-nested order as the tuple itself and as HoleSigs.Instantiation.toModuleExpr.
The head of the list corresponds to the most-recently appended hole signature.
Instances For
Instantiate all holes in a statement using resolve, turning each .hole into a
.call' of the resolved procedure. Hole-free constructors are simply re-typed.
Equations
- GaudisCrypt.StmtWithHoles.skip.instantiate instantiation = GaudisCrypt.StmtWithHoles.skip
- (GaudisCrypt.StmtWithHoles.sample x e).instantiate instantiation = GaudisCrypt.StmtWithHoles.sample x e
- (GaudisCrypt.StmtWithHoles.call' x ns hl hn b r p).instantiate instantiation = GaudisCrypt.StmtWithHoles.call' x ns hl hn b r p
- (GaudisCrypt.StmtWithHoles.hole n x p).instantiate instantiation = GaudisCrypt.StmtWithHoles.call x (instantiation.lookup n) p
- (s1.seq s2).instantiate instantiation = GaudisCrypt.StmtWithHoles.seq (s1.instantiate instantiation) (s2.instantiate instantiation)
- (GaudisCrypt.StmtWithHoles.ifThenElse c t e).instantiate instantiation = GaudisCrypt.StmtWithHoles.ifThenElse c (t.instantiate instantiation) (e.instantiate instantiation)
- (GaudisCrypt.StmtWithHoles.while c t).instantiate instantiation = GaudisCrypt.StmtWithHoles.while c (t.instantiate instantiation)
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
A structural size measure used to justify termination of programDenotation.
The auto-generated sizeOf for StmtWithHoles is trivially 0 (the inductive
lives in a higher universe because its constructors quantify over a : Type), so
we define our own.
Equations
- GaudisCrypt.StmtWithHoles.skip.depth = 0
- (GaudisCrypt.StmtWithHoles.sample a_1 a_2).depth = 0
- (GaudisCrypt.StmtWithHoles.hole n a a_1).depth = 0
- (GaudisCrypt.StmtWithHoles.call' a parameterNames a_1 a_2 body a_3 a_4).depth = body.depth + 1
- (p.seq q).depth = max p.depth q.depth + 1
- (GaudisCrypt.StmtWithHoles.ifThenElse a p q).depth = max p.depth q.depth + 1
- (GaudisCrypt.StmtWithHoles.while a p).depth = p.depth + 1
Instances For
A hole-free statement has nothing to instantiate: every constructor is re-typed as itself, and
the .hole case cannot occur (HoleIndex .empty _ is empty). Recursion is on depth — the
statement's own index HoleSigs.empty is not a variable, so the equation compiler cannot recurse
on it structurally.
Instantiating a procedure that has no holes leaves it alone.
Equations
- One or more equations did not get rendered due to their size.
- GaudisCrypt.programDenotation GaudisCrypt.StmtWithHoles.skip = GaudisCrypt.ProgramDenotation.skip
- GaudisCrypt.programDenotation (GaudisCrypt.StmtWithHoles.sample x_1 e) = do let μ ← GaudisCrypt.ProgramDenotation.get e let v ← μ.toProgramDenotation GaudisCrypt.ProgramDenotation.set x_1 v
- GaudisCrypt.programDenotation (p.seq q) = do let __discr ← GaudisCrypt.programDenotation p have x : Unit := __discr GaudisCrypt.programDenotation q
- GaudisCrypt.programDenotation (GaudisCrypt.StmtWithHoles.while c p) = GaudisCrypt.while_loop (GaudisCrypt.ProgramDenotation.get c) (GaudisCrypt.programDenotation p)
Instances For
Run proc on fresh locals (ProcedureWithHoles.initLocals); the callee's locals are
discarded at the end, only the globals are kept. The state and the result live in different
universes, hence hbind in place of do.
Not mutual with programDenotation, whose call' case repeats this body.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The call' case of programDenotation, with the callee run folded into
procedureDenotation.
The procedure denotation as an explicit wrapper: initialise locals, run the
body, extract (return_val, globals).
Equations
Instances For
procedureDenotation of an instantiated procedure is procWrap of its body
(generic over the holes and their instantiation).