What is the most efficient way to encode pseudoboolean constraints in z3?

前端 未结 1 902
长发绾君心
长发绾君心 2021-01-28 16:35

I think there\'s two different relevant cases here:

Case 1:

I have a set of boolean variables and I want another boolean variable which is true if any of these v

1条回答
  •  说谎
    说谎 (楼主)
    2021-01-28 17:26

    You can currently use integers to encode PB constraints. You have to bound the variables to be in the interval 0, 1. For example:

     (set-logic QF_LIA)
     (declare-const n1 Int)
     (declare-const n2 Int)
     (assert (<= 0 n1))
     (assert (<= n1 1))
     (assert (<= 0 n2))
     (assert (<= n2 1))
     (assert (>= (+ n1 n2) 1))
     (check-sat)
    

    If you set the logic to QF_LIA, then Z3 will automatically try to re-encode these constraints using bit-vectors. In the verbose output you will see that Z3 invokes a tactic pb2bv that does the rewriting for you

    z3 ty.smt2 /v:10
    (simplifier :num-exprs 10 :num-asts 171 :time 0.00 :before-memory 0.77 :after-memory 0.77)
    (propagate-values :num-exprs 10 :num-asts 171 :time 0.00 :before-memory 0.77 :after-memory 0.77)
    (ctx-simplify :num-steps 17)
    (ctx-simplify :num-exprs 10 :num-asts 171 :time 0.00 :before-memory 0.77 :after-memory 0.77)
    (simplifier :num-exprs 10 :num-asts 171 :time 0.00 :before-memory 0.77 :after-memory 0.77)
    (solve_eqs :num-exprs 10 :num-asts 171 :time 0.00 :before-memory 0.77 :after-memory 0.77)
    (elim-uncnstr-vars :num-exprs 10 :num-asts 171 :time 0.00 :before-memory 0.77 :after-memory 0.77)
    (simplifier :num-exprs 10 :num-asts 173 :time 0.00 :before-memory 0.77 :after-memory 0.77)
    (pb2bv :num-exprs 4 :num-asts 180 :time 0.00 :before-memory 0.77 :after-memory 0.77)
    (simplifier :num-exprs 3 :num-asts 178 :time 0.00 :before-memory 0.77 :after-memory 0.77)
    (propagate-values :num-exprs 3 :num-asts 178 :time 0.00 :before-memory 0.77 :after-memory 0.77)
    (solve_eqs :num-exprs 3 :num-asts 178 :time 0.00 :before-memory 0.77 :after-memory 0.77)
    (max-bv-sharing :num-exprs 3 :num-asts 178 :time 0.00 :before-memory 0.77 :after-memory 0.77)
    (bit-blaster :num-exprs 3 :num-asts 178 :time 0.00 :before-memory 0.77 :after-memory 0.77)
    (aig :num-exprs 3 :num-asts 178 :time 0.00 :before-memory 0.77 :after-memory 0.77)
    (ast-table :capacity 640 :size 178)
    (sat-status
      :inconsistent    false
       :vars            2
      :elim-vars       0
      :lits            2
      :assigned        0
      :binary-clauses  1
      :ternary-clauses 0
      :clauses         0
      :del-clause      0
      :avg-clause-size 2.00
      :memory          0.77)
    

    0 讨论(0)
提交回复
热议问题