Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
248 items
β’
Updated
β’
1
The equality detector. Fires when both inputs match - both 0 or both 1. Like XOR, this function is not linearly separable and requires two layers.
x y
β β
βββββ¬ββββ€
β β β
βΌ β βΌ
βββββββββββββββββ
β NOR βββ AND β Layer 1
βw:-1,-1ββw:1,1 β
βb: 0 βββb: -2 β
βββββββββββββββββ
β β β
βββββΌββββ
βΌ
ββββββββ
β OR β Layer 2
βw: 1,1β
βb: -1 β
ββββββββ
β
βΌ
XNOR(x,y)
XNOR catches equality via two cases:
| x | y | NOR | AND | OR(NOR,AND) |
|---|---|---|---|---|
| 0 | 0 | 1 | 0 | 1 |
| 0 | 1 | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 | 0 |
| 1 | 1 | 0 | 1 | 1 |
XNOR = NOT(XOR). Same non-linear structure, opposite meaning.
| Layer | Weights | Bias |
|---|---|---|
| NOR | [-1, -1] | 0 |
| AND | [1, 1] | -2 |
| OR | [1, 1] | -1 |
| Total | 9 |
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def xnor_gate(x, y):
inp = torch.tensor([float(x), float(y)])
nor_out = int((inp * w['layer1.neuron1.weight']).sum() + w['layer1.neuron1.bias'] >= 0)
and_out = int((inp * w['layer1.neuron2.weight']).sum() + w['layer1.neuron2.bias'] >= 0)
l1 = torch.tensor([float(nor_out), float(and_out)])
return int((l1 * w['layer2.weight']).sum() + w['layer2.bias'] >= 0)
threshold-xnor/
βββ model.safetensors
βββ model.py
βββ config.json
βββ README.md
MIT