Data science in my book Dancing with Python

In my blog entry Quantum computing in my book Dancing with Python,” I covered what my book covers related to quantum computing. I also published the entry “Availability of my book Dancing with Python and its table of contents.”

Today, I want to specifically list what I discuss in the book in what I term “an extended definition of data science.” The core chapters are in Part III. Here are their titles, introductions, and chapter tables of contents:

III Advanced Features and Libraries

12 Searching and Changing Text

We represent much of the world’s information as text. Think of all the words in all the digital newspapers, e-books, PDF files, blogs, emails, texts, and social media services such as Twitter and Facebook. Given a block of text, how do we search it to see if some desired information is present? How can we change the text to add formatting or corrections or extract information?

Chapter 4, Stringing You Along, covered Python’s functions and methods. This chapter begins with regular expressions and then proceeds to natural language processing (NLP) basics: how to go from a string of text to some of the meaning contained therein.

12.1 Core string search and replace methods
12.2 Regular expressions
12.3 Introduction to Natural Language Processing
12.4 Summary

13 Creating Plots and Charts

Among mathematicians and computer scientists, it’s said that a picture is worth 210 words. Okay, that’s a bad joke, but it’s one thing to manipulate and compute with data, but quite another to create stunning visualizations that convey useful information.

While there are many ways of building images and charts, Matplotlib is the most widely used Python library for doing so. [MAT] Matplotlib is very flexible and can produce high-quality output for print or digital media. It also has great support for a wide variety of backends
that give you powerful mouse-driven interactivity. Generally speaking, if you have a coding project and you need to visualize numeric information, see if Matplotlib already does what you want. This chapter covers the core functionality of this essential library.

13.1 Function plots
13.2 Bar charts
13.3 Histograms
13.4 Pie charts
13.5 Scatter plots
13.6 Moving to three dimensions
13.7 Summary

14 Analyzing Data

While we can use fancy names like “data science,” “analytics,” and “artificial intelligence” to talk about working with data, sometimes you just want to read, write, and process files containing many rows and columns of information. People have been doing this interactively for years, typically using applications like Microsoft Excel® and online apps like Google Sheets™.

To “programmatically” manipulate data, I mean that we use Python functions and methods. This chapter uses the popular pandas library to create and manipulate these collections of rows and columns, called DataFrames. [PAN] [PCB] We will later introduce other methods in Chapter 15, Learning, Briefly. Before we discuss DataFrames, let’s review some core ideas from statistics.

14.1 Statistics
14.2 Cats and commas
14.3 pandas DataFrames
14.4 Data cleaning
14.5 Statistics with pandas
14.6 Converting categorical data
14.7 Cats by gender in each locality
14.8 Are all tortoiseshell cats female?
14.9 Cats in trees and circles
14.10 Summary

15 Learning, Briefly

Machine learning is not new, but it and its sub-discipline, deep learning, are now being used extensively for many applications in artificial intelligence (AI). There are hundreds of academic and practical coding books about machine learning.

This final chapter introduces machine learning and neural networks primarily through the scikit-learn sklearn module. Consider this a jumping-off point where you can use the Python features you’ve learned in this book to go more deeply into these essential AI areas if they interest you.

15.1 What is machine learning?
15.2 Cats again
15.3 Feature scaling
15.4 Feature selection and reduction
15.5 Clustering
15.6 Classification
15.7 Linear regression
15.8 Concepts of neural networks
15.9 Quantum machine learning
15.10 Summary

This book is an introduction, so my goal is to get you started on a broad range of topics. For example, here are the Python modules and packages discussed or used in each of the four chapters in Part III:

12 Searching and Changing Text: re, flashtext, spacy
13 Creating Plots and Charts: matplotlib, numpy, mpl_toolkits.mplot3d
14 Analyzing Data: pandas, numpy, matplotlib, squarify, matplotlib-venn
15 Learning, Briefly: sklearn, pandas, numpy

I mention in passing in the book several other packages, such as pytorch, as pointers for further exploration. I did not include in the list above standard modules such as math, random, and sys.

Dancing With Qubits, First Edition: What’s in the book

