> From: Roger Hui <[email protected]>

> 
> It is not in the Special Code section because there is
> nothing special about its implementation.  
> There are examples of code that are even neater but are 
> not "special" and so are not in Appendix B.  For example, A. .
> http://www.jsoftware.com/jwiki/Essays/Permutation_Index
> 
> From: Zsbán Ambrus 
> 
> > On Fri, Feb 19, 2010 at 4:37 PM, Roger Hui wrote:
> > > The timings wouldn't be as follows if u/\. were quadratic:
> > > ----- Original Message -----
> > >> Is there any chance that a future J version would optimize 
> > the monad
> > >> u/\. for any verb u to make only linear number of calls to u 
> > instead>> of quadratic?
> > 
> > Wow, it's like that indeed, in the version I've got too.  Sorry.
> > 
> > However, I don't see this documented in the Special Code listing of
> > the Dictionary.  Could you point me to where this is 
> > documented, or
> > document this?

Here's a simple mechanism to show how things work:
argument tracing.

   plus=: 4 : 'x + y [ smoutput x,y'     NB. define a tracer

   plus /\. 1 10 100 1000 10000          NB. use illustrative data
1000 10000                               NB. linear algorithm
100 11000
10 11100
1 11110
11111 11110 11100 11000 10000

   plus /\ 1 10 100                      NB. "triangular" algorithm
1 10
10 100
1 110
1 11 111

   plus /\ 1 10 100 1000
1 10               (a)
10 100   --+
1 110    <-+       (b)
100 1000 --+
10 1100  <-+ --+
1 1110       <-+   (c)
1 11 111 1111
  (a)(b)  (c)

   plus /\ 1 10 100 1000 10000
1 10                   (a)
10 100     --+
1 110      <-+         (b)
100 1000   --+
10 1100    <-+ --+
1 1110         <-+     (c)
1000 10000 --+
100 11000  <-+ --+
10 11100       <-+ --+
1 11110            <-+ (d)
1 11 111 1111 11111
  (a)(b)  (c)  (d)


A variation with arguments and result:

   plus=: 4 : '(] ([smoutput) x,y,]) x + y'
   plus /\ 1 10 100 1000
1 10 11
10 100 110
1 110 111
100 1000 1100
10 1100 1110
1 1110 1111
1 11 111 1111


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

Reply via email to