I was wondering if there is a simple or known way to minimize the number of unique elements in a decision variable (vector). Note that I'm not asking for minimization of nonzero elements (rank constraint). In particular I'm searching for a penalization (soft constraint) or hard constraint in the form $$f(x) <= n_{max} $$ where f() is what I'm searching for, x is the decision vector and n_max is the maximum number of unique elements that x is allowed to have.
EDIT: I am not trying to minimize the number of unique elements in a vector " per se", which of course is trivial. The question is related to minimizing the unique element in a vector of decision variables that is the solution to another optimization problem. Eg: $$argmin_{x} g(x) $$ s.t. $$x \in \mathbb{X} $$ $$\sum(unique(x))<n_{max }$$ Thank you for your time, Lorenzo