Cover of the book Dancing with Qubits

This morning I awoke to a very nice email from Tom Jacob, the Project Editor for my book at Packt Publishing. He said, in part,

We were able to successfully ship the book to our printers. …
Congratulations on achieving this milestone!

As I’ve mentioned before, my book was prepared using LaTeX and not Microsoft Word. I gave the publishers what was essentially the “camera-ready” PDF file from which to print. Hence the part about being able to “successfully ship” the book. In fact, I sent them the final PDF last night. I thought I was done on Friday, but yesterday I noticed an out-of-place citation in the section on the Bloch sphere and did a quick fix.

Now that the book is in production and there is absolutely nothing else I can do to fiddle with it, I’m going to show you the table of contents. I tried to have fun with some of the chapter and section titles. Once the book is published, I’ll be happy to discuss why I included this content or that.


Dancing with Qubits
How quantum computing works and
how it can change the world

Preface ix

1  Why Quantum Computing? 1

1.1 The mysterious quantum bit 2

1.2 I’m awake! 4

1.3 Why quantum computing is different 7

1.4 Applications to artificial intelligence 9

1.5 Applications to financial services 15

1.6 What about cryptography? 18

1.7 Summary 21

I  Foundations 23

2  They’re Not Old, They’re Classics 25

2.1 What’s inside a computer? 26

2.2 The power of two 32

2.3 True or false? 33

2.4 Logic circuits 36

2.5 Addition, logically 39

2.6 Algorithmically speaking 42

2.7 Growth, exponential and otherwise 42

2.8 How hard can that be? 44

2.9 Summary 55

3  More Numbers than You Can Imagine 57

3.1 Natural numbers 58

3.2 Whole numbers 60

3.3 Integers 62

3.4 Rational numbers 66

3.5 Real numbers 73

3.6 Structure 88

3.7 Modular arithmetic 94

3.8 Doubling down 96

3.9 Complex numbers, algebraically 97

3.10 Summary 103

4  Planes and Circles and Spheres, Oh My 107

4.1 Functions 108

4.2 The real plane 111

4.3 Trigonometry 122

4.4 From Cartesian to polar coordinates 129

4.5 The complex “plane†129

4.6 Real three dimensions 133

4.7 Summary 134

5  Dimensions 137

5.1 R2 and C1 139

5.2 Vector spaces 144

5.3 Linear maps 146

5.4 Matrices 154

5.5 Matrix algebra 166

5.6 Cartesian products 176

5.7 Length and preserving it 177

5.8 Change of basis 189

5.9 Eigenvectors and eigenvalues 192

5.10 Direct sums 198

5.11 Homomorphisms 200

5.12 Summary 204

6  What Do You Mean “Probably� 205

6.1 Being discrete 206

6.2 More formally 208

6.3 Wrong again? 209

6.4 Probability and error detection 210

6.5 Randomness 212

6.6 Expectation 215

6.7 Markov and Chebyshev go to the casino 217

6.8 Summary 221

II  Quantum Computing 223

7  One Qubit 225

7.1 Introducing quantum bits 226

7.2 Bras and kets 229

7.3 The complex math and physics of a single qubit 234

7.4 A non-linear projection 241

7.5 The Bloch sphere 248

7.6 Professor Hadamard, meet Professor Pauli 253

7.7 Gates and unitary matrices 265

7.8 Summary 266

8  Two Qubits, Three 269

8.1 Tensor products 270

8.2 Entanglement 275

8.3 Multi-qubit gates 283

8.4 Summary 295

9  Wiring Up the Circuits 297

9.1 So many gates 298

9.2 From gates to circuits 299

9.3 Building blocks and universality 305

9.4 Arithmetic 315

9.5 Welcome to Delphi 322

9.6 Amplitude amplification 324

9.7 Searching 330

9.8 The Deutsch-Jozsa algorithm 338

9.9 Simon’s algorithm 346

9.10 Summary 354

10  From Circuits to Algorithms 357

10.1 Quantum Fourier Transform 358

10.2 Factoring 369

10.3 How hard can that be, again 379

