Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks. β’ 269 items β’ Updated
β’ 1
Symmetric function S_{1,3}^4: outputs 1 if exactly 1 or exactly 3 of 4 inputs are 1. Equivalent to 4-bit odd parity.
S_{1,3}^4(x3, x2, x1, x0) = 1 iff sum β {1, 3}
This is the "odd count" function on 4 bits.
| x3 | x2 | x1 | x0 | sum | y |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 1 | 1 | 1 |
| 0 | 0 | 1 | 1 | 2 | 0 |
| 0 | 1 | 1 | 1 | 3 | 1 |
| 1 | 1 | 1 | 1 | 4 | 0 |
Output is 1 for odd sums (1, 3), 0 for even sums (0, 2, 4).
x3 x2 x1 x0
β
ββββββ΄βββββ
β β
βββββ΄ββββ βββββ΄ββββ
β >=1 β β <=1 β β >=3 β β <=3 β Layer 1
βββββ¬ββββ βββββ¬ββββ βββββ¬ββββ βββββ¬ββββ
β β β β
ββββββ¬βββββ ββββββ¬βββββ
β β
βββββ΄ββββ βββββ΄ββββ
β AND β β AND β Layer 2
βexact=1β βexact=3β
βββββ¬ββββ βββββ¬ββββ
β β
βββββββββββ¬ββββββββββ
β
βββββ΄ββββ
β OR β Layer 3
βββββ¬ββββ
β
y
| Inputs | 4 |
| Outputs | 1 |
| Neurons | 7 |
| Layers | 3 |
| Parameters | 33 |
| Magnitude | 35 |
S_{1,3}^4 is equivalent to 4-bit parity (XOR of all bits). However, this implementation uses threshold counting rather than XOR decomposition, demonstrating an alternative approach.
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
# Full implementation in model.py
# s134(0, 1, 1, 1) = 1 # sum=3, odd
# s134(1, 1, 0, 0) = 0 # sum=2, even
MIT