This is a Mathematica package for doing tensor operations using Einstein summation rules, which is especially useful if you are working with special relativity or elasticity.
This package:
- Does basic tensor operations including:
- Tensor product
- Tensor contract
- Symmetrize and anti-symmetrize
- Derivative & parallel transport derivative in curved space.
- Has complete support for Einstein summation rules.
- Supports calculation curved space of arbitrary dimension.
This package has the following exceptional features which significantly reduces your effort when computing Einstein summation.
- WRITE AND COMPUTE!!! You can painlessly input the expression using virtually anything:
- Use Operators everywhere! You can use and as operators! You may also get a result in the form of a operator!
- Free Symmetrize! Support a very free usage of symmetrize symbol () and anti-symmetrize symbol []. e.g. you can write , or even , which do summation on first then symmetrize .
- Support symbolic tensors!!! You can work on subjects even if you don't know the exact value or even the exact dimension, thanks to Mathematica's latest feature!!!
To use this package, Mathematica 11.3 or later are required. (There is a slight possibility that Version 10 can work, if you have tried, please notify me and I'll update~) Wolfram Engine is also a viable option, which is freely available to developers.
The simplest way to configure your package is executing the following code:
PacletInstall["https://github.com/wjxway/EasyEinsteinSummation/releases/download/0.3.0/EinsteinSummation-0.3.0.paclet"]
Or you can download the lastest release of EinsteinSummation package on the Releases page, and install with:
PacletInstall["directory"]
To load and test the package, execute
<<EinsteinSummation`
SetVars[{x,y}];
$constants={a,b};
SetMetric[DiagonalMatrix@{a,b}]
AddTensorToDataset[<|"Symbol"->"A","IndexPosition"->{-1},"Value"->{p[x,y],q[x,y]}|>]
EvaluateEinsteinSummation["\*SuperscriptBox[\(g\), \(pq\)]\*SubscriptBox[\(\[Del]\), \([p\)]\*SubscriptBox[\(\[Del]\), \(\(q\)\(]\)\)]\*SuperscriptBox[\(A\), \(r\)]"]["Value"]//Normal
If you get {0,0} then the package is (probably) working right!
As a demonstration of basic workflow, here we will try to figure out the Killing vector field in a 2-D spherical surface.
Step 1. First load the package:
<<EinsteinSummation`
Step 2. Setup parameters of space and the corresponding metric.
By default, variables are {t,x,y,z} and metric is diag{-1,1,1,1}, which corresponds to 4-D Minkovski spacetime.
Here, we are working on a spherical surface , so . To optimize your reading, we will use t and p as parameters.
SetVars[{t, p}];
SetMetric[DiagonalMatrix@{1, Sin[t]^2}];
Step 3. Then we need to define a (1,0) style vector as Killing vector.
Here we encountered our first vector(tensor). To input it, you have two choices:
-
Manually input, here you will need to specify three properties: the name of your tensor, "Symbol", the position of its indexes, "IndexPosition" which takes 1 for upper index and -1 for lower index, and the value of your tensor, "Value":
AddTensorToDataset[<|"Symbol" -> "K", "IndexPosition" -> {1}, "Value" -> {kt[t, p], kp[t, p]}|>];
-
Or you might do the other way, You can:
- Use Mathematica's built-in Basic Math Assistant (which can be found under Palettes menu) and type in directly, and write like.
AddTensorToDataset["\!\(\*SuperscriptBox[\(K\), \(\[Mu]\)]\)", {kt[t, p], kp[t, p]}];
BTW, Don't be frightened by the long expression, this is just how Mathematica format things, not how you should input them.
- Use LaTeX To Type in the equation.
AddTensorToDataset["K^\\mu", {kt[t, p], kp[t, p]}];
- Use Word/MathType To Type in equation (A bit complicated, For details check this wiki page)
Step 4. Type in the equation same as the step above and evaluate!!!
res=EvaluateEinsteinSummation["\!\(\*SubscriptBox[\(\[Del]\), \((\[Mu]\)]\)\!\(\*SubscriptBox[\(K\), \(\(\[Nu]\)\()\)\)]\)"]
Unfortunately, you cannot use TeX Strings here due to some internal bugs of Mathematica.
Step 5. Analyze the result.
You will obtain a tensorSymb
object which shows you all sorts of information about the resulting tensor. From res["IndexName"]
you know that the free indexes are and there're no symmetry marker left. and from res["IndexPosition"]
you know that the result is a (0,2) type tensor. an finally, from res["Value"]
you know the computation's result, which is in the form of SparseArray
in this case.
You can do further analysis like TensorSymmetry@res["Value"]
which tells you that the resulting tensor is symmetric.
If you want to do something more later, you can also store it like:
AddTensorToDataset["Q", res];
so next time when you want to use this you only need to write Q in your string.
For more details, please check the Mathematica documentation built in the package (Working...). (The package is properly written so the documentation can seamlessly integrate into the documentation center!)