如何声明或检查一对一的功能?

时间:2013-07-30 02:20:24

标签: c++ z3

在z3的C ++ API中,函数被声明为:

func_decl f = function("f", I, I, I); 

表示函数接受输入(int, int)并返回int

我可以声明一对一(双射)函数,还是可以强制执行一对一(双射)函数?

1 个答案:

答案 0 :(得分:1)

据我所知,没有内置方式声明一个函数是一个双射。但是,你可以自己公理化:

(declare-sort X)
(declare-sort Y)

(declare-fun f (X) Y)

(assert (forall ((y Y))
  (exists ((x X))
    (and
      (= (f x) y)
      (forall ((z X))
        (implies
          (not (= x z))
          (not (= (f z) y))))))))

使用如下:

(declare-const x1 X)
(declare-const x2 X)
(declare-const y1 Y)
(declare-const y2 Y)

(assert (= (f x1) y1))
(check-sat) ; sat

(push)
  (assert (= (f x2) y1))
  (check-sat) ; sat
(pop)

(assert (not (= x1 x2)))
(check-sat) ; sat

(push)
  (assert (= (f x2) y1))
  (check-sat) ; unsat
(pop)

试试online here

我不确定这种编码的性能如何。交替量词通常会在自动定理证明中引起问题,而上述公理甚至没有模式/触发器。我的预感是,只要您提供“足够”的信息,公理就可以了,例如x1x2(= (f x1) y1)(not (= x1 x2))。我不确定模型发现在这里的效果如何。