threshold-or3 / README.md
CharlesCNorton
Add optimality note: exhaustive enumeration confirms magnitude 4 is minimum
0cca55a
---
license: mit
tags:
- pytorch
- safetensors
- threshold-logic
- neuromorphic
---
# threshold-or3
3-input OR gate. Fires when at least one input is active. The 1-of-3 threshold gate.
## Circuit
```
a b c
β”‚ β”‚ β”‚
β””β”€β”€β”€β”Όβ”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ w: 1,1,1β”‚
β”‚ b: -1 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
OR(a,b,c)
```
## The Existence Test
3-input OR detects "at least one active":
| Inputs | Sum | Output |
|--------|-----|--------|
| **000** | **-1** | **0** |
| 001 | 0 | 1 |
| 010 | 0 | 1 |
| 011 | +1 | 1 |
| 100 | 0 | 1 |
| 101 | +1 | 1 |
| 110 | +1 | 1 |
| 111 | +2 | 1 |
Only complete silence fails.
## Same Weights, Different Threshold
AND and OR use identical weights but different biases:
| Gate | Weights | Bias | Meaning |
|------|---------|------|---------|
| OR(a,b,c) | [1, 1, 1] | -1 | Need 1+ vote |
| MAJ(a,b,c) | [1, 1, 1] | -2 | Need 2+ votes |
| AND(a,b,c) | [1, 1, 1] | -3 | Need 3 votes |
The bias is the threshold. OR is the most permissive.
## De Morgan Dual
OR(a,b,c) = NOT(AND(NOT(a), NOT(b), NOT(c)))
But threshold logic computes OR directly - no inversion needed.
## Parameters
| Component | Value |
|-----------|-------|
| Weights | [1, 1, 1] |
| Bias | -1 |
| **Total** | **4 parameters** |
## Optimality
Exhaustive enumeration of all 321 weight configurations at magnitudes 0-4 confirms this circuit is **already at minimum magnitude (4)**. There is exactly one valid configuration at magnitude 4, and no valid configurations exist below it.
## Usage
```python
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def or3(a, b, c):
inp = torch.tensor([float(a), float(b), float(c)])
return int((inp * w['weight']).sum() + w['bias'] >= 0)
print(or3(0, 0, 1)) # 1
print(or3(0, 0, 0)) # 0
```
## Files
```
threshold-or3/
β”œβ”€β”€ model.safetensors
β”œβ”€β”€ model.py
β”œβ”€β”€ config.json
└── README.md
```
## License
MIT