use of kodkod.engine.bool.BooleanValue in project org.alloytools.alloy by AlloyTools.
the class BooleanCircuitTest method testCommutativityAndAssociativity.
private final void testCommutativityAndAssociativity(Operator.Nary op, BooleanValue p, BooleanValue q, BooleanValue r, BooleanValue s) {
// System.out.println("p: " + p + " " + p.digest());
// System.out.println("q: " + q + " " + q.digest());
// System.out.println("r: " + r + " " + r.digest());
// System.out.println("s: " + s + " " + s.digest());
// System.out.println("pq: " + p.compose(op, q));
// System.out.println("pqr: " + p.compose(op, q).compose(op, r));
// System.out.println("pqrs: " + p.compose(op, q).compose(op,
// r).compose(op, s));
// commutativity: p op q = p op q
// and associativity: p op (r op q) = (p op r) op q
// generate all permutations, and their parenthesizations, of p q r s
// and check that they are the same
final List<BooleanValue> formulas = new LinkedList<BooleanValue>();
formulas.add(p);
formulas.add(q);
formulas.add(r);
formulas.add(s);
final BooleanValue composition = compose(op, compose(op, compose(op, p, q), r), s);
for (int i0 = 0; i0 < 4; i0++) {
BooleanValue f0 = formulas.get(i0);
formulas.remove(i0);
for (int i1 = 0; i1 < 3; i1++) {
BooleanValue f1 = formulas.get(i1);
formulas.remove(i1);
for (int i2 = 0; i2 < 2; i2++) {
BooleanValue f2 = formulas.get(i2);
formulas.remove(i2);
testParenthesis(composition, op, f0, f1, f2, formulas.get(0));
formulas.add(i2, f2);
}
formulas.add(i1, f1);
}
formulas.add(i0, f0);
}
}
use of kodkod.engine.bool.BooleanValue in project org.alloytools.alloy by AlloyTools.
the class BooleanCircuitTest method testMultiGateWithNegatedArgument.
private final void testMultiGateWithNegatedArgument(Operator.Nary op) {
// negation / negation
final BooleanValue v842 = compose(op.complement(), v[8], compose(op.complement(), v[4], v[2])), v191015 = compose(op, v[19], compose(op, v[10], v[15])), v027 = compose(op.complement(), v[0], compose(op, v[2], v[7])), v15104 = compose(op, v[15], compose(op.complement(), v[10], v[4]));
testIdentityContradictionExcludedMiddle(op, f.not(v027));
testIdentityContradictionExcludedMiddle(op, f.not(v191015));
testCommutativityAndAssociativity(op, f.not(v842), f.not(v191015), f.not(v027), f.not(v15104));
// negation / multigate
testCommutativityAndAssociativity(op, v842, f.not(v191015), v027, f.not(v15104));
testCommutativityAndAssociativity(op, f.not(v842), v191015, v027, f.not(v15104));
testCommutativityAndAssociativity(op, v842, f.not(v191015), f.not(v027), v15104);
testCommutativityAndAssociativity(op, f.not(v842), v191015, f.not(v027), v15104);
}
use of kodkod.engine.bool.BooleanValue in project org.alloytools.alloy by AlloyTools.
the class BooleanCircuitTest method testMultiGateWithConstantArgument.
private final void testMultiGateWithConstantArgument(Operator.Nary op) {
// constant / constant
testIdentityContradictionExcludedMiddle(op, TRUE);
testIdentityContradictionExcludedMiddle(op, FALSE);
testIdempotencyAbsorptionContraction(op, TRUE, FALSE);
// constant / variable
testMultiGateWithConstantAndFormula(op, v[8], v[9]);
// constant / negation
final BooleanValue v246 = compose(op, v[2], compose(op.complement(), v[4], v[6]));
final BooleanValue v135 = compose(op.complement(), v[1], compose(op, v[3], v[5]));
testMultiGateWithConstantAndFormula(op, f.not(v246), f.not(v135));
testMultiGateWithConstantAndFormula(op, v246, f.not(v135));
// constant / multigate
testMultiGateWithConstantAndFormula(op, v246, v135);
testMultiGateWithConstantAndFormula(op, compose(op, v[2], v[3]), compose(op, v[1], v[4]));
}
use of kodkod.engine.bool.BooleanValue in project org.alloytools.alloy by AlloyTools.
the class BooleanMatrixTest method testTranspose.
public final void testTranspose() {
BooleanMatrix mF43t = mF43.transpose();
assertEquals(mF43.density(), mF43t.density());
assertTrue(equivalent(dim43.transpose(), mF43t.dimensions()));
fill(mF43, range(0, dim43.capacity() - 1));
BooleanValue[] result = new BooleanValue[dim43.capacity()];
final int a = dim43.dimension(0), b = dim43.dimension(1);
for (int i = 0; i < a; i++) {
for (int j = 0; j < b; j++) {
result[j * a + i] = vars[i * b + j];
}
}
mF43t = mF43.transpose();
assertEquals(mF43.density(), mF43t.density());
assertTrue(equivalent(dim43.transpose(), mF43t.dimensions()));
assertTrue(equivalent(mF43t, result));
}
use of kodkod.engine.bool.BooleanValue in project org.alloytools.alloy by AlloyTools.
the class BooleanMatrixTest method testClosure.
public final void testClosure() {
BooleanMatrix mF44 = f.matrix(Dimensions.square(4, 2));
assertTrue(equivalent(mF44, mF44.closure()));
mF44.set(0, vars[0]);
mF44.set(9, vars[9]);
assertTrue(equivalent(mF44, mF44.closure()));
mF44.set(2, vars[2]);
BooleanValue[] result = new BooleanValue[mF44.dimensions().capacity()];
for (int i = 0; i < result.length; i++) {
result[i] = FALSE;
}
result[0] = vars[0];
result[1] = f.and(vars[2], vars[9]);
result[1] = f.or(result[1], f.and(vars[0], result[1]));
result[2] = vars[2];
result[9] = vars[9];
assertTrue(equivalent(mF44.closure(), result));
mF44.set(7, vars[7]);
result[7] = vars[7];
result[3] = f.and(vars[2], f.and(vars[9], vars[7]));
result[11] = f.and(vars[7], vars[9]);
assertTrue(equivalent(mF44.closure(), result));
// System.out.println(mF44.closure());
}
Aggregations