ŷ

Jump to ratings and reviews
Rate this book

From Mathematics to Generic Programming

Rate this book
In this substantive yet accessible book, pioneering software designer Alexander Stepanov and his colleague Daniel Rose illuminate the principles of generic programming and the mathematical concept of abstraction on which it is based, helping you write code that is both simpler and more powerful.

If you’re a reasonably proficient programmer who can think logically, you have all the background you’ll need. Stepanov and Rose introduce the relevant abstract algebra and number theory with exceptional clarity. They carefully explain the problems mathematicians first needed to solve, and then show how these mathematical solutions translate to generic programming and the creation of more effective and elegant code. To demonstrate the crucial role these mathematical principles play in many modern applications, the authors show how to use these results and generalized algorithms to implement a real-world public-key cryptosystem.

As you read this book, you’ll master the thought processes necessary for effective programming and learn how to generalize narrowly conceived algorithms to widen their usefulness without losing efficiency. You’ll also gain deep insight into the value of mathematics to programming–insight that will prove invaluable no matter what programming languages and paradigms you use.

You will learn about
How to generalize a four thousand-year-old algorithm, demonstrating indispensable lessons about clarity and efficiency
Ancient paradoxes, beautiful theorems, and the productive tension between continuous and discrete
A simple algorithm for finding greatest common divisor (GCD) and modern abstractions that build on it
Powerful mathematical approaches to abstraction
How abstract algebra provides the idea at the heart of generic programming
Axioms, proofs, theories, and models: using mathematical techniques to organize knowledge about your algorithms and data structures
Surprising subtleties of simple programming tasks and what you can learn from them
How practical implementations can exploit theoretical knowledge

320 pages, Paperback

First published October 3, 2014

136 people are currently reading
1,012 people want to read

About the author

Alexander A. Stepanov

4books8followers

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
84 (40%)
4 stars
83 (39%)
3 stars
33 (15%)
2 stars
7 (3%)
1 star
3 (1%)
Displaying 1 - 20 of 20 reviews
Profile Image for Jake.
211 reviews41 followers
October 10, 2016
“As long as algebra and geometry have been separated, their progress have been slow and their uses limited, but when these two sciences have been united, they have lent each mutual forces, and have marched together towards perfection.� ~ Joseph Louis Lagrange

What does geometry, abstract algebra, number theory and generic programming have in common? This book attempts to answer that by starting at the early stages of organized mathematics and going all the way forward to the 1960’s. The way I thought about Stepanov’s approach is that he attempts to generalize algorithms and shows how algorithms in many respects can be used as axioms. In other words, generalization is not just merely a time saver, but more crucially is a way to ensure rigorousness.

“Mathematics is a game played according to certain simple rules with meaningless marks on paper.� ~ David Hilbert

In many ways this book is just Stepanov removing the paper. The fact that he uses C++ code is irrelevant. I used Python and Java, without having used C++ in years and it was sufficiently trivial that I could follow along. The Euclidean algorithm(greatest common denominator) is the main tool of Stepanov of this book, may be used too much. Algorithms have existed, as he says for as long as we’ve been doing math. The fact that computers use them is historically new, not the norm. Turns out that mathematicians have developed great methods for analyzing such algorithms and the Euclidean algorithm is used exhaustively in a variety of ways to illustrate both the axiomatic nature of algorithm reuse but also how we might do analysis on such algorithms.

If you’ve read my review for Dijkstra's A Discipline of Programming you might remember the line I said: “abstraction is not a nebulous idea, but how we’re absolutely precise.� That's what what Stepanov, like Dijkstra is trying to get across here. Just because we are reorienting our thinking does not mean we lose rigorousness, in fact it's how we ensure it. I'm taking a lot of Calculus in my undergrad so an algorithm I use daily is the Hessian Criterion or second derivative test, I followed along with Stepanov's writing by implementing that algorithm in SymPy then analyzing it. This is what I recommend you do with this book, don't simply copy his examples and expect to get some kind of understanding through wrought memorization but explore what he’s talking about with your own work. It's much more rewarding and more in line with what I think the author was trying to get across by including the examples to begin with.

"Pursue what you're interested in, keep working hard, pay attention to what's going on around you and be flexible-these are the rules. Sometimes it works, sometimes it doesn't." ~ Nathan Seiberg
Profile Image for Michael.
36 reviews7 followers
June 1, 2015
Depends on what you expect

I was very enthusiastic about this book when it was first announced. My expectation was that author will give some introduction to mathematical constructs related to program composition that comes from category theory and functional programming, like monads, applicatives, traversables and so on. Instead I found all familiar view on algebra, things ike groups, rings, some number theory and cryptography.
However despite my own dissatisfaction I can't avoid mentioning that book is exceptionally well written. Through historical view on mathematics development author achieved very whole and capturing story. I spent some fun good time reading it.
Bottom line: read it if you want to get familiar with abstract algebra and number theory. Or if you want some good time reading about history of mathematics.
Profile Image for John Jaksich.
114 reviews1 follower
September 27, 2018
For those of us who need a refresher-- and a bit more.

Computer programming is a wholly mathematical pursuit. Although many computer science departments are housed in engineering, the heart and soul is abstract mathematics.

