Re: [sage-devel] The fastest way to expand((a1+a2+a3+a4+sqrt(3)*a5)^25)

2015-01-20 Thread John Cremona
On 19 January 2015 at 23:03, mmarco mma...@unizar.es wrote:
 It is much faster to work with absolute fields instead of towers of
 extensions:

 sage: K.sqrt3=QuadraticField(3)
 sage: F.sqrt5=K.extension(x^2-5)
 sage: R.a1,a2,a3,a4,a5 = F[]
 sage: %time _=(a1+a2+a3+sqrt5*a4+sqrt3*a5)^25
 CPU times: user 27.4 s, sys: 12 ms, total: 27.4 s
 Wall time: 27.5 s
 sage: FF.a=F.absolute_field()
 sage: fsqrt3=FF(F(sqrt3))
 sage: fsqrt5=FF(sqrt5)
 sage: RR.a1,a2,a3,a4,a5 = FF[]
 sage: %time _=(a1+a2+a3+fsqrt5*a4+fsqrt3*a5)^25
 CPU times: user 1.26 s, sys: 3 ms, total: 1.27 s
 Wall time: 1.27 s


 I guess that pari internally follows the second approach.

No I don't think so.  In gp:

? Mod(x,x^2-3) + Mod(y,y^2-5)
%2 = Mod(x + Mod(y, y^2 - 5), x^2 - 3)

This can be read as a polynomial in x subject to the side condition
that x^2=3, where one of the coefficients is y subject to y^2=5.

Before I tried the above I did this:

? Mod(x,x^2-3) + Mod(x,x^2-5)
%1 = 0

which is a warning to anyone trying to interface between Sage and Pari/GP!

John


 --
 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.

-- 
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.


Re: [sage-devel] The fastest way to expand((a1+a2+a3+a4+sqrt(3)*a5)^25)

2015-01-20 Thread Jeroen Demeyer

On 2015-01-20 10:14, John Cremona wrote:

? Mod(x,x^2-3) + Mod(x,x^2-5)
%1 = 0


That's a PARI feature: the result would lie in the ring
QQ[x]/(x^2-3, x^2-5) = QQ[x]/(1)

--
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.


Re: [sage-devel] The fastest way to expand((a1+a2+a3+a4+sqrt(3)*a5)^25)

2015-01-20 Thread Sébastien Labbé


 any idea how to get the number of 
 terms in a better way in Sage?): 

 sage: K.sqrt3 = QuadraticField(3) 
 sage: L.sqrt5 = K.extension(x^2-5) 
 sage: R.a1,a2,a3,a4,a5 = L[] 
 sage: time f = (a1+a2+a3+sqrt5*a4+sqrt3*a5)^18 
 CPU times: user 2.43 s, sys: 3.94 ms, total: 2.44 s 
 Wall time: 2.44 s 
 sage: len(str(f).split(+)) 
 7315 



You may do len(list(f)). 
To avoid the creation of the list: sum(1 for _ in f).

Some timings:

sage: %time len(str(f).split(+)) 
CPU times: user 8.2 s, sys: 3.14 s, total: 11.3 s
Wall time: 12 s
7315
sage: %time len(list(f))
CPU times: user 699 ms, sys: 98.1 ms, total: 797 ms
Wall time: 770 ms
7315
sage: %time len(f.monomials())
CPU times: user 127 ms, sys: 13.7 ms, total: 141 ms
Wall time: 135 ms
7315
sage: %time sum(1 for _ in f)
CPU times: user 69.6 ms, sys: 18.8 ms, total: 88.3 ms
Wall time: 85.2 ms
7315

Sébastien

-- 
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.


Re: [sage-devel] The fastest way to expand((a1+a2+a3+a4+sqrt(3)*a5)^25)

2015-01-19 Thread mmarco
It is much faster to work with absolute fields instead of towers of 
extensions:

sage: K.sqrt3=QuadraticField(3)
sage: F.sqrt5=K.extension(x^2-5)
sage: R.a1,a2,a3,a4,a5 = F[]
sage: %time _=(a1+a2+a3+sqrt5*a4+sqrt3*a5)^25
CPU times: user 27.4 s, sys: 12 ms, total: 27.4 s
Wall time: 27.5 s
sage: FF.a=F.absolute_field()
sage: fsqrt3=FF(F(sqrt3))
sage: fsqrt5=FF(sqrt5)
sage: RR.a1,a2,a3,a4,a5 = FF[]
sage: %time _=(a1+a2+a3+fsqrt5*a4+fsqrt3*a5)^25
CPU times: user 1.26 s, sys: 3 ms, total: 1.27 s
Wall time: 1.27 s


