threshold-nand3

3-input NAND gate. Fires unless all three inputs are active. The universal gate extended.

Circuit

    a   b   c
    β”‚   β”‚   β”‚
    β””β”€β”€β”€β”Όβ”€β”€β”€β”˜
        β”‚
        β–Ό
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚w: -1,-1,-1β”‚
   β”‚ b:  +2   β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚
        β–Ό
  NAND(a,b,c)

The Veto Detector

3-input NAND fires when at least one input is 0:

Inputs Sum Output
000 +2 1
001 +1 1
010 +1 1
011 0 1
100 +1 1
101 0 1
110 0 1
111 -1 0

Only unanimous activation silences the gate.

Negative Weights

Each input subtracts from the sum. The positive bias provides headroom:

sum = -a - b - c + 2 = 2 - HW
fires when 2 - HW >= 0
fires when HW <= 2

This is AtMost2 for 3 inputs.

Functional Completeness

NAND is universal - any Boolean function can be built from NAND:

  • NOT(x) = NAND(x, x, x)
  • AND(x,y,z) = NAND(NAND(x,y,z), NAND(x,y,z), NAND(x,y,z))
  • OR(x,y,z) = NAND(NAND(x,x,x), NAND(y,y,y), NAND(z,z,z))

Dual of 3-input NOR

Gate Weights Bias Fires when
NAND3 all -1 +2 HW ≀ 2
NOR3 all -1 0 HW = 0

NAND is permissive (7 of 8 pass). NOR is restrictive (1 of 8 passes).

Parameters

Component Value
Weights [-1, -1, -1]
Bias +2
Total 4 parameters

Optimality

Exhaustive enumeration of all 681 weight configurations at magnitudes 0-5 confirms this circuit is already at minimum magnitude (5). There is exactly one valid configuration at magnitude 5, and no valid configurations exist below it.

Usage

from safetensors.torch import load_file
import torch

w = load_file('model.safetensors')

def nand3(a, b, c):
    inp = torch.tensor([float(a), float(b), float(c)])
    return int((inp * w['weight']).sum() + w['bias'] >= 0)

print(nand3(1, 1, 0))  # 1
print(nand3(1, 1, 1))  # 0

Files

threshold-nand3/
β”œβ”€β”€ model.safetensors
β”œβ”€β”€ model.py
β”œβ”€β”€ config.json
└── README.md

License

MIT

Downloads last month
17
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Collection including phanerozoic/threshold-nand3