Java Code Examples for kodkod.ast.Variable#join()
The following examples show how to use
kodkod.ast.Variable#join() .
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: ALG212.java From kodkod with MIT License | 6 votes |
/** * Returns the dist_long conjecture. * @return dist_long */ public final Formula distLong() { // all u, w, x, y, z: A | f[f[x][y][z]][u][w] = f[f[x][u][w]][f[y][u][w]][f[z][u][w]] final Variable u = Variable.unary("u"); final Variable w = Variable.unary("w"); final Variable x = Variable.unary("x"); final Variable y = Variable.unary("y"); final Variable z = Variable.unary("z"); final Expression e0 = z.join(y.join(x.join(f))); final Expression e1 = w.join(u.join(e0.join(f))); final Expression e2 = w.join(u.join(x.join(f))); final Expression e3 = w.join(u.join(y.join(f))); final Expression e4 = w.join(u.join(z.join(f))); final Expression e5 = e4.join(e3.join(e2.join(f))); return e1.eq(e5). forAll(u.oneOf(UNIV).and(w.oneOf(UNIV)).and(x.oneOf(UNIV)).and(y.oneOf(UNIV)).and(z.oneOf(UNIV))); }
Example 2
Source File: LAT258.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Returns the lower_bound_meet axiom. * * @return the lower_bound_meet axiom. */ public final Formula lowerBoundMeet() { final Variable c = Variable.unary("C"); final Expression e0 = c.join(lessThan); final Formula f0 = meet.join(c).in(e0.product(e0)); // all c: univ | meet.c in c.lessThan->c.lessThan return f0.forAll(c.oneOf(UNIV)); }
Example 3
Source File: GEO115.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Returns the conjecture theorem_3_8_5. * * @return theorem_3_8_5 */ public final Formula theorem385() { // all c: curve, p, q, r: point | // c->p->q->r in between => // incident.c - q in q.(p.(c.between)) + ((c.between).r).q final Variable c = Variable.unary("C"); final Variable p = Variable.unary("P"); final Variable q = Variable.unary("Q"); final Variable r = Variable.unary("R"); final Formula f0 = c.product(p).product(q).product(r).in(between); final Expression e0 = q.join(p.join(c.join(between))); final Expression e1 = c.join(between).join(r).join(q); final Formula f1 = incident.join(c).difference(q).in(e0.union(e1)); return f0.implies(f1).forAll(p.oneOf(point).and(q.oneOf(point)).and(r.oneOf(point)).and(c.oneOf(curve))); }
Example 4
Source File: DNACuts.java From kodkod with MIT License | 5 votes |
/** * Returns the cutLinkUniqueness constraint. * @return the cutLinkUniqueness constraint. */ public Formula cutLinkUniqueness() { final Variable c1 = Variable.unary("c1"); final Variable c2 = Variable.unary("c2"); final Formula f0 = c1.eq(c2).not().and(next.join(c1).in(JoinLink)).and(next.join(c2).in(JoinLink)); Formula f = c1.join(base).in(c2.join(base).union(c2.join(base).join(partner))).not(); for(int i = 0; i < neighbor.length; i++) { Expression c1n = c1.join(neighbor[i]), c2n = c2.join(neighbor[i]); f = f.or(c1n.in(JoinLink)).or(c2n.in(JoinLink)); f = f.or(c1n.join(base).in(c2n.join(base).union(c2n.join(base).join(partner))).not()); } return f0.implies(f).forAll(c1.oneOf(CutLink).and(c2.oneOf(CutLink))); }
Example 5
Source File: DNACuts.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Returns the cutLinkUniqueness constraint. * * @return the cutLinkUniqueness constraint. */ public Formula cutLinkUniqueness() { final Variable c1 = Variable.unary("c1"); final Variable c2 = Variable.unary("c2"); final Formula f0 = c1.eq(c2).not().and(next.join(c1).in(JoinLink)).and(next.join(c2).in(JoinLink)); Formula f = c1.join(base).in(c2.join(base).union(c2.join(base).join(partner))).not(); for (int i = 0; i < neighbor.length; i++) { Expression c1n = c1.join(neighbor[i]), c2n = c2.join(neighbor[i]); f = f.or(c1n.in(JoinLink)).or(c2n.in(JoinLink)); f = f.or(c1n.join(base).in(c2n.join(base).union(c2n.join(base).join(partner))).not()); } return f0.implies(f).forAll(c1.oneOf(CutLink).and(c2.oneOf(CutLink))); }
Example 6
Source File: GEO115.java From kodkod with MIT License | 5 votes |
/** * Returns the conjecture theorem_3_8_5. * @return theorem_3_8_5 */ public final Formula theorem385() { // all c: curve, p, q, r: point | // c->p->q->r in between => // incident.c - q in q.(p.(c.between)) + ((c.between).r).q final Variable c = Variable.unary("C"); final Variable p = Variable.unary("P"); final Variable q = Variable.unary("Q"); final Variable r = Variable.unary("R"); final Formula f0 = c.product(p).product(q).product(r).in(between); final Expression e0 = q.join(p.join(c.join(between))); final Expression e1 = c.join(between).join(r).join(q); final Formula f1 = incident.join(c).difference(q).in(e0.union(e1)); return f0.implies(f1).forAll(p.oneOf(point).and(q.oneOf(point)).and(r.oneOf(point)).and(c.oneOf(curve))); }
Example 7
Source File: Toughnut.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Returns the covering predicate. Note that we don't need to specify the first * two lines of the predicate, since they can be expressed as bounds * constraints. * * @return the covering predicate */ public Formula checkBelowTooDoublePrime() { final Variable x = Variable.unary("x"); final Variable y = Variable.unary("y"); final Decls d = x.oneOf(Cell).and(y.oneOf(Cell)); final Expression xy = y.join(x.join(covered)); // covering relation is symmetric Formula symm = xy.product(x.product(y)).in(covered).forAll(d); // each pair of cells on the board should be covered // by a domino, which also covers ONE of its neighbors Expression xNeighbors = (prev(x).union(next(x))).product(y); Expression yNeighbors = x.product(prev(y).union(next(y))); Formula covering = (xy.one().and(xy.in(xNeighbors.union(yNeighbors)))).forAll(d); return symm.and(covering); }
Example 8
Source File: Toughnut.java From kodkod with MIT License | 5 votes |
/** * Returns the covering predicate. Note that we don't * need to specify the first two lines of the predicate, * since they can be expressed as bounds constraints. * @return the covering predicate */ public Formula checkBelowTooDoublePrime() { final Variable x = Variable.unary("x"); final Variable y = Variable.unary("y"); final Decls d = x.oneOf(Cell).and(y.oneOf(Cell)); final Expression xy = y.join(x.join(covered)); // covering relation is symmetric Formula symm = xy.product(x.product(y)).in(covered).forAll(d); // each pair of cells on the board should be covered // by a domino, which also covers ONE of its neighbors Expression xNeighbors = (prev(x).union(next(x))).product(y); Expression yNeighbors = x.product(prev(y).union(next(y))); Formula covering = (xy.one().and(xy.in(xNeighbors.union(yNeighbors)))).forAll(d); return symm.and(covering); }
Example 9
Source File: ALG212.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Returns the associativity axiom. * * @return associativity */ public final Formula associativity() { // all w, x, y, z: A | f[f[x][w][y]][w][z] = f[x][w][f[y][w][z]] final Variable w = Variable.unary("w"); final Variable x = Variable.unary("x"); final Variable y = Variable.unary("y"); final Variable z = Variable.unary("z"); final Expression e0 = y.join(w.join(x.join(f))); final Expression e1 = z.join(w.join(e0.join(f))); final Expression e2 = z.join(w.join(y.join(f))); final Expression e3 = e2.join(w.join(x.join(f))); return e1.eq(e3).forAll(w.oneOf(UNIV).and(x.oneOf(UNIV)).and(y.oneOf(UNIV)).and(z.oneOf(UNIV))); }
Example 10
Source File: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
private final void doTestAleks_03102013() { Relation r = Relation.unary("R"); Relation s = Relation.binary("f"); Variable v = Variable.unary("e"); Decl decl = v.oneOf(r); Expression shared = v.join(s); Formula expr = (shared.difference(shared)).one().forAll(decl); Formula fin = expr.and(expr.not()); List<Object> atomlist = new LinkedList<Object>(); atomlist.add("R$0"); atomlist.add("R$1"); atomlist.add("R$2"); Universe universe = new Universe(atomlist); TupleFactory factory = universe.factory(); Bounds bounds = new Bounds(universe); bounds.bound(r, factory.allOf(1)); bounds.bound(s, factory.allOf(2)); Solver solver = new Solver(); solver.options().setSolver(SATFactory.DefaultSAT4J); solver.options().setBitwidth(4); solver.options().setSkolemDepth(0); solver.options().setLogTranslation(0); Solution sol = solver.solve(fin, bounds); assertNull(sol.instance()); }
Example 11
Source File: LAT258.java From kodkod with MIT License | 5 votes |
/** * Returns the lower_bound_meet axiom. * @return the lower_bound_meet axiom. */ public final Formula lowerBoundMeet() { final Variable c = Variable.unary("C"); final Expression e0 = c.join(lessThan); final Formula f0 = meet.join(c).in(e0.product(e0)); // all c: univ | meet.c in c.lessThan->c.lessThan return f0.forAll(c.oneOf(UNIV)); }
Example 12
Source File: FileSystem.java From kodkod with MIT License | 4 votes |
/** * Returns all facts in the model. * @return the facts. */ public final Formula facts() { // sig File extends Object {} { some d: Dir | this in d.entries.contents } final Variable file = Variable.unary("this"); final Variable d = Variable.unary("d"); final Formula f0 = file.in(d.join(entries).join(contents)).forSome(d.oneOf(Dir)).forAll(file.oneOf(File)); // sig Dir extends Object { // entries: set DirEntry, // parent: lone Dir // } { // parent = this.~@contents.~@entries // all e1, e2 : entries | e1.name = e2.name => e1 = e2 // this !in this.^@parent // this != Root => Root in this.^@parent // } final Variable dir = Variable.unary("this"); final Variable e1 = Variable.unary("e1"), e2 = Variable.unary("e2"); final Formula f1 = (dir.join(parent)).eq(dir.join(contents.transpose()).join(entries.transpose())); final Expression e0 = dir.join(entries); final Formula f2 = e1.join(name).eq(e2.join(name)).implies(e1.eq(e2)).forAll(e1.oneOf(e0).and(e2.oneOf(e0))); final Formula f3 = dir.in(dir.join(parent.closure())).not(); final Formula f4 = dir.eq(Root).not().implies(Root.in(dir.join(parent.closure()))); final Formula f5 = f1.and(f2).and(f3).and(f4).forAll(dir.oneOf(Dir)); // one sig Root extends Dir {} { no parent } final Formula f6 = Root.join(parent).no(); // sig DirEntry { // name: Name, // contents: Object // } { one this.~entries } final Variable entry = Variable.unary("this"); final Formula f7 = entry.join(entries.transpose()).one().forAll(entry.oneOf(DirEntry)); // fact OneParent { // // all directories besides root xhave one parent // all d: Dir - Root | one d.parent // } final Formula f8 = d.join(parent).one().forAll(d.oneOf(Dir.difference(Root))); return f0.and(f5).and(f6).and(f7).and(f8); }
Example 13
Source File: SkolemizationTest.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
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); }
Example 14
Source File: Dijkstra.java From org.alloytools.alloy with Apache License 2.0 | 3 votes |
/** * Returns the GrabbedInOrder predicate. * * @return * * <pre> * pred GrabbedInOrder ( ) { * all pre: State - so/last() | * let post = so/next(pre) | * let had = Process.(pre.holds), have = Process.(post.holds) | * let grabbed = have - had | * some grabbed => grabbed in mo/nexts(had) * } * </pre> */ public Formula grabbedInOrder() { final Variable pre = Variable.unary("pre"); final Expression post = pre.join(sord); final Expression had = Process.join(pre.join(holds)); final Expression have = Process.join(post.join(holds)); final Expression grabbed = have.difference(had); return grabbed.some().implies(grabbed.in(had.join(mord.closure()))).forAll(pre.oneOf(State.difference(slast))); }
Example 15
Source File: RingElection.java From kodkod with MIT License | 3 votes |
/** * Returns the Traces fact. * @return <pre> * fact Traces { * init (TO/first ()) * all t: Time - TO/last() | let t' = TO/next (t) | * all p: Process | step (t, t', p) or step (t, t', succ.p) or skip (t, t', p) } * </pre> */ public Formula traces() { final Variable t1 = Variable.unary("t"); final Expression t2 = t1.join(tord); final Variable p = Variable.unary("p"); final Formula f = step(t1, t2, p).or(step(t1, t2, succ.join(p))).or(skip(t1, t2, p)); final Formula fAll = f.forAll(p.oneOf(Process)).forAll(t1.oneOf(Time.difference(tlast))); return init(tfirst).and(fAll); }
Example 16
Source File: Dijkstra.java From kodkod with MIT License | 3 votes |
/** * Returns the GrabOrRelease predicate. * @return * <pre> * pred GrabOrRelease () { * Initial(so/first()) && * ( * all pre: State - so/last () | let post = so/next (pre) | * (post.holds = pre.holds && post.waits = pre.waits) * || * (some p: Process, m: Mutex | pre::GrabMutex (p, m, post)) * || * (some p: Process, m: Mutex | pre::ReleaseMutex (p, m, post)) * * ) * } * </pre> */ public Formula grabOrRelease() { final Variable pre = Variable.unary("pre"); final Expression post = pre.join(sord); final Formula f1 = post.join(holds).eq(pre.join(holds)); final Formula f2 = post.join(waits).eq(pre.join(waits)); final Variable p = Variable.unary("p"); final Variable m = Variable.unary("m"); final Decls d = p.oneOf(Process).and(m.oneOf(Mutex)); final Formula f3 = grabMutex(pre, post, p, m).forSome(d); final Formula f4 = releaseMutex(pre, post, p, m).forSome(d); return initial(sfirst).and(((f1.and(f2)).or(f3).or(f4)).forAll(pre.oneOf(State.difference(slast)))); }
Example 17
Source File: RingElection.java From org.alloytools.alloy with Apache License 2.0 | 3 votes |
/** * Returns the progress predicate. * * @return * * <pre> * pred progress () { * all t: Time - TO/last() | let t' = TO/next (t) | * some Process.toSend.t => some p: Process | not skip (t, t', p) } * </pre> */ public Formula progress() { final Variable t1 = Variable.unary("t"); final Expression t2 = t1.join(tord); final Variable p = Variable.unary("p"); final Formula f1 = Process.join(toSend).join(t1).some().implies(skip(t1, t2, p).not().forSome(p.oneOf(Process))); return f1.forAll(t1.oneOf(Time.difference(tlast))); }
Example 18
Source File: RingElection.java From org.alloytools.alloy with Apache License 2.0 | 3 votes |
/** * Returns the Traces fact. * * @return * * <pre> * fact Traces { * init (TO/first ()) * all t: Time - TO/last() | let t' = TO/next (t) | * all p: Process | step (t, t', p) or step (t, t', succ.p) or skip (t, t', p) } * </pre> */ public Formula traces() { final Variable t1 = Variable.unary("t"); final Expression t2 = t1.join(tord); final Variable p = Variable.unary("p"); final Formula f = step(t1, t2, p).or(step(t1, t2, succ.join(p))).or(skip(t1, t2, p)); final Formula fAll = f.forAll(p.oneOf(Process)).forAll(t1.oneOf(Time.difference(tlast))); return init(tfirst).and(fAll); }
Example 19
Source File: Dijkstra.java From kodkod with MIT License | 3 votes |
/** * Returns the GrabbedInOrder predicate. * @return * <pre> * pred GrabbedInOrder ( ) { * all pre: State - so/last() | * let post = so/next(pre) | * let had = Process.(pre.holds), have = Process.(post.holds) | * let grabbed = have - had | * some grabbed => grabbed in mo/nexts(had) * } * </pre> */ public Formula grabbedInOrder() { final Variable pre = Variable.unary("pre"); final Expression post = pre.join(sord); final Expression had = Process.join(pre.join(holds)); final Expression have = Process.join(post.join(holds)); final Expression grabbed = have.difference(had); return grabbed.some().implies(grabbed.in(had.join(mord.closure()))).forAll(pre.oneOf(State.difference(slast))); }
Example 20
Source File: GraphColoring.java From kodkod with MIT License | 3 votes |
/** * Returns a formula stating that all vertices * have one color, and that no two adjacent * vertices have intersecting colors. * @return a formula stating that all vertices * have one color, and that no two adjacent * vertices have intersecting colors. */ public Formula coloring() { final Variable v = Variable.unary("v"); final Expression vcolor = v.join(v2c); final Formula f0 = vcolor.one(); final Formula f1 = vcolor.intersection(v.join(edges).join(v2c)).no(); return f0.and(f1).forAll(v.oneOf(vertex)); }