@Before public void loadZ3() throws Exception { NativeLibraries.loadLibrary("z3j"); Configuration config = Configuration.defaultConfiguration(); LogManager logger = TestLogManager.getInstance(); mgr = Z3FormulaManager.create(logger, config, ShutdownNotifier.create(), null, 42); ifmgr = (Z3IntegerFormulaManager) mgr.getIntegerFormulaManager(); }
@Test public void testInterpolation() throws Exception { try (Z3InterpolatingProver prover = mgr.newProverEnvironmentWithInterpolation(false)) { IntegerFormula x, y, z; x = ifmgr.makeVariable("x"); y = ifmgr.makeVariable("y"); z = ifmgr.makeVariable("z"); BooleanFormula f1 = ifmgr.equal(y, ifmgr.multiply(ifmgr.makeNumber(2), x)); BooleanFormula f2 = ifmgr.equal(y, ifmgr.add(ifmgr.makeNumber(1), ifmgr.multiply(z, ifmgr.makeNumber(2)))); prover.push(f1); long id2 = prover.push(f2); boolean check = prover.isUnsat(); assert check : "formulas must be contradicting"; prover.getInterpolant(Collections.singletonList(id2)); // we actually only check for a successful execution here, the result is irrelevant. } }