Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FullSimplify does not eliminate factors that can be eliminated #1104

Open
HannesWell opened this issue Nov 25, 2024 · 3 comments
Open

FullSimplify does not eliminate factors that can be eliminated #1104

HannesWell opened this issue Nov 25, 2024 · 3 comments

Comments

@HannesWell
Copy link
Collaborator

Describe the bug

Applying FullSimplify or just Simplify to an expression does not always eliminate factors even if it would be possible.

To Reproduce

Steps to reproduce the behavior:

Example input Symja input expression:

>> FullSimplify(a-Max(x1*a,x2*a)==0)

Undesired result:

−Max(a⋅x1,a⋅x2)+a==0

Expected behavior

Expected (correct) result expression:

1−Max(x1,x2)==0

But the problem seems not to be limited to non-continuous functions like Min or Max, even for simpler expressions like

>>FullSimplify(a-x1*a==0)

the result is -a*x1+a==0, while it could be -x1+1==0.

@axkr
Copy link
Owner

axkr commented Nov 25, 2024

What if a is a negative number and x1, x2 are positive numbers?

@HannesWell
Copy link
Collaborator Author

That would indeed change Min respectively Max to the opposite.

But even the simple case

>>FullSimplify(a-x1*a==0)

does not result in a simplification, even the sign does not matter. The only problem would be a==0.
If I use assumptions:

FullSimplify(a-x1*a==0, Assumptions -> a>0)

the result is still -a*x1+a==0.
Or am I doing something wrong?

axkr added a commit that referenced this issue Nov 27, 2024
 `Simplify(a-a*b-a*c) -> a*(1-b-c)`
 `Simplify(a-a*b+a*c) -> a*(1-b+c)`
@axkr
Copy link
Owner

axkr commented Nov 27, 2024

With the last commit Simplify is more consistent with factoring out common factors from a Plus expression:

  • Simplify(a-a*b-a*c) -> a*(1-b-c)
  • Simplify(a-a*b+a*c) -> a*(1-b+c)

Note: Simplify determines the "simplicity" with a variant of the function LeafCount:

Unfortunately for the system the following expression determine the following leaf counts:

  • LeafCount(a-a*b) -> 6
  • LeafCount(a*(1-b)) ->7

so that Simplify(a*(1-b)) will not be considered as "simpler" and not be transformed.

Thereas this expression will be transformed by Simplify, because it has the same leaf count:

  • LeafCount(a+a*b) -> 5
  • LeafCount(a*(1+b)) -> 5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants