Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ff: connect sub-theories to main solver & test (#9218)
Organizing the PR a bit: we hook up the subtheories to TheoryFf we expose FF-related things via the C++/Pytohn API and SMT-LIB2 interface. we add a bunch of tests against these interfaces.
- Loading branch information
1 parent
374c6f2
commit 368f3c3
Showing
91 changed files
with
2,360 additions
and
396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/****************************************************************************** | ||
* Top contributors (to current version): | ||
* Alex Ozdemir | ||
* | ||
* This file is part of the cvc5 project. | ||
* | ||
* Copyright (c) 2009-2022 by the authors listed in the file AUTHORS | ||
* in the top-level source directory and their institutional affiliations. | ||
* All rights reserved. See the file COPYING in the top-level source | ||
* directory for licensing information. | ||
* **************************************************************************** | ||
* | ||
* An example of solving finite field problems with cvc5's cpp API | ||
*/ | ||
|
||
#include <cvc5/cvc5.h> | ||
|
||
#include <cassert> | ||
#include <iostream> | ||
|
||
using namespace std; | ||
using namespace cvc5; | ||
|
||
int main() | ||
{ | ||
Solver solver; | ||
solver.setOption("produce-models", "true"); | ||
|
||
Sort f5 = solver.mkFiniteFieldSort("5"); | ||
Term a = solver.mkConst(f5, "a"); | ||
Term b = solver.mkConst(f5, "b"); | ||
Term z = solver.mkFiniteFieldElem("0", f5); | ||
|
||
Term inv = | ||
solver.mkTerm(EQUAL, | ||
{solver.mkTerm(FINITE_FIELD_ADD, | ||
{solver.mkTerm(FINITE_FIELD_MULT, {a, b}), | ||
solver.mkFiniteFieldElem("-1", f5)}), | ||
z}); | ||
Term aIsTwo = solver.mkTerm( | ||
EQUAL, | ||
{solver.mkTerm(FINITE_FIELD_ADD, {a, solver.mkFiniteFieldElem("-2", f5)}), | ||
z}); | ||
// ab - 1 = 0 | ||
solver.assertFormula(inv); | ||
// a = 2 | ||
solver.assertFormula(aIsTwo); | ||
|
||
// should be SAT, with b = 2^(-1) | ||
Result r = solver.checkSat(); | ||
assert(r.isSat()); | ||
|
||
cout << "a = " << solver.getValue(a) << endl; | ||
cout << "b = " << solver.getValue(b) << endl; | ||
|
||
// b = 2 | ||
Term bIsTwo = solver.mkTerm( | ||
EQUAL, | ||
{solver.mkTerm(FINITE_FIELD_ADD, {b, solver.mkFiniteFieldElem("-2", f5)}), | ||
z}); | ||
|
||
// should be UNSAT, 2*2 - 1 != 0 | ||
solver.assertFormula(bIsTwo); | ||
|
||
r = solver.checkSat(); | ||
assert(!r.isSat()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/****************************************************************************** | ||
* Top contributors (to current version): | ||
* Alex Ozdemir, Mudathir Mohamed, Liana Hadarean, Morgan Deters | ||
* | ||
* This file is part of the cvc5 project. | ||
* | ||
* Copyright (c) 2009-2022 by the authors listed in the file AUTHORS | ||
* in the top-level source directory and their institutional affiliations. | ||
* All rights reserved. See the file COPYING in the top-level source | ||
* directory for licensing information. | ||
* **************************************************************************** | ||
* | ||
* An example of solving finite field problems with cvc5's Java API | ||
* | ||
*/ | ||
|
||
import io.github.cvc5.*; | ||
import java.util.*; | ||
|
||
public class FiniteField | ||
{ | ||
public static void main(String args[]) throws CVC5ApiException | ||
{ | ||
Solver slv = new Solver(); | ||
{ | ||
slv.setLogic("QF_FF"); // Set the logic | ||
|
||
Sort f5 = slv.mkFiniteFieldSort("5"); | ||
Term a = slv.mkConst(f5, "a"); | ||
Term b = slv.mkConst(f5, "b"); | ||
Term z = slv.mkFiniteFieldElem("0", f5); | ||
|
||
System.out.println("is ff: " + f5.isFiniteField()); | ||
System.out.println("ff size: " + f5.getFiniteFieldSize()); | ||
System.out.println("is ff value: " + z.isFiniteFieldValue()); | ||
System.out.println("ff value: " + z.getFiniteFieldValue()); | ||
|
||
Term inv = | ||
slv.mkTerm(Kind.EQUAL, | ||
slv.mkTerm(Kind.FINITE_FIELD_ADD, | ||
slv.mkTerm(Kind.FINITE_FIELD_MULT, a, b), | ||
slv.mkFiniteFieldElem("-1", f5)), | ||
z); | ||
|
||
Term aIsTwo = | ||
slv.mkTerm(Kind.EQUAL, | ||
slv.mkTerm(Kind.FINITE_FIELD_ADD, | ||
a, | ||
slv.mkFiniteFieldElem("-2", f5)), | ||
z); | ||
|
||
slv.assertFormula(inv); | ||
slv.assertFormula(aIsTwo); | ||
|
||
Result r = slv.checkSat(); | ||
System.out.println("is sat: " + r.isSat()); | ||
|
||
Term bIsTwo = | ||
slv.mkTerm(Kind.EQUAL, | ||
slv.mkTerm(Kind.FINITE_FIELD_ADD, | ||
b, | ||
slv.mkFiniteFieldElem("-2", f5)), | ||
z); | ||
|
||
slv.assertFormula(bIsTwo); | ||
r = slv.checkSat(); | ||
System.out.println("is sat: " + r.isSat()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
############################################################################### | ||
# Top contributors (to current version): | ||
# Andrew Reynolds, Alex Ozdemir | ||
# | ||
# This file is part of the cvc5 project. | ||
# | ||
# Copyright (c) 2009-2022 by the authors listed in the file AUTHORS | ||
# in the top-level source directory and their institutional affiliations. | ||
# All rights reserved. See the file COPYING in the top-level source | ||
# directory for licensing information. | ||
# ############################################################################# | ||
# | ||
# A simple test for cvc5's finite field solver. | ||
# | ||
## | ||
|
||
import cvc5 | ||
from cvc5 import Kind | ||
|
||
if __name__ == "__main__": | ||
slv = cvc5.Solver() | ||
slv.setOption("produce-models", "true") | ||
F = slv.mkFiniteFieldSort("5") | ||
a = slv.mkConst(F, "a") | ||
b = slv.mkConst(F, "b") | ||
|
||
inv = slv.mkTerm( | ||
Kind.EQUAL, | ||
slv.mkTerm(Kind.FINITE_FIELD_MULT, a, b), | ||
slv.mkFiniteFieldElem("1", F), | ||
) | ||
aIsTwo = slv.mkTerm( | ||
Kind.EQUAL, | ||
a, | ||
slv.mkFiniteFieldElem("2", F), | ||
) | ||
# ab - 1 = 0 | ||
slv.assertFormula(inv) | ||
# a = 2 | ||
slv.assertFormula(aIsTwo) | ||
r = slv.checkSat() | ||
|
||
# should be SAT, with b = 2^(-1) | ||
assert r.isSat() | ||
print(slv.getValue(a).toPythonObj()) | ||
assert slv.getValue(b).toPythonObj() == -2 | ||
|
||
bIsTwo = slv.mkTerm( | ||
Kind.EQUAL, | ||
b, | ||
slv.mkFiniteFieldElem("2", F), | ||
) | ||
|
||
# b = 2 | ||
slv.assertFormula(bIsTwo) | ||
r = slv.checkSat() | ||
|
||
# should be UNSAT, since 2*2 - 1 != 0 | ||
assert not r.isSat() |
Oops, something went wrong.