Function Repository Resource:

Minimal

Source Notebook

Get the minimal item in terms of canonical ordering

Contributed by: Wolfram Staff

ResourceFunction["Minimal"][list]

returns the canonically minimal item in list.

ResourceFunction["Minimal"][list,p]

uses the ordering function p.

Details

Values of list are compared using the same canonical order as in Sort.
Use MinimalBy instead to order through a criterion function.
In a numerical list, Ordering[list,n] gives the positions of the n smallest elements. Ordering[list,-n] gives the positions of the n largest elements.
If there are several smallest elements in list, Ordering[list,1] will give only the position of the one that appears first.

Examples

Basic Examples (4) 

Using canonical ordering, return the minimal item:

In[1]:=
items = {2, 6, 1, 9, 1, 2, 3, Sqrt[2] - 1, -\[Infinity]};
ResourceFunction["Minimal"][items]
Out[2]=

Sort the items:

In[3]:=
Sort[items]
Out[3]=

The numeric minimum is different:

In[4]:=
Min[items]
Out[4]=

Use a different ordering function to obtain the same result:

In[5]:=
ResourceFunction["Minimal"][items, NumericalOrder]
Out[5]=

Scope (2) 

Use Minimal on an association:

In[6]:=
ResourceFunction["Minimal"][<|a -> 4, b -> 1, c -> 3, d -> 2, e -> 2|>]
Out[6]=

Use Minimal on a sparse vector:

In[7]:=
ResourceFunction["Minimal"][SparseArray[{{3} -> 2, {7} -> -1}, 10]]
Out[7]=

Properties and Relations (2) 

Find the item with the smallest second item using an ordering function:

In[8]:=
ResourceFunction["Minimal"][{{a, 3}, {b, 2}, {a, 2}, {d, 1}, {b, 3}}, NumericalOrder[Last[#1], Last[#2]] &]
Out[8]=

The result of the function MinimalBy has a similar form:

In[9]:=
MinimalBy[{{a, 3}, {b, 2}, {a, 2}, {d, 1}, {b, 3}}, Last]
Out[9]=

Version History

  • 1.1.0 – 30 January 2023
  • 1.0.0 – 14 February 2022

Related Resources

License Information