From 723f2735dbd59f6000caecddccf321c8b03512fa Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Tue, 27 Jul 2021 22:28:33 -0400 Subject: Undo documentation --- docs/doc/identity.html | 2 +- docs/doc/index.html | 1 + docs/doc/primitive.html | 2 +- docs/doc/repeat.html | 2 +- docs/doc/transpose.html | 2 +- docs/doc/undo.html | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 docs/doc/undo.html (limited to 'docs/doc') diff --git a/docs/doc/identity.html b/docs/doc/identity.html index 196b219c..ec710ab6 100644 --- a/docs/doc/identity.html +++ b/docs/doc/identity.html @@ -19,7 +19,7 @@ "left"

Depending on your past experiences, this could cause some confusion: built-in support for functions that do nothing? Documentation should say why a feature's there and how to use it, not just what it does, so we'll try to address this below. The most important single use is for tacit programming, but there are a variety of other uses as well.

-

Of course, it's easy to write block functions {𝕩} and {𝕨} that return particular arguments. While I would already make ⊣ and ⊒ primitives just because they are common and important, there are also specific disadvantages to using blocks. They fail to indicate that there are no side effects, as primitives would, and they also need special casing for the interpreter to manipulate them when applying Undo (⁼) or making other inferences.

+

Of course, it's easy to write block functions {𝕩} and {𝕨} that return particular arguments. While I would already make ⊣ and ⊒ primitives just because they are common and important, there are also specific disadvantages to using blocks. They fail to indicate that there are no side effects, as primitives would, and they also need special casing for the interpreter to manipulate them when applying Undo (⁼) or making other inferences.

Filling arrays

What's the easiest way to create a matrix with 0 on the first row, 1 on the second, and so on? Probably this one, with table:

↗️
    (↕4) ⊣⌜ ↕5
