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:

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


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?

  • 2
    $\begingroup$ 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. $\endgroup$
    – Michael E2
    Feb 10, 2020 at 13:14
  • 2
    $\begingroup$ 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 0``n.) 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. $\endgroup$
    – Michael E2
    Feb 10, 2020 at 13:27

1 Answer 1


as Michael E2 indicated in the comments using

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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.