Skip to content

Commit f973ddd

Browse files
Enclose pi, e and Euler's constant past the digits held of them (#2542)
The precise interval evaluator held each constant to about two hundred digits and rounded them to the working precision each way. Past those digits the rounding reads them as exact, so both bounds were one number a unit in its last place from the constant. Deciding that a root's residual is zero asks for as many digits as its terms need, and the residual of a Cardano root of x^3 - 2.75 10^60 x - 1.5 10^90 in its own cubic, about 10^-309, was enclosed in 400 digits as the point -5.4 10^-112 + 9.0 10^-112 i. Two roots of i x + x^2 - 2 conj(x) = 0 with x written as 10^-30 x were dropped as no roots. Past the digits held, each constant is worked out ten digits past the precision and widened as a function's value is. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent d50ceec commit f973ddd

3 files changed

Lines changed: 79 additions & 14 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ no longer reads a root whose decimals were flushed to `0` as extending to no sol
7373
| `"x^5 - 3*10^(-60)*x + 10^(-150) = 0".ToEntity().Solve("x")` | `0` among the roots, where the polynomial is `10^-150` | `3.33e-91` in its place |
7474
| `"(1 + i) + 2*(10^12*x) - 3*(10^12*x)^2 + 10^12*x*abs(3 - 10^12*x) = 0".ToEntity().Solve("x")` | `{ -1.87e-13 - 1.58e-13i }`, one root of two | both, `10^-12` times those of the equation in `x` |
7575

76+
### A root is not shown to be none by the digits held of `pi`
77+
78+
**Silent: an unsolved equation is solved, with all its roots.** Whether a root's residual leaves out zero is decided
79+
by enclosing it in an interval, at as many digits as its terms need. `pi`, `e` and Euler's constant were held to about
80+
two hundred digits, and past that each was read as exact, so an interval enclosed a true zero as a point beside it,
81+
and a root was dropped as no root. Past their digits they are now worked out to the precision asked for.
82+
83+
| Input | Was (2.8.0) | Now |
84+
|---|---|---|
85+
| `"i*(10^(-30)*x) + (10^(-30)*x)^2 - 2*conj(10^(-30)*x) = 0".ToEntity().Solve("x")` | unsolved, the equation returned | the four roots, `0` and three in Cardano radicals, `10^30` times those of `i x + x^2 - 2 conj(x) = 0` |
86+
7687
### A root with a radical in it is not dropped for what its evaluation leaves
7788

7889
**Silent: `{ }` becomes the roots.** An equation in a modulus is solved for the real and imaginary parts of `x` as a

‎Sources/AngouriMath/Numerics/PreciseEvaluation.cs‎

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,9 @@ private PreciseComplexInterval Cos(PreciseComplexInterval a)
378378
}
379379

380380
private PreciseInterval Pi()
381-
{
382-
var pi = EDecimal.FromString(
383-
"3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196");
384-
return new(pi.RoundToPrecision(down), pi.RoundToPrecision(up));
385-
}
381+
=> Constant(
382+
"3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196",
383+
context => AngouriMath.InternalAMExtensions.ConstantCache.Lookup(context).Pi);
386384

387385
private PreciseInterval HalfPi()
388386
{
@@ -392,17 +390,33 @@ private PreciseInterval HalfPi()
392390
}
393391

394392
private PreciseInterval E()
395-
{
396-
var e = EDecimal.FromString(
397-
"2.71828182845904523536028747135266249775724709369995957496696762772407663035354759457138217852516642742746639193200305992181741359662904357290033429526059563073813232862794349076323382988075319525101901");
398-
return new(e.RoundToPrecision(down), e.RoundToPrecision(up));
399-
}
393+
=> Constant(
394+
"2.71828182845904523536028747135266249775724709369995957496696762772407663035354759457138217852516642742746639193200305992181741359662904357290033429526059563073813232862794349076323382988075319525101901",
395+
context => AngouriMath.InternalAMExtensions.ConstantCache.Lookup(context).E);
400396

