# 4.2.1.1. Built-in functions and operators¶

These functions and operators provide the core of the MiniZinc expression language.

## Comparison Builtins¶

These builtins implement comparison operations.

In this section: ‘!=’, ‘<’, ‘<=’, ‘=’, ‘>’, ‘>=’, ~!=, ~=.

### ‘!=’¶

 1. test '!='($T: x,$T: y) 2. test '!='(opt $T: x, opt$T: y) 3. predicate '!='(any $T: x, any$T: y) 4. test '!='(array [$U] of$T: x, array [$U] of$T: y) 5. test '!='(array [$U] of opt$T: x, array [$U] of opt$T: y) 6. predicate '!='(array [$U] of var$T: x, array [$U] of var$T: y) 7. predicate '!='(array [$U] of var opt$T: x, array [$U] of var opt$T: y)  1-3. Return if x is not equal to y Usage: x != y 4-7. Return if array x is not equal to array y Usage: x != y

### ‘<’¶

  1. test '<'($T: x,$T: y) 2. predicate '<'(var $T: x, var$T: y) 3. predicate '<'(var opt int: x, var opt int: y) 4. test '<'(opt int: x, opt int: y) 5. predicate '<'(var opt float: x, var opt float: y) 6. test '<'(opt float: x, opt float: y) 7. test '<'(array [$U] of$T: x, array [$U] of$T: y) 8. predicate '<'(array [$U] of var int: x, array [$U] of var int: y) 9. predicate '<'(array [$U] of var bool: x, array [$U] of var bool: y) 10. predicate '<'(array [$U] of var float: x, array [$U] of var float: y) 11. predicate '<'(array [$U] of var set of int: x, array [$U] of var set of int: y)  1, 2. Return if x is less than y Usage: x < y 3-6. Weak comparison: true iff either x or y is absent, or both occur and the value of x is less than the value of y. Usage: x < y 7-11. Return if array x is lexicographically smaller than array y Usage: x < y

### ‘<=’¶

  1. test '<='($T: x,$T: y) 2. predicate '<='(var $T: x, var$T: y) 3. predicate '<='(var opt int: x, var opt int: y) 4. test '<='(opt int: x, opt int: y) 5. predicate '<='(var opt float: x, var opt float: y) 6. test '<='(opt float: x, opt float: y) 7. test '<='(array [$U] of$T: x, array [$U] of$T: y) 8. predicate '<='(array [$U] of var int: x, array [$U] of var int: y) 9. predicate '<='(array [$U] of var bool: x, array [$U] of var bool: y) 10. predicate '<='(array [$U] of var float: x, array [$U] of var float: y) 11. predicate '<='(array [$U] of var set of int: x, array [$U] of var set of int: y)  1, 2. Return if x is less than or equal to y Usage: x <= y 3-6. Weak comparison: true iff either x or y is absent, or both occur and the value of x is less than or equal to the value of y. Usage: x <= y 7-11. Return if array x is lexicographically smaller than or equal to array y Usage: x <= y

### ‘=’¶

 1. test '='($T: x,$T: y) 2. test '='(opt $T: x, opt$T: y) 3. predicate '='(any $T: x, any$T: y) 4. test '='(array [$U] of$T: x, array [$U] of$T: y) 5. test '='(array [$U] of opt$T: x, array [$U] of opt$T: y) 6. predicate '='(array [$U] of var$T: x, array [$U] of var$T: y) 7. predicate '='(array [$U] of var opt$T: x, array [$U] of var opt$T: y)  1-3. Return if x is equal to y Usage: x = y 4-7. Return if array x is equal to array y Usage: x = y

