I wrote:
> >:@<.@^. 1 >. >./@:|@,

Raul responded:
> Personally, I prefer the fork 1 + u over the perhaps more obvious >:@u


In general I agree with you, but in this case I like the sequence of inflected 
arrows*:

  >: @  <. @  ^.

It’d be cuter if >: happened to be spelled >. but I still like it. 

Also, this particular form is closer to the source material I quoted earlier:

   2&#. b. _1
($&2@>:@(2&(<.@^.))@(1&>.)@(>./)@:|@, #: ]) :.(2&#.)

-----^

There is one hypothetical drawback, however.  The sequence  <.@^.  (as well as  
<.@:^. , though that’s still undocumented) has the potential to be supported by 
special code [1], as many similar sequences already are; prepending  >:@  would 
interfere with that.

Because conjunctions are left-associative, >:@<.@^. is parsed as (>:@<.)@^. 
instead of >:@(<.@^.) and so the interpreter never sees the sequence <.@^. in 
isolation, and therefore could never recognize an opportunity for optimization.

But, currently, that pitfall is academic; the sequence <.@f is optimized for 
many f, but ^. is not among them, and it’s unlikely to be included any time 
soon.  

Because, as Roger once pointed out to me [2]:
> The problem is not as easy as you imply.  To replace the nonce
> error, the implementation has to handle cases like the following:
> 
> a=: 11^309x
> a ^. a^100         NB. should be 100x
> a ^.  1+a^100      NB. should return a float at or near 100
> a ^. _1+a^100      NB. should return a float at or near 100
> a <.@^. _1+a^100   NB. should be 99x
> a >.@^.  1+a^100   NB. should be 101x


-Dan

* I’d call it “alliteration” but the initial arrow in each digraph is 
different, so, “assonance”?

[1]  Appendix B, “Special Code”:
     http://www.jsoftware.com/help/dictionary/special.htm 
<http://www.jsoftware.com/help/dictionary/special.htm>

        <.@f … avoids non-integer intermediate results on extended precision 
integers
        <.@% (dyad) … special code on integer arguments; see the J6.02 release 
notes

     And §II.G, "G. Extended and Rational Arithmetic” goes into more detail. 
     http://www.jsoftware.com/help/dictionary/dictg.htm 
<http://www.jsoftware.com/help/dictionary/dictg.htm>

     Neither mention ^. as an optimized primitive

[2] J General Forum, Nov, 2005, "Nonce error with #.”:
    http://www.jsoftware.com/pipermail/general/2005-November/025859.html

    The nonce error raised by <.@^. (implicitly via #:) bit me. I asked Roger 
to lift it. He pointed out (in the quote above) why that wouldn’t be as easy as 
I thought.


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

Reply via email to