z3中量词与集合的相互作用
我目前正在尝试使用Z3为一种带有集合的非类型化语言编码一个简单的程序逻辑 我的符号执行引擎需要证明以下公式的有效性:z3中量词与集合的相互作用,z3,Z3,我目前正在尝试使用Z3为一种带有集合的非类型化语言编码一个简单的程序逻辑 我的符号执行引擎需要证明以下公式的有效性: 为此,我们要求Z3检查以下各项的可满足性: 然后我们将其编码为以下SMT-LIB公式: (define-sort Set () (Array Real Bool)) (define-fun singleton ((x Real)) Set (store ((as const (Array Real Bool)) false) x
为此,我们要求Z3检查以下各项的可满足性: 然后我们将其编码为以下SMT-LIB公式:
(define-sort Set () (Array Real Bool))
(define-fun singleton ((x Real)) Set
(store
((as const (Array Real Bool)) false)
x
true))
(define-fun set-union ((x Set) (y Set)) Set
((_ map (or (Bool Bool) Bool)) x y))
(declare-const head Real)
(declare-const tail Set)
(declare-const result Set)
(declare-const value Real)
(assert (forall ((x Real)) (=> (select tail x) (> x head))))
(assert (> head value))
(assert
(forall ((result Set))
(let ((phi1
(forall ((x Real)) (=> (select result x) (> x value))))
(phi2
(= result (union (singleton head) tail))))
(not (and phi1 phi2)))))
(check-sat)
(define-sort Set () (Array Real Bool))
(define-fun singleton ((x Real)) Set
(store
((as const (Array Real Bool)) false)
x
true))
(define-fun set-union ((x Set) (y Set)) Set
((_ map (or (Bool Bool) Bool)) x y))
(declare-const head Real)
(declare-const tail Set)
(declare-const result Set)
(declare-const value Real)
(assert (forall ((x Real))(=> (select tail x) (> x head))))
(assert (> head value))
(assert
(not
(forall ((x Real))
(=> (select (union (singleton head) tail) x)
(not (<= x value))))))
(check-sat)
给出此公式后,解算器立即输出未知。
我的猜测是,问题在于对绑定到集合的变量进行量化。
为了验证这一点,我简化了上面的公式,得到:然后我们将其编码为以下SMT-LIB公式:
(define-sort Set () (Array Real Bool))
(define-fun singleton ((x Real)) Set
(store
((as const (Array Real Bool)) false)
x
true))
(define-fun set-union ((x Set) (y Set)) Set
((_ map (or (Bool Bool) Bool)) x y))
(declare-const head Real)
(declare-const tail Set)
(declare-const result Set)
(declare-const value Real)
(assert (forall ((x Real)) (=> (select tail x) (> x head))))
(assert (> head value))
(assert
(forall ((result Set))
(let ((phi1
(forall ((x Real)) (=> (select result x) (> x value))))
(phi2
(= result (union (singleton head) tail))))
(not (and phi1 phi2)))))
(check-sat)
(define-sort Set () (Array Real Bool))
(define-fun singleton ((x Real)) Set
(store
((as const (Array Real Bool)) false)
x
true))
(define-fun set-union ((x Set) (y Set)) Set
((_ map (or (Bool Bool) Bool)) x y))
(declare-const head Real)
(declare-const tail Set)
(declare-const result Set)
(declare-const value Real)
(assert (forall ((x Real))(=> (select tail x) (> x head))))
(assert (> head value))
(assert
(not
(forall ((x Real))
(=> (select (union (singleton head) tail) x)
(not (<= x value))))))
(check-sat)
(定义排序集()(数组实数Bool))
(定义有趣的单例((x实))集
(商店
((作为常量(数组实布尔))false)
x
正确的)
(定义乐趣集并集((x集)(y集))集
((uu-map(或(Bool-Bool)Bool))x y))
(宣布警察局长为真)
(声明常数尾集)
(声明常量结果集)
(声明常量值为实)
(断言(forall((x Real))(=>(选择尾部x)(>x头部)))
(断言(>头值))
(断言
(不是
(对于所有((x真实))
(=>(选择(联合(单体头)尾)x)
(非(量词推理对于SMT解算器来说总是很困难的,在这种情况下,你有嵌套的量词。听到Z3在第一种情况下简单地说未知,我并不感到惊讶。还要注意的是,你在量化本质上是一个函数的东西(你实现的集合实际上是函数)但是,即使你对简单的事情进行量化,嵌套的量词也永远不容易释放
你是否尝试过将你的公式简化,将其转换为prenex标准形式,并去除存在论?这可能会让你走得更远,尽管你可能需要拿出合适的模式来进行实例化。我对检查第一个公式的有效性感兴趣(重要的含义)我不太明白skolemization在这种特殊情况下是如何工作的,因为在否定了第一个公式之后,变量结果被普遍量化了。