I need to model length of array. So I declare a function
(declare-fun LEN ((Array Int Int)) Int)
At the same time, I want to define some macros using define-fun.
However, as I tested a little bit on Z3, it seems that define-fun and declare-fun can’t exist at the same source file?
This code like following works fine:
(define-fun mymax ((a Int) (b Int)) Int
(ite (> a b) a b))
(assert (= (mymax 100 7) 100))
(check-sat)
(src: http://rise4fun.com/Z3/jRzs)
But the following, no matter where the LEN inserted, there will be errors:
;(declare-fun LEN ((Array Int Int) Int)
;unknown sort 'assert'
(define-fun mymax ((a Int) (b Int)) Int
(ite (> a b) a b))
; (declare-fun LEN ((Array Int Int) Int)
;unknown sort 'assert'
(assert (= (mymax 4 7) 7))
; (declare-fun LEN ((Array Int Int) Int)
;;unknown sort 'check-assert'
(check-sat)
;(declare-fun LEN ((Array Int Int) Int)
;invalid sort, symbol, '_' or '(' expected
(src: http://rise4fun.com/Z3/HdEy)
Does anybody know how to work around this?
declare-funanddefine-funcan be used together.The problem is that you have a missing parenthesis.
It should be
instead of
Because of the missing parenthesis, the second is actually declaring a function
LENwith two arguments (array and integer), then Z3 generates an error when it can find the resulting sort for this declaration.Here is a link to the complete example: http://rise4fun.com/Z3/TjNS