Synopsis An unordered set of tuples.
Description In mathematics, given sets D1, D2, ... Dn, a n-ary relation R is characterized by RD1 × D2 × ... × Dn. In other words, R consists of a set of tuples <V1, ..., Vn> where each Vi is an element of the set Di. When n = 2, we call the relation a binary relation.

In database theory, a relation is a table with a heading and an unordered set of tuples:
D1 Name1 D2 Name2 ... Dn Namen
V11 V12 ... V1n
V21 V22 ... V2n
V31 V32 ... V3n
... ... ...

In Rascal, a relation is a set of tuples and is characterized by the type: rel[D1 Name1, D2 Name2, ..., Dn Namen] See Rascal:Values/Relation and for a description of relations and their operators (since relations are sets all set operators also apply to them, see Rascal:Values/Set) and Rascal:Prelude/Relation for functions on relations (and here again, since relations are sets all set operators also apply to them, see Rascal:Prelude/Set).

Relations in daily life

  • The parent-of or friend-of relation between people.
  • A character relation map, describing the relations between the characters in a play or soap series.
  • A listing of the top 2000 songs of all times including the position, artist name, song title, the year the song was published.
char-relation credit top2000-2010 credit

Relations in computer science

  • A relational data base.
  • Login information including user name, password, home directory, etc.

Relations in Rascal

  • A parent child relation:
    rel[str parent, str child] = {
    <"Paul", "Eva">,
    <"Paul", "Thomas">,
    <"Jurgen", "Simon">,
    <"Jurgen", "David">,
    <"Tijs", "Mats">
  • A fragment of the top 2000 relation:
    rel[int position, str artist, str title, int year] Top2000 = {
    <1, "Eagles", "Hotel California",1977>,
    <2, "Queen", "Bohemian rhapsody", 1975>,
    <3, "Boudewijn de Groot", "Avond", 1997>,
Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit