Help / Release / J 4.05 / c}x,y,:z Improved
< Help
Jump to navigation
Jump to search
>> << Pri JfC LJ Phr Dic Voc !: Rel NuVoc wd Help Release
c}x,y,:z Improved |
initial writing: 2000-00-00 |
The phrase b}x,:y for numeric x
and y is equivalent to the well-known
phrase (x*b)+y*-.b .
Recently, special code has been implemented
for the phrase name=: c}x,y,...,:z ,
with boolean c as a special case,
and the amendment is done in place
if name is x or y and c is boolean.
(In-place amendment is eschewed for
integral c due to the possibility of index error.)
A time-space comparison is as follows:
b=: ?(5$10)$2 x=: o.?($b)$1000 y=: o.?($b)$1000 z=: o.?($b)$1000 c=: ?($b)$3 ts=: 6!:2 , 7!:2@] +/,b NB. roughly equal proportions of 1s and 0s 50185 ts 'q=: (x*b)+y*-.b' 0.0279061 3.27834e6 ts 'r=: (b)}y,:x' NB. no special code 0.0570458 6.29325e6 ts 's=: b}y,:x' NB. special code but makes copy 0.0102885 1.05018e6 ts 'y=: b}y,:x' NB. special code, in place 0.00728388 1472 q&-:&> r;s;y 1 1 1 b1=: 0=?(5$10)$390 y=: o.?($b)$1000 +/,b1 NB. many more 0s than 1s 243 ts 'q=: (x*b1)+y*-.b1' 0.0281466 3.27821e6 ts 'r=: (b1)}y,:x' NB. no special code 0.0535643 6.29325e6 ts 's=: b1}y,:x' NB. special code but makes copy 0.00813539 1.05018e6 ts 'y=: b1}y,:x' NB. special code, in place 0.0012672 1600 q&-:&> r;s;y 1 1 1 y=: o.?($b)$1000 ts 'q=: (x*0=c)+(y*1=c)+z*2=c' 0.0600914 5.63834e6 ts 'r=: (c)}x,y,:z' NB. no special code 0.0848446 9.96352e6 ts 's=: c}x,y,:z' NB. special code but makes copy 0.0119311 1.0505e6 q&-:&> r;s 1 1