Kripke model

**Kripke models** are [interpretations](https://arbital.com/p/) of [https://arbital.com/p/-534](https://arbital.com/p/-534) which turn out to be adequate under some basic constraints for a wide array of systems of modal logic.

#Definition
A Kripke model $M$ is formed by three elements:

* A set of **worlds** $W$
* A **visibility relationship** between worlds $R$. If $wRx$, we will say that $w$ sees $x$ or that $x$ is a successor of $w$.
* A **valuation function** $V$ that associates pairs of worlds and sentence letters to truth values.

You can visualize Kripke worlds as a [https://arbital.com/p/-digraph](https://arbital.com/p/-digraph) in which each node is a world, and the edges represent visibility.

The valuation function can be extended to assign truth values to whole modal sentences. We will say that a world $w\in W$ makes a modal sentence $A$ true (*notation*: $M,w\models A$) if it is assigned a truth value of true according to the following rules:

* If $A$ is a sentence letter $p$, then $M,w\models p$ if $V(w,p)=\top$.
* If $A$ is a truth functional compound of sentences, then its value comes from the propositional calculus and the values of its components. For example, if $A=B\to C$, then $M,w\models A$ [https://arbital.com/p/-46m](https://arbital.com/p/-46m) $M,w\not\models B$ or $M,w\models C$.
* If $A$ is of the form $\square B$, then $M,w\models \square B$ if $M,x\models B$ for every successor $x$ of $w$.

Given this way of assigning truth values to sentences, we will say the following:

* $A$ is valid in a model $M$ (*notation*: $M\models A$) if $M,w\models A$ for every $w$ in $W$.
* $A$ is valid in a class of models if it is valid in every model of the class.
* $A$ is satisfiable in a model $M$ if there exists $w\in W$ such that $M,w\models A$.
* $A$ is satisfiable in a class of models if it is satisfiable in some model of the class.

Notice that a sentence $A$ is valid in a class of models iff its negation is not satisfiable.

#Kripke models as semantics of modal logic
Kripke models are tightly connected to the interpretations of certain modal logics.

For example, they model well the rules of [normal provability systems](https://arbital.com/p/5j8).

**Exercise**: show that Kripke models satisfy the necessitation rule of modal logic. That is, if $A$ is valid in $M$, then $\square A$ is valid in $M$.

%%hidden(Show solution):
Let $w\inW$ be a world of $M$. Let $x$ be an arbitrary successor of $w$. Then, as $M\models A$, then $M,x\models A$. Since $x$ was arbitrary, every successor of $w$ models $A$, so $w\models \square A$. As $w$ was arbitrary, then every world in $M$ models $\square A$, and thus $M\models \square A$.
%%

**Exercise**: Show that the distributive axioms are always valid in Kripke models. Distributive axioms are modal sentences of the form $\square[B](https://arbital.com/p/A\to)\to(\square A \to \square B)$.

%%hidden(Show solution):
Suppose that $w\in W$ is such that $w\models \square[B](https://arbital.com/p/A\to)$ and $w\models \square A$.

Let $x$ be a successor of $w$. Then $x\models A\to B$ and $x\models A$. We conclude by the propositional calculus that $x\models B$, so as $x$ was an arbitrary successor we have that $w\models \square B$, and thus $w\models\square[B](https://arbital.com/p/A\to)\to(\square A \to \square B)$.

We conclude that $M\models\square[B](https://arbital.com/p/A\to)\to(\square A \to \square B)$, no matter what $M$ is.
%%

Those two last exercises prove that the [K system](https://arbital.com/p/) of modal logic is [sound](https://arbital.com/p/soundness) for the class of all Kripke models. This is because we have proved that its axioms and rules of inference hold in all Kripke models (propositional tautologies and modus ponens trivially hold).

##Some adequacy theorems
Now we present a relation of modal logics and the class of Kripke models in which they are [adequate](https://arbital.com/p/adequacy). You can check the proofs of adequacy in their respective pages.

* The class of *all* Kripke models is adequate to the [K system](https://arbital.com/p/)
* The class of [transitive](https://arbital.com/p/573) Kripke models is adequate to [K4](https://arbital.com/p/)
* The class of [reflexive](https://arbital.com/p/) Kripke models is adequate to [T](https://arbital.com/p/)
* The class of [reflexive](https://arbital.com/p/) and [transitive](https://arbital.com/p/573) Kripke models is adequate to [S4](https://arbital.com/p/)
* The class of [reflexive](https://arbital.com/p/) and [symmetric](https://arbital.com/p/) Kripke models is adequate to [B](https://arbital.com/p/)
* The class of [reflexive](https://arbital.com/p/) and [euclidean](https://arbital.com/p/) Kripke models is adequate to [S5](https://arbital.com/p/)
* The class of [finite](https://arbital.com/p/), [irreflexive](https://arbital.com/p/) and [transitive](https://arbital.com/p/573) Kripke models is adequate to [GL](https://arbital.com/p/5l3)

Notice that as the constraint on the models becomes stronger, the set of valid sentences increases, and thus the correspondent adequate system is stronger.

A note about notation may be in order. We say that a Kripke model is, e.g, [transitive](https://arbital.com/p/573) if its visibility relation is transitive %%note:Same for reflexive, symmetric and euclidean %%. Similarly, a Kripke model is finite if its set of worlds is finite.


Antisymmetric relation

An antisymmetric relation is a relation where no two distinct elements are related in both directions. In other words. $R$ is antisymmetric iff

$(aRb ∧ bRa) → a = b$

or, equivalently, $a ≠ b → (¬aRb ∨ ¬bRa)$

Antisymmetry isn't quite the [compliment](https://arbital.com/p/set_theory_compliment) of [Symmetry](https://arbital.com/p/symmetric_relation). Due to the fact that $aRa$ is allowed in an antisymmetric relation, the equivalence relation, $\{(0,0), (1,1), (2,2)...\}$ is both symmetric and antisymmetric.

Examples of antisymmetric relations also include the successor relation, $\{(0,1), (1,2), (2,3), (3,4)...\}$, or this relation linking numbers to their prime factors $\{...(9,3),(10,5),(10,2),(14,7),(14,2)...)\}$


Fixed point theorem of provability logic

The fixed point theorem of provability logic is a key result that gives a explicit procedure to find equivalences for sentences such as the ones produced by the [https://arbital.com/p/-59c](https://arbital.com/p/-59c).

In its most simple formulation, it states that:

>Let $\phi(p)$ be a modal sentence [modalized](https://arbital.com/p/5m4) in $p$. Then there exists a letterless $H$ such that $GL\vdash \boxdot[\phi](https://arbital.com/p/p\leftrightarrow) \leftrightarrow \boxdot[H](https://arbital.com/p/p\leftrightarrow)$ %%note: Notation: $\boxdot A = A\wedge \square A$%%.

This result can be generalized for cases in which letter sentences other than $p$ appear in the original formula, and the case where multiple formulas are present.

#Fixed points
The $H$ that appears in the statement of the theorem is called a **fixed point** of $\phi(p)$ on $p$.

In general, a fixed point of a formula $\psi(p, q_1...,q_n)$ on $p$ will be a modal formula $H(q_1,...,q_n)$ in which $p$ does not appear such that $GL\vdash \boxdot[https://arbital.com/p/p\leftrightarrow\psi](https://arbital.com/p/p\leftrightarrow\psi) \leftrightarrow \boxdot[H](https://arbital.com/p/p_i\leftrightarrow)$.

The fixed point theorem gives a sufficient condition for the existence of fixed points, namely that $\psi$ is modalized in $\psi$. It is an open problem to determine a necessary condition for the existence of fixed points.

Fixed points satisfy some important properties:

If $H$ is a fixed point of $\phi$ on $p$, then $GL\vdash H(q_1,...,q_n)\leftrightarrow \phi(H(q_1,...,q_n),q_1,...,q_n)$. This coincides with our intuition of what a fixed point is, since this can be seen as an argument that when fed to $\phi$ it returns something equivalent to itself.

%%hidden(Proof):
Since $H$ is a fixed point, $GL\vdash \boxdot[https://arbital.com/p/p\leftrightarrow\psi](https://arbital.com/p/p\leftrightarrow\psi) \leftrightarrow \boxdot[H](https://arbital.com/p/p_i\leftrightarrow)$. Since $GL$ is [normal](https://arbital.com/p/), it is closed under substitution. By substituing $p$ for $H$, we find that $GL\vdash \boxdot[https://arbital.com/p/H](https://arbital.com/p/H) \leftrightarrow \boxdot[https://arbital.com/p/H](https://arbital.com/p/H)$.

But trivially $GL\vdash \boxdot[H(q_1,...,q_n)\leftrightarrow H(q_1,...,q_n)$, so $GL\vdash \boxdot[https://arbital.com/p/H](https://arbital.com/p/H)$.
%%

$H$ and $I$ are fixed points of $\phi$ if and only if $GL\vdash H\leftrightarrow I$. This is knows as the
**uniqueness of fixed points**.

%%hidden(Proof):
Let $H$ be a fixed point on $p$ of $\phi(p)$; that is, $GL\vdash \boxdot(p\leftrightarrow \phi(p))\leftrightarrow (p\leftrightarrow H)$.

Suppose $I$ is such that $GL\vdash H\leftrightarrow I$. Then by the first substitution theorem,  $GL\vdash F(I)\leftrightarrow F(H)$ for every formula $F(q)$. If $F(q)=\boxdot(p\leftrightarrow q)$, then $GL\vdash \boxdot(p\leftrightarrow H)\leftrightarrow \boxdot(p\leftrightarrow I)$, from which it follows that $GL\vdash \boxdot(p\leftrightarrow \phi(p))\leftrightarrow (p\leftrightarrow I)$.

Conversely, if $H$ and $I$ are fixed points, then $GL\vdash \boxdot (p\leftrightarrow H)\leftrightarrow \boxdot (p\leftrightarrow I)$, so since $GL$ is closed under substitution, $GL\vdash\boxdot (H\leftrightarrow H)\leftrightarrow \boxdot (H\leftrightarrow I)$. Since $GL\vdash \boxdot (H\leftrightarrow H)$, it follows that $GL\vdash (H\leftrightarrow I)$.
%%

#Special case fixed point theorem

The special case of the fixed point theorem is what we stated at the beginning of the page. Namely:

>Let $\phi(p)$ be a modal sentence [modalized](https://arbital.com/p/5m4) in p.
>Then there exists a letterless $H$ such that $GL\vdash \boxdot[\phi](https://arbital.com/p/p\leftrightarrow) \leftrightarrow \boxdot[H](https://arbital.com/p/p\leftrightarrow)$.

There is a nice semantical procedure based on [Kripke models](https://arbital.com/p/5ll)  that allows to compute $H$ as a truth functional compound of sentences $\square^n \bot$ %%note:$\square^n A = \underbrace{\square,\square,\ldots,\square}_{n\text{-times}} A$ %%. (ie, $H$ is in [normal form](https://arbital.com/p/)).

##$A$-traces
Let $A$ be a modal sentence modalized in $p$ in which no other sentence letter appears (we call such a sentence a $p$-sentence). We want to calculate $A$'s fixed point on $p$. This procedure bears a resemblance to the [trace](https://arbital.com/p/) method for evaluating letterless modal sentences.

We are going to introduce the notion of the $A$-trace of a $p$-sentence $B$, notated by $[https://arbital.com/p/[https://arbital.com/p/B](https://arbital.com/p/B)](https://arbital.com/p/[https://arbital.com/p/B](https://arbital.com/p/B))_A$. The $A$-trace maps modal sentences to sets of [natural numbers](https://arbital.com/p/45h), and is defined recursively as follows:

* $[https://arbital.com/p/[https://arbital.com/p/\bot](https://arbital.com/p/\bot)](https://arbital.com/p/[https://arbital.com/p/\bot](https://arbital.com/p/\bot))_A = \emptyset$
* $[https://arbital.com/p/[C](https://arbital.com/p/B\to)](https://arbital.com/p/[C](https://arbital.com/p/B\to))_A = (\mathbb{N} \setminus [https://arbital.com/p/[https://arbital.com/p/B](https://arbital.com/p/B)](https://arbital.com/p/[https://arbital.com/p/B](https://arbital.com/p/B))_A)\cup [https://arbital.com/p/[https://arbital.com/p/C](https://arbital.com/p/C)](https://arbital.com/p/[https://arbital.com/p/C](https://arbital.com/p/C))_A$
* $[https://arbital.com/p/[D](https://arbital.com/p/\square)](https://arbital.com/p/[D](https://arbital.com/p/\square))_A=\{m:\forall i < m i\in [https://arbital.com/p/[https://arbital.com/p/D](https://arbital.com/p/D)](https://arbital.com/p/[https://arbital.com/p/D](https://arbital.com/p/D))_A\}$
* $[https://arbital.com/p/[https://arbital.com/p/p](https://arbital.com/p/p)](https://arbital.com/p/[https://arbital.com/p/p](https://arbital.com/p/p))_A=[https://arbital.com/p/[https://arbital.com/p/A](https://arbital.com/p/A)](https://arbital.com/p/[https://arbital.com/p/A](https://arbital.com/p/A))_A$

*Lemma*: Let $M$ be a finite, transitive and irreflexive Kripke model in which $(p\leftrightarrow A) is valid, and $B$ a $p$-sentence. Then $M,w\models B$ iff $\rho(w)\in [https://arbital.com/p/[https://arbital.com/p/B](https://arbital.com/p/B)](https://arbital.com/p/[https://arbital.com/p/B](https://arbital.com/p/B))_A$.

%%hidden(Proof):
Coming soon
%%

*Lemma*: The $A$-trace of a $p$-sentence $B$ is either finite or cofinite, and furthermore either it has less than $n$ elements or lacks less than $n$ elements, where $n$ is the number of $\square$s in $A$.

%%hidden(Proof):
Coming soon
%%

Those two lemmas allow us to express the truth value of $A$ in terms of world ranks for models in which $p\leftrightarrow A$ is valid. Then the fixed point $H$ will be either the union or the negation of the union of a finite number of sentences $\square^{n+1}\bot\wedge \square^n \bot$ %%note:Such a sentence is only true in worlds of rank $n$%%

In the following section we work through an example, and demonstrate how can we easily compute those fixed points using a [Kripke chain](https://arbital.com/p/).

##Applications

For an example, we will compute the fixed point for the modal [Gödel sentence](https://arbital.com/p/) $p\leftrightarrow \neg\square p$ and analyze its significance.

We start by examining the truth value of $\neg\square p$ in the $0$th rank worlds. Since the only letter is $p$ and it is modalized, this can be done without problem (remember that $\square B$ is always true in the rank $0$ worlds, no mater what $B$ is). Now we apply to $p$ the constraint of having the same truth value as $\neg\square p$.

We iterate the procedure for the next world ranks.

$$
\begin{array}{cccc}
 \text{world= } & p & \square (p) & \neg \square (p) \\
 0 & \bot & \top & \bot \\
 1 & \top & \bot & \top \\
 2 & \top & \bot & \top \\
\end{array}
$$

Since there is only one $\square$ in the formula, the chain is guaranteed to stabilize in the first world and there is no need for going further. We have shown the truth values in world $2$ to show that this is indeed the case.

From the table we have just constructed it becomes evident that $[https://arbital.com/p/[https://arbital.com/p/p](https://arbital.com/p/p)](https://arbital.com/p/[https://arbital.com/p/p](https://arbital.com/p/p))_{\neg\square p} = \mathbb{N}\setminus \{0\}$. Thus $H = \square^{0+1}\bot \wedge \square^0\bot = \neg\square\bot$.

Therefore, $GL\vdash \square [\neg\square p](https://arbital.com/p/p\leftrightarrow)\leftrightarrow \square[\neg\square \bot](https://arbital.com/p/p\leftrightarrow)$. Thus, the fixed point for the modal Gödel sentence is the [https://arbital.com/p/-5km](https://arbital.com/p/-5km) of arithmetic!

By employing the [arithmetical soundness of GL](https://arbital.com/p/), we can translate this result to $PA$ and show that $PA\vdash \square_{PA} [\neg\square_{PA} G](https://arbital.com/p/G\leftrightarrow)\leftrightarrow \square_{PA}[\neg\square_{PA} \bot](https://arbital.com/p/G\leftrightarrow)$ for every sentence $G$ of arithmetic.

Since in $PA$ we can construct $G$ by the [https://arbital.com/p/-59c](https://arbital.com/p/-59c) such that $PA\vdash G\leftrightarrow \neg\square_{PA} G$, by necessitation we have that for such a $G$ then $PA\vdash \square_PA[G\leftrightarrow \neg\square_{PA} G](https://arbital.com/p/)$. By the theorem we just proved using the fixed point, then $PA\vdash \square_{PA}[\neg\square_{PA} \bot](https://arbital.com/p/G\leftrightarrow)$. SInce [everything $PA$ proves is true](https://arbital.com/p/) then $PA\vdash G\leftrightarrow \neg\square_{PA} \bot$.

Surprisingly enough, the Gödel sentence is equivalent to the consistency of arithmetic! This makes more evident that $G$ is not provable [unless $PA$ is inconsistent](https://arbital.com/p/godel_second_incompleteness_theorm), and that it is not disprovable unless it is [$\omega$-inconsistent](https://arbital.com/p/omega_inconsistency).

**Exercise:** Find the fixed point for the [Henkin sentence](https://arbital.com/p/) $H\leftrightarrow\square H$.

%%hidden(Show solution):
$$
\begin{array}{ccc}
 \text{world= } & p & \square (p) \\
 0 & \top & \top \\
 1 & \top & \top \\
\end{array}
$$
Thus the fixed point is simply $\top$.
%%

#General case
The first generalization we make to the theorem is allowing the appearance of sentence letters other than the one we are fixing. The concrete statement is as follows:

>Let $\phi(p, q_1,...,q_n)$ be a modal sentence [modalized](https://arbital.com/p/5m4) in p. Then $\phi$ has a fixed point on $p$.%%.

There are several constructive procedures for finding the fixed point in the general case.

One particularly simple procedure is based on **k-decomposition**.

##K-decomposition
Let $\phi$ be as in the hypothesis of the fixed point theorem. Then we can express $\phi$ as $B(\square D_1(p), ..., \square D_{k}(p))$, since every $p$ occurs within the scope of a $\square$ (The $q_i$s are omitted for simplicity, but they may appear scattered between $B$ and the $D_i$s). This is called a $k$-decomposition of $\phi$.

If $\phi$ is $0$-decomposable, then it is already a fixed point, since $p$ does not appear.

Otherwise, consider $B_i = B(\square D_1(p), ..., \square D_{i-1}(p),\top, \square D_{i+1}(p),...,\square D_k(p))$, which is $k-1$-decomposable.

Assuming that the procedure works for $k-1$ decomposable formulas, we can use it to compute a fixed point $H_i$ for each $B_i$. Now, $H=B(\square D_1(H_1),...,\square D_k(H_k))$ is the desired fixed point for $\phi$.

%%hidden(Proof):

There is a nice semantic proof in *Computability and Logic*, by Boolos *et al*.
%%

This procedure constructs fixed points with structural similarity to the original sentence.

###Example
Let's compute the fixed point of $p\leftrightarrow \neg\square(q\to p)$.

We can 1-decompose the formula in $B(d)=\neg d$, $D_1(p)=q\to p$.

Then $B_1(p)=\neg \top = \bot$, which is its own fixed point. Thus the desired fixed point is $H=B(\square D_1(\bot))=\neg\square \neg q$.

**Exercise:** Compute the fixed point of $p\leftrightarrow \square [https://arbital.com/p/\square](https://arbital.com/p/\square)$.

%%hidden(Show solution):
One possible decomposition of the the formula at hand is $B(a)=a$, $D_1(p)=\square(p\wedge q)\wedge \square(p\wedge r)$.

Now we compute the fixed point of $B(\top)$, which is simply $\top$.

Therefore the fixed point of the whole expression is $B(\square D_1(p=\top))=\square[https://arbital.com/p/\square](https://arbital.com/p/\square)=\square[https://arbital.com/p/\square](https://arbital.com/p/\square)$
%%

#Generalized fixed point theorem

>Suppose that $A_i(p_1,...,p_n)$ are $n$ modal sentences such that $A_i$ is modalized in $p_n$ (possibly containing sentence letters other than $p_js$).

>Then there exists $H_1, ...,H_n$ in which no $p_j$ appears such that $GL\vdash \wedge_{i\le n} \{\boxdot (p_i\leftrightarrow A_i(p_1,...,p_n)\}\leftrightarrow \wedge_{i\le n} \{\boxdot(p_i\leftrightarrow H_i)\}$.

%%hidden(Proof):
We will prove it by induction.

For the base step, we know by the fixed point theorem that there is $H$ such that $GL\vdash \boxdot(p_1\leftrightarrow A_i(p_1,...,p_n)) \leftrightarrow \boxdot(p_1\leftrightarrow H(p_2,...,p_n))$

Now suppose that for $j$ we have $H_1,...,H_j$ such that $GL\vdash \wedge_{i\le j} \{\boxdot(p_i\leftrightarrow A_i(p_1,...,p_n)\}\leftrightarrow \wedge_{i\le j} \{\boxdot(p_i\leftrightarrow H_i(p_{j+1},...,p_n))\}$.

By the [second substitution theorem](https://arbital.com/p/), $GL\vdash \boxdot(A\leftrightarrow B)\rightarrow [https://arbital.com/p/F](https://arbital.com/p/F)$. Therefore we have that $GL\vdash \boxdot(p_i\leftrightarrow H_i(p_{j+1},...,p_n)\rightarrow [https://arbital.com/p/\boxdot](https://arbital.com/p/\boxdot)$.

If we iterate the replacements, we finally end up with $GL\vdash \wedge_{i\le j} \{\boxdot(p_i\leftrightarrow A_i(p_1,...,p_n)\}\rightarrow \boxdot(p_{j+1}\leftrightarrow A_{j+1}(H_1,...,H_j,p_{j+1},...,p_n))$.

Again by the fixed point theorem, there is $H_{j+1}'$ such that $GL\vdash \boxdot(p_{j+1}\leftrightarrow A_{j+1}(H_1,...,H_j,p_{j+1},...,p_n)) \leftrightarrow \boxdot[H_{j+1}'](https://arbital.com/p/p_{j+1}\leftrightarrow)$.

But as before, by the second substitution theorem, $GL\vdash \boxdot[H_{j+1}'](https://arbital.com/p/p_{j+1}\leftrightarrow)\rightarrow [\boxdot(p_i\leftrightarrow H_i(p_{j+1},...,p_n)) \leftrightarrow \boxdot(p_i\leftrightarrow H_i(H_{j+1}',...,p_n))$.

Let $H_{i}'$ stand for $H_i(H_{j+1}',...,p_n)$, and by combining the previous lines we find that $GL\vdash \wedge_{i\le j+1} \{\boxdot(p_i\leftrightarrow A_i(p_1,...,p_n)\}\rightarrow \wedge_{i\le j+1} \{\boxdot(p_i\leftrightarrow H_i'(p_{j+2},...,p_n))\}$.

By [Goldfarb's lemma](https://arbital.com/p/), we do not need to check the other direction, so $GL\vdash \wedge_{i\le j+1} \{\boxdot(p_i\leftrightarrow A_i(p_1,...,p_n)\}\leftrightarrow \wedge_{i\le j+1} \{\boxdot(p_i\leftrightarrow H_i'(p_{j+2},...,p_n))\}$ and the proof is finished $\square$

----

One remark: the proof is wholly constructive. You can iterate the construction of fixed point following the procedure implied by the construction of the $H_i'$ to compute fixed points.

%%

An immediate consequence of the theorem is that for those fixed points $H_i$ and every $A_i$, $GL\vdash H_i\leftrightarrow A_i(H_1,...,H_n)$.

Indeed, since $GL$ is closed under substitution, we can make the change $p_i$ for $H_i$ in the theorem to get that $GL\vdash \wedge_{i\le n} \{\boxdot (H_i\leftrightarrow A_i(H_1,...,H_n)\}\leftrightarrow \wedge_{i\le n} \{\boxdot(H_i\leftrightarrow H_i)\}$.

Since the righthand side is trivially a theorem of $GL$, we get the desired result.

Summary:
>Let $\phi(p, q_1,...,q_n)$ be a modal sentence [modalized](https://arbital.com/p/5m4) in $p$.
>Then there exists a sentence $H(q_1,..,q_n)$ such that $GL\vdash \boxdot[\phi](https://arbital.com/p/p\leftrightarrow) \leftrightarrow \boxdot[H](https://arbital.com/p/p\leftrightarrow)$.

This result can be used to give us insight about [self-referent](https://arbital.com/p/59c) sentences of arithmetic.


Irreducible element (ring theory)

summary(Technical): Let $(R, +, \times)$ be a [ring](https://arbital.com/p/3gq) which is an [integral domain](https://arbital.com/p/5md). We say $x \in R$ is *irreducible* if, whenever we write $r = a \times b$, it is the case that (at least) one of $a$ or $b$ is a [unit](https://arbital.com/p/5mg) (that is, has a multiplicative inverse).

[Ring theory](https://arbital.com/p/3gq) can be viewed as the art of taking the integers [$\mathbb{Z}$](https://arbital.com/p/48l) and extracting or identifying its essential properties, seeing where they lead.
In that light, we might ask what the abstracted notion of "[prime](https://arbital.com/p/4mf)" should be.
Confusingly, we call this property *irreducibility* rather than "primality"; "[prime](https://arbital.com/p/5m2)" in ring theory corresponds to something closely related but not the same.

In a ring $R$ which is an [https://arbital.com/p/-5md](https://arbital.com/p/-5md), we say that an element $x \in R$ is *irreducible* if, whenever we write $r = a \times b$, it is the case that (at least) one of $a$ or $b$ is a [unit](https://arbital.com/p/5mg) (that is, has a multiplicative inverse).

# Why do we require $R$ to be an integral domain?

# Examples

# Relationship with primality in the ring-theoretic sense

It is always the case that [primes](https://arbital.com/p/5m2) are irreducible in any integral domain.
%%hidden(Show proof):
If $p$ is prime, then $p \mid ab$ implies $p \mid a$ or $p \mid b$ by definition.
We wish to show that if $p=ab$ then one of $a$ or $b$ is invertible.

Suppose $p = ab$.
Then in particular $p \mid ab$ so $p \mid a$ or $p \mid b$.
Assume without loss of generality that $p \mid a$; so there is some $c$ such that $a = cp$.

Therefore $p = ab = cpb$; we are working in a commutative ring, so $p(1-bc) = 0$.
Since the ring is an integral domain and $p$ is prime (so is nonzero), we must have $1-bc = 0$ and hence $bc = 1$.
That is, $b$ is invertible.
%%

However, the converse does not hold (though it may in certain rings).

- In $\mathbb{Z}$, it is a fact that irreducibles are prime. Indeed, it is a consequence of [Bézout's theorem](https://arbital.com/p/5mp) that if $p$ is "prime" in the usual $\mathbb{Z}$-sense (that is, irreducible in the rings sense) %%note:I'm sorry about the notation. It's just what we're stuck with. It is very confusing.%%, then $p$ is "prime" in the rings sense. ([Proof.](https://arbital.com/p/5mh))
- In the ring $\mathbb{Z}[https://arbital.com/p/\sqrt{-3}](https://arbital.com/p/\sqrt{-3})$ of [complex numbers](https://arbital.com/p/4zw) of the form $a+b \sqrt{-3}$ where $a, b$ are integers, the number $2$ is irreducible but we may express $4 = 2 \times 2 = (1+\sqrt{-3})(1-\sqrt{-3})$. That is, we have $2 \mid (1+\sqrt{-3})(1-\sqrt{-3})$ but $2$ doesn't divide either of those factors. Hence $2$ is not prime.

%%hidden(Proof that $2$ is irreducible in $\mathbb{Z}[https://arbital.com/p/\sqrt{-3}](https://arbital.com/p/\sqrt{-3})):
A slick way to do this goes via the [norm](https://arbital.com/p/norm_complex_number) $N(2)$ of the complex number $2$; namely $4$.

If $2 = ab$ then $N(2) = N(a)N(b)$ because [the norm is a multiplicative function](https://arbital.com/p/norm_of_complex_number_is_multiplicative), and so $N(a) N(b) = 4$.
But $N(x + y \sqrt{-3}) = x^2 + 3 y^2$ is an integer for any element of the ring, and so we have just two distinct options: $N(a) = 1, N(b) = 4$ or $N(a) = 2 = N(b)$.
(The other cases follow by interchanging $a$ and $b$.)

The first case: $N(x+y \sqrt{3}) = 1$ is only possible if $x= \pm 1, y = \pm 0$.
Hence the first case arises only from $a=\pm1, b=\pm2$; this has not led to any new factorisation of $2$.

The second case: $N(x+y \sqrt{3}) = 2$ is never possible at all, since if $y \not = 0$ then the norm is too big, while if $y = 0$ then we are reduced to finding $x \in \mathbb{Z}$ such that $x^2 = 2$.

Hence if we write $2$ as a product, then one of the factors must be invertible (indeed, must be $\pm 1$).
%%

In fact, in a [https://arbital.com/p/-principal_ideal_domain](https://arbital.com/p/-principal_ideal_domain), "prime" and "irreducible" are equivalent. ([Proof.](https://arbital.com/p/5mf))

# Relationship with unique factorisation domains

It is a fact that an integral domain $R$ is a [UFD](https://arbital.com/p/unique_factorisation_domain) if and only if it has "all irreducibles are [prime](https://arbital.com/p/5m2) (in the sense of ring theory)" and "every $r \in R$ may be written as a product of irreducibles". ([Proof.](https://arbital.com/p/alternative_condition_for_ufd))
This is a slightly easier condition to check than our original definition of a UFD, which instead of "all irreducibles are prime" had "products are unique up to reordering and multiplying by invertible elements".

Therefore the relationship between irreducibles and primes is at the heart of the nature of a unique factorisation domain.
Since $\mathbb{Z}$ is a UFD, in some sense the [Fundamental Theorem of Arithmetic](https://arbital.com/p/fundamental_theorem_of_arithmetic) holds precisely because of the fact that "prime" is the same as "irreducible" in $\mathbb{Z}$.

Summary: An irreducible element of a [ring](https://arbital.com/p/3gq) is one which cannot be written as a nontrivial product of two other elements of the ring.


Prime element of a ring

summary(Technical): Let $(R, +, \times)$ be a [ring](https://arbital.com/p/3gq) which is an [integral domain](https://arbital.com/p/5md). We say $p \in R$ is *prime* if, whenever $p \mid ab$, it is the case that either $p \mid a$ or $p \mid b$ (or both).

An element of an [https://arbital.com/p/-5md](https://arbital.com/p/-5md) is *prime* if it has the property that $p \mid ab$ implies $p \mid a$ or $p \mid b$.
Equivalently, if its generated [ideal](https://arbital.com/p/ideal_ring_theory) is [prime](https://arbital.com/p/prime_ideal) in the sense that $ab \in \langle p \rangle$ implies either $a$ or $b$ is in $\langle p \rangle$.

Be aware that "prime" in ring theory does not correspond exactly to "[prime](https://arbital.com/p/4mf)" in number theory (the correct abstraction of which is [irreducibility](https://arbital.com/p/5m1)).
It is the case that they are the same concept in the ring $\mathbb{Z}$ of [integers](https://arbital.com/p/48l) ([proof](https://arbital.com/p/5mf)), but this is a nontrivial property that turns out to be equivalent to the [https://arbital.com/p/-5rh](https://arbital.com/p/-5rh) ([proof](https://arbital.com/p/alternative_condition_for_ufd)).

# Examples

# Properties

- Primes are always [irreducible](https://arbital.com/p/5m1); a proof of this fact appears on the [page on irreducibility](https://arbital.com/p/5m1), along with counterexamples to the converse.
-

Summary: A prime element of a [ring](https://arbital.com/p/3gq) is one such that, if it divides a product, then it divides (at least) one of the terms of the product.


Modalized modal sentence

A [modal sentence](https://arbital.com/p/) $A$ is said to be **modalized** in $p$ if every occurrence of $p$ happens within the scope of a $\square$.

As an example, $\square p \wedge q$ is modalized in $p$, but not in $q$.

If $A$ does not contain $p$, then it is trivially modalized in $p$.

A sentence which is modalized in every sentence letter is said to be **fully modalized**.

Being modalized in $p$ is a sufficient condition for having a [fixed point](https://arbital.com/p/5lx) on $p$.


Integral domain

summary(Technical): An integral domain is a [ring](https://arbital.com/p/3gq) in which $ab=0$ implies $a=0$ or $b=0$. (We exclude the ring with one element: that is conventionally not considered an integral domain.)

In keeping with [ring theory](https://arbital.com/p/3gq) as the attempt to isolate each individual property of [$\mathbb{Z}$](https://arbital.com/p/48l) and work out how the properties interplay with each other, we define the notion of **integral domain** to capture the fact that if $a \times b = 0$ then $a=0$ or $b=0$.
That is, an integral domain is one which has no "zero divisors": $0$ cannot be nontrivially expressed as a product.
(For uninteresting reasons, we also exclude the ring with one element, in which $0=1$, from being an integral domain.)

# Examples

- $\mathbb{Z}$ is an integral domain.
- Any [field](https://arbital.com/p/481) is an integral domain. (The proof is an exercise.)

%%hidden(Show solution):
Suppose $ab = 0$, but $a \not = 0$. We wish to show that $b=0$.

Since we are working in a field, $a$ has an inverse $a^{-1}$; multiply both sides by $a^{-1}$ to obtain $a^{-1} a b = 0 \times a^{-1}$.
Simplifying, we obtain $b = 0$.
%%

- When $p$ is a [prime](https://arbital.com/p/4mf) integer, the ring $\mathbb{Z}_p$ of integers [mod](https://arbital.com/p/modular_arithmetic) $p$ is an integral domain.
- When $n$ is a [composite](https://arbital.com/p/composite_number) integer, the ring $\mathbb{Z}_n$ is *not* an integral domain. Indeed, if $n = r \times s$ with $r, s$ positive integers, then $r s = n = 0$ in $\mathbb{Z}_n$.

# Properties

The reason we care about integral domains is because they are precisely the rings in which we may cancel products: if $a \not = 0$ and $ab = ac$ then $b=c$.
%%hidden(Proof):
Indeed, if $ab = ac$ then $ab-ac = 0$ so $a(b-c) = 0$, and hence (in an integral domain) $a=0$ or $b=c$.

Moreover, if we are not in an integral domain, say $r s = 0$ but $r, s \not = 0$.
Then $rs = r \times 0$, but $s \not = 0$, so we can't cancel the $r$ from both sides.
%%

## Finite integral domains

If a ring $R$ is both finite and an integral domain, then it is a [field](https://arbital.com/p/481).
The proof is an exercise.
%%hidden(Show solution):
Given $r \in R$, we wish to find a multiplicative inverse.

Since there are only finitely many elements of the ring, consider $S = \{ ar : a \in R\}$.
This set is a subset of $R$, because the multiplication of $R$ is [closed](https://arbital.com/p/3gy).
Moreover, every element is distinct, because if $ar = br$ then we can cancel the $r$ (because we are in an integral domain), so $a = b$.

Since there are $|R|$-many elements of the subset $S$ (where $| \cdot |$ refers to the [https://arbital.com/p/-4w5](https://arbital.com/p/-4w5)), and since $R$ is finite, $S$ must in fact be $R$ itself.

Therefore in particular $1 \in S$, so $1 = ar$ for some $a$.
%%

Summary: An integral domain is a [ring](https://arbital.com/p/3gq) in which the only way to make $0$ as a product is to multiply $0$ by something. For instance, in an integral domain like [$\mathbb{Z}$](https://arbital.com/p/48l), $2 \times 3$ is not equal to $0$ because neither $2$ nor $3$ is.


In a principal ideal domain, "prime" and "irreducible" are the same

Let $R$ be a [ring](https://arbital.com/p/3gq) which is a [PID](https://arbital.com/p/principal_ideal_domain), and let $r \not = 0$ be an element of $R$.
Then $r$ is [irreducible](https://arbital.com/p/5m1) if and only if $r$ is [prime](https://arbital.com/p/5m2).

In fact, it is easier to prove a stronger statement: that the following are equivalent.
%%note:Every proof known to the author is of this shape either implicitly or explicitly, but when it's explicit, it should be clearer what is going on.%%

1. $r$ is irreducible.
2. $r$ is prime.
3. The generated [ideal](https://arbital.com/p/ideal_ring_theory) $\langle r \rangle$ is [maximal](https://arbital.com/p/maximal_ideal) in $R$.

# Proof

## $2 \Rightarrow 1$
A proof that "prime implies irreducible" appears on the page for [irreducibility](https://arbital.com/p/5m1).

## $3 \Rightarrow 2$
We wish to show that if $\langle r \rangle$ is maximal, then it is prime.
(Indeed, $r$ is [prime](https://arbital.com/p/5m2) if and only if its generated ideal is [prime](https://arbital.com/p/prime_ideal).)

An ideal $I$ is maximal if and only if the [quotient](https://arbital.com/p/quotient_ring) $R/I$ is a [field](https://arbital.com/p/481). ([Proof.](https://arbital.com/p/ideal_maximal_iff_quotient_is_field))

An ideal $I$ is [prime](https://arbital.com/p/prime_ideal) if and only if the quotient $R/I$ is an [https://arbital.com/p/-5md](https://arbital.com/p/-5md). ([Proof.](https://arbital.com/p/ideal_prime_iff_quotient_is_integral_domain))

All fields are integral domains. (A proof of this appears on [the page on integral domains](https://arbital.com/p/5md).)

Hence maximal ideals are prime.

## $1 \Rightarrow 3$
Let $r$ be irreducible; then in particular it is not invertible, so $\langle r \rangle$ isn't simply the whole ring.

To show that $\langle r \rangle$ is maximal, we need to show that if it is contained in any larger ideal then that ideal is the whole ring.

Suppose $\langle r \rangle$ is contained in the larger ideal $J$, then.
Because we are in a principal ideal domain, $J = \langle a \rangle$, say, for some $a$, and so $r = a c$ for some $c$.
It will be enough to show that $a$ is invertible, because then $\langle a \rangle$ would be the entire ring.

But $r$ is irreducible, so one of $a$ and $c$ is invertible; if $a$ is invertible then we are done, so suppose $c$ is invertible.

Then $a = r c^{-1}$.
We have supposed that $J$ is indeed larger than $\langle r \rangle$: that there is $j \in J$ which is not in $\langle r \rangle$.
Since $j \in J = \langle a \rangle$, we can find $d$ (say) such that $j = a d$; so $j = r c^{-1} d$ and hence $j \in \langle r \rangle$, which is a contradiction.

Summary: While there are two distinct but closely related notions of "[prime](https://arbital.com/p/5m2)" and "[irreducible](https://arbital.com/p/5m1)", the two ideas are actually the same in a certain class of [ring](https://arbital.com/p/3gq). This result is basically what enables the [https://arbital.com/p/-fundamental_theorem_of_arithmetic](https://arbital.com/p/-fundamental_theorem_of_arithmetic).


Unit (ring theory)

An element $x$ of a non-trivial [ring](https://arbital.com/p/3gq)%%note:That is, a ring in which $0 \not = 1$; equivalently, a ring with more than one element.%% is known as a **unit** if it has a multiplicative inverse: that is, if there is $y$ such that $xy = 1$.
(We specified that the ring be non-trivial.
If the ring is trivial then $0=1$ and so the requirement is the same as $xy = 0$; this means $0$ is actually invertible in this ring, since its inverse is $0$: we have $0 \times 0 = 0 = 1$.)

$0$ is never a unit, because $0 \times y = 0$ is never equal to $1$ for any $y$ (since we specified that the ring be non-trivial).

If every nonzero element of a ring is a unit, then we say the ring is a [field](https://arbital.com/p/481).

Note that if $x$ is a unit, then it has a *unique* inverse; the proof is an exercise.
%%hidden(Proof):
If $xy = xz = 1$, then $zxy = z$ (by multiplying both sides of $xy=1$ by $z$) and so $y = z$ (by using $zx = 1$).
%%

# Examples

- In [$\mathbb{Z}$](https://arbital.com/p/48l), $1$ and $-1$ are both units, since $1 \times 1 = 1$ and $-1 \times -1 = 1$. However, $2$ is not a unit, since there is no integer $x$ such that $2x=1$. In fact, the *only* units are $\pm 1$.
- [$\mathbb{Q}$](https://arbital.com/p/4zq) is a [field](https://arbital.com/p/481), so every rational except $0$ is a unit.

Summary: A unit of a [ring](https://arbital.com/p/3gq) is an element with a multiplicative inverse.


Euclid's Lemma on prime numbers

summary(Technical): Let $p$ be a [prime](https://arbital.com/p/4mf) natural number. Then $p \mid ab$ implies $p \mid a$ or $p \mid b$.

Euclid's lemma states that if $p$ is a [prime number](https://arbital.com/p/4mf), which divides a product $ab$, then $p$ divides at least one of $a$ or $b$.

# Proof

## Elementary proof

Suppose $p \mid ab$ %%note:That is, $p$ divides $ab$.%%, but $p$ does not divide $a$.
We will show that $p \mid b$.

Indeed, $p$ does not divide $a$, so the [https://arbital.com/p/-5mw](https://arbital.com/p/-5mw) of $p$ and $a$ is $1$ (exercise: do this without using integer factorisation); so by [Bézout's theorem](https://arbital.com/p/bezouts_theorem) there are integers $x, y$ such that $ax+py = 1$.

%%hidden(Show solution to exercise):
We are not allowed to use the fact that we can factorise integers, because we need "$p \mid ab$ implies $p \mid a$ or $p \mid b$" as a lemma on the way towards the proof of the [https://arbital.com/p/-5rh](https://arbital.com/p/-5rh) (which is the theorem that tells us we can factorise integers).

Recall that the highest common factor of $a$ and $p$ is defined to be the number $c$ such that:

- $c \mid a$;
- $c \mid p$;
- for any $d$ which divides $a$ and $p$, we have $d \mid c$.

[Euclid's algorithm](https://arbital.com/p/euclidean_algorithm) tells us that $a$ and $p$ do have a (unique) highest common factor.

Now, if $c \mid p$, we have that $c = p$ or $c=1$, because $p$ is [prime](https://arbital.com/p/4mf).
But $c$ is not $p$ because we also know that $c \mid a$, and we already know $p$ does not divide $a$.

Hence $c = 1$.
%%

But multiplying through by $b$, we see $abx + pby = b$.
$p$ divides $ab$ and divides $p$, so it divides the left-hand side; hence it must divide the right-hand side too.
That is, $p \mid b$.

## More abstract proof

This proof uses much more theory but is correspondingly much more general, and it reveals the important feature of $\mathbb{Z}$ here.

$\mathbb{Z}$, viewed as a [ring](https://arbital.com/p/3gq), is a [https://arbital.com/p/-5r5](https://arbital.com/p/-5r5). ([Proof.](https://arbital.com/p/integers_is_pid))
The theorem we are trying to prove is that the [irreducibles](https://arbital.com/p/5m1) in $\mathbb{Z}$ are all [prime](https://arbital.com/p/5m2) in the sense of ring theory.

But it is generally true that in a PID, "prime" and "irreducible" coincide ([proof](https://arbital.com/p/5mf)), so the result is immediate.

# Converse is false

Any composite number $pq$ (where $p, q$ are greater than $1$) divides $pq$ without dividing $p$ or $q$, so the converse is very false.

# Why is this important?

This lemma is a nontrivial step on the way to proving the [https://arbital.com/p/-5rh](https://arbital.com/p/-5rh); and in fact in a certain general sense, if we can prove this lemma then we can prove the FTA.
It tells us about the behaviour of the primes with respect to products: we now know that the primes "cannot be split up between factors" of a product, and so they behave, in a sense, ["irreducibly"](https://arbital.com/p/5m1).

The lemma is also of considerable use as a tiny step in many different proofs.

Summary: The [prime numbers](https://arbital.com/p/4mf) have a special property that they "can't be distributed between terms of a product": if $p$ is a prime dividing a product $ab$ of [integers](https://arbital.com/p/48l), then $p$ wholly divides one or both of $a$ or $b$. It cannot be the case that "some but not all of $p$ divides into $a$, and the rest of $p$ divides into $b$".


Bézout's theorem

Bézout's theorem is an important basic theorem of number theory.
It states that if $a$ and $b$ are integers, and $c$ is an integer, then the equation $ax+by = c$ has integer solutions in $x$ and $y$ if and only if the [https://arbital.com/p/-5mw](https://arbital.com/p/-5mw) of $a$ and $b$ divides $c$.

# Proof

We have two directions of the equivalence to prove.

## If $ax+by=c$ has solutions

Suppose $ax+by=c$ has solutions in $x$ and $y$.
Then the highest common factor of $a$ and $b$ divides $a$ and $b$, so it divides $ax$ and $by$; hence it divides their sum, and hence $c$.

## If the highest common factor divides $c$

Suppose $\mathrm{hcf}(a,b) \mid c$; equivalently, there is some $d$ such that $d \times \mathrm{hcf}(a,b) = c$.

We have the following fact: that the highest common factor is a linear combination of $a, b$. ([Proof](https://arbital.com/p/hcf_is_linear_combination); this [can also be seen](https://arbital.com/p/extended_euclidean_algorithm) by working through [Euclid's algorithm](https://arbital.com/p/euclidean_algorithm).)

Therefore there are $x$ and $y$ such that $ax + by = \mathrm{hcf}(a,b)$.

Finally, $a (xd) + b (yd) = d \mathrm{hcf}(a, b) = c$, as required.

# Actually finding the solutions

Suppose $d \times \mathrm{hcf}(a,b) = c$, as above.

The [https://arbital.com/p/-extended_euclidean_algorithm](https://arbital.com/p/-extended_euclidean_algorithm) can be used (efficiently!) to obtain a linear combination $ax+by$ of $a$ and $b$ which equals $\mathrm{hcf}(a,b)$.
Once we have found such a linear combination, the solutions to the integer equation $ax+by=c$ follow quickly by just multiplying through by $d$.

# Importance

Bézout's theorem is important as a step towards the proof of [Euclid's lemma](https://arbital.com/p/5mh), which itself is the key behind the [https://arbital.com/p/5rh](https://arbital.com/p/5rh).
It also holds in general [principal ideal domains](https://arbital.com/p/5r5).

Summary: Bézout's theorem states that if $a$ and $b$ are integers, and $c$ is an integer, then the equation $ax+by = c$ has integer solutions in $x$ and $y$ if and only if the [https://arbital.com/p/-5mw](https://arbital.com/p/-5mw) of $a$ and $b$ divides $c$.


Rice's Theorem

Rice's Theorem is a rather surprising and very strong restriction on what we can determine about the [https://arbital.com/p/-3jy](https://arbital.com/p/-3jy) computed by an arbitrary [Turing machine](https://arbital.com/p/5pd).
It tells us that for *every* nontrivial property of computable functions %%note:By "nontrivial", we mean there is at least one function with that property and at least one without that property.%%, there is no general procedure which takes as its input a Turing machine, and computes whether or not the function computed by that machine has that property.

Therefore, if we want to discover anything about the output of a general computer program, *in general* the best we can do is simply run the program.
As a corollary, there can be no *fully general* procedure that checks whether a piece of computer code is free of bugs or not.

# Formal statement

We will use the notation $[https://arbital.com/p/n](https://arbital.com/p/n)$ for the $n$th [Turing machine](https://arbital.com/p/5pd) under some fixed [numbering system](https://arbital.com/p/description_number).
Each such machine induces a [https://arbital.com/p/-5p2](https://arbital.com/p/-5p2), which we will also write as $[https://arbital.com/p/n](https://arbital.com/p/n)$ where this is unambiguous due to context; then it makes sense to write $[n](m)$ for the value that machine $[https://arbital.com/p/n](https://arbital.com/p/n)$ outputs when it is run on input $m$.

Let $A$ be a non-empty, proper %%note:That is, it is not the entire set.%% subset of $\{ \mathrm{Graph}(n) : n \in \mathbb{N} \}$, where $\mathrm{Graph}(n)$ is the [graph](https://arbital.com/p/graph_of_a_function) of the [https://arbital.com/p/-5p2](https://arbital.com/p/-5p2) computed by $[https://arbital.com/p/n](https://arbital.com/p/n)$, the $n$th Turing machine.
Then there is no Turing machine $[https://arbital.com/p/r](https://arbital.com/p/r)$ such that:

- $[r](i)$ is $1$ if $\mathrm{Graph}(i) \in A$
- $[r](i)$ is $0$ if $\mathrm{Graph}(i) \not \in A$.

# Caveats

- While this result tells us, for example, that "no procedure will ever be able to determine whether an arbitrary program is bug-free", in practice it may be possible to determine whether *a large class* of programs is bug-free, while accepting the fact that our procedure might not be able to solve the fully general case.

- Additionally, this result only tells us about the *graphs* of the functions in question.
We can determine certain properties which are specific to the Turing machine: for example, we can tell whether the program will halt in five steps, by simply running it for five steps.
This does not contradict Rice, because Rice tells us only about the ultimate answer the machines spit out, and nothing about the procedures they use to get to the answer; "the machine halts in five steps" is not a property of the graph of the function, but is a property of the Turing machine itself.

- Rice's theorem is only a restriction on whether we can *decide* the status of a function: that is, whether we can decide *whether or not* the function computed by some machine has a certain property. Rice tells us nothing if we're only looking for a procedure that "must find out in finite time whether a function *does* have a property, but is allowed to never give an answer if the function *doesn't* have the property".
For example, we can determine whether a partial function is defined anywhere (that is, it is not the empty function: the one which never outputs anything, whatever its input) by just attempting to evaluate the function in parallel at $0$, at $1$, at $2$, and so on.
If the partial function is defined anywhere, then eventually one of the parallel threads will discover this fact; but if it is defined nowhere, then the procedure might just spin on and on forever without giving any output.
However, Rice's theorem does guarantee that there is no procedure which will tell us in finite time *whether or not* its input is a function which is defined somewhere; even though we have just specified a procedure which will tell us in finite time *if* its input is defined somewhere.

# Proof outline

Several proofs exist: for example, [one by reduction](https://arbital.com/p/5n6) to the [halting problem](https://arbital.com/p/halting_problem), and one [standalone proof](https://arbital.com/p/5t9).
Here, we sketch the standalone proof in broad strokes, because it goes via a neat lemma.

The intermediate lemma we prove is:

> Let $h: \mathbb{N} \to \mathbb{N}$ be [total](https://arbital.com/p/total_function) computable: that is, it halts on every input.
Then there is $n \in \mathbb{N}$ such that $\mathrm{Graph}(n) = \mathrm{Graph}(h(n))$. %%note:And, moreover, we can actually *find* such an $n$.%%

That is, the "underlying function" of $n$ - the partial function computed by $[https://arbital.com/p/n](https://arbital.com/p/n)$ - has the same output, at every point, as the function computed by $[https://arbital.com/p/h](https://arbital.com/p/h)$.
If we view $h$ as a way of manipulating a program (as specified by its [https://arbital.com/p/-description_number](https://arbital.com/p/-description_number)), then this fixed-point theorem states that we can find a program whose underlying function is not changed at all by $h$.

This lemma might be somewhat surprising: it "ought" to be possible to find a change one could make to arbitrary computer code, with the guarantee that the altered code must do something different to the original.
The fixed-point theorem tells us that this is not the case.

The proof of the lemma is very difficult to understand fully, but rather easy to state, because there are several useful shorthands which hide much of the complexity of what is really going on; full details, along with a worked example, can be found in [the accompanying lens](https://arbital.com/p/5t9).

Once we have the intermediate lemma, Rice's theorem itself follows quickly.
Indeed, if the operation of "determine whether a machine computes a function whose graph is in $A$ or not" is computable, then we can do the following procedure:

- Take some computer code as input.
- Determine whether the code specifies a function whose graph is in $A$ or not.
- If it is in $A$, output code for a specific (probably unrelated) function whose graph is *not* in $A$.
- Otherwise, output code for a specific (probably unrelated) function whose graph is in $A$.

The fixed-point theorem tells us that some program isn't changed by the above procedure; but the procedure is guaranteed to interchange programs-from-$A$ with programs-not-from-$A$, so the procedure can't have any fixed points after all.

Jaime Sevilla Molina
Eric Rogstad
Eric Bruylant
Dylan Hendrickson
Patrick Stevens

Summary: Rice's Theorem tells us that for *every* nontrivial property of computable functions, there is no general procedure which takes as its input a Turing machine, and computes whether or not the function computed by that machine has that property. That is, there is no general way to determine anything nontrivial about the output of an arbitrary Turing machine.


Greatest common divisor

There are two ways to define the **greatest common divisor** (also known as **greatest common factor**, or **highest common factor**), both equivalent.

The first definition is as the name suggests: the GCD of $a$ and $b$ is the largest number which divides both $a$ and $b$.

The second definition is the more "mathematical", because it generalises to arbitrary [rings](https://arbital.com/p/3gq) rather than just [ordered rings](https://arbital.com/p/55j).
The GCD of $a$ and $b$ is the number $c$ such that $c \mid a$, $c \mid b$, and whenever $d \mid a$ and $d \mid b$, we have $d \mid c$.
(That is, it is the maximal element of the [https://arbital.com/p/-3rb](https://arbital.com/p/-3rb) that consists of the divisors of $a$ and $b$, ordered by division.)

# Examples

# Equivalence of the definitions

# Relation to prime factorisations

# Calculating the GCD efficiently

Eric Bruylant
Kendrea Beers
Patrick Stevens

Summary: The greatest common divisor of two [natural numbers](https://arbital.com/p/45h) is the largest number which divides both of them.


Metric

A **metric**, sometimes referred to as a distance function, is a [https://arbital.com/p/-3jy](https://arbital.com/p/-3jy) that defines a [real](https://arbital.com/p/-4bc) nonnegative distance between every two elements of a [set](https://arbital.com/p/3jz). It is commonly denoted by the variable $d$. In [https://arbital.com/p/-3vl](https://arbital.com/p/-3vl), a metric $d$ that defines distances between elements of the set $S$ is written:
$$d: S \times S \to [0, \infty)$$

In this case we say $d$ *is a metric on* $S$.

That is, a metric $d$ on a set $S$ takes as input any two elements $a$ and $b$ from $S$ and outputs a number that is taken to define their distance in $S$ under $d$. Apart from being nonnegative real numbers, the distances a metric outputs must follow three other rules in order for the function to meet the definition of a metric. A function that matches the above colon-to notation is called a metric if and only if it satisfies these requirements. The following must hold for any choice of $a$, $b$, and $c$ in $S$:

 1. $d(a, b) = 0 \iff a = b$

 2. $d(a, b) = d(b, a)$

 3. $d(a, b) + d(b, c) \geq d(a, c)$

(1) effectively states both that the distance from an element to itself is 0, and that the distance between non-identical elements must be greater than 0. (2) asserts that a metric must be [commutative](https://arbital.com/p/3jb); informally the distance from $a$ to $b$ must be the same as the distance from $b$ to $a$. Finally, (3) is known as the [https://arbital.com/p/-triangle_inequality](https://arbital.com/p/-triangle_inequality) and asserts that the distance from $a$ to $c$ is at most as large as the sum of the distances from $a$ to $b$ and from $b$ to $c$. It is named as such because in [https://arbital.com/p/euclidean_space](https://arbital.com/p/euclidean_space), the points $a$, $b$, and $c$ form a triangle, and the inequality requires that the length of one side of the triangle is not longer than the sum of the lengths of the other two sides; violating this would mean that the shortest path between two points is no longer the straight line between them.

It is possible (and relatively common!) to deal with multiple different metrics on the same set. This means we are using the same set elements as labels, but treating the distances between elements differently; in this case the different [metric spaces](https://arbital.com/p/metric_space) we are defining may have very different properties. If multiple metrics are being considered, we must be careful when speaking of distances between elements of the set to specify which metric we are using. For example, if $d$ and $e$ are both metrics on $S$, we cannot just say "the distance between $a$ and $b$ in $S$" because it is ambiguous whether we are referring to $d(a, b)$ or to $e(a, b)$. We could instead say something like "the distance between $a$ and $b$ under $e$" to remove the ambiguity.

The most commonly-used metric on Cartesian space is the Euclidean metric, defined in two dimensions as $d(a, b) = \sqrt{(a_1-b_1)^2 + (a_2-b_2)^2}$, and more generally in $n$ dimensions as $d(a, b) = \sqrt{\sum_{i=1}^n (a_i-b_i)^2}$.

A less-common metric on Cartesian space is the Manhattan metric, defined generally as $d(a, b) = \sum_{i=1}^n |a_i-b_i|$; the distance is analogous to the distance taken between two points on a rectangular grid when motion is constrained to be purely vertical or horizontal, but not diagonal.

Bryce Woodworth
Eric Rogstad
Adam Buchbinder
Kevin Clancy

Summary:
Let $S$ be a set. A **metric** on $S$ is a function $d : S \times S \to \mathbb R_{\ge 0}$ such that for all $a,b,c \in S$,

1. $d(a,b) = 0 \Leftrightarrow a = b$
2. $d(a,b) = d(b,a)$
3. $d(a,b) + d(b,c) \geq d(a,c)$

Such a function defines a notion of distance between pairs of elements of $S$.


Solovay's theorems of arithmetical adequacy for GL

One of the things that makes [https://arbital.com/p/-5l3](https://arbital.com/p/-5l3) such an interesting formal system is the direct relation between its theorems and a restricted albeit rich class of theorems regarding [provability predicates](https://arbital.com/p/5j7) in [https://arbital.com/p/3ft](https://arbital.com/p/3ft).

As usual, the adequacy result comes in the form of a pair of theorems, proving respectively [https://arbital.com/p/-soundness](https://arbital.com/p/-soundness) and [https://arbital.com/p/-completeness](https://arbital.com/p/-completeness) for this class. Before stating the results, we describe the way to [translate](https://arbital.com/p/translation)  modal sentences to sentences of arithmetic, thus describing the class of sentences of arithmetic the result alludes to.

##Realizations
A realization $*$ is a function from the set of well-formed sentences of modal logic to the set of sentences of arithmetic. Intuitively, we are trying to preserve the structure of the sentence while mapping the expressions proper of modal logic to related predicates in the language of $PA$.

Concretely,

* $p^* = S_p$: sentence letters are mapped to arbitrary closed sentences of arithmetic.
* $(\square A)^*=P(A^*)$: the box operator is mapped to a [https://arbital.com/p/-5j7](https://arbital.com/p/-5j7) $P$, usually the [https://arbital.com/p/-5gt](https://arbital.com/p/-5gt).
* $(A\to B)^* = A^* \to B^*$: truth functional compounds are mapped as expected.
* $\bot ^* = \neg X$, where $X$ is any theorem of $PA$, for example, $0\ne 1$.

The class of sentences of $PA$ such that there exists a modal sentence of which they are a realization is the set for which we will prove the soundness and completeness.

##Arithmetical soundness
> If $GL\vdash A$, then $PA\vdash A^*$ for every realization $*$.

The applications to this result are endless. For example, this theorem allows us to take advantage of the procedures to calculate [fixed points](https://arbital.com/p/5lx) in $GL$ to get results about $PA$.

To better get an intuition of how this correspondence works, try figuring out how the properties of the [https://arbital.com/p/-5j7](https://arbital.com/p/-5j7) relate to the axioms and rules of inference of $GL$.

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

##Arithmetical completeness
> If $GL\not\vdash A$, then there exists a realization $*$ such that $PA\not\vdash A^*$.

The proof of arithmetical completeness is a beautiful and intricate construction that exploits the semantical relationship between $GL$ and the finite, transitive and irreflexive [Kripke models](https://arbital.com/p/5ll). Check [its page](https://arbital.com/p/) for the details.

##Uniform arithmetical completeness
> There exists a realization $*$ such that for every modal sentence $A$ we have that $GL\not\vdash A$ only if $PA\not\vdash A$.

This result generalizes the arithmetical completeness theorem to a new level.

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

Summary:
$GL\vdash A$ iff $PA\vdash A^*$ for every realization $*$.

Realizations are translations from modal sentences to sentences of arithmetic.


Rice's theorem and the Halting problem

We will show that [Rice's theorem](https://arbital.com/p/5mv) and the [the halting problem](https://arbital.com/p/46h) are equivalent.

#The Halting theorem implies Rice's theorem
Let $S$ be a non trivial set of computable partial functions, and suppose that there exists a Turing machine encoded by $[https://arbital.com/p/n](https://arbital.com/p/n)$ such that:
$$
[n](m) =
\left\{
        \begin{array}{ll}
             1 & [https://arbital.com/p/m](https://arbital.com/p/m) \text{ computes a function in $S$} \\
             0 & \text{otherwise} \\
        \end{array}
    \right.
$$

We can assume [w.l.o.g.](https://arbital.com/p/without_loss_of_generality) that the empty function undefined on every input is not in $S$
%%note:Suppose that the empty function is in $S$. Then it is satisfied that the empty function is **not** in $S^c$, and if $S$ is decidable then it follows immediately that [$S^c$ is decidable as well](https://arbital.com/p/the_complement_of_a_decidable_set_is_decidable). So we can use $S^c$ as our $S$ and the argument follows exactly the same.%%.
Thus there exists a computable function in $S$ computed by some machine $[https://arbital.com/p/s](https://arbital.com/p/s)$ such that $[s](x)$ is defined for some input $x$.

Suppose we want to decide whether the machine $[https://arbital.com/p/m](https://arbital.com/p/m)$ halts on input $[https://arbital.com/p/x](https://arbital.com/p/x)$.

For that purpose we can build a machine $Proxy_s$ which does the following:

    Proxy_s(z):
        call [m](x)
        return s[https://arbital.com/p/z](https://arbital.com/p/z)

Clearly, if $[m](x)$ halts then Proxy_z computes the same function as $[https://arbital.com/p/s](https://arbital.com/p/s)$, and thus $[n](Proxy_s)=1$.

If on the other hand $[m](x)$ does not halt, then Proxy_s(z) computes the empty function, which we assumed to not be in $S$, and therefore $[n](Proxy_s)=0$.

Thus we can use a Turing machine computing pertinence to $S$ to decide the halting problem, which we know is undecidable. We conclude that such a machine cannot possibly exists, and thus Rice's theorem holds.

#Rice's Theorem implies the Halting theorem
Suppose that there was a Turing machine $HALT$ deciding the Halting Problem.

Let $S$ be the set of computable functions defined on a fixed input $x$, which is clearly non-trivial, as it does not contain the empty function but is not empty either. Let $[https://arbital.com/p/n](https://arbital.com/p/n)$ be a Turing machine, and we want to decide whether $[https://arbital.com/p/n](https://arbital.com/p/n)\in S$ or not. If this was possible for an arbitrary $[https://arbital.com/p/n](https://arbital.com/p/n)$, then we would have reached a contradiction, as Rice's theorem forbids this outcome.

But $[https://arbital.com/p/n](https://arbital.com/p/n)$ belongs to $S$ iff $[https://arbital.com/p/n](https://arbital.com/p/n)$ halts on input $x$, so we can use $HALT$ to decide whether $[https://arbital.com/p/n](https://arbital.com/p/n)$ belongs to $S$, in contradiction with Rice's theorem. So our supposition of the existence of $HALT$ was erroneous, and thus the Halting theorem is true.


Modular arithmetic

In ordinary [https://arbital.com/p/-arithmetic](https://arbital.com/p/-arithmetic), you can think of [https://arbital.com/p/-addition](https://arbital.com/p/-addition) and [https://arbital.com/p/-subtraction](https://arbital.com/p/-subtraction) as traveling in different directions along an [infinitely](https://arbital.com/p/infinity) long road.  A calculation like $9 + 6$ can be thought of as starting at kilometer marker 9, then driving for another 6 kilometers, which would bring you to kilometer marker 15 ([https://arbital.com/p/-negative_numbers](https://arbital.com/p/-negative_numbers) are analogous to driving along the road backwards). If the road is perfectly straight, you can never go back to a marker you've already visited by driving forward.  But what if the road were a circle?

Modular arithmetic is a type of addition that's more like driving around in a circle than along an infinite straight line.  In modular arithmetic, you can start with a number, add a positive number to it, and come out with the same number you started with--just as you can drive forward on a circular road to get right back where you started.  If the length of the road were 12, for example, then if you drove 12 kilometers you would wind up right back where you started.  In this case, we would call it *modulus 12* arithmetic, or *mod 12* for short.

Modular arithmetic may seem strange, but in fact, you probably use it every day!  The hours on the face of a clock "wrap around" from 12 to 1 in exactly the same way that a circular road wraps around on itself.  Thus, while in ordinary arithmetic $9 + 6 = 15$, when figuring out what time it will be 6 hours after 9 o'clock, we use modular arithmetic to arrive at the correct answer of 3 o'clock, rather than 15 o'clock.

Eric Rogstad
Mark Chimes
Eric Bruylant
Malcolm McCrimmon
Patrick Stevens

Summary: Modular arithmetic is the type of [https://arbital.com/p/-addition](https://arbital.com/p/-addition) we use when calculating dates and times.  In ordinary [https://arbital.com/p/-arithmetic](https://arbital.com/p/-arithmetic), $9 + 6 = 15$, but when working with the hours of the day, 6 hours after 9 o'clock is 3 o'clock, not 15 o'clock.  This type of "wrap-around" addition generalizes to many other domains.


Partial function

A **partial function** is like a [https://arbital.com/p/-3jy](https://arbital.com/p/-3jy) $f: A \to B$, but where we relax the requirement that $f(a)$ must be defined for all $a \in A$.
That is, it must still be the case that "$a = b$ and $f(a)$ is defined" implies "$f(b)$ is defined and $f(a) = f(b)$", but now we no longer need $f(a)$ to be defined everywhere.
We can write $f: A \rightharpoonup B$ %%note:In LaTeX, this symbol is given by `\rightharpoonup`.%%to denote that $f$ is a partial function with **domain** $A$ and **codomain** $B$: that is, whenever $f(x)$ is defined then we have $x \in A$ and $f(x) \in B$.

This idea is essentially the "flip side" to the distinction between the [https://arbital.com/p/-3lv](https://arbital.com/p/-3lv) dichotomy.

# Implementation in set theory

Just as a function can be implemented as a set $f$ of ordered pairs $(a, b)$ such that:

- every $x \in A$ appears as the first element of some ordered pair in $f$
- if $(a, b)$ is an ordered pair in $f$ then $a \in A$ and $b \in B$
- if $(a, b)$ and $(a, c)$ are ordered pairs in $f$, then $b=c$

so we can define a *partial* function as a set $f$ of ordered pairs $(a,b)$ such that:

- if $(a, b)$ is an ordered pair in $f$ then $a \in A$ and $b \in B$
- if $(a, b)$ and $(a, c)$ are ordered pairs in $f$, then $b=c$

(That is, we omit the first listed requirement from the definition of a *bona fide* function.)

# Relationship to Turing machines

Morally speaking, every [Turing machine](https://arbital.com/p/5pd) $\mathcal{T}$ may be viewed as computing some function $f: \mathbb{N} \to \mathbb{N}$, by defining $f(n)$ to be the state of the tape after $\mathcal{T}$ has been allowed to execute on the tape which has been initialised with the value $n$.

However, if $\mathcal{T}$ does not terminate on input $n$ (for example, it may be the machine "if $n = 3$ then return $1$; otherwise loop indefinitely"), then this "morally correct" state of affairs is not accurate: how should we define $f(4)$?
The answer is that we should instead view $f$ as a *partial* function which is just undefined if $\mathcal{T}$ fails to halt on the input in question.
So with the example $\mathcal{T}$ above, $f$ is the partial function which is only defined at $3$, and $f(3) = 1$.


Turing machine

A Turing Machine is a simple mathematical model of [https://arbital.com/p/-computation](https://arbital.com/p/-computation) that is powerful enough to describe any computation a computer can do.

Imagine a robot, in front of a little whiteboard, with infinitely many whiteboards to both sides, finitely many of which have a symbol written on them. The robot can erase the contents of a whiteboard and replace it with some other symbol, and it can move over to the next whiteboard on the left or right, or shut down. This is all the robot can do. The robot's actions are determined by only two things: the symbol on the whiteboard it just saw, and its internal state. The output of this process is defined to be "whatever is written on the string of whiteboards when the robot has shut down".

This is equivalent to a Turing Machine (with the robot replaced by a machine head and the infinite line of whiteboards replaced by an infinite tape subdivided into cells). The *halting problem* (which [is unsolvable](https://arbital.com/p/halting_problem_is_uncomputable) in general) asks whether the robot will eventually shut down at some point.

So, a Turing Machine can be specified with the following information:

- A finite set of symbols the robot can write (one of which is the null symbol, an empty board).
- A finite set of states the robot can be in (at least one of which causes the robot to shut down).
- A starting state for the robot.
- Starting symbols on finitely many of the boards (whiteboard location and symbol type data).
- A transition function for the robot, which takes a symbol/state pair as input, and has a $(\text{symbol},\text{state},\text{move left or right})$ triple as output. For example, ine such transition might be represented as `if symbol is 7 and state is FQUF, then (erase and write 4, set state to ZEXA, move left)`.

Surprisingly enough, other proposed models of computation have all been shown to be weaker than, or equivalent to, Turing Machines! With infinite memory space, and sufficiently intricate sets of symbols and states, the robot and whiteboard (or machine head and memory tape) system can compute anything at all that is computable in principle!
This fact is known as the Church-Turing thesis; it's very widely believed to be true, and certainly no-one has ever found any hint of a counterexample, but it's not "proved" in any meaningful sense.

# Variants of Turing machines

*Multi-tape Turing Machines* would be equivalent to having several robots in infinite whiteboard hallways, except that the robots are networked together to all share the same state. An example state transition is as follows:

`If symbol A is * and symbol B is 6 and symbol C is absent and state is VREJ, set state to IXXI, robot A writes ! and moves left, robot B writes 9 and moves left, robot C writes = and doesn't move.`

These Multi-tape Machines can speed up some computations polynomially (so, for example, a problem which would normally take 1 million steps to solve may be solvable in a thousand steps, because of the square root speedup). Because these machines can only muster a polynomial speedup, and moving to a one-tape Turing Machine only incurs a polynomial slowdown, the computational [complexity class P](https://arbital.com/p/5pf) is unchanged across Turing Machines with different numbers of tapes.

*Write-only Turing Machines* are Multi-tape Turing Machines where one of the tapes/hallways of whiteboards has its input ignored when determining the next state, written symbols and movements.
We can think of this situation as one where one particular robot is blind.

*Read-only Turing Machines* are Multi-tape Turing Machines, and one of the tapes/hallways of whiteboards cannot be rewritten. The robot in there can only move around and observe, but it has not been given a pen or rubber so it can't write on or erase the boards.

*Oracle Machines* (which are more powerful than Turing Machines, and don't exist in reality, though they are a very useful tool in computational complexity theory), are like a mult-tape machine with exactly two tapes: one tape is designated as the "oracle tape", and one tape as the "machine tape".
This time, one of the robot states is "INVOKING MAGIC ORACLE".
When that happens, the contents of the whiteboards in the machine hall (that is, the contents of the machine tape) are interpreted as the description of a problem, and then a correct solution to the problem magically appears on the string of whiteboards in the oracle hall (that is, on the oracle tape), completely erasing whatever was on the oracle hall whiteboards originally; and finally the oracle robot is moved to the first whiteboard of the answer.

Therefore the functionality of the oracle machine depends very strongly on what the oracle does! A given oracle machine might do one thing when the oracle does "compute the [https://arbital.com/p/-5bv](https://arbital.com/p/-5bv) of the number I was called with" than when it does "compute whether or not the number I was given is the [https://arbital.com/p/-description_number](https://arbital.com/p/-description_number) of a halting Turing machine".

Oracle machines are like ordinary Turing machines, except we also give them the ability (in principle) to obtain instant correct answers to any particular problem. The problem we may instantly solve is fixed in advance, before we ever start running the machine.
With the right oracle, oracle machines can solve *any* problem, where Turing machines cannot (recalling that the halting problem can't be solved by Turing machines).
However, the price is that oracle machines don't exist: they require a magic oracle, and we don't have any of those in nature.

Alexei Andreev
Eric Rogstad
Eric Bruylant
Alex Appel
Eric Leese
Patrick Stevens


P (Polynomial Time Complexity Class)

P is the [class of problems](https://arbital.com/p/problem_class) which can be solved by [algorithms](https://arbital.com/p/algorithm) whose run time is bounded by a [https://arbital.com/p/-polynomial](https://arbital.com/p/-polynomial).


Ordering of rational numbers (Math 0)

So far while learning about [how to combine rational numbers](https://arbital.com/p/514), we have seen [addition](https://arbital.com/p/55m), [subtraction](https://arbital.com/p/56x), [multiplication](https://arbital.com/p/59s) and [division](https://arbital.com/p/5jd).
There is one final major thing we can do to a pair of rational numbers: to *compare* them.
Once you know what you're looking for, it is very easy to compare certain pairs of rational numbers; in this page, we'll look at how to extend that.

Intuitively, if I gave you an apple in one hand, and four apples in the other hand %%note:My hands are rather large.%%, you would be able to tell me that the four-apples hand was holding more apples.
This is the kind of comparison we are trying to generalise, and we will do it from one simple observation.

The observation we will make is that it is very easy to determine whether a rational number is negative or not. %%note:Recall that "negative" meant "it is expressed in anti-apples rather than apples".%% Indeed, we just need to see if we're holding an anti-thing or not.
This might be hard if we have to do some calculations first—for example, it's not immediately obvious whether $\frac{16}{107} - \frac{3}{20}$ is anti- or not—but we'll assume that we've already done all the calculations to reduce an expression down to just a single rational number.
(In this example, we can use the [subtraction techniques](https://arbital.com/p/56x) to work out that $\frac{16}{107} - \frac{3}{20} = -\frac{1}{2140}$. That's obviously negative, because it's got a negative sign out the front.)

To summarise, then, what I have just asserted is that it is easy to see whether a rational number is negative or not; we say that a number which is *positive* %%note:That is, expressed in apples rather than anti-apples.%% is "*greater than $0$*".
Recall that $0$ was the name we gave to the rational number which is "no apples at all"; then what this is saying is that if I have a positive number of apples in one hand, and no apples at all in the other, then according to the intuition earlier, I have more apples in the first hand than in the no-apples hand.
(Hopefully you see that this is true; if not, let us know, because this is one of those strange areas where it's very hard for a mathematician to remember *not* understanding it immediately and intuitively, since we've each been doing this for decades. We're doing our best to remember what parts of the maths are genuinely difficult and weird, but we might get it wrong.)

Similarly, we say that $0$ is *less than* any positive number, and write $0 < \frac{5}{16}$, for instance.
The littler quantity always goes on the littler end of the arrow.
(The number $0$ itself is neither negative nor positive. It's just $0$.
Therefore we can't write $0 < 0$ or $0 > 0$; it's actually the case that $0=0$, and this excludes the other two options of $<$ or $>$.)

# One weird trick to compare any two rationals %%note:Mathematicians hate it!%%

Now that we can compare any rational with $0$, we will work out how to compare any rational with any other rational.

The key insight is that adding the same number of apples %%note:Or anti-apples.%% to each hand should not change the relative fact of whether there are more apples in one hand or the other.
For a real-world example, on a [balance scale](https://commons.wikimedia.org/wiki/File:Balanced_scale_of_Justice.svg) it doesn't matter whether you add five grams or even fifty kilograms onto each of the two pans; the result of the weight comparison will be the same.
(Now you should probably forget the scales metaphor again, because the weight of antimatter behaves in a way that doesn't lend itself nicely to what we're trying to do.)

## Example

So let's say we want to compare $\frac{5}{6}$ and $\frac{3}{4}$.
Which of the two is bigger?

Well, what we can do is add $\frac{3}{4}$ of an anti-apple to both hands.
By the principle that "adding the same amount to each hand doesn't change their quantity relative to each other", the result of the comparison between $\frac{5}{6}$ and $\frac{3}{4}$ is just the same as the result of the comparison between $\frac{5}{6} - \frac{3}{4}$ and $\frac{3}{4} - \frac{3}{4}$: that is, between $\frac{1}{12}$ and $0$.
That's easy, though, since we already know how to compare $0$ with anything!

So $\frac{5}{6}$ is bigger than $\frac{3}{4}$, since $\frac{1}{12}$ is bigger than $0$: we write $\frac{5}{6} > \frac{3}{4}$.

## Comparisons with anti-apples

In this section, we will just close our eyes, swallow grimly, and hope for the best.

If we want to compare $-\frac{59}{12}$ and $\frac{4}{7}$, what should happen?
If you already have the right intuition built in, then this will be obvious, but before you know how to do it, it's really not clear at all.
After all, $-\frac{59}{12}$ is "a large amount of anti-apple" (it's nearly five whole anti-apples!) but $\frac{4}{7}$ is "a small amount of apple" (not even one whole apple).

Here's where the "close our eyes" happens.
Let's just go by the principle that adding the same amount of apple to both hands shouldn't change anything, and we'll add $\frac{59}{12}$ apples to both sides.

Then the $-\frac{59}{12}$ becomes $0$, and the $\frac{4}{7}$ becomes the rather gruesome $\frac{461}{84}$. %%note:This is all good practice for you to get fluent with adding and subtracting.%%
But we already know how to compare $0$ with things, so we can see that $\frac{461}{84}$ is bigger than $0$.

Therefore we must have $\frac{4}{7}$ being bigger than $-\frac{59}{12}$.

By the same token, *any* amount of anti-apple is always less than *any* amount of apple, and indeed any amount of anti-apple is always less than $0$.

## Another example

How about comparing $\frac{-3}{5}$ and $\frac{9}{-11}$?
The first thing to do is to remember that we can take the minus signs outside the fractions, because an anti-chunk of apple is the same as a chunk of anti-apple.

That is, we are trying to compare $-\frac{3}{5}$ and $-\frac{9}{11}$.

Add $\frac{3}{5}$ to both, to compare $0$ and $-\frac{9}{11} + \frac{3}{5} = -\frac{12}{55}$.

Add $\frac{12}{55}$ to both again, to compare $\frac{12}{55}$ and $0$.

Clearly the $\frac{12}{55}$ is bigger, so it must be that $\frac{-3}{5}$ is bigger than $\frac{9}{-11}$.

## Instant rule

Just as we had an [instant rule for addition](https://arbital.com/p/55m), so we can make an instant rule for comparison.

If we want to see which of $\frac{a}{b}$ and $\frac{c}{d}$ is bigger, it is enough to see which of $0$ and $\frac{c}{d} - \frac{a}{b}$ is bigger.

But $$\frac{c}{d} - \frac{a}{b} = \frac{c \times b - a \times d}{b \times d}$$

Sadly from this point there are actually two cases to consider, because we might have produced something that looks like any of the following:

- $\frac{5}{6}$
- $\frac{-4}{7}$
- $\frac{3}{-8}$
- $\frac{-2}{-9}$

(That is, there could be minus-signs scattered all over the place.)

However, there is a way to get around this, and it hinges on the fact from the [Division page](https://arbital.com/p/5jd) that $\frac{-1}{-1} = 1$.

If $b$ is negative, then we can just write $\frac{a}{b} = \frac{-a}{-b}$, and now $-b$ is positive!
For example, $\frac{5}{-6}$ has $b=-6$; then that is the same as $\frac{-5}{6}$.
Similarly, $\frac{-7}{-8}$ is the same as $\frac{7}{8}$.

Likewise we can always write $\frac{c}{d}$ so that the numerator is positive: as $\frac{-c}{-d}$ if necessary.

So, we have four cases:

- If $b, d$ are both positive, then $\frac{c \times b - a \times d}{b \times d}$ is positive precisely when $c \times b - a \times d$ is positive as an integer; i.e. when $cb > ad$.
- If $b$ is positive and $d$ is negative, then $$\frac{c}{d} - \frac{a}{b} = \frac{-c}{-d} - \frac{a}{b} = \frac{(-c) \times b - a \times (-d)}{b \times (-d)}$$ where the denominator %%note:Remember, that's the thing on the bottom of the fraction: in this case, $b \times (-d)$.%% is positive.

## Why did I say "Mathematicians hate it"?%%note:Aside from parodying Internet banner ads, that is.%% A diversion on pedagogy

The way I've done this is all completely correct, but it's slightly backwards from the way a mathematician would usually present it.
(Not sufficiently backwards that mathematicians should hate it, but I couldn't resist.)

Usually, when *finding* a way of comparing objects, mathematicians would probably do what we've done above: find an easy way of comparing some of the objects, and then try to extend it to cover all the objects.

But if a mathematician *already knows* a way of comparing objects and is just writing it down for the benefit of other mathematicians, they would usually write down the complete "cover all the objects" method right at the start, and would then go on to show that it does indeed cover all the objects and has all the right properties.

This has the benefit of producing very terse descriptions with the minimum necessary amount of writing; but it's very *bad* at helping other people understand where it came from.
If you know where something came from, you stand a better chance of being able to recreate it yourself if you forget the bottom line, and you might well remember the bottom line better, too.
This is why we've done it slightly backwards here.

Summary: "Ordering" is the idea that some quantities of apple are "bigger" than others.