Ask Your Question

Revision history [back]

Using sympy, it seems to work:

sage: a,b,c,d = [a._sympy_() for a in G.list()]
sage: from sympy import Matrix
sage: G_sympy = Matrix([[a,b], [c,d]])
sage: G_sympy.exp().simplify()
sage: G_sympy_exp = G_sympy.exp()
sage: G_sympy_exp.simplify()
sage: G_sympy_exp
Matrix([
[(-(cos(theta) - 1)*exp(2*I*t) + cos(theta) + 1)*exp(-I*t)/2,                I*(I*sin(phi) - cos(phi))*sin(t)*sin(t
heta)],
[        (-exp(2*I*t) + 1)*exp(I*phi)*exp(-I*t)*sin(theta)/2, ((cos(theta) + 1)*exp(2*I*t) - cos(theta) + 1)*exp(-I
*t)/2]])

Then using copy-paste, I am able to construct the matrix G_exp as a Sage object:

sage: G_sympy_exp.tolist()
[[(-(cos(theta) - 1)*exp(2*I*t) + cos(theta) + 1)*exp(-I*t)/2,
  I*(I*sin(phi) - cos(phi))*sin(t)*sin(theta)],
 [(-exp(2*I*t) + 1)*exp(I*phi)*exp(-I*t)*sin(theta)/2,
  ((cos(theta) + 1)*exp(2*I*t) - cos(theta) + 1)*exp(-I*t)/2]]
sage: G_exp = matrix([[(-(cos(theta) - 1)*exp(2*I*t) + cos(theta) + 1)*exp(-I*t)/2,
....:   I*(I*sin(phi) - cos(phi))*sin(t)*sin(theta)],
....:  [(-exp(2*I*t) + 1)*exp(I*phi)*exp(-I*t)*sin(theta)/2,
....:   ((cos(theta) + 1)*exp(2*I*t) - cos(theta) + 1)*exp(-I*t)/2]]
....: )
sage: G_exp
[-1/2*((cos(theta) - 1)*e^(2*I*t) - cos(theta) - 1)*e^(-I*t)                  (-I*cos(phi) - sin(phi))*sin(t)*sin(theta)]
[            -1/2*(e^(2*I*t) - 1)*e^(I*phi - I*t)*sin(theta)  1/2*((cos(theta) + 1)*e^(2*I*t) - cos(theta) + 1)*e^(-I*t)]

Note: I was expecting that G._sympy_() would return the equivalent matrix in Sympy but this method does not exist. It would be nice to add it. Also, there must be an easier way to convert the sympy G_sympy_exp back to a sage matrix instead of the copy-paste I am doing above.

Using sympy, it seems to work:

sage: a,b,c,d = [a._sympy_() for a in G.list()]
sage: from sympy import Matrix
sage: G_sympy = Matrix([[a,b], [c,d]])
sage: G_sympy.exp().simplify()
sage: G_sympy_exp = G_sympy.exp()
sage: G_sympy_exp.simplify()
sage: G_sympy_exp
Matrix([
[(-(cos(theta) - 1)*exp(2*I*t) + cos(theta) + 1)*exp(-I*t)/2,                I*(I*sin(phi) - cos(phi))*sin(t)*sin(t
heta)],
[        (-exp(2*I*t) + 1)*exp(I*phi)*exp(-I*t)*sin(theta)/2, ((cos(theta) + 1)*exp(2*I*t) - cos(theta) + 1)*exp(-I
*t)/2]])

Then using copy-paste, I am able to construct the matrix G_exp as a Sage object:

sage: G_sympy_exp.tolist()
[[(-(cos(theta) - 1)*exp(2*I*t) + cos(theta) + 1)*exp(-I*t)/2,
  I*(I*sin(phi) - cos(phi))*sin(t)*sin(theta)],
 [(-exp(2*I*t) + 1)*exp(I*phi)*exp(-I*t)*sin(theta)/2,
  ((cos(theta) + 1)*exp(2*I*t) - cos(theta) + 1)*exp(-I*t)/2]]
