【问题标题】:Defining injective functions in Z3在 Z3 中定义单射函数
【发布时间】:2013-11-05 03:36:58
【问题描述】:

我的目标是定义一个单射函数f: Int -> Term,其中Term 是某种新类型。参考了单射函数的the definition,我写了以下内容:

(declare-sort Term)
(declare-fun f (Int) Term)
(assert (forall ((x Int) (y Int))
                (=> (= (f x) (f y)) (= x y))))
(check-sat)

这会导致超时。我怀疑这是因为求解器试图验证 Int 域中所有值的断言,这是无限的。

我还检查了上述模型是否适用于某些自定义排序而不是 Int

(declare-sort Term)
(declare-sort A)
(declare-fun f (A) Term)
(assert (forall ((x A) (y A))
                (=> (= (f x) (f y)) (= x y))))
(declare-const x A)
(declare-const y A)
(assert (and (not (= x y)) (= (f x) (f y))))
(check-sat)
(get-model)

第一个问题是如何实现Int排序而不是A的相同模型。求解器可以做到这一点吗?

我还在多模式部分的the tutorial 中找到了单射函数示例。我不太明白为什么 :pattern 注释有帮助。所以第二个问题是为什么使用:pattern,它给这个例子带来了什么特别的影响。

【问题讨论】:

    标签: z3 smt constraint-programming


    【解决方案1】:

    我正在尝试这个

    (declare-sort Term)
    (declare-const x Int)
    (declare-const y Int)
    (declare-fun f (Int) Term)
    (define-fun biyect () Bool
        (=> (= (f x) (f y)) (= x y)))
    (assert (not biyect))
    (check-sat)
    (get-model)
    

    我得到了这个

    sat 
    (model 
      ;; universe for Term: 
      ;; Term!val!0 
      ;; ----------- 
      ;; definitions for universe elements: 
      (declare-fun Term!val!0 () Term) 
      ;; cardinality constraint: 
      (forall ((x Term)) (= x Term!val !0)) 
      ;; ----------- 
      (define-fun y () Int 
        1) 
      (define-fun x () Int 
        0) 
      (define-fun f ((x!1 Int)) Term 
        (ite (= x!1 0) Term!val!0 
        (ite (= x!1 1) Term!val!0 
          Term!val!0))) 
      )
    

    【讨论】:

    • 这不太对。 1)您在定义函数之前声明常量,并且函数依赖于特定的常量值。正如您在我的第二个示例中看到的那样,为A 中的所有值定义了函数。 2)在您的情况下,函数 f 不是单射函数。从模型中可以看出。对于任何输入x!1,它将产生相同的答案Term!val!0。该函数应该为相同的参数产生相同的答案。
    【解决方案2】:

    你怎么看这个

    (declare-sort Term)
    (declare-fun f (Int) Term)
    (define-fun biyect () Bool
        (forall ((x Int) (y Int))
                (=> (= (f x) (f y)) (= x y))))
    (assert (not biyect))
    (check-sat)
    (get-model)
    

    输出是

    sat 
    (model 
    ;; universe for Term: 
    ;; Term!val!0 
    ;; ----------- 
    ;; definitions for universe elements: 
    (declare-fun Term!val!0 () Term) 
    ;; cardinality constraint: 
    (forall ((x Term)) (= x Term!val!0))
    ;; ----------- 
    (define-fun x!1 () Int 0)
    (define-fun y!0 () Int 1) 
    (define-fun f ((x!1 Int)) Term 
     (ite (= x!1 0) Term!val!0 
     (ite (= x!1 1) Term!val!0 
       Term!val!0))) 
    )
    

    【讨论】:

    • 这个和我写的差不多。但是为什么这里需要(assert (not biyect)) 约束呢?此外,f 函数仍然为两个不同的值(0 和 1)输出相同的值,所以据我所知,这不是单射函数。
    • 是的,你是对的,当你使用 (assert (not biyect)) Z3 产生一个非单射函数的例子。关键是不可能使用 Z3 来定义一般的单射函数。你同意吗?
    • 目前我看不出有任何理由说明它应该是不可能的。 the tutorial 中还提供了单射函数。我只是想弄清楚是否可以为无限域做,比如Int
    猜你喜欢
    • 2015-07-22
    • 1970-01-01
    • 2020-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多