Bo Jacoby asked:
> Can the expression
>   u&(-v)*u&v
> be simplified?

I responded with:
>  (*];.0)@:(u&v)

I just realized that my reformulation is actually longer than your original:

           u     =.  !/
           v     =.  i.@:>:
        
           hg0   =.  u&(-v)*u&v
           hg1   =.  (*];.0)@u&v
           
           (-.&' ' ,&# ;:)@(5!:5) HGs =. hg0`hg1              NB.  # chars, # 
words
        10 10
        11 10

though not by much.  It's also somewhat faster:
        
           5j1 ": (%"1 <./)  TS =. 5 ts&> HGs ,L:0 '~ 2000'   NB. time-space
comparison on large dataset
          2.0  1.0
          1.0  1.2

But the question is whether you think the reformulation is worth it for
just a factor of 2.  I guess it depends on whether you think "slightly
longer but less redundant" is simpler than your symmetric formulation, and
whether you find  ];.0  obscure.

By the way, stylistically I prefer to put the more complex tine of a fork
on the right.  Often this allows me to elide parens, but I also think it
scans better:

           u&(-v) * u&v
vs
           u&v * u&(-v)

Here, we get a gentler introduction to the idea, and then we get to see how
the right tine changed from the "basis".  Another indication that a
stylistic rule has merit is if it increases or retains a formula's
simplicity after "algebraic reduction".  For example, considering only the
monads (though you're concerned with the dyads), we could express the
second formulation as  *&:u&v -  .  But for the first one we'd have to add
an extra reflex  *&:u&v~ -  .

-Dan

PS:  The fact that J permits algebraic manipulations without even a
reference to data is another reason I enjoy it.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to