Hacker News new | past | comments | ask | show | jobs | submit login
Mathematics for Programmers [pdf] (yurichev.com)
194 points by signa11 4 hours ago | hide | past | favorite | 29 comments





For all the mathematics enthusiasts and scholars out here, we have Slack and Freenode IRC channels[1][2] to discuss mathematics and computer science literature like this.

It is a reading and discussion group that focuses on math and CS books, articles, and papers, as well as using software tools like Python, WolframAlpha, Desmos, etc. to explore new concepts we come across. As an example of what we discuss in this forum, see "From Vector Spaces to Periodic Functions"[3] that was a result of one of the discussions in this forum. We plan to discuss Munchausen numbers[4] next.

If this sounds interesting to you, please join us.

[1]: https://bit.ly/euclidslack

[2]: https://webchat.freenode.net/#euclidpoint

[3]: https://susam.in/blog/from-vector-spaces-to-periodic-functio...

[4]: https://arxiv.org/pdf/0911.3038.pdf


Thanks for this! As fresh IT Dev student, this will help me out!

In my opinion, the only type of mathematics that is useful to ALL programmers is discrete math. This is applied math that barely resembles the kind of math that you learned in high school, but it’s easy to see how these thoughts lead to the creation of computers.

Other types of math are relevant depending on what you’re interested in, but I think students should learn discrete math before diving into writing any serious code.


At first glance, this is actually a refreshing take on "teach math to coders".

There are 1-2 other books constantly recommend here, which are (probably) fantastic but throw you off the deep end with assumptions that you understand algebra, trigonometry, fundamental calculus, and statistics.

Essentially, that you finished school and paid attention. Which is a well-founded assumption. And I don't necessarily expect an author to assume responsibility for covering fundamentals, but it's nice if there are authors willing to do this.


That seems somewhat universal. I remember attending the first suggested university course on math and barely recognising what was written on the first page of the material. It turned out that the material was written well before the high school curriculum on math in my country was substantially dumbed down, and was not very accessible for recent high school graduates. Other universities provided more verbose study material, while mine was trying to make the material as concise as possible. For whatever reason, math seems to be the only field in which conciseness usually trumps readability.

I passed the course (Analysis I) with the minimum score by memorising previous exams and their answers, without understanding any of it, or ever needing the skills on my professional career.

Logic and algebra classes were a lot more approachable, enjoyable and eventually useful. I am looking forward to learn something from this material, too.


It would be cool if the authors offered a list of pre-reqs. Sometime I look at a math book and don't understand the first few chapters but I am willing to build up to it provided I know what to read first.

Coding and math books frequently list prerequisites by saying something like "only really trivial mathematics knowledge that any adult should be familiar with" and then you start working through the book and realize they meant any adult that took multiple years of calculus in high school and graduated with a BS in Comp Sci or mathematics.

As a high school drop out that only later on developed an interest in learning its pretty frustrating. My BS is in Information Systems so I've missed out on a lot of math that seems to make learning computer science and programming easier. I'll have to give this resource a try. I'm a big fan of his reverse engineering material already.


I identify so hard with your comment! I’m proficient with a handful of programming languages, very comfortable with most Sys admin tasks on Unix-like OSes, and I’m almost always able to reverse engineer someone else’s similar solution to meet my needs. However, I’ve had any formal computer science education. Now, in my early 30s, I’ve found a successful career in a non-tech field but find it unfulfilling. I still love to program and I’d love to make a change, but my lack of a math and comp sci foundation gnaws at me.

I’ve tried to relearn Calc a handful times, but find myself frustrated when I have to go look up basic trig identities, and order of operations stuff just to get through practice problems. I’d love to relearn math from scratch if anyone has any recommendations.


What are the 1-2 books that are constantly recommended here?

"A Programmer's Introduction to Mathematics", by Jeremy Kun is the one you'll see a lot

https://pimbook.org/

The other one is in web format, it's something along the lines of "Visual Linear Algebra". Really unsure of title, but it's centered around visualizations of the math.

On my laptop I would post bookmark but I'm in bed on phone, sorry =/

Edit: Here

https://textbooks.math.gatech.edu/ila/

http://immersivemath.com/ila/index.html


there's also Intro to mathematical thinking: https://www.coursera.org/learn/mathematical-thinking/home/we...

and mathematics for machine learning: https://mml-book.github.io/


MCS - Mathematics for Computer Science - is one. From MIT, free. A google should find it.

One subject that's pretty useful for programmers to understand reasonably well is numerical analysis, even if it's at a fairly basic level. It's amazing how quickly you run into problems in practice as soon as you try to do anything with floating point numbers.

I didn't carefully read through the section on modular arithmetic, so maybe this is already there, but one thing worth noting that bites a lot of people is that using modular arithmetic for integer representations means that addition, subtraction, and multiplication work the same for signed and unsigned integers. This means that you can typically write arithmetic expressions involving these operations without worrying too much about whether things are being regarded as signed or unsigned at intermediate steps. As soon as you introduce division into the mix, though, the whole thing falls apart, and you have to be very careful about how the language is interpreting each subexpression.


