From 2afb23928e1984d475cc460e1672e8f6fa0e4dbe Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Wed, 11 Aug 2021 17:21:31 -0400 Subject: Allow clicking on header to get fragment link --- docs/doc/leading.html | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'docs/doc/leading.html') diff --git a/docs/doc/leading.html b/docs/doc/leading.html index ac7d2d49..55b72a40 100644 --- a/docs/doc/leading.html +++ b/docs/doc/leading.html @@ -4,10 +4,10 @@ BQN: The leading axis convention -

The leading axis convention

+

The leading axis convention

Several primitive functions manipulate the right argument, or sometimes both arguments, of an array along one or more axes. According to the leading axis model, it's best to make the primitives operate on initial axes, because the Rank modifier then allows it to apply to later axes as well. Here we'll see how this pattern works in BQN.

-

Monadic functions

-

Manipulating cells

+

Monadic functions

+

Manipulating cells

Most non-arithmetic monadic functions work only on the first axis of the argument—that is, they treat it as a list of its major cells. The function Length () counts these major cells, while Prefixes (), Suffixes (), Reverse (), and First Cell () move them around. The Insert (˝) and Scan (`) modifiers also yield functions that work along the first axis; in contrast, Fold (´) requires 𝕩 to be a list, as it works on elements.

↗️
     a  32  "abcdef"  # An array with three major cells
 ┌─    
@@ -80,7 +80,7 @@
      0 a               # …or deeper still.
 ⟨ 3 2 1 ⟩
 
-

Comparing cells

+

Comparing cells

The functions in the last section manipulate cells in the same way regardless of what data they contain. Other functions compare cells to each other, either testing whether they match or how they are ordered relative to one another. The two Grade functions ⍋⍒, and the self-search functions Classify (), Mark Firsts (), and Occurrence Count (), each give a list result, with one number for each cell. We can see below that Occurrence Count returns the same results even as we make the argument cells more complicated, because the changes made preserve the matching of cells.

↗️
    s  "abracadabra"
      s
@@ -106,13 +106,13 @@
   3 3 2 1 0  
             ┘
 
-

Other monadic functions

+

Other monadic functions

Not all functions work on the first axis in a straightforward manner. Transpose moves the first axis to the end, so while it focuses on the first one, it shifts every axis of 𝕩. Join also works on every axis of its argument, and applies to the leading axes of 𝕩's elements instead: these leading inner axes are matched up with the outer axes, and trailing inner axes are allowed but the elements must have rank at least as high as the argument array.

The other two monadic functions that work on high-rank arguments are Deshape () and First (). These treat 𝕩 as one long list, ordered by its element indices. This ordering privileges leading axes (in fact, it is the reason for the choice of leading axes in the leading axis convention), but these functions can't really be said to work on leading axes: they apply to all axes.

The Each (¨) and Table () modifiers return functions which are the same in the monadic case. These functions simply go through all elements of the argument array without regard for its multi-dimensional structure (the operand is applied to elements in index order, matching Deshape; this matters if it has side effects). Similarly, monadic arithmetic functions do not have any sort of leading axis dependence.

-

Dyadic functions

+

Dyadic functions

For dyadic functions the pattern of working on only one argument axis is not so common. Only two functions can be said to follow it roughly: Join to () combines two arrays along one axis, using the first axis of both arguments if they have the same rank and of the higher-rank argument if they differ by one. Couple (), like Solo, does not manipulate the argument axes but adds a result axis. There are also some functions that can't be limited to leading axes: Reshape () treats 𝕩 as one long list, and Pick () requires each index to be as long as 𝕩's rank, because it selects elements and not cells from 𝕩.

-

Multiple axes

+

Multiple axes

Instead of always working on a single axis, many dyadic functions work on one axis by default, but also allow a left argument with multiple elements corresponding to leading axes of 𝕩. To decide which of the two possibilities applies, these functions test the depth of 𝕨, a convention that is discussed in the depth documentation. A left argument that applies to one axis has a particular depth; 𝕨 can also be a list of such arguments.

@@ -145,7 +145,7 @@ ⟨ 4 5 7 7 ⟩

Functions with single-axis depth 1 tend to be more complicated; see for example Group.

-

Leading axis agreement

+

Leading axis agreement

Arithmetic functions, and the Each (¨) and Depth () modifiers, use leading axis agreement to match their arguments together. All axes of the lower-rank argument are matched with the leading axes of the higher-rank one, and axes matched together must have the same length. After pairing axes in this way, a single element of the lower-rank argument might correspond to any number of elements of the higher-rank one. It's reused for each of those corresponding elements.

↗️
     x  324  60     # A rank-3 array
 ┌─             
@@ -200,7 +200,7 @@
 

If one argument is a unit, that is, it has no axes, then leading axis agreement reduces to APL's "scalar extension" (where "scalar" is equivalent to BQN's "unit"), where a single unit is matched with an entire array by repeating it at every application. A unit always agrees with any other array under leading axis agreement because it has no axes whose lengths would need to be checked.

With leading axis agreement, there are k+1 shapes for arrays that can be added (or any other function with Each) to a given array x without changing its rank. These are precisely the prefixes of x, with ranks from 0 to k inclusive. Arrays with larger rank can also be used as the other argument, but then the result shape will match that argument and not x.

-

Search functions

+

Search functions

The search functions, Index of (), Progressive Index of (), and Member of (), and also Bins (⍋⍒), look through cells of one argument to find cells of the other. Find () also does a search, but a slightly different one: it tries to find slices of cells of 𝕩 that match 𝕨.

-- cgit v1.2.3