The basic imports and the variables we'll be using:
In [1]:
from __future__ import division
import sympy
from sympy import *
from sympy import Rational as frac
import simpletensors
from simpletensors import Vector, TensorProduct, SymmetricTensorProduct, Tensor
init_printing()
var('vartheta, varphi')
var('nu, m, delta, c, t')
# These are related scalar functions of time
var('r, v, Omega', cls=Function)
r = r(t)
v = v(t)
Omega = Omega(t)
# These get redefined momentarily, but have to exist first
var('nHat, lambdaHat, ellHat', cls=Function)
# And now we define them as vector functions of time
nHat = Vector('nHat', r'\hat{n}', [cos(Omega*t),sin(Omega*t),0,])(t)
lambdaHat = Vector('lambdaHat', r'\hat{\lambda}', [-sin(Omega*t),cos(Omega*t),0,])(t)
ellHat = Vector('ellHat', r'\hat{\ell}', [0,0,1,])(t)
# These are the spin functions -- first, the individual components as regular sympy.Function objects; then the vectors themselves
var('S_n, S_lambda, S_ell', cls=Function)
var('Sigma_n, Sigma_lambda, Sigma_ell', cls=Function)
SigmaVec = Vector('SigmaVec', r'\vec{\Sigma}', [Sigma_n(t), Sigma_lambda(t), Sigma_ell(t)])(t)
SVec = Vector('S', r'\vec{S}', [S_n(t), S_lambda(t), S_ell(t)])(t)
In [3]:
nHat
Out[3]:
In [4]:
diff(nHat, t)
Out[4]:
In [5]:
diff(lambdaHat, t)
Out[5]:
In [6]:
diff(lambdaHat, t).components
Out[6]:
In [7]:
diff(lambdaHat, t).subs(t,0).components
Out[7]:
In [8]:
diff(lambdaHat, t, 2).components
Out[8]:
In [9]:
diff(lambdaHat, t, 2).subs(t,0).components
Out[9]:
In [10]:
diff(ellHat, t)
Out[10]:
In [11]:
diff(nHat, t, 2)
Out[11]:
In [12]:
diff(nHat,t, 3)
Out[12]:
In [13]:
diff(nHat,t, 4)
Out[13]:
In [14]:
diff(SigmaVec,t, 0)
Out[14]:
In [15]:
SigmaVec.fdiff()
Out[15]:
In [16]:
diff(SigmaVec,t, 1)
Out[16]:
In [17]:
diff(SigmaVec,t, 2)
Out[17]:
In [18]:
diff(SigmaVec,t, 2) | nHat
Out[18]:
In [19]:
T1 = TensorProduct(SigmaVec, SigmaVec, ellHat, coefficient=1)
T2 = TensorProduct(SigmaVec, nHat, lambdaHat, coefficient=1)
tmp = Tensor(T1,T2)
display(T1, T2, tmp)
In [20]:
diff(tmp, t, 1)
Out[20]:
In [21]:
T1+T2
Out[21]:
In [22]:
T2*ellHat
Out[22]:
In [23]:
ellHat*T2
Out[23]:
In [24]:
T1.trace(0,1)
Out[24]:
In [25]:
T2*ellHat
Out[25]:
In [26]:
for k in range(1,4):
display((T2*ellHat).trace(0,k))
In [27]:
for k in range(1,4):
display((T2*ellHat).trace(0,k).subs(t,0))
In [28]:
T1.trace(0,1) * T2
Out[28]:
Sympy can be a little tricky because it caches things, which means that the first implementation of this code silently changed tensors in place, without meaning to. Let's just check that our variables haven't changed:
In [29]:
display(T1, T2)
In [30]:
T3 = SymmetricTensorProduct(SigmaVec, SigmaVec, ellHat, coefficient=1)
display(T3)
T3.trace(0,1)
Out[30]:
In [31]:
diff(T3, t, 1)
Out[31]:
In [32]:
T3.symmetric
Out[32]:
In [33]:
T3*ellHat
Out[33]:
In [34]:
ellHat*T3
Out[34]:
In [35]:
T1+T3
Out[35]:
In [6]:
T1 = SymmetricTensorProduct(SigmaVec, SigmaVec, ellHat, nHat, coefficient=1)
display(T1)
display(T1.trace())
In [37]:
T1*T2
Out[37]:
In [38]:
type(_)
Out[38]:
In [39]:
import simpletensors
isinstance(__, simpletensors.TensorProductFunction)
Out[39]:
In [40]:
SymmetricTensorProduct(nHat, nHat, nHat).trace()
Out[40]:
In [7]:
diff(T1.trace(), t, 1)
Out[7]:
In [8]:
diff(T1.trace(), t, 2)
Out[8]:
In [9]:
diff(T1.trace(), t, 2).subs(t,0)
Out[9]:
In [ ]: