-
Notifications
You must be signed in to change notification settings - Fork 57
558 add general proof api #583
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
base: master
Are you sure you want to change the base?
Changes from all commits
d7f226a
9647cd5
570eb5c
0fd0070
6272b50
0f8c032
b9dc850
d3e69b1
1b79e82
9f2ac63
dcc728a
f849437
7abe581
f1fa31a
f5e3376
27847d8
8213c7a
6a133f6
72c9697
50a9b16
32da899
ed64164
f037077
77d77a8
c2cdbae
ab4e485
d1a18f9
98daf50
71fbd4b
0cdc9b0
230924a
47922a9
7f94d1b
127a0af
e969884
1e01011
c59874b
1684258
f750ce1
be6ae14
58cf62c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * This file is part of JavaSMT, | ||
| * an API wrapper for a collection of SMT solvers: | ||
| * https://github.com/sosy-lab/java-smt | ||
| * | ||
| * SPDX-FileCopyrightText: 2026 Dirk Beyer <https://www.sosy-lab.org> | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.sosy_lab.java_smt.api.proofs; | ||
|
|
||
| import com.google.common.collect.ImmutableSet; | ||
| import java.util.Optional; | ||
| import org.sosy_lab.java_smt.api.Formula; | ||
|
|
||
| /** A proof node in the proof DAG of a proof. */ | ||
| public interface Proof { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like the name of this class should be
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: this was named In general: the We should then add a new interface |
||
|
|
||
| /** Get the children of the proof node. */ | ||
| ImmutableSet<Proof> getChildren(); | ||
|
|
||
| /** | ||
| * Check if the proof node is a leaf. | ||
| * | ||
| * @return True if the proof node is a leaf, false otherwise. | ||
| */ | ||
| boolean isLeaf(); | ||
|
|
||
| /** | ||
| * Get the formula of the proof node. | ||
| * | ||
| * @return The formula of the proof node. | ||
| */ | ||
| Optional<Formula> getFormula(); | ||
|
|
||
| /** | ||
| * Get the rule of the proof node. | ||
| * | ||
| * @return The rule of the proof node. | ||
| */ | ||
| ProofRule getRule(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * This file is part of JavaSMT, | ||
| * an API wrapper for a collection of SMT solvers: | ||
| * https://github.com/sosy-lab/java-smt | ||
| * | ||
| * SPDX-FileCopyrightText: 2026 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. E.g.: | ||
| * | ||
| * <p>CVC5 currently uses many rules in its calculus for proving unsatisfiability. Through its API | ||
| * one can retrieve a rule in form of an enum. See: <a | ||
| * href="https://cvc5.github.io/docs/cvc5-1.3.2/api/java/io/github/cvc5/ProofRule.html">...</a> | ||
| * Note: Other solvers may return just a String, the name of the rule applied. | ||
| * | ||
| * <p>We can look at RESOLUTION: Given two nodes viewed as clauses C_1 and C_2, as well as the pivot | ||
| * which is a literal occurring in C_1 and C_2 (positively and negatively or the other way around) | ||
| * and its polarity, it produces C which "is a clause resulting from collecting all the literals in | ||
| * C_1, minus the first occurrence of the pivot or its negation, and C_2, minus the first occurrence | ||
| * of the pivot or its negation, according to the policy above". See the link given earlier. | ||
| */ | ||
| public interface ProofRule { | ||
|
|
||
| /** Get the name of the proof rule. */ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An example would be helpful for users to understand. Especially since distinct solvers can return distinct rules. |
||
| String getName(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| /* | ||
| * This file is part of JavaSMT, | ||
| * an API wrapper for a collection of SMT solvers: | ||
| * https://github.com/sosy-lab/java-smt | ||
| * | ||
| * SPDX-FileCopyrightText: 2026 Dirk Beyer <https://www.sosy-lab.org> | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| /** | ||
| * This package is meant to provide abstract classes and interfaces that are inherited and used all | ||
| * over to process proofs from the solvers. | ||
| */ | ||
| package org.sosy_lab.java_smt.api.proofs; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| /* | ||
| * This file is part of JavaSMT, | ||
| * an API wrapper for a collection of SMT solvers: | ||
| * https://github.com/sosy-lab/java-smt | ||
| * | ||
| * SPDX-FileCopyrightText: 2026 Dirk Beyer <https://www.sosy-lab.org> | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.sosy_lab.java_smt.basicimpl; | ||
|
|
||
| import com.google.common.collect.ImmutableSet; | ||
| import java.util.LinkedHashSet; | ||
| import java.util.Optional; | ||
| import java.util.Set; | ||
| import org.checkerframework.checker.nullness.qual.Nullable; | ||
| import org.sosy_lab.java_smt.api.Formula; | ||
| import org.sosy_lab.java_smt.api.proofs.Proof; | ||
| import org.sosy_lab.java_smt.api.proofs.ProofRule; | ||
|
|
||
| /** | ||
| * A proof DAG of a proof. | ||
| * | ||
| * @author Gabriel Carpio | ||
| */ | ||
| public abstract class AbstractProof implements Proof { | ||
|
|
||
| private ImmutableSet<Proof> children = ImmutableSet.of(); | ||
| private ProofRule rule; | ||
| protected Optional<Formula> formula = Optional.empty(); | ||
|
|
||
| protected AbstractProof(ProofRule pRule, @Nullable Formula pFormula) { | ||
| this.rule = pRule; | ||
| this.formula = Optional.ofNullable(pFormula); | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<Formula> getFormula() { | ||
| return this.formula; | ||
| } | ||
|
|
||
| @Override | ||
| public ImmutableSet<Proof> getChildren() { | ||
| return this.children; | ||
| } | ||
|
|
||
| protected void addChild(Proof pChild) { | ||
| Set<Proof> tempChildren = new LinkedHashSet<>(this.children); | ||
| tempChildren.add(pChild); | ||
| this.children = ImmutableSet.copyOf(tempChildren); | ||
| } | ||
|
|
||
| @Override | ||
| public ProofRule getRule() { | ||
| return rule; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isLeaf() { | ||
| return getChildren().isEmpty(); | ||
| } | ||
|
|
||
| /** | ||
| * This method gibes the proof back as a formatted string. It is meant to have a readable proof | ||
| * for debugging purposes. | ||
| */ | ||
| public String proofAsString() { | ||
| return proofAsString(0); | ||
| } | ||
|
|
||
| protected String proofAsString(int pIndentLevel) { | ||
| StringBuilder sb = new StringBuilder(); | ||
| String indent = " ".repeat(pIndentLevel); | ||
|
|
||
| String sFormula = getFormula().map(Object::toString).orElse("null"); | ||
|
|
||
| sb.append(indent).append("Formula: ").append(sFormula).append("\n"); | ||
| sb.append(indent).append("Rule: ").append(getRule().getName()).append("\n"); | ||
| sb.append(indent) | ||
| .append("No. Children: ") | ||
| .append(this.isLeaf() ? 0 : getChildren().size()) | ||
| .append("\n"); | ||
| sb.append(indent).append("leaf: ").append(isLeaf()).append("\n"); | ||
|
|
||
| int i = 0; | ||
| if (!isLeaf()) { | ||
| for (Proof child : getChildren()) { | ||
| sb.append(indent).append("Child ").append(++i).append(":\n"); | ||
| sb.append(((AbstractProof) child).proofAsString(pIndentLevel + 1)); | ||
| } | ||
| } | ||
|
|
||
| return sb.toString(); | ||
| } | ||
|
|
||
| protected abstract static class ProofFrame<T> { | ||
| final T proof; | ||
| int numArgs = 0; | ||
| boolean visited; | ||
|
|
||
| protected ProofFrame(T pProof) { | ||
| this.proof = pProof; | ||
| 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() { | ||
| this.visited = true; | ||
| } | ||
|
|
||
| /** Set the number of arguments the proof object has. */ | ||
| public void setNumArgs(int pNumArgs) { | ||
| this.numArgs = pNumArgs; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a note about Z3 here please? The Z3 proof situation might be confusing for users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean about it needing proof generation enabled on the context object?
I was thinking to leave that out for this, as the only solver with proof generation should be CVC5 for now. Once it is turn for Z3 then I would add the corresponding note.