Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -146,9 +138,7 @@ private static IEnumerable<NumericsComplex> 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;
Expand Down Expand Up @@ -215,10 +205,14 @@ private static bool AreTheSameRoot(Complex a, Complex b)
/// </summary>
private static HashSet<Complex> OnePerRoot(HashSet<Complex> 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<Complex>();
foreach (var root in roots
Expand Down Expand Up @@ -277,14 +271,9 @@ private static Entity WithoutConditions(Entity expr)
/// </returns>
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);
}
}
}
Expand Down
Loading