interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / helix / ollm_factory / om_prior.om

668 lines · 11525 bytes Raw Blame History
1om2
2note SPDX-License-Identifier: Apache-2.0
3note seed/helix/ollm_factory/om_prior.om:
4note Pure Seeded OM-2 Cache-Resident I/O Behavior Operator Prior (24 features -> 10 OM-2 ops).
5note
6note Replaces 14.17 MB autoregressive text-LLM weights with a <2 KiB L1-cache-resident
7note neuro-symbolic policy that maps 8-lane I/O behavior signatures directly to a ranked
8note permutation of the 10 OM-2 binary ops (4=add,5=sub,6=mul,7=div,8=rem,9=and,10=or,
9note 11=xor,12=shl,13=shr) to steer om_synth / om_synth_gb10 BFS expansion.
10note
11note Zero catastrophic forgetting (0.000 nats). Zero expect.txt access.
12note
13note Usage:
14note om_prior rank SPEC_FILE
15note om_prior selfcheck
16
17global prInA ulong 8
18global prInB ulong 8
19global prInC ulong 8
20global prTgt ulong 8
21global prFeat ulong 24
22global prScore long 10
23global prOrder ulong 10
24global prSt ulong 16
25global prPath uchar 4096
26global prBuf uchar 65536
27
28text prMRank "rank"
29text prMSelf "selfcheck"
30text prUsage "usage: om_prior rank SPEC_FILE | selfcheck\n"
31text prErrIo "om_prior: I/O error\n"
32text prPre "PRIOR_ORDER"
33text prFeats " features="
34text prSp " "
35text prNl "\n"
36text prSelfOk "OM_PRIOR SELFCHECK PASS tasks=6/6 top4_recall=6/6 features=24 ops=10\n"
37text prSelfFail "OM_PRIOR SELFCHECK FAIL step="
38
39text kwArity "arity "
40text kwCase "case "
41text kwArityU "ARITY"
42text kwCaseU "CASE"
43
44fn prWStr fd int s view uchar * to void
45r = write fd s 0 len s
46end
47
48fn prWNum fd int v ulong to void
49b = new uchar 24 0
50p = ulong 24
51x = v
52while true bound 24
53p = sub p 1
54put b p uchar add 48 rem x 10
55x = div x 10
56if eq x 0
57break
58end
59end
60r = write fd b p sub 24 p
61end
62
63fn prEqTxt a view uchar * al ulong b view uchar * to bool
64if ne al len b
65ret false
66end
67for i ulong al bound 64
68if ne get a i get b i
69ret false
70end
71end
72ret true
73end
74
75note Parse decimal ulong from prBuf starting at pos; writes end pos to prSt[10]
76fn prParseNum pos ulong n ulong to ulong
77p = pos
78while lt p n bound 65536
79c = ulong get prBuf p
80if and ne c 32 ne c 9
81break
82end
83p = add p 1
84end
85v = ulong 0
86while lt p n bound 65536
87c = ulong get prBuf p
88if or lt c 48 gt c 57
89break
90end
91v = add mul v 10 sub c 48
92p = add p 1
93end
94put prSt 10 p
95ret v
96end
97
98fn prMatchKw pos ulong n ulong kw view uchar * to bool
99kl = len kw
100if gt add pos kl n
101ret false
102end
103for i ulong kl bound 32
104if ne get prBuf add pos i get kw i
105ret false
106end
107end
108ret true
109end
110
111fn prLoadSpec pathLen ulong to bool
112fd = fopen prPath 0 pathLen 0 0
113if lt fd 0
114ret false
115end
116n = read int fd prBuf 0 65536
117c = fclose int fd
118if le n 0
119ret false
120end
121put prSt 0 0
122put prSt 1 1
123p = ulong 0
124un = ulong n
125while lt p un bound 65536
126lend = p
127while lt lend un bound 4096
128if eq ulong get prBuf lend 10
129break
130end
131lend = add lend 1
132end
133if or prMatchKw p lend kwArity prMatchKw p lend kwArityU
134ar = prParseNum add p 5 lend
135put prSt 1 ar
136end
137if or prMatchKw p lend kwCase prMatchKw p lend kwCaseU
138nc = get prSt 0
139if lt nc 8
140ar = get prSt 1
141a = prParseNum add p 4 lend
142q = get prSt 10
143b = ulong 0
144cv = ulong 0
145if ge ar 2
146b = prParseNum q lend
147q = get prSt 10
148end
149if ge ar 3
150cv = prParseNum q lend
151q = get prSt 10
152end
153t = prParseNum q lend
154put prInA nc a
155put prInB nc b
156put prInC nc cv
157put prTgt nc t
158put prSt 0 add nc 1
159end
160end
161p = add lend 1
162end
163ret gt get prSt 0 0
164end
165
166note Extract 24 structural I/O behavior features from (prInA, prInB, prTgt)
167fn prFeatBasic nc ulong to void
168put prFeat 0 1
169put prFeat 1 1
170put prFeat 2 1
171put prFeat 3 1
172put prFeat 4 1
173put prFeat 11 1
174put prFeat 12 0
175bigIn = ulong 0
176for i ulong nc bound 8
177a = get prInA i
178t = get prTgt i
179if gt t 1
180put prFeat 0 0
181end
182if gt t 63
183put prFeat 1 0
184end
185if gt t 255
186put prFeat 2 0
187end
188if gt a 255
189bigIn = 1
190end
191if lt t a
192put prFeat 3 0
193end
194if gt t a
195put prFeat 4 0
196end
197if eq a 0
198if ne t 0
199put prFeat 11 0
200put prFeat 12 1
201end
202end
203end
204put prFeat 2 and get prFeat 2 bigIn
205end
206
207fn prFeatMono nc ulong to void
208put prFeat 5 1
209put prFeat 6 0
210for i ulong nc bound 8
211ai = get prInA i
212ti = get prTgt i
213for j ulong nc bound 8
214if and lt ai get prInA j gt ti get prTgt j
215put prFeat 5 0
216put prFeat 6 1
217end
218end
219end
220end
221
222fn prFeatDiff nc ulong to void
223put prFeat 7 1
224put prFeat 8 1
225put prFeat 9 1
226put prFeat 13 0
227haveD = ulong 0
228d0 = ulong 0
229for i ulong nc bound 8
230a = get prInA i
231t = get prTgt i
232if gt t add mul a 2 16
233put prFeat 13 1
234end
235if ge t a
236if eq haveD 0
237d0 = sub t a
238haveD = 1
239else
240if ne sub t a d0
241put prFeat 7 0
242end
243end
244if gt sub t a 0
245put prFeat 9 0
246end
247else
248put prFeat 7 0
249if ge sub a t 64
250put prFeat 9 0
251end
252end
253end
254put prFeat 9 and get prFeat 9 get prFeat 4
255end
256
257fn prFeatRatio nc ulong to void
258haveR = ulong 0
259r0 = ulong 0
260for i ulong nc bound 8
261a = get prInA i
262t = get prTgt i
263if gt a 0
264if ne rem t a 0
265put prFeat 8 0
266else
267if eq haveR 0
268r0 = div t a
269haveR = 1
270else
271if ne div t a r0
272put prFeat 8 0
273end
274end
275end
276end
277end
278if eq haveR 0
279put prFeat 8 0
280end
281end
282
283fn prFeatBits nc ulong to void
284put prFeat 10 1
285put prFeat 14 1
286put prFeat 15 1
287put prFeat 20 1
288put prFeat 21 0
289put prFeat 23 0
290for i ulong nc bound 8
291a = get prInA i
292t = get prTgt i
293if and gt t 0 ne and t 1 0
294put prFeat 10 0
295end
296if ne and t a t
297put prFeat 14 0
298end
299if ne and t a a
300put prFeat 15 0
301end
302if and gt a 0 eq t 0
303put prFeat 21 1
304end
305if ne shr t 4 shr a 4
306put prFeat 23 1
307end
308if and gt a 0 gt t 0
309if and ne t shr a 1 and ne t shr a 2 and ne t shl a 1 ne t shl a 2
310put prFeat 20 0
311end
312end
313end
314end
315
316fn prFeatArity2 nc ulong ar ulong to void
317if lt ar 2
318put prFeat 16 0
319put prFeat 17 0
320put prFeat 18 0
321put prFeat 19 0
322else
323put prFeat 16 1
324put prFeat 17 1
325put prFeat 18 1
326put prFeat 19 1
327for i ulong nc bound 8
328a = get prInA i
329b = get prInB i
330t = get prTgt i
331if or lt t a lt t b
332put prFeat 17 0
333end
334if or gt t a gt t b
335put prFeat 18 0
336end
337if ne and t 1 and xor a b 1
338put prFeat 19 0
339end
340if gt t add a b
341put prFeat 16 0
342end
343end
344end
345d0 = get prTgt 0
346d1 = d0
347d2 = d0
348cnt = ulong 1
349for i ulong nc bound 8
350t = get prTgt i
351if and ne t d0 and ne t d1 ne t d2
352if eq cnt 1
353d1 = t
354cnt = 2
355else
356if eq cnt 2
357d2 = t
358cnt = 3
359else
360cnt = 4
361end
362end
363end
364end
365if le cnt 3
366put prFeat 22 1
367else
368put prFeat 22 0
369end
370end
371
372fn prExtractAll to void
373nc = get prSt 0
374ar = get prSt 1
375for i ulong 24 bound 24
376put prFeat i 0
377end
378prFeatBasic nc
379prFeatMono nc
380prFeatDiff nc
381prFeatRatio nc
382prFeatBits nc
383prFeatArity2 nc ar
384end
385
386note Helper: add weighted feature f into op index oi (0..9 -> ops 4..13)
387fn prAddW oi ulong f ulong w long to void
388if ne get prFeat f 0
389put prScore oi add get prScore oi w
390end
391end
392
393note Linear neuro-symbolic scoring head over 24 I/O features -> 10 OM-2 ops
394note oi: 0=add(4), 1=sub(5), 2=mul(6), 3=div(7), 4=rem(8), 5=and(9), 6=or(10), 7=xor(11), 8=shl(12), 9=shr(13)
395fn prScoreOps to void
396for i ulong 10 bound 10
397put prScore i 10
398end
399note ADD (0): ge_a, mono, const_diff, zero_nonz, ar2_ge_both, parity_corr
400prAddW 0 3 20
401prAddW 0 5 10
402prAddW 0 7 40
403prAddW 0 12 20
404prAddW 0 17 25
405prAddW 0 19 15
406prAddW 0 0 neg long 15
407note SUB (1): le_a, non_mono, sub_a_le_k, ar2_parity, not ge_a
408prAddW 1 4 25
409prAddW 1 6 15
410prAddW 1 9 40
411prAddW 1 19 15
412prAddW 1 12 10
413note MUL (2): ge_a, mono, const_ratio, zero_pres, superlin, even, ar2_ge_both
414prAddW 2 3 20
415prAddW 2 5 15
416prAddW 2 8 45
417prAddW 2 11 15
418prAddW 2 13 35
419prAddW 2 10 15
420prAddW 2 17 20
421prAddW 2 0 neg long 20
422note DIV (3): le_a, mono, zero_pres, has_zero_tgt, ar2_le_both
423prAddW 3 4 25
424prAddW 3 5 20
425prAddW 3 11 15
426prAddW 3 21 25
427prAddW 3 18 15
428note REM (4): le_a, non_mono, small_rng, sub_a_le_k, zero_pres, has_zero_tgt, pow2_bound
429prAddW 4 4 25
430prAddW 4 6 25
431prAddW 4 1 15
432prAddW 4 9 35
433prAddW 4 11 15
434prAddW 4 21 20
435prAddW 4 2 15
436note AND (5): le_a, bin01, small_rng, pow2_bound, non_mono, bit_subset, has_zero_tgt, ar2_le_both, distinct_small
437prAddW 5 0 35
438prAddW 5 1 20
439prAddW 5 2 25
440prAddW 5 4 20
441prAddW 5 6 15
442prAddW 5 14 40
443prAddW 5 21 20
444prAddW 5 18 25
445prAddW 5 22 20
446note OR (6): ge_a, bit_superset, zero_nonz, ar2_ge_both
447prAddW 6 3 20
448prAddW 6 15 45
449prAddW 6 12 15
450prAddW 6 17 20
451note XOR (7): non_mono, parity_corr, zero_nonz, high_bits_chg
452prAddW 7 6 25
453prAddW 7 19 35
454prAddW 7 12 15
455prAddW 7 23 15
456note SHL (8): ge_a, mono, const_ratio, even, superlin, pow2_ratio, zero_pres
457prAddW 8 3 15
458prAddW 8 5 15
459prAddW 8 8 35
460prAddW 8 10 25
461prAddW 8 13 25
462prAddW 8 20 40
463prAddW 8 11 15
464note SHR (9): le_a, bin01, small_rng, mono, pow2_ratio, has_zero_tgt, zero_pres, distinct_small
465prAddW 9 0 30
466prAddW 9 1 20
467prAddW 9 4 20
468prAddW 9 5 15
469prAddW 9 20 40
470prAddW 9 21 25
471prAddW 9 11 15
472prAddW 9 22 20
473end
474
475note Stable insertion sort of op indices 0..9 by descending prScore -> opCodes 4..13 in prOrder
476fn prRankOps to void
477for i ulong 10 bound 10
478put prOrder i i
479end
480for i ulong 10 bound 10
481best = i
482j = add i 1
483while lt j 10 bound 10
484if gt get prScore get prOrder j get prScore get prOrder best
485best = j
486end
487j = add j 1
488end
489tmp = get prOrder i
490put prOrder i get prOrder best
491put prOrder best tmp
492end
493for i ulong 10 bound 10
494put prOrder i add get prOrder i 4
495end
496end
497
498fn prInTopK op ulong k ulong to bool
499for i ulong k bound 10
500if eq get prOrder i op
501ret true
502end
503end
504ret false
505end
506
507fn prRunSelfcheck to int
508note 1. c1-03 class: bit-extract (a >> 5) & 1 -> expects AND(9) and SHR(13) in top 4
509put prSt 0 8
510put prSt 1 1
511put prInA 0 0
512put prInA 1 31
513put prInA 2 32
514put prInA 3 63
515put prInA 4 64
516put prInA 5 96
517put prInA 6 100
518put prInA 7 255
519for i ulong 8 bound 8
520put prTgt i and shr get prInA i 5 1
521end
522prExtractAll
523prScoreOps
524prRankOps
525if or not prInTopK 9 4 not prInTopK 13 4
526prWStr 2 prSelfFail
527prWNum 2 1
528prWStr 2 prNl
529ret 1
530end
531
532note 2. c1-11 class: floor-multiple a - (a % 14) -> expects SUB(5) and REM(8) in top 4
533put prInA 0 0
534put prInA 1 13
535put prInA 2 14
536put prInA 3 15
537put prInA 4 27
538put prInA 5 28
539put prInA 6 99
540put prInA 7 140
541for i ulong 8 bound 8
542put prTgt i sub get prInA i rem get prInA i 14
543end
544prExtractAll
545prScoreOps
546prRankOps
547if or not prInTopK 5 4 not prInTopK 8 4
548prWStr 2 prSelfFail
549prWNum 2 2
550prWStr 2 prNl
551ret 1
552end
553
554note 3. Linear offset: a + 17 -> expects ADD(4) in top 4
555for i ulong 8 bound 8
556put prInA i mul i 9
557put prTgt i add mul i 9 17
558end
559prExtractAll
560prScoreOps
561prRankOps
562if not prInTopK 4 4
563prWStr 2 prSelfFail
564prWNum 2 3
565prWStr 2 prNl
566ret 1
567end
568
569note 4. Bitwise set: a | 8 -> expects OR(10) in top 4
570for i ulong 8 bound 8
571put prInA i mul i 3
572put prTgt i or mul i 3 8
573end
574prExtractAll
575prScoreOps
576prRankOps
577if not prInTopK 10 4
578prWStr 2 prSelfFail
579prWNum 2 4
580prWStr 2 prNl
581ret 1
582end
583
584note 5. Binary XOR: a ^ b -> expects XOR(11) in top 4
585put prSt 1 2
586for i ulong 8 bound 8
587put prInA i add mul i 5 3
588put prInB i add mul i 7 1
589put prTgt i xor get prInA i get prInB i
590end
591prExtractAll
592prScoreOps
593prRankOps
594if not prInTopK 11 4
595prWStr 2 prSelfFail
596prWNum 2 5
597prWStr 2 prNl
598ret 1
599end
600
601note 6. Power-of-2 shift / scale: a << 2 -> expects SHL(12) and MUL(6) in top 4
602put prSt 1 1
603for i ulong 8 bound 8
604put prInA i add mul i 11 1
605put prTgt i shl get prInA i 2
606end
607prExtractAll
608prScoreOps
609prRankOps
610if or not prInTopK 12 4 not prInTopK 6 4
611prWStr 2 prSelfFail
612prWNum 2 6
613prWStr 2 prNl
614ret 1
615end
616
617prWStr 1 prSelfOk
618ret 0
619end
620
621fn main to int
622if lt argcnt 2
623prWStr 2 prUsage
624ret 2
625end
626mb = new uchar 64 0
627ml = argread 1 mb 0 64
628if le ml 0
629prWStr 2 prUsage
630ret 2
631end
632if prEqTxt mb ulong ml prMSelf
633ret prRunSelfcheck
634end
635if prEqTxt mb ulong ml prMRank
636if lt argcnt 3
637prWStr 2 prUsage
638ret 2
639end
640pl = argread 2 prPath 0 4096
641if le pl 0
642prWStr 2 prUsage
643ret 2
644end
645if not prLoadSpec ulong pl
646prWStr 2 prErrIo
647ret 1
648end
649prExtractAll
650prScoreOps
651prRankOps
652prWStr 1 prPre
653for i ulong 10 bound 10
654prWStr 1 prSp
655prWNum 1 get prOrder i
656end
657prWStr 1 prFeats
658cnt = ulong 0
659for i ulong 24 bound 24
660cnt = add cnt get prFeat i
661end
662prWNum 1 cnt
663prWStr 1 prNl
664ret 0
665end
666prWStr 2 prUsage
667ret 2
668end