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

[FEATURE] Rewrite \E x \in a..b: p to \E x \in Int: a <= x /\ x <= b /\ p #1407

Open
Kukovec opened this issue Feb 24, 2022 · 8 comments
Open
Assignees
Labels
FSMT Feature: Improvements in the SMT encoding

Comments

@Kukovec
Copy link
Collaborator

Kukovec commented Feb 24, 2022

ExprOptimizer already translates x \in a..b to a <= x <= b, and while there's no good way to handle the set a..b for non-constant a,b explicitly, quantification should be one of the cases where we can introduce optimizations.

We should also consider translating \A x \in a..b: p to \A x \in Int: (a <= x /\ x <= b) => p (though at the moment, \A x \in Int: ... might be a bad idea).

Related: #446

@Kukovec
Copy link
Collaborator Author

Kukovec commented Feb 24, 2022

@konnov thoughts?

@Kukovec
Copy link
Collaborator Author

Kukovec commented Feb 24, 2022

Also, from what I can tell, this would not throw in cases like #425

@konnov
Copy link
Collaborator

konnov commented Feb 24, 2022

Also mentioned in #481

@konnov konnov added the FSMT Feature: Improvements in the SMT encoding label Feb 24, 2022
@konnov
Copy link
Collaborator

konnov commented Feb 24, 2022

It is a very good idea and we should do it. It is not just an optimization. It may enable support of a..b for the case when a and b are not constants. As we discussed during the stand up, I think we should do that in two steps:

  1. Translate expressions over unbounded sets of integers into the unbound forms:
  • Translate \E x \in Int: P and \A x \in Int: P into \E x: P and \A x: P.
  • Translate \E x \in Nat: P and \A x \in Nat: P into \E x: x >= 0 /\ P and \A x: x >= 0 => P
  • Translate \E x \in a..b: P and \A x \in a..b: P into \E x: a <= x /\ x <= b /\ P and \A x: (a <= x /\ x <= b) => P
  1. Add a special rule for the unbound forms \E x: P and \A x: P. By having the types, we can figure the type of x. The only complication here is that Z3SolverContext immediately pushes assertions on assertGroundExpression. We have to introduce a stack of quantified contexts, similar to database transactions. Whenever \E x: P or \A x: P is met, it would call solver.introQuantifier(...). All calls to assertGroundExpressions should be buffered, if the quantifier stack is non-empty. Once the rewriting rule is done with P, it calls solver.commitQuantifier(...) and this pushes the buffered expressions either to the solver context, or to the higher level context (if quantifiers are nested).

@konnov
Copy link
Collaborator

konnov commented Feb 24, 2022

Also related is #844

@konnov
Copy link
Collaborator

konnov commented Feb 24, 2022

This one is also related #480. All these issues call for a general approach.

@konnov
Copy link
Collaborator

konnov commented Dec 21, 2022

Hey Jure @Kukovec! Is this issue closed via #1431?

@Kukovec
Copy link
Collaborator Author

Kukovec commented Dec 21, 2022

No. While that PR implements the rewriting itself, it does not

  • Change PreproPass to actually use it, or
  • Implement a translation rule for unbounded quantifiers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FSMT Feature: Improvements in the SMT encoding
Projects
None yet
Development

No branches or pull requests

2 participants