Hmm, is it better, in general to code that as

*./ reply = 'yes'

or

*/ reply = yes

or

reply -: 'yes'

or maybe

 (<,tolower reply) e. (,'y');'ye';'yes'

I know, my actual question is,

When I work with booleans I always try to use and and and or to maintain
boolean results.

I have noticed in other people's code that they use ordinary arithmetic to
get the same results - that is,

*/boolean and

*./boolean

will give the same result, while

+/boolean

and +./boolean

will both give a non-zero result if anyone of the booleans are true.

   blahblah =. ? 100000 $ 2

     5000 (6!:2) '*./blahblah'
5.05174e_7
     5000 (6!:2) '+/blahblah'
3.18783e_5
     5000 (6!:2) '+/blahblah'
3.13969e_5
     5000 (6!:2) '+./blahblah'
6.88214e_7
     5000 (6!:2) '+./blahblah'
6.90688e_7
     5000 (6!:2) '*./blahblah'
6.73963e_7
     5000 (6!:2) '*/blahblah'
7.35488e_7
     5000 (6!:2) '*/blahblah'
6.72256e_7
     5000 (6!:2) '*./blahblah'
7.08182e_7

So it looks like there is little difference between */ and *./ while +/ and
+./ are very different - perhaps +./ somehow shortcuts so that it can stop
after it finds the first true.  I wondered how much optimization there was
for these common cases and I wondered whether  about somehow getting around
the optimizations:

     5000 (6!:2) '+.`+./blahblah'
0.00992467
   +.`+./blahblah
   +.`+./blahblah
1

Yeah, we had a long pause when I hit enter on my test case - there must be
a huge amount of optimization on the normal case.


Is this all a matter of using the right optimized cases?  I like the fact
that the nuVoc calls out some of the optimized cases.

But certainly if you are not working with boolean data, the overhead of
calculating the LCM and GCD of numbers when all you really care about is
the zero or non-zero value really makes it important that you reduce the
data to boolean  using a simple test first:

  blahblahx =. ? 100000 $ 32000
     5000 (6!:2) '+/blahblahx'
9.56426e_5
     5000 (6!:2) '+/blahblahx'
9.69338e_5
     5000 (6!:2) '+./blahblahx'
0.00655577

     5000 (6!:2) '*/blahblahx'
0.000104107
     5000 (6!:2) '*./blahblahx'
0.00610307
     5000 (6!:2) '*/0 ~: blahblahx'
8.20438e_5
     5000 (6!:2) '*./0 ~: blahblahx'
8.02292e_5
     5000 (6!:2) '+/0 ~: blahblahx'
0.000109099
     5000 (6!:2) '+./0 ~: blahblahx'
7.78428e_5

I guess I am answering my own question by asking it.  As a relative novice
I find this interesting.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to