metadata
license: mit
tags:
- pytorch
- safetensors
- threshold-logic
- neuromorphic
threshold-and3
3-input AND gate. Fires when all three inputs are active. The 3-of-3 threshold gate.
Circuit
a b c
β β β
βββββΌββββ
β
βΌ
βββββββββββ
β w: 1,1,1β
β b: -3 β
βββββββββββ
β
βΌ
AND(a,b,c)
The Unanimity Requirement
3-input AND is the smallest non-trivial unanimity gate:
| Inputs | Sum | Output |
|---|---|---|
| 000 | -3 | 0 |
| 001 | -2 | 0 |
| 010 | -2 | 0 |
| 011 | -1 | 0 |
| 100 | -2 | 0 |
| 101 | -1 | 0 |
| 110 | -1 | 0 |
| 111 | 0 | 1 |
Only when all three contribute does the sum reach the threshold.
Generalization from 2-input AND
| Gate | Weights | Bias | Threshold |
|---|---|---|---|
| AND(a,b) | [1, 1] | -2 | 2 votes needed |
| AND(a,b,c) | [1, 1, 1] | -3 | 3 votes needed |
| AND(a,b,c,d) | [1, 1, 1, 1] | -4 | 4 votes needed |
The pattern: n inputs, all weight +1, bias -n.
Single Point of Veto
Any single 0 input blocks the gate:
- a=0: max sum = 0 + 1 + 1 - 3 = -1 < 0
- b=0: max sum = 1 + 0 + 1 - 3 = -1 < 0
- c=0: max sum = 1 + 1 + 0 - 3 = -1 < 0
Each input has veto power. This is unanimous consent.
Parameters
| Component | Value |
|---|---|
| Weights | [1, 1, 1] |
| Bias | -3 |
| Total | 4 parameters |
Optimality
Exhaustive enumeration of all 1,289 weight configurations at magnitudes 0-6 confirms this circuit is already at minimum magnitude (6). There is exactly one valid configuration at magnitude 6, and no valid configurations exist below it.
Usage
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def and3(a, b, c):
inp = torch.tensor([float(a), float(b), float(c)])
return int((inp * w['weight']).sum() + w['bias'] >= 0)
print(and3(1, 1, 1)) # 1
print(and3(1, 1, 0)) # 0
Files
threshold-and3/
βββ model.safetensors
βββ model.py
βββ config.json
βββ README.md
License
MIT