I guess that pari internally follows the second approach.

-- 
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.


Re: [sage-devel] The fastest way to expand((a1+a2+a3+a4+sqrt(3)*a5)^25)

2015-01-19 Thread Ondřej Čertík
Hi Miguel,

On Mon, Jan 19, 2015 at 4:03 PM, mmarco mma...@unizar.es wrote:
 It is much faster to work with absolute fields instead of towers of
 extensions:

 sage: K.sqrt3=QuadraticField(3)
 sage: F.sqrt5=K.extension(x^2-5)
 sage: R.a1,a2,a3,a4,a5 = F[]
 sage: %time _=(a1+a2+a3+sqrt5*a4+sqrt3*a5)^25
 CPU times: user 27.4 s, sys: 12 ms, total: 27.4 s
 Wall time: 27.5 s
 sage: FF.a=F.absolute_field()
 sage: fsqrt3=FF(F(sqrt3))
 sage: fsqrt5=FF(sqrt5)
 sage: RR.a1,a2,a3,a4,a5 = FF[]
 sage: %time _=(a1+a2+a3+fsqrt5*a4+fsqrt3*a5)^25
 CPU times: user 1.26 s, sys: 3 ms, total: 1.27 s
 Wall time: 1.27 s

Thanks. I tried it on SMC:

sage: K.sqrt3=QuadraticField(3)
sage: F.sqrt5=K.extension(x^2-5)
sage: R.a1,a2,a3,a4,a5 = F[]
sage: %time _=(a1+a2+a3+sqrt5*a4+sqrt3*a5)^18
CPU times: user 2.76 s, sys: 12.5 ms, total: 2.77 s
Wall time: 2.77 s
sage: len(str(_).split(+))
7315
sage: FF.a=F.absolute_field()
sage: fsqrt3=FF(F(sqrt3))
sage: fsqrt5=FF(sqrt5)
sage: RR.a1,a2,a3,a4,a5 = FF[]
sage: %time _=(a1+a2+a3+fsqrt5*a4+fsqrt3*a5)^18
CPU times: user 320 ms, sys: 0 ns, total: 320 ms
Wall time: 320 ms
sage: len(str(_).split(+))
12430

and your approach returns a wrong number of terms, so something is
wrong. But it is quite fast.

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.


Re: [sage-devel] The fastest way to expand((a1+a2+a3+a4+sqrt(3)*a5)^25)

2015-01-19 Thread Nils Bruin
On Monday, January 19, 2015 at 9:27:44 PM UTC-8, Ondřej Čertík wrote:


 and your approach returns a wrong number of terms, so something is 
 wrong. But it is quite fast. 

 
The term count doesn't tell you that. The representation of sqrt3 and sqrt5 
doesn't consist of single term expressions:
 
sage: fsqrt3
-1/4*a^3 + 7/2*a
sage: fsqrt5
-1/4*a^3 + 9/2*a


-- 
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.


Re: [sage-devel] The fastest way to expand((a1+a2+a3+a4+sqrt(3)*a5)^25)

2015-01-19 Thread Ralf Stephan


 What is here? 

 
AMD Phenom 3GHz, 8GB RAM, no other big jobs

Since that expression is large, the cache size of the CPU might 
 significantly impact performance. 


Wouldn't that affect any of the following?

│ Sage Version 6.5.beta5, Release Date: 2015-01-05   │
│ Type notebook() for the browser-based notebook interface.│
│ Type help() for help.│
└┘
┏┓
┃ Warning: this is a prerelease version, and it may be unstable. ┃
┗┛
sage: K.sqrt3 = QuadraticField(3)
sage: R.a1,a2,a3,a4,a5 = K[]
sage: timeit((a1+a2+a3+a4+sqrt3*a5)^25)
5 loops, best of 3: 140 ms per loop
sage: a1,a2,a3,a4,a5=var('a1,a2,a3,a4,a5')
sage: timeit(ex=expand((a1+a2+a3+a4+sqrt(3)*a5)^25))
5 loops, best of 3: 5.29 s per loop

I was wrong in the poly(SR) case. That's even slower than SR.expand():

sage: R.a1,a2,a3,a4,a5 = PolynomialRing(SR, 'a1,a2,a3,a4,a5')
sage: %time p=(a1+a2+a3+a4+sqrt(3)*a5)^25
stopped after a minute

