Standard Library: Math

The math module provides common mathematical functions for scalar and tensor operations.

Key Exports

  • sin, cos, tan — Trigonometric functions.
  • exp, log, log10 — Exponential and logarithmic functions.
  • sqrt, pow, abs — Power and absolute value functions.
  • relu, sigmoid, tanh — Activation functions for ML.

Example Usage

use math::{exp, relu, sigmoid};

fn softmax(x: Tensor<f32>[N]) -> Tensor<f32>[N] {
    let e = exp(x);
    return e / sum(e);
}

fn main() {
    let logits: Tensor<f32>[4] = [1.0, 2.0, 3.0, 4.0];
    let probs = softmax(logits);
    print(probs);
}