My goal is to define an injective function f: Int -> Term
, where Term
is some new sort. Having referred to the definition of the 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 causes a timeout. I suspect that this is because the solver tries to validate the assertion for all values in the Int
domain, which is infinite.
I also checked that the model described above works for some custom sort instead of 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 Int
sort instead of A
. Can solver do this?
I also found the injective function example in the tutorial in multi-patterns section. I don't quite get why :pattern
annotation is helpful. So the second question is why :pattern
is used and what does it brings to this example particularly.