Java Code Examples for kodkod.ast.Formula#and()
The following examples show how to use
kodkod.ast.Formula#and() .
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: Hotel.java From kodkod with MIT License | 6 votes |
/** * Returns the invariants for Enter and its fields. * @return invariants for Enter and its fields. */ public Formula enterInvariants() { // abstract sig Enter extends RoomCardEvent { } // { // card in guest.holds.pre // } final List<Formula> invs = new ArrayList<Formula>(); invs.add( Enter.in(RoomCardEvent)); invs.add( Enter.eq(NormalEnter.union(RecodeEnter)) ); invs.add( NormalEnter.intersection(RecodeEnter).no() ); final Variable e = Variable.unary("e"); invs.add( card(e).in(guest(e).join(holds).join(pre(e))).forAll(e.oneOf(Enter))); return Formula.and(invs); }
Example 2
Source File: Transpose4x4UnaryLR.java From kodkod with MIT License | 6 votes |
/** * Representation invariants which ensure that every relation * representing a hole is a singleton. * @return an encoding of representation invariants */ final Formula invariants() { final List<Formula> inv = new ArrayList<Formula>(32); for(int i = 0; i < 4; i++) { inv.add(sl[i].one()); inv.add(mx1[i].one()); inv.add(mx2[i].one()); inv.add(tl[i].one()); inv.add(sx1[i].one()); inv.add(sx2[i].one()); for(int j = 0; j < 4; j++) { inv.add(mi[i][j].one()); inv.add(si[i][j].one()); } } return Formula.and( inv ); }
Example 3
Source File: GraphColoring2.java From kodkod with MIT License | 6 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 List<Formula> formulas = new ArrayList<Formula>(vcolors.length); for(Relation r : vcolors) { formulas.add( r.one() ); } for(int i = 0; i < vcolors.length; i++) { final int[] neighbors = graph[i]; final int max = neighbors.length; final Relation vcolor = vcolors[i]; for(int j = 0; j < max; j++) { formulas.add( vcolor.intersection(vcolors[neighbors[j]]).no() ); } } return Formula.and(formulas); }
Example 4
Source File: ALG197.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** * Parametrization of axioms 14 and 15. * * @requires e's are unary, op is ternary */ @Override Formula ax14and15(Relation[] e, Relation op) { final Expression expr0 = e[6].join(op); // op(e6,...) final Expression expr1 = e[6].join(expr0); // op(e6,e6) final Expression expr2 = expr1.join(expr1.join(op)); // op(op(e6,e6),op(e6,e6)) final Expression expr3 = expr2.join(expr0); // op(e6,op(op(e6,e6),op(e6,e6))) // e0 = op(e6,op(e6,e6)) final Formula f0 = e[0].eq(expr1.join(expr0)); // e1 = op(op(e6,e6),op(e6,e6)) final Formula f1 = e[1].eq(expr2); // e2 = op(op(op(e6,e6),op(e6,e6)),op(e6,e6)) final Formula f2 = e[2].eq(expr1.join(expr2.join(op))); // e3 = op(e6,op(op(e6,e6),op(e6,e6))) final Formula f3 = e[3].eq(expr3); // e4 = op(e6,op(e6,op(op(e6,e6),op(e6,e6)))) final Formula f4 = e[4].eq(expr3.join(expr0)); return Formula.and(f0, f1, f2, f3, f4); }
Example 5
Source File: Hotel.java From kodkod with MIT License | 6 votes |
/** * Returns the invariants for the Time and Event signatures and their fields. * @return invariants for the Time and Event signatures and their fields. */ public Formula timeEventInvariants() { final List<Formula> invs = new ArrayList<Formula>(); invs.add(next.totalOrder(Time, first, last)); invs.add(pre.function(Event, Time)); invs.add(post.function(Event, Time)); final Variable t = Variable.unary("t"); final Variable e = Variable.unary("e"); // all t: Time - last | one e: Event | e.pre = t and e.post = t.next final Formula f0 = e.join(pre).eq(t).and(e.join(post).eq(t.join(next))); final Formula f1 = f0.comprehension(e.oneOf(Event)).one(); invs.add( f1.forAll(t.oneOf(Time.difference(last))) ); return Formula.and(invs); }
Example 6
Source File: AbstractWorldDefinitions.java From kodkod with MIT License | 5 votes |
/** * Returns the application of the XiAbPurse predicate. * @return application of the XiAbPurse predicate. */ public Formula XiAbPurse(Expression s, Expression sprime, Expression a) { final Expression aRestrict = a.product(Expression.UNIV); final Formula f0 = aRestrict.intersection(abBalance.join(s)).eq(aRestrict.intersection(abBalance.join(sprime))); final Formula f1 = aRestrict.intersection(abLost.join(s)).eq(aRestrict.intersection(abLost.join(sprime))); return f0.and(f1); }
Example 7
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 8
Source File: ListEncoding.java From kodkod with MIT License | 5 votes |
/** * Returns a formula stating that the given relation is a total function * with the specified domain and range. * @return {f: Formula | f <=> expr in domain->range && all v: domain | one v.expr } * @throws NullPointerException domain = null || range = null * @throws IllegalArgumentException domain.arity != 1 || range.arity != 1 * @throws IllegalArgumentException this.arity != 2 */ public Formula function(Expression expr, Expression domain, Expression range) { if (expr instanceof Relation) return ((Relation)expr).function(domain, range); // special handling for relations that enables better symmetry breaking if (domain.arity() != 1 || range.arity() != 1) throw new IllegalArgumentException("invalid arity: " + domain + " or " + range); // expr in domain->range final Formula domainConstraint = expr.in(domain.product(range)); // all v: domain | one v.expr final Variable v = Variable.unary("v"+expr.hashCode()); final Formula funConstraint = v.join(expr).one().forAll(v.oneOf(domain)); // expr in domain->range && all v: domain | targetMult v.relation return domainConstraint.and(funConstraint); }
Example 9
Source File: AbstractWorldDefinitions.java From kodkod with MIT License | 5 votes |
/** * Returns the application of the Abstract predicate. * @return application of the Abstract predicate. */ public Formula Abstract(Expression s) { final Expression e0 = s.join(abAuthPurse).join(abBalance).join(s).intersection(s.join(abAuthPurse).join(abLost).join(s)); final Formula f0 = e0.no(); final Expression e1 = s.join(abAuthPurse).product(Expression.UNIV); final Expression e2 = e1.intersection((abBalance.union(abLost)).join(s)); final Formula f1 = e2.in(AbPurse.product(Coin)); final Variable c = Variable.unary("c"); final Formula f2 = e2.join(c).lone().forAll(c.oneOf(Coin)); return Formula.and(f0, f1, f2); }
Example 10
Source File: ALG195_1.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Returns the relation constraints. * * @returns the relation constraints. */ public final Formula decls() { Formula f = function(s1, op1).and(function(s2, op2)); for (Relation x : h) { f = f.and(x.function(s1, s2)); } for (int i = 0; i < 7; i++) { f = f.and(h[i].function(s1, s2)); f = f.and(e1[i].one()).and(e2[i].one()); } return f; }
Example 11
Source File: Hotel.java From kodkod with MIT License | 5 votes |
/** * Returns the invariants for Checkin and its fields. * @return invariants for Checkin and its fields. */ public Formula invsForCheckin() { // sig Checkin extends RoomCardEvent { } // { // no room.occ.pre // card.k1 = room.prev.pre // holds.post = holds.pre + guest -> card // prev.post = prev.pre ++ room -> card.k2 // occ.post = occ.pre + room -> guest // // key.unchanged // } final List<Formula> invs = new ArrayList<Formula>(); invs.add(Checkin.in(RoomCardEvent)); final Variable c = Variable.unary("c"); // no room.occ.pre invs.add( room(c).join(occ).join(pre(c)).no().forAll(c.oneOf(Checkin)) ); // card.k1 = room.prev.pre invs.add( card(c).join(k1).eq(room(c).join(prev).join(pre(c))).forAll(c.oneOf(Checkin)) ); // holds.post = holds.pre + guest -> card invs.add( holds.join(post(c)).eq(holds.join(pre(c)).union(guest(c).product(card(c)))).forAll(c.oneOf(Checkin)) ); // prev.post = prev.pre ++ room -> card.k2 invs.add( prev.join(post(c)).eq(prev.join(pre(c)).override(room(c).product(card(c).join(k2)))).forAll(c.oneOf(Checkin)) ); // occ.post = occ.pre + room -> guest invs.add( occ.join(post(c)).eq(occ.join(pre(c)).union(room(c).product(guest(c)))).forAll(c.oneOf(Checkin)) ); invs.add( unchanged(c, key).forAll(c.oneOf(Checkin))); return Formula.and(invs); }
Example 12
Source File: SET948.java From kodkod with MIT License | 5 votes |
/** * Returns the declarations. * @return declarations */ public final Formula decls() { final Formula f0 = union.function(UNIV, UNIV); final Variable a = Variable.unary("A"); final Variable b = Variable.unary("B"); final Formula f1 = set_intersection2(a, b).one(); final Formula f2 = set_union2(a, b).one(); return f0.and(f1.and(f2).forAll(a.oneOf(UNIV).and(b.oneOf(UNIV)))); }
Example 13
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 14
Source File: Proc.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
@Override public Pair<Formula,Bounds> firstOrderProblem() { Formula[] formulas = new Formula[quantProcs.length]; Bounds[] boundss = new Bounds[quantProcs.length]; for (int i = 0; i < quantProcs.length; i++) { Pair<Formula,Bounds> p = quantProcs[i].proc.firstOrderProblem(); formulas[i] = p.a; boundss[i] = p.b; } return new Pair<Formula,Bounds>(Formula.and(formulas), union(boundss)); }
Example 15
Source File: ALG195_1.java From kodkod with MIT License | 5 votes |
/** * Returns axioms 16-22. * @return axioms 16-22. */ public final Formula ax16_22() { Formula f = Formula.TRUE; for(int i = 0; i < 7; i++) { f = f.and(ax16_22(e2[i], h[i])); } return f; }
Example 16
Source File: BugTests.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
public final void testVincent_03182006() { final Relation cAttributes = Relation.binary("cAttributes"), Int = Relation.unary("Integer"), c6001 = Relation.unary("6.001"), one = Relation.unary("ONE"), prereqsetUsed = Relation.binary("prereqsetUsed"), Course = Relation.unary("Course"), CardinalityGrouping = Relation.unary("CardinalityGrouping"), pCourses = Relation.binary("pCourses"), dec = Relation.binary("dec"), c6002 = Relation.unary("6.002"), greater = Relation.binary("greater"), size = Relation.binary("size"), less = Relation.binary("less"), sAttributes = Relation.binary("sAttributes"), PrereqSet = Relation.unary("PrereqSet"), inc = Relation.binary("inc"), next = Relation.binary("next"), equal = Relation.binary("equal"), Semester = Relation.unary("Semester"), index = Relation.ternary("index"), sCourses = Relation.binary("sCourses"), prev = Relation.binary("prev"), prereqs = Relation.binary("prereqs"); // [6.002, 8.02, 6.003, 6.001, Spring 2006, Fall 2006, [8.02], [6.001], // [], Spring, Even, Fall, 1, 2] final List<String> atoms = new ArrayList<String>(14); atoms.add("6.002"); atoms.add("8.02"); atoms.add("6.003"); atoms.add("6.001"); atoms.add("Spring 2006"); atoms.add("Fall 2006"); atoms.add("[8.02]"); atoms.add("[6.001]"); atoms.add("[]"); atoms.add("Spring"); atoms.add("Even"); atoms.add("Fall"); atoms.add("1"); atoms.add("2"); final Universe u = new Universe(atoms); final Bounds b = new Bounds(u); final TupleFactory f = u.factory(); b.bound(cAttributes, f.noneOf(2)); b.boundExactly(Int, f.range(f.tuple("1"), f.tuple("2"))); b.boundExactly(c6001, f.setOf(f.tuple("6.001"))); b.boundExactly(one, f.setOf(f.tuple("1"))); b.bound(prereqsetUsed, f.setOf(f.tuple("6.002", "[8.02]"), f.tuple("8.02", "[]"), f.tuple("6.003", "[6.001]"), f.tuple("6.001", "[]"))); b.bound(Course, f.range(f.tuple("6.002"), f.tuple("6.001"))); b.bound(CardinalityGrouping, f.noneOf(1)); b.boundExactly(pCourses, f.setOf(f.tuple("[8.02]", "8.02"), f.tuple("[6.001]", "6.001"))); b.boundExactly(dec, f.setOf(f.tuple("2", "1"))); b.boundExactly(greater, b.upperBound(dec)); b.bound(size, f.noneOf(2)); b.boundExactly(c6002, f.setOf(f.tuple("6.002"))); b.boundExactly(less, f.setOf(f.tuple("1", "2"))); b.boundExactly(sAttributes, f.setOf(f.tuple("Spring 2006", "Spring"), f.tuple("Spring 2006", "Even"), f.tuple("Fall 2006", "Even"), f.tuple("Fall 2006", "Fall"))); b.boundExactly(PrereqSet, f.setOf("[8.02]", "[6.001]", "[]")); b.boundExactly(inc, b.upperBound(less)); b.boundExactly(next, f.setOf(f.tuple("Spring 2006", "Fall 2006"))); b.boundExactly(equal, f.setOf(f.tuple("1", "1"), f.tuple("2", "2"))); b.boundExactly(Semester, f.setOf("Spring 2006", "Fall 2006")); b.bound(index, f.noneOf(3)); b.bound(sCourses, f.range(f.tuple("Spring 2006"), f.tuple("Fall 2006")).product(f.range(f.tuple("6.002"), f.tuple("6.001")))); b.boundExactly(prev, f.setOf(f.tuple("Fall 2006", "Spring 2006"))); b.boundExactly(prereqs, f.setOf(f.tuple("6.002", "[8.02]"), f.tuple("8.02", "[]"), f.tuple("6.003", "[6.001]"), f.tuple("6.001", "[]"))); // for(Relation r : b.relations()) { // System.out.println(r + " " + r.arity() + " " + b.lowerBound(r) + " ; // " + b.upperBound(r)); // } // System.out.println(u); final Formula f0 = sCourses.in(Semester.product(Course)); final Formula f1 = size.function(CardinalityGrouping, Int); final Formula f2 = prereqsetUsed.function(Semester.join(sCourses), PrereqSet); final Formula f3 = prereqsetUsed.in(prereqs); final Variable s = Variable.unary("s"); final Expression e0 = s.join(sCourses).join(prereqsetUsed).join(pCourses); final Expression e1 = s.join(prev.closure()).join(sCourses); final Formula f4 = e0.in(e1).forAll(s.oneOf(Semester)); final Formula f5 = c6002.in(Semester.join(sCourses)); final Variable e = Variable.unary("e"); final Expression e3 = Semester.join(sCourses).difference(e); final Formula f60 = c6002.in(e3); final Formula f61 = e3.join(prereqsetUsed).join(pCourses).in(e3); final Formula f6 = (f60.and(f61)).not().forAll(e.oneOf(Semester.join(sCourses))); final Variable c = Variable.unary("c"); final Formula f7 = c.join(cAttributes).in(s.join(sAttributes)).forAll(c.oneOf(s.join(sCourses))).forAll(s.oneOf(Semester)); final Variable s1 = Variable.unary("s1"), s2 = Variable.unary("s2"); final Formula f8 = s1.join(sCourses).intersection(s2.join(sCourses)).no().forAll(s2.oneOf(Semester.difference(s1))).forAll(s1.oneOf(Semester)); final Formula f9 = c6001.intersection(Semester.join(sCourses)).no(); final Formula x = f0.and(f1).and(f2).and(f3).and(f4).and(f5).and(f6).and(f7).and(f8); final Formula y = x.and(f9); // System.out.println(x); // System.out.println(y); solver.options().setSolver(SATFactory.DefaultSAT4J); Solution solution = solver.solve(x, b); // System.out.println(solution); // SATISFIABLE assertEquals(solution.outcome(), Solution.Outcome.SATISFIABLE); Solution solution2 = solver.solve(y, b); // System.out.println(solution2); // SATISFIABLE!!!??? // System.out.println((new // Evaluator(solution2.instance())).evaluate(x)); assertEquals(solution2.outcome(), Solution.Outcome.SATISFIABLE); }
Example 17
Source File: Dijkstra.java From org.alloytools.alloy with Apache License 2.0 | 4 votes |
/** * Returns the GrabMutex predicate for states s1, s2, process p and mutex m. * * @return * * <pre> * pred State.ReleaseMutex (p: Process, m: Mutex, s': State) { * !this::IsStalled(p) * m in p.(this.holds) * p.(s'.holds) = p.(this.holds) - m * no p.(s'.waits) * no m.~(this.waits) => { * no m.~(s'.holds) * no m.~(s'.waits) * } else { * some lucky: m.~(this.waits) | { * m.~(s'.waits) = m.~(this.waits) - lucky * m.~(s'.holds) = lucky * } * } * all mu: Mutex - m { * mu.~(s'.waits) = mu.~(this.waits) * mu.~(s'.holds)= mu.~(this.holds) * } * } * </pre> */ public Formula releaseMutex(Expression s1, Expression s2, Expression p, Expression m) { final Formula f1 = isStalled(s1, p).not().and(m.in(p.join(s1.join(holds)))); final Formula f2 = p.join(s2.join(holds)).eq(p.join(s1.join(holds)).difference(m)); final Formula f3 = p.join(s2.join(waits)).no(); final Expression cexpr = m.join((s1.join(waits)).transpose()); final Formula f4 = m.join(s2.join(holds).transpose()).no(); final Formula f5 = m.join(s2.join(waits).transpose()).no(); final Formula f6 = cexpr.no().implies(f4.and(f5)); final Variable lucky = Variable.unary("lucky"); final Formula f7 = m.join(s2.join(waits).transpose()).eq(m.join(s1.join(waits).transpose()).difference(lucky)); final Formula f8 = m.join(s2.join(holds).transpose()).eq(lucky); final Formula f9 = f7.and(f8).forSome(lucky.oneOf(m.join(s1.join(waits).transpose()))); final Formula f10 = cexpr.some().implies(f9); final Variable mu = Variable.unary("mu"); final Formula f11 = mu.join(s2.join(waits).transpose()).eq(mu.join(s1.join(waits).transpose())); final Formula f12 = mu.join(s2.join(holds).transpose()).eq(mu.join(s1.join(holds).transpose())); final Formula f13 = f11.and(f12).forAll(mu.oneOf(Mutex.difference(m))); return Formula.and(f1, f2, f3, f6, f10, f13); }
Example 18
Source File: JenaTranslator.java From quetzal with Eclipse Public License 2.0 | 4 votes |
@Override public void visit(OpTable arg0) { Set<Variable> vars = HashSetFactory.make(); Formula f = null; for(Iterator<Binding> bs = arg0.getTable().rows(); bs.hasNext(); ) { Formula rf = null; Binding b = bs.next(); for(Var jv : arg0.getTable().getVars()) { if (b.get(jv) != null) { Expression value = toTerm(b.get(jv)); Variable var = context.getVars().get(jv.getName()); vars.add(var); Formula ef = var.eq(value); rf = rf==null? ef: rf.and(ef); } } f = f==null? rf: f.or(rf); } context.setCurrentQuery(f==null? Formula.TRUE: f); if (context.getStaticBinding() != null) { context.getStaticBinding().addAll(vars); } else { context.setStaticBinding(vars); } Expression bound = null; for(Variable v : vars) { bound = bound==null? varExpr(v): bound.union(varExpr(v)); } if (bound != null) { if (context.getDynamicBinding() != null) { context.setDynamicBinding(context.getDynamicBinding().union(bound)); } else { context.setDynamicBinding(bound); } } context.getCurrentContinuation().next(context, context.getCurrentQuery()); }
Example 19
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 20
Source File: MED001.java From org.alloytools.alloy with Apache License 2.0 | 2 votes |
/** * Returns the conjunction of all axioms. * * @return conjunction of all axioms. */ public final Formula axioms() { return Formula.and(trans_ax2(), trans_ax3(), transitivity_gt(), decls(), irreflexivity_gt(), normo(), xorcapacity1_4(), xorcondition1_4(), insulin_effect(), liver_glucose(), sulfonylurea_effect(), biguanide_effect(), bg_completion(), sn_cure_1(), sn_cure_2(), ne_cure(), ex_cure(), su_completion(), xorstep1_7(), step1_4(), comp(), insulin_completion(), uptake_completion(), trans_ax1()); }