tree functions daily exercise

xah at xahlee.org xah at xahlee.org
Mon May 16 05:42:09 EDT 2005


K!
http://en.wikipedia.org/wiki/K_programming_language

Interesting.
Looking at your program, they are so short. I don't know if they are
full implementation or what...

Btw, the functions listed at
 http://xahlee.org/PerlMathematica_dir/Matica.html
are motly from Mathematica, except the Tree Index Set Utilities:
   RandomIndexSet, LeavesIndexSet, NonleavesIndexSet, MinimumIndexSet,
   CompleteIndexSet, IndexSetSort, TreeToIndexSet, IndexSetToTree

which isn't trivial to code. (nor is it trivial for some of the
Mathematica functions)
the complete documentation can be seen online
http://documents.wolfram.com/mathematica/

 Xah
 xah at xahlee.orghttp://xahlee.org/


sa wrote:
> xah:
>
> i've provided k implementations here:
>
>     http://www.nsl.com/k/xah.k
>
> of a dozen or so of the functions in your toolkit.  many are trivial,
> since they're simply k primitives.  e.g. transpose is just +:
>
> here are some of the definitions (the script contains test-examples
> as well):
>
> range1:!:
> range2:{x+!1+y-x}
> range3:{x+z*!1+_(y-x)%z}
> depth:{:[(@x)|~#x;0;1+|/_f'x]}
> leaves:,//
> leafcount:#leaves@
> leafpaths:{:[@x;,();,/(!#x),/:'_f'x]}
> subpaths:{(1+!#x)#\:x}
> nonleafpaths:?,/subpaths'-1_'leafpaths@
> nonleafcount:#nonleafpaths@
> nodecount:+/(leafcount;nonleafcount)@\:
> dimensions:^:
> part:.
> transpose:+:
> apply:{y{x'}/x}
> flattenat:{apply[,/;y]x}
> rotateleft:1!
>
> my immediate reaction is that a well-designed set of primitives
> obviates the need for such a toolkit.
> 
> nb: i've eliminated the newsgroup crossposting.




More information about the Python-list mailing list