Search in sources :

Example 26 with Decl

use of kodkod.ast.Decl in project org.alloytools.alloy by AlloyTools.

the class HOLSome4AllTest method testE7.

@Test
public void testE7() {
    // SAT: some s: ints |
    // s > 3 || (all ns: set Node | #ns > s)
    Formula cnd = si.gt(I3);
    QuantifiedFormula allQF = (QuantifiedFormula) ns.count().gt(si).forAll(ns.setOf(Node));
    Decl someDecls = s.oneOf(Expression.INTS);
    {
        Formula f = cnd.or(allQF).forSome(someDecls);
        Solution sol = solve(f);
        assertTrue(sol.sat());
        assertEquals(-1, evalS(sol));
    }
    {
        Formula f = cnd.or(flip(allQF)).forSome(someDecls);
        Solution sol = solve(f);
        assertTrue(sol.sat());
        assertEquals(-1, evalS(sol));
    }
}
Also used : QuantifiedFormula(kodkod.ast.QuantifiedFormula) Formula(kodkod.ast.Formula) Decl(kodkod.ast.Decl) Solution(kodkod.engine.Solution) QuantifiedFormula(kodkod.ast.QuantifiedFormula) Test(org.junit.Test)

Example 27 with Decl

use of kodkod.ast.Decl in project org.alloytools.alloy by AlloyTools.

the class HOLSome4AllTest method testE9i.

@Test
public void testE9i() {
    // SAT: some s: ints |
    // s > 3 || (some ns: set Node | #ns > s + 3)
    Formula cnd = si.gt(I3);
    QuantifiedFormula innerSomeQF = (QuantifiedFormula) ns.count().gt(si.plus(I3)).forSome(ns.setOf(Node));
    Decl someDecls = s.oneOf(Expression.INTS);
    Formula f = cnd.or(innerSomeQF).forSome(someDecls);
    Solution sol = solve(f);
    assertTrue(sol.sat());
    assertEquals(-1, evalS(sol));
}
Also used : QuantifiedFormula(kodkod.ast.QuantifiedFormula) Formula(kodkod.ast.Formula) Decl(kodkod.ast.Decl) Solution(kodkod.engine.Solution) QuantifiedFormula(kodkod.ast.QuantifiedFormula) Test(org.junit.Test)

Example 28 with Decl

use of kodkod.ast.Decl in project org.alloytools.alloy by AlloyTools.

the class HOLSome4AllTest method testE9ii.

@Test
public void testE9ii() {
    // SAT: some s: ints - 1 |
    // s > 2 || (some ns: set Node | #ns > s + 3)
    Formula cnd = si.gt(I2);
    QuantifiedFormula innerSomeQF = (QuantifiedFormula) ns.count().gt(si.plus(I3)).forSome(ns.setOf(Node));
    Decl someDecls = s.oneOf(Expression.INTS.difference(M1.toExpression()));
    Formula f = cnd.or(innerSomeQF).forSome(someDecls);
    Solution sol = solve(f);
    assertTrue(sol.sat());
    assertEquals(3, evalS(sol));
}
Also used : QuantifiedFormula(kodkod.ast.QuantifiedFormula) Formula(kodkod.ast.Formula) Decl(kodkod.ast.Decl) Solution(kodkod.engine.Solution) QuantifiedFormula(kodkod.ast.QuantifiedFormula) Test(org.junit.Test)

Example 29 with Decl

use of kodkod.ast.Decl in project org.alloytools.alloy by AlloyTools.

the class SkolemizationTest method testSkolems.

private final void testSkolems(Multiplicity mult) {
    final Variable va = Variable.unary("va");
    final Variable vb = Variable.unary("vb");
    final Set<String> skolems = new HashSet<String>(4);
    Decl da = va.declare(mult, r1a);
    Decl db = vb.declare(mult, r1b);
    skolems.add("$" + va.name());
    Instance inst = solve(va.in(r1b.join(r2b)).forAll(da).not());
    assertSkolems(bounds, inst, skolems);
    inst = solve((r2b.some().implies(va.in(r1b.join(r2b)).forAll(da))).not());
    assertSkolems(bounds, inst, skolems);
    inst = solve(va.in(r1b.join(r2b)).forSome(da));
    assertSkolems(bounds, inst, skolems);
    inst = solve(va.in(r1b.join(r2b)).forSome(da).and(va.in(r1b).not().forAll(mult == Multiplicity.ONE ? da : va.oneOf(r1a))));
    assertSkolems(bounds, inst, skolems);
    final Expression e0 = va.join(r2a);
    final Formula f0 = e0.some().forSome(va.oneOf(r1a));
    final Formula f1 = e0.no().forAll(va.oneOf(r2a.join(r1b)));
    inst = solve(f0.and(f1));
    assertSkolems(bounds, inst, skolems);
    skolems.add("$" + vb.name());
    inst = solve(va.in(vb.join(r2b)).forSome(da.and(vb.oneOf(va.join(r2a)))));
    assertSkolems(bounds, inst, skolems);
    inst = solve((va.in(vb.join(r2b)).forAll(vb.oneOf(va.join(r2a))).forAll(da)).not());
    assertSkolems(bounds, inst, skolems);
    inst = solve(va.in(vb.join(r2b)).forAll(da.and(db)).not());
    assertSkolems(bounds, inst, skolems);
    inst = solve(va.in(vb.join(r2b)).forSome(da.and(db)));
    assertSkolems(bounds, inst, skolems);
    inst = solve(va.in(r1b.join(r2b)).forSome(da).and(r1b.in(vb).forAll(db).not()));
    assertSkolems(bounds, inst, skolems);
}
Also used : Formula(kodkod.ast.Formula) Variable(kodkod.ast.Variable) Instance(kodkod.instance.Instance) Expression(kodkod.ast.Expression) Decl(kodkod.ast.Decl) HashSet(java.util.HashSet)

