Goto Chapter: Top 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 Bib Ind

33 Relations

33.2 Properties and Attributes of Binary Relations

33.2-1 IsReflexiveBinaryRelation

33.2-2 IsSymmetricBinaryRelation

33.2-3 IsTransitiveBinaryRelation

33.2-4 IsAntisymmetricBinaryRelation

33.2-5 IsPreOrderBinaryRelation

33.2-6 IsPartialOrderBinaryRelation

33.2-7 IsHasseDiagram

33.2-8 IsEquivalenceRelation

33.2-9 Successors

33.2-10 DegreeOfBinaryRelation

33.2-11 PartialOrderOfHasseDiagram

33.2-1 IsReflexiveBinaryRelation

33.2-2 IsSymmetricBinaryRelation

33.2-3 IsTransitiveBinaryRelation

33.2-4 IsAntisymmetricBinaryRelation

33.2-5 IsPreOrderBinaryRelation

33.2-6 IsPartialOrderBinaryRelation

33.2-7 IsHasseDiagram

33.2-8 IsEquivalenceRelation

33.2-9 Successors

33.2-10 DegreeOfBinaryRelation

33.2-11 PartialOrderOfHasseDiagram

A *binary relation* \(R\) on a set \(X\) is a subset of \(X \times X\). A binary relation can also be thought of as a (general) mapping from \(X\) to itself or as a directed graph where each edge represents an element of \(R\).

In **GAP**, a relation is conceptually represented as a general mapping from \(X\) to itself. The category `IsBinaryRelation`

(33.1-1) is a synonym for `IsEndoGeneralMapping`

(32.13-3). Attributes and properties of relations in **GAP** are supported for relations, via considering relations as a subset of \(X \times X\), or as a directed graph; examples include finding the strongly connected components of a relation, via `StronglyConnectedComponents`

(33.4-5), or enumerating the tuples of the relation.

This section lists general constructors of relations.

`‣ IsBinaryRelation` ( R ) | ( property ) |

is exactly the same category as (i.e. a synonym for) `IsEndoGeneralMapping`

(32.13-3).

`‣ BinaryRelationByElements` ( domain, elms ) | ( function ) |

is the binary relation on `domain` and with underlying relation consisting of the tuples collection `elms`. This construction is similar to `GeneralMappingByElements`

(32.2-1) where the source and range are the same set.

gap> r:=BinaryRelationByElements(Domain([1..3]),[Tuple([1,2]),Tuple([1,3])]); <general mapping: <object> -> <object> >

`‣ IdentityBinaryRelation` ( degree ) | ( function ) |

`‣ IdentityBinaryRelation` ( domain ) | ( function ) |

is the binary relation which consists of diagonal pairs, i.e., pairs of the form \((x,x)\). In the first form if a positive integer `degree` is given then the domain is the set of the integers \(\{ 1, \ldots, \textit{degree} \}\). In the second form, the objects \(x\) are from the domain `domain`.

gap> IdentityBinaryRelation(5); <equivalence relation on <object> > gap> s4:=SymmetricGroup(4); Sym( [ 1 .. 4 ] ) gap> IdentityBinaryRelation(s4); IdentityMapping( Sym( [ 1 .. 4 ] ) )

`‣ EmptyBinaryRelation` ( degree ) | ( function ) |

`‣ EmptyBinaryRelation` ( domain ) | ( function ) |

is the relation with `R` empty. In the first form of the command with `degree` an integer, the domain is the set of points \(\{ 1, \ldots, \textit{degree} \}\). In the second form, the domain is that given by the argument `domain`.

gap> EmptyBinaryRelation(3) = BinaryRelationOnPoints([ [], [], [] ]); true

`‣ IsReflexiveBinaryRelation` ( R ) | ( property ) |

returns `true`

if the binary relation `R` is reflexive, and `false`

otherwise.

A binary relation \(R\) (as a set of pairs) on a set \(X\) is *reflexive* if for all \(x \in X\), \((x,x) \in R\). Alternatively, \(R\) as a mapping is reflexive if for all \(x \in X\), \(x\) is an element of the image set \(R(x)\).

A reflexive binary relation is necessarily a total endomorphic mapping (tested via `IsTotal`

(32.3-1)).

