Java Code Examples for kodkod.ast.Expression#compose()
The following examples show how to use
kodkod.ast.Expression#compose() .
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: AbstractReplacer.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
/** * Calls lookup(expr) and returns the cached value, if any. If a replacement has * not been cached, visits the expr's children. If nothing changes, the argument * is cached and returned, otherwise a replacement expr is cached and returned. * * @return { e: Expression | e.op = expr.op && #e.children = #expr.children && * all i: [0..expr.children) | e.child(i) = * expr.child(i).accept(delegate) } */ @Override public Expression visit(NaryExpression expr) { Expression ret = lookup(expr); if (ret != null) return ret; final Expression[] visited = new Expression[expr.size()]; boolean allSame = true; for (int i = 0; i < visited.length; i++) { final Expression child = expr.child(i); visited[i] = child.accept(delegate); allSame = allSame && visited[i] == child; } ret = allSame ? expr : Expression.compose(expr.op(), visited); return cache(expr, ret); }
Example 2
Source File: TranslatorTest.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
private final void testNary(ExprOperator op) { bounds.bound(r1[0], factory.range(factory.tuple(1, 0), factory.tuple(1, 3))); bounds.bound(r1[1], factory.range(factory.tuple(1, 2), factory.tuple(1, 5))); bounds.bound(r1[3], factory.range(factory.tuple(1, 3), factory.tuple(1, 6))); for (int i = 2; i <= 5; i++) { final Expression[] exprs = new Expression[i]; exprs[0] = r1[0]; Expression binExpr = r1[0]; for (int j = 1; j < i; j++) { binExpr = binExpr.compose(op, r1[j % 4]); exprs[j] = r1[j % 4]; } Expression nExpr = Expression.compose(op, exprs); final Solution sol = solver.solve(binExpr.eq(nExpr).not(), bounds); assertNull(sol.instance()); } }
Example 3
Source File: TranslatorTest.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
private final void testNary(ExprOperator op) { bounds.bound(r1[0], factory.range(factory.tuple(1, 0), factory.tuple(1, 3))); bounds.bound(r1[1], factory.range(factory.tuple(1, 2), factory.tuple(1, 5))); bounds.bound(r1[3], factory.range(factory.tuple(1, 3), factory.tuple(1, 6))); for (int i = 2; i <= 5; i++) { final Expression[] exprs = new Expression[i]; exprs[0] = r1[0]; Expression binExpr = r1[0]; for (int j = 1; j < i; j++) { binExpr = binExpr.compose(op, r1[j % 4]); exprs[j] = r1[j % 4]; } Expression nExpr = Expression.compose(op, exprs); final Solution sol = solver.solve(binExpr.eq(nExpr).not(), bounds); assertNull(sol.instance()); } }
Example 4
Source File: AbstractReplacer.java From kodkod with MIT License | 6 votes |
/** * Calls lookup(expr) and returns the cached value, if any. * If a replacement has not been cached, visits the expr's * children. If nothing changes, the argument is cached and * returned, otherwise a replacement expr is cached and returned. * @return { e: Expression | e.op = expr.op && #e.children = #expr.children && all i: [0..expr.children) | e.child(i) = expr.child(i).accept(this) } */ public Expression visit(NaryExpression expr) { Expression ret = lookup(expr); if (ret!=null) return ret; final Expression[] visited = new Expression[expr.size()]; boolean allSame = true; for(int i = 0 ; i < visited.length; i++) { final Expression child = expr.child(i); visited[i] = child.accept(this); allSame = allSame && visited[i]==child; } ret = allSame ? expr : Expression.compose(expr.op(), visited); return cache(expr,ret); }
Example 5
Source File: TranslatorTest.java From kodkod with MIT License | 6 votes |
private final void testNary(ExprOperator op) { bounds.bound(r1[0], factory.range(factory.tuple(1, 0), factory.tuple(1, 3))); bounds.bound(r1[1], factory.range(factory.tuple(1, 2), factory.tuple(1, 5))); bounds.bound(r1[3], factory.range(factory.tuple(1, 3), factory.tuple(1, 6))); for(int i = 2; i <= 5; i++) { final Expression[] exprs = new Expression[i]; exprs[0] = r1[0]; Expression binExpr = r1[0]; for(int j = 1; j < i; j++) { binExpr = binExpr.compose(op, r1[j%4]); exprs[j] = r1[j%4]; } Expression nExpr = Expression.compose(op, exprs); final Solution sol = solver.solve(binExpr.eq(nExpr).not(), bounds); assertNull(sol.instance()); } }
Example 6
Source File: TranslatorTest.java From kodkod with MIT License | 6 votes |
private final void testNary(ExprOperator op) { bounds.bound(r1[0], factory.range(factory.tuple(1, 0), factory.tuple(1, 3))); bounds.bound(r1[1], factory.range(factory.tuple(1, 2), factory.tuple(1, 5))); bounds.bound(r1[3], factory.range(factory.tuple(1, 3), factory.tuple(1, 6))); for(int i = 2; i <= 5; i++) { final Expression[] exprs = new Expression[i]; exprs[0] = r1[0]; Expression binExpr = r1[0]; for(int j = 1; j < i; j++) { binExpr = binExpr.compose(op, r1[j%4]); exprs[j] = r1[j%4]; } Expression nExpr = Expression.compose(op, exprs); final Solution sol = solver.solve(binExpr.eq(nExpr).not(), bounds); assertNull(sol.instance()); } }
Example 7
Source File: Simplifier.java From quetzal with Eclipse Public License 2.0 | 6 votes |
public Expression visit(NaryExpression expr) { Expression ret = lookup(expr); if (ret!=null) return ret; final ExprOperator op = expr.op(); final List<Expression> children = simplify(op, visitAll(expr)); final int size = children.size(); switch(size) { case 0 : return cache(expr, empty(expr.arity())); case 1 : return cache(expr, children.get(0)); default : ret = expr.size()==size && allSame(expr,children) ? expr : Expression.compose(op, children); return cache(expr,ret); } }
Example 8
Source File: AbstractReplacer.java From org.alloytools.alloy with Apache License 2.0 | 5 votes |
/** * Calls lookup(binExpr) 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 { b: BinaryExpression | b.left = binExpr.left.accept(delegate) && * b.right = binExpr.right.accept(delegate) && b.op = binExpr.op } */ @Override public Expression visit(BinaryExpression binExpr) { Expression ret = lookup(binExpr); if (ret != null) return ret; final Expression left = binExpr.left().accept(delegate); final Expression right = binExpr.right().accept(delegate); ret = (left == binExpr.left() && right == binExpr.right()) ? binExpr : left.compose(binExpr.op(), right); return cache(binExpr, ret); }
Example 9
Source File: AbstractReplacer.java From kodkod with MIT License | 5 votes |
/** * Calls lookup(binExpr) 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 { b: BinaryExpression | b.left = binExpr.left.accept(this) && * b.right = binExpr.right.accept(this) && b.op = binExpr.op } */ public Expression visit(BinaryExpression binExpr) { Expression ret = lookup(binExpr); if (ret!=null) return ret; final Expression left = binExpr.left().accept(this); final Expression right = binExpr.right().accept(this); ret = (left==binExpr.left() && right==binExpr.right()) ? binExpr : left.compose(binExpr.op(), right); return cache(binExpr,ret); }
Example 10
Source File: PartialCannonicalizer.java From quetzal with Eclipse Public License 2.0 | 5 votes |
public Expression visit(BinaryExpression expr) { Expression ret = lookup(expr); if (ret!=null) return ret; final ExprOperator op = expr.op(); final Expression left = expr.left().accept(this); final Expression right = expr.right().accept(this); ret = simplify(op, left, right); if (ret==null) { final int hash = hash(op, left, right); for(Iterator<PartialCannonicalizer.Holder<Expression>> itr = exprs.get(hash); itr.hasNext(); ) { final Expression next = itr.next().obj; if (next instanceof BinaryExpression) { final BinaryExpression hit = (BinaryExpression) next; if (hit.op()==op && hit.left()==left && hit.right()==right) { return cache(expr, hit); } } } ret = left==expr.left()&&right==expr.right() ? expr : left.compose(op, right); exprs.add(new PartialCannonicalizer.Holder<Expression>(ret, hash)); } return cache(expr,ret); }
Example 11
Source File: Simplifier.java From quetzal with Eclipse Public License 2.0 | 5 votes |
public Expression visit(BinaryExpression expr) { Expression ret = lookup(expr); if (ret!=null) return ret; final ExprOperator op = expr.op(); final Expression left = expr.left().accept(this); final Expression right = expr.right().accept(this); ret = simplify(op, left, right); if (ret==null) { ret = left==expr.left()&&right==expr.right() ? expr : left.compose(op, right); } return cache(expr,ret); }