Skip to content

Latest commit

 

History

History
117 lines (85 loc) · 1.85 KB

VARIATIONS.md

File metadata and controls

117 lines (85 loc) · 1.85 KB

Take/Drop

Drop 6:

[}.\`7 x]

Take 7:

{. ([x] \`7 (irange 0 9))
 > {take ← λn.λxs. ⍳ 0 (n-1)⊂xs; take 7 (irange 0 9)}
Vec 7 [0, 1, 2, 3, 4, 5, 6]

Delete

Delete the ith element of vector xs:

 > ⍳ 0 9 \\ 4
Vec 9 [0, 1, 2, 3, 5, 6, 7, 8, 9]
 > {del ← λi.λxs. ((≠i)#.xsᶥ)⊂xs; del 4 (irange 0 9)}
Vec 9 [0, 1, 2, 3, 5, 6, 7, 8, 9]

Scatter

We can imitate scatter () with

λis.λxs. (xs˙)'is

Filter

One can replicate the functionality of filter (#.) with (indices-of) and

λp.λxs. p⩪xs⊂xs

Outer Product (Self)

[x(*)⊗x]
λxs. {x ⟜ ♯'xs; x%.|:x};
λxs. {x ⟜ ♯'xs; x%.♯xs};

Map, Rank

Map (') has type

(') : (a → b) → Vec i a → Vec i b

It cuts across the leading axis.

Sum Augmented Axis

 > (λa.λb. [(+)/ₒ x y]`{0,1∘[2]} a (b::M float)) ⟨1,2,3⟩ ⟨⟨4.0,5⟩,⟨6,7⟩,⟨8,9⟩⟩
Vec 3 [10.0, 15.0, 20.0]
 > (λa.λb. [(+)/x]`{1∘[2]} ((<|)`{0,1∘[2]} a (b::M float))) ⟨1,2,3⟩ ⟨⟨4.0,5⟩,⟨6,7⟩,⟨8,9⟩⟩
Vec 3 [10.0, 15.0, 20.0]

Infix, Convolve

 > [(+)/x%ℝ(:x)]\`7 (frange 0 9 10)
Vec 4 [3.0, 4.0, 5.0, 6.0]
 > [(+)/x%ℝ(:x)]⨳{7} (frange 0 9 10)
Vec 4 [3.0, 4.0, 5.0, 6.0]

Indices

[xᶥ]
([#t]⩪)
λxs. {n ← 𝓉xs; gen. (0,xs˙0) (λx. {i⟜x->1+1; (i,xs˙i)}) n}
λxs. {i ← (λx.λy. x+1) Λₒ (0::int) xs; [(x,y)]`({:i) xs}

Successive Application

 > (-)\~(irange 0 9)
Vec 9 [1, 1, 1, 1, 1, 1, 1, 1, 1]
 > [}.x-{.x]\`2 (irange 0 9)
Vec 9 [1, 1, 1, 1, 1, 1, 1, 1, 1]

Delete

 > {delete ← λxs.λi. ((≠i)#.xsᶥ)⊂xs; delete ⟨1::int,2,3,4⟩ 2}
Vec 3 [1, 2, 4]
 > {delete ← λxs.λi. (⍳ 0 (i-1)⊂xs)⧺(⍳ (i+1) (𝓉xs-1)⊂xs); delete ⟨1::int,2,3,4⟩ 2}
Vec 3 [1, 2, 4]