# 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¶

 function int: count(array [$T] of bool: x) function var int: count(array [$T] of var bool: x)  Return number of true elments in array x

### max¶

 1. function $T: max($T: x, $T: y) 2. function var int: max(var int: x, var int: y) 3. function var float: max(var float: x, var float: y) 4. function$T: max(array [$U] of$T: x) 5. function var int: max(array [$U] of var int: x) 6. function var float: max(array [$U] of var float: x) 7. function var int: max(array [$X] of var opt int: x) 8. function var float: max(array [$X] of var opt float: x) 9. function $$E: max(set of$$E: x)  1-3. Return maximum of x and y 4-6. Return maximum of elements in array x 7, 8. Return maximum of elements in x that are not absent. Result is undefined when all values are absent. Return maximum of elements in set x

### max_weak¶

 function var opt int: max_weak(array [$X] of var opt int: x) function var opt float: max_weak(array [$X] of var opt float: x)  Return maximum of elements in x that are not absent. Result is absent when all values are absent.

### min¶

 1. function $T: min($T: x, $T: y) 2. function var int: min(var int: x, var int: y) 3. function var float: min(var float: x, var float: y) 4. function$T: min(array [$U] of$T: x) 5. function var int: min(array [$U] of var int: x) 6. function var float: min(array [$U] of var float: x) 7. function var int: min(array [$X] of var opt int: x) 8. function var float: min(array [$X] of var opt float: x) 9. function $$E: min(set of$$E: x)  1-3. Return minimum of x and y 4-6. Return minimum of elements in array x 7, 8. Return minimum of elements in x that are not absent. Result is undefined when all values are absent. Return minimum of elements in set x

### min_weak¶

 function var opt int: min_weak(array [$X] of var opt int: x) function var opt float: min_weak(array [$X] of var opt float: x)  Return minimum of elements in x that are not absent. Result is absent when all values are absent.

### pow¶

 1. function int: pow(int: x, int: y) 2. function var int: pow(var int: x, int: y) 3. function var int: pow(var int: x, var int: y) 4. function float: pow(float: x, float: y) 5. function var float: pow(var float: x, var float: y)  Return $${\bf x} ^ {{\bf y}}$$, when $${\bf y} < 0$$ it returns 1 div pow(x, abs(y)). Return $${\bf x} ^ {{\bf y}}$$, when $${\bf y} < 0$$ it returns 1 div pow(x, abs(y)) Return $${\bf x} ^ {{\bf y}}$$, when $${\bf y} < 0$$ it returns 1 div pow(1, abs(y)) 4, 5. Return $${\bf x} ^ {{\bf y}}$$

### product¶

 1. function int: product(array [$T] of int: x) 2. function var int: product(array [$T] of var int: x) 3. function float: product(array [$T] of float: x) 4. function var float: product(array [$T] of var float: x) 5. function int: product(array [$T] of opt int: x) 6. function var int: product(array [$T] of var opt int: x) 7. function float: product(array [$T] of opt float: x) 8. function var float: product(array [$T] of var opt float: x)  1-4. Return product of elements in array x 5-8. Return product of non-absent elements of x.

### sqrt¶

 function float: sqrt(float: x) function var float: sqrt(var float: x)  Return $$\sqrt{{\bf x}}$$

### sum¶

 1. function int: sum(array [$T] of int: x) 2. function var int: sum(array [$T] of var int: x) 3. function float: sum(array [$T] of float: x) 4. function var float: sum(array [$T] of var float: x) 5. function var int: sum(array [int] of var opt int: x) 6. function int: sum(array [int] of opt int: x) 7. function var float: sum(array [int] of var opt float: x) 8. function float: sum(array [int] of opt float: x)  1-4. Return sum of elements in array x 5-8. Return sum of non-absent elements of x.

### ~*¶

 function var opt int: '~*'(var opt int: x, var opt int: y) function var opt float: '~*'(var opt float: x, var opt float: y)  Weak multiplication. Return product of x and y if both are present, otherwise return absent.

