Search in sources :

Example 1 with IPatternMap

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

the class CombinatoricTestCase method testRosenIterator.

public void testRosenIterator() {
    IAST lhsPatternAST = F.Plus(F.x_, F.y_, F.z_);
    IAST lhsEvalAST = F.Plus(F.a, F.b, F.c, F.d);
    PatternMatcher patternMatcher = new PatternMatcher(lhsPatternAST);
    IPatternMap patternMap = patternMatcher.createPatternMap();
    // StackMatcher stackMatcher = patternMatcher.new StackMatcher(EvalEngine.get());
    FlatOrderlessStepVisitor visitor = new FlatOrderlessStepVisitor(F.Plus, lhsPatternAST, lhsEvalAST, patternMatcher, patternMap);
    MultisetPartitionsIterator iter = new MultisetPartitionsIterator(visitor, lhsPatternAST.argSize());
    boolean b = false;
    while (!b) {
        b = iter.execute();
        if (!b) {
            System.out.println(iter.toString());
            iter.initPatternMap();
        }
    }
    assertEquals(true, b);
}
Also used : IPatternMap(org.matheclipse.core.patternmatching.IPatternMap) FlatOrderlessStepVisitor(org.matheclipse.core.patternmatching.FlatOrderlessStepVisitor) MultisetPartitionsIterator(org.matheclipse.core.combinatoric.MultisetPartitionsIterator) IAST(org.matheclipse.core.interfaces.IAST) PatternMatcher(org.matheclipse.core.patternmatching.PatternMatcher)

Example 2 with IPatternMap

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

the class EvalEngine method setOptionsPattern.

public void setOptionsPattern(ISymbol lhsHead, IPatternMap patternMap) {
    IdentityHashMap<ISymbol, IASTAppendable> optionsPattern = fOptionsStack.peek();
    boolean setHead = patternMap.setOptionsPattern(this, lhsHead);
    if (!optionsPattern.isEmpty()) {
        for (Map.Entry<ISymbol, IASTAppendable> element : optionsPattern.entrySet()) {
            ISymbol symbol = element.getKey();
            IAST list = PatternMatching.optionsList(element.getKey(), true);
            if (list.size() > 1) {
                IASTAppendable tempList = optionsPattern.get(symbol);
                if (tempList == null) {
                    tempList = F.ListAlloc(10);
                    optionsPattern.put(symbol, tempList);
                }
                tempList.appendArgs(list);
            }
        }
    }
    if (setHead) {
        optionsPattern.put(S.LHS_HEAD, F.ast(lhsHead));
    }
}
Also used : ISymbol(org.matheclipse.core.interfaces.ISymbol) IASTAppendable(org.matheclipse.core.interfaces.IASTAppendable) IAST(org.matheclipse.core.interfaces.IAST) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) IPatternMap(org.matheclipse.core.patternmatching.IPatternMap)

Example 3 with IPatternMap

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

the class SparseArrayExpr method patternPositionsList.

/**
 * Fill the sparse array by evaluating the rules left-hand-side as a pattern-matching expression.
 *
 * @param trie the internal trie structure of the sparse array
 * @param ruleLHS
 * @param ruleRHS
 * @param dimension the dimension of the sparse array
 * @param arrayRulesList parameter for error message handling
 * @param engine
 * @return
 */
private static boolean patternPositionsList(final Trie<int[], IExpr> trie, IExpr ruleLHS, IExpr ruleRHS, int[] dimension, IAST arrayRulesList, EvalEngine engine) {
    if (dimension == null) {
        return false;
    }
    final int depth = dimension.length;
    PatternMatcherAndEvaluator matcher = new PatternMatcherAndEvaluator(ruleLHS, ruleRHS);
    if (matcher.isRuleWithoutPatterns()) {
        // The left hand side of `2` in `1` doesn't match an int-array of depth `3`.
        IOFunctions.printMessage(S.SparseArray, "posr", F.list(arrayRulesList, ruleLHS, F.ZZ(depth)), EvalEngine.get());
        return false;
    }
    IASTMutable positionList = F.constantArray(F.C1, depth);
    int[] positionsKey = new int[depth];
    IPatternMap patternMap = matcher.getPatternMap();
    IExpr[] patternValuesArray = patternMap.copyPattern();
    patternPositionsRecursive(trie, dimension, engine, matcher, positionList, 0, positionsKey, patternMap, patternValuesArray);
    return true;
}
Also used : IPatternMap(org.matheclipse.core.patternmatching.IPatternMap) IASTMutable(org.matheclipse.core.interfaces.IASTMutable) IExpr(org.matheclipse.core.interfaces.IExpr) PatternMatcherAndEvaluator(org.matheclipse.core.patternmatching.PatternMatcherAndEvaluator)

Aggregations

IPatternMap (org.matheclipse.core.patternmatching.IPatternMap)3 IAST (org.matheclipse.core.interfaces.IAST)2 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 Map (java.util.Map)1 MultisetPartitionsIterator (org.matheclipse.core.combinatoric.MultisetPartitionsIterator)1 IASTAppendable (org.matheclipse.core.interfaces.IASTAppendable)1 IASTMutable (org.matheclipse.core.interfaces.IASTMutable)1 IExpr (org.matheclipse.core.interfaces.IExpr)1 ISymbol (org.matheclipse.core.interfaces.ISymbol)1 FlatOrderlessStepVisitor (org.matheclipse.core.patternmatching.FlatOrderlessStepVisitor)1 PatternMatcher (org.matheclipse.core.patternmatching.PatternMatcher)1 PatternMatcherAndEvaluator (org.matheclipse.core.patternmatching.PatternMatcherAndEvaluator)1