“**From Mathematics to Generic Programming**” review. A book by Alexander Stepanov and Daniel Rose. Published by Addison-Wesley.

## Book review

Let the title of the book, **From Mathematics to Generic Programming**, doesn’t confuse you. My first impression after seeing it was that the book will teach me how to write generic code including constructs like iterators and the mathematical theory being behind them. After reading it, it turned out that the book is in fact not about what I had excepted from the title. **From Mathematics to Generic Programming** is really a book about mathematics in programming in general, with focus on mathematics behind the generic programming. There is not much about generic programming itself. A much better title would be “The Mathematical Theory behind Generic Programming”.

If you are looking for a book about generic programming, you may be now wondering if you should get this book or not. The answer to this question is, in my opinion, definitely yes. **From Mathematics to Generic Programming** may not contain much about generic programming itself, but it contains a lot of well explained concepts from the mathematical background of generic programming. All of this theory is a fundamental that allows to truly understand the concept behind the generic programming.

**From Mathematics to Generic Programming** will teach you how to practically use various mathematical axioms, theorems, structures, algorithms and techniques that are very useful not only in generic programming, but in general programming as well. Starting with as simple concepts as ancient multiplication algorithms, through monoids, groups, rings or fields, the book will get you to the point where you will be able to very easily understand how RSA algorithm works and even to implement it yourself.

The book is written in light non-academic style, rather than in style of academic technical books. It is filled with short biographies of important mathematicians along with stories about how they developed the knowledge that strongly influenced generic programming. All of that make this book a very interesting read, making the entire experience of reading it similar to reading a history book. You simply don’t want to put the book away, because you are very curious of what is next in that great history of mathematics. After finishing the book I placed orders for next books, like Euclid’s Elements, because the author really made me interested in pursuing more knowledge about the topics he wrote about.

Since this is a book about mathematics, you may be wondering what prerequisites are needed to understand it. The good news is that anybody who understand high-school mathematics should have no problem with reading it. If you think that your knowledge is a little rusty, read about high-school-level algebra and geometry to recall most of the information you need. Beside mathematics, you will need some basic knowledge of C++ to understand the code examples (there are not much of them, however). The examples are simple enough to make them understood by non-C++ programmers. If you program in languages with a similar syntax, like Java, then you should have not much trouble with them. In case you would have any troubles with the examples, on the end of the book is an appendix “C++ for Non-C++ Programmers” which should dispel any doubts.

In a summary, the book is a great and unique position for people wanting to learn the mathematical theory behind generic programming, or learn about mathematics in computer programming in general. While this book will not teach you how to write generic code, it will teach you fundamental knowledge that will allow you to understand the concept behind generic programming. As mathematics is the fundamental of computer programming, learning mathematics is a certain way toward becoming a better programmer.

I have really enjoyed the book and I recommend it for anybody who wants to become a better programmer or wants to better understand generic programming.

Get **From Mathematics to Generic Programming** on Amazon

## Table of Contents

