Burcin Erocal wrote:
> Hi Jason,
>
> On Sat, 02 Jan 2010 15:14:15 -0700
> Jason Grout <[email protected]> wrote:
>
>> Here is the problem, narrowed down a bit:
>>
>>
>> sage: log(SR(float(-7.0)))
>> Traceback (most recent call last):
>> ...
>> ValueError: math domain error
>> sage: log(float(-7.0))
>> 1.94591014906 + 3.14159265359*I
>> sage: log(RR(-7.0))
>> 1.94591014905531 + 3.14159265358979*I
>> sage: log(SR(-7))
>> I*pi + log(7)
>> sage: log(SR(-7.0))
>> 1.94591014905531 + 3.14159265358979*I
>>
>>
>> Note the first answer, a symbolic-wrapped float, gave a domain error.
>> Is that version calling some C library that doesn't deal with complex
>> numbers? The floating point numbers in this problem appear because
>> we use hardware floats in plotting for speed.
>
> Many thanks for these examples. They were really helpful.
>
>> Burcin, do you see what is going on? Do you know how to fix it?
>
> With the patch at #7490, I changed pynac to call math.log() to evaluate
> logarithms when the argument is a float. This function raises the
> domain error we see on input <= 0, but I missed that.
>
> I attached a fix to #7822:
>
> http://trac.sagemath.org/sage_trac/ticket/7822
Thanks. The plot seems to work, but it is taking forever. Notice this:
sage: %timeit imag(1+I)
100 loops, best of 3: 1.65 ms per loop
sage: %timeit (1+I).imag()
1000 loops, best of 3: 198 盜 per loop
Does the top-level function have to be that much slower than the method
call?
Also, note this:
sage: %timeit log(CDF(1,2))
10000 loops, best of 3: 19.4 盜 per loop
sage: %timeit log(complex(1,2))
100 loops, best of 3: 1.62 ms per loop
sage: %timeit log(CDF(complex(1,2)))
10000 loops, best of 3: 24.5 盜 per loop
It looks like the best way to compute the log of a python complex object
is to convert it to CDF, which certainly does not seem intuitive.
Anyways, here is a *much* faster piece of code that is equivalent to the
original code posted above:
ff=lambda z: -2*log(z^3 - 8) + 4*log(z^3)
s=float(sqrt(3))
gg = lambda x,y: ff(CDF(x,y)).imag() if y < s*x else float('nan')
Also, the comparison was *way* slower if I did it symbolically
(y<sqrt(3)*x) versus doing it with a float approximating sqrt(3).
Compare:
sage: %timeit g(2,1)
10 loops, best of 3: 29.7 ms per loop
sage: %timeit gg(2,1)
10000 loops, best of 3: 114 盜 per loop
Now the contour plot takes under a second to generate on my computer.
sage: %time a=contour_plot(gg,(x,0,4),(y,0,4),fill=False,contours=30)
CPU times: user 0.86 s, sys: 0.00 s, total: 0.86 s
Wall time: 0.89 s
Thanks,
Jason
--
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
URL: http://www.sagemath.org