10.4 Phase estimation 382

10.5 Order and period finding 388

10.6 Shor’s algorithm 396

10.7 Summary 397

11  Getting Physical 401

11.1 That’s not logical 402

11.2 What does it take to be a qubit? 403

11.3 Light and photons 406

11.4 Decoherence 415

11.5 Error correction 423

11.6 Quantum Volume 429

11.7 The software stack and access 432

11.8 Simulation 434

11.9 The cat 439

11.10 Summary 441

12  Questions about the Future 445

12.1 Ecosystem and community 446

12.2 Applications and strategy 447

12.3 Access 448

12.4 Software 449

12.5 Hardware 450

12.6 Education 451

12.7 Resources 452

12.8 Summary 453

Afterword 455

Appendices 458

A  Quick Reference 459

A.1 Common kets 459

A.2 Quantum gates and operations 460

B  Symbols 463

B.1 Greek letters 463

B.2 Mathematical notation and operations 464

C  Notices 467

C.1 Creative Commons Attribution 3.0 Unported (CC BY 3.0) 467

C.2 Creative Commons Attribution-NoDerivs 2.0 Generic (CC BY-ND 2.0) 468

C.3 Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) 468

C.4 Los Alamos National Laboratory 469

C.5 Trademarks 469

D  Production Notes 471

Other Books You May Enjoy 473

Index 477


Changes, clarifications, and errata


Previous: Drawing quantum circuits
Next: What about the eBook?

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.

Dancing With Qubits, First Edition: Let me preface my remarks with …

Cover of the book Dancing with QubitsWay back in 1992, Springer-Verlag published my first book Axiom: The Scientific Computation System, co-authored with the late Richard D. Jenks. Since then I’ve thought of writing other books, but work and life in general caused enough inertia that I never got around to it.

I first got involved with IBM’s quantum computing effort in early 2016. By 2018, I was again thinking of writing a book and this subject was an obvious candidate. How would I start? What would I say? What was my perspective on the topic given that there were already some excellent books?

To write a book, you have to start writing. This is obvious, but no less true and important. In the summer of 2018, I started writing what I thought would be the introduction to the book. My perspective was, and is, very much from the mathematical and computer science directions. To be clear, I am not a physicist. If I could produce a coherent introduction to what I thought the book would cover, I might convince myself that it would be worth the hundreds of hours it would take to complete the project.

When I recently announced that the book was available for pre-order, my industry colleague Jason Bloomberg asked:

“So where does it fall on the spectrum between ‘totally accurate yet completely impenetrable’ and ‘approachable by normal humans but a complete whitewash’?”

I responded:

“I bring you along … to give you the underlying science of quantum computing so you can then read the “totally accurate but formally impenetrable” texts.”

I decided that I would cover the basic math necessary to understand quantum computing, and then get into quantum bits (qubits), gates, circuits, and algorithms. Although readers with the necessary background (or perhaps a good memory of that background) can skip the mathematical fundamentals, I decided to take people through the algebra and geometry of complex numbers, linear algebra, and probability necessary to understand what qubits are and what you can do with them.

That early draft of the book’s introduction described roughly 15 chapters divided into three parts. The final book has 12 chapters and 2 parts. That introduction eventually became the Preface. Part III eventually became Chapter 1.

It’s much tighter than what I imagined it would be, but there is still material I could have covered. There’s a natural tendency to want to add more and more, but I kept asking myself “What is this book about? How deeply do I want to go? Am I getting off track? Will I ever finish?”.

As 2018 went on, I kept tweaking the introduction and I started talking to publishers. In November, I started writing what was then the first chapter. Although I started in Microsoft Word, which is overwhelmingly the format of choice for many publishers, I quickly switched to LaTeX. This produced a far more beautiful book, but also placed constraints on how I could publish the book.

With this as teaser, in future entries I’ll talk more about the writing process, choices I made, LaTeX packages I used and macros I wrote, deciding how to publish the book, and working with editors. Once the book is available, I’ll talk about the specific content and why I included what I did.


Next: Last minute tweaks to my quantum computing book cover

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.
Verified by MonsterInsights