There's been a number of people asking how to set a tensor-valued variable in xAct; equivalently, how to define a new tensor from an expression of existing tensors.

For example, a very simple example: if we have some expression

$$A^{ab} = T^{a}_{\>\>c} B^{bc}$$

it would be nice to be able to refer to a single tensor $A$ and have xAct understand what I'm talking about, rather than carting the expression around all the time, and also without having to define its components in terms of the components of its dependent tensors.


1 Answer 1


As far as I know there's been no satisfactory answer on Mathematica SE; the answers that are easily found by Google are all workarounds. So here's a canonical answer.

The function that does this is in fact buried in the documentation for xTensor, though it's not the most discoverable as its name is rather unintuitive. The function required is IndexSet, which as the name implies defines a tensor as a function of its indices... and, implicitly, as a function of some tensorial expression. For example, we might say

defTensor[A[a, b], M];
IndexSet[A[a_, b_], T[a, -c] B[b, c];

and this would do what we wanted above; now we can, for example, symmetrize $A$ and then expand that expression as a sum of products of $T$ and $B$.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.