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
23 changes: 23 additions & 0 deletions BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,29 @@ before v3, which decides exact comparisons exactly (#1019 §10). Two decimals th
| `sqrt(5)^1000 = 5^500` | `False` | stays written |
| `sqrt(2) < sqrt(2) + 10^(-150)` | `False` | stays written |

### A system keeps the solutions where it divided by zero

**Silent: an incomplete answer becomes the whole solution set, or no answer.** Solving a system that the Gröbner
basis does not take, such as one with fewer equations than unknowns or one that is not polynomial, an equation was solved for its last unknown by dividing by a coefficient in the
others, and the solutions where that coefficient is zero were dropped. A factor free of that unknown is now
solved apart, and where the leading coefficient can be zero the system is solved again with it zero. Where a
root divides by another unknown and that case cannot be solved, the system is declined. Measured on master
`9b75a2678` and on this branch ([#2738](https://github.com/asc-community/AngouriMath/issues/2738)).

| `MathS.Equations(...).Solve(...)` | Was (master) | Now |
|---|---|---|
| `x*y - x` for `x, y` | `[[t_1, t_1 / t_1]]` | `[[0, t_1], [t_2, 1]]` |
| `x*y - x` for `y, x` | `[[t_1, 0]]` | `[[1, t_1], [t_2, 0]]` |
| `x^2 + x*y - x + y - 2` for `x, y` | `[[t_1, -(t_1 ^ 2 + -t_1 + -2) / (t_1 + 1)]]` | `[[-1, t_1], [t_2, -(t_2 + -2)]]` |
| `x*z + 2*x`, `y - 2` for `x, y, z` | `[[t_1, 2, -2 * t_1 / t_1]]` | `[[0, 2, t_1], [t_2, 2, -2]]` |
| `x*z + y` for `x, y, z` | `[[t_1, t_2, -t_2 / t_1]]` | `[[t_2, t_3, -t_3 / t_2], [0, 0, t_1]]` |
| `sin(x)*y - sin(x)` for `x, y` | `[[t_1, sin(t_1) / sin(t_1)]]` | `[[t_2, sin(t_2) / sin(t_2)], [2 * pi * n_1, t_1], [pi + 2 * pi * n_1, t_1]]` |
| `y^x - 2` for `x, y` | `[[t_1, 2 ^ (1 / t_1)]]` | `null` |
| `x*y - x`, `2*x*y - 2*x` for `x, y` | `[[t_1, t_1 / t_1]]` | `[[0, t_1], [0, 1], [t_1, 1]]` |
| `sin(x)*y - sin(x)`, `x - y` for `x, y` | `[[1, 1]]` | `[[2 * pi * n_1, 2 * pi * n_1], [pi + 2 * pi * n_1, pi + 2 * pi * n_1], [1, 1]]` |
| `sqrt(2)*x*y - sqrt(2)*x`, `x^2 + y - 4` for `x, y` | `[[sqrt(3), 1], [-sqrt(3), 1]]` | `[[0, 4], [sqrt(3), 1], [-sqrt(3), 1]]` |
| `e^x*y - 2*e^x + x*y - 2*x`, `x - y` for `x, y` | `[[2, 2]]`, without `x = y = -W(1)` | `null` |

### A square system is answered exactly whichever order its equations are in

**Not silent: a decimal answer is now exact, and a refused system has an answer.** The eliminator took the last
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,27 @@ private static Entity AtASamplePoint(Entity residual, HashSet<Variable> own)
return NonSquareSystemSolver.Solve(constraining, unknowns, ledger);
equations = constraining;
}
// A factor free of the last unknown is solved apart from what is left of its equation,
// as NonSquareSystemSolver does: x y - x, x + y - 3 solved for y as x/x left out (0, 3).
// A branch can leave an unknown that no equation mentions, which is that solver's shape.
// https://github.com/asc-community/AngouriMath/issues/2738
if (ledger is not null && NonSquareSystemSolver.FactorFreeOfTheLast(equations, vars.ToArray(), vars.Length) is var (at, factor, remainder))
{
var all = new List<List<Entity>>();
foreach (var part in new[] { factor, remainder })
{
var branch = new List<Entity>(equations);
branch[at] = part;
var unknowns = vars.ToArray();
var rows = unknowns.Any(unknown => !branch.Any(equation => equation.ContainsNode(unknown)))
? NonSquareSystemSolver.SolveOrNone(branch, unknowns, ledger)
: InSolveSystem(branch, vars, nameSource, ledger);
if (rows is null)
return null;
all.AddRange(rows);
}
return all;
}
var var = vars[^1];
if (equations.Count == 1)
{
Expand Down Expand Up @@ -536,7 +557,24 @@ private static Entity AtASamplePoint(Entity residual, HashSet<Variable> own)

var result = new List<List<Entity>>();
var told = true;
foreach (var sol in sols)
// The roots divide by the leading coefficient in `var`, and where it can be
// zero that case is solved apart, as NonSquareSystemSolver does; roots that
// cannot be told complete leave the candidate undecided.
// https://github.com/asc-community/AngouriMath/issues/2738
if (ledger is not null)
{
var unknowns = vars.ToArray();
if (!NonSquareSystemSolver.RootsAreComplete(equations[i], unknowns, unknowns.Length, sols, rest, out var degenerate))
told = false;
else if (degenerate is not null)
{
if (NonSquareSystemSolver.SolveOrNone(degenerate, unknowns, ledger, generic: true) is { } found)
result.AddRange(found);
else
told = false;
}
}
foreach (var sol in told ? sols : new List<Entity>())
{
var below = rest.Select(eq => eq.Substitute(var, sol)).ToList();
if (InSolveSystem(below, remainingVars, nameSource, ledger) is not { } rows)
Expand Down
Loading
Loading