On Tue, Aug 9, 2011 at 3:54 PM, Uriel Zylbermann
<[email protected]> wrote:
> (=([:+/((0=((|~)([:>:[:i.-&1)))#([:>:[:i.-&1))))

Note that you have a number of unnecessary parenthesis here.

If you are using J6, try (from the menu)

Edit -> Configure...

Then in the middle of the screen, in the region labeled Display Form,
select Linear (and hit OK).

Then, if you type this expression in, you will see the result:

= ([: +/ (0 = (|~ ([: >: [: i. -&1))) # [: >: [: i. -&1)

That said, note that this leaves off the outer parenthesis, and also
it includes some extra parenthesis for emphasis (the right tine of
hooks are parenthesized).  If we discard the parenthesis which were
added for clarity (they are easy to get back), and we add the outer
parenthesis, it looks like this:

   (=  [: +/ (0 = (|~ [: >: [: i. -&1)) # [: >: [: i. -&1)

Testing:

   I. (=  [: +/ (0 = (|~ [: >: [: i. -&1)) # [: >: [: i. -&1)"0 i. 30
6 28

I probably did not break anything, yet.

And note that [: instances can be replaced by an @ or @: formulation:

   I. (=  (0 = (|~ >:@i.@-&1)) +/@# >:@i.@-&1)"0 i. 30
6 28

And note also that that >:@i.@-&1 phrase is repeated twice, maybe we
can get rid of it?

   (([ = (0 = |~) +/@# ]) >:@i.@-&1)

Note that I have to have a [ at the beginning of the left part of this
expression, so that |~ gets both of the arguments it needs.

This is getting near to the limit of the simplifications I can see,
but I can trade a pair of parenthesis for a cross operator:

    (([ = ] +/@#~ 0 = |~) >:@i.@-&1)

And, I can trade >:@ for 1 +

    (([ = ] +/@#~ 0 = |~) 1 + i.@-&1)

And, I can replace -&1 with <:

   ([ = ] +/@#~ 0 = |~) 1 + i.@<:

Though it might be better to express that using under:

   (([ = ] +/@#~ 0 = |~) i.&.<:)

Note that I do not recommend doing these kind of gyrations when
actively working on code.  But this kind of thing can be a handy
exercise when studying code -- by manipulating it (and testing it) you
sort of have to learn how it's working.

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

Reply via email to