On 05/13/2013 04:56 PM, John H Palmieri wrote: > On Monday, May 13, 2013 2:11:59 PM UTC-7, ManDay wrote: > > Could anyone shed a bit of light on this? > > The more I try, the more SAGE's types get in my way. It turns out to be > an unpredictable element. Unless I make sure *every* involved function > really returns one specific type, calculations are becoming practically > impossible, because the results are completely random (malfunctions). > > Here is just the last and most annoying of my encounters I can't make > heads or tails of, enjoy: > > http://alpha.sagenb.org/home/pub/701/ > <http://alpha.sagenb.org/home/pub/701/> > > > The issue is, if you define a number a by > > sage: a = -CDF(2.4995) > > then the imaginary part of a is "-0.0", and it is treated as negative. > When a**(1/2) is computed, it is computed (according to the > documentation) as exp(log(a)*(1/2)), and since the imaginary part of a > is negative, its log has imaginary part approximately equal to -pi. This > choice of branch cut is documented: type "log?" On the other hand: > > sage: b = CDF(-2.4995) > > Then b has imaginary part which is 0.0, treated as positive, so log(b) > has imaginary part approximately equal to +pi.
Also, this not restricted to sage. Try this little C program (using C99 standard, so don't try it on Visual Studio): #include <stdio.h> #include <math.h> #include <complex.h> int main() { complex a = 2.4995, b = -2.4995; printf("%g %g\n", cimag(csqrt(-a)), cimag(csqrt(b))); } This really is what the C99 standard requires. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at http://groups.google.com/group/sage-devel?hl=en. For more options, visit https://groups.google.com/groups/opt_out.