# How to rewrite a constraint with sum of convex and concave components to satisfy DCP rule?

suppose that decision variable is X with N dimensions, and one type of the constraint is y = y0-sum(max(0,x)*b)-sum(min(0,x)*a), where the dimension of x is from 1 to N which means that there are N constraints, and the y should be less than y_min and be greater than y_max, i.e. y_min <= y0-sum(max(0,x)*b)-sum(min(0,x)*a) <= y_max.

In cvxpy, it could be write as y0 - cp.sum(cp.pos(x[:i])*b) + cp.sum(cp.neg(x[:i])*a),

however, -cp.sum(cp.pos(x[:i])*b) is a concave expression, cp.sum(cp.neg(x[:i])*a) is a convex expression, and the sum of them would not satisfy the DCP rule.

Is it possible to rewrite this type of constraint to follow the DCP rule?

(although we could use dccp to solve it.)

• Not sure if this is helpful, but your concave expression can be made linear using extra binary variables. Commented Mar 1, 2023 at 15:11
• @ErwinKalvelagen, could you give me some examples? Thanks Commented Mar 1, 2023 at 15:17
• \begin{aligned} &y^+ - y^- = y \\ & y^+ \le M\delta\\& y^- \le M(1-\delta)\\&y^+,y^- \ge 0 \\ & \delta\in \{0,1\}\end{aligned} This formulation should really be in your toolbox as it is not uncommon. Commented Mar 1, 2023 at 15:21
• ok, I understand, I will try, Thanks @ErwinKalvelagen Commented Mar 1, 2023 at 15:30