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 @@ -177,6 +177,23 @@ the division's; with it on, the rounding is the setting's own and stays
| `"(-60.5)!"` at 30 digits, downcasting off | `5.86118478907722232671451280188E-81` | `2.93059239453861116335725639905E-81` |
| `"abs(75 + 316.22776601683796i)"`, downcasting off | `325` | `325.000000000000026076735749…` |

### A power of a quadratic with symbols in its outer coefficients is integrated over the monic quadratic

**Answers where there were none.** `x^5/(a + b x + c x^2)^4` was declined, and so were `x^6` and `x^7` over the
fourth power and `x^5` and `x^7` over the fifth, Rubi's 1.2.1.2, while `x^5/(2 + b x + c x^2)^4` and
`x^5/(k + m x + x^2)^4` were answered. Where the reduction declines the quadratic as written, it is integrated as
`1/c^n` times the integral over `(x^2 + k x + m)^n`, with `k = b/c` and `m = a/c` fresh symbols while it is, and put
back after. Each answer is in three cases by the sign of `4 a/c - (b/c)^2`
([#718](https://github.com/asc-community/AngouriMath/issues/718)).

| Input | Was (2.5.0) | Now |
|---|---|---|
| `"x^5/(a + b*x + c*x^2)^4".ToEntity().Integrate("x")` | `integral(...)` | 3,474 characters |
| `"x^6/(a + b*x + c*x^2)^4".ToEntity().Integrate("x")` | `integral(...)` | 4,142 characters |
| `"x^7/(a + b*x + c*x^2)^4".ToEntity().Integrate("x")` | `integral(...)` | 4,823 characters |
| `"x^5/(a + b*x + c*x^2)^5".ToEntity().Integrate("x")` | `integral(...)` | 4,066 characters |
| `"x^7/(a + b*x + c*x^2)^5".ToEntity().Integrate("x")` | `integral(...)` | 5,602 characters |

### `a + i a tan` beside the tangent's differential is lowered over its conjugate

**Answers where there were none.** `sqrt(a + i a tan(x))/(c + d tan(x))^(3/2)` ran past thirty seconds:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,9 @@ _ when TryReadOverSquareTimesRoot(expr, x, out var overFactor, out var overRadic
&& repetitions.EInteger.ToInt32Checked() is var n and >= 2
&& TreeAnalyzer.TryGetPolyQuadratic(repeated, x, out var qa, out var qb, out var qc)
&& (!numerator.ContainsNode(x) || !TreeAnalyzer.IsZero(qa))
&& IntegrateRationalOverPowerOfQuadratic(numerator, qa, qb, qc, repeated, n, x,
withoutTheFirstPower: TheFirstPowerCancels(numerator, qa, qb, qc, repeated, n, x)) is { } repeatedAnswer
&& (IntegrateRationalOverPowerOfQuadratic(numerator, qa, qb, qc, repeated, n, x,
withoutTheFirstPower: TheFirstPowerCancels(numerator, qa, qb, qc, repeated, n, x))
?? OverThePowerOfTheMonicQuadraticInNamedCoefficients(numerator, qa, qb, qc, n, x)) is { } repeatedAnswer
=> repeatedAnswer,

// ∫ (px + q)/(bx + c) dx, the same rewrite one degree down: the quotient is the
Expand Down Expand Up @@ -1124,6 +1125,49 @@ private static Entity IntegrateLinearOverPowerOfQuadratic(
LinearOverPowerOfLinear(p, q, b, c, power, x));
}

/// <summary>
/// ∫ N(x)/(a x^2 + b x + c)^n dx as <c>1/a^n</c> times the integral over
/// <c>(x^2 + k x + m)^n</c>, with <c>k = b/a</c> and <c>m = c/a</c> each a fresh symbol
/// while it is integrated, where <see cref="IntegrateRationalOverPowerOfQuadratic"/>
/// declined the quadratic as written.
/// </summary>
/// <remarks>
/// With symbols in both <c>a</c> and <c>c</c> the divisions by the quadratic leave
/// remainders the reduction cannot read as linear: <c>x^5/(a + b x + c x^2)^4</c> was
/// declined, where <c>x^5/(k + m x + x^2)^4</c> and <c>x^5/(2 + b x + c x^2)^4</c> are
/// answered in a few hundred milliseconds. Rubi's 1.2.1.2. A leading coefficient that is a
/// number as written, such as the <c>1 * 1^2</c> a substitution leaves, is not one: the
/// substitution that wrote <c>(b d + 2 c d x)^8/(a + b x + c x^2)^3</c> in the quadratic
/// asks with one, and naming its other two took the answer from 65,236 characters to 202,057.
/// https://github.com/asc-community/AngouriMath/issues/718
/// </remarks>
private static Entity? OverThePowerOfTheMonicQuadraticInNamedCoefficients(
Entity numerator, Entity a, Entity b, Entity c, int power, Entity.Variable x)
{
if (a.InnerSimplified is Entity.Number)
return null;
Entity everything = numerator + a + b + c;
var named = new List<(Entity.Variable Name, Entity Value)>();
Entity Named(Entity value)
{
var written = value.InnerSimplified;
if (written is Entity.Variable or Entity.Number)
return written;
var name = Entity.Variable.CreateUnique(everything, "k_q");
everything += name;
named.Add((name, written));
return name;
}
var linear = Named(b / a);
var constant = Named(c / a);
var monic = MathS.Pow(x, 2) + linear * x + constant;
if (IntegrateRationalOverPowerOfQuadratic(numerator, Entity.Number.Integer.One, linear, constant, monic, power, x) is not { } answer)
return null;
foreach (var (name, value) in named)
answer = answer.Substitute(name, value);
return answer / MathS.Pow(a, power);
}

/// <summary>
/// ∫ N(x)/(a x^2 + b x + c)^n dx for a numerator of any degree, or <see langword="null"/>
/// where the fraction is improper and this is not the rule for it.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// 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 over a power of a quadratic with symbols in both outer coefficients is
/// integrated over the monic quadratic in named coefficients where the reduction declines
/// it as written. Rubi's 1.2.1.2.
/// <a href="https://github.com/asc-community/AngouriMath/issues/718">#718</a>
/// </summary>
[Trait("Area", "Calculus")]
public sealed class APowerOfAQuadraticMadeMonicIntegralTest
{
[Theory]
[InlineData("x^5/(a + b*x + c*x^2)^4")]
[InlineData("x^7/(a + b*x + c*x^2)^5")]
public void DifferentiatesBack(string integrand)
{
var integral = integrand.ToEntity().Integrate("x");
Assert.DoesNotContain("integral(", integral.Stringize());
Entity Pinned(Entity e) => e.Substitute("a", 2).Substitute("b", 3).Substitute("c", 5);
var derivative = Pinned(integral.Substitute("C", 0)).Differentiate("x");
var original = Pinned(integrand.ToEntity());
foreach (var at in new[] { -1.7, -0.6, 0.45, 1.3 })
{
var want = original.Substitute("x", at).EvalNumerical();
var got = derivative.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