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