sage: G_exp = matrix([[(-(cos(theta) - 1)*exp(2*I*t) + cos(theta) + 1)*exp(-I*t)/2,
....:   I*(I*sin(phi) - cos(phi))*sin(t)*sin(theta)],
....:  [(-exp(2*I*t) + 1)*exp(I*phi)*exp(-I*t)*sin(theta)/2,
....:   ((cos(theta) + 1)*exp(2*I*t) - cos(theta) + 1)*exp(-I*t)/2]]
....: )
sage: G_exp
[-1/2*((cos(theta) - 1)*e^(2*I*t) - cos(theta) - 1)*e^(-I*t)                  (-I*cos(phi) - sin(phi))*sin(t)*sin(theta)]
[            -1/2*(e^(2*I*t) - 1)*e^(I*phi - I*t)*sin(theta)  1/2*((cos(theta) + 1)*e^(2*I*t) - cos(theta) + 1)*e^(-I*t)]

Note: I was expecting that G._sympy_() would return the equivalent matrix in Sympy but this method does not exist. It would be nice to add it. Also, there must be an easier way to convert the sympy G_sympy_exp back to a sage matrix instead of the copy-paste I am doing above.

Using sympy, it seems to work:

sage: a,b,c,d = [a._sympy_() for a in G.list()]
sage: from sympy import Matrix
Matrix as SympyMatrix
sage: G_sympy = Matrix([[a,b], SympyMatrix([[a,b], [c,d]])
sage: G_sympy_exp = G_sympy.exp()
sage: G_sympy_exp.simplify()
sage: G_sympy_exp
Matrix([
[(-(cos(theta) - 1)*exp(2*I*t) + cos(theta) + 1)*exp(-I*t)/2,                I*(I*sin(phi) - cos(phi))*sin(t)*sin(t
heta)],
[        (-exp(2*I*t) + 1)*exp(I*phi)*exp(-I*t)*sin(theta)/2, ((cos(theta) + 1)*exp(2*I*t) - cos(theta) + 1)*exp(-I
*t)/2]])

Then using copy-paste, I am able to construct the matrix G_exp as a Sage object:

sage: G_sympy_exp.tolist()
[[(-(cos(theta) - 1)*exp(2*I*t) + cos(theta) + 1)*exp(-I*t)/2,
  I*(I*sin(phi) - cos(phi))*sin(t)*sin(theta)],
 [(-exp(2*I*t) + 1)*exp(I*phi)*exp(-I*t)*sin(theta)/2,
  ((cos(theta) + 1)*exp(2*I*t) - cos(theta) + 1)*exp(-I*t)/2]]
sage: G_exp = matrix([[(-(cos(theta) - 1)*exp(2*I*t) + cos(theta) + 1)*exp(-I*t)/2,
....:   I*(I*sin(phi) - cos(phi))*sin(t)*sin(theta)],
....:  [(-exp(2*I*t) + 1)*exp(I*phi)*exp(-I*t)*sin(theta)/2,
....:   ((cos(theta) + 1)*exp(2*I*t) - cos(theta) + 1)*exp(-I*t)/2]]
....: )
sage: G_exp
[-1/2*((cos(theta) - 1)*e^(2*I*t) - cos(theta) - 1)*e^(-I*t)                  (-I*cos(phi) - sin(phi))*sin(t)*sin(theta)]
[            -1/2*(e^(2*I*t) - 1)*e^(I*phi - I*t)*sin(theta)  1/2*((cos(theta) + 1)*e^(2*I*t) - cos(theta) + 1)*e^(-I*t)]

Note: I was expecting that G._sympy_() would return the equivalent matrix in Sympy but this method does not exist. It would be nice to add it. Also, there must be an easier way to convert the sympy G_sympy_exp back to a sage matrix instead of the copy-paste I am doing above.