4

I created this file which is supposed to represent Dekker's algorithm

  • Given a variable Turn of type proc and two arrays want and crit mapping proc to bools
  • The initial state is want[p] = false and crit[p] = false for all proc p
  • I can non deterministically take one of the three transitions below :
    • req : if there exists a proc p such that want[p] = false then want'[p] = true
    • enter : if there exists a proc p such that want[p] = true and turn = p then crit'[p] = true
    • exit : if there exists a proc p such that crit[p] = true then want'[p] = false, crit'[p] = false and turn = ? (? represent the fact that any proc p' can be attributed to turn).
  • A state is unsafe if there exists two proc p1 and p2 such that crit[p1] = crit[p2] = true

I represented it like this :

(set-logic HORN)

(define-sort proc () Int)
(define-sort myarray () (Array proc Bool))

(declare-var turn proc)
(declare-var want myarray)
(declare-var crit myarray)

(declare-fun reachable (proc myarray myarray) Bool)

;; Init
(rule
 (=>
  (forall ((z proc))
          (and
           (= (select want z) false)
           (= (select crit z) false)
           )
          )
  (reachable turn want crit)
  )
 )

;; Unsafe
(assert
 (exists ((z1 proc) (z2 proc))
         (=>
          (and
           (not (= z1 z2))
           (= (select want z1) true)
           (= (select want z2) true)
           )
          (reachable turn want crit)
          )
         )
 )

;; Req
(assert 
 (exists ((z proc))
         (=>
          (and
           (= (select want z) false)
           (reachable turn want crit)
           )
           (reachable turn (store want z true) crit)
           )
         )
 )

;; Enter
(assert 
 (exists ((z proc))
         (=>
          (and
           (= (select want z) true)
           (= turn z)
           (reachable turn want crit)
           )
          (reachable turn want (store crit z true))
          )
         )
 )

;; Exit
(assert 
 (exists ((z1 proc)
          (z2 proc)
          )
         (=>
          (and
           (= (select crit z1) true)
           (reachable turn want crit)
           )
          (and
           (reachable
            z2 
            (store want z1 false)
            (store crit z1 false)
            )
           )
          )
         )
 )

(check-sat)

But when I call z3 dekker.smt2 it gives me unknown as an answer.


If I try to do it like this :

(set-logic HORN)

(declare-fun reachable (Int
                        (Array Int Bool)
                        (Array Int Bool)) Bool)


;; Init
(assert
 (forall ((Turn Int)
          (Want (Array Int Bool))
          (Crit (Array Int Bool))
          )

         (=>
          (forall ((z Int))
                  (and
                   (= (select Want z) false)
                   (= (select Crit z) false)
                   ))
          (reachable Turn Want Crit)
          )))


;; Unsafe
(assert 
 (forall ((Turn Int)
          (Want (Array Int Bool))
          (Crit (Array Int Bool))
          )

         (=>
          (reachable Turn Want Crit)

          (not
           (exists ((z1 Int) (z2 Int))
                   (and (not (= z1 z2))
                        (= (select Crit z1) true)
                        (= (select Crit z2) true)
                        )
                   )
           )
          )
         )
 )


;; Transitions
(assert 
 (forall (
          (Turn Int)
          (Want (Array Int Bool))
          (Crit (Array Int Bool))

          (Turn_ Int)
          (Want_ (Array Int Bool))
          (Crit_ (Array Int Bool))
          )

         (=>
          (and
           (reachable Turn Want Crit)
           (or

            ;;req
            (exists ((n Int))
                    (and (= (select Want n) false)

                         (= Turn_ Turn)
                         (= Want_ (store Want n true))
                         (= Crit_ Crit)
                         )
                    )

            ;;req
            (exists ((n Int))
                    (and (= (select Want n) true)
                         (= Turn n)

                         (= Turn_ Turn)
                         (= Want_ Want)
                         (= Crit_ (store Crit n true))
                         )
                    )

            ;;req
            (exists ((n Int) (n2 Int))
                    (and (= (select Crit n) true)

                         (= Turn_ n2)
                         (= Want_ (store Want n false))
                         (= Crit_ (store Crit n false))
                         )
                    )
            )

           )
          (reachable Turn_ Want_ Crit_)
          )
         )
 )

(check-sat)

I get this answer :

PDR cannot solve non-ground tails: (let ((a!1 (forall ((z Int))
             (and (= (select reachable_1_n z) false)
                  (= (select reachable_2_n z) false)))))
  (= a!1 true))
unknown
Lhooq
  • 4,281
  • 1
  • 18
  • 37
  • This is a very Z3/muZ specific question. You might get better mileage by asking your question as an issue in http://github.com/Z3Prover/z3/issues, which I suspect will get a quick answer. Then you can summarize your learning and post/accept your own answer here for the rest of us! – alias May 11 '17 at 18:29

0 Answers0