| Crates.io | trit-vsa |
| lib.rs | trit-vsa |
| version | 0.1.1 |
| created_at | 2026-01-25 00:12:59.274814+00 |
| updated_at | 2026-01-25 03:00:55.716652+00 |
| description | Balanced ternary arithmetic library with bitsliced storage and VSA operations |
| homepage | https://github.com/tzervas/trit-vsa |
| repository | https://github.com/tzervas/trit-vsa |
| max_upload_size | |
| id | 2067753 |
| size | 156,510 |
A high-performance balanced ternary arithmetic library for Rust.
trit-vsa provides core primitives for balanced ternary arithmetic, including:
Add to your Cargo.toml:
[dependencies]
trit-vsa = "0.1"
use trit_vsa::{Trit, Tryte3, PackedTritVec, vsa};
// Basic trit operations
let a = Trit::P; // +1
let b = Trit::N; // -1
let product = a * b; // -1
assert_eq!(product, Trit::N);
// Tryte arithmetic
let x = Tryte3::from_value(5).unwrap();
let y = Tryte3::from_value(3).unwrap();
let (sum, carry) = x + y;
assert_eq!(sum.value() + carry.value() as i32 * 27, 8);
// High-dimensional vectors for VSA
let mut vec_a = PackedTritVec::new(1000);
let mut vec_b = PackedTritVec::new(1000);
// Set some values
for i in 0..500 {
vec_a.set(i, Trit::P);
vec_b.set(i, Trit::P);
}
// Compute similarity
let sim = vsa::cosine_similarity(&vec_a, &vec_b);
println!("Similarity: {:.3}", sim);
// Bind vectors (creates association)
let bound = vsa::bind(&vec_a, &vec_b);
let recovered = vsa::unbind(&bound, &vec_b);
// Bundle vectors (superposition)
let bundled = vsa::bundle(&vec_a, &vec_b);
| 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 |
Enable SIMD optimizations with the simd feature:
[dependencies]
trit-vsa = { version = "0.1", features = ["simd"] }
Supports:
Implements hyperdimensional computing operations:
use trit_vsa::{PackedTritVec, Trit, vsa};
// Create symbol vectors
let dog = PackedTritVec::random(10000);
let cat = PackedTritVec::random(10000);
let animal = PackedTritVec::random(10000);
// Create compound: "dog is an animal"
let dog_animal = vsa::bind(&dog, &animal);
// Query: what is dog?
let query_result = vsa::unbind(&dog_animal, &dog);
let sim = vsa::cosine_similarity(&query_result, &animal);
// sim should be high (close to 1.0)
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:
cargo bench -p trit-vsa
Full API documentation: docs.rs/trit-vsa
MIT License - see LICENSE for details.