Skip to content

Commit

Permalink
Added Config#MAX_POLYNOMIAL_DEGREE_LAGUERRE_SOLVER option (#990)
Browse files Browse the repository at this point in the history
Add an option Config#MAX_POLYNOMIAL_DEGREE_LAGUERRE_SOLVER to limit the maximum degree of a polynomial before passing to LaguerreSolver

Co-authored-by: duy <duy@mail.com>
  • Loading branch information
tranleduy2000 and duy committed May 23, 2024
1 parent ec2585d commit 5c2ec89
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ public class Config {
/** Maximum degree of a polynomial generating function */
public static int MAX_POLYNOMIAL_DEGREE = Integer.MAX_VALUE;

/** Maximum degree of a polynomial for Laguerre solver */
public static int MAX_POLYNOMIAL_DEGREE_LAGUERRE_SOLVER = Integer.MAX_VALUE;

/** Maximum number of loop runs in some Symja functions */
public static long MAX_LOOP_COUNT = Long.MAX_VALUE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.matheclipse.core.eval.EvalAttributes;
import org.matheclipse.core.eval.EvalEngine;
import org.matheclipse.core.eval.exception.JASConversionException;
import org.matheclipse.core.eval.exception.PolynomialDegreeLimitExceeded;
import org.matheclipse.core.eval.exception.Validate;
import org.matheclipse.core.eval.interfaces.AbstractFunctionEvaluator;
import org.matheclipse.core.expression.F;
Expand Down Expand Up @@ -1011,6 +1012,12 @@ public static IAST rootsOfVariable(final IExpr expr, final IExpr denominator,
*/
private static org.hipparchus.complex.Complex[] allComplexRootsLaguerre(
@Nonnull double[] coefficients) {

if (coefficients.length > Config.MAX_POLYNOMIAL_DEGREE_LAGUERRE_SOLVER) {
// PolynomialDegreeLimitExceeded.throwIt(coefficients.length);
return null;
}

for (int j = 0; j < coefficients.length; j++) {
if (!Double.isFinite(coefficients[j])) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ public void setUp() {
Config.MAX_MATRIX_DIMENSION_SIZE = 100;
Config.MAX_BIT_LENGTH = 200000;
Config.MAX_POLYNOMIAL_DEGREE = 150;
Config.MAX_POLYNOMIAL_DEGREE_LAGUERRE_SOLVER = 500;
Config.FILESYSTEM_ENABLED = false;
Config.ROUNDING_MODE = RoundingMode.HALF_EVEN;
// fScriptEngine = fScriptManager.getEngineByExtension("m");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2087,6 +2087,13 @@ public void testIssue947() {
"{{x->(1250000*Log(2))/Log(500)}}");
}

@Test
public void testSolveBigExponent() {
// message: Exponent ist out of bounds for function Factor.
check("Solve(40==5000000/E^(x/(2*1/10^6)),x)", //
"{{x->ConditionalExpression(I*1/250000*Pi*C(1)+Log(125000)/500000,C(1)∈Integers)}}");
}

/** The JUnit setup method */
@Override
public void setUp() {
Expand Down

0 comments on commit 5c2ec89

Please sign in to comment.