#13355: doctest proper handling of domain in evalf functions
-------------------------------------+-------------------------------------
Reporter: tkluck | Owner: burcin
Type: defect | Status: needs_work
Priority: major | Milestone: sage-6.3
Component: symbolics | Resolution:
Keywords: evalf, | Merged in:
fast_callable | Reviewers: Ralf Stephan
Authors: Timo Kluck | Work issues:
Report Upstream: N/A | Commit:
Branch: | 23e82c2ed92225aed5987f3fb22c576860237858
u/rws/plot_fails_if_a_function_implicitly_needs_complex_intermediate_values|
Stopgaps:
Dependencies: |
-------------------------------------+-------------------------------------
Changes (by {'newvalue': u'Timo Kluck', 'oldvalue': ''}):
* status: needs_review => needs_work
* author: => Timo Kluck
* commit: => 23e82c2ed92225aed5987f3fb22c576860237858
* milestone: sage-duplicate/invalid/wontfix => sage-6.3
* keywords: => evalf, fast_callable
* reviewer: => Ralf Stephan
* work_issues: compare patch with #15030 =>
Old description:
> Plotting currently fails when plotting a symbolic function that evaluates
> to complex values:
>
> {{{
> sage: def evalf_func(self,x,parent=None):
> ....: return parent(I*x) if parent!=None else 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.
New description:
Previous description of ticket:
------------------------------------
Plotting currently fails when plotting a symbolic function that evaluates
to complex values:
{{{
sage: def evalf_func(self,x,parent=None):
....: return parent(I*x) if parent!=None else 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.
--
Comment:
I have extracted the doctests from the patch and changed the description
accordingly. However, some doctests fail.
{{{
sage -t --long src/sage/ext/fast_callable.pyx
**********************************************************************
File "src/sage/ext/fast_callable.pyx", line 397, in
sage.ext.fast_callable.?
Failed example:
fc(3,4)
Expected:
12
Got:
f(3, 4)
**********************************************************************
File "src/sage/ext/fast_callable.pyx", line 405, in
sage.ext.fast_callable.?
Failed example:
fc(3,4)
Expected:
12*I
Got:
g(3, 4)
**********************************************************************
1 item had failures:
2 of 47 in sage.ext.fast_callable.?
[586 tests, 2 failures, 3.54 s]
----------------------------------------------------------------------
sage -t --long src/sage/ext/fast_callable.pyx # 2 doctests failed
----------------------------------------------------------------------
}}}
----
New commits:
||[http://git.sagemath.org/sage.git/commit/?id=23e82c2ed92225aed5987f3fb22c576860237858
23e82c2]||{{{13355: handle domain properly in evalf functions
(doctests)}}}||
--
Ticket URL: <http://trac.sagemath.org/ticket/13355#comment:21>
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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.