boundlab.polysp.legendre#

Polynomial (Legendre-projection) relaxations of scalar activations.

Instead of an affine enclosure, approximate \(f\) on \([c - a, c + a]\) by a degree-\(n\) polynomial and bound the residual. The polynomial is the truncated Legendre series

\[f(c + a u) \approx \sum_{i \le n} l_i\, a^i\, P_i(u), \qquad l_i = \frac{2i + 1}{2 a^i} \int_{-1}^{1} P_i(u)\, f(c + a u)\, du ,\]

the \(L^2\)-optimal degree-\(n\) approximation on the interval (Legendre polynomials are orthogonal on \([-1, 1]\)). The residual f - p is bounded soundly by spline3_ibp() and becomes interval noise; an optional Adam loop then perturbs the coefficients per element and keeps whichever iterate certified the smallest residual. The polynomial itself is applied through the domain’s poly handler — exactly, for a sparse polynomial input.

Functions

eval_legendre_form

Evaluate sum_i li[i] * hw**i * P_i((x - c) / hw), safe at hw == 0.

Classes

AdamConfig

Hyper-parameters for the optional per-element coefficient refinement (Adam with annealed gradient noise).

LegendreHandler

Base for activations relaxed by Legendre projection.

Poly2Mul

Evaluate a concrete-coefficient polynomial by Horner's rule, each step one mul and one add through the enclosing domain.

Poly2Square

Quadratic special case routed through the domain's square handler: a x^2 + b x + c with a single non-linear step.

Relu

Legendre relaxation of ReLU (orders 1–6, closed-form coefficients).

Tanh

Placeholder for a Legendre tanh relaxation (not yet implemented).