prodigy.analysis.lowerbounds.ir¶
Translation of pGCL programs (the AST of prodigy.pgcl) into the small intermediate representation used by the
exact generating-function calculus of prodigy.analysis.lowerbounds.egcalc.
Statements:
("seq", [stmt, ...]) | ("skip",) | ("abort",) | ("observe", cond)
("choice", prob, stmt, stmt) | ("if", cond, stmt, stmt) | ("assign", var, expr)
Expressions:
("num", Fraction) | ("var", name) | ("add"|"sub"|"mul"|"div"|"mod", e, e)
("call", name, [e, ...]) | ("cmp", op, e, e) | ("and"|"or", e, e) | ("not", e)
("true",) | ("false",)
abort is interpreted as divergence, i.e. its forward semantics maps every measure to the zero measure
(the run never terminates), which is the semantics of diverge in the paper.
- exception UnsupportedProgram[source]¶
Bases:
ExceptionThe program (or loop) is outside the fragment supported by the exact template calculus.
- instr_to_ir(instr)[source]¶
Translate a pGCL instruction or a list of instructions.
- Parameters:
instr (
SkipInstr|AbortInstr|WhileInstr|IfInstr|AsgnInstr|ChoiceInstr|LoopInstr|TickInstr|ObserveInstr|QueryInstr|ProbabilityQueryInstr|ExpectationInstr|PlotInstr|PrintInstr|OptimizationQuery|Sequence[SkipInstr|AbortInstr|WhileInstr|IfInstr|AsgnInstr|ChoiceInstr|LoopInstr|TickInstr|ObserveInstr|QueryInstr|ProbabilityQueryInstr|ExpectationInstr|PlotInstr|PrintInstr|OptimizationQuery])- Return type:
- eval_number(e)[source]¶
Evaluate a closed arithmetic expression (e.g. a probability such as 1/3) to a fraction.
- split_program(program)[source]¶
Split a program into the loop-free prefix, the (single, top-level) loop, and the instructions after it.
- Parameters:
program (
Program)- Return type:
Tuple[List[SkipInstr|AbortInstr|WhileInstr|IfInstr|AsgnInstr|ChoiceInstr|LoopInstr|TickInstr|ObserveInstr|QueryInstr|ProbabilityQueryInstr|ExpectationInstr|PlotInstr|PrintInstr|OptimizationQuery],WhileInstr,List[SkipInstr|AbortInstr|WhileInstr|IfInstr|AsgnInstr|ChoiceInstr|LoopInstr|TickInstr|ObserveInstr|QueryInstr|ProbabilityQueryInstr|ExpectationInstr|PlotInstr|PrintInstr|OptimizationQuery]]