Skip to content
Open
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
15 changes: 15 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,21 @@ sum leaves the integral unevaluated ([#2624](https://github.com/asc-community/An
| `integral(1/(x^3+x+1), x, -1, 0)` | a complex number | unevaluated (it diverges) |
| `integral(1/(x^3+x+1), x, -oo, 0)` | `NaN` | unevaluated |

### A limit of a quotient by a constant is its dividend's limit over the constant

**Not silent in time: answers that did not arrive now do.** The descent asked a quotient by a nonzero finite
constant whole, through the solvers that rewrite it, before asking its dividend. So
`4 arctan((6 tan(x/2) + 2)/(4 sqrt(2))) / (4 sqrt(2))` at `pi` from the left took seventeen seconds. The integral of
`1/(3 + sin(x))` over a range across `pi`, which asks that limit at the pole of `tan(x/2)`, did not finish. The
dividend's limit over the constant is now taken first. The values are unchanged where they arrived
([#2648](https://github.com/asc-community/AngouriMath/issues/2648)).

| simplified | Was (2.10.0), within 20 s | Now |
|---|---|---|
| `integral(1/(3+sin(x)), x, 0, 2 pi)` | did not finish | `sqrt(2) * pi / 2`, 0.8 s |
| `integral(1/(3+sin(x)), x, 0, 5)` | did not finish | closed form = `1.68876…`, 0.8 s |
| `limit(4 arctan((6 tan(x/2) + 2)/(4 sqrt(2)))/(4 sqrt(2)), x, pi-)` | did not finish | `4 * pi / 2 / (4 * sqrt(2))`, 0.4 s |

### A sum over roots cancels with a logarithm beside it at +oo

**An answer where there was none.** A sum over roots `sum(c(r) ln(x - r))` grows like `(sum c(r)) ln(x)` at `+oo`. It
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,17 @@ partial record Divf
{
internal override Entity? ComputeLimitDivideEtImpera(Variable x, Entity dist, ApproachFrom side)
{
// Over a finite constant other than 0, the limit of the dividend over it. Asked as a whole quotient first,
// the solvers rewrite it before the parts are read: arctan((6 tan(x/2) + 2)/(4 sqrt(2))) / (4 sqrt(2)) at
// pi from the left took fourteen seconds where its dividend's limit takes half of one, and the integral of
// 1/(3 + sin(x)) over [0, 2 pi], which asks it at the pole of tan(x/2), did not finish. A dividend whose
// limit is undecided or undefined goes the long way as before. The dividend's limit is asked whole, a
// smaller question than this one, so that a constant factor in it is taken out the same way.
// https://github.com/asc-community/AngouriMath/issues/2648
if (!Divisor.ContainsNode(x) && Divisor.Evaled is Number.Complex { IsZero: false } constant && Number.PartsAreFinite(constant)
&& ComputeLimit(Dividend, x, dist, side) is { } overTheConstant
&& !overTheConstant.ContainsNode(x) && overTheConstant.Evaled is Number.Complex { IsNaN: false })
return ComputeLimitImpl(New(overTheConstant, Divisor), x, dist, side);
// Over a quotient, as a quotient of products: a / (b / c) is a c / b wherever it has a value. Read as written,
// x^(-pi) / (ln(2) / ln(x)) at +oo is 0/0, and l'Hopital's rule makes each step of it another 0 * oo with a
// higher power of ln(x), so it was left unevaluated where x^(-pi) ln(x) / ln(2) is 0 at once. Only a value is
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// Copyright (c) 2019-2026 Angouri.
// AngouriMath is licensed under MIT.
// Details: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.
// Website: https://am.angouri.org.
//

using System;
using System.Threading.Tasks;
using AngouriMath.Core;
using AngouriMath.Extensions;
using Xunit;
using static AngouriMath.Entity;

namespace AngouriMath.Tests.Calculus
{
/// <summary>
/// A quotient by a nonzero constant was asked whole before its dividend, through the solvers that rewrite it, so
/// the limit of <c>4 arctan((6 tan(x/2) + 2)/(4 sqrt(2))) / (4 sqrt(2))</c> at <c>pi</c> took seventeen seconds,
/// and the integral of <c>1/(3 + sin(x))</c> over a range across <c>pi</c>, which asks it at the pole of
/// <c>tan(x/2)</c>, did not finish. https://github.com/asc-community/AngouriMath/issues/2648
/// </summary>
[Trait("Area", "Calculus")]
public sealed class ALimitOverAConstantIsTheDividendsLimitTest
{
private static Entity Within(Func<Entity> compute, string what)
{
var task = Task.Run(compute);
Assert.True(task.Wait(TimeSpan.FromSeconds(60)), $"{what} did not finish");
return task.Result;
}

/// <summary>Values from mpmath's quadrature at 30 digits.</summary>
[Theory]
[InlineData("1/(3 + sin(x))", "0", "2 pi", "2.22144146907918312350794049503")]
[InlineData("1/(3 + sin(x))", "0", "5", "1.68876091503969438318989039524")]
public void TheIntegralAcrossThePoleIsAnswered(string integrand, string from, string to, string expected)
{
var integral = Within(() => integrand.ToEntity().Integrate("x", from.ToEntity(), to.ToEntity()).Simplify(), integrand);
Assert.DoesNotContain(integral.Nodes, node => node is Integralf);
Assert.True((integral - expected.ToEntity()).EvalNumerical().Abs() < 1e-12,
$"{integrand} over [{from}, {to}] was {integral}, not {expected}");
}

/// <summary>
/// Within a budget of 200 limits asked along the way, which the dividend's limit needs a few dozen of; the
/// quotient asked whole spent thousands, which is where the seconds went.
/// </summary>
[Theory]
[InlineData("arctan((6 tan(x / 2) + 2) / (4 sqrt(2))) / (4 sqrt(2))", "pi / (8 sqrt(2))")]
[InlineData("4 arctan((6 tan(x / 2) + 2) / (4 sqrt(2))) / (4 sqrt(2))", "pi / (2 sqrt(2))")]
public void TheLimitFromTheLeftIsAnswered(string expression, string expected)
{
var limit = Within(() => Functions.Algebra.LimitFunctional.WithinABudget(200,
() => expression.ToEntity().Limit("x", "pi", ApproachFrom.Left)), expression);
Assert.DoesNotContain(limit.Nodes, node => node is Limitf);
Assert.True((limit - expected.ToEntity()).EvalNumerical().Abs() < 1e-12, $"{expression} at pi- was {limit}");
}
}
}
Loading