same -- whether everything in a list is the same

Synopsis

• Usage:
same L
• Inputs:
• L, a list
• Outputs:
• b, a Boolean

Description

 i1 : same {1, 1, 1, 1} o1 = true i2 : same {1, 2, 1, 1} o2 = false

The comparison is done with "===", which is quick, but not always intuitive. Here is a simple example of what can go wrong:

 i3 : R = QQ[x,y,z]; i4 : L = {gcd{x,y}, x/x, 1} o4 = {1, 1, 1} o4 : List i5 : same L o5 = false

We can see the problem by asking Macaulay2 to display the class of each element of L. (Or use the function uniform, which returns whether or not the elements of a list are all of the same class.)

 i6 : apply(L, class) o6 = {R, frac R, ZZ} o6 : List i7 : uniform L o7 = false

The first 1 is an element of the ring R, the second 1 is an element of the fraction field of R, and the third 1 is an integer. Thus Macaulay2 thinks of these three elements as being pairwise unequal, with respect to the operator "===".

See also

• commonest -- the most common elements of a list or tally
• number -- count how many elements of a list satisfy a condition
• set -- make a set
• uniform -- whether all elements of a list are the same class
• unique -- eliminate duplicates from a list
• lists and sequences -- a detailed overview of lists and sequences in Macaulay2

For the programmer

The object same is .