Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
153 items
β’
Updated
Computes Hamming weight mod 8 directly on inputs. Single-layer circuit.
xβ xβ xβ xβ xβ xβ
xβ xβ
β β β β β β β β
β β β β β β β β
w: 1 1 1 1 1 1 1 -7
ββββ΄βββ΄βββ΄βββΌβββ΄βββ΄βββ΄βββ
βΌ
βββββββββββ
β b: 0 β
βββββββββββ
β
βΌ
HW mod 8
Position 8 gets weight 1-8 = -7:
HW=0: sum=0 β 0 mod 8
...
HW=7: sum=7 β 7 mod 8
HW=8: sum=0 β 0 mod 8 (reset: 1+1+1+1+1+1+1-7=0)
The only non-trivial case is HW=8, which resets to 0.
| Weights | [1, 1, 1, 1, 1, 1, 1, -7] |
| Bias | 0 |
| Total | 9 parameters |
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def mod8(bits):
inputs = torch.tensor([float(b) for b in bits])
return int((inputs * w['weight']).sum() + w['bias'])
threshold-mod8/
βββ model.safetensors
βββ model.py
βββ config.json
βββ README.md
MIT