Tiny Verified Logic Circuits
Collection
Formally verified threshold logic circuits. Compatible with neuromorphic hardware.
•
33 items
•
Updated
Formally verified MOD-9 circuit. Single-layer threshold network computing modulo-9 arithmetic with 100% accuracy.
| Component | Value |
|---|---|
| Inputs | 8 |
| Outputs | 1 (per residue class) |
| Neurons | 9 (one per residue 0-8) |
| Parameters | 81 (9 × 9) |
| Weights | [1, 1, 1, 1, 1, 1, 1, 1] |
| Bias | 0 |
| Activation | Heaviside step |
MOD-9 uses all-ones weights because the reset position (position 9) is beyond the 8-bit input width:
The circuit tracks cumulative sum mod 9 using the Hamming weight directly.
import torch
from safetensors.torch import load_file
weights = load_file('mod9.safetensors')
def mod9_circuit(bits):
# bits: list of 8 binary values
inputs = torch.tensor([float(b) for b in bits])
weighted_sum = (inputs * weights['weight']).sum() + weights['bias']
# Weighted sum equals Hamming weight for all-ones weights
return int(weighted_sum.item()) % 9
# Test
print(mod9_circuit([1,1,1,1,1,1,1,1])) # 8 mod 9 = 8
print(mod9_circuit([1,1,1,1,1,1,1,1])) # 8 mod 9 = 8
Coq Theorem:
Theorem mod9_correct_residue_0 : forall x0 x1 x2 x3 x4 x5 x6 x7,
mod9_is_zero [x0; x1; x2; x3; x4; x5; x6; x7] =
Z.eqb ((Z.of_nat (hamming_weight [x0; x1; x2; x3; x4; x5; x6; x7])) mod 9) 0.
Proven axiom-free using algebraic weight patterns.
Full proof: coq-circuits/Modular/Mod9.v
For 8-bit inputs (256 total):
@software{tiny_mod9_verified_2025,
title={tiny-mod9-verified: Formally Verified MOD-9 Circuit},
author={Norton, Charles},
url={https://huggingface.co/phanerozoic/tiny-mod9-verified},
year={2025}
}