1 | initial version |
Hello, @Emmanuel Charpentier! I am not 100% sure if this is exactly what you are looking for, but there exist these methods called _sympy_()
and _sage_()
. The first one converts some Sage expression to Sympy, while the second converts Maxima/Sympy/Giac/etc. expressions to Sage.
For example, I can wrap your code inside a function like this:
def sympy_sin(a, b):
# Convert to Sympy (this renders the sympify method unnecessary in this case)
sa = a._sympy_()
sb = b._sympy_()
from sympy import sin as ssin
res = ssin(sa + sb)
# Convert back to Sage and return result
return res._sage_()
I hope this helps!
2 | No.2 Revision |
Hello, @Emmanuel Charpentier! I am not 100% sure if this is exactly what you are looking for, but there exist these methods called _sympy_()
and _sage_()
. The first one converts some Sage expression to Sympy, while the second converts Maxima/Sympy/Giac/etc. expressions to Sage.
For example, I can wrap your code inside a function like this:
def sympy_sin(a, b):
# Convert to Sympy (this renders the sympify method unnecessary in this case)
sa = a._sympy_()
sb = b._sympy_()
from sympy import sin as ssin
res = ssin(sa + sb)
# Convert back to Sage and return result
return res._sage_()
Now, you could do something like the following:
var('a b')
ss = sympy_sin(a, b)
ss.trig_expand()
and you will get the correct answer, cos(b)*sin(a) + cos(a)*sin(b)
. To further verify the conversion step, we do
type(ss)
and we get the expected <class 'sage.symbolic.expression.Expression'>
.
Of course, it is NOT necessary to wrap this into a function, like I did above; you can use these methods in any place on Sage.
I hope this helps!