Skip to content

Develop a common proof format and export proofs #458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 140 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
140 commits
Select commit Hold shift + click to select a range
9f449e7
Added multiple classes for supporting proof generation. Added method …
gcarpio21 Feb 3, 2025
b2bc9eb
Added GENERATE_PROOFS to ProverOptions
gcarpio21 Feb 17, 2025
766e665
Added implementation of getProof for SMTInterpol. Changed default beh…
gcarpio21 Feb 17, 2025
9c07f08
Merge remote-tracking branch 'refs/remotes/origin/master' into develo…
gcarpio21 Feb 20, 2025
ca725ba
Added ProofTermParser to transform a proof DAG made out of Term objec…
gcarpio21 Mar 3, 2025
955c1af
Z3: context now able to be created with proof generation.
gcarpio21 Mar 5, 2025
375937d
Merge branch 'master' into develop_a_common_proof_format_and_export_p…
gcarpio21 Mar 6, 2025
af4f670
Z3: Proof ast given by Z3 is now parsed to DAG made out of Z3ProofNode.
gcarpio21 Mar 11, 2025
c2139ad
Z3: Corrections to the parsing of the proof ast.
gcarpio21 Mar 12, 2025
e05451c
Mathsat5: The Native API now includes the methods for proof processing
gcarpio21 Mar 14, 2025
e69d1e0
Merge branch 'master' into develop_a_common_proof_format_and_export_p…
gcarpio21 Mar 16, 2025
a6a3efd
Z3: The transitivity proof step from Z3 is now able to be converted t…
gcarpio21 Mar 17, 2025
2015b46
Z3: Small correction when converting the transitivity proof rule to r…
gcarpio21 Mar 17, 2025
a4bbe62
Z3: True, Asserted, Goal, MP, Reflexivity and Symmetry proof rules ca…
gcarpio21 Mar 17, 2025
5962139
Refactor proof traversal, add tests, and add CVC5 support
gcarpio21 Mar 19, 2025
e7940f1
Renamed some classes
gcarpio21 Mar 19, 2025
f988d6a
Renaming some classes for clarity
gcarpio21 Mar 20, 2025
fcdf44f
Method `getFormula()` in the `ProofRule` interface has default imple…
gcarpio21 Mar 20, 2025
1d9ab98
Added Mathsat5ProofRule class
gcarpio21 Mar 20, 2025
2fec458
Added Mathsat5ProofProcessor class for processing the proofs straight…
gcarpio21 Mar 20, 2025
7c20761
Added Mathsat5ProofNode class for storing the proofs in JavaSMT
gcarpio21 Mar 20, 2025
3d89810
Mathsat5: proofs are enabled by setting `ProverOptions.GENERATE_PROOFS`
gcarpio21 Mar 20, 2025
d88ecb2
Mathsat5: method `getProof()` now can be called to get a `ProofNode` …
gcarpio21 Mar 20, 2025
e87f469
Checkstyle
gcarpio21 Mar 21, 2025
018d857
Class ProofRuleRegistry now allows to get a proof rule from any solve…
gcarpio21 Mar 21, 2025
818fe70
Class `ProofRuleRegistry` now allows to get a proof rule from any sol…
gcarpio21 Mar 21, 2025
87159e8
CVC5: Proofs are now processed and stored as `CVC5ProofNode`
gcarpio21 Mar 21, 2025
c1eef9f
CVC5: Added test for `getProof`
gcarpio21 Mar 21, 2025
746d653
Z3: Documentation on the proof format transformation.
gcarpio21 Mar 23, 2025
aca4b7c
Merge branch 'master' into develop_a_common_proof_format_and_export_p…
gcarpio21 Mar 23, 2025
34c9a7e
`ProofFactory` no longer public
gcarpio21 Mar 23, 2025
5aeb644
CVC5: fixed some proofs test issues
gcarpio21 Mar 23, 2025
f7c5682
CVC5: `getProof` handles the case where no proof is available
gcarpio21 Mar 23, 2025
4b35856
Refactoring some of the proof related classes
gcarpio21 Mar 24, 2025
7dce948
Proofs: Refactoring to have fewer classes and repeated code.
gcarpio21 Mar 24, 2025
4af588c
Extended documentation regarding proofs format
gcarpio21 Mar 24, 2025
1440715
Checkstyle
gcarpio21 Mar 24, 2025
c64814a
Documentation on the proof processing from Z3
gcarpio21 Mar 24, 2025
c5ea9bb
Z3: Changed the way the proof rule that Z3 gives back is processed
gcarpio21 Mar 24, 2025
e2268ba
`ResolutionProofNode` and `SourceProofNode` have been moved inside `R…
gcarpio21 Mar 24, 2025
e0d116d
`getProof` now checks if the state of the solver and throws an except…
gcarpio21 Mar 25, 2025
23e79a8
Added documentation.
gcarpio21 Mar 25, 2025
99f682e
SMTInterpol: added basic traversal for retrieved proofs in `SmtInterp…
gcarpio21 Mar 25, 2025
f0d19ac
Documentation
gcarpio21 Mar 28, 2025
3debfe2
`getProof` implementation was missing in some `ProverEnvironment` inh…
gcarpio21 Mar 28, 2025
85f8e11
Z3: added some tests for proofs
gcarpio21 Mar 28, 2025
44e6ce8
Refactoring of some methods and classes, name changes and modifiers.
gcarpio21 Mar 28, 2025
f7da393
CVC5: fixed unending loop in `getProof`.
gcarpio21 Mar 28, 2025
dc6d5b3
Z3: Added tests for proof methods, fixed rule not properly created wh…
gcarpio21 Mar 28, 2025
12e4ccb
CVC5: Corrected incorrect cast at `getProof`
gcarpio21 Mar 28, 2025
9bc37ca
CVC5: proof dag now gets completely generated.
gcarpio21 Mar 29, 2025
78e5431
Fixed incorrect generation of IDs for `AbstractProofNode` inheritors'…
gcarpio21 Mar 29, 2025
9617048
Documentation
gcarpio21 Mar 29, 2025
95ee755
`AbstractProofNode` now is an internal class of `AbstractProofDag`
gcarpio21 Mar 29, 2025
036a563
`getProof` no longer overridden in `AbstractProver`. default method a…
gcarpio21 Mar 29, 2025
fd2230a
`getProof` no longer overridden in `AbstractProver`. default method a…
gcarpio21 Mar 29, 2025
7fcd878
Mathsat5: `getProof` now checks if the state is closed and the stack …
gcarpio21 Mar 29, 2025
4dbc7ec
Mathsat5: `getProof` now checks if the state is closed and the stack …
gcarpio21 Mar 29, 2025
2aa8f25
Checkstyle
gcarpio21 Mar 29, 2025
07e5866
Delete useless test in `SmtInterpolProofsTest`
gcarpio21 Mar 29, 2025
912e315
`ProofRuleRegistry` and method `ProofRule.fromName` no longer used
gcarpio21 Mar 29, 2025
e942121
`ProofRuleRegistry` deleted `ProofRule` inheritor classes no longer p…
gcarpio21 Mar 29, 2025
a888646
Removed unwanted test
gcarpio21 Mar 29, 2025
2dce339
Merge branch 'master' into develop_a_common_proof_format_and_export_p…
gcarpio21 Mar 30, 2025
9fc4a22
Checkstyle
gcarpio21 Apr 1, 2025
a268761
Removed duplicates
gcarpio21 Apr 1, 2025
fd5ae78
SMTInterpol: `SmtInterpolProofNodeCreator` creates a provitional proo…
gcarpio21 Apr 1, 2025
4e9bd18
SMTInterpol: First implementation of non recursive processing of the …
gcarpio21 Apr 1, 2025
7d9ab91
SMTInterpol: First implementation of non recursive processing of the …
gcarpio21 Apr 1, 2025
a677bbb
solved warnings.
gcarpio21 Apr 6, 2025
1131456
MathSAT5: nodes with rule `CLAUSE-HYP` are now leaves.
gcarpio21 Apr 7, 2025
f9e4209
Chekstyle
gcarpio21 Apr 7, 2025
f81f2e3
Mathsat5: nodes with the `THEORY_LEMMA` `ProofRule` now also have a n…
gcarpio21 Apr 7, 2025
6fa3a60
Mathsat5: nodes with the `RES_CHAIN` `ProofRule` now also have a non …
gcarpio21 Apr 8, 2025
7fa1304
Documentation, checkstyle and deleted unnecessary checks
gcarpio21 Apr 8, 2025
50ecf10
Add a Mathsat5 native test for proof generation options in shared env…
Apr 10, 2025
15f4bc7
Delete src/org/sosy_lab/java_smt/solvers/cvc5/CVC5ProofsTest.java
gcarpio21 Apr 10, 2025
9166aee
MathSAT5: the resolution chain for the proofs is now executed iterati…
gcarpio21 Apr 10, 2025
6c0fc0a
Z3: The state of the solver is checked as well as whether the asserti…
gcarpio21 Apr 11, 2025
c379e89
Merge remote-tracking branch 'origin/develop_a_common_proof_format_an…
gcarpio21 Apr 16, 2025
f81fbe8
Renamed for clarity
gcarpio21 Apr 21, 2025
f9fd81e
Documentation and rename
gcarpio21 Apr 21, 2025
f0e702c
Z3: No more ProofProcessor class, proofs are now processed in the 'Z3…
gcarpio21 Apr 21, 2025
35732ed
Test for handling proofs expanded, now tests if all methods from 'Pro…
gcarpio21 Apr 21, 2025
fce8053
Z3: Native method for retrieving proofs in 'Z3TheoremProver' now wrap…
gcarpio21 Apr 21, 2025
1fbc3cc
CVC5: 'CVC5ProofProcessor' deleted. Proofs are now processed in 'CVC5…
gcarpio21 Apr 21, 2025
2007795
AbstractProofDAG: formula is now nullable. 'setFormula' set to public.
gcarpio21 May 2, 2025
066de33
Checkstyle
gcarpio21 May 2, 2025
16c9aa8
'setFormula' deleted
gcarpio21 May 2, 2025
e4f52c2
First steps towards implementing 'getProof'
gcarpio21 May 2, 2025
5cef715
SMTInterpol: proof generation support now implemented.
gcarpio21 May 2, 2025
fa3cfb4
Delete src/org/sosy_lab/java_smt/solvers/smtinterpol/SmtInterpolProof…
gcarpio21 May 2, 2025
5375cf4
Delete src/org/sosy_lab/java_smt/solvers/z3/Z3ProofsTest.java
gcarpio21 May 2, 2025
24f4ddf
Corrected multiple warnings to be able to build.
gcarpio21 May 2, 2025
59bcd5e
Deleted class that is not needed. Made changes to pass unit tests and…
gcarpio21 May 2, 2025
1f805df
Made changes to pass unit tests and checkstyle.
gcarpio21 May 2, 2025
4b89e38
Corrected warnings
gcarpio21 May 3, 2025
3119873
Deleted unsued variable
gcarpio21 May 7, 2025
e814fa2
Deleted unused methods
gcarpio21 May 7, 2025
e59a15f
Z3 now has proof production always enabled
gcarpio21 May 7, 2025
d26157d
MathSAT5: Changed proof rule in the enum Rule from Rule.NULL to Rule.…
gcarpio21 May 12, 2025
136f1fe
SMTInterpol: Reverted changes to SmtInterpolFormulaCreator from commi…
gcarpio21 May 12, 2025
9303114
Changed the parameter of 'toLowerCase' from Locale.ROOT to Locale.ENG…
gcarpio21 May 13, 2025
ca7e1eb
Renamed classes and added methods 'proofAsString' and 'getDAG'.
gcarpio21 May 15, 2025
a761fca
Renamed class ProofNode to Subproof
gcarpio21 May 15, 2025
28390a2
Methods that should not be public no longer in 'Proof' interface move…
gcarpio21 May 15, 2025
5096139
Moved classes, removed not needed ones
gcarpio21 May 15, 2025
85d89a1
Renaming of classes, methods and adjusting constructors. 'Subproof' n…
gcarpio21 May 15, 2025
ea1735a
Deleted method 'setProof' in 'ProofFrame'. Attribute proof now final.
gcarpio21 May 15, 2025
6bbb92d
Made necessary changes to have proof production always enabled in Z3.
gcarpio21 May 15, 2025
81780c6
Renamed 'ProofNode' into 'Subproof'
gcarpio21 May 15, 2025
e751e16
Proofs: Proof edges is now a map from 'Subproof' -> 'LinkedHashSet<Su…
gcarpio21 May 16, 2025
640c6f7
SmtInterpol: Added extra proof rules.
gcarpio21 May 16, 2025
303713b
'ResProofRule': check for null removed. It should be checked elsewhere.
gcarpio21 May 16, 2025
84f1a16
CVC5: 'getProof' now checks whether proof generation is enabled throu…
gcarpio21 May 16, 2025
86c01cd
Proofs: Test cases for solvers' outputs for retrieving a proof when a…
gcarpio21 May 16, 2025
24991fe
Changed incorrect cast in 'AbstractProof'
gcarpio21 May 17, 2025
331f7ac
'AbstractProof' method 'proofAsString' did not print formulas correct…
gcarpio21 May 17, 2025
48534bd
'AbstractProof' method 'proofAsString' did not print formulas correct…
gcarpio21 May 17, 2025
dd460aa
'TOTAL_INT' rule in 'ResProofRule' had wrong name previously.
gcarpio21 May 17, 2025
a687265
MathSAT5: method 'getProof' now checks that proof generation is enabl…
gcarpio21 May 17, 2025
0bbaa73
Added multiple tests for proofs: test boolean proof, integer proof, r…
gcarpio21 May 17, 2025
0739661
Checkstyle
gcarpio21 May 17, 2025
16c6c9b
Merge branch 'master' into develop_a_common_proof_format_and_export_p…
gcarpio21 May 20, 2025
bcad354
Some (not working) code added so that proofs from OpenSMT are parsed …
gcarpio21 May 20, 2025
e86e7e2
No longer logging whole proof in 'LoggingBasicProverEnvironment'
gcarpio21 May 21, 2025
7aa247c
Added bit vector and array tests for retrieving proofs in `ProverEnvi…
gcarpio21 May 24, 2025
cec06cf
Multiple changes regarding the proof interface to fix warnings. Unche…
gcarpio21 May 26, 2025
c8009f0
MathSAT5: added test in `Mathsat5NativeApiTest` taken from `api_examp…
gcarpio21 May 26, 2025
25f67f7
Don't check primitive for null in Mathsat5 native tests and simply ch…
May 26, 2025
4200112
Add require methods for theories used in proof tests
May 26, 2025
b6a786c
Add an assertion as a hint for a necessary check when traversing Math…
May 26, 2025
27e4bb3
Disable eager BV theory option for proof generation in Mathsat, as it…
May 26, 2025
14e4991
Add more require methods for theories used in proof tests
May 26, 2025
08f8038
MathSAT5: added test in `Mathsat5NativeApiTest` to confirm that an ex…
gcarpio21 May 26, 2025
d056b4e
Merge remote-tracking branch 'origin/develop_a_common_proof_format_an…
gcarpio21 May 26, 2025
6171224
MathSAT5: now correctly handles the case when no proof manager is ava…
gcarpio21 May 26, 2025
78f891c
Checkstyle
gcarpio21 May 26, 2025
5383562
OpenSMT: formulas for proofs are stored as strings in each node which…
gcarpio21 May 28, 2025
c2b67a9
OpenSMT: fix incorrect handling of nested applications of the resolut…
gcarpio21 May 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 156 additions & 0 deletions src/org/sosy_lab/java_smt/ResProofRule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*
* This file is part of JavaSMT,
* an API wrapper for a collection of SMT solvers:
* https://github.com/sosy-lab/java-smt
*
* SPDX-FileCopyrightText: 2024 Dirk Beyer <https://www.sosy-lab.org>
*
* SPDX-License-Identifier: Apache-2.0
*/

