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

SMTLib 2.7 compliance: Bit-vector to/from Int conversions #7572

Closed
LeventErkok opened this issue Mar 6, 2025 · 0 comments
Closed

SMTLib 2.7 compliance: Bit-vector to/from Int conversions #7572

LeventErkok opened this issue Mar 6, 2025 · 0 comments

Comments

@LeventErkok
Copy link

SMTLib 2.7 has standardized on conversions, which I quote below.

Good news is that most of the functionality is already in z3. If I read the code correctly:

  • ubv_to_int is z3's bv2nat
  • sbv_to_int doesn't seem to exist. (Note that z3's bv2int is actually an alias to bv2nat, which is rather confusing.)
  • int_to_bv is z3's int2bv

Here's Clark's message:

Conversion operators
We have also standardized three new conversion operators:

ubv_to_int and sbv_to_int

convert from bitvectors to integers, where the bitvector is interpreted as unsigned or signed. respectively.

Examples:
(ubv_to_int #b1011) = 11
(sbv_to_int #b1011) = -5

And the operator

int_to_bv

is a new indexed operator, which is indexed by a positive numeral N and converts an integer to a bitvector of size N. The semantics here is that given an input x, the value x mod 2^N is computed and then the unsigned bitvector corresponding to this value (which is a positive integer) is returned. Note that this same definition also correctly converts negative integers to their signed bitvector representation, so only a single integer to bitvector operator is needed. Please refer to the theory documentation for more details.

Examples;
((_ int_to_bv 4) 11) = #b1011
((_ int_to_bv 4) -5) = #b1011

One other note: there are two functions, bv2nat and nat2bv, that appear in the theory documentation (and indeed were already there in version 2.6) . However, these functions are NOT operators in the SMT-LIB theory - they are only used to help define the semantics of certain operators. Some solvers have implemented support for operators with these or similar names. Such implementations should be viewed as solver-specific extensions and are not part of the standard. The new operators mentioned here are the ones that should be supported to be compliant with version 2.7. The rationale for the new names (as opposed to the semantic function names) is that natural numbers are not part of SMT-LIB, so those names would be misnomers. Additionally, the use of "2" as opposed to "to" is not consistent with other conversion operators in SMT-LIB (in strings and floating point, for example).

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

1 participant