Revision history [back]

Is there a way to update an expression with new variable values?

Is there a way to update an expression if the symbolic variables that it contains have been overwritten? For example,

sage: var('beta')
beta
sage: eq = x == beta
sage: beta = 1
sage: eq
x == beta


Is there a way for it to change to x == 1? I wrote the following function to do this, but I wanted to know if something similar existed already.

def update(expr):
return expr.subs(dict(zip(expr.variables(), map(lambda v:eval(str(v)), expr.variables()))))

 2 retagged tmonteil 21078 ●25 ●152 ●390 http://wiki.sagemath.o...

Is there a way to update an expression with new variable values?

Is there a way to update an expression if the symbolic variables that it contains have been overwritten? For example,

sage: var('beta')
beta
sage: eq = x == beta
sage: beta = 1
sage: eq
x == beta


Is there a way for it to change to x == 1? I wrote the following function to do this, but I wanted to know if something similar existed already.

def update(expr):
return expr.subs(dict(zip(expr.variables(), map(lambda v:eval(str(v)), expr.variables()))))