I'm trying to find a maximum for a function whose variables have binary values (either -1 or 1). The clumsy code for that constraint I use is shown below. There must be a more compact code, and I would be grateful for any suggestion.
That said, the sum works (1st expression given below), but the product doesn't (2nd expression). What am I doing wrong? Any clue how to fix all this?
I would like to obtain Max of f[x, y , z, ...]
where the arguments take on only binary values.
FindMaximum[
{x + y,
x >= -1 && x <= 1 && (x ∈ NegativeIntegers ∨ x ∈ PositiveIntegers),
y >= -1 && y <= 1 && (y ∈ NegativeIntegers ∨ y ∈ PositiveIntegers)},
{x, y}]```
{2., {x -> 1, y -> 1}}
FindMaximum[
{x * y,
x >= -1 && x <= 1 && ((x ∈ NegativeIntegers) ∨ (x ∈ PositiveIntegers)),
y >= -1 && y <= 1 && ((y ∈ NegativeIntegers) ∨ (y ∈ PositiveIntegers))},
{x, y}]
Error := Constraints in ({x ∈ Z, y ∈ Z, x > 0, y > 0, x >= -1, y >= -1, x <= 1, y <= 1}) are not all equality or inequality constraints.```