use of kodkod.ast.Expression in project org.alloytools.alloy by AlloyTools.
the class BugTests method testGreg_01192006.
public final void testGreg_01192006() {
// circular linked list
Relation Entry = Relation.unary("Entry");
Relation head = Relation.unary("head");
Relation next = Relation.binary("next");
Formula nextFun = next.function(Entry, Entry);
// bijection between indices and entries in linked list
Relation Index = Relation.unary("Index");
Relation index2Entry = Relation.binary("index2Entry");
Expression entries = head.join(next.closure());
Variable e = Variable.unary("e");
Expression preImage = index2Entry.join(e);
Formula index2EntryBij = e.in(entries).implies(preImage.one()).and(e.in(entries).not().implies(preImage.no())).forAll(e.oneOf(Entry));
// try to force list to have three distinct entries
Variable e1 = Variable.unary("e1");
Variable e2 = Variable.unary("e2");
Variable e3 = Variable.unary("e3");
Formula threeEntries = e1.eq(e2).not().and(e1.eq(e3).not()).and(e2.eq(e3).not()).forSome(e1.oneOf(entries).and(e2.oneOf(entries).and(e3.oneOf(entries))));
Formula simulate = head.one().and(nextFun).and(index2EntryBij).and(threeEntries);
Object Entry0 = "Entry0";
Object Entry1 = "Entry1";
Object Entry2 = "Entry2";
Object Entry3 = "Entry3";
Object Index0 = "Index0";
Object Index1 = "Index1";
Object Index2 = "Index2";
Object Index3 = "Index3";
Universe univ = new Universe(Arrays.asList(Entry0, Entry1, Entry2, Entry3, Index0, Index1, Index2, Index3));
TupleFactory factory = univ.factory();
TupleSet entryTuples = factory.setOf(Entry0, Entry1, Entry2, Entry3);
TupleSet indexTuples = factory.setOf(Index0, Index1, Index2, Index3);
Instance instance = new Instance(univ);
instance.add(Entry, entryTuples);
instance.add(head, factory.setOf(Entry0));
instance.add(Index, indexTuples);
Tuple next0 = factory.tuple(Entry0, Entry1);
Tuple next1 = factory.tuple(Entry1, Entry2);
Tuple next2 = factory.tuple(Entry2, Entry3);
Tuple next3 = factory.tuple(Entry3, Entry0);
instance.add(next, factory.setOf(next0, next1, next2, next3));
Tuple i2e0 = factory.tuple(Index0, Entry0);
Tuple i2e1 = factory.tuple(Index1, Entry1);
Tuple i2e2 = factory.tuple(Index2, Entry2);
Tuple i2e3 = factory.tuple(Index3, Entry3);
instance.add(index2Entry, factory.setOf(i2e0, i2e1, i2e2, i2e3));
Evaluator eval = new Evaluator(instance);
assertTrue(eval.evaluate(simulate));
Bounds bounds = new Bounds(univ);
bounds.boundExactly(Entry, entryTuples);
bounds.bound(head, entryTuples);
bounds.bound(next, entryTuples.product(entryTuples));
bounds.bound(Index, indexTuples);
bounds.bound(index2Entry, indexTuples.product(entryTuples));
// Solver solver = new Solver(SATSolverName.Default);
// System.out.println(simulate);
// System.out.println(bounds);
// System.out.println(instance);
instance = solver.solve(simulate, bounds).instance();
// System.out.println(instance);
assertNotNull(instance);
}
use of kodkod.ast.Expression in project org.alloytools.alloy by AlloyTools.
the class BugTests method testFelix_10272008.
public final void testFelix_10272008() {
Relation x0 = Relation.unary("Int/min");
Relation x1 = Relation.unary("Int/zero");
Relation x2 = Relation.unary("Int/max");
Relation x3 = Relation.nary("Int/next", 2);
Relation x4 = Relation.unary("seq/Int");
Relation x5 = Relation.unary("this/X");
List<String> atomlist = Arrays.asList("-1", "-2", "-3", "-4", "-5", "-6", "-7", "-8", "0", "1", "2", "3", "4", "5", "6", "7", "unused0", "unused1", "unused2");
Universe universe = new Universe(atomlist);
TupleFactory factory = universe.factory();
Bounds bounds = new Bounds(universe);
TupleSet x0_upper = factory.noneOf(1);
x0_upper.add(factory.tuple("-8"));
bounds.boundExactly(x0, x0_upper);
TupleSet x1_upper = factory.noneOf(1);
x1_upper.add(factory.tuple("0"));
bounds.boundExactly(x1, x1_upper);
TupleSet x2_upper = factory.noneOf(1);
x2_upper.add(factory.tuple("7"));
bounds.boundExactly(x2, x2_upper);
TupleSet x3_upper = factory.noneOf(2);
x3_upper.add(factory.tuple("-8").product(factory.tuple("-7")));
x3_upper.add(factory.tuple("-7").product(factory.tuple("-6")));
x3_upper.add(factory.tuple("-6").product(factory.tuple("-5")));
x3_upper.add(factory.tuple("-5").product(factory.tuple("-4")));
x3_upper.add(factory.tuple("-4").product(factory.tuple("-3")));
x3_upper.add(factory.tuple("-3").product(factory.tuple("-2")));
x3_upper.add(factory.tuple("-2").product(factory.tuple("-1")));
x3_upper.add(factory.tuple("-1").product(factory.tuple("0")));
x3_upper.add(factory.tuple("0").product(factory.tuple("1")));
x3_upper.add(factory.tuple("1").product(factory.tuple("2")));
x3_upper.add(factory.tuple("2").product(factory.tuple("3")));
x3_upper.add(factory.tuple("3").product(factory.tuple("4")));
x3_upper.add(factory.tuple("4").product(factory.tuple("5")));
x3_upper.add(factory.tuple("5").product(factory.tuple("6")));
x3_upper.add(factory.tuple("6").product(factory.tuple("7")));
bounds.boundExactly(x3, x3_upper);
TupleSet x4_upper = factory.noneOf(1);
x4_upper.add(factory.tuple("0"));
x4_upper.add(factory.tuple("1"));
x4_upper.add(factory.tuple("2"));
x4_upper.add(factory.tuple("3"));
bounds.boundExactly(x4, x4_upper);
TupleSet x5_upper = factory.noneOf(1);
x5_upper.add(factory.tuple("unused0"));
x5_upper.add(factory.tuple("unused1"));
x5_upper.add(factory.tuple("unused2"));
bounds.bound(x5, x5_upper);
bounds.boundExactly(-8, factory.range(factory.tuple("-8"), factory.tuple("-8")));
bounds.boundExactly(-7, factory.range(factory.tuple("-7"), factory.tuple("-7")));
bounds.boundExactly(-6, factory.range(factory.tuple("-6"), factory.tuple("-6")));
bounds.boundExactly(-5, factory.range(factory.tuple("-5"), factory.tuple("-5")));
bounds.boundExactly(-4, factory.range(factory.tuple("-4"), factory.tuple("-4")));
bounds.boundExactly(-3, factory.range(factory.tuple("-3"), factory.tuple("-3")));
bounds.boundExactly(-2, factory.range(factory.tuple("-2"), factory.tuple("-2")));
bounds.boundExactly(-1, factory.range(factory.tuple("-1"), factory.tuple("-1")));
bounds.boundExactly(0, factory.range(factory.tuple("0"), factory.tuple("0")));
bounds.boundExactly(1, factory.range(factory.tuple("1"), factory.tuple("1")));
bounds.boundExactly(2, factory.range(factory.tuple("2"), factory.tuple("2")));
bounds.boundExactly(3, factory.range(factory.tuple("3"), factory.tuple("3")));
bounds.boundExactly(4, factory.range(factory.tuple("4"), factory.tuple("4")));
bounds.boundExactly(5, factory.range(factory.tuple("5"), factory.tuple("5")));
bounds.boundExactly(6, factory.range(factory.tuple("6"), factory.tuple("6")));
bounds.boundExactly(7, factory.range(factory.tuple("7"), factory.tuple("7")));
Variable x11 = Variable.unary("c");
Expression x12 = x5.difference(x5);
Decls x10 = x11.oneOf(x12);
IntExpression x13 = IntConstant.constant(0);
IntExpression x9 = x13.sum(x10);
IntExpression x14 = IntConstant.constant(0);
Formula x8 = x9.eq(x14);
Formula x17 = x0.eq(x0);
Formula x18 = x2.eq(x2);
Formula x16 = x17.and(x18);
Formula x19 = x3.eq(x3);
Formula x15 = x16.and(x19);
Formula x7 = x8.and(x15);
Formula x22 = x1.eq(x1);
Formula x23 = x4.eq(x4);
Formula x21 = x22.and(x23);
Formula x24 = x5.eq(x5);
Formula x20 = x21.and(x24);
Formula x6 = x7.and(x20);
Solver solver = new Solver();
solver.options().setSolver(SATFactory.DefaultSAT4J);
solver.options().setBitwidth(4);
// solver.options().setFlatten(false);
solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT);
solver.options().setSymmetryBreaking(20);
solver.options().setSkolemDepth(0);
Solution sol = solver.solve(x6, bounds);
assertEquals(sol.outcome(), Solution.Outcome.TRIVIALLY_SATISFIABLE);
}
use of kodkod.ast.Expression in project org.alloytools.alloy by AlloyTools.
the class TranslatorTest method testNary.
private final void testNary(ExprOperator op) {
bounds.bound(r1[0], factory.range(factory.tuple(1, 0), factory.tuple(1, 3)));
bounds.bound(r1[1], factory.range(factory.tuple(1, 2), factory.tuple(1, 5)));
bounds.bound(r1[3], factory.range(factory.tuple(1, 3), factory.tuple(1, 6)));
for (int i = 2; i <= 5; i++) {
final Expression[] exprs = new Expression[i];
exprs[0] = r1[0];
Expression binExpr = r1[0];
for (int j = 1; j < i; j++) {
binExpr = binExpr.compose(op, r1[j % 4]);
exprs[j] = r1[j % 4];
}
Expression nExpr = Expression.compose(op, exprs);
final Solution sol = solver.solve(binExpr.eq(nExpr).not(), bounds);
assertNull(sol.instance());
}
}
use of kodkod.ast.Expression in project org.alloytools.alloy by AlloyTools.
the class BugTests method testMana_01132006.
public final void testMana_01132006() {
// r0=[[], [[null], [DblLinkedList0]]],
// null=[[[null]], [[null]]],
// head=[[], [[DblLinkedList0, null], [DblLinkedList0,
// DblLinkedListElem0]]],
// next=[[], [[DblLinkedListElem0, null], [DblLinkedListElem0,
// DblLinkedListElem0]]],
// univ=[[[null], [DblLinkedList0], [1], [DblLinkedListElem0], [0]],
// [[null], [DblLinkedList0], [1], [DblLinkedListElem0], [0]]]
// r1=[[], [[null], [DblLinkedListElem0]]],
final List<String> atoms = new ArrayList<String>(5);
atoms.add("null");
atoms.add("DblLinkedList0");
atoms.add("1");
atoms.add("DblLinkedListElem0");
atoms.add("0");
final Universe u = new Universe(atoms);
final TupleFactory t = u.factory();
// !((head . univ) in ((if (r1 in null) then (head ++ (r0 -> (r1 .
// next))) else head) . univ))
final Relation head = Relation.binary("head"), univ = Relation.unary("univ"), r0 = Relation.unary("r0"), r1 = Relation.unary("r1"), next = Relation.binary("next"), nil = Relation.unary("null"), none = Relation.unary("none");
final Expression override = head.override(r0.product(r1.join(next)));
final Expression ifElse = r1.in(nil).thenElse(override, head);
final Formula f = head.join(univ).in(ifElse.join(univ)).not();
final Bounds b = new Bounds(u);
b.bound(r0, t.setOf("null", "DblLinkedList0"));
b.bound(r1, t.setOf("null", "DblLinkedListElem0"));
b.bound(head, t.setOf("DblLinkedList0").product(b.upperBound(r1)));
b.bound(next, t.setOf(t.tuple("DblLinkedListElem0", "null"), t.tuple("DblLinkedListElem0", "DblLinkedListElem0")));
b.boundExactly(univ, t.allOf(1));
b.boundExactly(nil, t.setOf("null"));
b.boundExactly(none, t.noneOf(1));
// System.out.println(f);
// System.out.println(b);
final Instance instance = solver.solve(f, b).instance();
assertNull(instance);
}
use of kodkod.ast.Expression in project org.alloytools.alloy by AlloyTools.
the class BugTests method testGreg_02192006.
public final void testGreg_02192006() {
Relation r1 = Relation.unary("r1");
Relation r2 = Relation.unary("r2");
Relation r3 = Relation.unary("r3");
Expression e = r1.in(r2).thenElse(r2, r1);
Formula f = e.eq(r2).and(e.in(r3));
Object o1 = "o1";
Object o2 = "o2";
Universe univ = new Universe(Arrays.asList(o1, o2));
TupleFactory factory = univ.factory();
TupleSet set1 = factory.setOf(o1);
TupleSet set2 = factory.setOf(o2);
Bounds bounds = new Bounds(univ);
bounds.bound(r1, set1);
bounds.boundExactly(r2, set2);
bounds.bound(r3, set1);
assertEquals(Solution.Outcome.TRIVIALLY_UNSATISFIABLE, solver.solve(f, bounds).outcome());
}
Aggregations