use of org.matheclipse.combinatoric.NumberPartitionsIterator in project symja_android_library by axkr.
the class PatternMatcher method matchFlatAndFlatOrderlessAST.
private boolean matchFlatAndFlatOrderlessAST(final ISymbol sym, final IAST lhsPatternAST, final IAST lhsEvalAST, StackMatcher stackMatcher) {
if ((sym.getAttributes() & ISymbol.ORDERLESS) == ISymbol.ORDERLESS) {
if (lhsPatternAST.isAST1()) {
// TODO check for OneIdentity?
return matchExpr(lhsPatternAST.arg1(), lhsEvalAST, stackMatcher);
}
for (int i = 1; i < lhsPatternAST.size(); i++) {
if (!(lhsPatternAST.get(i) instanceof IPatternObject)) {
// try to find a matchin sub-expression
for (int j = 1; j < lhsEvalAST.size(); j++) {
if (matchExpr(lhsPatternAST.get(i), lhsEvalAST.get(j))) {
if (matchFlatAndFlatOrderlessAST(sym, lhsPatternAST.removeAtClone(i), lhsEvalAST.removeAtClone(j), stackMatcher)) {
return true;
}
}
}
return false;
}
}
FlatOrderlessStepVisitor visitor = new FlatOrderlessStepVisitor(sym, lhsPatternAST, lhsEvalAST, stackMatcher, fPatternMap);
MultisetPartitionsIterator iter = new MultisetPartitionsIterator(visitor, lhsPatternAST.size() - 1);
return !iter.execute();
} else {
if (lhsPatternAST.isAST1()) {
if (lhsPatternAST.arg1().isPatternSequence()) {
// TODO only the special case, where the last element is
// a pattern sequence, is handled here
IAST seq = F.Sequence();
seq.appendAll(lhsEvalAST, 1, lhsEvalAST.size());
if (((IPatternSequence) lhsPatternAST.arg1()).matchPatternSequence(seq, fPatternMap)) {
// }
return true;
}
}
if (lhsPatternAST.size() == lhsEvalAST.size()) {
return matchASTSequence(lhsPatternAST, lhsEvalAST, 0, stackMatcher);
}
return false;
}
FlatStepVisitor visitor = new FlatStepVisitor(sym, lhsPatternAST, lhsEvalAST, stackMatcher, fPatternMap);
NumberPartitionsIterator iter = new NumberPartitionsIterator(visitor, lhsEvalAST.size() - 1, lhsPatternAST.size() - 1);
return !iter.execute();
}
}
Aggregations