Java Code Examples for kodkod.ast.Expression#join()

The following examples show how to use kodkod.ast.Expression#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: ALG197.java    From kodkod with MIT License 6 votes vote down vote up
/**
 * Parametrization of axioms 14 and 15.
 * @requires e's are unary, op is ternary
 */
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 2
Source File: ALG197.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * 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 3
Source File: ALG197.java    From kodkod with MIT License 6 votes vote down vote up
/**
 * Parametrization of axioms 16-22.
 * @requires e is unary, h is binary
 */
Formula ax16_22(Relation e, Relation h) {
	final Expression expr0 = e.join(op2); // op2(e,...)
	final Expression expr1 = e.join(expr0); // op2(e,e)
	final Expression expr2 = expr1.join(expr1.join(op2)); // op2(op2(e,e),op2(e,e))
	final Expression expr3 = expr2.join(expr0); // op2(e,op2(op2(e,e),op2(e,e)))
	//  h(e10) = op2(e,op2(e,e))
	final Formula f0 = e1[0].join(h).eq(expr1.join(expr0));
	//  h(e11) = op2(op2(e,e),op2(e,e))
	final Formula f1 = e1[1].join(h).eq(expr2);
	//  h(e12) = op2(op2(op2(e,e),op2(e,e)),op2(e,e))
	final Formula f2 = e1[2].join(h).eq(expr1.join(expr2.join(op2)));
	//  h(e13) = op2(e,op2(op2(e,e),op2(e,e)))
	final Formula f3 = e1[3].join(h).eq(expr3);
	//  h(e14) = op2(e,op2(e,op2(op2(e,e),op2(e,e))))
	final Formula f4 = e1[4].join(h).eq(expr3.join(expr0));
	//  h(e15) = op2(e,e)
	final Formula f5 = e1[5].join(h).eq(expr1);
	return Formula.and(f0, f1, f2, f3, f4, f5);
}
 
Example 4
Source File: Nodes.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns an expression that evaluates to the transitive reduction of r.
 * @requires r.arity = 2
 * @return an expression that evaluates to the transitive reduction of r.
 */
public static Expression transitiveReduction(Expression r) { 
	final Variable a = Variable.unary("a");
	final Variable b = Variable.unary("b");
	final Expression dom = r.join(Expression.UNIV);
	final Expression ran = a.join(r);
	final Formula reduct = a.join(r).intersection(r.join(b)).in(a.union(b));//r.difference(a.product(b)).closure().eq(r.closure()).not();
	return reduct.comprehension(a.oneOf(dom).and(b.oneOf(ran)));
}
 
Example 5
Source File: ALG212.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * 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 6
Source File: Dijkstra.java    From org.alloytools.alloy with Apache License 2.0 4 votes vote down vote up
/**
 * 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 7
Source File: Hotel.java    From kodkod with MIT License 4 votes vote down vote up
/** @return e.guest */
Expression guest(Expression e) { return e.join(guest); }
 
Example 8
Source File: RingElection.java    From org.alloytools.alloy with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the step predicate.
 *
 * @return
 *
 *         <pre>
 * pred step (t, t': Time, p: Process) {
 *  let from = p.toSend, to = p.succ.toSend |
 *   some id: from.t {
 *    from.t' = from.t - id
 *    to.t' = to.t + (id - PO/prevs(p.succ)) } }
 *         </pre>
 */
public Formula step(Expression t1, Expression t2, Expression p) {
    final Expression from = p.join(toSend);
    final Expression to = p.join(succ).join(toSend);
    final Variable id = Variable.unary("id");
    final Expression prevs = (p.join(succ)).join((pord.transpose()).closure());
    final Formula f1 = from.join(t2).eq(from.join(t1).difference(id));
    final Formula f2 = to.join(t2).eq(to.join(t1).union(id.difference(prevs)));
    return f1.and(f2).forSome(id.oneOf(from.join(t1)));
}
 
Example 9
Source File: SET967.java    From kodkod with MIT License 2 votes vote down vote up
/**
 * Returns ordered_pair[A][B]
 * @return ordered_pair[A][B]
 */
final Expression ordered_pair(Expression a, Expression b) {
	return b.join(a.join(ordered));
}
 
Example 10
Source File: LAT258.java    From org.alloytools.alloy with Apache License 2.0 2 votes vote down vote up
/**
 * Assumes that e is a ternary relation.
 *
 * @return e.univ~ in e.univ
 */
private final Formula commutative(Expression e) {
    final Expression first2 = e.join(UNIV);
    return first2.transpose().in(first2);
}
 
Example 11
Source File: SET948.java    From org.alloytools.alloy with Apache License 2.0 2 votes vote down vote up
/**
 * Returns set_intersection2[A][B]
 *
 * @return set_intersection2[A][B]
 */
final Expression set_intersection2(Expression a, Expression b) {
    return b.join(a.join(intersect2));
}
 
Example 12
Source File: TOP020.java    From kodkod with MIT License 2 votes vote down vote up
/**
 * Returns coerce_to_class[A].
 * @return coerce_to_class[A]
 */
final Expression coerce_to_class(Expression a) {
	return a.join(coerce);
}
 
Example 13
Source File: SET967.java    From org.alloytools.alloy with Apache License 2.0 2 votes vote down vote up
/**
 * Returns singleton[a]
 *
 * @return singleton[a]
 */
final Expression singleton(Expression a) {
    return a.join(singleton);
}
 
Example 14
Source File: SET967.java    From org.alloytools.alloy with Apache License 2.0 2 votes vote down vote up
/**
 * Returns union[a]
 *
 * @return union[a]
 */
final Expression union(Expression a) {
    return a.join(union);
}
 
Example 15
Source File: Transpose4x4UnaryLR.java    From kodkod with MIT License 2 votes vote down vote up
/**
 * Returns an encoding of sequence lookup using relational join, where
 * seq is a sequence (binary relation from integers to values) and idx is an integer.
 * @return seq[idx]
 */
final Expression get(Expression seq, Expression idx) { 
	return idx.join(seq);								 
}
 
Example 16
Source File: TOP020.java    From kodkod with MIT License 2 votes vote down vote up
/**
 * Returns the_product_top_space_of[A][B].
 * @return the_product_top_space_of[A][B]
 */
final Expression the_product_top_space_of(Expression a, Expression b) {
	return b.join(a.join(tsproduct));
}
 
Example 17
Source File: NUM374.java    From kodkod with MIT License 2 votes vote down vote up
/**
 * Returns op[X][Y].
 * @return op[X][Y]
 */
final Expression apply(Relation op, Expression X, Expression Y) {
	return Y.join(X.join(op));
}
 
Example 18
Source File: SET967.java    From kodkod with MIT License 2 votes vote down vote up
/**
 * Returns singleton[a]
 * @return singleton[a]
 */
final Expression singleton(Expression a) { 
	return a.join(singleton);
}
 
Example 19
Source File: ToyLists.java    From kodkod with MIT License votes vote down vote up
private Expression equivTo(Expression expr) { return expr.join(equivTo); } 
Example 20
Source File: ToyLists.java    From kodkod with MIT License votes vote down vote up
private Expression prefixes(Expression expr) { return expr.join(prefixes); }