This book reminds us that a computer only does what it is told to do-- and told in a proper fashion. While the present tends fall towards AI --- this book takes a decidedly different tact---- It gives us the rudimentary basics of computer security-- whose fundamentals rest in Abstract Algebra. It is a joy to read.
Profile Image for Filippo Pacifici.
46 reviews3 followers
January 3, 2021
This book outlines the mathematical foundations of abstract algorithms very well. The path from abstract algebra to abstract algorithms is outlines quite well.
What I think was not so compelling is the amount of time spent on the details of numbers theory which I don't think helps the narrative a lot.
I feel going deeper in the foundation of types and their connection to generic programming (like touching on category theory) could have been more informative than going so deep in the numbers theory aspect of so many examples.
I may just not represent the intended audience for this book.
41 reviews
April 23, 2023
A wonderful introduction to generic programming as a way of thinking about code. It has well-motivated examples, and new ones I wasn't aware of, like Stein's GCD. All in all, a lot of food for thought, especially for the next time I write code.
22 reviews3 followers
May 15, 2018
Not the best to learn Number Theory and Algebra from, really requires you to have some knowledge of these in the first place.
Profile Image for Riley Holmes.
61 reviews20 followers
September 19, 2018
Very cool book which builds a bridge between abstract algebra, and template functions in C++.
Profile Image for Eric.
674 reviews8 followers
January 16, 2019
I wonder what’s up with C++ Concepts these days...
6 reviews1 follower
June 22, 2020
Много Математики и Языка C++, но к сожелению не рассматирвается алгоритмы на уровне машины, высокоуровневый язык имеет много ограничений
Profile Image for Austin Gilbert.
9 reviews
April 3, 2024
I didn't attempt to follow all the math, but I really enjoyed the math history and information about mathematicians and their contributions.
208 reviews46 followers
February 6, 2015
A worthy follow-up to . Where Elements was terse, like an old math book, this book is more conversational; and it includes short biographies about some of the mathematicians mentioned in the text. Includes more by way of proofs than Elements. Includes a handful of programming "laws" such as "the law of useful return" (if you've gone through the trouble of calculating something, consider returning it even if your current callers will ignore the return value).

, Stepanov said "It is as if mathematicians would start with axioms. You do not start with axioms - you start with proofs. Only when you have found a bunch of related proofs, can you come up with axioms. You end with axioms." Since all math textbooks I've ever used started with axioms, I was curious to see how things could be different. This book stands as a great example of just that (the authors don't point that out until near the end). I am considering sending copies to some friends and relatives; not all programmers or mathematicians.
2 reviews
January 30, 2016
This is a short dense book packed with historical information about mathematics. All the template code examples given are short and well-explained.

While the title implies a mathematical derivation for the use of generic programming, it rather uses varied mathematical algorithms to illustrate its use.

The cover blurb states "If you’re a reasonably proficient programmer who can think logically, you have all the background you’ll need" while the Prerequisites given in chapter 1 state "we don’t assume any specific mathematical knowledge beyond high school algebra and geometry". Both these statements are disingenuous if not outright misleading. Having studied maths at University I was still frequently confused and had to take time to work out what was being explained. For example, while I'm familiar with � notation for summation I'd never seen its product equivalent �, this was not explained.

So, while this book is interesting and informative, due to its length it is terse, dense and challenging. It is also very readable and covers a lot of material.

It is of use and value, but not one to be used lightly or easily and really only for mathematicians.
Profile Image for Tim Robinson.
998 reviews55 followers
February 10, 2017
If you are really interested in the mathematical discipline of abstract algebra, and you are really interested writing code that is both efficient and has the widest possible application, and you can read C++, then this is the book for you.
Profile Image for ifknot.
12 reviews4 followers
June 25, 2016
Very good book has really inspired me on many levels by its mathematical depth (which was set just about as far down as I can go) as well its breadth with the historical interludes were fascinating and stimulating. I wasn't sure where it was going when it started with GCD and Egyptians but it worked really well. A genuinely good read as well as reference and a store of multiple jump off points into further reading.
3 reviews39 followers
August 29, 2016
It takes a special author to seamlessly jump between ancient Babylonian astronomers using positional sexagesimal (60 based) system and C++ generics. Lucky for reader, both authors are doing it with ease.

Read this exceptionally well written book packed with historical information about mathematics and programming if you want some good time learning about history.

44 reviews29 followers
April 14, 2017
A difficult but rewarding read. It's one of those one-in-a-hundred books that have truly remarkable insights to offer which will permanently affect the way you look at things. While the subject matter can be a bit dry sometimes, it's loosened up with interesting historical context around number theory and abstract algebra.

For all the insight it offers, unfortunately, there are some aspects which I thought prevented it from being flawless:

The authors chose the unfortunate approach of teaching you so often find in academia, where one is expected to pore over difficult problems while only been given the vaguest idea of what they might be useful for. Once you see it all come together in the last chapter, chances are you have already forgotten what those key ideas were you tried to decipher 6 chapters earlier. And these aren't trivial matters we're talking about, but profound mathematical insights such as Fermat's Little Theorem and related work about primes.

This is amplified by the authors sending you through mathematical proofs sometimes stretching over multiple pages, an exercise which I personally find exhausting and useless. I get it: you're smart guys and you can demonstrate what you say is truthful, but I don't need it laid out in front of me in excruciating detail. Whenever a proof spans more than a paragraph or two, I think it belongs in an appendix, since it doesn't further the ideas being conveyed, it merely backs them up formally.

I personally found the choice of language, C++, to be understandable but unfortunate (Stepanov is the main guy behind the STL). Not that it's impossible to follow the code, but its arcane syntax does get in the way sometimes (who iterates collections using pointer arithmetic these days?), and it does feel a little like time traveling to the 90s. There are modern languages that have much better support for expressing generic algebraic structures while enjoying terse and straight-forward syntax (Scala, for instance) which would have helped in focusing on the actual problem and help readers translate these ideas into code they would actually write.

None of that makes this book any less of a recommendation though.
Displaying 1 - 20 of 20 reviews

Can't find what you're looking for?

Get help and learn more about the design.