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);
}
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;
}
Aggregations