-- 
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.


Re: [sage-devel] The fastest way to expand((a1+a2+a3+a4+sqrt(3)*a5)^25)

2015-01-19 Thread Ralf Stephan
On Sunday, January 18, 2015 at 9:18:53 AM UTC+1, vdelecroix wrote:

 Your example can be reduced to polynomials 

 sage: K.sqrt3 = QuadraticField(3) 
 sage: R.a1,a2,a3,a4,a5 = K[] 
 sage: timeit((a1+a2+a3+a4+sqrt3*a5)^25) 
 5 loops, best of 3: 81 ms per loop 

 
How do you get this speed? Here it's three orders of magnitude slower.

BTW another way is to use polynomials over SR, for about the same
speed but without number field restrictions.


Regards,

-- 
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.


Re: [sage-devel] The fastest way to expand((a1+a2+a3+a4+sqrt(3)*a5)^25)

2015-01-19 Thread William Stein
On Mon, Jan 19, 2015 at 8:55 AM, Ralf Stephan gtrw...@gmail.com wrote:
 On Sunday, January 18, 2015 at 9:18:53 AM UTC+1, vdelecroix wrote:

 Your example can be reduced to polynomials

 sage: K.sqrt3 = QuadraticField(3)
 sage: R.a1,a2,a3,a4,a5 = K[]
 sage: timeit((a1+a2+a3+a4+sqrt3*a5)^25)
 5 loops, best of 3: 81 ms per loop


 How do you get this speed? Here it's three orders of magnitude slower.

What is here?

When I try it on SageMathCloud it's almost 4 *times* slower, so half
of an order of magnitude:

https://cloud.sagemath.com/projects/4a5f0542-5873-4eed-a85c-a18c706e8bcd/files/support/2015-01-19-expand-speed.sagews

Since that expression is large, the cache size of the CPU might
significantly impact performance.

William



 BTW another way is to use polynomials over SR, for about the same
 speed but without number field restrictions.


 Regards,

 --
 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.


Re: [sage-devel] The fastest way to expand((a1+a2+a3+a4+sqrt(3)*a5)^25)

2015-01-19 Thread William Stein
On Mon, Jan 19, 2015 at 9:46 AM, Ralf Stephan gtrw...@gmail.com wrote:
 What is here?


 AMD Phenom 3GHz, 8GB RAM, no other big jobs

 Since that expression is large, the cache size of the CPU might
 significantly impact performance.


 Wouldn't that affect any of the following?

 │ Sage Version 6.5.beta5, Release Date: 2015-01-05   │
 │ Type notebook() for the browser-based notebook interface.│
 │ Type help() for help.│
 └┘
 ┏┓
 ┃ Warning: this is a prerelease version, and it may be unstable. ┃
 ┗┛
 sage: K.sqrt3 = QuadraticField(3)
 sage: R.a1,a2,a3,a4,a5 = K[]
 sage: timeit((a1+a2+a3+a4+sqrt3*a5)^25)
 5 loops, best of 3: 140 ms per loop
 sage: a1,a2,a3,a4,a5=var('a1,a2,a3,a4,a5')
 sage: timeit(ex=expand((a1+a2+a3+a4+sqrt(3)*a5)^25))
 5 loops, best of 3: 5.29 s per loop

That expand above is probably the problem.  When you evaluate

   (a1+a2+a3+a4+sqrt3*a5)^25

it is *already* expanded.  Doing an additional expand isn't necessary.
It should be ano-op.  In fact,

 sage: timeit(ex=expand((a1+a2+a3+a4+sqrt(3)*a5)^25))
 5 loops, best of 3: 5.29 s per loop

should take the same time as the previous line and without the
assignment it *does*:

sage: timeit(expand((a1+a2+a3+a4+sqrt3*a5)^25))
FAST

But with the assignment it takes way longer.  Hence I suspect some
issue with memory management... no clue though.



 I was wrong in the poly(SR) case. That's even slower than SR.expand():

 sage: R.a1,a2,a3,a4,a5 = PolynomialRing(SR, 'a1,a2,a3,a4,a5')
 sage: %time p=(a1+a2+a3+a4+sqrt(3)*a5)^25
 stopped after a minute

 --
 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.


Re: [sage-devel] The fastest way to expand((a1+a2+a3+a4+sqrt(3)*a5)^25)

