aboutsummaryrefslogtreecommitdiff
path: root/spec/inferred.md
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2021-01-06 21:53:45 -0500
committerMarshall Lochbaum <mwlochbaum@gmail.com>2021-01-06 21:53:45 -0500
commit337044f77dc491459e798625972cd83bed1e72bc (patch)
tree03557a9c73b1e0401608cd7413633933b2ed2280 /spec/inferred.md
parent3850e3a71dc69b633a6bc7211be2882c77d137d5 (diff)
Specify Insert identity behavior
Diffstat (limited to 'spec/inferred.md')
-rw-r--r--spec/inferred.md8
1 files changed, 6 insertions, 2 deletions
diff --git a/spec/inferred.md b/spec/inferred.md
index 55d01352..a12da31b 100644
--- a/spec/inferred.md
+++ b/spec/inferred.md
@@ -10,9 +10,11 @@ For the specified cases, the given functions and modifiers refer to those partic
When monadic Fold (`Β΄`) or Insert (`˝`) is called on an array of length 0, BQN attempts to infer a right identity value for the function in order to determine the result. A right identity value for a dyadic function `𝔽` is a value `r` such that `e≑e𝔽r` for any element `e` in the domain. For such a value `r`, the reduction `r 𝔽´ l` is equivalent to `𝔽´ l` for a non-empty list `l`, because the first application `(Β―1βŠ‘l) 𝔽 r` gives `Β―1βŠ‘l`, which is the starting point when no initial value is given. It's thus reasonable to define `𝔽´ l` to be `r 𝔽´ l` for an empty list `l` as well, giving a result `r`.
-More specifically, the identity of a dyadic function `𝔽` is defined to be a right identity value for the *range* of `𝔽`, if exactly one such value exists. Otherwise, there is no identity and `𝔽´` or `𝔽˝` on an argument with length 0 results in an error.
+For Fold, the result of `𝔽´` on an empty list is defined to be a right identity value for the *range* of `𝔽`, if exactly one such value exists. If an identity can't be proven to uniquely exist, then an error results.
-Identity values for the arithmetic primitives below must be recognized.
+For Insert, `𝔽˝` on an array of length 0 is defined similarly, but also depends on the cell shape `1↓≒𝕩`. The required domain is the arrays of that shape that also lie in the range of `𝔽` (over arbitrary arguments, not shape-restricted ones).
+
+Identity values for the arithmetic primitives below must be recognized. Under Fold, the result is the given identity value, while under Insert, it is the identity value reshaped to the argument's cell shape.
| Id | Fn | Fn | Id |
|-----:|:---:|:---:|-----:|
@@ -24,6 +26,8 @@ Identity values for the arithmetic primitives below must be recognized.
| `0` | `β‰ ` | `=` | `1` |
| `0` | `>` | `β‰₯` | `1` |
+Additionally, the identity of `∾˝` must be recognized: if `0=≠𝕩`, then `βˆΎΛπ•©` is `(0∾2↓≒𝕩)β₯Šπ•©`.
+
## Undo
The Undo 1-modifier `⁼`, given an operand `𝔽` and argument `𝕩`, and possibly a left argument `𝕨`, finds a value `y` such that `𝕩≑𝕨𝔽y`, that is, an element of the pre-image of `𝕩` under `𝔽` or `π•¨π”½βŠ’`. Thus it satisfies the constraint `𝕩 ≑ 𝕨𝔽𝕨𝔽⁼𝕩` (`π•¨π”½βΌβŠ’` is a *right inverse* of `π•¨π”½βŠ’`) provided `𝔽⁼` and `𝔽` both complete without error. `𝔽⁼` should of course give an error if no inverse element exists, and can also fail if no inverse can be found. It is also preferred for `𝔽⁼` to give an error if there are many choices of inverse with no clear way to choose one of them: for example, `0β€Ώ0⍉m` returns the diagonal of matrix `m`; `0β€Ώ0⍉⁼2β€Ώ3` requires values to be chosen for the off-diagonal elements in its result. It is better to give an error, encouraging the programmer to use a fully-specified approach like `2β€Ώ3⌾(0β€Ώ0βŠΈβ‰)` applied to a matrix of initial elements, than to return a result that could be very different from other implementations.