Skip to content
Open
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
20 changes: 20 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,26 @@ multiple of `pi/3` for large x, so no finite set answers them and they are left
| `"e^(-x) = sin(3x)".Solve("x")` | stack overflow after about 2.5 min | `{ x : e ^ (-x) = sin(3 * x) }`, 0.6 s |
| `"e^(-x) + sin(x)^3 = 3 sin(x) cos(x)^2".Solve("x")` | did not finish in 60 s | `{ x : e ^ (-x) + sin(x) ^ 3 = 3 * sin(x) * cos(x) ^ 2 }`, 0.8 s |

### A root of a modulus raised to a negative number has no roots

**Silent: a circle of non-roots becomes `{ }`.** A root of `abs(u)` is real and not negative, but raising
`sqrt(abs(x)) = -1` gives `abs(x) = 1`, and its roots `e^(i r)` were answered. Each was checked by substituting it, and a
family with a real parameter was not, so it was kept. Where `x` is only inside one modulus the equation depends on
`|u|` alone, which is the same at every member of such a family, so one member is now checked
([#2712](https://github.com/asc-community/AngouriMath/issues/2712)).

Measured over 90 equations of an even or fractional root of a modulus, on `409d68805` and on this branch: 27 answers
changed, each to `{ }` or to the old answer without its non-roots. Every root left was checked with mpmath.

| `.Solve("x")` | Was (`409d68805`) | Now |
|---|---|---|
| `sqrt(abs(x)) = -1` | `{ e ^ (i * r_1) provided r_1 in RR }` | `{ }` |
| `sqrt(abs(x - 4) - 3) = -5` | `{ 28 * e ^ (i * r_1) + 4 provided r_1 in RR }` | `{ }` |
| `sqrt(abs(x) + 1) = -1` | `{ 0 provided r_1 in RR }` | `{ }` |
| `abs(x)^(3/2) = -8` | `{ 4 * e ^ (i * r_1) provided r_1 in RR }` | `{ }` |
| `sqrt(abs(x)) = abs(x) - 2` | `{ e ^ (i * r_1) provided r_1 in RR, 4 * e ^ (i * r_1) provided r_1 in RR }` | `{ 4 * e ^ (i * r_1) provided r_1 in RR }` |
| `sqrt(abs(x)) = -abs(x)` | `{ 0 provided r_1 in RR, e ^ (i * r_1) provided r_1 in RR }` | `{ 0 provided r_1 in RR }` |

### The whole part of a large rational power is taken out

**Silent, in the printed form only.** A rational raised to a rational power was written as a whole part times a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,17 @@ private Set Bind(FiniteSet listed)
/// <summary>
/// <paramref name="root"/> at one member of its family: each symbol in it a whole
/// parameter minted in the scope open, put at the whole number nearest 0 in its set; or
/// <see langword="null"/> where a symbol is anything else.
/// <see langword="null"/> where a symbol is anything else. With
/// <paramref name="angles"/>, a real parameter, the angle a modulus is inverted with, is
/// put at 0 as well.
/// </summary>
internal static Entity? AtAMember(Entity root)
internal static Entity? AtAMember(Entity root, bool angles = false)
{
if (current is not { } scope)
return null;
foreach (var parameter in root.Vars.Distinct().ToList())
{
if (scope.SetOf(parameter) is not { } set || !IsWhole(set))
if (scope.SetOf(parameter) is not { } set || !(IsWhole(set) || angles && set == MathS.Sets.R))
return null;
Entity? value = null;
foreach (var candidate in Nearest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,13 @@ private static RootVerdict Verdict(Entity equation, Variable x, Entity root)
// members, as the principal root alone was before the family was written: a member
// that fails is evidence against the family, and one that passes proves nothing
// about the rest, so the family is kept. https://github.com/asc-community/AngouriMath/issues/2319
// So is a family the modulus is inverted into, |u| = c being u = c e^(i r) for every real r,
// where the equation has x only inside that one modulus: there it is a function of |u|,
// which is c at every member, so every member is a root or none is. Raising
// sqrt(abs(x)) = -1 gives abs(x) = 1, and e^(i r) was answered, whose members all have
// sqrt(abs(x)) = 1. https://github.com/asc-community/AngouriMath/issues/2712
if (root.Vars.Any())
return SolutionParameters.AtAMember(root) is { } member && !member.Vars.Any() && Verdict(equation, x, member) is var verdict and not RootVerdict.Kept
return SolutionParameters.AtAMember(root, angles: HasXOnlyInsideOneModulus(equation, x)) is { } member && !member.Vars.Any() && Verdict(equation, x, member) is var verdict and not RootVerdict.Kept
? verdict
: RootVerdict.Kept;
var substituted = equation.Substitute(x, root);
Expand Down Expand Up @@ -396,6 +401,31 @@ private static bool IsAWrittenInteger(Real part)
return part.EDecimal.IsFinite && part.EDecimal.Exponent.IsZero;
}

/// <summary>
/// Whether every <paramref name="x"/> in <paramref name="equation"/> is inside a modulus, and
/// every modulus with <paramref name="x"/> in it, outermost, is the same one.
/// </summary>
private static bool HasXOnlyInsideOneModulus(Entity equation, Variable x)
{
Entity? modulus = null;
bool Walk(Entity node)
{
if (node is Absf && node.ContainsNode(x))
{
modulus ??= node;
return modulus == node;
}
if (node == x)
return false;
var children = node.DirectChildren;
for (var i = 0; i < children.Count; i++)
if (!Walk(children[i]))
return false;
return true;
}
return Walk(equation) && modulus is not null;
}

/// <summary>What <see cref="WithoutSpuriousRoots"/> does with a root.</summary>
private enum RootVerdict
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// 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.Linq;
using AngouriMath;
using AngouriMath.Extensions;
using Xunit;
using static AngouriMath.Entity;

namespace AngouriMath.Tests.Algebra
{
/// <summary>
/// A root of a modulus is real and not negative, so raising <c>sqrt(abs(x)) = -1</c> to
/// <c>abs(x) = 1</c> adds the circle <c>e^(i r)</c>, none of whose members is a root. The equation
/// has <c>x</c> only inside the modulus, so one member decides the family.
/// https://github.com/asc-community/AngouriMath/issues/2712
/// </summary>
[Trait("Area", "Algebra")]
public sealed class ARadicalOfAModulusIsNeverNegativeTest
{
[Theory]
[InlineData("sqrt(abs(x)) = -1")]
[InlineData("sqrt(abs(x - 4) - 3) = -5")]
[InlineData("sqrt(abs(x)) + 1 = 0")]
[InlineData("sqrt(abs(x) + 1) = -1")]
[InlineData("2 sqrt(abs(x)) + 3 = 0")]
[InlineData("abs(x) ^ (1/4) = -1")]
[InlineData("abs(x) ^ (3/4) = -1")]
[InlineData("abs(x) ^ (3/2) = -8")]
[InlineData("sqrt(abs(x)) * abs(x) = -8")]
public void HasNoRoot(string equation)
=> Assert.Equal(Set.Empty, equation.ToEntity().Solve("x"));

// Each answer is one family, every member of which is a root: |x| = 4 and |x| = 0, and not
// the |x| = 1 and |x| = 1/4 the squares add.
[Theory]
[InlineData("sqrt(abs(x)) - abs(x) + 2", 4)]
[InlineData("sqrt(abs(x)) + 2 abs(x)", 0)]
[InlineData("sqrt(abs(x)) + abs(x)", 0)]
[InlineData("sqrt(abs(x)) - 2", 4)]
[InlineData("abs(x) ^ (3/2) - 8", 4)]
public void HasOneCircleOfRoots(string residual, int modulus)
{
var root = Assert.Single(Assert.IsType<Set.FiniteSet>(residual.ToEntity().Equalizes(0).Solve("x")));
foreach (var angle in new[] { "0", "1/3", "2", "-5/2" })
{
var member = root.Vars.Aggregate(root, (at, parameter) => at.Substitute(parameter, angle.ToEntity()));
Assert.Equal(0, ((Entity.Number.Complex)(MathS.Abs(member) - modulus).Evaled).Abs().EDecimal.ToDouble(), 12);
Assert.Equal(0, ((Entity.Number.Complex)residual.ToEntity().Substitute("x", member).Evaled).Abs().EDecimal.ToDouble(), 12);
}
}
}
}
Loading