gap> IsReflexiveBinaryRelation(BinaryRelationOnPoints([[1,3],[2],[3]])); true gap> IsReflexiveBinaryRelation(BinaryRelationOnPoints([[2],[2]])); false

`‣ IsSymmetricBinaryRelation` ( R ) | ( property ) |

returns `true`

if the binary relation `R` is symmetric, and `false`

otherwise.

A binary relation \(R\) (as a set of pairs) on a set \(X\) is *symmetric* if \((x,y) \in R\) then \((y,x) \in R\). Alternatively, \(R\) as a mapping is symmetric if for all \(x \in X\), the preimage set of \(x\) under \(R\) equals the image set \(R(x)\).

gap> IsSymmetricBinaryRelation(BinaryRelationOnPoints([[2],[1]])); true gap> IsSymmetricBinaryRelation(BinaryRelationOnPoints([[2],[2]])); false

`‣ IsTransitiveBinaryRelation` ( R ) | ( property ) |

returns `true`

if the binary relation `R` is transitive, and `false`

otherwise.

A binary relation `R` (as a set of pairs) on a set \(X\) is *transitive* if \((x,y), (y,z) \in R\) implies \((x,z) \in R\). Alternatively, \(R\) as a mapping is transitive if for all \(x \in X\), the image set \(R(R(x))\) of the image set \(R(x)\) of \(x\) is a subset of \(R(x)\).

gap> IsTransitiveBinaryRelation(BinaryRelationOnPoints([[1,2,3],[2,3],[]])); true gap> IsTransitiveBinaryRelation(BinaryRelationOnPoints([[1,2],[2,3],[]])); false

`‣ IsAntisymmetricBinaryRelation` ( rel ) | ( property ) |

returns `true`

if the binary relation `rel` is antisymmetric, and `false`

otherwise.

A binary relation `R` (as a set of pairs) on a set \(X\) is *antisymmetric* if \((x,y), (y,x) \in R\) implies \(x = y\). Alternatively, \(R\) as a mapping is antisymmetric if for all \(x \in X\), the intersection of the preimage set of \(x\) under \(R\) and the image set \(R(x)\) is \(\{ x \}\).

`‣ IsPreOrderBinaryRelation` ( rel ) | ( property ) |

returns `true`

if the binary relation `rel` is a preorder, and `false`

otherwise.

A *preorder* is a binary relation that is both reflexive and transitive.

`‣ IsPartialOrderBinaryRelation` ( rel ) | ( property ) |

returns `true`

if the binary relation `rel` is a partial order, and `false`

otherwise.

A *partial order* is a preorder which is also antisymmetric.

`‣ IsHasseDiagram` ( rel ) | ( property ) |

returns `true`

if the binary relation `rel` is a Hasse Diagram of a partial order, i.e., was computed via `HasseDiagramBinaryRelation`

(33.4-4).

`‣ IsEquivalenceRelation` ( R ) | ( property ) |

returns `true`

if the binary relation `R` is an equivalence relation, and `false`

otherwise.

Recall, that a relation `R` is an *equivalence relation* if it is symmetric, transitive, and reflexive.

`‣ Successors` ( R ) | ( attribute ) |

returns the list of images of a binary relation `R`. If the underlying domain of the relation is not \(\{ 1, \ldots, n \}\), for some positive integer \(n\), then an error is signalled.

The returned value of `Successors`

is a list of lists where the lists are ordered as the elements according to the sorted order of the underlying set of `R`. Each list consists of the images of the element whose index is the same as the list with the underlying set in sorted order.

The `Successors`

of a relation is the adjacency list representation of the relation.

gap> r1:=BinaryRelationOnPoints([[2],[3],[1]]);; gap> Successors(r1); [ [ 2 ], [ 3 ], [ 1 ] ]

`‣ DegreeOfBinaryRelation` ( R ) | ( attribute ) |

returns the size of the underlying domain of the binary relation `R`. This is most natural when working with a binary relation on points.

gap> DegreeOfBinaryRelation(r1); 3

`‣ PartialOrderOfHasseDiagram` ( HD ) | ( attribute ) |

is the partial order associated with the Hasse Diagram `HD` i.e. the partial order generated by the reflexive and transitive closure of `HD`.

We have special construction methods when the underlying `X` of our relation is the set of integers \(\{ 1, \ldots, n \}\).

