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 / src / physics0 / pd0_relation.om

752 lines · 17169 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note src/physics0/pd0_relation.om: PD-0 relations in PDLAW1 delta form, rollout, NRMSE, support/coef-err, PDLAW1 codec, claim_text, JSON.
3note Learner-side safe: no generator, no world, no file I/O.
4
5const P0R_SLOTS ulong 16
6const P0R_EQ_STRIDE ulong 6
7const P0R_TERM_STRIDE ulong 72
8const P0R_EX_STRIDE ulong 576
9
10global p0r_nvars uchar 16
11global p0r_nlat uchar 16
12global p0r_nch uchar 16
13global p0r_neq uchar 16
14global p0r_eq_tgt uchar 96
15global p0r_eq_nt uchar 96
16global p0r_coef long 1152
17global p0r_ex uchar 9216
18
19text PD0_MAGIC_LAW1 "PDLAW1"
20text PD0_HEX_DIGITS "0123456789abcdef"
21
22fn p0r_clear slot ulong to void
23put p0r_nvars slot uchar 0
24put p0r_nlat slot uchar 0
25put p0r_nch slot uchar 0
26put p0r_neq slot uchar 0
27ebase = mul slot P0R_EQ_STRIDE
28for e ulong 6
29put p0r_eq_tgt add ebase e uchar 0
30put p0r_eq_nt add ebase e uchar 0
31end
32tbase = mul slot P0R_TERM_STRIDE
33for t ulong 72
34put p0r_coef add tbase t long 0
35end
36xbase = mul slot P0R_EX_STRIDE
37for x ulong 576
38put p0r_ex add xbase x uchar 0
39end
40ret
41end
42
43fn p0r_copy dst ulong src ulong to void
44put p0r_nvars dst get p0r_nvars src
45put p0r_nlat dst get p0r_nlat src
46put p0r_nch dst get p0r_nch src
47put p0r_neq dst get p0r_neq src
48de = mul dst P0R_EQ_STRIDE
49se = mul src P0R_EQ_STRIDE
50for e ulong 6
51put p0r_eq_tgt add de e get p0r_eq_tgt add se e
52put p0r_eq_nt add de e get p0r_eq_nt add se e
53end
54dt = mul dst P0R_TERM_STRIDE
55st = mul src P0R_TERM_STRIDE
56for t ulong 72
57put p0r_coef add dt t get p0r_coef add st t
58end
59dx = mul dst P0R_EX_STRIDE
60sx = mul src P0R_EX_STRIDE
61for x ulong 576
62put p0r_ex add dx x get p0r_ex add sx x
63end
64ret
65end
66
67fn p0r_eq_idx slot ulong eqi ulong to ulong
68ret add mul slot P0R_EQ_STRIDE eqi
69end
70
71fn p0r_term_idx slot ulong eqi ulong t ulong to ulong
72ret add add mul slot P0R_TERM_STRIDE mul eqi PD0_MAX_TERMS t
73end
74
75fn p0r_ex_idx slot ulong eqi ulong t ulong k ulong to ulong
76ti = p0r_term_idx slot eqi t
77ret add mul ti PD0_MAX_EX k
78end
79
80fn p0r_valid_term ti ulong nv ulong nc ulong to int
81if eq get p0r_coef ti long 0
82ret -1
83end
84xb = mul ti PD0_MAX_EX
85for x ulong PD0_MAX_VARS
86if ge x nv
87if ne get p0r_ex add xb x uchar 0
88ret -1
89end
90end
91end
92for c ulong PD0_MAX_CH
93if ge c nc
94if ne get p0r_ex add xb add PD0_MAX_VARS c uchar 0
95ret -1
96end
97end
98end
99ret 0
100end
101
102fn pd0_relation_valid slot ulong to int
103nv = ulong get p0r_nvars slot
104nl = ulong get p0r_nlat slot
105nc = ulong get p0r_nch slot
106ne_cnt = ulong get p0r_neq slot
107if or lt nv ulong 1 gt nv PD0_MAX_VARS
108ret -1
109end
110if or gt nl PD0_MAX_LATENT ge nl nv
111ret -1
112end
113if or lt nc ulong 1 gt nc PD0_MAX_CH
114ret -1
115end
116if gt ne_cnt nv
117ret -1
118end
119for i ulong ne_cnt bound 6
120ei = p0r_eq_idx slot i
121tgt = ulong get p0r_eq_tgt ei
122nt = ulong get p0r_eq_nt ei
123if or ge tgt nv gt nt PD0_MAX_TERMS
124ret -1
125end
126for j ulong ne_cnt bound 6
127if gt j i
128ej = p0r_eq_idx slot j
129if eq ulong get p0r_eq_tgt ej tgt
130ret -1
131end
132end
133end
134for t ulong nt bound 12
135ti = p0r_term_idx slot i t
136if ne p0r_valid_term ti nv nc 0
137ret -1
138end
139end
140end
141ret 0
142end
143
144fn pd0_relation_size slot ulong to int
145n = int get p0r_nlat slot
146ne_cnt = ulong get p0r_neq slot
147for i ulong ne_cnt bound 6
148n = add n int get p0r_eq_nt p0r_eq_idx slot i
149end
150ret n
151end
152
153fn pd0_relation_degree_ok slot ulong to int
154ne_cnt = ulong get p0r_neq slot
155for i ulong ne_cnt bound 6
156nt = ulong get p0r_eq_nt p0r_eq_idx slot i
157for t ulong nt bound 12
158ti = p0r_term_idx slot i t
159d = ulong 0
160for x ulong PD0_MAX_EX
161d = add d ulong get p0r_ex add mul ti PD0_MAX_EX x
162end
163if gt d PD0_MAX_DEG
164ret 0
165end
166end
167end
168ret 1
169end
170
171fn pd0_relation_description_bits slot ulong to uint
172nv = uint get p0r_nvars slot
173nl = uint get p0r_nlat slot
174nc = uint get p0r_nch slot
175bits = mul uint 8 nl
176per = add mul uint 8 add nv nc uint 24
177ne_cnt = ulong get p0r_neq slot
178for i ulong ne_cnt bound 6
179nt = uint get p0r_eq_nt p0r_eq_idx slot i
180bits = add bits mul per nt
181end
182ret bits
183end
184
185fn pd0_monomial_ti ti ulong vars view long 6 u view long 2 to long
186xb = mul ti PD0_MAX_EX
187m = PD0_MICRO
188for v ulong 6
189ex = ulong get p0r_ex add xb v
190for p ulong ex bound 8
191m = pd0_mul m get vars v
192end
193end
194for c ulong 2
195ex = ulong get p0r_ex add xb add PD0_MAX_VARS c
196for p ulong ex bound 8
197m = pd0_mul m get u c
198end
199end
200ret m
201end
202
203fn p0r_eval_eq slot ulong eqi ulong inv view long 6 u view long 2 to long
204nt = ulong get p0r_eq_nt p0r_eq_idx slot eqi
205d = long 0
206for t ulong nt bound 12
207ti = p0r_term_idx slot eqi t
208m = pd0_monomial_ti ti inv u
209d = add d pd0_mul get p0r_coef ti m
210end
211ret d
212end
213
214fn pd0_relation_step slot ulong inv view long 6 u view long 2 outv edit long 6 to void
215nv = ulong get p0r_nvars slot
216for v ulong nv bound 6
217put outv v get inv v
218end
219ne_cnt = ulong get p0r_neq slot
220for i ulong ne_cnt bound 6
221tgt = ulong get p0r_eq_tgt p0r_eq_idx slot i
222d = p0r_eval_eq slot i inv u
223put outv tgt add get inv tgt d
224end
225ret
226end
227
228fn p0r_find_eq slot ulong tgt uchar to int
229ne_cnt = ulong get p0r_neq slot
230for i ulong ne_cnt bound 6
231if eq get p0r_eq_tgt p0r_eq_idx slot i tgt
232ret int i
233end
234end
235ret -1
236end
237
238fn p0r_ex_match xb ulong txb ulong to int
239for k ulong PD0_MAX_EX
240if ne get p0r_ex add xb k get p0r_ex add txb k
241ret 0
242end
243end
244ret 1
245end
246
247fn p0r_find_term slot ulong eqi ulong tslot ulong teq ulong tt ulong to int
248nt = ulong get p0r_eq_nt p0r_eq_idx slot eqi
249txb = mul p0r_term_idx tslot teq tt PD0_MAX_EX
250for i ulong nt bound 12
251xb = mul p0r_term_idx slot eqi i PD0_MAX_EX
252if eq p0r_ex_match xb txb 1
253ret int i
254end
255end
256ret -1
257end
258
259fn pd0_relation_supports slot ulong tslot ulong to int
260tne = ulong get p0r_neq tslot
261for i ulong tne bound 6
262tgt = get p0r_eq_tgt p0r_eq_idx tslot i
263ei = p0r_find_eq slot tgt
264if lt ei 0
265ret 0
266end
267tnt = ulong get p0r_eq_nt p0r_eq_idx tslot i
268for t ulong tnt bound 12
269if lt p0r_find_term slot ulong ei tslot i t 0
270ret 0
271end
272end
273end
274ret 1
275end
276
277fn p0r_coef_ppm mc long tc long to long
278d = sub mc tc
279if lt d long 0
280d = neg d
281end
282tv = tc
283if lt tv long 0
284tv = neg tv
285end
286if ne tv long 0
287ret long div mul f64 d 1000000.0f64 f64 tv
288end
289if ne d long 0
290ret long 9223372036854775807
291end
292ret long 0
293end
294
295fn pd0_relation_coef_err_ppm slot ulong tslot ulong to long
296if eq pd0_relation_supports slot tslot 0
297ret long -1
298end
299worst = long 0
300tne = ulong get p0r_neq tslot
301for i ulong tne bound 6
302tgt = get p0r_eq_tgt p0r_eq_idx tslot i
303ei = ulong p0r_find_eq slot tgt
304tnt = ulong get p0r_eq_nt p0r_eq_idx tslot i
305for t ulong tnt bound 12
306mi = ulong p0r_find_term slot ei tslot i t
307mc = get p0r_coef p0r_term_idx slot ei mi
308tc = get p0r_coef p0r_term_idx tslot i t
309ppm = p0r_coef_ppm mc tc
310if gt ppm worst
311worst = ppm
312end
313end
314end
315ret worst
316end
317
318fn pd0_confidence_ppm p uint f uint to uint
319num = mul ulong 1000000 add ulong p ulong 1
320den = add add ulong p ulong f ulong 2
321ret uint div num den
322end
323
324fn pd0_hex h view uchar * n ulong dst edit uchar * to void
325for i ulong n bound 64
326b = ulong get h i
327put dst mul i 2 get PD0_HEX_DIGITS shr b 4
328put dst add mul i 2 1 get PD0_HEX_DIGITS and b 15
329end
330ret
331end
332
333note ---- PDLAW1 minimal globals + codec (substrate lane; Pd0LawMeta in pd0_types.om) ----
334
335global p0l_law_id uchar 32
336global p0l_chain_root uchar 32
337global p0l_var_min long 4
338global p0l_var_max long 4
339global p0l_ch_min long 2
340global p0l_ch_max long 2
341global p0l_exc_seq ulong 16
342global p0l_exc_hash uchar 512
343global p0l_exc_pred long 16
344global p0l_exc_obs long 16
345global p0l_exc_err long 16
346global p0l_exp_id uchar 512
347global p0l_exp_kind uchar 16
348global p0l_exp_prereg uchar 512
349global p0l_exp_outcome uchar 512
350global p0l_exp_res uchar 16
351global p0l_exp_fseq ulong 16
352global p0l_exp_lseq ulong 16
353
354text P0L_C1 "Across "
355text P0L_C2 " observations under "
356text P0L_C3 " episodes, "
357text P0L_C4 " variables in the reset box ["
358text P0L_C5 ", "
359text P0L_C6 "] micro, episode length "
360text P0L_C7 ", this relation predicts within "
361text P0L_C8 " (rollout NRMSE, 20 steps). Confidence "
362text P0L_C9 " ppm. "
363text P0L_C10 " exceptions recorded."
364
365fn pd0_claim_text slot ulong m view Pd0LawMeta dst edit uchar * to ulong
366cap = len dst
367pos = ulong 0
368pos = pd0_buf_str dst pos cap P0L_C1
369pos = pd0_buf_u64 dst pos cap get m n_obs_dom
370pos = pd0_buf_str dst pos cap P0L_C2
371pos = pd0_buf_u64 dst pos cap ulong get m n_ep_dom
372pos = pd0_buf_str dst pos cap P0L_C3
373nobs = sub ulong get p0r_nvars slot ulong get p0r_nlat slot
374pos = pd0_buf_u64 dst pos cap nobs
375pos = pd0_buf_str dst pos cap P0L_C4
376pos = pd0_buf_i64 dst pos cap get m reset_min
377pos = pd0_buf_str dst pos cap P0L_C5
378pos = pd0_buf_i64 dst pos cap get m reset_max
379pos = pd0_buf_str dst pos cap P0L_C6
380pos = pd0_buf_u64 dst pos cap ulong get m ep_len
381pos = pd0_buf_str dst pos cap P0L_C7
382eps = ulong get m eps_micro
383pos = pd0_buf_u64 dst pos cap div eps ulong 1000000
384pos = pd0_buf_ch dst pos cap uchar 46
385pos = pd0_buf_u64_pad6 dst pos cap rem eps ulong 1000000
386pos = pd0_buf_str dst pos cap P0L_C8
387pos = pd0_buf_u64 dst pos cap ulong get m confidence_ppm
388pos = pd0_buf_str dst pos cap P0L_C9
389pos = pd0_buf_u64 dst pos cap ulong get m n_exc
390pos = pd0_buf_str dst pos cap P0L_C10
391ret pos
392end
393
394fn pd0_law_encode_rel slot ulong dst edit uchar * pos ulong to ulong
395nv = get p0r_nvars slot
396nl = get p0r_nlat slot
397nc = get p0r_nch slot
398ne_cnt = get p0r_neq slot
399put dst pos nv
400put dst add pos 1 nl
401put dst add pos 2 nc
402pos = add pos 3
403pd0_put_u32 dst pos pd0_relation_description_bits slot
404pos = add pos 4
405ret pos
406end
407
408fn pd0_law_encode_term ti ulong nv ulong nc ulong dst edit uchar * pos ulong to ulong
409xb = mul ti PD0_MAX_EX
410pd0_put_u64 dst pos bitcast ulong get p0r_coef ti
411pos = add pos 8
412for v ulong nv bound 6
413put dst pos get p0r_ex add xb v
414pos = add pos 1
415end
416for c ulong nc bound 2
417put dst pos get p0r_ex add xb add PD0_MAX_VARS c
418pos = add pos 1
419end
420ret pos
421end
422
423fn pd0_law_encode_eqs slot ulong dst edit uchar * pos ulong to ulong
424nv = ulong get p0r_nvars slot
425nc = ulong get p0r_nch slot
426ne_cnt = ulong get p0r_neq slot
427for i ulong ne_cnt bound 6
428ei = p0r_eq_idx slot i
429nt = ulong get p0r_eq_nt ei
430put dst pos get p0r_eq_tgt ei
431pd0_put_u16 dst add pos 1 ushort nt
432pos = add pos 3
433for t ulong nt bound 12
434ti = p0r_term_idx slot i t
435pos = pd0_law_encode_term ti nv nc dst pos
436end
437end
438ret pos
439end
440
441fn pd0_law_encode_exc nexc ulong dst edit uchar * pos ulong to ulong
442pd0_put_u16 dst pos ushort nexc
443pos = add pos 2
444for i ulong nexc bound 16
445pd0_put_u64 dst pos get p0l_exc_seq i
446pos = add pos 8
447for k ulong 32
448put dst pos get p0l_exc_hash add mul i 32 k
449pos = add pos 1
450end
451pd0_put_u64 dst pos bitcast ulong get p0l_exc_pred i
452pos = add pos 8
453pd0_put_u64 dst pos bitcast ulong get p0l_exc_obs i
454pos = add pos 8
455pd0_put_u64 dst pos bitcast ulong get p0l_exc_err i
456pos = add pos 8
457end
458ret pos
459end
460
461fn pd0_law_encode_exp nexp ulong dst edit uchar * pos ulong to ulong
462pd0_put_u16 dst pos ushort nexp
463pos = add pos 2
464for i ulong nexp bound 16
465for k ulong 32
466put dst pos get p0l_exp_id add mul i 32 k
467pos = add pos 1
468end
469put dst pos get p0l_exp_kind i
470pos = add pos 1
471for k ulong 32
472put dst pos get p0l_exp_prereg add mul i 32 k
473pos = add pos 1
474end
475for k ulong 32
476put dst pos get p0l_exp_outcome add mul i 32 k
477pos = add pos 1
478end
479put dst pos get p0l_exp_res i
480pos = add pos 1
481pd0_put_u64 dst pos get p0l_exp_fseq i
482pos = add pos 8
483pd0_put_u64 dst pos get p0l_exp_lseq i
484pos = add pos 8
485end
486ret pos
487end
488
489fn pd0_law_encode slot ulong m view Pd0LawMeta dst edit uchar * to ulong
490if or ne pd0_relation_valid slot 0 gt get m state PD0_LAW_PROVISIONAL
491ret ulong 0
492end
493if or gt get m n_exc ushort 16 gt get m n_exp ushort 16
494ret ulong 0
495end
496if lt len dst ulong 64
497ret ulong 0
498end
499for i ulong 6
500put dst i get PD0_MAGIC_LAW1 i
501end
502put dst 6 uchar 0
503put dst 7 uchar 0
504pd0_put_u16 dst ulong 8 ushort 1
505put dst 10 get m state
506for i ulong 32
507put dst add ulong 11 i uchar 0
508end
509pos = pd0_law_encode_rel slot dst ulong 43
510pd0_put_u16 dst pos get m n_refutations
511pos = add pos 2
512put dst pos get p0r_neq slot
513pos = add pos 1
514pos = pd0_law_encode_eqs slot dst pos
515nobs = sub ulong get p0r_nvars slot ulong get p0r_nlat slot
516nc = ulong get p0r_nch slot
517for v ulong nobs bound 4
518pd0_put_u64 dst pos bitcast ulong get p0l_var_min v
519pos = add pos 8
520pd0_put_u64 dst pos bitcast ulong get p0l_var_max v
521pos = add pos 8
522end
523for c ulong nc bound 2
524pd0_put_u64 dst pos bitcast ulong get p0l_ch_min c
525pos = add pos 8
526pd0_put_u64 dst pos bitcast ulong get p0l_ch_max c
527pos = add pos 8
528end
529pd0_put_u64 dst pos bitcast ulong get m dt_micro
530pos = add pos 8
531pd0_put_u64 dst pos get m n_obs_dom
532pos = add pos 8
533pd0_put_u32 dst pos get m n_ep_dom
534pos = add pos 4
535pd0_put_u64 dst pos bitcast ulong get m reset_min
536pos = add pos 8
537pd0_put_u64 dst pos bitcast ulong get m reset_max
538pos = add pos 8
539pd0_put_u32 dst pos get m ep_len
540pos = add pos 4
541pd0_put_u64 dst pos bitcast ulong get m latent_reset
542pos = add pos 8
543pd0_put_u32 dst pos get m confidence_ppm
544pos = add pos 4
545pos = pd0_law_encode_exc ulong get m n_exc dst pos
546pos = pd0_law_encode_exp ulong get m n_exp dst pos
547for k ulong 32
548put dst pos get p0l_chain_root k
549pos = add pos 1
550end
551claim = new uchar 512 0
552cl = pd0_claim_text slot m edit claim
553pd0_put_u16 dst pos ushort cl
554pos = add pos 2
555for k ulong cl bound 512
556put dst pos get claim k
557pos = add pos 1
558end
559h = new uchar 32 0
560pd0_sha256_hash view dst pos edit h
561for k ulong 32
562put p0l_law_id k get h k
563put dst add ulong 11 k get h k
564end
565ret pos
566end
567
568fn pd0_law_decode_term src view uchar * pos ulong ti ulong nv ulong nc ulong to ulong
569xb = mul ti PD0_MAX_EX
570put p0r_coef ti bitcast long pd0_get_u64 src pos
571pos = add pos 8
572for v ulong nv bound 6
573put p0r_ex add xb v get src pos
574pos = add pos 1
575end
576for c ulong nc bound 2
577put p0r_ex add xb add PD0_MAX_VARS c get src pos
578pos = add pos 1
579end
580ret pos
581end
582
583fn pd0_law_decode_eqs src view uchar * pos ulong slot ulong to ulong
584slen = len src
585nv = ulong get p0r_nvars slot
586nc = ulong get p0r_nch slot
587ne_cnt = ulong get p0r_neq slot
588need_t = add ulong 8 add nv nc
589for i ulong ne_cnt bound 6
590if gt add pos 3 slen
591ret ulong 0
592end
593ei = p0r_eq_idx slot i
594put p0r_eq_tgt ei get src pos
595nt = ulong pd0_get_u16 src add pos 1
596pos = add pos 3
597if gt nt PD0_MAX_TERMS
598ret ulong 0
599end
600put p0r_eq_nt ei uchar nt
601for t ulong nt bound 12
602if gt add pos need_t slen
603ret ulong 0
604end
605ti = p0r_term_idx slot i t
606pos = pd0_law_decode_term src pos ti nv nc
607end
608end
609ret pos
610end
611
612fn pd0_law_decode_tail src view uchar * pos ulong nobs ulong nc ulong m edit Pd0LawMeta to int
613slen = len src
614dom_need = add mul ulong 16 add nobs nc ulong 54
615if gt add pos dom_need slen
616ret -1
617end
618for v ulong nobs bound 4
619put p0l_var_min v bitcast long pd0_get_u64 src pos
620pos = add pos 8
621put p0l_var_max v bitcast long pd0_get_u64 src pos
622pos = add pos 8
623end
624for c ulong nc bound 2
625put p0l_ch_min c bitcast long pd0_get_u64 src pos
626pos = add pos 8
627put p0l_ch_max c bitcast long pd0_get_u64 src pos
628pos = add pos 8
629end
630put m dt_micro bitcast long pd0_get_u64 src pos
631pos = add pos 8
632put m n_obs_dom pd0_get_u64 src pos
633pos = add pos 8
634put m n_ep_dom pd0_get_u32 src pos
635pos = add pos 4
636put m reset_min bitcast long pd0_get_u64 src pos
637pos = add pos 8
638put m reset_max bitcast long pd0_get_u64 src pos
639pos = add pos 8
640put m ep_len pd0_get_u32 src pos
641pos = add pos 4
642put m latent_reset bitcast long pd0_get_u64 src pos
643pos = add pos 8
644put m confidence_ppm pd0_get_u32 src pos
645pos = add pos 4
646nexc = ulong pd0_get_u16 src pos
647pos = add pos 2
648if gt nexc ulong 16
649ret -1
650end
651put m n_exc ushort nexc
652if gt add pos mul nexc ulong 64 slen
653ret -1
654end
655pos = add pos mul nexc ulong 64
656if gt add pos 2 slen
657ret -1
658end
659nexp = ulong pd0_get_u16 src pos
660pos = add pos 2
661if gt nexp ulong 16
662ret -1
663end
664put m n_exp ushort nexp
665if gt add pos mul nexp ulong 114 slen
666ret -1
667end
668pos = add pos mul nexp ulong 114
669if gt add pos 34 slen
670ret -1
671end
672pos = add pos 32
673cl = ulong pd0_get_u16 src pos
674pos = add pos 2
675if ne add pos cl slen
676ret -1
677end
678ret 0
679end
680
681fn pd0_law_verify_hash src view uchar * to int
682slen = len src
683if gt slen ulong 4096
684ret -1
685end
686copy = new uchar 4096 0
687for i ulong slen bound 4096
688put copy i get src i
689end
690for k ulong 32
691put copy add ulong 11 k uchar 0
692end
693h = new uchar 32 0
694pd0_sha256_hash view copy slen edit h
695for k ulong 32
696if ne get h k get src add ulong 11 k
697ret -1
698end
699put p0l_law_id k get h k
700end
701ret 0
702end
703
704fn pd0_law_decode_hdr src view uchar * slot ulong m edit Pd0LawMeta to int
705if lt len src ulong 53
706ret -1
707end
708if ne pd0_eq_bytes src ulong 0 PD0_MAGIC_LAW1 ulong 6 1
709ret -1
710end
711if or ne get src 6 uchar 0 ne get src 7 uchar 0
712ret -1
713end
714if ne pd0_get_u16 src ulong 8 ushort 1
715ret -1
716end
717if gt get src 10 PD0_LAW_PROVISIONAL
718ret -1
719end
720put m state get src 10
721p0r_clear slot
722if or gt ulong get src 43 PD0_MAX_VARS or gt ulong get src 45 PD0_MAX_CH gt ulong get src 52 PD0_MAX_VARS
723ret -1
724end
725put p0r_nvars slot get src 43
726put p0r_nlat slot get src 44
727put p0r_nch slot get src 45
728put p0r_neq slot get src 52
729put m n_refutations pd0_get_u16 src ulong 50
730ret 0
731end
732
733fn pd0_law_decode src view uchar * slot ulong m edit Pd0LawMeta to int
734if ne pd0_law_decode_hdr src slot m 0
735ret -1
736end
737pos = pd0_law_decode_eqs src ulong 53 slot
738if eq pos ulong 0
739ret -1
740end
741if ne pd0_relation_valid slot 0
742ret -1
743end
744if ne pd0_get_u32 src ulong 46 pd0_relation_description_bits slot
745ret -1
746end
747nobs = sub ulong get p0r_nvars slot ulong get p0r_nlat slot
748if ne pd0_law_decode_tail src pos nobs ulong get p0r_nch slot m 0
749ret -1
750end
751ret pd0_law_verify_hash src
752end