Search in sources :

Example 16 with Variable

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);
}
Also used : Signal(de.neemann.digital.core.Signal) Variable(de.neemann.digital.analyse.expression.Variable) BoolTableByteArray(de.neemann.digital.analyse.quinemc.BoolTableByteArray)

Example 17 with Variable

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));
}
Also used : Variable(de.neemann.digital.analyse.expression.Variable) Expression(de.neemann.digital.analyse.expression.Expression) NamedExpression(de.neemann.digital.analyse.expression.NamedExpression)

Example 18 with Variable

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));
}
Also used : Variable(de.neemann.digital.analyse.expression.Variable) ArrayList(java.util.ArrayList)

Example 19 with Variable

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("--");
}
Also used : Variable(de.neemann.digital.analyse.expression.Variable) PrimeSelectorDefault(de.neemann.digital.analyse.quinemc.primeselector.PrimeSelectorDefault) FormatToExpression(de.neemann.digital.analyse.expression.format.FormatToExpression) Expression(de.neemann.digital.analyse.expression.Expression) ContextFiller(de.neemann.digital.analyse.expression.ContextFiller) ArrayList(java.util.ArrayList)

Example 20 with Variable

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)));
}
Also used : Variable(de.neemann.digital.analyse.expression.Variable) FormatToExpression(de.neemann.digital.analyse.expression.format.FormatToExpression) Expression(de.neemann.digital.analyse.expression.Expression) ContextFiller(de.neemann.digital.analyse.expression.ContextFiller) ArrayList(java.util.ArrayList)

Aggregations

Variable (de.neemann.digital.analyse.expression.Variable)51 Expression (de.neemann.digital.analyse.expression.Expression)34 ContextFiller (de.neemann.digital.analyse.expression.ContextFiller)10 NamedExpression (de.neemann.digital.analyse.expression.NamedExpression)8 ArrayList (java.util.ArrayList)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 BoolTableByteArray (de.neemann.digital.analyse.quinemc.BoolTableByteArray)6 FormatToExpression (de.neemann.digital.analyse.expression.format.FormatToExpression)5 TestExecuter (de.neemann.digital.TestExecuter)4 Circuit (de.neemann.digital.draw.elements.Circuit)4 ElementLibrary (de.neemann.digital.draw.library.ElementLibrary)4 ModelCreator (de.neemann.digital.draw.model.ModelCreator)4 ShapeFactory (de.neemann.digital.draw.shapes.ShapeFactory)4 ExpressionException (de.neemann.digital.analyse.expression.ExpressionException)3 BoolTable (de.neemann.digital.analyse.quinemc.BoolTable)3 TableReducer (de.neemann.digital.analyse.quinemc.TableReducer)3 TruthTable (de.neemann.digital.analyse.TruthTable)2 FormatterException (de.neemann.digital.analyse.expression.format.FormatterException)2 FuseMapFillerException (de.neemann.digital.builder.jedec.FuseMapFillerException)2 JedecWriter (de.neemann.digital.builder.jedec.JedecWriter)2