# Revision history [back]

### Undeterministic numerical approximation

Let the following expression of x :

 f=1/152444172305856930250752000000*x^28 + 1/10888869450418352160768000000*x^27 + 1/15511210043330985984000000*x^25 + 1/310224200866619719680000*x^24 + 1/25852016738884976640000*x^23 + 1/51090942171709440000*x^21 + 1/1216451004088320000*x^20 + 1/121645100408832000*x^19 + 1/355687428096000*x^17 + 1/10461394944000*x^16 + 1/1307674368000*x^15 + 1/6227020800*x^13 + 1/239500800*x^12 + 1/39916800*x^11 + 1/362880*x^9 + 1/20160*x^8 + 1/5040*x^7 + 1/120*x^5 + 1/12*x^4 + 1/6*x^3 + x - cos(x) + 2 -exp(x) 

I noticed that evaluating that for the value x=numerical_approximation(10) leads to non-deterministic results (from the 12th decimal).

I guess that this is a "cancellation error" : the last term (-exp(x)) and the whole stuff before are both of the order of magnitude 22026.

I'm only interested in the first 3 or 4 decimals.

• QUESTION 1 How can I "force" sage to provide deterministic results ? Doing numerical_approx(...,prec=30) makes the job, but the "30" is quite heuristic; I'm not sure that this is a good approach.

• QUESTION 2 (not really sage-related) How should I unit-test a function that has undeterministic bahaviour like that ?