Understanding the indexing of bound variables in Z3

后端 未结 1 1071
夕颜
夕颜 2020-12-19 08:11

I am trying to understand how the bound variables are indexed in z3. Here in a snippet in z3py and the corresponding output. ( http://rise4fun.com/

相关标签:
1条回答
  • 2020-12-19 08:36

    Z3 encodes bound variables using de Bruijn indices. The following wikipedia article describes de Bruijn indices in detail: http://en.wikipedia.org/wiki/De_Bruijn_index Remark: in the article above the indices start at 1, in Z3, they start at 0.

    Regarding your second question, you can change the Z3 pretty printer. The Z3 distribution contains the source code of the Python API. The pretty printer is implemented in the file python\z3printer.py. You just need to replace the method:

    def pp_var(self, a, d, xs):
        idx = z3.get_var_index(a)
        sz  = len(xs)
        if idx >= sz:
            return seq1('Var', (to_format(idx),))
        else:
            return to_format(xs[sz - idx - 1])
    

    with

    def pp_var(self, a, d, xs):
        idx = z3.get_var_index(a)
        return seq1('Var', (to_format(idx),))
    

    If you want to redefine the HTML pretty printer, you should also replace.

    def pp_var(self, a, d, xs):
        idx = z3.get_var_index(a)
        sz  = len(xs)
        if idx >= sz:
            # 957 is the greek letter nu
            return to_format('&#957;<sub>%s</sub>' % idx, 1)
        else:
            return to_format(xs[sz - idx - 1])
    

    with

    def pp_var(self, a, d, xs):
        idx = z3.get_var_index(a)
        return to_format('&#957;<sub>%s</sub>' % idx, 1)
    
    0 讨论(0)
提交回复
热议问题