MathGroup Archive 1998

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

Search the Archive

Re: A Bug in Flatten?



Ted Ersek,

Here's a simulation of Flatten and FlattenAt. I havn't tested them or studied them in depth. Soon I'll be come to them and there will be implementations with basic constructs. Quick Note: you can have
non-atomic Head in expr as in Flatten[expr,f[x][g]] and it still works...

Clear[flatten];
flatten::"usage"  "flatten simulates the build-in function Flatten. Example: \
flatten[f[1,f[2,f[3,f[4,5]]]],2,f]";

flatten[expr_]:õatten[expr,Infinity,Head@expr];
flatten[expr_,n_Integer]:õatten[expr,n,Head@expr];
flatten[expr_,Infinity]:õatten[expr,Infinity,Head@expr];

flatten[expr_,0,h_]:ápr;
flatten[expr_,1,h_]:‚f[Head@#Ýh,Sequence@@#,#]&)/@expr;
flatten[expr_,n_Integer,h_]:õatten[flatten[expr,n-1,h],1,h];
flatten[expr_,Infinity,h_]:òxedPoint[(flatten[#,1,h]&),expr];

Clear[flattenAt];
flattenAt::"usage"  "flattenAt simulates the build-in function FlattenAt. Example: \
flattenAt[Array[List,{3,2}],2]";

flattenAt[expr_,parts_]:jpAt[(Sequence@@#&),expr,parts];

 Xah, xah@best.com
 http://www.best.com/~xah/Wallpaper_dir/c0_WallPaper.html
 "morality abets evil"




  • Prev by Date: how do I tell math. that expressions are equal?
  • Next by Date: Re: lattice definition: help
  • Prev by thread: how do I tell math. that expressions are equal?
  • Next by thread: Mathematica bug when resolving Contex-names