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
17 changes: 17 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,23 @@ searched as before, and where a search at another size cannot be run, the answer
| `10^(-12) arcsin(x / 10^(-12)) = x pi / 3` | `{ 0 }` | `{ 0, -5E-13, 5E-13 }` |
| `arcsin(x) = x pi / 3` | `{ -0.4999…, 0, 0.4999… }` | unchanged |

### The limits at a break of an antiderivative are remembered

**Not silent in time: answers or declines that did not arrive now do.** A definite integral across a break of its
antiderivative takes the antiderivative's one-sided limits there. These were taken outside the cache
that the limits at a bound have, so every candidate `Simplify` tried took them again. With a parameter, as in
`1/(a + sin(x))` over `[0, 2 pi]`, they are undecided after seconds each, and the simplification did not finish. With
numbers, several integrals of `1/(A + B sin(x))` across `pi` took over thirty seconds. Without an assumption on `a`
the parametric integral is left unevaluated: it is `2 pi / sqrt(a^2 - 1)` for `a > 1` and diverges for `|a| <= 1`
([#2658](https://github.com/asc-community/AngouriMath/issues/2658)).

| simplified | Was (2.10.0), within 20 s | Now |
|---|---|---|
| `integral(1/(a + sin(x)), x, 0, 2 pi)` | did not finish | unevaluated, 8.5 s |
| `integral(1/(a + cos(x)), x, 0, pi)` | unevaluated | unevaluated, 1.5 s |
| `integral(1/(3 + sin(x)), x, 0, 5)` | did not finish | closed form = `1.68876…` |
| `integral(1/(4 - sin(x)), x, -7, -2)` | did not finish | closed form = `1.36096…` |

### A definite integral of a function of abs is split where its argument changes sign

**An answer where there was none.** A definite integral whose integrand holds `abs(u)` was left unevaluated unless the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,14 @@ public Entity Integrate(Variable x, Entity from, Entity to) =>
{
// Approached from the side the range comes from, then left on the other.
var (arriving, leaving) = lower < upper ? (ApproachFrom.Left, ApproachFrom.Right) : (ApproachFrom.Right, ApproachFrom.Left);
var before = antiderivative.Limit(x, at, arriving);
var after = antiderivative.Limit(x, at, leaving);
// Through the cache of the limits at a bound: an undecided limit at a break was taken again by every
// candidate Simplify tried, at seconds each, and with a parameter in the antiderivative they are undecided
// often -- the integral of 1/(a + sin(x)) over [0, 2 pi], whose antiderivative has a case for each sign of
// a^2 - 1 and a pole of tan(x/2) at pi in each, did not finish. Not under its budget: a limit at a break
// can take more limits than one at a bound and still be decided, as the antiderivative of
// 1/((1 + x^2)^(1/3) (9 + x^2)) at 0 does. https://github.com/asc-community/AngouriMath/issues/2658
var before = LimitAtTheBound(antiderivative, x, at, arriving, budgeted: false);
var after = LimitAtTheBound(antiderivative, x, at, leaving, budgeted: false);
if (before.Nodes.Any(node => node is Limitf) || after.Nodes.Any(node => node is Limitf))
return null;
total += before - after;
Expand Down Expand Up @@ -558,7 +564,7 @@ private static bool HoldsAnInfinity(Entity expr)
/// not settle, two seconds of search each time, and the simplification ran past two minutes.
/// https://github.com/asc-community/AngouriMath/issues/2081
/// </summary>
private static Entity LimitAtTheBound(Entity antiderivative, Variable x, Entity bound, ApproachFrom side)
private static Entity LimitAtTheBound(Entity antiderivative, Variable x, Entity bound, ApproachFrom side, bool budgeted = true)
{
if (limitsAtBounds is null || limitsAtBoundsUnder is null || !SettingsState.StillHolds(limitsAtBoundsUnder))
{
Expand All @@ -573,9 +579,9 @@ private static Entity LimitAtTheBound(Entity antiderivative, Variable x, Entity
// Within a budget of the limits it asks along the way. Past it the limit is undecided and the integral left
// as written, which is no wrong answer. The most a decided limit at a bound took in the tests is 957; one
// spelling of the antiderivative of ln(x) Si(x) took over 38,000 in forty seconds without deciding.
var limit = Functions.Algebra.LimitFunctional.WithinABudget(LimitsAtABound,
() => (bound.Evaled is Number.Real { EDecimal: var at } && at.IsInfinity() ? WithItsLogarithmsGathered(antiderivative, x, bound, side) : antiderivative)
.Limit(x, bound, side));
Entity Taken() => (bound.Evaled is Number.Real { EDecimal: var at } && at.IsInfinity() ? WithItsLogarithmsGathered(antiderivative, x, bound, side) : antiderivative)
.Limit(x, bound, side);
var limit = budgeted ? Functions.Algebra.LimitFunctional.WithinABudget(LimitsAtABound, Taken) : Taken();
if (SettingsState.StillHolds(stamp))
{
if (into.Count >= 256)
Expand Down
44 changes: 44 additions & 0 deletions Sources/Tests/UnitTests/Calculus/ALimitAtABreakIsRememberedTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// 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.Linq;
using System.Threading.Tasks;
using AngouriMath.Extensions;
using Xunit;
using static AngouriMath.Entity;

namespace AngouriMath.Tests.Calculus
{
/// <summary>
/// The antiderivative of <c>1/(a + sin(x))</c> has a case for each sign of <c>a^2 - 1</c>, and a pole of
/// <c>tan(x/2)</c> at <c>pi</c> in each, where its limits with <c>a</c> unknown are undecided after seconds. Those
/// limits were taken outside the cache of the limits at a bound, so every candidate
/// <c>Simplify</c> tried took them again, and the simplification of the integral over <c>[0, 2 pi]</c> did not
/// finish. Without an assumption on <c>a</c> it is left unevaluated: it is <c>2 pi / sqrt(a^2 - 1)</c> for
/// <c>a &gt; 1</c> and diverges for <c>|a| &lt;= 1</c>. https://github.com/asc-community/AngouriMath/issues/2658
/// </summary>
[Trait("Area", "Calculus")]
public sealed class ALimitAtABreakIsRememberedTest
{
[Theory]
[InlineData("1/(a + sin(x))", "0", "2 pi")]
[InlineData("1/(a + cos(x))", "0", "pi")]
public void AParametricIntegralAcrossAPoleIsLeftUnevaluatedInTime(string integrand, string from, string to)
{
var task = Task.Run(() => integrand.ToEntity().Integrate("x", from.ToEntity(), to.ToEntity()).Simplify());
Assert.True(task.Wait(TimeSpan.FromSeconds(60)), $"{integrand} over [{from}, {to}] did not finish");
Assert.Contains(task.Result.Nodes, node => node is Integralf);
}

/// <summary>At a numeric parameter the same integral has its value.</summary>
[Fact]
public void AtANumericParameterItIsAnswered()
=> Assert.Equal(Number.Integer.Zero,
("integral(1/(3 + cos(x)), x, 0, 2 pi) - 2 pi / sqrt(8)").ToEntity().Simplify());
}
}
Loading