π² chip_as_code
Semantic Chips β Computation as Text DNA
Deterministic boolean circuits you can read, evolve, and prove.
Overview β’ Installation β’ Quick Start β’ DNA Format β’ GateBox β’ Evolution β’ API
Overview
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βββΆβ β β
β βββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Key Features
| 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 |
Part of the LogLine Ecosystem
[]
= "0.1" # This crate
= "0.1" # TDLN + JSONβ―Atomic bundle
= "0.1" # Append-only canonical ledger
All crates by danvoulez
Installation
As a library
[]
= "0.1"
As a CLI
Quick Start
30 seconds to your first chip
# Run the demo (commit, ghost, reject scenarios)
# Evolve a chip that learns XOR
# Verify the result
# Check the golden reference
Use as a library
use ;
DNA Format
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
Operators
| 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 |
References
f0,f1, ...fN-1β Input featuresg0,g1, ...gM-1β Gate outputs (must reference earlier gates only)
Example: XOR Gate
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))
Canonical Identity
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.
GateBox
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) β β
β ββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Verdicts
| 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 |
Usage
use ;
let verdict = run_gate?;
match verdict
Evolution
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 β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
CLI
Outputs
| 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) |
Determinism Guarantee
Same seed + Same command = Identical artifacts
- RNG:
ChaCha20Rngwith explicit seed - Fitness: Integer per10k accuracy (no floats in core)
- Hashes: BLAKE3 over JSONβ―Atomic canonical bytes
API
Core Types
/// A semantic chip (boolean circuit)
/// A gate operation
/// Reference to a feature or gate
Key Methods
CLI Reference
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
Examples
# Evolve XOR with custom params
# Verify a ledger file
# Single gate decision
Architecture
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
Contributing
# Run tests
# Run with debug output
# Build with GPU support
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.
Part of the LogLine Foundation ecosystem
chip_as_code β’ logline β’ json_atomic β’ tdln-* β’ ubl-ledger