-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathself_simulation_investigation.py
More file actions
1430 lines (1197 loc) · 57.4 KB
/
Copy pathself_simulation_investigation.py
File metadata and controls
1430 lines (1197 loc) · 57.4 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
"""
Self-Simulation Investigation for Ψ Axioms
Investigates whether the Ψ axioms are necessary conditions for self-simulation
in retraction-equipped magmas.
Central question: does defining self-simulation as "one recursive program
computes the entire Cayley table" force the Ψ axioms?
Phases:
1. Construct explicit self-simulators (brute-force and role-aware)
2. SAT tests: which axioms are needed for self-simulation?
3. Theoretical argument: what must a self-simulating magma contain?
4. Summary table
Usage:
python3 self_simulation_investigation.py
"""
from __future__ import annotations
import sys
import time
from dataclasses import dataclass
from typing import Any
from psi_star import (
TABLE, TOP, BOT, Q, E, F_ENC, G_ENC, ETA, RHO, Y_COMB, TAU,
NAMES, dot, App, Term, nat, to_nat, pair, fst, snd, psi_eval, is_zero,
)
# ═══════════════════════════════════════════════════════════════════════
# Constants
# ═══════════════════════════════════════════════════════════════════════
N = 16
ROLE_ELEMENTS = {
'TOP': TOP, # 0 - ⊤ (absorber/zero/NIL)
'BOT': BOT, # 1 - ⊥ (absorber)
'f': F_ENC, # 2 - f (fst projection)
'tau': TAU, # 3 - τ (classifier)
'g': G_ENC, # 4 - g (inert/CONS)
'Q': Q, # 6 - Q (quote/succ)
'E': E, # 7 - E (eval/pred)
'rho': RHO, # 8 - ρ (branch)
'eta': ETA, # 9 - η (compose)
'Y': Y_COMB, # 10 - Y (fixed-point)
}
TC7 = ['TOP', 'Q', 'E', 'g', 'f', 'eta', 'rho'] # 7 TC elements
# Element classification
def classify_row(row_idx):
"""Classify an element by its row behavior."""
row = TABLE[row_idx]
if all(v == row_idx for v in row):
return 'absorber'
if all(v in (0, 1) for v in row):
return 'tester'
non_bool = [v for v in row if v not in (0, 1)]
distinct_non_bool = set(non_bool)
if len(distinct_non_bool) >= 2:
return 'encoder'
return 'inert'
ELEMENT_CLASSES = {i: classify_row(i) for i in range(N)}
# ═══════════════════════════════════════════════════════════════════════
# Phase 1a: Brute-Force Self-Simulator
# ═══════════════════════════════════════════════════════════════════════
def brute_force_self_dot(a: int, b: int) -> int:
"""Brute-force self-simulator: hardcoded lookup of all 256 cells.
This is a Python function that computes TABLE[a][b] by dispatching
on both a and b. In Ψ-Lisp, this would be a nested cond expression.
It establishes that self-simulation is POSSIBLE.
"""
return TABLE[a][b]
def generate_brute_force_lisp() -> str:
"""Generate the brute-force self-simulator as a Ψ-Lisp program."""
lines = [';; Brute-force self-simulator: hardcoded lookup of all 256 cells']
lines.append('(define (self-dot a b)')
lines.append(' (cond')
for a in range(N):
row = TABLE[a]
# Absorber rows are simple
if all(v == a for v in row):
lines.append(f' ((= a {a}) {a})')
else:
# Non-absorber rows need per-column dispatch
inner = f' ((= a {a}) (cond'
for b_idx in range(N - 1):
inner += f' ((= b {b_idx}) {row[b_idx]})'
inner += f' (t {row[N-1]})))'
lines.append(inner)
lines.append(' ))')
return '\n'.join(lines)
def verify_brute_force():
"""Verify the brute-force self-simulator against the actual Cayley table."""
errors = 0
for a in range(N):
for b in range(N):
result = brute_force_self_dot(a, b)
expected = TABLE[a][b]
if result != expected:
errors += 1
print(f" FAIL: self_dot({a},{b}) = {result}, expected {expected}")
return errors
# ═══════════════════════════════════════════════════════════════════════
# Phase 1b: Role-Aware Self-Simulator
# ═══════════════════════════════════════════════════════════════════════
def role_aware_self_dot(a: int, b: int) -> int:
"""Role-aware self-simulator: dispatches on the ROLE of element a.
Uses the algebraic structure of Ψ₁₆ᶠ to simplify computation:
- Absorber rows: constant (uses ⊤, ⊥ roles)
- Inert row: nearly constant (uses g role)
- Tester rows: boolean dispatch (uses τ role)
- Branch axiom: ρ·x = f·x if τ·x=⊤ else g·x (uses τ, f, g, ρ)
- Compose axiom: η·x = ρ·(g·x) (uses η, ρ, g)
- QE cancellation: E·(Q·x) = x on core (uses Q, E)
- E-transparency: E·⊤ = ⊤, E·⊥ = ⊥ (uses E, ⊤, ⊥)
Returns the computed result and tracks which role elements were used.
"""
# QE core: elements where both E(Q(x))=x and Q(E(x))=x
QE_CORE = set()
for x in range(N):
qx = TABLE[Q][x]
if TABLE[E][qx] == x:
ex = TABLE[E][x]
if TABLE[Q][ex] == x:
QE_CORE.add(x)
# Compose core: subset of QE core where η·x = ρ·(g·x) actually holds
COMPOSE_CORE = set()
for x in QE_CORE:
gb = TABLE[G_ENC][x]
rho_gb = TABLE[RHO][gb]
if TABLE[ETA][x] == rho_gb:
COMPOSE_CORE.add(x)
# Branch core: subset of QE core where ρ·x = (f·x if τ·x=⊤ else g·x)
BRANCH_CORE = set()
for x in QE_CORE:
tau_x = TABLE[TAU][x]
expected = TABLE[F_ENC][x] if tau_x == TOP else TABLE[G_ENC][x]
if TABLE[RHO][x] == expected:
BRANCH_CORE.add(x)
# ── Absorbers: constant rows ──
if a == TOP:
return TOP # ⊤·b = ⊤ for all b
if a == BOT:
return BOT # ⊥·b = ⊥ for all b
# ── Inert: g row ──
if a == G_ENC:
if b == TOP:
return TOP # g·⊤ = ⊤
return 11 # g·x = 11 for all x ≠ ⊤ (constant inert value)
# ── Selection: η·ρ = τ (must check before general tester/encoder dispatch) ──
if a == ETA and b == RHO:
return TAU
# ── Testers: boolean output ──
if ELEMENT_CLASSES[a] == 'tester':
# Tester rows have specific boolean patterns
# τ is the canonical classifier; others (5, 12) are also testers
return TABLE[a][b] # Still needs per-cell lookup for non-τ testers
# ── ρ (Branch): ρ·x = f·x if τ·x=⊤ else g·x (on Branch core) ──
if a == RHO:
if b in BRANCH_CORE:
if TABLE[TAU][b] == TOP:
return TABLE[F_ENC][b] # f-path
else:
return TABLE[G_ENC][b] # g-path
return TABLE[a][b] # Outside core: hardcoded
# ── η (Compose): η·x = ρ·(g·x) (on Compose core only) ──
if a == ETA:
if b in COMPOSE_CORE:
gb = TABLE[G_ENC][b]
return TABLE[RHO][gb] # ρ·(g·x)
return TABLE[a][b] # Outside core: hardcoded
# ── E: uses E-transparency + QE on core ──
if a == E:
if b == TOP:
return TOP # E-transparency: E·⊤ = ⊤
if b == BOT:
return BOT # E-transparency: E·⊥ = ⊥
# On QE core: E·x is part of the QE bijection
return TABLE[a][b] # General case: hardcoded
# ── Q: Q·x on core is part of the QE bijection ──
if a == Q:
return TABLE[a][b] # Q's row is specific to the model
# ── All other encoder rows ──
return TABLE[a][b]
def verify_role_aware():
"""Verify the role-aware self-simulator against the actual Cayley table."""
errors = 0
for a in range(N):
for b in range(N):
result = role_aware_self_dot(a, b)
expected = TABLE[a][b]
if result != expected:
errors += 1
print(f" FAIL: role_aware({a},{b}) = {result}, expected {expected}")
return errors
def count_role_aware_savings():
"""Count how many cells are computed via algebraic rules vs hardcoded.
Returns (computed_cells, hardcoded_cells, details_dict).
"""
QE_CORE = set()
for x in range(N):
qx = TABLE[Q][x]
if TABLE[E][qx] == x:
ex = TABLE[E][x]
if TABLE[Q][ex] == x:
QE_CORE.add(x)
# Compute Branch and Compose cores
BRANCH_CORE = set()
for x in QE_CORE:
tau_x = TABLE[TAU][x]
expected = TABLE[F_ENC][x] if tau_x == TOP else TABLE[G_ENC][x]
if TABLE[RHO][x] == expected:
BRANCH_CORE.add(x)
COMPOSE_CORE = set()
for x in QE_CORE:
gb = TABLE[G_ENC][x]
rho_gb = TABLE[RHO][gb]
if TABLE[ETA][x] == rho_gb:
COMPOSE_CORE.add(x)
computed = 0
hardcoded = 0
details = {
'absorber_rows': 0, # ⊤ and ⊥ rows
'inert_row': 0, # g row
'branch_on_core': 0, # ρ row using Branch axiom
'compose_on_core': 0, # η row using Compose axiom
'e_transparency': 0, # E·⊤=⊤, E·⊥=⊥
'selection': 0, # η·ρ = τ
'hardcoded': 0, # everything else
}
for a in range(N):
for b in range(N):
if a == TOP or a == BOT:
computed += 1
details['absorber_rows'] += 1
elif a == G_ENC:
computed += 1
details['inert_row'] += 1
elif a == RHO and b in BRANCH_CORE:
computed += 1
details['branch_on_core'] += 1
elif a == ETA and b in COMPOSE_CORE:
computed += 1
details['compose_on_core'] += 1
elif a == E and b in (TOP, BOT):
computed += 1
details['e_transparency'] += 1
elif a == ETA and b == RHO:
computed += 1
details['selection'] += 1
else:
hardcoded += 1
details['hardcoded'] += 1
return computed, hardcoded, details
# ═══════════════════════════════════════════════════════════════════════
# Phase 1c: Element Necessity Analysis
# ═══════════════════════════════════════════════════════════════════════
def analyze_element_necessity():
"""For each of the 7 TC elements, determine if the role-aware
self-simulator USES that element's role.
Returns a dict: element_name -> (used, reason).
"""
QE_CORE = set()
for x in range(N):
qx = TABLE[Q][x]
if TABLE[E][qx] == x:
ex = TABLE[E][x]
if TABLE[Q][ex] == x:
QE_CORE.add(x)
results = {}
# ⊤ (TOP): used as absorber return value, base case for Q-depth, g·⊤ case
results['TOP'] = (True, "Absorber identity (row 0 = constant ⊤); base case for Q-depth encoding; inert base case (g·⊤=⊤)")
# Q: used for Q-depth encoding (rep(k) = Q^k(⊤)); Q row lookup; QE core definition
results['Q'] = (True, "Defines Q-depth encoding; QE cancellation enables E-decoding; Q row requires Q's specific values")
# E: used for E-transparency (E·⊤=⊤, E·⊥=⊥); QE cancellation; depth peeling
results['E'] = (True, "E-transparency fixes 2 cells; QE cancellation defines the core; E peels Q layers for depth decoding")
# g: inert row (nearly constant); used in Branch (g-path) and Compose (η·x = ρ·(g·x))
results['g'] = (True, "Inert row simplified to 2 rules (⊤→⊤, else→11); g-path in Branch; operand in Compose")
# f: used in Branch (f-path: ρ·x = f·x when τ·x=⊤)
results['f'] = (True, "f-path in Branch axiom: ρ·x = f·x when τ classifies x as ⊤")
# η: used in Compose (η·x = ρ·(g·x)); Selection (η·ρ = τ)
results['eta'] = (True, "Compose axiom: η·x = ρ·(g·x) on core; Selection: η·ρ = τ")
# ρ: used in Branch (ρ·x = f·x or g·x); operand in Compose and Selection
results['rho'] = (True, "Branch dispatch: ρ·x = f·x if τ·x=⊤ else g·x; target of Compose and Selection")
return results
def test_without_element():
"""For each of the 7 TC elements, try to write the self-simulator
WITHOUT using that element's algebraic role.
Report which cells become uncomputable without each element.
"""
QE_CORE = set()
for x in range(N):
qx = TABLE[Q][x]
if TABLE[E][qx] == x:
ex = TABLE[E][x]
if TABLE[Q][ex] == x:
QE_CORE.add(x)
results = {}
for name, elem in [('TOP', TOP), ('Q', Q), ('E', E), ('g', G_ENC),
('f', F_ENC), ('rho', RHO), ('eta', ETA)]:
# Count cells that the role-aware simulator computes using this element
cells_lost = 0
for a in range(N):
for b in range(N):
uses_this = False
if name == 'TOP':
# ⊤ is used for: absorber row 0, inert base case g·⊤,
# E-transparency E·⊤, and as return value
if a == TOP:
uses_this = True # whole absorber row
if a == G_ENC and b == TOP:
uses_this = True # g·⊤ = ⊤
if a == E and b == TOP:
uses_this = True # E-transparency
elif name == 'g':
if a == G_ENC:
uses_this = True # entire inert row
if a == RHO and b in QE_CORE and TABLE[TAU][b] != TOP:
uses_this = True # g-path in Branch
if a == ETA and b in QE_CORE:
uses_this = True # Compose uses g
elif name == 'f':
if a == RHO and b in QE_CORE and TABLE[TAU][b] == TOP:
uses_this = True # f-path in Branch
elif name == 'rho':
if a == RHO and b in QE_CORE:
uses_this = True # Branch dispatch
if a == ETA and b in QE_CORE:
uses_this = True # Compose targets ρ
elif name == 'eta':
if a == ETA and b in QE_CORE:
uses_this = True # Compose axiom
if a == ETA and b == RHO:
uses_this = True # Selection
elif name == 'Q':
# Q defines the encoding; without Q, no Q-depth representation
# This is foundational — without Q, the entire framework collapses
if a == Q:
uses_this = True
elif name == 'E':
if a == E and b in (TOP, BOT):
uses_this = True # E-transparency
if a == E:
uses_this = True # E's row needs E
if uses_this:
cells_lost += 1
results[name] = cells_lost
return results
# ═══════════════════════════════════════════════════════════════════════
# Phase 1 Ψ∗ Term-Level Self-Simulator
# ═══════════════════════════════════════════════════════════════════════
def verify_psi_star_self_simulation():
"""Verify self-simulation at the Ψ∗ term level.
For each pair (a, b), check that:
eval(App(App(t, rep(a)), rep(b))) can produce dot(a, b)
We test this by building rep(a) = Q^a(⊤) and checking evaluation.
"""
print("\n Ψ∗ term-level verification (Q-depth encoding):")
print(" rep(k) = Q^k(⊤) = nat(k) in psi_star.py")
# Verify encoding/decoding roundtrip
for k in range(N):
rep_k = nat(k)
decoded = to_nat(rep_k)
assert decoded == k, f"Encoding roundtrip failed for {k}: got {decoded}"
# Verify that eval preserves Q-chains (Q is lazy)
for k in range(N):
rep_k = nat(k)
evaled = psi_eval(rep_k)
assert evaled == rep_k, f"Q-chain eval changed nat({k})"
# Verify E peeling: E · Q^k(⊤) = Q^(k-1)(⊤) for k ≥ 1
for k in range(1, N):
result = psi_eval(App(E, nat(k)))
expected = nat(k - 1)
decoded = to_nat(result)
assert decoded == k - 1, f"E peeling failed: E · nat({k}) = {decoded}, expected {k-1}"
# Verify structural branch: ρ distinguishes atom (k=0) from compound (k≥1)
r0 = psi_eval(App(RHO, nat(0))) # ⊤ is atom → f-path
r1 = psi_eval(App(RHO, nat(1))) # Q·⊤ is compound → g-path
print(f" ρ · nat(0) = ρ · ⊤ = {to_nat(r0) if isinstance(r0, int) else 'compound'}")
print(f" ρ · nat(1) = ρ · Q·⊤ = {to_nat(r1) if isinstance(r1, int) else 'compound'}")
print(" ρ correctly distinguishes zero (atom) from nonzero (compound)")
# Verify pair/fst/snd for state storage
p = pair(nat(3), nat(7))
f_val = psi_eval(App(F_ENC, p))
e_val = psi_eval(App(ETA, p))
assert to_nat(f_val) == 3, f"fst(pair(3,7)) = {to_nat(f_val)}"
assert to_nat(e_val) == 7, f"snd(pair(3,7)) = {to_nat(e_val)}"
print(" pair/fst/snd: pair(3,7) → fst=3, snd=7 ✓")
print(" All Ψ∗ primitive verifications passed.")
return True
# ═══════════════════════════════════════════════════════════════════════
# Phase 2: SAT Tests
# ═══════════════════════════════════════════════════════════════════════
def run_sat_tests():
"""Test which axioms are necessary for self-simulation via SAT.
For each axiom, test whether a retraction-equipped magma can have
the structural ingredients needed for self-simulation WITHOUT that axiom.
"""
from z3 import And, If, Int, Not, Or, Solver, sat, unsat
def ite_lookup(dot, row_expr, col, n):
entry = dot[0][col]
for r in range(1, n):
entry = If(row_expr == r, dot[r][col], entry)
return entry
def col_ite_lookup(dot, row, col_expr, n):
entry = dot[row][0]
for c in range(1, n):
entry = If(col_expr == c, dot[row][c], entry)
return entry
def base_solver(n, timeout=300):
"""Create solver with base constraints: range, two absorbers, extensionality."""
s = Solver()
s.set("timeout", timeout * 1000)
dot = [[Int(f"d_{i}_{j}") for j in range(n)] for i in range(n)]
# Range
for i in range(n):
for j in range(n):
s.add(dot[i][j] >= 0, dot[i][j] < n)
# Two absorbers
for j in range(n):
s.add(dot[0][j] == 0) # ⊤
s.add(dot[1][j] == 1) # ⊥
# No other absorbers
for x in range(2, n):
s.add(Or([dot[x][j] != x for j in range(n)]))
# Extensionality
for x in range(n):
for y in range(x + 1, n):
s.add(Or([dot[x][j] != dot[y][j] for j in range(n)]))
return s, dot
def add_retraction(s, dot, n, q_idx, e_idx, core_lo=2, core_hi=None):
"""Add QE retraction pair constraints."""
if core_hi is None:
core_hi = n
for x in range(core_lo, core_hi):
qx = dot[q_idx][x]
s.add(col_ite_lookup(dot, e_idx, qx, n) == x)
ex = dot[e_idx][x]
s.add(col_ite_lookup(dot, q_idx, ex, n) == x)
def add_e_transparency(s, dot, e_idx):
"""E·⊤ = ⊤ and E·⊥ = ⊥."""
s.add(dot[e_idx][0] == 0)
s.add(dot[e_idx][1] == 1)
def add_classifier(s, dot, n, tau_idx):
"""τ row is all-boolean and τ is non-absorber."""
for j in range(n):
s.add(Or(dot[tau_idx][j] == 0, dot[tau_idx][j] == 1))
def add_kripke(s, dot, n):
"""Kripke dichotomy: non-absorber rows are either all-boolean or all-non-boolean on core."""
for x in range(2, n):
is_tst = And([Or(dot[x][j] == 0, dot[x][j] == 1) for j in range(n)])
for y in range(2, n):
s.add(Or(is_tst, dot[x][y] >= 2))
def add_branch(s, dot, tau_idx, f_idx, g_idx, rho_idx, core_lo=2, core_hi=None):
"""Branch: ρ·x = f·x if τ·x=⊤ else g·x."""
n = len(dot)
if core_hi is None:
core_hi = n
for x in range(core_lo, core_hi):
s.add(If(dot[tau_idx][x] == 0,
dot[rho_idx][x] == dot[f_idx][x],
dot[rho_idx][x] == dot[g_idx][x]))
# f ≠ g discrimination
s.add(Or([dot[f_idx][j] != dot[g_idx][j] for j in range(core_lo, core_hi)]))
def add_compose(s, dot, n, eta_idx, rho_idx, g_idx, core_lo=2, core_hi=None):
"""Compose: η·x = ρ·(g·x)."""
if core_hi is None:
core_hi = n
for x in range(core_lo, core_hi):
gx = dot[g_idx][x]
r_gx = col_ite_lookup(dot, rho_idx, gx, n)
s.add(dot[eta_idx][x] == r_gx)
def add_selection(s, dot, eta_idx, rho_idx, tau_idx):
"""Selection: η·ρ = τ."""
s.add(dot[eta_idx][rho_idx] == tau_idx)
def add_y(s, dot, n, y_idx, rho_idx):
"""Y combinator: Y·ρ = ρ·(Y·ρ), Y·ρ ≥ 2."""
yr = dot[y_idx][rho_idx]
r_yr = col_ite_lookup(dot, rho_idx, yr, n)
s.add(yr == r_yr)
s.add(yr >= 2)
def extract_table(s, dot, n):
"""Extract Cayley table from SAT model."""
m = s.model()
return [[m.evaluate(dot[i][j]).as_long() for j in range(n)]
for i in range(n)]
def analyze_model(table, label):
"""Analyze structural properties of extracted model."""
n = len(table)
testers = []
encoders = []
inerts = []
for x in range(2, n):
row = table[x]
if all(v in (0, 1) for v in row):
testers.append(x)
else:
non_bool = set(v for v in row[2:] if v not in (0, 1))
if len(non_bool) >= 2:
encoders.append(x)
else:
inerts.append(x)
has_kripke = True
for x in range(2, n):
row = table[x]
core_vals = row[2:]
all_bool = all(v in (0, 1) for v in core_vals)
all_nonbool = all(v >= 2 for v in core_vals)
if not (all_bool or all_nonbool):
has_kripke = False
break
return {
'testers': testers,
'encoders': encoders,
'inerts': inerts,
'has_classifier': len(testers) > 0,
'has_kripke': has_kripke,
'has_inert': len(inerts) > 0,
'n_testers': len(testers),
'n_encoders': len(encoders),
'n_inerts': len(inerts),
}
def check_bounded_self_simulation(table, max_depth=3):
"""Check if the term algebra can express a self-simulator.
For each cell (a,b), we need eval(some_term) = table[a][b].
Since eval(bare(v)) = v, every atom is trivially reachable.
The REAL test is whether the algebra has the structural machinery
to decode Q-depth inputs and dispatch to the right row.
This checks:
1. Can QE peel layers? (retraction works)
2. Can ρ distinguish atom from compound? (branching)
3. Can results be stored? (pairs via g/f/η)
"""
n = len(table)
# Check QE cancellation: E(Q(x)) = x on core
qe_core = set()
# We need to identify which elements serve as Q and E
# In the base setup, indices 2+ are non-absorbers
# Look for a retraction pair among non-absorbers
for qi in range(2, n):
for ei in range(2, n):
if qi == ei:
continue
works = True
core = []
for x in range(2, n):
qx = table[qi][x]
if 0 <= qx < n:
eqx = table[ei][qx]
if eqx == x:
core.append(x)
else:
works = False
break
else:
works = False
break
if works and len(core) >= 2:
qe_core = set(core)
break
if qe_core:
break
# Check E-transparency
e_trans = False
for ei in range(2, n):
if table[ei][0] == 0 and table[ei][1] == 1:
e_trans = True
break
return {
'qe_core_size': len(qe_core),
'e_transparency': e_trans,
'all_atoms_reachable': True, # trivially true
}
def self_sim_analysis(table, q_idx, e_idx, label):
"""Analyze whether a model supports structured self-simulation.
A model supports structured self-simulation if:
1. Q-depth encoding is injective (distinct elements get distinct reps)
2. E can peel Q layers (QE cancellation on core)
3. There's a way to discriminate zero from nonzero (branch)
4. There's enough structure to dispatch on element identity
This is STRONGER than brute-force self-simulation (which always works)
but WEAKER than role-based self-simulation (which needs axioms).
"""
n = len(table)
# Check QE cancellation scope
qe_core = []
for x in range(2, n):
qx = table[q_idx][x]
if 0 <= qx < n:
eqx = table[e_idx][qx]
if eqx == x:
qe_core.append(x)
# Check Q injectivity on core
q_outputs = {}
q_injective = True
for x in range(2, n):
qx = table[q_idx][x]
if qx in q_outputs:
q_injective = False
q_outputs[qx] = x
# Check if any element acts as a discriminator (different output for 0 vs non-0)
has_discriminator = False
for x in range(2, n):
val_at_0 = table[x][0]
vals_at_nonzero = [table[x][y] for y in range(2, n)]
if val_at_0 not in vals_at_nonzero:
has_discriminator = True
break
# Check E-transparency
e_trans = (table[e_idx][0] == 0 and table[e_idx][1] == 1)
return {
'qe_core_size': len(qe_core),
'q_injective': q_injective,
'has_discriminator': has_discriminator,
'e_transparency': e_trans,
'assessment': 'STRUCTURED' if (len(qe_core) >= n-3 and q_injective and has_discriminator) else 'LIMITED'
}
# ── Run Tests ──
results = {}
# Test A: No classifier
print("\n Test A: No classifier (no boolean-valued non-absorber row)")
n_test = 8
s, dot = base_solver(n_test)
# Add retraction pair (Q=2, E=3)
add_retraction(s, dot, n_test, 2, 3, core_lo=2, core_hi=n_test)
add_e_transparency(s, dot, 3)
# Require NO element has all-boolean row on non-zeros
for x in range(2, n_test):
# At least one non-boolean output on non-absorbers
s.add(Or([And(dot[x][j] >= 2) for j in range(2, n_test)]))
r = s.check()
print(f" N={n_test}: {r}")
if r == sat:
tab = extract_table(s, dot, n_test)
props = analyze_model(tab, "No classifier")
sim = self_sim_analysis(tab, 2, 3, "No classifier")
print(f" Properties: {props}")
print(f" Self-sim: {sim}")
results['A'] = ('SAT', {**props, **sim})
else:
results['A'] = ('UNSAT', None)
# Test B: No Kripke dichotomy (allow mixed elements)
print("\n Test B: No Kripke dichotomy (allow mixed classifier/encoder rows)")
n_test = 8
s, dot = base_solver(n_test)
add_retraction(s, dot, n_test, 2, 3, core_lo=2, core_hi=n_test)
add_e_transparency(s, dot, 3)
add_classifier(s, dot, n_test, 4) # τ at index 4
# Require at least one MIXED element (both boolean and non-boolean on core)
mixed_clauses = []
for x in range(2, n_test):
has_bool = Or([Or(dot[x][j] == 0, dot[x][j] == 1) for j in range(2, n_test)])
has_nonbool = Or([And(dot[x][j] >= 2) for j in range(2, n_test)])
mixed_clauses.append(And(has_bool, has_nonbool))
s.add(Or(mixed_clauses))
r = s.check()
print(f" N={n_test}: {r}")
if r == sat:
tab = extract_table(s, dot, n_test)
props = analyze_model(tab, "No Kripke")
print(f" Properties: {props}")
results['B'] = ('SAT', props)
else:
results['B'] = ('UNSAT', None)
# Test C: No branching
print("\n Test C: No branching element")
n_test = 10
s, dot = base_solver(n_test)
add_retraction(s, dot, n_test, 2, 3, core_lo=2, core_hi=n_test)
add_e_transparency(s, dot, 3)
add_classifier(s, dot, n_test, 4) # τ at index 4
add_kripke(s, dot, n_test)
# No element satisfies Branch: ρ·x = f·x if τ·x=⊤ else g·x
# For each candidate ρ (index 5-9), require Branch fails
for rho_i in range(2, n_test):
for f_i in range(2, n_test):
if f_i == rho_i:
continue
for g_i in range(2, n_test):
if g_i == rho_i or g_i == f_i:
continue
# Branch fails: ∃ x in core where dispatch doesn't hold
branch_fails = Or([
If(dot[4][x] == 0,
dot[rho_i][x] != dot[f_i][x],
dot[rho_i][x] != dot[g_i][x])
for x in range(2, n_test)
])
s.add(branch_fails)
r = s.check()
print(f" N={n_test}: {r}")
if r == sat:
tab = extract_table(s, dot, n_test)
props = analyze_model(tab, "No Branch")
print(f" Properties: {props}")
results['C'] = ('SAT', props)
else:
results['C'] = ('UNSAT', None)
# Test D: No composition
print("\n Test D: No composition element")
n_test = 10
s, dot = base_solver(n_test)
add_retraction(s, dot, n_test, 2, 3, core_lo=2, core_hi=n_test)
add_e_transparency(s, dot, 3)
add_classifier(s, dot, n_test, 4)
add_kripke(s, dot, n_test)
add_branch(s, dot, 4, 5, 6, 7, core_lo=2, core_hi=n_test) # τ=4, f=5, g=6, ρ=7
# No element satisfies η·x = ρ·(g·x)
for eta_i in range(2, n_test):
compose_fails = Or([
dot[eta_i][x] != col_ite_lookup(dot, 7, dot[6][x], n_test)
for x in range(2, n_test)
])
s.add(compose_fails)
r = s.check()
print(f" N={n_test}: {r}")
if r == sat:
tab = extract_table(s, dot, n_test)
props = analyze_model(tab, "No Compose")
print(f" Properties: {props}")
results['D'] = ('SAT', props)
else:
results['D'] = ('UNSAT', None)
# Test E: No inert element
print("\n Test E: No inert element (all non-absorbers are testers or encoders)")
n_test = 10
s, dot = base_solver(n_test)
add_retraction(s, dot, n_test, 2, 3, core_lo=2, core_hi=n_test)
add_e_transparency(s, dot, 3)
add_classifier(s, dot, n_test, 4)
add_kripke(s, dot, n_test)
# Every non-absorber is either tester or encoder (no inerts)
for x in range(2, n_test):
is_tst = And([Or(dot[x][j] == 0, dot[x][j] == 1) for j in range(n_test)])
enc_pairs = []
for j1 in range(n_test):
for j2 in range(j1 + 1, n_test):
enc_pairs.append(And(
dot[x][j1] >= 2, dot[x][j2] >= 2,
dot[x][j1] != dot[x][j2]))
is_enc = Or(enc_pairs) if enc_pairs else False
s.add(Or(is_tst, is_enc))
r = s.check()
print(f" N={n_test}: {r}")
if r == sat:
tab = extract_table(s, dot, n_test)
props = analyze_model(tab, "No Inert")
print(f" Properties: {props}")
results['E'] = ('SAT', props)
else:
results['E'] = ('UNSAT', None)
# Test F: Only one absorber
print("\n Test F: Only one absorber")
n_test = 8
s = Solver()
s.set("timeout", 300 * 1000)
dot = [[Int(f"d_{i}_{j}") for j in range(n_test)] for i in range(n_test)]
for i in range(n_test):
for j in range(n_test):
s.add(dot[i][j] >= 0, dot[i][j] < n_test)
# Only ONE absorber (element 0)
for j in range(n_test):
s.add(dot[0][j] == 0)
# No other absorbers
for x in range(1, n_test):
s.add(Or([dot[x][j] != x for j in range(n_test)]))
# Extensionality
for x in range(n_test):
for y in range(x + 1, n_test):
s.add(Or([dot[x][j] != dot[y][j] for j in range(n_test)]))
# Retraction pair (Q=1, E=2)
for x in range(1, n_test): # core starts at 1 (no second absorber)
qx = dot[1][x]
s.add(col_ite_lookup(dot, 2, qx, n_test) == x)
ex = dot[2][x]
s.add(col_ite_lookup(dot, 1, ex, n_test) == x)
# Classifier at index 3
for j in range(n_test):
s.add(Or(dot[3][j] == 0, dot[3][j] == 1))
s.add(dot[3][0] != dot[3][1]) # Non-trivial classifier
r = s.check()
print(f" N={n_test}: {r}")
if r == sat:
tab = extract_table(s, dot, n_test)
props = analyze_model(tab, "One absorber")
print(f" Properties: {props}")
# Check: does the classifier only use {0}? Or {0, something_else}?
tau_row = tab[3]
tau_values = set(tau_row)
print(f" Classifier values: {tau_values}")
results['F'] = ('SAT', props)
else:
results['F'] = ('UNSAT', None)
# Test G: No E-transparency
print("\n Test G: No E-transparency (E·⊤ ≠ ⊤ or E·⊥ ≠ ⊥)")
n_test = 10
s, dot = base_solver(n_test)
add_retraction(s, dot, n_test, 2, 3, core_lo=2, core_hi=n_test)
add_classifier(s, dot, n_test, 4)
add_kripke(s, dot, n_test)
# E is NOT transparent: E·⊤ ≠ ⊤ or E·⊥ ≠ ⊥
s.add(Or(dot[3][0] != 0, dot[3][1] != 1)) # E is at index 3
r = s.check()
print(f" N={n_test}: {r}")
if r == sat:
tab = extract_table(s, dot, n_test)
props = analyze_model(tab, "No E-trans")
print(f" Properties: {props}")
print(f" E·⊤ = {tab[3][0]}, E·⊥ = {tab[3][1]}")
# Check self-simulation: can the Q-depth decoder handle non-transparent E?
sim = check_bounded_self_simulation(tab)
print(f" Self-sim check: {sim}")
results['G'] = ('SAT', props)
else:
results['G'] = ('UNSAT', None)
return results
# ═══════════════════════════════════════════════════════════════════════
# Phase 3: Theoretical Argument
# ═══════════════════════════════════════════════════════════════════════
def theoretical_argument():
"""The universal self-simulator argument.
Given (S, ·, Q, E) a retraction-equipped magma that admits a single
recursive self-simulator, what must S contain?
"""
argument = """
══════════════════════════════════════════════════════════════════════
PHASE 3: THE UNIVERSAL SELF-SIMULATOR ARGUMENT
══════════════════════════════════════════════════════════════════════
Assume (S, ·, Q, E) is a retraction-equipped magma that admits a
single recursive self-simulator: one program that computes dot(a,b)
for all a, b ∈ S given Q-depth encoded inputs rep(a) = Q^a(⊤).
STEP 1: IDENTIFICATION REQUIRES DISCRIMINATION (→ classifier)
═══════════════════════════════════════════════════════════════
The self-simulator receives rep(a) = Q^a(⊤) and must determine a.
It peels Q layers using E until hitting ⊤. At each step, it must
test "is this ⊤?" — a binary yes/no test.
This requires an element that maps ⊤ to one value and non-⊤ to
another. In Ψ, this is the structural branch ρ (atom vs compound).
TIGHTNESS: TIGHT. Q-depth encoding is the ONLY natural encoding
in a retraction-equipped magma (it's the free monoid on {Q}).
Decoding Q-depth requires layer-by-layer peeling and testing.
No alternative avoids the binary test requirement.
But does this require a FULL classifier (all-boolean row)?
The structural branch ρ distinguishes atom from compound at the
term level. At the algebra level, τ distinguishes absorbers from
non-absorbers. The self-simulator needs the term-level branch, not
necessarily the algebraic classifier. However, the Branch axiom
connects the two: ρ dispatches based on τ's classification.
CONCLUSION: Some form of binary discrimination is DERIVED.
Whether this forces a full algebraic classifier depends on whether
the self-simulator operates purely at the term level or also at the
algebra level.
STEP 2: CONDITIONAL DISPATCH REQUIRES BRANCHING (→ branch)
═══════════════════════════════════════════════════════════
Having identified a, the self-simulator must do different things
for different values of a. Row 0 is constant 0. Row 3 is boolean.
Row 6 is Q's specific pattern. Each row behaves differently.