is called
an equivalence relation on A if the following properties
all hold
These conditions can also be written, using a different notation
and
As an example, consider a high-level block structured programming language like Pascal, and let D denote the set of all declared identifiers in a Pascal program, then ``is declared in the same block as'' constitutes an equivalence relation, while ``is declared in a block which encloses'' is not an equivalence relation since property (2) does not hold in the second example.
As a further example, consider aliased variables. If two or more variables denote the same memory address, the variables are called aliases of one another. The ANSI version of Fortran allows aliased variables to be introduced by means of the aptly named non-executable EQUIVALENCE statement which declares that two or more variables in a program refer to the same memory location. As an example, the statement
If
denotes the relation ``is an alias of'', then
constitutes an equivalence relation over the set of all
program variables V. We can express the elements of the
relation as
We say that the set of all program variables V is partitioned by the equivalence relation
.
The set of
all
variables in V which are aliases of each other constitute what
is called an equivalence class so that {T1, T2} and
{INDEX, JCOUNT, LOOPVAR} constitute two
separate equivalence
classes. These ideas of partitioning and equivalence classes are
formalised in the following definitions.