import sympy as sp
from sympy.matrices import Matrix
from sympy import cos, sin
import time

def T_sigma(t):
    return Matrix([[cos(t)**2, sin(t)**2, 2*cos(t)*sin(t)],
                [sin(t)**2, cos(t)**2, -2*cos(t)*sin(t)],
                [-cos(t)*sin(t), cos(t)*sin(t), cos(t)**2 - sin(t)**2]])

def T_epsilon(t):
    return Matrix([[cos(t)**2, sin(t)**2, cos(t)*sin(t)],
                    [sin(t)**2, cos(t)**2, -cos(t)*sin(t)],
                    [-2*cos(t)*sin(t), 2*cos(t)*sin(t), cos(t)**2 - sin(t)**2]])

t0 = time.process_time()

t = sp.Symbol('t')
s11, s22, s66, s12 = sp.symbols('s11, s22, s66, s12')

S = Matrix([[s11, s12,  0 ],
            [s12, s22,  0 ],
            [0  ,  0 , s66]])

Q = S.inv()
Q_prime1 = T_sigma(-t) * Q * T_epsilon(t)
Q_prime2 = T_sigma(t) * Q * T_epsilon(-t)
Q_prime = sp.simplify(sp.trigsimp(Q_prime1 + Q_prime2))

sp.pprint(Q_prime)