#11837: Make Newton basin plotting fun and easy
---------------------------+------------------------------------------------
Reporter: kcrisman | Owner: jason, was
Type: enhancement | Status: new
Priority: major | Milestone:
Component: graphics | Keywords: fractal newton complex plot
Work_issues: | Upstream: N/A
Reviewer: | Author: Karl-Dieter Crisman
Merged: | Dependencies:
---------------------------+------------------------------------------------
Comment(by SimonKing):
Here are some more detailed remarks on the code:
* In `which_root`, the expression `abs(varia-root)` seems to be rather
expensive. If you know the type of `varia` and `root` and if you know how
`abs` is computed for that type, you may help the compiler. See below:
Indeed that seems to be part of the problem.
* Since `which_root` is frequently called, it would make sense to improve
the inner loop:
{{{
cdef int counter
for counter from 0<=counter<20:
varia = newtf(varia)
...
}}}
* Again, since `which_root is frequently called, it would make sense to
reveal that `roots` is a list (could be done in the argument line of
`basin_plot`).
* I just tested that one gets
{{{
AttributeError: 'function' object has no attribute 'variables'
}}}
when trying to create `f1` as a fast callable. I don't know how that can
be worked around.
* The strange calls to complex interval field and so on really occur when
you do `varia-root`. This is because varia is a complex double, but root
(depending on the input) may be a symbolic expression. In the application,
you have
{{{
sage: roots = [-1,i,1]
sage: prefunc = prod([(x-root) for root in roots])
sage: newtf = fast_callable(newt(prefunc), domain=CDF,
expect_one_var=True)
sage: varia = newtf(roots[1])
sage: root = roots[1]
sage: type(varia)
<type 'sage.rings.complex_double.ComplexDoubleElement'>
sage: type(root)
<type 'sage.symbolic.expression.Expression'>
sage: %prun varia-root
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.001 0.001 <string>:1(<module>)
4/3 0.000 0.000 0.000 0.000
complex_interval_field.py:261(__call__)
2/1 0.000 0.000 0.000 0.000
complex_field.py:279(_element_constructor_)
39 0.000 0.000 0.000 0.000 {isinstance}
2 0.000 0.000 0.000 0.000 qqbar.py:2951(interval)
2 0.000 0.000 0.000 0.000
polynomial_ring.py:301(_element_constructor_)
3 0.000 0.000 0.000 0.000
complex_field.py:246(__call__)
2 0.000 0.000 0.000 0.000
polynomial_ring_constructor.py:47(PolynomialRing)
2 0.000 0.000 0.000 0.000
qqbar.py:2927(interval_diameter)
...
}}}
So, it would make sense to first convert the given roots to complex
doubles. If that isn't good enough, one may even cdef them as such. And,
in addition, cythonise the innermost loop. I'll soon test if it helps...
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11837#comment:6>
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.