What is the definition of "equality" I thought we could define "the equality on set $A$" by the relation $\{(a,a):a\in A\}\subseteq A^2$. However, no book has this definition. Moreover, some books say that this is the "diagonal relation". Is it just another name for the equality?


*

*Of course I am also interested in the general properties of equality, but now I wonder if the above definition makes sense.

 A: Equality is typically a predicate and built in to the logic itself. For a first-order theory of set theory, such as ZFC, this means equality is defined for all sets. Alternatively, equality of sets is defined by the formula $x=y:\equiv \forall z.z\in x\iff z\in y$. If equality is built in to the logic, then we axiomatically identify this formula with equality.
The question then becomes: how do we define equality of the logic? There are two approaches to defining a logic. You can give it a semantics, or you can give it a proof theory. The semantic definition of equality is indeed usually done via the diagonal relation (or more generally a diagonal monomorphism) on the domain. However, this may not be very compelling when set theory is the thing you're trying to understand. A proof theoretic approach is to give the axiom $\forall x.x=x$ and the rule if $\varphi(x)$ is derivable and $x=y$ is derivable then $\varphi(y)$ is derivable for all first-order formulas $\varphi$. Conceptually, this states that if two things are equal then every property (that we can write down) that holds of one holds of the other.
Within a set theory, we can define an equality relation on a set just as you state. A predicate is a formula of the logic, while a relation is a set of pairs. (An alternative definition would be as the smallest equivalence relation on the set.) Another way of writing the set would be $\{(a,b)\mid (a,b)\in A\times A \land a=b\}$. This set is the restriction of the equality predicate to $A$, but the notion of equality is pre-existing.
In type theories or more structural approaches to set theory, we may not have a global notion of equality for all sets. In these contexts, it may make more sense to consider a family of equality predicates indexed in some manner whose semantics may well look like a diagonal relation for each member of the family of equality predicates. In these contexts, it does not make sense to (directly) talk about the equality of unrelated sets. ("Does not make sense" means there is no well-formed formula corresponding to the notion.) In particular, two elements can be compared for equality only if they are elements of the same containing set. This can lead to terms being equal as elements of some sets but not others, e.g. $2=5\in\mathbb Z/3$ but not in $\mathbb Z$.
