|
|
--- |
|
|
license: mit |
|
|
tags: |
|
|
- formal-verification |
|
|
- coq |
|
|
- threshold-logic |
|
|
- neuromorphic |
|
|
--- |
|
|
|
|
|
# tiny-2OutOf8-verified |
|
|
|
|
|
Formally verified 2-out-of-8 threshold gate. Single threshold neuron with 100% accuracy. |
|
|
|
|
|
## Architecture |
|
|
|
|
|
| Component | Value | |
|
|
|-----------|-------| |
|
|
| Inputs | 8 | |
|
|
| Outputs | 1 | |
|
|
| Neurons | 1 | |
|
|
| Parameters | 9 | |
|
|
| Weights | [1, 1, 1, 1, 1, 1, 1, 1] | |
|
|
| Bias | -2 | |
|
|
| Activation | Heaviside step | |
|
|
|
|
|
## Key Properties |
|
|
|
|
|
- 100% accuracy (256/256 inputs correct) |
|
|
- Coq-proven correctness |
|
|
- Single threshold neuron |
|
|
- Integer weights |
|
|
- Fires when at least 2 of 8 inputs are true |
|
|
|
|
|
|
|
|
## Usage |
|
|
|
|
|
```python |
|
|
import torch |
|
|
from safetensors.torch import load_file |
|
|
|
|
|
weights = load_file('twooutof8.safetensors') |
|
|
|
|
|
def twooutof8_gate(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 >= 0) |
|
|
|
|
|
# Test |
|
|
print({func}_gate([0,0,0,0,0,0,0,0])) # 0 (0/2, below threshold) |
|
|
print({func}_gate([1,0,0,0,0,0,0,0])) # 0 (1/8, below threshold) |
|
|
print({func}_gate([1,1,0,0,0,0,0,0])) # 1 (2/8, at threshold) |
|
|
print(twooutof8_gate([1,1,1,1,1,1,1,1])) # 1 (8/8, above threshold) |
|
|
``` |
|
|
|
|
|
## Verification |
|
|
|
|
|
**Coq Theorem**: |
|
|
```coq |
|
|
Theorem twoout_eight_correct : forall x0 x1 x2 x3 x4 x5 x6 x7, |
|
|
twoout_eight_circuit [x0; x1; x2; x3; x4; x5; x6; x7] = |
|
|
twoout_eight_spec [x0; x1; x2; x3; x4; x5; x6; x7]. |
|
|
``` |
|
|
|
|
|
Proven axiom-free via: |
|
|
1. **Exhaustive**: All 256 inputs verified |
|
|
2. **Universal**: Quantified proof over boolean combinations |
|
|
3. **Algebraic**: Hamming weight ≥ 2 |
|
|
|
|
|
Full proof: [coq-circuits/Threshold/TwoOutOfEight.v](https://github.com/CharlesCNorton/coq-circuits/blob/main/coq/Threshold/TwoOutOfEight.v) |
|
|
|
|
|
## Circuit Operation |
|
|
|
|
|
Input with h true bits (Hamming weight h): |
|
|
- Weighted sum: h - 2 |
|
|
- Output: 1 if h ≥ 2, else 0 |
|
|
|
|
|
## Citation |
|
|
|
|
|
```bibtex |
|
|
@software{tiny_2outof8_prover_2025, |
|
|
title={tiny-2OutOf8-verified: Formally Verified 2-out-of-8 threshold gate}, |
|
|
author={Norton, Charles}, |
|
|
url={https://huggingface.co/phanerozoic/tiny-2OutOf8-verified}, |
|
|
year={2025} |
|
|
} |
|
|
``` |
|
|
|