# Relational operators

## Purpose of relational operators

To say things such as "the name of the owner", we want to string together multiple relations (viz. `name` and `owner`). Relational operators allow us to make such statements.

## Converse

A relation can be altered by swapping the elements of every pair in the relation. Mathematically, $$(a, b)$$ is a different from $$(b,a)$$. This operation is called the converse operator. It produces a new relation from an existing one. It is denoted by writing $$\smallsmile$$ (pronounced 'wok' or ’flip’) after the relation name. This is how converse is defined:

$$
a(r\smallsmile)b\ \Leftrightarrow\ b\ r\ a
$$

If $$r$$ has type$$\[A\times B]$$, then $$r\smallsmile$$ has type $$\[B\times A]$$.

## Composition

The composition operator is denoted by a semicolon $$;$$ between two terms. It is pronounced as 'composed with'. Let us take a look at $$r$$ composed with $$s$$. Let $$r\_{\[A\times B]}$$ and $$s\_{\[B\times C]}$$ be two relations, with the target of r being the same as the source of s. Then the composition of $$r$$ and $$s$$ is defined by:

$$
a(r;s)c\ \Leftrightarrow\ ∃ b∈B\ ∙\ a\ r\ b ∧ b\ s\ c
$$

If $$r$$ has type$$\[A\times B]$$and $$s$$has type$$\[B\times C]$$, then $$r;s$$ has type $$\[A\times C]$$.

## How to type boolean operators in your script

[This page](/documentation/the-language-ampersand/terms.md#notation-on-the-keyboard) shows how you can type boolean (and other) operators in your Ampersand script.

## Other explanation

Would you like a different explanation of the relational operators? [This page](/documentation/the-language-ampersand/terms/semantics-in-sets/relational-operators-in-set-theory.md) explains the relational operators in terms of set theory. [This page](/documentation/the-language-ampersand/terms/semantics-in-natural-language/relational-operators-in-natural-language.md) explains them in natural language. [Click here](/documentation/the-language-ampersand/terms/semantics-in-algebra/relational-operators-in-algebra.md) for some algebraic rules about relational operators.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ampersandtarski.gitbook.io/documentation/the-language-ampersand/terms/semantics-in-logic/relational-operators.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
