APL Notes: BQN Primitives

BQN Primitves

official docs. Also, bqncrate, which can be searched by primitive as well.
˜˘¨⁼⌜´˝ ∞¯•÷×  ¬⎉⚇⍟⊘⎊⍎⍕⟨⟩√⋆
⌽𝕨∊↑∧ ⊏⊐π←→   ↙𝕎⍷𝕣⍋  ⊑⊒⍳⊣⊢
⍉𝕤↕𝕗𝕘⊸∘○⟜⋄↩    ↖𝕊 𝔽𝔾« ⌾»·˙|
⥊𝕩↓∨⌊ ≡∾≍≠     ⋈𝕏 ⍒⌈ ≢≤≥⇐
 i+j Add         2 + 3‿1‿0‿5 → 5‿3‿2‿7 ⋄ 97‿'a' + @‿1 → "ab"
 i-j Subtract    2‿5 - 1‿9 → 1‿¯4 ⋄ "ab" - @‿1 → 97‿'a'
 i×j Multiply    1.5‿2‿0.5 × 2 → 3‿4‿1
 i÷j Divide      3‿4‿1 ÷ 2 → 1.5‿2‿0.5
 i⋆j Power       3 ⋆ 0‿1‿2 → 1‿3‿9
 i√j Root        4 √ 81 → 3
 i¬j Span        2024 ¬ 2015 → 10
  -j Negate      -6 → ¯6
  ×j Sign        × ∞‿¯2‿¯0‿0‿4 → 1‿¯1‿0‿0‿1
  ÷j Reciprocal  ÷ 0‿1‿2 → ∞‿1‿0.5
  ⋆j Exponential ⋆ 0‿1‿2 → 1‿2.718‿7.389
  √j Square_Root √ 0‿1‿2‿4 → 0‿1‿1.414‿2
 ⋆⁼j Logarithm   ⋆⁼ 10 → 2.302
