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.


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

2015-01-19 Thread parisse
A perhaps more interesting benchmark : how long does it take to factor it 
back?

-- 
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  wrote:
> It is much faster to work with absolute fields instead of towers of
> extensions:
>
> sage: K.=QuadraticField(3)
> sage: F.=K.extension(x^2-5)
> sage: R. = 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.=F.absolute_field()
> sage: fsqrt3=FF(F(sqrt3))
> sage: fsqrt5=FF(sqrt5)
> sage: RR. = 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.=QuadraticField(3)
sage: F.=K.extension(x^2-5)
sage: R. = 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.=F.absolute_field()
sage: fsqrt3=FF(F(sqrt3))
sage: fsqrt5=FF(sqrt5)
sage: RR. = 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] Re: inherit group from monoid

2015-01-19 Thread Robert Bradshaw
On Sun, Jan 18, 2015 at 2:17 AM, Nicolas M. Thiery
 wrote:
> Hi Robert,
>
> On Tue, Jan 13, 2015 at 06:11:09PM -0800, Robert Bradshaw wrote:
>> :). It might be possible, but it'd be really, really messy (messier
>> than it is in C++, because one needs the shared PyObject_HEAD to be
>> correctly accessed by all the Python C API framework).
>
> Didn't you mention at some point that, for purely abstract classes
> (like those from categories), this would be not so bad?

True. Or the diamond pattern without any members added along one of
the branches. But there's still the issue that if I had

cdef class A(object): pass
cdef class B(object): pass

and someone else wrote

cdef class C(A, B): ...

now adding members to A and B would unknowingly break C which used to be valid.

- Robert

-- 
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.=QuadraticField(3)
sage: F.=K.extension(x^2-5)
sage: R. = 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.=F.absolute_field()
sage: fsqrt3=FF(F(sqrt3))
sage: fsqrt5=FF(sqrt5)
sage: RR. = 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.


[sage-devel] Re: How does the ECL+Maxima combination work ?

2015-01-19 Thread Robert Dodier
On 2015-01-19, Nils Bruin  wrote:

>> (require `maxima)
> [...]
>> (in-package :maxima)
> MAXIMA> #$2+2$ 
>
> 4
> MAXIMA> '#$x+5$
>
> (MEVAL* '((MPLUS) $X 5))
> MAXIMA> (meval '((mplus) 2 2))
>
> 4

One more thing that might be relevant in this context. You can call
the DISPLA (note the lack of a trailing y) function to pretty print
a Maxima expression. E.g.

  MAXIMA> (displa '((mplus) 2 2))
   => 2 + 2

Of course it works equally well with the output of some operation:

  MAXIMA> (displa (meval* '((mplus) $x $x)))
   => 2 x

Maxima is a many-splendored thing but I'll leave it at that for now.

best,

Robert Dodier

-- 
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 :
> On Mon, Jan 19, 2015 at 10:47 AM, Nils Bruin  wrote:
>>> Nils, did you specifically try this **exact input**??
>>
>>
>> Full session:
>>
>> sage: sage: K. = QuadraticField(3)
>> sage: sage: R. = 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-19 Thread William Stein
On Mon, Jan 19, 2015 at 10:47 AM, Nils Bruin  wrote:
>> Nils, did you specifically try this **exact input**??
>
>
> Full session:
>
> sage: sage: K. = QuadraticField(3)
> sage: sage: R. = 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.


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. = QuadraticField(3)
sage: sage: R. = 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 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. = QuadraticField(3)
sage: L. = K.extension(x^2-5)
sage: R. = 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 William Stein
On Mon, Jan 19, 2015 at 10:32 AM, Nils Bruin  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. = 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. = 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 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. = 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. = 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 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 :
> On Mon, Jan 19, 2015 at 11:19 AM, Ondřej Čertík 
> 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 :
 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. = QuadraticField(3)
>> sage: K. = QuadraticField(5)
>> sage: R. = 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. = QuadraticField(3)
> sage: L. = K.extension(x^2-5)
> sage: R. = 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
On Mon, Jan 19, 2015 at 11:19 AM, Ondřej Čertík  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 :
>>> 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. = QuadraticField(3)
> sage: K. = QuadraticField(5)
> sage: R. = 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. = QuadraticField(3)
sage: L. = K.extension(x^2-5)
sage: R. = 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 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 :
>> 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. = QuadraticField(3)
sage: K. = QuadraticField(5)
sage: R. = 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 William Stein
On Mon, Jan 19, 2015 at 9:46 AM, Ralf Stephan  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. = QuadraticField(3)
> sage: R. = 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. = 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 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. = QuadraticField(3)
sage: R. = 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. = 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 William Stein
On Mon, Jan 19, 2015 at 8:55 AM, Ralf Stephan  wrote:
> On Sunday, January 18, 2015 at 9:18:53 AM UTC+1, vdelecroix wrote:
>>
>> Your example can be reduced to polynomials
>>
>> sage: K. = QuadraticField(3)
>> sage: R. = 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 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. = QuadraticField(3) 
> sage: R. = 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.


[sage-devel] Re: How does the ECL+Maxima combination work ?

2015-01-19 Thread Nils Bruin
On Monday, January 19, 2015 at 8:22:15 AM UTC-8, Dima Pasechnik wrote:
>
> On 2015-01-19, Julien Puydt > wrote: 
> > Hi, 
> > 
> > I wanted to play with maxima-in-ecl to understand how it works, but 
> > failed: from reading sage's sources I thought I was supposed to use a 
> > MEVAL function, but it failed. Here is what I did: 
> > 
> > jpuydt@cauchy:~/sage-6.4.1$ ./sage -ecl 
> > ECL (Embeddable Common-Lisp) 13.5.1 (git:UNKNOWN) 
> > Copyright (C) 1984 Taiichi Yuasa and Masami Hagiya 
> > Copyright (C) 1993 Giuseppe Attardi 
> > Copyright (C) 2000 Juan J. Garcia-Ripoll 
> > ECL is free software, and you are welcome to redistribute it 
> > under certain conditions; see file 'Copyright' for details. 
> > Type :h for Help. 
> > Top level. 
> > > (require 'maxima) 
> > 
> > ;;; Loading #P"/home/jpuydt/sage-6.4.1/local/lib/ecl/maxima.fas" 
> > ;;; Loading #P"/home/jpuydt/sage-6.4.1/local/lib/ecl/sb-bsd-sockets.fas" 
> > ;;; Loading #P"/home/jpuydt/sage-6.4.1/local/lib/ecl/sockets.fas" 
> > ("SB-BSD-SOCKETS" "SOCKETS" "MAXIMA") 
>
> here you need to go into the right namespace, or whatever it is called: 
>
> > (in-package :maxima) 
>
> > > (meval "2+2") 
>
> but I don't know how to compute 2+2, still :-)) 
>
>  
The maxima parser is available via the reader macro. Normally it will 
produce a form that evaluates too, but if you quote it, you can prevent 
that from happening:

> (require `maxima)
[...]
> (in-package :maxima)
MAXIMA> #$2+2$ 

