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

More differences with z3 API #102

Open
3 tasks
user202729 opened this issue Dec 12, 2024 · 5 comments · May be fixed by #103
Open
3 tasks

More differences with z3 API #102

user202729 opened this issue Dec 12, 2024 · 5 comments · May be fixed by #103

Comments

@user202729
Copy link

user202729 commented Dec 12, 2024

  • evaluate(x) returns the result in a different context than x
  • cvc5.pythonic.Model is not defined, unlike z3.Model
  • operator ~ does not work on boolean expression, need to use Not(...)
@alex-ozdemir
Copy link
Member

Hi,

Thank you for this inconsistency report.

I'm working on addressing it here: #103. It's is clear what do to about the inconsistency in operator overloading, but for the other issues I could use some more information from you:

  1. Could you give an example of how the different between the context of
    evaluate(x) and x is a problem for you?

    I ask because cvc5 and z3 contexts work differently. I'll need to understand
    your use case better to determine the correct fix.

  2. Could you give an example of how you want to use the Model function? Again,
    z3 and cvc5 models work somewhat differently, so I need to understand your
    use case better to determine the correct fix.

Cheers,
Alex

@alex-ozdemir alex-ozdemir linked a pull request Dec 12, 2024 that will close this issue
@user202729
Copy link
Author

In [3]: from cvc5.pythonic import evaluate, BitVecVal

In [4]: BitVecVal(2, 32) + BitVecVal(3, 32)
Out[4]: 2 + 3

In [5]: evaluate(BitVecVal(2, 32) + BitVecVal(3, 32))
Out[5]: 5

In [6]: evaluate(BitVecVal(2, 32) + BitVecVal(3, 32)) + BitVecVal(4, 32)
SMTException: Context mismatch

In [7]: from z3 import Model, BitVecVal

In [8]: Model().evaluate(BitVecVal(2, 32) + BitVecVal(3, 32))
Out[8]: 5

My use case is quite simple, just the above.

Basically because expressions that are "trivially constant" are not simplified to a single constant I need to simplify them somehow. At least simplify works, but the problem is simplify is slower than evaluate in z3 so ideally both can work the same way…

@alex-ozdemir
Copy link
Member

Hi,

Thank you for the example of how cvc5.python.evaluate is misbehaving. I've
added a patch for it to the PR above.

I'm still a bit confused about your use-case for Model. Do you only use it to
do evaluation, or also for other things? I ask because I'm considering just not
supporting it (and documenting the non-support), but if there are other
use-cases then supporting it might be important.

Cheers,
Alex

@user202729
Copy link
Author

user202729 commented Dec 13, 2024

Yes, I used it only for evaluation… for comparison z3 doesn't have z3.evaluate, so it's not entirely unreasonable to not be able to find that one.

It doesn't seem too difficult to have Model() return a dummy object whose evaluate is the evaluation function either… for the sake of z3 compatibility.

@alex-ozdemir
Copy link
Member

It doesn't seem too difficult to have Model() return a dummy object whose evaluate is the evaluation function either… for the sake of z3 compatibility.

This is a good approach, and we'll follow it.

Anyways, that resolves the last question then. We'll merge the PR as soon as we can review it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants