Skip to content

Commit 730942f

Browse files
committed
Update for new Uiua version
1 parent 533442d commit 730942f

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

lib.ua

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ Stdev ← √Var
2929
GaussEliminate‼ ↚ ∧(
3030
⊢⍖⊸⌵⍜⊙↙×0⟜⊡⤚⊸⊙⍉
3131
⍜⊏⇌ ⊃⊙⊙∘^0 ⊟⤙⊙⊙∘ ⊙(⊃⋅⊙∘^1 ⍤.≥ε⊸⌵) ⟜⊡
32-
⊸⍜⊡(÷⊸⊡:)⤙∘
33-
⍜(°⊂↻|𝄐⌞-˜⊸⊞×⊙(⊡⤚˜⊙⍉))⤙∘
32+
⊸⍜⊡(÷⊸⊡:)⊸:
33+
⍜(°⊂↻|𝄐⌞-˜⊸⊞×⊙(⊡⤚˜⊙⍉))⊸:
3434
)°⊏
3535

3636
# Matrix Determinant
@@ -77,11 +77,10 @@ Mpow ← ◌⍥⟜Mmp⊙(:⊞=.°⊏)
7777
⍤⤙≍ [¯8 5 ¯3 2 ¯1 1 0 1 1 2 3 5 8] ≡(⊢♭Mpow) ⍜-⇡¯7 6 ¤ [1_1 1_0]
7878
└─╴
7979

80-
QqpMask ↚ [
81-
1_2_3_4
82-
2_¯1_4_¯3
83-
3_¯4_¯1_2
84-
4_3_¯2_¯1]
80+
QqpMask ↚ [1_2_3_4
81+
2_¯1_4_¯3
82+
3_¯4_¯1_2
83+
4_3_¯2_¯1]
8584
# Quaternion product
8685
#
8786
# Computes PQ for quaternion arrays P and Q.
@@ -166,7 +165,8 @@ Gamma ← (
166165
¯2.7405717035683877e-8
167166
4.048694881756761e-9
168167
]
169-
/+÷⍜⊢⋅1≡+⊙¤⊙:)
168+
/+÷⍜⊢⋅1≡+⊙¤⊙:
169+
)
170170
××× √τ ⁿ¯⊙e ⤙ⁿ ⤙+ 8 # g
171171
)
172172

@@ -218,7 +218,7 @@ LCM ← ⌵÷⊃GCD×
218218
# ```
219219
Base ← ⌅(
220220
⍉◌∧⊃◿(⊂¤⌊÷)ⁿ⊙¤⇌⇡/↥♭+1⌊⊃ₙ⊙⊙[]
221-
| /+×ⁿ⊙¤⇡⧻⤙∘⊙°⍉)
221+
| /+×ⁿ⊙¤⇡◡⋅⧻⊙°⍉)
222222

