Java Code Examples for kodkod.ast.Variable#in()
The following examples show how to use
kodkod.ast.Variable#in() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SkolemizationTest.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
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()); }
Example 2
Source File: SkolemizationTest.java From kodkod with MIT License | 6 votes |
@Test 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()); }
Example 3
Source File: Lists.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Returns all facts in the model. * * @return the facts. */ public final Formula facts() { // fact NoStrayThings {Thing in List.car} final Formula f0 = Thing.in(List.join(car)); // fact finite {all L: List | isFinite(L)} final Variable L = Variable.unary("L"); final Formula f1 = isFinite(L).forAll(L.oneOf(List)); // fact Equivalence { // all a,b: List | (a in b.equivTo) <=> (a.car = b.car and b.cdr in // a.cdr.equivTo) // } final Variable a = Variable.unary("a"); final Variable b = Variable.unary("b"); final Formula f2 = a.in(b.join(equivTo)); final Formula f3 = a.join(car).eq(b.join(car)); final Formula f4 = b.join(cdr).in(a.join(cdr).join(equivTo)); final Formula f6 = f2.iff(f3.and(f4)).forAll(a.oneOf(List).and(b.oneOf(List))); // fact prefix { //a is a prefix of b // List->EmptyList in prefixes // all a,b: NonEmptyList | (a in b.prefixes) <=> (a.car = b.car // and a.cdr in b.cdr.prefixes) // } final Formula f7 = List.product(EmptyList).in(prefixes); final Formula f8 = a.in(b.join(prefixes)); final Formula f9 = a.join(cdr).in(b.join(cdr).join(prefixes)); final Formula f11 = f8.iff(f3.and(f9)).forAll(a.oneOf(NonEmptyList).and(b.oneOf(NonEmptyList))); return f0.and(f1).and(f6).and(f7).and(f11); }
Example 4
Source File: OverflowTheoremTest.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * 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); }
Example 5
Source File: RingElection.java From kodkod with MIT License | 5 votes |
/** * Return DefineElected fact. * @return <pre> * fact DefineElected { * no elected.TO/first() * all t: Time - TO/first()| * elected.t = {p: Process | p in p.toSend.t - p.toSend.(TO/prev(t))} } * </pre> */ public Formula defineElected() { final Variable t = Variable.unary("t"); final Formula f1 = elected.join(tfirst).no(); final Variable p = Variable.unary("p"); final Formula c = p.in(p.join(toSend).join(t).difference(p.join(toSend).join(t.join(tord.transpose())))); final Expression comprehension = c.comprehension(p.oneOf(Process)); final Formula f2 = elected.join(t).eq(comprehension).forAll(t.oneOf(Time.difference(tfirst))); return f1.and(f2); }
Example 6
Source File: Lists.java From kodkod with MIT License | 5 votes |
/** * Returns all facts in the model. * @return the facts. */ public final Formula facts() { // fact NoStrayThings {Thing in List.car} final Formula f0 = Thing.in(List.join(car)); // fact finite {all L: List | isFinite(L)} final Variable L = Variable.unary("L"); final Formula f1 = isFinite(L).forAll(L.oneOf(List)); // fact Equivalence { // all a,b: List | (a in b.equivTo) <=> (a.car = b.car and b.cdr in a.cdr.equivTo) // } final Variable a = Variable.unary("a"); final Variable b = Variable.unary("b"); final Formula f2 = a.in(b.join(equivTo)); final Formula f3 = a.join(car).eq(b.join(car)); final Formula f4 = b.join(cdr).in(a.join(cdr).join(equivTo)); final Formula f6 = f2.iff(f3.and(f4)).forAll(a.oneOf(List).and(b.oneOf(List))); // fact prefix { //a is a prefix of b // List->EmptyList in prefixes // all a,b: NonEmptyList | (a in b.prefixes) <=> (a.car = b.car // and a.cdr in b.cdr.prefixes) // } final Formula f7 = List.product(EmptyList).in(prefixes); final Formula f8 = a.in(b.join(prefixes)); final Formula f9 = a.join(cdr).in(b.join(cdr).join(prefixes)); final Formula f11 = f8.iff(f3.and(f9)).forAll(a.oneOf(NonEmptyList).and(b.oneOf(NonEmptyList))); return f0.and(f1).and(f6).and(f7).and(f11); }
Example 7
Source File: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
public final void testFelix_06192008() { Relation x5 = Relation.unary("R"); List<String> atomlist = Arrays.asList("X"); Universe universe = new Universe(atomlist); TupleFactory factory = universe.factory(); Bounds bounds = new Bounds(universe); TupleSet x5_upper = factory.noneOf(1); x5_upper.add(factory.tuple("X")); bounds.bound(x5, x5_upper); Variable x10 = Variable.unary("a"); Expression x11 = x5.difference(x5); Decls x9 = x10.oneOf(x11); Variable x14 = Variable.nary("b", 2); Expression x15 = x5.product(x5); Decls x13 = x14.setOf(x15); Expression x19 = x5.product(x5); Formula x17 = x14.in(x19); Expression x22 = x10.product(x10); Formula x21 = x22.eq(x14); Formula x16 = x17.and(x21); Formula x12 = x16.forSome(x13); Formula x7 = x12.forAll(x9); // System.out.println(x7); 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); // System.out.println("Depth=0..."); System.out.flush(); solver.options().setSkolemDepth(0); assertEquals(Solution.Outcome.TRIVIALLY_SATISFIABLE, solver.solve(x7, bounds).outcome()); // System.out.println("Depth=1..."); System.out.flush(); solver.options().setSkolemDepth(1); final Solution sol = solver.solve(x7, bounds); assertEquals(Solution.Outcome.SATISFIABLE, sol.outcome()); assertEquals(2, sol.instance().relations().size()); for (Relation r : sol.instance().relations()) { assertTrue(sol.instance().tuples(r).isEmpty()); } }
Example 8
Source File: RegressionTests.java From kodkod with MIT License | 4 votes |
@Test public final void testFelix_06192008() { Relation x5 = Relation.unary("R"); List<String> atomlist = Arrays.asList("X"); Universe universe = new Universe(atomlist); TupleFactory factory = universe.factory(); Bounds bounds = new Bounds(universe); TupleSet x5_upper = factory.noneOf(1); x5_upper.add(factory.tuple("X")); bounds.bound(x5, x5_upper); Variable x10=Variable.unary("a"); Expression x11=x5.difference(x5); Decls x9=x10.oneOf(x11); Variable x14=Variable.nary("b",2); Expression x15=x5.product(x5); Decls x13=x14.setOf(x15); Expression x19=x5.product(x5); Formula x17=x14.in(x19); Expression x22=x10.product(x10); Formula x21=x22.eq(x14); Formula x16=x17.and(x21); Formula x12=x16.forSome(x13); Formula x7= x12.forAll(x9); // System.out.println(x7); Solver solver = new Solver(); solver.options().setSolver(SATFactory.DefaultSAT4J); solver.options().setBitwidth(4); solver.options().setIntEncoding(Options.IntEncoding.TWOSCOMPLEMENT); solver.options().setSymmetryBreaking(20); // System.out.println("Depth=0..."); System.out.flush(); solver.options().setSkolemDepth(0); assertEquals(Solution.Outcome.TRIVIALLY_SATISFIABLE, solver.solve(x7, bounds).outcome()); // System.out.println("Depth=1..."); System.out.flush(); solver.options().setSkolemDepth(1); final Solution sol = solver.solve(x7, bounds); assertEquals(Solution.Outcome.SATISFIABLE, sol.outcome()); assertEquals(2, sol.instance().relations().size()); for(Relation r : sol.instance().relations()) { assertTrue(sol.instance().tuples(r).isEmpty()); } }
Example 9
Source File: Trees.java From org.alloytools.alloy with Apache License 2.0 | 3 votes |
/** * Returns the inCycle predicate. * * @return * * <pre> * pred InCycle(v: V, c: V -> V) { * v in v.c or * some v': v.c | v' in v.^(c - v->v' - v'->v) * } * </pre> */ public final Formula inCycle(Expression/* V */ v, Expression/* V->V */ c) { final Formula f0 = v.in(v.join(c)); final Variable vp = Variable.unary("v'"); final Formula f1 = vp.in(v.join((c.difference(v.product(vp)).difference(vp.product(v))).closure())); return f0.or(f1.forSome(vp.oneOf(v.join(c)))); }
Example 10
Source File: RingElection.java From org.alloytools.alloy with Apache License 2.0 | 3 votes |
/** * Return DefineElected fact. * * @return * * <pre> * fact DefineElected { * no elected.TO/first() * all t: Time - TO/first()| * elected.t = {p: Process | p in p.toSend.t - p.toSend.(TO/prev(t))} } * </pre> */ public Formula defineElected() { final Variable t = Variable.unary("t"); final Formula f1 = elected.join(tfirst).no(); final Variable p = Variable.unary("p"); final Formula c = p.in(p.join(toSend).join(t).difference(p.join(toSend).join(t.join(tord.transpose())))); final Expression comprehension = c.comprehension(p.oneOf(Process)); final Formula f2 = elected.join(t).eq(comprehension).forAll(t.oneOf(Time.difference(tfirst))); return f1.and(f2); }
Example 11
Source File: Trees.java From kodkod with MIT License | 3 votes |
/** * Returns the inCycle predicate. * @return * <pre> * pred InCycle(v: V, c: V -> V) { * v in v.c or * some v': v.c | v' in v.^(c - v->v' - v'->v) * } * </pre> */ public final Formula inCycle(Expression/*V*/ v, Expression/*V->V*/ c) { final Formula f0 = v.in(v.join(c)); final Variable vp = Variable.unary("v'"); final Formula f1 = vp.in(v.join((c.difference(v.product(vp)).difference(vp.product(v))).closure())); return f0.or(f1.forSome(vp.oneOf(v.join(c)))); }