package org.sosy_lab.java_smt;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.sosy_lab.java_smt.api.proofs.ProofRule;

/**
* A proof rule in the proof DAG of the proof format RESOLUTE used by SMTInterpol. See: <a
* href="https://ultimate.informatik.uni-freiburg.de/smtinterpol/proof-format.html">...</a>
*
* <p>The conversion from other formats to RESOLUTE appears to be simple and as such, it is a good
* candidate for a common proof format.
*
* @author Gabriel Carpio
*/
public final class ResProofRule {

private static final Map<String, ResAxiom> RULE_MAP = new HashMap<>();

private ResProofRule() {
// prevent instantiation
}

static {
for (ResAxiom rule : ResAxiom.values()) {
RULE_MAP.put(rule.getName().toLowerCase(Locale.ENGLISH), rule);
}
}

/** Any operation that proves a term. */
public enum ResAxiom implements ProofRule {
// Resolution Rule
RESOLUTION("res", "(res t proof1 proof2)"),
ASSUME("assume", "(assume t)"),
// Logical operators
TRUE_POSITIVE("true+", "(+ true)"),
FALSE_NEGATIVE("false-", "(- false)"),
NOT_POSITIVE("not+", "(+ (not p0) + p0)"),
NOT_NEGATIVE("not-", "(- (not p0) - p0)"),
AND_POSITIVE("and+", "(+ (and p0 … pn) - p0 … - pn)"),
AND_NEGATIVE("and-", "(- (and p0 … pn) + pi)"),
OR_POSITIVE("or+", "(+ (or p0 … pn) - pi)"),
OR_NEGATIVE("or-", "(- (or p0 … pn) + p0 … + pn)"),
IMPLIES_POSITIVE("=>+", "(+ (=> p0 … pn) +/- pi)"),
IMPLIES_NEGATIVE("=>-", "(- (=> p0 … pn) - p0 … + pn)"),
EQUAL_POSITIVE1("=+1", "(+ (= p0 p1) + p0 + p1)"),
EQUAL_NEGATIVE1("=-1", "(- (= p0 p1) + p0 - p1)"),
EQUAL_POSITIVE2("=+2", "(+ (= p0 p1) - p0 - p1)"),
EQUAL_NEGATIVE2("=-2", "(- (= p0 p1) - p0 + p1)"),
XOR_POSITIVE("xor+", "(+(xor l1) +(xor l2) -(xor l3))"),
XOR_NEGATIVE("xor-", "(-(xor l1) -(xor l2) -(xor l3))"),

// Quantifiers
FORALL_POSITIVE("forall+", "(+ (forall x (F x)) - (F (choose x (F x))))"),
FORALL_NEGATIVE("forall-", "(- (forall x (F x)) + (F t))"),
EXISTS_POSITIVE("exists+", "(+ (exists x (F x)) - (F t))"),
EXISTS_NEGATIVE("exists-", "(- (exists x (F x)) + (F (choose x (F x))))"),

// Equality axioms
REFLEXIVITY("refl", "(+ (= t t))"),
SYMMETRY("symm", "(+(= t0 t1) -(= t1 t0))"),
TRANSITIVITY("trans", "(+(= t0 tn) -(= t0 t1) … -(= tn-1 tn))"),
CONGRUENCE("cong", "(+(= (f t0 … tn) (f t0' … tn')) -(= t0 t0') … -(= tn tn'))"),
EQUALITY_POSITIVE("=+", "(+ (= t0 … tn) -(= t0 t1) … -(= tn-1 tn))"),
EQUALITY_NEGATIVE("=-", "(- (= t0 … tn) +(= ti tj))"),
DISTINCT_POSITIVE("distinct+", "(+ (distinct t0 … tn) +(= t0 t1) … +(= t0 tn) … +(= tn-1 tn))"),
DISTINCT_NEGATIVE("distinct-", "(- (distinct t0 … tn) -(= ti tj))"),

// ITE, define-fun, annotations
ITE1("ite1", "(+(= (ite t0 t1 t2) t1) - t0)"),
ITE2("ite2", "(+(= (ite t0 t1 t2) t2) + t0)"),
DEL("del!", "(+(= (! t :annotation…) t))"),
EXPAND("expand", "(+(= (f t0 … tn) (let ((x0 t0)…(xn tn)) d)))"),

// Array Theory
SELECTSTORE1("selectstore1", "(+ (= (select (store a i v) i) v))"),
SELECTSTORE2("selectstore2", "(+ (= (select (store a i v) j) (select a j)) (= i j))"),
EXTDIFF("extdiff", "(+ (= a b) (- (= (select a (@diff a b)) (select b (@diff a b)))))"),
CONST("const", "(+ (= (select (@const v) i) v))"),

// Linear Arithmetic
POLY_ADD("poly+", "(+ (= (+ a1 ... an) a))"),
POLY_MUL("poly*", "(+ (= (* a1 ... an) a))"),
TO_REAL("to_real", "(+ (= (to_real a) a'))"),
FARKAS("farkas", "(- (<=? a1 b1) ... - (<=? an bn))"),
TRICHOTOMY("trichotomy", "(+ (< a b) (= a b) (< b a))"),
TOTAL("total", "(+ (<= a b) (< b a))"),
GT_DEF("gt_def", "(+ (= (> a b) (< b a)))"),
GE_DEF("ge_def", "(+ (= (>= a b) (<= b a)))"),
DIV_DEF("div_def", "(+ (= a (* b1 ... bn (/ a b1 ... bn))) (= b1 0) ... (= bn 0))"),
NEG_DEF("neg_def", "(+ (= (- a) (* (- 1) a)))"),
NEG_DEF2("neg_def2", "(+ (= (- a b1 ... bn) (+ a (* (- 1) b1)) ... (* (- 1) bn)))"),
ABS_DEF("abs_def", "(+ (= (abs x) (ite (< x 0) (- x) x)))"),
TOTAL_INT("total-int", "(+ (<= a c) (<= (c+1) a))"),
TO_INT_LOW("to_int_low", "(+ (<= (to_real (to_int x)) x))"),
TO_INT_HIGH("to_int_high", "(+ (< x (+ (to_real (to_int x)) 1.0)))"),
DIV_LOW("div_low", "(+ (<= (* d (div x d)) x) (= d 0))"),
DIV_HIGH("div_high", "(+ (< x (+ (* d (div x d)) (abs d))) (= d 0))"),
MOD_DEF("mod_def", "(+ (= (mod x d) (- x (* d (div x d)))) (= d 0))"),
DIVISIBLE_DEF("divisible_def", "(+ (= ((_ divisible c) x) (= x (* c (div x c)))))"),
EXPAND_IS_INT("expand_is_int", "(+ (= (is_int x) (= x (to_real (to_int x)))))"),

// Data Types
DT_PROJECT("dt_project", "(= (seli (cons a1 ... an)) ai)"),
DT_CONS("dt_cons", "(~ ((_ is cons) x), (= (cons (sel1 x) ... (seln x)) x))"),
DT_TEST_CONS("dt_test_cons", "((_ is cons) (cons a1 ... an))"),
DT_TEST_CONS_PRIME("dt_test_cons_prime", "(~ ((_ is cons') (cons a1 ... an)))"),
DT_EXHAUST("dt_exhaust", "((_ is cons1) x), ..., ((_ is consn) x)"),
DT_ACYCLIC("dt_acyclic", "(~ (= (cons ... x ...) x))"),
DT_MATCH(
"dt_match",
"(= (match t ((p1 x1) c1) ...) (ite ((_ is p1) t) (let (x1 (sel1 t)) c1) ...))");

private final String name;
private final String formula;

ResAxiom(String pName, String pFormula) {
name = pName;
formula = pFormula;
}

@Override
public String getName() {
return name;
}

@Override
public String getFormula() {
return formula;
}
}

/**
* Retrieves a ProofRule by its name.
*
* @param name The name of the proof rule.
* @return The matching ProofRule.
* @throws NullPointerException if the name is null.
* @throws IllegalArgumentException if the name does not match any rule.
*/
public static ResAxiom getFromName(String name) {
ResAxiom rule = RULE_MAP.get(name.toLowerCase(Locale.ENGLISH));
return rule;
}
}
68 changes: 68 additions & 0 deletions src/org/sosy_lab/java_smt/ResolutionProof.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* This file is part of JavaSMT,
* an API wrapper for a collection of SMT solvers:
* https://github.com/sosy-lab/java-smt
*
* SPDX-FileCopyrightText: 2024 Dirk Beyer <https://www.sosy-lab.org>
*
* SPDX-License-Identifier: Apache-2.0
*/