i⋆⁼j Log_Base    2 ⋆⁼ 1024 → 10
  ⌊j Floor       ⌊ π → 3
  ⌈j Ceiling     ⌈ ¯0.6‿3‿3.01 → 0‿3‿4
  |j Abs         | ¯∞‿¯6‿0‿2 → ∞‿6‿0‿2
 i⌊j Minimum     3 ⌊ ↕8 → 0‿1‿2‿3‿3‿3‿3‿3
 i⌈j Maximum     3 ⌈ ↕8 → 3‿3‿3‿3‿4‿5‿6‿7
 i|j Modulus     3 | ↕8 → 0‿1‿2‿0‿1‿2‿0‿1
 x=y Equals      3‿4‿5‿6 = 5 → 0‿0‿1‿0
 x≠y Not_Equals  3‿4‿5‿6 ≠ 5 → 1‿1‿0‿1
 x≤y LessOrEqual 3‿4‿5‿6 ≤ 5 → 1‿1‿1‿0
 x<y Less_Than   3‿4‿5‿6 < 5 → 1‿1‿0‿0
 x≤y GreaterOrEq 3‿4‿5‿6 ≥ 5 → 0‿0‿1‿1
 x>y GreaterThan 3‿4‿5‿6 > 5 → 0‿0‿0‿1

  ∧x Sort_Up     ∧ "delta"‿"alpha" → "alpha"‿"delta"
  ∨x Sort_Down   ∨ "δαβγ" → "δγβα"
  ⍋x Grade_Up    ⍋ "pmsa" → 3‿1‿0‿2
  ⍒x Grade_Down  ⍒ "pmsa" → 2‿0‿1‿3
 x⍋y Bins_Up     60‿85‿100 ⍋ 101‿90‿0‿45‿80 → 3‿2‿0‿0‿1
 x⍒y Bins_Down   100‿85‿60 ⍒ 101‿90‿0‿45‿80 → 0‿1‿3‿3‿2

 a∧b And         (4<1) ∧ 4>3 → 0
 a∨b Or          (4<1) ∨ 4>3 → 1
  ¬a Not         ¬0‿1‿5 → 1‿0‿¯4

  <x Enclose     (<"abc") ∊ "abc"‿"def" → <1
  >x Merge       ≢>"ab"‿"cd" → 2‿2
  ≍x Solo        ≢≍2‿2⥊'x' → 1‿2‿2
 x≍y Couple      1≍2 → 1‿2 ⋄ "ab"≍1‿2 → >⟨'a'‿'b', 1‿2⟩
  ⥊x Deshape     ⥊↕2‿2 → ⟨0‿0, 0‿1, 1‿0, 1‿1⟩
 i⥊x Reshape     2‿2⥊"abcd" → >"ab"‿"cd"
  ∾x Join        ∾"words"‿","‿"words" → "words,words"
 x∾y Join_To     "abcd" ∾ "EFG" → "abcdEFG"
  ⋈x Enlist      ⋈ "enlist" → ⟨"enlist"⟩
 x⋈y Pair        "pa" ⋈ "ir" → ⟨"pa", "ir"⟩
 ⋈⁼x ?           ⋈⁼ ⟨"enlist"⟩ → "enlist"
 ≍⁼x ?           ≍⁼ "a" → <'a'

  ≢x Shape       ≢¨ ⟨"list", ⟨⟩, ↕2‿2⟩ → ⟨⟨4⟩, ⟨0⟩, ⟨2, 2⟩⟩
  ≡x Depth       ≡¨ ⟨"list", ⟨⟩, ↕2‿2⟩ → 1‿1‿2
  =x Rank        =¨ ⟨"list", ⟨⟩, ↕2‿2⟩ → 1‿1‿2
  ≠x Length      ≠¨ ⟨"list", ⟨⟩, ↕2‿2⟩ → 4‿0‿2

  ⊣x Identity    ⊣ 1 → 1
  ⊢x Identity    ⊢ 1 → 1
 x⊣y Left        'a' ⊣ 0 → 'a' ⋄ "123" ⊣⌾(1⊸⊑) "abc" → "a2c"
 x⊢y Right       'a' ⊢ 0 → 0

 x≡y Match       "abc" ≡ 'a'‿'b'‿'c' → 1
 x≢y Not_Match   4 ≢ <4 → 1

 i↑x Take        4 ↑ "take and drop" → "take"
 i↓x Drop        4 ↑ "take and drop" → " and drop"
  ↑x Prefixes    ↑ "abc" → ⟨⟨⟩, "a", "ab", "abc"⟩
  ↓x Suffixes    ↓ "abc" → ⟨"abc", "bc", "c", ⟨⟩⟩
 ↑⁼x ArePrefixes •Show¨⌾↑ "hello"
 ↓⁼x AreSuffixes ((1⊣↓⁼)⎊0) "ab"‿"b"‿⟨⟩ → 1

  ↕i Range       ↕ 3 → 0‿1‿2
 i↕x Windows     3 ↕ "hello" → >"hel"‿"ell"‿"llo"

  «x Nudge       « 1‿2‿3 → 2‿3‿0
  »x Nudge_Back  » 1‿2‿3 → 0‿1‿2
 x«y ShiftBefore "end" « "add to the " → " to the end"
 x»y Shift_After "then " » "add to the " → "then add to"
  ⌽x Reverse     ⌽ "abc" → "cba"
 i⌽x Rotate      2 ⌽ "hello" → "llohe"
  ⍉x Transpose   ≢ ⍉ ↕1‿2‿3‿4 → 2‿3‿4‿1
 i⍉x ReorderAxes

  /i Indices     /'l' = "hello world" → 2‿3‿9
 /⁼i             /⁼ 7‿7 ∾ ↕4 → 1‿1‿1‿1‿0‿0‿0‿2

  ⊏x First_Cell  ⊏ "hi" → <'h' ⋄ ⊏ "abc"≍"def" → "abc"
 i⊏x Select      2‿1‿1‿5 ⊏ "select" → "leet"
  ⊑x First       ⊑ "hi" → 'h' ⋄ ⊑ "abc"≍"def" → 'a'
 i⊑x Pick        2‿0 ⊑ ↕4‿5 → 2‿0

  ⊐x Classify    ⊐ "apple apl" → 0‿1‿1‿2‿3‿4‿0‿1‿2
 x⊐y Index_Of    "apl" ⊐ "apple" → 0‿1‿1‿2‿3
  ∊x Mark_Firsts ∊ "apple apl" → 1‿1‿0‿1‿1‿1‿0‿0‿0
 x∊y Member_Of   10‿1‿¯1‿5 ∊ ↕10 → 0‿1‿0‿1
  ⍷x Deduplicate ⍷ "apple" → "aple"
 x⍷y Find        "xx" ⍷ "xxbdxxxcx" → 1‿0‿0‿0‿1‿1‿0‿0
  ⊒x Occurrence_Count ⊒ "apple apl" → 0‿0‿1‿0‿0‿0‿1‿2‿1
 x⊒y Progressive_Index_Of "apl" ⊒ "apple apl" → 0‿1‿3‿2‿3‿3‿3‿3‿3

  ⊔x Group_Indices ⊔ 0‿0‿1‿0‿1 → ⟨0‿1‿3, 2‿4⟩
 x⊔y Groups      0‿0‿1‿0‿1 ⊔ "apple" → "apl"‿"pe"

  !x Assert      !1 ⋄ !"anything else"
 c!x Assert_With_Message "Message" ! 0

◶ - choose

   {+´1‿2×0=3‿5|𝕩}◶{•Show 𝕩}‿{𝕤⋄•Out "Fizz"}‿{𝕤⋄•Out "Buzz"}‿{𝕤⋄•Out "FizzBuzz"}¨ 1+↕15
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz

⊔ - group indices / group

   # string splitting, 0 = first group, 1 = second group, -1 = omitted
   ' ' = "hello world"
⟨ 0 0 0 0 0 1 0 0 0 0 0 ⟩
   ∨`' ' = "hello world"
⟨ 0 0 0 0 0 1 1 1 1 1 1 ⟩
   (∨`' ' = "hello world") - 2×' '="hello world"
⟨ 0 0 0 0 0 ¯1 1 1 1 1 1 ⟩
   {mask←' '=𝕩 ⋄ ((∨`mask)-2×mask)⊔𝕩} "hello world"
⟨ "hello" "world" ⟩

   # groups don't have to be boolean
   (↕5) ⊔ "hello"
⟨ "h" "e" "l" "l" "o" ⟩
   (⌽↕5) ⊔ "hello"
⟨ "o" "l" "l" "e" "h" ⟩
   # groups do need to be ¯1⊸⌈
   (¯1⌈¯3+⌽↕5) ⊔ "hello"
⟨ "e" "h" ⟩
   # groups don't have to be contiguous
   0‿¯1‿¯1‿4‿4 ⊔ "hello"
⟨ "h" ⟨⟩ ⟨⟩ ⟨⟩ "lo" ⟩