Reputation: 39
I would like to define a piece-wise (linear) function in Z3py, for example, the function f(x)
has the form
f(x) = a*x + b when 0 <= x <= 1
f(x) = exp(c*x) when 1 < x <= 2
f(x) = 1/(1+10^x) when 2 < x <= 3
etc.
where a
, b
and c
are constants.
I guess the z3.If()
function will be relevant, but as the number of pieces grows, the expression gets convoluted.
My questions is, does Z3pyprovides the if-else statement, or is there an elegant way to define piece-wise function in Z3py?
Upvotes: 0
Views: 169
Reputation: 8393
Yes, Z3 supports if-then-elses and in Python they can be constructed using the If
function. An example from the documentation of If
:
>>> x = Int('x')
>>> y = Int('y')
>>> max = If(x > y, x, y)
max = If(x > y, x, y)
Upvotes: 2