package org.sosy_lab.java_smt;

import java.util.Objects;
import org.sosy_lab.java_smt.ResProofRule.ResAxiom;
import org.sosy_lab.java_smt.api.Formula;
import org.sosy_lab.java_smt.api.proofs.ProofRule;
import org.sosy_lab.java_smt.basicimpl.AbstractProof;

/**
* This class represents a resolution proof DAG. Its nodes might be of the type {@link
* AxiomSubproof} or {@link ResolutionSubproof}. It is used to represent proofs based on the
* RESOLUTE proof format from SMTInterpol.
*
* @see ResProofRule
*/
public class ResolutionProof extends AbstractProof {
// Work in progress. The functionality of producing just nodes should be provided first.
// The idea is to provide extended functionality (by providng a set of edges for example).

public static class ResolutionSubproof extends AbstractSubproof implements Subproof {

private final Formula pivot;

@Override
public void addChild(Subproof pSubproof) {
super.addChild(pSubproof);
}

public ResolutionSubproof(Formula formula, Formula pivot, AbstractProof p) {
super(ResAxiom.RESOLUTION, Objects.requireNonNull(formula, "Formula must not be null"), p);
this.pivot = Objects.requireNonNull(pivot, "Pivot must not be null");
}

public Formula getPivot() {
return pivot;
}

@Override
public ProofRule getRule() {
return super.getRule();
}
}

public static class AxiomSubproof extends AbstractSubproof implements Subproof {

public AxiomSubproof(ResAxiom rule, Formula formula, AbstractProof proof) {
super(
Objects.requireNonNull(rule, "Rule must not be null"),
Objects.requireNonNull(formula, "Formula must not be null"),
proof);
}

@Override
protected void addChild(Subproof pSubproof) {
super.addChild(pSubproof);
}
}
}
2 changes: 1 addition & 1 deletion src/org/sosy_lab/java_smt/SolverContextFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ private SolverContext generateContext0(Solvers solverToCreate)
case Z3:
return Z3SolverContext.create(
logger,
config,
Configuration.builder().copyFrom(config).setOption("requireProofs", "true").build(),
shutdownNotifier,
logfile,
randomSeed,
Expand Down
7 changes: 7 additions & 0 deletions src/org/sosy_lab/java_smt/api/BasicProverEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.Optional;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.sosy_lab.java_smt.api.SolverContext.ProverOptions;
import org.sosy_lab.java_smt.api.proofs.Proof.Subproof;

/**
* Super interface for {@link ProverEnvironment} and {@link InterpolatingProverEnvironment} that
Expand Down Expand Up @@ -149,6 +150,12 @@ default ImmutableMap<String, String> getStatistics() {
return ImmutableMap.of();
}

/**
* Get proof of unsatisfiability of the conjuction of the current satck of all formulas. Should
* only be called after {@link #isUnsat()} returned <code>true</code>.
*/
Subproof getProof() throws SolverException, InterruptedException;

/**
* Closes the prover environment. The object should be discarded, and should not be used after
* closing. The first call of this method will close the prover instance, further calls are
Expand Down
8 changes: 8 additions & 0 deletions src/org/sosy_lab/java_smt/api/SolverContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ enum ProverOptions {
*/
GENERATE_UNSAT_CORE_OVER_ASSUMPTIONS,

/**
* Whether the solver should generate proofs for unsatisfiable formulas. For Z3, this parameter
* is context(not solver)-based, so for setting it, the extra option in the {@link
* org.sosy_lab.common.configuration.Configuration} instance: "requireProofs" should be set to
* "true".
*/
GENERATE_PROOFS,

/** Whether the solver should enable support for formulae build in SL theory. */
ENABLE_SEPARATION_LOGIC
}
Expand Down
49 changes: 49 additions & 0 deletions src/org/sosy_lab/java_smt/api/proofs/Proof.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* This file is part of JavaSMT,
* an API wrapper for a collection of SMT solvers:
* https://github.com/sosy-lab/java-smt
*
* SPDX-FileCopyrightText: 2024 Dirk Beyer <https://www.sosy-lab.org>
*
* SPDX-License-Identifier: Apache-2.0
*/

