Search in sources :

Example 1 with PatternMatcherList

use of org.matheclipse.core.patternmatching.PatternMatcherList in project symja_android_library by axkr.

the class Functors method listRules.

public static Function<IExpr, IExpr> listRules(IAST astRules, IASTAppendable result, EvalEngine engine) {
    final Map<IExpr, IExpr> equalRules;
    List<PatternMatcherList> matchers = new ArrayList<PatternMatcherList>();
    if (astRules.isList()) {
        if (astRules.size() > 1) {
            // assuming multiple rules in a list
            IAST rule;
            int argsSize = astRules.argSize();
            if (argsSize <= 5) {
                equalRules = new OpenFixedSizeMap<IExpr, IExpr>(argsSize * 3 - 1);
            } else {
                equalRules = new HashMap<IExpr, IExpr>();
            }
            for (final IExpr expr : astRules) {
                if (expr.isRuleAST()) {
                    rule = (IAST) expr;
                    createPatternMatcherList(equalRules, matchers, rule);
                } else {
                    throw new ArgumentTypeException("rule expression (x->y or x:>y) expected instead of " + expr.toString());
                }
            }
        } else {
            equalRules = new HashMap<IExpr, IExpr>();
        }
    } else {
        if (astRules.isRuleAST()) {
            equalRules = new OpenFixedSizeMap<IExpr, IExpr>(3);
            createPatternMatcherList(equalRules, matchers, astRules);
        } else {
            throw new ArgumentTypeException("rule expression (x->y or x:>y) expected instead of " + astRules.toString());
        }
    }
    if (matchers.size() > 0) {
        return new ListRulesPatternFunctor(equalRules, matchers, result, engine);
    }
    return listRules(equalRules, result);
}
Also used : PatternMatcherList(org.matheclipse.core.patternmatching.PatternMatcherList) ArrayList(java.util.ArrayList) IExpr(org.matheclipse.core.interfaces.IExpr) IAST(org.matheclipse.core.interfaces.IAST) ArgumentTypeException(org.matheclipse.core.eval.exception.ArgumentTypeException)

Aggregations

ArrayList (java.util.ArrayList)1 ArgumentTypeException (org.matheclipse.core.eval.exception.ArgumentTypeException)1 IAST (org.matheclipse.core.interfaces.IAST)1 IExpr (org.matheclipse.core.interfaces.IExpr)1 PatternMatcherList (org.matheclipse.core.patternmatching.PatternMatcherList)1