aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2020-07-01 19:09:08 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2020-07-01 19:09:08 -0400
commit35b312299a40ac6fc1725901e99b62239be2e5c9 (patch)
tree6bb99ae4c4870ac4aee235a18a6967c8145ad0eb /spec
parent01fe8ee5bbba4631b12290a6f50b5412b7aaf096 (diff)
Test layer 6 structural and search functions
Diffstat (limited to 'spec')
-rwxr-xr-xspec/dzref64
-rw-r--r--spec/reference.bqn46
2 files changed, 52 insertions, 58 deletions
diff --git a/spec/dzref b/spec/dzref
index 6034fa78..db98ef89 100755
--- a/spec/dzref
+++ b/spec/dzref
@@ -64,20 +64,7 @@ _perv←{ ⍝ Pervasion
Int←IsArray◶⟨⌊⊸=,0⟩
Nat←IsArray◶⟨0⊸≤∧⌊⊸=,0⟩
-Pick1←{
- ! 1=≠≢𝕨
- ! 𝕨=○≠s←≢𝕩
- ! ∧´Int¨𝕨
- ! ∧´𝕨(≥⟜-∧<)s
- 𝕨↩𝕨+s×𝕨<0
- (⥊𝕩)⊑˜0(⊑⟜𝕨+⊑⟜s×⊢)´-↕⊸¬≠𝕨
-}
-Pickd←(0∨´⟜⥊IsArray¨∘⊣)◶Pick1‿{Pickd⟜𝕩¨𝕨}
-Pick←IsArray◶⥊‿⊢⊸Pickd
-
Depth←IsArray◶0‿{1+0⌈´Depth¨⥊𝕩}
-
-⊑ ↩ (0¨∘≢)⊸Pick ⊘ Pick
≡ ← Depth ⊘ ≡
@@ -223,11 +210,11 @@ Join←{
C←(<⟨⟩)⥊⊸∾⌜´⊢ ⍝ Cartesian array product
! IsArray 𝕩
s←≢¨𝕩
- c←≠⊑s
- ! ∧´c=≠¨s
- ! c≥≠≢𝕩
- l←(≢𝕩){(𝕩⊑a⊑˜(j=𝕩)⊸×)¨↕𝕨}¨j←↕≠≢a←𝕩
- ! s≡C l
+ d←≠⊑s
+ ! ∧´⥊d=≠¨s
+ ! d≥≠≢𝕩
+ l←(≢𝕩){(𝕩⊑⟜≢a⊑˜(j=𝕩)⊸×)¨↕𝕨}¨j←↕r←≠≢a←𝕩
+ ! (r↑¨s)≡C l
i←C{p←+´¨↑𝕩⋄(↕⊑⌽p)-𝕩/¯1↓p}¨l
>i<¨⊸⊏¨l/𝕩
}⍟(0<≠∘⥊)
@@ -238,43 +225,47 @@ Group←{
l←(1<≡)◶Chk‿{!1=≠≢𝕩⋄Chk¨𝕩}𝕨
! l≤○≠≢𝕩
! ∧´l=l≠⊸↑≢𝕩
- (𝕨⊸=/𝕩˜)¨↕1+0⌈´⚇1𝕨
+ (𝕨⊸=/𝕩˜)¨↕1+¯1⌈´⚇1𝕨
}
-ReorderAxes←{
- 𝕩↩<⍟(0=≡)𝕩
- ! 𝕨≤○≠≢𝕩
- r←(≠≢𝕩)-+´¬∊𝕨
- ! ∧´𝕨<r
- 𝕨↩𝕨∾𝕨(¬∘∊˜/⊢)↕r
- (𝕨⊸⊏⊑𝕩˜)¨↕1×´¨𝕨⊔≢𝕩
-}
-Transpose←(≠∘≢-1˜)⊸ReorderAxes⍟(0<≠∘≢)
-
∾ ↩ Join ⊘ JoinTo
-⊔ ← ⊔⟜(↕∘≠⚇1) ⊘ Group
-⍉ ← Transpose ⊘ ReorderAxes
+⊔ ← Group⟜(↕≠⚇1) ⊘ Group
⍝ Searching
IndexOf←{
c←1-˜≠≢𝕨
! 0≤c
- 𝕨 (0<≠𝕨)◶⟨0⎉c∘⊢,((+´<˘)∧`)≢⎉c⎉∞‿c⟩ 𝕩
+ 𝕨 (0<≠𝕨)◶⟨0⎉c∘⊢,((+´<˘)∧`)≢⎉c⎉c‿∞⟩ 𝕩
}
UniqueMask←{
! 1≤≠≢𝕩
u←0↑𝕩
- {𝕩∊u}⊘{u↩u∾𝕩⋄1}‿0˘𝕩
+ {(≠u)>⊑u IndexOf 𝕩}◶{u↩u∾𝕩⋄1}‿0˘𝕩
}
Find←{
r←≠s←≢𝕨
- 𝕨≡⎉r s↕⎉r 𝕩
+ ! r≤≠≢𝕩
+ 𝕨 ≡⎉r s ↕⎉r 𝕩
}
⊐ ← !∘0 ⊘ IndexOf
∊ ← UniqueMask ⊘ (⊐˜<≠∘⊢)
⍷ ← ∊⊸/ ⊘ Find
+ReorderAxes←{
+ 𝕩↩<⍟(0=≡)𝕩
+ ! 1≥≠≢𝕨
+ 𝕨↩⥊𝕨
+ ! 𝕨≤○≠≢𝕩
+ ! ∧´Nat¨⥊𝕨
+ r←(≠≢𝕩)-+´¬∊𝕨
+ ! ∧´𝕨<r
+ 𝕨↩𝕨∾𝕨(¬∘∊˜/⊢)↕r
+ (𝕨⊸⊏⊑𝕩˜)¨↕⌊´¨𝕨⊔≢𝕩
+}
+Transpose←(≠∘≢-1˜)⊸ReorderAxes⍟(0<≠∘≢)
+⍉ ← Transpose ⊘ ReorderAxes
+
⍝ Sorting
Cmp ← ∨○IsArray◶{ ⍝ No arrays
𝕨(>-<)𝕩 ⍝ Assume they're numbers
@@ -292,7 +283,7 @@ Cmp ← ∨○IsArray◶{ ⍝ No arrays
_grade←{
! 1≤≠≢𝕩
- i⊐+´˘(𝔽⎉∞‿¯1⎉¯1‿∞˜𝕩)(⌈⟜0+=⟜0⊸×)>⌜˜i←↕≠𝕩
+ i⊐˜+´˘(𝔽⎉∞‿¯1⎉¯1‿∞˜𝕩)(⌈⟜0+=⟜0⊸×)>⌜˜i←↕≠𝕩
}
_bins←{
r←1-˜≠≢𝕨
@@ -314,7 +305,7 @@ ProgressiveIndexOf ← {𝕨⊐○(≍˘⟜OccurrenceCount𝕨⊸⊐)𝕩}
{
chrs←⟨
- "!√∧∨|≡∾↑↓↕⌽⍉/⍋⍒⊏⊑⊐⊒∊⍷⊔"
+ "!√∧∨|≡∾↑↓↕⌽⍉/⍋⍒⊏⊐⊒∊⍷⊔"
"˘¨⌜´`"
"⎉⚇⍟◶"
@@ -345,7 +336,6 @@ ProgressiveIndexOf ← {𝕨⊐○(≍˘⟜OccurrenceCount𝕨⊸⊐)𝕩}
⍎"Type ← ⟨⟩⥊0⊸⥊"
'!' Mod "{𝕩 ⋄ ≤1}⍟¬"
- '⊑' Mod "⊑"
'↕' Mod "↕"
'≡' Mod "≡"
diff --git a/spec/reference.bqn b/spec/reference.bqn
index 9c82cda1..241be28a 100644
--- a/spec/reference.bqn
+++ b/spec/reference.bqn
@@ -317,7 +317,7 @@ Replicate ← {0<≠≢𝕨}◶(⥊˜⟜≠Rep⊢)‿{!𝕨=○≠𝕩⋄𝕨Rep
⍝ LAYER 6: Everything else
∾ ↩ Join ⊘ JoinTo
-⊔ ← ⊔⟜(↕∘≠⚇1) ⊘ Group
+⊔ ← ⊔⟜(↕≠⚇1) ⊘ Group
⍉ ← Transpose ⊘ ReorderAxes
⊐ ← !∘0 ⊘ IndexOf
∊ ← UniqueMask ⊘ (⊐˜<≠∘⊢)
@@ -332,11 +332,11 @@ Join←{
C←(<⟨⟩)⥊⊸∾⌜´⊢ ⍝ Cartesian array product
! IsArray 𝕩
s←≢¨𝕩
- c←≠⊑s
- ! ∧´c=≠¨s
- ! c≥≠≢𝕩
- l←(≢𝕩){(𝕩⊑a⊑˜(j=𝕩)⊸×)¨↕𝕨}¨j←↕≠≢a←𝕩
- ! s≡C l
+ d←≠⊑s
+ ! ∧´⥊d=≠¨s
+ ! d≥≠≢𝕩
+ l←(≢𝕩){(𝕩⊑⟜≢a⊑˜(j=𝕩)⊸×)¨↕𝕨}¨j←↕r←≠≢a←𝕩
+ ! (r↑¨s)≡C l
i←C{p←+´¨↑𝕩⋄(↕⊑⌽p)-𝕩/¯1↓p}¨l
>i<¨⊸⊏¨l/𝕩
}⍟(0<≠∘⥊)
@@ -347,35 +347,39 @@ Group←{
l←(1<≡)◶Chk‿{!1=≠≢𝕩⋄Chk¨𝕩}𝕨
! l≤○≠≢𝕩
! ∧´l=l≠⊸↑≢𝕩
- (𝕨⊸=/𝕩˜)¨↕1+0⌈´⚇1𝕨
+ (𝕨⊸=/𝕩˜)¨↕1+¯1⌈´⚇1𝕨
}
-ReorderAxes←{
- 𝕩↩<⍟(0=≡)𝕩
- ! 𝕨≤○≠≢𝕩
- r←(≠≢𝕩)-+´¬∊𝕨
- ! ∧´𝕨<r
- 𝕨↩𝕨∾𝕨(¬∘∊˜/⊢)↕r
- (𝕨⊸⊏⊑𝕩˜)¨↕×´¨𝕨⊔≢𝕩
-}
-Transpose←(≠∘≢-1˜)⊸ReorderAxes⍟(0<≠∘≢)
-
⍝ Searching
IndexOf←{
c←1-˜≠≢𝕨
! 0≤c
- 𝕨 (0<≠𝕨)◶⟨0⎉c∘⊢,((+´<˘)∧`)≢⎉c⎉∞‿c⟩ 𝕩
+ 𝕨 (0<≠𝕨)◶⟨0⎉c∘⊢,((+´<˘)∧`)≢⎉c⎉c‿∞⟩ 𝕩
}
UniqueMask←{
! 1≤≠≢𝕩
u←0↑𝕩
- {𝕩∊u}⊘{u↩u∾𝕩⋄1}‿0˘𝕩
+ {⊑𝕩∊u}⊘{u↩u∾𝕩⋄1}‿0˘𝕩
}
Find←{
r←≠s←≢𝕨
- 𝕨≡⎉r s↕⎉r 𝕩
+ ! r≤≠≢𝕩
+ 𝕨 ≡⎉r s ↕⎉r 𝕩
}
+ReorderAxes←{
+ 𝕩↩<⍟(0=≡)𝕩
+ ! 1≥≠≢𝕨
+ 𝕨↩⥊𝕨
+ ! 𝕨≤○≠≢𝕩
+ ! ∧´Nat¨⥊𝕨
+ r←(≠≢𝕩)-+´¬∊𝕨
+ ! ∧´𝕨<r
+ 𝕨↩𝕨∾𝕨(¬∘∊˜/⊢)↕r
+ (𝕨⊸⊏⊑𝕩˜)¨↕⌊´¨𝕨⊔≢𝕩
+}
+Transpose←(≠∘≢-1˜)⊸ReorderAxes⍟(0<≠∘≢)
+
⍝ Sorting
Cmp ← ∨○IsArray◶{ ⍝ No arrays
𝕨(>-<)𝕩 ⍝ Assume they're numbers
@@ -393,7 +397,7 @@ Cmp ← ∨○IsArray◶{ ⍝ No arrays
_grade←{
! 1≤≠≢𝕩
- i⊐+´˘(𝔽⎉∞‿¯1⎉¯1‿∞˜𝕩)(⌈⟜0+=⟜0⊸×)>⌜˜i←↕≠𝕩
+ i⊐˜+´˘(𝔽⎉∞‿¯1⎉¯1‿∞˜𝕩)(⌈⟜0+=⟜0⊸×)>⌜˜i←↕≠𝕩
}
_bins←{
r←1-˜≠≢𝕨