ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 25 Sep 2019 11:42:43 -0500Stack overflow in boolean testhttp://ask.sagemath.org/question/48058/stack-overflow-in-boolean-test/Using SageMath 8.8, I encountered a strange error involving boolean tests. The following code reproduces the issue:
x, y = var('x, y')
assume(x>0)
assume(y>0)
bool(y*(x-y)==0)
`RuntimeError: ECL says: C-STACK overflow at size 1048576. Stack can probably be resized.
Proceed with caution.`
This code should obviously return `False`. Changing `y*(x-y)` to `x*(y-x)` indeed returns `False`, which means `x` and `y` cannot be exchanged. Without the assumptions, the code works as expected.
I initially thought it was due to my Sage installation, but running this code on https://sagecell.sagemath.org/ also produces asymmetric behavior, though no error comes out (just a blank answer).
Is this a known issue ? Can someone reproduce this ?Florentin JaffredoWed, 25 Sep 2019 11:42:43 -0500http://ask.sagemath.org/question/48058/Support for arbitrarily large numbers?http://ask.sagemath.org/question/42070/support-for-arbitrarily-large-numbers/ Hi, I'm trying to compute the Juggler Sequence for relatively large numbers. Standard python doesn't calculate these correctly; I've discovered that Mathematica does, but I'm more familiar with Python and someone suggested I try out Sage.
I've tried this a couple ways using SageCell, and haven't yet succeeded. Here's the simplest possible implementation:
def juggle(n):
if n % 2:
return floor(sqrt(n)**3)
return floor(sqrt(n))
When I run this on 37, it works perfectly:
x = 37
print x,
while x > 1:
x = juggle(x)
print u"\u2192 {}".format(x),
produces
37 → 225 → 3375 → 196069 → 86818724 → 9317 → 899319 → 852846071 → 24906114455136 → 4990602 → 2233 → 105519 → 34276462 → 5854 → 76 → 8 → 2 → 1
which standard python fails (it finds 3374 instead of 3375). However, if I try a hard one, say, x = 48443, it times out after a few iterations:
48443 → 10662193 → 34815273349 → 6496130099313865 → 523578821252958052233532 → 723587466207 → 615512041010804067 → 482897358660562651148793788 → 21974925680433 → 103012783516625098121 → 1045530445028727953685811220915
I can improve this by using logarithms:
def juggle(n):
if n % 2:
return floor(exp(1.5*log(n)))
return floor(sqrt(n))
This implementation is much faster and gets much farther; however, it ends with an error:
TypeError: ECL says: #<a FLOATING-POINT-OVERFLOW>
I'd like to attach the full output as a text file, because it involves some very large numbers, but I don't have the karma yet. The number which causes the code to crash is about 3300 characters long. Here's the traceback, at least:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-1-a9218cbdcf1b> in <module>()
8
9 while x > Integer(1):
---> 10 x = juggle(x)
11 print u"\u2192 {}".format(x),
<ipython-input-1-a9218cbdcf1b> in juggle(n)
1 def juggle(n):
2 if n % Integer(2):
----> 3 return floor(exp(RealNumber('1.5')*log(n)))
4 return floor(sqrt(n))
5
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/functions/other.pyc in __call__(self, x, **kwds)
412
413 try:
--> 414 return floor(SR(x).full_simplify().canonicalize_radical())
415 except ValueError:
416 pass
/home/sc_serv/sage/src/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.simplify_full (build/cythonized/sage/symbolic/expression.cpp:53709)()
9698 x = self
9699 x = x.simplify_factorial()
-> 9700 x = x.simplify_rectform()
9701 x = x.simplify_trig()
9702 x = x.simplify_rational()
/home/sc_serv/sage/src/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.simplify_rectform (build/cythonized/sage/symbolic/expression.cpp:55646)()
9846
9847 """
-> 9848 simplified_expr = self.rectform()
9849
9850 if complexity_measure is None:
/home/sc_serv/sage/src/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.rectform (build/cythonized/sage/symbolic/expression.cpp:53186)()
9530
9531 """
-> 9532 return self.maxima_methods().rectform()
9533
9534 def unhold(self, exclude=None):
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/symbolic/maxima_wrapper.pyc in __call__(self, *args, **kwds)
30 """
31 return super(MaximaFunctionElementWrapper, self).__call__(*args,
---> 32 **kwds).sage()
33
34 class MaximaWrapper(SageObject):
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/interfaces/interface.pyc in __call__(self, *args, **kwds)
655
656 def __call__(self, *args, **kwds):
--> 657 return self._obj.parent().function_call(self._name, [self._obj] + list(args), kwds)
658
659 def help(self):
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/interfaces/interface.pyc in function_call(self, function, args, kwds)
576 [s.name() for s in args],
577 ['%s=%s'%(key,value.name()) for key, value in kwds.items()])
--> 578 return self.new(s)
579
580 def _function_call_string(self, function, args, kwds):
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/interfaces/interface.pyc in new(self, code)
345
346 def new(self, code):
--> 347 return self(code)
348
349 ###################################################################
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/interfaces/interface.pyc in __call__(self, x, name)
280
281 if isinstance(x, string_types):
--> 282 return cls(self, x, name=name)
283 try:
284 return self._coerce_from_special_method(x)
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/interfaces/interface.pyc in __init__(self, parent, value, is_name, name)
695 self._name = parent._create(value, name=name)
696 except (TypeError, RuntimeError, ValueError) as x:
--> 697 raise TypeError(x)
698
699 def _latex_(self):
TypeError: ECL says: #<a FLOATING-POINT-OVERFLOW>
Does anyone have any suggestions for me? Thanks in advance!gkanarekTue, 17 Apr 2018 10:36:02 -0500http://ask.sagemath.org/question/42070/stack overflow in computing entropyhttp://ask.sagemath.org/question/9342/stack-overflow-in-computing-entropy/Hi,
I am still new to sage, I am trying to compute use sage to do some symbolic computation. Here is my test to compute entropy of the Gaussian distribution:
x, sigma, mu,a = var('x','sigma','mu','a')
q = 1/((2*pi)^(1/2)*sigma)*exp(-(x - mu)^2/(2*sigma^2))
assume(sigma>0)
assume(mu>0)
show(q)
import sympy
integral(q,(x,-oo,oo))
integral(-q*log(q),(x,-oo,oo))
First of all, it complains if I don't assume mu is positive. It is right that sigma should be positive but why mu ?! Second, even after assuming mu>0, it produces stack overflow:
WARNING: Output truncated!
full_output.txt
;;;
;;; Binding stack overflow.
;;; Jumping to the outermost toplevel prompt
;;;
;;;
;;; Binding stack overflow.
;;; Jumping to the outermost toplevel prompt
;;;
Does anyone know why? I am sure I am missing something.kayhanSat, 22 Sep 2012 13:42:12 -0500http://ask.sagemath.org/question/9342/variables get deleted after calulation, overflow?http://ask.sagemath.org/question/8619/variables-get-deleted-after-calulation-overflow/Hello and happy 1000 questions,
I tried to solve an equation and wanted to reinsert the solutions so I can check weather everything worked correctly. But after the calculations are finished, all variables and their values are gone.
Here is the code
var('n,R,T')
var('test,test2,test3')
eq1 = ((n-1)^2/(n+1)^2)==(-1-2*R+R^2-T^2+sqrt(4*T^2+(1-2*R+R^2-T^2)^2))/(2*R-4)
sol=solve(eq1,n,solution_dict=true)
test = (eq1.substitute(n=sol[0][n]))
test2 = test*(test.lhs().denominator())*(test.rhs().denominator())
test3 = expand(test2).full_simplify()
show(test3)
Errorcode:
Traceback (click to the left of this block for traceback)
File "<stdin>", line 1, in <module>
File "_sage_input_3.py", line 10, in <module>
exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("ZXEx"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
File "", line 1, in <module>
File "/tmp/tmpDYArBS/___code___.py", line 2, in <module>
exec compile(u'eq1
File "", line 1, in <module>
NameError: name 'eq1' is not defined
I'm working with sage SageVersion 4.7.2 under win7 with Oracle VirtualBox as recommended. Thanks in advance.
god.oneWed, 11 Jan 2012 01:43:10 -0600http://ask.sagemath.org/question/8619/