Skip to content

Commit 9880e18

Browse files
A cube shifted is solved (#2315)
SolveCubic takes Cardano's C as a cube root of (D1 + sqrt(D1^2 - 4 D0^3)) / 2, either root of C^6 - D1 C^3 + D0^3 = 0 doing as long as it is not 0, since the roots divide by C. A cube shifted, a(x + h)^3 = k written out, has D0 = b^2 - 3ac = 0, and then the square root is |D1|, so for a negative D1 the sum is 0 and C was 0. Every root was taken for -b/(3a), the branch for a triple root, none of them was a root, and the empty set that was left claimed there was none: (x + 1)^3 = 2 and 3x^3 + 9x^2 + 9x + 1 = 0 were answered { }. With D0 = 0, C is a cube root of D1 itself, and the roots are -(b + u C)/(3a), D0/C being 0. For a negative D1 it is written as the negative of the cube root of -D1, a cube root of D1 whichever root of a negative number a power is read as. Found by a cross-check of equations in logarithms, one of which exponentiates to 3x^3 + 9x^2 + 9x + 1. 2.6.0 answers them the same. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent b20a516 commit 9880e18

4 files changed

Lines changed: 78 additions & 2 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,18 @@ did, and `ln(x + 2) / ln(x + 3)` at 0 was `ln(2) / ln(3)`. With symbols it was n
128128
| `"limit(ln(a + 1/x) / ln(b + 1/x), x, +oo)".ToEntity().Simplify()` | `a / b` | `ln(a) / ln(b)` |
129129
| `"limit(ln(1 + x) / ln(y + x), x, 0)".ToEntity().Simplify()` | `1 / y` | `0 provided not ln(y) = 0` |
130130

131+
### A cube shifted is solved
132+
133+
**Silent: a cubic `a(x + h)^3 = k` written out, with `b^2 = 3ac`, is solved where it was answered `{ }`.** Cardano's
134+
`C^3` is `(D1 + sqrt(D1^2 - 4 D0^3)) / 2`, and with `D0 = 0` that is `(D1 + |D1|) / 2`, which is 0 for a negative `D1`.
135+
Every root was then taken for `-b/(3a)`, which is none, and the empty set claimed there was no root. With `D0 = 0`, `C` is a
136+
cube root of `D1` itself.
137+
138+
| Input | Was (2.6.0) | Now |
139+
|---|---|---|
140+
| `"(x + 1)^3 = 2".ToEntity().Solve("x")` | `{ }` | `{ -(3 + -3 * 2 ^ (1/3)) / 3, … }`, the three cube roots of 2 less 1 |
141+
| `"3x^3 + 9x^2 + 9x + 1 = 0".ToEntity().Solve("x")` | `{ }` | `{ -(9 + -3 * 18 ^ (1/3)) / 3 / 3, … }` |
142+
131143
### A quadratic whose discriminant is a square is answered without the root
132144

133145
**Silent: the same roots, written as what they are.** The quadratic formula wrote `sqrt(b^2 - 4ac)` whatever the

‎Sources/.editorconfig‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
9696
[Tests/UnitTests/Convenience/EmptySequenceFoldTest.cs]
9797
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
9898

99+
[Tests/UnitTests/Algebra/SolveTest/AShiftedCubeTest.cs]
100+
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
101+
99102
[Tests/UnitTests/Convenience/FoldEnumerationTest.cs]
100103
file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed under MIT.\nDetails: https://github.com/asc-community/AngouriMath/blob/master/LICENSE.md.\nWebsite: https://am.angouri.org.\n
101104

‎Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/PolynomialSolver.cs‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,23 @@ internal static IEnumerable<Entity> SolveCubic(Entity a, Entity b, Entity c, Ent
239239
var u3 = Rational.Create(-1, 2) - coeff;
240240
var D0 = MathS.Sqr(b) - 3 * a * c;
241241
var D1 = (2 * MathS.Pow(b, 3) - 9 * a * b * c + 27 * MathS.Sqr(a) * d).InnerSimplified;
242-
var C = MathS.Pow((D1 + MathS.Sqrt(MathS.Sqr(D1) - 4 * MathS.Pow(D0, 3))) / 2, Rational.Create(1, 3));
242+
// C is a cube root of either root of C^6 - D1 C^3 + D0^3 = 0, and only one that is not 0
243+
// can be divided by. With D0 = 0 those roots are D1 and 0, and the square root of D1^2
244+
// is |D1|, so for a negative D1 the sum below is 0: a(x + h)^3 = k, a cube shifted, had
245+
// C = 0 and every root taken for -b/(3a), which is none, and (x + 1)^3 = 2 was answered
246+
// { }. With D0 = 0 a cube root of D1 itself is C, and the roots are -(b + u C)/(3a),
247+
// D0/C being 0; that is -b/(3a) three times where D1 is 0 as well. For a negative D1 the
248+
// cube root is written as the negative of the cube root of -D1, which is a cube root of
249+
// D1 whichever root of a negative number a power is read as.
250+
var shifted = D0.Evaled == 0;
251+
var C = !shifted
252+
? MathS.Pow((D1 + MathS.Sqrt(MathS.Sqr(D1) - 4 * MathS.Pow(D0, 3))) / 2, Rational.Create(1, 3))
253+
: D1.Evaled is Real { IsNegative: true }
254+
? -MathS.Pow(-D1, Rational.Create(1, 3))
255+
: MathS.Pow(D1, Rational.Create(1, 3));
243256

244257
return new[] { u1, u2, u3 }.Select(uk =>
245-
C.Evaled == 0 && D0.Evaled == 0 ? -(b + uk * C) / 3 / a : -(b + uk * C + D0 / C / uk) / 3 / a);
258+
shifted ? -(b + uk * C) / 3 / a : -(b + uk * C + D0 / C / uk) / 3 / a);
246259
}
247260

