diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-01-06 21:53:45 -0500 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-01-06 21:53:45 -0500 |
| commit | 337044f77dc491459e798625972cd83bed1e72bc (patch) | |
| tree | 03557a9c73b1e0401608cd7413633933b2ed2280 /spec/inferred.md | |
| parent | 3850e3a71dc69b633a6bc7211be2882c77d137d5 (diff) | |
Specify Insert identity behavior
Diffstat (limited to 'spec/inferred.md')
| -rw-r--r-- | spec/inferred.md | 8 |
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. |
