From c96289046dbd42678c10d03ceb5734737392bf4c Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Mon, 5 Jul 2021 22:20:19 -0400 Subject: Inter-documentation links and minor editing --- docs/doc/arithmetic.html | 6 +++--- docs/doc/based.html | 6 +++--- docs/doc/couple.html | 4 ++-- docs/doc/depth.html | 18 +++++++++--------- docs/doc/fold.html | 8 ++++---- 5 files changed, 21 insertions(+), 21 deletions(-) (limited to 'docs') diff --git a/docs/doc/arithmetic.html b/docs/doc/arithmetic.html index 40a6067e..42bf677a 100644 --- a/docs/doc/arithmetic.html +++ b/docs/doc/arithmetic.html @@ -89,7 +89,7 @@ 0124 ⟨ 0 1 1.4142135623730951 2 ⟩ -

Take note of the difference between the function -, and the "high minus" character ¯, which is a part of numeric notation. Also shown is the number , which BQN supports along with ¯∞ (but depending on implementation BQN may or may not keep track of ¯0. Integer optimization loses the distinction so it's best not to rely on it).

+

Take note of the difference between the function -, and the "high minus" character ¯, which is a part of numeric notation. Also shown is the number , which BQN supports along with ¯∞ (but depending on implementation BQN may or may not keep track of ¯0. Integer optimization loses the distinction so it's best not to rely on it).

The logarithm is written with Undo: . As with Power, the default base is e, giving a natural logarithm.

↗️
     10
 2.302585092994046
@@ -176,7 +176,7 @@
 
 
 
-

Now the monadic function symbols resemble those used in mathematics. In the case of Floor and Ceiling, this is because Ken Iverson invented them! As with other functions, he adapted them to work like other functions in order to create APL\360, in this case by removing the paired closing version of each one.

+

Now the monadic function symbols resemble those used in mathematics. In the case of Floor and Ceiling, this is because Ken Iverson invented them! As with other functions, he adapted them to use more uniform syntax in order to create APL\360, in this case by removing the paired closing version of each one.

↗️
     π
 3
 
@@ -276,7 +276,7 @@
     ¯∞π  @'0''?'
 ⟨ 0 0 0 ⟩
 
-

Equals and Not Equals are the two equality comparisons. Equals tests for atomic equality between each pair of atoms, as described in the Match documentation. Essentially, it returns 1 only if the two values are indistinguishable to BQN and 0 otherwise. Values of different types can never be equal, and characters are equal when they have the same code point.

+

Equals and Not Equals are the two equality comparisons. Equals tests for atomic equality between each pair of atoms, as described in the Match documentation. Essentially, it returns 1 only if the two values are indistinguishable to BQN and 0 otherwise. Values of different types can never be equal, and characters are equal when they have the same code point.

↗️
    +-×÷ = -
 ⟨ 0 1 0 0 ⟩
 
diff --git a/docs/doc/based.html b/docs/doc/based.html
index 23278025..e865ad4b 100644
--- a/docs/doc/based.html
+++ b/docs/doc/based.html
@@ -9,8 +9,8 @@
 

This page explains how BQN's array model (christened "based" in 1981) differs from the models used by existing APL dialects, and why the choice was made to discard APL's "everything is an array" dictum. If you're not wondering what the difference is, and don't think everything should be an array, then you can probably just read about BQN's type system instead.

If you're an array programmer then I have bad news for you. My thesis here is that APL took a wrong turn around 1981 when it extrapolated the excellent, but limited, flat array model of APL\360 to the ill-founded nested array model and the rigorous but clumsy boxed array model. Make that two wrong turns, I guess. Simultaneously. Anyway, if you've been brought up in either of these array models, then the best thing to do when starting BQN is to throw out your existing ideas about array depth and nesting (but don't worry too much: the fundamental concept of an array as a rectangular collection of data still holds!). If you'd like to ponder the relationship of BQN to APL later, that's great, but trying to initially understand BQN in terms of APL or J will just cause confusion.

Starting from atoms

-

APL tends to define its data by starting with the array and then looking downwards in depth at what it contains. The based array model, as the name suggests, starts at the foundations, which in BQN are called "atoms". There are five types of atom, which together with the array type give the six types a value can have in BQN. Based means being yourself, and an atom's not an array.

-

An atom has depth 0, and doesn't inherently have a shape. However, primitives that expect an array promote atoms by enclosing them to get a rank-0, or unit, array that contains the atom (any value can be enclosed in this way, giving a unit array with higher depth, but it only happens automatically for atoms). Rank and shape both do this, so an atom can be considered to have the same dimensions as a unit array: rank 0 and shape ⟨⟩. An atom is also considered a kind of unit, but it's not a unit array.

+

APL tends to define its data by starting with the array and then looking downwards in depth at what it contains. The based array model, as the name suggests, starts at the foundations, which in BQN are called "atoms". There are six types of atom, which together with the array type give the seven types a value can have in BQN. Based means being yourself, and an atom's not an array.

+

An atom has depth 0, and doesn't inherently have a shape. However, primitives that expect an array promote atoms by enclosing them to get a rank-0, or unit, array that contains the atom (any value can be enclosed in this way, giving a unit array with higher depth, but it only happens automatically for atoms). Rank and shape both do this, so an atom can be considered to have the same dimensions as a unit array: rank 0 and shape ⟨⟩. An atom is also considered a kind of unit, but it's not a unit array.

Atoms are displayed as plain values, while enclosed atoms, that is, depth-1 unit arrays, are shown with an array display.

↗️
    3    # Atom
 3
@@ -26,7 +26,7 @@
      plus
 0
 
-

The primitives that return a single number, like Rank (=), Length (), and Match (), give it as an atom, not an array.

+

The primitives that return a single number, like Rank (=), Length (), and Match (), give it as an atom, not an array.

↗️
     "abc"
 1
       "abc"  # The result was an atom
diff --git a/docs/doc/couple.html b/docs/doc/couple.html
index fa9b905a..1e55a233 100644
--- a/docs/doc/couple.html
+++ b/docs/doc/couple.html
@@ -65,7 +65,7 @@
       ¨ a
 "ABrstABuvwABxyzCDrstCDuvwCDxyz"
 
-

The way this happens, and the constraint that all inner arrays have the same shape, is closely connected to the concept of an array, and like Table , Merge might be considered a fundamental way to build up multidimensional arrays from lists. In both cases rank-0 or unit arrays are somewhat special. They are the identity element of a function with Table, and can be produced by Merge inverse, > on a list, which forces either the outer or inner shape to be empty (BQN chooses > to be <, but only on an array, as > cannot produce non-arrays). Merge has another catch as well: it cannot produce arrays with a 0 in the shape, except at the end, without some sort of prototype system.

+

The way this happens, and the constraint that all inner arrays have the same shape, is closely connected to the concept of an array, and like Table , Merge might be considered a fundamental way to build up multidimensional arrays from lists. In both cases rank-0 or unit arrays are somewhat special. They are the identity value of a function with Table, and can be produced by Merge inverse, > on a list, which forces either the outer or inner shape to be empty (BQN chooses > to be <, but only on an array, as > cannot produce non-arrays). Merge has another catch as well: it cannot produce arrays with a 0 in the shape, except at the end, unless fills can be specified.

↗️
     e  ⟨⟩¨ 3
 ⟨ ⟨⟩ ⟨⟩ ⟨⟩ ⟩
      > e
@@ -75,7 +75,7 @@
 

Above we start with a list of three empty arrays. After merging once we get a shape 30 array, sure, but what happens next? The shape added by another merge is the shared shape of that array's elements—and there aren't any! If the nested list kept some type information around then we might know, but extra type information is essentially how lists pretend to be arrays. True dynamic lists simply can't represent multidimensional arrays with a 0 in the middle of the shape. In this sense, arrays are a richer model than nested lists.

Coupling units

-

A note on the topic of Solo and Couple applied to units. As always, one axis will be added, so that the result is a list (strangely, J's laminate differs from Couple in this one case, as it will add an axis to get a shape 21 result). For Solo, this is interchangeable with Deshape (), and either primitive might be chosen for stylistic reasons. For Couple, it is equivalent to Join-to (), but this is an irregular form of Join-to because it is the only case where Join-to adds an axis to both arguments instead of just one. Couple should be preferred in this case.

+

A note on the topic of Solo and Couple applied to units. As always, one axis will be added, so that the result is a list (strangely, J's laminate differs from Couple in this one case, as it will add an axis to get a shape 21 result). For Solo, this is interchangeable with Deshape (), and either primitive might be chosen for stylistic reasons. For Couple, it is equivalent to Join-to (), but this is an irregular form of Join-to because it is the only case where Join-to adds an axis to both arguments instead of just one. Couple should be preferred in this case.

The pair function, which creates a list from its arguments, can be written Pair <, while in either valence is >Pair. As an interesting consequence, ←→ ><, and the same relationship holds for Pair.

↗️
    2,3 < "abc"  # Pair two values
 ⟨ ⟨ 2 3 ⟩ "abc" ⟩
diff --git a/docs/doc/depth.html b/docs/doc/depth.html
index 2332c674..4c5ca982 100644
--- a/docs/doc/depth.html
+++ b/docs/doc/depth.html
@@ -72,7 +72,7 @@
      "a string is a list of characters"
 1
 
-

Depth is somewhat analogous to an array's rank =𝕩, and in fact rank can be "converted" to depth by splitting rows with <1, reducing the rank by 1 and increasing the depth. Unlike rank, Depth doesn't care at all about its argument's shape:

+

Depth is somewhat analogous to an array's rank =𝕩, and in fact rank can be "converted" to depth by splitting rows with <1, reducing the rank by 1 and increasing the depth. Unlike rank, Depth doesn't care at all about its argument's shape:

↗️
     34"characters"
 1
      (1+↕10)"characters"
@@ -125,13 +125,13 @@
 
 
 
-

Functions such as Take and Drop use a single number per axis. When the left argument is a list of numbers, they apply to initial axes. But for convenience, a single number is also accepted, and applied to the first axis only. This is equivalent to ravelling the left argument before applying the function.

+

Functions such as Take and Drop use a single number per axis. When the left argument is a list of numbers, they apply to initial axes. But for convenience, a single number is also accepted, and applied to the first axis only. This is equivalent to deshaping the left argument before applying the function.

↗️
    27777"abc"
 ⟨ 2 7 7 7 ⟩
     2117777"abc"
 ⟨ 2 1 1 7 ⟩
 
-

In these cases the flexibility seems trivial because the left argument has depth 1 or 0: it is an array or isn't, and it's obvious what a plain number should do. But for the second row in the table, the left argument is always an array. The general case is that the left argument is a vector and its elements correspond to right argument axes:

+

In these cases the flexibility seems trivial because the left argument has depth 1 or 0: it is an array or isn't, and it's obvious what a plain number should do. But for the second row in the table, the left argument is always an array. The general case (Select below) is that the left argument is a list and its elements correspond to right argument axes:

↗️
    32,141  67
 ┌─                         
 ╵ ⟨ 3 1 ⟩ ⟨ 3 4 ⟩ ⟨ 3 1 ⟩  
@@ -142,7 +142,7 @@
 ↗️
    32,1 <(0=≡)¨ 67
 ⟨ ⟨ 3 1 ⟩ ⟨ 2 1 ⟩ ⟩
 
-

While very consistent, this extension represents a small convenience and makes it difficult to act on a single axis, which for Replicate and Group is probably the most common way the primitive is used:

+

While very consistent, this extension represents a small convenience and makes it difficult to act on a single axis, which for Replicate and Group is probably the most common way the primitive is used:

↗️
    32123 / "abcde"
 "aaabbcddeee"
 
@@ -152,7 +152,7 @@ ⟨ ⟨ 2 1 4 0 ⟩ ⟨ 2 1 4 1 ⟩ ⟩

The Depth modifier

-

The Depth 2-modifier () is a generalization of Each that allows diving deeper into an array. To illustrate it we'll use a shape 43 array of lists of lists.

+

The Depth 2-modifier () is a generalization of Each that allows diving deeper into an array. To illustrate it we'll use a shape 43 array of lists of lists.

↗️
     n  <12 4322⥊↕48
 ┌─                                                                         
 ╵ ⟨ ⟨ 0 1 ⟩ ⟨ 2 3 ⟩ ⟩     ⟨ ⟨ 4 5 ⟩ ⟨ 6 7 ⟩ ⟩     ⟨ ⟨ 8 9 ⟩ ⟨ 10 11 ⟩ ⟩    
@@ -163,7 +163,7 @@
      n
 3
 
-

Reversing n swaps all the rows:

+

Reversing n swaps all the rows:

↗️
     n
 ┌─                                                                         
 ╵ ⟨ ⟨ 36 37 ⟩ ⟨ 38 39 ⟩ ⟩ ⟨ ⟨ 40 41 ⟩ ⟨ 42 43 ⟩ ⟩ ⟨ ⟨ 44 45 ⟩ ⟨ 46 47 ⟩ ⟩  
@@ -172,7 +172,7 @@
   ⟨ ⟨ 0 1 ⟩ ⟨ 2 3 ⟩ ⟩     ⟨ ⟨ 4 5 ⟩ ⟨ 6 7 ⟩ ⟩     ⟨ ⟨ 8 9 ⟩ ⟨ 10 11 ⟩ ⟩    
                                                                           ┘
 
-

Depth ¯1 is equivalent to Each, and reverses the larger vectors, while depth ¯2 applies Each twice to reverse the smaller vectors:

+

Depth ¯1 is equivalent to Each, and reverses the larger lists, while depth ¯2 applies Each twice to reverse the smaller lists:

↗️
    ¯1 n
 ┌─                                                                         
 ╵ ⟨ ⟨ 2 3 ⟩ ⟨ 0 1 ⟩ ⟩     ⟨ ⟨ 6 7 ⟩ ⟨ 4 5 ⟩ ⟩     ⟨ ⟨ 10 11 ⟩ ⟨ 8 9 ⟩ ⟩    
@@ -188,13 +188,13 @@
   ⟨ ⟨ 37 36 ⟩ ⟨ 39 38 ⟩ ⟩ ⟨ ⟨ 41 40 ⟩ ⟨ 43 42 ⟩ ⟩ ⟨ ⟨ 45 44 ⟩ ⟨ 47 46 ⟩ ⟩  
                                                                           ┘
 
-

While a negative depth tells how many levels to go down, a non-negative depth gives the maximum depth of the argument before applying the left operand. On a depth-3 array like above, depth 2 is equivalent to ¯1 and depth 1 is equivalent to ¯2. A depth of 0 means to descend all the way to the level of atoms, that is, apply pervasively, like an arithmetic function.

+

While a negative depth tells how many levels to go down, a non-negative depth gives the maximum depth of the argument before applying the left operand. On a depth-3 array like above, depth 2 is equivalent to ¯1 and depth 1 is equivalent to ¯2. A depth of 0 means to descend all the way to the level of atoms, that is, apply pervasively, like an arithmetic function.

↗️
    'a',"bc" 0 23,4
 ┌─                                                 
 · ⟨ ⟨ 'a' 2 ⟩ ⟨ 'a' 3 ⟩ ⟩ ⟨ ⟨ 'b' 4 ⟩ ⟨ 'c' 4 ⟩ ⟩  
                                                   ┘
 
-

With a positive operand, Depth doesn't have to use the same depth everywhere. Here, Length is applied as soon as the depth for a particular element is 1 or less, including if the argument has depth 0. For example, it maps over 2,3,4⟩⟩, but not over 11,12, even though these are elements of the same array.

+

With a positive operand, Depth doesn't have to use the same depth everywhere. Here, Length is applied as soon as the depth for a particular element is 1 or less, including if the argument has depth 0. For example, it maps over 2,3,4⟩⟩, but not over 11,12, even though these are elements of the same array.

↗️
    1 1,2,3,4⟩⟩,5,6,7,8,9,10⟩⟩,11,12⟩⟩
 ⟨ 1 ⟨ 1 2 ⟩ ⟨ 1 2 3 ⟩ 2 ⟩
 
diff --git a/docs/doc/fold.html b/docs/doc/fold.html index 7c03d174..7c2703c8 100644 --- a/docs/doc/fold.html +++ b/docs/doc/fold.html @@ -69,7 +69,7 @@ ↗️
    !´ 
-

Folding over a list of two values applies 𝔽 once, since 𝔽 is always called on two arguments. But what about zero values? Should 𝔽 be applied minus one times? Sort of. BQN checks to see if it knows an identity value for the operand function, and returns that, never calling the function. This works for the arithmetic functions we showed above, always returning a single number.

+

Folding over a list of two values applies 𝔽 once, since 𝔽 is always called on two arguments. But what about zero values? Should 𝔽 be applied minus one times? Sort of. BQN checks to see if it knows an identity value for the operand function, and returns that, never calling the function. This works for the arithmetic functions we showed above, always returning a single number.

↗️
    +´ ⟨⟩  # Add nothing up, get zero
 0
     ´ ⟨⟩  # The smallest number
@@ -133,15 +133,15 @@
 
 
 

Right-to-left

-

The functions we've shown so far are associative (ignoring floating point imprecision), meaning it's equally valid to combine elements of the argument list in any order. But it can be useful to fold using a non-associative function. In this case you must know that Fold performs a right fold, starting from the array and working towards the beginning.

+

The functions we've shown so far are associative (ignoring floating point imprecision), meaning it's equally valid to combine elements of the argument list in any order. But it can be useful to fold using a non-associative function. In this case you must know that Fold performs a right fold, starting from the end of the array and working towards the beginning.

↗️
    <´ "abcd"
 ⟨ 'a' ⟨ 'b' "cd" ⟩ ⟩
 
     'a' < 'b' < 'c' < 'd'  # Expanded form
 ⟨ 'a' ⟨ 'b' "cd" ⟩ ⟩
 
-

Using the pair function < as an operand shows the structure nicely. This fold first pairs the final two characters 'c' and 'd', then pairs 'b' with that and so on. This matches BQN's right-to-left order of evaluation. More declaratively we might say that each character is paired with the result of folding over everything to its right.

-

BQN doesn't provide a left Fold (` is Scan). However, you can fold from the left by reversing () the argument list and also reversing (˜) the operand function's argument order.

+

Using the pair function < as an operand shows the structure nicely. This fold first pairs the final two characters 'c' and 'd', then pairs 'b' with that and so on. This matches BQN's right-to-left order of evaluation. More declaratively we might say that each character is paired with the result of folding over everything to its right.

+

BQN doesn't provide a left Fold (` is Scan). However, you can fold from the left by reversing () the argument list and also reversing (˜) the operand function's argument order.

↗️
    <˜´  "abcd"
 ⟨ ⟨ "ab" 'c' ⟩ 'd' ⟩
 
-- cgit v1.2.3