aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2020-09-01 11:48:57 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2020-09-01 11:48:57 -0400
commitc23d80bb6081e83e06bd5f269ecc8596aff0de0e (patch)
treed4c243fa887d337b5a1bef89b13837d654ac7ec6 /src
parentd620ce201b4e59265cf645cf4649da1462d05d79 (diff)
Fix ∧∨ identity issue by defining sorting before pervasion
Diffstat (limited to 'src')
-rw-r--r--src/r.bqn51
1 files changed, 26 insertions, 25 deletions
diff --git a/src/r.bqn b/src/r.bqn
index 21db791e..5f0dbc74 100644
--- a/src/r.bqn
+++ b/src/r.bqn
@@ -15,7 +15,8 @@ Int←IsArray◶⟨⌊⊸=,0⟩
Nat←IsArray◶⟨0⊸≤×⌊⊸=,0⟩
# LIMITED to numeric arguments for scalar cases
-< ← {⟨⟩⥊⟨𝕩⟩} ⊘ (1-≤˜)
+≥ ← ≤˜
+< ← {⟨⟩⥊⟨𝕩⟩} ⊘ (1-≥)
> ← (1-≤)
⌊ ↩ ⌊ ⊘ (>⊑{𝕨‿𝕩})
⌈ ← -∘⌊∘- ⊘ (<⊑{𝕨‿𝕩})
@@ -56,7 +57,7 @@ _perv←{ # Pervasion
+○IsArray◶⟨𝔽⋄R⌜⊘(>○IsArray◶{𝕨{𝕗R𝕩}⌜𝕩}‿{𝕩{𝕩R𝕗}⌜𝕨})⋄R _eachd⟩
}
-Cmp0 ← ≤˜-≤
+Cmp0 ← ≥-≤
Cmp1 ← (0<1×´≢∘⊢)◶⟨1, IsArray∘⊢◶(1-2×≤)‿{𝕨Cmp1𝕩}⟜(0⊑⥊)⟩
Cmp ← +○IsArray◶⟨
Cmp0
@@ -158,26 +159,45 @@ Depth←IsArray◶0‿{1+0(⊣-≤×-)´Depth⌜⥊𝕩}
≡ ← Depth ⊘ Match
≢ ↩ IsArray◶⟨⟩‿≢ ⊘ (1-Match)
+˘ ← {𝔽 _rankOp_ ¯1}
+_onAxes_←{
+ F←𝔽
+ (𝔾<≡)∘⊣◶{ # One axis
+ "First-axis function right argument must have rank at least 1" ! 1≤=𝕩
+ 𝕨F𝕩
+ }‿{ # Multiple axes
+ "Left argument must have rank at most 1" ! 1≥=𝕨
+ "Left argument length must be at most right argument rank" ! 𝕨≤○≠≢𝕩
+ l←≠𝕨 ⋄ W←⊑⟜(⥊𝕨)
+ 0{(W𝕨)F(1+𝕨)⊸𝕊˘⍟(𝕨<l-1)𝕩}⍟(0<l)𝕩
+ }
+}
+
+Select←ToArray⊸(SelSub _onAxes_ 1)
+⊏ ← 0⊸Select ⊘ Select
+
Merge←{
c←≢0⊑⥊𝕩
"Elements in Merge argument must have matching shapes" ! 1×´(c≡≢)⌜⥊𝕩
𝕩⊑⟜Deshape˜⌜c⥊↕1×´c
}⍟(0<≠∘⥊)⍟IsArray
+_sort ← {(𝕗⊑⟨Cmp,Cmp˜⟩)_grade_𝕗 ⊸ Select}
+
÷ ↩ ÷ _perv
⋆ ↩ ⋆ _perv
√ ← ⋆⟜(÷2) ⊘ (⋆⟜÷˜)
| ← (0⊸≤◶-‿⊢ ⊘ {𝕩-𝕨×⌊𝕩÷𝕨}) _perv
⌊ ↩ (⌊ ⊘ {(𝕨>𝕩)⊑𝕨‿𝕩}) _perv
⌈ ↩ (-∘⌊∘- ⊘ {(𝕨<𝕩)⊑𝕨‿𝕩}) _perv
-∧ ← × _perv
-∨ ← (+-×) _perv
+∧ ← 0 _sort ⊘ (× _perv)
+∨ ← 1 _sort ⊘ ((+-×) _perv)
× ↩ (0⊸(<->) ⊘ ×) _perv
-< ↩ {⟨⟩⥊⟨𝕩⟩} ⊘ ((1-≤˜) _perv)
+< ↩ {⟨⟩⥊⟨𝕩⟩} ⊘ ((1-≥) _perv)
> ↩ Merge ⊘ ((1-≤) _perv)
≠ ↩ ≠ ⊘ ((1-=) _perv)
= ↩ = ⊘ (= _perv)
-≥ ← ("No monadic form: ≥"!0˜) ⊘ (≤˜_perv)
+≥ ← ("No monadic form: ≥"!0˜) ⊘ (≥ _perv)
≤ ↩ ("No monadic form: ≤"!0˜) ⊘ (≤ _perv)
+ ↩ + _perv
- ↩ - _perv
@@ -228,7 +248,6 @@ _rankOp_←{
> ((0⊑k)Enc𝕨) 𝔽¨ ((1-˜≠)⊸⊑k)Enc𝕩
}
⎉ ← _rankOp_
-˘ ← {𝔽⎉¯1}
_insert←{
"Insert argument must have rank at least 1" ! 1≤=𝕩
𝕨 𝔽´ <˘𝕩
@@ -236,22 +255,6 @@ _insert←{
˝ ← _insert
-_onAxes_←{
- F←𝔽
- (𝔾<≡)∘⊣◶{ # One axis
- "First-axis function right argument must have rank at least 1" ! 1≤=𝕩
- 𝕨F𝕩
- }‿{ # Multiple axes
- "Left argument must have rank at most 1" ! 1≥=𝕨
- "Left argument length must be at most right argument rank" ! 𝕨≤○≠≢𝕩
- l←≠𝕨 ⋄ W←⊑⟜(⥊𝕨)
- 0{(W𝕨)F(1+𝕨)⊸𝕊˘⍟(𝕨<l-1)𝕩}⍟(0<l)𝕩
- }
-}
-
-Select←ToArray⊸(SelSub _onAxes_ 1)
-⊏ ← 0⊸Select ⊘ Select
-
JoinTo←∨○(1<=)◶(∾○⥊)‿{
s←𝕨Pair○≢𝕩
a←1⌈´k←≠⌜s
@@ -517,6 +520,4 @@ _repeat_←{
⥊ ↩ Deshape ⊘ Reshape
⌜ ↩ {𝔽⌜○ToArray}
-∧ ↩ ⍋⊸⊏ ⊘ ∧
-∨ ↩ ⍒⊸⊏ ⊘ ∨
⌾ ← _under_