metadata
license: mit
tags:
- pytorch
- safetensors
- threshold-logic
- neuromorphic
- multi-layer
threshold-biimplies
The biconditional: x β y ("if and only if"). Functionally identical to XNOR, but framed as the logical equivalence relation.
Circuit
x y
β β
βββββ¬ββββ€
β β β
βΌ β βΌ
βββββββββββββββββ
β NOR βββ AND β Layer 1
βw:-1,-1ββw:1,1 β
βb: 0 βββb: -2 β
βββββββββββββββββ
β β β
βββββΌββββ
βΌ
ββββββββ
β OR β Layer 2
βw: 1,1β
βb: -1 β
ββββββββ
β
βΌ
x β y
Mechanism
The biconditional tests whether x and y have the same truth value:
| x | y | NOR | AND | x β y |
|---|---|---|---|---|
| 0 | 0 | 1 | 0 | 1 |
| 0 | 1 | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 | 0 |
| 1 | 1 | 0 | 1 | 1 |
NOR catches "both false," AND catches "both true," OR combines.
Why Two Layers?
Unlike simple implication (x β y), the biconditional is not linearly separable. It requires detecting two diagonal cases - same problem as XOR.
Implication x β y can be computed with weights [-1, +1] because it fails only at (1,0). Biimplication fails at both (0,1) and (1,0) - these points cannot be separated from (0,0) and (1,1) by a single hyperplane.
Parameters
| Layer | Weights | Bias |
|---|---|---|
| NOR | [-1, -1] | 0 |
| AND | [1, 1] | -2 |
| OR | [1, 1] | -1 |
| Total | 9 |
Properties
- Reflexive: x β x = 1
- Symmetric: (x β y) = (y β x)
- Transitive: (x β y) β§ (y β z) β (x β z)
Full equivalence relation.
Usage
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def biimplies_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)
Files
threshold-biimplies/
βββ model.safetensors
βββ model.py
βββ config.json
βββ README.md
License
MIT