On the other hand, you can do things like:

   x=: (50 [EMAIL PROTECTED] 2) { 'democratic';'republican'
   y=: 50 [EMAIL PROTECTED] 2e6
   x </. y

which you can not do with <;.n .  The trick is
to make "key" fast for special but common and
important cases and still have the general capability.  
What is "special but common and important"?
As my former colleague Seth Breidbart once
observed, if it were easy they wouldn't pay us
so much.



----- Original Message -----
From: "R.E. Boss" <[EMAIL PROTECTED]>
Date: Wednesday, November 5, 2008 8:45
Subject: RE: [Jprogramming] cut on length
To: 'Programming forum' <[email protected]>

> If these results are analysed further, I get
> 
> NB. rnk gives the relative performance of execution time and space
> 
>    rnk 5&ts&>'x f0 y'; 'x f1 y'; 'x f2 y'
> 2 6.79 4.14
> 1 1.63 1.59
> 0 1.00 1.00
> 
>    rnk 5&ts&>'I.x'; '((i.#y) e. +/\0,x)'; '(1 
> (<:+/\x)} (#y)$0) '
> 2 1.60 3.42
> 1 1.54 2.63
> 0 1.00 1.00
> 
>   rnk 5&ts&>'t0=.I.x'; 't1=.((i.#y) e. +/\0,x)'; 't2=.(1 
> (<:+/\x)} (#y)$0) '
> 2 3.50 3.42
> 1 3.20 2.63
> 0 1.00 1.00
> 
>    rnk 5&ts&>'t0</.y'; 't1<;.1 y'; 't2<;.2 y'
> 2 8.10 4.56
> 1 1.10 1.00
> 0 1.00 1.00
> 
> 
> Apparently </. is much slower than <;.
> 
> 
> R.E. Boss
> 
> 
> 
> -----Oorspronkelijk bericht-----
> Van: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] Namens Sherlock, Ric
> Verzonden: woensdag 5 november 2008 7:53
> Aan: Programming forum
> Onderwerp: RE: [Jprogramming] cut on length
> 
> ---Roger Hui wrote:
> >    f0=: 4 : '(I.x)</.y'
> >    f1=: 4 : '((i.#y) e. +/\0,x) <;.1 y'
> >
> >    x=: 1+1e4 [EMAIL PROTECTED] 100
> >    y=: t {~ (+/x) [EMAIL PROTECTED] #t=. 'barack obama'
> >
> >    x (f0 -: f1) y
> > 1
> >    ts=: 6!:2 , 7!:[EMAIL PROTECTED]
> >
> >    ts 'x f0 y'
> > 0.0700156 1.09591e7
> >    ts 'x f1 y'
> > 0.00778395 4.20992e6
> 
> When I saw Brian's solution I wasn't going to post mine - his 
> was so much
> simpler (BTW I have only used monadic I. to turn a boolean into 
> an index of
> 1s and hadn't realised what it did with integers). Roger's post 
> prompted me
> to time mine and the result surprised me.
> 
>    f2=: 4 : '(1 (<:+/\x)} (#y)$0) <;.2 y'
>    x (f1 -: f2) y
> 1
>   50 ts 'x f0 y'
> 0.030942459167 10976256
>   50 ts 'x f1 y'
> 0.0077791269561 4227072
>   50 ts 'x f2 y'
> 0.0060425808308 2654272
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to