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));
}
}
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));
}
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));
}
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);
}
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);
}
Aggregations