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 / rlvr_breadth.om

936 lines · 18390 bytes Raw Blame History
1om2
2note SPDX-License-Identifier: Apache-2.0
3note seed/helix/ollm_factory/rlvr_breadth.om:
4note Pure seeded OM-2 Mechanical RLVR Breadth Factory covering all 10 coding skill
5note families (arith, branch, bits, digits, loop, fold, select, count, scan, rewrite)
6note with multi-phrasing natural-language prompts, NUL (\0) EOS delimiters, and a
7note self-checking `oracle` mode compiled identically across Strand A and Strand B.
8note
9note Modes (argv[1]):
10note corpus [variant 1..9] -> NUL-delimited verified OM-2 training records
11note oracle [variant 1..9] -> self-checking om2 program executing 100% of records
12
13global rbMode ulong 1
14global rbVar ulong 1
15global rbId ulong 1
16
17text rbOm2 "om2\n"
18text rbNote "note "
19text rbFnU1 "\nfn solve a ulong to ulong\n"
20text rbFnU2 "\nfn solve a ulong b ulong to ulong\n"
21text rbFnU3 "\nfn solve a ulong b ulong c ulong to ulong\n"
22text rbFnAr "\nfn solve a view ulong 8 n ulong to ulong\n"
23text rbFnAw "\nfn solve a edit ulong 8 n ulong to void\n"
24text rbEnd "\nend\n"
25text rbOrPfx "fn g_"
26text rbOrU1 " a ulong to ulong\n"
27text rbOrU2 " a ulong b ulong to ulong\n"
28text rbOrU3 " a ulong b ulong c ulong to ulong\n"
29text rbOrAr " a view ulong 8 n ulong to ulong\n"
30text rbOrAw " a edit ulong 8 n ulong to void\n"
31text rbMainH "fn main to int\narr = new ulong 8 0\nput arr 0 3\nput arr 1 11\nput arr 2 0\nput arr 3 7\nput arr 4 19\nput arr 5 4\nput arr 6 2\nput arr 7 15\n"
32text rbMainT "ret 0\nend\n"
33text rbReset "put arr 0 3\nput arr 1 11\nput arr 2 0\nput arr 3 7\nput arr 4 19\nput arr 5 4\nput arr 6 2\nput arr 7 15\n"
34text rbChkA "if ne g_"
35text rbChkB " "
36text rbChkC "\nexit 1\nend\n"
37text rbCallG "g_"
38text rbAwChk " arr 8\nif ne add get arr 0 add get arr 3 get arr 7 "
39text rbSpc " "
40text rbNl "\n"
41text rbOrArrArg "arr 8"
42
43text rbV0 "return "
44text rbV1 "compute "
45text rbV2 "find "
46text rbV3 "calculate "
47text rbV4 "output "
48text rbV5 "give "
49
50text rbArgOracle "oracle"
51
52fn rbWrt s view uchar * to void
53r = write 1 s 0 len s
54end
55
56fn rbNul to void
57b = new uchar 1 0
58r = write 1 b 0 1
59end
60
61fn rbNum v ulong to void
62b = new uchar 24 0
63p = ulong 24
64x = v
65while true bound 24
66p = sub p 1
67put b p uchar add 48 rem x 10
68x = div x 10
69if eq x 0
70break
71end
72end
73r = write 1 b p sub 24 p
74end
75
76fn rbVerb k ulong to void
77m = rem k 6
78if eq m 0
79rbWrt rbV0
80ret
81end
82if eq m 1
83rbWrt rbV1
84ret
85end
86if eq m 2
87rbWrt rbV2
88ret
89end
90if eq m 3
91rbWrt rbV3
92ret
93end
94if eq m 4
95rbWrt rbV4
96ret
97end
98rbWrt rbV5
99end
100
101fn rbNextId to ulong
102id = add get rbId 0 1
103put rbId 0 id
104ret id
105end
106
107fn rbBeginFn shape ulong desc view uchar * to ulong
108id = rbNextId
109if eq get rbMode 0 0
110rbWrt rbNote
111rbVerb add id get rbVar 0
112rbWrt desc
113if eq shape 1
114rbWrt rbFnU1
115end
116if eq shape 2
117rbWrt rbFnU2
118end
119if eq shape 3
120rbWrt rbFnU3
121end
122if eq shape 4
123rbWrt rbFnAr
124end
125if eq shape 5
126rbWrt rbFnAw
127end
128else
129rbWrt rbOrPfx
130rbNum id
131if eq shape 1
132rbWrt rbOrU1
133end
134if eq shape 2
135rbWrt rbOrU2
136end
137if eq shape 3
138rbWrt rbOrU3
139end
140if eq shape 4
141rbWrt rbOrAr
142end
143if eq shape 5
144rbWrt rbOrAw
145end
146end
147ret id
148end
149
150fn rbEndFn to void
151rbWrt rbEnd
152if eq get rbMode 0 0
153rbNul
154else
155rbWrt rbNl
156end
157end
158
159fn rbChkU1 id ulong x ulong exp ulong to void
160rbWrt rbChkA
161rbNum id
162rbWrt rbChkB
163rbNum x
164rbWrt rbChkB
165rbNum exp
166rbWrt rbChkC
167end
168
169fn rbChkU2 id ulong x ulong y ulong exp ulong to void
170rbWrt rbChkA
171rbNum id
172rbWrt rbChkB
173rbNum x
174rbWrt rbChkB
175rbNum y
176rbWrt rbChkB
177rbNum exp
178rbWrt rbChkC
179end
180
181fn rbChkU3 id ulong x ulong y ulong z ulong exp ulong to void
182rbWrt rbChkA
183rbNum id
184rbWrt rbChkB
185rbNum x
186rbWrt rbChkB
187rbNum y
188rbWrt rbChkB
189rbNum z
190rbWrt rbChkB
191rbNum exp
192rbWrt rbChkC
193end
194
195fn rbChkAr id ulong exp ulong to void
196rbWrt rbChkA
197rbNum id
198rbWrt rbSpc
199rbWrt rbOrArrArg
200rbWrt rbSpc
201rbNum exp
202rbWrt rbChkC
203end
204
205fn rbChkAw id ulong exp ulong to void
206rbWrt rbReset
207rbWrt rbCallG
208rbNum id
209rbWrt rbAwChk
210rbNum exp
211rbWrt rbChkC
212end
213
214note ==================== 1. BRANCH & ARITH ====================
215text dSatSubA "a minus "
216text dSatSubB " clamped at zero"
217text bSatSub0 "if lt a "
218text bSatSub1 "\nret 0\nend\nret sub a "
219
220text dStepA "value "
221text dStepB " if a is less than "
222text dStepC " else "
223text bStep0 "if lt a "
224text bStep1 "\nret "
225text bStep2 "\nend\nret "
226
227text dRndUpA "a rounded up to a multiple of "
228text bRndUp0 "r = rem a "
229text bRndUp1 "\nif eq r 0\nret a\nend\nret add a sub "
230text bRndUp2 " r"
231
232text dAbsDiff "absolute difference between unsigned a and b"
233text bAbsDiff "if ge a b\nret sub a b\nend\nret sub b a"
234
235text dSatSub2 "saturating difference a minus b or zero when a is smaller"
236text bSatSub2 "if lt a b\nret 0\nend\nret sub a b"
237
238text dMin2 "the smaller of a and b"
239text bMin2 "if lt a b\nret a\nend\nret b"
240
241text dMax2 "the larger of a and b"
242text bMax2 "if gt a b\nret a\nend\nret b"
243
244text dMed3 "the median of three unsigned numbers a b c"
245text bMed3 "if lt a b\nif lt b c\nret b\nend\nif lt a c\nret c\nend\nret a\nend\nif lt a c\nret a\nend\nif lt b c\nret c\nend\nret b"
246
247text dMin3 "the smallest of a b and c"
248text bMin3 "m = a\nif lt b m\nm = b\nend\nif lt c m\nm = c\nend\nret m"
249
250text dMax3 "the largest of a b and c"
251text bMax3 "m = a\nif gt b m\nm = b\nend\nif gt c m\nm = c\nend\nret m"
252
253text dInRng3 "1 if a is between b and c inclusive else 0"
254text bInRng3 "if lt a b\nret 0\nend\nif gt a c\nret 0\nend\nret 1"
255
256text dClp3 "a clamped between b and c"
257text bClp3 "if lt a b\nret b\nend\nif gt a c\nret c\nend\nret a"
258
259fn rbEmitBranch isMain bool to void
260v = get rbVar 0
261note 1a. 10 saturating sub a - k
262for i ulong 10
263k = add 5 mul add i v 7
264id = rbNextId
265if not isMain
266if eq get rbMode 0 0
267rbWrt rbNote
268rbVerb add id v
269rbWrt dSatSubA
270rbNum k
271rbWrt dSatSubB
272rbWrt rbFnU1
273else
274rbWrt rbOrPfx
275rbNum id
276rbWrt rbOrU1
277end
278rbWrt bSatSub0
279rbNum k
280rbWrt bSatSub1
281rbNum k
282rbEndFn
283else
284rbChkU1 id add k 11 11
285rbChkU1 id sub k 1 0
286end
287end
288note 1b. 10 step functions
289for i ulong 10
290k = add 8 mul add i v 5
291v0 = add 2 mul i 3
292v1 = add 50 mul i 4
293id = rbNextId
294if not isMain
295if eq get rbMode 0 0
296rbWrt rbNote
297rbVerb add id v
298rbWrt dStepA
299rbNum v0
300rbWrt dStepB
301rbNum k
302rbWrt dStepC
303rbNum v1
304rbWrt rbFnU1
305else
306rbWrt rbOrPfx
307rbNum id
308rbWrt rbOrU1
309end
310rbWrt bStep0
311rbNum k
312rbWrt bStep1
313rbNum v0
314rbWrt bStep2
315rbNum v1
316rbEndFn
317else
318rbChkU1 id sub k 1 v0
319rbChkU1 id k v1
320end
321end
322note 1c. 8 round up to multiple of m
323for i ulong 8
324m = add 3 mul add i v 2
325id = rbNextId
326if not isMain
327if eq get rbMode 0 0
328rbWrt rbNote
329rbVerb add id v
330rbWrt dRndUpA
331rbNum m
332rbWrt rbFnU1
333else
334rbWrt rbOrPfx
335rbNum id
336rbWrt rbOrU1
337end
338rbWrt bRndUp0
339rbNum m
340rbWrt bRndUp1
341rbNum m
342rbWrt bRndUp2
343rbEndFn
344else
345rbChkU1 id add mul m 2 1 mul m 3
346rbChkU1 id mul m 2 mul m 2
347end
348end
349note 1d. U2 & U3 core branch idioms
350if not isMain
351id = rbBeginFn 2 dAbsDiff
352rbWrt bAbsDiff
353rbEndFn
354id = rbBeginFn 2 dSatSub2
355rbWrt bSatSub2
356rbEndFn
357id = rbBeginFn 2 dMin2
358rbWrt bMin2
359rbEndFn
360id = rbBeginFn 2 dMax2
361rbWrt bMax2
362rbEndFn
363id = rbBeginFn 3 dMed3
364rbWrt bMed3
365rbEndFn
366id = rbBeginFn 3 dInRng3
367rbWrt bInRng3
368rbEndFn
369id = rbBeginFn 3 dClp3
370rbWrt bClp3
371rbEndFn
372else
373rbChkU2 rbNextId 10 3 7
374rbChkU2 rbNextId 10 3 7
375rbChkU2 rbNextId 10 3 3
376rbChkU2 rbNextId 10 3 10
377rbChkU3 rbNextId 9 2 5 5
378rbChkU3 rbNextId 5 2 9 1
379rbChkU3 rbNextId 12 2 9 9
380end
381end
382
383note ==================== 2. BITS & DIGITS & LOOP ====================
384text dClrBitA "a with bit "
385text dClrBitB " cleared to zero"
386text bClrBit0 "ret and a xor ulong 18446744073709551615 shl ulong 1 "
387
388text dLowMskA "the low "
389text dLowMskB " bits of a"
390text bLowMsk0 "ret and a sub shl ulong 1 "
391text bLowMsk1 " 1"
392
393text dParity "parity 1 if a has an odd number of 1 bits else 0"
394text bParity "x = a\np = ulong 0\nwhile gt x 0 bound 64\np = xor p and x 1\nx = shr x 1\nend\nret p"
395
396text dPow2 "1 if a is a power of two else 0"
397text bPow2 "if eq a 0\nret 0\nend\nif eq and a sub a 1 0\nret 1\nend\nret 0"
398
399text dBitLen "number of bits needed to represent unsigned a"
400text bBitLen "x = a\nc = ulong 0\nwhile gt x 0 bound 64\nc = add c 1\nx = shr x 1\nend\nret c"
401
402text dRevDigA "reverse the digits of a in base "
403text bRevDig0 "x = a\nr = ulong 0\nwhile gt x 0 bound 64\nr = add mul r "
404text bRevDig1 " rem x "
405text bRevDig2 "\nx = div x "
406text bRevDig3 "\nend\nret r"
407
408text dGcd "greatest common divisor of a and b"
409text bGcd "x = a\ny = b\nwhile gt y 0 bound 128\nt = rem x y\nx = y\ny = t\nend\nret x"
410
411text dFib "fibonacci number of a mod 25"
412text bFib "n = rem a 25\nx = ulong 0\ny = ulong 1\nfor i ulong n bound 25\nt = add x y\nx = y\ny = t\nend\nret x"
413
414text dPow "a raised to the power b mod 10"
415text bPow "e = rem b 10\nr = ulong 1\nfor i ulong e bound 10\nr = mul r a\nend\nret r"
416
417text dSumN "sum of integers from 1 to a mod 32"
418text bSumN "n = rem a 32\ns = ulong 0\nfor i ulong n bound 32\ns = add s add i 1\nend\nret s"
419
420fn rbEmitBitsLoop isMain bool to void
421v = get rbVar 0
422for i ulong 8
423bit = add 1 rem add i v 12
424id = rbNextId
425if not isMain
426if eq get rbMode 0 0
427rbWrt rbNote
428rbVerb add id v
429rbWrt dClrBitA
430rbNum bit
431rbWrt dClrBitB
432rbWrt rbFnU1
433else
434rbWrt rbOrPfx
435rbNum id
436rbWrt rbOrU1
437end
438rbWrt bClrBit0
439rbNum bit
440rbEndFn
441else
442rbChkU1 id add shl ulong 1 bit 1 1
443end
444end
445for i ulong 8
446k = add 2 rem add i v 10
447id = rbNextId
448if not isMain
449if eq get rbMode 0 0
450rbWrt rbNote
451rbVerb add id v
452rbWrt dLowMskA
453rbNum k
454rbWrt dLowMskB
455rbWrt rbFnU1
456else
457rbWrt rbOrPfx
458rbNum id
459rbWrt rbOrU1
460end
461rbWrt bLowMsk0
462rbNum k
463rbWrt bLowMsk1
464rbEndFn
465else
466rbChkU1 id sub shl ulong 1 k 1 sub shl ulong 1 k 1
467end
468end
469for i ulong 3
470base = ulong 10
471if eq i 1
472base = 8
473end
474if eq i 2
475base = 16
476end
477id = rbNextId
478if not isMain
479if eq get rbMode 0 0
480rbWrt rbNote
481rbVerb add id v
482rbWrt dRevDigA
483rbNum base
484rbWrt rbFnU1
485else
486rbWrt rbOrPfx
487rbNum id
488rbWrt rbOrU1
489end
490rbWrt bRevDig0
491rbNum base
492rbWrt bRevDig1
493rbNum base
494rbWrt bRevDig2
495rbNum base
496rbWrt bRevDig3
497rbEndFn
498else
499if eq base 10
500rbChkU1 id 1234 4321
501end
502if eq base 8
503rbChkU1 id 83 209
504end
505if eq base 16
506rbChkU1 id 291 801
507end
508end
509end
510if not isMain
511id = rbBeginFn 1 dParity
512rbWrt bParity
513rbEndFn
514id = rbBeginFn 1 dBitLen
515rbWrt bBitLen
516rbEndFn
517id = rbBeginFn 2 dGcd
518rbWrt bGcd
519rbEndFn
520id = rbBeginFn 1 dFib
521rbWrt bFib
522rbEndFn
523id = rbBeginFn 2 dPow
524rbWrt bPow
525rbEndFn
526id = rbBeginFn 1 dSumN
527rbWrt bSumN
528rbEndFn
529else
530rbChkU1 rbNextId 7 1
531rbChkU1 rbNextId 13 4
532rbChkU2 rbNextId 48 18 6
533rbChkU1 rbNextId 7 13
534rbChkU2 rbNextId 2 5 32
535rbChkU1 rbNextId 5 15
536end
537end
538
539note ==================== 3. FOLD, SELECT, COUNT, SCAN ====================
540text dSumArr "sum of first n elements of array a"
541text bSumArr "s = ulong 0\nfor i ulong n bound 8\ns = add s get a i\nend\nret s"
542
543text dMaxArr "maximum of first n elements of array a or 0 if empty"
544text bMaxArr "if eq n 0\nret 0\nend\nm = get a 0\nfor i ulong n bound 8\nv = get a i\nif gt v m\nm = v\nend\nend\nret m"
545
546text dMinArr "minimum of first n elements of array a or 0 if empty"
547text bMinArr "if eq n 0\nret 0\nend\nm = get a 0\nfor i ulong n bound 8\nv = get a i\nif lt v m\nm = v\nend\nend\nret m"
548
549text dXorArr "bitwise XOR of first n elements of array a"
550text bXorArr "s = ulong 0\nfor i ulong n bound 8\ns = xor s get a i\nend\nret s"
551
552text dArgMax "index of maximum element in first n elements of array a"
553text bArgMax "if eq n 0\nret 0\nend\nbi = ulong 0\nbv = get a 0\nfor i ulong n bound 8\nv = get a i\nif gt v bv\nbv = v\nbi = i\nend\nend\nret bi"
554
555text dArgMin "index of minimum element in first n elements of array a"
556text bArgMin "if eq n 0\nret 0\nend\nbi = ulong 0\nbv = get a 0\nfor i ulong n bound 8\nv = get a i\nif lt v bv\nbv = v\nbi = i\nend\nend\nret bi"
557
558text dCntEv "count of even elements in first n elements of array a"
559text bCntEv "c = ulong 0\nfor i ulong n bound 8\nif eq rem get a i 2 0\nc = add c 1\nend\nend\nret c"
560
561text dCntOd "count of odd elements in first n elements of array a"
562text bCntOd "c = ulong 0\nfor i ulong n bound 8\nif ne rem get a i 2 0\nc = add c 1\nend\nend\nret c"
563
564text dSumEv "sum of even elements in first n elements of array a"
565text bSumEv "s = ulong 0\nfor i ulong n bound 8\nv = get a i\nif eq rem v 2 0\ns = add s v\nend\nend\nret s"
566
567text dSumOd "sum of odd elements in first n elements of array a"
568text bSumOd "s = ulong 0\nfor i ulong n bound 8\nv = get a i\nif ne rem v 2 0\ns = add s v\nend\nend\nret s"
569
570text dRngArr "difference between max and min of first n elements of array a"
571text bRngArr "if eq n 0\nret 0\nend\nlo = get a 0\nhi = lo\nfor i ulong n bound 8\nv = get a i\nif lt v lo\nlo = v\nend\nif gt v hi\nhi = v\nend\nend\nret sub hi lo"
572
573text dIsSort "1 if first n elements of array a are non-decreasing else 0"
574text bIsSort "if le n 1\nret 1\nend\nfor i ulong sub n 1 bound 8\nif gt get a i get a add i 1\nret 0\nend\nend\nret 1"
575
576text dCntGtA "count of elements strictly greater than "
577text dCntGtB " in first n elements of array a"
578text bCntGt0 "c = ulong 0\nfor i ulong n bound 8\nif gt get a i "
579text bCntGt1 "\nc = add c 1\nend\nend\nret c"
580
581text dFndEqA "first index equal to "
582text dFndEqB " in first n elements of array a or n if absent"
583text bFndEq0 "for i ulong n bound 8\nif eq get a i "
584text bFndEq1 "\nret i\nend\nend\nret n"
585
586fn rbEmitArrayRead isMain bool to void
587v = get rbVar 0
588if not isMain
589id = rbBeginFn 4 dSumArr
590rbWrt bSumArr
591rbEndFn
592id = rbBeginFn 4 dMaxArr
593rbWrt bMaxArr
594rbEndFn
595id = rbBeginFn 4 dMinArr
596rbWrt bMinArr
597rbEndFn
598id = rbBeginFn 4 dXorArr
599rbWrt bXorArr
600rbEndFn
601id = rbBeginFn 4 dArgMax
602rbWrt bArgMax
603rbEndFn
604id = rbBeginFn 4 dArgMin
605rbWrt bArgMin
606rbEndFn
607id = rbBeginFn 4 dCntEv
608rbWrt bCntEv
609rbEndFn
610id = rbBeginFn 4 dCntOd
611rbWrt bCntOd
612rbEndFn
613id = rbBeginFn 4 dSumEv
614rbWrt bSumEv
615rbEndFn
616id = rbBeginFn 4 dSumOd
617rbWrt bSumOd
618rbEndFn
619id = rbBeginFn 4 dRngArr
620rbWrt bRngArr
621rbEndFn
622id = rbBeginFn 4 dIsSort
623rbWrt bIsSort
624rbEndFn
625else
626rbChkAr rbNextId 61
627rbChkAr rbNextId 19
628rbChkAr rbNextId 0
629rbChkAr rbNextId 21
630rbChkAr rbNextId 4
631rbChkAr rbNextId 2
632rbChkAr rbNextId 3
633rbChkAr rbNextId 5
634rbChkAr rbNextId 6
635rbChkAr rbNextId 55
636rbChkAr rbNextId 19
637rbChkAr rbNextId 0
638end
639for i ulong 8
640thr = add 1 mul i 2
641id = rbNextId
642if not isMain
643if eq get rbMode 0 0
644rbWrt rbNote
645rbVerb add id v
646rbWrt dCntGtA
647rbNum thr
648rbWrt dCntGtB
649rbWrt rbFnAr
650else
651rbWrt rbOrPfx
652rbNum id
653rbWrt rbOrAr
654end
655rbWrt bCntGt0
656rbNum thr
657rbWrt bCntGt1
658rbEndFn
659else
660cnt = ulong 0
661if gt 3 thr
662cnt = add cnt 1
663end
664if gt 11 thr
665cnt = add cnt 1
666end
667if gt 7 thr
668cnt = add cnt 1
669end
670if gt 19 thr
671cnt = add cnt 1
672end
673if gt 4 thr
674cnt = add cnt 1
675end
676if gt 2 thr
677cnt = add cnt 1
678end
679if gt 15 thr
680cnt = add cnt 1
681end
682rbChkAr id cnt
683end
684end
685for i ulong 4
686tgt = ulong 7
687exp = ulong 3
688if eq i 1
689tgt = 19
690exp = 4
691end
692if eq i 2
693tgt = 15
694exp = 7
695end
696if eq i 3
697tgt = 99
698exp = 8
699end
700id = rbNextId
701if not isMain
702if eq get rbMode 0 0
703rbWrt rbNote
704rbVerb add id v
705rbWrt dFndEqA
706rbNum tgt
707rbWrt dFndEqB
708rbWrt rbFnAr
709else
710rbWrt rbOrPfx
711rbNum id
712rbWrt rbOrAr
713end
714rbWrt bFndEq0
715rbNum tgt
716rbWrt bFndEq1
717rbEndFn
718else
719rbChkAr id exp
720end
721end
722end
723
724note ==================== 4. REWRITE (IN-PLACE ARRAY TRANSFORMS) ====================
725text dRwAddA "add "
726text dRwAddB " to each of first n elements of array a in place"
727text bRwAdd0 "for i ulong n bound 8\nput a i add get a i "
728text bRwAdd1 "\nend"
729
730text dRwCapA "cap each of first n elements of array a at "
731text dRwCapB " in place"
732text bRwCap0 "for i ulong n bound 8\nif gt get a i "
733text bRwCap1 "\nput a i "
734text bRwCap2 "\nend\nend"
735
736text dRwFlrA "raise any element below "
737text dRwFlrB " in first n elements of array a to "
738text bRwFlr0 "for i ulong n bound 8\nif lt get a i "
739text bRwFlr1 "\nput a i "
740text bRwFlr2 "\nend\nend"
741
742text dRwRev "reverse the first n elements of array a in place"
743text bRwRev "i = ulong 0\nwhile lt mul i 2 n bound 8\nj = sub sub n 1 i\nt = get a i\nput a i get a j\nput a j t\ni = add i 1\nend"
744
745text dRwPfx "replace first n elements of array a with running prefix sums in place"
746text bRwPfx "s = ulong 0\nfor i ulong n bound 8\ns = add s get a i\nput a i s\nend"
747
748text dRwZOd "zero out all odd elements in first n elements of array a in place"
749text bRwZOd "for i ulong n bound 8\nif ne rem get a i 2 0\nput a i 0\nend\nend"
750
751text dRwDOd "double all odd elements in first n elements of array a in place"
752text bRwDOd "for i ulong n bound 8\nv = get a i\nif ne rem v 2 0\nput a i mul v 2\nend\nend"
753
754fn rbEmitRewrite isMain bool to void
755v = get rbVar 0
756for i ulong 6
757k = add 1 add i v
758id = rbNextId
759if not isMain
760if eq get rbMode 0 0
761rbWrt rbNote
762rbVerb add id v
763rbWrt dRwAddA
764rbNum k
765rbWrt dRwAddB
766rbWrt rbFnAw
767else
768rbWrt rbOrPfx
769rbNum id
770rbWrt rbOrAw
771end
772rbWrt bRwAdd0
773rbNum k
774rbWrt bRwAdd1
775rbEndFn
776else
777rbChkAw id add 25 mul 3 k
778end
779end
780for i ulong 5
781cap = add 5 mul i 3
782id = rbNextId
783if not isMain
784if eq get rbMode 0 0
785rbWrt rbNote
786rbVerb add id v
787rbWrt dRwCapA
788rbNum cap
789rbWrt dRwCapB
790rbWrt rbFnAw
791else
792rbWrt rbOrPfx
793rbNum id
794rbWrt rbOrAw
795end
796rbWrt bRwCap0
797rbNum cap
798rbWrt bRwCap1
799rbNum cap
800rbWrt bRwCap2
801rbEndFn
802else
803e0 = ulong 3
804if gt e0 cap
805e0 = cap
806end
807e3 = ulong 7
808if gt e3 cap
809e3 = cap
810end
811e7 = ulong 15
812if gt e7 cap
813e7 = cap
814end
815rbChkAw id add e0 add e3 e7
816end
817end
818for i ulong 5
819flr = add 4 mul i 3
820id = rbNextId
821if not isMain
822if eq get rbMode 0 0
823rbWrt rbNote
824rbVerb add id v
825rbWrt dRwFlrA
826rbNum flr
827rbWrt dRwFlrB
828rbNum flr
829rbWrt rbFnAw
830else
831rbWrt rbOrPfx
832rbNum id
833rbWrt rbOrAw
834end
835rbWrt bRwFlr0
836rbNum flr
837rbWrt bRwFlr1
838rbNum flr
839rbWrt bRwFlr2
840rbEndFn
841else
842e0 = ulong 3
843if lt e0 flr
844e0 = flr
845end
846e3 = ulong 7
847if lt e3 flr
848e3 = flr
849end
850e7 = ulong 15
851if lt e7 flr
852e7 = flr
853end
854rbChkAw id add e0 add e3 e7
855end
856end
857if not isMain
858id = rbBeginFn 5 dRwRev
859rbWrt bRwRev
860rbEndFn
861id = rbBeginFn 5 dRwPfx
862rbWrt bRwPfx
863rbEndFn
864id = rbBeginFn 5 dRwZOd
865rbWrt bRwZOd
866rbEndFn
867id = rbBeginFn 5 dRwDOd
868rbWrt bRwDOd
869rbEndFn
870else
871rbChkAw rbNextId 37
872rbChkAw rbNextId 85
873rbChkAw rbNextId 0
874rbChkAw rbNextId 50
875end
876end
877
878fn rbEqArg a view uchar * al ulong b view uchar * to bool
879if ne al len b
880ret false
881end
882for i ulong al bound 32
883if ne get a i get b i
884ret false
885end
886end
887ret true
888end
889
890fn main to int
891ab = new uchar 32 0
892vb = new uchar 16 0
893mode = ulong 0
894varn = ulong 1
895if ge argcnt 2
896lr = argread 1 ab 0 32
897if gt lr 0
898if rbEqArg ab ulong lr rbArgOracle
899mode = 1
900end
901end
902end
903if ge argcnt 3
904vr = argread 2 vb 0 16
905if gt vr 0
906ch = ulong get vb 0
907if and ge ch 49 le ch 57
908varn = sub ch 48
909end
910end
911end
912put rbMode 0 mode
913put rbVar 0 varn
914if eq mode 1
915rbWrt rbOm2
916put rbId 0 0
917rbEmitBranch false
918rbEmitBitsLoop false
919rbEmitArrayRead false
920rbEmitRewrite false
921rbWrt rbMainH
922put rbId 0 0
923rbEmitBranch true
924rbEmitBitsLoop true
925rbEmitArrayRead true
926rbEmitRewrite true
927rbWrt rbMainT
928ret 0
929end
930put rbId 0 0
931rbEmitBranch false
932rbEmitBitsLoop false
933rbEmitArrayRead false
934rbEmitRewrite false
935ret 0
936end