use of kodkod.ast.Decl in project org.alloytools.alloy by AlloyTools.
the class HOLSome4AllTest method testE8.
@Test
public void testE8() {
// UNSAT: some s: ints - (-1) |
// s > 3 || (all ns: set Node | #ns > s)
Formula cnd = si.gt(I3);
QuantifiedFormula allQF = (QuantifiedFormula) ns.count().gt(si).forAll(ns.setOf(Node));
Decl someDecls = s.oneOf(Expression.INTS.difference(M1.toExpression()));
{
Formula f = cnd.or(allQF).forSome(someDecls);
assertFalse(solve(f).sat());
}
// same thing, but inner flipped
// UNSAT: some s: ints - (-1) |
// s > 3 || (all ns: set Node | #ns > s)
{
Formula f = cnd.or(flip(allQF)).forSome(someDecls);
assertFalse(solve(f).sat());
}
}
use of kodkod.ast.Decl in project org.alloytools.alloy by AlloyTools.
the class HOLSome4AllTest method testE9.
@Test
public void testE9() {
// UNSAT: some s: ints - (-1) |
// s > 3 || (some ns: set Node | #ns > s + 3)
Formula cnd = si.gt(I3);
QuantifiedFormula innerSomeQF = (QuantifiedFormula) ns.count().gt(si.plus(I3)).forSome(ns.setOf(Node));
Decl someDecls = s.oneOf(Expression.INTS.difference(M1.toExpression()));
Formula f = cnd.or(innerSomeQF).forSome(someDecls);
assertFalse(solve(f).sat());
}
use of kodkod.ast.Decl in project org.alloytools.alloy by AlloyTools.
the class AbstractReplacer method visit.
/**
* Calls lookup(decls) and returns the cached value, if any. If a replacement
* has not been cached, visits each of the children's variable and expression.
* If nothing changes, the argument is cached and returned, otherwise a
* replacement Decls object is cached and returned.
*
* @return { d: Decls | d.size = decls.size && all i: [0..d.size) |
* d.declarations[i] = decls.declarations[i].accept(delegate) }
*/
@Override
public Decls visit(Decls decls) {
Decls ret = lookup(decls);
if (ret != null)
return ret;
Decls visitedDecls = null;
boolean allSame = true;
for (Decl decl : decls) {
Decls newDecl = visit(decl);
if (newDecl != decl)
allSame = false;
visitedDecls = (visitedDecls == null) ? newDecl : visitedDecls.and(newDecl);
}
ret = allSame ? decls : visitedDecls;
return cache(decls, ret);
}
use of kodkod.ast.Decl in project org.alloytools.alloy by AlloyTools.
the class FOL2BoolTranslator method some.
/**
* Translates the given existentially quantified formula as follows (where
* A_0...A_|A| stand for boolean variables that represent the tuples of the
* expression A, etc.): let quantFormula = "some 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 = "some 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.TRUE intially
* @param acc the accumulator that contains the top level conjunction; should be
* an empty OR accumulator initially
* @ensures the given accumulator contains the translation of the formula "some
* decls | formula"
*/
private void some(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.and(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.SOME);
for (IndexedEntry<BooleanValue> entry : declTransl) {
groundValue.set(entry.index(), BooleanConstant.TRUE);
some(decls, formula, currentDecl + 1, factory.and(entry.value(), declConstraints), acc);
groundValue.set(entry.index(), BooleanConstant.FALSE);
}
env = env.parent();
}
use of kodkod.ast.Decl in project org.alloytools.alloy by AlloyTools.
the class FOL2BoolTranslator method sum.
/**
* Translates the given sum expression as follows (where A_0...A_|A| stand for
* boolean variables that represent the tuples of the expression A, etc.): let
* sum = "sum a: A, b: B, ..., x: X | IE(a, b, ..., x) " | sum a: A, b: B, ...,
* x: X | if (a in A && b in B && ... && x in X) then IE(a, b, ..., x) else 0 }.
*
* @param decls intexpr 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.TRUE intially
* @param values integer values computed so far
*/
private final void sum(Decls decls, IntExpression expr, int currentDecl, BooleanValue declConstraints, List<Int> values) {
final BooleanFactory factory = interpreter.factory();
if (decls.size() == currentDecl) {
Int intExpr = expr.accept(this);
Int newInt = intExpr.choice(declConstraints, factory.integer(0));
values.add(newInt);
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);
for (IndexedEntry<BooleanValue> entry : declTransl) {
groundValue.set(entry.index(), BooleanConstant.TRUE);
sum(decls, expr, currentDecl + 1, factory.and(entry.value(), declConstraints), values);
groundValue.set(entry.index(), BooleanConstant.FALSE);
}
env = env.parent();
}
Aggregations