CoCalc Shared Filessupport / 2015-01-19-expand-speed.sagews
Authors: Harald Schilly, ℏal Snyder, William A. Stein
Description: Examples for support purposes.
K.<sqrt3> = QuadraticField(3)
R.<a1,a2,a3,a4,a5> = K[]
timeit("(a1+a2+a3+a4+sqrt3*a5)^25")

5 loops, best of 3: 317 ms per loop
317/80.

3.96250000000000
!hostname

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

960153
%timeit (a1+a2+a3+a4+sqrt3*a5)^2

625 loops, best of 3: 145 µs per loop
%timeit expand((a1+a2+a3+a4+sqrt3*a5)^2)

625 loops, best of 3: 156 µs per loop

expand(a1+a2)

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

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

Error in lines 1-1 Traceback (most recent call last): File "/projects/4a5f0542-5873-4eed-a85c-a18c706e8bcd/.sagemathcloud/sage_server.py", line 876, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> File "/projects/4a5f0542-5873-4eed-a85c-a18c706e8bcd/.sagemathcloud/sage_salvus.py", line 1482, in timeit go(*args) File "/projects/4a5f0542-5873-4eed-a85c-a18c706e8bcd/.sagemathcloud/sage_salvus.py", line 1478, in go print sage.misc.sage_timeit.sage_timeit(code, globals_dict=salvus.namespace, **kwds) File "/usr/local/sage/sage-6.4/local/lib/python2.7/site-packages/sage/misc/sage_timeit.py", line 242, in sage_timeit series = [s/number for s in timer.repeat(repeat, number)] File "/usr/local/sage/sage-6.4/local/lib/python/timeit.py", line 223, in repeat t = self.timeit(number) File "/usr/local/sage/sage-6.4/local/lib/python/timeit.py", line 195, in timeit timing = self.inner(it, self.timer) File "<magic-timeit>", line 6, in inner File "/usr/local/sage/sage-6.4/local/lib/python2.7/site-packages/sage/calculus/functional.py", line 433, in expand return x.expand(*args, **kwds) File "sage/symbolic/expression.pyx", line 3787, in sage.symbolic.expression.Expression.expand (build/cythonized/sage/symbolic/expression.cpp:22037) File "sage/ext/c_lib.pyx", line 73, in sage.ext.c_lib.sig_raise_exception (build/cythonized/sage/ext/c_lib.c:769) KeyboardInterrupt