Re: ListDimension function
- To: mathgroup at smc.vnet.net
- Subject: [mg72580] Re: ListDimension function
- From: "Ray Koopman" <koopman at sfu.ca>
- Date: Thu, 11 Jan 2007 02:36:26 -0500 (EST)
- References: <eo25ue$as5$1@smc.vnet.net>
car... 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.
I'm not at a machine where I can try this, but how about something
like:
ListDim[x_?AtomQ] := 0;
ListDim[x_] := Boole[Head@x == List] + Max[ListDim /@ x]
I don't know what you want to do with lists that appear inside other
expressions, such as
{Outer[f, list1, list2], Outer[g, list3, list4]}
which I think ListDim would treat as equivalent to
{f, list1, list2, g, list3, list4}.