3 Building Primitives and Programs: Canonical Examples
The Monist Engine uses its hybrid synthetic pipeline to map complex paradoxes and mathematical programs down into topological constraints. By examining the canonical examples located in tools/monist-examples/src/bin, we can demonstrate how to build primitives, tests, and self-referential programs using this architecture.
Note: While end-users typically will write high-level logic interactively via the CLI, developers building custom primitives or integrating Monist into larger distributed systems interact directly with the underlying GraphArena Rust API, as shown in these examples.
3.1 1. Russell’s Paradox: Capturing Extensionality Collisions
Russell’s Paradox represents the most direct violation of typical topological bounds. The engine intercepts this before compiling into combinators by mapping the recursive self-membership constraint into a negative-weight geometric loop.
3.1.1 Primitives
The core primitive here is the structural definition of membership (in), which mandates a +1 type elevation, while a self-mapping creates a simultaneous -1 constraint to bridge the gap.
// From tools/monist-examples/src/bin/russell.rs
let mut arena = GraphArena::new();
let r_var = ScopedVar(Var::Free("R".to_string()), 0);
let u = arena.add_var(r_var.clone());
// Add R in R boundaries
arena.edges.push((u, u, 1, true));
arena.edges.push((u, u, -1, true));3.1.2 Execution & Testing
When passed to the monist-core geometry solver, the ExecutionLimits::compute_for_graph or bellman_ford routing immediately tracks the \(K\)-Iteration depth limits. The paradox halts structurally:
if let Some(limits) = ExecutionLimits::compute_for_graph(&arena) {
if limits.mcm < 0.0 {
println!("[SUCCESS] Extensionality Collision structurally intercepted!");
}
}3.2 2. Specker’s Refutation of Global Choice
A far more complex programmatic boundary is Specker’s sequence, attempting to map global choice across a sequence of distinct cardinal topologies without stabilizing via a \(T\)-functor.
3.2.1 Primitives
This requires parsing dense, nested implications into a unified geometric DAG. The CLI or Rust programmatic string bindings convert the human interface directly into the constraint mapping layer.
// From tools/monist-examples/src/bin/specker_refutation.rs
let specker_formula = "{ F | (((m in F /\\ p1 in F) /\\ p2 in F) /\\ (z in p1 -> (w in z -> w in m))) /\\ (z2 in p2 -> (w2 in z2 -> w2 in p1)) }";3.2.2 Execution & Testing
The AST string is parsed, producing structural bounds. The nodes are structurally evaluated until they collapse into an unstratified loop. The diagnostic framework generates an SMT-LIB witness, piping out the precise vertex graph to formally prove the failure across \(m\), \(2^m\), and \(2^{2^m}\) cardinal spaces.
3.3 3. Agentic Reflection & Principle of Least Syntactic Action
When interacting with agentic loops, the architecture shifts towards the Interaction Net pipeline (monist-comb), leveraging the \(S,K,I\) combinators inside a safe topological boundary (SC_CUT).
3.3.1 Primitives
Using programmatic combinator definitions, we define the computational operation physically. The \(Y\) combinator creates the unstratified self-reference, bypassing normal hierarchical scoping limits.
// From tools/monist-examples/src/bin/agentic_reflection.rs
use monist_comb::comblib::encodings::{v, y_comb};
use monist_comb::ir::Comb;
// A self-referential agent loop constructed natively
let self_referential_agent_loop = y_comb().app(v("agent_step"));3.3.2 Execution & Testing
An AgenticPlanningMatrix is used to map alternative combinatory routes. By using the “Principle of Least Syntactic Action,” the agent evaluates the paths statically prior to execution:
let selected_path = planning_matrix.principle_of_least_syntactic_action();When handed off to the engine, it performs lock-free XOR collisions across parallel CPU/GPU threads (simulating the Holographic physics layer limit) ensuring the coreclusive interactions rapidly decay without mutating memory pointers globally.
3.4 4. Dispatching to the GPU Physics Backend
The previous examples covered the CPU geometry layer (GraphArena, bellman_ford) and the combinator layer (y_comb, v, abstract_var). This example introduces the final step: compiling a combinator term into a GNet Interaction Net and dispatching it to the WGPU physics backend for lock-free parallel evaluation.
The working demo (proteomic_autocatalysis.rs) models a cyclic kinase cascade — a domain where traditional type-checkers would diverge. After intercepting the cycle geometrically (Section 1’s API), it synthesizes a \(Y\)-combinator fixpoint and hands it to the GPU.
3.4.1 Combinator Synthesis
// From tools/monist-examples/src/bin/proteomic_autocatalysis.rs
use monist_comb::comblib::encodings::{v, y_comb};
let kinase_step = v("catalyst")
.app(v("f").app(v("kinase")))
.abstract_var("f");
let pathway_oscillator = y_comb().app(kinase_step);3.4.2 GPU Dispatch
GNet::from_comb serializes the combinator tree into a 32-bit tagged pointer arena. WgpuExecutor::execute dispatches it to the WGSL compute shaders, which perform lock-free CAS graph reduction until no further interactions occur:
use monist_comb::ast::GNet;
use monist_comb::backend::WgpuExecutor;
let net = GNet::from_comb(&pathway_oscillator, 1024 * 1024);
let executor = WgpuExecutor::new();
let (_result_net, state) = executor.execute(&net);
// state.interactions: total graph-rewrite collisions before stabilization
// state.active_nodes: remaining live nodes in the arena
println!("Interactions: {}, Active: {}", state.interactions, state.active_nodes);[HARDWARE] Dispatching biological net to GPU...
[SUCCESS] Oscillator stabilized at 0 unreachable floating rings. Total molecular collisions evaluated: 2003
The state.interactions count directly measures the topological recursion cost of the compiled term — how many annihilation and commutation rewrites the GPU needed before reaching a stable fixpoint. See The Interaction Net Compiler for details on the underlying CAS atomics and cycle garbage collection.
3.5 5. The Holographic Co-processor: VSA Embedding and Discrete Recovery
The Holographic Co-processor provides a continuous-domain alternative to discrete graph evaluation. This example introduces its programmatic API: HDCVector, Codebook, superpose, holographic_exclusion_query, and the pattern for writing custom WGSL shaders that bridge continuous results back into discrete monist-core variables.
The working demo (holographic_genomic_sieve.rs) uses this API to filter transcriptomic noise — but the same pattern applies to any domain where massive discrete search can be replaced by continuous superposition and \(O(1)\) cancellation.
3.5.1 VSA Embedding
HDCVector::random_basis() generates quasi-orthogonal 10,000-dimensional vectors. Codebook provides an associative memory for mapping between labels and vectors. superpose() folds arbitrarily many vectors into a single running sum:
// From tools/monist-examples/src/bin/holographic_genomic_sieve.rs
use monist_comb::comblib::vsa_embed::{Codebook, HDCVector};
let mut codebook = Codebook::new();
let vec_a = HDCVector::random_basis();
codebook.insert("Label_A".to_string(), vec_a.clone());
// Fold N vectors into a single tensor — O(D) per call, O(1) storage
let mut superposed = HDCVector::new();
superposed = superposed.superpose(&vec_a);3.5.2 Destructive Interference
holographic_exclusion_query performs pointwise subtraction — a single \(O(D)\) operation that cancels a known signal from the superposed wave, regardless of how many vectors were folded in:
let residual = patient_tensor.holographic_exclusion_query(&baseline_tensor);3.5.3 Custom WGSL Compute Shaders
When the built-in WgpuExecutor (which runs reduce.wgsl for Interaction Nets) is not the right tool, you can write custom WGSL shaders following the pattern in vsa_gpu_stress.rs. This example dispatches a massively parallel dot-product kernel for Successive Interference Cancellation:
@compute @workgroup_size(256)
fn sic_dot_product(@builtin(global_invocation_id) gid: vec3<u32>) {
let entry_idx = gid.x;
if (entry_idx >= params.x) { return; }
var acc: f32 = 0.0;
let base = entry_idx * params.y;
for (var d = 0u; d < params.y; d = d + 1u) {
acc += residual[d] * codebook[base + d];
}
scores[entry_idx] = acc;
}
3.5.4 Discrete Bridge
Recovered results are snapped back into ScopedVar entries in a GraphArena, completing the continuous→discrete handoff. From this point, the standard monist-core evaluation pipeline (Bellman-Ford, SCC, etc.) can process them:
let mut arena = GraphArena::new();
let var = ScopedVar(Var::Free("EGFR_L858R".into()), 0);
arena.add_var(var);[SUCCESS] Isolated Somatic Mutations: [EGFR_L858R (Confidence: 1.00), KRAS_G12C (Confidence: 0.99)]
3.6 Conclusion
These five examples cover the core API surfaces in execution order: GraphArena constraint geometry (Russell’s), parser string bindings (Specker’s), combinator synthesis (Agentic), GPU Interaction Net dispatch (GNet/WgpuExecutor), and the Holographic Co-processor (HDCVector/Codebook/custom WGSL). Together they form a complete developer reference for building programs on top of the Monist Engine’s hybrid synthetic pipeline.