MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: ListDimension function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg72587] Re: [mg72595] ListDimension function
  • From: Adriano Pascoletti <pascolet at dimi.uniud.it>
  • Date: Thu, 11 Jan 2007 03:04:34 -0500 (EST)
  • References: <200701100907.EAA13288@smc.vnet.net>

On 10 gen 2007, at 10:07, carlos at colorado.edu wrote:

> Hi - I need a short function ListDimension that
> given a list returns its "brace dimensionality" =
> max number of brace levels to reach deepest entry.
> Examples
>
>    List         ListDimension
>    a+b                   0
>    {1,2,x*y}             1
>    {1,2,{3,0,1}}         2
>    {{},{},{}}            2
>    {{},{{1,2}},a}        3
>
> Built-in functions dont seem to be of help.
> Dimensions is restricted to matrix or tensor type of lists.
> Depth (minus 1) doesnt help as it is entry type dependent:
>
>    Depth[{1,2,3}] -> 2
>    Depth[{1,2,3+a}] -> 3
>    Depth[{1,2,3+a+Sqrt[x+y]}] -> 5
>
> For the above three, ListDimension=1.

Carlos,
this works on your examples.
Adriano Pascoletti

In[1]:= h[{}] = 1;
h[l_List] := 1 + Max[h /@ l];
h[l_] /; Head[l] =!= List := 0;

In[4]:= h[a + b]
Out[4]= 0

In[5]:= h[{1, 2, x*y}]
Out[5]= 1

In[6]:= h[{1, 2, {3, 0, 1}}]
Out[6]= 2

In[7]:= h[{{}, {}, {}}]
Out[7]= 2

In[8]:= h[{{}, {{1, 2}}, a}]
Out[8]= 3



  • Prev by Date: ListDimension function
  • Next by Date: How install tools for mmade?
  • Previous by thread: Re: ListDimension function
  • Next by thread: Re: ListDimension function