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.Tue, 15 Sep 2020 01:40:53 +0200Coefficient of Polynomial Function in a loophttps://ask.sagemath.org/question/53457/coefficient-of-polynomial-function-in-a-loop/ Hello so I am using the .coefficient function to extract the coefficient of a monomial given some polynomial. For example, 3x^(2).coefficient(x^(2)) is 3.
R.<x,y,z,w> = QQ[]
List1= [x^(2), y^(2),z^(2)]
List2= [x^(2)+y^(2)+z^(2), 3*x^(2),4*y^(2)]
List3=[]
For example if I do List2[0].coefficient(List1[0]), Sage immediately outputs 1. However, when I try to run it through all of List1, for some reason, the runtime seems to go forever so I feel I am doing something wrong. Even if I restrict to only the first term in List2, the runtime is very long and doesn't stop. Am I doing something wrong? In the code below, it should only run through 3 terms.
i=0
while i<len(List1):
Result=List2[0].coefficient(List1[i])
List3.append(Result)
i+=1whatupmattTue, 15 Sep 2020 01:40:53 +0200https://ask.sagemath.org/question/53457/erfc for arbitrary precision real fieldhttps://ask.sagemath.org/question/52525/erfc-for-arbitrary-precision-real-field/ The following code raised a runtime error:
R = RealField(500)
print(erfc(R(28.0)))
Output:
/home/sc_serv/sage/local/lib/python3.7/site-packages/sage/rings/real_mpfr.pyx in sage.rings.real_mpfr.RealNumber.erfc (build/cythonized/sage/rings/real_mpfr.c:31648)()
5047 """
5048 cdef RealNumber x = self._new()
-> 5049 sig_on()
5050 mpfr_erfc(x.value, self.value, (<RealField_class>self._parent).rnd)
5051 sig_off()
RuntimeError: Aborted
However, it would work if the RealField is removed:
print(erfc(28.0))
Output:
6.56321584032878e-343
Is there a way to make `erfc` work also for arbitrary precision real fields?WhatsUpFri, 17 Jul 2020 13:22:20 +0200https://ask.sagemath.org/question/52525/RuntimeError Groebner basis for a Boolean systemhttps://ask.sagemath.org/question/51072/runtimeerror-groebner-basis-for-a-boolean-system/ Hello everyone,
i've started using sage for a few days and i'm having a rough time trying to use groebner basis with big boolean systems. Right now my goal is to verify the time it takes to solve these systems in this way: keep in mind that these equation are extracted from a cipher, and they are roughly 150 for 130 variables.
var = "x01, x02, x03, x04, x05, x06, x07, x08, x09, x10, x11, x12, x13, x14, x15, x16, x17, x18, x19, x20, x21, x22, x23, x24, x25, x26, x27, x28, x29, x30, x31, x32, x33, x34, x35, x36, x37, x38, x39, x40, x41, x42, x43, x44, x45, x46, x47, x49, x54, x70, x81, x89, x92, x93, y01, y02, y03, y04, y05, y06, y07, y08, y09, y10, y11, y12, y13, y14, y15, y16, y17, y18, y19, y20, y21, y22, y23, y24, y25, y26, y27, y28, y29, y30, y31, y32, y33, y34, y35, y36, y37, y38, y39, y40, y41, y42, y43, y44, y45, y46, y47, y48, y49, y50, y52, y80, y83, y84"
B = BooleanPolynomialRing(var)
System = [B('x93 + y84'), B('x92 +y83'), B('x89 + y80'), B('x54 + x81'), B('x49 + y52')]
I = ideal(System)
G = I.groebner_basis()
The thing is that when i try to call the method 'variety' on the ideal 'I', i get a runtime error (even with this reduced example):
RuntimeError: error in Singular function call 'groebner':
int overflow in hilb 1
error occurred in or before standard.lib::stdhilb line 299: ` intvec hi = hilb( Id(1),1,W );`
expected intvec-expression. type 'help intvec;'
leaving standard.lib::stdhilb
leaving standard.lib::groebner
Do you have any idea why this happens? Or if you have any suggestions with the approach i could take, i'm happy to listen to them.
Thank you in advance for your time.torresMon, 27 Apr 2020 18:59:50 +0200https://ask.sagemath.org/question/51072/Definite Integral Fails due to Runtime Errorhttps://ask.sagemath.org/question/39354/definite-integral-fails-due-to-runtime-error/Here is the code that I have been writing; it's meant to predict the moment of inertia of a perfect cylinder tilted and offset from its axis of rotation, among other things. However, the definite_integral command fails with an error thrown by the gcd function. I suspect the issue is due to Sage's inner workings; however, I do not have the time or know-how to fully debug this issue. Any help would be appreciated.
from sage.symbolic.integration.integral import definite_integral
from sage.calculus.integration import numerical_integral
dSpringStretchedFully=10.625
dSpringUnstretchedLength=7.875
dArmatureInches=8
dSpringAnchor=4.75
thetaArmatureDefault=95
dSpringPitch=dSpringUnstretchedLength/sin(thetaArmatureDefault*pi/180)*sin(pi/180*(180-thetaArmatureDefault-(180/pi*arcsin(dSpringAnchor*sin(thetaArmatureDefault*pi/180)/dSpringUnstretchedLength))))
fSpringPoundsPerInch=65.69
kNewtonsPerPound=4.44822
kMetersPerInch=0.0254
fSpringNewtonsPerInch=fSpringPoundsPerInch*kNewtonsPerPound
dArmatureMeters=dArmatureInches*kMetersPerInch
dHalfRopeInches=dArmatureInches*cos(pi/180*(thetaArmatureDefault-90))
dHalfRopeMeters=dHalfRopeInches*kMetersPerInch
fSpringNewtonsPerMeter=fSpringNewtonsPerInch/kMetersPerInch
fSpringMinimumLoad=0
kSpringDirection=1
rRopeInches=0.5
rRopeMeters=rRopeInches*kMetersPerInch
var('x')
var('dHalfRope')
var('thetaArmatureToRope')
thetaPointToAxis(x,thetaArmatureToRope)=thetaArmatureToRope-(180/pi*arctan((x-rRopeMeters)/dArmatureMeters))
dPointFromFarAxis(x,dHalfRope)=((dHalfRope^2)+(x-rRopeMeters)^2)^(1/2)
dPointFromNearAxis(x,dHalfRope,thetaArmatureToRope)=((dArmatureMeters^2)+((dPointFromFarAxis(x,dHalfRope))^2)-2*dPointFromFarAxis(x,dHalfRope)*dArmatureMeters*cos(pi/180*thetaPointToAxis(x,thetaArmatureToRope)))^(1/2)
IMultiplier(x)=2*(((rRopeMeters^2)-(x-rRopeMeters)^2)^(1/2))
ILine(x,dHalfRope,thetaArmatureToRope)=((dPointFromNearAxis(x,dHalfRope, thetaArmatureToRope))^2)*IMultiplier(x)
ISlice(dHalfRope,thetaArmatureToRope)=definite_integral(ILine(x,dHalfRope,thetaArmatureToRope),x,0,2*rRopeMeters)
ISlice(3,4)Benji_ZhangTue, 31 Oct 2017 17:17:36 +0100https://ask.sagemath.org/question/39354/Why can't I compute the ehrhart polynomial of a polytope?https://ask.sagemath.org/question/34457/why-cant-i-compute-the-ehrhart-polynomial-of-a-polytope/I'm getting an error message when I try to compute the ehrhart polynomial of a polytope:
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 7.3, Release Date: 2016-08-04 │
│ Type "notebook()" for the browser-based notebook interface. │
│ Type "help()" for help. │
└────────────────────────────────────────────────────────────────────┘
sage: P = polytopes.simplex(3)
sage: P.ehrhart_polynomial()
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-2-9033e1d690fd> in <module>()
----> 1 P.ehrhart_polynomial()
/home/brian/.computer_algebra_systems/sage-7.0/local/lib/python2.7/site-packages/sage/geometry/polyhedron/base_ZZ.pyc in ehrhart_polynomial(self, verbose, dual, irrational_primal, irrational_all_primal, maxdet, no_decomposition, compute_vertex_cones, smith_form, dualization, triangulation, triangulation_max_height, **kwds)
317 else:
318 err = ":\n" + err
--> 319 raise RuntimeError("LattE integrale failed with exit code {} to execute {}".format(ret_code, ' '.join(args)) + err.strip())
320
321 p = ans.splitlines()[-2]
RuntimeError: LattE integrale failed with exit code 127 to execute count --ehrhart-polynomial --redundancy-check=none --cdd /dev/stdin:
count: error while loading shared libraries: libntl.so.19: cannot open shared object file: No such file or directory
sage:
done_with_fishSat, 13 Aug 2016 00:27:28 +0200https://ask.sagemath.org/question/34457/How to fix Runtime Error while doing integration?https://ask.sagemath.org/question/32934/how-to-fix-runtime-error-while-doing-integration/ I'm trying to evaluate:
`definite_integral(z,t,0,2*pi)`
where z is:
`z = 1-exp(2.0*cos(t) - 2.0*sin(t)-0.4*sqrt(-25*(cos(t) - sin(t))^2 + 100)^2)`
But it is throwing following error:
RuntimeError: ECL says: THROW: The catch RAT-ERR is undefined.
I' new to Sage, but following through some posts at ask.sagemath (I can't post link), I feel it may be due to precision. 5 digits are OK with me.
Any fix/workaround? Thanks.tdc2bdcFri, 01 Apr 2016 09:39:28 +0200https://ask.sagemath.org/question/32934/Unable to start QEPCADhttps://ask.sagemath.org/question/28857/unable-to-start-qepcad/I have compiled and installed qepcad-1.50, but I can't run it. For example, these are lifted from the documentation:
sage: var('a,b,c,d,x,y,z')
sage: qf = qepcad_formula
sage: ellipse = 3*x^2 + 2*x*y + y^2 - x + y - 7
sage: F = qf.exists(y, ellipse == 0)
sage: qepcad(F)
However, this produces an error:
RuntimeError: Unable to start QEPCAD
I did discover a patch at https://abf.rosalinux.ru/import/sagemath/blob/rosa2014.1/sage-qepcad.patch but I'm not sure how to apply it. I'd be very happy for some advice.
I'm running sage-6.2, under Ubuntu 14.04.AlasdairTue, 18 Aug 2015 13:13:10 +0200https://ask.sagemath.org/question/28857/What does "Runtime Error: ECL says: ... is not of type FIXNUM" mean and how to fix it?https://ask.sagemath.org/question/10908/what-does-runtime-error-ecl-says-is-not-of-type-fixnum-mean-and-how-to-fix-it/I am trying to integrate $x(0.6x^{0.5}+0.6)$ from $0$ to 1.
Here's what I tried:
var('x')
(x*(0.6*x^0.5+0.6)).integrate(x,0,1)
But I received the following error:
RuntimeError: ECL says: 3.0 is not of type FIXNUM.
What does the error mean (I am especially curious where the 3 came from) and what can I do to correctly evaluate the definite integral? According to Wolfram Alpha, the answer is 0.54.ensabaMon, 13 Jan 2014 10:42:37 +0100https://ask.sagemath.org/question/10908/Weird behavior BuiltinFunctionhttps://ask.sagemath.org/question/9387/weird-behavior-builtinfunction/Dear Sage,
I'm trying to program qPochhammer functions which can interact with sage in a nice way. However I encounter some weird behavior of these new BuiltinFunctions. This is what I made:
from sage.symbolic.function import BuiltinFunction
class qPochhammer(BuiltinFunction):
def __init__(self, m=1, expand_exp=False):
self.m = m
self.expand_exp = expand_exp
self.has_arguments = False
BuiltinFunction.__init__(self, 'qPochhammer(%i)' % self.m, nargs=(m+2))
def _latex_(self):
if self.has_arguments:
return '(%s; %s)_{%s}' % (self.a, self.q, self.n)
return 'qPochhammer'
def _qPochhammer1(self, a, q, n):
if n == 0:
return 1
return (1 - a*q**(n-1))*self._qPochhammer1(a, q, n-1)
def _expand(self):
return prod([self._qPochhammer1(elm, self.q, self.n) \
for elm in self.a])
def _eval_(self, *args):
if len(args) != self.m + 2:
raise RuntimeError, args
if self.expand_exp:
return self.evaluate(args[:self.m], args[-2], args[-1])
return None
def _evalf_(self, *args, **kwds):
if type(self.a) == tuple:
return self._expand()
return self._qPochhammer1(self.a, self.q, self.n)
def evaluate(self, a, q, n):
self.a = a
self.q = q
self.n = n
self.has_arguments = True
if type(self.a) == tuple:
return self._expand()
return self._qPochhammer1(self.a, self.q, self.n)
Now I try the following the the sage console:
sage: a, b, c, q = var('a b c q')
sage: qshift3 = qPochhammer(m=3, expand_exp=True)
sage: qshift3(a, b, c, q, 2)
(c - 1)*(b - 1)*(a - 1)*(c*q - 1)*(b*q - 1)*(a*q - 1)
sage: qshift2 = qPochhammer(m=2, expand_exp=True)
sage: qshift2(a, b, q, 2)
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
/home/noud/work/sage/local/lib/python2.7/site-packages/sage/all_cmdline.pyc in <module>()
----> 1
2
3
4
5
/home/noud/work/sage/local/lib/python2.7/site-packages/sage/symbolic/function.so in sage.symbolic.function.Function.__call__ (sage/symbolic/function.cpp:4941)()
430
431
--> 432
433
434
/home/noud/work/sage/local/lib/python2.7/site-packages/sage/all_cmdline.pyc in _eval_(self, *args)
27
28
---> 29
30
31
RuntimeError: (a, b, q, 2)
Can someone explain to my why I get a RuntimeError and how to solve this?
Best regards,
NoudNoudFri, 05 Oct 2012 07:22:43 +0200https://ask.sagemath.org/question/9387/Why can't I attach files?https://ask.sagemath.org/question/8815/why-cant-i-attach-files/Hi -
I recently installed Sage on my new Macbook (although I've used Sage before, on my old -- and sadly, recently stolen -- Macbook). I'm using the Sage notebook. (Details of my installation below.)
If I attach a file ("attach foo.sage"), it loads/runs the commands in that file, just like it's supposed to and used to. However, if I make any alteration to the attached file while the Sage notebook is still running, then when I return to the notebook and try to do anything, Sage freaks out.
By "freak out," I mean that if I try to do any computation, even one that doesn't involve the variables or functions in the attached file (e.g., "2+2"), I get a massive error message, which ends with "RuntimeError: maximum recursion depth exceeded in cmp". I've pasted more of the error message below. This behavior continues until I quit and restart that notebook. It seems that the contents of the attached file are irrelevant -- I've tried it with simple files that contain nothing but a single print command, or something basic like "a=5".
I did a little searching, and I turned up [this discussion](http://groups.google.com/group/sage-notebook/browse_thread/thread/f0004f475fb26b23) on the sage-notebook Google Group, where William Stein notes this behavior. So obviously somebody who knows something is aware of this. But that was all I could find anywhere, and I have no sense for whether there is a fix/workaround for this.
I briefly tested to see if this also happens when I use Sage from a terminal. I don't get the recursion error then. However, if I re-enter the "attach" command after I've altered the attached file, it appears to run through the commands in that file twice. (So, for instance, if the attached file includes "print 'Hello!'", it will do this twice.) I understand that the command line avoids the error, but I would really prefer to use the notebook if I can.
Any ideas? Please speak slowly and use small words (metaphorically). Thanks!
---
The error message starts with...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "_sage_input_14.py", line 10, in <module>
File "", line 1, in <module>
File "/private/var/folders/5h/c6x89ch91fjgr43q99g8wbjw0000gn/T/tmphXrluN/___code___.py", line 3, in <module>
sage.misc.preparser.load(sage.misc.preparser.base64.b64decode("Ii9Vc2Vycy9Kb2huL0Rlc2t0b3AvU2FnZV9zY3JpcHRzL3Rlc3Rlci5zYWdlIg=="),globals(),True)
File "/Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/sage/local/lib/python2.6/site-packages/sage/misc/preparser.py", line 1644, in load
execfile(preparse_file_named(fpath), globals)
File "/Users/John/.sage/temp/C_K_Dexter_Haven.local/34442/_Users_John_Desktop_Sage_scripts_tester_sage_6.py", line 6, in <module>
Then, the latter 4 lines (starting with "sage.misc.preparser.load") are repeated 492 more times, with the only thing changing being the number following "scripts_tester_sage_" in the last line. Then, it ends with:
sage.misc.preparser.load(sage.misc.preparser.base64.b64decode("Ii9Vc2Vycy9Kb2huL0Rlc2t0b3AvU2FnZV9zY3JpcHRzL3Rlc3Rlci5zYWdlIg=="),globals(),True)
File "/Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/sage/local/lib/python2.6/site-packages/sage/misc/preparser.py", line 1644, in load
execfile(preparse_file_named(fpath), globals)
File "/Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/sage/local/lib/python2.6/site-packages/sage/misc/interpreter.py", line 385, in preparse_file_named
preparse_file_named_to_stream(name, out)
File "/Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/sage/local/lib/python2.6/site-packages/sage/misc/interpreter.py", line 368, in preparse_file_named_to_stream
parsed = preparse_file(contents)
File "/Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/sage/local/lib/python2.6/site-packages/sage/misc/preparser.py", line 1240, in preparse_file
numeric_literals=not numeric_literals))
File "/Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/sage/local/lib/python2.6/site-packages/sage/misc/preparser.py", line 1126, in preparse
L)
File "/Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/sage/local/lib/python/re.py", line 151, in sub
return _compile(pattern, 0).sub(repl, string, count)
File "/Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/sage/local/lib/python/re.py", line 273, in _subx
template = _compile_repl(template, pattern)
File "/Applications/Sage-4.8-OSX-64bit-10.6.app/Contents/Resources/sage/local/lib/python/re.py", line 253, in _compile_repl
p = _cache_repl.get(key)
RuntimeError: maximum recursion depth exceeded in cmp
Installation details:
I'm using OSX Lion 10.7.3, and I installed the app version of Sage 4.8 (Sage-4.8-OSX-64bit-10.6.app). (Yes, I know I'm using the 10.6 version on a computer running 10.7, but as far as I could figure out, that's the best solution that works right now.) Thanks to some of the helpful posts and responses here on ASKSAGE about installing Sage on Lion, after some initial bumps, it seems to be running well, with this one exception.jdcThu, 22 Mar 2012 15:48:05 +0100https://ask.sagemath.org/question/8815/