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.

Reply via email to