Java Code Examples for kodkod.ast.Formula#comprehension()

The following examples show how to use kodkod.ast.Formula#comprehension() . 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: Skolemizer.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * @see kodkod.ast.visitor.AbstractReplacer#visit(kodkod.ast.Comprehension)
 */
@Override
public final Expression visit(Comprehension expr) {
    Expression ret = lookup(expr);
    if (ret != null)
        return ret;
    final Environment<Expression,Expression> oldRepEnv = repEnv; // skolemDepth
                                                                // < 0
                                                                // at
                                                                // this
                                                                // point
    final Decls decls = visit(expr.decls());
    final Formula formula = expr.formula().accept(this);
    ret = (decls == expr.decls() && formula == expr.formula()) ? expr : formula.comprehension(decls);
    repEnv = oldRepEnv;
    return cache(expr, ret);
}
 
Example 2
Source File: AbstractReplacer.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Calls lookup(comprehension) and returns the cached value, if any. If a
 * replacement has not been cached, visits the expression's children. If nothing
 * changes, the argument is cached and returned, otherwise a replacement
 * expression is cached and returned.
 *
 * @return { c: Comprehension | c.declarations =
 *         comprehension.declarations.accept(delegate) && c.formula =
 *         comprehension.formula.accept(delegate) }
 */
@Override
public Expression visit(Comprehension comprehension) {
    Expression ret = lookup(comprehension);
    if (ret != null)
        return ret;

    final Decls decls = comprehension.decls().accept(delegate);
    final Formula formula = comprehension.formula().accept(delegate);
    ret = (decls == comprehension.decls() && formula == comprehension.formula()) ? comprehension : formula.comprehension(decls);
    return cache(comprehension, ret);
}
 
Example 3
Source File: RingElection.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * 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 4
Source File: AbstractReplacer.java    From kodkod with MIT License 5 votes vote down vote up
/** 
 * Calls lookup(comprehension) and returns the cached value, if any.  
 * If a replacement has not been cached, visits the expression's 
 * children.  If nothing changes, the argument is cached and
 * returned, otherwise a replacement expression is cached and returned.
 * @return { c: Comprehension | c.declarations = comprehension.declarations.accept(this) &&
 *                              c.formula = comprehension.formula.accept(this) }
 */
public Expression visit(Comprehension comprehension) {
	Expression ret = lookup(comprehension);
	if (ret!=null) return ret;
	
	final Decls decls = (Decls)comprehension.decls().accept(this);
	final Formula formula = comprehension.formula().accept(this);
	ret = (decls==comprehension.decls() && formula==comprehension.formula()) ? 
		  comprehension : formula.comprehension(decls); 
	return cache(comprehension,ret);
}
 
Example 5
Source File: Skolemizer.java    From kodkod with MIT License 5 votes vote down vote up
/**
 * @see kodkod.ast.visitor.AbstractReplacer#visit(kodkod.ast.Comprehension)
 */
@Override
public final Expression visit(Comprehension expr) {
	Expression ret = lookup(expr);
	if (ret!=null) return ret;
	final Environment<Expression> oldRepEnv = repEnv; // skolemDepth < 0 at this point
	final Decls decls = visit((Decls)expr.decls());
	final Formula formula = expr.formula().accept(this);
	ret = (decls==expr.decls() && formula==expr.formula()) ? expr : formula.comprehension(decls);
	repEnv = oldRepEnv;		
	return cache(expr,ret);
}
 
Example 6
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 7
Source File: RingElection.java    From org.alloytools.alloy with Apache License 2.0 3 votes vote down vote up
/**
 * 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);
}