### ~+¶

 function var opt int: '~+'(var opt int: x, var opt int: y) function var opt float: '~+'(var opt float: x, var opt float: y)  Weak addition. Return sum of x and y if both are present, otherwise return absent.

### ~-¶

 function var opt int: '~-'(var opt int: x, var opt int: y) function var opt float: '~-'(var opt float: x, var opt float: y)  Weak subtraction. Return difference of x and y if both are present, otherwise return absent.

### ~/¶

 function var opt float: '~/'(var opt float: x, var opt float: y) function opt float: '~/'(opt float: x, opt float: y)  Weal optional division. Return absent if x or y is absent, x divided by y if both are present.

### ~div¶

 function var opt int: '~div'(var opt int: x, var opt int: y) function opt int: '~div'(opt int: x, opt int: y)  Weak optional division. Return absent if x or y is absent, x divided by y if both are present.

## Exponential and logarithmic builtins¶

These builtins implement exponential and logarithmic functions.

In this section: exp, ln, log, log10, log2.

### exp¶

 function float: exp(float: x) function var float: exp(var float: x)  Return $$e ^ {{\bf x}}$$

### ln¶

 function float: ln(float: x) function var float: ln(var float: x)  Return $$\ln {\bf x}$$

### log¶

 function float: log(float: x, float: y)  Return $$\log_{{\bf x}} {\bf y}$$

### log10¶

 function float: log10(float: x) function var float: log10(var float: x)  Return $$\log_{10} {\bf x}$$

### log2¶

 function float: log2(float: x) function var float: log2(var float: x)  Return $$\log_{2} {\bf x}$$

## Trigonometric functions¶

These builtins implement the standard trigonometric functions.

In this section: acos, acosh, asin, asinh, atan, atanh, cos, cosh, sin, sinh, tan, tanh.

### acos¶

 function float: acos(float: x) function var float: acos(var float: x)  Return $$\mbox{acos}\ {\bf x}$$

### acosh¶

 function float: acosh(float: x) function var float: acosh(var float: x)  Return $$\mbox{acosh}\ {\bf x}$$

### asin¶

 function float: asin(float: x) function var float: asin(var float: x)  Return $$\mbox{asin}\ {\bf x}$$

### asinh¶

 function float: asinh(float: x) function var float: asinh(var float: x)  Return $$\mbox{asinh}\ {\bf x}$$

### atan¶

 function float: atan(float: x) function var float: atan(var float: x)  Return $$\mbox{atan}\ {\bf x}$$

### atanh¶

 function float: atanh(float: x) function var float: atanh(var float: x)  Return $$\mbox{atanh}\ {\bf x}$$

### cos¶

 function float: cos(float: x) function var float: cos(var float: x)  Return $$\cos {\bf x}$$

### cosh¶

 function float: cosh(float: x) function var float: cosh(var float: x)  Return $$\cosh {\bf x}$$

### sin¶

 function float: sin(float: x) function var float: sin(var float: x)  Return $$\sin {\bf x}$$

### sinh¶

 function float: sinh(float: x) function var float: sinh(var float: x)  Return $$\sinh {\bf x}$$

### tan¶

 function float: tan(float: x) function var float: tan(var float: x)  Return $$\tan {\bf x}$$

### tanh¶

 function float: tanh(float: x) function var float: tanh(var float: x)  Return $$\tanh {\bf x}$$

## Coercions¶

These functions implement coercions, or channeling, between different types.

In this section: bool2float, bool2int, ceil, floor, int2float, round, set2array.

