# Dealing with zero at high precision

I am using mathematica to deal with rational functions, $$p(x)/q(x)$$, where the polynomials, $$p,q$$ have a high degree and coefficients with high order of precision, e.g:

Precision/@CoefficientList[p[x],x]
Out: {350,350,350,...}


The problem is that I need use values of that are shifted from x, and the rational function then look like

rational = p[x+7]/q[x+3]
Out:  (a[1] x+ a[2]x^2+...)/(0.*10^-280+b[1]x+...)


where a[n],b[n] are actual numbers. By shifting from x, I of course lose some precision, which I am okay-ish with (also I wouldn't mind be able to get higher precision).

When I use rational as a rational function everything works fine, but I sometimes need it evaluated at x=0. If I do so using rational/.x->0, I get the following error:

"Infinite expression 1/0.*10^-280 encountered"


whereas the correct answer should be a[1]/b[1]. I managed to fix this error by using

Chop[rational,10^-279]/.x->0


which gives me the correct answer. I however have a lot of different polynomials and the loss of precision changes depending on their degree, coeffiients, etc.

the rational function is an approximation of a function, which I know is non-singular at the evaluated point, so I know that this precision zero is spurious. The coefficients are however generated by another program I do not have control over, only the high precision. Of course that does not help here because demanding a higher precision I only push the problem forward.

Is there a best-practice way of dealing with that kind of problem?

• Does rational /. c_Real /; c == 0 -> 0 instead of Chop work? Looks like it might be best if rational = p[x+7]/q[x+3] /. c_Real /; c == 0 -> 0 were used to define rational. Might also want to make sure the fraction is reduced, maybe with Simplify. Commented Feb 10, 2020 at 13:14
• Mathematically, c_Real /; c == 0 -> 0 amounts to the assumption that any coefficient in which the round-off error bound (computed by the arbitrary-precision arithmetic) is greater than the estimated value should in fact be equal to zero. (When the error is greater than the value, the number is represented by 0n.) The method Chop[rational, 10-^n] represents the assumption that any coefficient whose value is less than 10^-n should in fact be zero. The difference is similar to the difference between relative and absolute error respectively. Commented Feb 10, 2020 at 13:27

rational = p[x+7]/q[x+3] /. c_Real /; c == 0 -> 0

is the best way to get rid of the spurious zero, as Chop will also potentially discard small values, and one does not need to look at what the precision of 0. is.