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
omega-mv / src / checker2 / c2_lrat.h
| 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* c2_lrat: checker2's own DIMACS CNF reader and LRAT proof checker (omega#446). |
| 18 | * |
| 19 | * Trusted part of checker2. The SAT solver that writes proofs is NOT trusted and is not linked here. |
| 20 | * Written from the published formats only: DIMACS CNF ("p cnf V C", clauses of nonzero literals |
| 21 | * ended by 0, "c" comment lines) and textual LRAT (Cruz-Filipe, Heule, Hunt, Kaufmann, Schneider-Kamp, |
| 22 | * "Efficient certified RAT verification", CADE 2017): |
| 23 | * <id> <lit>* 0 <hint>* 0 add a clause, justified by reverse unit propagation (RUP) |
| 24 | * <id> d <id>* 0 delete clauses |
| 25 | * checker2 accepts RUP steps only: a negative hint (a RAT step) is refused, never interpreted. |
| 26 | * Each added clause is checked by assigning all its literals false and walking the hints in order: |
| 27 | * every hint must be unit (then its last literal is assigned) or falsified (then the step is |
| 28 | * proved). A hint that is neither, or a hint list that ends without a conflict, fails the proof. |
| 29 | * The proof is accepted only if it adds the empty clause. Added clause ids must be strictly |
| 30 | * increasing and at most (input clauses + proof lines), LRAT-ID-RANGE otherwise, so the id-indexed |
| 31 | * clause table stays proportional to the input. Fails closed on any malformed input. */ |
| 32 | #ifndef C2_LRAT_H |
| 33 | #define C2_LRAT_H |
| 34 | |
| 35 | #include <stddef.h> |
| 36 | #include <stdint.h> |
| 37 | |
| 38 | typedef struct { |
| 39 | int nvars; |
| 40 | int nclauses; |
| 41 | int32_t *lits; /* all clause literals, each clause ended by 0 */ |
| 42 | size_t nlits; |
| 43 | size_t *start; /* nclauses offsets into lits */ |
| 44 | size_t lcap, scap; /* allocated entries of lits / start */ |
| 45 | } C2Cnf; |
| 46 | |
| 47 | typedef struct { |
| 48 | int ok; /* 1: the empty clause was derived, the formula is unsatisfiable */ |
| 49 | const char *rule; /* stable failure name, "LRAT-OK" on success */ |
| 50 | long line; /* proof line of the failure, 0 if none */ |
| 51 | long steps, deletions; |
| 52 | } C2LratResult; |
| 53 | |
| 54 | /* 0 ok, -1 malformed (rule in *why). Caller frees with c2_cnf_free. */ |
| 55 | int c2_cnf_parse(const char *text, size_t len, C2Cnf *cnf, const char **why); |
| 56 | void c2_cnf_free(C2Cnf *cnf); |
| 57 | /* Append clause (lits[0..n), 0 excluded) to an in-memory formula (used by the bit-blaster). */ |
| 58 | int c2_cnf_add(C2Cnf *cnf, const int32_t *lits, int n); |
| 59 | /* DIMACS text of cnf into a malloc'd buffer. */ |
| 60 | char *c2_cnf_print(const C2Cnf *cnf, size_t *len); |
| 61 | |
| 62 | /* 0 proof accepted (empty clause derived), -1 refused (r->rule says why). */ |
| 63 | int c2_lrat_check(const C2Cnf *cnf, const char *proof, size_t len, C2LratResult *r); |
| 64 | |
| 65 | #endif /* C2_LRAT_H */ |