number -- count how many elements of a list satisfy a condition

Synopsis

• Usage:
number(A, f)
• Inputs:
• A, a list or sequence
• f, a boolean function
• Outputs:
• c, an integer, the number of elements of A that satisfy f

Description

 i1 : number(0..100, isPrime) o1 = 25 i2 : number(0..100, odd) o2 = 50 i3 : number(0..100, i -> i==17) o3 = 1

To find the first or last index of an element satisfying the condition, see position. For all indices that match the condition, see positions. To return the elements, rather than their indices, see select.

 i4 : position((10,20,43,105,6), odd) o4 = 2 i5 : positions((10,20,43,105,6), odd) o5 = {2, 3} o5 : List i6 : select((10,20,43,105,6), odd) o6 = (43, 105) o6 : Sequence

• all -- whether all elements satisfy a specified condition
• any -- whether any elements satisfy a specified condition
• commonest -- the most common elements of a list or tally
• position -- the first element of a list satisfying a condition
• positions -- which elements of a list satisfy a condition
• same -- whether everything in a list is the same
• select -- select from a list, hash table, or string
• tally -- tally the elements of a list, sequence, array, or string
• lists and sequences -- a detailed overview of lists and sequences in Macaulay2

For the programmer

The object number is .