### ‘>’¶

  1. test '>'($T: x,$T: y) 2. predicate '>'(var $T: x, var$T: y) 3. predicate '>'(var opt int: x, var opt int: y) 4. test '>'(opt int: x, opt int: y) 5. predicate '>'(var opt float: x, var opt float: y) 6. test '>'(opt float: x, opt float: y) 7. test '>'(array [$U] of$T: x, array [$U] of$T: y) 8. predicate '>'(array [$U] of var int: x, array [$U] of var int: y) 9. predicate '>'(array [$U] of var bool: x, array [$U] of var bool: y) 10. predicate '>'(array [$U] of var float: x, array [$U] of var float: y) 11. predicate '>'(array [$U] of var set of int: x, array [$U] of var set of int: y)  1, 2. Return if x is greater than y Usage: x > y 3-6. Weak comparison: true iff either x or y is absent, or both occur and the value of x is greater than the value of y. Usage: x > y 7-11. Return if array x is lexicographically greater than array y Usage: x > y

### ‘>=’¶

  1. test '>='($T: x,$T: y) 2. predicate '>='(var $T: x, var$T: y) 3. predicate '>='(var opt int: x, var opt int: y) 4. test '>='(opt int: x, opt int: y) 5. predicate '>='(var opt float: x, var opt float: y) 6. test '>='(opt float: x, opt float: y) 7. test '>='(array [$U] of$T: x, array [$U] of$T: y) 8. predicate '>='(array [$U] of var int: x, array [$U] of var int: y) 9. predicate '>='(array [$U] of var bool: x, array [$U] of var bool: y) 10. predicate '>='(array [$U] of var float: x, array [$U] of var float: y) 11. predicate '>='(array [$U] of var set of int: x, array [$U] of var set of int: y)  1, 2. Return if x is greater than or equal to y Usage: x >= y 3-6. Weak comparison: true iff either x or y is absent, or both occur and the value of x is greater than or equal to the value of y. Usage: x >= y 7-11. Return if array x is lexicographically greater than or equal to array y Usage: x >= y

### ~!=¶

 predicate '~!='(var opt bool: x, var opt bool: y) predicate '~!='(var opt int: x, var opt int: y) predicate '~!='(var opt float: x, var opt float: y)  Weak disequality. True if either x or y are absent, or present and not equal.

### ~=¶

 predicate '~='(var opt bool: x, var opt bool: y) predicate '~='(var opt int: x, var opt int: y) predicate '~='(var opt float: x, var opt float: y)  Weak equality. True if either x or y are absent, or present and equal.

## Arithmetic Builtins¶

These builtins implement arithmetic operations.

In this section: ‘*’, ‘+’, ‘-‘, ‘/’, ‘^’, ‘div’, ‘mod’, abs, arg_max, arg_min, count, max, max_weak, min, min_weak, pow, product, sqrt, sum, ~*, ~+, ~-, ~/, ~div.

### ‘*’¶

 1. function int: '*'(int: x, int: y) 2. function var int: '*'(var int: x, var int: y) 3. function var int: '*'(var opt int: x, var opt int: y) 4. function int: '*'(opt int: x, opt int: y) 5. function var float: '*'(var opt float: x, var opt float: y) 6. function float: '*'(opt float: x, opt float: y) 7. function float: '*'(float: x, float: y) 8. function var float: '*'(var float: x, var float: y)  1, 2. Return x * y Usage: x * y 3-6. Optional multiplication. Return product of x and y, with absent replaced by 1. Usage: x * y 7, 8. Return x * y Usage: x * y

### ‘+’¶

 1. function int: '+'(int: x, int: y) 2. function var int: '+'(var int: x, var int: y) 3. function float: '+'(float: x, float: y) 4. function var float: '+'(var float: x, var float: y) 5. function var int: '+'(var opt int: x, var opt int: y) 6. function int: '+'(opt int: x, opt int: y) 7. function var float: '+'(var opt float: x, var opt float: y) 8. function float: '+'(opt float: x, opt float: y)  1-4. Return x + y Usage: x + y 5-8. Optional addition. Return sum of x and y, with absent replaced by 0. Usage: x + y

