2021-04-12 12:31:43 -07:00
|
|
|
/******************************************************************************
|
|
|
|
|
* Top contributors (to current version):
|
2025-01-23 09:54:20 -08:00
|
|
|
* Mudathir Mohamed, Andres Noetzli, Daniel Larraz
|
2021-04-12 12:31:43 -07:00
|
|
|
*
|
|
|
|
|
* This file is part of the cvc5 project.
|
|
|
|
|
*
|
2025-01-23 09:54:20 -08:00
|
|
|
* Copyright (c) 2009-2025 by the authors listed in the file AUTHORS
|
2021-04-12 12:31:43 -07:00
|
|
|
* 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.
|
|
|
|
|
* ****************************************************************************
|
|
|
|
|
*
|
2021-11-16 12:13:19 -06:00
|
|
|
* An example of interacting with unsat cores using cvc5's Java API.
|
2021-04-12 12:31:43 -07:00
|
|
|
*/
|
2019-05-16 00:18:48 +00:00
|
|
|
|
2022-03-30 21:09:03 -07:00
|
|
|
import io.github.cvc5.*;
|
2021-10-01 18:21:02 -05:00
|
|
|
import java.util.Arrays;
|
2019-05-16 00:18:48 +00:00
|
|
|
|
2021-10-01 18:21:02 -05:00
|
|
|
public class UnsatCores
|
|
|
|
|
{
|
|
|
|
|
public static void main(String[] args) throws CVC5ApiException
|
|
|
|
|
{
|
2024-09-26 16:00:25 -05:00
|
|
|
TermManager tm = new TermManager();
|
|
|
|
|
Solver solver = new Solver(tm);
|
2021-10-01 18:21:02 -05:00
|
|
|
{
|
2021-11-03 16:32:10 -05:00
|
|
|
// Enable the production of unsat cores
|
|
|
|
|
solver.setOption("produce-unsat-cores", "true");
|
|
|
|
|
|
2024-09-26 16:00:25 -05:00
|
|
|
Sort boolSort = tm.getBooleanSort();
|
|
|
|
|
Term a = tm.mkConst(boolSort, "A");
|
|
|
|
|
Term b = tm.mkConst(boolSort, "B");
|
2021-11-03 16:32:10 -05:00
|
|
|
|
|
|
|
|
// A ^ B
|
2024-09-26 16:00:25 -05:00
|
|
|
solver.assertFormula(tm.mkTerm(Kind.AND, a, b));
|
2021-11-03 16:32:10 -05:00
|
|
|
// ~(A v B)
|
2024-09-26 16:00:25 -05:00
|
|
|
solver.assertFormula(tm.mkTerm(Kind.NOT, tm.mkTerm(Kind.OR, a, b)));
|
2021-11-03 16:32:10 -05:00
|
|
|
|
|
|
|
|
Result res = solver.checkSat(); // result is unsat
|
|
|
|
|
|
|
|
|
|
// Retrieve the unsat core
|
|
|
|
|
Term[] unsatCore = solver.getUnsatCore();
|
|
|
|
|
|
|
|
|
|
// Print the unsat core
|
|
|
|
|
System.out.println("Unsat Core: " + Arrays.asList(unsatCore));
|
|
|
|
|
|
|
|
|
|
// Iterate over expressions in the unsat core.
|
|
|
|
|
System.out.println("--- Unsat Core ---");
|
|
|
|
|
for (Term e : unsatCore)
|
|
|
|
|
{
|
|
|
|
|
System.out.println(e);
|
|
|
|
|
}
|
2019-05-16 00:18:48 +00:00
|
|
|
}
|
2023-10-02 01:20:26 -05:00
|
|
|
Context.deletePointers();
|
2019-05-16 00:18:48 +00:00
|
|
|
}
|
|
|
|
|
}
|