2015-01-19 Thread Ondřej Čertík
On Mon, Jan 19, 2015 at 11:19 AM, Ondřej Čertík ondrej.cer...@gmail.com wrote:
 Hi Vincent,

 On Sun, Jan 18, 2015 at 10:06 AM, Vincent Delecroix
 20100.delecr...@gmail.com wrote:
 Hi,

 2015-01-18 18:03 UTC+01:00, Ondřej Čertík ondrej.cer...@gmail.com:
 Can you invent an example, that can't be converted to polynomials?
 Perhaps (a1+a2+a3+sqrt(5)*a4+sqrt(3)*a5)^25?

 Still doable. You need to involve log, exp, cos or similar
 transcendental functions.

 Can you show me how to do that? I tried:

 sage: K.sqrt3 = QuadraticField(3)
 sage: K.sqrt5 = QuadraticField(5)
 sage: R.a1,a2,a3,a4,a5 = K[]
 sage: time f = (a1+a2+a3+sqrt5*a4+sqrt3*a5)^25

 But I got:

 TypeError: unsupported operand parent(s) for '*': 'Number Field in
 sqrt3 with defining polynomial x^2 - 3' and 'Multivariate Polynomial
 Ring in a1, a2
 , a3, a4, a5 over Number Field in sqrt5 with defining polynomial x^2 - 5'

 Full stacktrace here:

 https://gist.github.com/certik/a7f2434820f8dbf890b9


I think I figured it out:

sage: K.sqrt3 = QuadraticField(3)
sage: L.sqrt5 = K.extension(x^2-5)
sage: R.a1,a2,a3,a4,a5 = L[]
sage: time f = (a1+a2+a3+sqrt5*a4+sqrt3*a5)^18
CPU times: user 2.43 s, sys: 3.94 ms, total: 2.44 s
Wall time: 2.44 s

(I did smaller exponent so that it finishes.)

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.


Re: [sage-devel] The fastest way to expand((a1+a2+a3+a4+sqrt(3)*a5)^25)

2015-01-19 Thread Vincent Delecroix
Hello Ondrej,

For such questions of Sage usage, it is better to discuss on
ask.sagemath.org or sage-support.

You can also deal with all algebraic numbers at once with QQbar

sage: sqrt3 = QQbar(sqrt(3))
sage: sqrt5 = QQbar(sqrt(5))

But then polynomials over QQbar are much slower.

Vincent

2015-01-19 19:24 UTC+01:00, Ondřej Čertík ondrej.cer...@gmail.com:
 On Mon, Jan 19, 2015 at 11:19 AM, Ondřej Čertík ondrej.cer...@gmail.com
 wrote:
 Hi Vincent,

 On Sun, Jan 18, 2015 at 10:06 AM, Vincent Delecroix
 20100.delecr...@gmail.com wrote:
 Hi,

 2015-01-18 18:03 UTC+01:00, Ondřej Čertík ondrej.cer...@gmail.com:
 Can you invent an example, that can't be converted to polynomials?
 Perhaps (a1+a2+a3+sqrt(5)*a4+sqrt(3)*a5)^25?

 Still doable. You need to involve log, exp, cos or similar
 transcendental functions.

 Can you show me how to do that? I tried:

 sage: K.sqrt3 = QuadraticField(3)
 sage: K.sqrt5 = QuadraticField(5)
 sage: R.a1,a2,a3,a4,a5 = K[]
 sage: time f = (a1+a2+a3+sqrt5*a4+sqrt3*a5)^25

 But I got:

 TypeError: unsupported operand parent(s) for '*': 'Number Field in
 sqrt3 with defining polynomial x^2 - 3' and 'Multivariate Polynomial
 Ring in a1, a2
 , a3, a4, a5 over Number Field in sqrt5 with defining polynomial x^2 - 5'

 Full stacktrace here:

 https://gist.github.com/certik/a7f2434820f8dbf890b9


 I think I figured it out:

 sage: K.sqrt3 = QuadraticField(3)
 sage: L.sqrt5 = K.extension(x^2-5)
 sage: R.a1,a2,a3,a4,a5 = L[]
 sage: time f = (a1+a2+a3+sqrt5*a4+sqrt3*a5)^18
 CPU times: user 2.43 s, sys: 3.94 ms, total: 2.44 s
 Wall time: 2.44 s

 (I did smaller exponent so that it finishes.)

 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.


-- 
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.


Re: [sage-devel] The fastest way to expand((a1+a2+a3+a4+sqrt(3)*a5)^25)