Example 30 with Decl

use of kodkod.ast.Decl in project org.alloytools.alloy by AlloyTools.

the class SkolemizationTest method testDeepSkolems.

private final void testDeepSkolems(Multiplicity mult) {
    final Variable va = Variable.unary("va");
    final Variable vb = Variable.unary("vb");
    final Variable vc = Variable.unary("vc");
    final Variable vd = Variable.unary("vd");
    final Set<String> skolems = new HashSet<String>(4);
    Decl da1 = va.oneOf(r1a);
    Decl db = vb.declare(mult, r1b);
    Decl dc = vc.declare(mult, r1a);
    Decl dc1 = vc.oneOf(r1a);
    Decl dd = vd.declare(mult, r1b);
    Decl dd1 = vd.oneOf(r1b);
    skolems.add("$" + vb.name());
    Instance inst = solve(va.in(vb.join(r2b)).forSome(db).forAll(da1));
    assertSkolems(bounds, inst, skolems);
    skolems.add("$" + vc.name());
    inst = solve(va.in(vb.join(r2b).union(vd.join(r2b)).union(vc)).forSome(db).forAll(da1).forSome(dc).forAll(dd1));
    assertSkolems(bounds, inst, skolems);
    inst = solve(va.in(vb.join(r2b).union(vd.join(r2b)).union(vc)).forSome(db).forSome(dc).forAll(da1.and(dd1)));
    assertSkolems(bounds, inst, skolems);
    skolems.add("$" + vd.name());
    inst = solve(va.in(vb.join(r2b).union(vd.join(r2b)).union(vc)).forSome(db).forAll(da1).forSome(dc).not().forAll(dd).not());
    assertSkolems(bounds, inst, skolems);
    inst = solve(va.in(vb.join(r2b).union(vd.join(r2b)).union(vc)).forAll(dc).forAll(db).forSome(da1).not().forAll(dd1));
    skolems.remove("$" + vd.name());
    assertSkolems(bounds, inst, skolems);
    inst = solve(va.in(vb.join(r2b).union(vd.join(r2b)).union(vc)).forSome(db).forAll(dc1).forAll(da1).forAll(dd1));
    skolems.remove("$" + vc.name());
    assertSkolems(bounds, inst, skolems);
}
Also used : Variable(kodkod.ast.Variable) Instance(kodkod.instance.Instance) Decl(kodkod.ast.Decl) HashSet(java.util.HashSet)

Aggregations

Decl (kodkod.ast.Decl)32 Formula (kodkod.ast.Formula)12 Variable (kodkod.ast.Variable)12 QuantifiedFormula (kodkod.ast.QuantifiedFormula)9 Decls (kodkod.ast.Decls)7 Expression (kodkod.ast.Expression)6 IntExpression (kodkod.ast.IntExpression)6 Relation (kodkod.ast.Relation)6 SumExpression (kodkod.ast.SumExpression)5 Solution (kodkod.engine.Solution)5 Test (org.junit.Test)5 BinaryFormula (kodkod.ast.BinaryFormula)4 BooleanFactory (kodkod.engine.bool.BooleanFactory)4 BooleanMatrix (kodkod.engine.bool.BooleanMatrix)4 BooleanValue (kodkod.engine.bool.BooleanValue)4 Instance (kodkod.instance.Instance)4 HashSet (java.util.HashSet)3 ComparisonFormula (kodkod.ast.ComparisonFormula)3 IntComparisonFormula (kodkod.ast.IntComparisonFormula)3 MultiplicityFormula (kodkod.ast.MultiplicityFormula)3