A 4-of-4 threshold gate. All four inputs must be active to reach the firing threshold.
x1 x2 x3 x4
│ │ │ │
└───┴───┴───┘
│
▼
┌─────────┐
│w: 1,1,1,1│
│ b: -4 │
└─────────┘
│
▼
AND4(x1,x2,x3,x4)
Each input contributes +1 to the sum. The bias of -4 means exactly four contributions are required to reach zero:
Only the all-ones input reaches the threshold.
This circuit is at minimum magnitude (8). The pattern generalizes: n-input AND requires weights all 1 and bias -n, giving magnitude 2n.
1from safetensors.torch import load_file
2import torch
3
4w = load_file('model.safetensors')
5
6def and4_gate(x1, x2, x3, x4):
7 inputs = torch.tensor([float(x1), float(x2), float(x3), float(x4)])
8 return int((inputs * w['weight']).sum() + w['bias'] >= 0)
9
10# Test
11assert and4_gate(1, 1, 1, 1) == 1
12assert and4_gate(1, 1, 1, 0) == 0
13assert and4_gate(0, 0, 0, 0) == 0
threshold-and4/
├── model.safetensors
├── model.py
├── config.json
├── create_safetensors.py
└── README.md