use of kodkod.engine.bool.BooleanMatrix in project org.alloytools.alloy by AlloyTools.
the class FOL2BoolTranslator method visit.
/**
* Returns this.interpreter.interpret(constExpr).
*
* @return this.interpreter.interpret(constExpr).
*/
@Override
public final BooleanMatrix visit(ConstantExpression constExpr) {
BooleanMatrix ret = leafCache.get(constExpr);
if (ret == null) {
ret = interpreter.interpret(constExpr);
leafCache.put(constExpr, ret);
}
return ret;
}
use of kodkod.engine.bool.BooleanMatrix in project org.alloytools.alloy by AlloyTools.
the class FOL2BoolTranslator method visit.
/**
* Calls lookup(cexpr) and returns the cached value, if any. If a translation
* has not been cached, translates the expression, calls cache(...) on it and
* returns it.
*
* @return let t = lookup(cexpr) | some t => t, cache(cexpr, translate(cexpr))
*/
@Override
public BooleanMatrix visit(Comprehension cexpr) {
BooleanMatrix ret = lookup(cexpr);
if (ret != null)
return ret;
ret = interpreter.factory().matrix(Dimensions.square(interpreter.universe().size(), cexpr.decls().size()));
comprehension(cexpr.decls(), cexpr.formula(), 0, BooleanConstant.TRUE, 0, ret);
return cache(cexpr, ret);
}
use of kodkod.engine.bool.BooleanMatrix in project org.alloytools.alloy by AlloyTools.
the class FOL2BoolTranslator method visit.
/**
* Calls this.env.lookup(variable) and returns the current binding for the given
* variable and adds it to the current level of nested variables
* (<code>cars</code>). If no binding is found, an UnboundLeafException is
* thrown.
*
* @return this.env.lookup(variable)
* @throws UnboundLeafException no this.env.lookup(variable)
*/
@Override
public final BooleanMatrix visit(Variable variable) {
final BooleanMatrix ret = env.lookup(variable);
if (ret == null)
throw new UnboundLeafException("Unbound variable", variable);
vars.add(variable);
return ret;
}
use of kodkod.engine.bool.BooleanMatrix in project org.alloytools.alloy by AlloyTools.
the class FOL2BoolTranslator method all.
/**
* Translates the given universally quantified formula as follows (where
* A_0...A_|A| stand for boolean variables that represent the tuples of the
* expression A, etc.): let quantFormula = "all a: A, b: B, ..., x: X | F(a, b,
* ..., x)" | (A_0 && B_0 && ... && X_0 => translate(F(A_0, B_0, ..., X_0))) &&
* ... && (A_|A| && B_|B| && ... && X_|X| => translate(F(A_|A|, B_|B|, ...,
* X_|X|))) If the noOverflow option is specified, then the translation looks
* like: let quantFormula = "all a: A, b: B, ..., x: X | F(a, b, ..., x)" | (A_0
* && B_0 && ... && X_0 => (!of(F(A_0, B_0, ..., X_0)) => translate(F(A_0, B_0,
* ..., X_0)))) && ... && (A_|A| && B_|B| && ... && X_|X| => (!of(F(A_|A|,
* B_|B|, ..., X_|X|)) => translate(F(A_|A|, B_|B|, ..., X_|X|)))) where
* of(F(A_|a|, B_|b|, ..., X_|x|)) is the portion of the overflow circuit
* generated by the translation of F(A_|a|, B_|b|, ..., X_|x|) contributed by
* arithmetic operations over only the integer variables of this quantifier
*
* @param decls formula declarations
* @param formula the formula body
* @param currentDecl currently processed declaration; should be 0 initially
* @param declConstraints the constraints implied by the declarations; should be
* Boolean.FALSE initially
* @param acc the accumulator that contains the top level conjunction; should be
* an empty AND accumulator initially
* @ensures the given accumulator contains the translation of the formula "all
* decls | formula"
*/
private void all(Decls decls, Formula formula, int currentDecl, BooleanValue declConstraints, BooleanAccumulator acc) {
if (acc.isShortCircuited())
return;
final BooleanFactory factory = interpreter.factory();
if (decls.size() == currentDecl) {
BooleanValue formulaCircuit = formula.accept(this);
BooleanValue finalCircuit = factory.or(declConstraints, formulaCircuit);
acc.add(finalCircuit);
return;
}
final Decl decl = decls.get(currentDecl);
final BooleanMatrix declTransl = visit(decl);
final BooleanMatrix groundValue = factory.matrix(declTransl.dimensions());
env = env.extend(decl.variable(), decl.expression(), groundValue, Quantifier.ALL);
for (IndexedEntry<BooleanValue> entry : declTransl) {
groundValue.set(entry.index(), BooleanConstant.TRUE);
all(decls, formula, currentDecl + 1, factory.or(factory.not(entry.value()), declConstraints), acc);
groundValue.set(entry.index(), BooleanConstant.FALSE);
}
env = env.parent();
}
use of kodkod.engine.bool.BooleanMatrix in project org.alloytools.alloy by AlloyTools.
the class FOL2BoolTranslator method visit.
/**
* Calls lookup(unaryExpr) and returns the cached value, if any. If a
* translation has not been cached, translates the expression, calls cache(...)
* on it and returns it.
*
* @return let t = lookup(unaryExpr) | some t => t, let op =
* (unaryExpr.op).(TRANSPOSE->transpose + CLOSURE->closure +
* REFLEXIVE_CLOSURE->(lambda(m)(m.closure().or(iden))) |
* cache(unaryExpr, op(unaryExpr.child))
*/
@Override
public final BooleanMatrix visit(UnaryExpression unaryExpr) {
BooleanMatrix ret = lookup(unaryExpr);
if (ret != null)
return ret;
final BooleanMatrix child = unaryExpr.expression().accept(this);
final ExprOperator op = unaryExpr.op();
switch(op) {
case TRANSPOSE:
ret = child.transpose();
break;
case CLOSURE:
ret = child.closure();
break;
case REFLEXIVE_CLOSURE:
ret = child.closure().or(visit((ConstantExpression) Expression.IDEN));
break;
default:
throw new IllegalArgumentException("Unknown operator: " + op);
}
return cache(unaryExpr, ret);
}
Aggregations