Re: TensorQ

• To: mathgroup at smc.vnet.net
• Subject: [mg20699] Re: [mg20686] TensorQ
• From: Bob HYDE <bobhyde at wanadoo.fr>
• Date: Mon, 8 Nov 1999 02:48:44 -0500
• Organization: ALP OPTICS
• References: <199911070710.CAA10906@smc.vnet.net.>
• Sender: owner-wri-mathgroup at wolfram.com

```Ted,  a list is a tensor so it is a bit much to exclude it.

As I see it;
In Mathematica expressions with a Head List are all Tensors of rank  1 to  Infinity.  A
simple list has Tensor Rank =1. A matrix has tensor rank =2
Above 2 we have what are commonly referred to as  tensors as distinct from
simple matrices.
Think of them all as arrays..

Example.

In[1]:=
l = Array[f, 1];
m = Array[f, {1, 2}];
t = Array[f, {1, 2, 3}];

In[4]:=
TensorRank[l]

Out[4]=
1

In[5]:=
TensorRank[m]

Out[5]=
2

In[6]:=
TensorRank[t]

Out[6]=
3

Bob

"Ersek, Ted R" a *crit :

> I was thinking it would be nice to have a function that determines if
> something is a vector, matrix, or higher dimension analogue of a matrix.  Is
> something like that called a tensor?  I know almost nothing about tensors.
> Anyway I wrote an elegant program that performs such a test and called it
> TensorQ.
>
> In[1]:=
> TensorQ[tnsr_List] := With[{ s1=Level[tnsr,{TensorRank[tnsr]}]  },
>     FreeQ[s1,_List,{1}]
>  ]
>
> Suppose (tnsr) above is a vector, matrix, or similar structure with greater
> dimensions.
> Then (s1) will be all the elements of the vector, matrix, etc.
> Next I use FreeQ to see if any of these elements have the head List.
> I give FreeQ the level specification {1} which tells it to ignore lists
> inside the elements.
>
> TensorQ  does what I want in the examples below.
>
> ----------------
> In[2]:=
> TensorQ[  {1, 2, foo[3, {1}] }  ]
> Out[2]=
> True
>
> In[3]:=
> TensorQ[{{1,2,3},{2,3,4}}]
> Out[3]=
> True
>
> In[4]:=
> TensorQ[ {{{2, 1}, {3, 2}}, {{4, foo[3, {1}]}, {5, 4}}} ]
> Out[4]=
> True
>
> In[5]:=
> TensorQ[{1,2,{3}}]
> Out[5]=
> False
>
> In[6]:=
> TensorQ[{{1,2,3},{2,3,4,5}}]
> Out[6]:=
> False
>
> In[7]:=
> TensorQ[{{{2,1},{3,2}},{{4,3,4},{5,4}}}]
> Out[7]=
> False
>
> In[8]:=
> TensorQ[{f[1,2,3],f[3,4,5]}]
> Out[8]=
> True
>
> You can read about Level and level specification at my web site.
>
> --------------------
> Regards,
> Ted Ersek
>
> For Mathematica tips, tricks see
> http://www.dot.net.au/~elisha/ersek/Tricks.html

```

• References:
• TensorQ
• From: "Ersek, Ted R" <ErsekTR@navair.navy.mil>
• Prev by Date: How to get the pdf of a complex variable?
• Next by Date: Re: Bug in math4
• Previous by thread: TensorQ
• Next by thread: Re: TensorQ