### bool2float¶

 1. function float: bool2float(bool: b) 2. function opt float: bool2float(opt bool: b) 3. function array [$T] of float: bool2float(array [$T] of bool: x) 4. function array [$T] of var float: bool2float(array [$T] of var bool: x) 5. function var float: bool2float(var bool: b) 6. function var opt float: bool2float(var opt bool: x) 7. function array [$T] of opt float: bool2float(array [$T] of opt bool: x) 8. function array [$T] of var opt float: bool2float(array [$T] of var opt bool: x)  1, 2. Return Boolean b coerced to a float 3, 4. Return array of Booleans x coerced to an array of floats Return Boolean b coerced to a float Return optional 0/1 float that is absent iff x is absent, and 1 iff x occurs and is true. 7, 8. Return array of Booleans x coerced to an array of floats

### bool2int¶

  1. function int: bool2int(bool: b) 2. function opt int: bool2int(opt bool: b) 3. function var opt int: bool2int(var opt bool: x) 4. function var int: bool2int(var bool: b) 5. function array [$T] of var int: bool2int(array [$T] of var bool: b) 6. function array [$T] of int: bool2int(array [$T] of bool: x) 7. function array [$T] of set of int: bool2int(array [$T] of set of bool: x) 8. function array [$T] of var int: bool2int(array [$T] of var bool: x) 9. function array [$T] of opt int: bool2int(array [$T] of opt bool: x) 10. function array [$T] of var opt int: bool2int(array [$T] of var opt bool: x)  1, 2. Return Boolean b coerced to an integer Return optional 0/1 integer that is absent iff x is absent, and 1 iff x occurs and is true. Return Boolean b coerced to an integer Return array of Booleans b coerced to an array of integers Return array of Booleans x coerced to an array of integers Return array of sets of Booleans x coerced to an array of sets of integers 8-10. Return array of Booleans x coerced to an array of integers

### ceil¶

 function int: ceil(float: x)  Return $$\lceil{ {\bf x}} \rceil$$

### floor¶

 function int: floor(float: x)  Return $$\lfloor{ {\bf x}} \rfloor$$

### int2float¶

 1. function float: int2float(int: x) 2. function opt float: int2float(opt int: x) 3. function var float: int2float(var int: x) 4. function var opt float: int2float(var opt int: x) 5. function array [$T] of float: int2float(array [$T] of int: x) 6. function array [$T] of opt float: int2float(array [$T] of opt int: x) 7. function array [$T] of var float: int2float(array [$T] of var int: x) 8. function array [$T] of var opt float: int2float(array [$T] of var opt int: x)  1-3. Return integer x coerced to a float Return optional 0/1 integer that is absent iff x is absent, and 1 iff x occurs and is true. 5-7. Return array of integers x coerced to an array of floats Return array of optional integers x coerced to an array of optional floats

### round¶

 function int: round(float: x)  Return x rounded to nearest integer

### set2array¶

 function array [int] of $$E: set2array(set of$$E: x)  Return a set of integers x coerced to an array of integers

## Array operations¶

These functions implement the basic operations on arrays.

### Functions and Predicates¶

#### array5d¶

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

### ‘in’¶

 1. test 'in'(int: x, set of int: y) 2. predicate 'in'(var int: x, var set of int: y) 3. predicate 'in'(var opt int: x, set of int: y) 4. test 'in'(opt int: x, set of int: y) 5. predicate 'in'(var opt int: x, var set of int: y) 6. test 'in'(float: x, set of float: y) 7. predicate 'in'(var float: x, set of float: y) 8. test 'in'(opt float: x, set of float: y) 9. predicate 'in'(var opt float: x, set of float: y)  Test if x is an element of the set y Usage: x in y x is an element of the set y Usage: x in y x is an element of the set y. False if x is absent. Usage: x in y Test if x is an element of the set y. False if x is absent. Usage: x in y x is an element of the set y. False if x is absent. Usage: x in y 6, 7. Test if x is an element of the set y Usage: x in y Test if x is an element of the set y. False if x is absent. Usage: x in y x is an element of the set y. False if x is absent. Usage: x in y

### ..o¶

 function set of $$E: '..o'($$E: a)  Return the set $$\{{\bf a},\ldots,{\bf b}-1\}$$