|
| 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