#13355: Plot fails if a function implicitly needs complex intermediate values
-------------------------+--------------------------------------------------
Reporter: tkluck | Owner: burcin
Type: defect | Status: new
Priority: major | Milestone: sage-5.3
Component: symbolics | Keywords: needs-review
Work issues: | Report Upstream: N/A
Reviewers: | Authors:
Merged in: | Dependencies:
Stopgaps: |
-------------------------+--------------------------------------------------
Plotting currently fails when plotting a symbolic function that evaluates
to complex values:
{{{
sage: def evalf_func(self,x,parent):
....: return parent(I*x)
....:
sage: f = function('f', evalf_func=evalf_func)
sage: plot(abs(f(x)),0,5)
verbose 0 (2392: plot.py, generate_plot_points) WARNING: When plotting,
failed to evaluate function at 199 points.
verbose 0 (2392: plot.py, generate_plot_points) Last error message:
'unable to simplify to float approximation'
}}}
This is because `plot` uses `fast_float`, and `fast_float` cannot deal
with the intermediate complex value.
The attached patch first changes these things:
* it adds a method to `class Function` that allows one to see what output
range is to be expected for a given input range. By default, it will
return a complex field.
* it overrides this method for builtin functions, which return floats for
float input
* this is then used by `fast_float` to throw an exception if complex
values are to be expected
This exception will cause `plot` to fall back to `fast_callable` instead
of `fast_float`. However, `fast_callable` needs patching too:
* it now uses the `_evalf_` method when available instead of just
`__call__`. Otherwise, `plot` will try to coerce the result to `float`,
which also cannot deal with complex intermediate values.
An alternative to this step would be to fix `float` coercion, which I
haven't looked into.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/13355>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.