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.Tue, 15 Sep 2015 04:09:49 -0500High memory usage when substituting variableshttp://ask.sagemath.org/question/29444/high-memory-usage-when-substituting-variables/I need to make a lot of variable substitutions in multivariate polynomials. However, I only need to store one polynomial at a time and I only need to make one substitution at a time. Nonetheless sage uses a lot of memory. This memory is not freed until sage is killed.
Here is a small example:
var("x y z")
# A polynomial in three variables (The Trott quartic):
poly=12^2*(x^4+y^4)-15^2*(x^2+y^2)*z^2+350*x^2*y^2+9^2*z^4
poly=poly.polynomial(ZZ)
pnt=[1,2,3]
# Makes a certain variable subsitution, defined by pt, n times.
def test_subs(f,pt,n):
for i in xrange(n):
temp=f.substitute(x=x+pt[0]*z,y=y+pt[1]*z,z=pt[2]*z)
#temp=f(x=x+pt[0]*z,y=y+pt[1]*z,z=pt[2]*z) #This also uses a lot of memory.
When i run `test_subs(poly,pnt,100000)` I can see the memory usage ticking up from around 1% up to nearly 2%. if I then run the function again the ticking starts at 2%, and so on. In the real problem I have my program eventually fills up all memory and then crashes.
Can you see why this is happening and do you know how to prevent it from happening?Olof BergvallTue, 15 Sep 2015 04:09:49 -0500http://ask.sagemath.org/question/29444/Simplify shenaniganshttp://ask.sagemath.org/question/10129/simplify-shenanigans/I've noticed a strange (and annoying) behaviour in sage concerning symbolic substitution and simplification
def demonstrate_simplify_shenanigans():
sym_func = function('func',nargs=1)
my_expression = sym_func(0)+sym_func(1)+sym_func(2)
print
print 'without simplify'
print my_expression.subs(func(0)==1)
print
print 'with simplify in expression'
print my_expression.simplify().subs(func(0)==1)
print
print 'with simplify in both expression and substitution'
print my_expression.simplify().subs(func(0).simplify()==1)
demonstrate_simplify_shenanigans()
The output is
without simplify
func(1) + func(2) + 1
with simplify in expression
func(0) + func(1) + func(2)
with simplify in both expression and substitution
func(1) + func(2) + 1
Why is there a different behaviour depending on whether simplify was called? Even though `func(0)` and `func(0).simplify()` seem identical.bolverkFri, 17 May 2013 19:48:32 -0500http://ask.sagemath.org/question/10129/