The Amazon Kindle version of Dancing with Qubits is now available!

Page from Kindle version of Dancing with QubitsI’m pleased to announce that the Amazon Kindle version of my quantum computing book Dancing with Qubits is now available!

This book provides a comfortable and conversational introduction to quantum computing. I take you through the mathematics you need at a pace that allows you to understand not just “what” but also “why.” When we get to quantum computing, concepts like superposition and entanglement are shown to be natural ideas building on what we’ve already seen, and then illustrated via gates, circuits, and algorithms.

Throughout the book, I highlight important results, provide questions to answer, and give links to references where you can learn more. This allows the book to be used for self-study or as a textbook.

Important ideas like Quantum Volume are explained to give you a head start for reading more advanced texts and research papers. I provide many references to related content in math, physics, quantum computing, AI, and financial services. Dancing with Qubits concludes with questions for you to think about and ask experts so that you can gauge progress in the field over the next few years.

Features of the Kindle edition

Page from the book Dancing with Qubits

  • The text will get larger or smaller as you wish and you can change to a font that is comfortable for you to read.
  • There are links throughout the book to other sections and the references in each chapter.
  • Many of the references have links to external sources, such as arxiv or Nature for research papers.
  • The content is in color, if your Kindle device supports it.
  • You can search for terms throughout the book.
  • I’ve maximized the number of mathematical expressions that are expressed textually (see below) to improve the reading experience.

The print version of Dancing with Qubits still has the full, rich mathematical formatting, albeit in black and white. In essence, whether you choose the print or Kindle version, the content is consistent and the formatting is the best I know how to produce for each medium.

Technical Notes

Here are a few comments about the production of the Kindle version, in case you are interested.

Page from the book Dancing with Qubits

  • The original content for Dancing with Qubits is in LaTeX. From that I can produce the black and white print version, a color PDF eBook, and an epub3 file from which the Amazon Kindle and several other MOBI eBook versions are created.
  • I used make4ht and tex4ht to go from the LaTeX source files to HTML. While very powerful, the documentation is scarce and I spent many hours trying to figure how to make things work and then writing sed and Python scripts to fix things that were not quite right.
  • I wrote Python scripts to create the various files needed for epub3, such as opf and navigation, and to break the 30,000+ line HTML file into smaller XHTML files. I used tidy several times to format the HTML and XHTML.
  • The epub3 validators in several free epub3 editing apps either skipped problems entirely or gave false negatives. I found pagina EPUB-Checker to be the best software for validation.
  • I wanted to maximize the amount of HTML formatting I could use and MathML is not available in a practical sense for all eBook formats. tex4ht produced very inconsistent results. So while I could express $x_2$ as x2 in the text without extra fonts, more two-dimensional objects like matrices had to be represented using images. I created macros to produce the right format based on what kind of document I was trying to produce.
  • I used tikz/pgf and quantikz for the figures, especially the quantum circuit diagrams. I externalized the figures as JPEG images. It took quite a bit to figure out how to get them to be the right size for the Kindle version.
  • Some math expressions in the book and chapter tables of contents have weird spacing if they involve subscripts or superscripts. This is an artifact of the Kindle software. This did not happen, for example, when I viewed the book in the Apple Books app.

Dancing With Qubits, First Edition: What about the eBook?

Cover of the book Dancing with QubitsYesterday was very exciting because I received my first printed copy of the book. There’s just something about holding a physical, printed book that you’ve labored over for many months. Others are starting to get their copies too, and I hope that within a couple of weeks everyone who pre-ordered the print version will have copies in hand.

What if you ordered the eBook? Wasn’t that an option on Amazon? Why isn’t it listed there now? Why was your Kindle eBook order canceled?

The original plan was to provide the eBook in a PDF-like, print replica format that was in color and had active links within and beyond the book. You can still purchase this eBook at the Packt Publishing website.

As for Amazon, let’s just say that they ultimately wanted a reflowable version of the book rather than a fixed format version. As I’ve mentioned before, this presents many challenges to producing beautiful math. The reflowable format allows you to change the font and font size you use on your Kindle or in the Kindle app. It makes it easier to read on small devices. I understand the value.

Hence, I’m now working to create a reflowable version with one guiding principle: as much as possible, I must have a single source for the book that will produce future versions of the printed, fixed-format PDF, and reflowable formats

Here’s the strategy:

  • Use tools like make4ht to translate the original LaTeX into HTML. Convert the HTML into MOBI and EPUB3 formats with a minimal amount of hand editing.
  • Use standard HTML entities and CSS for as much of the in-sentence math as possible.
  • Avoid using extra fonts within the HTML.
  • Use automatically-generated PNG files for any other math.
  • Use automatically-generated SVG and PNG files for figures coming from LaTeX tikz environments. (This is not working at all right now.)
  • Use new macros for the math to produce either LaTeX or HTML versions.
  • Use a small Python program I wrote to convert simple math to new markup using the new macros.

