Skip to content

Commit 72de9cf

Browse files
committed
Sort removedPositions int array before processing AbstractAST#remove()
1 parent 8dbfb48 commit 72de9cf

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/eval/SimplifyUtil.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -441,10 +441,7 @@ private IExpr eval(IExpr a) {
441441
return fEngine.evaluate(a);
442442
}
443443

444-
private void functionExpand(IExpr expr, SimplifyUtil.SimplifiedResult sResult) { // long
445-
// minCounter,
446-
// IExpr
447-
// result) {
444+
private void functionExpand(IExpr expr, SimplifyUtil.SimplifiedResult sResult) {
448445
if (expr.isBooleanFunction()) {
449446
try {
450447
IExpr temp = eval(F.BooleanMinimize(expr));
@@ -505,14 +502,9 @@ private void functionExpand(IExpr expr, SimplifyUtil.SimplifiedResult sResult) {
505502
IExpr conjugateArg = times.get(index1).first();
506503
int index2 = expr.indexOf(x -> x.equals(conjugateArg));
507504
if (index2 > 0) {
508-
final IASTAppendable removeAtClone;
509-
if (index2 > index1) {
510-
removeAtClone = times.removeAtClone(index2);
511-
removeAtClone.remove(index1);
512-
} else {
513-
removeAtClone = times.removeAtClone(index1);
514-
removeAtClone.remove(index2);
515-
}
505+
final IASTAppendable removeAtClone =
506+
times.removePositionsAtCopy(new int[] {index1, index2}, 2);
507+
516508
removeAtClone.append(F.Sqr(F.Abs(conjugateArg)));
517509
if (sResult.checkLessEqual(removeAtClone.oneIdentity1())) {
518510
expr = sResult.result;

symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/AbstractAST.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5929,6 +5929,7 @@ public IASTAppendable removePositionsAtCopy(int[] removedPositions, int untilInd
59295929
// if (untilIndex == 1) {
59305930
// return removeAtCopy(removedPositions[0]);
59315931
// }
5932+
Arrays.sort(removedPositions, 0, untilIndex);
59325933
IASTAppendable result = copyAppendable();
59335934
for (int j = untilIndex - 1; j >= 0; j--) {
59345935
result.remove(removedPositions[j]);

0 commit comments

Comments
 (0)