-
Notifications
You must be signed in to change notification settings - Fork 274
Fix SMT2 encoding of array_comprehension_exprt
#5973
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
Fix SMT2 encoding of array_comprehension_exprt
#5973
Conversation
e99097e
to
1a5a4d3
Compare
array_comprehension_exprt
Codecov Report
@@ Coverage Diff @@
## develop #5973 +/- ##
===========================================
+ Coverage 75.12% 75.14% +0.02%
===========================================
Files 1435 1444 +9
Lines 156301 157307 +1006
===========================================
+ Hits 117416 118207 +791
- Misses 38885 39100 +215
Continue to review full report at Codecov.
|
If you can use an SMT-LIB expression that maps directly onto what you want to translate, you no longer need the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Is you think it fixes other things, please can you take the time to find out what they are? Someone will have to do this at some point and it would be better that it is connected with the change that fixes them.
- I'm pretty sure
lambda
isn't in SMT-LIB 2. It has been /proposed/ for SMT-LIB 3 but we shouldn't be outputting it in an SMT-LIB 2.0 back-end.
src/solvers/smt2/smt2_conv.cpp
Outdated
|
||
const irep_idt id = | ||
"array_comprehension." + std::to_string(defined_expressions.size()); | ||
out << "(define-fun " << id << " () "; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you creating a function with no arguments that returns a lambda?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless I have got the wrong end of the stick completely, I think you can implement this without the lambda.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arrays are infinite maps in SMT and are represented just like key -> value functions. The function with no arguments returns a lambda, because we want to return an array.
This has been tested with both Z3 -- you can run the attached regression test with cbmc --smt2
.
I am not super sure about the official status of lambda
within SMTLIB2 vs SMTLIB3, but Z3 supports it for a while now.
AFAIK, the only other way to implement array comprehension would be to use quantifiers, but that did not work even for the simpler case of array_of
where the lambda expression was a constant (independent of the index).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will make this translation solver-specific then -- only emit SMT2 output using lambda if solver is Z3. Otherwise, fall back to quantifier-based initialization.
[Also, more info about lambda
handling here: Z3Prover/z3/issues/2221]
1a5a4d3
to
0e2e339
Compare
I have tested this (the attached regression test) locally with both However, with CVC4 (and other solvers that don't allow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather not have the default logic change to be quantified as it will block some solvers. Beyond that, looks OK.
Thanks for taking a look, @martin-cs. I agree with not changing the default logic to allow quantifiers. I opened #5977 to discuss more about this issue. |
7037b93
to
0c4f8b3
Compare
Z3 treats arrays and lambdas as identical structures, so we use lambdas in the z3-specific encoding of `array_comprehension_exprt`. For other solvers, we fall back to a universally quantified expression to initialize the array.
0c4f8b3
to
c499ff7
Compare
The SMT conversion routines were missing a rule for translating
array_comprehension_exprt
.This PR creates a new translation rule leveraging the
lambda
construct in SMTLIB2.NOTE: There may be several other
broken-smt-backend
regression tests that may be fixed by this change; I haven't checked (there are too many!).Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/My commit message includes data points confirming performance improvements (if claimed).White-space or formatting changes outside the feature-related changed lines are in commits of their own.