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 [int] of var opt int: x)

8.  function var float: max(array [int] 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.
  1. Return maximum of elements in set x

max_weak

function var opt int: max_weak(array [int] of var opt int: x)
function var opt float: max_weak(array [int] 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 [int] of var opt int: x)

8.  function var float: min(array [int] 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.
  1. Return minimum of elements in set x

min_weak

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

pow

function int: pow(int: x, int: y)
function var int: pow(var int: x, var int: y)
function float: pow(float: x, float: y)
function var float: pow(var float: x, var float: y)
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 [int] of opt int: x)

6.  function var int: product(array [int] of var opt int: x)

7.  function float: product(array [int] of opt float: x)

8.  function var float: product(array [int] 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
  1. Return Boolean b coerced to a float

  2. 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
  1. Return optional 0/1 integer that is absent iff x is absent, and 1 iff x occurs and is true.

  2. Return Boolean b coerced to an integer

  3. Return array of Booleans b coerced to an array of integers

  4. Return array of Booleans x coerced to an array of integers

  5. 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
  1. 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
  1. 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.

In this section: ‘++’, ‘in’, array1d, array2d, array2set, array3d, array4d, array5d, array6d, arrayXd, col, has_element, has_index, index_set, index_set_1of2, index_set_1of3, index_set_1of4, index_set_1of5, index_set_1of6, index_set_2of2, index_set_2of3, index_set_2of4, index_set_2of5, index_set_2of6, index_set_3of3, index_set_3of4, index_set_3of5, index_set_3of6, index_set_4of4, index_set_4of5, index_set_4of6, index_set_5of5, index_set_5of6, index_set_6of6, index_sets_agree, length, reverse, row, slice_1d, slice_2d, slice_3d, slice_4d, slice_5d, slice_6d, array_check_form.

Functions and Predicates

‘++’

function array [int] of any $T: '++'(array [int] of any $T: x,
                                     array [int] of any $T: y)

Return the concatenation of arrays x and y

Usage: x ++ y

‘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

array1d

1.  function array [int] of any $V: array1d(array [$U] of any $V: x)

2.  function array [$$E] of any $V: array1d(set of $$E: S,
                                            array [$U] of any $V: x)
  1. Return array x coerced to index set 1..length(x). Coercions are performed by considering the array x in row-major order.

  2. Return array x coerced to one-dimensional array with index set S. Coercions are performed by considering the array x in row-major order.

array2d

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

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.

array4d

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

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.

array6d

function array [$$E,$$F,$$G,$$H,$$I,$$J] of any $V: array6d(set of $$E: S1,
                                                            set of $$F: S2,
                                                            set of $$G: S3,
                                                            set of $$H: S4,
                                                            set of $$I: S5,
                                                            set of $$J: S6,
                                                            array [$U] of any $V: x)
Return array x coerced to 6-dimensional array with index sets S1, S2, S3, S4, S5 and S6. 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.

col

function array [$$E] of any $T: col(array [$$E,int] of any $T: x,
                                    int: c)
Return column c of array x

has_element

test has_element($T: e, array [int] of $T: x)
test has_element($T: e, array [int] of opt $T: x)
predicate has_element($T: e, array [$$E] of any $T: x)
Test if e is an element of array x

has_index

test has_index(int: i, array [int] of any $T: x)
Test if i is in the index set of x

index_set

function set of $$E: index_set(array [$$E] of any $U: x)
Return index set of one-dimensional array x

index_set_1of2

function set of $$E: index_set_1of2(array [$$E,int] of any $U: x)
Return index set of first dimension of two-dimensional array x

index_set_1of3

function set of $$E: index_set_1of3(array [$$E,int,int] of any $U: x)
Return index set of first dimension of 3-dimensional array x

index_set_1of4

function set of $$E: index_set_1of4(array [$$E,int,int,int] of any $U: x)
Return index set of first dimension of 4-dimensional array x

index_set_1of5

function set of $$E: index_set_1of5(array [$$E,int,int,int,int] of any $U: x)
Return index set of first dimension of 5-dimensional array x

index_set_1of6

function set of $$E: index_set_1of6(array [$$E,int,int,int,int,int] of any $U: x)
Return index set of first dimension of 6-dimensional array x

index_set_2of2

function set of $$E: index_set_2of2(array [int,$$E] of any $U: x)
Return index set of second dimension of two-dimensional array x

index_set_2of3

function set of $$E: index_set_2of3(array [int,$$E,int] of any $U: x)
Return index set of second dimension of 3-dimensional array x

index_set_2of4

function set of $$E: index_set_2of4(array [int,$$E,int,int] of any $U: x)
Return index set of second dimension of 4-dimensional array x

index_set_2of5

function set of $$E: index_set_2of5(array [int,$$E,int,int,int] of any $U: x)
Return index set of second dimension of 5-dimensional array x

index_set_2of6

function set of $$E: index_set_2of6(array [int,$$E,int,int,int,int] of any $U: x)
Return index set of second dimension of 6-dimensional array x

index_set_3of3

function set of $$E: index_set_3of3(array [int,int,$$E] of any $U: x)
Return index set of third dimension of 3-dimensional array x

index_set_3of4

function set of $$E: index_set_3of4(array [int,int,$$E,int] of any $U: x)
Return index set of third dimension of 4-dimensional array x

index_set_3of5

function set of $$E: index_set_3of5(array [int,int,$$E,int,int] of any $U: x)
Return index set of third dimension of 5-dimensional array x

index_set_3of6

function set of $$E: index_set_3of6(array [int,int,$$E,int,int,int] of any $U: x)
Return index set of third dimension of 6-dimensional array x

index_set_4of4

function set of $$E: index_set_4of4(array [int,int,int,$$E] of any $U: x)
Return index set of fourth dimension of 4-dimensional array x

index_set_4of5

function set of $$E: index_set_4of5(array [int,int,int,$$E,int] of any $U: x)
Return index set of fourth dimension of 5-dimensional array x

index_set_4of6

function set of $$E: index_set_4of6(array [int,int,int,$$E,int,int] of any $U: x)
Return index set of fourth dimension of 6-dimensional array x

index_set_5of5

function set of $$E: index_set_5of5(array [int,int,int,int,$$E] of any $U: x)
Return index set of fifth dimension of 5-dimensional array x

index_set_5of6

function set of $$E: index_set_5of6(array [int,int,int,int,$$E,int] of any $U: x)
Return index set of fifth dimension of 6-dimensional array x

index_set_6of6

function set of $$E: index_set_6of6(array [int,int,int,int,int,$$E] of any $U: x)
Return index set of sixth dimension of 6-dimensional array x

index_sets_agree

test index_sets_agree(array [$T] of any $U: x, array [$T] of any $W: y)
Test if x and y have the same index sets

length

function int: length(array [$T] of any $U: x)

Return the length of array x

Note that the length is defined as the number of elements in the array, regardless of its dimensionality.

reverse

function array [$$E] of $T: reverse(array [$$E] of $T: x)
function array [$$E] of opt $T: reverse(array [$$E] of opt $T: x)
function array [$$E] of any $T: reverse(array [$$E] of any $T: x)

Return the array x in reverse order

The resulting array has the same index set as x.

row

function array [$$E] of any $T: row(array [int,$$E] of any $T: x,
                                    int: r)
Return row r of array x

slice_1d

function array [$$F] of any $T: slice_1d(array [$E] of any $T: x,
                                         array [int] of set of int: s,
                                         set of $$F: dims1)
Return slice of array x specified by sets s, coerced to new 1d array with index set dims1

slice_2d

function array [$$F,$$G] of any $T: slice_2d(array [$E] of any $T: x,
                                             array [int] of set of int: s,
                                             set of $$F: dims1,
                                             set of $$G: dims2)
Return slice of array x specified by sets s, coerced to new 2d array with index sets dims1 and dims2

slice_3d

function array [$$F,$$G,$$H] of any $T: slice_3d(array [$E] of any $T: x,
                                                 array [int] of set of int: s,
                                                 set of $$F: dims1,
                                                 set of $$G: dims2,
                                                 set of $$H: dims3)
Return slice of array x specified by sets s, coerced to new 3d array with index sets dims1, dims2 and dims3

slice_4d

function array [$$F,$$G,$$H,$$I] of any $T: slice_4d(array [$E] of any $T: x,
                                                     array [int] of set of int: s,
                                                     set of $$F: dims1,
                                                     set of $$G: dims2,
                                                     set of $$H: dims3,
                                                     set of $$I: dims4)
Return slice of array x specified by sets s, coerced to new 4d array with index sets dims1, dims2, dims3, dims4

slice_5d

function array [$$F,$$G,$$H,$$I,$$J] of any $T: slice_5d(array [$E] of any $T: x,
                                                         array [int] of set of int: s,
                                                         set of $$F: dims1,
                                                         set of $$G: dims2,
                                                         set of $$H: dims3,
                                                         set of $$I: dims4,
                                                         set of $$J: dims5)
Return slice of array x specified by sets s, coerced to new 5d array with index sets dims1, dims2, dims3, dims4, dims5

slice_6d

function array [$$F,$$G,$$H,$$I,$$J,$$K] of any $T: slice_6d(array [$E] of any $T: x,
                                                             array [int] of set of int: s,
                                                             set of $$F: dims1,
                                                             set of $$G: dims2,
                                                             set of $$H: dims3,
                                                             set of $$I: dims4,
                                                             set of $$J: dims5,
                                                             set of $$K: dims6)
Return slice of array x specified by sets s, coerced to new 6d array with index sets dims1, dims2, dims3, dims4, dims5, dims6

Annotations

array_check_form

annotation array_check_form
Forces a arrayNd call to throw an error if the new index sets are offsets of the current index sets.

Logical operations

Logical operations are the standard operators of Boolean logic.

In this section: ‘->’, ‘/’, ‘<-‘, ‘<->’, ‘\/’, ‘not’, ‘xor’, bool_not, clause, exists, forall, iffall, xorall.

‘->’

test '->'(bool: x, bool: y)
test '->'(opt bool: x, opt bool: y)
predicate '->'(var bool: x, var bool: y)
predicate '->'(var opt bool: x, var opt bool: y)

Return truth value of x implies y

Usage: x -> y

‘/’

1.  test '/\'(bool: x, bool: y)

2.  test '/\'(opt bool: x, opt bool: y)

3.  predicate '/\'(var bool: x, var bool: y)

4.  predicate '/\'(var opt bool: x, var opt bool: y)
  1. Return truth value of x &and; y

    Usage: x /\ y

  2. Return truth value of x &and; y with identity <> = True

    Usage: x /\ y

  3. Return truth value of x &and; y

    Usage: x /\ y

  4. Return truth value of x &and; y with identity <> = True

    Usage: x /\ y

‘<-‘

test '<-'(bool: x, bool: y)
test '<-'(opt bool: x, opt bool: y)
predicate '<-'(var bool: x, var bool: y)
predicate '<-'(var opt bool: x, var opt bool: y)

Return truth value of y implies x

Usage: x <- y

‘<->’

test '<->'(bool: x, bool: y)
test '<->'(opt bool: x, opt bool: y)
predicate '<->'(var bool: x, var bool: y)
predicate '<->'(var opt bool: x, var opt bool: y)

Return truth value of x if-and-only-if y

Usage: x <-> y

‘/’

1.  test '\/'(bool: x, bool: y)

2.  test '\/'(opt bool: x, opt bool: y)

3.  predicate '\/'(var bool: x, var bool: y)

4.  predicate '\/'(var opt bool: x, var opt bool: y)
  1. Return truth value of x &or; y

    Usage: x \/ y

  2. Return truth value of x &or; y with identity <> = False

    Usage: x \/ y

  3. Return truth value of x &or; y

    Usage: x \/ y

  4. Return truth value of x &or; y with identity <> = False

    Usage: x \/ y

‘not’

1.  test 'not'(bool: x)

2.  function opt bool: 'not'(opt bool: x)

3.  predicate 'not'(var bool: x)

4.  function var opt bool: 'not'(var opt bool: x)
  1. Return truth value of the negation of x

    Usage: not x

  2. Negation of x if it occurs, otherwise absent

    Usage: not x

  3. Return truth value of the negation of x

    Usage: not x

  4. Negation of x if it occurs, otherwise absent

    Usage: not x

‘xor’

test 'xor'(bool: x, bool: y)
test 'xor'(opt bool: x, opt bool: y)
predicate 'xor'(var bool: x, var bool: y)
predicate 'xor'(var opt bool: x, var opt bool: y)

Return truth value of x xor y

Usage: x xor y

bool_not

predicate bool_not(var bool: b)
Return negation of b

clause

test clause(array [$T] of bool: x, array [$T] of bool: y)
test clause(array [$T] of opt bool: x, array [$T] of opt bool: y)
predicate clause(array [$T] of var bool: x, array [$T] of var bool: y)
predicate clause(array [$T] of var opt bool: x,
                 array [$T] of var opt bool: y)
Return truth value of \((\bigvee_i {\bf x}[i]) \lor (\bigvee_j \lnot {\bf y}[j])\)

exists

1.  test exists(array [$T] of bool: x)

2.  predicate exists(array [$T] of var bool: x)

3.  predicate exists(array [int] of var opt bool: x)
1, 2.
Return truth value of \(\bigvee_i {\bf x}[i]\)
  1. True iff for at least one i, x[i] occurs and is true

forall

1.  test forall(array [$T] of bool: x)

2.  predicate forall(array [$T] of var bool: x)

3.  predicate forall(array [int] of var opt bool: x)
1, 2.
Return truth value of \(\bigwedge_i {\bf x}[i]\)
  1. True iff for any i, x[i] is absent or true

iffall

test iffall(array [$T] of bool: x)
test iffall(array [$T] of opt bool: x)
predicate iffall(array [$T] of var bool: x)
predicate iffall(array [$T] of var opt bool: x)
Return truth value of \(\text{true}\oplus (\oplus_i {\bf x}[i])\)

xorall

test xorall(array [$T] of bool: x)
test xorall(array [$T] of opt bool: x)
predicate xorall(array [$T] of var bool: x)
predicate xorall(array [$T] of var opt bool: x)
Return truth value of \(\oplus_i {\bf x}[i]\)

Set operations

These functions implement the basic operations on sets.

In this section: ‘..’, ‘..<’, ‘<..’, ‘<..<’, ‘diff’, ‘in’, ‘intersect’, ‘subset’, ‘superset’, ‘symdiff’, ‘union’, ..<o, ..o, <..<o, <..o, array_intersect, array_union, card, max, min, o.., o..<, o<.., o<..<, set_to_ranges.

‘..’

function set of $$E: '..'($$E: a, $$E: b)
function set of float: '..'(float: a, float: b)
function set of bool: '..'(bool: a, bool: b)

Return the set \(\{{\bf a},\ldots,{\bf b}\}\)

Usage: a .. b

‘..<’

function set of $$E: '..<'($$E: a, $$E: b)

Return the set \(\{{\bf a},\ldots,{\bf b}-1\}\)

Usage: a ..< b

‘<..’

function set of $$E: '<..'($$E: a, $$E: b)

Return the set \(\{{\bf a}+1,\ldots,{\bf b}\}\)

Usage: a <.. b

‘<..<’

function set of $$E: '<..<'($$E: a, $$E: b)

Return the set \(\{{\bf a}+1,\ldots,{\bf b}-1\}\)

Usage: a <..< b

‘diff’

function set of $T: 'diff'(set of $T: x, set of $T: y)
function var set of $$T: 'diff'(var set of $$T: x, var set of $$T: y)

Return the set difference of sets \({\bf x} \setminus {\bf y}\)

Usage: x diff y

‘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)
  1. Test if x is an element of the set y

    Usage: x in y

  2. x is an element of the set y

    Usage: x in y

  3. x is an element of the set y. False if x is absent.

    Usage: x in y

  4. Test if x is an element of the set y. False if x is absent.

    Usage: x in y

  5. 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

  1. Test if x is an element of the set y. False if x is absent.

    Usage: x in y

  2. x is an element of the set y. False if x is absent.

    Usage: x in y

‘intersect’

function set of $T: 'intersect'(set of $T: x, set of $T: y)
function var set of $$T: 'intersect'(var set of $$T: x,
                                     var set of $$T: y)

Return the intersection of sets x and y

Usage: x intersect y

‘subset’

1.  test 'subset'(set of $T: x, set of $T: y)

2.  predicate 'subset'(var set of int: x, var set of int: y)
  1. Test if x is a subset of y

    Usage: x subset y

  2. x is a subset of y

    Usage: x subset y

‘superset’

1.  test 'superset'(set of $T: x, set of $T: y)

2.  predicate 'superset'(var set of int: x, var set of int: y)
  1. Test if x is a superset of y

    Usage: x superset y

  2. x is a superset of y

    Usage: x superset y

‘symdiff’

function set of $T: 'symdiff'(set of $T: x, set of $T: y)
function var set of $$T: 'symdiff'(var set of $$T: x,
                                   var set of $$T: y)

Return the symmetric set difference of sets x and y

Usage: x symdiff y

‘union’

function set of $T: 'union'(set of $T: x, set of $T: y)
function var set of $$T: 'union'(var set of $$T: x, var set of $$T: y)

Return the union of sets x and y

Usage: x union y

..<o

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

..o

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

<..<o

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

<..o

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

array_intersect

1.  function set of $U: array_intersect(array [$T] of set of $U: x)

2.  function var set of int: array_intersect(array [int] of var set of int: x)
  1. Return the intersection of the sets in array x

  2. Return the intersection of the sets in array x. Undefined for empty x.

array_union

function set of $U: array_union(array [$T] of set of $U: x)
function var set of int: array_union(array [int] of var set of int: x)
Return the union of the sets in array x

card

function int: card(set of $T: x)
function var int: card(var set of int: x)
Return the cardinality of the set x

max

function var $$E: max(var set of $$E: s)
Return the maximum of the set s

min

function var $$E: min(var set of $$E: s)
Return the minimum of the set s

o..

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

o..<

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

o<..

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

o<..<

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

set_to_ranges

function array [int] of int: set_to_ranges(set of int: S)
function array [int] of float: set_to_ranges(set of float: S)
function array [int] of bool: set_to_ranges(set of bool: S)
Return a sorted list of the non-overlapping ranges in S

String operations

These functions implement operations on strings.

In this section: ‘++’, concat, file_path, format, format_justify_string, join, json_array, json_object, outputJSON, outputJSONParameters, output_to_section, show, show2d, show2d_indexed, show3d, showJSON, show_float, show_int, string_length.

‘++’

function string: '++'(string: s1, string: s2)

Return concatenation of s1 and s2

Usage: s1 ++ s2

concat

function string: concat(array [$T] of string: s)
Return concatenation of strings in array s

file_path

function string: file_path()
Return path of file where this function is called

format

1.  function string: format(any $T: x)

2.  function string: format(array [$U] of any $T: x)

3.  function string: format(int: w, int: p, any $T: x)

4.  function string: format(int: w, int: p, array [$U] of any $T: x)

5.  function string: format(int: w, any $T: x)

6.  function string: format(int: w, array [$U] of any $T: x)
1, 2.
Convert x into a string
  1. Formatted to-string conversion

    Converts the value x into a string right justified by the number of characters given by w, or left justified if w is negative.

    The maximum length of the string representation of x is given by p, or the maximum number of digits after the decimal point for floating point numbers. It is a run-time error for p to be negative.

  2. Formatted to-string conversion

    Converts the value x into a string right justified by the number of characters given by w, or left justified if w is negative.

    The maximum length of the string representation of x is given by p. It is a run-time error for p to be negative.

5, 6.

Formatted to-string conversion

Converts the value x into a string right justified by the number of characters given by w, or left justified if w is negative.

format_justify_string

function string: format_justify_string(int: w, string: x)

String justification

Returns the string x right justified by the number of characters given by w, or left justified if w is negative.

join

function string: join(string: d, array [$T] of string: s)
Join string in array s using delimiter d

json_array

function string: json_array(array [int] of string: arr)

Create a JSON array from an array of JSON strings arr.

The elements are assumed to be strings already in JSON format (usually generated using showJSON)

json_object

function string: json_object(array [int,1..2] of string: obj)

Create a JSON object from an array of key-value pairs obj.

obj[i, 1] is the key name for the i-th entry obj[i, 2] is the JSON value for the o i-th entry (usually generated using showJSON)

outputJSON

1.  function array [int] of string: outputJSON()

2.  function array [int] of string: outputJSON(bool: b)
  1. Return array for output of all variables in JSON format

  2. Return array for output of all variables in JSON format, including objective if b is true

outputJSONParameters

function array [int] of string: outputJSONParameters()
Return array for output of all parameters in JSON format

output_to_section

test output_to_section(string: s, string: o)
Add o to the output section s

show

function string: show(any $T: x)
function string: show(array [$U] of any $T: x)
Convert x into a string

show2d

function string: show2d(array [$$E,$$F] of any $T: x)
Convert two-dimensional array x into a string

show2d_indexed

function string: show2d_indexed(array [int] of string: row_hdr,
                                array [int] of string: col_hdr,
                                array [int,int] of string: vs)
Convert two-dimensional array x into a string with row and column headers row_hdr and col_hdr

show3d

function string: show3d(array [int,int,int] of any $T: x)
Convert three-dimensional array x into a string

showJSON

function string: showJSON(any $T: x)
function string: showJSON(array [$U] of any $T: x)
Convert x into JSON string

show_float

function string: show_float(int: w, int: p, var float: x)

Formatted to-string conversion for floats.

Converts the float x into a string right justified by the number of characters given by w, or left justified if w is negative. The number of digits to appear after the decimal point is given by p. It is a run-time error for p to be negative.

show_int

function string: show_int(int: w, var int: x)

Formatted to-string conversion for integers

Converts the integer x into a string right justified by the number of characters given by w, or left justified if w is negative.

string_length

function int: string_length(string: s)
Return length of s

Functions for enums

In this section: enum_next, enum_of, enum_prev, to_enum.

enum_next

1.  function $$E: enum_next($$E: x)

2.  function opt $$E: enum_next(opt $$E: x)

3.  function var $$E: enum_next(var $$E: x)

4.  function var opt $$E: enum_next(var opt $$E: x)

5.  function $$E: enum_next(set of $$E: e, $$E: x)

6.  function opt $$E: enum_next(set of $$E: e, opt $$E: x)

7.  function var $$E: enum_next(set of $$E: e, var $$E: x)

8.  function var opt $$E: enum_next(set of $$E: e, var opt $$E: x)
1-4.
Return next greater enum value of x
5-8.
Return next greater enum value of x in enum e

enum_of

function set of $$E: enum_of(var opt $$E: x)
function set of $$E: enum_of(var set of $$E: x)
function set of $$E: enum_of(array [$T] of var opt $$E: x)
function set of $$E: enum_of(array [$T] of var set of $$E: x)
Return enum set of x

enum_prev

1.  function $$E: enum_prev($$E: x)

2.  function opt $$E: enum_prev(opt $$E: x)

3.  function var $$E: enum_prev(var $$E: x)

4.  function var opt $$E: enum_prev(var opt $$E: x)

5.  function $$E: enum_prev(set of $$E: e, $$E: x)

6.  function opt $$E: enum_prev(set of $$E: e, opt $$E: x)

7.  function var $$E: enum_prev(set of $$E: e, var $$E: x)

8.  function var opt $$E: enum_prev(set of $$E: e, var opt $$E: x)
1-4.
Return next smaller enum value of x
5-8.
Return next smaller enum value of x in enum e

to_enum

function $$E: to_enum(set of $$E: X, int: x)
function opt $$E: to_enum(set of $$E: X, opt int: x)
function var $$E: to_enum(set of $$E: X, var int: x)
function var opt $$E: to_enum(set of $$E: X, var opt int: x)
function array [$U] of $$E: to_enum(set of $$E: X,
                                    array [$U] of int: x)
function array [$U] of opt $$E: to_enum(set of $$E: X,
                                        array [$U] of opt int: x)
function array [$U] of var $$E: to_enum(set of $$E: X,
                                        array [$U] of var int: x)
function array [$U] of var opt $$E: to_enum(set of $$E: X,
                                            array [$U] of var opt int: x)
function set of $$E: to_enum(set of $$E: X, set of int: x)
function array [$U] of set of $$E: to_enum(set of $$E: X,
                                           array [$U] of set of int: x)
function array [$U] of var set of $$E: to_enum(set of $$E: X,
                                               array [$U] of var set of int: x)
Convert x to enum type X