2015-01-19 Thread Ondřej Čertík
Hi Vincent,

On Mon, Jan 19, 2015 at 11:30 AM, Vincent Delecroix
20100.delecr...@gmail.com wrote:
 Hello Ondrej,

 For such questions of Sage usage, it is better to discuss on
 ask.sagemath.org or sage-support.

 You can also deal with all algebraic numbers at once with QQbar

 sage: sqrt3 = QQbar(sqrt(3))
 sage: sqrt5 = QQbar(sqrt(5))

 But then polynomials over QQbar are much slower.

Thanks, I'll ask there the next time. Since I started the thread here,
I'll keep it here so that everything is in one place.

So if you agree that I did things correctly, let's compare timings
(and lengths of expressions --- any idea how to get the number of
terms in a better way in Sage?):

sage: K.sqrt3 = QuadraticField(3)
sage: L.sqrt5 = K.extension(x^2-5)
sage: R.a1,a2,a3,a4,a5 = L[]
sage: time f = (a1+a2+a3+sqrt5*a4+sqrt3*a5)^18
CPU times: user 2.43 s, sys: 3.94 ms, total: 2.44 s
Wall time: 2.44 s
sage: len(str(f).split(+))
7315

Now compare this to CSymPy:


In [1]: from csympy import *

In [2]: var('a1 a2 a3 a4 a5 a6 a7')
Out[2]: (a1, a2, a3, a4, a5, a6, a7)

In [3]: %time f = ((a1+a2+a3+sqrt(5)*a4+sqrt(3)*a5)**18).expand()
CPU times: user 125 ms, sys: 7.73 ms, total: 133 ms
Wall time: 133 ms

In [4]: len(f.args)
Out[4]: 7315


You can also compare this to Sage symbolics (which should use the same
algorithm as CSymPy):


sage: var('a1 a2 a3 a4 a5 a6 a7')
(a1, a2, a3, a4, a5, a6, a7)
sage: %time f = ((a1+a2+a3+sqrt(5)*a4+sqrt(3)*a5)**18).expand()
CPU times: user 4.98 s, sys: 76.4 ms, total: 5.05 s
Wall time: 4.95 s
sage: len(f.operands())
7315


Which is also very slow.

I will try this in ginac directly, as that's what pynac is forked
from, maybe it's just the Python overhead. Also, I will carefully
check that we don't have a bug in csympy.

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.


Re: [sage-devel] The fastest way to expand((a1+a2+a3+a4+sqrt(3)*a5)^25)

2015-01-19 Thread Ondřej Čertík
Hi Vincent,

On Sun, Jan 18, 2015 at 10:06 AM, Vincent Delecroix
20100.delecr...@gmail.com wrote:
 Hi,

 2015-01-18 18:03 UTC+01:00, Ondřej Čertík ondrej.cer...@gmail.com:
 Can you invent an example, that can't be converted to polynomials?
 Perhaps (a1+a2+a3+sqrt(5)*a4+sqrt(3)*a5)^25?

 Still doable. You need to involve log, exp, cos or similar
 transcendental functions.

Can you show me how to do that? I tried:

sage: K.sqrt3 = QuadraticField(3)
sage: K.sqrt5 = QuadraticField(5)
sage: R.a1,a2,a3,a4,a5 = K[]
sage: time f = (a1+a2+a3+sqrt5*a4+sqrt3*a5)^25

But I got:

TypeError: unsupported operand parent(s) for '*': 'Number Field in
sqrt3 with defining polynomial x^2 - 3' and 'Multivariate Polynomial
Ring in a1, a2
, a3, a4, a5 over Number Field in sqrt5 with defining polynomial x^2 - 5'

Full stacktrace here:

https://gist.github.com/certik/a7f2434820f8dbf890b9


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.


Re: [sage-devel] The fastest way to expand((a1+a2+a3+a4+sqrt(3)*a5)^25)

2015-01-19 Thread Nils Bruin
On Monday, January 19, 2015 at 9:46:47 AM UTC-8, Ralf Stephan wrote:

 What is here? 

  
 AMD Phenom 3GHz, 8GB RAM, no other big jobs


On Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz I'm getting the same times as 
Vincent. That's on 6.5beta4 or 5.

The difference you're reporting is very large. You might want to check your 
sage build. Or otherwise sell your timing results to Intel to finance the 
purchase of another computer.
 


 I was wrong in the poly(SR) case. That's even slower than SR.expand():

 sage: R.a1,a2,a3,a4,a5 = PolynomialRing(SR, 'a1,a2,a3,a4,a5')
 sage: %time p=(a1+a2+a3+a4+sqrt(3)*a5)^25
 stopped after a minute


 Yes, I would expect that SR is *much* slower for computing in Q(sqrt(3)) 
