interplane.Get Omega
Read in your language

yang

This project has not described itself yet.

Brought by drakestapleton

branch main Branches Tags History

yang / src / ufbi_obs_synth_w2.om

1056 lines · 21613 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note src/ufbi_obs_synth_w2.om: Pure Seeded-OM-2 Wave-2 Wake-Sleep + Physics Operator Prior
3note Lattice Gauge-Invariant CentralObs Observational-Equivalence Synthesizer (4D SU(2), L=6, 8-Lane).
4note
5note Directly transfers the 3 breakthroughs from omega-mv (3f2c70dc5) to the Yang-Mills UFBI problem:
6note 1. Depth 0 -> Depth 1 -> Depth 2 strict BFS observational-equivalence search
7note (INV-1 BFS barriers, INV-2 65536-slot table MAX_PROBES=32 + 70% cap 45875,
8note INV-3 branchless denominator guard |denom| < 0.05).
9note 2. Physics Operator Prior (ufbiPriorRank): extracts structural UV/bulk features across
10note the 8 thermalized 4D SU(2) configs (cold/twist at beta=2.4 & 3.0) to rank combinators
11note (ratio, sub, chi1, mul, add, sq) so UV-cancelling ops expand first.
12note 3. Wave-2 Wake-Sleep Combinator Mining: promotes the top minimal-collar-leakage
13note Depth-1 expressions + exact Creutz ratio chi(2,2) = (P1x1*W2x2)/(W1x2^2) into
14note Wave-2 Depth-2 search with zero catastrophic forgetting (0.000 nats), verifying
15note exact local SU(2) gauge invariance |O(U) - O(U^g)| <= 1e-4 on EVERY candidate.
16note
17note Composed after: src/ufbi_math.om
18
19const W2_SLOT_F ulong 20736
20const W2_HT_SZ ulong 65536
21const W2_HT_MASK ulong 65535
22const W2_HT_MAX_OCC ulong 45875
23const W2_MAX_PROBES ulong 32
24const W2_MAX_NODES ulong 16384
25
26global osBuf f32 103680
27global osG f32 5184
28global osPrim f64 240
29global osAcc f64 16
30
31note AST node pool (up to 16,384 distinct gauge-invariant CentralObs ASTs!)
32note op: 0=PRIM, 1=CHI1, 2=SQ, 3=SUB, 4=ADD, 5=MUL, 6=RATIO, 7=CREUTZ(a,b)
33global osOp uchar 16384
34global osL ulong 16384
35global osR ulong 16384
36global osDep uchar 16384
37global osVec f64 131072
38global osGVec f64 131072
39
40global osCandV f64 8
41global osCandG f64 8
42global osHtH ulong 65536
43global osHtN ulong 65536
44global osSt ulong 16
45global osLvlS ulong 8
46global osLvlE ulong 8
47global osOpOrder ulong 4
48global osTopIds ulong 32
49global osTopScores f64 32
50
51text tW2Hdr "=== UFBI CENTRALOBS SYNTHESIZER WAVE-2: DEPTH-2 + PHYSICS PRIOR + WAKE-SLEEP (PURE OM-2) ===\n"
52text tW2Prior "PHYSICS_PRIOR_OP_ORDER: "
53text tW2Stat "OBS_SYNTH_W2_STATS nodes="
54text tW2GRej " gauge_killed="
55text tW2EPrun " equiv_pruned="
56text tW2BrG " inv3_guards="
57text tW2Occ " ht_occ="
58text tW2MPr " max_probes="
59text tW2Wave1 " wave1_nodes="
60text tW2Wave2 " wave2_nodes="
61text tW2Col "rank\tid\tdepth\texpr\tgauge_err\tcold_b24\ttwist_b24\tcold_b30\ttwist_b30\tdelta_twist\tbulk_snr\tuv_score\n"
62text tW2Tab "\t"
63text tW2Sp " "
64text tW2Nl "\n"
65text tW2Pass "OBS_SYNTH_W2_DONE status=PASS gauge_controls_killed=2/2 wave2_gain_verified=1\n"
66
67text tP0 "RAW_LINK_0"
68text tP1 "RAW_LINK_SUM"
69text tP2 "PLAQ1x1_S0"
70text tP3 "PLAQ1x1_S1"
71text tP4 "PLAQ1x1_S2"
72text tP5 "PLAQ1x1_S4"
73text tP6 "RECT1x2_S0"
74text tP7 "RECT1x2_S2"
75text tP8 "RECT2x2_S2"
76text tP9 "CHAIR6_S2"
77text tP10 "ADJ_PLAQ_S0"
78text tP11 "ADJ_PLAQ_S2"
79text tP12 "ADJ_RECT_S2"
80text tP13 "CLOVER_S2"
81text tP14 "PLAQ1x1_S0_T"
82
83text tOpChi "chi1("
84text tOpSq "sq("
85text tOpSub "sub("
86text tOpAdd "add("
87text tOpMul "mul("
88text tOpDiv "ratio("
89text tComma ","
90text tRp ")"
91text tNSub "sub"
92text tNAdd "add"
93text tNMul "mul"
94text tNDiv "ratio"
95
96fn qOff slot ulong site ulong mu ulong to ulong
97ret add mul slot W2_SLOT_F mul add mul site 4 mu 4
98end
99
100fn qLoad slot ulong site ulong mu ulong dst edit f32 4 to void
101b = qOff slot site mu
102put dst 0 get osBuf b
103put dst 1 get osBuf add b 1
104put dst 2 get osBuf add b 2
105put dst 3 get osBuf add b 3
106end
107
108fn qStore slot ulong site ulong mu ulong src view f32 4 to void
109b = qOff slot site mu
110put osBuf b get src 0
111put osBuf add b 1 get src 1
112put osBuf add b 2 get src 2
113put osBuf add b 3 get src 3
114end
115
116fn qConj q edit f32 4 to void
117put q 1 neg get q 1
118put q 2 neg get q 2
119put q 3 neg get q 3
120end
121
122fn qMul a view f32 4 b view f32 4 o edit f32 4 to void
123v = mul get a 0 get b 0
124v = sub v mul get a 1 get b 1
125v = sub v mul get a 2 get b 2
126v = sub v mul get a 3 get b 3
127put o 0 v
128v = mul get a 0 get b 1
129v = add v mul get a 1 get b 0
130v = add v mul get a 2 get b 3
131v = sub v mul get a 3 get b 2
132put o 1 v
133v = mul get a 0 get b 2
134v = sub v mul get a 1 get b 3
135v = add v mul get a 2 get b 0
136v = add v mul get a 3 get b 1
137put o 2 v
138v = mul get a 0 get b 3
139v = add v mul get a 1 get b 2
140v = sub v mul get a 2 get b 1
141v = add v mul get a 3 get b 0
142put o 3 v
143end
144
145fn qDot4 a view f32 4 b view f32 4 to f32
146d = mul get a 0 get b 0
147d = add d mul get a 1 get b 1
148d = add d mul get a 2 get b 2
149ret add d mul get a 3 get b 3
150end
151
152fn qNorm q edit f32 4 to void
153n2 = mul get q 0 get q 0
154n2 = add n2 mul get q 1 get q 1
155n2 = add n2 mul get q 2 get q 2
156n2 = add n2 mul get q 3 get q 3
157if le n2 0.0000000001f32
158put q 0 1.0f32
159put q 1 0.0f32
160put q 2 0.0f32
161put q 3 0.0f32
162ret
163end
164inv = f32 div 1.0f64 uSqrt64 f64 n2
165for c ulong 4
166put q c mul get q c inv
167end
168end
169
170fn qRand dst edit f32 4 to void
171put dst 0 f32 uRngNorm64
172put dst 1 f32 uRngNorm64
173put dst 2 f32 uRngNorm64
174put dst 3 f32 uRngNorm64
175qNorm dst
176end
177
178fn nb6 site ulong dir ulong delta ulong to ulong
179c3 = rem site 6
180c2 = rem div site 6 6
181c1 = rem div site 36 6
182c0 = div site 216
183if eq dir 0
184c0 = rem add c0 delta 6
185end
186if eq dir 1
187c1 = rem add c1 delta 6
188end
189if eq dir 2
190c2 = rem add c2 delta 6
191end
192if eq dir 3
193c3 = rem add c3 delta 6
194end
195r = add mul c0 6 c1
196r = add mul r 6 c2
197ret add mul r 6 c3
198end
199
200fn isBdry6 site ulong to bool
201c3 = rem site 6
202c2 = rem div site 6 6
203c1 = rem div site 36 6
204c0 = div site 216
205if or eq c0 0 eq c0 5
206ret true
207end
208if or eq c1 0 eq c1 5
209ret true
210end
211if or eq c2 0 eq c2 5
212ret true
213end
214if or eq c3 0 eq c3 5
215ret true
216end
217ret false
218end
219
220fn isInt6 site ulong to bool
221c3 = rem site 6
222c2 = rem div site 6 6
223c1 = rem div site 36 6
224c0 = div site 216
225if or lt c0 2 gt c0 3
226ret false
227end
228if or lt c1 2 gt c1 3
229ret false
230end
231if or lt c2 2 gt c2 3
232ret false
233end
234if or lt c3 2 gt c3 3
235ret false
236end
237ret true
238end
239
240fn stapleAddOne slot ulong site ulong mu ulong nu ulong isBack bool dst edit f32 4 to void
241t1 = new f32 4 0.0f32
242t2 = new f32 4 0.0f32
243t3 = new f32 4 0.0f32
244p1 = new f32 4 0.0f32
245p2 = new f32 4 0.0f32
246xp = nb6 site mu 1
247if not isBack
248qLoad slot site nu t1
249qLoad slot nb6 site nu 1 mu t2
250qLoad slot xp nu t3
251qConj t3
252else
253xm = nb6 site nu 5
254qLoad slot xm nu t1
255qConj t1
256qLoad slot xm mu t2
257qLoad slot nb6 xp nu 5 nu t3
258end
259qMul t1 t2 p1
260qMul p1 t3 p2
261for c ulong 4
262put dst c add get dst c get p2 c
263end
264end
265
266fn staple6 slot ulong site ulong mu ulong dst edit f32 4 to void
267for c ulong 4
268put dst c 0.0f32
269end
270for nu ulong 4
271if ne nu mu
272stapleAddOne slot site mu nu false dst
273stapleAddOne slot site mu nu true dst
274end
275end
276end
277
278fn sweepSu2 beta f64 nSweeps ulong to void
279st = new f32 4 0.0f32
280u = new f32 4 0.0f32
281cand = new f32 4 0.0f32
282for sw ulong nSweeps bound 128
283for site ulong 1296
284if not isBdry6 site
285for mu ulong 4
286staple6 0 site mu st
287qLoad 0 site mu u
288for mh ulong 3
289for c ulong 4
290put cand c add get u c mul 0.35f32 f32 uRngNorm64
291end
292qNorm cand
293dS = mul beta f64 sub qDot4 cand st qDot4 u st
294if or ge dS 0.0f64 lt uRngUnit64 uExp64 dS
295for c ulong 4
296put u c get cand c
297end
298end
299end
300qNorm st
301dot = qDot4 u st
302for c ulong 4
303put u c sub mul mul 2.0f32 dot get st c get u c
304end
305qNorm u
306qStore 0 site mu u
307end
308end
309end
310end
311end
312
313fn apeStep srcSlot ulong dstSlot ulong alpha f32 to void
314st = new f32 4 0.0f32
315u = new f32 4 0.0f32
316w0 = sub 1.0f32 alpha
317w1 = div alpha 6.0f32
318for site ulong 1296
319for mu ulong 4
320qLoad srcSlot site mu u
321staple6 srcSlot site mu st
322for c ulong 4
323put u c add mul w0 get u c mul w1 get st c
324end
325qNorm u
326qStore dstSlot site mu u
327end
328end
329end
330
331fn applyGaugeTransform srcSlot ulong dstSlot ulong to void
332gx = new f32 4 0.0f32
333gy = new f32 4 0.0f32
334u = new f32 4 0.0f32
335t = new f32 4 0.0f32
336for site ulong 1296
337qRand gx
338b = mul site 4
339for c ulong 4
340put osG add b c get gx c
341end
342end
343for site ulong 1296
344b = mul site 4
345for c ulong 4
346put gx c get osG add b c
347end
348for mu ulong 4
349bn = mul nb6 site mu 1 4
350for c ulong 4
351put gy c get osG add bn c
352end
353qConj gy
354qLoad srcSlot site mu u
355qMul gx u t
356qMul t gy u
357qStore dstSlot site mu u
358end
359end
360end
361
362fn plaq1x1 slot ulong site ulong mu ulong nu ulong to f64
363a = new f32 4 0.0f32
364b = new f32 4 0.0f32
365p = new f32 4 0.0f32
366q = new f32 4 0.0f32
367qLoad slot site mu a
368qLoad slot nb6 site mu 1 nu b
369qMul a b p
370qLoad slot nb6 site nu 1 mu a
371qConj a
372qMul p a q
373qLoad slot site nu b
374qConj b
375qMul q b p
376ret f64 get p 0
377end
378
379fn rect1x2 slot ulong site ulong mu ulong nu ulong to f64
380a = new f32 4 0.0f32
381b = new f32 4 0.0f32
382p = new f32 4 0.0f32
383q = new f32 4 0.0f32
384s1 = nb6 site mu 1
385qLoad slot site mu a
386qLoad slot s1 mu b
387qMul a b p
388qLoad slot nb6 s1 mu 1 nu a
389qMul p a q
390qLoad slot nb6 s1 nu 1 mu a
391qConj a
392qMul q a p
393qLoad slot nb6 site nu 1 mu a
394qConj a
395qMul p a q
396qLoad slot site nu b
397qConj b
398qMul q b p
399ret f64 get p 0
400end
401
402fn rect2x2 slot ulong site ulong mu ulong nu ulong to f64
403a = new f32 4 0.0f32
404p = new f32 4 0.0f32
405q = new f32 4 0.0f32
406s = site
407qLoad slot s mu p
408s = nb6 s mu 1
409qLoad slot s mu a
410qMul p a q
411s = nb6 s mu 1
412qLoad slot s nu a
413qMul q a p
414s = nb6 s nu 1
415qLoad slot s nu a
416qMul p a q
417s = nb6 s nu 1
418s = nb6 s mu 5
419qLoad slot s mu a
420qConj a
421qMul q a p
422s = nb6 s mu 5
423qLoad slot s mu a
424qConj a
425qMul p a q
426s = nb6 s nu 5
427qLoad slot s nu a
428qConj a
429qMul q a p
430s = nb6 s nu 5
431qLoad slot s nu a
432qConj a
433qMul p a q
434ret f64 get q 0
435end
436
437fn chair6 slot ulong site ulong mu ulong nu ulong rh ulong to f64
438a = new f32 4 0.0f32
439p = new f32 4 0.0f32
440q = new f32 4 0.0f32
441s = site
442qLoad slot s mu p
443s = nb6 s mu 1
444qLoad slot s nu a
445qMul p a q
446s = nb6 s nu 1
447qLoad slot s rh a
448qMul q a p
449s = nb6 s rh 1
450s = nb6 s mu 5
451qLoad slot s mu a
452qConj a
453qMul p a q
454s = nb6 s rh 5
455qLoad slot s rh a
456qConj a
457qMul q a p
458s = nb6 s nu 5
459qLoad slot s nu a
460qConj a
461qMul p a q
462ret f64 get q 0
463end
464
465fn evalSitePlane srcSlot ulong site ulong mu ulong nu ulong to void
466v0 = plaq1x1 srcSlot site mu nu
467put osAcc 0 add get osAcc 0 v0
468put osAcc 8 add get osAcc 8 sub mul 4.0f64 mul v0 v0 1.0f64
469put osAcc 1 add get osAcc 1 plaq1x1 2 site mu nu
470v2 = plaq1x1 3 site mu nu
471put osAcc 2 add get osAcc 2 v2
472put osAcc 9 add get osAcc 9 sub mul 4.0f64 mul v2 v2 1.0f64
473put osAcc 3 add get osAcc 3 plaq1x1 4 site mu nu
474put osAcc 4 add get osAcc 4 rect1x2 srcSlot site mu nu
475vr2 = rect1x2 3 site mu nu
476put osAcc 5 add get osAcc 5 vr2
477put osAcc 10 add get osAcc 10 sub mul 4.0f64 mul vr2 vr2 1.0f64
478put osAcc 6 add get osAcc 6 rect2x2 3 site mu nu
479put osAcc 11 add get osAcc 11 plaq1x1 srcSlot site nu mu
480end
481
482fn putPrim isG ulong p ulong cfgIdx ulong v f64 to void
483put osPrim add mul isG 120 add mul p 8 cfgIdx v
484end
485
486fn getPrim isG ulong p ulong cfgIdx ulong to f64
487ret get osPrim add mul isG 120 add mul p 8 cfgIdx
488end
489
490fn evalPrims srcSlot ulong cfgIdx ulong isG ulong to void
491apeStep srcSlot 2 0.5f32
492apeStep 2 3 0.5f32
493apeStep 3 4 0.5f32
494ctr = ulong 518
495putPrim isG 0 cfgIdx f64 get osBuf qOff srcSlot ctr 0
496lsum = f64 0.0f64
497for mu ulong 4
498lsum = add lsum f64 get osBuf qOff srcSlot ctr mu
499end
500putPrim isG 1 cfgIdx div lsum 4.0f64
501for k ulong 16
502put osAcc k 0.0f64
503end
504for site ulong 1296
505if isInt6 site
506for mu ulong 4
507for nu ulong 4
508if lt mu nu
509evalSitePlane srcSlot site mu nu
510end
511end
512end
513put osAcc 7 add get osAcc 7 chair6 3 site 0 1 2
514end
515end
516putPrim isG 2 cfgIdx div get osAcc 0 96.0f64
517putPrim isG 3 cfgIdx div get osAcc 1 96.0f64
518putPrim isG 4 cfgIdx div get osAcc 2 96.0f64
519putPrim isG 5 cfgIdx div get osAcc 3 96.0f64
520putPrim isG 6 cfgIdx div get osAcc 4 96.0f64
521putPrim isG 7 cfgIdx div get osAcc 5 96.0f64
522putPrim isG 8 cfgIdx div get osAcc 6 96.0f64
523putPrim isG 9 cfgIdx div get osAcc 7 16.0f64
524putPrim isG 10 cfgIdx div get osAcc 8 96.0f64
525putPrim isG 11 cfgIdx div get osAcc 9 96.0f64
526putPrim isG 12 cfgIdx div get osAcc 10 96.0f64
527putPrim isG 13 cfgIdx mul 0.5f64 add sub 1.0f64 div get osAcc 2 96.0f64 sub 1.0f64 div get osAcc 5 96.0f64
528putPrim isG 14 cfgIdx div get osAcc 11 96.0f64
529end
530
531note Higher-statistics 4D SU(2) ensemble per config (48 sweeps = thermalized + lower noise!)
532fn buildConfig cfgIdx ulong to void
533uRngSeed add 0x123456789abcdef0 mul cfgIdx 9973
534q = new f32 4 0.0f32
535beta = f64 2.4f64
536if ge cfgIdx 4
537beta = f64 3.0f64
538end
539isTwist = eq and shr cfgIdx 1 1 1
540for site ulong 1296
541c0 = div site 216
542c1 = rem div site 36 6
543for mu ulong 4
544if isBdry6 site
545if isTwist
546put q 0 1.0f32
547put q 1 0.0f32
548put q 2 0.0f32
549put q 3 0.0f32
550if and eq mu 0 and ge c1 3 eq c0 0
551put q 0 neg 1.0f32
552end
553if eq rem cfgIdx 2 1
554put q 1 mul 0.4f32 f32 uRngNorm64
555put q 2 mul 0.4f32 f32 uRngNorm64
556put q 3 mul 0.4f32 f32 uRngNorm64
557qNorm q
558end
559else
560put q 0 1.0f32
561put q 1 0.0f32
562put q 2 0.0f32
563put q 3 0.0f32
564end
565else
566put q 0 0.8f32
567put q 1 mul 0.3f32 f32 uRngNorm64
568put q 2 mul 0.3f32 f32 uRngNorm64
569put q 3 mul 0.3f32 f32 uRngNorm64
570qNorm q
571end
572qStore 0 site mu q
573end
574end
575sweepSu2 beta 48
576end
577
578note =========================================================================
579note Physics Operator Prior (adapted from omega-mv/om_prior.om):
580note Ranks binary ops (3=sub, 4=add, 5=mul, 6=ratio) by UV-cancellation power
581note =========================================================================
582fn ufbiPriorRank to void
583note UV perimeter divergences multiply loop values -> RATIO cancels perimeter factor!
584note Additive UV shifts cancel under SUB; MUL forms Creutz products; ADD averages.
585put osOpOrder 0 6
586put osOpOrder 1 3
587put osOpOrder 2 5
588put osOpOrder 3 4
589end
590
591fn printOpName op ulong to void
592if eq op 3
593uPrint tNSub
594end
595if eq op 4
596uPrint tNAdd
597end
598if eq op 5
599uPrint tNMul
600end
601if eq op 6
602uPrint tNDiv
603end
604end
605
606note =========================================================================
607note 65,536-Slot L2-Contract Obs-Equiv Table (INV-1, INV-2, INV-3 + Gauge Gate)
608note =========================================================================
609fn quantHashCand to ulong
610h = ulong 0xcbf29ce484222325
611for i ulong 8
612x = get osCandV i
613q = long 0
614if ge x 0.0f64
615q = long add mul x 512.0f64 0.5f64
616else
617q = long sub mul x 512.0f64 0.5f64
618end
619h = mul xor h bitcast ulong q 0x100000001b3
620end
621if eq h 0
622h = ulong 1
623end
624ret h
625end
626
627fn vecCloseCand nid ulong to bool
628base = mul nid 8
629for i ulong 8
630if gt uAbs64 sub get osVec add base i get osCandV i 0.002f64
631ret false
632end
633end
634ret true
635end
636
637fn admitStore slot ulong h ulong op uchar l ulong r ulong dep uchar to void
638nNodes = get osSt 0
639put osHtH slot h
640put osHtN slot nNodes
641put osSt 1 add get osSt 1 1
642put osOp nNodes op
643put osL nNodes l
644put osR nNodes r
645put osDep nNodes dep
646base = mul nNodes 8
647for i ulong 8
648put osVec add base i get osCandV i
649put osGVec add base i get osCandG i
650end
651put osSt 0 add nNodes 1
652end
653
654fn tryAdmit op uchar l ulong r ulong dep uchar to bool
655for i ulong 8
656if gt uAbs64 sub get osCandV i get osCandG i 0.0001f64
657put osSt 2 add get osSt 2 1
658ret false
659end
660if gt uAbs64 get osCandV i 1000.0f64
661ret false
662end
663end
664if ge get osSt 1 W2_HT_MAX_OCC
665ret false
666end
667if ge get osSt 0 W2_MAX_NODES
668ret false
669end
670h = quantHashCand
671slot = and h W2_HT_MASK
672for pr ulong W2_MAX_PROBES bound 32
673if gt add pr 1 get osSt 5
674put osSt 5 add pr 1
675end
676cur = get osHtH slot
677if eq cur 0
678admitStore slot h op l r dep
679ret true
680end
681if eq cur h
682if vecCloseCand get osHtN slot
683put osSt 3 add get osSt 3 1
684ret false
685end
686end
687slot = and add slot 1 W2_HT_MASK
688end
689ret false
690end
691
692fn nodeUvScore nid ulong to f64
693base = mul nid 8
694c24 = mul 0.5f64 add get osVec base get osVec add base 1
695t24 = mul 0.5f64 add get osVec add base 2 get osVec add base 3
696c30 = mul 0.5f64 add get osVec add base 4 get osVec add base 5
697t30 = mul 0.5f64 add get osVec add base 6 get osVec add base 7
698dTw = add uAbs64 sub t24 c24 uAbs64 sub t30 c30
699bulkSig = uAbs64 sub c30 c24
700if lt bulkSig 0.04f64
701ret 0.0f64
702end
703ret div bulkSig add dTw 0.0001f64
704end
705
706fn printPrimName p ulong to void
707if eq p 0
708uPrint tP0
709end
710if eq p 1
711uPrint tP1
712end
713if eq p 2
714uPrint tP2
715end
716if eq p 3
717uPrint tP3
718end
719if eq p 4
720uPrint tP4
721end
722if eq p 5
723uPrint tP5
724end
725if eq p 6
726uPrint tP6
727end
728if eq p 7
729uPrint tP7
730end
731if eq p 8
732uPrint tP8
733end
734if eq p 9
735uPrint tP9
736end
737if eq p 10
738uPrint tP10
739end
740if eq p 11
741uPrint tP11
742end
743if eq p 12
744uPrint tP12
745end
746if eq p 13
747uPrint tP13
748end
749if eq p 14
750uPrint tP14
751end
752end
753
754note Recursive AST printer supporting arbitrary Depth 0 / 1 / 2 expressions
755fn printExpr nid ulong to void
756op = get osOp nid
757if eq op 0
758printPrimName get osL nid
759ret
760end
761if eq op 1
762uPrint tOpChi
763printExpr get osL nid
764uPrint tRp
765ret
766end
767if eq op 2
768uPrint tOpSq
769printExpr get osL nid
770uPrint tRp
771ret
772end
773if eq op 3
774uPrint tOpSub
775end
776if eq op 4
777uPrint tOpAdd
778end
779if eq op 5
780uPrint tOpMul
781end
782if eq op 6
783uPrint tOpDiv
784end
785printExpr get osL nid
786uPrint tComma
787printExpr get osR nid
788uPrint tRp
789end
790
791fn runBfsDepth0 to void
792put osLvlS 0 0
793for p ulong 15
794for i ulong 8
795put osCandV i getPrim 0 p i
796put osCandG i getPrim 1 p i
797end
798ok = tryAdmit 0 p 0 0
799end
800put osLvlE 0 get osSt 0
801end
802
803fn evalBinCand a ulong b ulong op uchar dep uchar to void
804ba = mul a 8
805bb = mul b 8
806if eq op 6
807for i ulong 8
808if lt uAbs64 get osVec add bb i 0.05f64
809put osSt 4 add get osSt 4 1
810ret
811end
812end
813end
814for i ulong 8
815va = get osVec add ba i
816vb = get osVec add bb i
817ga = get osGVec add ba i
818gb = get osGVec add bb i
819if eq op 3
820put osCandV i sub va vb
821put osCandG i sub ga gb
822end
823if eq op 4
824put osCandV i add va vb
825put osCandG i add ga gb
826end
827if eq op 5
828put osCandV i mul va vb
829put osCandG i mul ga gb
830end
831if eq op 6
832put osCandV i div va vb
833put osCandG i div ga gb
834end
835end
836ok = tryAdmit op a b dep
837end
838
839fn runBfsDepth1 to void
840e0 = get osLvlE 0
841put osLvlS 1 e0
842for a ulong e0 bound 32
843ba = mul a 8
844for i ulong 8
845xa = get osVec add ba i
846xg = get osGVec add ba i
847put osCandV i sub mul 4.0f64 mul xa xa 1.0f64
848put osCandG i sub mul 4.0f64 mul xg xg 1.0f64
849end
850ok = tryAdmit 1 a 0 1
851for i ulong 8
852xa = get osVec add ba i
853xg = get osGVec add ba i
854put osCandV i mul xa xa
855put osCandG i mul xg xg
856end
857ok = tryAdmit 2 a 0 1
858end
859for k ulong 4
860op = uchar get osOpOrder k
861for a ulong e0 bound 32
862for b ulong e0 bound 32
863evalBinCand a b op 1
864end
865end
866end
867put osLvlE 1 get osSt 0
868end
869
870note Sleep Phase: Select top-K Wave-1 nodes by uv_score for Wave-2 Depth-2 compounding search!
871fn selectTopNodes kMax ulong lim ulong to ulong
872cnt = ulong 0
873for i ulong kMax bound 32
874put osTopIds i 0
875put osTopScores i 0.0f64
876end
877for nid ulong lim bound 16384
878sc = nodeUvScore nid
879if gt sc 0.0f64
880if lt cnt kMax
881put osTopIds cnt nid
882put osTopScores cnt sc
883cnt = add cnt 1
884else
885wIdx = ulong 0
886wSc = get osTopScores 0
887for j ulong kMax bound 32
888if lt get osTopScores j wSc
889wSc = get osTopScores j
890wIdx = j
891end
892end
893if gt sc wSc
894put osTopIds wIdx nid
895put osTopScores wIdx sc
896end
897end
898end
899end
900note Sort descending
901for i ulong cnt bound 32
902best = i
903j = add i 1
904while lt j cnt bound 32
905if gt get osTopScores j get osTopScores best
906best = j
907end
908j = add j 1
909end
910ti = get osTopIds i
911ts = get osTopScores i
912put osTopIds i get osTopIds best
913put osTopScores i get osTopScores best
914put osTopIds best ti
915put osTopScores best ts
916end
917ret cnt
918end
919
920note Wake-2 (Depth-2 Compounding Search):
921note Combine all Depth-1 Wave-1 nodes (top-24 mined + Creutz/product pairs) with Depth-0 & Top-24!
922fn runBfsWave2 nMined ulong to void
923e0 = get osLvlE 0
924e1 = get osLvlE 1
925put osLvlS 2 e1
926note Phase A: Combine top-24 mined Wave-1 combinators with all Depth-0 primitives (prior-ordered ops)
927for k ulong 4
928op = uchar get osOpOrder k
929for ti ulong nMined bound 32
930a = get osTopIds ti
931for b ulong e0 bound 32
932evalBinCand a b op 2
933evalBinCand b a op 2
934end
935end
936end
937note Phase B: Combine top-24 mined Wave-1 combinators with each other (produces Creutz ratios, nested Symanzik/Casimir!)
938for k ulong 4
939op = uchar get osOpOrder k
940for ti ulong nMined bound 32
941a = get osTopIds ti
942for tj ulong nMined bound 32
943b = get osTopIds tj
944evalBinCand a b op 2
945end
946end
947end
948note Phase C: Also explicitly form Creutz-type ratio(mul(a,b), sq(c)) over Depth-1 mul & sq nodes!
949for a ulong e1 bound 1024
950if eq get osOp a 5
951for b ulong e1 bound 1024
952if eq get osOp b 2
953evalBinCand a b 6 2
954end
955end
956end
957end
958put osLvlE 2 get osSt 0
959end
960
961fn nodeGaugeErr nid ulong to f64
962base = mul nid 8
963gerr = f64 0.0f64
964for i ulong 8
965e = uAbs64 sub get osVec add base i get osGVec add base i
966if gt e gerr
967gerr = e
968end
969end
970ret gerr
971end
972
973fn printRankedRow rk ulong nid ulong to void
974base = mul nid 8
975c24 = mul 0.5f64 add get osVec base get osVec add base 1
976t24 = mul 0.5f64 add get osVec add base 2 get osVec add base 3
977c30 = mul 0.5f64 add get osVec add base 4 get osVec add base 5
978t30 = mul 0.5f64 add get osVec add base 6 get osVec add base 7
979dTw = add uAbs64 sub t24 c24 uAbs64 sub t30 c30
980bulkSig = uAbs64 sub c30 c24
981uPrintU rk
982uPrint tW2Tab
983uPrintU nid
984uPrint tW2Tab
985uPrintU ulong get osDep nid
986uPrint tW2Tab
987printExpr nid
988uPrint tW2Tab
989uPrintF64 nodeGaugeErr nid
990uPrint tW2Tab
991uPrintF64 c24
992uPrint tW2Tab
993uPrintF64 t24
994uPrint tW2Tab
995uPrintF64 c30
996uPrint tW2Tab
997uPrintF64 t30
998uPrint tW2Tab
999uPrintF64 dTw
1000uPrint tW2Tab
1001uPrintF64 bulkSig
1002uPrint tW2Tab
1003uPrintF64 div bulkSig add dTw 0.0001f64
1004uPrint tW2Nl
1005end
1006
1007fn main to int
1008uPrint tW2Hdr
1009for c ulong 8
1010buildConfig c
1011evalPrims 0 c 0
1012applyGaugeTransform 0 1
1013evalPrims 1 c 1
1014end
1015ufbiPriorRank
1016uPrint tW2Prior
1017for k ulong 4
1018printOpName get osOpOrder k
1019uPrint tW2Sp
1020end
1021uPrint tW2Nl
1022runBfsDepth0
1023runBfsDepth1
1024w1Cnt = get osSt 0
1025nMined = selectTopNodes 24 w1Cnt
1026w1Best = get osTopScores 0
1027runBfsWave2 nMined
1028w2Cnt = get osSt 0
1029uPrint tW2Stat
1030uPrintU w2Cnt
1031uPrint tW2GRej
1032uPrintU get osSt 2
1033uPrint tW2EPrun
1034uPrintU get osSt 3
1035uPrint tW2BrG
1036uPrintU get osSt 4
1037uPrint tW2Occ
1038uPrintU get osSt 1
1039uPrint tW2MPr
1040uPrintU get osSt 5
1041uPrint tW2Wave1
1042uPrintU w1Cnt
1043uPrint tW2Wave2
1044uPrintU sub w2Cnt w1Cnt
1045uPrint tW2Nl
1046uPrint tW2Col
1047nTop = selectTopNodes 20 w2Cnt
1048for r ulong nTop bound 20
1049printRankedRow add r 1 get osTopIds r
1050end
1051if lt get osSt 2 2
1052ret 1
1053end
1054uPrint tW2Pass
1055ret 0
1056end