Just looking at the code: e.g. by replacing
(>:i.y)-.,(>:i.y)*/(y$q:y)

with
  (1 + i.y) ([ -. [: , */) {. __ q: y

ending up with a tacit verb:

phi17=: [: (% ([: # (1 + i.) ([ -. [: , */) {.@q:~&__)"0)2+i.


    ts 'P=.phi 2+i.1e3'
7.58904 9.48134e6
    ts 'Q=.phi17 1e3'
0.111421 66816
    P-:Q
1

-->
much faster and leaner.





Hallo David Vaughan, je schreef op 12-09-11 13:34:
> 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?
>
> On 12 Sep 2011, at 03:19, bill lam wrote:
>
>> There was domain error becasue q: cannot take 0 as its argument. Similarly
>> q:1 will return an empty list so that your phi will raise errors even for
>> scalar 0 and 1.
>>
>> Пнд, 12 Сен 2011, David Vaughan писал(а):
>>> Hi,
>>>
>>> I have defined a verb like so:
>>>
>>>    phi=: 3 : 'y%#(>:i.y)-.,(>:i.y)*/(y$q:y)'
>>>
>>> It seems I can only use with atoms, e.g.
>>>
>>>    phi 6
>>> 3
>>>
>>> What I want to be able to do, is apply this verb to a list. I would also 
>>> like to know how I can define verbs so they can be more flexible in this 
>>> way in a general sense.
>>>
>>> This is the output of my failed attempt:
>>>
>>>    phi i.6
>>> |domain error: phi
>>> |   y%#(>:i.y)-.,(>:i.y)*/(y$    q:y)
>>>
>>> I can kind of see where the problems may be, but I can't think how to 
>>> eradicate them - this is the sort of thing I would usually be just using  
>>> loop for in a C type language, but I would dearly love to know the best J 
>>> style approach. Also, I find that these error messages are difficult to 
>>> interpret - I'm not clear where the error has been found, but I assume the 
>>> large space has something to do with it (any advice here would be helpful).
>>>
>>> Thanks in advance.
>>> ----------------------------------------------------------------------
>>> For information about J forums see http://www.jsoftware.com/forums.htm
>> -- 
>> regards,
>> ====================================================
>> GPG key 1024D/4434BAB3 2008-08-24
>> gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>

-- 
Met vriendelijke groet,
=@@i

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

Reply via email to