### ‘-‘¶

  1. function int: '-'(int: x, int: y) 2. function var int: '-'(var int: x, var int: y) 3. function float: '-'(float: x, float: y) 4. function var float: '-'(var float: x, var float: y) 5. function var opt int: '-'(var opt int: x, var opt int: y) 6. function var opt float: '-'(var opt float: x, var opt float: y) 7. function opt int: '-'(opt int: x, opt int: y) 8. function opt float: '-'(opt float: x, opt float: y) 9. function int: '-'(int: x) 10. function var int: '-'(var int: x) 11. function float: '-'(float: x) 12. function var float: '-'(var float: x)  1-4. Return x - y Usage: x - y 5-8. Optional subtraction. Return absent if x is absent, x if y is absent, difference of x and y if both are present. Usage: x - y 9-12. Return negative x Usage: - x

### ‘/’¶

 1. function float: '/'(float: x, float: y) 2. function var float: '/'(var float: x, var float: y) 3. function var opt float: '/'(var opt float: x, var opt float: y) 4. function opt float: '/'(opt float: x, opt float: y)  1, 2. Return result of floating point division x / y Usage: x / y 3, 4. Optional division. Return absent if x is absent, x if y is absent, x divided by y if both are present. Usage: x / y

### ‘^’¶

 function int: '^'(int: x, int: y) function var int: '^'(var int: x, var int: y) function float: '^'(float: x, float: y) function var float: '^'(var float: x, var float: y)  Return $${\bf x} ^ {{\bf y}}$$ Usage: x ^ y

### ‘div’¶

 1. function int: 'div'(int: x, int: y) 2. function var int: 'div'(var int: x, var int: y) 3. function var opt int: 'div'(var opt int: x, var opt int: y) 4. function opt int: 'div'(opt int: x, opt int: y)  1, 2. Return result of integer division x / y Usage: x div y 3, 4. Optional division. Return absent if x is absent, x if y is absent, x divided by y if both are present. Usage: x div y

### ‘mod’¶

 1. function int: 'mod'(int: x, int: y) 2. function var int: 'mod'(var int: x, var int: y) 3. function var opt int: 'mod'(var opt int: x, var opt int: y) 4. function opt int: 'mod'(opt int: x, opt int: y)  1, 2. Return remainder of integer division x % y Usage: x mod y 3, 4. Optional modulo. Return absent if x or y is absent, x modulo y if both are present. Usage: x mod y

### abs¶

 function int: abs(int: x) function var int: abs(var int: x) function float: abs(float: x) function var float: abs(var float: x)  Return absolute value of x

### arg_max¶

 function $$E: arg_max(array [$$E] of bool: x) function $$E: arg_max(array [$$E] of int: x) function $$E: arg_max(array [$$E] of float: x)  Returns the index of the maximum value in the array x. When breaking ties the least index is returned.

### arg_min¶

 function $$E: arg_min(array [$$E] of bool: x) function $$E: arg_min(array [$$E] of int: x) function $$E: arg_min(array [$$E] of float: x)  Returns the index of the minimum value in the array x. When breaking ties the least index is returned.

### count¶

#### ‘in’¶

 test 'in'($X: x, array [$T] of $X: y) test 'in'(opt$X: x, array [$T] of opt$X: y) predicate 'in'(var $X: x, array [$T] of var $X: y) predicate 'in'(var opt$X: x, array [$T] of var opt$X: y) test 'in'(set of $X: x, array [$T] of set of $X: y) predicate 'in'(var set of$X: x, array [$T] of var set of$X: y)  Return if y contains x Usage: x in y

#### array2set¶

 function var set of $$T: array2set(array [int] of var$$T: x) function set of $$T: array2set(array [int] of$$T: x) function set of $$T: array2set(array [int] of opt$$T: x) function set of bool: array2set(array [int] of bool: x) function set of float: array2set(array [int] of float: x)  Return the set containing the elements of x

#### array3d¶

 function array [$$E,$$F,$$G] of any V: array3d(set of$$E: S1, set of $$F: S2, set of$$G: S3, array [$U] of any$V: x)  Return array x coerced to three-dimensional array with index sets S1, S2 and S3. Coercions are performed by considering the array x in row-major order.

#### arrayXd¶

 function array [$T] of any$V: arrayXd(array [$T] of any$X: x, array [$U] of any$V: y)  Return array y coerced to array with same number of dimensions and same index sets as array x. Coercions are performed by considering the array y in row-major order.