On Mon, Jun 30, 2014 at 9:29 AM, Ondřej Čertík <ondrej.cer...@gmail.com> wrote:
> Thanks Volker for the tip, that does the job. More comments below:

Another comment.  Evidently Sage uses **Maxima** for
rational_simplify, hence the integer factorization that is required to
do this is not-surprisingly insanely stupidly slow, by modern
standards:

sage: p = next_prime(10^10); q = next_prime(10^11)
sage: a = sqrt(p^2*q)/p
sage: %time a.rational_simplify()
1/10000000019*sqrt(10000000038300000037240000001083)
CPU time: 1.12 s, Wall time: 3.52 s
sage: %time factor(p^2*q)
10000000019^2 * 100000000003
CPU time: 0.00 s, Wall time: 0.03 s

Don't even try increasing the size of p, q above... or it'll take forever.

We should maybe consider sometime make our rational_simplify first
factor or something (I don't know), so it can leverage sage's much
better integer factorization code.

William


>
> On Sun, Jun 29, 2014 at 11:52 PM, John Cremona <john.crem...@gmail.com> wrote:
>> Be careful though:
>>
>> sage: (sqrt(-2)*sqrt(-3)).simplify_radical()
>> -sqrt(3)*sqrt(2)
>>
>> i.e. you cannot use sqrt(a)*sqrt(b)=sqrt(a*b) everywhere without
>> reaching a contradiction.
>>
>> sage: bool( (sqrt(-2)*sqrt(-3)) == sqrt(2)*sqrt(3) )
>> False
>
> Right, e.g. in sympy:
>
>>>> sqrt(-2)*sqrt(-3)
> -sqrt(6)
>
>
> Coming to the original example, sympy returns
>
>>>> sqrt(3)/sqrt(15)
> sqrt(5)/5
>
> And Mathematica returns 1/sqrt(5).
>
>
> Here is a more difficult example, in SymPy:
>
>>>> 2**(S(1)/3) * 6**(S(1)/4)
> 2**(7/12)*3**(1/4)
>
> Mathematica returns the same thing. Sage, on the other hand, does not
> simplify this:
>
> sage: 2**(1/3) * 6**(1/4)
> 6^(1/4)*2^(1/3)
> sage: _.rational_simplify()
> 6^(1/4)*2^(1/3)
>
>
> What is interesting though, is that Sage does perform some
> factorization automatically, e.g.:
>
> sage: sqrt(12)
> 2*sqrt(3)
>
> Mathematica and SymPy do the same here.
>
> Here is even better example, in Sage:
>
> sage: sqrt(12)/sqrt(6)
> 1/3*sqrt(6)*sqrt(3)
> sage: _.rational_simplify()
> 1/3*sqrt(6)*sqrt(3)
>
> SymPy or Mathematica:
>
>>>> sqrt(12)/sqrt(6)
> sqrt(2)
>
> So the Sage rule seems to be --- factorize simple sqrt(N) into the
> form a*sqrt(b), do this for all sqrt() in the expression, and then
> just convert 1/sqrt(n) -> sqrt(n)/n, and return the result, after
> canceling common factors.
>
> I think a better rule is to either
>
> a) factor everything, like SymPy or Mathematica
> 2) do not factor anything, and just leave sqrt(12)/sqrt(6) as is. Then
> rational_simplify() should return the result from a).
>
> Ondrej
>
> --
> 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.
> For more options, visit https://groups.google.com/d/optout.



-- 
William Stein
Professor of Mathematics
University of Washington
http://wstein.org

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to