Skip to content

Add VC Folding Simplification#250

Open
rcosta358 wants to merge 39 commits into
mainfrom
vc-folding
Open

Add VC Folding Simplification#250
rcosta358 wants to merge 39 commits into
mainfrom
vc-folding

Conversation

@rcosta358

Copy link
Copy Markdown
Collaborator

Description

This PR adds VC simplification for foldable expressions through VCImplication chains. When a refinement contains constant arithmetic, boolean expressions, conditionals, adjacent integer constants, or resolved enum literals, it folds the VC node while preserving its origin and the rest of the VC chain.

It also adds focused unit tests for both the VC folding alone and the VC simplification with both the substitution and folding.

Example

1 + 2 > 0

is simplified to

3 > 0

with origin 1 + 2 > 0

and then simplified to

true

with origin 3 > 0

Related Issue

None.

Type of change

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

Checklist

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

@rcosta358 rcosta358 self-assigned this Jun 11, 2026
@rcosta358 rcosta358 added enhancement New feature or request simplification Related to the simplification of expressions labels Jun 11, 2026
@rcosta358 rcosta358 requested a review from CatarinaGamboa June 11, 2026 15:37

// TODO: add more simplification steps here (e.g., folding)
return substituted;
return VCFolding.apply(implication);

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.

It could be cool to have like implication.fold() and have that method call the VCFolding. In terms of API thats a bit more ergonomic since the user doenst need to know that there is another class resposible for the folding itself

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.

Maybe just implication.simplify() to call VCSimplification.simplifyToFixedPoint?

return null;

Expression expression = implication.getRefinement().getExpression();
Expression folded = fold(expression);

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.

So with this architecture, each VCImplication only has one origin->simplification right?
Its not possible for one VCImplication to formulate 2 "independent" simplifications for different parts of the expression like you had planned before.
Like

           VC: forall x: x == 3 -> forall y: y == 4 -> x < y
            // there are 2 independent simplifcations possible
VC: forall y: y == 4 -> 3 < y      e      forall x: x == 3 -> x < 4
           // but just one outcome for each of the next ones
                             3 < 4
                              true

If you want to keep this structure, I think this architecture does not work 😕
Nevertheless, this current option works for me if you want to leave that for a followup but it might require some more deep changes

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.

Yes, you are correct, but I think we should keep this approach because it stays consistent with the VCSubstitution, and even though it can be a bit more verbose than the previous one, each simplification step is atomic and easier to debug.

@rcosta358 rcosta358 changed the base branch from vc-substitution to main June 12, 2026 12:46
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