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

Get bitvector model as a vector of bool #357

Open
mikhailramalho opened this issue Jul 9, 2020 · 5 comments
Open

Get bitvector model as a vector of bool #357

mikhailramalho opened this issue Jul 9, 2020 · 5 comments
Milestone

Comments

@mikhailramalho
Copy link

I'm using the vc_bvConstExprFromStr methods to create some large bitvectors (width > 64), but is there a way to get its value from the model also as an array of bools or a string of 0's/1's? I only found the getBVInt, getBVUnsigned and getBVUnsignedLongLong functions.

@aytey
Copy link
Member

aytey commented Jul 9, 2020

Joining the dots: Z3Prover/z3#4568 (comment)

Are you using the C or Python API? Do you want an STP vc_boolType or a language-level Boolean type (e.g., bool in C99/Python)?

@aytey
Copy link
Member

aytey commented Jul 9, 2020

So I was just taking a look at this for you, and I noticed this:

The code for GetUnsignedConst seems to be limited to unsigned numbers that fit in a machine unsigned int (the message says 32, but I think it would be supported for a 64-bit value if you're on a 64-bit host).

When you say you're "creat[ing] some large bitvectors (width > 64)", have you created BVs that are larger than your machine-size unsigned int and successfully retrieved them over the API?

Anyway back to your original issue: behind the scenes getBVUnsignedLongLong calls BitVector_to_Bin, which looks like it is close to what you need.

Edit

Actually, I need to change my response here. As far as I'm aware, there are no functions in the C API that directly return a heap-based object that is expected to be managed by the caller. Anything that returns a char* (e.g., get_git_version_sha) is returning a pointer that we do not expect the to free.

That being said, there are a few vc_print... methods that take a char** as an argument, and we update that as an output parameter. Would this work for you? You would need to pass in an address to an (unallocated) pointer, we could make this (double pointer) point to a string in memory that had your 0s/1s, and then you'd need to free it.

These print methods are exposed by the Python API, but I am really not sure how these are supposed to work. If you need this in the Python API, I might need to think a bit more ...

aytey added a commit to aytey/stp that referenced this issue Jul 9, 2020
…#357

Signed-off-by: Andrew V. Jones <andrew.jones@vector.com>
@aytey
Copy link
Member

aytey commented Jul 9, 2020

Should be done; take a look at: #358

To be clear: this PR needs to be agreed by one of: @msoos @TrevorHansen @rgov -- it is possible that they might not want this API call.

@mikhailramalho
Copy link
Author

So I was just taking a look at this for you, and I noticed this:

The code for GetUnsignedConst seems to be limited to unsigned numbers that fit in a machine unsigned int (the message says 32, but I think it would be supported for a 64-bit value if you're on a 64-bit host).

When you say you're "creat[ing] some large bitvectors (width > 64)", have you created BVs that are larger than your machine-size unsigned int and successfully retrieved them over the API?

Anyway back to your original issue: behind the scenes getBVUnsignedLongLong calls BitVector_to_Bin, which looks like it is close to what you need.

Edit

Actually, I need to change my response here. As far as I'm aware, there are no functions in the C API that directly return a heap-based object that is expected to be managed by the caller. Anything that returns a char* (e.g., get_git_version_sha) is returning a pointer that we do not expect the to free.

That being said, there are a few vc_print... methods that take a char** as an argument, and we update that as an output parameter. Would this work for you? You would need to pass in an address to an (unallocated) pointer, we could make this (double pointer) point to a string in memory that had your 0s/1s, and then you'd need to free it.

These print methods are exposed by the Python API, but I am really not sure how these are supposed to work. If you need this in the Python API, I might need to think a bit more ...

Returning the char pointer is fine by me, and it seems consistent with other functions like vc_printQueryStateToBuffer and vc_printCounterExampleToBuffer.

@aytey
Copy link
Member

aytey commented Jul 9, 2020

Okay; cool. So that's what's in the PR.

An example of usage is here: https://github.com/andrewvaughanj/stp/blob/return_bit_string/tests/api/C/bit_string.cpp#L40

aytey added a commit to aytey/stp that referenced this issue Jul 9, 2020
…#357

Signed-off-by: Andrew V. Jones <andrew.jones@vector.com>
aytey added a commit to aytey/stp that referenced this issue Jul 20, 2020
…#357

Signed-off-by: Andrew V. Jones <andrew.jones@vector.com>
@TrevorHansen TrevorHansen added this to the STP 2.4 milestone Aug 5, 2022
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

No branches or pull requests

3 participants