Creating List in z3 using function

前端 未结 1 1773
我在风中等你
我在风中等你 2021-01-27 10:44

I\'m trying to convert this piece of pseudocode to SMT-LIB language, but I got stuck.

List function my_fun(int x)
{
    list = nil
    for(i in 1 to x):
                 


        
相关标签:
1条回答
  • 2021-01-27 11:20

    SMT-LIB models logic, where variables are always immutable; your code, on the other hand, appears to be imperative, i.e. variables such as list and i are mutable. This crucial difference will be the biggest challenge in encoding your program and the challenge of reasoning about imperative programs has sparked research tools such as Dafny, Boogie, or Viper

    Here are a few pointers:

    • (insert t l1) represents a new list, obtained by inserting t into l1. It will not modify l1 (and there is no way to modify l1 since it is a logical variable)
    • A logical forall is a boolean formula (it evaluates to true or false), it is not a statement that you can execute (e.g. for its side effects)
    • If the value of x were statically known (i.e. if it were 5), then you could unroll the loop (here in pseudo-code):

      l0 := Nil
      l1 := ite(condition(1), insert(1, l0), l0)
      l2 := ite(condition(2), insert(2, l1), l1)
      ...
      l4 := ite(condition(4), insert(4, l3), l3)
      
    • If the value of x isn't statically known then you'll most likely either need a loop invariant or work with fix points in order to account for an unknown number of loop iterations
    0 讨论(0)
提交回复
热议问题