{
 "description": "Verified Soma programs. Every entry passed `soma check` (and `soma test` / `soma verify` where applicable) on the soma version below, re-run when this index was generated. Fetch `url` for the source. Filter by `domain` or `features` to find a working example of what you are about to write.",
 "soma_version": "3.2.4",
 "count": 17,
 "domains": {
  "math": 17
 },
 "features": [
  "agent",
  "cost",
  "fail",
  "guard",
  "http",
  "invariant",
  "lambda",
  "match",
  "multi_cell",
  "native",
  "pipeline",
  "service",
  "skeleton",
  "state_machine",
  "sum_type",
  "think",
  "tools",
  "try"
 ],
 "programs": [
  {
   "id": "math/bisection_root",
   "domain": "math",
   "title": "Bisection — bracket a root of a continuous function and halve",
   "summary": "Bisection — bracket a root of a continuous function and halve Given a bracket [a,b] with f(a)·f(b) < 0, the root lies between them; halve the interval toward whichever sub-bracket keeps the sign change. Converges linearly but never diverges. Here f(x) = x² − 2, whose positive root is √2.",
   "url": "https://soma-lang.dev/corpus/math/bisection_root.cell",
   "repo_path": "examples/corpus/math/bisection_root.cell",
   "lines": 61,
   "features": [
    "native"
   ],
   "cells": [
    "BisectionRoot",
    "BisectTests"
   ],
   "usage": [
    "soma run bisection_root.cell run"
   ]
  },
  {
   "id": "math/combinatorics",
   "domain": "math",
   "title": "Combinatorics — factorial, permutations, combinations factorial folds product over range(1, n+1)",
   "summary": "Combinatorics — factorial, permutations, combinations factorial folds product over range(1, n+1). nPr = n!/(n-r)! and nCr = n!/(r!(n-r)!). To stay exact for larger n we compute nCr with a running product instead of three separate factorials. Pascal's identity is the cross-check: C(n,r) = C(n-1,r-1) + C(n-1,r).",
   "url": "https://soma-lang.dev/corpus/math/combinatorics.cell",
   "repo_path": "examples/corpus/math/combinatorics.cell",
   "lines": 64,
   "features": [],
   "cells": [
    "Combinatorics",
    "ComboTests"
   ],
   "usage": [
    "soma run combinatorics.cell run"
   ]
  },
  {
   "id": "math/complex",
   "domain": "math",
   "title": "Complex numbers — records carrying real and imaginary parts",
   "summary": "Complex numbers — records carrying real and imaginary parts Soma has no native complex type, so a Complex is a record { re, im }. Addition is componentwise; multiplication uses the FOIL identity (a+bi)(c+di) = (ac−bd) + (ad+bc)i; modulus is sqrt(re²+im²). Records carry a _type field so is_a recognizes them.",
   "url": "https://soma-lang.dev/corpus/math/complex.cell",
   "repo_path": "examples/corpus/math/complex.cell",
   "lines": 63,
   "features": [],
   "cells": [
    "Complex",
    "ComplexTests"
   ],
   "usage": [
    "soma run complex.cell run"
   ]
  },
  {
   "id": "math/ext_euclid",
   "domain": "math",
   "title": "Extended Euclidean algorithm — Bezout coefficients and modular inverse",
   "summary": "Extended Euclidean algorithm — Bezout coefficients and modular inverse Beyond the gcd, the extended algorithm finds integers x, y with a·x + b·y = gcd(a, b) (Bezout's identity). When gcd(a, m) = 1, x mod m is the modular inverse of a. Returns a record { g, x, y }.",
   "url": "https://soma-lang.dev/corpus/math/ext_euclid.cell",
   "repo_path": "examples/corpus/math/ext_euclid.cell",
   "lines": 70,
   "features": [],
   "cells": [
    "ExtEuclid",
    "ExtEuclidTests"
   ],
   "usage": [
    "soma run ext_euclid.cell run"
   ]
  },
  {
   "id": "math/fibonacci",
   "domain": "math",
   "title": "Fibonacci — iterative, and the closed-form Binet approximation",
   "summary": "Fibonacci — iterative, and the closed-form Binet approximation The iterative version carries the last two terms in two variables. Binet's formula F(n) = (phi^n − psi^n)/√5 gives a closed form; we round it back to the exact integer for small n. Both agree, which the tests cross-check.",
   "url": "https://soma-lang.dev/corpus/math/fibonacci.cell",
   "repo_path": "examples/corpus/math/fibonacci.cell",
   "lines": 66,
   "features": [],
   "cells": [
    "Fibonacci",
    "FibTests"
   ],
   "usage": [
    "soma run fibonacci.cell run"
   ]
  },
  {
   "id": "math/gcd_lcm",
   "domain": "math",
   "title": "GCD / LCM — Euclid's algorithm and its consequences gcd() is a builtin (Euclid on absolute values)",
   "summary": "GCD / LCM — Euclid's algorithm and its consequences gcd() is a builtin (Euclid on absolute values). lcm(a,b) = a*b / gcd(a,b). gcd_list folds the builtin across a whole list with reduce. Coprimality is just gcd == 1.",
   "url": "https://soma-lang.dev/corpus/math/gcd_lcm.cell",
   "repo_path": "examples/corpus/math/gcd_lcm.cell",
   "lines": 54,
   "features": [
    "pipeline",
    "lambda"
   ],
   "cells": [
    "GcdLcm",
    "GcdTests"
   ],
   "usage": [
    "soma run gcd_lcm.cell run"
   ]
  },
  {
   "id": "math/integration",
   "domain": "math",
   "title": "Numerical integration — trapezoidal and Simpson's rule",
   "summary": "Numerical integration — trapezoidal and Simpson's rule Approximate the area under f over [a,b] with n panels. The trapezoid rule averages the endpoints of each panel; Simpson's rule fits parabolas and is exact for cubics. Here f(x) = x², whose integral over [0,1] is 1/3.",
   "url": "https://soma-lang.dev/corpus/math/integration.cell",
   "repo_path": "examples/corpus/math/integration.cell",
   "lines": 66,
   "features": [
    "native"
   ],
   "cells": [
    "Integration",
    "IntegrationTests"
   ],
   "usage": [
    "soma run integration.cell run"
   ]
  },
  {
   "id": "math/linear_solve",
   "domain": "math",
   "title": "Solving 2x2 linear systems — Cramer's rule via determinants",
   "summary": "Solving 2x2 linear systems — Cramer's rule via determinants For A·x = b with A 2x2, Cramer's rule gives x_i = det(A_i)/det(A), where A_i is A with column i replaced by b. det() is the matrix builtin. A zero determinant means the system is singular (no unique solution).",
   "url": "https://soma-lang.dev/corpus/math/linear_solve.cell",
   "repo_path": "examples/corpus/math/linear_solve.cell",
   "lines": 46,
   "features": [],
   "cells": [
    "LinearSolve",
    "SolveTests"
   ],
   "usage": [
    "soma run linear_solve.cell run"
   ]
  },
  {
   "id": "math/matrix_algebra",
   "domain": "math",
   "title": "Matrix algebra — product, transpose, determinant, trace",
   "summary": "Matrix algebra — product, transpose, determinant, trace Matrices are List<List<Float>> built by reshape. `*` is matmul, `.T` is transpose, det() is the determinant (LU with pivoting), diag_sum() the trace. Soma has no structural list ==, so we probe results by index/det.",
   "url": "https://soma-lang.dev/corpus/math/matrix_algebra.cell",
   "repo_path": "examples/corpus/math/matrix_algebra.cell",
   "lines": 56,
   "features": [],
   "cells": [
    "MatrixAlgebra",
    "MatrixTests"
   ],
   "usage": [
    "soma run matrix_algebra.cell run"
   ]
  },
  {
   "id": "math/modular",
   "domain": "math",
   "title": "Modular arithmetic — fast exponentiation and Fermat primality pow_mod(base, exp, m) is a builtin doing square-and-multiply mod m",
   "summary": "Modular arithmetic — fast exponentiation and Fermat primality pow_mod(base, exp, m) is a builtin doing square-and-multiply mod m. Fermat's little theorem: if p is prime then a^(p-1) ≡ 1 (mod p) for any a coprime to p. We use it as a probable-prime witness. modinv finds a^-1 via Fermat when the modulus is prime: a^(p-2) mod p.",
   "url": "https://soma-lang.dev/corpus/math/modular.cell",
   "repo_path": "examples/corpus/math/modular.cell",
   "lines": 54,
   "features": [],
   "cells": [
    "Modular",
    "ModularTests"
   ],
   "usage": [
    "soma run modular.cell run"
   ]
  },
  {
   "id": "math/monte_carlo_pi",
   "domain": "math",
   "title": "Monte Carlo — estimate pi by dart-throwing",
   "summary": "Monte Carlo — estimate pi by dart-throwing Throw random points into the unit square; the fraction landing inside the quarter circle (x²+y² ≤ 1) approaches pi/4. random() is the time-seeded PRNG — flagged nondeterministic for `soma replay`, so the estimate varies run-to-run. The test asserts only that the estimate is in a loose band.",
   "url": "https://soma-lang.dev/corpus/math/monte_carlo_pi.cell",
   "repo_path": "examples/corpus/math/monte_carlo_pi.cell",
   "lines": 44,
   "features": [],
   "cells": [
    "MonteCarloPi",
    "MonteCarloTests"
   ],
   "usage": [
    "soma run monte_carlo_pi.cell run"
   ]
  },
  {
   "id": "math/newton_sqrt",
   "domain": "math",
   "title": "Newton's method — square root and reciprocal without division/sqrt sqrt(a) is the positive root of f(x) = x² − a; Newton's iteration becomes the Babylonian update x ← (x + a/x) / 2",
   "summary": "Newton's method — square root and reciprocal without division/sqrt sqrt(a) is the positive root of f(x) = x² − a; Newton's iteration becomes the Babylonian update x ← (x + a/x) / 2. The reciprocal 1/a is the root of f(x) = 1/x − a, giving x ← x·(2 − a·x) — a multiply-only iteration.",
   "url": "https://soma-lang.dev/corpus/math/newton_sqrt.cell",
   "repo_path": "examples/corpus/math/newton_sqrt.cell",
   "lines": 67,
   "features": [
    "native"
   ],
   "cells": [
    "NewtonSqrt",
    "NewtonTests"
   ],
   "usage": [
    "soma run newton_sqrt.cell run"
   ]
  },
  {
   "id": "math/primes",
   "domain": "math",
   "title": "Primes — primality test, prime list, factorization",
   "summary": "Primes — primality test, prime list, factorization Trial division up to √n decides primality. primes_up_to collects them into a list. factorize peels off prime factors smallest-first. Everything stays in plain Int arithmetic with while loops.",
   "url": "https://soma-lang.dev/corpus/math/primes.cell",
   "repo_path": "examples/corpus/math/primes.cell",
   "lines": 76,
   "features": [],
   "cells": [
    "Primes",
    "PrimeTests"
   ],
   "usage": [
    "soma run primes.cell run"
   ]
  },
  {
   "id": "math/quadratic",
   "domain": "math",
   "title": "Quadratic equations — discriminant and the two real roots",
   "summary": "Quadratic equations — discriminant and the two real roots For ax² + bx + c = 0 the discriminant D = b² − 4ac decides the root count: D > 0 two real roots, D == 0 one repeated, D < 0 none real. Vieta's relations cross-check: roots sum to −b/a and multiply to c/a.",
   "url": "https://soma-lang.dev/corpus/math/quadratic.cell",
   "repo_path": "examples/corpus/math/quadratic.cell",
   "lines": 54,
   "features": [],
   "cells": [
    "Quadratic",
    "QuadraticTests"
   ],
   "usage": [
    "soma run quadratic.cell run"
   ]
  },
  {
   "id": "math/series",
   "domain": "math",
   "title": "Power series — e via 1/k!, and pi via the Leibniz / Nilakantha series e = Σ 1/k!",
   "summary": "Power series — e via 1/k!, and pi via the Leibniz / Nilakantha series e = Σ 1/k! converges fast (factorial denominator). The Leibniz series pi = 4·Σ (−1)^k/(2k+1) converges painfully slowly; Nilakantha's 3 + 4·Σ (−1)^k / (2k(2k+1)(2k+2)) is far quicker. We carry the factorial incrementally to avoid recomputing it each term.",
   "url": "https://soma-lang.dev/corpus/math/series.cell",
   "repo_path": "examples/corpus/math/series.cell",
   "lines": 75,
   "features": [
    "native"
   ],
   "cells": [
    "Series",
    "SeriesTests"
   ],
   "usage": [
    "soma run series.cell run"
   ]
  },
  {
   "id": "math/statistics",
   "domain": "math",
   "title": "Descriptive statistics — mean, variance, stddev, median via sort",
   "summary": "Descriptive statistics — mean, variance, stddev, median via sort Mean is sum/len. Variance is the mean of squared deviations. Median sorts the sample and takes the middle (or the average of the two middles for an even count). All of it rides on list reductions and bracket indexing.",
   "url": "https://soma-lang.dev/corpus/math/statistics.cell",
   "repo_path": "examples/corpus/math/statistics.cell",
   "lines": 69,
   "features": [
    "pipeline",
    "lambda"
   ],
   "cells": [
    "Statistics",
    "StatTests"
   ],
   "usage": [
    "soma run statistics.cell run"
   ]
  },
  {
   "id": "math/vector_ops",
   "domain": "math",
   "title": "Vector operations — dot product, norm, cosine similarity",
   "summary": "Vector operations — dot product, norm, cosine similarity Vectors are plain lists. dot() zips two lists and sums the pairwise products; norm is sqrt of the self-dot; cosine similarity normalizes the dot by the product of the norms. Reductions (sum) and zip do the work.",
   "url": "https://soma-lang.dev/corpus/math/vector_ops.cell",
   "repo_path": "examples/corpus/math/vector_ops.cell",
   "lines": 56,
   "features": [
    "pipeline",
    "lambda"
   ],
   "cells": [
    "VectorOps",
    "VectorTests"
   ],
   "usage": [
    "soma run vector_ops.cell run"
   ]
  }
 ]
}