248261
[ConstantField] private static readonly int[] sqrtsOf1 = { -1, 1 };
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
/// A cube shifted, <c>a(x + h)^3 = k</c>, has <c>D0 = b^2 - 3ac = 0</c>, and Cardano's
17+
/// <c>C^3 = (D1 + sqrt(D1^2 - 4 D0^3)) / 2</c> is then <c>(D1 + |D1|) / 2</c>, which is 0 for a
18+
/// negative <c>D1</c>. Every root was taken for <c>-b/(3a)</c>, none was one, and
19+
/// <c>(x + 1)^3 = 2</c> was answered <c>{ }</c>. Found by a cross-check of equations in
20+
/// logarithms, one of which exponentiates to <c>3x^3 + 9x^2 + 9x + 1</c>; no issue was filed.
21+
/// </summary>
22+
[Trait("Area", "Algebra")]
23+
public sealed class AShiftedCubeTest
24+
{
25+
[Theory]
26+
[InlineData("(x + 1)^3 = 2", "-1", "2")]
27+
[InlineData("x^3 + 3x^2 + 3x - 1 = 0", "-1", "2")]
28+
[InlineData("3x^3 + 9x^2 + 9x + 1 = 0", "-1", "2/3")]
29+
[InlineData("x^3 - 3x^2 + 3x - 3 = 0", "1", "2")]
30+
// D1 positive, which was answered: (x + 1)^3 = -2.
31+
[InlineData("x^3 + 3x^2 + 3x + 3 = 0", "-1", "-2")]
32+
public void ItsRootsAreTheCubeRootsShifted(string equation, string shift, string cube)
33+
{
34+
var answer = Assert.IsType<FiniteSet>(equation.ToEntity().Solve("x"));
35+
Assert.Equal(3, answer.Count);
36+
foreach (var unity in new[] { "1", "-1/2 + sqrt(3) / 2 * i", "-1/2 - sqrt(3) / 2 * i" })
37+
{
38+
// The real cube root of the cube, times each cube root of unity, shifted.
39+
var root = $"({shift}) + ({unity}) * sgn({cube}) * abs({cube})^(1/3)".ToEntity();
40+
Assert.Contains(answer, found => Number.IsZero((found - root).EvalNumerical()));
41+
}
42+
}
43+
44+
[Fact]
45+
public void ATripleRootIsStillOne()
46+
=> Assert.Equal("{ -1 }".ToEntity(), "x^3 + 3x^2 + 3x + 1 = 0".ToEntity().Solve("x"));
47+
}
48+
}

0 commit comments

Comments
 (0)