# 4.2.2.8. Mathematical constraints

## arg_max

 ```1. function var \$\$E: arg_max(array [\$\$E] of var int: x) 2. function var \$\$E: arg_max(array [\$\$E] of var bool: x) 3. function var \$\$E: arg_max(array [\$\$E] of var float: x) 4. function var \$\$E: arg_max(array [\$\$E] of var opt int: x) 5. function var \$\$E: arg_max(array [\$\$E] of var opt bool: x) 6. function var \$\$E: arg_max(array [\$\$E] of var opt float: x) ``` 1-3. Returns the index of the maximum value in the array x. When breaking ties the least index is returned. 4-6. Returns the index of the maximum non-absent value in the array x. When breaking ties the least index is returned.

## arg_max_weak

 ```function var opt \$\$E: arg_max_weak(array [\$\$E] of var opt int: x) function var opt \$\$E: arg_max_weak(array [\$\$E] of var opt bool: x) function var opt \$\$E: arg_max_weak(array [\$\$E] of var opt float: x) ``` Returns the index of the maximum non-absent value in the array x. When breaking ties the least index is returned. Returns absent when all elements are absent.

## arg_min

 ```1. function var \$\$E: arg_min(array [\$\$E] of var int: x) 2. function var \$\$E: arg_min(array [\$\$E] of var bool: x) 3. function var \$\$E: arg_min(array [\$\$E] of var float: x) 4. function var \$\$E: arg_min(array [\$\$E] of var opt int: x) 5. function var \$\$E: arg_min(array [\$\$E] of var opt bool: x) 6. function var \$\$E: arg_min(array [\$\$E] of var opt float: x) ``` 1-3. Returns the index of the minimum value in the array x. When breaking ties the least index is returned. 4-6. Returns the index of the minimum non-absent value in the array x. When breaking ties the least index is returned.

## arg_min_weak

 ```function var opt \$\$E: arg_min_weak(array [\$\$E] of var opt int: x) function var opt \$\$E: arg_min_weak(array [\$\$E] of var opt bool: x) function var opt \$\$E: arg_min_weak(array [\$\$E] of var opt float: x) ``` Returns the index of the minimum non-absent value in the array x. When breaking ties the least index is returned. Returns absent when all elements are absent.

## arg_val

 ```function var \$\$E: arg_val(array [\$\$E] of var bool: x, var bool: v) function var \$\$E: arg_val(array [\$\$E] of var opt bool: x, var opt bool: v) function var \$\$E: arg_val(array [\$\$E] of var float: x, var float: v) function var \$\$E: arg_val(array [\$\$E] of var opt float: x, var float: v) function var \$\$E: arg_val(array [\$\$E] of var \$\$V: x, var \$\$V: v) function var \$\$E: arg_val(array [\$\$E] of var opt \$\$V: x, var opt \$\$V: v) ``` Returns the index of the value v in the array x. When breaking ties the least index is returned. Note that this function forces the value v to occur in x.

## arg_val_weak

 ```function var opt \$\$E: arg_val_weak(array [\$\$E] of var bool: x, var bool: v) function var opt \$\$E: arg_val_weak(array [\$\$E] of var opt bool: x, var opt bool: v) function var opt \$\$E: arg_val_weak(array [\$\$E] of var float: x, var float: v) function var opt \$\$E: arg_val_weak(array [\$\$E] of var opt float: x, var opt float: v) function var opt \$\$E: arg_val_weak(array [\$\$E] of var \$\$V: x, var \$\$V: v) function var opt \$\$E: arg_val_weak(array [\$\$E] of var opt \$\$V: x, var opt \$\$V: v) ``` Returns the index of the value v in the array x when v. When breaking ties the least index is returned. Returns absent when v does not occur in x.

## maximum

 ```predicate maximum(var \$\$E: m, array [int] of var \$\$E: x) predicate maximum(var float: m, array [int] of var float: x) ``` Constrains m to be the maximum of the values in x. Assumptions: |x| > 0.

## maximum_arg

 ```1. predicate maximum_arg(array [int] of var int: x, var int: i) 2. predicate maximum_arg(array [\$\$E] of var bool: x, var \$\$E: i) 3. predicate maximum_arg(array [\$\$E] of var float: x, var \$\$E: i) ``` 1, 2. Constrain i to be the index of the maximum value in the array x. When breaking ties the least index is returned. Assumption: |x| > 0 Constrain i to be the index of the maximum value in the array x. When breaking ties the least index is returned. Assumption: |x| > 0

## minimum

 ```predicate minimum(var float: m, array [int] of var float: x) predicate minimum(var \$\$E: m, array [int] of var \$\$E: x) ``` Constrains m to be the minimum of the values in x. Assumptions: |x| > 0.

## minimum_arg

 ```predicate minimum_arg(array [int] of var int: x, var int: i) predicate minimum_arg(array [int] of var bool: x, var int: i) predicate minimum_arg(array [int] of var float: x, var int: i) ``` Constrain i to be the index of the minimum value in the array x. When breaking ties the least index is returned. Assumption: |x| > 0

## piecewise_linear

 ```1. function var float: piecewise_linear(var float: x, array [int] of float: xi, array [int] of float: vi) 2. predicate piecewise_linear(var float: x, var float: y, array [int] of float: xi, array [int] of float: vi) 3. function var float: piecewise_linear(var float: x, array [int] of float: x_start, array [int] of float: x_end, array [int] of float: v_start, array [int] of float: v_end) 4. predicate piecewise_linear(var float: x, var float: y, array [int] of float: x_start, array [int] of float: x_end, array [int] of float: v_start, array [int] of float: v_end) ``` Return the piecewise-linear function of x on the given point-value sequence. The array xi defines the points, and vi the corresponding values. Constrains y(x) to be the piecewise-linear function on the provided point-value sequence. The array xi defines the points, and vi the corresponding values. Return the piecewise-linear function of x on the given (possibly disconnected) intervals. Each interval i connects (x_start[i], v_start[i]) to (x_end[i], v_end[i]). Constrains y(x) to be the piecewise-linear function on the given (possibly disconnected) intervals. Each interval i connects (x_start[i], v_start[i]) to (x_end[i], v_end[i]).

## range

 ```1. predicate range(array [\$\$X] of var \$\$Y: x, var set of \$\$X: s, var set of \$\$Y: t) 2. function var set of int: range(array [int] of var int: x, var set of int: s) ``` Requires that the image of function x (represented as an array) on set of values s is t. ub(s) must be a subset of index_set(x) otherwise an assertion failure will occur. Returns the image of function x (represented as an array) on set of values s. ub(s) must be a subset of index_set(x) otherwise an assertion failure will occur.

## sliding_sum

 ```predicate sliding_sum(int: low, int: up, int: seq, array [int] of var int: vs) ``` Requires that in each subsequence vs[i], …, vs[i + seq - 1] the sum of the values belongs to the interval [low, up].

## sum_pred

 ```predicate sum_pred(var \$\$X: i, array [\$\$X] of set of \$\$Y: sets, array [\$\$Y] of int: cs, var int: s) ``` Requires that the sum of cs[i1]..cs[iN] equals s, where i1..iN are the elements of the i th set in sets. Nb: not called ‘sum’ as in the constraints catalog because ‘sum’ is a MiniZinc built-in function.

## sum_set

 ```predicate sum_set(array [\$\$X] of \$\$Y: vs, array [\$\$X] of int: ws, var set of \$\$Y: x, var int: s) ``` Requires that the sum of the weights ws[i1]..ws[iN] equals s, where vs[i1]..vs[iN] are the elements appearing in set x