what is the definition of $=$?

In logic, equality is not something we define, it's a primitive notion. If $A=B$ then $A$ has property $P$ if and only if $B$ has property $P$—this is probably the most important thing to know about equality and although it doesn't define equality, it is assumptions like this that shape our understanding of what equality "is", just like the axioms of set theory shape our understanding of what it means to say $A \in B$ even though membership is a primitive notion that is not defined in terms of other things.

The converse statement "if for every property $P$, $A$ has property $P$ if and only if $B$ has property $P$, then $A=B$" is not true in general. (Unless you allow the property $P$ to have a parameter—then as you point out it's trivially true because $P(x)$ can say $x =B$.) It's true in structures like the natural numbers, where every object is definable, but other structures may have indiscernible elements that cannot be distinguished by any logical property.


From a reductionist foundational viewpoint, equality in mathematics is equality of sets, as defined by the (ZFC) axioms of set theory. Recall that the axiom of extensionality states that two sets are equal iff they have precisely the same elements. Let's examine how the equality of sets percolates up to equality on other mathematical objects, e.g. number systems, algebraic structures, etc.

The natural numbers $\,\Bbb N\,$ may be represented by sets, e.g. von-Neumann ordinals. Then equality of naturals is the same as set-theoretic equality. The integers $\,\Bbb Z\,$ may be constructed from $\,\Bbb N\,$ by a standard difference semiring construction, where integers are represented by equivalence classes of pairs $\rm\,(j,k)\,$ of naturals modulo the equivalence relation $\rm\,(j,k) \equiv (m,n)\,$ iff $\rm\,j+n = m+k.\:$ The idea is that the equivalence class $\rm\,[(j,k)]\,$ represents the solution $\rm\,x\,$ of $\rm\, x + k = j,\,$ i.e. the integer $\rm\: j-k.\:$ Thus, set-theoretically, integers are certain subsets of $\,\Bbb N^2,\,$ and, hence, integer equality is set-theoretic equality in $\,\Bbb N^2.\,$

Similarly, rationals (fractions) are constructed as pairs of integers, modulo the well-known equivalence relation for fractions, i.e. if a fraction $\rm\,a/b\,$ is represented by the pair $\rm\,(a,b),\,$ then $\rm\, (a,b) \equiv (c,d)\,$ iff $\rm\,ad = bc,\:$ e.g. $\rm\,1/2 = [(1,2)] = \{\ldots,(-2,-4),(-1,-2)(1,2),(2,4),\ldots\}.$ Again, fractions are certain subsets of $\rm\,\Bbb Z^2,\,$ and fraction equality is the same as set-theoretic equality of these sets (equivalence classes). The same holds true for all other numbers systems (e.g. Hamilton's construction of $\,\Bbb C\,$ as pairs of reals). In every case, their equality relations are equivalence relations, so equality boils down to set-theoretic equality of equivalence classes.

Moving up to the structural level, rings are represented by equivalence classes of isomorphic rings, so ring equality is again set-theoretic equality. Similarly for other algebraic structures.

In analogy with programming languages, this is the "assembly language" view of mathematical objects, where everything has been disassembled to its primitive machine-level data-types and operations. When working at a high-level, we don't conceptualize the objects in terms of these primitive representations. But to be rigorous, they must be built up this way from the primitive set-theoretical foundations. And it is set-theoretic equality that percolates up to the higher-level equivalence relations that define equality on these higher-level composite mathematical objects.


Equality relations are expected to be symmetric, reflexive and transitive. Relations which have these three properties are called equivalence relations. These conditions allow us to reject certain relations from being used as definitions of equality. For instance $\in$ is not an equivalence relation and so it will not serve very well as equality. It is not symmetric: $A\in B$ does not imply $B\in A$. It is also not reflexive: $A\in A$ is not generally true, but only if $A$ is a set which contain itself.

In mathematics, the usual equivalence concerns itself with the sameness of value. If we have a real number $x$ and a real number $y$, then $x = y$ is true if $x$ and $y$ are in fact not distinct, but are the same number. Unlike in computer programming languages, we don't have to worry about the type. That is to say, there is no distinction between 3.0 and 3. In computing, there can be equalities which distinguish those two as unequal; yet, those equalities are still proper equality relations.

Two complex numbers are equal if their corresponding real and imaginary parts, taken as real numbers, are equal, which means that a complex number is only equal to itself and not to any other complex number.

Two vectors are equal if they are of the same dimension, and each member of one vector is equal to the corresponding member of the other.

Two sets are equal if they are of the same cardinality and contain the same elements.

Whether you want to treat objects of different kinds, such the vector or matrix $[1]$ as equal to the real number $1$ or to the set ${1}$, depends on the situation. If such a notion of equality doesn't lead to any flaws in a proof, and adds some kind of convenience, then it is admissible.