Hacker News new | ask | show | jobs
by dilippkumar 1723 days ago
I’m currently enjoying “From Mathematics to Generic Programming” by Alexander Stepanov and Daniel E. Rose.

One thing about the book is that it’s a lot more interesting than what a cursory scan of the table of contents would suggest. An O(log n) algorithm for multiplication doesn’t seem interesting at first. But the authors do an amazing job of starting from familiar ideas and building up to surprisingly beautiful and elegant ideas.

I think I’m finally able to grok c++ templates half way through this book.

One unfortunate downside to this book is that the authors wrote this before concepts were introduced in c++20. I would love to see an updated edition of this book that use the real c++20 concepts. However, this doesn’t diminish my recommendation for this book.

2 comments

Sounds interesting. I know no C++, can I still enjoy the book? I have no interest in learning it.
I don't know the answer - This is primarily a book about generic programming using C++ templates.

I suppose you can learn about the power of generic programming and apply it to another language. There is probably some non-zero amount of things that you can pick up from this book that you can apply elsewhere. However, I don't know if that is enough to justify going through this book. Your milage might vary.

What do you mean by an O(log(n)) algorithm for multiplication ? The naive approach takes O(n^2) and O(nlog(n)) is extremely state of the art and is unlikely to be in a programming book
See page 17 of [0]. Here the big-O is about the value of one of the parameters to multiply(n,m) (say the first), not the number of bits in the values. In the naive multiplication algorithm you have repeated addition which gives you a O(n) algorithm, but you can also do the half & double approach (similar to fast exponentiation) which gives you a O(log n) algorithm.

[0] https://www.fm2gp.com/slides/FM2GP_Course_Slides_Pt1.pdf