package org.sosy_lab.java_smt.api.proofs;

import java.util.Collection;
import java.util.Set;
import org.sosy_lab.java_smt.api.Formula;

/**
* A DAG representing a proof. Each node in the DAG is a {@link Subproof} and each edge is a
* directed edge from a parent node to a child node.
*/
public interface Proof {

/** Get all proof steps in the proof. */
Collection<Subproof> getSubproofs();

/**
* A proof node in the proof DAG of a proof.
*
* @author Gabriel Carpio
*/
interface Subproof {

/** Get the children of the proof node. */
Set<Subproof> getArguments();

boolean isLeaf();

/**
* Get the formula of the proof node.
*
* @return The formula of the proof node.
*/
Formula getFormula();

ProofRule getRule();

Proof getDAG();
}
}
53 changes: 53 additions & 0 deletions src/org/sosy_lab/java_smt/api/proofs/ProofFrame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* This file is part of JavaSMT,
* an API wrapper for a collection of SMT solvers:
* https://github.com/sosy-lab/java-smt
*
* SPDX-FileCopyrightText: 2024 Dirk Beyer <https://www.sosy-lab.org>
*
* SPDX-License-Identifier: Apache-2.0
*/

package org.sosy_lab.java_smt.api.proofs;

/**
* Stores proof related information and gets stored in a stack when processing proofs. Each frame
* contains a proof object and the number of arguments it has.
*
* @param <T> The type of the proof object.
*/
public abstract class ProofFrame<T> {
final T proof;
int numArgs = 0;
boolean visited;

protected ProofFrame(T proof) {
this.proof = proof;
this.visited = false;
}

/** Get the proof object. */
public T getProof() {
return proof;
}

/** Get the number of arguments the proof object has. */
public int getNumArgs() {
return numArgs;
}

/** Check if the frame has been visited. */
public boolean isVisited() {
return visited;
}

/** Set the frame as visited. */
public void setAsVisited(boolean isVisited) {
this.visited = isVisited;
}

/** Set the number of arguments the proof object has. */
public void setNumArgs(int numArgs) {
this.numArgs = numArgs;
}
}
23 changes: 23 additions & 0 deletions src/org/sosy_lab/java_smt/api/proofs/ProofRule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* This file is part of JavaSMT,
* an API wrapper for a collection of SMT solvers:
* https://github.com/sosy-lab/java-smt
*
* SPDX-FileCopyrightText: 2024 Dirk Beyer <https://www.sosy-lab.org>
*
* SPDX-License-Identifier: Apache-2.0
*/

package org.sosy_lab.java_smt.api.proofs;

/** A proof rule from a given proof format. */
public interface ProofRule {

/** Get the name of the proof rule. */
String getName();

/** Get the formula of the proof rule. */
default String getFormula() {
return "no formula available";
}
}
Loading