ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 05 Sep 2022 19:38:04 +0200The performance speed of "len(str(n))" method and "a^b % p" method in Sagehttps://ask.sagemath.org/question/63916/the-performance-speed-of-lenstrn-method-and-ab-p-method-in-sage/
Hi.
Using the same Jupyter Notebook, I've found that identical codes between SageMath and Python turns out that
the running time of SageMath shows up much faster than the same code written in Python.
Those codes are as follows.
import timeit
def modular():
return 3**10000000 % (2**127-1)
def countlength():
return len(str(3**10000000))
print(timeit.timeit(modular, number=1))
print(timeit.timeit(countlength, number=1))
In SageMath, the running time is less than 1 second for both functions.
On the other hand, the running time for "modular' is 5 times slower in Python and for the "countlengh" function,
there isn't even an answer from Python.
It makes me curious, what's the magic behind the speed of SageMath?
Recently I'm working on algorithm and coding optimization so any advice from a senior would be grateful.
Thanks.
VibapMon, 05 Sep 2022 19:38:04 +0200https://ask.sagemath.org/question/63916/Running time increment of repeating 'zsolve' in 4ti2https://ask.sagemath.org/question/52233/running-time-increment-of-repeating-zsolve-in-4ti2/I found an interesting phenomenon about zsolve in 4ti2. Here is the sample code.
from sage.interfaces.four_ti_2 import four_ti_2
import time
A = [[1,1,1],[1,2,3]]
rel = ['<', '<']
rhs = [2, 3]
sign = [1,1,1]
for i in range(1000):
start = time.time()
result=four_ti_2.zsolve(A, rel, rhs, sign)
print("Running time for zsolve in 4ti2:", time.time()-start," sec")
I expected that except for the first iteration, which needs time for loading the library at first time on the memory, all iterations should take statistically consistent time with some noise following a normal distribution. However, What I got is a chart showing that running time is increasing linearly, with some noises. You can see the chart on the comment (Due to my insufficient Karma, I cannot make a hyperlink for the chart. You can see it in the comment.)
As you can see from the chart, the running time is increasing while the operation itself still the same. Could anyone explains why this phenomenon happens and how to prevent it to minimize its running time?Byeongsu YuSat, 27 Jun 2020 04:54:17 +0200https://ask.sagemath.org/question/52233/Is there any way to have a cell tell you how long it took to run in the Jupyter notebook?https://ask.sagemath.org/question/47269/is-there-any-way-to-have-a-cell-tell-you-how-long-it-took-to-run-in-the-jupyter-notebook/ The question is basically all in the title. I'm working on a project in the Jupyter and notebook, and I have some cells that have longer run times. Sometimes I let these run, and come back to check on them later, however it would be nice to know exactly what duration those cells ran for.sum8tionFri, 26 Jul 2019 23:31:17 +0200https://ask.sagemath.org/question/47269/solve fails to solve a simple system and runs out of memoryhttps://ask.sagemath.org/question/11037/solve-fails-to-solve-a-simple-system-and-runs-out-of-memory/Hello,
I have a system of linear algebraic equations formed by the nodal equations of a linear electric circuit. The nodal voltages are the unknowns.
There are 16 unknowns.
sage runs forever and in the end I obtain:
RuntimeError: ECL says: Memory limit reached. Please jump to an outer pointer,
quit program and enlarge the
memory limits before executing the program again.
Am I missing something or doing something wrong ?
It is possible that sage cannot solve this linear algebraic system in a reasonable (short) time with "only" 16 unknowns ?
The unknowns are
[V_3, V_4, V_5, V_8, V_7, V_1, V_8, V_10, V_9l, V_4, V_4, V_7, V_2, V_3, V_6, V_9]
and the system is:
[V_10/RLOAD + ((V_1 - V_8)*K1*sqrt(Ltrafo6) - sqrt(Ltrafo5)*V_10)/((K1^2*Ltrafo6*s - Ltrafo6*s)*sqrt(Ltrafo5)) == 0,
-(V_9 - V_9l)/RL2 + ((V_4 - V_7)*(K3*K4 - K2)*sqrt(L1)*sqrt(L2) + ((K4^2 - 1)*(V_4 - V_9l)*sqrt(L1) + (V_2 - V_3)*(K2*K4 - K3)*sqrt(L2))*sqrt(L3))/((2*K2*K3*K4*s - K2^2*s - K3^2*s - K4^2*s + s)*sqrt(L1)*L2*sqrt(L3)) == 0,
(V_1 - V_7)/R4 + (V_1 - V_2)/R1 + V_1/RI + (K1*sqrt(Ltrafo5)*V_10 - (V_1 - V_8)*sqrt(Ltrafo6))/((K1^2*Ltrafo5*s - Ltrafo5*s)*sqrt(Ltrafo6)) - ICC_small_signal_0_1(s) == 0,
(V_3 - V_4)*CBC_Q1*s + (V_4 - V_5)*GM_Q1 + (V_3 - V_5)/RO_Q1 - ((V_4 - V_7)*(K2*K3 - K4)*sqrt(L1)*sqrt(L2) - ((K2^2 - 1)*(V_2 - V_3)*sqrt(L2) + (V_4 - V_9l)*(K2*K4 - K3)*sqrt(L1))*sqrt(L3))/((2*K2*K3*K4*s - K2^2*s - K3^2*s - K4^2*s + s)*L1*sqrt(L2)*sqrt(L3)) == 0,
Cbp1*V_2*s - (V_1 - V_2)/R1 + V_2/RCbp1 + ((V_4 - V_7)*(K2*K3 - K4)*sqrt(L1)*sqrt(L2) - ((K2^2 - 1)*(V_2 - V_3)*sqrt(L2) + (V_4 - V_9l)*(K2*K4 - K3)*sqrt(L1))*sqrt(L3))/((2*K2*K3*K4*s - K2^2*s - K3^2*s - K4^2*s + s)*L1*sqrt(L2)*sqrt(L3)) == 0,
(V_5 - V_7)*CBE_Q2*s + (V_5 - V_7)*GM_Q2 - (V_4 - V_5)*GM_Q1 + (V_5 - V_8)/RO_Q2 + (V_5 - V_7)/RPI_Q2 - (V_4 - V_5)/RPI_Q1 - (V_3 - V_5)/RO_Q1 + (V_5 - V_6)/(LRFC1*s) == 0, -(V_3 - V_4)*CBC_Q1*s + (V_4 - V_5)/RPI_Q1 - ((V_4 - V_7)*(K3*K4 - K2)*sqrt(L1)*sqrt(L2) + ((K4^2 - 1)*(V_4 - V_9l)*sqrt(L1) + (V_2 - V_3)*(K2*K4 - K3)*sqrt(L2))*sqrt(L3))/((2*K2*K3*K4*s - K2^2*s - K3^2*s - K4^2*s + s)*sqrt(L1)*L2*sqrt(L3)) - ((K3^2 - 1)*(V_4 - V_7)*sqrt(L1)*sqrt(L2) + ((V_4 - V_9l)*(K3*K4 - K2)*sqrt(L1) - (V_2 - V_3)*(K2*K3 - K4)*sqrt(L2))*sqrt(L3))/((2*K2*K3*K4*s - K2^2*s - K3^2*s - K4^2*s + s)*sqrt(L1)*sqrt(L2)*L3) == 0,
(V_7 - V_8)*CBC_Q2*s - (V_5 - V_7)*CBE_Q2*s + Cbp2*V_7*s - (V_5 - V_7)/RPI_Q2 - (V_1 - V_7)/R4 + V_7/R3 + ((K3^2 - 1)*(V_4 - V_7)*sqrt(L1)*sqrt(L2) + ((V_4 - V_9l)*(K3*K4 - K2)*sqrt(L1) - (V_2 - V_3)*(K2*K3 - K4)*sqrt(L2))*sqrt(L3))/((2*K2*K3*K4*s - K2^2*s - K3^2*s - K4^2*s + s)*sqrt(L1)*sqrt(L2)*L3) == 0,
V_6/R2 - (V_5 - V_6)/(LRFC1*s) == 0,
C2*V_9*s + (V_9 - V_9l)/RL2 == 0,
-(V_7 - V_8)*CBC_Q2*s - (V_5 - V_7)*GM_Q2 - (V_5 - V_8)/RO_Q2 - (K1*sqrt(Ltrafo5)*V_10 - (V_1 - V_8)*sqrt(Ltrafo6))/((K1^2*Ltrafo5*s - Ltrafo5*s)*sqrt(Ltrafo6)) == 0]
Thank you
ekaSat, 15 Feb 2014 14:09:08 +0100https://ask.sagemath.org/question/11037/RuntimeError when computing Heilbronn-Merel Matrixhttps://ask.sagemath.org/question/9624/runtimeerror-when-computing-heilbronn-merel-matrix/This following Error comes out when I run
> sage: H=HeilbronnMerel(50000)
Does anybody have an idea why this happened? What can I do with this?
sage: H=HeilbronnMerel(50000)
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
/home/guests/sage-5.4.1/<ipython console> in <module>()
/home/guests/sage-5.4.1/local/lib/python2.7/site-packages/sage/modular/modsym/heilbronn.so in sage.modular.modsym.heilbronn.HeilbronnMerel.__init__ (sage/modular/modsym/heilbronn.c:5185)()
/home/guests/sage-5.4.1/local/lib/python2.7/site-packages/sage/modular/modsym/heilbronn.so in sage.modular.modsym.heilbronn.HeilbronnMerel._initialize_list (sage/modular/modsym/heilbronn.c:5343)()
RuntimeError: Floating point exceptionPengTue, 11 Dec 2012 05:58:44 +0100https://ask.sagemath.org/question/9624/Any simple way to divert calculations in Sage to the graphics card?https://ask.sagemath.org/question/9129/any-simple-way-to-divert-calculations-in-sage-to-the-graphics-card/Hey,
I'm fairly new to Sage, pls accept my question under this comment:
I've heard that diverting calculations to the graphics card might speed up running time. Person I heard it from uses C and Matlab.
How true is it? And if so - is there a simple way to do this in Sage?
I'm looking for any good advice on how to speed up my calculations, I have installed Ubuntu 12.04 for Sage, and stoped any programs from running in the background when I'm running my code. I try to achieve as much power I can get from my computer solely for the purpose of my calculation.
Thanking u on advence! ErezWed, 04 Jul 2012 06:04:18 +0200https://ask.sagemath.org/question/9129/Calculation taking too long, stats from scipy may be the problem?https://ask.sagemath.org/question/9114/calculation-taking-too-long-stats-from-scipy-may-be-the-problem/Hey!
I have a question regarding a calculation I'm running.
The code includes only 2 loops, one inside another, and some calculus inside.
The loop run over many iterations (~100000X100000), but it is not an excuse for the calculation to be taking (so far...!) over 20 hours!
- The calcultation inside the loops is a fairly simple one: W[k]=W[k]+1/2*...+...,
but -
i also include - sqrt(bla bla bla)*stats.norm.rvs . One of the reasons for the ridiculously long calculation time, as I heard, might the calling for library from Scipy, where - as it means calling an outside library, which I don't know how it works, increeses the time of every step in the calculation in such a way that for such many iterations results in the long running time.
Can this be the source of the problem? Can calling an outside library, no matter if - Scipy of whatever else, increase the calculation time by so much?
What can I do?
Thanking you on advance! ErezWed, 27 Jun 2012 06:34:40 +0200https://ask.sagemath.org/question/9114/