use of org.matheclipse.core.interfaces.IPattern in project symja_android_library by axkr.
the class CompareToTestCase method testIssue122c.
public void testIssue122c() {
ISymbol b = F.$s("b");
ISymbol c = F.$s("c");
ISymbol x1 = F.$s("x1");
ISymbol x3 = F.$s("x3");
ISymbol x4 = F.$s("x4");
ISymbol x5 = F.$s("x5");
IPattern x1_c = F.$p(x1, c);
IPattern x3_b = F.$p(x3, b);
IPattern x3_c = F.$p(x3, c);
IPattern x5_c = F.$p(x5, c);
IAST ast1 = F.Times(x3, x5, x5_c);
IAST ast2 = F.Times(F.CN1, x1_c, x3_b, x3_c);
int res = ast1.compareTo(ast2);
assertEquals(2, res);
res = ast2.compareTo(ast1);
assertEquals(-2, res);
check("-Infinity+b+a", "-Infinity+a+b");
}
use of org.matheclipse.core.interfaces.IPattern in project symja_android_library by axkr.
the class CompareToTestCase method testIssue122a.
public void testIssue122a() {
ISymbol b = F.$s("b");
ISymbol c = F.$s("c");
ISymbol x1 = F.$s("x1");
ISymbol x3 = F.$s("x3");
ISymbol x4 = F.$s("x4");
ISymbol x5 = F.$s("x5");
IPattern x1_c = F.$p(x1, c);
IPattern x3_b = F.$p(x3, b);
IPattern x3_c = F.$p(x3, c);
IPattern x4_c = F.$p(x4, c);
IAST ast1 = F.Times(F.CN1, x1_c, x3_b, x3_c);
IAST ast2 = F.Times(F.CN1, x3, x5, x1_c, x4_c);
int res = ast1.compareTo(ast2);
assertEquals(-1, res);
res = ast2.compareTo(ast1);
assertEquals(1, res);
check("-Infinity+b+a", "-Infinity+a+b");
}
use of org.matheclipse.core.interfaces.IPattern in project symja_android_library by axkr.
the class PatternMatcher method matchDefaultArgumentsAST.
/**
* Match the <code>lhsPatternAST</code> with its <code>Default[]</code> values.
*
* @param symbolWithDefaultValue
* the symbol for getting the associated default values from
* @param lhsPatternAST
* left-hand-side which may contain patterns with default values
* @return <code>F.NIL</code> if the given <code>lhsPatternAST</code> could not be matched or contains no pattern
* with default value.
*/
private IExpr matchDefaultArgumentsAST(ISymbol symbolWithDefaultValue, IAST lhsPatternAST) {
IAST cloned = F.ast(lhsPatternAST.head(), lhsPatternAST.size(), false);
boolean defaultValueMatched = false;
for (int i = 1; i < lhsPatternAST.size(); i++) {
if (lhsPatternAST.get(i).isPatternDefault()) {
IPattern pattern = (IPattern) lhsPatternAST.get(i);
IExpr positionDefaultValue = pattern.getDefaultValue();
if (positionDefaultValue == null) {
positionDefaultValue = symbolWithDefaultValue.getDefaultValue(i);
}
if (positionDefaultValue != null) {
if (!((IPatternObject) lhsPatternAST.get(i)).matchPattern(positionDefaultValue, fPatternMap)) {
return F.NIL;
}
defaultValueMatched = true;
continue;
} else {
IExpr commonDefaultValue = symbolWithDefaultValue.getDefaultValue();
if (commonDefaultValue != null) {
if (!((IPatternObject) lhsPatternAST.get(i)).matchPattern(commonDefaultValue, fPatternMap)) {
return F.NIL;
}
defaultValueMatched = true;
continue;
}
}
}
cloned.append(lhsPatternAST.get(i));
}
if (defaultValueMatched) {
if (cloned.isOneIdentityAST1()) {
return cloned.arg1();
}
return cloned;
}
return F.NIL;
}
use of org.matheclipse.core.interfaces.IPattern in project symja_android_library by axkr.
the class PatternMatcher method matchOptionalArgumentsAST.
/**
* Match the <code>lhsPatternAST</code> with its <code>Default[]</code> values.
*
* @param symbolWithDefaultValue
* the symbol for getting the associated default values from
* @param lhsPatternAST
* left-hand-side which may contain patterns with default values
* @return <code>F.NIL</code> if the given <code>lhsPatternAST</code> could not be matched or contains no pattern
* with default value.
*/
private IExpr matchOptionalArgumentsAST(ISymbol symbolWithDefaultValue, IAST lhsPatternAST, IAST lhsEvalAST) {
int lhsSize = lhsEvalAST.size();
IAST cloned = F.ast(lhsPatternAST.head(), lhsPatternAST.size(), false);
boolean defaultValueMatched = false;
for (int i = 1; i < lhsPatternAST.size(); i++) {
if (lhsPatternAST.get(i).isPatternDefault()) {
IPattern pattern = (IPattern) lhsPatternAST.get(i);
if (i < lhsSize) {
cloned.append(pattern);
continue;
}
IExpr positionDefaultValue = pattern.getDefaultValue();
if (positionDefaultValue == null) {
positionDefaultValue = symbolWithDefaultValue.getDefaultValue(i);
}
if (positionDefaultValue != null) {
if (!((IPatternObject) lhsPatternAST.get(i)).matchPattern(positionDefaultValue, fPatternMap)) {
return F.NIL;
}
defaultValueMatched = true;
continue;
} else {
IExpr commonDefaultValue = symbolWithDefaultValue.getDefaultValue();
if (commonDefaultValue != null) {
if (!((IPatternObject) lhsPatternAST.get(i)).matchPattern(commonDefaultValue, fPatternMap)) {
return F.NIL;
}
defaultValueMatched = true;
continue;
}
}
}
cloned.append(lhsPatternAST.get(i));
}
if (defaultValueMatched) {
if (cloned.isOneIdentityAST1()) {
return cloned.arg1();
}
return cloned;
}
return F.NIL;
}
use of org.matheclipse.core.interfaces.IPattern in project symja_android_library by axkr.
the class Pattern method equivalent.
/**
* Check if the two left-hand-side pattern expressions are equivalent. (i.e. <code>f[x_,y_]</code>
* is equivalent to <code>f[a_,b_]</code> )
*
* @param patternObject
* @param pm1
* @param pm2
* @return
*/
@Override
public boolean equivalent(final IPatternObject patternObject, final IPatternMap pm1, IPatternMap pm2) {
if (this == patternObject) {
return true;
}
if (patternObject instanceof Pattern) {
// test if the pattern indices are equal
final IPattern p2 = (IPattern) patternObject;
if (getIndex(pm1) != p2.getIndex(pm2)) {
return false;
}
// test if the "check" expressions are equal
final IExpr o1 = getHeadTest();
final IExpr o2 = p2.getHeadTest();
if ((o1 == null) || (o2 == null)) {
return o1 == o2;
}
return o1.equals(o2);
}
return false;
}
Aggregations