From c618ade174cc2b4e428457751ad8dd01130c2239 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sat, 25 Jun 2022 22:20:19 -0400 Subject: Back to editing docs --- docs/doc/under.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'docs/doc/under.html') diff --git a/docs/doc/under.html b/docs/doc/under.html index ae931d47..2a06e458 100644 --- a/docs/doc/under.html +++ b/docs/doc/under.html @@ -57,15 +57,15 @@ 0 10 11 ┘ -

When used with Under, the function 1 applies to the first column, rotating it. The result of 𝔽 needs to be compatible with the selection function, so Rotate works but trying to remove an element is no good:

+

When used with Under, the function 1 applies to the first column, rotating it. The result of 𝔽 needs to be compatible with the selection function, so Rotate works but trying to drop an element is no good:

↗️
    1(˘) a
 Error: ⁼: Inverse not found
 
-

BQN can detect lots of structural functions when written in tacit form; see the list of functions in the spec. You can also include computations on the shape. For example, here's a function to reverse the first half of a list.

+

BQN can detect lots of structural functions when written tacitly; see the list of recognized forms in the spec. You can also include computations on the shape. For example, here's a function to reverse the first half of a list.

↗️
    (⊢↑˜≠÷2˙) "abcdef"
 "cbadef"
 
-

But you can't use a computation that uses array values, such as 10+((<5)/) to add 10 to each element below 5. This is because Under can change the array values, so that the function 𝔾 doesn't select the same elements before and after applying it (at the same time, Under can't change array structure, or at least not the parts that matter to 𝔾). To use a dynamic selection function, compute the mask or indices based on a copy of the argument and use those as part of 𝔾.

+

But you can't use a computation that uses array values, such as 10+((<5)/) to add 10 to each element below 5. This is because Under can change the array values, so that the function 𝔾 doesn't select the same elements before and after applying it (contrarily, Under can't change array structure, or at least not the parts that matter to 𝔾). To use a dynamic selection function, compute the mask or indices based on a copy of the argument and use those as part of 𝔾.

↗️
    {10+((𝕩<5)/)𝕩} 38226
 ⟨ 13 8 12 12 6 ⟩
 
@@ -89,14 +89,14 @@
 ↗️
    (10×) 3.5246.7992.031
 ⟨ 3.5 6.7 2 ⟩
 
-

See how it works? rounds down to an integer, but we can get it to round down to a decimal by first multiplying by 10 (single decimals are now integers), then rounding, then undoing that multiplication. A related idea is to not just round but produce a range. Suppose I want the arithmetic progression 4, 7, 10, ... <20. If I had the right range n, then it would be 4+3×↕n, or (4+3×⊢)n. By using the inverse of this transformation function on the desired endpoint, I can make sure it's applied on the way out, and BQN figures out what to do on the way in as if by magic.

+

See how it works? rounds down to an integer, but we can get it to round down to a decimal by first multiplying by 10 (so that single decimals become integers), then rounding, then undoing that multiplication. A related idea is to not just round but produce a range. Suppose I want the arithmetic progression 4, 7, 10, ... <20. If I had the right range n, then it would be 4+3×↕n, or (4+3×⊢)n. By using the inverse of this transformation function on the desired endpoint, I can make sure it's applied on the way out, and BQN figures out what to do on the way in as if by magic.

↗️
    ((4+3×⊢)) 20
 ⟨ 4 7 10 13 16 19 ⟩
 
-

Well, really it's a bit of simple algebra, but if it wants to wear a pointy hat and wave a wand around I won't judge.

+

Well, really it's some simple algebra, but if it wants to wear a pointy hat and wave a wand around I won't judge.

Left argument

When called dyadically, Under applies 𝔽 dyadically, like Over. This doesn't affect the undoing part of Under, which still tries to put the result of 𝔽 back into 𝕩 for structural Under or invert 𝔾 for computational. In fact, 𝕨 𝔽𝔾 𝕩 is equivalent to (𝔾𝕨)˙𝔽𝔾 𝕩 so no exciting language stuff is happening here at all.

-

But you can still do some cool stuff with it! One pattern is simply to set 𝔽 to , the identity function that just returns its left argument. Now structural Under will replace everything that 𝔾 selects from 𝕩 with the corresponding values in 𝕨. Here's an example that replaces elements with indices 1 and 2.

+

But you can still do cool things with it! One pattern is simply to set 𝔽 to , the identity function that just returns its left argument. Now structural Under will replace everything that 𝔾 selects from 𝕩 with the corresponding values in 𝕨. Here's an example that replaces elements with indices 1 and 2.

↗️
    "abcd" (12) "0123"
 "0bc3"
 
-- cgit v1.2.3