Hi Raul,

What I am trying to do is a prerequisite to tree processing as in [1]. This
page shows parent vectors built manually, but in Dr. Hsu's thesis [2] those
are derived from the depth vector describing the tree, itself derived from
the tree in "record format" ( p.66 of the pdf in [2] ). The purpose is fast
manipulation of trees by total ordering of nodes in 2D space using 2 simple
vectors (a. parent vector and b. left sibling vector), and the APL sentence
I showed (p.73 in [2]) is the initial step in that process.
Now, of course this cannot work as a literal translation from APL to J
since the APL sentence designed for a nested APL array has to be adapted to
the J boxed array model. That's what I am trying to do.

I had your

;@(+L:0 L.)L:1^:_ L.L:0 ast

as

# S:1@{:: ast

which yields the same answer less efficiently, but indeed that's not the
desired result since it doesn't use the same tree model.

I've been trying quite hard, but I'm completely stumped.

[1] https://code.jsoftware.com/wiki/User:Devon_McCormick/Tree
[2] caution, big file!
https://scholarworks.iu.edu/dspace/bitstream/handle/2022/24749/Hsu%20Dissertation.pdf?sequence=1&isAllowed=y

On Mon, May 24, 2021 at 12:42 AM Raul Miller <rauldmil...@gmail.com> wrote:

> The "no base case" phrase might mean that there's some infinite loop
> transformation mechanism in the language.
>
> That said, I also don't understand that result.
>
> Here's the example value 'ast' represented in J:
>
> t=:'.'
> ast=:t;(t;t);(t;(t;t);t);(t;(t;t;t);(t;t;t);t)
>
> And, here's the corresponding "depth vector in record format" mapped
> back onto the corresponding positions in ast:
>
> 0;(1;2);(1;(2;3);2);(1;(2;3;3);(2;3;3);2)
>
> So either this result is wrong, or 'depth' in this context does not
> have a simple relationship with 'depth' as we know it in J.
>
> Here's J's idea of the depths of each of the boxes:
>
>     ;@(+L:0 L.)L:1^:_ L.L:0 ast
> 1 2 2 2 3 3 2 1 2 2 2 2 2 2 1
>
> We could treat the top level box as depth 0 easily enough
>     <: ;@(+L:0 L.)L:1^:_ L.L:0 ast
> 0 1 1 1 2 2 1 0 1 1 1 1 1 1 0
>
> But obviously that's still different from that "depth vector in record
> format".
>
> Anyways... color me confused.
>
> Is there a simple way of describing the purpose of that "depth vector
> in record format"?
>
> Thanks,
>
> --
> Raul
>
> On Sun, May 23, 2021 at 2:35 PM Raoul Schorer <raoul.scho...@gmail.com>
> wrote:
> >
> > Dear all,
> >
> > I am struggling with the translation of the following APL dyad to J:
> >
> > ∊ 0 {(⊢,(⍺+1)∇⊣)/⌽⍺,1↓⍵} y
> >
> > which is the expression to yield a depth vector from a tree in record
> > format (drawn from Dr. Hsu's thesis). Demo:
> >
> > t ← '∘'
> > ast ← t (t t) (t (t t) t) (t (t t t) (t t t) t)
> > ∊ 0 {(⊢,(⍺+1)∇⊣)/⌽⍺,1↓⍵} ast
> > 0 1 2 1 2 3 2 1 2 3 3 2 3 3 2
> >
> > In particular, I don't understand the control flow and termination
> > condition for the recursion. Dr. Hsu says that this uses tree reduction
> > with no base case.
> >
> > An attempt at a partial litteral translation as:
> >
> > dv =. {{ (];(>:x) dv [)/\ |.x;}.y }}
> >
> >
> > results in an infinite loop. What am I missing? Is there some kind of
> > implicit termination condition in the ∇ primitive?
> >
> >
> > Thanks,
> >
> > Raoul
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to