Screen shot of the VSCode editor

There is much work to do but things are looking promising. I can’t now give you any estimated time of arrival for the Kindle reflowable version or any guarantee that it will arrive eventually, but it’s my strong intention to make it happen. There are unknown unknowns yet to be discovered.

In the meanwhile, as I mentioned above, you can get a PDF-like digital version of the book from Packt.

A final point: despite several people staring at the text, a few errors crept in. These are mostly typos or omitted words. I’m keeping track of these on the corrections and clarifications page for the book. I incorporate these fixes into the text as they are discovered and I hope that future versions of the book, printed and digital, include them.


Previous: What’s in the book

In December, 2019, Packt Publishing published my book Dancing with Qubits: How quantum computing works and how it can change the world. Through a series of blog entries, I talk about the writing and publishing process, and then about the content.

Dancing With Qubits, First Edition: Drawing quantum circuits

This entry is for people who use the LaTeX document preparation system, as I did in the book. It’s not a tutorial on LaTeX in general, but shows some techniques for drawing quantum circuits. To be direct, it’s pretty geeky for LaTeX people.

An early decision I had to make was how to draw quantum circuit diagrams in the book. Here’s an example of one:

A quantum circuit

This includes three Hadamard H gates, two S gates, a T gate, and a swap gate. Would I need to write my own drawing routines?

I really didn’t want to do that because of my time constraints but I also hoped that I could find something better. It didn’t take me long to do so: Alastair Kay’s excellent quantikx package on the CTAN Comprehensive TeX Archive Network. The documentation there is very good, but in this blog entry I’m going to show you how to evolve a simple circuit to have stylistic customizations that you might want to modify and use.

Below are five displayed versions of the same circuit. They are numbered on the left side.Five example circuits

The first is the default formatting from quantikz. It is perfectly fine and you can see similarly formatted circuits in research articles about quantum computing.

\begin{center}
    \begin{tikzpicture}
        \node[scale=1.0] {
            \begin{quantikz}
                \ket{0} & \qw       & \gate{H} & \ctrl{1}   & \meter{} & \qw \\
                \ket{0} & \gate{X}  & \gate{H} & \targ{}    & \meter{} & \qw
            \end{quantikz}
        };
    \end{tikzpicture}
\end{center}

The markup \ket{0} produces the |0> at the beginning of each wire, which is a horizontal line. \qw creates a segment of a quantum wire. \gate is the basic command for drawing a labeled gate with a rectangle. \meter is the quantum measurement operator. \ctrl{1} and \targ{} are the two parts of a CNOT two-qubit gate. \ctrl{1} is on the wire for the control qubit and extends a line down one wire. There the line meets the \targ{} (target) qubit and is drawn as a circle around a “+” sign.

In the second example, I’ve changed the font in the H and X gates.

