Ouch, you are taking very small steps in
your code, and it requires quite a bit of
thought to step back and try to see the bigger
picture.

One of the first things I noticed was that addVP
was always used with rank 0 1.  So it would make
sense to move that rank into its definition.

Another thing I noticed was that addVP and
cartanReflect were both using origin 1 indices
which required extra code to use.  So it would
make sense to use origin 0 (for cartanReflect)
and only adjust the numbers used for addVP.

These would simplify the right part of the hook
newFromWeight from >:@:(0&< # i. @: #)
to I.@:>&0

But then there's the bit where addVP is being
used at rank 0 1, and it's really just generating
a bit vector -- one invocation of an explicit
function per generated bit seems like a bit much.

Its rank 0 1 definition is: given a count x and
a vector 1 return 1 if numbers after the first
x are non-negative.  And if we could turn x into
an index, instead of a count, we would not have
to add 1 to it before it was useful.

In other words,

   (1+0 2 3) addVP"0 1]_1 _3  1  1, 1 _3 _1  2,: 1 _4  2 _1
0 1 1
   (0 2 3) ((>: (#,:@i.)/@$) */"1@:+. 0&<@])_1 _3  1  1, 1 _3 _1  2,: 1 _4  2 _1
0 1 1

But this is just scratching the surface...

I am still trying to deduce the purpose of "reflect" or,
more properly, the purpose of nextLevel.  I feel that
some serious simplifications are possible, but I am
too wrapped up in details to see where I want to go
right now.

That said, here is my current code, which
I think is equivalent to yours:

cartReflect =: 1 : 0
:
  y - y *&(x&{) m
)
keepv =:(>: (#,:@i.)/@$) */"1@:+. 0&<@]
byLev =: 3 : 0
  'w A maxLevel' =. y
  reflect =: A cartReflect"0 1
  newFromWeight =. 4 : '(#~ y&keepv) y reflect x' I.@:>&0
  nextLevel =. ;@:(<@newFromWeight " 1)
  currentLevel =. weights =.,: w
  for.i.maxLevel
  do.
    currentLevel =. nextLevel currentLevel
    weights =. weights , currentLevel
  end.
)
A =: 4 4 $ 2 _1 0 0 _1 2 _1 0 0 _1 2 _1 0 0 _1 2
assert (byLev-: byLevel) (1 1 1 1 ; A ; 10)

(where byLevel is your implementation)

Can you describe the purpose of this code?

(I might be able to figure this out for myself, but for
now I just need to get out of the weeds.)

One obvious step, by the way, would be to define
newFromWeight so it did not need to be used at
rank 1, which should get rid of the need for the
(;@:)(<@) thing you have there.  A related issue
would be to get rid of the need for rank 0 1 in
the definition of reflect itself.

But there are so many things I do not understand,
about the concepts underlying this code.  For example,
what are "weights" and what do they accomplish?

Thanks,

-- 
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to