2021-10-01 18:21:02 -05:00
|
|
|
/******************************************************************************
|
|
|
|
|
* Top contributors (to current version):
|
2025-01-23 09:54:20 -08:00
|
|
|
* Mudathir Mohamed, Daniel Larraz, Andrew Reynolds
|
2021-10-01 18:21:02 -05: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-10-01 18:21:02 -05: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.
|
|
|
|
|
* ****************************************************************************
|
|
|
|
|
*
|
|
|
|
|
* A simple demonstration of the Sygus API.
|
|
|
|
|
*
|
|
|
|
|
* A simple demonstration of how to use the Sygus API to synthesize a simple
|
2022-03-29 21:11:08 -05:00
|
|
|
* invariant. This is a direct translation of sygus-inv.cpp.
|
2021-10-01 18:21:02 -05:00
|
|
|
*/
|
|
|
|
|
|
2022-03-30 21:09:03 -07:00
|
|
|
import static io.github.cvc5.Kind.*;
|
2021-10-01 18:21:02 -05:00
|
|
|
|
2022-03-30 21:09:03 -07:00
|
|
|
import io.github.cvc5.*;
|
2021-10-01 18:21:02 -05:00
|
|
|
|
|
|
|
|
public class SygusInv
|
|
|
|
|
{
|
|
|
|
|
public static void main(String args[]) throws CVC5ApiException
|
|
|
|
|
{
|
2024-09-26 16:00:25 -05:00
|
|
|
TermManager tm = new TermManager();
|
|
|
|
|
Solver slv = new Solver(tm);
|
2021-10-01 18:21:02 -05:00
|
|
|
{
|
2021-11-03 16:32:10 -05:00
|
|
|
// required options
|
2022-03-24 21:21:44 -05:00
|
|
|
slv.setOption("sygus", "true");
|
2021-11-03 16:32:10 -05:00
|
|
|
slv.setOption("incremental", "false");
|
|
|
|
|
|
|
|
|
|
// set the logic
|
|
|
|
|
slv.setLogic("LIA");
|
|
|
|
|
|
2024-09-26 16:00:25 -05:00
|
|
|
Sort integer = tm.getIntegerSort();
|
|
|
|
|
Sort bool = tm.getBooleanSort();
|
2021-11-03 16:32:10 -05:00
|
|
|
|
2024-09-26 16:00:25 -05:00
|
|
|
Term zero = tm.mkInteger(0);
|
|
|
|
|
Term one = tm.mkInteger(1);
|
|
|
|
|
Term ten = tm.mkInteger(10);
|
2021-11-03 16:32:10 -05:00
|
|
|
|
|
|
|
|
// declare input variables for functions
|
2024-09-26 16:00:25 -05:00
|
|
|
Term x = tm.mkVar(integer, "x");
|
|
|
|
|
Term xp = tm.mkVar(integer, "xp");
|
2021-11-03 16:32:10 -05:00
|
|
|
|
|
|
|
|
// (ite (< x 10) (= xp (+ x 1)) (= xp x))
|
2024-09-26 16:00:25 -05:00
|
|
|
Term ite = tm.mkTerm(ITE,
|
|
|
|
|
tm.mkTerm(LT, x, ten),
|
|
|
|
|
tm.mkTerm(EQUAL, xp, tm.mkTerm(ADD, x, one)),
|
|
|
|
|
tm.mkTerm(EQUAL, xp, x));
|
2021-11-03 16:32:10 -05:00
|
|
|
|
|
|
|
|
// define the pre-conditions, transition relations, and post-conditions
|
2024-09-26 16:00:25 -05:00
|
|
|
Term pre_f = slv.defineFun("pre-f", new Term[] {x}, bool, tm.mkTerm(EQUAL, x, zero));
|
2021-11-03 16:32:10 -05:00
|
|
|
Term trans_f = slv.defineFun("trans-f", new Term[] {x, xp}, bool, ite);
|
2024-09-26 16:00:25 -05:00
|
|
|
Term post_f = slv.defineFun("post-f", new Term[] {x}, bool, tm.mkTerm(LEQ, x, ten));
|
2021-11-03 16:32:10 -05:00
|
|
|
|
|
|
|
|
// declare the invariant-to-synthesize
|
2023-07-14 12:43:25 -05:00
|
|
|
Term inv_f = slv.synthFun("inv-f", new Term[] {x}, bool);
|
2021-11-03 16:32:10 -05:00
|
|
|
|
|
|
|
|
slv.addSygusInvConstraint(inv_f, pre_f, trans_f, post_f);
|
|
|
|
|
|
|
|
|
|
// print solutions if available
|
2022-03-25 15:00:14 -05:00
|
|
|
if (slv.checkSynth().hasSolution())
|
2021-11-03 16:32:10 -05:00
|
|
|
{
|
|
|
|
|
// Output should be equivalent to:
|
|
|
|
|
// (
|
|
|
|
|
// (define-fun inv-f ((x Int)) Bool (not (>= x 11)))
|
|
|
|
|
// )
|
|
|
|
|
Term[] terms = new Term[] {inv_f};
|
|
|
|
|
Utils.printSynthSolutions(terms, slv.getSynthSolutions(terms));
|
|
|
|
|
}
|
2021-10-01 18:21:02 -05:00
|
|
|
}
|
2023-10-02 01:20:26 -05:00
|
|
|
Context.deletePointers();
|
2021-10-01 18:21:02 -05:00
|
|
|
}
|
2021-11-03 16:32:10 -05:00
|
|
|
}
|