Your analysis of how that verb acts is correct, with one small exception. 

Adverbs (and conjunctions) have long left scope, so =&0@:+/ isn't (=&0)@:(+/), 
it's actually (=&0@:+)/ . So =&0@:+/ 1 1 1 is 1 (=&0@:+) 1 (=&0@:+) 1 .  

What you want is coprime =. =&0@:(+/)@:(e.&q:) . 

With that said, what if (q:x) has two 3s, and (q:y) has only one 3? Or 
vice-versa?

Without spoiling your fun, there's a single, primitive, verb in the J 
Vocabulary that will make your whole expression shorter and sweeter. 

-Dan

Please excuse typos; sent from a phone.

> On Jun 15, 2014, at 7:49 AM, Jon Hough <[email protected]> wrote:
> 
> My attempt at a coprime dyadic verb, which returns 1 for coprime integers and 
> 0 otherwise seems to not work. I do not understand why this verb fails.
> coprime =. =&0@:+/@:(e.&q:)
> 5 coprime 6
> returns 0.
> My understanding is thus:
> Verb is read right to left.First :
> 5 (e.&q:) 6
> 
> is evaluated. This equates to (q: 5) e. (q: 6). (which gives 0)
> Next +/ acts monadically on this result.
> 
> Finally we compare the result with 0. 
> 
> So my understanding is 5 coprime 6 should return 1.
> Regards.
> 
>                         
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to