On May 19, 4:50 pm, Volker Braun <
vbraun.n...@gmail.com> wrote:
> Floating-point and numerically unstable formula just don't mix. Sure,
> working with RIF makes it much harder to get something that is plainly
> wrong, but you can still construct quickly-varying functions where it will
> give you the wrong result. There is no magic bullet, you have to learn
> about numerics if you want to use floating point numbers effectively.
mpfi (on which RIF is based) is implemented in such way that you
*always* have a good answer. Sometimes the answer is nothing useful
(like the interval [-infinity...+infinity]) but it is always such that
the computer answer of f(I) contains the mathematical f(I). I am
curious to see your example and will add it to the documentation if it
exists !
> It would still be nice to have an option .n(adaptive=True) or so to adapt
> the input precision until a desired output precision in reached. You also
> need a fuzzy zero in case the actual value is zero.
Thanks for the suggestion. I opened a ticket in that direction #14620.
I would also like to ask a more general design question. There is a
conversion from SR to RR and RIF implemented respectively through the
method _mpfr_ and _real_mpfi_ (why the second one is explicitly
implemented in the __init__ of RealIntervalFieldElement and not as a
conversion method as in the case of RR ?). Both of them uses the
method _eval_self of a symbolic expression which does what we expect
and does it quick! Now the thing is that by doing
{{{
sage: expr = a = (106*pi - 333) / (355 - 113*pi)
sage: RR(expr)
}}}
I would like to get the floating point that is the nearest to my
expression (perhaps this is not what everybody wants ?). As you
mentioned there is a problem when the result is actually zero and expr
does not know itself it is zero. This might be a problem of SR and I
would be happy if there was a way to work with the transcendental
extension QQ[pi] where I can assert that an expression is zero.
More concretely, once the adaptive algorithm is implemented, it will
be possible to have two conversions from SR to RR:
- one which just works through _eval_self (and behaves
like .n(adaptive=False))
- one which try to check equality to zero, then make some adaptive
evaluation using intervals and if the precision increase too much
raise an error arguing that the answer is too small (behave
like .n(adaptive=True))
My question is what should be the default ?
The same question should be asked for number fields (and the answer
need not be the same).