223223
┌─╴test
224224
⍤⤙≍ [[2_2 1_0][3_1 1_1]] Base 5 [12_1 8_6]
@@ -229,24 +229,30 @@ Base ← ⌅(
229229

230230
# Inverse of N modulo M (M if nonexistent)
231231
# ? N M
232-
ModInv ← ⊗1◿:×⇡⤙∘
232+
ModInv ← ⊗1◿:×◡⋅⇡
233233
# Multiplicative order of N modulo M
234234
# ? N M
235-
ModOrd ← ⊡1⊚=1◿:ⁿ⇡⤙∘
235+
ModOrd ← ⊡1⊚=1◿:ⁿ◡⋅⇡
236236

237237
┌─╴test
238238
⍤⤙≍ 2 ModInv 4 7
239239
└─╴
240240

241241
# Binomial coefficient aka N choose K
242242
# ? K N
243+
# Deprecated! Use `⧅<` instead.
243244
Binom ← /×÷+1⟜-⇡
244245

245246
# Convert a number X to a continued fraction to N terms.
246247
#
247248
# Use `°CFrac` to convert to a number from a continued fraction.
248249
# ? N X
249-
CFrac ← ⌅([◌⍥⊃(÷⤚◿1)⌊]|⊃⧻/(+÷:1))
250+
CFrac ← ⌅(⍥⊃(÷⤚◿1)⌊|⊃⧻/(+÷:1)⇌)
251+
252+
┌─╴test
253+
⍤⤙≍ [3 7 15 1 292 1 1 1] CFrac 8 π
254+
⍤⤙≍ e ◌°CFrac CFrac 100 e
255+
└─╴
250256

251257
# Divisors of N (including 1 and N)
252258
# The values are in increasing order and distinct.
@@ -329,7 +335,7 @@ BinomCmf ← /+BinomPmf⊓∩¤(⇡+1)
329335
#
330336
# Probability of X failures before the first success of repeated trials with success probability p
331337
# ? p X
332-
GeomPmf ← טⁿ⤚¬
338+
GeomPmf ← טⁿ¬⟜:
333339
# Cumulative geometric distribution
334340
#
335341
# Probability of X or fewer failures before the first success of repeated trials with success probability p
@@ -360,18 +366,13 @@ NormalCdf ← ÷2+1Erf÷×√2⊙-
360366

361367
# -- Misc --
362368

363-
# Permutation indices of N items
364-
# Indices ? N
365-
# Deprecated! Use `⧅≠⟜⇡` instead.
366-
Perms ← ♭₂⍉∧(≡↻⇡⟜↯+1⟜⊂):¤¤°⊂⇡
367-
368369
# Po-Shen quadratic solver
369370
#
370371
# Returns roots as a list
371372
#
372373
# Outputs complex-typed numbers only if the roots are complex
373374
# ? A B C
374-
Quad ← ⍥R⌵↥0:⊟⊃-+⊙:√⟜±-:⤚°√ℂ0¯÷2∩⌞÷
375+
Quad ← ⍥R⌵↥:⊟⊃-+⊙:√⟜±˜-°√⟜:ℂ₀¯÷₂∩⌞÷
375376

376377
┌─╴test
377378
⍤⤙≍ [1 2] Quad 1 ¯3 2
@@ -383,15 +384,16 @@ Quad ← ⍥R⌵↥0:⊟⊃-+⊙:√⟜±-:⤚°√ℂ0¯÷2∩⌞÷
383384
PSet ← ⍚▽⋯⇡ⁿ:2⧻⟜¤
384385

385386
# Rank-polymorphic fast fourier transform
387+
# Deprecated! `fft` has been updated to be rank-polymorphic by default. Use that instead.
386388
RPFFT ← ⌅(⍥(⍉fft)⧻△.|⍥°(⍉fft)⧻△.)
387389

388390
# Rank-polymorphic convolution using fast fourier transform
389391
┌─╴FFTConvolve
390392
# Full convolution wherever any overlap between the inputs exists
391-
Full ← ⍥R=0↥⊃∩type(×√/×⊸△⍜∩RPFFT×∩⌞⬚0↙-1+◡∩△)
393+
Full ← ⍥R=0↥⊃∩type(×√/×⊸△⍜∩fft×∩⌞⬚0↙-1+◡∩△)
392394
Call ← Full
393395
# Convolution of only instances of complete overlap between inputs
394-
Valid ← ⍥R=0↥⊃∩type(↘-+1⌵⊙⟜(×√/×⊸△⍜∩RPFFT×∩⌞⬚0↙)⊃-↥◡∩△)
396+
Valid ← ⍥R=0↥⊃∩type(↘-+1⌵⊙⟜(×√/×⊸△⍜∩fft×∩⌞⬚0↙)⊃-↥◡∩△)
395397
# Convolution that maintains the shape of the larger input
396398
# **CURRENTLY UNIMPLEMENTED** - PR welcome
397399
Same ← ⍤"Not yet implemented"0 ⋅∘

0 commit comments

Comments
 (0)