Search in sources :

Example 11 with QuantifiedFormula

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

the class HOLTranslator method visit.

@Override
public Proc visit(QuantifiedFormula qf) {
    assertNotSkolemizable(qf);
    Formula qfFlipped = qf.body().quantify(qf.quantifier().opposite, qf.decls(), qf.domain());
    Proc body = toProc(qfFlipped);
    boolean firstOrder = true;
    for (Decl decl : qf.decls()) if (decl.multiplicity() != Multiplicity.ONE) {
        firstOrder = false;
        break;
    }
    if (firstOrder && body instanceof FOL && noNewHOLSkolems(((FOL) body).bounds.skolems(), bounds.skolems()))
        return new Proc.FOL(bounds, qf);
    else
        return new Proc.Some4All(bounds, qf, body);
}
Also used : ConstantFormula(kodkod.ast.ConstantFormula) ComparisonFormula(kodkod.ast.ComparisonFormula) NaryFormula(kodkod.ast.NaryFormula) BinaryFormula(kodkod.ast.BinaryFormula) MultiplicityFormula(kodkod.ast.MultiplicityFormula) QuantifiedFormula(kodkod.ast.QuantifiedFormula) NotFormula(kodkod.ast.NotFormula) Formula(kodkod.ast.Formula) FixFormula(kodkod.ast.FixFormula) IntComparisonFormula(kodkod.ast.IntComparisonFormula) FOL(kodkod.engine.hol.Proc.FOL) Decl(kodkod.ast.Decl) FOL(kodkod.engine.hol.Proc.FOL) Some4All(kodkod.engine.hol.Proc.Some4All)

Example 12 with QuantifiedFormula

use of kodkod.ast.QuantifiedFormula 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 13 with QuantifiedFormula

use of kodkod.ast.QuantifiedFormula 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 14 with QuantifiedFormula

use of kodkod.ast.QuantifiedFormula 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)

Aggregations

QuantifiedFormula (kodkod.ast.QuantifiedFormula)14 Formula (kodkod.ast.Formula)12 Decl (kodkod.ast.Decl)9 BinaryFormula (kodkod.ast.BinaryFormula)7 NaryFormula (kodkod.ast.NaryFormula)7 NotFormula (kodkod.ast.NotFormula)7 ComparisonFormula (kodkod.ast.ComparisonFormula)6 IntComparisonFormula (kodkod.ast.IntComparisonFormula)6 MultiplicityFormula (kodkod.ast.MultiplicityFormula)6 ConstantFormula (kodkod.ast.ConstantFormula)5 Decls (kodkod.ast.Decls)5 Test (org.junit.Test)5 FixFormula (kodkod.ast.FixFormula)4 IntExpression (kodkod.ast.IntExpression)3 Variable (kodkod.ast.Variable)3 Quantifier (kodkod.ast.operator.Quantifier)3 Solution (kodkod.engine.Solution)3 ArrayList (java.util.ArrayList)2 BinaryExpression (kodkod.ast.BinaryExpression)2 ExprToIntCast (kodkod.ast.ExprToIntCast)2