viva_tensor/lns
LNS - Log-Number System
Efficient arithmetic for resonance and probabilistic computing.
Represents numbers as their logarithms: x => log(|x|) + sign. Multiplication becomes addition: log(a*b) = log(a) + log(b). Division becomes subtraction: log(a/b) = log(a) - log(b). Power becomes multiplication: log(x^p) = p * log(x).
Used for:
- High-dynamic range calculations
- Chain multiplications (probability chains)
- “Resonance” calculations (heavy multiplication/exponentiation)
Precision is traded for speed (up to 8x faster than FP32 FMA).
Types
LNS Tensor reference (storage in f32 log-domain)
pub type LogNumber =
ffi.LnsTensorRef
Values
pub fn div(
a: ffi.LnsTensorRef,
b: ffi.LnsTensorRef,
) -> ffi.LnsTensorRef
Divide two LNS tensors (Subtraction in log-domain)
pub fn from_tensor(ref: ffi.NativeTensorRef) -> ffi.LnsTensorRef
Convert standard f64 tensor to LNS format
pub fn mul(
a: ffi.LnsTensorRef,
b: ffi.LnsTensorRef,
) -> ffi.LnsTensorRef
Multiply two LNS tensors (Addition in log-domain)
pub fn sqrt(a: ffi.LnsTensorRef) -> ffi.LnsTensorRef
Square root of LNS tensor (Bit shift / division by 2 in log-domain)
pub fn to_tensor(lns: ffi.LnsTensorRef) -> ffi.NativeTensorRef
Convert LNS tensor back to standard f64 tensor