Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
269 items
β’
Updated
β’
1
3-input XOR gate at optimal magnitude 10.
Exhaustive search over 387,328,512 configurations proved magnitude 10 is optimal for XOR3. This flat 2-layer architecture beats the cascade approach (magnitude 14) by 29%.
| Architecture | Neurons | Params | Magnitude |
|---|---|---|---|
| Cascade (2ΓXOR) | 6 | 18 | 14 |
| Flat 3-hidden | 4 | 16 | 10 |
a βββ
b βββΌβββΊ [h1] βββ
c βββ [h2] βββΌβββΊ [out] βββΊ XOR3(a,b,c)
[h3] βββ
Single hidden layer with 3 neurons, all biases = 0.
18 solutions exist at magnitude 10, related by input permutation and neuron reordering symmetry.
| Solution | h1 weights | h2 weights | h3 weights | out weights |
|---|---|---|---|---|
| 1 | [-1,0,0] | [-1,-1,1] | [-1,1,-1] | [1,-1,-1] |
| 2 | [-1,0,0] | [-1,1,-1] | [-1,-1,1] | [1,-1,-1] |
| 3 | [0,-1,0] | [-1,-1,1] | [1,-1,-1] | [1,-1,-1] |
| 4 | [0,-1,0] | [1,-1,-1] | [-1,-1,1] | [1,-1,-1] |
| 5 | [0,0,-1] | [-1,1,-1] | [1,-1,-1] | [1,-1,-1] |
| 6 | [0,0,-1] | [1,-1,-1] | [-1,1,-1] | [1,-1,-1] |
| 7 | [-1,-1,1] | [-1,0,0] | [-1,1,-1] | [-1,1,-1] |
| 8 | [-1,-1,1] | [0,-1,0] | [1,-1,-1] | [-1,1,-1] |
| 9 | [-1,1,-1] | [-1,0,0] | [-1,-1,1] | [-1,1,-1] |
| 10 | [-1,1,-1] | [0,0,-1] | [1,-1,-1] | [-1,1,-1] |
| 11 | [1,-1,-1] | [0,-1,0] | [-1,-1,1] | [-1,1,-1] |
| 12 | [1,-1,-1] | [0,0,-1] | [-1,1,-1] | [-1,1,-1] |
| 13 | [-1,-1,1] | [-1,1,-1] | [-1,0,0] | [-1,-1,1] |
| 14 | [-1,-1,1] | [1,-1,-1] | [0,-1,0] | [-1,-1,1] |
| 15 | [-1,1,-1] | [-1,-1,1] | [-1,0,0] | [-1,-1,1] |
| 16 | [-1,1,-1] | [1,-1,-1] | [0,0,-1] | [-1,-1,1] |
| 17 | [1,-1,-1] | [-1,-1,1] | [0,-1,0] | [-1,-1,1] |
| 18 | [1,-1,-1] | [-1,1,-1] | [0,0,-1] | [-1,-1,1] |
Six unique neuron types appear across solutions:
| Type | Weights | Function |
|---|---|---|
| Sel-a | [-1,0,0] | fires when a=0 |
| Sel-b | [0,-1,0] | fires when b=0 |
| Sel-c | [0,0,-1] | fires when c=0 |
| XOR-ab | [-1,-1,1] | fires when c>(a+b) |
| XOR-ac | [-1,1,-1] | fires when b>(a+c) |
| XOR-bc | [1,-1,-1] | fires when a>(b+c) |
threshold-xor3-mag10/
βββ model.safetensors (default = solution1)
βββ solution1.safetensors
βββ solution2.safetensors
βββ ...
βββ solution18.safetensors
βββ model.py
βββ config.json
βββ README.md
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors') # or solution1-18
def xor3(a, b, c):
inp = torch.tensor([float(a), float(b), float(c)])
h1 = int((inp * w['h1.weight']).sum() + w['h1.bias'] >= 0)
h2 = int((inp * w['h2.weight']).sum() + w['h2.bias'] >= 0)
h3 = int((inp * w['h3.weight']).sum() + w['h3.bias'] >= 0)
hidden = torch.tensor([float(h1), float(h2), float(h3)])
return int((hidden * w['out.weight']).sum() + w['out.bias'] >= 0)
MIT