Since all of this is also directed at users
trying to figure out how rank works, I want
to further clarify two things:
“3 items in left, 3 rows in right”
yes, but in J lingo, these rows are items
as well. And the IE does just that: match
the number of items (generally: prefixes
of noun ranks) against each other.
The last example doesn’t need the explicitely
stated rank, either, thanks to this very matching.
100 200 300 400 +&.|: a
100 201 302 403
104 205 306 407
108 209 310 411
I attach my effort at explaining ranks stemming
from the discussions about conjunctions back in
May.
Am 17.01.21 um 04:33 schrieb 'Rob Hodgkinson' via Programming:
> Arnab, Henry’s explanation below should be really helpful. When I learnt
> rank it also helped me to see what happens with rank slicing up the left and
> right arguments.
>
> I add some (hopeful) clarity here that may help using the + primitive again
> to show how rank can provide looping constructs between the arguments …
>
> ]a=. i.3 4
> 0 1 2 3
> 4 5 6 7
> 8 9 10 11
>
> 100+a NB. Add 100 to every element of a (+ does
> this natively)
> 100 101 102 103
> 104 105 106 107
> 108 109 110 111
>
> 100 200 300 + a NB. But ‘frames’ are also used to line up to slice
> arguments so the “3 frames” in each argument (3 items in left, 3 rows in
> right) produce this result
> 100 101 102 103
> 204 205 206 207
> 308 309 310 311
>
> 100 200 300 +"0 _ a NB. Rank allows us to now explicitly along a cell in
> the left argument (using rank 0) with the *whole* of the right argument <a>
> (using rank _ infinity)
> 100 101 102 103
> 104 105 106 107
> 108 109 110 111
>
> 200 201 202 203
> 204 205 206 207
> 208 209 210 211
>
> 300 301 302 303
> 304 305 306 307
> 308 309 310 311
>
> 100 200 300 +"0 1 a NB. This case mirrors the second example above (that
> was done within frames by the engine) … each cell is added to each row (3
> frames) using expect rank
> 100 101 102 103
> 204 205 206 207
> 308 309 310 311
>
> 100 200 300 400 +"0 1 &. |: a NB. This shows how we might now add
> cells to columns, by transposing, applying row-wise, then transposing back
> 100 201 302 403
> 104 205 306 407
> 108 209 310 411
>
> I hope this does not confuse, but playing with examples as per above should
> help you understand the rank operator more clearly (and how it slices the
> data, potentially in both arguments in the dyadic case).
>
> HTH, Rob
>
>> On 17 Jan 2021, at 1:52 pm, Henry Rich <[email protected]> wrote:
>>
>> Well explained! What you say makes perfect sense. Now, what can we do to
>> help people stop doing that?
>>
>> Abstractly, specifying rank u"n is simply an instruction to JE to chop up
>> the arguments into pieces of rank(s) n before applying u. For general u, JE
>> does exactly that. Thus "n is a directive to execute a certain loop. It is
>> not merely informational.
>>
>> [Implicitly, every verb has a rank. Presented with an argument larger than
>> its verb rank, the verb will chop up its arguments.]
>>
>> The implementation problem is that executing a verb u has a certain overhead
>> because of the nature of interpreters: arguments have different types,
>> results have types and shapes, they all have to coexist: starting u and
>> assimilating its result takes a few dozen clock cycles. If u executes on
>> one lousy atom, it's finished in 1 clock cycle, and almost all the CPU time
>> is spent in overhead.
>>
>> The solution to this problem is Integrated Rank Support (IRS). When a verb
>> supports IRS, it warrants to JE that it will take care of a rank if given.
>> JE will skip the chopping-up step, trusting the verb to create the right
>> result. All the usual arithmetic verbs, and several others, have IRS.
>>
>> When you write a + b, JE passes a and b to the + verb. Even though its rank
>> is 0, + knows better than to chop up the arguments into atoms: instead it
>> processes them as vectors, repeating a short-frame argument if needed.
>> That's IRS for you: even though the verb has nominal rank 0, it can use the
>> SIMD instructions. The result is AS IF the processing were at rank 0.
>>
>> When you write a +"1 b or a +/ b, JE does even more for you. JE notes that
>> + supports IRS, so it avoids the explicit chopping-up step and passes a and
>> b to + . + now has more work to do: rather than just repeating a short
>> argument, it must also repeat over inner cells, with 4 nested loops. If you
>> perversely write +"0, JE will set up the 4 loops, then see that two are
>> nugatory, and revert to just one or two loops.
>>
>>
>>
>> What's the practical effect of all this? You provided a great example by
>> pointing out that it makes perfect sense to think of scalar and vector
>> addition as different operations. What the beginner needs to do is note
>> that the rank of + is 0, which means that if you want scalar addition you
>> don't need to write +"0: + means the same thing. The added "0 might seem
>> harmless, or even useful for documentation, but it does add to the
>> interpreter's work. If you are adding vectors, write +"1 only when it would
>> give different results from +"0, that is, when you have one vector to add to
>> an array of vectors.
>>
>> The apparent anomaly of sin is because of the details of the & and o.
>> primitives. o. has rank 0 with IRS, but m&o. is defined as having infinite
>> rank (with IRS). So yes, sin has infinite rank. But because it's a monad,
>> it produces the same results no matter what its rank: there is no extension
>> of a short argument.
>>
>> Henry Rich
>>
>>
>>
>>
>>
>> which knows to repeat an argument that
>>
>>
>>
>> On 1/16/2021 8:59 PM, Arnab Chakraborty wrote:
>>> Thanks for the lively discussion, much of which I could not follow, though,
>>> owing to my ignorance about rank integration.
>>>
>>> However, I understand that some sort of efficiency issue is involved.
>>>
>>> BTW, I can answer one question that even Henry could not answer (for a
>>> change): why beginners write things like +"0 and sin"0.
>>>
>>> They (read "we") are confused by ranks, and the closest concept familiar to
>>> them is that of dimension of domain. For instance, scalar addition is
>>> different from vector addition. So +"0 is scalar addition, and +"1 is
>>> vector addition. This habit is further encouraged by the apparently
>>> inconsistent rank system of J, like *: having rank 0 while sin has rank
>>> infinity. But both are functions from IR to IR. Not sure what is happening
>>> internally, they prefer to explicitly "specify the domain."
>>>
>>> Indeed, before this email thread, it never occurred to me that rank is
>>> somehow linked with efficiency. I just considered a function's rank to be a
>>> property that is competely dictated by the math of the function.
>>>
>>>
>>>
>>> On Sun, 17 Jan 2021, 06:46 Henry Rich, <[email protected]> wrote:
>>>
>>>> I can't answer that, but I can assure you that they do.
>>>>
>>>> Henry Rich
>>>>
>>>> On 1/16/2021 7:38 PM, bill lam wrote:
>>>>> I didn't mean to change stdlib sooner or later, but if we do it again,
>>>> rank
>>>>> 0 should be a better option.
>>>>>
>>>>> Why users (beginner or not) would write a+"0 b or sin"0 ?
>>>>>
>>>>>
>>>>>
>>>>> On Sun, Jan 17, 2021, 8:20 AM Henry Rich <[email protected]> wrote:
>>>>>
>>>>>> I would be happy for a user to do that, but changing stdlib might not be
>>>>>> a good idea. Beginning users often write
>>>>>>
>>>>>> a +"0 b
>>>>>>
>>>>>> and it doesn't cost them dearly. If you make the change, sin"0 will be
>>>>>> expensive.
>>>>>>
>>>>>> Henry Rich
>>>>>>
>>>>>> On 1/16/2021 7:17 PM, bill lam wrote:
>>>>>>> Thanks. then defining sine as 1&o."0 should be fine.
>>>>>>>
>>>>>>> On Sun, Jan 17, 2021, 8:07 AM Henry Rich <[email protected]> wrote:
>>>>>>>
>>>>>>>> What makes them efficient is IRS. 1&o. supports IRS; 1&o."0 does not.
>>>>>>>> Is you define sin as 1&o."0, sin will run fast, but sin"0 will not.
>>>>>>>>
>>>>>>>> Henry Rich
>>>>>>>>
>>>>>>>> On 1/16/2021 6:24 PM, bill lam wrote:
>>>>>>>>> IIUC All atomic math functions are rank 0 but support IRS so that
>>>> they
>>>>>>>> are
>>>>>>>>> as efficient as rank infinity on long array arguments.
>>>>>>>>>
>>>>>>>>> The question should be that
>>>>>>>>> is 1&o."0 as efficient as 1&o. on long arrays.
>>>>>>>>>
>>>>>>>>> On Sun, Jan 17, 2021, 12:32 AM Henry Rich <[email protected]>
>>>>>> wrote:
>>>>>>>>>> Terminology. If verb v has IRS, it can handle v"n internally
>>>> without
>>>>>> a
>>>>>>>>>> rank loop.
>>>>>>>>>>
>>>>>>>>>> + has IRS. +"n does not need a rank loop.
>>>>>>>>>>
>>>>>>>>>> +"n does not have IRS. +"n"n2 does need a rank loop.
>>>>>>>>>>
>>>>>>>>>> +/@:*"1 has IRS, but +/@:* does not - that's how they're coded.
>>>>>>>>>>
>>>>>>>>>> 1&o."0 does not have IRS.
>>>>>>>>>>
>>>>>>>>>> Henry Rich
>>>>>>>>>>
>>>>>>>>>> On 1/16/2021 11:27 AM, bill lam wrote:
>>>>>>>>>>> but the verb in this question is
>>>>>>>>>>> (1&o.)"0
>>>>>>>>>>>
>>>>>>>>>>> even if 1&o. has IRS, does (1&o.)"0 also has IRS ?
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On Sun, Jan 17, 2021, 12:02 AM Henry Rich <[email protected]>
>>>>>>>> wrote:
>>>>>>>>>>>> m&v does have IRS if v does. I didn't know that until I just
>>>>>> checked.
>>>>>>>>>>>> Henry Rich
>>>>>>>>>>>>
>>>>>>>>>>>> On 1/16/2021 7:10 AM, bill lam wrote:
>>>>>>>>>>>>> I'm not sure if 1&o."0 has IRS (integrated rank support) or not.
>>>> If
>>>>>>>> it
>>>>>>>>>>>>> doesn't then I think the phase with infinity rank is fine.
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> On Sat, Jan 16, 2021, 7:02 PM Arnab Chakraborty <
>>>>>> [email protected]>
>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>> Dear all,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Just wondering if the correct defn of sin shouldn't be
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> sin=:1&o."0
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> instead of
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> sin=:1&o.
>>>>>>>>>>>>>> which has rank infinity.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> With the rank infinity definition +/@sin behaves just like
>>>> +/@:sin
>>>>>>>>>>>>>> But, ideally, +/@sin 4 5 should be a list of two numbers, while
>>>>>>>>>> +/@:sin
>>>>>>>>>>>>>> should be their sum.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Just like, +/@*: and +/@:*:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Thanks and regards,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Arnab
>>>>>>>>>>>>>>
>>>>>>>> ----------------------------------------------------------------------
>>>>>>>>>>>>>> For information about J forums see
>>>>>>>>>> http://www.jsoftware.com/forums.htm
>>>>>>>> ----------------------------------------------------------------------
>>>>>>>>>>>>> For information about J forums see
>>>>>>>> http://www.jsoftware.com/forums.htm
>>>>>>>>>>>> --
>>>>>>>>>>>> This email has been checked for viruses by AVG.
>>>>>>>>>>>> https://www.avg.com
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>> ----------------------------------------------------------------------
>>>>>>>>>>>> For information about J forums see
>>>>>>>> http://www.jsoftware.com/forums.htm
>>>>>> ----------------------------------------------------------------------
>>>>>>>>>>> For information about J forums see
>>>>>> http://www.jsoftware.com/forums.htm
>>>>>>>>>> --
>>>>>>>>>> This email has been checked for viruses by AVG.
>>>>>>>>>> https://www.avg.com
>>>>>>>>>>
>>>>>>>>>>
>>>> ----------------------------------------------------------------------
>>>>>>>>>> For information about J forums see
>>>>>> http://www.jsoftware.com/forums.htm
>>>> ----------------------------------------------------------------------
>>>>>>>>> For information about J forums see
>>>> http://www.jsoftware.com/forums.htm
>>>>>>>> --
>>>>>>>> This email has been checked for viruses by AVG.
>>>>>>>> https://www.avg.com
>>>>>>>>
>>>>>>>> ----------------------------------------------------------------------
>>>>>>>> For information about J forums see
>>>> http://www.jsoftware.com/forums.htm
>>>>>>> ----------------------------------------------------------------------
>>>>>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>>>>> --
>>>>>> This email has been checked for viruses by AVG.
>>>>>> https://www.avg.com
>>>>>>
>>>>>> ----------------------------------------------------------------------
>>>>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>>>>>
>>>>> ----------------------------------------------------------------------
>>>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>>>
>>>> --
>>>> This email has been checked for viruses by AVG.
>>>> https://www.avg.com
>>>>
>>>> ----------------------------------------------------------------------
>>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>>>
>>> ----------------------------------------------------------------------
>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>>
>> --
>> This email has been checked for viruses by AVG.
>> https://www.avg.com
>>
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
----------------------
mail written using NEO
neo-layout.org
%PDF-1.5
%ÐÔÅØ
6 0 obj
<</Length 5026 /Filter/FlateDecode>>
stream
xÚÕ][·
~÷¯?
©¨»À@íu´OnýäÉm´q䥿5£Û\Î̯wO¬Ï®G)"õQS9ü<Èáû7òàð¯h°ÞZ«ÁÑ9;|þòæ·Dßòu
vøßÀÍø¦F½$nåNäh¿øµP.Rz?1 4u£.Ú!â)~ÿ×ðæÝðæãÜß4K<kG4þÀ
iä^§ö÷Ï_º¼CPÓ#£ÒeûõÇÚÞôqÿû@ó+ÕÌìcx6þ¦õÏ«Ôüh¢nФÒÒùAPù¨rc
Rܼt#iEZ£§°+,릥Ã/R1Ù»Ooþô8F§>ý4É3õ§/ÃßIi½Dø4oüô×7>U5tCÓ}³&3S¢áêcå¼ëFS§
q$²Ö4òô£´Jݧê8Ã(Ýg1¦Ð^abè4½=¤©giÚbÓífRLl«gTù±P~ÆX
T0+%íð¥k~ÎÉÍc Â*{·9.j§¶Ïxò°LlIi»¬met~¼6;VÖ·Ú¥¶Nª½¶ñãe¢
ie¨v¹Á;ÿ=Ô[©¬µËUktê)ÓȾ«{RcÖg%¦<gêYù´RFüXüðïOo
ÖÕZÖçã¨=[¶ÇFS7=ãù9üÅ&axeDÂ÷Oóüó~¥þF½¬a¬Qÿ$LÑHsOù×-u)ËrK5&5¯×¨±VÐmn©´ujÜVݬ]¶:z§Æ
ZñºFaÐÙPmë´¸!l78_*q'=%v´!\RâÃM%¶iGÀ_uØò¦8«°ÚTa
ñ*Lê¼
k Êèë*ÜðµVá*Ë¢Â7£ ìEþÂüA:4Í¿oþºí¤?BÇÓÌ3KöCIÿ0k2â¸å
þuÙ'úǪéë_Ë×¢~ÿËðnø8䨫N}awyêµùÌÔþæSo<Ë´v]\ZhDÀdoFotðÓðÆ[h¶qèx'8åJL
±ô(½b\hSûÖeÈpøE#ò°Ö©gâ|x˦
l6²Ù¬¦`ú÷?Cû×ßÊØ÷ÇEòÃüxÁððÁØÁ(N<*õd³E¿J³±&#ýeh²6#}=k53+ÜI²ýwN¶+¬Ft#{Ó<^>äy{ ëVؾ«èÛn^qÑ,ùÇ^/~ÿyÈ×M¯Ý¶ÍlÐ^¹dZ϶!E2Ö(¢Æ¶
HGà°ZÞaþ¨íÙGh2£UñÛ»¬wÊ[öð
ÎDéÁ/×ÀZâÍm3$Lõ¡RÁÀY¹±µ?´°«X#uÚß6h]¤àC¤ÑvbË¿¬Æ(óçÜÌÈZ¡ðàáã«
á3Á!]pé ¤YaÉeÃÜÈ»`·H9^Ë¢ÑVm£±
Ö0ê¨`öknùFkSi÷¬N,mëÚCí9µáÀªãÚu`DØN{qFsÉ9¯R|ß/оQ§df¬Ï(Ø´")/<Açª4~NÇsDÔHAiÛôYZÊèééÒmXcÊÚ¡¼
t®½4¦çëTâÊRíuý9#iún%³uèÞ¸)pòW'$z?nboGÐ)n2qS¦çxA©)fÈG)dyê¢
öÉ1Ä)êi¢woíwsñC¦¹£§jsòXyJb>¥3ëÑØwrlS#2¦&¨s|óç<óe\£yì¤U4Ý¡ë´
¢Y×L$¿ÿ<ä°y!ÇQÿJQ±cRRc-§Â}ðU6v|·?ë7Yé-EúeÍÿ6¯½Säà(}Ó~+
">ö:ÓÎãðÜ"WËuD®çZ8ñi¹õ»±è é¯áÇoKlÆR¹tVäFOÔ`iÑI$«)0{¹ÑéX*tüʱ´÷q×åÈ{g¯røeòL}ä:B°tïæK-²¥³i"vtнè¤O'EN+d*ªPo¤ViÃJùå6¬Ñ®'>çÌRû@M÷Zfô)¬ì
§á
AJÞPRTØc'¬ä§JZ
Wl|1¿r`)ŵ<£ 1âY>²¿6GÙ3u&>ÔÃb=ÎuÉüá`ø²h¡ìê"ûkh¡âó
-T!pTx-ÌԧѦû-«ruZ¬pÚ¸`!!²Q?;X¨$§°á$X©Á¦Û
!6̼X¨àhÖ^õ(ÒJÎB*zaâF**:¥VܤöWÛÊÐÄB£VxØcAB
ÏÍ>¹]Û:¥!-Ü4]n0¾YZì,
1B¥çG
q@tr)ÌÔ÷"
*êÎÀ,|tÞñSÈÈÉyÌ{GÞK¿ê^b»ñuo¶õ®gf+[ÂÝóTÁ®`f5ïA*
¿Y'}oBdÀ#!ijL§ÕªqnêL¨V»¨ýÕ¶<roA¾C)#¤}KSg?°rRû[ó¼´V;ÆÃ¡¡
þÙJäó|`v¡ÌÄ÷"Ïùâ9á«È"ùzÓaIoöv`:Ä@g¸Ãt¹®L§YËkébã)0ci>3V'þioïyæ¥õÌÄ«ù<
<J<9ì
áQV1hÖ7GÃJ{:fêgH] ¤
óä¾!U·£¯HykÒ}-DÚ#mÖýk1Òɤ¦Ä _;GdïÂHùÊðú°Ñ°²[×ÖÊ`*¢18
ñP)0!ektú&AJ94:À:Eiè¡Å`:ÑsÀ^§Àð8RÃ> ´
uCþ¬ß$Ñ8Ö%$(ÁêGJ3¯¤=Ì6K>óÔ%gý¯
7xE@§%b»G@'õ&$$"º
zs)Iê½®ÔÛ9ø#2úqÓ´Ñã+wÆõpæ.Ä£.?g?(`¶ø[µ L)`ÛVpð-dª$Ö
Z[в6öiKж×ÒVfЦ|ÏÌ>Ióq^HID@mìQÓ¸òÕt»!lÚÉg6¥ ¤x~Ø4mèNâ¦ú>à4CM
r8M¡¥È)<>º¯ANélA§ÍªNô9ír#ÎÙ{±S¸ý ùÂ{Ó¯Øim?6Öó8¼!52NZ³\HËÀ
ö{±Sî 6äÔ#c§da^ÁaVì4H5n"§,=e®÷0öµ
û;}ÏÎ{2y¦>Ng/qEh§mõy"a2VõÄ<¾ywú(,G«^n¢p´ÅäÎé±nn5äþéù¸5¤yZúÞ
7«º]:÷Ψ"ÆçQE_Éí!Æé&ði^Ayسn#Æiëºvöj¹Fì.Ä>-`ãø`v¢ÎÄ·
Èq Ä
ù_)[¸o?Þ)û.Oà=`5íæËÌÓâé¬Iqnû9WÙµùtEôÝ*fCêã«.³d|8¥¿M=õ~ÿþ´[HX°³Ê1"þ³Kb§V¢aw§Ð¯qóÔf%b$Ö2ZS]B£Â[u
Y½j]8¾k}õ3ìÑÇç¯J $ÎU útUBÓýÖæÂÔ}E ;4|y*A&·Ï
QèÙöøúrîr-¾ÊÄËU#
J.j`yÚkjqT\Ü94³4u8j%,èhí®4åaû«z¾q\zsøÔz[:µÕbÒ×Õ%~Ú`>å9opIàÌÎ^RÎÔ÷B?Ö_(=
¢QIõL¥ËÞK°qèy>mäºOëZÞSx 6íETm+*)Öª+ZÝ-*^
!4ýÕ¶MÕ¶j¶*:c¬¤Úåí¥ícãAjê»öÀ2vòrôL{÷Ýh>
ÓÏTw°îì¨ì É×ͦJti5u ¯tÖaûÜxµ/z÷ÅbsÖâÊ´ÅËÍûãvÌûü!ã*\
wrÆWJ+CL&Àëb[Ó|Y9åáø- >ÑFÚÆî
¹´¾%åË)2ð·ÚciËc§§KkÄÃ_R;dÁ!plÎMéÙ<ÇJW8©½Xý_í³ÅFt
7(¾`Ì'YzQoov¿F=¥
áè;<S_
øVH$£V'Ü Ñ4>òöoêqÝаÕFɳ4Eç
-¼®¥ØÖ_Q=ëØP"ÑiQQ·´heÓcmÛV`ÑèzísË~Do@eª
me©éuÍþJÅ)e|<ý5m¾µ¡³zÆá¹öé0ÝÊÔ3ñÕ-=ë2MCú.#µ5ö]®Lm¨rå²1Ǹ¨LUÖÈbù$2C#*`jó¯]³Ûcj¯½tí¿ì<²\㣸\ᨻ¤\¶WK,2ëZz¥Ù!f:SÏÄÏSF>åp};f:ðr_ë®4>Jh
âÎú3ÀDq|^÷:øz4CUðÚÎë-êßY|Æ1*ÅyõókÿháF¡x^ñ[;t/ÌÕä\öÌõTı¸XxÄ6fúÝ
îE±>