Skip to main content

Sets

A set is a collection of distinct elements.

The Compute Engine standard library includes definitions for common numeric sets. Checking if a value belongs to a set is done using the Element expression, or the \in (\in) command in LaTeX.

ce.box(['Element', 3.14, 'NegativeIntegers']).evaluate().print();
// ➔ False

ce.parse("42 \\in \\Z").evaluate().print();
// ➔ True

Checking if an element is in a set is equivalent to checking if the type of the element matches the type associated with the set.

const x = ce.box(42);

x.type;
// ➔ "finite_integer"

x.type.matches("integer");
// ➔ true

x.isInteger;
// ➔ true

ce.box(['Element', x, 'Integers']).evaluate().print();
// ➔ True

ce.parse("42 \\in \\Z").evaluate().print();
// ➔ True

Constants

SymbolNotation Definition
EmptySet\varnothing or \emptyset\varnothing or \emptysetA set that has no elements
Numbers\mathrm{Numbers}\mathrm{Numbers}Any number, real, imaginary, or complex
ComplexNumbers\C\CReal or imaginary numbers
ExtendedComplexNumbers\overline\C\overline\CReal or imaginary numbers, including +\infty, -\infty and \tilde\infty
ImaginaryNumbers\imaginaryI\R\imaginaryI\RComplex numbers with a non-zero imaginary part and no real part
RealNumbers\R\RNumbers that form the unique Dedekind-complete ordered field \left( \mathbb{R} ; + ; \cdot ; \lt \right), up to an isomorphism (does not include \pm\infty)
ExtendedRealNumbers\overline\R\overline\RReal numbers extended to include \pm\infty
Integers\Z \ZWhole numbers and their additive inverse \lbrace \ldots -3, -2, -1,0, 1, 2, 3\ldots\rbrace
ExtendedIntegers\overline\Z \overline\ZIntegers extended to include \pm\infty
RationalNumbers\Q\QNumbers which can be expressed as the quotient \nicefrac{p}{q} of two integers p, q \in \mathbb{Z}.
ExtendedRationalNumbers\overline\Q \overline\QRational numbers extended to include \pm\infty
NegativeNumbers\R_{<0}\R_{<0}Real numbers \lt 0
NonPositiveNumbers\R_{\leq0}\R_{\leq0}Real numbers \leq 0
NonNegativeNumbers\R_{\geq0}\R_{\geq0}Real numbers \geq 0
PositiveNumbers\R_{>0}\R_{>0}Real numbers \gt 0
NegativeIntegers\Z_{<0}\Z_{<0}Integers \lt 0, \lbrace \ldots -3, -2, -1\rbrace
NonPositiveIntegers\Z_{\le0}\Z_{\le0}Integers \leq 0, \lbrace \ldots -3, -2, -1, 0\rbrace
NonNegativeIntegers\N\NIntegers \geq 0, \lbrace 0, 1, 2, 3\ldots\rbrace
PositiveIntegers\N^*\N^*Integers \gt 0, \lbrace 1, 2, 3\ldots\rbrace

Functions

New sets can be defined using one of the following operators.

FunctionOperation
CartesianProduct\operatorname{A} \times \operatorname{B}A.k.a the product set, the set direct product or cross product. Q173740
Complement\operatorname{A}^\complementThe set of elements that are not in \operatorname{A}. If \operatorname{A} is a numeric type, the universe is assumed to be the set of all numbers. Q242767
Intersection\operatorname{A} \cap \operatorname{B}The set of elements that are in \operatorname{A} and in \operatorname{B} Q185837
Union\operatorname{A} \cup \operatorname{B}The set of elements that are in \operatorname{A} or in \operatorname{B} Q173740
Set\lbrace 1, 2, 3 \rbrace Set builder notation
SetMinus\operatorname{A} \setminus \operatorname{B}Q18192442
SymmetricDifference\operatorname{A} \triangle \operatorname{B}Disjunctive union = (\operatorname{A} \setminus \operatorname{B}) \cup (\operatorname{B} \setminus \operatorname{A}) Q1147242

Relations

To check the membership of an element in a set or the relationship between two sets using the following operators.

FunctionNotation 
Elementx \in \operatorname{A}x \in \operatorname{A}
NotElementx \not\in \operatorname{A}x \not\in \operatorname{A}
NotSubset\operatorname{A} \nsubset \operatorname{B}\operatorname{A} \nsubset \operatorname{B}
NotSuperset\operatorname{A} \nsupset \operatorname{B}\operatorname{A} \nsupset \operatorname{B}
Subset\operatorname{A} \subset \operatorname{B}
\operatorname{A} \subsetneq \operatorname{B}
\operatorname{A} \varsubsetneqq \operatorname{B}
\operatorname{A} \subset \operatorname{B}
\operatorname{A} \subsetneq \operatorname{B}
\operatorname{A} \varsubsetneqq \operatorname{B}
SubsetEqual\operatorname{A} \subseteq \operatorname{B}\operatorname{A} \subseteq \operatorname{B}
Superset\operatorname{A} \supset \operatorname{B}
\operatorname{A} \supsetneq \operatorname{B}
\operatorname{A} \varsupsetneq \operatorname{B}
\operatorname{A} \supset \operatorname{B}
\operatorname{A} \supsetneq \operatorname{B}
\operatorname{A} \varsupsetneq \operatorname{B}
SupersetEqual\operatorname{A} \supseteq \operatorname{B}\operatorname{A} \supseteq \operatorname{B}