Chapter 1: What This Book Is About
1.1 Programming and Mathematics 1.2 A Historical Perspective 1.3 Prerequisites 1.4 Roadmap
2.1 Egyptian Multiplication 2.2 Improving the Algorithm 2.3 Thoughts on the Chapter
3.1 Geometric Properties of Integers 3.2 Sifting Primes 3.3 Implementing and Optimizing the Code 3.4 Perfect Numbers 3.5 The Pythagorean Program 3.6 A Fatal Flaw in the Program 3.7 Thoughts on the Chapter
4.1 Athens and Alexandria 4.2 Euclid’s Greatest Common Measure Algorithm 4.3 A Millennium without Mathematics 4.4 The Strange History of Zero 4.5 Remainder and Quotient Algorithms 4.6 Sharing the Code 4.7 Validating the Algorithm 4.8 Thoughts on the Chapter
5.1 Mersenne Primes and Fermat Primes 5.2 Fermat’s Little Theorem 5.3 Cancellation 5.4 Proving Fermat’s Little Theorem 5.5 Euler’s Theorem 5.6 Applying Modular Arithmetic 5.7 Thoughts on the Chapter
6.1 Groups 6.2 Monoids and Semigroups 6.3 Some Theorems about Groups 6.4 Subgroups and Cyclic Groups 6.5 Lagrange’s Theorem 6.6 Theories and Models 6.7 Examples of Categorical and Non-categorical Theories 6.8 Thoughts on the Chapter
7.1 Untangling Algorithm Requirements 7.2 Requirements on A 7.3 Requirements on N 7.4 New Requirements 7.5 Turning Multiply into Power 7.6 Generalizing the Operation 7.7 Computing Fibonacci Numbers 7.8 Thoughts on the Chapter
8.1 Stevin, Polynomials, and GCD 8.2 Göttingen and German Mathematics 8.3 Noether and the Birth of Abstract Algebra 8.4 Rings 8.5 Matrix Multiplication and Semirings 8.6 Application: Social Networks and Shortest Paths 8.7 Euclidean Domains 8.8 Fields and Other Algebraic Structures 8.9 Thoughts on the Chapter |
Chapter 9: Organizing Mathematical Knowledge
9.1 Proofs 9.2 The First Theorem 9.3 Euclid and the Axiomatic Method 9.4 Alternatives to Euclidean Geometry 9.5 Hilbert’s Formalist Approach 9.6 Peano and His Axioms 9.7 Building Arithmetic 9.8 Thoughts on the Chapter
10.1 Aristotle and Abstraction 10.2 Values and Types 10.3 Concepts 10.4 Iterators 10.5 Iterator Categories, Operations, and Traits 10.6 Ranges 10.7 Linear Search 10.8 Binary Search 10.9 Thoughts on the Chapter
11.1 Permutations and Transpositions 11.2 Swapping Ranges 11.3 Rotation 11.4 Using Cycles 11.5 Reverse 11.6 Space Complexity 11.7 Memory-Adaptive Algorithms 11.8 Thoughts on the Chapter
12.1 Hardware Constraints and a More Efficient Algorithm 12.2 Generalizing Stein’s Algorithm 12.3 Bézout’s Identity 12.4 Extended GCD 12.5 Applications of GCD 12.6 Thoughts on the Chapter
13.1 Cryptology 13.2 Primality Testing 13.3 The Miller-Rabin Test 13.4 The RSA Algorithm: How and Why It Works 13.5 Thoughts on the Chapter
B.1 Proof by Contradiction B.2 Proof by Induction B.3 The Pigeonhole Principle
C.1 Template Functions C.2 Concepts C.3 Declaration Syntax and Typed Constants C.4 Function Objects C.5 Preconditions, Postconditions, and Assertions C.6 STL Algorithms and Data Structures C.7 Iterators and Ranges C.8 Type Aliases and Type Functions with using in C++11 C.9 Initializer Lists in C++11 C.10 Lambda Functions in C++11 C.11 A Note about inline |

## About the authors

**Alexander Stepanov** is a computer programmer, mathematician and pioneer of generic programming. He is most known by creation and major contribution to the C++ STL (Standard Template Library), for which he received Dr. Dobb’s Journal Excellence in Programming Award. Currently he is working for A9, a subsidiary of Amazon that works on developing product search and advertising technology. His previous employers include GE, Polytechnic University, Bell Labs, HP, SGI and Adobe.

**Daniel Rose** is a computer programmer and research scientist specializing in search technologies, ranging from low-level algorithms for index compression to human-computer interaction issues in web search. Currently he works as Chief Scientist at A9, together with Alexander Stepanov. His previous employers include Yahoo!, AltaVista, Xigo and Apple. He holds a PhD in cognitive and computer science from University of California and a B.A. in philosophy from Harvard.

Omid3 years agoThat is a great book, I have bough it some time ago. Some topics are hard but still understandable.

Joseph3 years agoI did read this book. It gives an enlightenment when you learn what is happening behind the code on mathematics level. Suddenly I understood a bunch of other concepts that were hard for me earlier. Before going into any advanced programming one should grab this book to open his or hers eyes. It makes much things easier to understand.

joenilly3 years agonever knew that Stepanov wrote books

xxx3 years agoHonestly i did not liked it, i expected generic programming as the title said and there was nothing about generic programming all math!

Anna S.3 years agoAs a mathematician I can recommend this book as well. It explains plenty of concepts in simple language. I wish I had this book when I was about to start the uni!

whitesunshine3 years agoA book by Stepanov must be a good one. This guy is a genius!

Ryan3 years agoI finished this book in december. Indeed this is mathematics book rather than generic programming book but nevertheless it is great to read.

It’s looking interesting

Peter Kole3 years agoVery helpful review. I have seen some negative reviews and comments about this book, but it seems that those people didn’t get the point about importance about mathematics in (generic) programming. I will get the book when I get home. Thank you.

Ray3 years agoI got this book for Christmas, I’ve just finished it reading now as well! Nice coincidence!

I agree with the blog author about the review. Not much about generic programming, but a lot about great mathematics. Definitely a good supplement for learning generic programming.

Jurij3 years agoRussian readers know there is a Russian version of this book (От математики к обобщенному программированию)