Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I figured out that the "subs" command in sympy is far more powerful than substitute in sage. So I converted the sage expression into sympy expression using f=f._sympy_() then did the substitution I wanted to do and after the substitution converted to sage again using f=f._sage_(). The problem is that sympy gives a problem because it cannot recognize i. So I declared a variable name i and restored it in the end. Here is an example script. It would be awesome though if the sage substitute command worked like the sympy subs command.

from sympy import Symbol, cos, sympify, pprint

from sympy.abc import x

x=var('x')

z=var('z')

i=var('i')

f=xx+xi+1

view(f)

f=f._sympy_()

view(f)

f=f.subs(x*x,z)

f=f._sage_()

view(f)

restore('i')

I figured out that the "subs" command in sympy is far more powerful than substitute in sage. So I converted the sage expression into sympy expression using f=f._sympy_() then did the substitution I wanted to do and after the substitution converted to sage again using f=f._sage_(). The problem is that sympy gives a problem because it cannot recognize i. So I declared a variable name i and restored it in the end. Here is an example script. It would be awesome though if the sage substitute command worked like the sympy subs command.

from sympy import Symbol, cos, sympify, pprint

pprint

from sympy.abc import x

x x=var('x')

x=var('x')

z=var('z') i=var('i')

z=var('z')

f=x*x+x*i+1 view(f)

i=var('i')

f=f._sympy_() view(f)

f=xx+xi+1

f=f.subs(x*x,z) f=f._sage_()

view(f)

view(f) restore('i')

f=f._sympy_()

view(f)

f=f.subs(x*x,z)

f=f._sage_()

view(f)

restore('i')

I figured out that the "subs" command in sympy is far more powerful than substitute in sage. So I converted the sage expression into sympy expression using f=f._sympy_() then did the substitution I wanted to do and after the substitution converted to sage again using f=f._sage_(). The problem is that sympy gives a problem because it cannot recognize i. So I declared a variable name i and restored it in the end. Here is an example script. It would be awesome though if the sage substitute command worked like the sympy subs command.

from sympy import Symbol, cos, sympify, pprint
pprint 
from sympy.abc import x
 x=var('x')
 z=var('z')
 i=var('i')
 f=x*x+x*i+1
 view(f)
 f=f._sympy_()
 view(f)
 f=f.subs(x*x,z)
 f=f._sage_()
 view(f)
 restore('i')