Definition of injective functions in Z3

My goal is to define an injective function f: Int -> Term, where Termis a new type. Noting the definition of injective function, I wrote the following:

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

This results in a timeout. I suspect this is because the solver is trying to validate the statement for all values ​​in a domain Intthat is infinite.

I also verified that the model described above works for a specific custom sort instead 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)

The first question is how to implement the same model for sorting Intinstead A. Could this solve it?

. , :pattern . , :pattern .

+4
2

(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))) 
  )
+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))) 
)
+1

All Articles