diff --git a/docs/doc/index.html b/docs/doc/index.html
index 1c68347a..356773a9 100644
--- a/docs/doc/index.html
+++ b/docs/doc/index.html
@@ -67,6 +67,7 @@
 
  • Solo, Couple, and Merge (≍>)
  • Take and Drop (↑)
  • Transpose (⍉)
  • +
  • Undo (⁼)
  • Windows (↕)
  • Environment:

    diff --git a/docs/doc/primitive.html b/docs/doc/primitive.html index 56b8a1a3..4c6ef8a8 100644 --- a/docs/doc/primitive.html +++ b/docs/doc/primitive.html @@ -506,7 +506,7 @@ ⁼ -Undo +Undo ⍟ Repeat diff --git a/docs/doc/repeat.html b/docs/doc/repeat.html index 2de6fd6e..bfbe28e5 100644 --- a/docs/doc/repeat.html +++ b/docs/doc/repeat.html @@ -17,7 +17,7 @@ F⍟4 ←→ F∘F∘F∘F

    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.

    +

    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

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

    ↗️
        3 +⍟2 7
    diff --git a/docs/doc/transpose.html b/docs/doc/transpose.html
    index ee3e926c..e0cdf512 100644
    --- a/docs/doc/transpose.html
    +++ b/docs/doc/transpose.html
    @@ -63,7 +63,7 @@
                              β”˜  
                                β”˜
     
    -

    To exchange multiple axes, use the Repeat modifier. A negative power moves axes in the other direction, just like how Rotate handles negative left arguments. In particular, to move the last axis to the front, use Undo (as you might expect, this exactly inverts ⍉).

    +

    To exchange multiple axes, use the Repeat modifier. A negative power moves axes in the other direction, just like how Rotate handles negative left arguments. In particular, to move the last axis to the front, use Undo (as you might expect, this exactly inverts ⍉).

    ↗️
        β‰’ β‰βŸ3 a23456
     ⟨ 5 6 2 3 4 ⟩
     
    diff --git a/docs/doc/undo.html b/docs/doc/undo.html
    new file mode 100644
    index 00000000..973a942a
    --- /dev/null
    +++ b/docs/doc/undo.html
    @@ -0,0 +1,53 @@
    +
    +  
    +  
    +  BQN: Undo
    +
    +
    +

    Undo

    +

    Oh no, you've deleted a function after spending half an hour writing it! Well… hopefully your editor can help with that. But maybe you'll be interested to hear that BQN can reverse the action of some functionsβ€”ones that don't lose information. This capability is also used by Repeat (⍟) to repeat a negative number of times.

    +↗️
        2 ⌽ "abcde"
    +"cdeab"
    +
    +    2 ⌽⁼ 2 ⌽ "abcde"
    +"abcde"
    +
    +

    Above is one example of Undo (⁼) in action. Rotate shifts the elements of a list left, and undoing shifts them to the right. BQN's ability to undo functions covers a lot of cases and can seem somewhat magical:

    +↗️
        (Fn ← -⟜1⌾(Β―1βŠΈβŠ‘)) "BQN"
    +"BQM"
    +
    +    Fn⁼ Fn "BQN"
    +"BQN"
    +
    +

    Here it undoes a function to decrement the last character by incrementing that character. In part this is enabled by the clean design of BQN primitives, because better-behaved functions like those using structural Under are easier to invert.

    +

    The rules

    +

    If 𝔽 can be inverted exactly, then Undo just does that. However, there are also some other functions that BQN inverts. For example, the squaring function Γ—Λœ has both a positive and a negative inverse, and yet:

    +↗️
        Γ—Λœ Β―3
    +9
    +    Γ—ΛœβΌ Γ—Λœ Β―3  # It's not the same!
    +3
    +
    +

    Don't worry, this isn't 'nam. Undo doesn't always satisfy 𝕩 ≑ 𝔽⁼ 𝔽 𝕩, but it does obey 𝕩 ≑ 𝔽 𝔽⁼ 𝕩. That is, it gives one possible argument that could have been passed to 𝔽, just not necessarily the one that actually was. BQN is conservative in how it uses this freedom, so that it won't for example make up new elements entirely to find an inverse. It's usually used when there's an obvious or standard way to pick which of the possible values should be returned.

    +

    In a BQN with floating-point numbers, computations are approximate, so the inverse is allowed to be approximate as well (any error should still be very small though).

    +↗️
        6 - √⁼√6
    +8.881784197001252eΒ―16
    +
    +

    What's supported?

    +

    For the full list, see the specification. An individual implementation might support a lot more functionality than is required, so if you're not concerned about portability just try out whatever function you're interested in.

    +

    Arithmetic and simple combinators are usually invertible. A compound function that refers to its argument just once, like 6+βŒ½βˆ˜β‰, can typically be undone, but one that uses the argument in two different ways, such as ⊒+⋆, probably can't.

    +

    A few notable inverses are the logarithm ⋆⁼, un-Transpose ⍉⁼, and Indices inverse /⁼. Enclose inverse, <⁼, is an alternative to First that requires its argument to be a unit.

    +

    Structural functions like Take and shifts that remove elements from 𝕩 can't be inverted, because given the result there's no way to know what the elements should be. However, there are two special cases that have inverses defined despite losing data: these are ⊣⁼ and k⁼ where k is a constant (a data type, or kΛ™). For these, 𝕩 is required to match the always returned value 𝕨 or k, and this value is also used for the resultβ€”even though any result would be valid, as these functions ignore 𝕩.

    +↗️
        3 ⊣⁼ 4
    +ERROR
    +    3 ⊣⁼ 3
    +3
    +
    +

    Undo headers

    +

    Undo headers are currently supported only by dzaima/BQN.

    +

    Of course BQN will never be able to invert all the functions you could write (if it could you could earn a lot of bitcoins, among other feats). But it does recognize some header forms that you can use to specify the inverse of a block function. BQN will trust you and won't verify the results your specified inverse gives.

    +
    {
    +  π•Šπ•©:  𝕩÷𝕩+1
    +  π•ŠβΌπ•©: 𝕩÷𝕩-1
    +}
    +
    +

    The above function could also be defined with the automatically invertible 1⊸+⌾÷, but maybe there's a numerical reason to use the definition above. Like a normal header, an undo header reflects the normal use, but it includes ⁼ and possibly ˜ addition to the function and arguments.

    -- cgit v1.2.3