next | previous | forward | backward | up | top | index | toc | home
Macaulay2 > The Macaulay2 language > operators > ==

== -- equality

Synopsis

Description

Returns true or false, depending on whether the objects x and y are (mathematically) equal. The objects x and y are typically numbers, elements of rings, matrices, modules, ideals, chain complexes, and so on.

A test for mathematical equality will typically involve doing a computation to see whether two representations of the same mathematical object are being compared. For example, an ideal in a ring is represented by giving its generators, and checking whether two sets of generators produce the same ideal involves a computation with Groebner bases. The ideals must be defined in the same ring.

Ideals

i1 : R = QQ[a,b,c];
i2 : ideal(a^2-b,a^3) == ideal(b^2, a*b, a^2-b)

o2 = true
Often mathematical objects can be tested to see if they are 0 or 1.
i3 : L = ideal(a^2-a-1,a^3+a+3)

             2           3
o3 = ideal (a  - a - 1, a  + a + 3)

o3 : Ideal of R
i4 : L == 1

o4 = true
i5 : L == 0

o5 = false

Matrices

Two matrices are equal if their entries are equal, the source and target are the same (including degrees), and the degree of the matrices are the same. In this example, m and n have different source free modules.
i6 : m = matrix{{a,b},{c,a}}

o6 = | a b |
     | c a |

             2       2
o6 : Matrix R  <--- R
i7 : n = map(R^2,R^2,m)

o7 = | a b |
     | c a |

             2       2
o7 : Matrix R  <--- R
i8 : m == n

o8 = false
i9 : source m == source n

o9 = false
If you only want to know if they have the same entries, test the difference against zero.
i10 : m-n == 0

o10 = true

Rings

Rings are handled in a different manner in Macaulay2. Each time you create a polynomial ring in Macaulay2, you are handed a new ring, which is not equal to any other ring. For example, the rings A and B below are not considered the same by Macaulay2.
i11 : A = QQ[x,y,z]; B = QQ[x,y,z];
i13 : A == B

o13 = false

Modules

Two modules are equal if they are isomorphic as subquotients of the same ambient free module.
i14 : image matrix {{2,a},{1,5}} == R^2

o14 = false
i15 : image matrix {{2,a},{0,5}} == R^2

o15 = true

It may happen that for certain types of objects, there is no method installed for testing mathematical equality, in which case strict equality will be tested with the operator ===. If a test for mathematical equality is installed later, your results may change.

Caveat

Warning: whether this comparison operator returns true is not necessarily related to whether the comparison operator ? returns symbol==.

See also

Ways to use == :

For the programmer

The object == is a keyword.

This operator may be used as a binary operator in an expression like x==y. The user may install binary methods for handling such expressions with code such as
         X == Y := (x,y) -> ...
where X is the class of x and Y is the class of y.