MathGroup Archive 1998

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

Search the Archive

Re: A Bug in Flatten?



Ted,

Perhaps info should give something like

Flatten[expr, n, h] deletes up to n consecutive h in each branch of
expr.

(in The Book 2.1.6 "branch" seems to exclude the head of expr)


Ersek_Ted%PAX1A@mr.nawcad.navy.mil wrote:
> 
> Hi
> This is Ted Ersek
> 
> I got the info on Flatten, and wanted to see what I can do when I give
> it a  third argument.
> 
> In[1]:=
> Remove[f,g];
> ?Flatten
> 
> "Flatten[list] flattens out nested lists.  Flatten[list, n] flattens to
> level \
> n. Flatten[list, n, h] flattens subexpressions with head h."
> 
>  -------------------------------------- Examples:
> In this case it looks like Flatten removed the two outer layers of (f)
> In[2]:=
> s1=g[f[f[f[1],f[2]],f[f[3],f[4]]]];
> Flatten[s1,2,f]
> 
> Out[2]=
> g[f[1],f[2],f[3],f[4]]
> 
> In this case all layers of (f) are removed. In[3]:=
> Flatten[s1,Infinity,f]
> 
> Out[3]=
> g[1,2,3,4]
> 
> In the next examples (f) doesn't appear until the third level. Now
> Flatten doesn't see (f) at all.  Should layers of (f) get removed in
> these examples?
> In[4]:=
> s2=g[g[f[f[f[1],f[2]],f[f[3],f[4]]]]]; Flatten[s2,3,f]
> 
> Out[4]=
> g[g[f[f[f[1],f[2]],f[f[3],f[4]]]]]
> 
> In[5]:=
> Flatten[s2,Infinity,f]
> 
> Out[5]=
> g[g[f[f[f[1],f[2]],f[f[3],f[4]]]]]
> 
> Ted Ersek

-- 
Allan Hayes
Mathematica Training and Consulting
Leicester, UK
hay@haystack.demon.co.uk
http://www.haystack.demon.co.uk
voice: +44 (0)116 271 4198
fax: +44 (0)116 271 8642




  • Prev by Date: Re: Conic Sections and Quadric Surfaces
  • Next by Date: Re: Mathematica frustrations...
  • Prev by thread: A Bug in Flatten?
  • Next by thread: Differential Equation evaluation