On 2/2/12 10:03 PM, Oscar Lazo wrote:
Hello
I've got the following expression:
z=(24*K1**2*K2**2*e**(4*I) + (24*K2**2 - 32*I*K2 + 32)*K1**2 +
(-48*I*K2**2 - 64*K2 - 64*I)*K1 - ((48*K2**2 - 32*I*K2)*K1**2 -
(48*I*K2**2 + 32*K2)*K1)*e**(2*I))*(24*K1**2*K2**2*e**(-4*I) + (24*K2**2
+ 32*I*K2 + 32)*K1**2 + (48*I*K2**2 - 64*K2 + 64*I)*K1 - ((48*K2**2 +
32*I*K2)*K1**2 - (-48*I*K2**2 +
32*K2)*K1)*e**(-2*I))/((9*K1**3*K2**3*e**(6*I) - (9*K2**3 - 30*I*K2**2 -
12*K2 - 24*I)*K1**3 + (30*I*K2**3 + 100*K2**2 - 40*I*K2 + 80)*K1**2 +
24*I*K2**3 - ((27*K2**3 - 30*I*K2**2)*K1**3 - (30*I*K2**3 +
28*K2**2)*K1**2)*e**(4*I) + (12*K2**3 - 40*I*K2**2 - 16*K2 - 32*I)*K1 +
((27*K2**3 - 60*I*K2**2 - 12*K2)*K1**3 + (-60*I*K2**3 - 128*K2**2 +
16*I*K2)*K1**2 - (12*K2**3 - 16*I*K2**2 + 16*K2)*K1)*e**(2*I) + 80*K2**2
- 32*I*K2 + 64)*(9*K1**3*K2**3*e**(-6*I) - (9*K2**3 + 30*I*K2**2 - 12*K2
+ 24*I)*K1**3 + (-30*I*K2**3 + 100*K2**2 + 40*I*K2 + 80)*K1**2 -
24*I*K2**3 - ((27*K2**3 + 30*I*K2**2)*K1**3 - (-30*I*K2**3 +
28*K2**2)*K1**2)*e**(-4*I) + (12*K2**3 + 40*I*K2**2 - 16*K2 + 32*I)*K1 +
((27*K2**3 + 60*I*K2**2 - 12*K2)*K1**3 + (60*I*K2**3 - 128*K2**2 -
16*I*K2)*K1**2 - (12*K2**3 + 16*I*K2**2 + 16*K2)*K1)*e**(-2*I) +
80*K2**2 + 32*I*K2 + 64)) + (8*K1**2*K2**2*e**(4*I) + (8*K2**2 -
16*I*K2)*K1**2 - ((16*K2**2 - 16*I*K2)*K1**2 + 32*K1*K2)*e**(2*I) +
32*K2**2 - 64*I*K2)*(8*K1**2*K2**2*e**(-4*I) + (8*K2**2 + 16*I*K2)*K1**2
- ((16*K2**2 + 16*I*K2)*K1**2 + 32*K1*K2)*e**(-2*I) + 32*K2**2 +
64*I*K2)/((9*K1**3*K2**3*e**(6*I) - (9*K2**3 - 30*I*K2**2 - 12*K2 -
24*I)*K1**3 + (30*I*K2**3 + 100*K2**2 - 40*I*K2 + 80)*K1**2 + 24*I*K2**3
- ((27*K2**3 - 30*I*K2**2)*K1**3 - (30*I*K2**3 +
28*K2**2)*K1**2)*e**(4*I) + (12*K2**3 - 40*I*K2**2 - 16*K2 - 32*I)*K1 +
((27*K2**3 - 60*I*K2**2 - 12*K2)*K1**3 + (-60*I*K2**3 - 128*K2**2 +
16*I*K2)*K1**2 - (12*K2**3 - 16*I*K2**2 + 16*K2)*K1)*e**(2*I) + 80*K2**2
- 32*I*K2 + 64)*(9*K1**3*K2**3*e**(-6*I) - (9*K2**3 + 30*I*K2**2 - 12*K2
+ 24*I)*K1**3 + (-30*I*K2**3 + 100*K2**2 + 40*I*K2 + 80)*K1**2 -
24*I*K2**3 - ((27*K2**3 + 30*I*K2**2)*K1**3 - (-30*I*K2**3 +
28*K2**2)*K1**2)*e**(-4*I) + (12*K2**3 + 40*I*K2**2 - 16*K2 + 32*I)*K1 +
((27*K2**3 + 60*I*K2**2 - 12*K2)*K1**3 + (60*I*K2**3 - 128*K2**2 -
16*I*K2)*K1**2 - (12*K2**3 + 16*I*K2**2 + 16*K2)*K1)*e**(-2*I) +
80*K2**2 + 32*I*K2 + 64))
which depends on K1 and K2. I need to evaluate for many values of K1 and
K2. I know it to be real, but doing
real(z)
takes forever, so I tried using simply
z.subs(K1=k1,K2=k2)
inside two nested for loops, but that also takes very long. Next I tried
to use fast_float, but that won't accept my complex expression. I also
tried fast_callable, but it takes even longer than z.subs.
So, Is there some way to evaluate fastly a complex expression?
I would use fast_callable (which for me is 5x faster than subs), or even
better, just use straight cython (which for me is around 100x faster
than subs). You can also precompute e^(kI) for your various k to get a
25% speedup from that cython too.
See http://sagenb.org/home/pub/4200/ for examples
Thanks,
Jason
--
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org