@@ -5214,11 +5214,11 @@ private static IExpr factorComplex(IExpr expr, List<IExpr> varList, ISymbol head
5214
5214
ComplexRing <BigRational > cfac = new ComplexRing <BigRational >(BigRational .ZERO );
5215
5215
JASConvert <Complex <BigRational >> jas = new JASConvert <Complex <BigRational >>(varList , cfac );
5216
5216
GenPolynomial <Complex <BigRational >> polyRat = jas .expr2JAS (expr , numeric2Rational );
5217
- return factorComplex (expr , polyRat , jas , head , cfac ).eval (engine );
5217
+ return factorComplex (polyRat , jas , head , cfac , expr ).eval (engine );
5218
5218
} else {
5219
5219
JASConvert <BigRational > jas = new JASConvert <BigRational >(varList , BigRational .ZERO );
5220
5220
GenPolynomial <BigRational > polyRat = jas .expr2JAS (expr , numeric2Rational );
5221
- return factorRational (polyRat , jas , head , expr );
5221
+ return factorRational (polyRat , jas , head );
5222
5222
}
5223
5223
} catch (RuntimeException rex ) {
5224
5224
LOGGER .debug ("Algebra.factorComplex() failed" , rex );
@@ -5237,10 +5237,16 @@ public static IExpr factor(IExpr arg1, EvalEngine engine) {
5237
5237
* @param head the head of the factorization result AST (typically <code>F.Times</code> or <code>
5238
5238
* F.List</code>)
5239
5239
* @param cfac
5240
+ * @param original the original expression
5240
5241
* @return
5241
5242
*/
5242
- private static IExpr factorComplex (IExpr expr , GenPolynomial <Complex <BigRational >> polynomial ,
5243
- JASConvert <? extends RingElem <?>> jas , ISymbol head , ComplexRing <BigRational > cfac ) {
5243
+ private static IExpr factorComplex (GenPolynomial <Complex <BigRational >> polynomial ,
5244
+ JASConvert <? extends RingElem <?>> jas , ISymbol head , ComplexRing <BigRational > cfac ,
5245
+ IExpr original ) {
5246
+ if (polynomial .degree () > Config .MAX_POLYNOMIAL_DEGREE ) {
5247
+ // Exponent ist out of bounds for function `1`.
5248
+ return Errors .printMessage (S .Factor , "lrgexp" , F .List (S .Factor ));
5249
+ }
5244
5250
FactorComplex <BigRational > factorAbstract = new FactorComplex <BigRational >(cfac );
5245
5251
SortedMap <GenPolynomial <Complex <BigRational >>, Long > map = factorAbstract .factors (polynomial );
5246
5252
@@ -5253,7 +5259,7 @@ private static IExpr factorComplex(IExpr expr, GenPolynomial<Complex<BigRational
5253
5259
if (entry .getValue ().equals (1L ) && map .size () <= 2
5254
5260
&& (key .equals (F .CNI ) || key .equals (F .CI ))) {
5255
5261
// hack: factoring -I and I out of an expression should give no new factorized expression
5256
- return expr ;
5262
+ return original ;
5257
5263
}
5258
5264
result .append (F .Power (jas .complexPoly2Expr (entry .getKey ()), F .ZZ (entry .getValue ())));
5259
5265
}
@@ -5307,7 +5313,11 @@ public static IAST factorModulus(JASModInteger jas, ModLongRing modIntegerRing,
5307
5313
}
5308
5314
5309
5315
public static IAST factorRational (GenPolynomial <BigRational > polyRat , JASConvert <BigRational > jas ,
5310
- ISymbol head , IExpr original ) {
5316
+ ISymbol head ) {
5317
+ if (polyRat .degree () > Config .MAX_POLYNOMIAL_DEGREE ) {
5318
+ // Exponent ist out of bounds for function `1`.
5319
+ return Errors .printMessage (S .Factor , "lrgexp" , F .List (S .Factor ));
5320
+ }
5311
5321
Object [] objects = jas .factorTerms (polyRat );
5312
5322
GenPolynomial <edu .jas .arith .BigInteger > poly =
5313
5323
(GenPolynomial <edu .jas .arith .BigInteger >) objects [2 ];
0 commit comments