viva_math
viva_math - Core mathematical functions for VIVA.
A specialized math library for sentient digital life, built on top of gleam_community_maths.
Modules
viva_math/common- Utilities: clamp, sigmoid, softmax, lerpviva_math/vector- Vec3 type for PAD emotional spaceviva_math/cusp- Cusp catastrophe theoryviva_math/free_energy- Free Energy Principleviva_math/attractor- Emotional attractor dynamicsviva_math/entropy- Information theory
Dependencies
Re-exports gleam_community_maths for convenience.
Use import gleam_community/maths for:
- Trigonometry (sin, cos, tan, etc.)
- Statistics (mean, variance, etc.)
- Distances (euclidean, manhattan, etc.)
- Constants (pi, e, tau)
Example
import viva_math/vector
import viva_math/attractor
import viva_math/cusp
// Create PAD state
let state = vector.pad(-0.3, 0.7, -0.2)
// Classify emotion
let emotion = attractor.classify_emotion(state)
// -> "fear"
// Check for cusp bistability
let params = cusp.from_arousal_dominance(0.7, -0.2)
let volatile = cusp.is_bistable(params)
// -> True (high arousal creates bistability)
Values
pub fn classify(state: vector.Vec3) -> String
Classify emotional state to nearest attractor name. Shorthand for attractor.classify_emotion/1.
pub fn entropy(probabilities: List(Float)) -> Float
Compute Shannon entropy of a probability distribution.
pub fn free_energy(
expected: vector.Vec3,
actual: vector.Vec3,
) -> free_energy.FreeEnergyState
Compute free energy from expected and actual states.
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.