Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- formal-verification
|
| 5 |
+
- coq
|
| 6 |
+
- threshold-logic
|
| 7 |
+
- neuromorphic
|
| 8 |
+
- modular-arithmetic
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# tiny-mod11-verified
|
| 12 |
+
|
| 13 |
+
Formally verified MOD-11 circuit. Single-layer threshold network computing modulo-11 arithmetic with 100% accuracy.
|
| 14 |
+
|
| 15 |
+
## Architecture
|
| 16 |
+
|
| 17 |
+
| Component | Value |
|
| 18 |
+
|-----------|-------|
|
| 19 |
+
| Inputs | 8 |
|
| 20 |
+
| Outputs | 1 (per residue class) |
|
| 21 |
+
| Neurons | 11 (one per residue 0-10) |
|
| 22 |
+
| Parameters | 99 (11 × 9) |
|
| 23 |
+
| Weights | [1, 1, 1, 1, 1, 1, 1, 1] |
|
| 24 |
+
| Bias | 0 |
|
| 25 |
+
| Activation | Heaviside step |
|
| 26 |
+
|
| 27 |
+
## Key Properties
|
| 28 |
+
|
| 29 |
+
- 100% accuracy (256/256 inputs correct)
|
| 30 |
+
- Coq-proven correctness
|
| 31 |
+
- All-ones weight pattern (m > input width)
|
| 32 |
+
- Computes Hamming weight mod 11
|
| 33 |
+
- Compatible with neuromorphic hardware
|
| 34 |
+
|
| 35 |
+
## Algebraic Pattern
|
| 36 |
+
|
| 37 |
+
MOD-11 uses all-ones weights because the reset position (position 11) is beyond the 8-bit input width:
|
| 38 |
+
- All positions 1-8: weight = 1
|
| 39 |
+
- Position 11 (beyond input): would be weight = 1-11 = -10
|
| 40 |
+
|
| 41 |
+
The circuit tracks cumulative sum mod 11 using the Hamming weight directly.
|
| 42 |
+
|
| 43 |
+
## Usage
|
| 44 |
+
|
| 45 |
+
```python
|
| 46 |
+
import torch
|
| 47 |
+
from safetensors.torch import load_file
|
| 48 |
+
|
| 49 |
+
weights = load_file('mod11.safetensors')
|
| 50 |
+
|
| 51 |
+
def mod11_circuit(bits):
|
| 52 |
+
# bits: list of 8 binary values
|
| 53 |
+
inputs = torch.tensor([float(b) for b in bits])
|
| 54 |
+
weighted_sum = (inputs * weights['weight']).sum() + weights['bias']
|
| 55 |
+
return int(weighted_sum.item()) % 11
|
| 56 |
+
|
| 57 |
+
# Test
|
| 58 |
+
print(mod11_circuit([1,1,1,1,1,1,1,1])) # 8 mod 11 = 8
|
| 59 |
+
print(mod11_circuit([1,1,1,0,0,0,0,0])) # 3 mod 11 = 3
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
## Verification
|
| 63 |
+
|
| 64 |
+
**Coq Theorem**:
|
| 65 |
+
```coq
|
| 66 |
+
Theorem mod11_correct_residue_0 : forall x0 x1 x2 x3 x4 x5 x6 x7,
|
| 67 |
+
mod11_is_zero [x0; x1; x2; x3; x4; x5; x6; x7] =
|
| 68 |
+
Z.eqb ((Z.of_nat (hamming_weight [x0; x1; x2; x3; x4; x5; x6; x7])) mod 11) 0.
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
Proven axiom-free using algebraic weight patterns.
|
| 72 |
+
|
| 73 |
+
Full proof: [coq-circuits/Modular/Mod11.v](https://github.com/CharlesCNorton/coq-circuits/blob/main/coq/Modular/Mod11.v)
|
| 74 |
+
|
| 75 |
+
## Residue Distribution
|
| 76 |
+
|
| 77 |
+
For 8-bit inputs (256 total), limited to residues 0-8:
|
| 78 |
+
- Residue 0: 1 inputs
|
| 79 |
+
- Residue 1: 8 inputs
|
| 80 |
+
- Residue 2: 28 inputs
|
| 81 |
+
- Residue 3: 56 inputs
|
| 82 |
+
- Residue 4: 70 inputs
|
| 83 |
+
- Residue 5: 56 inputs
|
| 84 |
+
- Residue 6: 28 inputs
|
| 85 |
+
- Residue 7: 8 inputs
|
| 86 |
+
- Residue 8: 1 inputs
|
| 87 |
+
- Residues 9-10: 0 inputs (unreachable with 8-bit input)
|
| 88 |
+
|
| 89 |
+
## Citation
|
| 90 |
+
|
| 91 |
+
```bibtex
|
| 92 |
+
@software{tiny_mod11_verified_2025,
|
| 93 |
+
title={tiny-mod11-verified: Formally Verified MOD-11 Circuit},
|
| 94 |
+
author={Norton, Charles},
|
| 95 |
+
url={https://huggingface.co/phanerozoic/tiny-mod11-verified},
|
| 96 |
+
year={2025}
|
| 97 |
+
}
|
| 98 |
+
```
|