pertaro
Pruned Expert Regrounding Trie via Answer-set Reduct Optimization.
pertaro is a #![no_std], zero-dependency, zero-heap Rust primitive for cache-resident neuro-symbolic inference and bounded-horizon state planning. It packs an entire 5-tier ternary decision trie (3^5 = 243 leaves), an 8-byte deterministic PRNG seed, a 4-byte lineage link, and a 13-state in-band control envelope (243..=255) into an exact 256-byte cache-aligned word (Word256).
Core Architecture: The 243 + 13 = 256 Isomorphism
A single byte (u8) has 256 possible states (0..=255). pertaro partitions both the value space of a byte and the structural layout of a 256-byte cache block along the exact same boundary:
- Coordinate Space (
0..243): A 1-in, 3-out ternary trie expanded across 5 tiers yields 3^5 = 243 leaves (MAX_PACKED = 243). Values0..243represent packed 5-trit coordinates or modular residual deltas in Z_243. - In-Band Control Envelope (
243..=255): The remaining 13 byte values (SENTINEL_COUNT = 13) act as in-band non-monotonic control sentinels directly inside the payload:243(Sentinel::NullNode): Terminal Answer Set leaf. The deterministicxorshift64(seed)default prior holds at zero delta cost.244(Sentinel::MersenneOverflow): Out-of-band arithmetic overflow marker.245(Sentinel::Tombstone): Branch defeated by integrity constraints under the Gelfond-Lifschitz reduct.246(Sentinel::BusIndirect): Horizon boundary trigger signalling a Tier-5 reground jump.247..=255(Sentinel::Phase5..Sentinel::Phase13): Horizon / phase anchors.
Exact 256-Byte Header-First Memory Layout
Every Word256 / PertaroExpert243 instance is aligned to 256 bytes (#[repr(C, align(256))], four 64-byte CPU cache lines) with compile-time verified field offsets:
| Byte Offset | Size | Field | Description |
|---|---|---|---|
0..8 |
8 B | hash: u64 |
Deterministic xorshift64 seed and FNV-1a content signature |
8..12 |
4 B | parent: u32 |
Lineage link to the parent 5-tier horizon word |
12..255 |
243 B | trits[0..243] |
3^5 = 243 ternary trie leaf deltas (0..243) or in-band Sentinels (243..=255) |
255 |
1 B | trits[243] |
Active root_sentinel / horizon phase byte (243..=255) |
| Total | 256 B | Word256 |
128 complete 5-tier trees fit inside a single 32 KB L1 data cache |
Quick Start
This example ships as examples/quick_start.rs and is compiled by cargo check --examples.
use ;
Key Guarantees
- Unbiased radix-243 extraction. Because 2438 = 340 = 12,157,665,459,056,928,801 < 264,
materialize()extracts 8 independent, strictly unbiased base-243 coordinates (0..243) perxorshift64word by rejection sampling below 2438, avoidingu8 % 243modulo bias entirely. - Strict const bounds.
trie_indexenforces tier digits in0..3andreground_seedenforces winning leaves in0..243, so a sentinel is never folded as a leaf. - Zero unsafe, zero heap.
#![no_std]and#![forbid(unsafe_code)], with no dynamic memory allocation anywhere.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.