aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2020-09-01 11:29:12 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2020-09-01 11:29:12 -0400
commitd620ce201b4e59265cf645cf4649da1462d05d79 (patch)
tree47bc3766b2d05180dc4b4905c5099c6b3d8fa4d2 /src
parent5cc52e4c3ec1a727014afcbac2a4e925e37c9d33 (diff)
Support more inverses: ¬⊢⊣∾≍↑↓↕⌽⊔
Diffstat (limited to 'src')
-rw-r--r--src/r.bqn34
1 files changed, 30 insertions, 4 deletions
diff --git a/src/r.bqn b/src/r.bqn
index de302385..21db791e 100644
--- a/src/r.bqn
+++ b/src/r.bqn
@@ -463,6 +463,22 @@ ProgressiveIndexOf ← {𝕨⊐○(≍˘⟜OccurrenceCount𝕨⊸⊐)𝕩}
◶ ↩ {𝕨((𝕨𝔽𝕩)⊑𝕘){𝔽}𝕩} # Same definition, new Pick
IA ← "Inverse failed"⊸!
+IX ← "Inverse does not exist"⊸!
+_invChk_ ← {i←𝕨𝔽𝕩⋄IX 𝕩≡𝕨𝔾i⋄i}
+GroupIndsInv ← {
+ IA 1==𝕩
+ j←∾𝕩
+ IA∧´Nat⌜j
+ g←GroupLen j
+ IX∧´g≤1
+ o←/¬g
+ (⍋j∾o)⊏(/≠¨𝕩)∾¯1¨o
+}
+GroupInv ← {
+ IA 1==𝕨
+ IA ∧´Nat⌜𝕨
+ (⊔𝕨) ⍋⊸⊏○∾ 𝕩
+}
inverse ← {(⊑(0⊏𝕩)⊐<) ⊑ ((1⊏𝕩)∾⟨"Inverse not found"!0˜⟩)˜} ⍉ (2∾˜2÷˜≠)⊸⥊ ⟨
+, +⊘(-˜)
-, -
@@ -470,11 +486,21 @@ inverse ← {(⊑(0⊏𝕩)⊐<) ⊑ ((1⊏𝕩)∾⟨"Inverse not found"!0˜⟩
÷, ÷
⋆, Log _perv
√, ⋆⟜2⊘(⋆˜)
- ∧, ⊢⊘(÷˜)
- ∨, ⊢⊘(-˜÷1-⊢)
- <, {IA IsArray𝕩⋄IA 0==𝕩⋄⊑𝕩}⊘(IA∘0)
+ ∧, ⊢_invChk_∧⊘(÷˜)
+ ∨, ⊢_invChk_∨⊘(-˜÷1-⊢)
+ ¬, ¬
+ <, {IX IsArray𝕩⋄IX 0==𝕩⋄⊑𝕩}⊘(IA∘0)
+ ⊢, ⊢
+ ⊣, ⊢⊘(⊢⊣IX∘≡)
+ ∾, IA∘0 ⊘ {d←𝕩-○=𝕨⋄IX(0⊸≤∧≤⟜1)d⋄l←d◶1‿≠𝕨⋄IX l≤≠𝕩⋄IX 𝕨≡d◶⟨⊏,l⊸↑⟩𝕩⋄l↓𝕩}
+ ≍, {IX 1=≠𝕩⋄⊏𝕩} ⊘ {IX 2=≠𝕩⋄IX 𝕨≡⊏𝕩⋄1⊏𝕩}
+ ↑, ¯1⊸⊑_invChk_↑ ⊘ (IA∘0)
+ ↓, ⊑_invChk_↓ ⊘ (IA∘0)
+ ↕, ≢_invChk_↕ ⊘ (IA∘0) # Should trace edge and invChk
+ ⌽, ⌽ ⊘ (-⊸⌽)
⍉, TransposeInv ⊘ ReorderAxesInv
- /, {IA 1==𝕩⋄IA∧´Nat⌜𝕩⋄IA(∧´¯1⊸↓≤1⊸↓)𝕩⋄GroupLen𝕩}⊘(IA∘0)
+ /, {IA 1==𝕩⋄IA∧´Nat⌜𝕩⋄IX(∧´¯1⊸↓≤1⊸↓)𝕩⋄GroupLen𝕩}⊘(IA∘0)
+ ⊔, GroupIndsInv ⊘ GroupInv
⁼ ← {Inverse 𝕗}