Skip to content

Incomplete Simplification (Factoring) and Equality Check #531

Closed

Description

@jclapis

The version I use:
AngouriMath v1.3.0 from NuGet

Unexpected behaviour or bug:
I have the following expression:

Entity expr = "a*c + a*d + b*c + b*d";

When I call Simplify() on it, it becomes the following:

a * (c + d) + b * c + b * d

I would expect it to be the reduced form ((a + b) * (c + d)). Normally this wouldn't be a problem, but testing for equality between these two fails unless they are both in their maximally expanded forms:

Entity expr = "a*c + a*d + b*c + b*d";
Entity expr2 = "(a + b) * (c + d)";
Entity eq = new Entity.Equalsf(expr, expr2);
eq = eq.Simplify();
Console.WriteLine(eq); // Prints "a * (c + d) + b * c + b * d = (a + b) * (c + d)"

expr2 = expr2.Expand();
eq = new Entity.Equalsf(expr, expr2);
eq = eq.Simplify();
Console.WriteLine(eq); // Prints "true"

We require this equality check to function properly, and (hopefully) fixing this simplification bug will make that work.

Activity

  1. added this to the 1.4 milestone on Oct 7, 2021
  2. Rafael-SOWNet commented on Aug 5, 2026

    @Rafael-SOWNet
    Member

    Both halves of this work on master now.

    simplify(a*c + a*d + b*c + b*d)                          =>  (a + b) * (c + d)
    simplify(a*c + a*d + b*c + b*d = (a + b) * (c + d))      =>  True
    

    The cause of the first: the factoring rules only ever looked at two adjacent terms of the sum tree, so a sum of four was left half-factored at a*(c + d) + b*c + b*d. Collection now runs over the whole sum rather than pairwise, and the equality check falls out of it -- both sides reach the same form, so Equalsf(...).Simplify() is True without expanding by hand first.

    Regression tests are in SimplificationRegressionTest.Issue531_TermsCollectOverTheWholeSum and Issue531_CollectionPreservesValue, the second of which checks the collected form is still the same expression rather than just a tidier-looking one.

    Closing.

  3. added theissue type on Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions