Rational coefficients of special functions in scattering amplitudes are known to simplify on singular surfaces, often diverging less strongly than the naïve expectation. To systematically study these surfaces and rational functions on them, we employ tools from algebraic geometry. We show how the divergences of a rational function constrain its numerator to belong to symbolic powers of ideals associated to the singular surfaces. To study the divergences of the coefficients, we make use of p-adic numbers, closely related to finite fields. These allow us to perform numerical evaluations close to the singular surfaces in a stable manner and thereby characterize the divergences of the coefficients. We then use this information to construct low-dimensional Ansätze for the rational coefficients. As a proof-of-concept application of our algorithm, we reconstruct the two-loop 0 → q$$ \overline{q} $$
q
¯
γγγ pentagon-function coefficients with fewer than 1000 numerical evaluations.