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 / gpu / checker2 / test.om

211 lines · 5445 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note gpu/checker2/test.om: comprehensive positive & negative-control test suite for checker2 LRAT & DIMACS CNF.
3note Tests: valid UNSAT proofs (pigeonhole PHP(2,1), multi-step RUP with deletions, tautology, trailing hints,
4note comments/whitespace) AND all 13 fail-closed refusal rules (CNF-HEADER, CNF-LITERAL, CNF-COUNT,
5note LRAT-SYNTAX, LRAT-DELETE-UNKNOWN, LRAT-ID-ORDER, LRAT-ID-RANGE, LRAT-LITERAL, LRAT-RAT-UNSUPPORTED,
6note LRAT-HINT-UNKNOWN, LRAT-HINT-NOT-UNIT, LRAT-NO-CONFLICT, LRAT-NO-EMPTY-CLAUSE).
7note Compose: si/directives/om2.om gpu/checker2/lrat.om gpu/checker2/test.om
8
9text t_ok1 "PASS valid UNSAT LRAT proofs (3-var chain, deletions, tautology, trailing hints, comments)\n"
10text t_ok2 "PASS DIMACS CNF fail-closed refusals (HEADER, LITERAL, COUNT)\n"
11text t_ok3 "PASS LRAT fail-closed refusals (SYNTAX, DELETE-UNKNOWN, ID-ORDER, ID-RANGE, LITERAL)\n"
12text t_ok4 "PASS LRAT RUP trust-boundary refusals (RAT-UNSUPPORTED, HINT-UNKNOWN, HINT-NOT-UNIT, NO-CONFLICT, NO-EMPTY-CLAUSE)\n"
13text t_all "ALL PASS gpu-checker2-lrat\n"
14text t_fail "FAIL gpu-checker2-lrat\n"
15
16note ---- Positive test fixtures ----
17
18note CNF 1: (1 2) (-1 2) (1 -2) (-1 -2) -- classic 2-variable UNSAT with comments
19text cnf_unsat2 "c 2-var unsat formula\np cnf 2 4\n1 2 0\n-1 2 0\n1 -2 0\n-1 -2 0\n"
20note LRAT 1: derive (2) via 1 2, delete 1 2, derive () via 5 3 4
21text lrat_unsat2 "5 2 0 1 2 0\n5 d 1 2 0\n6 0 5 3 4 0\n"
22
23note CNF 2: 3-var implication chain UNSAT: (1) (-1 2) (-2 3) (-3)
24text cnf_chain3 "p cnf 3 4\n1 0\n-1 2 0\n-2 3 0\n-3 0\n"
25note LRAT 2: includes a tautology clause (1 -1), trailing hint after conflict, and empty clause
26text lrat_chain3 "5 1 -1 0 1 0\n6 2 0 1 2 0\n7 0 6 3 4 1 0\n"
27
28note CNF 3: Pigeonhole PHP(2,1) -- 3 pigeons (vars 1,2,3) in 2 holes? No, 2 pigeons in 1 hole: (1) (2) (-1 -2)
29text cnf_php21 "c PHP(2,1)\np cnf 2 3\n1 0\n2 0\n-1 -2 0\n"
30text lrat_php21 "4 0 1 2 3 0\n"
31
32note ---- Negative control fixtures ----
33
34text cnf_bad_hdr "p sat 2 2\n1 0\n-1 0\n"
35text cnf_bad_lit "p cnf 2 1\n3 0\n"
36text cnf_bad_cnt "p cnf 2 3\n1 0\n-1 0\n"
37text cnf_bad_trail "p cnf 2 1\n1 0\n2\n"
38
39text lrat_bad_syntax "5 2 0 1\n"
40text lrat_del_unk "5 d 99 0\n"
41text lrat_del_twice "5 d 1 0\n6 d 1 0\n"
42text lrat_id_order "4 2 0 1 2 0\n"
43text lrat_id_range "500 2 0 1 2 0\n"
44text lrat_bad_lit "5 9 0 1 2 0\n"
45text lrat_rat_neg "5 2 0 -1 2 0\n"
46text lrat_hint_unk "5 2 0 99 0\n"
47text lrat_hint_del "5 d 1 0\n6 2 0 1 2 0\n"
48text lrat_not_unit "5 0 1 2 0\n"
49text lrat_no_conf "5 2 0 1 0\n"
50text lrat_no_empty "5 2 0 1 2 0\n"
51
52fn c2_puts s view uchar * to void
53k = write 1 s 0 len s
54if lt k 0
55exit 2
56end
57ret
58end
59
60fn test_valid_proofs to int
61res = new C2LratRes 0 0 0 0 0
62note 1. 2-var UNSAT with deletion
63if ne c2_cnf_parse cnf_unsat2 C2_OK
64ret 1
65end
66if ne c2_lrat_check lrat_unsat2 edit res C2_OK
67ret 2
68end
69if ne get res ok 1
70ret 3
71end
72if ne get res steps 2
73ret 4
74end
75if ne get res dels 2
76ret 5
77end
78note 2. 3-var chain with tautology & trailing hint after conflict
79if ne c2_cnf_parse cnf_chain3 C2_OK
80ret 6
81end
82if ne c2_lrat_check lrat_chain3 edit res C2_OK
83ret 7
84end
85if ne get res ok 1
86ret 8
87end
88if ne get res steps 3
89ret 9
90end
91note 3. PHP(2,1) direct RUP
92if ne c2_cnf_parse cnf_php21 C2_OK
93ret 10
94end
95if ne c2_lrat_check lrat_php21 edit res C2_OK
96ret 11
97end
98if ne get res steps 1
99ret 12
100end
101ret 0
102end
103
104fn test_cnf_refusals to int
105if ne c2_cnf_parse cnf_bad_hdr C2_E_CNF_HEADER
106ret 20
107end
108if ne c2_cnf_parse cnf_bad_lit C2_E_CNF_LITERAL
109ret 21
110end
111if ne c2_cnf_parse cnf_bad_cnt C2_E_CNF_COUNT
112ret 22
113end
114if ne c2_cnf_parse cnf_bad_trail C2_E_CNF_COUNT
115ret 23
116end
117ret 0
118end
119
120fn test_lrat_structural_refusals to int
121res = new C2LratRes 0 0 0 0 0
122if ne c2_cnf_parse cnf_unsat2 C2_OK
123ret 30
124end
125if ne c2_lrat_check lrat_bad_syntax edit res C2_E_LRAT_SYNTAX
126ret 31
127end
128if ne c2_lrat_check lrat_del_unk edit res C2_E_LRAT_DELETE_UNKNOWN
129ret 32
130end
131if ne c2_lrat_check lrat_del_twice edit res C2_E_LRAT_DELETE_UNKNOWN
132ret 33
133end
134if ne c2_lrat_check lrat_id_order edit res C2_E_LRAT_ID_ORDER
135ret 34
136end
137if ne c2_lrat_check lrat_id_range edit res C2_E_LRAT_ID_RANGE
138ret 35
139end
140if ne c2_lrat_check lrat_bad_lit edit res C2_E_LRAT_LITERAL
141ret 36
142end
143ret 0
144end
145
146fn test_lrat_rup_refusals to int
147res = new C2LratRes 0 0 0 0 0
148if ne c2_cnf_parse cnf_unsat2 C2_OK
149ret 40
150end
151note Negative hint (RAT step) must be refused outright
152if ne c2_lrat_check lrat_rat_neg edit res C2_E_LRAT_RAT_UNSUPPORTED
153ret 41
154end
155if ne get res ok 0
156ret 42
157end
158if ne c2_lrat_check lrat_hint_unk edit res C2_E_LRAT_HINT_UNKNOWN
159ret 43
160end
161note Hint referencing a deleted clause must be refused
162if ne c2_lrat_check lrat_hint_del edit res C2_E_LRAT_HINT_UNKNOWN
163ret 44
164end
165note Non-unit hint (clause 1 has 2 unassigned literals when deriving empty clause)
166if ne c2_lrat_check lrat_not_unit edit res C2_E_LRAT_HINT_NOT_UNIT
167ret 45
168end
169note Hints finish without conflict
170if ne c2_lrat_check lrat_no_conf edit res C2_E_LRAT_NO_CONFLICT
171ret 46
172end
173note Valid step but never derives empty clause
174if ne c2_lrat_check lrat_no_empty edit res C2_E_LRAT_NO_EMPTY_CLAUSE
175ret 47
176end
177ret 0
178end
179
180fn main to int
181rc = test_valid_proofs
182if ne rc 0
183c2_puts t_fail
184ret rc
185end
186c2_puts t_ok1
187
188rc = test_cnf_refusals
189if ne rc 0
190c2_puts t_fail
191ret rc
192end
193c2_puts t_ok2
194
195rc = test_lrat_structural_refusals
196if ne rc 0
197c2_puts t_fail
198ret rc
199end
200c2_puts t_ok3
201
202rc = test_lrat_rup_refusals
203if ne rc 0
204c2_puts t_fail
205ret rc
206end
207c2_puts t_ok4
208
209c2_puts t_all
210ret 0
211end