\newcommand*{\gateStyle}[1]{{\textsf{\bfseries #1}}}
\newcommand*{\hGate}{\gateStyle{H}}
\newcommand*{\xGate}{\gateStyle{X}}

\begin{center}
    \begin{tikzpicture}
        \node[scale=1.0] {
            \begin{quantikz}
                \ket{0} & \qw            & \gate{\hGate} & \ctrl{1}   & \meter{} & \qw \\
                \ket{0} & \gate{\xGate}  & \gate{\hGate} & \targ{}    & \meter{} & \qw
            \end{quantikz}
        };
    \end{tikzpicture}
\end{center}

I added three LaTeX macros to encapsulate the new function and make it easier to reuse.

  1. \gatestyle puts its text in a bold sans serif font.
  2. \hGate draws the Hadamard H using \gatestyle.
  3. \xGate draws the X using \gatestyle.

While it is now easier to use \hGate and \xGate for text, it’s still wordy to use them as gates in a circuit. The third example defines two more macros, \circuitH and \circuitX, and shows how to set the background and font colors. For a printed book, you might want to have gates with backgrounds in different shades of gray. Alternatively, you could use the same background color for all the Clifford gates.

\newcommand*{\circuitH}{\gate[style={fill=black},label style=white]{\textnormal{\hGate{}}}}
\newcommand*{\circuitX}{\gate[style={fill=teal},label style=white]{\textnormal{\xGate}}}

\begin{center}
    \begin{tikzpicture}
        \node[scale=1.0] {
            \begin{quantikz}
                \ket{0} & \qw            & \circuitH & \ctrl{1}   & \meter{} & \qw \\
                \ket{0} & \circuitX      & \circuitH & \targ{}    & \meter{} & \qw
            \end{quantikz}
        };
    \end{tikzpicture}
\end{center}

Now let’s set the color for the circle in \targ.

\newcommand*{\circuitTarget}[1]{\targ[style={fill=yellow}]{#1}}

\begin{center}
    \begin{tikzpicture}
        \node[scale=1.0] {
            \begin{quantikz}
                \ket{0} & \qw            & \circuitH & \ctrl{1}         & \meter{} & \qw \\
                \ket{0} & \circuitX      & \circuitH & \circuitTarget{} & \meter{} & \qw
            \end{quantikz}
        };
    \end{tikzpicture}
\end{center}

I think you get the idea. You can also set the background color for \meter, which I leave to you as an exercise. Note that in the April, 2019, version of quantikx, you could not change the color of the line inside the \meter graphic. You need to copy and redefine the macro (or create a new macro) to do that.

Finally, let me explain what that [scale=1.0] is doing after the \node. This allows you to scale the entire drawing and make it larger or smaller. However, it does not change the text size. The fifth example shows the fourth example drawn 20% larger.

\begin{center}
    \begin{tikzpicture}
        \node[scale=1.2] {
            \begin{quantikz}
                \ket{0} & \qw            & \circuitH & \ctrl{1}         & \meter{} & \qw \\
                \ket{0} & \circuitX      & \circuitH & \circuitTarget{} & \meter{} & \qw
            \end{quantikz}
        };
    \end{tikzpicture}
\end{center}

Here is the complete LaTeX file I used to generate the examples:


\usetikzlibrary{quantikz}

\mainmatter


\begin{center}
    \begin{tikzpicture}
        \node at (-5,0) {(1)};
        \node[scale=1.0] {
            \begin{quantikz}
                \ket{0} & \qw       & \gate{H} & \ctrl{1}   & \meter{} & \qw \\
                \ket{0} & \gate{X}  & \gate{H} & \targ{}    & \meter{} & \qw
            \end{quantikz}
        };
    \end{tikzpicture}
\end{center}


\newcommand*{\gateStyle}[1]{{\textsf{\bfseries #1}}}
\newcommand*{\hGate}{\gateStyle{H}}
\newcommand*{\xGate}{\gateStyle{X}}

\begin{center}
    \begin{tikzpicture}
        \node at (-5,0) {(2)};
        \node[scale=1.0] {
            \begin{quantikz}
                \ket{0} & \qw            & \gate{\hGate} & \ctrl{1}   & \meter{} & \qw \\
                \ket{0} & \gate{\xGate}  & \gate{\hGate} & \targ{}    & \meter{} & \qw
            \end{quantikz}
        };
    \end{tikzpicture}
\end{center}


\newcommand*{\circuitH}{\gate[style={fill=black},label style=white]{\textnormal{\hGate{}}}}
\newcommand*{\circuitX}{\gate[style={fill=teal},label style=white]{\textnormal{\xGate}}}

\begin{center}
    \begin{tikzpicture}
        \node at (-5,0) {(3)};
        \node[scale=1.0] {
            \begin{quantikz}
                \ket{0} & \qw            & \circuitH & \ctrl{1}   & \meter{} & \qw \\
                \ket{0} & \circuitX      & \circuitH & \targ{}    & \meter{} & \qw
            \end{quantikz}
        };
    \end{tikzpicture}
\end{center}


\newcommand*{\circuitTarget}[1]{\targ[style={fill=yellow}]{#1}}

\begin{center}
    \begin{tikzpicture}
        \node at (-5,0) {(4)};
        \node[scale=1.0] {
            \begin{quantikz}
                \ket{0} & \qw            & \circuitH & \ctrl{1}         & \meter{} & \qw \\
                \ket{0} & \circuitX      & \circuitH & \circuitTarget{} & \meter{} & \qw
            \end{quantikz}
        };
    \end{tikzpicture}
\end{center}


\begin{center}
    \begin{tikzpicture}
        \node at (-4.4,0) {(5)};
        \node[scale=1.2] {
            \begin{quantikz}
                \ket{0} & \qw            & \circuitH & \ctrl{1}         & \meter{} & \qw \\
                \ket{0} & \circuitX      & \circuitH & \circuitTarget{} & \meter{} & \qw
            \end{quantikz}
        };
    \end{tikzpicture}
\end{center}



Previous: My five rules for making revisions from editorial comments
Next: What’s in the book

In December, 2019, Packt Publishing published my book Dancing with Qubits: How quantum computing works and how it can change the world. Through a series of blog entries, I talk about the writing and publishing process, and then about the content.

Dancing With Qubits, First Edition: The writing process – what format?

Cover of the book Dancing with QubitsBefore I discuss what and I how I wrote, let me talk about the markup of the book. By “markup” I mean the underlying format of the content that determines its structure such as the title page, table of contents, parts, chapters, sections, paragraphs, bibliography, and the index, along with font styles and sizes.

In my experience, most publishers, both traditional and online, prefer you to use Microsoft Word to create the book, and it has its own underlying markup language that you typically never see. In a more-or-less what-you-see-is-what-you-get way, you can write and style the book.The publishing workflow is often based on this choice.

My requirements for the book creation process included:

  • beautiful math rendering, both in sentences and displayed multi-part formulas,
  • built-in support for generating diagrams,
  • easy methods to change formatting throughout the book quickly, and
  • good support for working quickly on a large text.

Regarding the size of the book, in early 2019 I thought the book would come in around 300 pages and I would have a complete draft on September 1. I ended up writing a book with slightly more than 500 pages with the first full draft delivered on October 9. I had full drafts of various chapters before then, but that was the first time there were no sections with TODO markers.

ebook on iPadWord has come a long way on many of these requirements, especially the math, though it can be very laborious to create a book with hundreds or thousands of formulas. Here’s the real problem though: eBooks with math in them often look terrible if you put them in a reflowable format. That is, if you let, say, your Amazon Kindle change the fonts and the line widths, the math just doesn’t look right.

People argue about this forever, but there is an excellent chance that you will end up with fuzzy, misaligned expressions that are the wrong size compared to the surrounding text. So, I early on made the decision that the eBook would not be reflowable. Since that was the case, there was no reason for me to stick with Word. I decided to markup the book in LaTeX. Luckily, Andrew Waldron at Packt Publishing agreed. [Though see this later development regarding the eBook.]

With LaTeX, you have complete and arbitrary control over all parts of the formatting. There are thousands of packages that make your life easier by providing significant functionality that you would not want to write yourself.

LaTeX has

  • the best math formatting facilities of any system,
  • packages like pgf/tikz for creating diagrams,
  • a full macro programming language for formatting control and calculations, and
  • easy ways to break a document into sections so you can work on one part at a time.

If you get into macro programming, things can get complicated. I’ve been doing it for 30 years, so it doesn’t faze me. Here are two good books on LaTeX to get you started:


Previous: Last minute tweaks to my quantum computing book cover
Next: My five rules for making revisions from editorial comments

In December, 2019, Packt Publishing published my book Dancing with Qubits: How quantum computing works and how it can change the world. Through a series of blog entries, I talk about the writing and publishing process, and then about the content.

A tikz macro for drawing axes and grid for LaTeX

I’m writing something that requires me to draw many plots in the Cartesian plane R2 and so I wrote this macro to simplify the process. The arguments are

  1. The optional tikzpicture scaling factor
  2. The x-coordinate of the lower left corner
  3. The y-coordinate of the lower left corner
  4. The x-coordinate of the upper right corner
  5. The y-coordinate of the upper right corner
  6. The label for the horizontal axis
  7. The label for the vertical axis

It behaves nicely if any of the coordinates are 0 but does no checking for the values or placement of the corners.

I have a separate macro \tikzGridColor that defines the grid color. At the moment it is set to a shade of blue so the graph looks like it is done on graph paper.

Scroll right to see all the code.

[sourcecode language=”tex”]

\usetikzlibrary{angles,quotes,arrows,positioning}
\usetikzlibrary{arrows.meta,calc,patterns}
\usetikzlibrary{decorations.pathreplacing,backgrounds}

\def\tikzGridColor{blue!75!white}

\newcommand{\graphGridTwoD}[7][0.5]{
\draw[step=#1,\tikzGridColor,very thin] (#2-0.9,#3-0.9) grid (#4+0.9,#5+0.9);
\draw[thick,<->] (#2-0.75,0) — (#4+0.75,0) node[below] {\small #6};
\draw[thick,<->] (0,#3-0.75) — (0,#5+0.75) node[left] {\small #7};
\ifthenelse{#2<0} {\foreach \x in {#2,…,-1}
\draw[thick] (\x,.1) — (\x,-.1) node[below] {\tiny$\x$};
}{}
\ifthenelse{#4>0} {\foreach \x in {1,…,#4}
\draw[thick] (\x,.1) — (\x,-.1) node[below] {\tiny$\x$};
}{}
\ifthenelse{#3<0} {\foreach \y in {#3,…,-1}
\draw[thick] (.1,\y) — (-.1,\y) node[left] {\tiny$\y$};
}{}
\ifthenelse{#5>0} {\foreach \y in {1,…,#5}
\draw[thick] (.1,\y) — (-.1,\y) node[left] {\tiny$\y$};
}{}
\node[below left] at (0,0) {\tiny$0$};
}
[/sourcecode]

Verified by MonsterInsights