Skip to content

Commit 09a132d

Browse files
A radical times a power of its variable is solved as one fractional power (#2323)
An equation in sqrt(x), or a cube root of x, beside powers of x is solved by raising the radical's side to a power, and FractionedPolynoms looks for each fractional power first. The power rules write x * sqrt(x) as x ^ (1/2 + 1), and it matched only an exponent that was already a number, so a term with an exponent written as a sum was no fractional power. Such equations, including every c/x cleared of its denominator, went to Newton's method, which answered in decimals, missed roots, and kept numbers that are not roots: sqrt(x) - 1/x - 1 - i = 0 was answered with one decimal root and without -1. The exponent is now folded before it is read. A power past one is then read as a whole power times a proper fractional one, x^(3/2) as x * sqrt(x), so it shares the radical of sqrt(x): 3 sqrt(x) - x^(3/2) is the one term (3 - x) sqrt(x), where read as sqrt(x) and sqrt(x^3) it would be two radicals that cannot be raised together. Raising keeps every root whichever root is taken, since (x^(p/q))^q is x^p, and the solution check removes what it adds. Generated equations of this shape (e387 radcheck, powers-of-x mode, 200 at seed 31): 2.6.0 missed 45 roots in 22 equations and answered 5 numbers that are not roots; master before this, 37 in 20 and 4; now 2 and 0. The default mode, 400 equations in roots of polynomials at seed 21, is unchanged: the same 39 sums of two radicals left unsolved on both builds, and no root missed or wrong on either. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent d6e8427 commit 09a132d

4 files changed

Lines changed: 100 additions & 2 deletions

File tree

‎BREAKING-CHANGES.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,26 @@ 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 radical times a power of its variable is solved exactly
132+
133+
**Silent: an equation in `sqrt(x)` or a cube root of `x` beside powers of `x` is answered in radicals and with all its
134+
roots, where it was answered in decimals and could miss roots or include a number that is not one.** Such an equation is
135+
solved by raising the radical's side to a power, and the solver looks for each fractional power before doing it. The
136+
power rules write `x * sqrt(x)` as `x ^ (1/2 + 1)`, and an exponent written as a sum was not read as a fractional power.
137+
Equations with that term, which includes any `c/x` cleared of its denominator, went to Newton's method. It answered in
138+
decimals, and in `sqrt(x) - 1/x - 1 - i = 0` it found one root and missed the root -1. The exponent is now folded, and a
139+
power past one is read as a whole power times a proper fractional one, so `x^(3/2)` shares the radical of `sqrt(x)`. One
140+
answer that was exact is spelled differently. No issue was filed; a check of systems built from known solutions met this
141+
equation after an elimination. On 200 generated equations of this shape, 2.6.0 missed 45 roots in 22 of them and
142+
answered 5 numbers that are not roots. Now 2 roots are missing and none is wrong.
143+
144+
| Input | Was (2.6.0) | Now |
145+
|---|---|---|
146+
| `"sqrt(x) - 1/x - 1 - i = 0".Solve("x")` | `{ 1.3002… + 1.6248…i }` | `-1` and that root in radicals |
147+
| `"sqrt(x) + 1/x = 0".Solve("x")` | `{ -0.5 - 0.8660…i, -0.5 + 0.8660…i }` | `{ -1/2 + i * 1/2 * sqrt(3), -1/2 + i * -1/2 * sqrt(3) }` |
148+
| `"sqrt(x) - 1/x - 1 = 0".Solve("x")` | `{ 2.1478… }` | that root in radicals |
149+
| `"(3 - x)*sqrt(x) - x = 0".Solve("x")` | `{ 0, (7 - sqrt(13)) / 2 }` | `{ 0, (-7 + sqrt(13)) / (-2) }` |
150+
131151
### A cube shifted is solved
132152

133153
**Silent: a cubic `a(x + h)^3 = k` written out, with `b^2 = 3ac`, is solved where it was answered `{ }`.** Cardano's

‎Sources/.editorconfig‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ file_header_template=\nCopyright (c) 2019-2026 Angouri.\nAngouriMath is licensed
6666
[Tests/UnitTests/Algebra/SolveTest/AQuotientIsZeroWhereItsNumeratorIsTest.cs]
6767
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
6868

69+
[Tests/UnitTests/Algebra/SolveTest/ARadicalTimesAPowerTest.cs]
70+
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
71+
6972
[Tests/UnitTests/Core/FactorialCacheIsThreadSafeTest.cs]
7073
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
7174

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77

88
using AngouriMath.Core.Multithreading;
9+
using PeterO.Numbers;
910

1011
namespace AngouriMath.Functions.Algebra.AnalyticalSolving
1112
{
@@ -34,15 +35,34 @@ internal static bool TrySolve(Entity expr, Variable x, out Set dst)
3435
potentialFraction.fracs = new List<(Entity main, Integer pow)>();
3536
foreach (var mpChild in Mulf.LinearChildren(child))
3637
{
37-
if (!(mpChild is Powf(var @base, Number num and not Integer))) // (x + 3) ^ 3
38+
// The exponent is folded first: the power rules write x * sqrt(x) as x ^ (1/2 + 1),
39+
// whose exponent is a sum, and read as it stands that was no fractional power, so
40+
// sqrt(x) - 1/x - 1 - i = 0, cleared of its denominator, went to Newton's method and
41+
// was answered without its root -1.
42+
if (!(mpChild is Powf(var @base, var exponent) && exponent.InnerSimplified is Number num and not Integer)) // (x + 3) ^ 3
3843
{
3944
potentialFraction.multiplier *= mpChild;
4045
continue;
4146
}
4247
if (num is not Rational fracNum)
4348
return false; // (x + 1)^0.2348728
44-
var newChild = MathS.Pow(@base, fracNum.ERational.Numerator).InnerSimplified;
49+
// A power past one is a whole power times a proper fractional one, x^(3/2) being
50+
// x * sqrt(x), so it shares its radical with sqrt(x): 3 sqrt(x) - x^(3/2) is the one
51+
// term (3 - x) sqrt(x), where read as sqrt(x) and sqrt(x^3) it was two radicals that
52+
// cannot be raised together, and the equation went to Newton's method without its
53+
// root 0. Raising to the power keeps every root whichever root is taken, since
54+
// (x^(p/q))^q is x^p, and the roots it adds are not the equation's.
4555
var den = fracNum.ERational.Denominator;
56+
var whole = fracNum.ERational.Numerator.Divide(den);
57+
var rest = fracNum.ERational.Numerator.Subtract(whole.Multiply(den));
58+
if (rest.Sign < 0)
59+
{
60+
whole = whole.Subtract(EInteger.One);
61+
rest = rest.Add(den);
62+
}
63+
if (!whole.IsZero)
64+
potentialFraction.multiplier *= MathS.Pow(@base, Integer.Create(whole));
65+
var newChild = MathS.Pow(@base, Integer.Create(rest)).InnerSimplified;
4666
potentialFraction.fracs.Add((newChild, den));
4767

4868
MultithreadingFunctional.ExitIfCancelled();
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 System.Linq;
9+
using AngouriMath.Extensions;
10+
using PeterO.Numbers;
11+
using Xunit;
12+
using static AngouriMath.Entity;
13+
using static AngouriMath.Entity.Number;
14+
15+
namespace AngouriMath.Tests.Algebra
16+
{
17+
/// <summary>
18+
/// An equation in <c>sqrt(x)</c> and <c>x</c> is solved by raising the radical's side to a power.
19+
/// Cleared of its denominator, <c>sqrt(x) - 1/x - 1 - i = 0</c> holds <c>x * sqrt(x)</c>, which
20+
/// the power rules write as <c>x ^ (1/2 + 1)</c>; read with its exponent a sum, that was no
21+
/// fractional power, and the equation went to Newton's method, which answered one decimal root
22+
/// and not the other, -1. A power past one is read as a whole power times a proper fractional
23+
/// one, so <c>x^(3/2)</c> shares its radical with <c>sqrt(x)</c>. Found by a check of systems
24+
/// built from known solutions, which met this equation after an elimination; no issue was filed.
25+
/// </summary>
26+
[Trait("Area", "Algebra")]
27+
public sealed class ARadicalTimesAPowerTest
28+
{
29+
[Theory]
30+
[InlineData("sqrt(x) - 1/x - 1 - i = 0", "sqrt(x) - 1/x - 1 - i", 2, "-1")]
31+
[InlineData("x*sqrt(x) - 1 - (1 + i)*x = 0", "x*sqrt(x) - 1 - (1 + i)*x", 2, "-1")]
32+
// 3 sqrt(x) - x^(3/2) is the one term (3 - x) sqrt(x). Read as sqrt(x) and sqrt(x^3), two
33+
// radicals, it cannot be raised to a power, and Newton's method finds no root 0.
34+
[InlineData("(3 - x)*sqrt(x) - x = 0", "(3 - x)*sqrt(x) - x", 2, "0")]
35+
[InlineData("x^2*sqrt(x) + 3*sqrt(x) + 2*x = 0", "x^2*sqrt(x) + 3*sqrt(x) + 2*x", 3, "0")]
36+
// s^3 + 1 = 0 in s = sqrt(x): the two roots with a principal square root, and not s = -1.
37+
[InlineData("sqrt(x) + 1/x = 0", "sqrt(x) + 1/x", 2, "-1/2 + sqrt(3)/2 * i")]
38+
// s^3 - s^2 - 1 = 0: the real root only, as the other two have a negative real part.
39+
[InlineData("sqrt(x) - 1/x - 1 = 0", "sqrt(x) - 1/x - 1", 1, null)]
40+
public void EveryRootIsExactAndSatisfiesTheEquation(string equation, string residual, int count, string? among)
41+
{
42+
var roots = Assert.IsType<Set.FiniteSet>(equation.ToEntity().Solve("x"));
43+
Assert.Equal(count, roots.Count);
44+
foreach (var root in roots)
45+
{
46+
Assert.True(root.Nodes.OfType<Complex>().All(number => number.RealPart is Rational && number.ImaginaryPart is Rational),
47+
$"{root} is in decimals");
48+
var value = residual.ToEntity().Substitute("x", root).EvalNumerical();
49+
Assert.True(Complex.Abs(value).EDecimal.CompareTo(EDecimal.FromString("1E-20")) < 0, $"{root} leaves {value}");
50+
}
51+
if (among is { })
52+
Assert.Contains(roots, root => (root - among.ToEntity()).Simplify() == 0);
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)