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/repeat.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'docs/doc/repeat.html') diff --git a/docs/doc/repeat.html b/docs/doc/repeat.html index aaa68219..b5e4ba06 100644 --- a/docs/doc/repeat.html +++ b/docs/doc/repeat.html @@ -4,7 +4,7 @@ BQN: The Repeat modifier -

The Repeat modifier

+

The Repeat modifier

Repeat (⍟) is a 2-modifier that applies its operand function 𝔽 multiple times.

↗️
    »»» "ABCDE"
 "   AB"
@@ -18,7 +18,7 @@
 

F⍟0 repeats F zero times, that is, does nothing. Like n⋆0 gives the multiplicative identity 1, F⍟0 is the compositional identity, ⊒. Since F⍟1 applies F and F⍟0 doesn't, Repeat might be pronounced "if" or "conditional" when 𝔾 is boolean.

BQN's Repeat modifier has some extra functionality relative to the mathematical version. It allows a left argument, and some extensions to the right operand 𝔾. As usual for 2-modifiers, 𝔾 is actually a function that applies to the arguments to give a result. The result can be a natural number as shown above, or a negative number to Undo (⁼) 𝔽, or an array of values.

-

Left argument

+

Left argument

If 𝕨 is given, it's passed as the left argument to 𝔽 for every invocation.

↗️
    3 +⍟2 7
 13
@@ -26,7 +26,7 @@
 13
 

This kind of composition can't be represented by ∘ anymore (you'd need a train), but it's similar in spirit. 𝕨 π”½βŸn 𝕩 is always equivalent to π•¨βŠΈπ”½βŸn 𝕩, provided n is a constantβ€”not a function, as discussed in the next section.

-

Dynamic repetition count

+

Dynamic repetition count

In the general case, 𝔾 is a function, which is applied to all arguments to get the repetition count. That is, the actual count is 𝕨𝔾𝕩.

↗️
    ∾⟜1⍟⊒ 4
 ⟨ 4 1 1 1 1 ⟩
@@ -42,13 +42,13 @@
 ↗️
    3 ⊣⍟<Β¨ 2β€Ώ4β€Ώ6  # Left if less, i.e. minimum
 ⟨ 2 3 3 ⟩
 
-

Negative repetition

+

Negative repetition

What does it mean to repeat a function a negative number of times? For a negative integer -n, BQN defines F⍟(-n) to be F⁼⍟n. In particular, F⍟¯1 simply undoes F.

↗️
    1 ⌽⍟¯1 "abcde"  # Rotate backwards
 "eabcd"
 

Because BQN's Undo is a little looser than a strict mathematical inverse, this is an extension of the function inverse written f⁻¹ in mathematics. As a result, it doesn't have all the same properties. For natural numbers, Repeat follows the rule that F⍟m F⍟n 𝕩 is F⍟(m+n) 𝕩. For integers, we have 𝕩 ≑ F⍟n F⍟(-n) 𝕩, but not necessarily 𝕩 ≑ F⍟(-n) F⍟n 𝕩.

-

Array of repetition counts

+

Array of repetition counts

The value of 𝕨𝔾𝕩 might also be an array, whose elements are any valid repetition valuesβ€”integers, or other arrays. Each integer in the nested structure is replaced with the result of repeating 𝔽 that many times.

↗️
    2βŠΈΓ—βŸβŸ¨2,⟨4,Β―2,1⟩⟩ 1
 ⟨ 4 ⟨ 16 0.25 2 ⟩ ⟩
-- 
cgit v1.2.3