On Sun, Sep 11, 2011 at 9:20 PM, David Vaughan <[email protected]> wrote: > phi=: 3 : 'y%#(>:i.y)-.,(>:i.y)*/(y$q:y)' ... > phi i.6 > |domain error: phi > | y%#(>:i.y)-.,(>:i.y)*/(y$ q:y) > > ... 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).
Yes, the large space shows where the interpreter had reached, when the error occurred. And, as bill lam pointed out q: 0 1 2 3 4 5 is erroneous because q:0 is erroneous. Note also that this space will be to the left of the verb which was being evaluated when the error occurred. This has some implications which might be non-obvious: (2+2),((5%2)$0),(3+3) |domain error | (2+2),((5%2) $0),(3+3) Here, even though the noun on the left has been evaluated, and the interpreter works "from right to left", the quadruple space appears to the right of the left argument. (2+2),(2.5(+,$)0),(3+3) |domain error | (2+2),(2.5 (+,$)0),(3+3) Here, in contrast, the interpreter was working on a verb phrase when the error happened. We might have a mental model that tells us where in the verb phrase the problem happened, but the interpreter does not draw such distinctions. On Mon, Sep 12, 2011 at 7:34 AM, David Vaughan <[email protected]> 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? Yes. Here's a minor speedup: phi=: 3 : 'y%#(>:i.y)-.,(>:i.y)*/~.q:y'"0 In other words, instead of 1 2 3 4 -. , 1 2 3 4 */ 2 2 2 2 we find 1 2 3 4 -. , 1 2 3 4 */ ,2 And, instead of 1 2 3 4 5 6 -. , 1 2 3 4 5 6 */ 2 3 2 3 2 3 we find 1 2 3 4 5 6 -. , 1 2 3 4 5 6 */ 2 3 And consider what this means when y=100 and q:y is 2 2 5 5... But perhaps we should instead define: phi=: % totient totient=: 3 :'#(>:i.y)-.,(>:i.y)*/~.q:y'"0 This might seem like a trivial refactorization... and it is... but it also suggests a google search site:jsoftware.com totient which, in this case, gives us some interesting results, including: http://www.jsoftware.com/help/dictionary/dqco.htm http://www.jsoftware.com/jwiki/Essays/Totient%20Function http://www.jsoftware.com/docs/help701/release/totient.htm Google does not hold all the answers, not by a long shot, but sometimes it's useful. -- Raul ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
