Z3 Conditional Statement

放肆的年华 提交于 2021-02-08 10:45:25

问题


How to write a conditional statement in Z3.

eg: 
if (a%2==0){
value=1
}

I am trying to achieve this in Z3 Solver by Microsoft Research but so far no luck


回答1:


Look up SSA form: https://en.wikipedia.org/wiki/Static_single_assignment_form

Essentially, you'll have to change your program to look something like:

value_0 = 0
value_1 = (a%2 == 0) ? 1 : value_0

Once it is in this so called static single assignment form, you can now translate each line more or less directly; with the latest assignment to value_N being the final value of value.

Loops will be problematic: The usual strategy is to unroll them up to a certain count (bounded model checking), and hope that this suffices. If you detect that the last unrolling isn't sufficient, then you can generate an uninterpreted value at that point; which might cause your proofs to fail with spurious counter-examples; but that's the best you can do without a scheme that involves proper handling of induction and loop-invariants.

Note that this field of study is called "symbolic execution" and has a long history, with active research still being conducted. You might want to read through this: https://en.wikipedia.org/wiki/Symbolic_execution



来源:https://stackoverflow.com/questions/44314486/z3-conditional-statement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!