//tensor product of A and v for a matrix A and a row vector v tensor_vec:=proc(A,v) local C; local j; begin C:=A*v[1,1]: for j from 2 to linalg::ncols(v) do C:=C.(A*v[1,j]): end_for: //j end_proc: //tensor product of A and B tensor:=proc(A,B) local C; local i; begin C:=tensor_vec(A,linalg::row(B,1)): for i from 2 to linalg::nrows(B) do C:=linalg::stackMatrix(C,tensor_vec(A,linalg::row(B,i))): end_for: //i return(C); end_proc: