From 1faa7283a06e59a07f71bd44d4faf522cd36c840 Mon Sep 17 00:00:00 2001 From: axexlck Date: Fri, 15 Mar 2024 19:18:01 +0100 Subject: [PATCH] WIP #931 use `Simplify` to create better L'Hospitale results - set LIMIT_LHOSPITAL_RECURSION_LIMIT = 20 to avoid StackOverflow --- .../src/main/java/org/matheclipse/core/basic/Config.java | 2 +- .../java/org/matheclipse/core/builtin/SeriesFunctions.java | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/basic/Config.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/basic/Config.java index a38c18967d..52e72e4182 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/basic/Config.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/basic/Config.java @@ -309,7 +309,7 @@ public static Cache getExprCache() { public static int INTEGRATE_RUBI_TIMELIMIT = 8; /** Define the recursion limit for Limit#lHospitalesRule() method. */ - public static int LIMIT_LHOSPITAL_RECURSION_LIMIT = 128; + public static int LIMIT_LHOSPITAL_RECURSION_LIMIT = 20; /** * Flag for thread usage. diff --git a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/SeriesFunctions.java b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/SeriesFunctions.java index e5a0cfd3fa..471c66c844 100644 --- a/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/SeriesFunctions.java +++ b/symja_android_library/matheclipse-core/src/main/java/org/matheclipse/core/builtin/SeriesFunctions.java @@ -476,7 +476,7 @@ private static IExpr lHospitalesRule(IExpr numerator, IExpr denominator, LimitDa IExpr expr = engine.evalQuiet(F.Times(F.D(F.Power(numerator, exp), x), F.Power(F.D(denominator.base(), x), F.CN1))); if (expr.isTimes() && expr.leafCount() < Config.MAX_SIMPLIFY_TOGETHER_LEAFCOUNT) { - expr = engine.evalQuiet(F.Expand(expr)); + expr = engine.evalQuiet(F.Simplify(expr)); } expr = evalLimit(expr, data, engine); if (expr.isNumber()) { @@ -491,6 +491,9 @@ private static IExpr lHospitalesRule(IExpr numerator, IExpr denominator, LimitDa } IExpr expr = engine.evalQuiet(F.Times(F.D(numerator, x), F.Power(F.D(denominator, x), F.CN1))); + if (expr.isTimes() && expr.leafCount() < Config.MAX_SIMPLIFY_TOGETHER_LEAFCOUNT) { + expr = engine.evalQuiet(F.Simplify(expr)); + } return evalLimit(expr, data, engine); } catch (RecursionLimitExceeded rle) { engine.setRecursionLimit(recursionLimit);