Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks. • 269 items • Updated • 1
Computes Hamming weight mod 6 directly on inputs. Single-layer circuit.
x₀ x₁ x₂ x₃ x₄ x₅ x₆ x₇
│ │ │ │ │ │ │ │
│ │ │ │ │ │ │ │
w: 1 1 1 1 1 -5 1 1
└──┴──┴──┴──┼──┴──┴──┴──┘
▼
┌─────────┐
│ b: 0 │
└─────────┘
│
▼
HW mod 6
For 8 inputs and mod 6, position 6 gets weight 1-6 = -5:
HW=0: sum=0 → 0 mod 6
HW=1: sum=1 → 1 mod 6
...
HW=5: sum=5 → 5 mod 6
HW=6: sum=0 → 0 mod 6 (reset)
HW=7: sum=1 → 1 mod 6
HW=8: sum=2 → 2 mod 6
| Weights | [1, 1, 1, 1, 1, -5, 1, 1] |
| Bias | 0 |
| Total | 9 parameters |
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def mod6(bits):
inputs = torch.tensor([float(b) for b in bits])
return int((inputs * w['weight']).sum() + w['bias'])
threshold-mod6/
├── model.safetensors
├── model.py
├── config.json
└── README.md
MIT