I'm not sure understand what you're saying with mod arithmetic.

Can you provide an example?


Not OP, but I'll give it a shot. At a low level pretty much all standard integer math is mod arithmetic, typically mod 2^32 or 2^64 depending on if a computer is 32 or 64 bit. This means that when a number goes above this limit it "overflows" and only the part left after dividing by the mod size is left. Additionally, negative numbers are stored by essentially counting down from the maximum number that can be stored + 1, in scholarly terms this is the twos complement. For instance on a 32 bit system -7 as a signed integer would be stored identically to the unsigned integer (2^32)-7. For anyone new to programming, unsigned meaning an integer variable that can only be positive and signed being an integer variable that could be positive or negative.

Now all of this combines to make addition, subtraction, and even multiplication essentially identical for signed and unsigned numbers. On an 8 bit system (so integers can be between 0 to 255 inclusive) you could be trying to add the signed number 40 and the unsigned number 200. Naturally, this is 200+40 or 240. Now inside the computer, 240 is stored in the exact same way that -16 is so it is important that the software knows the correct way to handle the variable. This is equivalent to subtracting 56 from 40, and the signed integer -56 is represented in the exact same way as the unsigned integer 200.

Now this is where it starts to get crazy. What if you add the signed integer -5 (represented by 251 in the unsigned world) and the unsigned integer 100? Well it is equivalent to 251 + 100 = 351. However, now we encounter modular arithmetic, because this is an 8 bit system and the maximum value for an integer is 255 we calculate everythihg mod 256, so ar left with 351 % 256 = 95. You can mentally view this as the calculation occurring with 1s and 0s, where everytime a 1 is added to a 1, there is a single bit carried and the last bit is dropped, which is exactly how full and half adders work in a processor!

This also works for multiplication! If we multiply -5 by 5, we get -25 easily. But for computers we do 251 * 5 = 1255. The modulo math starts to get tricky for us puny humans but for a computer it is trivial, 1255 % 256 = 231. As a signed integer that is equal to -25, as it is equivalent to (255+1-25).

For division, everything is just crazy. 250/5 is way different than -5/5, no amount if mod arithmetic will save it. Unsigned 50 and signed -1 have completely different representations, and this is even an example without fractions and rounding.

I may have went long winded, but hopefully this helps someone!


You're a cool bear! Thanks for the detailed explanation!

You can think of it as applying a mod operator after each operation.

Say we wanted to work with mod 5 Then 6 + 8 = 14 = 4 mod 5


Also see Matters Computational (the fxtbook): https://www.jjj.de/fxt/

My impression after a quick once-over is that there's an order of magnitude too little linear algebra in this. Can't have 3D video games without it, can't do large parts of machine learning and statistics without it, etc etc.

It says it's an early draft, and the lack of a coherent path in the Linear Algebra section (currently final section) plus only two sub-chapters makes me think it's under work atm.

I also have not a clue what I'm talking about with math (sub-highschool understanding) so I could be very mistaken about the path thing.


I’m in the middle of speed running khan academy’s entire math section. This’ll compliment my task well. Thanks for sharing.

I would also recommend Concrete Mathematics by Donald Knuth, Oren Patashnik, and Ronald Graham as another refreshing approach.

Unlike the other comments so far, I have a link that is in my opinion NOT generally useful for most programmers. I figured it is worth a share for the programmer who knows all of the math in this post and wants to learn yet more:

https://bartoszmilewski.com/2014/10/28/category-theory-for-p...

Other people can debate category theory's utility: I have no expert insight of my own to lend.


Does anyone have any opinion on this book as an introduction to category theory compared to something like Category Theory by Steve Awodey (https://books.google.com/books/about/Category_Theory.html?id...) or Seven Sketches in Compositionality (http://math.mit.edu/~dspivak/teaching/sp18/)?

I'm interested in learning about category theory in general just to get a feel for the subject, but I also want to have a better concrete understanding of the category theory that is put to use in Haskell.



Also there was a course earlier this year that teaches an intro to Category Theory but doesn't assume a previous math background with the same author.

http://brendanfong.com/programmingcats.html


I think it would be awesome if OP open-sourced this. That way we could make suggestions via pull request.

This looks great. I'm looking forward to reading future revisions. I hope you'll post it here when a final draft is available. Keep up the good work. Cheers.

These kinds of things pop up a lot on HN, so I want to ask: are they helpful to people? I save basically every single one, planning to come back to them (I studied math and economics in college, and do a little programming now but not enough to call myself a developer), but can’t find time between work and everything else to dive in and actually advance my skills.

So maybe what I’m asking for is this: is there a “refresh your math, sharpen your sword” resource that exists that one could tune to what they do today?




Applications are open for YC Winter 2021

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: