APL Wiki logo: Difference between revisions

Jump to navigation Jump to search
408 bytes removed ,  21:19, 7 January 2020
Line 178: Line 178:
<source lang=apl inline>⊢</source> is the [[identity]] function, which is just used here get the pass-though value from the assignment, as it would otherwise be hidden. (We call assignment ''shy''.) <source lang=apl inline>\</source> is just like <source lang=apl inline>/</source> but gives us the intermediate values.
<source lang=apl inline>⊢</source> is the [[identity]] function, which is just used here get the pass-though value from the assignment, as it would otherwise be hidden. (We call assignment ''shy''.) <source lang=apl inline>\</source> is just like <source lang=apl inline>/</source> but gives us the intermediate values.


=== Generating indices in 2D ===
=== Combining arrays ===
<source lang=apl inline>⍴r</source> is the [[shape]] of our array of radii. Now, you remember <source lang=apl inline></source>, [[#Generating_indices|right]]? As it turns out, it can actually generate of an array of any number of dimensions; two in our case:
We need our offsets in two dimensions. So we need to combine the elements of <source lang=apl inline>offset</source> with themselves in all possible combinations.
 
The [[Rank operator]] (<source lang=apl inline></source>) allows you to specify what you want paired up with what. In our case, we want individual numbers (which have zero [[axes]]) paired up with other individual numbers. As pairing up the numbers in <source lang=apl inline>3 1 4</source> with those in <source lang=apl inline>2 7 1</source>:
<source lang=apl>
<source lang=apl>
       ⊢indices←⍳⍴sizes
       3 1 4(,⍤0)2 7 1
┌───┬───┬───┬───┬───┐
3 2
│0 0│0 1│0 2│0 3│0 4│
1 7
├───┼───┼───┼───┼───┤
4 1
│1 0│1 1│1 2│1 3│1 4│
├───┼───┼───┼───┼───┤
│2 0│2 1│2 2│2 3│2 4│
├───┼───┼───┼───┼───┤
│3 0│3 1│3 2│3 3│3 4│
├───┼───┼───┼───┼───┤
│4 0│4 1│4 2│4 3│4 4│
└───┴───┴───┴───┴───┘
</source>
</source>
Now we take each coordinate (i.e. each [[rank]] 0 sub-array) from that and use it to [[Squad index|index]] (<source lang=apl inline>⌷</source>) into the list (a [[rank]] 1 array) of offsets. The result has shape…
But we want to pair up each of the individual offsets with each of all the offsets. The offsets form a list, so we want to apply this pair-wise pairing function between each number and the entire list, as in:
<source lang=apl>
<source lang=apl>
      3 1 4(,⍤0⍤0 1)2 7 1
3 2
3 7
3 1
 
1 2
1 7
1 1
 
4 2
4 7
4 1
</source>
Since we want the offsets paird up with themselves, we can use <source lang=apl inline>⍨</source> again:
<source lang=apl>
            ,⍤0⍤0 1⍨⍳3
0 0
0 1
0 2
 
1 0
1 1
1 2
 
2 0
2 1
2 2
</source>
The offset pairs form our circle locations:
       ⍴locs←indices⌷⍤0 1⊢offsets
       ⍴locs←indices⌷⍤0 1⊢offsets
5 5 2
5 5 2
</source>
</source>
that is, it is a 3D array with 5 layers, 5 rows in each layer, and 2 columns in each row. The [[Rank operator]] (<source lang=apl inline>⍤</source>) allows me to specify that I want rank 0 sub-arrays on the left paired up with rank-1 sub-arrays on the right. The <source lang=apl inline>⊢</source> doesn't do anything other than separate <source lang=apl inline>0 1</source> from <source lang=apl inline>offsets</source>, so the <source lang=apl inline>⍤</source> knows what is its right [[operand]] (which specifies on what sub-arrays the function left operand is to be called) and what is its right [[argument]] (which contains the arguments for that function in its sub-arrays).
that is, it is a 3D array with 5 layers, 5 rows in each layer, and 2 columns in each row. The [[Rank operator]] (<source lang=apl inline>⍤</source>) allows me to specify that I want rank 0 sub-arrays on the left paired up with rank-1 sub-arrays on the right. Each row of our result represents an <math>(x,y)</math> value. The first and last layers, which represents the leftmost and rightmost columns of the logo, are:
 
Each row of our result represents an <math>(x,y)</math> value. The first and last layers, which represents the leftmost and rightmost columns of the logo, are:
<source lang=apl>
<source lang=apl>
       (1↑locs) (¯1↑locs)
       (1↑locs) (¯1↑locs)

Navigation menu