than PARI is:

sage: K.sqrt3 = QuadraticField(3)
sage: s=sqrt(3)
sage: %timeit (sqrt3+1)^25
10 loops, best of 3: 5.32 µs per loop
sage: %timeit ((s+1)^25).expand()
100 loops, best of 3: 5.85 ms per loop


-- 
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.


Re: [sage-devel] The fastest way to expand((a1+a2+a3+a4+sqrt(3)*a5)^25)

2015-01-19 Thread William Stein
On Mon, Jan 19, 2015 at 10:32 AM, Nils Bruin nbr...@sfu.ca wrote:
 On Monday, January 19, 2015 at 9:46:47 AM UTC-8, Ralf Stephan wrote:

 What is here?


 AMD Phenom 3GHz, 8GB RAM, no other big jobs


 On Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz I'm getting the same times as
 Vincent. That's on 6.5beta4 or 5.

 The difference you're reporting is very large. You might want to check your
 sage build. Or otherwise sell your timing results to Intel to finance the
 purchase of another computer.

Nils, did you specifically try this **exact input**??

sage: timeit(ex=expand((a1+a2+a3+a4+sqrt(3)*a5)^25))
5 loops, best of 3: 5.29 s per loop




 I was wrong in the poly(SR) case. That's even slower than SR.expand():

 sage: R.a1,a2,a3,a4,a5 = PolynomialRing(SR, 'a1,a2,a3,a4,a5')
 sage: %time p=(a1+a2+a3+a4+sqrt(3)*a5)^25
 stopped after a minute


  Yes, I would expect that SR is *much* slower for computing in Q(sqrt(3))
 than PARI is:

 sage: K.sqrt3 = QuadraticField(3)
 sage: s=sqrt(3)
 sage: %timeit (sqrt3+1)^25
 10 loops, best of 3: 5.32 µs per loop
 sage: %timeit ((s+1)^25).expand()
 100 loops, best of 3: 5.85 ms per loop


 --
 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.


Re: [sage-devel] The fastest way to expand((a1+a2+a3+a4+sqrt(3)*a5)^25)

2015-01-19 Thread Nils Bruin


On Monday, January 19, 2015 at 10:35:42 AM UTC-8, William wrote:


 Nils, did you specifically try this **exact input**?? 


Full session:

sage: sage: K.sqrt3 = QuadraticField(3)
sage: sage: R.a1,a2,a3,a4,a5 = K[]
sage: sage: timeit((a1+a2+a3+a4+sqrt3*a5)^25) 
5 loops, best of 3: 79.9 ms per loop
sage: sage: timeit(ex=(a1+a2+a3+a4+sqrt3*a5)^25)
5 loops, best of 3: 80.4 ms per loop
sage: sage: timeit(ex=expand((a1+a2+a3+a4+sqrt3*a5)^25))
5 loops, best of 3: 80.5 ms per loop
sage: sage: timeit(expand((a1+a2+a3+a4+sqrt3*a5)^25))
5 loops, best of 3: 79.6 ms per loop

version:

commit b1287e75962a2dc590f1fa22acc90a4e53383aab
Merge: 99ec4cc 106f5d4
Author: Jeroen Demeyer
Date:   Mon Jan 12 13:51:07 2015 +0100

Merge branch 'ticket/17561' into ticket/10513

Conflicts:
src/sage/modules/free_module_element.pyx

commit 106f5d41398794b13a6a683236cf219d49602312
Author: Jeroen Demeyer
Date:   Sat Jan 3 11:04:51 2015 +0100

Minor improvements in FreeModuleElement_generic_sparse.__init__

commit 99ec4cc13099658e0bc762a6e8d230c3956c7150
Author: Peter Bruin
Date:   Sat Jan 3 09:40:54 2015 +0100

Trac 10513: revert a change in try...except

commit df0fb69e1aa9ab205e35b98ad6d97d0c67b889af
Author: Jeroen Demeyer
Date:   Mon Dec 29 09:19:24 2014 +0100

Declare types of _entries

commit 5bf671225b38a8efd55a662a8c967767ac85c7db
Author: Volker Braun
Date:   Sun Dec 21 22:47:26 2014 +0100

Updated Sage version to 6.5.beta4

