use of kodkod.ast.Formula in project org.alloytools.alloy by AlloyTools.
the class OverflowTheoremTest method test2.
public void test2() {
Formula body = bs.eq(MAXINT).and(as.eq(MAXINT).implies(as.plus(as).eq(bs.plus(bs))));
Formula qf = body.forSome(b.oneOf(Expression.INTS)).forAll(a.oneOf(Expression.INTS));
checkSat(qf.implies(ZERO.eq(ZERO)));
checkSat(qf.implies(ZERO.neq(ZERO)));
checkSat(qf.not().implies(ZERO.eq(ZERO)));
checkUnsat(qf.not().implies(ZERO.neq(ZERO)));
Formula qfnot = body.not().forAll(b.oneOf(Expression.INTS)).forSome(a.oneOf(Expression.INTS));
checkSat(qfnot.implies(ZERO.eq(ZERO)));
checkUnsat(qfnot.implies(ZERO.neq(ZERO)));
}
use of kodkod.ast.Formula in project org.alloytools.alloy by AlloyTools.
the class OverflowTheoremTest method testCardinality3.
/**
* all a, b: set univ | a in b => #a <= #b
*/
@Test
public void testCardinality3() {
Variable a = Variable.unary("a");
Variable b = Variable.unary("b");
Decls dcls = a.setOf(Expression.UNIV).and(b.setOf(Expression.UNIV));
Formula pre = a.in(b);
Formula post = a.count().lte(b.count());
checkTrue(pre, post, dcls);
}
use of kodkod.ast.Formula in project org.alloytools.alloy by AlloyTools.
the class SkolemizationTest method testDeepSkolems.
public final void testDeepSkolems() {
solver.options().setSkolemDepth(3);
testDeepSkolems(Multiplicity.ONE);
testDeepSkolems(Multiplicity.LONE);
testDeepSkolems(Multiplicity.SOME);
testDeepSkolems(Multiplicity.SET);
final Variable va = Variable.unary("va");
final Variable vb = Variable.unary("vb");
Decl da1 = va.oneOf(r1a);
Decl db = vb.oneOf(r1b);
final Formula f0 = va.in(vb.join(r2b));
final Formula f1 = f0.forAll(db).not().forAll(da1);
final Formula f2 = f0.forSome(db).forSome(da1);
Instance inst = solve(f1.and(f2));
assertEquals(bounds.relations().size() + 3, inst.relations().size());
}
use of kodkod.ast.Formula in project org.alloytools.alloy by AlloyTools.
the class UCoreStats method checkMinimal.
/**
* Checks that the given proof of unsatisfiablity for the given problem is
* miminal. This method assumes that the given proof is correct.
*
* @return true if the core is minimal; false otherwise.
*/
static boolean checkMinimal(Set<Formula> core, Bounds bounds) {
System.out.print("checking minimality ... ");
final long start = System.currentTimeMillis();
final Set<Formula> minCore = new LinkedHashSet<Formula>(core);
Solver solver = solver();
solver.options().setSolver(SATFactory.MiniSat);
for (Iterator<Formula> itr = minCore.iterator(); itr.hasNext(); ) {
Formula f = itr.next();
Formula noF = Formula.TRUE;
for (Formula f1 : minCore) {
if (f != f1)
noF = noF.and(f1);
}
if (solver.solve(noF, bounds).instance() == null) {
itr.remove();
}
}
final long end = System.currentTimeMillis();
if (minCore.size() == core.size()) {
System.out.println("minimal (" + (end - start) + " ms).");
return true;
} else {
System.out.println("not minimal (" + (end - start) + " ms). The minimal core has these " + minCore.size() + " formulas:");
for (Formula f : minCore) {
System.out.println(" " + f);
}
return false;
}
}
use of kodkod.ast.Formula in project org.alloytools.alloy by AlloyTools.
the class BenchmarkSymmStats method main.
/**
* Usage: java tests.benchmarks.BenchmarkSymmStats <class name>[(<primitive |
* string | enum>[,<primitive | string | enum>]*)] <method name>[(<primitive |
* string | enum>[,<primitive | string | enum>]*)] [<method name>(<primitive |
* string | enum>[,<primitive | string | enum>]*)]
*/
public static void main(String[] args) {
if (args.length != 2 && args.length != 3)
usage();
try {
final Object instance = construct(args[0].contains("(") ? args[0] : args[0] + "()");
final Formula formula = create(instance, args[1].contains("(") ? args[1] : args[1] + "()");
final Bounds bounds = create(instance, args.length == 3 ? args[2] : "bounds()");
// <class name> <method name>
System.out.print(args[0] + "\t");
System.out.print(args[1].split("\\(")[0] + "\t");
// <PURE|EXT> <gbp (ms)> <gbp (symms)> <gad (ms)> <gad (symms)>
printSymmInfo(formula, bounds);
} catch (NumberFormatException nfe) {
usage();
}
}
Aggregations