Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
269 items
β’
Updated
β’
1
Symmetric function S_2^3: outputs 1 if and only if exactly 2 of 3 inputs are 1.
S_2^3(x2, x1, x0) = 1 iff (x2 + x1 + x0) = 2
Symmetric functions are invariant under input permutation.
| x2 | x1 | x0 | sum | y |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 0 | 1 | 0 |
| 0 | 1 | 1 | 2 | 1 |
| 1 | 0 | 0 | 1 | 0 |
| 1 | 0 | 1 | 2 | 1 |
| 1 | 1 | 0 | 2 | 1 |
| 1 | 1 | 1 | 3 | 0 |
x2 x1 x0
β β β
ββββββ΄βββββ
β
ββββββ΄βββββ
β β
βΌ βΌ
βββββββ βββββββ
β>=2 β β<=2 β Layer 1
βββββββ βββββββ
β β
βββββ¬βββββ
β
βΌ
βββββββ
β AND β Layer 2
βββββββ
β
βΌ
y
| Inputs | 3 |
| Outputs | 1 |
| Neurons | 3 |
| Layers | 2 |
| Parameters | 11 |
| Magnitude | 14 |
The general symmetric function S_k^n outputs 1 iff exactly k of n inputs are 1. Special cases:
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def s23(x2, x1, x0):
inp = torch.tensor([float(x2), float(x1), float(x0)])
al2 = int((inp @ w['at_least_2.weight'].T + w['at_least_2.bias'] >= 0).item())
am2 = int((inp @ w['at_most_2.weight'].T + w['at_most_2.bias'] >= 0).item())
l1 = torch.tensor([float(al2), float(am2)])
return int((l1 @ w['y.weight'].T + w['y.bias'] >= 0).item())
# s23(1, 1, 0) = 1 # exactly 2 of 3
# s23(1, 1, 1) = 0 # 3 of 3, not exactly 2
MIT