diff --git a/BREAKING-CHANGES.md b/BREAKING-CHANGES.md index fad9d71b9..e4ccd9325 100644 --- a/BREAKING-CHANGES.md +++ b/BREAKING-CHANGES.md @@ -498,6 +498,25 @@ only in decimals, is answered as before ([#2607](https://github.com/asc-communit | `2^x + 2^y - 8`, `x - y` | `null` | `[[2 + 2 * pi * i * n_1 / ln(2), …]]` | | `x - y`, `ln(x) + ln(y) - 1` | `[[sqrt(e), sqrt(e)]]` | unchanged | +### A family of roots through n = 0 is kept, and its undefined member left out + +**Silent: missing real roots come back.** Solving `f(g(x)) = c` for a periodic `f` gives a family `c n` with +no offset, whose member at `n = 0` is `1/0` through a reciprocal and has `arg(0)` in its condition through a +root. A family is checked at one member, and that member dropped it whole: `tan(1/x) = 0` was `{ }`. Through a +reciprocal the family now runs over `n in ZZ \ { 0 }`, so `cos(pi/x) = 1` no longer lists `pi/0`. Measured on +master (409d68805) and on this branch +([#2710](https://github.com/asc-community/AngouriMath/issues/2710)). + +| `.Solve("x")` | Was (master) | Now | +|---|---|---| +| `tan(1/x) = 0` | `{ }` | `union({ 1 / (pi * n) }, n in ZZ \ { 0 })` | +| `sin(1/x) = 0` | `union({ 1 / (pi + 2 * pi * n) }, n in ZZ)` | `union({ 1 / (2 * pi * n) }, n in ZZ \ { 0 }) \/ union({ 1 / (pi + 2 * pi * n) }, n in ZZ)` | +| `cos(pi/x) = 1` | `union({ pi / (2 * pi * n) }, n in ZZ)` | `union({ pi / (2 * pi * n) }, n in ZZ \ { 0 })` | +| `cos(sqrt(x)) = 1` | `{ }` | `union({ (2 * pi * n) ^ 2 provided 2 * pi * n = 0 or -1/2 * pi < arg(2 * pi * n) and arg(2 * pi * n) <= 1/2 * pi }, n in ZZ)` | +| `e^(sqrt(x)) = 1` | `{ }` | `union({ (2 * pi * i * n) ^ 2 provided 2 * pi * i * n = 0 or -1/2 * pi < arg(2 * pi * i * n) and arg(2 * pi * i * n) <= 1/2 * pi }, n in ZZ)` | +| `cos(x^(1/3)) = 1` | `{ }` | `union({ (2 * pi * n) ^ 3 provided 2 * pi * n = 0 or -1/3 * pi < arg(2 * pi * n) and arg(2 * pi * n) <= 1/3 * pi or arg(2 * pi * n) = pi }, n in ZZ)` | +| `cos(x^(2/3)) = 1` | `union({ -(2 * pi * n) ^ (3/2) provided 2 * pi * n > 0 }, n in ZZ)` | `union({ (2 * pi * n) ^ (3/2) provided 2 * pi * n = 0 or -2/3 * pi < arg(2 * pi * n) and arg(2 * pi * n) <= 2/3 * pi, -(2 * pi * n) ^ (3/2) provided 2 * pi * n > 0 }, n in ZZ)` | + ### An odd root of a negative number is real with downcasting off as well **Silent, with `MathS.Settings.DowncastingEnabled` off only.** An odd root of a negative number is the real one: diff --git a/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/InvertNode.Classes.cs b/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/InvertNode.Classes.cs index 44898e18d..e9b3be4c3 100644 --- a/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/InvertNode.Classes.cs +++ b/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/InvertNode.Classes.cs @@ -99,8 +99,11 @@ partial record Divf Dividend.ContainsNode(x) // x / a = value => x = a * value ? Dividend.Invert(value * Divisor, x) - // a / x = value => x = a / value - : Divisor.Invert(Dividend / value, x); + // a / x = value => x = a / value, where value is not 0, which a / x never is for + // a number a other than 0: tan(1/x) = 0 is 1/x = pi n, so x = 1/(pi k) for a whole + // k other than 0, and the family was dropped whole for its member 1/0. + // https://github.com/asc-community/AngouriMath/issues/2710 + : Divisor.Invert(Dividend / (Dividend.Evaled is Complex { IsZero: false } ? Powf.WhereAPowerCanBe(value, false) : value), x); } partial record Modf @@ -150,8 +153,14 @@ partial record Powf return null; if (pow.Sign < 0 && value.Evaled is Complex { IsZero: true }) return Enumerable.Empty(); + // And x^(-2) = 2 pi n is the same away from n = 0. + // https://github.com/asc-community/AngouriMath/issues/2710 + if (pow.Sign < 0) + value = WhereAPowerCanBe(value, false); return Together(Number.GetAllRootsOf1(pow.Abs()).Select(root => Base.Invert(root * MathS.Pow(value, 1 / Exponent), x))); } + if (Exponent.Evaled is Real { IsNegative: true }) + value = WhereAPowerCanBe(value, false); var principal = Base.Invert(MathS.Pow(value, 1 / Exponent), x) ?.Select(root => root.Provided(InTheRange(value))); // With an even numerator a negative base has a positive power, (-8)^(2/3) = 4, @@ -211,7 +220,7 @@ partial record Powf /// another root, as the two of a sine are. /// https://github.com/asc-community/AngouriMath/issues/2319 /// - private static Entity WhereAPowerCanBe(Entity value, bool positive) + internal static Entity WhereAPowerCanBe(Entity value, bool positive) { if (SolutionParameters.Current is not { } scope) return value; diff --git a/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/SolveStatement.cs b/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/SolveStatement.cs index df9698c17..9a3976181 100644 --- a/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/SolveStatement.cs +++ b/Sources/AngouriMath/Functions/Continuous/Solvers/EquationSolver/SolveStatement.cs @@ -669,10 +669,23 @@ internal static bool IsUndefinedExactly(Entity substituted) { static bool IsExact(Entity argument) => argument.Evaled is Complex value && value.RealPart is Rational && value.ImaginaryPart is Rational; - foreach (var node in substituted.Nodes) + // A connective that is decided is decided whatever has no value under it: the condition + // (2 pi n) ^ 2 is provided at n = 0, 0 = 0 or -pi/2 < arg(0) <= pi/2, is true, and the + // arg(0) in it dropped the family of cos(sqrt(x)) = 1 whole. + // https://github.com/asc-community/AngouriMath/issues/2710 + var pending = new Stack(); + pending.Push(substituted); + while (pending.Count > 0) + { + var node = pending.Pop(); + if (node is Orf or Andf or Impliesf && node.Evaled is Entity.Boolean) + continue; if (node.DirectChildren.Count > 0 && node.DirectChildren.All(IsExact) && node.Evaled is Complex { IsFinite: false }) return true; + foreach (var child in node.DirectChildren) + pending.Push(child); + } return false; } diff --git a/Sources/Tests/UnitTests/Algebra/SolveTest/AFamilyThroughZeroIsKeptTest.cs b/Sources/Tests/UnitTests/Algebra/SolveTest/AFamilyThroughZeroIsKeptTest.cs new file mode 100644 index 000000000..9bd75e1bc --- /dev/null +++ b/Sources/Tests/UnitTests/Algebra/SolveTest/AFamilyThroughZeroIsKeptTest.cs @@ -0,0 +1,74 @@ +// +// 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 AngouriMath; +using AngouriMath.Extensions; +using System.Linq; +using Xunit; +using static AngouriMath.Entity; +using static AngouriMath.Entity.Set; + +namespace AngouriMath.Tests.Algebra.SolveTest +{ + /// + /// A family of roots c n, with no offset, has its member at n = 0 where the + /// periodic function is 0 or 1. Through 1/u that member is 1/0, and through a root + /// it carries arg(0) in its condition; a family is judged by that member, and both + /// dropped it whole: tan(1/x) = 0 and cos(sqrt(x)) = 1 were { }. And + /// cos(pi/x) = 1 kept its family with the member pi/0 in it. + /// https://github.com/asc-community/AngouriMath/issues/2710 + /// + [Trait("Area", "Algebra")] + public sealed class AFamilyThroughZeroIsKeptTest + { + private static Set Solve(string statement) => statement.ToEntity().Solve("x"); + + [Theory] + [InlineData("tan(1/x) = 0", "1/pi", "-1/pi", "1/(3pi)")] + [InlineData("cos(1/x) = 1", "1/(2pi)", "-1/(2pi)", "1/(4pi)")] + [InlineData("sin(1/x) = 0", "1/(2pi)", "-1/(2pi)", "1/pi")] + [InlineData("cos(1/x^2) = 1", "sqrt(1/(2pi))", "-sqrt(1/(2pi))", "-sqrt(1/(4pi))")] + [InlineData("cos(sqrt(x)) = 1", "0", "4pi^2", "16pi^2")] + [InlineData("tan(sqrt(x)) = 0", "0", "pi^2", "4pi^2")] + [InlineData("sin(sqrt(x)) = 0", "0", "pi^2", "4pi^2")] + [InlineData("sin(sqrt(x + 1)) = 0", "-1", "pi^2 - 1", "4pi^2 - 1")] + [InlineData("cos(1/sqrt(x)) = 1", "1/(4pi^2)", "1/(16pi^2)", "1/(36pi^2)")] + // An odd root of a negative real is real, (-8)^(1/3) = -2. + [InlineData("cos(x^(1/3)) = 1", "0", "8pi^3", "-8pi^3")] + [InlineData("cos(x^(-1/3)) = 1", "1/(8pi^3)", "-1/(8pi^3)", "1/(64pi^3)")] + // And x^(2/3) of a negative real is the square of its real cube root, (-8)^(2/3) = 4. + [InlineData("cos(x^(2/3)) = 1", "0", "(2pi)^(3/2)", "-(2pi)^(3/2)")] + [InlineData("tan(x^(2/3)) = 0", "0", "pi^(3/2)", "-pi^(3/2)")] + public void EveryRootIsInTheAnswer(string equation, string root, string other, string third) + { + var solved = Solve(equation); + foreach (var value in new[] { root, other, third }) + Assert.True(value.ToEntity().In(solved).Simplify() == Entity.Boolean.True, + $"{value} is a root of {equation}, missing from {solved.Stringize()}"); + } + + [Fact] + public void ARootOfAPowerOfERootIsKept() + => Assert.Equal(Entity.Boolean.True, "0".ToEntity().In(Solve("e^(sqrt(x)) = 1")).Simplify()); + + /// Every member of a family through a reciprocal is a number: none is 1/0. + [Theory] + [InlineData("cos(pi/x) = 1")] + [InlineData("cosh(pi/x) = 1")] + [InlineData("e^(pi/x) = 1")] + [InlineData("tan(pi/x) = 0")] + [InlineData("tan(1/x) = 0")] + [InlineData("cos(1/x^2) = 1")] + public void NoMemberIsUndefined(string equation) + { + var members = Solve(equation).Members(-3, -2, -1, 0, 1, 2, 3); + Assert.NotEmpty(members); + Assert.All(members, member => + Assert.True(member.Evaled is Number.Complex { IsFinite: true }, $"{member.Stringize()} has no value")); + } + } +}