# positions -- which elements of a list satisfy a condition

## Synopsis

• Usage:
positions(A, f)
• Inputs:
• A,
• f,
• Outputs:
• p, a list, the list of indices i such that f(A#i) is true

## Description

The indices are listed in ascending order. If no element satisfies the condition, an empty list is returned.

 i1 : positions((10,20,43,105,6,93), odd) o1 = {2, 3, 5} o1 : List i2 : positions((10,20,43,105,6,93), i -> i<0) o2 = {} o2 : List i3 : positions(100..110, isPrime) o3 = {1, 3, 7, 9} o3 : List

To find the first or last index of an element satisfying the condition, see position. To return the elements, rather than their indices, see select. The function number counts the number of elements satisfying the condition.

 i4 : position((10,20,43,105,6), odd) o4 = 2 i5 : position((10,20,43,105,6), odd, Reverse => true) o5 = 3 i6 : select((10,20,43,105,6), odd) o6 = (43, 105) o6 : Sequence i7 : number((10,20,43,105,6), odd) o7 = 2

• minPosition -- position of the smallest element
• maxPosition -- position of the largest element
• number -- count how many elements of a list satisfy a condition
• position -- the first element of a list satisfying 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 positions :

• "positions(MutableList,Function)"
• "positions(VisibleList,Function)"

## For the programmer

The object positions is .