diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-07-21 19:13:22 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-07-21 19:24:35 -0400 |
| commit | b3ecbb5695a5a0a0637c924da0022abca940ffee (patch) | |
| tree | bb6928abcb6d2019450ea48637ef1ceb856fe3c5 | |
| parent | bb7f6750d5be62bafff46dd94883189977b39d6a (diff) | |
Add Rank function as monadic =
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | doc/depth.md | 2 | ||||
| -rw-r--r-- | doc/transpose.md | 8 | ||||
| -rw-r--r-- | docs/doc/depth.html | 2 | ||||
| -rw-r--r-- | docs/doc/transpose.html | 8 | ||||
| -rw-r--r-- | docs/index.html | 2 | ||||
| -rwxr-xr-x | dzref | 37 | ||||
| -rw-r--r-- | md.bqn | 10 | ||||
| -rw-r--r-- | spec/reference.bqn | 68 | ||||
| -rw-r--r-- | test/testref.bqn | 2 |
10 files changed, 71 insertions, 70 deletions
@@ -108,7 +108,7 @@ Functions that have significant differences from APL functions are marked with a | `<` | [Enclose](https://aplwiki.com/wiki/Enclose) | [Less Than](https://aplwiki.com/wiki/Less_than) | `>` | [Merge](https://aplwiki.com/wiki/Mix) | [Greater Than](https://aplwiki.com/wiki/Greater_than) | `≥` | | [Greater Than or Equal to](https://aplwiki.com/wiki/Greater_than_or_Equal_to) -| `=` | | [Equals](https://aplwiki.com/wiki/Equal_to) +| `=` | Rank | [Equals](https://aplwiki.com/wiki/Equal_to) | `≠` | [Length](https://aplwiki.com/wiki/Tally) | [Not Equals](https://aplwiki.com/wiki/Not_Equal_to) | `≡` | [Depth](doc/depth.md)* | [Match](https://aplwiki.com/wiki/Match) | `≢` | [Shape](https://aplwiki.com/wiki/Shape) | [Not Match](https://aplwiki.com/wiki/Not_Match) diff --git a/doc/depth.md b/doc/depth.md index 8738e7ed..d1e4fda3 100644 --- a/doc/depth.md +++ b/doc/depth.md @@ -11,7 +11,7 @@ To find the depth of an array, use Depth (`≡`). For example, the depth of a li ≡ 2‿3‿4 ≡ "a string is a list of characters" -Depth is somewhat analogous to an array's rank `≠≢𝕩`, and in fact rank can be "converted" to depth by splitting rows with `<⎉1`, reducing the rank by 1 and increasing the depth. Unlike rank, Depth doesn't care at all about its argument's shape: +Depth is somewhat analogous to an array's rank `=𝕩`, and in fact rank can be "converted" to depth by splitting rows with `<⎉1`, reducing the rank by 1 and increasing the depth. Unlike rank, Depth doesn't care at all about its argument's shape: ≡ 3‿4⥊"characters" ≡ (1+↕10)⥊"characters" diff --git a/doc/transpose.md b/doc/transpose.md index 82123644..3e7bf5c3 100644 --- a/doc/transpose.md +++ b/doc/transpose.md @@ -45,7 +45,7 @@ And of course, Rank and Power can be combined to do more complicated transpositi Using these forms, we can state BQN's generalized matrix product swapping rule: - a MP b ←→ ⍉⍟(≠≢a) a ⍉⁼⊸MP⟜⍉ b + a MP b ←→ ⍉⍟(=a) a ⍉⁼⊸MP⟜⍉ b Certainly not as concise as APL's version, but not a horror either. BQN's rule is actually more parsimonious in that it only performs the axis exchanges necessary for the computation: it moves the two axes that will be paired with the matrix product into place before the product, and directly exchanges all axes afterwards. Each of these steps is equivalent in terms of data movement to a matrix transpose, the simplest nontrivial transpose to perform. Also remember that for two-dimensional matrices both kinds of transposition are the same, and APL's rule holds in BQN. @@ -80,7 +80,7 @@ In particular, the case with only one argument specified is interesting. Here, t ≢ 2 ⍉ a23456 # Restrict Transpose to the first three axes ⟨ 3 4 2 5 6 ⟩ -Finally, it's worth noting that, as monadic Transpose moves the first axis to the end, it's equivalent to dyadic Transpose with a "default" left argument: `(≠∘≢-1˜)⊸⍉`. +Finally, it's worth noting that, as monadic Transpose moves the first axis to the end, it's equivalent to dyadic Transpose with a "default" left argument: `(=-1˜)⊸⍉`. ## Definitions @@ -88,6 +88,6 @@ Here we define the two valences of Transpose more precisely. A non-array right argument to Transpose is always enclosed to get a scalar array before doing anything else. -Monadic transpose is identical to `(≠∘≢-1˜)⊸⍉`, except that for scalar arguments it returns the array unchanged rather than giving an error. +Monadic transpose is identical to `(=-1˜)⊸⍉`, except that for scalar arguments it returns the array unchanged rather than giving an error. -In Dyadic transpose, the left argument is a number or numeric array of rank 1 or less, and `𝕨≤○≠≢𝕩`. Define the result rank `r←(≠≢𝕩)-+´¬∊𝕨` to be the argument rank minus the number of duplicate entries in the left argument. We require `∧´𝕨<r`. Bring `𝕨` to full length by appending the missing indices: `𝕨∾↩𝕨(¬∘∊˜/⊢)↕r`. Now the result shape is defined to be `⌊´¨𝕨⊔≢𝕩`. Element `i⊑z` of the result `z` is element `(𝕨⊏i)⊑𝕩` of the argument. +In Dyadic transpose, the left argument is a number or numeric array of rank 1 or less, and `𝕨≤○≠≢𝕩`. Define the result rank `r←(=𝕩)-+´¬∊𝕨` to be the argument rank minus the number of duplicate entries in the left argument. We require `∧´𝕨<r`. Bring `𝕨` to full length by appending the missing indices: `𝕨∾↩𝕨(¬∘∊˜/⊢)↕r`. Now the result shape is defined to be `⌊´¨𝕨⊔≢𝕩`. Element `i⊑z` of the result `z` is element `(𝕨⊏i)⊑𝕩` of the argument. diff --git a/docs/doc/depth.html b/docs/doc/depth.html index e141585c..cd025527 100644 --- a/docs/doc/depth.html +++ b/docs/doc/depth.html @@ -9,7 +9,7 @@ <span class='Function'>≡</span> <span class='String'>"a string is a list of characters"</span> 1 </pre> -<p>Depth is somewhat analogous to an array's rank <code><span class='Function'>≠≢</span><span class='Value'>𝕩</span></code>, and in fact rank can be "converted" to depth by splitting rows with <code><span class='Function'><</span><span class='Modifier2'>⎉</span><span class='Number'>1</span></code>, reducing the rank by 1 and increasing the depth. Unlike rank, Depth doesn't care at all about its argument's shape:</p> +<p>Depth is somewhat analogous to an array's rank <code><span class='Function'>=</span><span class='Value'>𝕩</span></code>, and in fact rank can be "converted" to depth by splitting rows with <code><span class='Function'><</span><span class='Modifier2'>⎉</span><span class='Number'>1</span></code>, reducing the rank by 1 and increasing the depth. Unlike rank, Depth doesn't care at all about its argument's shape:</p> <pre> <span class='Function'>≡</span> <span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>4</span><span class='Function'>⥊</span><span class='String'>"characters"</span> 1 <span class='Function'>≡</span> <span class='Paren'>(</span><span class='Number'>1</span><span class='Function'>+↕</span><span class='Number'>10</span><span class='Paren'>)</span><span class='Function'>⥊</span><span class='String'>"characters"</span> diff --git a/docs/doc/transpose.html b/docs/doc/transpose.html index 2020a520..3b5af23b 100644 --- a/docs/doc/transpose.html +++ b/docs/doc/transpose.html @@ -53,7 +53,7 @@ <span class='Bracket'>⟨</span> <span class='Number'>2</span> <span class='Number'>6</span> <span class='Number'>3</span> <span class='Number'>4</span> <span class='Number'>5</span> <span class='Bracket'>⟩</span> </pre> <p>Using these forms, we can state BQN's generalized matrix product swapping rule:</p> -<pre><span class='Value'>a</span> <span class='Function'>MP</span> <span class='Value'>b</span> <span class='Gets'>←→</span> <span class='Function'>⍉</span><span class='Modifier2'>⍟</span><span class='Paren'>(</span><span class='Function'>≠≢</span><span class='Value'>a</span><span class='Paren'>)</span> <span class='Value'>a</span> <span class='Function'>⍉</span><span class='Modifier'>⁼</span><span class='Modifier2'>⊸</span><span class='Function'>MP</span><span class='Modifier2'>⟜</span><span class='Function'>⍉</span> <span class='Value'>b</span> +<pre><span class='Value'>a</span> <span class='Function'>MP</span> <span class='Value'>b</span> <span class='Gets'>←→</span> <span class='Function'>⍉</span><span class='Modifier2'>⍟</span><span class='Paren'>(</span><span class='Function'>=</span><span class='Value'>a</span><span class='Paren'>)</span> <span class='Value'>a</span> <span class='Function'>⍉</span><span class='Modifier'>⁼</span><span class='Modifier2'>⊸</span><span class='Function'>MP</span><span class='Modifier2'>⟜</span><span class='Function'>⍉</span> <span class='Value'>b</span> </pre> <p>Certainly not as concise as APL's version, but not a horror either. BQN's rule is actually more parsimonious in that it only performs the axis exchanges necessary for the computation: it moves the two axes that will be paired with the matrix product into place before the product, and directly exchanges all axes afterwards. Each of these steps is equivalent in terms of data movement to a matrix transpose, the simplest nontrivial transpose to perform. Also remember that for two-dimensional matrices both kinds of transposition are the same, and APL's rule holds in BQN.</p> <p>Axis permutations of the types we've shown generate the complete permutation group on any number of axes, so you could produce any transposition you want with the right sequence of monadic transpositions with Rank. However, this can be unintuitive and tedious. What if you want to transpose the first three axes, leaving the rest alone? With monadic Transpose you have to send some axes to the end, then bring them back to the beginning. For example [following four or five failed tries]:</p> @@ -80,10 +80,10 @@ <pre> <span class='Function'>≢</span> <span class='Number'>2</span> <span class='Function'>⍉</span> <span class='Value'>a23456</span> <span class='Comment'># Restrict Transpose to the first three axes </span><span class='Bracket'>⟨</span> <span class='Number'>3</span> <span class='Number'>4</span> <span class='Number'>2</span> <span class='Number'>5</span> <span class='Number'>6</span> <span class='Bracket'>⟩</span> </pre> -<p>Finally, it's worth noting that, as monadic Transpose moves the first axis to the end, it's equivalent to dyadic Transpose with a "default" left argument: <code><span class='Paren'>(</span><span class='Function'>≠</span><span class='Modifier2'>∘</span><span class='Function'>≢-</span><span class='Number'>1</span><span class='Modifier'>˜</span><span class='Paren'>)</span><span class='Modifier2'>⊸</span><span class='Function'>⍉</span></code>.</p> +<p>Finally, it's worth noting that, as monadic Transpose moves the first axis to the end, it's equivalent to dyadic Transpose with a "default" left argument: <code><span class='Paren'>(</span><span class='Function'>=-</span><span class='Number'>1</span><span class='Modifier'>˜</span><span class='Paren'>)</span><span class='Modifier2'>⊸</span><span class='Function'>⍉</span></code>.</p> <h2 id="definitions">Definitions</h2> <p>Here we define the two valences of Transpose more precisely.</p> <p>A non-array right argument to Transpose is always enclosed to get a scalar array before doing anything else.</p> -<p>Monadic transpose is identical to <code><span class='Paren'>(</span><span class='Function'>≠</span><span class='Modifier2'>∘</span><span class='Function'>≢-</span><span class='Number'>1</span><span class='Modifier'>˜</span><span class='Paren'>)</span><span class='Modifier2'>⊸</span><span class='Function'>⍉</span></code>, except that for scalar arguments it returns the array unchanged rather than giving an error.</p> -<p>In Dyadic transpose, the left argument is a number or numeric array of rank 1 or less, and <code><span class='Value'>𝕨</span><span class='Function'>≤</span><span class='Modifier2'>○</span><span class='Function'>≠≢</span><span class='Value'>𝕩</span></code>. Define the result rank <code><span class='Value'>r</span><span class='Gets'>←</span><span class='Paren'>(</span><span class='Function'>≠≢</span><span class='Value'>𝕩</span><span class='Paren'>)</span><span class='Function'>-+</span><span class='Modifier'>´</span><span class='Function'>¬∊</span><span class='Value'>𝕨</span></code> to be the argument rank minus the number of duplicate entries in the left argument. We require <code><span class='Function'>∧</span><span class='Modifier'>´</span><span class='Value'>𝕨</span><span class='Function'><</span><span class='Value'>r</span></code>. Bring <code><span class='Value'>𝕨</span></code> to full length by appending the missing indices: <code><span class='Value'>𝕨</span><span class='Function'>∾</span><span class='Gets'>↩</span><span class='Value'>𝕨</span><span class='Paren'>(</span><span class='Function'>¬</span><span class='Modifier2'>∘</span><span class='Function'>∊</span><span class='Modifier'>˜</span><span class='Function'>/⊢</span><span class='Paren'>)</span><span class='Function'>↕</span><span class='Value'>r</span></code>. Now the result shape is defined to be <code><span class='Function'>⌊</span><span class='Modifier'>´¨</span><span class='Value'>𝕨</span><span class='Function'>⊔≢</span><span class='Value'>𝕩</span></code>. Element <code><span class='Value'>i</span><span class='Function'>⊑</span><span class='Value'>z</span></code> of the result <code><span class='Value'>z</span></code> is element <code><span class='Paren'>(</span><span class='Value'>𝕨</span><span class='Function'>⊏</span><span class='Value'>i</span><span class='Paren'>)</span><span class='Function'>⊑</span><span class='Value'>𝕩</span></code> of the argument.</p> +<p>Monadic transpose is identical to <code><span class='Paren'>(</span><span class='Function'>=-</span><span class='Number'>1</span><span class='Modifier'>˜</span><span class='Paren'>)</span><span class='Modifier2'>⊸</span><span class='Function'>⍉</span></code>, except that for scalar arguments it returns the array unchanged rather than giving an error.</p> +<p>In Dyadic transpose, the left argument is a number or numeric array of rank 1 or less, and <code><span class='Value'>𝕨</span><span class='Function'>≤</span><span class='Modifier2'>○</span><span class='Function'>≠≢</span><span class='Value'>𝕩</span></code>. Define the result rank <code><span class='Value'>r</span><span class='Gets'>←</span><span class='Paren'>(</span><span class='Function'>=</span><span class='Value'>𝕩</span><span class='Paren'>)</span><span class='Function'>-+</span><span class='Modifier'>´</span><span class='Function'>¬∊</span><span class='Value'>𝕨</span></code> to be the argument rank minus the number of duplicate entries in the left argument. We require <code><span class='Function'>∧</span><span class='Modifier'>´</span><span class='Value'>𝕨</span><span class='Function'><</span><span class='Value'>r</span></code>. Bring <code><span class='Value'>𝕨</span></code> to full length by appending the missing indices: <code><span class='Value'>𝕨</span><span class='Function'>∾</span><span class='Gets'>↩</span><span class='Value'>𝕨</span><span class='Paren'>(</span><span class='Function'>¬</span><span class='Modifier2'>∘</span><span class='Function'>∊</span><span class='Modifier'>˜</span><span class='Function'>/⊢</span><span class='Paren'>)</span><span class='Function'>↕</span><span class='Value'>r</span></code>. Now the result shape is defined to be <code><span class='Function'>⌊</span><span class='Modifier'>´¨</span><span class='Value'>𝕨</span><span class='Function'>⊔≢</span><span class='Value'>𝕩</span></code>. Element <code><span class='Value'>i</span><span class='Function'>⊑</span><span class='Value'>z</span></code> of the result <code><span class='Value'>z</span></code> is element <code><span class='Paren'>(</span><span class='Value'>𝕨</span><span class='Function'>⊏</span><span class='Value'>i</span><span class='Paren'>)</span><span class='Function'>⊑</span><span class='Value'>𝕩</span></code> of the argument.</p> diff --git a/docs/index.html b/docs/index.html index f57273e5..57e708ba 100644 --- a/docs/index.html +++ b/docs/index.html @@ -209,7 +209,7 @@ </tr> <tr> <td><code><span class='Function'>=</span></code></td> -<td></td> +<td>Rank</td> <td><a href="https://aplwiki.com/wiki/Equal_to">Equals</a></td> </tr> <tr> @@ -33,10 +33,10 @@ _depthOp_←{ _onAxes_←{ F←𝔽 (𝔾<≡)∘⊣◶{ # One axis - ! 1≤≠≢𝕩 + ! 1≤=𝕩 𝕨F𝕩 }‿{ # Multiple axes - ! 1≥≠≢𝕨 + ! 1≥=𝕨 ! 𝕨≤○≠≢𝕩 R←{(⊑𝕨)F(1↓𝕨)⊸R˘𝕩}⍟{0<≠𝕨} 𝕨R𝕩 @@ -45,7 +45,7 @@ _onAxes_←{ Windows←{ ! IsArray 𝕩 - ! 1≥≠≢𝕨 + ! 1≥=𝕨 ! 𝕨≤○≠≢𝕩 ! ∧´Nat¨⥊𝕨 s←(≠𝕨)↑≢𝕩 @@ -69,8 +69,8 @@ Join←{ s←≢¨𝕩 d←≠⊑s ! ∧´⥊d=≠¨s - ! d≥≠≢𝕩 - l←(≢𝕩){(𝕩⊑⟜≢a⊑˜(j=𝕩)⊸×)¨↕𝕨}¨j←↕r←≠≢a←𝕩 + ! d≥=𝕩 + l←(≢𝕩){(𝕩⊑⟜≢a⊑˜(j=𝕩)⊸×)¨↕𝕨}¨j←↕r←=a←𝕩 ! (r↑¨s)≡C l i←C{p←+´¨↑𝕩⋄(↕⊑⌽p)-𝕩/¯1↓p}¨l >i<¨⊸⊏¨l/𝕩 @@ -79,20 +79,20 @@ Join←{ ∾ ↩ Join ⊘ ∾ # Searching -IndexOf←(1<⌈○(≠≢))◶⊐‿{ - c←1-˜≠≢𝕨 +IndexOf←(1<⌈○=)◶⊐‿{ + c←1-˜=𝕨 ! 0≤c 𝕨 (0<≠𝕨)◶⟨0⎉c∘⊢,((+´<˘)∧`)≢⎉c⎉c‿∞⟩ 𝕩 } UniqueMask←{ - ! 1≤≠≢𝕩 + ! 1≤=𝕩 u←0↑𝕩 {(≠u)>⊑u IndexOf 𝕩}◶{u↩u∾𝕩⋄1}‿0˘𝕩 } Find←{ - r←≠s←≢𝕨 - ! r≤≠≢𝕩 - 𝕨 ≡⎉r s ↕⎉r 𝕩 + r←=𝕨 + ! r≤=𝕩 + 𝕨 ≡⎉r (≢𝕨) ↕⎉r 𝕩 } ⊐ ← !∘0 ⊘ IndexOf @@ -101,16 +101,16 @@ Find←{ ReorderAxes←{ 𝕩↩<⍟(0=≡)𝕩 - ! 1≥≠≢𝕨 + ! 1≥=𝕨 𝕨↩⥊𝕨 ! 𝕨≤○≠≢𝕩 ! ∧´Nat¨⥊𝕨 - r←(≠≢𝕩)-+´¬∊𝕨 + r←(=𝕩)-+´¬∊𝕨 ! ∧´𝕨<r 𝕨↩𝕨∾𝕨(¬∘∊˜/⊢)↕r (𝕨⊸⊏⊑𝕩˜)¨↕⌊´¨𝕨⊔≢𝕩 } -Transpose←(≠∘≢-1˜)⊸ReorderAxes⍟(0<≠∘≢) +Transpose←(=-1˜)⊸ReorderAxes⍟(0<=) ⍉ ← Transpose ⊘ ReorderAxes # Sorting @@ -119,8 +119,8 @@ Cmp ← ∨○IsArray◶{ # No arrays }‿{ # At least one array e←𝕨-˜○(0∨´0=≢)𝕩 𝕨(e=0)◶e‿{ - c←𝕨×∘-○(IsArray+≠∘≢)𝕩 - s←≢𝕨 ⋄ t←≢𝕩 ⋄ r←s⌊○≠t + c←𝕨×∘-○(IsArray+=)𝕩 + s←≢𝕨 ⋄ t←≢𝕩 ⋄ r←𝕨⌊○=𝕩 l←s{i←+´∧`𝕨=𝕩⋄m←1×´i↑𝕨⋄{c↩×-´𝕩⋄m↩m×⌊´𝕩}∘(⊑¨⟜𝕨‿𝕩)⍟(r⊸>)i⋄m}○(r↑⌽)t a←⥊𝕨⋄b←⥊𝕩 Trav←(=⟜l)◶{Trav∘(1+𝕩)⍟(0⊸=)a Cmp○(𝕩⊸⊑)b}‿c @@ -129,7 +129,7 @@ Cmp ← ∨○IsArray◶{ # No arrays } _bins←{ - c←1-˜≠≢𝕨 + c←1-˜=𝕨 ! 0≤c LE←𝔽⎉c≤0˜ ! (0<≠)◶⟨1,∧´·LE´˘2↕<˘⟩𝕨 @@ -147,7 +147,7 @@ ProgressiveIndexOf ← {𝕨⊐○(≍˘⟜OccurrenceCount𝕨⊸⊐)𝕩} X←Raw←{≤4} { chrs←⟨ - "!∾↕⌽⍉⍋⍒⊐⊒∊⍷" + "!=∾↕⌽⍉⍋⍒⊐⊒∊⍷" "" "⚇" ⟩ @@ -176,6 +176,7 @@ X←Raw←{≤4} ⍎"Type ← ⟨⟩⥊0⊸⥊" '!' Mod "{𝕩 ⋄ ≤1}⍟¬" + '=' Mod "≠∘≢ ⊘ =" Mod⟜⥊¨ "↕∾⌽⊐⍋⍒" @@ -457,7 +457,7 @@ Fmt ← { p ↩ 0⌾(¯1⊸⊑) p Pad ← {i←/1+𝕨 ⋄ (¯1¨⌾((¬∊i)⊸/)i) ⊏ 𝕩∾(¯1⊑≢𝕩)⥊" "} p (⊑0∊ls)◶⟨Pad,+´⊸↑⟩ ((×´ls)∾¯1⊑≢𝕩) ⥊ 𝕩 - }⍟(2 < ≠∘≢) + }⍟(2 < =) # Horizontal padding: just some spaces on either side PadH ← { (𝕨/" ") (∾⎉1∾⎉1⊣) 𝕩 @@ -473,7 +473,7 @@ Fmt ← { (1∾-l)↑"┘" ⟩ } - FmtEmpty ← (0‿0≢≢)◶("┌┐"≍"└┘")‿(((2≠≠∘≢)∨0=≠)◶{ + FmtEmpty ← (0‿0≢≢)◶("┌┐"≍"└┘")‿(((2≠=)∨0=≠)◶{ '┐'⌾(0‿¯1⊸⊑) 2 Enframe 1 PadH " "¨𝕩 }‿{ ≍"⟨⟩"∾˜(1<≠)◶⟨"",'⥊'⌾(¯1⊸⊑)·∾·∾⟜"‿"¨⍕¨⟩≢𝕩 @@ -482,13 +482,13 @@ Fmt ← { s ← ≢¨ 𝕩 w ← ⌈´⥊<⎉1 1⊑¨s h ← ⌈´⎉1 ⊑¨s - ∾⎉2 ≍⍟(0⌈2-≠∘≢) (h ∾⌜ 𝕨×w¬(-𝕨×≠w)↑1) ↑¨ 𝕩 + ∾⎉2 ≍⍟(0⌈2-=) (h ∾⌜ 𝕨×w¬(-𝕨×≠w)↑1) ↑¨ 𝕩 } FmtMixed ← { - (≠≢𝕩) Enframe 2 Pad 𝕨 PaddingJoin F¨𝕩 + (=𝕩) Enframe 2 Pad 𝕨 PaddingJoin F¨𝕩 } F ← (2⌊≡)◶(≍≤⟜∞◶⟨"'"⊸(∾∾⊣),⍕⟩)‿{ - num ← 𝕩≤∞ ⋄ r ← ≠≢𝕩 + num ← 𝕩≤∞ ⋄ r ← =𝕩 ((≠(0⊸<+≤)+´)⥊num)◶{ # All characters k ← -≠ c ← ¯1↓≢𝕩 diff --git a/spec/reference.bqn b/spec/reference.bqn index bba39aef..5d5424d8 100644 --- a/spec/reference.bqn +++ b/spec/reference.bqn @@ -23,7 +23,7 @@ ÷ # Reciprocal Divide ⋆ # Exponential Power ⌊ # Floor -= # Equals += # Rank Equals ≤ # Less Than or Equal to # Other basic functionality that we need to assume @@ -77,13 +77,13 @@ _eachm←{ E 0 ⋄ (≢𝕩)⥊r } _reduce←{ - ! 1=≠≢𝕩 + ! 1==𝕩 l←≠v←𝕩 ⋄ F←𝔽 r←𝕨 (0<l)◶{𝕩⋄Identity f}‿{l↩l-1⋄l⊑𝕩}⊘⊣ 𝕩 {r↩(𝕩⊑v)F r}¨(l-1)⊸-¨↕l r } -Length ← (0<0⊑≢)◶⟨1⋄0⊑⊢⟩∘≢ +Length ← (0<=)◶⟨1⋄0⊑≢⟩ #⌜ @@ -110,7 +110,7 @@ _eachd←{ a←⥊𝕨 ⋄ b←⥊𝕩 q⥊⥊(≠a) (⊑⟜a𝔽l⊸×⊸+⊑b˜)_table○↕ l } - (>○(≠≢))◶⟨𝔽_e⋄𝔽˜_e˜⟩ + (>○=)◶⟨𝔽_e⋄𝔽˜_e˜⟩ } _perv←{ # Pervasion (⊢⊘∨○IsArray)◶⟨𝔽⋄𝔽{𝕨𝔽_perv𝕩}¨⟩ @@ -129,7 +129,7 @@ Nat←IsArray◶⟨0⊸≤∧⌊⊸=,0⟩ Deshape←IsArray◶{⟨𝕩⟩}‿⥊ Reshape←{ - ! 1≥≠≢𝕨 + ! 1≥=𝕨 𝕨↩⥊𝕨 ! ∧´Nat¨𝕨 n←≠𝕩 ⋄ l←×´𝕨 @@ -139,12 +139,12 @@ Reshape←{ Range←{ I←{!Nat𝕩⋄↕𝕩} - M←{!1=≠≢𝕩⋄(<⟨⟩)⥊⊸∾⌜´I¨𝕩} + M←{!1==𝕩⋄(<⟨⟩)⥊⊸∾⌜´I¨𝕩} IsArray◶I‿M 𝕩 } Pick1←{ - ! 1=≠≢𝕨 + ! 1==𝕨 ! 𝕨=○≠s←≢𝕩 ! ∧´Int¨𝕨 ! ∧´𝕨(≥⟜-∧<)s @@ -157,7 +157,7 @@ Pick←IsArray◶⥊‿⊢⊸Pickd match←{¬∘(0⊑𝕨)◶(1⊑𝕨)‿𝕩}´⟨ ⟨≠○IsArray , 0⟩ ⟨¬IsArray∘⊢, =⟩ - ⟨≠○(≠≢) , 0⟩ + ⟨≠○= , 0⟩ ⟨∨´≠○≢ , 0⟩ {∧´⥊𝕨Match¨𝕩} ⟩ @@ -203,7 +203,7 @@ _depthOp_←{ 𝕨 n _d 𝕩 } _rankOp_←{ - k←𝕨(Pair○(≠≢) (0≤⊢)◶⟨⌊⟜-,0⌈-⟩¨ 𝔾_ranks)𝕩 + k←𝕨(Pair○= (0≤⊢)◶⟨⌊⟜-,0⌈-⟩¨ 𝔾_ranks)𝕩 Enc←{ f←⊑⟜(≢𝕩)¨↕𝕨 c←×´s←𝕨Cell𝕩 @@ -213,7 +213,7 @@ _rankOp_←{ } _scan←{ ! IsArray 𝕩 - ! 1≤≠≢𝕩 + ! 1≤=𝕩 F←𝔽 (0<≠∘⥊)◶⊢‿{ r←⥊𝕩 ⋄ l←≠𝕩 ⋄ c←×´1 Cell 𝕩 @@ -245,10 +245,10 @@ _iterate_←{ _onAxes_←{ F←𝔽 (𝔾<≡)∘⊣◶{ # One axis - ! 1≤≠≢𝕩 + ! 1≤=𝕩 𝕨F𝕩 }‿{ # Multiple axes - ! 1≥≠≢𝕨 + ! 1≥=𝕨 ! 𝕨≤○≠≢𝕩 R←{(⊑𝕨)F(1 DropV 𝕨)⊸R˘𝕩}⍟{0<≠𝕨} 𝕨R𝕩 @@ -288,12 +288,12 @@ Drop←{ s←(≠𝕨)(⊣↑⊢∾˜1⥊˜0⌈-⟜≠)≢𝕩 ((sׯ1⋆𝕨>0)+(-s)⌈s⌊𝕨)↑𝕩 } -Prefixes ← {!1≤≠≢𝕩 ⋄ (↕1+≠𝕩)Take¨<𝕩} -Suffixes ← {!1≤≠≢𝕩 ⋄ (↕1+≠𝕩)Drop¨<𝕩} +Prefixes ← {!1≤=𝕩 ⋄ (↕1+≠𝕩)Take¨<𝕩} +Suffixes ← {!1≤=𝕩 ⋄ (↕1+≠𝕩)Drop¨<𝕩} Windows←{ ! IsArray 𝕩 - ! 1≥≠≢𝕨 + ! 1≥=𝕨 ! 𝕨≤○≠≢𝕩 ! ∧´Nat¨⥊𝕨 s←(≠𝕨)↑≢𝕩 @@ -301,16 +301,16 @@ Windows←{ 𝕨{(∾⟜(𝕨≠⊸↓≢𝕩)∘≢⥊>)<¨⊸⊏⟜𝕩¨s(¬+⌜○↕⊢)⥊𝕨}⍟(0<≠𝕨)𝕩 } -Reverse ← {!1≤≠≢𝕩 ⋄ (-↕⊸¬≠𝕩)⊏𝕩} +Reverse ← {!1≤=𝕩 ⋄ (-↕⊸¬≠𝕩)⊏𝕩} Rotate ← {!Int𝕨 ⋄ l←≠𝕩⋄(l|𝕨+↕l)⊏𝕩} _onAxes_ 0 Indices←{ - ! 1=≠≢𝕩 + ! 1==𝕩 ! ∧´Nat¨𝕩 ⟨⟩∾´𝕩⥊¨↕≠𝕩 } Rep ← Indices⊸⊏ -Replicate ← {0<≠≢𝕨}◶(⥊˜⟜≠Rep⊢)‿{!𝕨=○≠𝕩⋄𝕨Rep𝕩} _onAxes_ (1-0=≠) +Replicate ← {0<=𝕨}◶(⥊˜⟜≠Rep⊢)‿{!𝕨=○≠𝕩⋄𝕨Rep𝕩} _onAxes_ (1-0=≠) #⌜ @@ -334,8 +334,8 @@ Join←{ s←≢¨𝕩 d←≠⊑s ! ∧´⥊d=≠¨s - ! d≥≠≢𝕩 - l←(≢𝕩){(𝕩⊑⟜≢a⊑˜(j=𝕩)⊸×)¨↕𝕨}¨j←↕r←≠≢a←𝕩 + ! d≥=𝕩 + l←(≢𝕩){(𝕩⊑⟜≢a⊑˜(j=𝕩)⊸×)¨↕𝕨}¨j←↕r←=a←𝕩 ! (r↑¨s)≡C l i←C{p←+´¨↑𝕩⋄(↕⊑⌽p)-𝕩/¯1↓p}¨l >i<¨⊸⊏¨l/𝕩 @@ -343,8 +343,8 @@ Join←{ Group←{ ! IsArray 𝕩 - Chk←{!1=≠≢𝕩⋄!∧´Int¨𝕩⋄!∧´¯1≤𝕩⋄≠𝕩} - l←(1<≡)◶Chk‿{!1=≠≢𝕩⋄Chk¨𝕩}𝕨 + Chk←{!1==𝕩⋄!∧´Int¨𝕩⋄!∧´¯1≤𝕩⋄≠𝕩} + l←(1<≡)◶Chk‿{!1==𝕩⋄Chk¨𝕩}𝕨 ! l≤○≠≢𝕩 ! ∧´l=l≠⊸↑≢𝕩 (𝕨⊸=/𝕩˜)¨↕1+¯1⌈´⚇1𝕨 @@ -352,33 +352,33 @@ Group←{ # Searching IndexOf←{ - c←1-˜≠≢𝕨 + c←1-˜=𝕨 ! 0≤c 𝕨 (0<≠𝕨)◶⟨0⎉c∘⊢,((+´<˘)∧`)≢⎉c⎉c‿∞⟩ 𝕩 } UniqueMask←{ - ! 1≤≠≢𝕩 + ! 1≤=𝕩 u←0↑𝕩 {⊑𝕩∊u}⊘{u↩u∾𝕩⋄1}‿0˘𝕩 } Find←{ - r←≠s←≢𝕨 - ! r≤≠≢𝕩 - 𝕨 ≡⎉r s ↕⎉r 𝕩 + r←=𝕨 + ! r≤=𝕩 + 𝕨 ≡⎉r (≢𝕨) ↕⎉r 𝕩 } ReorderAxes←{ 𝕩↩<⍟(0=≡)𝕩 - ! 1≥≠≢𝕨 + ! 1≥=𝕨 𝕨↩⥊𝕨 ! 𝕨≤○≠≢𝕩 ! ∧´Nat¨⥊𝕨 - r←(≠≢𝕩)-+´¬∊𝕨 + r←(=𝕩)-+´¬∊𝕨 ! ∧´𝕨<r 𝕨↩𝕨∾𝕨(¬∘∊˜/⊢)↕r (𝕨⊸⊏⊑𝕩˜)¨↕⌊´¨𝕨⊔≢𝕩 } -Transpose←(≠∘≢-1˜)⊸ReorderAxes⍟(0<≠∘≢) +Transpose←(=-1˜)⊸ReorderAxes⍟(0<=) # Sorting Cmp ← ∨○IsArray◶{ # No arrays @@ -386,8 +386,8 @@ Cmp ← ∨○IsArray◶{ # No arrays }‿{ # At least one array e←𝕨-˜○(∨´0=≢)𝕩 𝕨(e=0)◶e‿{ - c←𝕨×∘-○(IsArray+≠∘≢)𝕩 - s←≢𝕨 ⋄ t←≢𝕩 ⋄ r←s⌊○≠t + c←𝕨×∘-○(IsArray+=)𝕩 + s←≢𝕨 ⋄ t←≢𝕩 ⋄ r←𝕨⌊○=𝕩 l←s{i←+´∧`𝕨=𝕩⋄m←×´i↑𝕨⋄{c↩×-´𝕩⋄m↩m×⌊´𝕩}∘(⊑¨⟜𝕨‿𝕩)⍟(r⊸>)i⋄m}○(r↑⌽)t a←⥊𝕨⋄b←⥊𝕩 Trav←(=⟜l)◶{Trav∘(1+𝕩)⍟(0⊸=)a Cmp○(𝕩⊸⊑)b}‿c @@ -396,11 +396,11 @@ Cmp ← ∨○IsArray◶{ # No arrays } _grade←{ - ! 1≤≠≢𝕩 + ! 1≤=𝕩 i⊐˜+´˘(𝔽⎉∞‿¯1⎉¯1‿∞˜𝕩)(⌈⟜0+=⟜0⊸×)>⌜˜i←↕≠𝕩 } _bins←{ - c←1-˜≠≢𝕨 + c←1-˜=𝕨 ! 0≤c LE←𝔽⎉c≤0˜ ! (0<≠)◶⟨1,∧´·LE´˘2↕<˘⟩𝕨 diff --git a/test/testref.bqn b/test/testref.bqn index d6217106..62b40719 100644 --- a/test/testref.bqn +++ b/test/testref.bqn @@ -187,7 +187,7 @@ (≍˘˜⥊˘1‿5‿9)≡⌽⎉2⊸+⥊⟜(↕×´)3‿2‿1 (↕4)(×⌜≡×⎉0‿2)↕5 (↕4)(⋆˜⌜˜≡⋆⎉∞‿¯4)↕5 - (⟨2⟩⊸∾⍟(2‿2⥊0‿1‿1‿1)2‿3)≡≢¨≍⎉(⌊○(≠≢))⌜˜⟨↕3,2‿3⥊↕6⟩ + (⟨2⟩⊸∾⍟(2‿2⥊0‿1‿1‿1)2‿3)≡≢¨≍⎉(⌊○=)⌜˜⟨↕3,2‿3⥊↕6⟩ (2=⌜○↕3)≡(2‿4⥊"abc")≡⎉1(2‿3‿4⥊"abc") ⟨0,0⟩≡(2‿4⥊"abc")≡⎉¯1(2‿3‿4⥊"abc") ⟨5,⟨15,1⟩⟩≡+´⚇1⟨⟨3,2⟩,⟨⟨4,5,6⟩,⟨1⟩⟩⟩ |
