In Macaulay2, a tensor is stored as a vector which is a member of a tensor module.
i1 : R=QQ[a..h] o1 = R o1 : PolynomialRing |
i2 : T=makeTensor({2,2,2},a..h) +------+------+ o2 = |{a, b}|{c, d}| +------+------+ |{e, f}|{g, h}| +------+------+ 8 o2 : R {2x2x2} |
i3 : class T 8 o3 = R {2x2x2} o3 : Free R-TensorModule of order 3, dimensions {2, 2, 2} |
i4 : vector T o4 = | a | | b | | c | | d | | e | | f | | g | | h | 8 o4 : R |
Tensor products of tensors have the appropriate dimensions.
i5 : X=makeTensor{{a,b},{c,d}} +-+-+ o5 = |a|b| +-+-+ |c|d| +-+-+ 4 o5 : R {2x2} |
i6 : Y=makeTensor{{1_R,2},{3,4}} +-+-+ o6 = |1|2| +-+-+ |3|4| +-+-+ 4 o6 : R {2x2} |
i7 : X**Y +-------------------+-------------------+ o7 = |{{a, 2a}, {3a, 4a}}|{{b, 2b}, {3b, 4b}}| +-------------------+-------------------+ |{{c, 2c}, {3c, 4c}}|{{d, 2d}, {3d, 4d}}| +-------------------+-------------------+ 16 o7 : R {2x2x2x2} |
Tensors can be manipulated similarly to vectors.
i8 : U=makeTensor({2,2,2},{h,g,f,e,d,c,b,a}) +------+------+ o8 = |{h, g}|{f, e}| +------+------+ |{d, c}|{b, a}| +------+------+ 8 o8 : R {2x2x2} |
i9 : T+2*U +----------------+----------------+ o9 = |{a + 2h, b + 2g}|{c + 2f, d + 2e}| +----------------+----------------+ |{2d + e, 2c + f}|{2b + g, 2a + h}| +----------------+----------------+ 8 o9 : R {2x2x2} |