How I can write sqrt function in smt-libv2 format.
Note: To get a maximum of two values, i found a useful link here: Use Z3 and SMT-LIB to get a maximum of two values.
Suppose that your formula is quantifier free, then you can define square-roots implicitly by introducing fresh variables and adding constraints. For example you can write:
(define-fun is_sqrt ((x Real) (y Real)) Bool (= y (* x x)))
Then 'x' is a square root of 'y'; and if you just want the non-negative square roots, then:
(define-fun is_sqrt ((x Real) (y Real)) Bool (and (>= x 0) (= y (* x x))))
For every occurrence in your assertion where you have a square root, introduce a fresh variable and plug the fresh variable into that place. Then add the assertion
(assert (is_sqrt fresh-variable sub-term))
Z3 also provides a built-in operator for lifting terms into a power. You can use this to get a square root. So to write the square root of 'x', you can write the term:
(^ x 0.5)
The inference using powers in Z3 is somewhat limited, so it really depends on what your formula says whether this formulation will be handled in the same way as the relational encoding.