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