diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/F.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/F.java index 2026fca749..e9351ed72e 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/F.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/F.java @@ -5454,7 +5454,10 @@ public static IAST Plus(final IExpr a0, final IExpr a1) { } public static IAST Plus(final long num, final IExpr... a) { - return ast(a, Plus).prependClone(ZZ(num)); + IASTAppendable ast = ast(Plus, a.length + 1, false); + ast.append(ZZ(num)); + ast.appendAll(a, 0, a.length); + return ast; } public static IAST Pochhammer(final IExpr a0, final IExpr a1) { @@ -6490,7 +6493,10 @@ public static IASTMutable Times(final IExpr a0, final IExpr a1) { } public static IAST Times(final long num, final IExpr... a) { - return ast(a, Times).prependClone(ZZ(num)); + IASTAppendable ast = ast(Times, a.length + 1, false); + ast.append(ZZ(num)); + ast.appendAll(a, 0, a.length); + return ast; } public static IAST Together(final IExpr a0) { diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/HMArrayList.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/HMArrayList.java index edace953e3..423da8b3c7 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/HMArrayList.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/HMArrayList.java @@ -351,6 +351,23 @@ public boolean appendAll(List list, int startPosition, int endP } return false; } + + /** {@inheritDoc} */ + @Override + public boolean appendAll(IExpr[] args, int startPosition, int endPosition) { + if (args.length > 0 && startPosition < endPosition) { + hashValue = 0; + int length = endPosition - startPosition; + if (length > array.length - lastIndex) { + growAtEnd(length); + } + for (int i = startPosition; i < endPosition; i++) { + array[lastIndex++] = args[i]; + } + return true; + } + return false; + } /** {@inheritDoc} */ @Override diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/NILPointer.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/NILPointer.java index c5b1d6a028..bf71b4fe93 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/NILPointer.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/expression/NILPointer.java @@ -74,6 +74,11 @@ public boolean appendAll(List list, int startPosition, int endP throw new UnsupportedOperationException(); } + @Override + public boolean appendAll(IExpr[] args, int startPosition, int endPosition) { + throw new UnsupportedOperationException(); + } + @Override public boolean appendArgs(IAST ast) { throw new UnsupportedOperationException(); diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/interfaces/IASTAppendable.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/interfaces/IASTAppendable.java index dd2e0f1289..8bd9313b80 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/interfaces/IASTAppendable.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/interfaces/IASTAppendable.java @@ -131,6 +131,21 @@ public interface IASTAppendable extends IASTMutable { */ public boolean appendAll(List list, int startPosition, int endPosition); + /** + * Appends all elements from offset startPosition to endPosition in the specified list to + * the end of this AST. + * + * @param args + * array containing elements to be added to this AST + * @param startPosition + * the start position, inclusive. + * @param endPosition + * the ending position, exclusive. + * @return true if this AST changed as a result of the call + * + */ + public boolean appendAll(IExpr[] args, int startPosition, int endPosition); + /** * Appends all of the arguments (starting from offset 1) in the specified AST to the end of this AST. *