# `min`, `mins`, `mmin`

_Minimums_

## `min`

_Minimum_
```syntax
min x     min[x]
```

Where `x` is a non-symbol sortable list, returns its minimum.
The minimum of an atom is itself.
`min` supports GUIDs from KDB-X 5.0.20261015.

`min` ignores nulls. If `x` is an empty vector or has only nulls, the result is infinity.
```q
q)min 2 5 7 1 3
1
q)min "genie"
"e"
q)min 0N 5 0N 1 3                  / nulls are ignored
1
q)min 0N 0N                        / infinity if all null
0W
q)t:([]sym:`a`b`a`b;price:10 20 5 25)
q)select min price by sym from t   / use in a select statement
sym| price
---| -----
a  | 5
b  | 20
```

`min` is an aggregate function, equivalent to `&/`.

`min` is a [multithreaded primitive](mt-primitives.md).

## `mins`

_Running minimums_
```syntax
mins x     mins[x]
```

Where `x` is a non-symbol sortable list, returns the running minimums of the prefixes.

`mins` ignores nulls, except that it returns initial nulls as infinity.
```q
q)mins 2 5 7 1 3
2 2 2 1 1
q)mins "genie"
"geeee"
q)mins 0N 5 0N 1 3         / initial nulls return infinity
0W 5 5 1 1
```

`mins` is a uniform function, equivalent to `&\`.

## `mmin`

_Moving minimums_
```syntax
x mmin y     mmin[x;y]
```

Where `y` is a non-symbol sortable list and `x` is a

- positive integer atom, returns the `x`-item moving minimums of `y`, treating nulls as the minimum value. The first `x` items of the result are the minimums of the items so far; after that, each item is the moving minimum.
- 0 or a negative integer, returns `y`
```q
q)3 mmin 0N -3 -2 1 -0W 0
0N 0N 0N -3 -0W -0W
q)3 mmin 0N -3 -2 1 0N -0W    / null is the minimum value
0N 0N 0N -3 0N 0N
q)3 mmin 5 1 4 2 8
5 1 1 1 2
```

`mmin` is a uniform function.

[Sliding windows](../examples/programming-idioms.md#how-do-i-apply-a-function-to-a-sequence-sliding-window)

## Domain and range

`min`
```txt
domain: B G X H I J E F C S P M D Z N U V T
range:  b g x h i j e f c . p m d z n u v t
```

`mins`
```txt
domain: B G X H I J E F C S P M D Z N U V T
range:  B G X H I J E F C . P M D Z N U V T
```

`mmin`, where `x` (rows) is an atom and `y` (columns) is a list
```txt
    B G X H I J E F C S P M D Z N U V T
----------------------------------------
b | B G X H I J E F C S P M D Z N U V T
g | . . . . . . . . . . . . . . . . . .
x | B G X H I J E F C . P M D Z N U V T
h | B G X H I J E F C . P M D Z N U V T
i | B G X H I J E F C . P M D Z N U V T
j | B G X H I J E F C . P M D Z N U V T
e | . . . . . . . . . . . . . . . . . .
f | . . . . . . . . . . . . . . . . . .
c | . . . . . . . . . . . . . . . . . .
s | . . . . . . . . . . . . . . . . . .
p | . . . . . . . . . . . . . . . . . .
m | . . . . . . . . . . . . . . . . . .
d | . . . . . . . . . . . . . . . . . .
z | . . . . . . . . . . . . . . . . . .
n | . . . . . . . . . . . . . . . . . .
u | . . . . . . . . . . . . . . . . . .
v | . . . . . . . . . . . . . . . . . .
t | . . . . . . . . . . . . . . . . . .
```

Range: `BCDEFGHIJMNPSTUVXZ`

A boolean `x` is a window of at most one item, so `mmin` returns `y` unchanged.

## Implicit iteration

`min`, `mins`, and `mmin` apply to [dictionaries and tables](math.md#dictionaries-and-tables).
```q
q)kt:`k xkey update k:`abc`def`ghi from t:flip d:`a`b!(10 21 3;4 5 6)

q)min d
4 5 3
q)min t
a| 3
b| 4
q)min kt
a| 3
b| 4

q)mins t
a  b
----
10 4
10 4
3  4

q)2 mmin kt
k  | a  b
---| ----
abc| 10 4
def| 10 4
ghi| 3  5
```

## Aggregating nulls

`avg`, `min`, `max`, and `sum` ignore nulls, as in SQL-92.
For nested `x`, however, these functions preserve nulls.
```q
q)min (1 2;0N 4)
0N 2
```

----

[`max`, `maxs`, `mmax`](max.md)


[Mathematics](math.md)
