</> APL Run Loading interactive WebAssembly workspace…

mAPL Scientific Computing Library

Pure APL implementations of standard mathematical and numerical algorithms. All functions use well-known textbook methods. Import with import { Fn } from 'sci/module.mapl'.

Core Utilities sci/core.mapl

Array generation, cumulative operations, indexing utilities, and meshgrid construction.

import { Linspace, Logspace, Colon, CumSum, CumProd, ... } from 'sci/core.mapl'
FunctionTypeSignatureDescriptionExample
Linspace⍺ f ⍵scalar, vector → vectorn linearly spaced points between (a,b)5 Linspace (0,1) → 0 0.25 0.5 0.75 1
Logspace⍺ f ⍵scalar, vector → vectorn log-spaced points between 10^a and 10^b4 Logspace (0,3) → 1 10 100 1000
Colon⍺ f ⍵vector, scalar → vectorRange from start to end with step(0,0.5) Colon 2 → 0 0.5 1 1.5 2
CumSumf ⍵vector → vectorCumulative sum (+\)CumSum 1 2 3 4 5 → 1 3 6 10 15
CumProdf ⍵vector → vectorCumulative product (×\)CumProd 1 2 3 4 5 → 1 2 6 24 120
CumMaxf ⍵vector → vectorRunning maximum (⌈\)CumMax 3 1 4 1 5 → 3 3 4 4 5
CumMinf ⍵vector → vectorRunning minimum (⌊\)CumMin 5 3 4 1 2 → 5 3 3 1 1
Difff ⍵vector → vectorFirst differences (length n → n−1)Diff 1 4 9 16 → 3 5 7
Findf ⍵vector → vectorIndices of nonzero elementsFind 0 3 0 5 → 2 4
Anyf ⍵vector → scalar1 if any element nonzeroAny 0 0 1 0 → 1
Allf ⍵vector → scalar1 if all elements nonzeroAll 1 1 1 1 → 1
Numelf ⍵any → scalarTotal number of elementsNumel 3 4 ⍴ ⍳12 → 12
Sub2Ind⍺ f ⍵vector, vector → scalarSubscripts → linear index(3,4) Sub2Ind (1,2) → 6
Ind2Sub⍺ f ⍵vector, scalar → vectorLinear index → subscripts(3,4) Ind2Sub 6 → 1 2
Meshgrid⍺ f ⍵vector, vector → dictCoordinate matrices {X, Y}(1 2 3) Meshgrid (4 5) → {X:…, Y:…}
Accumarray⍺ f ⍵vector, vector → vectorAccumulate values by group keys(1 1 2 2 3) Accumarray (10 20 30 40 50) → 30 70 50

Polynomials sci/poly.mapl

Horner evaluation, differentiation, integration, root-finding, and polynomial arithmetic.

