# position -- the first element of a list satisfying a condition

## Synopsis

• Usage:
position(A, f)
position(A, B, f)
position(A, f, Reverse => true)
• Inputs:
• A, ,
• B, ,
• f, ,
• Optional inputs:
• Reverse => ..., default value false
• Outputs:
• p, an integer, the first index to satisfy the boolean function f

## Description

position(A, f) returns the smallest index i such that f(A#i) is true. If no element satisfies the condition, null is returned.

 i1 : position((10,20,43,105,6,93), odd) o1 = 2 i2 : position((10,20,43,105,6,93), i -> i<0)

Use position(A, B, f) to return the smallest index i such that f(A#i, B#i) is true.

 i3 : position((10,20,43,105,6,93),(18,82,12,7,35,92), (a,b) -> a>b) o3 = 2

The Reverse option will return the largest index instead.

 i4 : position((10,20,43,105,6,93), odd, Reverse => true) o4 = 5 i5 : position((10,20,43,105,6,93),(18,82,12,7,35,92), (a,b) -> a>b, Reverse => true) o5 = 5

To find all indices of elements satisfying the condition, see positions. To return the elements, rather than their indices, see select. The function number counts the number of elements satisfying the condition.

 i6 : positions((10,20,43,105,6,93), odd) o6 = {2, 3, 5} o6 : List i7 : select((10,20,43,105,6,93), odd) o7 = (43, 105, 93) o7 : Sequence i8 : number((10,20,43,105,6,93), odd) o8 = 3

• minPosition -- position of the smallest element
• maxPosition -- position of the largest element
• number -- count how many elements of a list satisfy a condition
• positions -- which elements of a list satisfy a condition
• select -- select from a list, hash table, or string
• take -- Take some elements from a list or sequence.
• lists and sequences -- a detailed overview of lists and sequences in Macaulay2

## Ways to use position :

• "position(VisibleList,Function)"
• "position(VisibleList,VisibleList,Function)"

## For the programmer

The object position is .