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
17 changes: 17 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,23 @@ simplified as before
| `"sec(x)^2/(a + b*cos(x))^4".ToEntity().Integrate("x")` | `integral(...)` | the same |
| `"sec(c + d*x)^2/(a + b*cos(c + d*x))^4".ToEntity().Integrate("x")` | `integral(...)` | the same in `tan((c + d x)/2)` |

### A polynomial times an odd half power of a quadratic with compound coefficients is answered shortly

**Answers where there were none, and short ones where the unreleased master's were not.**
`sqrt(a + b x + g^2 x^2/f^2)` was declined by 2.5.0. The unreleased master answers it by reducing
a polynomial times an odd half power of the quadratic with one linear solve in the coefficients,
and carried as written, a quotient or a product of symbols among them came back in answers of 40,000
to 480,000 characters, after up to eight seconds, which took up to a minute more to differentiate
back. Each such coefficient is named for the solve now and written back in what it gives, and the
answers are a thousand characters, in a tenth of a second
([#718](https://github.com/asc-community/AngouriMath/issues/718)).

| Input | Was (2.5.0) | Now |
|---|---|---|
| `"sqrt(a + b*x + g^2*x^2/f^2)".ToEntity().Integrate("x")` | `integral(...)` | the root times a linear, and an arcsine or a logarithm by the sign of `g^2/f^2` |
| `"(a + b*x + c*x^2/f)^(3/2)".ToEntity().Integrate("x")` | `integral(...)` | the same with the power |
| `"x^2*sqrt(a*f + b*x + c*x^2/f)".ToEntity().Integrate("x")` | `integral(...)` | the same with a cubic in front of the root |

### A linear over a quadratic beside the root of another quadratic is integrated

`(g + h x)/(A sqrt(B))`, `A` and `B` two different quadratics, was left unevaluated wherever a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14197,8 +14197,34 @@ static Dictionary<EInteger, Entity> Scaled(Dictionary<EInteger, Entity> poly, En
if (coefficient.Evaled is Number.Complex and not Number.Real)
return null;

var q = new Dictionary<EInteger, Entity> { [EInteger.Zero] = c, [EInteger.One] = b, [EInteger.FromInt32(2)] = a };
var qPrime = new Dictionary<EInteger, Entity> { [EInteger.Zero] = b, [EInteger.One] = (2 * a).InnerSimplified };
// Each coefficient that is neither a number nor a symbol is named for the solve and
// written back into what it gives. Carried through the elimination as written,
// `g^2/f^2` as the leading coefficient of `sqrt(a + b x + g^2 x^2/f^2)` came back in an
// answer of 188,000 characters after four seconds, where a symbol in its place gives a
// short one at once.
var names = new List<(Variable Name, Entity Value)>();
Entity Named(Entity value)
{
if (value is Number or Variable)
return value;
foreach (var (name, named) in names)
if (named == value)
return name;
var fresh = Variable.CreateUnique(expr, "k_named" + names.Count);
names.Add((fresh, value));
return fresh;
}
Entity Back(Entity value)
{
foreach (var (name, named) in names)
value = value.Substitute(name, named);
return value;
}
var (namedA, namedB, namedC) = (Named(a), Named(b), Named(c));
pRead = pRead.ToDictionary(pair => pair.Key, pair => Named(pair.Value));

var q = new Dictionary<EInteger, Entity> { [EInteger.Zero] = namedC, [EInteger.One] = namedB, [EInteger.FromInt32(2)] = namedA };
var qPrime = new Dictionary<EInteger, Entity> { [EInteger.Zero] = namedB, [EInteger.One] = (2 * namedA).InnerSimplified };
Dictionary<EInteger, Entity> PowerOfQ(int j)
{
var result = new Dictionary<EInteger, Entity> { [EInteger.Zero] = Number.Integer.One };
Expand Down Expand Up @@ -14239,12 +14265,12 @@ Dictionary<EInteger, Entity> PowerOfQ(int j)
Entity r = Number.Integer.Zero;
for (var k = 0; k <= degreeOfR; k++)
{
var value = values[k].InnerSimplified;
var value = Back(values[k]).InnerSimplified;
if (value.Evaled is Number.Complex { IsZero: true })
continue;
r = r + value * (k == 0 ? Number.Integer.One : k == 1 ? x : MathS.Pow(x, k));
}
var kValue = values[degreeOfR + 1].InnerSimplified;
var kValue = Back(values[degreeOfR + 1]).InnerSimplified;
var root = MathS.Pow(radicand, Number.Rational.Create(1, 2));
var powerOfQInFront = positive ? root : MathS.Pow(radicand, Number.Rational.Create(-(2 * j + 1), 2));
Entity reduced = r == Number.Integer.Zero ? Number.Integer.Zero : r * powerOfQInFront;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// 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 AngouriMath.Extensions;
using Xunit;

namespace AngouriMath.Tests.Calculus
{
/// <summary>
/// A polynomial times an odd half power of a quadratic whose coefficients are quotients or
/// products of symbols. The reduction solves a linear system in those coefficients, and
/// carried as written they came back in answers of 40,000 to 480,000 characters, after up to
/// eight seconds; named for the solve and written back, the answers are a thousand. The length is
/// what is checked, beside the derivative, since a time is not something a test can hold.
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
/// </summary>
[Trait("Area", "Calculus")]
public sealed class CompoundCoefficientsOfAQuadraticIntegralTest
{
[Theory]
[InlineData("sqrt(a + b*x + g^2*x^2/f^2)")]
[InlineData("d + g*x + f*sqrt(a + b*x + g^2*x^2/f^2)")]
[InlineData("x/sqrt(a + b*x + g^2*x^2/f^2)")]
[InlineData("(a + b*x + c*x^2/f)^(3/2)")]
[InlineData("x^2*sqrt(a*f + b*x + c*x^2/f)")]
public void IsAnsweredShortly(string integrand)
{
var integral = integrand.ToEntity().Integrate("x");
var written = integral.Stringize();
Assert.DoesNotContain("integral(", written);
Assert.True(written.Length < 5000, $"the antiderivative of {integrand} is {written.Length} characters long");
Entity Pinned(Entity e) => e.Substitute("a", 1.3).Substitute("b", 0.7).Substitute("c", 0.6)
.Substitute("d", 1.9).Substitute("f", 1.1).Substitute("g", 0.8);
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
var original = Pinned(integrand.ToEntity());
foreach (var at in new[] { 0.3, 0.8, 1.5, 2.4 })
{
var got = derivative.Substitute("x", at).EvalNumerical();
var want = original.Substitute("x", at).EvalNumerical();
Assert.True(Math.Abs((double)(got - want).RealPart) + Math.Abs((double)(got - want).ImaginaryPart)
< 1e-9 * Math.Max(1, Math.Abs((double)want.RealPart)),
$"d/dx of the antiderivative of {integrand} is {got} at x = {at}, where the integrand is {want}");
}
}
}
}
Loading