phanerozoic commited on
Commit
f2cdec9
·
verified ·
1 Parent(s): f3c659b

Rename from tiny-Implies-verified

Browse files
Files changed (4) hide show
  1. README.md +90 -0
  2. config.json +21 -0
  3. model.py +61 -0
  4. model.safetensors +3 -0
README.md ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ tags:
4
+ - pytorch
5
+ - safetensors
6
+ - threshold-logic
7
+ - neuromorphic
8
+ ---
9
+
10
+ # threshold-implies
11
+
12
+ Material implication: x → y. The only two-input Boolean function with asymmetric weights.
13
+
14
+ ## Circuit
15
+
16
+ ```
17
+ x y
18
+ │ │
19
+ └─┬─┘
20
+
21
+ ┌───────┐
22
+ │w: -1,1│
23
+ │ b: 0 │
24
+ └───────┘
25
+
26
+
27
+ x → y
28
+ ```
29
+
30
+ ## Mechanism
31
+
32
+ The antecedent x has weight -1 (inhibitory), the consequent y has weight +1 (excitatory):
33
+
34
+ | x | y | sum | output | meaning |
35
+ |---|---|-----|--------|---------|
36
+ | 0 | 0 | 0 | 1 | false → false |
37
+ | 0 | 1 | +1 | 1 | false → true |
38
+ | 1 | 0 | -1 | 0 | true → false ✗ |
39
+ | 1 | 1 | 0 | 1 | true → true |
40
+
41
+ The only failure: asserting a true antecedent with a false consequent. This is the only thing implication forbids.
42
+
43
+ ## Equivalent Forms
44
+
45
+ - x → y = ¬x ∨ y
46
+ - x → y = ¬(x ∧ ¬y)
47
+
48
+ The weights [-1, +1] directly implement ¬x + y.
49
+
50
+ ## Parameters
51
+
52
+ | | |
53
+ |---|---|
54
+ | Weights | [-1, +1] |
55
+ | Bias | 0 |
56
+ | Total | 3 parameters |
57
+
58
+ ## Properties
59
+
60
+ - Linearly separable (unlike XOR)
61
+ - Not commutative: (x → y) ≠ (y → x)
62
+ - Reflexive: x → x = 1
63
+ - Ex falso quodlibet: 0 → y = 1
64
+
65
+ ## Usage
66
+
67
+ ```python
68
+ from safetensors.torch import load_file
69
+ import torch
70
+
71
+ w = load_file('model.safetensors')
72
+
73
+ def implies_gate(x, y):
74
+ inputs = torch.tensor([float(x), float(y)])
75
+ return int((inputs * w['weight']).sum() + w['bias'] >= 0)
76
+ ```
77
+
78
+ ## Files
79
+
80
+ ```
81
+ threshold-implies/
82
+ ├── model.safetensors
83
+ ├── model.py
84
+ ├── config.json
85
+ └── README.md
86
+ ```
87
+
88
+ ## License
89
+
90
+ MIT
config.json ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_type": "threshold_network",
3
+ "task": "implies_gate",
4
+ "architecture": "2 -> 1",
5
+ "input_size": 2,
6
+ "output_size": 1,
7
+ "num_neurons": 1,
8
+ "num_parameters": 3,
9
+ "activation": "heaviside",
10
+ "weight_constraints": "integer",
11
+ "verification": {
12
+ "method": "coq_proof",
13
+ "exhaustive": true,
14
+ "inputs_tested": 4
15
+ },
16
+ "accuracy": {
17
+ "all_inputs": "4/4",
18
+ "percentage": 100.0
19
+ },
20
+ "github": "https://github.com/CharlesCNorton/coq-circuits"
21
+ }
model.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Threshold Network for Implication Gate
3
+
4
+ A formally verified single-neuron threshold network computing material conditional.
5
+ Weights are integer-constrained and activation uses the Heaviside step function.
6
+ """
7
+
8
+ import torch
9
+ from safetensors.torch import load_file
10
+
11
+
12
+ class ThresholdImplies:
13
+ """
14
+ Implication gate implemented as a threshold neuron.
15
+
16
+ Circuit: output = (w1*x + w2*y + bias >= 0)
17
+ With weights=[-1,1], bias=0: fails only when x=1 and y=0.
18
+ """
19
+
20
+ def __init__(self, weights_dict):
21
+ self.weight = weights_dict['weight']
22
+ self.bias = weights_dict['bias']
23
+
24
+ def __call__(self, x, y):
25
+ inputs = torch.tensor([float(x), float(y)])
26
+ weighted_sum = (inputs * self.weight).sum() + self.bias
27
+ return (weighted_sum >= 0).float()
28
+
29
+ @classmethod
30
+ def from_safetensors(cls, path="model.safetensors"):
31
+ return cls(load_file(path))
32
+
33
+
34
+ def forward(x, weights):
35
+ """
36
+ Forward pass with Heaviside activation.
37
+
38
+ Args:
39
+ x: Input tensor of shape [..., 2]
40
+ weights: Dict with 'weight' and 'bias' tensors
41
+
42
+ Returns:
43
+ Implies(x[0], x[1])
44
+ """
45
+ x = torch.as_tensor(x, dtype=torch.float32)
46
+ weighted_sum = (x * weights['weight']).sum(dim=-1) + weights['bias']
47
+ return (weighted_sum >= 0).float()
48
+
49
+
50
+ if __name__ == "__main__":
51
+ weights = load_file("model.safetensors")
52
+ model = ThresholdImplies(weights)
53
+
54
+ print("Implication Gate Truth Table:")
55
+ print("-" * 30)
56
+ for x in [0, 1]:
57
+ for y in [0, 1]:
58
+ out = int(model(x, y).item())
59
+ expected = 1 if (x == 0 or y == 1) else 0
60
+ status = "OK" if out == expected else "FAIL"
61
+ print(f"Implies({x}, {y}) = {out} [{status}]")
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:58321831e59f81f25f0b72275ea479cc41ab21cf5ff808e3e0a6bbd4c1b37268
3
+ size 140