`‣ BinaryRelationOnPoints` ( list ) | ( function ) |

`‣ BinaryRelationOnPointsNC` ( list ) | ( function ) |

Given a list of \(n\) lists, each containing elements from the set \(\{ 1, \ldots, n \}\), this function constructs a binary relation such that \(1\) is related to `list``[1]`

, \(2\) to `list``[2]`

and so on. The first version checks whether the list supplied is valid. The the `NC`

version skips this check.

gap> R:=BinaryRelationOnPoints([[1,2],[2],[3]]); Binary Relation on 3 points

`‣ RandomBinaryRelationOnPoints` ( degree ) | ( function ) |

creates a relation on points with degree `degree`.

`‣ AsBinaryRelationOnPoints` ( trans ) | ( function ) |

`‣ AsBinaryRelationOnPoints` ( perm ) | ( function ) |

`‣ AsBinaryRelationOnPoints` ( rel ) | ( function ) |

return the relation on points represented by general relation `rel`, transformation `trans` or permutation `perm`. If `rel` is already a binary relation on points then `rel` is returned.

Transformations and permutations are special general endomorphic mappings and have a natural representation as a binary relation on points.

In the last form, an isomorphic relation on points is constructed where the points are indices of the elements of the underlying domain in sorted order.

gap> t:=Transformation([2,3,1]);; gap> r1:=AsBinaryRelationOnPoints(t); Binary Relation on 3 points gap> r2:=AsBinaryRelationOnPoints((1,2,3)); Binary Relation on 3 points gap> r1=r2; true

`‣ ReflexiveClosureBinaryRelation` ( R ) | ( operation ) |

is the smallest binary relation containing the binary relation `R` which is reflexive. This closure inherits the properties symmetric and transitive from `R`. E.g., if `R` is symmetric then its reflexive closure is also.

`‣ SymmetricClosureBinaryRelation` ( R ) | ( operation ) |

is the smallest binary relation containing the binary relation `R` which is symmetric. This closure inherits the properties reflexive and transitive from `R`. E.g., if `R` is reflexive then its symmetric closure is also.

`‣ TransitiveClosureBinaryRelation` ( rel ) | ( operation ) |

is the smallest binary relation containing the binary relation `R` which is transitive. This closure inherits the properties reflexive and symmetric from `R`. E.g., if `R` is symmetric then its transitive closure is also.

`TransitiveClosureBinaryRelation`

is a modified version of the Floyd-Warshall method of solving the all-pairs shortest-paths problem on a directed graph. Its asymptotic runtime is \(O(n^3)\) where \(n\) is the size of the vertex set. It only assumes there is an arbitrary (but fixed) ordering of the vertex set.

`‣ HasseDiagramBinaryRelation` ( partial-order ) | ( operation ) |

is the smallest relation contained in the partial order `partial-order` whose reflexive and transitive closure is equal to `partial-order`.

`‣ StronglyConnectedComponents` ( R ) | ( operation ) |

returns an equivalence relation on the vertices of the binary relation `R`.

`‣ PartialOrderByOrderingFunction` ( dom, orderfunc ) | ( function ) |

constructs a partial order whose elements are from the domain `dom` and are ordered using the ordering function `orderfunc`. The ordering function must be a binary function returning a boolean value. If the ordering function does not describe a partial order then `fail`

is returned.

An *equivalence relation* `E` over the set `X` is a relation on `X` which is reflexive, symmetric, and transitive. A *partition* `P` is a set of subsets of `X` such that for all \(R, S \in P\), \(R \cap S\) is the empty set and \(\cup P = X\). An equivalence relation induces a partition such that if \((x,y) \in E\) then \(x, y\) are in the same element of `P`.

Like all binary relations in **GAP** equivalence relations are regarded as general endomorphic mappings (and the operations, properties and attributes of general mappings are available). However, partitions provide an efficient way of representing equivalence relations. Moreover, only the non-singleton classes or blocks are listed allowing for small equivalence relations to be represented on infinite sets. Hence the main attribute of equivalence relations is `EquivalenceRelationPartition`

(33.6-1) which provides the partition induced by the given equivalence.

`‣ EquivalenceRelationByPartition` ( domain, list ) | ( function ) |

`‣ EquivalenceRelationByPartitionNC` ( domain, list ) | ( function ) |

