I created this file which should represent the Dekker algorithm
- For
Turntype variable procand two arrays wantand critmapping procin bools - Initial state
want[p] = falseand crit[p] = falsefor allproc p - I can deterministically accept one of the three transitions below:
req: if there exists proc psuch that want[p] = false, thenwant'[p] = trueenter: if there exists proc psuch that want[p] = trueand turn = p, thencrit'[p] = trueexit: if there proc pis such that crit[p] = true, then want'[p] = false, crit'[p] = falseand turn = ?( ?represent the fact that anyone proc p'can be attributed to Turn).
- A condition is unsafe if there are two
proc p1and p2such thatcrit[p1] = crit[p2] = true
I represented it as follows:
(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, he gives me unknownas 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 the 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 source
share