Search in sources :

Example 1 with BooleanFunctionConversionException

use of org.matheclipse.core.eval.exception.BooleanFunctionConversionException in project symja_android_library by axkr.

the class QuineMcCluskyFormula method read.

public static QuineMcCluskyFormula read(IAST orAST) throws BooleanFunctionConversionException {
    VariablesSet exVar = new VariablesSet(orAST);
    IAST vars = exVar.getVarList();
    if (vars.isAST0()) {
        throw new BooleanFunctionConversionException();
    }
    ArrayList<QuineMcCluskyTerm> terms = QuineMcCluskyTerm.convertToTerms(orAST, vars);
    return new QuineMcCluskyFormula(terms, vars);
}
Also used : BooleanFunctionConversionException(org.matheclipse.core.eval.exception.BooleanFunctionConversionException) VariablesSet(org.matheclipse.core.convert.VariablesSet) IAST(org.matheclipse.core.interfaces.IAST)

Example 2 with BooleanFunctionConversionException

use of org.matheclipse.core.eval.exception.BooleanFunctionConversionException in project symja_android_library by axkr.

the class QuineMcCluskyTerm method convertToTerms.

public static ArrayList<QuineMcCluskyTerm> convertToTerms(IAST orAST, final IAST vars) throws BooleanFunctionConversionException {
    ArrayList<QuineMcCluskyTerm> terms = new ArrayList<QuineMcCluskyTerm>();
    IExpr temp;
    IExpr a;
    for (int i = 1; i < orAST.size(); i++) {
        temp = orAST.get(i);
        ArrayList<Byte> t = new ArrayList<Byte>();
        for (int j = 1; j < vars.size(); j++) {
            t.add(NIL);
        }
        if (temp.isAST(F.And)) {
            IAST andAST = (IAST) temp;
            for (int j = 1; j < andAST.size(); j++) {
                a = andAST.get(j);
                if (a.isAST(F.Not, 2)) {
                    IExpr arg1 = a.getAt(1);
                    if (!arg1.isSymbol()) {
                        throw new BooleanFunctionConversionException();
                    }
                    for (int j2 = 1; j2 < vars.size(); j2++) {
                        if (arg1.equals(vars.get(j2))) {
                            t.set(j2 - 1, (byte) 0);
                            break;
                        }
                    }
                } else if (a.isSymbol()) {
                    for (int j2 = 1; j2 < vars.size(); j2++) {
                        if (a.equals(vars.get(j2))) {
                            t.set(j2 - 1, (byte) 1);
                            break;
                        }
                    }
                } else {
                    throw new BooleanFunctionConversionException();
                }
            }
        } else {
            throw new BooleanFunctionConversionException();
        }
        if (!t.isEmpty()) {
            addBytes(terms, t);
        }
    }
    return terms;
}
Also used : ArrayList(java.util.ArrayList) BooleanFunctionConversionException(org.matheclipse.core.eval.exception.BooleanFunctionConversionException) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST)

Aggregations

BooleanFunctionConversionException (org.matheclipse.core.eval.exception.BooleanFunctionConversionException)2 IAST (org.matheclipse.core.interfaces.IAST)2 ArrayList (java.util.ArrayList)1 VariablesSet (org.matheclipse.core.convert.VariablesSet)1 IExpr (org.matheclipse.core.interfaces.IExpr)1