use of de.neemann.digital.analyse.expression.Variable in project Digital by hneemann.
the class BoolTableExpandedTest method checkTable.
private void checkTable(ArrayList<Signal> in1) {
ArrayList<Signal> in2 = new Signals("a", "b", "c", "d").list();
List<Variable> vars = new Vars("a", "b", "c", "d").list();
check(new BoolTableByteArray(new byte[] { 1, 1, 0, 1 }), in1, in2, vars);
check(new BoolTableByteArray(new byte[] { 0, 1, 1, 0 }), in1, in2, vars);
check(new BoolTableByteArray(new byte[] { 1, 0, 0, 1 }), in1, in2, vars);
check(new BoolTableByteArray(new byte[] { 0, 0, 0, 1 }), in1, in2, vars);
check(new BoolTableByteArray(new byte[] { 0, 1, 1, 1 }), in1, in2, vars);
}
use of de.neemann.digital.analyse.expression.Variable in project Digital by hneemann.
the class FormatToExpressionTest method testFormatExpNot2.
public void testFormatExpNot2() throws Exception {
Variable a = v("A");
Variable b = v("B");
Variable c = v("C");
Expression e = or(and(a, b), not(c));
assertEquals("(A ∧ B) ∨ ¬C", FormatToExpression.FORMATTER_UNICODE.format(e));
}
use of de.neemann.digital.analyse.expression.Variable in project Digital by hneemann.
the class QuineMcCluskeyExactCoverTest method testExactCoverLoop.
public void testExactCoverLoop() {
ArrayList<Variable> vars = new ArrayList<>();
vars.add(new Variable("a"));
vars.add(new Variable("b"));
vars.add(new Variable("c"));
vars.add(new Variable("d"));
ArrayList<TableRow> primes = new ArrayList<>();
primes.add(new TableRow(9, 0).addSource(1, 3, 5, 7, 9));
primes.add(new TableRow(9, 1).addSource(0, 1, 2, 3, 5, 6, 7, 8, 9));
primes.add(new TableRow(9, 2).addSource(0, 2, 3, 5, 8, 9));
primes.add(new TableRow(9, 3).addSource(1, 2, 4, 6, 8, 9));
primes.add(new TableRow(9, 4).addSource(0, 1, 4, 5, 8, 9));
primes.add(new TableRow(9, 5).addSource(2, 3, 6, 8, 9));
primes.add(new TableRow(9, 6).addSource(2, 4, 5, 7, 9));
primes.add(new TableRow(9, 7).addSource(0, 1, 3, 6, 7, 9));
QuineMcCluskey qmc = new QuineMcCluskey(vars, null, primes);
qmc.simplifyPrimes(null);
final ArrayList<TableRow> pri = qmc.getPrimes();
assertEquals(2, pri.size());
Collection<Integer> s1 = pri.get(0).getSource();
assertEquals(1, s1.size());
assertTrue(s1.contains(3));
Collection<Integer> s2 = pri.get(1).getSource();
assertEquals(1, s2.size());
assertTrue(s2.contains(4));
}
use of de.neemann.digital.analyse.expression.Variable in project Digital by hneemann.
the class QuineMcCluskeyRegressionTest method testRegression3.
public void testRegression3() throws Exception {
Variable a = new Variable("A");
Variable b = new Variable("B");
Variable c = new Variable("C");
Variable d = new Variable("D");
ArrayList<Variable> vars = new ArrayList<>();
vars.add(a);
vars.add(b);
vars.add(c);
vars.add(d);
QuineMcCluskey t = new QuineMcCluskey(vars);
Expression ex = or(a, c);
t.fillTableWith(new BoolTableExpression(ex, new ContextFiller(vars)));
// System.out.println("--");
while (!t.isFinished()) {
// System.out.println(FormatToExpression.FORMATTER_JAVA.format(t.getExpression()));
t.simplifyStep();
}
t.simplifyPrimes(new PrimeSelectorDefault());
assertEquals("A || C", FormatToExpression.FORMATTER_JAVA.format(t.getExpression()));
// System.out.println("--");
}
use of de.neemann.digital.analyse.expression.Variable in project Digital by hneemann.
the class QuineMcCluskeyRegressionTest method testRegression.
private static void testRegression(int n, int j) throws Exception {
int size = 1 << n;
boolean[] table = new boolean[size];
ArrayList<Integer> index = new ArrayList<>();
for (int i = 0; i < size; i++) index.add(i);
Collections.shuffle(index);
for (int i = 0; i < j; i++) table[index.get(i)] = true;
ArrayList<Variable> var = Variable.vars(n);
Expression expression = new QuineMcCluskey(var).fillTableWith(new BoolTableBoolArray(table)).simplify().getExpression();
ContextFiller cf = new ContextFiller(var);
for (int i = 0; i < table.length; i++) assertEquals(table[i], expression.calculate(cf.setContextTo(i)));
}
Aggregations