# MiniZinc Documentation - Standard Library

These builtins implement arithmetic operations.

Functions and Predicates
function int: '*'(int: x, int: y)

Usage: x*y

Return x * y

function var int: '*'(var int: x, var int: y)

Usage: x*y

Return x * y

function float: '*'(float: x, float: y)

Usage: x*y

Return x * y

function var float: '*'(var float: x, var float: y)

Usage: x*y

Return x * y

function int: '+'(int: x, int: y)

Usage: x+y

Return x + y

function var int: '+'(var int: x, var int: y)

Usage: x+y

Return x + y

function float: '+'(float: x, float: y)

Usage: x+y

Return x + y

function var float: '+'(var float: x, var float: y)

Usage: x+y

Return x + y

function int: '-'(int: x, int: y)

Usage: x-y

Return x - y

function var int: '-'(var int: x, var int: y)

Usage: x-y

Return x - y

function float: '-'(float: x, float: y)

Usage: x-y

Return x - y

function var float: '-'(var float: x, var float: y)

Usage: x-y

Return x - y

function int: '-'(int: x)

Usage: -x

Return negative x

function var int: '-'(var int: x)

Usage: -x

Return negative x

function float: '-'(float: x)

Usage: -x

Return negative x

function var float: '-'(var float: x)

Usage: -x

Return negative x

function float: '/'(float: x, float: y)

Usage: x/y

Return result of floating point division x / y

function var float: '/'(var float: x, var float: y)

Usage: x/y

Return result of floating point division x / y

function int: 'div'(int: x, int: y)

Usage: x div y

Return result of integer division x / y

function var int: 'div'(var int: x, var int: y) =
if mzn_in_root_context(y) \/ not (0 in dom(y)) then div_t(x, y) else let {constraint y!=0,} in (div_mt(x, y)) endif
(standard decomposition from builtins.mzn:190)

Usage: x div y

Return result of integer division x / y

function int: 'mod'(int: x, int: y)

Usage: x mod y

Return remainder of integer division x % y

function var int: 'mod'(var int: x, var int: y) =
if mzn_in_root_context(y) \/ not (0 in dom(y)) then mod_t(x, y) else let {constraint y!=0,} in (mod_mt(x, y)) endif
(standard decomposition from builtins.mzn:198)

Usage: x mod y

Return remainder of integer division x % y

function int: abs(int: x)

Return absolute value of x

function var int: abs(var int: x) =
if has_bounds(x) /\ lb(x)>=0 then x else let { var 0..max(-lb(x), ub(x)): m, constraint int_abs(x, m), } in (m) endif
(standard decomposition from builtins.mzn:310)

Return absolute value of x

function float: abs(float: x)

Return absolute value of x

function var float: abs(var float: x) =
if has_bounds(x) then if lb(x)>=0.0 then x else let { var 0.0..max(-lb(x), ub(x)): m, constraint float_abs(x, m), } in (m) endif else let { var float: m, constraint m>=0.0, constraint float_abs(x, m), } in (m) endif
(standard decomposition from builtins.mzn:320)

Return absolute value of x

function $$E: arg_max(array [$$E] of int: x)

Return index of maximum of elements in array x

function $$E: arg_max(array [$$E] of float: x)

Return index of maximum of elements in array x

function $$E: arg_min(array [$$E] of int: x)

Return index of minimum of elements in array x

function $$E: arg_min(array [$$E] of float: x)

Return index of minimum of elements in array x

function $T: max($T: x, $T: y) Return maximum of x and y function$T: max(array [$U] of$T: x)

Return maximum of elements in array x

function $$E: max(set of$$E: x)

Return maximum of elements in set x

function var int: max(var int: x, var int: y) =
let { var max(lb(x), lb(y))..max(ub(x), ub(y)): m, constraint int_max(x, y, m), } in (m)
(standard decomposition from builtins.mzn:242)

Return maximum of x and y

function var int: max(array [$U] of var int: x) = let { array [int] of var int: xx = array1d(x), constraint length(x)>=1, } in (max_t(xx)) (standard decomposition from builtins.mzn:248) Return maximum of elements in array x function var float: max(var float: x, var float: y) = let { var float: m, constraint float_max(x, y, m), } in (m) (standard decomposition from builtins.mzn:271) Return maximum of x and y function var float: max(array [$U] of var float: x) =
let { array [int] of var float: xx = array1d(x), constraint length(x)>=1, } in (max_t(xx))
(standard decomposition from builtins.mzn:277)

Return maximum of elements in array x

function $T: min($T: x, $T: y) Return minimum of x and y function$T: min(array [$U] of$T: x)

Return minimum of elements in array x

function $$E: min(set of$$E: x)

Return minimum of elements in set x

function var int: min(var int: x, var int: y) =
let { var min(lb(x), lb(y))..min(ub(x), ub(y)): m, constraint int_min(x, y, m), } in (m)
(standard decomposition from builtins.mzn:255)

Return minimum of x and y

function var int: min(array [$U] of var int: x) = let { array [int] of var int: xx = array1d(x), constraint length(x)>=1, } in (min_t(xx)) (standard decomposition from builtins.mzn:261) Return minimum of elements in array x function var float: min(var float: x, var float: y) = let { var float: m, constraint float_min(x, y, m), } in (m) (standard decomposition from builtins.mzn:284) Return minimum of x and y function var float: min(array [$U] of var float: x) =
let { array [int] of var float: xx = array1d(x), constraint length(x)>=1, } in (min_t(xx))
(standard decomposition from builtins.mzn:290)

Return minimum of elements in array x

function int: pow(int: x, int: y)

Return $${\bf x} ^ {{\bf y}}$$

function var int: pow(var int: x, var int: y) =
let { int: yy = if is_fixed(y) then fix(y) else -1 endif,} in (if yy==0 then 1 elseif yy==1 then x elseif yy==2 then x*x else let { var int: r, constraint int_pow(x, y, r), } in (r) endif)
(standard decomposition from builtins.mzn:355)

Return $${\bf x} ^ {{\bf y}}$$

function float: pow(float: x, float: y)

Return $${\bf x} ^ {{\bf y}}$$

function var float: pow(var float: x, var float: y) =
let { float: yy = if is_fixed(y) then fix(y) else -1.0 endif,} in (if yy==0.0 then 1.0 elseif yy==1.0 then x elseif yy==2.0 then x*x else let { var float: r, constraint float_pow(x, y, r), } in (r) endif)
(standard decomposition from builtins.mzn:372)

Return $${\bf x} ^ {{\bf y}}$$

function int: product(array [$T] of int: x) Return product of elements in array x function var int: product(array [$T] of var int: x) =
product_rec(array1d(x))
(standard decomposition from builtins.mzn:219)

Return product of elements in array x

function float: product(array [$T] of float: x) Return product of elements in array x function var float: product(array [$T] of var float: x) =
product_rec(array1d(x))
(standard decomposition from builtins.mzn:225)

Return product of elements in array x

function float: sqrt(float: x)

Return $$\sqrt{{\bf x}}$$

function var float: sqrt(var float: x) =
let {constraint x>=0.0,} in (sqrt_t(x))
(standard decomposition from builtins.mzn:337)

Return $$\sqrt{{\bf x}}$$

function int: sum(array [$T] of int: x) Return sum of elements in array x function var int: sum(array [$T] of var int: x)

Return sum of elements in array x

function float: sum(array [$T] of float: x) Return sum of elements in array x function var float: sum(array [$T] of var float: x)

Return sum of elements in array x