Function Repository Resource:

# Maximal

Get the maximal item in terms of canonical ordering

Contributed by: Wolfram Staff
 ResourceFunction["Maximal"][list] returns the canonically maximal item in list. ResourceFunction["Maximal"][list,p] uses the ordering function p.

## Details

Values of list are compared using the same canonical order as in Sort.
Use MaximalBy instead if ordering through a criterion function is desired.
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.

## Examples

### Basic Examples (5)

Using canonical ordering, return the maximal item:

 In[1]:=
 Out[2]=

If the last item is dropped, the more numerically complicated item is returned:

 In[3]:=
 Out[3]=

Sort the items:

 In[4]:=
 Out[4]=

The numeric maximum is different:

 In[5]:=
 Out[5]=

Use a different ordering function to obtain the same result:

 In[6]:=
 Out[6]=

### Scope (2)

Use Maximal on an association:

 In[7]:=
 Out[7]=

Use Maximal on a sparse vector:

 In[8]:=
 Out[8]=

### Properties and Relations (2)

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

 In[9]:=
 Out[9]=

The result of the function MaximalBy has a similar form:

 In[10]:=
 Out[10]=

## Version History

• 1.1.0 – 03 February 2023
• 1.0.0 – 14 February 2022