Documentation

Sigma is a purely functional programming language designed for high-performance numerical computing within the Python ecosystem.

It combines the elegance of functional programming with the speed of Rust and the ubiquity of Python. Sigma is statically typed with Hindley-Milner type inference, meaning you get the safety of types without the verbosity.

Syntax Basics

Function Definition

Functions are defined using the name args = body syntax.

add x y = x + y;

# Recursive function
factorial n = if n == 0 then 1 else n * factorial (n - 1);

Let Bindings

Use let ... in ... for local bindings.

main = 
    let x = 10 in
    let y = 20 in
    x + y

Conditionals

Sigma supports if ... then ... else ... expressions.

check n = if n > 0 then "positive" else "non-positive";

Anonymous Functions

Lambdas are defined using the \args -> body syntax.

map (\x -> x * 2) [1, 2, 3]

Data Types

Numbers

Sigma supports integers and floating-point numbers. It also has native support for complex numbers using the i suffix.

z = 3 + 4i;
abs_z = abs z; # Returns 5.0

Lists

Lists are homogeneous and support standard functional operations.

my_list = [1, 2, 3, 4, 5];
empty = [];
first = head my_list;
rest = tail my_list;

Vectors and Matrices

Sigma has first-class support for linear algebra, mapping directly to Numpy arrays.

v = vec [1.0, 2.0, 3.0];
m = mat [
    [1.0, 0.0],
    [0.0, 1.0]
];

# Matrix multiplication
result = mul m v;

Python Interop

Sigma is designed to be called from Python. The sigma package provides a SigmaContext for loading and executing Sigma code.

import sigma
import numpy as np

ctx = sigma.SigmaContext()
ctx.load("my_script.sg")

# Call Sigma functions directly
result = ctx.my_func(np.array([1, 2, 3]))

Standard Library

Sigma comes with a built-in library of functions for math, list manipulation, and linear algebra.

  • abs: Absolute value (works on complex numbers)
  • sin, cos, tan, exp, log: Trigonometric and exponential functions
  • head, tail, isEmpty, cons: List operations
  • mul, det, inv, dot: Linear algebra operations
  • map, filter, foldl, foldr: Higher-order functions