# Does the cvxpy replace the max function by MIP formulation under the hood?

Does the cvxpy replace the max function, which is convex, by MIP formulation under the hood when shows up in the constraints (for example, $$\max(x,y)\le z$$) or in the objective function? In gurobipy, we need to introduce a new variable and new constraint: $$L=\max(x,y)$$ and $$L\le z$$

Then gurobipy converts it to MIP.

for example:

import gurobipy as gp
m=gp.Model()


L=gp.max_(x,y) is nonconvex, and gurobipy converts it to MIP convex under the hood.

$$\max(x,y)\le z$$ can b formulated in cvxpy as follows:

import cvxpy as cp
Cons=[cp.max(x,y)<=z]


Does cvxpy do something similar to gurobipy?

Thanks, @xd y! My problem was the following: $$g+z\ge\max(x,y)+L$$ Does that mean it can be rewritten as $$g+z\ge x+L$$, $$g+z\ge y+L$$?

No. Firstly you should use cp.maximum instead of cp.max. Secondly, it is converted to a convex programming problem (LP in this case, like $$x \leq z, y \leq z$$) since it follows DCP rules, rather than introducing binary variables. To see that, you can try Cons=[cp.maximum(x, y) >= z] and solving the problem, you will see it fails to solve it.
• My problem was like the following: $g+z>=max(x,y) +L$ This can be rewritten as: $g+z>=x +L$ $g+z>=y +L$ Thanks @xd y ! Commented Dec 5, 2022 at 2:29