2

Can someone kindly point out why the final query doesn't have output?

Basically I tell Z3 if vs-)vd and vs->ss and vd->sd, then sd is derived from ss.

(set-option :fixedpoint.engine datalog)
(define-sort site () (_ BitVec 3))

(declare-rel pointsto (Int site))
(declare-rel dcall (Int Int))
(declare-rel derived (site site))

(declare-var vs Int)
(declare-var vd Int)
(declare-var ss site)
(declare-var sd site)

;;;;; definition of derived ;;
(rule (=> (and (dcall vs vd) (pointsto vs ss) (pointsto vd sd)) (derived ss sd)))          

(rule (dcall 11 12))
(rule (pointsto 11 #b001))
(rule (pointsto 12 #b010))

(query (derived #b001 #b010))
Tim
  • 355
  • 1
  • 8
  • The syntax seems to be wrong. Why do you write pointsto(vs ss) instead of (pointsto vs ss) ? – Nikolaj Bjorner Apr 19 '15 at 10:17
  • Sorry. A typo. corrected now. But still no results show. – Tim Apr 19 '15 at 16:14
  • By running on local Z3 instead of rise4fun, I found "libc++abi.dylib: terminating with uncaught exception of type std::bad_cast: std::bad_cast" – Tim Apr 19 '15 at 16:33

1 Answers1

2

This example exposes a few things. I will try to go through these.

  1. The query returns "sat" or "unsat". In the "sat" case there is a set of tuples corresponding to the free variables in the query such that the query is derivable. To print these tuples you can specify ":print-answer true" as an option.
  2. Your particular query does not contain any free variables, so there are no tuples to print.
  3. I added another example that contains free variables and Z3 prints a solution.
  4. The datalog engine doesn't really support infinite domains. You should use relations over Booleans, bit-vectors or finite domain values (a special sort used for programs entered in datalog format). I have changed your example to use bit-vectors.

(set-option :fixedpoint.engine datalog)
(define-sort site () (_ BitVec 3))
(define-sort Loc () (_ BitVec 8))

(declare-rel pointsto (Loc site))
(declare-rel dcall (Loc Loc))
(declare-rel derived (site site))

(declare-var vs Loc)
(declare-var vd Loc)
(declare-var ss site)
(declare-var sd site)

;;;;; definition of derived ;;
(rule (=> (and (dcall vs vd) (pointsto vs ss) (pointsto vd sd)) (derived ss sd)))          

(rule (dcall (_ bv11 8) (_ bv12 8)))
(rule (pointsto (_ bv11 8) #b001))
(rule (pointsto (_ bv12 8) #b010))

(query (derived #b001 #b010) 
   :print-answer true)

(query (derived #b001 ss) 
   :print-answer true)
Nikolaj Bjorner
  • 8,229
  • 14
  • 15