> For the complete documentation index, see [llms.txt](https://ampersandtarski.gitbook.io/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ampersandtarski.gitbook.io/documentation/the-language-ampersand/terms/semantics-in-sets/boolean-operators-sets.md).

# Boolean operators in set theory

A relation is by definition a subset of the Cartesian Product of the source and target sets. So, if two different relations r and s are defined on the same source A and target B, then the ordinary set operators can be applied to produce a new relation.

* intersection : $$r ∩ s$$ is the set that contains the elements that are contained in relation $$r$$ as well as in $$s$$, or $$r ∩ s\ =\ { (x,y)\ |\ (x,y) ∈ r ∧ (x,y) ∈ s }$$
* union : $$r ∪ s$$ is the set that contains all elements that are contained either in relation $$r$$ or in $$s$$, or $$r ∪ s\ =\ { (x,y)\ |\ (x,y) ∈ r ∨ (x,y) ∈ s }$$
* difference : $$r - s$$ is the set that contains the elements of relation $$r$$ that are not contained in $$s$$, or $$r - s\ =\ { (x,y)\ |\ (x,y) ∈ r ∧ (x,y) ∉ s }$$

The complement (or negation) of a relation $$r\_{\[A x B]}$$ is defined by means of the difference operator:

* complement : If $$r$$ is defined as $$r\_{A\times B}$$, then $$\overline{r}$$ is the set of all tuples in $$A\times B$$ (the Cartesian product) that are not contained in $$r$$. So $$\overline{r} = V\_{\[A\times B]} - r$$

Note that the complement is defined in terms of $$A$$ and $$B$$. So, two relations with the identical population yet a different type may have different complements.

## How to type boolean operators in your script

[This page](/documentation/the-language-ampersand/terms.md#notation-on-the-keyboard) shows how you can write these things in your Ampersand script.

## Other explanation

Would you like a different explanation of the boolean operators? [This page](/documentation/the-language-ampersand/terms/semantics-in-logic/boolean-operators.md) explains the boolean operators in logic.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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-sets/boolean-operators-sets.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.
