On Dec 27, 2007 1:53 PM, pgdoyle <[EMAIL PROTECTED]> wrote:
> I'm having problems doing symbolic computations in Sage. Calls to
> rational_simplify() seem to take about .2 seconds each. Working
> directly in Maxima is about 100 times faster. Mathematica is
> something like 500 times faster.
>
> In Sage, where does the time go? Is there something I can do right
> now to speed things up? Is this something that will eventually go
> faster?
>
> Cheers,
>
> Peter Doyle
> -------------------------
> sage: var(x)
> x
> sage: time sum(((x+sin(i))/x+(x-sin(i))/x).rational_simplify() for i
> in xrange(100))
> 200
> CPU time: 5.29 s, Wall time: 39.10 s
> sage: time maxima('sum(ratsimp((x+sin(i))/x+(x-sin(i))/x),i,1,100)')
> 200
> CPU time: 0.02 s, Wall time: 0.55 s
Those times above are really weird. On my laptop (OSX 10.5.1):
sage: var(x)
x
sage: time sum(((x+sin(i))/x+(x-sin(i))/x).rational_simplify() for i
in xrange(100))
200
Time: CPU 0.97 s, Wall: 3.20 s
sage: time maxima('sum(ratsimp((x+sin(i))/x+(x-sin(i))/x),i,1,100)')
200
CPU time: 0.01 s, Wall time: 0.34 s
Thus it takes 3.2 seconds wall time instead of 39.10 seconds for me.
If you use more specialized algebraic structures in Sage, then the
time directly in Sage comes down a lot (to beat Maxima):
sage: x = RDF['x'].gen()
sage: time sum(((x+math.sin(i))/x+(x-math.sin(i))/x) for i in xrange(100))
200.0*x^200/(1.0*x^200)
CPU time: 0.20 s, Wall time: 0.21 s
Above we make x the indeterminate of the RDF[x], and use the floating
point sin function from Python. But it's not symbolic.
But sympy is still way faster and is symbolic:
sage: from sympy import Symbol, sin
sage: x = Symbol('x')
sage: time sum(((x+sin(i))/x+(x-sin(i))/x).expand() for i in xrange(100))
200
Time: CPU 0.09 s, Wall: 0.09 s
which is why it's a good thing that sympy is the future of symbolic
computation in Sage :-).
And since Sympy comes with Sage, maybe you can use it for
your intended application right now?!
-- William
> sage: time mathematica('Sum[Simplify[(x+Sin[i])/x+(x-Sin[i])/x],{i,
> 1,100}]')
> 200
> CPU time: 0.00 s, Wall time: 0.09 s
> sage: time maxima('sum(ratsimp((x+sin(i))/x+(x-sin(i))/x),i,1,10000)')
> 20000
> CPU time: 0.01 s, Wall time: 30.21 s
> sage: time mathematica('Sum[Simplify[(x+Sin[i])/x+(x-Sin[i])/x],{i,
> 1,10000}]')
> 20000
> CPU time: 0.01 s, Wall time: 2.20 s
> sage: time mathematica('Sum[Simplify[(x+Sin[i])/x+(x-Sin[i])/x],{i,
> 1,100000}]')
> 200000
> CPU time: 0.00 s, Wall time: 70.05 s
> sage: time mathematica('Sum[Evaluate[Simplify[(x+Sin[i])/x+(x-Sin[i])/
> x]],{i,1,100000}]')
> 200000
> CPU time: 0.00 s, Wall time: 0.03 s
> >
>
--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org
--~--~---------~--~----~------------~-------~--~----~
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-support
URLs: http://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/
-~----------~----~----~----~------~----~------~--~---