Skip to content

Simplify Conjunctions#182

Merged
rcosta358 merged 3 commits intomainfrom
simplify-conjunctions
Mar 28, 2026
Merged

Simplify Conjunctions#182
rcosta358 merged 3 commits intomainfrom
simplify-conjunctions

Conversation

@rcosta358
Copy link
Copy Markdown
Collaborator

This PR adds a small simplification to avoid duplicate conjunctions in predicates, which made error messages redundant and harder to read.

To fix this, before creating a conjunction with two predicates, it recursively checks whether the second operand is already present in the first operand conjunctions. If so, the first one is returned.

Example

Before

#b_2 == #b_1 + 100 && #b_1 == b && b > 0 && b > 0 

After

#b_2 == #b_1 + 100 && #b_1 == b && b > 0

After with #181

#b_2 == b + 100 && b > 0

@rcosta358 rcosta358 self-assigned this Mar 17, 2026
@rcosta358 rcosta358 added enhancement New feature or request simplification Related to the simplification of expressions labels Mar 17, 2026
}

private static boolean containsConjunct(Predicate c1, Predicate c2) {
if (c1.toString().equals(c2.toString()))
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used string comparison instead of equals() to handle inconsistent GroupExpression wrapping.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets juts add this to the javadoc so we know in the future

}

@Override
public boolean equals(Object obj) {
Copy link
Copy Markdown
Collaborator Author

@rcosta358 rcosta358 Mar 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added missing equals() for predicates anyway.

Copy link
Copy Markdown
Collaborator

@CatarinaGamboa CatarinaGamboa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor changes

}

private static boolean containsConjunct(Predicate c1, Predicate c2) {
if (c1.toString().equals(c2.toString()))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets juts add this to the javadoc so we know in the future

@rcosta358 rcosta358 merged commit a2f5975 into main Mar 28, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request simplification Related to the simplification of expressions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants