Skip to content
Relation Literals

Relation Literals

Relation literals do not have a dedicated syntax, but are by convention written with outer curly braces, parentheses around tuples, commas in the tuples, and semicolons between the tuples.

ExampleDescription
{1}Singleton relation (arity 1, cardinality 1).
{1; 2; 3; 4}Unary relation (arity 1, cardinality 4).
{(1, 2); (3, 4); (5, 6)}Binary relation (arity 2, cardinality 3).
{1; 2; 1; 2}Arity 1, cardinality 2 (duplicates are eliminated).
{()}Unit relation (cardinality 1, arity 0).
{}Empty relation (cardinality 0, any arity).

Note that the arguments do not have to be constants, so the relation literal is not a relation constant. The tuples can contain variables and other expressions.

For example, {(friend, 1); (family, 2); (partner, 3)} for binary friend, family and partner has arity 3 and unknown cardinality. You can define it explicitly as:

x, y, v:
    (friend(x, y) and v = 1) or
    (family(x, y) and v = 2) or
    (partner(x, y) and v = 3)

Here is a more complicated example. The second element of the tuple in the relation literal that is the body of the definition for output is an expression that involves another relation literal and a partial relational application:

// read query
 
def name = {"Bob"; "Jill"; "Joe"}
def father = {("Bob", "Jill"); ("Bob", "Joe")}
def output = {("-->", {(1, father, 2)}[_])}

Next: Composition

Was this doc helpful?