-
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 21 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
3fcf9f0
4329cbf
f6489e8
76d8d71
cdca7ce
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: 2024 Dirk Beyer <https://www.sosy-lab.org> | ||
|
gcarpio21 marked this conversation as resolved.
Outdated
|
||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.sosy_lab.java_smt.api.proofs; | ||
|
|
||
| import java.util.Optional; | ||
| import java.util.Set; | ||
| 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
Member
Author
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. This has been renamed and now there is a new |
||
|
|
||
| /** Get the children of the proof node. */ | ||
| Set<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,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> { | ||
|
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. Do i see it correctly that this class is only needed to generate the proof?
Member
Author
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. Yes, this is wrapper that helps process the proofs, I did not want to repeat code over all solvers so I put the class in this directory.
Member
Author
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. I moved this class inside |
||
| 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; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /* | ||
| * 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. */ | ||
|
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: 2024 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,110 @@ | ||
| /* | ||
| * 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.basicimpl; | ||
|
|
||
| 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 { | ||
|
|
||
| // protected abstract class Transformation { | ||
|
gcarpio21 marked this conversation as resolved.
Outdated
|
||
| // protected <TFormulaInfo, TType, TEnv, TFuncDecl, T> Transformation( | ||
| // FormulaCreator<TFormulaInfo, TType, TEnv, TFuncDecl> formulaCreator, T proof) {} | ||
|
|
||
| // protected abstract Proof generateProof(); | ||
| // } | ||
|
|
||
| private final Set<Proof> children = new LinkedHashSet<>(); | ||
|
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. Please try using immutable data-structures as far as possible. |
||
| private ProofRule rule; | ||
| protected Optional<Formula> formula = Optional.empty(); | ||
|
|
||
| protected AbstractProof(ProofRule rule, @Nullable Formula formula) { | ||
| this.rule = rule; | ||
| this.formula = Optional.ofNullable(formula); | ||
| } | ||
|
|
||
| // TODO: Use Optional instead of nullable | ||
|
gcarpio21 marked this conversation as resolved.
Outdated
|
||
| @Override | ||
| public Optional<Formula> getFormula() { | ||
| return this.formula; | ||
| } | ||
|
|
||
| @Override | ||
| public Set<Proof> getChildren() { | ||
| return this.children; | ||
| } | ||
|
|
||
| protected void addChild(Proof child) { | ||
| this.children.add(child); | ||
| } | ||
|
|
||
| @Override | ||
| public ProofRule getRule() { | ||
| return rule; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isLeaf() { | ||
| return getChildren().isEmpty(); | ||
| } | ||
|
|
||
| // void setRule(ProofRule rule) { | ||
| // this.rule = rule; | ||
| // } | ||
|
|
||
| public void setFormula(@Nullable Formula pFormula) { | ||
| formula = Optional.ofNullable(pFormula); | ||
| } | ||
|
|
||
| public void setRule(ProofRule pRule) { | ||
| rule = pRule; | ||
| } | ||
|
|
||
| // use this for debugging | ||
| public String proofAsString() { | ||
| return proofAsString(0); | ||
| } | ||
|
|
||
| protected String proofAsString(int indentLevel) { | ||
| StringBuilder sb = new StringBuilder(); | ||
| String indent = " ".repeat(indentLevel); | ||
|
|
||
| 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(indentLevel + 1)); | ||
| } | ||
| } | ||
|
|
||
| return sb.toString(); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.