▼ 3 Builtins and Libraries
 3.1 Global Utilities 3.2 Numbers 3.3 Strings 3.4 Booleans 3.5 Raw  Array 3.6 Tables 3.7 lists 3.8 sets 3.9 arrays 3.1 string-dict 3.11 option 3.12 pick 3.13 either 3.14 srcloc 3.15 pprint 3.16 s-exp 3.17 s-exp-structs 3.18 color 3.19 image-structs 3.2 The image libraries 3.21 world 3.22 gdrive-sheets 3.23 data-source 3.24 reactors 3.25 chart 3.26 plot 3.27 statistics 3.28 math
 ► 3.28 math
 3.28.1 Arithmetic Functions sum 3.28.2 Minimization & Maximization max min arg-max arg-min
8.9

#### 3.28math

Usage:
include math
import math as ...
The Pyret Math library. It consists of functions for arithmetic calculations, optimization, and more to come!

Every function in this library is available on the math module object. For example, if you used import math as M, you would write M.arg-max to access arg-max below. If you used include, then you can refer to identifiers without writing M. as a prefix.

##### 3.28.1Arithmetic Functions

sum :: (l :: List<Number>) -> Number

Calculates the arithmetic sum of the Numbers in l. If l contains at least one RoughNum, then the output will be a RoughNum.

Examples:
```check:
sum([list: ]) is 0
sum([list: 0, 2, 4]) is 6
sum([list: -1, 1, ~2]) is-roughly ~2
end```

##### 3.28.2Minimization & Maximization

max :: (l :: List<Number>) -> Number

Calculates the maximal element of the set of Numbers in l.

Examples:
```check:
max([list: ]) raises "Empty List"
max([list: 10]) is 10
max([list: 2.1, 2, 4.5, ~1.5, -1, 1]) is-roughly 4.5
end```

min :: (l :: List<Number>) -> Number

Calculates the minimal element of the set of Numbers in l.

Examples:
```check:
min([list: ]) raises "Empty List"
min([list: 2]) is 2
min([list: -1, 0, ~1, 2, 5]) is-roughly -1
end```

arg-max :: (l :: List<Number>) -> Number

Calculates the index of the maximal element within l.

Examples:
```check:
arg-max([list: ]) raises "Empty List"
arg-max([list: 2]) is 0
arg-max([list: -1, 0, ~1, 5, 2]) is 3
end```

arg-min :: (l :: List<Number>) -> Number

Calculates the index of the minimal element within l.

Examples:
```check:
arg-max([list: ]) raises "Empty List"
arg-max([list: 8]) is 0
arg-max([list: -1, 0, ~1, -3, 5]) is 3
end```