Search in sources :

Example 1 with ContextFiller

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

the class TruthTableFormatterLaTeX method format.

@Override
public String format(TruthTable truthTable) throws ExpressionException {
    StringBuilder sb = new StringBuilder();
    sb.append("\\begin{center}\n\\begin{tabular}{");
    for (Variable v : truthTable.getVars()) sb.append("c");
    sb.append("|");
    for (int i = 0; i < truthTable.getResultCount(); i++) sb.append("c");
    sb.append("}\n");
    for (Variable v : truthTable.getVars()) sb.append("$").append(formatVar(v.getIdentifier())).append("$&");
    for (int i = 0; i < truthTable.getResultCount(); i++) {
        sb.append("$").append(formatVar(truthTable.getResultName(i))).append("$");
        if (i < truthTable.getResultCount() - 1)
            sb.append("&");
    }
    sb.append("\\\\\n");
    sb.append("\\hline\n");
    ContextFiller cf = new ContextFiller(truthTable.getVars());
    for (int i = 0; i < cf.getRowCount(); i++) {
        cf.setContextTo(i);
        for (Variable v : cf) sb.append(format(cf.get(v))).append("&");
        for (int j = 0; j < truthTable.getResultCount(); j++) {
            ThreeStateValue r = truthTable.getResult(j).get(i);
            sb.append(format(r));
            if (j < truthTable.getResultCount() - 1)
                sb.append("&");
        }
        sb.append("\\\\\n");
    }
    sb.append("\\end{tabular}\n\\end{center}\n");
    return sb.toString();
}
Also used : ThreeStateValue(de.neemann.digital.analyse.quinemc.ThreeStateValue) Variable(de.neemann.digital.analyse.expression.Variable) ContextFiller(de.neemann.digital.analyse.expression.ContextFiller)

Example 2 with ContextFiller

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

the class TestReorderInputs method testDeleteVar.

public void testDeleteVar() throws Exception {
    TruthTable t = new TruthTable(3).addResult();
    BoolTableByteArray col = (BoolTableByteArray) t.getResult(0);
    for (int i = 0; i < t.getRows(); i++) col.set(i, i + 1);
    ReorderInputs reorderInputs = new ReorderInputs(t);
    reorderInputs.getItems().delete(2);
    TruthTable newTable = reorderInputs.reorder();
    assertEquals(2, newTable.getVars().size());
    assertEquals(1, newTable.getResultCount());
    ContextFiller cf = new ContextFiller(newTable.getVars());
    cf.set(t.getVars().get(2), false);
    for (int i = 0; i < newTable.getRows(); i++) {
        cf.setContextTo(i);
        assertEquals(newTable.getByContext(0, cf), t.getByContext(0, cf));
    }
}
Also used : BoolTableByteArray(de.neemann.digital.analyse.quinemc.BoolTableByteArray) ContextFiller(de.neemann.digital.analyse.expression.ContextFiller) TruthTable(de.neemann.digital.analyse.TruthTable)

Example 3 with ContextFiller

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

the class TestReorderInputs method testReorder.

public void testReorder() throws Exception {
    TruthTable t = new TruthTable(5).addResult();
    BoolTableByteArray col = (BoolTableByteArray) t.getResult(0);
    for (int i = 0; i < t.getRows(); i++) col.set(i, i + 1);
    ReorderInputs reorderInputs = new ReorderInputs(t);
    reorderInputs.getItems().swap(1, 2);
    TruthTable newTable = reorderInputs.reorder();
    ContextFiller cf = new ContextFiller(t.getVars());
    for (int i = 0; i < t.getRows(); i++) {
        cf.setContextTo(i);
        assertEquals(newTable.getByContext(0, cf), t.getByContext(0, cf));
    }
}
Also used : BoolTableByteArray(de.neemann.digital.analyse.quinemc.BoolTableByteArray) ContextFiller(de.neemann.digital.analyse.expression.ContextFiller) TruthTable(de.neemann.digital.analyse.TruthTable)

Example 4 with ContextFiller

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

the class TableReducerTest method testReduce2.

public void testReduce2() {
    List<Variable> vars = new ArrayList<>();
    vars.add(a);
    vars.add(b);
    vars.add(c);
    vars.add(d);
    Expression ex = and(a, c, d);
    ContextFiller cf = new ContextFiller(vars);
    BoolTableExpression bte = new BoolTableExpression(ex, cf);
    TableReducer tr = new TableReducer(vars, bte);
    assertTrue(tr.canReduce());
    vars = tr.getVars();
    assertEquals(3, vars.size());
    assertEquals(a, vars.get(0));
    assertEquals(c, vars.get(1));
    assertEquals(d, vars.get(2));
}
Also used : Variable(de.neemann.digital.analyse.expression.Variable) Expression(de.neemann.digital.analyse.expression.Expression) ContextFiller(de.neemann.digital.analyse.expression.ContextFiller) ArrayList(java.util.ArrayList)

Example 5 with ContextFiller

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

the class TableReducerTest method testReduce.

public void testReduce() {
    List<Variable> vars = new ArrayList<>();
    vars.add(a);
    vars.add(b);
    vars.add(c);
    vars.add(d);
    Expression ex = and(a, b, c);
    ContextFiller cf = new ContextFiller(vars);
    BoolTableExpression bte = new BoolTableExpression(ex, cf);
    TableReducer tr = new TableReducer(vars, bte);
    assertTrue(tr.canReduce());
    vars = tr.getVars();
    assertEquals(3, vars.size());
    assertEquals(a, vars.get(0));
    assertEquals(b, vars.get(1));
    assertEquals(c, vars.get(2));
}
Also used : Variable(de.neemann.digital.analyse.expression.Variable) Expression(de.neemann.digital.analyse.expression.Expression) ContextFiller(de.neemann.digital.analyse.expression.ContextFiller) ArrayList(java.util.ArrayList)

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