Search in sources :

Example 6 with Formula

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)));
}
Also used : Formula(kodkod.ast.Formula)

Example 7 with Formula

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);
}
Also used : Formula(kodkod.ast.Formula) Variable(kodkod.ast.Variable) Decls(kodkod.ast.Decls) Test(org.junit.Test)

Example 8 with Formula

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());
}
Also used : Formula(kodkod.ast.Formula) Variable(kodkod.ast.Variable) Instance(kodkod.instance.Instance) Decl(kodkod.ast.Decl)

Example 9 with Formula

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;
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Formula(kodkod.ast.Formula) Solver(kodkod.engine.Solver)

Example 10 with Formula

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();
    }
}
Also used : Formula(kodkod.ast.Formula) Bounds(kodkod.instance.Bounds)

Aggregations

Formula (kodkod.ast.Formula)346 Variable (kodkod.ast.Variable)151 Solution (kodkod.engine.Solution)101 Expression (kodkod.ast.Expression)95 Bounds (kodkod.instance.Bounds)83 QuantifiedFormula (kodkod.ast.QuantifiedFormula)72 Solver (kodkod.engine.Solver)67 BinaryFormula (kodkod.ast.BinaryFormula)50 NaryFormula (kodkod.ast.NaryFormula)49 Relation (kodkod.ast.Relation)45 NotFormula (kodkod.ast.NotFormula)43 ComparisonFormula (kodkod.ast.ComparisonFormula)40 IntExpression (kodkod.ast.IntExpression)40 IntComparisonFormula (kodkod.ast.IntComparisonFormula)39 MultiplicityFormula (kodkod.ast.MultiplicityFormula)39 Universe (kodkod.instance.Universe)37 ArrayList (java.util.ArrayList)35 TupleFactory (kodkod.instance.TupleFactory)35 ConstantFormula (kodkod.ast.ConstantFormula)29 TupleSet (kodkod.instance.TupleSet)29