Ring

summary(Technical): A ring $R$ is a triple $(X, \oplus, \otimes)$ where $X$ is a [set](https://arbital.com/p/3jz) and $\oplus$ and $\otimes$ are binary [operations](https://arbital.com/p/set_theory_operation) subject to the ring axioms. We write $x \oplus y$ for the application of $\oplus$ to $x, y \in X$, which must be defined, and similarly for $\otimes$. Terminology varies across sources; our rings will have both operations [commutative](https://arbital.com/p/3jb) and will have an [https://arbital.com/p/-54p](https://arbital.com/p/-54p) under multiplication, denoted $1$.

A ring $R$ is a triple $(X, \oplus, \otimes)$ where $X$ is a [set](https://arbital.com/p/3jz) and $\oplus$ and $\otimes$ are binary [operations](https://arbital.com/p/set_theory_operation) subject to the ring axioms. We write $x \oplus y$ for the application of $\oplus$ to $x, y \in X$, which must be defined, and similarly for $\otimes$. It is standard to abbreviate $x \otimes y$ as $xy$ when $\otimes$ can be inferred from context. The ten ring axioms (which govern the behavior of $\oplus$ and $\otimes$) are as follows:

1. $X$ must be a [commutative group](https://arbital.com/p/3h2) under $\oplus$. That means:
   * $X$ must be [closed](https://arbital.com/p/3gy) under $\oplus$.
   * $\oplus$ must be [associative](https://arbital.com/p/associative_function).
   * $\oplus$ must be [commutative](https://arbital.com/p/commutative_function).
   * $\oplus$ must have an identity, which is usually named $0$.
   * Every $x \in X$ must have an inverse $(-x) \in X$ such that $x \oplus (-x) = 0$.
2. $X$ must be a [monoid](https://arbital.com/p/3h3) under $\otimes$. That means:
   * $X$ must be [closed](https://arbital.com/p/3gy) under $\otimes$.
   * $\otimes$ must be [associative](https://arbital.com/p/associative_function).
   * $\otimes$ must have an identity, which is usually named $1$.
3. $\otimes$ must [distribute](https://arbital.com/p/distributive_property) over $\oplus$. That means:
  * $a \otimes (x \oplus y) = (a\otimes x) \oplus (a\otimes y)$ for all $a, x, y \in X$.
  * $(x \oplus y)\otimes a = (x\otimes a) \oplus (y\otimes a)$ for all $a, x, y \in X$.

Though the axioms are many, the idea is simple: A ring is a [commutative group](https://arbital.com/p/3h2) equipped with an additional operation, under which the ring is a [monoid](https://arbital.com/p/3h3), and the two operations play nice together (the monoid operation [distributes](https://arbital.com/p/distributive_property) over the group operation).

A ring is an [algebraic structure](https://arbital.com/p/3gx).  To see how it relates to other algebraic structures, refer to the [tree of algebraic structures](https://arbital.com/p/5dz).

# Examples

The integers $\mathbb{Z}$ form a ring under addition and multiplication.

[Add more example rings.](https://arbital.com/p/fixme:)
\[in progress.\](https://arbital.com/p/work)

# Notation

Given a ring $R = (X, \oplus, \otimes)$, we say "$R$ forms a ring under $\oplus$ and $\otimes$." $X$ is called the [underlying set](https://arbital.com/p/3gz) of $R$. $\oplus$ is called the "additive operation," $0$ is called the "additive identity", $-x$ is called the "additive inverse" of $x$. $\otimes$ is called the "multiplicative operation," $1$ is called the "multiplicative identity", and a ring does not necessarily have multiplicative inverses.

# Basic properties

[Add the basic properties of rings.](https://arbital.com/p/fixme:)
\[in progress.\](https://arbital.com/p/work)

# Interpretations, Visualizations, and Applications

[Add ](https://arbital.com/p/fixme:)
\[in progress.\](https://arbital.com/p/work)

Eric Bruylant
Nate Soares
Dylan Hendrickson
Patrick Stevens

Summary: A ring is a kind of [https://arbital.com/p/-3gx](https://arbital.com/p/-3gx) which we obtain by considering [groups](https://arbital.com/p/3gd) as being "things with addition" and then endowing them with a multiplication operation which must interact appropriately with the pre-existing addition. Terminology varies across sources;  we will take "ring" to refer to "commutative ring with $1$".


Algebraic structure

Roughly speaking, an algebraic structure is a set $X$, known as the [underlying set](https://arbital.com/p/3gz), paired with a collection of [operations](https://arbital.com/p/3h7) that obey a given set of laws. For example, a [group](https://arbital.com/p/3gd) is a set paired with a single binary operation that satisfies the four group axioms, and a [ring](https://arbital.com/p/3gq) is a set paired with two binary operations that satisfy the ten ring axioms.

In fact, algebraic structures can have more than one underlying set. Most have only one (including [monoids](https://arbital.com/p/3h3), [groups](https://arbital.com/p/3gd), [rings](https://arbital.com/p/3gq), [fields](https://arbital.com/p/algebraic_field), [lattices](https://arbital.com/p/algebraic_lattice), and [arithmetics](https://arbital.com/p/algebraic_arithmetic)), and differ in how their associated operations work. More complex algebraic structures (such as  [algebras](https://arbital.com/p/algebraic_algebra), [modules](https://arbital.com/p/algebraic_module), and [vector spaces](https://arbital.com/p/3w0)) have two underlying sets. For example, vector spaces are defined using both an underlying [field](https://arbital.com/p/algebraic_field) of scalars and an underlying [commutative group](https://arbital.com/p/3h2) of vectors.

For a map of algebraic structures and how they relate to each other, see the [tree of algebraic structures](https://arbital.com/p/algebraic_structure_tree).

Eric Bruylant
Nate Soares
Alexei Andreev
Eric Rogstad


Closure

A [set](https://arbital.com/p/3jz) $S$ is _closed_ under an [operation](https://arbital.com/p/3h7) $f$ if, whenever $f$ is fed elements of $S$, it produces another element of $S$. For example, if $f$ is a trinary operation (i.e., a function of three arguments) then "$S$ is closed under $f$" means "if $x, y, z \in S$ then $f(x, y, z) \in S$".

For example, the set [$\mathbb Z$](https://arbital.com/p/integer) is closed under addition (because adding two integers yields another integer), but the set $\mathbb Z_5 = \{0, 1, 2, 3, 4, 5\}$ is not (because $1 + 5$ is not in $\mathbb Z_5$).


Underlying set

What do a [https://arbital.com/p/-3gd](https://arbital.com/p/-3gd), a [https://arbital.com/p/-3rb](https://arbital.com/p/-3rb), and a [topological space](https://arbital.com/p/) have in common? Each is a [https://arbital.com/p/-3jz](https://arbital.com/p/-3jz) with some structure built on top of it, and in each case, we call the set the *underlying set*. %%note: A group is a set with an [operation](https://arbital.com/p/3h7), a poset is a set with an [ordering](https://arbital.com/p/3dt), and a topological space is a set with a collection of subsets that satisfy a [certain property](https://arbital.com/p/).%%

###Algebraic structures###

An [algebraic structure](https://arbital.com/p/3gx) is a set equipped with operators that follow certain laws, such as a [group](https://arbital.com/p/3gd), which is a pair $(X, \bullet)$ where $X$ is a [set](https://arbital.com/p/3jz) and $\bullet$ is an operator that follows certain laws. Given an algebraic structure,  we can simply throw away the operators and recover the set ($X$, in this case), which is known as the "underlying set" of the structure.

The underlying set is sometimes known as the "carrier set." Some algebraic structures have more than one underlying set; for example, a vector space is an algebraic structure built out of a [field](https://arbital.com/p/481) of scalars and a [commutative group](https://arbital.com/p/3h2), in which case the term "underlying set" is ambiguous.

Alexei Andreev
Eric Rogstad
Eric Bruylant
Nate Soares
Patrick Stevens


Abstract algebra

Abstract algebra is the study of [algebraic structures](https://arbital.com/p/3gx), including [groups](https://arbital.com/p/3gd), [rings](https://arbital.com/p/3gq), [fields](https://arbital.com/p/algebraic_field), [modules](https://arbital.com/p/algebraic_module), [vector spaces](https://arbital.com/p/vector_space), [lattices](https://arbital.com/p/algebraic_lattice), [arithmetics](https://arbital.com/p/algebraic_arithmetic), and [algebras](https://arbital.com/p/algebraic_algebra).

The main idiom of abstract algebra is [abstracting away from the objects](https://arbital.com/p/abstract_over_objects): Abstract algebra concerns itself with the manipulation of objects, by focusing not on the objects themselves but on the relationships between them.

If you find any collection of objects that are related to each other in a manner that follows the laws of some algebraic structure, then those relationships are governed by the corresponding theorems, regardless of what the objects are. An abstract algebraist does not ask "what are numbers, really?"; rather, they say "I see that the operations of 'adding apples to the table' and 'removing apples from the table' follow the laws of numbers (in a limited domain), thus, theorems about numbers can tell what to expect as I add or remove apples (in that limited domain)."

For a map of algebraic structures and how they relate to each other, see the [tree of algebraic structures](https://arbital.com/p/algebraic_structures_tree).


Abelian group

An abelian group is a [group](https://arbital.com/p/3gd) $G=(X, \bullet)$ where $\bullet$ is [commutative](https://arbital.com/p/3jb). In other words, the group operation satisfies the five axioms:

1. [Closure](https://arbital.com/p/3gy): For all $x, y$ in $X$, $x \bullet y$ is defined and in $X$. We abbreviate $x \bullet y$ as $xy$.
2. [Associativity](https://arbital.com/p/3h4): $x(yz) = (xy)z$ for all $x, y, z$ in $X$.
3. Identity: There is an element $e$ such that for all $x$ in $X$, $xe=ex=x$.
4. Inverses: For each $x$ in $X$ is an element $x^{-1}$ in $X$ such that $xx^{-1}=x^{-1}x=e$.
5. [Commutativity](https://arbital.com/p/3jb): For all $x, y$ in $X$, $xy=yx$.

The first four are the standard [group axioms](https://arbital.com/p/3gd); the fifth is what distinguishes abelian groups from groups.

Commutativity gives us license to re-arrange chains of elements in formulas about commutative groups. For example, if in a commutative group with elements $\{1, a, a^{-1}, b, b^{-1}, c, c^{-1}, d\}$, we have the claim $aba^{-1}db^{-1}=d^{-1}$, we can shuffle the elements to get $aa^{-1}bb^{-1}d=d^{-1}$ and reduce this to the claim $d=d^{-1}$. This would be invalid for a nonabelian group, because $aba^{-1}$ doesn't necessarily equal $aa^{-1}b$ in general.

Abelian groups are very well-behaved groups, and they are often much easier to deal with than their non-commutative counterparts. For example, every [https://arbital.com/p/576](https://arbital.com/p/576) of an abelian group is [normal](https://arbital.com/p/4h6), and all finitely generated abelian groups are a [direct product](https://arbital.com/p/group_theory_direct_product) of [cyclic groups](https://arbital.com/p/47y) (the [structure theorem for finitely generated abelian groups](https://arbital.com/p/structure_theorem_for_finitely_generated_abelian_groups)).

Alexei Andreev
Qiaochu Yuan
Eric Rogstad
Nate Soares
Patrick Stevens

Summary:
An abelian group is a [group](https://arbital.com/p/3gd) where the operation is [commutative](https://arbital.com/p/3jb). That is, an abelian group $G$ is a pair $(X, \bullet)$ where $X$ is a [set](https://arbital.com/p/3jz) and $\bullet$ is a binary [operation](https://arbital.com/p/3h7) obeying the four group axioms plus an axiom of commutativity:

1. [Closure](https://arbital.com/p/3gy): For all $x, y$ in $X$, $x \bullet y$ is defined and in $X$. We abbreviate $x \bullet y$ as $xy$.
2. [Associativity](https://arbital.com/p/3h4): $x(yz) = (xy)z$ for all $x, y, z$ in $X$.
3. Identity: There is an element $e$ such that for all $x$ in $X$, $xe=ex=x$.
4. Inverses: For each $x$ in $X$ is an element $x^{-1}$ in $X$ such that $xx^{-1}=x^{-1}x=e$.
5. [Commutativity](https://arbital.com/p/3jb): For all $x, y$ in $X$, $xy=yx$.

Abelian groups are very "well-behaved" groups that are often easier to deal with than their non-commuting counterparts.


Monoid

A monoid $M$ is a pair $(X, \diamond)$ where $X$ is a [set](https://arbital.com/p/set_theory_set) and $\diamond$ is an [associative](https://arbital.com/p/associative_function) binary [operator](https://arbital.com/p/3h7) with an identity. $\diamond$ is often interpreted as concatenation; data structures that support concatenation and have an "empty element" (such as lists, strings, and the natural numbers under addition) are examples of monoids.

 Monoids are [algebraic structures](https://arbital.com/p/3gx). We write $x \diamond y$ for the application of $\diamond$ to $x, y \in X$, which must be defined. $x \diamond y$ is commonly abbreviated $xy$ when $\diamond$ can be inferred from context. The monoid axioms (which govern the behavior of $\diamond$) are as follows.

1. (Closure) For all $x, y$ in $X$, $xy$ is also in $X$.
1. (Associativity) For all $x, y, z$ in $X$, $x(yz) = (xy)z$.
2. (Identity) There is an $e$ in $X$ such that, for all $x$ in $X$, $xe = ex = x.$

The axiom of closure says that $x \diamond y \in X$, i.e. that combining two elements of $X$ using $\diamond$ yields another element of $X$. In other words, $X$ is [closed](https://arbital.com/p/3gy) under $\diamond$.

The axiom of associativity says that $\diamond$ is an [associative](https://arbital.com/p/3h4) operation, which justifies omitting parenthesis when describing the application of $\diamond$ to many elements in sequence..

The axiom of identity says that there is some element $e$ in $X$ that $\diamond$ treats as "empty": If you apply $\diamond$ to $e$ and $x$, then $\diamond$ simply returns $x$. The identity is unique: Given two elements $e$ and $z$ that satisfy the axiom of identity, we have $ze = e = ez = z.$ Thus, we can speak of "the identity" $e$ of $M$. $e$ is often written $1$ or $1_M$.

%%%knows-requisite([https://arbital.com/p/4c7](https://arbital.com/p/4c7)):
Equivalently, a monoid is a category with exactly one object.
%%%

Monoids are [semigroups](https://arbital.com/p/algebraic_semigroup) equipped with an identity. [Groups](https://arbital.com/p/3gd) are monoids with inverses. For more on how monoids relate to other [algebraic structures](https://arbital.com/p/algerbraic_structure), refer to the [tree of algebraic structures](https://arbital.com/p/algebraic_structure_tree).

# Notation

Given a monoid $M = (X, \diamond)$, we say "$X$ forms a monoid under $\diamond$." For example, the set of finite bitstrings forms a monoid under concatenation: The set of finite bitstrings is closed under concatenation; concatenation is an associative operation; and the empty bitstring is a finite bitstring that acts like an identity under concatenation.

$X$ is called the [underlying set](https://arbital.com/p/3gz) of $M$, and $\diamond$ is called the _monoid operation_. $x \diamond y$ is usually abbreviated $xy$. $M$ is generally allowed to substitute for $X$ when discussing the monoid. For example, we say that the elements $x, y \in X$ are "in $M$," and sometimes write "$x, y \in M$" or talk about the "elements of $M$."

# Examples

Bitstrings form a monoid under concatenation, with the empty string as the identity.

The set of finite lists of elements drawn from $Y$ (for any set $Y$) form a monoid under concatenation, with the empty list as the identity.

The natural numbers [$\mathbb N$](https://arbital.com/p/45h) form a monid under addition, with $0$ as the identity.

Monoids have found some use in functional programming languages such as [https://arbital.com/p/https://en.wikipedia.org/wiki/Haskell_](https://arbital.com/p/https://en.wikipedia.org/wiki/Haskell_) and [https://arbital.com/p/https://en.wikipedia.org/wiki/Scala_](https://arbital.com/p/https://en.wikipedia.org/wiki/Scala_), where they are used to generalize over data types in which values can be "combined" (by some operation $\diamond$) and which include an "empty" value (the identity).

Eric Bruylant
Nate Soares
Louis Paquin
Patrick Stevens


Associative operation

An **associative operation** $\bullet : X \times X \to X$ is a [binary](https://arbital.com/p/3kb) [operation](https://arbital.com/p/3h7) such that for all $x, y, z$ in $X$, $x \bullet (y \bullet z) = (x \bullet y) \bullet z$. For example, $+$ is an associative function, because $(x + y) + z = x + (y + z)$ for all values of $x, y,$ and $z$. When an associative function is used to combine many elements in a row, parenthesis can be dropped, because the order of application is irrelevant.

Imagine that you're trying to use $f$ to combine 3 elements $x, y,$ and $z$ into one element, via two applications of $f$. $f$ is associative if $f(f(x, y), z) = f(x, f(y, z)),$ i.e., if the result is the same regardless of whether you apply $f$ to $x$ and $y$ first (and then apply that result to $z$), or whether you apply $f$ to $y$ and $z$ first (and then apply $x$ to that result).

Visualizing $f$ as a [physical mechanism](https://arbital.com/p/3mb), there are two different ways to hook up two copies of $f$ together to create a function $f_3 : X \times X \times X \to X,$ which takes three inputs and produces one output:

![Two ways of combining f](http://i.imgur.com/Ezs1P8l.png)

An associative function $f$ is one where the result is the same no matter which way the functions are hooked up, which means that the result of using $f$ twice to turn three inputs into one output yields the same output regardless of the order in which we combine adjacent inputs.

![3-arity f](http://i.imgur.com/WCT9HaA.png)

By similar argument, an associative operator $f$ also gives rise (unambiguously) to functions $f_4, f_5, \ldots,$ meaning that [associative functions can be seen as a family of functions on lists](https://arbital.com/p/3ms).

This justifies the omission of parenthesis when writing expressions where an associative operator $\bullet$ is applied to many inputs in turn, because the order of application does not matter. For example, multiplication is associative, so we can write expressions such as $2 \cdot 3 \cdot 4 \cdot 5$ without ambiguity. It makes no difference whether we compute the result by first multiplying 2 by 3, or 3 by 4, or 4 by 5.

By contrast, the function `prependx` that sticks its inputs together and puts an `x` on the front is not associative: `prependx(prependx("a","b"),"c") = "xxabc"`, but `prependx("a",prependx("b","c"))=xaxbc`.

Eric Bruylant
Nate Soares
Dylan Hendrickson
Eric Rogstad


Operator

An operation $f$ on a [set](https://arbital.com/p/3jz) $S$ is a function that takes some values from $S$ and produces a new value. An operation can take any number of values from $S$, including zero (in which case $f$ is simply a constant) or infinitely many (in which case we call $f$ an "infinitary operation"). Common operations take a finite non-zero number of parameters. Operations often produce a value that is also in $S$ (in which case we say $S$ is [closed](https://arbital.com/p/3gy) under $f$), but that is not always the case.

For example, the function $+$ is a binary operation on [$\mathbb N$](https://arbital.com/p/45h), meaning it takes two values from $\mathbb N$ and produces another. Because $+$ produces a value that is also in $\mathbb N$, we say that $\mathbb N$ is closed under $+$.

The function $\operatorname{neg}$ that maps $x$ to $-x$ is a unary operation on [$\mathbb Z$](https://arbital.com/p/48l): It takes one value from $\mathbb Z$ as input, and produces an output in $\mathbb Z$ (namely, the negation of the input). $\operatorname{neg}$ is also a unary operation on $\mathbb N$, but $\mathbb N$ is not closed under $\operatorname{neg}$ (because $\operatorname{neg}(3)=-3$ is not in $\mathbb N$).

The number of values that the operator takes as input is called the [arity](https://arbital.com/p/3h8) of the operator. For example, the function $\operatorname{zero}$ which takes no inputs and returns $0$ is a zero-arity operator; and the operator $f(a, b, c, d) = ac - bd$ is a four-arity operator (which can be used on any [ring](https://arbital.com/p/3gq), if we interpret multiplication and subtraction as ring operations).

Eric Bruylant
Nate Soares
Patrick Stevens


Arity (of a function)

The arity of a [function](https://arbital.com/p/3jy) is the number of parameters that it takes. For example, the function $f(a, b, c, d) = ac - bd$ is a function with arity 4, and $+$ is a function with arity 2; 2-arity functions are known as [binary functions](https://arbital.com/p/3kb).

A function is said to take multiple parameters when its [domain](https://arbital.com/p/3js) is the product of multiple sets. For example, consider the function `is_older_than` that takes (as input) a person and an age and returns `yes` if the person is older than that age, and `no` otherwise. The domain of `is_older_than` is the set of all pairs of people and ages, which we might write as $(\mathrm{People} \times \mathrm{Ages})$. Because this set is a product of two sets, we say that `is_older_than` is a function of two parameters, and that it has arity 2.


Commutative operation

A commutative function $f$ is a [function](https://arbital.com/p/3jy) that takes multiple inputs from a [set](https://arbital.com/p/3jz) $X$ and produces an output that does not depend on the ordering of the inputs. For example, the binary operation $+$ is commutative, because $3 + 4 = 4 + 3.$ The string concatenation function [`concat`](https://arbital.com/p/3jv) is not commutative, because `concat("3","4")="34"` does not equal `concat("4","3")="43"`.

Eric Bruylant
Nate Soares
Dylan Hendrickson


Commutativity: Intuition

# Commutativity as an artifact of notation

Instead of thinking of a commutative function $f(x, y)$ as a function that takes an ordered pair of inputs, we can think of $f$ as a function that takes an unordered [bag](https://arbital.com/p/3jk) of inputs, and therefore _can't_ depend on their order. On this interpretation, the fact that functions are always given inputs in a particular order is an artifact of our definitions, not a fundamental property of functions themselves. If we had notation for functions applied to arguments in no particular order, then commutative functions would be the norm, and non-commutative functions would require additional structure imposed on their inputs.

In a world of linear left-to-right notation, where $f(x, y)$ means "$f$ applied to $x$ first and $y$ second", commutativity looks like a constraint. In an alternative world where functions are applied to their inputs in parallel, with none of them distinguished as "first" by default, commutativity is the natural state of affairs.

# Commutativity as symmetry in the output

Commutativity can be seen as a form of symmetry in the output of a [binary](https://arbital.com/p/3kb) [function](https://arbital.com/p/3jy). Imagine a binary function as a physical mechanism of wheels and gears, that takes two inputs in along conveyer belts (one on the left, one on the right), manipulates those inputs (using mechanical sensors and manipulators and tools), and produces a result that is placed on an outgoing conveyer belt.

The output of a commutative function is symmetric in the way it relates to the inputs. Consider a function that takes two wooden blocks and glues them together. The function might _manipulate_ them in a symmetric fashion (if both blocks are picked up simultaneously, and have glue applied simultaneously, and are pushed together simultaneously), but the output is not symmetric: If a red block comes in on the left and a blue block comes in on the right, then the resulting block is red on the left and blue on the right, and the function is not commutative (though it is [associative](https://arbital.com/p/3h4)).

By contrast, a function that mixes the red and blue together — producing, for example, the uniform color purple or the unordered [set](https://arbital.com/p/3jz) $\{b, d, e, l, u, r\}$ — would be commutative, because the way that the output relates to each input is independent of which side the input came in on.

A function is probably commutative if you can visualize the output itself as left/right symmetric, even if the left input was very different from the right input. For example, we can use the following visualization to show that multiplication is commutative. Imagine a function that takes in two stacks of poker chips, one on the left conveyer belt and one on the right conveyer belt. The function has a square of wet plaster in the middle. On each conveyer belt, an arm removes chips from the stack of poker chips until the stack only has one chip left, and for each chip that is removed, a perpendicular cut is put in the plaster (as in the diagram below). The plaster is then allowed to set, and the plaster pieces are then shaken out into a big bag. A third arm removes plaster pieces from the bag one at a time, and adds a poker chip to the outgoing conveyer belt for each one. To visualize this, see the diagram below:

![Why multiplication commutes](http://i.imgur.com/Q3QBUT6.png)

If the input conveyer belts had 4 and 6 poker chips on them (respectively), then the output belt will have 24 chips on it (because 24 different chunks of plaster will have fallen into the bag), but the chips don't necessarily come from any one particular side: The output relates to each input in a manner that doesn't depend on which side they came in.

%%%knows-requisite([https://arbital.com/p/1r6](https://arbital.com/p/1r6)):
In mathematics, a [symmetry](https://arbital.com/p/symmetry_mathematics) is some structure on a set that is preserved under some transformation of that set. In our case, the structure is the value of the output, which is preserved under the transformation of changing which side the inputs come in on. Formally, let $X^2$ be the set of all pairs of two values from the set $X;$ each point in $X^2$ is a pair $(x_1, x_2).$ $X^2$ can be visualized as an [$|X|$](https://arbital.com/p/4w5) by $|X|$ grid. Consider a function $f : X^2 \to Y$ as a structure on $X^2$ that assigns a value $f(x_1, x_2)$ to each point $(x_1, x_2);$ this can be visualized as a terrain atop $X^2$ induced by $f$. Consider the transformation $\operatorname{swap} : X^2 \to X^2$ that maps $(x_1, x_2)$ to $(x_2, x_1),$ and the set $\operatorname{swap}(X^2)$ generated by applying $\operatorname{swap}$ to all points in $X^2$. This can be visualized as reflecting $X^2$ along a diagonal. $f$ also induces a structure on $\operatorname{swap}(X^2).$ If the structure of $f$ on $X^2$ is identical to the structure of $f$ on $\operatorname{swap}(X^2),$ then $f$ is a symmetry of $X^2$ under the transformation $\operatorname{swap}$. This occurs exactly when $f(x_1, x_2)=f(x_2, x_1)$ for all $(x_1, x_2)$ pairs, which is the formal definition of commutativity.
%%%

Summary: We can think of commutativity either as an artifact of notation, or as a symmetry in the output of a function (with respect to the ordering of the inputs).


Bag

In mathematics, a "bag" is an unordered list. A bag differs from a [set](https://arbital.com/p/set_mathematics) in that it can contain the same value more than once. A bag differs from a list in that its elements are not ordered. For example, $\operatorname{Bag}(1, 1, 2, 3) = \operatorname{Bag}(2, 1, 3, 1) \neq \operatorname{Bag}(1, 2, 3).$


String (of text)

A string (of text) is a series of letters (often denoted by quote marks), such as `"abcd"` or `"hello"` or `"this is a string"`. For example, the function [concat](https://arbital.com/p/3jv) takes two strings as inputs and puts them together, i.e., `concat("one","two")="onetwo"`.


Domain (of a function)

The domain $\operatorname{dom}(f)$ of a [function](https://arbital.com/p/3jy) $f : X \to Y$ is $X$, the set of valid inputs for that function. For example, the domain of $+$ is the set of all pairs of numbers, and the domain of the division operation is the set of all pairs $(x, y)$ of numbers where $y$ is non-zero.

Visualizing a function as a map that takes every point in an input set to one point in an output set, the domain is the input set (pictured on the left in red in the image below).

![Domain, Codomain, and Image](http://i.imgur.com/ZZgVHaI.png)


concat (function)

The string concatenation function `concat` puts two [strings](https://arbital.com/p/3jr) together, i.e., `concat("one","two")="onetwo"`.


Function

Intuitively, a function $f$  is a procedure (or machine) that takes an input and performs some operations to produce an output. For example, the function "+" takes a pair of numbers as input and produces their sum as output: on input (3, 6) it produces 9 as output, on input (2, 18) it produces 20 as output, and so on.

Formally, in mathematics, a function $f$ is a relationship between a [set](https://arbital.com/p/3jz) $X$ of inputs and a set $Y$ of outputs, which relates each input to exactly one output. For example, $-$ is a function that relates the pair $(4, 3)$ to $1,$ and $(19, 2)$ to $17,$ and so on. In this case, the input set is all possible pairs of [numbers](https://arbital.com/p/number), and the output set is numbers. We write [$f : X \to Y$](https://arbital.com/p/3vl) (and say "$f$ has the [type](https://arbital.com/p/type_mathematics) $X$ to $Y$") to denote that $f$ is some function that relates inputs from the set $X$ to outputs from the set $Y$. For example, $- : (\mathbb N \times \mathbb N) \to \mathbb N,$ which is read "subtraction is a function from [natural number](https://arbital.com/p/natural_number)-pairs to natural numbers."

$X$ is called the [domain](https://arbital.com/p/3js) of $f.$ $Y$ is called the [codomain](https://arbital.com/p/3lg) of $f$. We can visualize a function as a mapping between domain and codomain that takes every element of the domain to exactly one element of the codomain, as in the image below.

![Domain, Codomain, and Image](http://i.imgur.com/ZZgVHaI.png)

[Talk about how they're a pretty dang fundamental concept.](https://arbital.com/p/fixme:)
[Talk about how we can think of functions as mechanisms.](https://arbital.com/p/fixme:)
[Add pages on set theoretic and type theoretic formalizations.](https://arbital.com/p/fixme:)
[Talk about their relationships to programming.](https://arbital.com/p/fixme:)
[Talk about generalizations including partial functions, multifunctions, etc.](https://arbital.com/p/fixme:)
[Give some history, e.g. Church-Turing, Ackerman, recursion, etc. ](https://arbital.com/p/fixme:)

# Examples

There is a function $f : \mathbb{R} \to \mathbb{R}$ from the [real numbers](https://arbital.com/p/real_number) to the real numbers which sends every real number to its square; symbolically, we can write $f(x) = x^2$.

(TODO)

Eric Rogstad
Mark Chimes
Eric Bruylant
Nate Soares
Patrick Stevens


Set

A __set__ is an unordered collection of distinct [objects](https://arbital.com/p/-5xx). The objects in a set are typically referred to as its __elements__. A set is usually denoted by listing all of its elements between braces. For example, $\{1, 3, 2\}$ denotes a set of three numbers, and because sets are unordered, $\{3, 2, 1\}$ denotes the same set. $\{1, 2, 2, 3, 3, 3\}$ does not denote a set, because the elements of a set must be distinct.

Another way to denote sets is the so-called abstraction method, in which the members of a set are given an explicit description, leaving no need for listing them. For example, the set from the example above $\{1, 3, 2\}$ can be described as the set of all natural numbers $x$ which are less than $4$. Formally that is denoted as $\{x \mid (x < 4) \text{ and } (x \text{ is a natural number})\}$.

[I am new to using Latex for editing, so I am not sure if this is the best way to display what's above. Also, "x is a natural number" is the same as x∈N but we did not get to the membership operator yet.](https://arbital.com/p/comment:)

Using the abstraction method allows for denoting sets with infinitely many elements, which would be impossible by listing them all. For example, the set $\{x \mid x = 2n \text{ for some natural } n \}$ is the set of all even numbers.

A set doesn't need to contain things of the same type, nor does it need to contain things that can all be brought to the same place: We could define a set $S$ that contains the apple nearest you, the left shoe which you wore last, the number 17, and London (though it's not clear why you'd want to). Rather, a set is an arbitrary boundary that we draw around some collection of objects, for our own purposes.

The use of sets is that we can manipulate representations of sets and study relationships between sets without concern for the actual objects in the sets. For example, we can say "there are 35 ways to choose three objects from a set of seven objects" regardless of whether the objects in the set are apples, people, or abstract concepts. %%note: This is an example of [abstracting over the objects](https://arbital.com/p/abstract_over_objects).%%

It's also worth noting that a set of elements is itself a single distinct object, different from the things it contains, and in fact, one set can contain other sets among its elements. For example, $\{1,2,\{1,2\}\}$ is a set containing three elements: $1$, $2$ and $\{1,2\}$.

##Examples

 - $\{1,5,8,73\}$ is a set, containing numbers $1$, $5$, $8$ and $73$;
 - $\{\{0,-3,8\}\}$ is a set, containing __one__ element — the set $\{0,-3,8\}$;
 - $\{\text{Mercury}, \text{Venus}, \text{Earth}, \text{Mars} \}$ is a set of four planets;
 - $\{x \mid x \text{ is a human, born on 01.01.2000} \}$ is a set all people whose age is the same as the current year number;
 - $\{\text{author's favorite mug}, \text{Arbital's main page}, 73, \text{the tallest man born in London}\}$ is a set of four seemingly random objects.

## Set membership
*Main page: [Set membership](https://arbital.com/p/set_membership)*

Set membership can be stated using the symbols $∈$ and $∉$. They describe the contents of a set. $∈$ indicates what is in a set.  $∉$ indicates what is **not** in a set. For example, "$x ∈ A$" translated into English is "$x$ is a member of the set $A$." and "$x ∉ A$" translates to "$x$ is **not** in the set $A$."

##Set cardinality
*Main page: [https://arbital.com/p/4w5](https://arbital.com/p/4w5)*

The size of a set is called its __cardinality__. If $A$ is a finite set then the cardinality of $A$, denoted $|A|$, is the number of elements $A$ contains. When $|A| = n$, we say that $A$ is a set of cardinality $n$. There exists a [bijection](https://arbital.com/p/499) from any finite set of cardinality $n$ to the set $\{0, ..., (n-1)\}$ containing the first $n$ natural numbers. We can generalize this idea to infinite sets: we say that two infinite sets have the same cardinality if there exists a bijection between them. Any set in bijective correspondence with [$\mathbb N$](https://arbital.com/p/45h) is called __countably infinite__, while any infinite set that is not in bijective correspondence with $\mathbb N$ is call __uncountably infinite__. All countably infinite sets have the same cardinality, whereas there are multiple distinct uncountably infinite cardinalities.

## See also

* [https://arbital.com/p/5s5](https://arbital.com/p/5s5) - Common [operations](https://arbital.com/p/3jy) in set theory.
* [https://arbital.com/p/sets_examples](https://arbital.com/p/sets_examples) - Examples of significant sets.
* [https://arbital.com/p/2w0](https://arbital.com/p/2w0) - A concrete exercise in comparing the cardinalities of infinite sets

Ilia Zaichuk
Alexei Andreev
Eric Rogstad
Eric Bruylant
Nate Soares
Kevin Clancy
Travis Rivera
Patrick Stevens


Binary function

A binary function $f$ is a [function](https://arbital.com/p/3jy) of two inputs (i.e., a function with [arity](https://arbital.com/p/3h8) 2). For example, $+,$ $-,$ $\times,$ and $\div$ are all binary functions.

Eric Bruylant
Nate Soares
Alexei Andreev


Associativity: Intuition

Associative functions can be interpreted as families of functions that reduce lists down to a single output by combining adjacent elements in any order. Alternatively, associativity can be seen as a generalization of "listyness," which captures and generalizes the "it doesn't matter whether you added [b](https://arbital.com/p/a,) to c or a to [c](https://arbital.com/p/b,), the result is [b, c](https://arbital.com/p/a,) regardless" aspect of lists.

There are many different ways for a function to be associative, so it is difficult to provide a single litmus test for looking at a function and telling whether it associates (aside from just checking the associative axiom directly). However, a few heuristics can be used to make a good guess.

[https://arbital.com/p/toc:](https://arbital.com/p/toc:)

# Associative operators as natural functions on lists

The [generalized associative law](https://arbital.com/p/3ms) says that an [associative](https://arbital.com/p/3h4) [function](https://arbital.com/p/3jy) $f : X \times X \to X$ gives rise to a method for combining any non-empty list of $X$ elements into a single output, where the order in which adjacent elements are combined doesn't affect the result. We can flip that result around, and interpret associative operators as the pairwise versions of a certain class of "natural" functions for combining the elements of a list.

On this interpretation, we start by noting that some methods for reducing a list down to a single element can be broken down into pairwise combinations of adjacent elements, while others can't. For example, when we're trying to compute $3 + 4 + 5 + 6,$ we can pick any two adjacent elements and start by combining those using the binary version of $+$. But when we're trying to compute `adjacent_ones([0, 0, 1, 1, 0](https://arbital.com/p/0,))` to check whether the list has any two adjacent ones, we're going to run into trouble if we only look for adjacent ones in the pairs (0, 0), (0, 1), and (1, 0).

The lists that can be reduced by pairwise combination of adjacent pairs have a nice locality property; the result can be computed only by looking at adjacent elements (without worrying about the global structure). Locality is a common idiom in physics and mathematics, so we might start by asking what sort of functions on lists have this locality property. The answer is "any list that can be broken down into pairwise combinations of elements such that the order doesn't matter." If we formalize that notion, we get the result that any function on lists with this locality property corresponds (in a one-to-one fashion) to an associative operation. Thus, we can view associativity as the mathematical formalization of this nice "locality" property on lists.

Empirically, this locality property turns out to be quite useful for math, physics, and in computer programming, as evidenced by the commonality of associative operators. See, for example, [https://arbital.com/p/3g8](https://arbital.com/p/3g8), or the pages on [semigroups](https://arbital.com/p/algebraic_semigroup) and [monoids](https://arbital.com/p/3h3).

# Associativity as a generalization of "list"

The above interpretation gives primacy to lists, and interprets associative operators in terms of natural functions on lists. We can invert that argument by treating associativity as a _generalization_ of what it means for something to act "list-like."

A list $[b, c, d, \ldots](https://arbital.com/p/a,)$ is a set of elements that have been combined by some "combiner" function, where the order of the elements matters, but the order _in which they were combined_ does not matter. For example, if we combine $a$ with $b$ (forming $[b](https://arbital.com/p/a,)$) and then combine that with $c$, then we get the same list as if we combine $b$ and $c$ into $[c](https://arbital.com/p/b,)$ first, and then combine $a$ with that.

The very fact that we can unambiguously say "the list $[b, c](https://arbital.com/p/a,)$" without worrying about the order that the elements were combined in means that lists are built out of an associative "combination" operator. On this interpretation, associativity is capturing part of the essence of listyness, and associativity _in general_ generalizes this notion. For example, associative operators are allowed to be a little forgetful about what exact elements you combined (e.g., 3 + 4 = 2 + 5) so long as you retain the "it doesn't matter what order you combine the things in" property. In other words, we can view associativity as "part of what it means to be list-like."

(One particularly important property of lists — namely, that they can be empty — is not captured by associativity alone. Associative operators on sets that have an element that acts like an "empty list" are called "monoids." For more on the idea of generalizing the notion of "list", refer to the page on [monoids](https://arbital.com/p/3h3).)

# Associative mechanisms

The above two interpretations give an intuition for what it _means_ that a function is associative. This still leaves open the question of _how_ a function can be associative. Imagine $f : X \times X \to Y$ as a [physical mechanism](https://arbital.com/p/3mb) of wheels and gears. Someone says "$f$ is associative." What does that _mean,_ in terms of the function's physical mechanisms? What should we expect to see when we pop the function open, given the knowledge that it "is associative"?

Recall that associativity says that the two methods for combining two instantiations of the function yield the same output:

![Associative paths](http://i.imgur.com/Ezs1P8l.png)

Thus, the ultimate physical test of associativity is hooking up two instantiations of $f$ as in the left diagram, and then checking whether dragging the mechanisms of the lower-right instantiation above the mechanisms of the upper-left instantiation (thereby reconfiguring the system according to the diagram on the right) causes the behavior of the overall system to change. What happens when the right-hand-side instantiation is given access to the middle input first versus second? Does that affect the behavior at all? If not, $f$ is associative.

This is not always an easy property to check by looking at the mechanisms of $f$ alone, and sometimes functions that appear non-associative (at first glance) turn out to be associative by apparent coincidence. In other words, there are many different ways for a function to be associative, so it is difficult to give a single simple criterion for determining associativity by looking at the internals of the function. However, we can use a few heuristics that help one distinguish associative functions from non-associative ones.

## Heuristic: Can two copies of the function operate in parallel?

$f$ is associative if, when using two copies of $f$ to reduce three inputs to one output, then changing whether the right-hand copy gets access to the middle tape first vs second does not affect the output. One heuristic for checking whether this is the case is to check whether both copies of $f$ can make use of the middle input at the same time, without getting in each other's way. If so, $f$ is likely associative.

For example, consider an implementation of $+$ that gets piles of poker chips as input (where a pile of $n$ chips represents the number $n$) and computes the output by simply sweeping all the poker chips from its input belts onto its output belt. To  make a function that adds three piles of chips together, you could set up two two-pile adders in the configuration of the diagram on the left, but you could also have two two-tape sweepers operating on three tapes in parallel, such that they both sweep the middle tape. This parallelization wouldn't change the output, and thus $+$ is associative.

By contrast, consider a mechanism that takes wooden blocks as input, and glues them together, and nails silver-colored caps on either end of the glued block. For example, if you put in a red block on the left and a blue block on the right, you get a silver-red-blue-silver block in the output. You could set up two copies of these like the diagram on the left, but if you tired to parallelize them, you'd get into trouble — each mechanism would be trying to nail one of its caps into the place that the other mechanism was attempting to apply glue. And indeed, this mechanism is non-associative.

This heuristic is imperfect. Some mechanisms that seem difficult to parallelize are still associative. For example, consider the multiplier mechanism, which takes two poker piles as input and puts a copy of the left pile onto the output tape for every chip in the right pile. It would be difficult to parallelize two copies of this function: One would be trying to count the chips in the middle pile while the other was attempting to copy the chips in the middle pile, and the result might not be pretty. However, multiplication _is_ associative, because a pile of $x$-many copies of a ($y$ copies of $z$)-many poker chips has the same number of chips as a pile of ($x$ copies $y$)-many copies of $z$-many poker chips.

## Heuristic: Does the output interpretation match both input interpretations?

Another (vaguer) heuristic is to ask whether the output of the function should _actually_ be treated as the same sort of thing as the input to the function. For example, recall the `adjacent_ones` function from above, which checks a list for adjacent ones, and returns `1` if it finds some and `0` otherwise. The inputs to `adjacent_ones` are 0 and 1, and the output is 0 or 1, but the output interpretation doesn't quite match the input interpretation: Intuitively, the output is _actually_ intended to mean "yes there were adjacent ones" or "not here weren't adjacent ones", and so applying `adjacent_ones` to the output of `adjacent_ones` is possible but ill-advised. If there is a mismatch between the output interpretation and at least one of the input interpretations, then the function probably isn't associative.

For example, imagine a person who is playing a game that works as follows. The board has three positions: red, green, and blue. The player's objective is to complete as many clockwise red-green-blue cycles as possible, without ever backtracking in the counter-clockwise direction.

![3-cycle board](http://i.imgur.com/bxCnXUs.png)

 Each turn, the game offers them a choice of one of the three spaces, and they get to choose whether or not to travel to that square or stay where they are. Clearly, their preferences depend on where they currently are: If they're on "red", "green" is a good move and "blue" is a bad one; but if they're on "blue" then choosing "green" is ill-advised. We can consider a binary function $f$ which takes their current position on the left and the proposed position on the right, and returns the position that the player prefers. For example, $f(red,blue)=red,$ $f(red,green)=green,$ $f(blue,blue)=blue,$ $f(blue,green=blue).$ In this case, the interpretation of the left input is a "player position," the interpretation of the right input is an "offered move", and the interpretation of the output is the resulting "player position." The output interpretation mismatches one of the input interpretations, which implies that $f$ probably isn't associative, and indeed it is not: $f(f(red, green), blue))=blue,$ whereas $f(red, f(green, blue))=red.$ The former expression can be interpreted as "where the player would be if they started at red, and were then offered green, and were then offered blue." The latter expression doesn't have a great interpretation, because it's feeding the output of $f(green, blue)$ (a player position) in as an "offered move."

If the interpretation of the output (in this case, "player position") mismatches the interpretations of at least one of the inputs, then the function likely isn't associative. However, this heuristic is also imperfect: The most obvious interpretations of the inputs and outputs to the subtraction function are "they're all just numbers," and subtraction still fails to associate.

## Further discussion

There are many different ways for a function to be associative, so it is difficult to give a simple litmus test. The ultimate test is always to imagine using two copies of $f$ to combine three outputs into one, and check whether the result changes depending on whether the left-hand copy of $f$ gets to run first (in which case it gets to access the second input belt at the source) or second (in which case its right-hand input is the right-hand copy's output). For examples of functions that pass or fail this ultimate test, refer to the [examples page](https://arbital.com/p/3mt).


List

A list is an ordered collection of objects, such as `[1, 2, 3](https://arbital.com/p/0,)` or `["blue", 0, "shoe"](https://arbital.com/p/"red",)`. Lists are generally denoted by square brackets, with elements separated by commas. Lists allow repetition (unlike [sets](https://arbital.com/p/3jz)) and are ordered (unlike [bags](https://arbital.com/p/3jk)).

Sometimes lists are typed, in which case they contain only one type of element. For example, `[1, 2, 3](https://arbital.com/p/0,)` is a well-typed list of numbers, whereas the list `["blue", 0, "shoe"](https://arbital.com/p/"red",)` is not well-typed (because it contains both numbers and [strings](https://arbital.com/p/3jr)). The set of all lists of type $X$ is usually denoted $[https://arbital.com/p/X](https://arbital.com/p/X)$ or $X^{\le \omega}$, where $\omega$ is the smallest infinite [limit ordinal](https://arbital.com/p/limit_ordinal). The set of all finite lists of type $X$ is usually denoted $X^{< \omega}$, and the set of all infinite lists of type $X$ is usually denoted $X^{\omega}$.


Codomain (of a function)

The codomain $\operatorname{cod}(f)$ of a [function](https://arbital.com/p/3jy) $f : X \to Y$ is $Y$, the set of possible outputs for the function. For example, the codomain of [concat](https://arbital.com/p/3jv) is the set of all [strings](https://arbital.com/p/3jr), and the codomain of the function $+$ is the set of all numbers.

Visualizing a function as a map that takes every point in an input set to one point in an output set, the codomain is the output set (pictured on the right in blue in the image below).

![Domain, Codomain, and Image](http://i.imgur.com/ZZgVHaI.png)

The codomain of a function is not to be confused with the [image](https://arbital.com/p/3lh) of a function, which is the set of points in $Y$ that can actually be reached by following $f$, and which may not include the whole set $Y$. For example, consider all the functions that take a [real number](https://arbital.com/p/real_number) as input and produce another real number. Many of those functions cannot be made to produce every possible real number: For example, the function $\operatorname{square} : \mathbb R \to \mathbb R$ only produces non-negative numbers. For more on the distinction, see the page on [codomain vs image](https://arbital.com/p/3lv).

[Add a lens talking about how codomains are arbitrary but often natural/useful. Use example like how we can consider $+$ to have codomain $\mathbb N$, $\mathbb Z$, etc., and examples like Ackerman where the codomain "nat" makes by far the most sense ](https://arbital.com/p/fixme:)


Image (of a function)

The image $\operatorname{im}(f)$ of a [function](https://arbital.com/p/3jy) $f : X \to Y$ is the set of all possible outputs of $f$, which is a subset of $Y$. Using [set builder notation](https://arbital.com/p/3lj), $\operatorname{im}(f) = \{f(x) \mid x \in X\}.$

Visualizing a function as a map that takes every point in an input set to one point in an output set, the image is the set of all places where $f$-arrows land (pictured as the yellow subset of $Y$ in the image below).

![Domain, Codomain, and Image](http://i.imgur.com/ZZgVHaI.png)

The image of a function is not to be confused with the [codomain](https://arbital.com/p/3lg), which is the _type_ of output that the function produces. For example, consider the [Ackermann function](https://arbital.com/p/43x), which is a very fast-growing (and difficult to compute) function. When someone asks what sort of thing the Ackermann function produces, the natural answer is not "something from a sparse and hard-to-calculate set of numbers that I can't tell you off the top of my head"; the natural answer is "it outputs a number." In this case, the codomain is "number", while the image is the sparse and hard-to-calculate subset of numbers. For more on this distinction, see the page on [codomain vs image](https://arbital.com/p/3lv).


Set builder notation

$\{ 2n \mid n \in \mathbb N \}$ denotes the set of all even numbers, using set builder notation. Set builder notation involves an expression on the left and a series of constraints on the right, separated by a pipe and placed between curly braces. The expression on the left makes use of variables that are introduced and constrained on the right. The result denotes the set of all possible values on the left-hand side that obey the constraints on the right-hand side. For example, $\{ (x, y) \mid x \in \mathbb R, y \in \mathbb R, x \cdot y = 1 \}$ is the set of all pairs of real numbers whose product is 1.


Range (of a function)

The "range" of a function is an ambiguous term that is generally used to refer to either the function's [codomain](https://arbital.com/p/3lg) or [image](https://arbital.com/p/3lh).


Codomain vs image

A function $f : X \to Y$ with [domain](https://arbital.com/p/3js) $X$ and [codomain](https://arbital.com/p/3lg) $Y$ cannot necessarily produce all values in $Y$. For example, consider the function that takes a [real number](https://arbital.com/p/real_number) and squares it. We could say that this function has codomain $\mathbb R$, because it produces a real number, even though its image is the set of non-negative real numbers.

![Domain, Codomain, and Image](http://i.imgur.com/EHBsE1C.png)

If $f$ maps $X$ to a subset $I$ of $Y$, why not just say that its codomain is $I$ and do away with the distinction between codomain and image? There are at least two cases where the distinction is useful.

1. It is useful to distinguish codomain from image in cases where the _type of thing_ that the function produces is easy to specify, but the _specific values_ are hard to calculate. Consider, for instance, the [Ackermann function](https://arbital.com/p/43x). It definitely produces numbers (i.e. its codomain is $\mathbb N$), but it's not easy to figure out what numbers (exactly) it produces. When talking about what sort of outputs to expect from the Ackermann function, the natural answer is "a number," rather than "either 1 through 7, 9, 11, 13, 29, 61, 125, 65533, $2^{65536} − 3$, or some other ungodly large numbers that I lack the resources to calculate." For this purpose, the codomain can be thought of as a natural/simple boundary drawn around a complex image.

2. Cases where we're considering a set of all functions that map into a certain set. For example, if we're discussing all possible functions from the [natural numbers](https://arbital.com/p/natural_number) to the set $\{0, 1\},$ we want to be able to talk about "functions with codomain $\{0, 1\}$" even if some of those functions are things like "always return 0" (which have an image smaller than $\{0, 1\}$). For this purpose, the codomain can be thought of as a context-dependent tool that's useful when considering (or making use of) a bunch of different functions that are all producing objects of the same type.

Eric Bruylant
Nate Soares
Eric Rogstad
Patrick Stevens

Summary: It is useful to distinguish codomain from image both (a) when the type of thing that the function produces is simple to describe, but the specific objects produced are complicated and hard to identify; and (b) when talking about (or making use of) a collection of functions from a set $X$ to a set $Y$, many of which have an image which is a subset of $Y$.


Function: Physical metaphor

Many functions can be visualized as physical mechanisms of wheels and gears, that take their inputs on conveyor belts, manipulate them (using mechanical sensors and tools), and produce an output which is placed on an outgoing conveyor belt.

![A binary function](http://i.imgur.com/lKxAXcK.png)

For example, we can visualize the function $+$ as a function that takes two stacks of poker chips in as input (one on the left conveyor belt and one on the right conveyor belt) and produces its output by dumping both stacks onto the output belt. We can visualize the function $\times$ as a function that also gets a stack of poker chips on each input belt, and which puts a copy of the left stack onto the output tape for each poker chip in the right stack.

All [computable](https://arbital.com/p/computable_function) functions can (in principle) be implemented by a physical system of wheels and gears (or circuits and wires, etc.), and it is conjectured that the computable functions are the _only_ functions that can be implemented by physical systems. (This conjecture is known as the [Church-Turing thesis](https://arbital.com/p/church_turing_thesis).)


Generalized associative law

Given an [associative](https://arbital.com/p/3h4) [operator](https://arbital.com/p/3h7) $\cdot$ and a [list](https://arbital.com/p/3kd) $[b, c, \ldots](https://arbital.com/p/a,)$ of parameters, all ways of reducing the list to a single element by combining adjacent pairs yield the same result. In other words, while associativity only talks about the behavior of $f$ when combining three elements, this is sufficient to ensure that $f$ has similar good behavior when combining arbitrarily many elements

For example, consider the list $[b, c, d, e](https://arbital.com/p/a,),$ and abbreviate $a \cdot b$ as $ab.$ $((ab)c)(de)$ then denotes the output created by first combining $a$ and $b$, and then combining that with $c$, and then combining $d$ and $e$, and then putting the two results together. $a(b(c(de))$ denotes the result of combining $d$ and $e$ first, and then combining $c$ with that, and then combining $b$ with that, and then combining $a$ with that. The generalized associative law says that all possible orders of reducing the list (by combining adjacent elements) yield the same result, which means we are justified in dropping all parenthesis (and just writing $abcde$ for the result of reducing the list $[b, c, d, e](https://arbital.com/p/a,)$ using $\cdot$), because the order of application does not matter.

Visually, given an associative [function](https://arbital.com/p/3jy) $f$, there are five ways to use three copies of $f$ to combine four inputs into one output:

![Five ways of hooking up three instantiations of f](http://i.imgur.com/OvLsjqr.png)

The generalized associative law says that all five yield the same result. Because all five combinations are equivalent, there is only one function $f_4$ that uses three copies of $f$ to combine four inputs into one output. Similarly, there is only one function $f_5$ that combines five elements into one using four applications of $f,$ and so on.

# Proof sketch

Associativity of $\cdot$ lets us shift parenthesis to the left or right when manipulating expressions that use $\cdot$ multiple times in a row, because associativity says that $(x\cdot y) \cdot z = x \cdot (y \cdot z).$ Abbreviating $x \cdot y$ as $xy,$ we can use this rule to prove the generalized associative law.

Let a "reduction path" of a list $[b, c, d](https://arbital.com/p/a,)$ be an expression of the form $a(b(cd)),$ where the parenthesis tell us explicitly how to use applications of $\cdot$ on adjacent elements to combine the elements of the list into a single output. To prove the generalized associative law for lists of length 4, observe that any reduction path can be turned into any other, by repeatedly shifting the parenthesis left or right. For example:

$a(b(cd))=a((bc)d)=(a(bc))d=((ab)c)d=(ab)(cd).$

In this case, the expression is transformed by shifting the inner parentheses left, then shifting the outer parentheses left, then shifting the inner parentheses left again, then shifting the outer parenthesis right, with each step allowed by associativity. By a similar method (of "walking" the parenthesis all over the reduction path one step at a time), any two reduction paths (of the same list) can be shown equivalent.

# Implications

An associative function $f : X \times X \to X$ gives rise to a single natural function $f_n$ for reducing a list of $n$ inputs to a single output, given any number $n \ge 1$. ($f_1$ is the function that uses zero applications of $f,$ and thus leaves the input untouched.) This means that we can see associative functions not as just binary functions, but as a family of functions for reducing lists to a single output.

Furthermore, whenever we want to use an associative function to reduce a list to a single element, we can do so in a "local" fashion, by repeatedly combining adjacent elements in the list, without worrying about the order in which we do so. This is certainly not true for all functions that reduce a list to a single output! For example, consider the function `adjacent_ones` which takes a list of ones and zeroes and produces a `1` if the list contains any adjacent ones, and a `0` otherwise. `adjacent_ones([https://arbital.com/p/0,0,0,1,1,0](https://arbital.com/p/0,0,0,1,1,0))=1`, but we can't compute this result by just combining adjacent elements pairwise willy-nilly: If we use the order ((00)(01))(10) we get the answer `0`, when the correct answer is `1`.

Associative functions are precisely those that give rise to a family of functions for reducing lists where the result _can_ be computed by just combining adjacent elements pairwise willy-nilly. Thus, associative operators describe list operations that can be computed _locally,_ only ever looking at two adjacent elements, without worrying that some important global structure (such as "are there two ones in a row?") will be destroyed.

This family of functions also has the nice property that if you reduce one list $[b, c, \ldots](https://arbital.com/p/a,)$ to a single element $\alpha,$ and another list $[y, z, \ldots](https://arbital.com/p/x,)$ to a single element $\chi,$ then $f(\alpha, \chi)$ is the same as reducing $[b, c, \ldots, x, y, z, \ldots](https://arbital.com/p/a,):$ in other words, we can reduce two lists separately and then combine the results, and get the same answer as we would have gotten by combining the lists first and then reducing them to a single result.

# What about empty lists?

Any associative function $f$ can be used to reduce a non-empty finite list to a single element, by repeatedly applying $f$ to adjacent elements, without worrying about the order. This works for one-element lists, despite the fact that $f$ takes two parameters, because for one-element lists we can just use zero applications of $f$. But what about zero-element lists?

To create a family $f_n : X^n \to X$ of functions on lists with the nice locality properties discussed above for all $n \ge 0,$ we need some "canonical" element of $0_X$ in $X$ that $f_0$ can return given an empty list, such that $0_X$ "acts like an empty element" with respect to $f.$ [Monoids](https://arbital.com/p/3h3) formalize this notion of "an associative operator plus an element that acts like an empty element," and thus, they capture the idea of a family of functions that can reduce any list (of finite size) to a single output, regardless of what order adjacent elements are combined in.

Summary: Given an [associative](https://arbital.com/p/3h4) [operator](https://arbital.com/p/3h7) $\cdot$ and a [list](https://arbital.com/p/3kd) $[b, c, \ldots](https://arbital.com/p/a,)$ of parameters, all ways of reducing the list to a single element by combining adjacent pairs yield the same result. In other words, while associativity only talks about the behavior of $f$ when combining three elements, this is sufficient to ensure that $f$ has similar good behavior when combining arbitrarily many elements. Thus, we can unambiguously drop parenthesis when using $\cdot$ to combine multiple elements. In other words, an associative function $f : X \times X \to X$ gives rise to a method for combining any non-empty finite list of elements of $X$ into a single output, such that the result can be computed by combining adjacent elements in any order.


Associativity: Examples

[https://arbital.com/p/toc:](https://arbital.com/p/toc:)

## Positive examples

### Addition

$(x + y) + z = x + (y + z)$ for all numbers $x, y,$ and $z.$ Thus, addition associates. One easy way to see this fact is to consider a [physical system](https://arbital.com/p/3mb) that implements addition, e.g., by taking two piles of poker chips (where a poker chip with $n$ chips represents the number $n$) in on two input belts, and producing a pile of poker chips on the output belt. This function can be implemented by simply shoving both input piles onto the output pile. Clearly, when combining three piles, it doesn't matter which piles get shoved onto the output tape in which order, so addition is associative.

### Multiplication

$(x \times y) \times z = x \times (y \times z)$ for all numbers $x, y,$ and $z.$ Thus, multiplication associates. It is, however, a little harder to see why this must be the case for multiplication.

Imagine a physical system implementing multiplication, by taking stacks of poker chips as input (where stacks with $n$ chips in them represents the number $n$), and producing an output by putting a copy of the left stack on the output tape for every chip in the right stack. Imagine using this function to combine three stacks of poker chips, a blue stack (representing $x$), a yellow stack (representing $y$), and a red stack (representing $z$). We can either calculate $(x \times y) \times z$ or $x \times (y \times z).$ In both cases, the result will be a bunch of copies of the original blue $x$ stack. The question is, how many copies will there be in each case?

In the first case, the machine first puts $y$ copies of the blue stack in a line, and then makes $z$ copies of that line. In the second case, the machine first makes $z$ copies of the yellow stack. Each of those yellow stacks corresponds to one of the lines from the first case, and each yellow chip on each yellow stack corresponds to one of the blue stacks in the first case. A blue stack is placed on the output in the second case for each of those yellow chips, so the number of blue stacks in each case is the same.

### Concatenation

The concatenation of [strings](https://arbital.com/p/3jr) is another associative function: `concat("a",concat("b","c")) = concat(concat("a","b"),"c") = "abc"`.

Concatenation is an example of an associative function that is not [commutative](https://arbital.com/p/3jb): When reducing a list of strings to a single string, it doesn't matter what order you combine adjacent elements in, but it _does_ matter that you leave the elements in their original order.

In fact, any function that just sticks its inputs together (possibly with some extra stuff in the middle) is associative: A function which takes wooden blocks as input, and glues them together (with a small white block in the middle) is associative, because if you put in blue, yellow, and red blocks then you get a blue-white-yellow-white-red block out the end, regardless of the order you combine adjacent blocks in.

## Negative examples

### Functions with a history

The function `xconcat` that concatenates its inputs and puts an "x" on the front: `xconcat("A", xconcat("B","C")) = "xAxBC"`, but `xconcat(xconcat("A", "B"), "C") = "xxABC"`. The problem in this case is that the output carries a trace of which adjacent elements were combined in which order, which makes the function non-associative.

In fact, any function that carries a history of the application order with it can't be associative. Thus, if the inputs carry history about which inputs were combined with which other inputs, and the output preserves (and adds to) that history, the function can't be associative. Associativity is, fundamentally, about the output not depending on which path was taken to get to it.

### Subtraction

Subtraction does not associate, as $(5-3)-2=0$ but $5-(3-2)=4.$ To see what went wrong, first notice that all inputs contribute either positively or negatively to the result. Label all inputs (in their original positive states) with up-arrows; we will track whether that input has a positive or negative impact on the final output. Subtraction flips its right-hand input upside down before combining it with its left-hand input, so given inputs labeled $\uparrow$ and $\uparrow$ we should label its output $\uparrow\downarrow.$ When combining three inputs, we can either combine the left two first or the right two first. If we combine the left two first, then the second subtraction is run on inputs labeled $\uparrow\downarrow$ and $\uparrow,$ and produces an output $\uparrow\downarrow\downarrow,$ in which the first input contributes positively and the other inputs contribute negatively. But if we combine the right two inputs first, then the second subtraction is run on inputs labeled $\uparrow$ and $\uparrow\downarrow,$ and produces an output $\uparrow\downarrow\uparrow,$ in which the first and third inputs contribute positively and the second contributes negatively. Thus, the contribution of the third input depends on which adjacent elements are combined in which order, so subtraction does not associate.

### Cyclical preferences

Consider a person who is playing a game that works as follows. The board has three positions: red, green, and blue. The player's objective is to complete as many clockwise red-green-blue cycles as possible, without ever backtracking in the counter-clockwise direction.

![3-cycle board](http://i.imgur.com/bxCnXUs.png)

 Each turn, the game offers them a choice of one of the three spaces, and they get to choose whether or not to travel to that square or stay where they are. Clearly, their preferences depend on where they currently are: If they're on "red", "green" is a good move and "blue" is a bad one; but if they're on "blue" then choosing "green" is ill-advised.

We can consider a binary operation $?$ which takes their current position on the left and the proposed position on the right, and returns the position that the player prefers. Specifically:

\begin{align}
& red \ ?\  red \ &= red\\
& red \ ?\  green \ &= green\\
& red \ ?\  blue \ &= red\\
\end{align}
\begin{align}
& green \ ?\  red \ &= green\\
& green \ ?\  green \ &= green\\
& green \ ?\  blue \ &= blue\\
\end{align}
\begin{align}
& blue \ ?\  red \ &= red\\
& blue \ ?\  green \ &= blue\\
& blue \ ?\  blue \ &= blue
\end{align}

This function does not associate, because $(red\ ?\ green)\ ?\ blue = blue$ but $red\ ?\ (green\ ?\ blue)=red.$ To show that a function is not associative, it is sufficient to simply do out the whole function table and then find any one case that violates the axiom of associativity, as above.

Summary: Yes: [https://arbital.com/p/Addition](https://arbital.com/p/Addition), [https://arbital.com/p/multiplication](https://arbital.com/p/multiplication), [string concatenation](https://arbital.com/p/3jv). No: [https://arbital.com/p/subtraction](https://arbital.com/p/subtraction), [https://arbital.com/p/division](https://arbital.com/p/division), a [https://arbital.com/p/-3jy](https://arbital.com/p/-3jy) that concatenates strings and then puts an "x" on the front.


Commutativity: Examples

## Positive examples

### Addition

$x+y = y+x$ for all numbers $x$ and $y,$ so addition commutes. One easy way to see this fact is to consider a physical system that implements addition, e.g., by taking two piles of poker chips (where a poker chip with nn chips represents the number nn) in on two input belts, and producing a pile of poker chips on the output belt. This function can be implemented by simply shoving both input piles onto the output pile. Because a pile of chips represents the same number regardless of how those chips are arranged on the output belt, it doesn't matter which pile comes in on which input belt, so addition is commutative.

### Multiplication

$x \times y = y \times x$ for all numbers $x$ and $y,$ so multiplication also commutes. It is a bit harder to see why this must be so in the case of multiplication, as $x \times y$ can be interpreted as "take the $x$ input and stretch it out according to the $y$ input," and it's not entirely obvious that "stretching the $x$ input according to $y$" should yield the same result as "stretching the $y$ input according to $x.$"

To see that multiplication commutes, it is helpful to visualize _copying_ $x$ (rather than stretching it out) into $y$ many rows. This allows us to visualize $x \times y$ as a square divided into $x$ parts along one side and $y$ parts along the other side, which makes it clearer that multiplication commutes.

![Multiplicaiton commutes](http://i.imgur.com/Q3QBUT6.png)

It is worth noting that the concept of "multiplication" generalizes beyond the concept of "numbers," and in those contexts, "stretching $x$ out according to $y$" and "stretching $y$ out according to $x$" might be quite different operations. For example, [multiplication of matrices](https://arbital.com/p/matrix_multiplication) does not commute.

### Maximum and minimum

The [max](https://arbital.com/p/maximum_function) and [min](https://arbital.com/p/minimum_function) functions commute, because "which of these elements is largest/smallest?" is a question that doesn't depend upon the order that the elements are presented in.

### Rock, Paper, Scissors

The question of who won in a game of [rock-paper-scissors](https://arbital.com/p/rock_paper_scissors) is commutative. Writing $r$ for rock, $p$ for paper, $s$ for scissors, and $?$ for the binary operator saying who won, we have $r ? p = p,$ $r ? s = r,$ and $p ? s = s,$ and so on. This function is commutative: who won a game of rock-paper-scissors does not depend upon which side of the judge they were standing on.

This provides an example of a commutative function that is not [associative](https://arbital.com/p/3h4): $r?p=p?r$ and so on, but $(r?p)?s=s$ while $r?(p?s)=r.$ In other words, who won a game of rock-paper-scissors does not depend on which side of the judge they were standing on, but if you have a line of people throw "rock," "paper," or "scissors," then the question "who won?" _does_ depend on which end of the line you start from.

## Negative examples

### Concatenation

Any function that includes its inputs in its outputs _in order_ is not commutative. For example, the function `pair` which puts its inputs into a pair (such that `pair(x, y) = (x, y)`) is not commutative. The function [concat](https://arbital.com/p/3jv), which also sticks its inputs together in order, is also not commutative, though it is associative.

### Division

Division is not commutative, because $x / y$ does not equal $y / x$ in general. In this case, the function is using $x$ and $y$ in a very different way. One is interpreted as a numerator that will be cut up, the other is treated as a denominator that says how many times to cut the numerator up. Numerator and denominator are not exchangeable concepts: Division needs to know which input is intended to be the numerator and which is intended to be the denominator.

### Matrix multiplication

[Matrix multiplication](https://arbital.com/p/matrix_multiplication) is not only non-commutative, it may fail to even make sense. Two [matrices](https://arbital.com/p/linear_algebra_matrix) can be multiplied if and only if the number of columns in the left-hand matrix is equal to the number of rows in the right-hand matrix. Thus, a $2 \times 3$ matrix can be multiplied with a $3 \times 5$ matrix if and only if the $2 \times 3$ matrix is on the left. Clearly, then, matrix multiplication does not commute.

Summary: Yes: addition, multiplication, maximum, minimum, rock-paper-scissors. No: subtraction, division, string concatenation, matrix multiplication.


Associativity vs commutativity

[Associativity](https://arbital.com/p/3h4) and [commutativity](https://arbital.com/p/3jb) are often confused, because they are both constraints on how a [function](https://arbital.com/p/3jy) treats its inputs, and they are both constraints saying "these two paths for calculating the output must yield the same answer." The difference is that commutativity says "this function shouldn't care what order its own arguments come in," while associativity says "different ways of using this function multiple times should yield the same results."

Commutativity is about an invariance in _one_ call to the function: If you run the function once with inputs $x$ and $y,$ you'll get the same result as if you run it once with inputs $y$ and $x.$

Associativity is about an invariance in _multiple_ calls to the function: If you combine four elements using three function calls in the order $a \cdot (b \cdot (c \cdot d)),$ you'll get the same answer as if you use the three function calls in the order $((a \cdot b) \cdot c) \cdot d.$

Commutativity means you can swap the order of the elements. Associativity means you can drop parenthesis when combining multiple elements in a row.

If an operator $\cdot$ is both commutative and associative, then when you're combining multiple elements in a row, you're welcome to combine them in _any_ order: For example, when adding $3 + 2 + (-7) + 5 + (-2) + (-3) + 7,$ we can re-arrange the list to get $3 - 3 + 2 - 2 + 7 - 7 + 5 = 5,$ which makes calculation easy. To see that this is the case, note that the result won't change if we swap any two adjacent elements, because associativity means that we can pick any two adjacent elements to start with and commutativity says that the order of those elements doesn't matter. Then, we can re-arrange the list however we like using a series of two-element swaps.
[Perhaps conditionalize this parenthetical on something like "cares about abstract algebra" or "wants tidbits they don't understand to point them towards cool things" or something.](https://arbital.com/p/fixme:)
(This is why [commutative groups](https://arbital.com/p/3h2) are especially easy to work with.)

## Examples

Addition is both commutative and associative (same with multiplication). Subtraction is neither commutative nor associative (same with division).

[String concatenation](https://arbital.com/p/3jv) is associative but not commutative: If you're sticking a bunch of [strings](https://arbital.com/p/3jr) together end on end, then it doesn't matter which adjacent pairs you combine first, but `"onetwo"` is a very different string than `"twoone"`.

Rock-paper-scissors is commutative but not associative. The winner of "rock v scissors" is rock, and the winner of "scissors v rock" is rock, and so on; but if you have a bunch of people in a line make rock, paper, or scissors signs, then who is the winer depends on which end of the line you start from: If the line has three people, and they throw [paper, scissors](https://arbital.com/p/rock,), then the winner will be whoever threw scissors if you start from the left (by finding the winner between rock and paper,  and then playing that against scissors) or rock if you start on the right (by finding the winner between paper and scissors, and then playing that against rock).

The function `pair` which puts its inputs into a pair (such that `pair(x, y) = (x, y)`) is neither commutative nor associative: `(x, y)` does not equal `(y, x)`, and `(x, (y, z))` does not equal `((x, y), z)`. The output of `pair` preserves the ordering and structure of all its inputs, and leaves a trace that allows one to distinguish which inputs it was called on when. Both commutativity and associativity require the function to be "forgetful" about some aspect of how it was called: Commutative functions need to be insensitive to the ordering of their arguments; associative functions need to leave no trace that can be used to figure out which inputs were combined in what order. Thus, any function that bakes a lot of history about what it was called with into the output is unlikely to be commutative or associative.

## Mnemonics

If it helps you to remember which is which, consider these two mnemonics:

For "commutativity," imagine that the two parameters to the function each live on one side of town and work on the other side. Each morning, they pass each other on their morning _commute,_ as they swap places.

For "associativity," imagine a bunch of _associates_ all standing in a line, ranked according to their hierarchy in a law firm. Any two adjacent people are willing to converse with each other, although people on one end of the line might not be willing to associate with people on the other end.


Eigenvalues and eigenvectors

Consider a linear transformation represented by a matrix $A$, and some vector $v$. If $Av = \lambda v$, we say that $v$ is an _eigenvector_ of $A$ with corresponding eigenvalue $\lambda$. Intuitively, this means that $A$ doesn't rotate or change the direction of $v$; it can only stretch it ($|\lambda| > 1$) or squash it ($|\lambda| < 1$) and maybe flip it ($\lambda < 0$). While this notion may initially seem obscure, it turns out to have many useful applications, and many fundamental properties of a linear transformation can be characterized by its eigenvalues and eigenvectors.

Zack M. Davis
Alexei Andreev
Qiaochu Yuan
Eric Rogstad
Eric Bruylant
Nate Soares
Ryan Neufeld


Logarithm

summary(Technical): $\log_b(n)$ is defined to be the number $x$ such that $b^x = n.$ Thus, logarithm functions satisfy the following properties, among others:

- $\log_b(1) = 0$
- $\log_b(b) = 1$
- $\log_b(x\cdot y) = log_b(x) + \log_b(y)$
- $\log_b(\frac{x}{y}) = \log_b(x) - \log_b(y)$
- $\log_b(x^n) = n\log_b(x)$
- $\log_b(\sqrt[https://arbital.com/p/n](https://arbital.com/p/n){x}) = \frac{\log_b(x)}{n}$
- $\log_b(n) = \frac{\log_a(n)}{\log_a(b)}$

summary(Inverse exponentials): Logarithms are the inverse of [exponentials](https://arbital.com/p/exponential). That is, for any base $b$ and number $n,$ $\log_b(b^n) = n$ and $b^{\log_b(n)} = n.$

summary(Measure of data): A message that singles out one thing from a set of $n$ carries $\log(n)$ units of data, where the unit of information depends on the base of the logarithm. For example, a message singling out one thing from 1024 carries about three [decits](https://arbital.com/p/3wn) of data (because $\log_{10}(1024) \approx 3$), or exactly ten [bits](https://arbital.com/p/3p0) of data (because $\log_2(1024)=10$). For details, see [https://arbital.com/p/+3p0](https://arbital.com/p/+3p0).

summary(Generalized lengths):  A quick way of approximating the logarithm base 10 is to look at the length of a number: 103 is a 3-digit number but it's _almost_ a 2-digit number, so its logarithm (base ten) is a little higher than 2 (it's about 2.01). 981 is also a three-digit number, and it's using nearly all three of those digits, so its logarithm (base ten) is just barely lower than 3 (it's about 2.99). In this way, logarithms generalize the notion of "length," and in particular, $\log_b(n)$ measures the generalized length of the number $n$ when it's written in $b$-ary notation.

The logarithm base $b$ of a number $n,$ written $\log_b(n),$ is the answer to the question "how many times do you have to multiply 1 by $b$ to get $n$?" For example, $\log_{10}(100)=2,$ and $\log_{10}(316) \approx 2.5,$ because $316 \approx$ $10 \cdot 10 \cdot \sqrt{10},$ and [multiplying by $\sqrt{10}$ corresponds to multiplying by 10 "half a time"](https://arbital.com/p/).

In other words, $\log_b(x)$ counts the number of $b$-factors in $x$. For example, $\log_2(100)$ counts the number of "doublings" in the number 100, and $6 < \log_2(100) < 7$ because scaling an object up by a factor of 100 requires more than 6 (but less than 7) doublings. For an introduction to logarithms, see the [Arbital logarithm tutorial](https://arbital.com/p/3wj). For an advanced introduction, see the [advanced logarithm tutorial](https://arbital.com/p/advanced_log_tutorial).

Formally, $\log_b(n)$ is defined to be the number $x$ such that $b^x = n,$ where $b$ and $n$ are numbers. $b$ is called the "base" of the logarithm, and has a relationship to the [base of a number system](https://arbital.com/p/number_base). For a discussion of common and useful bases for logarithms, see the page on [logarithm bases](https://arbital.com/p/logarithm_bases). $x$ is unique if by "number" we mean [$\mathbb R$](https://arbital.com/p/4bc), but may not be unique if by "number" we mean [$\mathbb C$](https://arbital.com/p/complex_number). For details, see the page on [complex logarithms](https://arbital.com/p/complex_logarithm).

# Basic properties

Logarithms satisfy a number of desirable properties, including:

- $\log_b(1) = 0$ for any $b$
- $\log_b(b) = 1$ for any $b$
- $\log_b(x\cdot y) = log_b(x) + \log_b(y)$
- $\log_b(x^n) = n\log_b(x)$
- $\log_a(n) = \frac{\log_b(n)}{\log_b(a)}$

For an expanded list of properties, explanations of what they mean, and the reasons for why they hold, see [https://arbital.com/p/+3wp](https://arbital.com/p/+3wp).

# Interpretations

- Logarithms can be interpreted as a generalization of the notion of the [length of a number](https://arbital.com/p/number_length): 103 and 981 are both three digits long, but, intuitively, 103 is only barely using three digits, whereas 981 is pushing its three digits to the limit. Logarithms quantify this intuition: the [common logarithm](https://arbital.com/p/common_logarithm) of 103 is approximately 2.01, and the common log of 981 is approximately 2.99. Logarithms give rise to a notion of exactly how many digits a number is "actually" making use of, and give us a notion of "fractional digits." For more on this interpretation (and why it is 316, not 500, that is two and a half digits long), see [https://arbital.com/p/+416](https://arbital.com/p/+416).

- Logarithms can be interpreted as a measure of how much data it takes to carry a message. Imagine that you and I are both facing a collection of 100 different objects, and I'm thinking of one of them in particular. If I want to tell you which one I'm thinking of, how many digits do I need to transmit to you? The answer is $\log_{10}(100)=2,$ assuming that by "digit" we mean "some method of encoding one of the symbols 0-9 in a physical medium." Measuring data in this way is the cornerstone of [information theory](https://arbital.com/p/3qq).

- Logarithms are the inverse of exponentials. The function $\log_b(\cdot)$ inverts the function $b^{\ \cdot}.$ In other words, $\log_b(n) = x$ implies that $b^x = n,$ so $\log_b(b^x)=x$ and $b^{\log_b(n)}=n.$ Thus, logarithms give us tools for analyzing anything that grows exponentially. If a population of bacteria doubles each day, then logarithms measure days in terms of bacteria — that is, they can tell you how long it will take for the population to reach a certain size. For more on this idea, see [https://arbital.com/p/+3wr](https://arbital.com/p/+3wr).

# Applications

Logarithms are ubiquitous in many fields, including mathematics, physics, computer science, cognitive science, and artificial intelligence, to name a few. For example:

- In mathematics, the most natural logarithmic base is [$e$](https://arbital.com/p/mathematics_e) ([Why?](https://arbital.com/p/log_e_is_natural)) and the log base $e$ of $x$ is written $\ln(x)$, pronounced "[natural log](https://arbital.com/p/natural_logarithm) of x." The natural logarithm of a number gives one notion of the "intrinsic length" of a number, a concept that proves useful when reasoning about other properties of that number. For example, the quantity of prime numbers smaller than $x$ is approximately $\frac{x}{\ln(x)},$ this is the [prime number theorem](https://arbital.com/p/prime_number_theorem).

- Logarithms also give us tools for measuring the runtime (or memory usage) of algorithms. When an algorithm uses a [divide and conquer](https://arbital.com/p/divide_and_conquer) approach, the amount of time (or memory) used by the algorithm increases logarithmically as the input size grows linearly. For example, the amount of time that it takes to perform a [binary search](https://arbital.com/p/binary_search) through $n$ possibilities is $\log_2(n),$ which means that the search takes one unit longer to run every time the set of things to search through doubles in size.

- Logarithms give us tools for studying the tools we use to represent numbers. For example, humans tend to use ten different symbols to represent numbers (0, 1, 2, 3, 4, 5, 6, 7, 8, and 9), while computers tend to use two digits (0 and 1). Are some representations better or worse than others? What are the pros and cons of using more or fewer symbols? For more on these questions, see [Number bases](https://arbital.com/p/number_base).

- The human brain encodes various perceptions logarithmically. For example, the perceived tone of a sound goes up by one octave every time the frequency of air vibrations doubles. Your perception of tone is proportional to the logarithm (base 2) of the frequency at which the air is vibrating. See also [Hick's law](https://arbital.com/p/https://en.wikipedia.org/wiki/Hick%27s_law).

Summary: The logarithm base $b$ of a number $n,$ written $\log_b(n),$ is the answer to the question "how many times do you have to multiply 1 by $b$ to get $n$?" For example, $\log_{10}(1000)=3,$ because $10 \cdot 10 \cdot 10 = 1000,$ and $\log_2(16)=4$ because $2 \cdot 2 \cdot 2 \cdot 2 = 16.$


Relation

%%comment:
I do not want to be shortened. The motivation for this is that I would prefer that someone has the ability to learn everything they need to know about relations just by reading the popup summary.
%%

summary: A **relation** is a [set](https://arbital.com/p/3jz) of [tuples](https://arbital.com/p/tuple_mathematics), all of which have the same [arity](https://arbital.com/p/tuple_arity). The inclusion of a tuple in a relation indicates that the components of the tuple are related. A set of $n$-tuples is called an $n$*-ary relation*. Sets of pairs are called binary relations, sets of triples are called ternary relations, etc.

Examples of binary relations include the equality relation on natural numbers $\{ (0,0), (1,1), (2,2), ... \}$ and the predecessor relation $\{ (0,1), (1,2), (2,3), ... \}$. When a symbol is used to denote a specific binary relation ($R$ is commonly used for this purpose),  that symbol can be used with infix notation to denote set membership: $xRy$ means that the pair $(x,y)$ is an element of the set $R$.

A **relation** is a [set](https://arbital.com/p/3jz) of [tuples](https://arbital.com/p/tuple_mathematics), all of which have the same [arity](https://arbital.com/p/tuple_arity). The inclusion of a tuple in a relation indicates that the components of the tuple are related. A set of $n$-tuples is called an $n$*-ary relation*. Sets of pairs are called binary relations, sets of triples are called ternary relations, etc.

Examples of binary relations include the equality relation on natural numbers $\{ (0,0), (1,1), (2,2), ... \}$ and the predecessor relation $\{ (0,1), (1,2), (2,3), ... \}$. When a symbol is used to denote a specific binary relation ($R$ is commonly used for this purpose),  that symbol can be used with infix notation to denote set membership: $xRy$ means that the pair $(x,y)$ is an element of the set $R$.

Alexei Andreev
Eric Bruylant
Nate Soares
Kevin Clancy
Dylan Hendrickson
Joe Zeng


Bit (of data)

A bit of data (not to be confused with a [https://arbital.com/p/shannon](https://arbital.com/p/shannon), an [abstract bit](https://arbital.com/p/3y3), or a [bit of evidence](https://arbital.com/p/evidence_bit)) is the amount of data required to single out one message from a set of two. If you want to single out one of the hands of one of your biological grandparents (such as the left hand of your paternal grandmother), you can do that with three bits of data: One to single out "left hand" or "right hand", one to single out "maternal" or "paternal", and one to single out "grandfather" or "grandmother". In order for someone to look at the data and know which hand you singled out, they need to know what method you used to [encode](https://arbital.com/p/encoding) the message into the data.

Data can be stored in physical systems which can be put into multiple states: A coin can be used to store a single bit of data (by placing it either heads or tails); a normal six-sided die can be used to store a little over [2.5 bits](https://arbital.com/p/3ty) of data. In general, a message that singles out one thing from a set of $n$ is defined to contain [$\log_2](https://arbital.com/p/3nd) bits of data.

"Bit" is a portmanteau of "binary digit": "binary" because it is the amount of information required to single out one message from a set of 2. The 2 is arbitrary; analogous units of data exist for every other number. For example, a [https://arbital.com/p/3ww](https://arbital.com/p/3ww) is the amount of data required to single out one message from a set of three, a [https://arbital.com/p/3wn](https://arbital.com/p/3wn) is the amount of data it takes to single out one message from a set of ten, and so on. It is easy to convert between units, for example, a decit is $\log_2(10) \approx 3.32$ bits, because it takes a little over three bits to pick one thing out from a set of 10. See also the pages on [converting between units of data](https://arbital.com/p/) and [fractional bits](https://arbital.com/p/3ty).

[Talk about how we want to define data such that two objects hold twice as much.](https://arbital.com/p/fixme:)

The amount of data you can transmit (or store) grows [exponentially](https://arbital.com/p/exponential) in the number of bits at your disposal. For example, consider a punch card that can hold ten bits of data. You can use one punch card to pick out a single thing from a set of $2^{10}=1024.$ From two punch cards you can pick out a single thing from a set of $2^{20}=1048576.$ The number of _things you can distinguish_ using two punch cards is 1024 times larger than the number of things you can distinguish with one punch card, and the amount of data you can encode using two punch cards is precisely twice as much (20 bits) as the amount of information you can encode using one punch card (10 bits). In other words, you can single out one object from a collection of $n$ (or store a number between 1 and $n$) using [$\log_2](https://arbital.com/p/3nd) bits of data. For more on why the amount of data is logarithmic in the number of possible messages, see [Data is logarithmic](https://arbital.com/p/).

[Add a formalization section.](https://arbital.com/p/fixme:)

Summary: A bit of data is the amount of data required to single out one message from a set of two. Equivalently, it is the amount of data required to cut the set of possible messages in half. If you want to single out one of the hands of one of your biological grandparents (such as the left hand of your paternal grandmother), you can do that by transmitting three bits of data: One to single out "left hand" or "right hand", one to single out "maternal" or "paternal", and one to single out "grandfather" or "grandmother". We can also speak of storing data in physical systems which can be put into multiple states: A coin can be used to store a single bit of data (by placing it either heads or tails); a normal six-sided die can be used to store a little over [2.5 bits](https://arbital.com/p/3ty) of data. In general, a message that singles out one message from a set of $n$ is defined to contain [$\log_2](https://arbital.com/p/3nd) bits of data.


Information theory

The study (and quantificaiton) of information, and its communication and storage.

Eric Bruylant
Eliezer Yudkowsky
Nate Soares
jorgejuan lafuente