用户定义的z3排序的问题
我试图在z3中定义一个新的分数排序,以便更好地理解z3是如何工作的。我使用此查询并定义两个分数之间的相等:用户定义的z3排序的问题,z3,smt,Z3,Smt,我试图在z3中定义一个新的分数排序,以便更好地理解z3是如何工作的。我使用此查询并定义两个分数之间的相等: ;;;;;;;;;;;;;;;;;;; ;; TEMPLATE CTOR ;; ;;;;;;;;;;;;;;;;;;; (declare-datatypes (T1 T2) ((Pair (mk-pair (first T1) (second T2))))) ;;;;;;;;;;;;;;;;;;;;;; ;; SORT DEFINITIONS ;; ;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;
;; TEMPLATE CTOR ;;
;;;;;;;;;;;;;;;;;;;
(declare-datatypes (T1 T2) ((Pair (mk-pair (first T1) (second T2)))))
;;;;;;;;;;;;;;;;;;;;;;
;; SORT DEFINITIONS ;;
;;;;;;;;;;;;;;;;;;;;;;
(define-sort Fraction () (Pair Int Int))
;;;;;;;;;;;;;;;;;;;;;;;;;;
;; FUNCTION DEFINITIONS ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-fun Fraction_Eq ((f1 Fraction) (f2 Fraction)) Bool
(if (= (* (first f1) (second f2))
(* (first f2) (second f1)))
true
false
)
)
(declare-const x1 Fraction)
(declare-const x2 Fraction)
(declare-const x3 Fraction)
(assert (Fraction_Eq x1 (mk-pair 3 5)))
(assert (Fraction_Eq x2 (mk-pair 4 7)))
(assert (Fraction_Eq x3 (mk-pair 8 9)))
(check-sat)
(get-value (x1 x2 x3))
我预计x1将等于3/5,但事实并非如此。以下是我得到的答案:
sat
((x1 (mk-pair 0 0))
(x2 (mk-pair 1304 2282))
(x3 (mk-pair 0 0)))
有人能帮忙吗?谢谢 方程式
n * 5 = d * 3
完全满足于n=d=0
由于被零除在普通算术中没有意义,您应该丰富您的语句,并要求d
不同于0
请注意,这并不保证n,d
等于3,5
,因为该方程有无限多个解。然而,x1
的标准化值应对应于3/5
以下是修复此问题的方法:
;;;;;;;;;;;;;;;;;;;
;; TEMPLATE CTOR ;;
;;;;;;;;;;;;;;;;;;;
(declare-datatypes (T1 T2) ((Pair (mk-pair (first T1) (second T2)))))
;;;;;;;;;;;;;;;;;;;;;;
;; SORT DEFINITIONS ;;
;;;;;;;;;;;;;;;;;;;;;;
(define-sort Fraction () (Pair Int Int))
;;;;;;;;;;;;;;;;;;;;;;;;;;
;; FUNCTION DEFINITIONS ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-fun Fraction_Eq ((f1 Fraction) (f2 Fraction)) Bool
(if (= (* (first f1) (second f2))
(* (first f2) (second f1)))
true
false
)
)
(define-fun Fraction_Valid ((f1 Fraction)) Bool
(not (= 0 (second f1)))
)
(declare-const x1 Fraction)
(declare-const x2 Fraction)
(declare-const x3 Fraction)
(assert (Fraction_Valid x1))
(assert (Fraction_Valid x2))
(assert (Fraction_Valid x3))
(assert (Fraction_Eq x1 (mk-pair 3 5)))
(assert (Fraction_Eq x2 (mk-pair 4 7)))
(assert (Fraction_Eq x3 (mk-pair 8 9)))
(check-sat)
(get-value (x1 x2 x3))
结果是:
sat
((x1 (mk-pair 3 5))
(x2 (mk-pair 4 7))
(x3 (mk-pair (- 8) (- 9))))
新引入的分数\u Valid
谓词应防止应用它的任何分数的分母等于零