4
MAXIMA> '#$x+5$

(MEVAL* '((MPLUS) $X 5))
MAXIMA> (meval '((mplus) 2 2))

4

See the maxima source for the (subtle and as far as I can see largely 
irrelevant) differences between meval and meval*.

The key thing to realize is that the maxima language gets parsed into lisp 
expressions (that's what they are for!) and that you can enter those 
expressions yourself once you've figured out what structure is expected: 
it's always:

( ( [   )  ... )

so it's almost lisp syntax, except that the operator slot is *itself* a 
list too to allow for flags marking properties of the expression. This 
feature doesn't get used much, and the "SIMP" flags hardly seem to make any 
difference in practice when you enter an expression.

-- 
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] Re: How does the ECL+Maxima combination work ?

2015-01-19 Thread Dima Pasechnik
On 2015-01-19, Julien Puydt  wrote:
> Hi,
>
> I wanted to play with maxima-in-ecl to understand how it works, but 
> failed: from reading sage's sources I thought I was supposed to use a 
> MEVAL function, but it failed. Here is what I did:
>
> jpuydt@cauchy:~/sage-6.4.1$ ./sage -ecl
> ECL (Embeddable Common-Lisp) 13.5.1 (git:UNKNOWN)
> Copyright (C) 1984 Taiichi Yuasa and Masami Hagiya
> Copyright (C) 1993 Giuseppe Attardi
> Copyright (C) 2000 Juan J. Garcia-Ripoll
> ECL is free software, and you are welcome to redistribute it
> under certain conditions; see file 'Copyright' for details.
> Type :h for Help.
> Top level.
> > (require 'maxima)
>
> ;;; Loading #P"/home/jpuydt/sage-6.4.1/local/lib/ecl/maxima.fas"
> ;;; Loading #P"/home/jpuydt/sage-6.4.1/local/lib/ecl/sb-bsd-sockets.fas"
> ;;; Loading #P"/home/jpuydt/sage-6.4.1/local/lib/ecl/sockets.fas"
> ("SB-BSD-SOCKETS" "SOCKETS" "MAXIMA")

here you need to go into the right namespace, or whatever it is called:

> (in-package :maxima)

> > (meval "2+2")

but I don't know how to compute 2+2, still :-))

Dima
>
> Condition of type: UNDEFINED-FUNCTION
> The function MEVAL is undefined.
>
> Available restarts:
>
> 1. (RESTART-TOPLEVEL) Go back to Top-Level REPL.
>
> Broken at SI:BYTECODES. [Evaluation of: (MEVAL "2+2")]
>
>
> What did I do wrong ?
>
> Snark on #sagemath
>

-- 
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] How does the ECL+Maxima combination work ?

2015-01-19 Thread Julien Puydt

Hi,

I wanted to play with maxima-in-ecl to understand how it works, but 
failed: from reading sage's sources I thought I was supposed to use a 
MEVAL function, but it failed. Here is what I did:


jpuydt@cauchy:~/sage-6.4.1$ ./sage -ecl
ECL (Embeddable Common-Lisp) 13.5.1 (git:UNKNOWN)
Copyright (C) 1984 Taiichi Yuasa and Masami Hagiya
Copyright (C) 1993 Giuseppe Attardi
Copyright (C) 2000 Juan J. Garcia-Ripoll
ECL is free software, and you are welcome to redistribute it
under certain conditions; see file 'Copyright' for details.
Type :h for Help.
Top level.
> (require 'maxima)

;;; Loading #P"/home/jpuydt/sage-6.4.1/local/lib/ecl/maxima.fas"
;;; Loading #P"/home/jpuydt/sage-6.4.1/local/lib/ecl/sb-bsd-sockets.fas"
;;; Loading #P"/home/jpuydt/sage-6.4.1/local/lib/ecl/sockets.fas"
("SB-BSD-SOCKETS" "SOCKETS" "MAXIMA")
> (meval "2+2")

Condition of type: UNDEFINED-FUNCTION
The function MEVAL is undefined.

Available restarts:

1. (RESTART-TOPLEVEL) Go back to Top-Level REPL.

Broken at SI:BYTECODES. [Evaluation of: (MEVAL "2+2")]


What did I do wrong ?

Snark on #sagemath

--
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] Dashes in software name or version number

2015-01-19 Thread Jeroen Demeyer
I believe dashes can appear in the version number (Singular-x-y-z should 
be safe) but not in the package name.


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