| Crates.io | chip_as_code |
| lib.rs | chip_as_code |
| version | 0.1.0 |
| created_at | 2026-01-13 20:29:40.435172+00 |
| updated_at | 2026-01-13 20:29:40.435172+00 |
| description | Semantic Chips β deterministic boolean circuits as text DNA. Parse, evaluate, evolve, and prove policy gates with No-Guess constitutional checkpoints. |
| homepage | https://logline.foundation |
| repository | https://github.com/danvoulez/chip-as-code |
| max_upload_size | |
| id | 2041139 |
| size | 319,707 |
Semantic Chips β Computation as Text DNA
Deterministic boolean circuits you can read, evolve, and prove.
Overview β’ Installation β’ Quick Start β’ DNA Format β’ GateBox β’ Evolution β’ API
chip_as_code implements the Chip as Code paradigm: policy logic as compilable, auditable, and evolvable text files.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β SEMANTIC CHIP β
β β
β CHIP v0 βββββ β
β FEATURES n=3 f0ββββΆβANDββββ β
β GATES m=1 f1ββββΆβ β β βββββ β
β g0 = AND(f0,f1,f2) f2ββββΆβββββ βββββΆβOUTββββΆ 0|1 β
β OUTPUT = g0 g0βββΆβ β β
β βββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
| Feature | Description |
|---|---|
| π Text DNA | Human-readable .chip files define boolean circuits |
| π Deterministic | Same input β same output, always |
| 𧬠Evolvable | Discrete evolution learns circuits from data |
| βοΈ No-Guess Law | GateBox enforces constitutional checkpoints |
| π Provable | BLAKE3 hashes + JSONβ―Atomic CIDs for every artifact |
[dependencies]
chip_as_code = "0.1" # This crate
logline = "0.1" # TDLN + JSONβ―Atomic bundle
ubl-ledger = "0.1" # Append-only canonical ledger
All crates by danvoulez
[dependencies]
chip_as_code = "0.1"
cargo install chip_as_code
# Run the demo (commit, ghost, reject scenarios)
chip demo
# Evolve a chip that learns XOR
chip evolve --task xor --seed 1337 --generations 100
# Verify the result
chip replay --task xor --seed 1337 --chip out/best_chip.txt
# Check the golden reference
chip replay --task xor --seed 1337 --chip examples/xor_golden.chip
use chip_as_code::{Chip, ChipHash};
fn main() -> anyhow::Result<()> {
// Parse a chip from text
let source = r#"
CHIP v0
FEATURES n=2
GATES m=3
g0 = NOT(f1)
g1 = AND(f0,g0)
g2 = NOT(f0)
OUTPUT = g1
"#;
let chip = Chip::parse(source)?;
// Evaluate against features
let features = vec![true, false]; // f0=1, f1=0
let result = chip.eval(&features)?;
println!("Result: {}", result); // true
// Get the canonical hash
let hash = chip.hash();
println!("Hash: blake3:{}", hash);
Ok(())
}
Chips are defined in .chip files with a simple, deterministic grammar:
CHIP v0
FEATURES n=<N>
GATES m=<M>
g0 = OP(inputs...)
g1 = OP(inputs...)
...
OUTPUT = gK
| Operator | Syntax | Description |
|---|---|---|
AND |
AND(a,b,c,...) |
All inputs must be true |
OR |
OR(a,b,c,...) |
At least one input true |
NOT |
NOT(a) |
Negate single input |
THRESH |
THRESH(k,a,b,c,...) |
At least k inputs true |
f0, f1, ... fN-1 β Input featuresg0, g1, ... gM-1 β Gate outputs (must reference earlier gates only)CHIP v0
FEATURES n=2
GATES m=5
g0 = NOT(f1)
g1 = AND(f0,g0)
g2 = NOT(f0)
g3 = AND(g2,f1)
g4 = OR(g1,g3)
OUTPUT = g4
This implements: XOR(f0, f1) = OR(AND(f0, NOT(f1)), AND(NOT(f0), f1))
chip_hash = blake3(json_atomic_canonical_bytes(chip_ast))
Whitespace doesn't affect the hash. Two chips with the same logic have the same hash.
The GateBox is a constitutional checkpoint that enforces the No-Guess Law:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β GATEBOX β
β β
β Intent βββββββ β
β β ββββββββββββββββββββββββββββββββββββ β
β Evidence βββββΌββββΆβ 1. Missing evidence? β GHOST β β
β β β 2. Unanchored? β REJECT β β
β Policy βββββββ β 3. Policy fails? β REJECT β β
β (chip) β 4. Otherwise β COMMIT β β
β ββββββββββββββββββββββββββββββββββββ β
β β β
β βΌ β
β ββββββββββββββββ β
β β Ledger β β
β β (NDJSON) β β
β ββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
| Verdict | When | Ledger Append |
|---|---|---|
| Commit | All evidence present, anchored, policy passes | β Yes |
| Ghost | Missing supporting evidence | β Yes (with question) |
| Reject | Unanchored evidence OR policy fails | β No |
use chip_as_code::gatebox::{run_gate, GateVerdict};
let verdict = run_gate(
"intent.json",
"evidence.json",
"policy.chip",
"ledger.ndjson"
)?;
match verdict {
GateVerdict::Commit { cid_hex, chip_hash, proof } => {
println!("β
Committed: {}", cid_hex);
}
GateVerdict::Ghost { question } => {
println!("β Need more info: {}", question);
}
GateVerdict::Reject { reason } => {
println!("β Rejected: {}", reason);
}
}
EvoChip learns boolean circuits from labeled data using discrete evolution β no gradients, no floats in the core.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β EVOLUTION β
β β
β Dataset βββΆ ββββββββββββ ββββββββββββ ββββββββββ β
β βPopulationβββββΆβ Evaluate βββββΆβ Select β β
β β (chips) β β (fitness)β β (elite)β β
β ββββββββββββ ββββββββββββ ββββββ¬ββββ β
β β² β β
β β ββββββββββββ β β
β βββββββββββ Mutate βββββββββββ β
β β Crossoverβ β
β ββββββββββββ β
β β
β Output: best_chip.txt + training_curve.ndjson β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
chip evolve \
--task xor \
--seed 1337 \
--generations 200 \
--population 2000 \
--elite 50 \
--max-gates 32
| File | Description |
|---|---|
out/best_chip.txt |
Best evolved chip (canonical DNA) |
out/training_curve.ndjson |
Per-generation metrics |
out/lineage.ndjson |
Offspring lineage (who came from whom) |
out/replay_report.json |
Deterministic replay proof |
out/dataset.ndjson |
Training/test data (transparency) |
Same seed + Same command = Identical artifacts
ChaCha20Rng with explicit seed/// A semantic chip (boolean circuit)
pub struct Chip {
pub features: usize,
pub gates: Vec<Gate>,
pub output: Ref,
}
/// A gate operation
pub enum GateOp {
And(Vec<Ref>),
Or(Vec<Ref>),
Not(Ref),
Threshold { k: usize, inputs: Vec<Ref> },
}
/// Reference to a feature or gate
pub enum Ref {
Feature(usize),
Gate(usize),
}
impl Chip {
/// Parse from text DNA
pub fn parse(text: &str) -> Result<Self, ChipParseError>;
/// Evaluate against feature vector
pub fn eval(&self, features: &[bool]) -> Result<bool, EvalError>;
/// Get canonical BLAKE3 hash
pub fn hash(&self) -> ChipHash;
/// Serialize to canonical text DNA
pub fn to_dna(&self) -> String;
/// Generate random chip
pub fn random<R: Rng>(rng: &mut R, features: usize, max_gates: usize) -> Self;
/// Mutate chip (for evolution)
pub fn mutate<R: Rng>(&self, rng: &mut R, rate_per10k: u32) -> Self;
}
chip_as_code β Semantic Chips CLI
USAGE:
chip <COMMAND>
COMMANDS:
demo Run 4 GateBox scenarios (commit, ghost, rejectΓ2)
gate Single GateBox decision
verify Verify ledger CIDs
evolve Evolve a chip from data
replay Replay chip against dataset
stats Show dataset statistics
help Print help
OPTIONS:
-h, --help Print help
-V, --version Print version
# Evolve XOR with custom params
chip evolve --task xor --seed 42 --generations 500 --population 5000
# Verify a ledger file
chip verify --ledger out/ledger.ndjson
# Single gate decision
chip gate \
--intent examples/intent_good.json \
--evidence examples/evidence_good.json \
--policy examples/policy.txt \
--ledger out/ledger.ndjson
chip_as_code/
βββ src/
β βββ lib.rs # Public API exports
β βββ chip_ir.rs # Chip parsing, evaluation, hashing
β βββ evolve.rs # Discrete evolution engine
β βββ gatebox.rs # No-Guess Law checkpoint
β βββ gpu_eval.rs # Optional GPU acceleration
β βββ main.rs # CLI
βββ examples/
β βββ xor_golden.chip
β βββ policy.txt
β βββ intent_*.json
β βββ evidence_*.json
βββ out/ # Generated artifacts
# Run tests
cargo test
# Run with debug output
cargo run -- evolve --task xor --seed 1337 --debug
# Build with GPU support
cargo build --release --features gpu
Licensed under either of:
at your option.
Part of the LogLine Foundation ecosystem
chip_as_code β’ logline β’ json_atomic β’ tdln-* β’ ubl-ledger