import { Polyval, Polyder, Polyint, Roots2, Poly, Polyadd, Polymul } from 'sci/poly.mapl'
FunctionTypeSignatureDescriptionExample
Polyval⍺ f ⍵vector, any → anyEvaluate polynomial (Horner's method)(1 2 3) Polyval 5 → 38
Polyderf ⍵vector → vectorDifferentiate polynomial (power rule)Polyder 3 2 1 → 6 2
Polyintf ⍵vector → vectorIntegrate polynomialPolyint 6 2 → 2 2 0
Roots2f ⍵vector → vectorQuadratic formula rootsRoots2 (1 ¯3 2) → 2 1
Polyf ⍵vector → vectorRoots → polynomial coefficientsPoly 2 1 → 1 ¯3 2
Polyadd⍺ f ⍵vector, vector → vectorAdd two polynomials(1 2) Polyadd (3 4 5) → 3 5 7
Polymul⍺ f ⍵vector, vector → vectorMultiply polynomials (convolution)(1 1) Polymul (1 1) → 1 2 1

Special Matrices sci/special.mapl

Classic matrix families: magic squares, Hilbert, Vandermonde, Pascal, Toeplitz, Hankel, circulant, companion.

import { Magic, Hilb, InvHilb, Vander, Toeplitz, Hankel, Pascal, Companion, Circulant } from 'sci/special.mapl'
FunctionTypeSignatureDescriptionExample
Magicf ⍵scalar → matrixn×n magic square (Siamese method, odd n)Magic 3 → rows/cols/diags all sum to 15
Hilbf ⍵scalar → matrixHilbert matrix H[i,j]=1/(i+j+1)Hilb 3 → 1 0.5 0.333 / …
InvHilbf ⍵scalar → matrixInverse of Hilbert matrixInvHilb 3 → exact inverse
Vanderf ⍵vector → matrixVandermonde matrix v^(n-1..0)Vander 1 2 3 → power matrix
Toeplitzf ⍵vector → matrixSymmetric Toeplitz matrixToeplitz 1 2 3 → 1 2 3 / 2 1 2 / 3 2 1
Hankelf ⍵vector → matrixHankel matrix H[i,j]=c[i+j]Hankel 1 2 3 → 1 2 3 / 2 3 0 / 3 0 0
Pascalf ⍵scalar → matrixPascal/binomial coefficient matrixPascal 4 → 1 1 1 1 / 1 2 3 4 / …
Companionf ⍵vector → matrixCompanion matrix from polynomialCompanion 1 ¯6 11 ¯6 → …
Circulantf ⍵vector → matrixCirculant matrix (cyclic rows)Circulant 1 2 3 → 1 2 3 / 3 1 2 / 2 3 1

Linear Algebra sci/linalg.mapl

Decompositions (LU, QR, eigen), norms, vector products, matrix operations, pseudoinverse.

import { Det, Inv, LU, QR, Eig, Dot, Cross, Norm, Kron, Triu, Tril, ... } from 'sci/linalg.mapl'
FunctionTypeSignatureDescriptionExample
Invf ⍵matrix → matrixMatrix inverse (via ⌹)Inv 2 2⍴4 7 2 6 → 0.6 ¯0.7…
Detf ⍵matrix → scalarDeterminant (cofactor expansion)Det 2 2⍴1 2 3 4 → ¯2
Dot⍺ f ⍵vector, vector → scalarDot product (+/⍺×⍵)(1 2 3) Dot (4 5 6) → 32
Cross⍺ f ⍵vector, vector → vectorCross product (3D vectors)(1 2 3) Cross (4 5 6) → ¯3 6 ¯3
Normf ⍵vector → scalarEuclidean (L²) normNorm 3 4 → 5
Norm1f ⍵vector → scalarManhattan (L¹) normNorm1 (¯3 4) → 7
NormInff ⍵vector → scalarInfinity norm (max |x|)NormInf (¯3 4 ¯7) → 7
NormFrof ⍵matrix → scalarFrobenius normNormFro 2 2⍴1 2 3 4 → √30
Triuf ⍵matrix → matrixUpper triangular partTriu M → zeros below diagonal
Trilf ⍵matrix → matrixLower triangular partTril M → zeros above diagonal
FlipUDf ⍵matrix → matrixFlip upside-down (⊖)FlipUD M → reversed rows
FlipLRf ⍵matrix → matrixFlip left-right (⌽)FlipLR M → reversed columns
Rot90f ⍵matrix → matrixRotate 90° counter-clockwiseRot90 M → ⍉⊖M
Repmat⍺ f ⍵vector, matrix → matrixTile matrix into m×n grid(2,3) Repmat M → 2×3 copies
Kron⍺ f ⍵matrix, matrix → matrixKronecker (tensor) productI₂ Kron σₓ → 4×4 block matrix
LUf ⍵matrix → dictLU decomposition {L, U} (Doolittle)lu←LU A ⋄ lu.L +.× lu.U ≡ A
QRf ⍵matrix → dictQR decomposition {Q, R} (Gram-Schmidt)qr←QR A ⋄ qr.Q +.× qr.R ≡ A
Eigf ⍵matrix → dictDominant eigenvalue {val, vec} (power iter)Eig 2 2⍴2 1 1 3 → {val:3.618…}
EigAllf ⍵matrix → dictAll eigenvalues {vals} (deflation)EigAll M → {vals: …}
Rankf ⍵matrix → scalarMatrix rankRank 3 3⍴1 2 3 4 5 6 7 8 9 → 2
Condf ⍵matrix → scalarCondition numberCond (Hilb 4) → large number
Pinvf ⍵matrix → matrixPseudoinverse (AᵀA)⁻¹AᵀPinv A → A⁺

Signal Processing sci/signal.mapl

Cooley-Tukey FFT, convolution, deconvolution, cross-correlation, and IIR/FIR digital filtering.

import { FFT, IFFT, Conv, Deconv, XCorr, Filter } from 'sci/signal.mapl'
FunctionTypeSignatureDescriptionExample
FFTf ⍵vector → vectorFast Fourier Transform (radix-2)FFT 1 1 1 1 0 0 0 0 → complex spectrum
IFFTf ⍵vector → vectorInverse FFTIFFT FFT signal → signal (roundtrip)
Conv⍺ f ⍵vector, vector → vectorDiscrete convolution(1 2 3) Conv (4 5) → 4 13 22 15
Deconv⍺ f ⍵vector, vector → dictDeconvolution {Q: quotient, R: remainder}(4 13 22 15) Deconv (4 5) → {Q:1 2 3}
XCorr⍺ f ⍵vector, vector → vectorCross-correlationsignal XCorr template → lag peaks
Filter⍺ f ⍵dict, vector → vectorIIR/FIR digital filter {b, a}{b:(1 1),a:(1 ¯0.5)} Filter impulse

Numerical Methods sci/numerical.mapl

ODE solvers (Euler, RK4), root finding (bisection), numerical integration (Simpson, trapezoidal), differentiation, interpolation.

import { OdeRK4, OdeEuler, Fzero, Quad, Trapz, Gradient, Interp1 } from 'sci/numerical.mapl'
FunctionTypeSignatureDescriptionExample
OdeEuler⍺ f ⍵dict, scalar → vectorEuler ODE solver {f, h, n}{f:{-⍵},h:0.1,n:10} OdeEuler 1
OdeRK4⍺ f ⍵dict, scalar → vectorRunge-Kutta 4th order {f, h, n}{f:{-⍵},h:0.1,n:10} OdeRK4 1
Fzero⍺ f ⍵dict, scalar → scalarRoot finder (bisection) {f, a, b}{f:{(⍵*2)-2},a:0,b:2} Fzero 1E¯10 → √2
Quad⍺ f ⍵dict, scalar → scalarNumerical integration (Simpson's rule){f:{⍵*2},a:0,b:1} Quad 100 → 0.333…
Trapzf ⍵vector → scalarTrapezoidal integration from dataTrapz 0 1 4 9 → area under curve
HTrapz⍺ f ⍵scalar, vector → scalarTrapezoidal with custom spacing h0.5 HTrapz data → area
Gradientf ⍵vector → vectorNumerical differentiation (central diff)Gradient 0 1 4 9 16 → approx 2x
Interp1⍺ f ⍵dict, vector → vectorLinear interpolation {x, y}{x:(0 1 2),y:(0 10 20)} Interp1 (0.5 1.5)
mAPL Scientific Computing Library — Pure APL implementations of standard textbook algorithms. Part of APL Studio.