Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
269 items
β’
Updated
β’
1
Carry generate signal for carry-lookahead adders. Outputs 1 when the bit position will definitely generate a carry, regardless of incoming carry.
a b
β β
βββββ¬ββββ
β
βΌ
βββββββββ
β AND β
β w:1,1 β
β b: -2 β
βββββββββ
β
βΌ
G(a,b)
generate(a, b) = a AND b
A carry is generated at position i when both inputs are 1, because 1+1=10 in binary always produces a carry.
| a | b | G | Meaning |
|---|---|---|---|
| 0 | 0 | 0 | 0+0=0, no carry |
| 0 | 1 | 0 | 0+1=1, no carry |
| 1 | 0 | 0 | 1+0=1, no carry |
| 1 | 1 | 1 | 1+1=10, generates carry |
The AND gate fires when both inputs contribute, guaranteeing a carry output:
In a carry-lookahead adder, each bit position computes two signals:
| Signal | Function | Meaning |
|---|---|---|
| G (Generate) | a AND b | Will produce carry regardless of Cin |
| P (Propagate) | a XOR b | Will pass through incoming carry |
The carry equation becomes:
C[i+1] = G[i] OR (P[i] AND C[i])
For multi-bit lookahead:
C[4] = G[3] OR (P[3] AND G[2]) OR (P[3] AND P[2] AND G[1]) OR (P[3] AND P[2] AND P[1] AND G[0]) OR (P[3] AND P[2] AND P[1] AND P[0] AND C[0])
| Weights | [1, 1] |
| Bias | -2 |
| Inputs | 2 |
| Outputs | 1 |
| Neurons | 1 |
| Layers | 1 |
| Parameters | 3 |
| Magnitude | 4 |
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def carry_generate(a, b):
inp = torch.tensor([float(a), float(b)])
return int((inp @ w['and.weight'].T + w['and.bias'] >= 0).item())
# Examples
print(carry_generate(0, 0)) # 0
print(carry_generate(0, 1)) # 0
print(carry_generate(1, 0)) # 0
print(carry_generate(1, 1)) # 1 (generates carry)
threshold-carry-propagate: The P signal (a XOR b)threshold-carrylookahead4bit: 4-bit CLA using G and Pthreshold-kogge-stone: Parallel prefix adderthreshold-carry-generate/
βββ model.safetensors
βββ model.py
βββ create_safetensors.py
βββ config.json
βββ README.md
MIT