diff --git a/Sources/AngouriMath/Functions/Continuous/Limits/Gruntz/Gruntz.cs b/Sources/AngouriMath/Functions/Continuous/Limits/Gruntz/Gruntz.cs index c5dfb0f43..32ff6c504 100644 --- a/Sources/AngouriMath/Functions/Continuous/Limits/Gruntz/Gruntz.cs +++ b/Sources/AngouriMath/Functions/Continuous/Limits/Gruntz/Gruntz.cs @@ -79,10 +79,7 @@ private static void Trace(string what, object? value) if (depth > 0) return null; // already inside; the caller is the entry expr = AsExponentials(expr, x); - try { return LimitInf(expr, x); } - catch (Core.Exceptions.AngouriBugException) { throw; } - catch (OperationCanceledException) { throw; } - catch (Exception) { return null; } + return LimitInf(expr, x); } private static Entity? LimitInf(Entity e, Variable x) diff --git a/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/SolveStatement.cs b/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/SolveStatement.cs index 948312c0a..69de0ecd1 100644 --- a/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/SolveStatement.cs +++ b/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/SolveStatement.cs @@ -123,18 +123,13 @@ private static bool IsSpurious(Entity equation, Variable x, Entity root) return true; if (root.Vars.Any()) return false; - try - { - var substituted = equation.Substitute(x, root); - if (substituted.Evaled is not Number.Complex residual || !residual.IsFinite) - return false; - var size = residual.Abs().EDecimal; - if (size.LessThan(MathS.Settings.PrecisionErrorCommon)) - return false; - return size.GreaterThan(LargestTerm(substituted).Multiply(RelativeResidualTolerance)); - } - catch (Core.Exceptions.AngouriBugException) { throw; } - catch (System.Exception) { return false; } + var substituted = equation.Substitute(x, root); + if (substituted.Evaled is not Number.Complex residual || !residual.IsFinite) + return false; + var size = residual.Abs().EDecimal; + if (size.LessThan(MathS.Settings.PrecisionErrorCommon)) + return false; + return size.GreaterThan(LargestTerm(substituted).Multiply(RelativeResidualTolerance)); } /// diff --git a/Sources/AngouriMath/Functions/Continuous/Solvers/NumericalSolving/NewtonSolver.cs b/Sources/AngouriMath/Functions/Continuous/Solvers/NumericalSolving/NewtonSolver.cs index 79b94cc6b..c2f2a7d43 100644 --- a/Sources/AngouriMath/Functions/Continuous/Solvers/NumericalSolving/NewtonSolver.cs +++ b/Sources/AngouriMath/Functions/Continuous/Solvers/NumericalSolving/NewtonSolver.cs @@ -42,18 +42,10 @@ NumericsComplex ChooseGood() => { if (i == precision - 1) prev = value;//.Copy(); - try // TODO: remove try catch in for - { - - var dfv = df.Substitute(value); - if (dfv == 0) - return ChooseGood(); - value -= f.Substitute(value) / dfv; - } - catch (OverflowException) - { + var dfv = df.Substitute(value); + if (dfv == 0) return ChooseGood(); - } + value -= f.Substitute(value) / dfv; if (i > minCheckIters && prev == value) return value; } @@ -146,9 +138,7 @@ private static IEnumerable RealSignChanges( // intermediate value theorem has nothing to say about a complex value. double? RealValueAt(double at) { - NumericsComplex value; - try { value = f.Call(new NumericsComplex(at, 0)); } - catch (System.Exception) { return null; } + var value = f.Call(new NumericsComplex(at, 0)); if (double.IsNaN(value.Real) || double.IsInfinity(value.Real) || double.IsNaN(value.Imaginary) || double.IsInfinity(value.Imaginary)) return null; @@ -215,10 +205,14 @@ private static bool AreTheSameRoot(Complex a, Complex b) /// private static HashSet OnePerRoot(HashSet roots, FastExpression f) { + // A residual that is not a finite number ranks last. EDecimal Residual(Complex root) { - try { return f.Call(root.ToNumerics()).ToNumber().Abs().EDecimal; } - catch (System.Exception) { return EDecimal.PositiveInfinity; } + var residual = f.Call(root.ToNumerics()); + return double.IsNaN(residual.Real) || double.IsInfinity(residual.Real) + || double.IsNaN(residual.Imaginary) || double.IsInfinity(residual.Imaginary) + ? EDecimal.PositiveInfinity + : residual.ToNumber().Abs().EDecimal; } var kept = new List(); foreach (var root in roots @@ -277,14 +271,9 @@ private static Entity WithoutConditions(Entity expr) /// private static bool Satisfies(Entity expr, Entity.Variable v, Complex root) { - try - { - return expr.Substitute(v, root).Evaled is not Complex residual - || !residual.IsFinite - || residual.Abs().EDecimal.LessThan(MathS.Settings.PrecisionErrorCommon); - } - catch (Core.Exceptions.AngouriBugException) { throw; } - catch (System.Exception) { return true; } + return expr.Substitute(v, root).Evaled is not Complex residual + || !residual.IsFinite + || residual.Abs().EDecimal.LessThan(MathS.Settings.PrecisionErrorCommon); } } }