[[TOC]]
= Remez tutorial 5/5: additional tips =
This part of the tutorial is constantly updated. Check its [?action=history history] to know what is new.
== What to do when the solver doesn’t converge? ==
It may happen that the solver doesn’t converge. There are many possible reasons for that:
* the function being approximated is not smooth enough; try to increase the polynomial degree, or reduce the approximation range.
* the solver cycles between a finite number (usually 3 or 4) of solutions; in this case, experiments indicate that you may safely choose the solution with the smaller error.
== Floating point precision ==
The Remez algorithm performs high precision computations to find its solutions. As a result, the polynomial coefficients found are printed with far more decimals than the usual `double` or `float` numbers can store. So when you write:
{{{
#!cpp
float a = 8.333017134192478312472752663154642556843e-3;
}}}
The exact value of `a` is actually:
{{{
8.333017118275165557861328125e-3
^-- this decimal changes!
}}}
See [wiki:doc/maths/remez/tutorial-fixing-parameters “fixing lower-order parameters”] for both an explanation of why this can be a problem, and a method to reduce the introduced error.
== When not to use Remez? ==
There are cases when you should expect the Remez algorithm to potentially perform badly:
* when the function is not [http://en.wikipedia.org/wiki/Continuous_function continuous] (for instance, a step function)
* when the function is not [http://en.wikipedia.org/wiki/Differentiable_function differentiable] (for instance, the ''x+abs(x)'' function)
* sometimes when the function is not [http://en.wikipedia.org/wiki/Smooth_function smooth]
* sometimes even when the function is not [http://en.wikipedia.org/wiki/Analytic_function analytic]
There are cases where you should not try to use the Remez algorithm at all:
* when the '''source''' range is not finite, ''eg.'' [0,+∞]
* when the '''destination''' range is not finite, ''eg.'' ''log(x)'' tends to -∞ near 0
* when the function to approximate has an infinite derivative at a point contained in or near the approximation range, ''eg.'' ''sqrt(x)'' or ''cbrt(x)'' in 0
== What if I want to use Remez anyway? ==
If you need to approximate a function ''f(x)'' over [a,+∞] and for some reason you want to use the Remez exchange algorithm, you can still through a change of variable: ''y = 1/x''. The function to approximate becomes ''f(1/y)'' and the new range is ![0,1/a] (see [wiki:doc/maths/remez/tutorial-changing-variables “changing variables”] for how to deal with ''1/x'' in 0). The minimax polynomial will use ''1/x'' as its variable; please be aware that computing ''1/x'' at runtime may be expensive.
== Conclusion ==
Please report any trouble you may have had with this document to sam@hocevar.net. You may then return to the [wiki:doc/maths/remez Remez exchange documentation].