viva_math

viva_math - Mathematical foundations for VIVA’s sentient digital life.

A specialized math library for the BEAM, designed to sit between gleam_community_maths (primitives) and viva_tensor (tensors + NIF).

Modules

Foundations

Geometry & linear algebra

Stochastic & inference

Dynamical systems

Quick start

import viva_math/scalar
import viva_math/vector
import viva_math/attractor
import viva_math/random

// PAD emotional state
let state = vector.pad(-0.3, 0.7, -0.2)

// Classify nearest emotion
let emotion = attractor.classify_emotion(state)
// -> "fear"

// Scalar activations for ML
let y = scalar.gelu(0.5)

// Seedable, reproducible normal sample
let seed = random.from_int(42)
let #(x, _) = random.normal(seed, 0.0, 1.0)

Values

pub fn clamp_bipolar(x: Float) -> Float

Clamp value to [-1, 1] range.

pub fn classify(state: vector.Vec3) -> String

Classify emotional state to nearest attractor name.

pub fn entropy(probabilities: List(Float)) -> Float

Shannon entropy of a probability distribution.

pub fn erf(x: Float) -> Float

Error function. Delegates to viva_math/scalar.erf (Erlang :math.erf).

pub fn free_energy(
  expected: vector.Vec3,
  actual: vector.Vec3,
) -> free_energy.FreeEnergyState

Compute free energy from expected and actual states with default precision.

pub fn gelu(x: Float) -> Float

GELU activation (exact form using erf).

pub fn is_volatile(arousal: Float, dominance: Float) -> Bool

Check if emotional state is volatile (cusp bistability).

pub fn pad(
  pleasure: Float,
  arousal: Float,
  dominance: Float,
) -> vector.Vec3

Create a PAD vector with clamping. Shorthand for vector.pad/3.

pub fn sigmoid(x: Float) -> Float

Standard sigmoid σ(x) = 1 / (1 + e^(-x)).

pub const version: String

Library version.

Search Document