Nodal-polynomial criterion for quadrature exactness (source code)

= Nodal-polynomial criterion for quadrature exactness

Let an $(n+1)$-node <quadrature rule> already be exact on all <polynomials> of <polynomial degree> at most $n$, for integration against a specified measure $\mu$. Its nodal <polynomial> is
$$
Q_{n+1}(x)=\prod_{i=0}^n(x-x_i).
$$
For an integer $k\geq0$, the rule is exact through <polynomial degree> $n+1+k$ if and only if
$$
\int Q_{n+1}(x)r(x)\,d\mu(x)=0
$$
for every <polynomial> $r$ of <polynomial degree> at most $k$, assuming the needed <moments> exist. Indeed, <polynomial division> expresses every candidate $p$ as $p=Q_{n+1}r+s$, with $\deg s\leq n$. The <quadrature rule> sees only $s$, since $Q_{n+1}$ vanishes at every <quadrature node>; exactness on $s$ leaves precisely the displayed <orthogonality> condition. Conversely, exactness applied to each product $Q_{n+1}r$ forces that condition. This is the mechanism behind the higher precision of <Gaussian quadrature>.