Minimal Set
While TinyAPL is "tiny" in many ways, it is definitely not tiny in the amount of primitives it has. It might be interesting to find out what the minimal set of primitives is, i.e. the ones that can't be implemneted in terms of other primitives.
Aliases
Some of the primitives are pretty much simple applications of other primitives:
∡
Arctangent is∡⍤⊕⍨
ᑣ
Boxed is⊂⍤F
⊕
Cartesian is+∘(0ᴊ1∘×)
⌈
Ceiling is-⍤⌊⍤-
¨
Each isFᑣᑒ◠
ᐵ
Each Left isF¨∘⊂
ᑈ
Each Right is⊂⍛(F¨)
⊇
From is⌷⍨∘⊃⍨⍤0‿∞
,
Laminate is⍪⍥∧
⊇
Last is⊃⍤⊖⍤,
↓
Major Cells is⊂⍤¯1
↑
Mix is⊃⍤0
⍲
Nand is~⍤∧
⍱
Nor is~⍤∨
~
Not is1∘-
◡
On Cells isF⍤¯1
ᑒ
On Contents isF⍥⊃
◠
On Scalars isF⍤0
⌓
On Simple Scalars isF⍥0
⊗
Polar is×∘(0ᴊ1∘×⍛*)
ϼ
Rank is≠⍤⍴
⍪
Join is⊃⍤(⍪¨⍆)
√
Root is*∘÷⍨
⊵
Sort Down is⍒⍨
⊴
Sort Up is⍋⍨
⍬
Empty Vector is⟨⟩
∻
Empty Dictionary is⟨:⟩
⍮
Pair and⍮
Singleton are both,⍥⊂
Default argument
Some primitives' monadic case is related to the corresponding dyad by either binding an argument or using a hook.
⍟
Natural Logarithm is(*1)∘⍟
-
Negate is0∘-
⊕
Pure Imaginary is0∘⊕
÷
Reciprocal is1∘÷
√
Square Root is2∘√
⊗
Unit Polar is1∘⊗
⋷
Histogram is(⍳⍤≢)⊸⋷
Combinators
All combinators can be rewritten using trains, as described in Combinators ↔ Trains.
⊢
Right is{⍵}
⊣
Left is{⍵}⁖{⍺}
⍤
Atop is⦅F⋄G⦆
⍥
Over is⦅F⍤⊣⋄G⋄F⍤⊢⦆
⍨
Constant is⦅n⦆
⍨
Commute and⍨
Duplicate are⦅⊢⋄F⋄⊣⦆
⊸
Left Hook is⦅F⍤⊣⋄G⋄⊢⦆
⟜
Right Hook is⦅⊣⋄F⋄G⍤⊢⦆
⇾
Left Fork is⦅F⋄G⋄⊢⦆
⇽
Right Fork is⦅⊣⋄F⋄G⦆
⸚
Mirror is⦅G⍨⋄F⋄G⦆
«»
Fork is⦅F⋄G⋄H⦆
∘
After is⦅F⋄G⦆⁖⦅⊣⋄F⋄G⍤⊢⦆
⍛
Before is⦅G⋄F⦆⁖⦅F⍤⊣⋄G⋄⊢⦆
Promote, Demote, Rerank
∧
Promote is {⍵⍴⍨1⍪⍴⍵}
.
∨
Demote is
{ 0=ϼ⍵: ■⍵
⋄ 1=ϼ⍵: ■⊃⍵
⋄ ⍵⍴⍨(×⍆2↑⍴⍵)⍪2↓⍴⍵ }
ϼ
Rerank is
{ ⍺=ϼ⍵: ■⍵
⋄ ⍺>ϼ⍵: ■⍺ ∇ ∧⍵
⋄ ⍺ ∇ ∨⍵ }
Set operations
∪
Unique is≠⊸⌿
∪
Union is{⍺⍪⍵⌿⍨~⍵∊⍺}
∩
Intersection is{⍺⌿⍨⍺∊⍵}
~
Difference is{⍺⌿⍨~⍺∊⍵}
§
Symmetric Difference is∪«~»∩
Comparisons
All comparisons can be reconstructed from just =
Equal To and ≤
Less Than or Equal To.
≠
Not Equal To is~⍤=
<
Less Than is≤«∧»≠
>
Greater Than is~⍤≤
≥
Greater Than or Equal To is~⍤<
Similarly, TAO comparisons can be reconstructed from ≡
Identical and ⊴
Precedes Or Identical.
≢
Not Identical is~⍤≡
⊲
Precedes is⊴«∧»≢
⊳
Succeeds is~⍤⊴
⊴
Precedes Or Identical is~⍤⊲
But TAO comparisons can be reconstructed from grading:
≡
Identical is⦅⍋⋄=ᑒ⋄⍒⦆⍤⍮
⊴
Precedes Or Identical is⦅⍋⋄≤ᑒ⋄⍒⦆⍤⍮
Min/max are also easy:
Floor and Round
⌊
Floor is "complex floor":
{ RealFloor←1∘|⊸-
⋄ x←1|ℜ⍵
⋄ y←1|ℑ⍵
⋄ p←(ℜ⍵)⊕⍥RealFloorℑ⍵
⋄ 1>x+y: ■p
⋄ x≥y: ■p+1
⋄ p+0ᴊ1 }
⸠
Round is componentwise round: ⦅ℜ⋄⊕⍥(⌊⍤+∘0.5)⋄ℑ⦆
Reduce
Reductions are special cases of folds where the initial value is the first/last cell of the array.
⍆
Reduce is_{(⊃↓⍵)⍶⍶⍆(1↓↓⍵)}
⍅
Reduce Back is_{(⊇↓⍵)⍶⍶⍆(¯1↓⍵)}
Remainder, GCD and LCM
|
Remainder is{ ⍺=0: ■⍵ ⋄ ⍵-⍺×⌊⍵÷⍺ }⌓
∨
Greatest Common Divisor is{ 0=⍺|⍵: ⍺ ⋄ ⍵ ∇⍨ ⍺|⍵ }⌓
∧
Least Common Multiple is׫÷»∨
Inner Product and Table
∙
Inner Product isF⍤(G◠◡)⍤1‿∞
⊞
Table isF◠⍤0‿∞
Tally and Depth
≢
Tally is ⦅⊃⋄0⋄⍪⍨⋄⍴⦆
≡
Depth is
{ (0≡ϼ⍵)∧⍵≡⊂⍵: ■0
⋄ 0≡ϼ⍵: ■1+∇⊃⍵
⋄ 0∊⍴⍵:■1
⋄ 1+⌈⍆∇ᑒ¨,⍵ }
Repeat and Until
Monadic ⍣
Repeat is _{ 0=⍵⍵: ■⍵ ⋄ ⍶⍶ _∇_ (⍵⍵-1) ⍶⍶ ⍵ }_
; dyadic is an application of ∘
Bind.
Similarly, monadic ⍣
Until is _{(⍶⍶ ⍵) ⍶⍶ _{ ⍺ ⍹⍹ ⍵: ■⍺ ⋄ (⍶⍶ ⍺) ⍶⍶ _∇_ ⍹⍹ ⍺ }_ ⍹⍹ ⍵}_
; dyadic as above.