401397
private PreciseInterval EulerGamma()
402-
{
403-
var gamma = EDecimal.FromString(
404-
"0.57721566490153286060651209008240243104215933593992359880576723488486772677766467093694706329174674951463144724980708248096050401448654283622417399764492353625350033374293733773767394279259525824709491");
405-
return new(gamma.RoundToPrecision(down), gamma.RoundToPrecision(up));
398+
=> Constant(
399+
"0.57721566490153286060651209008240243104215933593992359880576723488486772677766467093694706329174674951463144724980708248096050401448654283622417399764492353625350033374293733773767394279259525824709491",
400+
Number.EulerGamma);
401+
402+
/// <summary>
403+
/// A constant as an interval: the <paramref name="known"/> digits of it rounded each way, where they
404+
/// are more than the working precision; otherwise <paramref name="compute"/>d to ten digits
405+
/// past it and widened as a function's value is. The digits held are about two hundred, and
406+
/// rounding them to more reads them as exact, so each bound was the same number, a unit in
407+
/// their last place from the constant: the residual of a Cardano root of
408+
/// <c>x^3 - 2.75 10^60 x - 1.5 10^90</c> in its own cubic, about <c>10^-309</c> in 400 digits,
409+
/// was enclosed as the point <c>-5.4 10^-112 + 9.0 10^-112 i</c>, and the root, shown not to
410+
/// be one, was dropped from <c>i x + x^2 - 2 conj(x) = 0</c> with x written as <c>10^-30 x</c>.
411+
/// </summary>
412+
private PreciseInterval Constant(string known, Func<EContext, EDecimal> compute)
413+
{
414+
var value = EDecimal.FromString(known);
415+
if (value.UnsignedMantissa.GetDigitCountAsEInteger().CompareTo(digits + 10) > 0)
416+
return new(value.RoundToPrecision(down), value.RoundToPrecision(up));
417+
value = compute(near);
418+
var slack = value.Abs().Multiply(unit, up).Add(least, up);
419+
return new(value.Subtract(slack, down), value.Add(slack, up));
406420
}
407421

408422
private PreciseComplexInterval Evaluate(Entity expr)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// Copyright (c) 2019-2026 Angouri.
3+
// AngouriMath is licensed under MIT.
4+
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
5+
// Website: https://am.angouri.org.
6+
//
7+
8+
using AngouriMath.Extensions;
9+
using Xunit;
10+
using static AngouriMath.Entity;
11+
using static AngouriMath.Entity.Set;
12+
13+
namespace AngouriMath.Tests.Algebra
14+
{
15+
/// <summary>
16+
/// <c>i x + x^2 - 2 conj(x) = 0</c> with x written as <c>10^-30 x</c> has the four roots of the
17+
/// equation in x times <c>10^30</c>. Three are Cardano roots of a cubic whose terms are near
18+
/// <c>1e90</c>, and the interval their residual was enclosed in to decide it is zero was worked
19+
/// to more digits than the two hundred held of <c>pi</c>, which were read as exact: the true
20+
/// zero was enclosed as a point beside it, and two roots were dropped. Found by solving
21+
/// generated equations as written and scaled; no issue was filed.
22+
/// </summary>
23+
[Trait("Area", "Algebra")]
24+
public sealed class AnIntervalHoldsAConstantToItsDigitsTest
25+
{
26+
[Fact]
27+
public void TheRootsAreThoseInXTimesTheScale()
28+
{
29+
const string equation = "i * x + x^2 - 2 * conj(x)";
30+
var asWritten = Assert.IsType<FiniteSet>($"{equation} = 0".ToEntity().Solve("x"));
31+
Assert.Equal(4, asWritten.Count);
32+
var scaled = Assert.IsType<FiniteSet>(
33+
$"{equation.Replace("x", "(10^(-30) * x)")} = 0".ToEntity().Solve("x"));
34+
Assert.Equal(4, scaled.Count);
35+
foreach (var root in scaled)
36+
Assert.Contains(asWritten, other =>
37+
((Number.Complex)(root / "10^30".ToEntity() - other).EvalNumerical()).Abs() < 1e-20);
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)