Dan Baronet: Difference between revisions

Jump to navigation Jump to search
117 bytes added ,  21:23, 10 September 2022
m
Text replacement - "</source>" to "</syntaxhighlight>"
mNo edit summary
m (Text replacement - "</source>" to "</syntaxhighlight>")
Line 6: Line 6:
== The "Dan Baronet special" ==
== The "Dan Baronet special" ==


Baronet was famous for innovative uses of APL primitives. He's credited with discovering that <source lang=APL inline>b⊥b</source> or, as he preferred writing it, <source lang=APL inline>⊥⍨b</source>, counts the number of trailing ones in the Boolean vector <source lang=APL inline>b</source>:<ref>Roger Hui. [http://danielbaronet.rip/ Tribute to Daniel Baronet]. DanielBaronet.RIP</ref>
Baronet was famous for innovative uses of APL primitives. He's credited with discovering that <source lang=APL inline>b⊥b</syntaxhighlight> or, as he preferred writing it, <source lang=APL inline>⊥⍨b</syntaxhighlight>, counts the number of trailing ones in the Boolean vector <source lang=APL inline>b</syntaxhighlight>:<ref>Roger Hui. [http://danielbaronet.rip/ Tribute to Daniel Baronet]. DanielBaronet.RIP</ref>


<source lang=apl inline>⊥</source> ([[Decode]]) performs base conversion. If the left argument is a vector, it performs ''mixed'' base conversion.
<source lang=apl inline>⊥</syntaxhighlight> ([[Decode]]) performs base conversion. If the left argument is a vector, it performs ''mixed'' base conversion.


For a base vector <math>b = b_n,\cdots,b_0</math> and a digit vector <math>a = a_n,\cdots, a_0</math>, <source lang=apl inline>b ⊥ a</source> converts <math>a</math> to the mixed base <math>b</math>, i.e., it computes <math>b_0\cdots b_{n-1}a_n + \cdots + b_0b_1a_2 + b_0a_1 + a_0</math>.
For a base vector <math>b = b_n,\cdots,b_0</math> and a digit vector <math>a = a_n,\cdots, a_0</math>, <source lang=apl inline>b ⊥ a</syntaxhighlight> converts <math>a</math> to the mixed base <math>b</math>, i.e., it computes <math>b_0\cdots b_{n-1}a_n + \cdots + b_0b_1a_2 + b_0a_1 + a_0</math>.


Now, in a monadic context, <source lang=apl inline>⍨</source> ([[Commute]]) causes the function to the left to be called with equal left and right arguments.
Now, in a monadic context, <source lang=apl inline>⍨</syntaxhighlight> ([[Commute]]) causes the function to the left to be called with equal left and right arguments.


So <source lang=apl inline>⊥⍨b</source> is defined as <source lang=apl inline>b⊥b</source>, which computes <math>a_0\cdots a_n + \cdots + a_0a_1a_2 + a_0a_1 + a_0</math>, the sum of all cumulative products from the right to the left.
So <source lang=apl inline>⊥⍨b</syntaxhighlight> is defined as <source lang=apl inline>b⊥b</syntaxhighlight>, which computes <math>a_0\cdots a_n + \cdots + a_0a_1a_2 + a_0a_1 + a_0</math>, the sum of all cumulative products from the right to the left.


For <source lang=apl inline>k</source> trailing ones, the <source lang=apl inline>k</source> rightmost products are <source lang=apl inline>1</source> and all others are <source lang=apl inline>0</source>, so their sum is equal to <source lang=apl inline>k</source>.<ref>Stack User "Dennis". [https://codegolf.stackexchange.com/a/98764 Answer] in [[Dyalog APL]] to [[Adám Brudzewsky]]'s [[code golf]] challenge. Code Golf and Coding Challenges Stack Exchange.</ref>
For <source lang=apl inline>k</syntaxhighlight> trailing ones, the <source lang=apl inline>k</syntaxhighlight> rightmost products are <source lang=apl inline>1</syntaxhighlight> and all others are <source lang=apl inline>0</syntaxhighlight>, so their sum is equal to <source lang=apl inline>k</syntaxhighlight>.<ref>Stack User "Dennis". [https://codegolf.stackexchange.com/a/98764 Answer] in [[Dyalog APL]] to [[Adám Brudzewsky]]'s [[code golf]] challenge. Code Golf and Coding Challenges Stack Exchange.</ref>


== Publications ==
== Publications ==

Navigation menu