Multi-Eulerian tours of directed graphs

Abstract: Not every graph has an Eulerian tour. But every finite, strongly connected graph has a multi-Eulerian tour, which we define as a closed path that uses each directed edge at least once, and uses edges e and f the same number of times whenever tail(e)=tail(f). This definition leads to a simple generalization of the BEST Theorem. We then show that the minimal length of a multi-Eulerian tour is bounded in terms of the Pham index, a measure of 'Eulerianness'.

\section*{#1}}
\newcommand{\silentsubsec}[1]{\addtocontents{toc}{\SkipTocEntry}\subsection*{#1}}

\hyphenation{qua-si-ran-dom}
\hyphenation{Schutz-en-ber-ger}
\hyphenation{com-mut-at-iv-ity}

\newtheorem{thm}{Theorem}
\newtheorem{prop}[thm]{Proposition}
\newtheorem{proc}[thm]{Procedure}
\newtheorem{lem}[thm]{Lemma}
\newtheorem{cor}[thm]{Corollary}
\newtheorem{conjecture}[thm]{Conjecture}

\theoremstyle{remark}
\newtheorem*{remark}{Remark}
\newtheorem*{example}{Example}

\newcounter{counter}
\numberwithin{counter}{section}

\theoremstyle{definition}
\newtheorem{defn}{Definition}

\def\mathop{\rm lim\,inf}\limits{\mathop{\rm lim\,inf}\limits}
\def\mbox{mod }{\mbox{mod }}

\def\simeq{\simeq}
\def\mbox{outdeg}{\mbox{outdeg}}
\def\mbox{indeg}{\mbox{indeg}}
\def\mbox{\scriptsize indeg}{\mbox{\scriptsize indeg}}
\def\mbox{\scriptsize vertex}{\mbox{\scriptsize vertex}}
\def\mbox{\scriptsize edge}{\mbox{\scriptsize edge}}
\defs{s}
\deft{t}
\defs{s}
\deft{t}
\def{\mbox{\scriptsize root}}{{\mbox{\scriptsize root}}}
\def{\scriptsize \mbox{ spans }}{{\scriptsize \mbox{ spans }}}
\def\mbox{Im}{\mbox{Im}}
\def\mbox{Id}{\mbox{Id}}
\def\mathbf{a}{\mathbf{a}}
\def\mathbf{b}{\mathbf{b}}
\def\mathbf{d}{\mathbf{d}}
\def\mathbf{m}{\mathbf{m}}
\def\mathbf{n}{\mathbf{n}}
\def\mathbf{q}{\mathbf{q}}
\def\mathbf{r}{\mathbf{r}}
\def\mathbf{s}{\mathbf{s}}
\def\mathbf{t}{\mathbf{t}}
\def\mathbf{u}{\mathbf{u}}
\def\mathbf{v}{\mathbf{v}}
\def\mathbf{w}{\mathbf{w}}
\def\mathbf{x}{\mathbf{x}}
\def\mathbf{y}{\mathbf{y}}
\def\mathbf{z}{\mathbf{z}}
\def\mathbf{0}{\mathbf{0}}
\def\mathbf{1}{\mathbf{1}}
\def\mathbf{m}{\mathbf{m}}
\def\mathbf{k}{\mathbf{k}}
\def\widetilde{\widetilde}

\defN{N}
\def\mathbb{N}{\mathbb{N}}
\def\mathbb{Z}{\mathbb{Z}}
\def\mathbb{Q}{\mathbb{Q}}
\def\mathbb{R}{\mathbb{R}}
\def\mathbb{E}{\mathbb{E}}
\def\mathbb{P}{\mathbb{P}}
\def\epsilon{\epsilon}
\def\mathcal{L}{\mathcal{L}}

\begin{document}

\title[]{Multi-Eulerian tours of directed graphs}

\author{Matthew Farrell and Lionel Levine}

\thanks{This research was supported by NSF grant \href{http://www.nsf.gov/awardsearch/showAward?AWD_ID=1455272}{DMS-1455272} and a Sloan Fellowship.}
\address{Matthew Farrell, Department of Mathematics, Cornell University, Ithaca, NY 14850. msf235@cornell.edu}
\keywords{chip-firing, critical group, Eulerian digraph, Laplacian lattice, oriented spanning tree, period vector, Pham index, sandpile group}
\address{Lionel Levine, Department of Mathematics, Cornell University, Ithaca, NY 14850. \url{http://www.math.cornell.edu/~levine/}}

\date{September 21, 2015}
\keywords{BEST theorem, coEulerian digraph, Eulerian digraph, Laplacian, Markov chain tree theorem, oriented spanning tree, period vector, Pham index}
\subjclass[2010]{
05C05,
05C20,
05C30,
05C45,
05C50}

\begin{abstract}
Not every graph has an Eulerian tour. But every finite, strongly connected graph has a \emph{multi-Eulerian tour}, which we define as a closed path that uses each directed edge at least once, and uses edges $e$ and $f$ the same number of times whenever $\mathrm{tail}(e)=\mathrm{tail}(f)$.
This definition leads to a simple generalization of the BEST Theorem. We then show that the minimal length of a multi-Eulerian tour is bounded in terms of the Pham index, a measure of `Eulerianness'.
\end{abstract}

\maketitle

In the following $G=(V,E)$ denotes a finite directed graph, with loops and multiple edges permitted. We assume throughout that $G$ is \textbf{strongly connected}: for each $v,w \in V$ there are directed paths from $v$ to $w$ and from $w$ to $v$. An \textbf{Eulerian tour} of $G$ is a closed path that traverses each directed edge exactly once.
Such a tour exists if and only if the indegree of each vertex equals its outdegree; the graphs with this property are called \textbf{Eulerian}.
The BEST theorem (named for its discoverers: de Bruijn, Ehrenfest, Smith and Tutte) counts the number of such tours.
The purpose of this note is to generalize the notion of Eulerian tour and the BEST theorem to any finite, strongly connected graph $G$.

\begin{defn} Fix a vector $\pi \in \mathbb{N}^V$ with all entries strictly positive. A \textbf{$\pi$-Eulerian tour} of $G$ is a closed path that uses each directed edge $e$ of $G$ exactly $\pi_{\mathrm{tail}(e)}$ times.
\end{defn}

We will see shortly that every strongly connected $G$ has a $\pi$-Eulerian tour for suitable $\pi$, and count the number of such tours. To do so, recall the BEST theorem counting $\mathbf{1}$-Eulerian tours of an Eulerian directed multigraph $G$. Write $\epsilon_\pi(G,e)$ for the number of $\pi$-Eulerian tours of $G$ starting with a fixed edge $e$.

\begin{thm} \emph{(BEST \cite{EdB51,TS})}
A finite, strongly connected multigraph $G$ has a $\mathbf{1}$-Eulerian tour if and only if the indegree of each vertex equals its outdegree, in which case the number of such tours starting with a fixed edge $e$ is
	\[ \epsilon_\mathbf{1}(G,e) =
	\kappa_w \prod_{v \in V} (d_v -1)! \]
where $d_v$ is the outdegree of $v$; vertex $w$ is the tail of edge $e$, and $\kappa_w$ is the number of spanning trees of $G$ oriented toward $w$.
\end{thm}

The \textbf{graph Laplacian} is the $V \times V$ matrix
	\[ \Delta_{uv} = \begin{cases} d_v - d_{vv}, & u=v \\
							-d_{vu} & u \neq v \end{cases} \]
where $d_{vu}$ is the number of edges directed from $v$ to $u$, and $d_v = \sum_u d_{vu}$ is the outdegree of $v$.  Observing that the `indegree$=$outdegree' condition above is equivalent to $\Delta \mathbf{1} = \mathbf{0}$ where $\mathbf{1}$ is the all ones vector, we arrive at the statement of our main result.

\begin{thm}
\label{t.BETTER}
Let $G=(V,E)$ be a strongly connected directed multigraph with Laplacian $\Delta$, and let $\pi \in \mathbb{N}^V$. Then $G$ has a $\pi$-Eulerian tour if and only if
	\[ \Delta \pi = \mathbf{0}. \]
If $\Delta \pi = \mathbf{0}$, then the number of $\pi$-Eulerian tours starting with edge $e$ is given by
\[
\epsilon_\pi(G,e)= \kappa_w \prod_{v\in V} \frac {(d_{v}\pi_v-1)!}{(\pi_v!)^{d_{v}-1}(\pi_v-1)!}
\]
where $d_v$ is the outdegree of $v$; vertex $w$ is the tail of edge $e$, and $\kappa_w$ is the number of spanning trees of $G$ oriented toward $w$.
\end{thm}

Note that the ratio on the right side is a multinomial coefficient and hence an integer.
Next we turn to the proof, which is a straightforward application of the BEST theorem. The same device of constructing an Eulerian multigraph from a strongly connected graph was used in \cite[Theorem~3.18]{AB} to relate the Riemann-Roch property of `row chip-firing' to that of `column chip firing'.

\begin{proof}
Define a multigraph $\tilde{G}$ by replacing each edge $e$ of $G$ from $u$ to $v$ by $\pi_u$ edges $e^1,\ldots,e^{\pi_u}$ from $u$ to $v$. Each vertex $v$ of $\tilde{G}$ has outdegree $d_v \pi_v$ and indegree $\sum_{u \in V} \pi_u d_{uv}$, so $\tilde{G}$ is Eulerian if and only if $\Delta \pi = \mathbf{0}$.

If $(e_1^{i_1}, \ldots, e_m^{i_m})$ is a $\mathbf{1}$-Eulerian tour of $\tilde{G}$, then $(e_1, \ldots, e_m)$ is a $\pi$-Eulerian tour of $G$. Conversely, for each $\pi$-Eulerian tour of $G$ beginning with a fixed vertex $w$, the occurrences of each edge $e$ in the tour can be labeled with an arbitrary permutation of $\{1,\ldots,\pi_{\mathrm{tail}(e)}\}$ to obtain a $\mathbf{1}$-Eulerian tour of $\tilde G$. Hence
	\[ \epsilon_\mathbf{1}(\tilde{G},w) = \epsilon_\pi(G,w) \prod_{v \in V} (\pi_v!)^{d_v}. \]
In particular, $G$ has a $\pi$-Eulerian tour if and only if $\tilde G$ is Eulerian.

To complete the counting in the case when $\tilde G$ is Eulerian, the BEST theorem gives the number of Eulerian tours of $\tilde{G}$ starting with a fixed edge $e^1$ with tail $w$, namely
	\[ \epsilon_\mathbf{1}(\tilde{G},e^1) = \tilde{\kappa}_w \prod_{v \in V} (d_v \pi_v - 1)!. \]
where
	\begin{equation} \label{e.tildekappa} \tilde \kappa_w = \kappa_w \prod_{v \neq w} \pi_v  \end{equation}
is the number of spanning trees of $\tilde G$ oriented toward $w$,
since each spanning tree of $G$ oriented toward $w$ gives rise to $\prod_{v \neq w} \pi_v$ spanning trees of $\tilde G$.

By cyclically shifting the tour, the number of $\pi$-Eulerian tours of $G$ starting with a given edge $e=(w,v)$ does not depend on $v$. Hence
	\[ \frac{\epsilon_\pi(G,e)}{\epsilon_\pi(G,w)} = \frac{1}{d_w}, \qquad \frac{\epsilon_\mathbf{1}(\tilde{G}, e^1)}{\epsilon_\mathbf{1}(\tilde{G},w)} = \frac{1}{d_w \pi_w}. \]
We conclude that
	\begin{align*} \epsilon_\pi(G,e)
					&= \frac{1}{d_w} (d_w\pi_w) \tilde{\kappa}_w \prod_{v \in V} \frac{(d_v \pi_v -1)!}{(\pi_v !)^{d_v}}
	\end{align*}
which together with \eqref{e.tildekappa} completes the proof.
\end{proof}

The watchful reader must now be wondering, is there a suitable vector $\pi$ with \emph{positive integer} entries in the kernel of the Laplacian? The answer is yes. Following Bj\"{o}rner and Lov\'{a}sz, we say that a vector $\mathbf{p} \in \mathbb{N}^V$ is a \textbf{period vector} for $G$ if $\mathbf{p} \neq \mathbf{0}$ and $\Delta\mathbf{p}=\mathbf{0}$. A period vector is \textbf{primitive} if the greatest common divisor of its entries is $1$.

\old{
\begin{defn} \cite{BL92}
Given a graph $G$ with Laplacian $\Delta$, a vector $\mathbf{p}\in\mathbb{N}^{n}$
is called a \textbf{period vector} for $G$ if $\mathbf{p} \neq \mathbf{0}$ and $\Delta\mathbf{p}=\mathbf{0}$.
A period vector is \textbf{primitive} if the greatest common divisor of its entries is $1$.
\end{defn}

The following lemma sums up some useful properties of period vectors.
}

\begin{lem} \cite[Prop.\ 4.1]{BL92}
\label{lem:period}
A strongly connected multigraph $G$ has a unique primitive period vector $\pi_{G}$. All entries of $\pi_G$ are strictly positive, and all period vectors of $G$ are of the form $n\pi_{G}$ for $n=1,2,\ldots$.
Moreover, if $G$ is Eulerian, then $\pi_{G}=\mathbf{1}$.
\end{lem}

Let $\kappa_v$ denote the number of spanning trees of $G$ oriented toward $v$.
Broder \cite{Broder} and Aldous \cite{Aldous} observed that $\kappa$ is a period vector!  This result is sometimes called the `Markov chain tree theorem'.

\begin{lem}[\cite{Aldous,Broder}]
\label{lem:kerper} $\Delta \kappa = \mathbf{0}$.
\end{lem}

Lemmas \ref{lem:period} and \ref{lem:kerper} imply that the vector $\pi=\frac{1}{M_G} \kappa$ is the unique primitive period vector of $G$, where
	\[ M_G = \gcd \{ \kappa_v \,:\, v \in V\} \]
is the greatest common divisor of the oriented spanning tree counts.
Our next result expresses the minimal length of a multi-Eulerian tour in terms of $M_G$ and the number
	\[ U_G = \sum_{v \in V} \kappa_v d_v \]
of \textbf{unicycles} in $G$ (that is, pairs $(t,e)$ where $t$ is an oriented spanning tree and $e$ is an outgoing edge from the root of $t$).

\begin{thm}
\label{t.minimal}
The minimal length of a multi-Eulerian tour in $G$ is $U_G/M_G$.
\end{thm}

\begin{proof} The length of a $\pi$-Eulerian tour is $\sum_{v \in V} \pi_v d_v$. By Theorem~\ref{t.BETTER} along with Lemmas~\ref{lem:period} and~\ref{lem:kerper}, there exists a $\pi$-Eulerian tour if and only if $\pi$ is a positive integer multiple of the primitive period vector $\frac{1}{M_G} \kappa$. The result follows.
\end{proof}

A special class of multi-Eulerian tours are the simple rotor walks \cite{PDDK,WLB,HLMPPW,HP,Trung}. In a \textbf{simple rotor walk}, the successive exits from each vertex repeatedly cycle through a given cyclic permutation of the outgoing edges from that vertex.  If $G$ is Eulerian then a simple rotor walk on $G$ eventually settles into an Eulerian tour which it traces repeatedly.  More generally, if $G$ is strongly connected then a simple rotor walk eventually settles into a $\pi$-Eulerian tour where $\pi$ is the primitive period vector of $G$.

Trung Van Pham introduced the quantity $M_G$ in \cite{Trung} in order to count orbits of the rotor-router operation. In \cite{coEulerian} we have called $M_G$ the \textbf{Pham index} of $G$ and studied the graphs with $M_G=1$, which we called \textbf{coEulerian graphs}. The significance of $M_G$ is not readily apparent from its definition, but we argue in \cite{coEulerian} that $M_G$ measures `Eulerianness'. Theorem~\ref{t.minimal} makes this explicit, in that the minimal length of a multi-Eulerian tour depends inversely on $M_G$.

Multi-Eulerian tours of directed graphs


Parity and Partition of the Rational Numbers

Abstract: We define an extension of parity from the integers to the rational numbers. Three parity classes are found -- even, odd and `none'. Using the 2-adic valuation, we partition the rationals into subgroups with a rich algebraic structure. The natural density provides a means of distinguishing the sizes of countably infinite sets. The Calkin-Wilf tree has a remarkably simple parity pattern, with the sequence `odd/none/even' repeating indefinitely. This pattern means that the three parity classes have equal natural density in the rationals. A similar result holds for the Stern-Brocot tree.

\section{Parity.}
\label{sec:parity}

The distinction between odd and even numbers is called \emph{parity}.
The even/odd concept is defined only for the integers. The distinction
does not apply to fractions or irrational
numbers, but one may wonder if there is a natural way to extend the
concept of  parity to larger sets of numbers.

What characteristics might one require of such an extension?  The
definition would have to agree with the traditional definition for the
integers, so $5$ would continue to be odd and $10$ even. In addition,
the usual `rules of parity' might be required:
\begin{enumerate}
\item The sum of two even numbers is even; the product is even.
\item The sum of two odd numbers is even; the product is odd.
\item The sum of an even and an odd number is odd; the product is even.
\item An odd number plus $1$ is even; an even number plus $1$ is odd.
\end{enumerate}
Table \ref{tab:AddMultZ} shows the effects of addition and multiplication
on the ring of integers.

\begin{table}
\begin{center}
\caption{Addition table (left) and multiplication table (right) for $\mathbb{Z}$.}
\label{tab:AddMultZ}

\bigskip
\begin{minipage}[c]{0.45\textwidth}
\begin{center}
\begin{tabular}{||c||c|c||}

\hline \hline
        $\boldsymbol{+}$    &   $\mathbf{even}$  &  $\mathbf{odd}$  \\
\hline \hline
   $\mathbf{even}$   &   $even$  &  $odd$  \\
   $\mathbf{odd}$     &   $odd$   &  $even$  \\
\hline  \hline

\end{tabular}
\end{center}
\end{minipage}
\begin{minipage}[c]{0.45\textwidth}
\begin{center}
\begin{tabular}{||c||c|c||}

\hline \hline
   $\boldsymbol{\times}$       &   $\mathbf{even}$  &    $\mathbf{odd}$  \\
\hline \hline
       $\mathbf{even}$     &   $even$  &  $even$  \\
       $\mathbf{odd}$       &  $even$    &  $odd$  \\
  \hline  \hline

\end{tabular}
\end{center}
\end{minipage}
\end{center}
\end{table}

If the concept of parity is extended to larger sets of numbers,
some of the properties indicated above may have to be sacrificed.
For rational numbers, we might define a number $q=m/n$ to be even
if the numerator $m$ is even and odd if $m$ is odd. But
then $\frac{1}{4}+\frac{1}{4} = \frac{1}{2}$,
meaning that two odd rationals would add to yield another odd one.

We will distinguish between `odd' and `uneven' rationals:
assuming $m$ and $n$ to be relatively prime integers, $(m,n)=1$,
we will adopt the following definition:
\begin{equation}
\mbox{For any rational number\ } q=\frac{m}{n} \,,
\quad
\begin{cases}
q \ \mbox{is \emph{even} if $m$ is even}, \\
q \ \mbox{is \emph{uneven} if $m$ is odd} \,.
\end{cases}
\label{eq:def1}
\end{equation}

\section*{A three-way split.}
\label{sec:3way}

There is a simple way of separating the rational numbers into three subsets:
\begin{equation}
\mbox{For any rational\ } q=\frac{m}{n} \,,
\quad
\begin{cases}
q \ \mbox{has parity \emph{even} if $m$ is even and $n$ is odd,} \\
q \ \mbox{has parity \emph{odd} if $m$ is odd and $n$ is odd,} \\
q \ \mbox{has parity \emph{none} if $m$ is odd and $n$ is even.}
\end{cases}
\label{eq:def2}
\end{equation}
The term \emph{none} is an initialism for `neither odd nor even'.
Corresponding to this three-way partition, we define three subsets of the rationals:
\begin{eqnarray*}
\mbox{Even:\ \ }
\mathbb{Q}_\mathrm{E} &=& \{ q\in\mathbb{Q} :
q = \textstyle{\frac{2m}{2n+1}\ \mbox{for some}\ m,n\in\mathbb{Z}} \} \\
\mbox{Odd:\ \ }
\mathbb{Q}_\mathrm{O} &=& \{ q\in\mathbb{Q} :
q = \textstyle{\frac{2m+1}{2n+1}\ \mbox{for some}\ m,n\in\mathbb{Z}} \} \\
\mbox{None:\ \ }
\mathbb{Q}_\mathrm{N} &=& \{ q\in\mathbb{Q} :
q = \textstyle{\frac{2m+1}{2n}\ \mbox{for some}\ m,n\in\mathbb{Z}} \} \,.
\end{eqnarray*}
These three sets are mutually disjoint and
$\mathbb{Q} = \mathbb{Q}_\mathrm{E} \uplus \mathbb{Q}_\mathrm{O} \uplus \mathbb{Q}_\mathrm{N}$.
It is immediately obvious that $\mathbb{Z}_\mathrm{E} \subset \mathbb{Q}_\mathrm{E}$ and
$\mathbb{Z}_\mathrm{O} \subset \mathbb{Q}_\mathrm{O}$, confirming that the definition of parity
for the rationals is an extension of the usual meaning for the integers.
We see that the even and odd rationals
respect the four `rules of parity' listed above.

\subsection{``Twice as many uneven as even fractions''.}
\label{sec:twiceasmany}

The rational numbers are countable: they can be put into one-to-one
correspondence with the natural numbers.  We can list all rationals
in $(0,1)$ in a sequence where, for each $n$ in turn, all (new) numbers
$m/n$ with $m < n$ are listed in order. For $n_\mathrm{max}=8$ we have
\begin{eqnarray}
\bigl\{
\textstyle{
\frac{1}{2},\frac{1}{3},\frac{2}{3},\frac{1}{4},\frac{3}{4},
\frac{1}{5},\frac{2}{5},\frac{3}{5},\frac{4}{5},\frac{1}{6},\frac{5}{6},
\frac{1}{7},\frac{2}{7},\frac{3}{7},\frac{4}{7},\frac{5}{7},\frac{6}{7},
\frac{1}{8},\frac{3}{8},\frac{5}{8},\frac{7}{8}}
\bigr\} \,.
\label{eq:farish}
\end{eqnarray}
Rearrangement in increasing order of magnitude gives the Farey sequence $F_8$.

A \textsc{Mathematica} program was written to count the proportion
of rationals in each parity class in the interval $(0,1)$,
with denominators less than or equal to $n$, for a range of cut-off values
$n \le n_\mathrm{max}$.  The ratios are plotted in Fig.~\ref{fig:pratio20}.
As $n$ increases, the ratios of numbers with parity even, odd and none all
tend to the limit $\frac{1}{3}$.
Colloquially, there are an equal number of rationals with parity even, odd and none,
and ``twice as many uneven as even rationals''.
\begin{figure}[h]
\begin{center}
\includegraphics[width=0.95\textwidth]{./Parity-ratios-20-COL.jpg}
\caption{Parity ratio $r$ for rationals $m/n$ of parity even (solid line, blue online),
odd (dashed line, red online) and none (dotted line, black online) for $n\le n_{\mathrm{max}}=20$.}
\label{fig:pratio20}
\end{center}
\end{figure}

\section{The Density of subsets of $\mathbb{N}$.}
\label{sec:density}

In pure set-theoretic terms, the set of even positive numbers is ``the same size''
as the set of all natural numbers; both are infinite countable sets.  However,
cardinality is a blunt instrument: with the usual ordering, every second natural number
is even and, intuitively, we feel that there are half as many even numbers as natural numbers.
The concept of \emph{density} provides a means of expressing the relative sizes
of sets that is more discriminating than cardinality.

Density --- also called natural or asymptotic density --- is defined for many
interesting subsets of $\mathbb{N}$, although not for all subsets. Assume a
subset $A$ of $\mathbb{N}$ is enumerated as $\{a_1, a_2, \dots \}$.
We define the density of $A$ in $\mathbb{N}$ as the limit, if it exists,
\begin{equation}
\rho_\mathbb{N}(A) = \lim_{n\to\infty}\ \frac{|\{a_k : a_k\le n\}|} {n} \,.
\label{eq:defdenN}
\end{equation}
Thus, if the fraction of elements of $A$ among the first $n$ natural numbers
converges to a limit $\rho_\mathbb{N}(A)$ as $n$ tends to infinity, then $A$
has density $\rho_\mathbb{N}(A)$ \cite{Te}.
More generally, if $A = \{a_1, a_2, a_3, \dots \}$
is a subset of a countable set $X$ enumerated as
$\{x_1,x_2,x_3, \dots \}$, we define
the density of $A$ in $X$ --- if it exists --- as
\begin{equation}
\rho_{X}(A) = \lim_{n\to\infty}\ \frac{|A\cap \{x_1, x_2, \dots ,  x_n\}|}{n} \,.
\label{eq:defdenZ}
\end{equation}
For $X = \mathbb{N}$, we usually write $\rho_\mathbb{N}(A)$ as $\rho(A)$.
For $A = \mathbb{N}_\mathrm{E}$ or $A = \mathbb{N}_\mathrm{O}$, we have $\rho(A) = \textstyle{\frac{1}{2}}$, as might be expected.
This is consistent with our intuitive notion that $50\%$ of the natural numbers
are even and $50\%$ are odd.

Let us now rearrange the natural numbers into a set $F$ such that there are
\emph{twice as many even as odd numbers in $F$}.
We reorder $\mathbb{N}$ so that each odd number is followed by two even ones:
$$
F = \{ 1, 2, 4, 3, 6, 8, 5, 10, 12,\ \dots\ , 2n-1, 4n-2, 4n, \dots \} \,.
$$
It is easy to see that $\rho_F(\mathbb{N}_\mathrm{E}) = \frac{2}{3}$ and $\rho_F(\mathbb{N}_\mathrm{O}) = \frac{1}{3}$.
Proceeding further, we can construct a set $H$ in which the $n$-th odd number is followed by
$n$ even numbers.  We find that $\rho_H(\mathbb{N}_\mathrm{E})=1$,
so that ``almost all the elements of $H$ are even''.

These examples make it clear that density depends strongly on the ordering of the reference set.
Our intuition is guided by the usual (natural) ordering of the natural numbers and the alternation
between odd and even numbers leads us to the conclusion that, somehow, they are equal in number,
each comprising ``half'' of the set of natural numbers. Density relative to $\mathbb{N}$ is consistent
with this intuition.

With the ordering $\{0, +1, -1, +2, -2, \ldots \}$ of the integers,
the densities defined by (\ref{eq:defdenZ}) are
$$
\rho_\mathbb{Z}(\mathbb{Z}_\mathrm{E}) = \textstyle{\frac{1}{2}} \,, \qquad \rho_\mathbb{Z}(\mathbb{Z}_\mathrm{O}) = \textstyle{\frac{1}{2}} \,.
$$
We will prove that, for the rational numbers with the Calkin-Wilf and
Stern-Brocot orderings defined below,
\begin{equation}
\rho_\mathbb{Q}(\mathbb{Q}_\mathrm{E}) = \rho_\mathbb{Q}(\mathbb{Q}_\mathrm{O}) = \rho_\mathbb{Q}(\mathbb{Q}_\mathrm{N}) = \tfrac{1}{3} \,.
\label{eq:DenOneThird}
\end{equation}

\section{Partitioning the rationals.}
\label{sec:paritioning}

\begin{table}[h]
\begin{center}
\caption{Addition table (left) and multiplication table (right) for $\mathbb{Q}$.
The entry `\emph{any}' indicates that the result may be in any of the three parity classes.}
\label{tab:qaddmul}

\bigskip
\begin{minipage}[c]{0.45\textwidth}
\begin{center}
\begin{tabular}{||c||c|c||c||}
   \hline \hline
   $\boldsymbol{+}$      &   $\mathbf{even}$  &  $\mathbf{odd}$   &  \cellcolor{Gray}  $\mathbf{none}$  \\
   \hline \hline
   $\mathbf{even}$   &   $even$  &  $odd$   &  \cellcolor{Gray}  $none$  \\
   $\mathbf{odd}$    &   $odd$   &  $even$  &   \cellcolor{Gray}  $none$  \\
   \hline\hline
  \cellcolor{Gray}   $\mathbf{none}$   &  \cellcolor{Gray}   $none$  &  \cellcolor{Gray}  $none$  &  \cellcolor{Gray}  $\underline{any}$  \\
   \hline \hline
\end{tabular}
\end{center}
\end{minipage}
\hspace{3mm}
\begin{minipage}[c]{0.45\textwidth}
\begin{center}
\begin{tabular}{||c||c|c||c||}
   \hline \hline
   $\boldsymbol{\times}$  &  $\mathbf{even}$   &   $\mathbf{odd}$   &  \cellcolor{Gray}  $\mathbf{none}$  \\
   \hline \hline
   $\mathbf{even}$    &  $even$   &   $even$  & \cellcolor{Gray}   $\underline{any}$   \\
   $\mathbf{odd}$     &  $even$   &   $odd$   &  \cellcolor{Gray}  $none$  \\
   \hline\hline
  \cellcolor{Gray}   $\mathbf{none}$    &   \cellcolor{Gray}  $\underline{any}$   &  \cellcolor{Gray}   $none$  &  \cellcolor{Gray}  $none$  \\
   \hline \hline
\end{tabular}
\end{center}
\end{minipage}

\end{center}
\end{table}

In Table~\ref{tab:qaddmul} we show the results of adding and multiplying
numbers from the three parity classes.  The most important thing
to notice is that, if we confine attention to only the even and odd
rationals, the tables are identical to the addition and multiplication
tables for $\mathbb{Z}$ (Table~\ref{tab:AddMultZ}).  The entry
\emph{``any''} in the tables indicates a number that is a ratio of two
even numbers and that may, after reduction, be in any of the
three parity classes.
Examining the left panel of Table~\ref{tab:qaddmul}, we see that $(\mathbb{Q}_\mathrm{E},+)$
is an additive (normal) subgroup of $(\mathbb{Q},+)$.
In Table~\ref{tab:qaddmul} (right panel) we show the results of
multiplying numbers from the three parity classes.
Restricting attention to the even and odd rationals only --- omitting those with
no parity --- we define
\begin{equation}
\mathbb{Q}_\mathrm{P} := \mathbb{Q}_\mathrm{E} \uplus \mathbb{Q}_\mathrm{O}  \,.
\end{equation}
This is the set of all rationals whose denominators are odd numbers in $\mathbb{Z}$.
It is closed under addition and multiplication and forms a
commutative subring of the field $\mathbb{Q}$.
Moreover, since there are no divisors of zero, $\mathbb{Q}_\mathrm{P}$
is an integral domain \cite{DuFo}.
Although $\mathbb{Q}_\mathrm{P}$ is not an ideal of $\mathbb{Q}$ (fields do not have proper ideals),
it is a (normal) subgroup of $(\mathbb{Q},+)$. So, we may enquire about its index
$[\mathbb{Q} : \mathbb{Q}_\mathrm{P}]$ and its quotient group $\mathbb{Q} / \mathbb{Q}_\mathrm{P}$.%

Somewhat out of context, we mention the easily-proved observation that
all three parity classes, $\mathbb{Q}_\mathrm{E}$, $\mathbb{Q}_\mathrm{O}$ and $\mathbb{Q}_\mathrm{N}$,
are (topologically) dense in the rationals.

\subsection*{2-Adic valuation and the ``degree of evenness''.}

\begin{center}
\emph{All multiples of 2 are even, but}
\emph{some are more even than others.}
\end{center}

The $p$-adic valuation --- or $p$-adic order \cite{Ka} --- of an integer $n$ is the function
$$
\nu_p(n) = \begin{cases}
\max\{k\in\mathbb{N} : p^k \mid n \} & \mbox{for\ } n \neq 0 \\
\infty                               & \mbox{for\ } n   =  0
\end{cases}
$$
This is extended to the rational numbers $m/n$:
$$
\nu_p\left(\frac{m}{n}\right) = \nu_p(m) - \nu_p(n) \,.
$$
It is easily proved that, for any rationals $q_1$ and $q_2$,
\begin{equation}
\nu_p(q_1+q_2) \ge \min\{\nu_p(q_1),\nu_p(q_2)\} \,,
\label{eq:nuineq}
\end{equation}
with equality holding if $\nu_p(q_1) \neq \nu_p(q_2)$.

We shall be concerned exclusively with the case $p = 2$.
We note that $\mathbb{Q}_\mathrm{P} = \{q\in\mathbb{Q} : \nu_2(q) \ge 0 \}$
and $\mathbb{Q}_\mathrm{E} = \{q\in\mathbb{Q} : \nu_2(q)  >  0 \}$.
The ``degree of evenness'' of a number can be expressed in terms of the 2-adic valuation.
For an integer $n$, the 2-adic valuation is the largest natural number $k$ such that
$2^k$ divides $n$. It is normally written $\nu_2(n)$ or $\mathop\mathrm{ord}_2(n)$.
For even integers, $\nu_2(n)>0$; for odd integers, $\nu_2(n)=0$.
By convention, $\nu_2(0)=\infty$ (since zero is divisible by every power of $2$).

If we write a rational number $q$ in the form $2^k(2m+1)/(2n+1)$ with $k\in\mathbb{Z}$,
then $\nu_2(q) = k$.  Odd rationals have order $0$ and rationals with no parity
have negative 2-adic order. In particular, half integers have 2-adic order equal to $-1$.
In summary,
\begin{eqnarray*}
\mbox{For $q$ rational with parity \emph{even},\ } & \nu_2(q) > 0 \,, \\
\mbox{For $q$ rational with parity \emph{odd},\  } & \nu_2(q) = 0 \,, \\
\mbox{For $q$ rational with parity \emph{none},\ } & \nu_2(q) < 0 \,.
\end{eqnarray*}

The 2-adic order clearly identifies the parity classes of the rationals, and it
provides a means of partitioning them into finer-grain parity classes.
The resulting partition reveals a wealth of algebraic structure.
For all $k\in\mathbb{Z}$, we define the set of all rational numbers with 2-adic valuation $k$:
$$
\mathit{Q}_k = \{q\in\mathbb{Q} : \nu_2(q) = k \} \qquad\mbox{and}\qquad
\mathit{Q}_\infty = \{\ 0\ \} \,.
$$
The union of all the $\mathit{Q}$-sets comprises the entire set of rationals
$$
\mathbb{Q} = \{\ 0\ \} \uplus \biguplus_{k=-\infty}^\infty \mathit{Q}_k \,.
$$
We illustrate the subsets $\mathit{Q}_k$ in Fig.~\ref{fig:QP-Plane-Lin}.
The vertical axis is the 2-adic valuation $\nu_2$. Each subset $\mathit{Q}_k$
is represented by a horizontal dotted line.
We remark that all odd rationals are in $\mathit{Q}_0$ and
all even rationals are in $\bigcup_{k>0}\mathit{Q}_k$.
For all $K\in\mathbb{Z}$, we define
\begin{equation}
\mathbb{Q}_\mathrm{K} \equiv \{\ 0\ \} \uplus \biguplus_{k\ge K} \mathit{Q}_k
\label{eq:QK}
\end{equation}
and observe that $\mathbb{Q}_\mathrm{K}$ is a subgroup of $\mathbb{Q}$.  We write this as $\mathbb{Q}_\mathrm{K}\ \text{\large$\trianglelefteq$}\ \ \mathbb{Q}$.
Note, in particular, that $\mathbb{Q}_0 = \mathbb{Q}_\mathrm{P}$ and $\mathbb{Q}_1 = \mathbb{Q}_\mathrm{E}$.
There is an infinite chain of subgroups, starting with $\mathbb{Q}_\infty = \{\ 0\ \}$
and extending through all the $\mathbb{Q}_K$ groups to the full group of rationals:
$$
\mathbb{Q}_\infty = \{\ 0\ \} \ \text{\large$\trianglelefteq$}\ \ \cdots\ \text{\large$\trianglelefteq$}\ \ \mathbb{Q}_{2}\ \text{\large$\trianglelefteq$}\ \ \mathbb{Q}_{1}\
\text{\large$\trianglelefteq$}\ \ \mathbb{Q}_{0}\ \text{\large$\trianglelefteq$}\ \ \mathbb{Q}_{-1}\ \text{\large$\trianglelefteq$}\ \ \mathbb{Q}_{-2}\ \text{\large$\trianglelefteq$}\ \ \cdots\ \text{\large$\trianglelefteq$}\ \ \mathbb{Q} \,.
$$

\subsection*{Dyadic rational numbers.}

A dyadic rational is a number that can be expressed as a fraction whose
denominator is a power of two.  The usual definition of the dyadic
rational numbers \cite[pg.~122]{Ba} is
$$
\mathbb{D} = \left\{ \frac{z}{2^m} : z\in\mathbb{Z}, m\in\mathbb{Z} \right\} \,.
$$
Note that the integers are included in the set of dyadic rationals.
A convenient alternative definition is
$$
\mathbb{D} = \{ 2^k(2\ell-1) : k\in\mathbb{Z}, \ell\in\mathbb{Z} \} \uplus \{\ 0\ \} \,,
$$
since all the numbers of the form $2^k(2\ell-1)$ are in $\mathit{Q}_k$.
Moreover, the expression of each number in this form is unique.
We also define the sets
$$
\mathit{D}_k = \{ 2^k(2\ell-1) : \ell\in\mathbb{Z} \} \qquad\mbox{and}\qquad
\mathit{D}_\infty = \{\ 0\ \} \,,
$$
and note that $\mathbb{D} = \biguplus_{k} \mathit{D}_k \,\uplus \,\mathit{D}_\infty$.
We see that $\mathit{D}_0 = \mathbb{Z}_\mathrm{O}$ and $\biguplus_{k>0}\mathit{D}_k = \mathbb{Z}_\mathrm{E}$.

The dyadics correspond to all real numbers with finite binary expansions,
and also to the set of surreal numbers born on finite days \cite{Co}.
The dyadic rational numbers form a ring between the ring of
integers and the field of rational numbers:
$$
\mathbb{Z} \ \text{\large$\trianglelefteq$}\ \mathbb{D} \ \text{\large$\trianglelefteq$}\ \mathbb{Q} \,.
$$

The sets $\mathit{D}_k$ are indicated in Fig.~\ref{fig:QP-Plane-Lin} by the marked points in $\mathit{Q}_k$.
The vertical axis is the 2-adic valuation $\nu_2$.
For each $k$,  $\mathit{D}_k\subset\mathit{Q}_k$.
The (black) dots at level $k=0$ are the odd integers.
The (blue) dots at positive $k$-levels are the even integers.
The (red) dots at each negative level $k<0$ are the dyadic fractions,
with odd numerator and denominator $2^{k}$.
Zero sits, like an angel, on top of the tree.

By analogy with the definition (\ref{eq:QK}) of the $\mathbb{Q}_K$-sets,
we construct a countable infinity of subgroups of $\mathbb{D}$:
$$
\mathbb{D}_K := \{\ 0\ \} \uplus \biguplus_{k\ge K} \mathit{D}_k \,.
$$
Particular cases of the $\mathbb{D}$-sets include
$$
\mathbb{D}_{-\infty} = \mathbb{D} \,, \qquad \mathbb{D}_{-1} = \textstyle{\frac{1}{2}}\mathbb{Z} \,, \qquad
\mathbb{D}_0 = \mathbb{Z} \,, \qquad \mathbb{D}_1 = \mathbb{Z}_\mathrm{E} \,, \qquad \mathbb{D}_\infty = \{\ 0\ \} \,.
$$
There is an infinite chain of subgroups starting with $\mathbb{D}_\infty$
and extending through all the $\mathbb{D}_K$ groups to the full group of dyadic rationals:
$$
\mathbb{D}_\infty = \{\ 0\ \} \ \text{\large$\trianglelefteq$}\ \ \cdots\ \text{\large$\trianglelefteq$}\ \ \mathbb{D}_{2}\ \text{\large$\trianglelefteq$}\ \ \mathbb{D}_{1}\
\text{\large$\trianglelefteq$}\ \ \mathbb{D}_{0}\ \text{\large$\trianglelefteq$}\ \ \mathbb{D}_{-1}\ \text{\large$\trianglelefteq$}\ \ \mathbb{D}_{-2}\
\text{\large$\trianglelefteq$}\ \ \cdots\ \text{\large$\trianglelefteq$}\ \ \mathbb{D} \,.
$$

\begin{figure}[t]
\begin{center}
\includegraphics[width=0.75\textwidth]{./QP-Plane-Lin.jpg}
\caption{Partition of the rational numbers.
The vertical axis is the 2-adic valuation $\nu_2$.
Each (dense) subset $\mathit{Q}_k$ is represented by a horizontal dotted line.
The sets $\mathit{D}_k$ are indicated by the marked points in $\mathit{Q}_k$.
The totality of these comprises the dyadic rationals $\mathbb{D}$.}
\label{fig:QP-Plane-Lin}
\end{center}
\end{figure}

Readers familiar with the theory of $p$-adic numbers may wish to show that
$\mathbb{Q}_\mathrm{P}$ is the ring of rational-valued 2-adic integers, $\mathbb{Q}\cap\mathbb{Z}_2$,
and the dyadic rational numbers may be expressed as
$$
\mathbb{D} = \mathbb{Q} \cap \bigcap_{p\ \mathrm{odd}} \mathbb{Z}_p \,.
$$

\section{Cosets of $\mathbb{Q}_\mathrm{P}$ in $\mathbb{Q}$.}
\label{sec:cosets}

In the following section we show that any two rationals $q_1$ and $q_2$ with distinct,
negative 2-adic orders are representatives of distinct cosets: $q_1 + \mathbb{Q}_\mathrm{P} \neq q_2 + \mathbb{Q}_\mathrm{P}$.
Thus, if $q_1 + \mathbb{Q}_\mathrm{P} = q_2 + \mathbb{Q}_\mathrm{P}$ then $\nu_2(q_1)=\nu_2(q_2)$. Consequently, there is
at least one coset for each $k<0$ and therefore an infinite number of cosets. However,
it is clear that
$\nu_2(q_1) = \nu_2(q_2)$ does not imply equality of cosets; consider, for example,
$q_1 =\frac{1}{4}$ and $q_2 = \frac{3}{4}$, since $(q_2-q_1)=\textstyle{\frac{1}{2}}\not\in \mathbb{Q}_\mathrm{P}$.

We now investigate the cosets $q + \mathbb{Q}_\mathrm{P}$ in $\mathbb{Q} / \mathbb{Q}_\mathrm{P}$.
First, we note that if $q \in \mathit{Q}_{-k}$ then $q + \mathbb{Q}_\mathrm{P} \subset \mathit{Q}_{-k}$,
but there is no guarantee that $q + \mathbb{Q}_\mathrm{P}$ is equal to $\mathit{Q}_{-k}$.
Suppose $q_1$ and $q_2$ are in $\mathit{Q}_{-k}$ for some $k>0$. If they represent the same coset
then $q_1 - q_2 \in \mathbb{Q}_\mathrm{P}$. However, it is easily seen that $\nu_2(q_1-q_2)$ may assume any value
greater than $-k$:
$$
q_1 - q_2 = 2^{\ell-k} \frac{o_1}{o_2} \quad\mbox{for}\quad \ell > 0 \,.
$$
Thus, $q_1 - q_2$ may be in any of the following sets:
$$
\mathit{Q}_{-k+1} \,, \mathit{Q}_{-k+2} \,, \mathit{Q}_{-k+3}\,, \dots \,, \mathit{Q}_{-1} \,, \mathbb{Q}_\mathrm{P} \,.
$$
Clearly, $q_1 - q_2 \in \mathbb{Q}_\mathrm{P}$ if and only if $\ell \ge k$, whence
$$
q_1 + \mathbb{Q}_\mathrm{P} = q_2 + \mathbb{Q}_\mathrm{P} \qquad \mbox{\textrm{iff}} \qquad \ell \ge k \,.
$$

For each $k>0$, we define a set of values
\begin{equation}
q_{k}^{\ell} = 2^{-k}(2\ell-1) \in \mathit{Q}_{-k}
\quad\mbox{for}\quad  \ell=1,2,3, \dots , 2^{k-1} \,.
\label{eq:qkl}
\end{equation}
We note that these are the first $2^{k-1}$ positive values in $\mathit{D}_{-k}$.
We show in the following section that these are representatives of $2^{k-1}$
cosets, which are all distinct and which provide a disjoint partition of $\mathit{Q}_{-k}$.
This analysis provides explicit expressions for each of the infinite set
of cosets of $\mathbb{Q}_\mathrm{P}$ in $\mathbb{Q}$:
\begin{equation}
 q_{k}^{\ell}+\mathbb{Q}_\mathrm{P} \,, \qquad \ell=1, 2, 3, \dots 2^{k-1} \,, \quad k=1,2, \dots  \,.
\end{equation}

\subsection*{Scale invariance of the structure.}

\begin{figure}[h]
\begin{center}
\includegraphics[width=0.75\textwidth]{./QP-Plane-Log.jpg}
\caption{Partition of the rational numbers.
The vertical axis is $\mu_2 = 2^{\nu_2}$.
Each subset $\mathit{Q}_k$ is represented by a horizontal dotted line.
The sets $\mathit{D}_k$ are indicated by the marked points in $\mathit{Q}_k$.
The dyadic numbers in $\mathbb{D}$ all appear on a pencil of lines emanating
from the origin.}
\label{fig:QP-Plane-Log}
\end{center}
\end{figure}

We notice that the diagram in Fig.~\ref{fig:QP-Plane-Lin} has a scaling invariance:
if the horizontal axis is stretched by a factor of 2 and the diagram translated
one unit in the vertical, the dyadic rationals occupy the same set of points.
We have chosen to analyse the quotient group $\mathbb{Q}/\mathbb{Q}_\mathrm{P}$. However, a similar analysis
could be done for any subgroup $\mathbb{Q}_\mathrm{K}$, with directly analogous results.

In Fig.~\ref{fig:QP-Plane-Log}, we re-plot Fig.~\ref{fig:QP-Plane-Lin}
with vertical axis $\mu_2 = 2^{\nu_2}$.  The dyadic numbers in $\mathbb{D}$ now appear
on a pencil of lines with slopes $1/(2\ell-1)$, emanating from the origin.

\subsection*{Density of $\mathit{Q}_{k}$: a heuristic discussion.}

The set $\mathit{Q}_{-1} = \textstyle{\frac{1}{2}} + \mathbb{Q}_\mathrm{P}$ is a coset of $\mathbb{Q}_\mathrm{P}$. It can be
visualized as a copy of $\mathbb{Q}_\mathrm{P}$ shifted by a distance $\textstyle{\frac{1}{2}}$.
We argue heuristically that $\mathit{Q}_{-1}$ is ``as dense as $\mathbb{Q}_\mathrm{P}$''.

More generally, for any $k$, there is a natural correspondence between
elements of $\mathit{Q}_{k}$ and elements of $\mathit{Q}_{k-1}$:
$$
\frac{1}{2^{k}}  \left(\frac{2m+1}{2n+1}\right) \in \mathit{Q}_{k} \longleftrightarrow
\frac{1}{2^{k-1}}\left(\frac{2m+1}{2n+1}\right) \in \mathit{Q}_{k-1}  \,.
$$
Thus, $\mathit{Q}_{k-1}$ may be visualized as a compressed version of $\mathit{Q}_{k}$.
Since $\mathit{Q}_{k-1}$ is ``twice as dense as $\mathit{Q}_{k}$'', we may argue that we
should have twice as many cosets in $\mathit{Q}_{k-1}$ as there are in $\mathit{Q}_{k}$.
This is consistent with what is proved rigorously below.

\section{Formal proof of the coset structure for $\mathbb{Q}_\mathrm{P}$.}
\label{sec:proofs}

In this section, we give rigorous proofs of some of the results
considered heuristically in the discussion above.
Lemmas 1 and 2 give conditions for cosets to be equal. Proposition 1
gives explicit representatives $q_k^\ell$ for each of the distinct
cosets.  In the following, we abbreviate the $2$-adic valuation $\nu_2$ to $\nu$.

\begin{lemma}
Suppose $q_1, q_2 \in \mathbb{Q}_\mathrm{N}$ and $q_1+\mathbb{Q}_\mathrm{P} = q_2+\mathbb{Q}_\mathrm{P}$.  Then $\nu(q_1)=\nu(q_2)$.
\end{lemma}

\begin{proof}
For the cosets to be equal, we must have $q_1-q_2 \in\mathbb{Q}_\mathrm{P}$. Suppose that
$\nu(q_1)=-k$ and $\nu(q_2)=-\ell$ with $k\ne\ell\in\mathbb{N}$. Without loss of generality,
we may assume that $\ell = k+d$ with $d>0$.
Then, using (\ref{eq:nuineq}),
\begin{equation}
\nu(q_1-q_2) = \min(\nu(q_1), \nu(-q_2)) = \min(\nu(q_1), \nu(q_2)) = \min(-\ell, -k) = -\ell \,.
\nonumber
\end{equation}
Thus, $q_1-q_2 \in \mathit{Q}_{-\ell}$,
so that $q_1+\mathbb{Q}_\mathrm{P} \ne q_2+\mathbb{Q}_\mathrm{P}$.
Consequently, a necessary condition for equality of the cosets is that $q_1$ and $q_2$
have the same 2-adic valuation, $\nu(q_1)=\nu(q_2)$.
\end{proof}

The next lemma strengthens this to a necessary and sufficient condition.

\begin{lemma}
Let $q_1$ and $q_2$ be in $\mathbb{Q}_\mathrm{N}$.  Then $q_1+\mathbb{Q}_\mathrm{P}=q_2+\mathbb{Q}_\mathrm{P}$ if, and only
if, $\nu(q_1)=\nu(q_2)=-k$ for some $k\in \mathbb{N}$ and
$\nu(a_1b_2-a_2b_1))\ge k$ where $q_1={a_1}/{(2^kb_1)}$ and
$q_2={a_2}/{(2^kb_2)}$.
\end{lemma}

\begin{proof}
Let $q_1$ and $q_2$ be in $\mathbb{Q}_\mathrm{N}$.  Suppose that $q_1+\mathbb{Q}_\mathrm{P}=q_2+\mathbb{Q}_\mathrm{P}$.
Lemma 1 tells us that $\nu(q_1)=\nu(q_2)=-k$ for some $k\in \mathbb{N}$.   We
may thus write
\begin{equation}
q_1= \frac{a_1}{2^kb_1} \quad \mathrm{and} \quad
q_2=\frac{a_2}{2^kb_2}
\label{eq:0}
\end{equation}
where
$a_i, b_i$ are odd, and so
\begin{equation}
  q_1-q_2 = \frac{a_1 b_2 - a_2 b_1}{2^k b_1 b_2}.
  \label{eq:00}
\end{equation}
By hypothesis, this is an element of $\mathbb{Q}_\mathrm{P}$ which implies
  $2^k |(a_1b_2-a_2b_1)$, as asserted.

  For the converse, if $\nu(q_1)=\nu(q_2)=-k$, then \eqref{eq:0}, and
  hence \eqref{eq:00}, holds.   The condition $\nu(a_1b_2-a_2b_1)\ge
  k$ then implies $\nu(q_1-q_2)\ge 0 $ and so $q_1-q_2\in \mathbb{Q}_\mathrm{P}$.

\end{proof}

\begin{proposition}
  For each $k\in\mathbb{N}$, let $q_k^\ell = ({2\ell-1})/{2^k} \in \mathit{Q}_{-k}$ for
  $\ell=1,\ldots, 2^{k-1}$. These numbers generate $2^{k-1}$ distinct $\mathbb{Q}_\mathrm{P}$-cosets,
  which comprise all the cosets of $\mathbb{Q}_\mathrm{P}$ by elements of $\mathit{Q}_{-k}$.
\end{proposition}

\begin{proof}
  It is clear that $q_k^\ell = {(2\ell-1)}/{2^k}$ lies in
  $\mathit{Q}_{-k}$.   If two of these numbers, $q_k^\ell$ and $q_k^{\ell'}$ say, generate
  the same coset, then $q_k^\ell - q_k^{\ell'} \in \mathbb{Q}_\mathrm{P}$ and so, by Lemma 2,
  $2^k $ divides $2{\ell'}-1 - (2\ell-1)=2({\ell'}-\ell)$ and hence $2^{k-1}$ divides
  $\ell-\ell'$.  As $1\le \ell,\ell'\le 2^{k-1}$, the only way this can occur is if
  $\ell=\ell'$. This shows that all $2^{k-1}$ cosets generated by $q_k^\ell$ are distinct.

  Next, we show that these exhaust all possible cosets by elements of
  $\mathit{Q}_{-k}$.  For this, given $q\in \mathit{Q}_{-k}$ we need to show that
  $q+\mathbb{Q}_\mathrm{P}= q_{k}^{\ell}+\mathbb{Q}_\mathrm{P}$ for some $\ell\in\{1,2,\ldots 2^{k-1}\}$.  As $q = n/(2^k m)$
  for $m$ and $n$ odd, by Lemma 2, this amounts to showing
  $\nu(1.n - (2\ell-1)m) \ge k$, or that $2^k$ divides $n+m-2\ell m$.
  We may let $n+m=2s$ ($s\in\mathbb{Z}$) and examine instead whether $2^{k-1}$
  divides $s-\ell m$ for some $\ell\in\{1,\ldots,2^{k-1}\}$.

  Notice that
  \begin{align*}
  s-\ell m \equiv s-\ell' m ( \!\!\!\!\!  \mod 2^{k-1} )   &\iff   2^{k-1} \mbox{\ divides\ } m(\ell-\ell')   \\
                              & \overset{\mbox{$m$\ odd} } \iff    2^{k-1} \mbox{\ divides\ } (\ell-\ell')    \iff \ell = \ell'
  \end{align*}
  as again $1\le \ell,\ell'\le 2^{k-1}$.
  In particular, by the pigeonhole
  principle, all $2^{k-1}$ possible $2^{k-1}$-remainders, including 0, are
  contributed by $s-\ell m$, $\ell =1,\ldots,2^{k-1}$.   So $2^{k-1}$ divides
  $s-\ell m$ for some $\ell$ and, for this $\ell$ we have $q\in q_k^\ell+\mathbb{Q}_\mathrm{P}$, as stated.
\end{proof}

\section{Densities of the parity classes.}
\label{sec:CW-Tree}

\begin{figure}[t]
\begin{center}
\includegraphics[width=0.45\textwidth]{./CW-TreeStructure.jpg}
\hspace{5mm}
\includegraphics[width=0.45\textwidth]{./SB-TreeStructure.jpg}
\caption{The initial rows of the Calkin-Wilf tree (left) and Stern-Brocot tree (right).}
\label{fig:CWtreeSBtree}
\end{center}
\end{figure}

There are many exhaustive sequences of rationals other than (\ref{eq:farish}), one attractive
option being the Calkin-Wilf tree \cite{CaWi}.
The Calkin-Wilf tree is complete: it includes all positive rational numbers and each such number
occurs precisely once.  The tree starts with the root value ${1}/{1}$,
and everything springs from this root (see Fig.~\ref{fig:CWtreeSBtree}, left panel).
Each rational in the tree has two ``children'': for the entry $m/n$,
the children are $m/(m+n)$ and $(m+n)/n$.  The ``left child''
$m/(m+n)$ is always smaller that $1$ while the ``right child''
$(m+n)/n$ is always greater that $1$
(mnemonic: the \emph{children} are ``top over sum'' and ``sum over bottom'').

The pattern of parity from one row of the Calkin-Wilf diagram to the next
is simple.  Denoting odd parity, even parity and no parity by $o$, $e$ and $n$
respectively, the parity transfer rules are as follows:
\begin{eqnarray}
\phantom{o}\phantom{\swarrow}        {\ e\ }\phantom{\searrow}\phantom{o}\qquad \quad
\phantom{o}\phantom{\swarrow}        {\ o\ }\phantom{\searrow}\phantom{o}\qquad \quad
\phantom{o}\phantom{\swarrow}        {\ n\ }\phantom{\searrow}\phantom{o}\qquad \quad
\nonumber
\\
\phantom{o}        {\swarrow}\phantom{\ o\ }        {\searrow}\phantom{o}\qquad \quad
\phantom{o}        {\swarrow}\phantom{\ o\ }        {\searrow}\phantom{o}\qquad \quad
\phantom{o}        {\swarrow}\phantom{\ o\ }        {\searrow}\phantom{o}\qquad \quad
\label{eq:CWtransfer}
\\
        {e}\phantom{\swarrow}\phantom{\ o\ }\phantom{\searrow}        {o}\qquad \quad
          {n}\phantom{\swarrow}\phantom{\ o\ }\phantom{\searrow}        {e}\qquad \quad
            {o}\phantom{\swarrow}\phantom{\ o\ }\phantom{\searrow}        {n}\qquad \quad
\nonumber
\end{eqnarray}
We will now show that the elements of the Calkin-Wilf tree
are remarkably regular, with the pattern $(o, n, e)$ repeating interminably.
Thus, the parity of any specific term in the tree can easily be deduced.
We also prove that, with the ordering of $\mathbb{Q}$ corresponding to the
Calkin-Wilf tree, the three parity classes all have the same density.

\begin{theorem}
Let $\mathbb{Q}^{+}$ be ordered with the Calkin-Wilf tree.
Then $\mathbb{Q}^{+}$ may be partitioned into three parity classes,
$\mathbb{Q}_\mathrm{E}^{+}$, $\mathbb{Q}_\mathrm{O}^{+}$ and $\mathbb{Q}_\mathrm{N}^{+}$, each having asymptotic density $\frac{1}{3}$.
\end{theorem}

\begin{proof}
The parity classes for the first few rows of the Calkin-Wilf tree are shown in
Fig.~\ref{fig:CWparitytree}. Odd rows follow a pattern $(one)^k o$ for some
$k \ge 0$ and even rows follow a pattern $ne(one)^k$. This is clearly true for the
first few rows. Using the transfer rules (\ref{eq:CWtransfer}), and arguing
inductively, it is clear that a row with pattern
$(one)^k o$ is followed by a row with pattern $ne(one)^{2k}$. This, in turn,
is followed by a row with pattern $(one)^{4k+1} o$. The full sequence begins
$$
o\ \quad\ ne\ \quad\ (one) o\ \quad\ ne (one)^2\ \quad\
(one)^5 o\ \quad\ ne (one)^{10}\ \quad\ \cdots
$$
We conclude that, if the entire tree is written row by row as a sequence,
the parity follows an unvarying pattern, with \emph{odd} followed
by \emph{none} followed by \emph{even}.
The parity of an element at any position $N$ is immediately deduced
from $m = N (\mbox{mod}\ 3)$. The pattern also implies that the three
parity classes have equal densities.
\end{proof}

\begin{figure}[t]
\begin{center}
\includegraphics[width=0.8\textwidth]{./CW-Parity-Tree.jpg}
\caption{Parity classes of terms in the Calkin-Wilf tree.}
\label{fig:CWparitytree}
\end{center}
\end{figure}

The Calkin-Wilf tree enumerates the positive rationals $\mathbb{Q}^{+}$. This enumeration,
which we write $\{q_n:n\in\mathbb{N}\}$, can be extended in a natural way to the full set of rationals:
we enumerate $\mathbb{Q}$ by $\{0,q_1,-q_1,q_2,-q_2, \dots \}$. With this ordering,
the rational numbers split into three parts, each of asymptotic density $\frac{1}{3}$.

To summarise, the parity classes of elements of the Calkin-Wilf tree follow a simple
pattern if arranged in a single sequence: the pattern $\{o, n, e\}$ repeats indefinitely
(see Fig.~\ref{fig:CWparitytree}).
As a result, the densities of the parity classes in $\mathbb{Q}$ are all equal for this ordering:
\begin{equation}
\rho_\mathbb{Q}(\mathbb{Q}_\mathrm{E}) = \rho_\mathbb{Q}(\mathbb{Q}_\mathrm{O}) = \rho_\mathbb{Q}(\mathbb{Q}_\mathrm{N}) = \tfrac{1}{3} \,.
\label{fig:Q-OneThird}
\end{equation}

The Stern-Brocot tree \cite[pg.~116]{GrKnPa}
is another ordering of $\mathbb{Q}$ very similar to the Calkin-Wilf tree.
The numbers at each level are formed from the mediants of adjacent pairs of numbers above
(Fig.~\ref{fig:CWtreeSBtree}, right panel). The mediant of two (reduced) rationals,
$m_1/n_1$ and $m_2/n_2$ is defined as $M(m_1/n_1, m_2/n_2):= (m_1+m_2)/(n_1+n_2)$.
We note that the parity of the mediants of two numbers of
different parity is the third parity:
\begin{equation}
M(e,o) = n \,,\qquad M(o, n) = e \,,\qquad M(n,e) = o \,.
\label{eq:Mtrans}
\end{equation}
We now show that, with the ordering of the Stern-Brocot tree,
(\ref{fig:Q-OneThird}) holds true.

\begin{theorem}
For the order of $\mathbb{Q}$ induced by the Stern-Brocot process,
the asymptotic density of each parity class, $\mathbb{Q}_\mathrm{E}$, $\mathbb{Q}_\mathrm{O}$ and $\mathbb{Q}_\mathrm{N}$,
is $\frac{1}{3}$.
\end{theorem}

\begin{proof}
The Stern-Brocot tree is generated starting from level $0$ with the boundary elements
$\left[\frac{0}{1}\right]$ and $\left[\frac{1}{0}\right]$, representing $0$ and $\infty$
and with parities $[e]$ and $[n]$.
To get each subsequent level we add, between each pair of adjacent numbers,
the mediant of that pair, retaining all numbers already generated.
The results, for the first few levels, are shown in Fig.~\ref{fig:CWtreeSBtree}
(right panel).  The parity pattern for the first few levels is
$$
[e]o[n] \quad\
[e]noe[n] \quad\
[e]oneoneo[n] \quad\
[e]noenoenoenoenoe[n] \,.
$$
Using the transfer rules (\ref{eq:Mtrans}), an odd row with parity
$(eon)^{K}$ is followed by even row with parity $e(noe)^{2K-1}n$.
This in turn is followed by an odd row with parity $(eon)^{4K-1}$.
By an inductive argument, it follows that the parity pattern for an
odd row $k$ is $(eon)^{K}$,
where $K =   (2^k+1)/3$ and, for an even row $k$, is $e(noe)^{K}n$
where $K = (2^\ell-1)/3$.
This implies that the asymptotic densities are equal for all three parity classes.

The Stern-Brocot tree enumerates the positive rationals $\mathbb{Q}^{+}$. This enumeration,
is easily extended to the full set of rationals, as was done above for the Calkin-Wilf tree.
Then the rational numbers split into three parts, each of asymptotic density $\frac{1}{3}$.
\end{proof}

The determination of the densities of parity classes for the ordering corresponding to
the Farey sequences is left as a challenge for readers.

\section{Conclusion.}
\label{sec:conclude}

We have extended parity from the integers to the rational
numbers. Three parity classes --- even, odd and `none' ---
were found.  The even and odd rationals $\mathbb{Q}_\mathrm{E}$ and $\mathbb{Q}_\mathrm{O}$ follow the
usual rules of parity.  The union of these forms an additive subgroup
$\mathbb{Q}_\mathrm{P}$ of $\mathbb{Q}$.

Using the 2-adic valuation, we partitioned $\mathbb{Q}$ into subsets and
found a chain of subgroups, each having a quotient group of cosets.
We constructed a complete set of representatives for the cosets of $\mathbb{Q}_\mathrm{P}$.

The Calkin-Wilf tree was found to have a remarkably simple parity
pattern, with the sequence `odd/none/even' repeating indefinitely.
Using the natural density, which provides a means of distinguishing
the sizes of countably infinite sets, we showed that, with the
Calkin-Wilf ordering, the three parity classes are equally dense
in the rationals. The same conclusion holds for the Stern-Brocot tree.

Finally, we remark that, while this study used only 2-adic numbers,
there is potential for broad extensions and generalizations using more general $p$-adic
numbers.

\subsection*{Acknowledgments.}
We are grateful to Tom Laffey, Emeritus Professor, School of Mathematics
\&\ Statistics, University College Dublin, for reading a draft of this paper
and to Tony O'Farrell, Emeritus Professor at Maynooth University
for guidance on $p$-adic numbers.