For some common conditions, include the one specified in David Vaughan's original query, the special code can be better stated as x (condition i. 1:) y x (condition i. 0:) y
For example: x=: 1e6 ?@$ 0 x (> i. 1:) 0.5 0 x (> i. 1:) 1 1000000 timer=: 6!:2 timer 'x (> i. 1:) 0.5' 2.0673e_5 timer 'x (> i. 1:) 1' 0.0311936 timer '(x>1) i. 1' 0.0760541 The last benchmark shows that the special code is faster even when the interpreter has to scan the vector right to the end. ----- Original Message ----- From: Henry Rich <[email protected]> Date: Sunday, September 25, 2011 17:23 Subject: Re: [Jprogramming] Infixes To: Programming forum <[email protected]> > [x] i.&1@:condition list > > 0.5 i.&1@:< 0 0.2 > 0.5 0.6 0.9 0 0.6 > 3 > > Backed by special code if the condition is simple, as above > > Henry Rich > > On 9/25/2011 7:14 PM, David Vaughan wrote: > > Thanks, that seems quicker. > > > > I have another question, which is how can i find the first > value that appears in the list that meets some condition - i.e. > if the item> 0.5 - and return its position? > > > > On 25 Sep 2011, at 22:03, Henry Rich wrote: > > > >> (% 4 *>:@i.@#) _4 > {:\ +/\ 1&p: 3 5 7 9 13 17 21 25 31 37 43 49 > >> 0.75 0.625 0.666667 > >> > >> > >> Henry Rich > >> > >> On 9/25/2011 4:46 PM, Don Guinn wrote: > >>> Apply the 1&p: to the list before doing the infixes. Cuts > down the number of > >>> times 1&p: is invoked. But why are you adding one to the > number of items in > >>> each infix? Seems like the 3 5 7 9 should give 0.75, not 0.6 . > >>> > >>> ((+/%#)&,)\_4,\1 p:3 5 7 9 13 17 21 > 25 31 37 43 49 > >>> > >>> On Sun, Sep 25, 2011 at 1:47 PM, David > Vaughan<[email protected]>>>> wrote: > >>> > >>>> I've done: verb&,\ > >>>> > >>>> I arranged the list to be of shape 'x 4'. This seems to > work. The problem > >>>> I'm now having is that my verb is slow. Can this be refined > (significantly)?>>>> > >>>> +/@:(1&p:) % 1&+@:# > >>>> > >>>> It takes finds the percentage of items in the list which > are prime. > >>>> > >>>> On 25 Sep 2011, at 20:04, Don Guinn wrote: > >>>> > >>>>> verb=.< > >>>>> (verb&,)\_4,\3 5 7 9 13 17 21 25 31 37 > 43 49 > >>>>> +-------+-------------------+------------------------------ > -+ > >>>>> |3 5 7 9|3 5 7 9 13 17 21 25|3 5 7 9 13 17 21 25 31 37 43 49| > >>>>> +-------+-------------------+------------------------------ > -+ > >>>>> > >>>>> > >>>>> On Sun, Sep 25, 2011 at 12:44 PM, David Vaughan< > >>>>> [email protected]> wrote: > >>>>> > >>>>>> I'm trying to apply a verb to infixes of length 4 but I > want it to be > >>>>>> cumulative. i.e. in the list: > >>>>>> > >>>>>> 3 5 7 9 13 17 21 25 31 37 43 49 > >>>>>> > >>>>>> I want: > >>>>>> > >>>>>> verb 3 5 7 9 > >>>>>> verb 3 5 7 9 13 17 21 25 > >>>>>> verb 3 5 7 9 13 17 21 25 31 37 43 49 > >>>>>> > >>>>>> Any help? Thanks. > >>>>>> ---------------------------------------------------------- > ------------ > >>>>>> For information about J forums see > http://www.jsoftware.com/forums.htm>>>>>> > >>>>> ----------------------------------------------------------- > ----------- > >>>>> For information about J forums see > http://www.jsoftware.com/forums.htm>>>> > >>>> ------------------------------------------------------------ > ---------- > >>>> For information about J forums see > http://www.jsoftware.com/forums.htm>>>> > >>> ------------------------------------------------------------- > --------- > >>> For information about J forums see > http://www.jsoftware.com/forums.htm>>> > >> -------------------------------------------------------------- > -------- > >> For information about J forums see > http://www.jsoftware.com/forums.htm> > > --------------------------------------------------------------- > ------- > > For information about J forums see > http://www.jsoftware.com/forums.htm> > ----------------------------------------------------------------- > ----- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
