This is as far as I could go:
public class MySMT extends SMT{
public static void main(String[] args){
MySMT msm = new MySMT();
Script sc;
try {
sc = msm.createScript();
msm.solver = msm.startSolver(msm.smtConfig,
msm.property("org.smtlib.defaultSolver"),
msm.property("org.smtlib.solver_simplify")
);
IResponse resp = sc.execute(msm.solver);
msm.printScript(sc);
} catch (Exception e) {
e.printStackTrace();
}
}
public MySMT(){
super();
this.props = this.readProperties();
}
public String property(String key){
return this.props.getProperty(key);
}
public Script createScript() throws IOException{
List<ISort> argSorts = new LinkedList<ISort>();
SMTExpr.Symbol logicSymbol = new SMTExpr.Symbol("AUFLIA");
C_set_logic logic = new C_set_logic(logicSymbol);
SMTExpr.Symbol sym = new SMTExpr.Symbol("a-boolean-function");
C_declare_fun declar = new C_declare_fun(sym,argSorts, Sort.Bool());
C_assert assertion = new C_assert(sym);
C_check_sat cksat = new C_check_sat();
List<IExpr> args = new LinkedList<IExpr>();
args.add(sym);
args.add(new SMTExpr.Symbol("false"));
C_assert newassertion = new C_assert(
new SMTExpr.FcnExpr(new SMTExpr.Symbol("="),args)
);
C_get_model gmods = new C_get_model();
Script sc = new Script(null,null);
sc.add(logic);
sc.add(declar);
sc.add(assertion);
sc.add(cksat);
//sc.add(newassertion);
sc.add(cksat);
// get-model does not work on Simplify
//sc.add(gmods);
return sc;
}
public void printScript(Script sc) throws Exception{
OutputStreamWriter osw = new OutputStreamWriter(System.out);
Printer pr = new Printer(osw);
sc.accept(pr);
osw.close();
}
public class MyConfig extends SMT.Configuration{
}
}
If your goal is to create programmatically an SMT script and execute it:
See the createScript
function above, and how you can print it to file using the pattern in printScript
. Then you can use it by creating a Process and doing what jSMTLIB is supposed to do.
The problem with using jSMTLIB: if I try to invoke programmatically the command line on a script file the program loops complaining that the parser found an "EOD character". (utf 0019, end of medium). To avoid this you have to put the script between a pair of parentheses. Funny enough the command line from a shell does not suffer from this.
In both cases though the (get-model)
SMT directive is not accepted.
If your goal is to use jSMTLIB to execute commands incrementally
It works partially:
Simplify - works;
Z3 - the latest version does not work for me.
I think it has something to do with the fact that Simplify is interactive, but Z3 is not.
Therefore in the above code you will get an IOException when using Z3, because streams to the Z3 process get closed when jSMTLIB tries to access them.
Make sure to place the property file correctly. Read the (incomplete) tutorial to see where to place the properties file that contain those properties with key, for instance the org.smtlib.defaultSolver
I wrote above.
You can also pass additional arguments to the solver in the property file:
org.smtlib.solver_<name-of-the-solver>.command=<arguments-to-the-solver>
Unfortunately I could not make Z3 work by playing with the arguments either.
Anyway, if you want to use Z3, there is a Java API for it that should offer pretty much the same functionality jSMTLIB should have:
http://research.microsoft.com/en-us/um/people/leonardo/blog/2012/12/10/z3-for-java.html