Search in sources :

Example 6 with ContextFiller

use of de.neemann.digital.analyse.expression.ContextFiller in project Digital by hneemann.

the class IndependentCheckerTest method testRemoveVar2.

public void testRemoveVar2() {
    Expression ex = and(a, c, d);
    ContextFiller cf = new ContextFiller(a, b, c, d);
    BoolTableExpression bte = new BoolTableExpression(ex, cf);
    IndependentChecker ic = new IndependentChecker(bte);
    BoolTable btr = ic.removeVar(1);
    assertEquals(8, btr.size());
    for (int i = 0; i < 7; i++) assertEquals(ThreeStateValue.zero, btr.get(i));
    assertEquals(ThreeStateValue.one, btr.get(7));
}
Also used : Expression(de.neemann.digital.analyse.expression.Expression) ContextFiller(de.neemann.digital.analyse.expression.ContextFiller)

Example 7 with ContextFiller

use of de.neemann.digital.analyse.expression.ContextFiller 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 8 with ContextFiller

use of de.neemann.digital.analyse.expression.ContextFiller 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)

Example 9 with ContextFiller

use of de.neemann.digital.analyse.expression.ContextFiller in project Digital by hneemann.

the class IndependentCheckerTest method testSimple.

public void testSimple() {
    Expression ex = and(a, b, c);
    ContextFiller cf = new ContextFiller(a, b, c, d);
    BoolTableExpression bte = new BoolTableExpression(ex, cf);
    IndependentChecker ic = new IndependentChecker(bte);
    assertEquals(4, ic.getVars());
    assertFalse(ic.isIndependentFrom(0));
    assertFalse(ic.isIndependentFrom(1));
    assertFalse(ic.isIndependentFrom(2));
    assertTrue(ic.isIndependentFrom(3));
}
Also used : Expression(de.neemann.digital.analyse.expression.Expression) ContextFiller(de.neemann.digital.analyse.expression.ContextFiller)

Example 10 with ContextFiller

use of de.neemann.digital.analyse.expression.ContextFiller in project Digital by hneemann.

the class IndependentCheckerTest method testSimple2.

public void testSimple2() {
    Expression ex = and(a, c, d);
    ContextFiller cf = new ContextFiller(a, b, c, d);
    BoolTableExpression bte = new BoolTableExpression(ex, cf);
    IndependentChecker ic = new IndependentChecker(bte);
    assertEquals(4, ic.getVars());
    assertFalse(ic.isIndependentFrom(0));
    assertTrue(ic.isIndependentFrom(1));
    assertFalse(ic.isIndependentFrom(2));
    assertFalse(ic.isIndependentFrom(3));
}
Also used : Expression(de.neemann.digital.analyse.expression.Expression) ContextFiller(de.neemann.digital.analyse.expression.ContextFiller)

Aggregations

ContextFiller (de.neemann.digital.analyse.expression.ContextFiller)17 Expression (de.neemann.digital.analyse.expression.Expression)10 Variable (de.neemann.digital.analyse.expression.Variable)10 ArrayList (java.util.ArrayList)6 BoolTableByteArray (de.neemann.digital.analyse.quinemc.BoolTableByteArray)4 TruthTable (de.neemann.digital.analyse.TruthTable)3 FormatToExpression (de.neemann.digital.analyse.expression.format.FormatToExpression)2 ExpressionException (de.neemann.digital.analyse.expression.ExpressionException)1 QuineMcCluskey (de.neemann.digital.analyse.quinemc.QuineMcCluskey)1 TableRow (de.neemann.digital.analyse.quinemc.TableRow)1 ThreeStateValue (de.neemann.digital.analyse.quinemc.ThreeStateValue)1 PrimeSelectorDefault (de.neemann.digital.analyse.quinemc.primeselector.PrimeSelectorDefault)1 ExpressionListenerStore (de.neemann.digital.gui.components.table.ExpressionListenerStore)1