On Mon, Jun 30, 2014 at 11:23 AM, William Stein <
wst...@gmail.com> wrote:
> On Mon, Jun 30, 2014 at 9:29 AM, Ondřej Čertík <
ondrej...@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
More importantly, the result is not simplified...
> 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.
Btw, Mathematica always returns sqrt(100000000003) and it seems to
cancel "p" no matter how large p and q is (I assume it puts 1/p into
the sqrt() and simplifies the rational).
However, in Mathematica, sqrt(12) gets simplified to 2*sqrt(3). But
sqrt(p*q) returns as
sqrt(1000000001930000000057). So Mathematica seems to have a cut-off, after
which it won't attempt the factorization.
In SymPy, we have a cut-off as well, but unlike Mathematica, we don't
seem to be able to factorize
it either for larger p, q, e.g.:
In [21]: p = 19
In [22]: q = 31
In [23]: sqrt(p**2*q)/p
sqrt(31)
But:
In [18]: p = 10000000019
In [19]: q = 100000000003
In [20]: sqrt(p**2*q)/p
sqrt(10000000038300000037240000001083)/10000000019
> 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.
Btw, in csympy we started using a very fast primesieve library
(
http://primesieve.org/).
It's only for generating the primes (and only up to 10^9), but it
might be the fastest library out there.
Ondrej