CharlesCNorton commited on
Commit ·
44ae225
1
Parent(s): 657864a
neural_ca: demonstrate gate composition. A third particle at (0,9) collides with the A&B output particle, so cell (3,5) carries A&B&C, verified over all 8 inputs; chained collisions build larger circuits from the interaction gate. README updated.
Browse files
README.md
CHANGED
|
@@ -693,7 +693,10 @@ reversibly (verified as a genuine interaction, distinct from independent motion)
|
|
| 693 |
A collision computes logic directly: with input particles at (2,2) and (7,7),
|
| 694 |
three output cells at step 4 carry A AND B (the deflected paths (3,6) and (6,3)),
|
| 695 |
A AND NOT B ((6,6)), and NOT A AND B ((3,3)), the billiard-ball interaction
|
| 696 |
-
gate, verified over all four inputs.
|
|
|
|
|
|
|
|
|
|
| 697 |
functionally complete (Margolus 1984).
|
| 698 |
|
| 699 |
```bash
|
|
|
|
| 693 |
A collision computes logic directly: with input particles at (2,2) and (7,7),
|
| 694 |
three output cells at step 4 carry A AND B (the deflected paths (3,6) and (6,3)),
|
| 695 |
A AND NOT B ((6,6)), and NOT A AND B ((3,3)), the billiard-ball interaction
|
| 696 |
+
gate, verified over all four inputs. The gates compose: launching a third
|
| 697 |
+
particle at (0,9) to collide with the A AND B output makes cell (3,5) carry
|
| 698 |
+
A AND B AND C, verified over all eight inputs, so chained collisions build larger
|
| 699 |
+
circuits. With mirror routing and a constant-particle source the construction is
|
| 700 |
functionally complete (Margolus 1984).
|
| 701 |
|
| 702 |
```bash
|
src/ca.py
CHANGED
|
@@ -192,6 +192,30 @@ def _test_gate():
|
|
| 192 |
return ok
|
| 193 |
|
| 194 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
def _test_collision():
|
| 196 |
# Two particles interact (the joint evolution differs from independent
|
| 197 |
# motion) and the collision stays reversible: the physics that logic needs.
|
|
@@ -233,4 +257,5 @@ if __name__ == "__main__":
|
|
| 233 |
c = _test_ballistic()
|
| 234 |
d = _test_collision()
|
| 235 |
e = _test_gate()
|
| 236 |
-
|
|
|
|
|
|
| 192 |
return ok
|
| 193 |
|
| 194 |
|
| 195 |
+
def and3(a: int, b: int, c: int) -> int:
|
| 196 |
+
"""Two composed collisions. A at (2,2) and B at (7,7) collide into an A&B
|
| 197 |
+
particle, which then collides with C launched at (0,9); the output cell
|
| 198 |
+
(3,5) at step 4 is occupied iff a, b and c. Composing gates this way builds
|
| 199 |
+
arbitrary circuits from the interaction gate."""
|
| 200 |
+
H = W = 16
|
| 201 |
+
g = [[0] * W for _ in range(H)]
|
| 202 |
+
if a:
|
| 203 |
+
g[2][2] = 1
|
| 204 |
+
if b:
|
| 205 |
+
g[7][7] = 1
|
| 206 |
+
if c:
|
| 207 |
+
g[0][9] = 1
|
| 208 |
+
return run(g, 4)[3][5]
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
def _test_compose():
|
| 212 |
+
ok = all(and3(a, b, c) == (a & b & c)
|
| 213 |
+
for a in (0, 1) for b in (0, 1) for c in (0, 1))
|
| 214 |
+
print(f" composed 3-input AND (two chained collisions) over all 8 inputs: "
|
| 215 |
+
f"{'OK' if ok else 'FAIL'}")
|
| 216 |
+
return ok
|
| 217 |
+
|
| 218 |
+
|
| 219 |
def _test_collision():
|
| 220 |
# Two particles interact (the joint evolution differs from independent
|
| 221 |
# motion) and the collision stays reversible: the physics that logic needs.
|
|
|
|
| 257 |
c = _test_ballistic()
|
| 258 |
d = _test_collision()
|
| 259 |
e = _test_gate()
|
| 260 |
+
f = _test_compose()
|
| 261 |
+
print("PASS" if (a and g and b and c and d and e and f) else "FAIL")
|