This repository was archived by the owner on Jul 29, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphi_compose_probe_v3.py
More file actions
286 lines (245 loc) · 10.4 KB
/
Copy pathphi_compose_probe_v3.py
File metadata and controls
286 lines (245 loc) · 10.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
# ratios: loc_comments=193:50 imports_exports=5:9 calls_definitions=92:9
"""
phi_compose_probe_v3.py — keystone, full depth (payload + face).
Lineage:
v1: carrier composes 100%; coordinate 43% (histogram forgot order).
v2: order-aware host coordinate -> offset-sum law, 600/600 EXACT.
Host channel composition PROVEN at depth-0.
v3 closes the two fences v2 left open:
(A) PAYLOAD channel (epicyclic recursion).
Every closed-token object carries a feature payload (recon: 196/196).
Does Phi compose THROUGH the recursive descent? i.e. is the field
embedding of A⊠B's payloads recoverable from the payloads of A and B
under the same offset-sum law, recursively, to the base (unit)?
This is the test the §3 resolution (open-class = epicyclic payload)
stands or falls on.
(B) FACE channel (XOR, "no bit negation" frozen).
Recon shows the encoder emits all-zero host faces, so a face law would
pass trivially. To actually EXERCISE the claim we build SYNTHETIC
face-bearing objects and test whether the face sequence composes under
XOR-in-product-order, matching multiply()'s f_A[k] ^ f_B[j].
Stdlib only. Run from repo root.
"""
from __future__ import annotations
from fractions import Fraction
import sys, os
HERE = os.path.dirname(os.path.abspath(__file__))
for cand in (HERE, os.getcwd(), os.path.join(HERE,'edcmbone'), os.path.join(os.getcwd(),'edcmbone')):
if cand not in sys.path:
sys.path.insert(0, cand)
try:
from ucns_v04 import UCNSObject, AnchorPayload, multiply
from closed_tokens import encode, DISPATCH
except ImportError as e:
print("FATAL: run from repo root (needs ucns_v04.py + closed_tokens.py).")
print(f" import error: {e}")
sys.exit(1)
def primes_of(n: int):
out, d = [], 2
while d * d <= n:
if n % d == 0:
out.append(d)
while n % d == 0:
n //= d
d += 1
if n > 1:
out.append(n)
return out or [1]
# ------------------------------------------------------------------
# Phi v3 — RECURSIVE, order-aware, with face.
#
# carriers : active prime set of n_min
# coords : ordered host anchor angles (mod 1 turn)
# faces : ordered host face bits
# sub : ordered tuple of Phi(payload) | None — RECURSIVE descent
#
# None payload encodes as None (the unit's image); recursion bottoms out there.
# ------------------------------------------------------------------
def phi(obj):
if obj is None:
return None
o = obj.normalize()
return {
"carriers": frozenset(primes_of(o.n_min)),
"coords": tuple(ap.theta % 1 for ap in o.anchors_pos),
"faces": tuple(o.faces_pos),
"sub": tuple(phi(ap.payload) for ap in o.anchors_pos),
}
# ---- composition laws (mirror multiply exactly) ----
def compose_phi(fa, fb):
"""
Predict Phi(A⊠B) from Phi(A), Phi(B), recursively — mirroring multiply():
host theta: (a + b) mod 1, A-outer / B-inner
host face : fa ^ fb, same order
payload : unit short-circuit, else recurse compose_phi
carriers : union (lcm at set level)
"""
if fa is None and fb is None:
return None
if fa is None: # unit ⊠ B = B
return fb
if fb is None: # A ⊠ unit = A
return fa
A, B = fa["coords"], fb["coords"]
fA, fB = fa["faces"], fb["faces"]
sA, sB = fa["sub"], fb["sub"]
coords, faces, sub = [], [], []
for k, a in enumerate(A):
for j, b in enumerate(B):
coords.append((a + b) % 1)
faces.append(fA[k] ^ fB[j])
# payload product with unit short-circuit (Guard 1 semantics)
pa, pb = sA[k], sB[j]
if pa is None and pb is None:
sub.append(None)
elif pa is None:
sub.append(pb)
elif pb is None:
sub.append(pa)
else:
sub.append(compose_phi(pa, pb))
return {
"carriers": fa["carriers"] | fb["carriers"],
"coords": tuple(coords),
"faces": tuple(faces),
"sub": tuple(sub),
}
def phi_equal(p, q):
if p is None and q is None:
return True
if p is None or q is None:
return False
if p["carriers"] != q["carriers"]:
return False
if p["coords"] != q["coords"]:
return False
if p["faces"] != q["faces"]:
return False
if len(p["sub"]) != len(q["sub"]):
return False
return all(phi_equal(a, b) for a, b in zip(p["sub"], q["sub"]))
def phi_equal_ignoring_face(p, q):
"""Diagnostic: do coords+carriers+payload match, isolating face as the culprit?"""
if p is None and q is None:
return True
if p is None or q is None:
return False
if p["carriers"] != q["carriers"] or p["coords"] != q["coords"]:
return False
if len(p["sub"]) != len(q["sub"]):
return False
return all(phi_equal_ignoring_face(a, b) for a, b in zip(p["sub"], q["sub"]))
# ------------------------------------------------------------------
# Part A — real recursive payload test on the closed-token vocabulary.
# ------------------------------------------------------------------
def test_payload():
toks = sorted(DISPATCH.keys())
objs = [(t, encode(t).normalize()) for t in toks if encode(t) is not None]
n = len(objs)
MAX = 600
step = max(1, (n * n) // MAX)
pairs = []
for i in range(n):
for j in range(n):
if (i * n + j) % step == 0:
pairs.append((objs[i], objs[j]))
if len(pairs) >= MAX:
break
if len(pairs) >= MAX:
break
full_ok = 0
total = 0
for (ta, A), (tb, B) in pairs:
try:
P = multiply(A, B)
except Exception:
continue
total += 1
pred = compose_phi(phi(A), phi(B))
if phi_equal(pred, phi(P)):
full_ok += 1
return full_ok, total
# ------------------------------------------------------------------
# Part B — synthetic face test (encoder emits all-zero faces, so we must
# construct face variation to actually exercise the XOR law).
# ------------------------------------------------------------------
def make_flat(angles, faces, n_dec):
return UCNSObject(
n_dec=n_dec, n_min=1,
anchors_pos=tuple(AnchorPayload(Fraction(a), None) for a in angles),
faces_pos=tuple(faces),
).normalize()
def test_face():
# A battery of small flat objects with VARIED face bits.
cases = [
# (anglesA, facesA, n_decA, anglesB, facesB, n_decB)
([0, Fraction(1,2)], [1, 0], 2, [0, Fraction(1,3), Fraction(2,3)], [0, 1, 1], 3),
([0, Fraction(1,3), Fraction(2,3)], [1,1,0], 3, [0, Fraction(1,2)], [1, 0], 2),
([0, Fraction(1,4), Fraction(1,2), Fraction(3,4)], [1,0,1,0], 4, [0, Fraction(1,2)], [1,1], 2),
([0, Fraction(1,2)], [0, 1], 2, [0, Fraction(1,2)], [1, 0], 2),
([0, Fraction(1,5), Fraction(2,5), Fraction(3,5), Fraction(4,5)], [1,1,0,0,1], 5,
[0, Fraction(1,3), Fraction(2,3)], [0,1,0], 3),
]
ok = 0
face_isolated_fail = 0
for aA, fA, dA, aB, fB, dB in cases:
A = make_flat(aA, fA, dA)
B = make_flat(aB, fB, dB)
P = multiply(A, B)
pred = compose_phi(phi(A), phi(B))
if phi_equal(pred, phi(P)):
ok += 1
elif phi_equal_ignoring_face(pred, phi(P)):
face_isolated_fail += 1
return ok, len(cases), face_isolated_fail
def main():
print("=" * 72)
print("Phi COMPOSITION PROBE v3 — payload + face (eng_ucns_spec.md §2.2.3)")
print("=" * 72)
print("\n[A] PAYLOAD channel — recursive descent on real closed-token objects")
pok, ptot = test_payload()
print(f" full recursive Phi composition: {pok}/{ptot} "
f"({100*pok/ptot:.1f}%)")
print("\n[B] FACE channel — synthetic face-bearing objects (XOR law)")
fok, ftot, fiso = test_face()
print(f" full Phi composition (incl. face): {fok}/{ftot}")
if fiso:
print(f" failures isolated to the FACE coordinate: {fiso}")
print("\n" + "-" * 72)
print("VERDICT")
payload_clean = (pok == ptot)
face_clean = (fok == ftot)
if payload_clean and face_clean:
print(" EXACT on BOTH channels.")
print(" -> Phi composes recursively through payloads AND through the")
print(" face XOR channel. Composition is carried at full depth for")
print(" the structures present. The keystone (§2.2.3) is answered:")
print(" the field is DERIVED, not learned, end to end.")
print(" -> §3 (open-class = epicyclic payload) is validated: the same")
print(" offset-sum law that composes the host also composes the")
print(" recursive interior. Content words can descend without")
print(" breaking field composition.")
print(" -> Remaining open: §2.2.4 carrier-bound over LONG sequences")
print(" (the genuine widening frontier), and the metric definition.")
elif payload_clean and not face_clean:
print(" PAYLOAD composes exactly; FACE has residual.")
print(f" Of {ftot} face cases, {fiso} failed ONLY in the face coordinate.")
print(" -> Recursion is sound; the face law needs inspection. Given")
print(" 'no bit negation' is frozen, suspect ORDER of XOR under")
print(" normalize() reordering, not the XOR itself.")
elif face_clean and not payload_clean:
print(f" FACE composes; PAYLOAD residual ({pok}/{ptot}).")
print(" -> Recursion does NOT compose cleanly. This bears directly on")
print(" §3: open-class payloads may not be free. Inspect depth where")
print(" it breaks — likely where payload carriers widen (ties to")
print(" the unsolved analytic widening frontier).")
else:
print(f" Residual on both ({pok}/{ptot} payload, {fok}/{ftot} face).")
print(" -> Re-isolate: host alone was 600/600 in v2, so any break here")
print(" is in recursion or face, not the offset-sum core.")
print("\nhmm: face was tested synthetically because the encoder emits all-zero")
print(" host faces — a clean synthetic pass means the LAW is sound; the")
print(" encoder simply hasn't yet used the channel it's entitled to.")
if __name__ == "__main__":
main()
# ratios: loc_comments=193:50 imports_exports=5:9 calls_definitions=92:9