David Vaughan-5 wrote: > > This verb is considerably slower than I was hoping - is there a particular > part of it that would be a bottleneck, or that I've written naively? > [...] > >> I have defined a verb like so: >> >> phi=: 3 : 'y%#(>:i.y)-.,(>:i.y)*/(y$q:y)' >> > You could use ~.@q: instead of q: A different approach will speed things up, since phi finds the ratio of y and the number of positive integers less than y that are not multiple of one of the factors of y.
So, I'd go here with the reduction of the list >:i.y according to the "inverted" Eratosthenes's sieve: sieve =: ] #~ 0 < | phi1 =: (%#)(>:@i. sieve~ RL ~.@q:) where "reduce from left" was defined in one of my previous posts as: RL =: 1 : 0 : for_e.y do.x=.x u e end. x ) All in all, phi1 is much faster and leaner than phi: ts'a=.phi"0]2+i.1000' 3.40205 1.79064e7 ts'b=.phi1"0]2+i.1000' 0.044305 57856 a-:b 1 phi1 12345678 3.06543 -- View this message in context: http://old.nabble.com/Applying-defined-verb-to-list-tp32444698s24193p32448442.html Sent from the J Programming mailing list archive at Nabble.com. ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
