Thanks for the thoughts!

> not as pretty, but simpler and pretty enough?
> 
>  (":"0@i.@# (,~ #&'-')"1 0 ]) 0 1 2 2 1 1 2 2 3
> 
> 0
> 
> -1
> 
> --2
> 
> --3
> 
> -4
> 
> -5
> 
> --6
> 
> --7
> 
> ---8

This is sort of in between the raw depth vector and the graph representation.

It's probably fine for smallish trees, but especially with larger trees, I find
it hard to visually pick out subtrees. For that, the explicit links between
sibling nodes is really helpful.

Otherwise, an even more minimal "mountain graph" is probably serviceable:

       (=/ ~.) d
    1 0 0 0
    0 1 0 0
    0 0 1 0
    0 0 1 0
    0 1 0 0
    0 1 0 0
    0 0 1 0
    0 0 1 0
    0 0 0 1

> J has several functions built in to process trees that are represented as 
> nested box structures, and so may be useful in converting from various 
> representations to and from such boxed structures.  Or more interesting to 
> me, but I need more thought on this.

It really depends. Nested boxes require quite a lot of overhead, no? Pilfering
the structure of an example tree from Voc, Appendix A (Foreign Conjunction),
Representation (5!:) [0]:

       [ s=: (((0;1;2);3;<4;5));6;7  NB. Nested box representation
    ┌─────────────────┬─┬─┐
    │┌───────┬─┬─────┐│6│7│
    ││┌─┬─┬─┐│3│┌─┬─┐││ │ │
    │││0│1│2││ ││4│5│││ │ │
    ││└─┴─┴─┘│ │└─┴─┘││ │ │
    │└───────┴─┴─────┘│ │ │
    └─────────────────┴─┴─┘
       7!:5 <'s'
    512
       [ t=: 0 1 2 3 3 3 2 2 3 3 1 1  NB. Depth vector representation
       7!:5 <'t'
    256

That said, it would be neat if we could trick (5!:4) into pretty-printing (s)
for us.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to