File size: 2,587 Bytes
e1404bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
---

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

```python

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