简体   繁体   English

将Z3整数表达式转换为C / C ++ int

[英]Casting a Z3 integer expression to a C/C++ int

I'm new to Z3 and searched for the answer to my question here and on Google. 我是Z3的新手,在这里和Google上搜索了我的问题的答案。 Unfortunately, I was not successful. 不幸的是,我没有成功。

I'm using the Z3 4.0 C/C++ API. 我正在使用Z3 4.0 C / C ++ API。 I declared an undefined function d: (Int Int) Int , added some assertions, and computed a model. 我声明了一个未定义的函数d:(Int Int)Int ,添加了一些断言,并计算了一个模型。 So far, that works fine. 到目前为止,这很好。

Now, I want to extract certain values of the function d defined by the model, say d(0,0) . 现在,我想提取模型定义的函数d的某些值,比如d(0,0) The following statement works, but returns an expression rather than the function value, ie, an integer, of d(0,0) . 以下语句有效,但返回表达式而不是函数值,即d(0,0)的整数。

z3::expr args[] = {c.int_val(0), c.int_val(0)};
z3::expr result = m.eval(d(2, args));

The check 支票

result.is_int();

returns true . 返回true

My (hopefully not too stupid) question is how to cast the returned expression to a C/C++ int? 我的(希望不是太愚蠢)问题是如何将返回的表达式转换为C / C ++ int?

Help is very appreciated. 非常感谢帮助。 Thank you! 谢谢!

Z3_get_numeral_int is what you're looking for. Z3_get_numeral_int正是您要找的。

Here is an excerpt from the docummentation: 以下是文档摘录的摘录:

 Z3_bool Z3_get_numeral_int(__in Z3_context c, __in Z3_ast v, __out int * i) Similar to Z3_get_numeral_string, but only succeeds if the value can fit in a machine int. Return Z3_TRUE if the call succeeded. 

You should be careful though. 你应该小心。 Z3's integer is mathematical integer which can easily exceed the range of 32-bit int. Z3的整数是数学整数,很容易超过32位int的范围。 In that sense, using Z3_get_numeral_string and parsing string to big integer is a better option. 从这个意义上说,使用Z3_get_numeral_string并将字符串解析为大整数是一个更好的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM