PRTensor.mws

>    restart:

>   

>    # Define operations for multiplication of tensors

>   

>    PTM:=proc(R,S)
# "Pure tensor" (tensor monomial) multiplication
# This procedure is not used on the command line, but by the procedures `&*` and `&^`

# convert R,S to lists of the form [c,[a,b]] that represent c*(a \otimes b)
# or more generally [c,[a_1,a_2,...,a_n]]
# represents c*(a_1 \otimes ... \otimes a_n)
local A,B:
if type(R,`*`) then A:=[mul(op(i,R),i=1..nops(R)-1),[op([op(R)][nops(R)])]]
else A:=[1,[op(R)]] fi;
if type(S,`*`) then B:=[mul(op(i,S),i=1..nops(S)-1),[op([op(S)][nops(S)])]]
else B:=[1,[op(S)]] fi;

RETURN(A[1]*B[1]*`&o`(seq(A[2,i]*B[2,i],i=1..nops(A[2]))));
end:

>   

>    `&*`:=proc(R,S)
# Multiplies sums of "pure tensors".
local M,r,s;
if type(R,`+`) then r:=nops(R) else r:=1 fi; #print(r);
if type(S,`+`) then s:=nops(S) else s:=1 fi; #print(s);
if (r=1 and s=1) then
   RETURN(PTM(R,S));

 elif r=1 then
   M:=matrix(r,s,(i,j)->PTM(R,op(j,S)));

 elif s=1 then
   M:=matrix(r,s,(i,j)->PTM(op(i,R),S));

 else
   M:=matrix(r,s,(i,j)->PTM(op(i,R),op(j,S)));
fi;
RETURN(add(add(M[i,j],i=1..r),j=1..s))
end:

>   

>    `&^`:=proc(a,p)
# An exponentiation for sums of "pure tensors".
if p=0 then RETURN(1)
elif p=1 then RETURN(a)
else RETURN(`&*`(a,`&^`(a,p-1))); fi;
end:

>   

>    # Save these procedures in a file `PRTensor.m` that can be read into "future" Maple worksheets

>    save PTM,`&*`,`&^`, `PRTensor.m`;

>   

>   

>   

>   

>   

>   

>    # Sample future Maple worksheet

>   

>    restart:

>    # Load the file `PRTensor.m` so that we can use the procedures `&*` and `&^`

>    read `PRTensor.m`;

>   

>    # Remark: to get the "define" command to work
# correctly, you may need to download the
# package for Maple called "Bigebra" from
# http://math.tntech.edu/rafal/

>    with(Bigebra);

Increase verbosity by infolevel[`function`]=val -- use online help > ?Bigebra[help]

[`&cco`, `&gco`, `&gco_d`, `&gco_pl`, `&map`, `&v`, EV, VERSION, bracket, contract, drop_t, eps, gantipode, gco_unit, gswitch, hodge, linop, linop2, lists2mat, lists2mat2, make_BI_Id, mapop, mapop2, me...
[`&cco`, `&gco`, `&gco_d`, `&gco_pl`, `&map`, `&v`, EV, VERSION, bracket, contract, drop_t, eps, gantipode, gco_unit, gswitch, hodge, linop, linop2, lists2mat, lists2mat2, make_BI_Id, mapop, mapop2, me...

>   

>    # Define the tensor product.
define(`&o`,flat,multilinear);
# Remark: we could've named this tensor product `&t` or something else besides `&o`

>   

>    # Examples

>   

>    &*( &o(4*v,3*w)+&o(2*v,5*y), &o(x,z) );

12*`&o`(v*x,w*z)+10*`&o`(v*x,y*z)

>    &^( &o(4*v,3*w), 3);

1728*`&o`(v^3,w^3)

>    # Remark: for more options about the kinds of scalars allowed (e.g. integer, rational, etc.), see the Bigebra documentation.