prodigy.analysis.lowerbounds.egcalc¶
Exact generating-function calculus over a fixed product denominator.
A (generalised) generating function is represented as P / D where D is a fixed product denominator:
D = (1 - r_1 X_1^{p_1}) * ... * (1 - r_k X_k^{p_k}) (r_i >= 0 rational, p_i >= 1; r_i = 0: no factor)
and P is a polynomial with rational coefficients, stored as a dict mapping exponent tuples to
fractions.Fraction. The coefficients of P / D are eventually geometric: along variable i they
satisfy c_{n + p_i e_i} = r_i c_n as soon as n_i exceeds the degree of P in X_i.
All loop-free pGCL statements of the supported fragment map numerators over D to numerators over the same
D: guards and observations comparing a single variable with a constant (or testing it modulo m with
m | p_i), increments and decrements (monus) by constants, constant assignments, sampling from unif,
bernoulli and binomial (and from geometric(q) if r_i = 1 - q and p_i = 1), probabilistic choice,
conditionals, observe (which removes the violating mass) and abort (divergence).
Coefficient-wise nonnegativity of P / D is decided exactly by finitely many coefficients (Lemma “finite
positivity check” of the paper): P / D >= 0 iff all coefficients in the box prod_i [0, deg_i P + p_i - 1] are
nonnegative.
- class Denominator(rates, periods)[source]¶
Bases:
objectThe fixed product denominator
prod_i (1 - r_i X_i^{p_i}).
- class GFCalculus(variables, den)[source]¶
Bases:
objectExact transformer semantics of loop-free statements on numerators over a fixed denominator.
- Parameters:
den (
Denominator)
- with_den(den)[source]¶
- Parameters:
den (
Denominator)- Return type:
- coeffs_along(poly, i, upto)[source]¶
The
X_i-coefficientsc_0..c_uptoofP / D, each as a numerator overDwithout theX_ifactor (exponentiset to 0).
- restrict_pred(poly, i, pred, threshold, modulus)[source]¶
Restriction of
P / Dto the states whosei-th component satisfiespred, wherepred(v)depends only onv mod modulusforv >= threshold; requiresmodulus | p_iifr_i != 0.
- eliminate(poly, i)[source]¶
F(X_i = 1)as a numerator overDwithout theX_ifactor (exponentiset to 0), or None if the series diverges atX_i = 1(only possible ifr_i >= 1).
- restrict(poly, guard)[source]¶
Restriction
<P/D>_guardof the measure to the states satisfyingguard.
- run(stmt, poly)[source]¶
Forward semantics of a loop-free statement on the measure
P / D(unnormalised;observeremoves the violating mass,abortdiverges).
- expand(poly, box)[source]¶
The coefficients of
P / Don the boxprod_i [0, box_i](object array of Fractions).
- mass(poly)[source]¶
Total mass
(P / D)(1, ..., 1)in[0, inf](exact);math.infif the series diverges.
- moment(poly, i)[source]¶
First moment
sum_n n_i * coeff_n(P / D)of variablei(exact),math.infif it diverges. RequiresP / D >= 0for the valueinfto be meaningful.