trit-vsa
A high-performance balanced ternary arithmetic library for Rust.
Overview
trit-vsa provides core primitives for balanced ternary arithmetic, including:
- Trit: Single balanced ternary digit {-1, 0, +1}
- Tryte3: 3 trits packed in a byte (values -13 to +13)
- Word6: 6 trits packed in a u16 (values -364 to +364)
- PackedTritVec: Bitsliced vector storage with SIMD acceleration
- SparseVec: COO format for high-sparsity vectors
- VSA Operations: Vector Symbolic Architecture (bind, bundle, similarity)
Installation
Add to your Cargo.toml:
[]
= "0.1"
Quick Start
use ;
// Basic trit operations
let a = P; // +1
let b = N; // -1
let product = a * b; // -1
assert_eq!;
// Tryte arithmetic
let x = from_value.unwrap;
let y = from_value.unwrap;
let = x + y;
assert_eq!;
// High-dimensional vectors for VSA
let mut vec_a = new;
let mut vec_b = new;
// Set some values
for i in 0..500
// Compute similarity
let sim = cosine_similarity;
println!;
// Bind vectors (creates association)
let bound = bind;
let recovered = unbind;
// Bundle vectors (superposition)
let bundled = bundle;
Features
Core Types
| Type | Storage | Range | Use Case |
|---|---|---|---|
Trit |
2 bits | {-1, 0, +1} | Single digit |
Tryte3 |
1 byte | [-13, +13] | Small integers |
Word6 |
2 bytes | [-364, +364] | Medium integers |
PackedTritVec |
Bitsliced | Any length | Dense vectors |
SparseVec |
COO | Any length | Sparse vectors |
SIMD Acceleration
Enable SIMD optimizations with the simd feature:
[]
= { = "0.1", = ["simd"] }
Supports:
- x86_64: AVX2
- aarch64: NEON
Vector Symbolic Architecture (VSA)
Implements hyperdimensional computing operations:
- Bind: Creates associations between vectors
- Bundle: Superposition via majority voting
- Similarity: Cosine and Hamming metrics
use ;
// Create symbol vectors
let dog = random;
let cat = random;
let animal = random;
// Create compound: "dog is an animal"
let dog_animal = bind;
// Query: what is dog?
let query_result = unbind;
let sim = cosine_similarity;
// sim should be high (close to 1.0)
Performance
Benchmarks on typical hardware show:
| Operation | Dimension | Throughput |
|---|---|---|
| Dot product | 10,000 | ~50 million trits/sec |
| Bind | 10,000 | ~40 million trits/sec |
| Bundle (3 vectors) | 10,000 | ~30 million trits/sec |
Run benchmarks:
Documentation
Full API documentation: docs.rs/trit-vsa
References
- Kanerva, P. (2009). "Hyperdimensional Computing"
- Gayler, R. (2003). "Vector Symbolic Architectures"
- Rachkovskij, D. (2001). "Binding and Normalization of Binary Sparse Distributed Representations"
License
MIT License - see LICENSE for details.