Skip to content

Propagate Expressions#215

Merged
rcosta358 merged 5 commits into
mainfrom
improve-simplification
May 11, 2026
Merged

Propagate Expressions#215
rcosta358 merged 5 commits into
mainfrom
improve-simplification

Conversation

@rcosta358
Copy link
Copy Markdown
Collaborator

@rcosta358 rcosta358 commented May 9, 2026

Description

This PR enables the propagation of expressions, instead of only literals or other variables.
With this, we can propagate all the following: var == literal, var == var, and now var == expression.
For example, the assignment x == y + 1 now adds the mapping x → y + 1, allowing the RHS to be propagated wherever x appears.

Example

Before

Refinement Error: #ret³ == y² - 2 && y² == x + 1 is not a subtype of #ret³ > 0

After

Refinement Error: #ret³ == x - 1 is not a subtype of #ret³ > 0

Related Issue

None.

Type of change

  • Bug fix
  • New feature
  • Documentation update
  • Code refactoring

Checklist

  • Added tests in ExpressionSimplifierTest
  • mvn test passes locally
  • Updated docs/README if behavior or API changed

@rcosta358 rcosta358 requested a review from CatarinaGamboa May 9, 2026 21:44
@rcosta358 rcosta358 self-assigned this May 9, 2026
@rcosta358 rcosta358 added enhancement New feature or request simplification Related to the simplification of expressions labels May 9, 2026
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.
For you thesis, you should plan to write a pseudo-code algorithm of how simplification of expressions works with all the steps and additions you have been making.

return null;

int signedLeft = "+".equals(leftBinary.getOperator()) ? leftLiteral.getValue() : -leftLiteral.getValue();
int signedRight = "+".equals(op) ? rightLiteral.getValue() : -rightLiteral.getValue();
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.

overflows? maybe just an if checking its fine

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.

Good catch. I think that can happen in more places, not just here. Will fix it in a follow-up PR.

return null;
if (!(rightNode.getValue()instanceof LiteralInt rightLiteral))
return null;
if (!(leftNode.getValue()instanceof BinaryExpression leftBinary))
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.

nit spacee between method and instanceof

@rcosta358 rcosta358 merged commit 0de6d8f into main May 11, 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