-- 
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.


Re: [sage-devel] The fastest way to expand((a1+a2+a3+a4+sqrt(3)*a5)^25)

2015-01-19 Thread Vincent Delecroix
The computation in pari (directed from Sage):

sage: x=pari(x)
sage: y=pari(y)
sage: sqrt3=pari(Mod)(x, x^2-3)
sage: sqrt5=pari(Mod)(y, y^2-5)
sage: a1=pari(a1)
sage: a2=pari(a2)
sage: a3=pari(a3)
sage: a4=pari(a4)
sage: a5=pari(a5)
sage: time f = (a1+a2+a3+sqrt5*a4+sqrt3*a5)**18
CPU times: user 148 ms, sys: 0 ns, total: 148 ms
Wall time: 146 ms
sage: len(str(f).split(+))
7315

But in pari, it is not very elegant to see as there is no real support
for polynomials over several variables.

My conclusion is that generic polynomials in Sage are very slow!

Vincent

2015-01-19 19:53 UTC+01:00, William Stein wst...@gmail.com:
 On Mon, Jan 19, 2015 at 10:47 AM, Nils Bruin nbr...@sfu.ca wrote:
 Nils, did you specifically try this **exact input**??


 Full session:

 sage: sage: K.sqrt3 = QuadraticField(3)
 sage: sage: R.a1,a2,a3,a4,a5 = K[]
 sage: sage: timeit((a1+a2+a3+a4+sqrt3*a5)^25)
 5 loops, best of 3: 79.9 ms per loop
 sage: sage: timeit(ex=(a1+a2+a3+a4+sqrt3*a5)^25)
 5 loops, best of 3: 80.4 ms per loop
 sage: sage: timeit(ex=expand((a1+a2+a3+a4+sqrt3*a5)^25))
 5 loops, best of 3: 80.5 ms per loop
 sage: sage: timeit(expand((a1+a2+a3+a4+sqrt3*a5)^25))
 5 loops, best of 3: 79.6 ms per loop

 version:

 Thanks.  I tried again and found that

timeit(ex=expand((a1+a2+a3+a4+sqrt3*a5)^25))

 is (of course) the same speed as

timeit((a1+a2+a3+a4+sqrt3*a5)^25)

 in my tests.(I was in a spouse-induced hurry before.)

 William


 commit b1287e75962a2dc590f1fa22acc90a4e53383aab
 Merge: 99ec4cc 106f5d4
 Author: Jeroen Demeyer
 Date:   Mon Jan 12 13:51:07 2015 +0100

 Merge branch 'ticket/17561' into ticket/10513

 Conflicts:
 src/sage/modules/free_module_element.pyx

 commit 106f5d41398794b13a6a683236cf219d49602312
 Author: Jeroen Demeyer
 Date:   Sat Jan 3 11:04:51 2015 +0100

 Minor improvements in FreeModuleElement_generic_sparse.__init__

 commit 99ec4cc13099658e0bc762a6e8d230c3956c7150
 Author: Peter Bruin
 Date:   Sat Jan 3 09:40:54 2015 +0100

 Trac 10513: revert a change in try...except

 commit df0fb69e1aa9ab205e35b98ad6d97d0c67b889af
 Author: Jeroen Demeyer
 Date:   Mon Dec 29 09:19:24 2014 +0100

 Declare types of _entries

 commit 5bf671225b38a8efd55a662a8c967767ac85c7db
 Author: Volker Braun
 Date:   Sun Dec 21 22:47:26 2014 +0100

 Updated Sage version to 6.5.beta4

 --
 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.


-- 
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.


Re: [sage-devel] The fastest way to expand((a1+a2+a3+a4+sqrt(3)*a5)^25)

2015-01-18 Thread Vincent Delecroix
Your example can be reduced to polynomials

sage: K.sqrt3 = QuadraticField(3)
sage: R.a1,a2,a3,a4,a5 = K[]
sage: timeit((a1+a2+a3+a4+sqrt3*a5)^25)
5 loops, best of 3: 81 ms per loop

(And just for completeness, the symbolic expansion on my laptop took 4.54s)

Vincent

2015-01-18 7:26 UTC+01:00, Ondřej Čertík ondrej.cer...@gmail.com:
 Hi,

 I was wondering what the fastest way is to do this benchmark in Sage:

 ┌┐
 │ Sage Version 6.4, Release Date: 2014-11-14 │
 │ Enhanced for SageMathCloud.│
 └┘
 sage: var('a1 a2 a3 a4 a5 a6 a7')
 (a1, a2, a3, a4, a5, a6, a7)
 sage: time f = expand((a1+a2+a3+a4+sqrt(3)*a5)^25)
 CPU times: user 9.02 s, sys: 281 ms, total: 9.3 s
 Wall time: 8.91 s
 sage: len(f.operands())
 23751


 I took the Expanding a Symbolic Expression from
 http://www.sagemath.org/tour-benchmarks.html, but made it shorter and
 added sqrt(3) in there. I tried to use the polynomials way, i.e.
 R.a1,a2,a3,a4,a5,a6,a7 = QQ[], but that didn't expand it at all. The
 above is using SMC.

 On my slow laptop, using our CSymPy library
 (https://github.com/sympy/csympy), written in C++, I get:

 In [4]: time f = ((a1+a2+a3+a4+sqrt(3)*a5)**25).expand()
 CPU times: user 201 ms, sys: 23.9 ms, total: 225 ms
 Wall time: 226 ms

 In [5]: len(f.args)
 Out[5]: 23751

 Which is almost 40x faster.

 Essentially I am wondering, if there is any software in Sage that can
 do this faster. In other words, whether this is a good benchmark to
 test general symbolic manipulation, that cannot be trivially converted
 to a polynomial manipulation (for which there are great libraries out
 there, that one should just call).

 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.


-- 
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.


Re: [sage-devel] The fastest way to expand((a1+a2+a3+a4+sqrt(3)*a5)^25)

2015-01-18 Thread Vincent Delecroix
Hi,

2015-01-18 18:03 UTC+01:00, Ondřej Čertík ondrej.cer...@gmail.com:
 Can you invent an example, that can't be converted to polynomials?
 Perhaps (a1+a2+a3+sqrt(5)*a4+sqrt(3)*a5)^25?

Still doable. You need to involve log, exp, cos or similar
transcendental functions.

Vincent

-- 
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.


Re: [sage-devel] The fastest way to expand((a1+a2+a3+a4+sqrt(3)*a5)^25)

2015-01-18 Thread Ondřej Čertík
Hi Vincent,

On Sun, Jan 18, 2015 at 1:18 AM, Vincent Delecroix
20100.delecr...@gmail.com wrote:
 Your example can be reduced to polynomials

 sage: K.sqrt3 = QuadraticField(3)
 sage: R.a1,a2,a3,a4,a5 = K[]
 sage: timeit((a1+a2+a3+a4+sqrt3*a5)^25)
 5 loops, best of 3: 81 ms per loop

That's cool, I wasn't aware you can do that. Thanks.

Can you invent an example, that can't be converted to polynomials?
Perhaps (a1+a2+a3+sqrt(5)*a4+sqrt(3)*a5)^25?

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.


[sage-devel] The fastest way to expand((a1+a2+a3+a4+sqrt(3)*a5)^25)

2015-01-17 Thread Ondřej Čertík
Hi,

I was wondering what the fastest way is to do this benchmark in Sage:

┌┐
│ Sage Version 6.4, Release Date: 2014-11-14 │
│ Enhanced for SageMathCloud.│
└┘
sage: var('a1 a2 a3 a4 a5 a6 a7')
(a1, a2, a3, a4, a5, a6, a7)
sage: time f = expand((a1+a2+a3+a4+sqrt(3)*a5)^25)
CPU times: user 9.02 s, sys: 281 ms, total: 9.3 s
Wall time: 8.91 s
sage: len(f.operands())
23751


I took the Expanding a Symbolic Expression from
http://www.sagemath.org/tour-benchmarks.html, but made it shorter and
added sqrt(3) in there. I tried to use the polynomials way, i.e.
R.a1,a2,a3,a4,a5,a6,a7 = QQ[], but that didn't expand it at all. The
above is using SMC.

On my slow laptop, using our CSymPy library
(https://github.com/sympy/csympy), written in C++, I get:

In [4]: time f = ((a1+a2+a3+a4+sqrt(3)*a5)**25).expand()
CPU times: user 201 ms, sys: 23.9 ms, total: 225 ms
Wall time: 226 ms

In [5]: len(f.args)
Out[5]: 23751

Which is almost 40x faster.

Essentially I am wondering, if there is any software in Sage that can
do this faster. In other words, whether this is a good benchmark to
test general symbolic manipulation, that cannot be trivially converted
to a polynomial manipulation (for which there are great libraries out
there, that one should just call).

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.