Search in sources :

Example 1 with NumberPartitionsIterator

use of org.matheclipse.core.combinatoric.NumberPartitionsIterator in project symja_android_library by axkr.

the class PatternMatcher method matchFlat.

/**
 * Match <code>Flat</code> LHS pattern expressions. It's assumed that the headers of the
 * expressions already matched.
 *
 * @param sym
 * @param lhsPattern
 * @param lhsEval
 * @param engine
 * @param stackMatcher
 * @return
 */
private boolean matchFlat(final ISymbol sym, final IAST lhsPattern, final IAST lhsEval, EvalEngine engine, StackMatcher stackMatcher) {
    if (lhsPattern.isAST1()) {
        int lhsEvalSize = lhsEval.size();
        if (lhsPattern.arg1().isPatternSequence(false)) {
            // TODO only the special case, where the last element is
            // a pattern sequence, is handled here
            IASTAppendable seq = F.Sequence();
            seq.appendAll(lhsEval, 1, lhsEvalSize);
            if (((IPatternSequence) lhsPattern.arg1()).matchPatternSequence(seq, fPatternMap, lhsPattern.topHead())) {
                return true;
            }
        }
        if (lhsPattern.size() == lhsEval.size()) {
            return matchASTSequence(lhsPattern, lhsEval, 0, engine, stackMatcher);
        }
        return false;
    }
    IAST lhsPatternAST = lhsPattern;
    IAST lhsEvalAST = lhsEval;
    // removeFlat already called a level up
    FlatStepVisitor visitor = new FlatStepVisitor(sym, lhsPatternAST, lhsEvalAST, stackMatcher, fPatternMap);
    NumberPartitionsIterator iter = new NumberPartitionsIterator(visitor, lhsEvalAST.argSize(), lhsPatternAST.argSize());
    return !iter.execute();
}
Also used : NumberPartitionsIterator(org.matheclipse.core.combinatoric.NumberPartitionsIterator) IASTAppendable(org.matheclipse.core.interfaces.IASTAppendable) IPatternSequence(org.matheclipse.core.interfaces.IPatternSequence) IAST(org.matheclipse.core.interfaces.IAST)

Aggregations

NumberPartitionsIterator (org.matheclipse.core.combinatoric.NumberPartitionsIterator)1 IAST (org.matheclipse.core.interfaces.IAST)1 IASTAppendable (org.matheclipse.core.interfaces.IASTAppendable)1 IPatternSequence (org.matheclipse.core.interfaces.IPatternSequence)1