# Adding a symbolic tensor and a specific one

I need to add a symbolic tensor and a specific one, but it seems the symbolic tensor is always treated as a number and is added in very components of the specific tensor.

Firsts I give assumptions

$Assumptions = v1 \[Element] Vectors[4] && v2 \[Element] Vectors[4]  so the tensor product of v1 and v2 should be a rank 2 tensor in 4 dimension. The functions like TensorRank and TensorDimensions agree with this. But when I try to add it to a tensor whose components are given explicitly things go wrong. TensorProduct[v1, v2] + DiagonalMatrix[{1, 2, 3, 4}]  gives a result like this: {{1 + v1\[TensorProduct]v2, v1\[TensorProduct]v2, v1\[TensorProduct]v2, v1\[TensorProduct]v2}, {v1\[TensorProduct]v2, 2 + v1\[TensorProduct]v2, v1\[TensorProduct]v2, v1\[TensorProduct]v2}, {v1\[TensorProduct]v2, v1\[TensorProduct]v2, 3 + v1\[TensorProduct]v2, v1\[TensorProduct]v2}, {v1\[TensorProduct]v2, v1\[TensorProduct]v2, v1\[TensorProduct]v2, 4 + v1\[TensorProduct]v2}}  It is clear that MMA treated $$v_1 \otimes v_2$$ as a number instead of a rank 2 tensor, so it is added to every components of the matrix. So how can it be added correctly? I mean, I want it to keep the result just as the sum of $$v_1 \otimes v_2$$ and the matrix given explicitly (as this can not be simplified actually), so I can do some further calculation. • The "usual Mathematica model" is that it applies every rule and operator it can to try to complete as much as it can for every calculation. When it finally runs out of things that it can do it then shows you the result. Imagine your reaction if you gave it matrix.vector and it didn't know whether it should perform that dot product or not. Now at a more expert level, it is possible, using things like Hold to tell it that you do not want it to perform a specific step yet. Maybe that is what you want, cannot tell. Later you can ReleaseHold to remove the Hold and do the step. Read docs. – Bill Dec 11, 2023 at 15:49 ## 1 Answer $Version

(* "13.3.1 for Mac OS X ARM (64-bit) (July 24, 2023)" *)

Clear["Global*"]


\$Assumptions only affects functions that use the option Assumptions. Since neither TensorProduct nor Plus have options, you need to use either implicit or explicit tensors throughout. Using explicit,

(Format[#[n_]] := Subscript[#, n]) & /@ {v1, v2};

vec1 = Array[v1, 4];
vec2 = Array[v2, 4];

(mat = TensorProduct[vec1, vec2] + DiagonalMatrix[{1, 2, 3, 4}]) //
MatrixForm


#[mat] & /@ {TensorRank, TensorDimensions}

(* {2, {4, 4}} *)
`