aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2020-12-13 16:19:10 -0500
committerMarshall Lochbaum <mwlochbaum@gmail.com>2020-12-14 10:15:40 -0500
commita6963e79122a0e54ba91cad3514e0df62f236633 (patch)
treecd2bb819aea33b9ed7d77a5d160e2062772f0564 /src
parent05bf5980f8e7e5bcf74676370fbabefa203ee5c4 (diff)
Support undoing compound functions
Diffstat (limited to 'src')
-rw-r--r--src/r.bqn94
1 files changed, 74 insertions, 20 deletions
diff --git a/src/r.bqn b/src/r.bqn
index dc727069..bc17f5d5 100644
--- a/src/r.bqn
+++ b/src/r.bqn
@@ -557,9 +557,29 @@ ProgressiveIndexOf ↠{ð•¨âŠâ—‹((≠∾2Ë™)⥊·â‰Ë˜âŸœOccurrenceCountð•¨âŠ
⊠↠FirstCell ⊘ (ToArray⊸(SelSub _onAxes_ 1))
⊑ ↩ (0⊑⥊) ⊘ Pick
â—¶ ↩ {ð•¨((ð•¨ð”½ð•©)⊑ð•˜){ð”½}ð•©} # Same definition, new Pick
+⼠↠{Inverse ð•—}
+
+_repeat_â†{
+ nâ†ð•¨ð”¾ð•©
+ lâ†uâ†0
+ {"âŸ: Repetition numbers in 𕨠must be integers"!Intð•©â‹„l↩l⌊ð•©â‹„u↩u⌈ð•©}⚇0 n
+ aâ†ð•©â‹„_pâ†{ð”½âˆ˜âŠ£`⟨a⟩∾↕0+ð•©}
+ posâ†(ð•¨ð”½ ⊢)_p u
+ negâ†(ð•¨ð”½â¼âŠ¢)_p-l
+ (|⊑<⟜0⊑pos‿neg˙)⚇0 n
+}
+
+ReshapeT ↠⟨∘,⌊,⌽,↑⟩⊑∘âŠ<
+
+⟠↩ _repeat_
+⥊ ↩ Deshape ⊘ Reshape
+⌾ ↠_under_
+⊒ ↠OccurrenceCount⊘ ProgressiveIndexOf
+ⷠ↠∊⊸/ ⊘ Find
IA ↠"â¼: Inverse failed"⊸!
IX ↠"â¼: Inverse does not exist"⊸!
+INF↠"â¼: Inverse not found"!0Ë™
_invChk_ ↠{iâ†ð•¨ð”½ð•©â‹„IX ð•©â‰¡ð•¨ð”¾iâ‹„i}
GroupIndsInv ↠{
IA 1==ð•©
@@ -575,7 +595,11 @@ GroupInv ↠{
IA ∧´Nat⌜ð•¨
(⊔ð•¨) â‹âЏâŠâ—‹âˆ¾ ð•©
}
-inverse ↠{(⊑(0âŠð•©)âŠ<) ⊑ ((1âŠð•©)∾⟨"â¼: Inverse not found"!0˜⟩)Ëœ} ≠(2∾˜2÷˜≠)⊸⥊ ⟨
+_lookup_ ↠{
+ s ↠2×↕(≠ð•˜)÷2
+ (⊑(sâŠð•˜)âŠ<) ⊑ (((1+s)âŠð•˜)∾⟨ð•—⟩)Ë™
+}
+PrimInverse ↠INF _lookup_ ⟨
+, +⊘(-˜)
-, -
×, ⊢⊘(÷˜)
@@ -598,23 +622,53 @@ inverse ↠{(⊑(0âŠð•©)âŠ<) ⊑ ((1âŠð•©)∾⟨"â¼: Inverse not found"!0
/, {IA 1==ð•©â‹„IA∧´Nat⌜ð•©â‹„IX(∧´¯1⊸↓≤1⊸↓)ð•©â‹„GroupLenð•©}⊘(IA∘0)
⊔, GroupIndsInv ⊘ GroupInv
⟩
-⼠↠{Inverse ð•—}
-
-_repeat_â†{
- nâ†ð•¨ð”¾ð•©
- lâ†uâ†0
- {"âŸ: Repetition numbers in 𕨠must be integers"!Intð•©â‹„l↩l⌊ð•©â‹„u↩u⌈ð•©}⚇0 n
- aâ†ð•©â‹„_pâ†{ð”½âˆ˜âŠ£`⟨a⟩∾↕0+ð•©}
- posâ†(ð•¨ð”½ ⊢)_p u
- negâ†(ð•¨ð”½â¼âŠ¢)_p-l
- (|⊑<⟜0⊑pos‿neg˙)⚇0 n
-}
-
-ReshapeT ↠⟨∘,⌊,⌽,↑⟩⊑∘âŠ<
-
-⟠↩ _repeat_
-⥊ ↩ Deshape ⊘ Reshape
⌜ ↩ {ð•¨ð”½âŒœâ—‹ToArrayð•©}
-⌾ ↠_under_
-⊒ ↠OccurrenceCount⊘ ProgressiveIndexOf
-ⷠ↠∊⊸/ ⊘ Find
+_inv_ ↠{ð•˜â‹„ð•¨ð”½ð•©}
+AtopInverse ↠{(ð•ð•Ž)⊘(ð•⟜ð•Ž)}â—‹{Inverseð•©}
+Mod1Inverse ↠INF˙ _lookup_ ⟨
+ ˜, INF _lookup_ ⟨
+ +, ÷⟜2⊘(-˜)
+ -, IA∘0⊘+
+ ×, √⊘(÷˜)
+ ÷, IA∘0⊘×
+ ⋆, IA∘0⊘√
+ √, IA∘0⊘(÷Log)
+ ∧, √⊘(÷˜)
+ ∨, (¬√∘¬)⊘(-˜÷1-⊣)
+ ¬, IA∘0⊘(+-1˙)
+ ⟩
+ ¨, {ð•â¼Â¨ ⊣·IA 0<≡∘⊢}
+ ⌜, {ð•â¼âŒœâŠ˜(IA∘0)⊣·IA 0<≡∘⊢}
+ ˘, {ð•â¼Ë˜ ⊣·IA 0<=∘⊢}
+ `, {(âŠâˆ¾Â¯1⊸↓ð•â¼Â¨1⊸↓)âŸ(1<≠)⊘(IA∘0)}
+⟩ {
+ 0⊸⊑ {ð•ð•¨}⟜𔽠1⊸⊑
+}
+IsConstant ↠(3≤Type)◶⟨1 â‹„ 4‿˙ ≡ 0‿¯1âŠDecompose⟩
+Mod2Inverse ↠INF˙ _lookup_ ⟨
+ _inv_, {ð•ŽâŠ¸âŠ¢ð•}
+ ∘, AtopInverse
+ â—‹, {Fiâ†ð•Žâ¼â‹„ð•â¼ Fi⊘(ð•⊸Fi)}
+ ⌾, {ð•Žâ¼âŒ¾ð•} # Need to verify for computation Under
+ âŸ, Int∘⊢◶⟨IA∘0Ë™,{ð•ŽâŸ(-ð•©)}⟩
+ ⊘, {(ð•Žâ¼)⊘(ð•â¼)}
+ ⊸, IsConstant∘⊣ ⊣◶{INF⊘ð•}‿⊢ {ð•ŽâЏ(ð•â¼)}
+ ⟜, IsConstant∘⊢◶⟨INFË™,{(ð•¨ð•Ëœâ¼âŠ¢)⊘(IA∘0)}⟩
+⟩ {
+ 0‿2⊸⊠{ð•´ð•¨}⟜𔽠1⊸⊑
+}
+TrainInverse ↠{
+ f‿g‿hâ†ð•©
+ Kâ†Â¬IsConstant⊸∧⟜((⊑⟨⊢⟩)⊸=)
+ f K◶⟨{ð•¨Gâ¼âŠ¢},K˜◶⟨{ð•©GËœâ¼âŠ¢},INF˙⟩⟩ h
+}
+FuncInverse ↠(⊑ ⊣◶⟨
+ PrimInverse∘⊑⊢ # 0 primitive
+ ("Cannot currently invert blocks"!0Ë™)Ë™ # 1 block
+ AtopInverse´⊢ # 2-train
+ TrainInverse # 3-train
+ Mod1Inverse # 4 1-modifier
+ Mod2Inverse # 5 2-modifier
+⟩ 1⊸↓) Decompose
+Inverse ↠Typeâ—¶(3‿1‿2/{⊢⊣ð•©IX∘≡⊢}‿FuncInverse‿("Cannot invert modifier"!0Ë™))
+⼠↩ {𕗠≠◶⊢‿{ð•©_inv_ð•¨} Inverse ð•—}