constructs the equivalence relation over the set `domain` which induces the partition represented by `list`. This representation includes only the non-trivial blocks (or equivalent classes). `list` is a list of lists, each of these lists contain elements of `domain` and are pairwise mutually exclusive.

The list of lists do not need to be in any order nor do the elements in the blocks (see `EquivalenceRelationPartition`

(33.6-1)). a list of elements of `domain` The partition `list` is a list of lists, each of these is a list of elements of `domain` that makes up a block (or equivalent class). The `domain` is the domain over which the relation is defined, and `list` is a list of lists, each of these is a list of elements of `domain` which are related to each other. `list` need only contain the nontrivial blocks and singletons will be ignored. The `NC`

version will not check to see if the lists are pairwise mutually exclusive or that they contain only elements of the domain.

gap> er:=EquivalenceRelationByPartition(Domain([1..10]),[[1,3,5,7,9],[2,4,6,8,10]]); <equivalence relation on <object> > gap> IsEquivalenceRelation(er); true

`‣ EquivalenceRelationByRelation` ( rel ) | ( function ) |

returns the smallest equivalence relation containing the binary relation `rel`.

`‣ EquivalenceRelationByPairs` ( D, elms ) | ( function ) |

`‣ EquivalenceRelationByPairsNC` ( D, elms ) | ( function ) |

return the smallest equivalence relation on the domain `D` such that every pair in `elms` is in the relation.

In the `NC`

form, it is not checked that `elms` are in the domain `D`.

`‣ EquivalenceRelationByProperty` ( domain, property ) | ( function ) |

creates an equivalence relation on `domain` whose only defining datum is that of having the property `property`.

`‣ EquivalenceRelationPartition` ( equiv ) | ( attribute ) |

returns a list of lists of elements of the underlying set of the equivalence relation `equiv`. The lists are precisely the nonsingleton equivalence classes of the equivalence. This allows us to describe "small" equivalences on infinite sets.

`‣ GeneratorsOfEquivalenceRelationPartition` ( equiv ) | ( attribute ) |

is a set of generating pairs for the equivalence relation `equiv`. This set is not unique. The equivalence `equiv` is the smallest equivalence relation over the underlying set which contains the generating pairs.

`‣ JoinEquivalenceRelations` ( equiv1, equiv2 ) | ( operation ) |

`‣ MeetEquivalenceRelations` ( equiv1, equiv2 ) | ( operation ) |

`JoinEquivalenceRelations`

returns the smallest equivalence relation containing both the equivalence relations `equiv1` and `equiv2`.

`MeetEquivalenceRelations`

returns the intersection of the two equivalence relations `equiv1` and `equiv2`.

`‣ IsEquivalenceClass` ( obj ) | ( category ) |

returns `true`

if the object `obj` is an equivalence class, and `false`

otherwise.

An *equivalence class* is a collection of elements which are mutually related to each other in the associated equivalence relation. Note, this is a special category of objects and not just a list of elements.

`‣ EquivalenceClassRelation` ( C ) | ( attribute ) |

returns the equivalence relation of which `C` is a class.

`‣ EquivalenceClasses` ( rel ) | ( attribute ) |

returns a list of all equivalence classes of the equivalence relation `rel`. Note that it is possible for different methods to yield the list in different orders, so that for two equivalence relations \(c1\) and \(c2\) we may have \(c1 = c2\) without having `EquivalenceClasses`

\(( c1 ) = \)`EquivalenceClasses`

\(( c2 )\).

gap> er:=EquivalenceRelationByPartition(Domain([1..10]),[[1,3,5,7,9],[2,4,6,8,10]]); <equivalence relation on <object> > gap> classes := EquivalenceClasses(er); [ {1}, {2} ]

`‣ EquivalenceClassOfElement` ( rel, elt ) | ( operation ) |

`‣ EquivalenceClassOfElementNC` ( rel, elt ) | ( operation ) |

return the equivalence class of `elt` in the binary relation `rel`, where `elt` is an element (i.e. a pair) of the domain of `rel`. In the `NC`

form, it is not checked that `elt` is in the domain over which `rel` is defined.

gap> EquivalenceClassOfElement(er,3); {3}

Goto Chapter: Top 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 Bib Ind

generated by GAPDoc2HTML