Hacker News new | ask | show | jobs
by jerf 2988 days ago
Programmers use tons of math, they just don't recognize it. Partially because you can still come out of even a bachelor's program in computer science and still think "math is just about numbers", but some of it is also just excessive familiarity and not realizing the easy things that you're doing that are actually mathematical because school trained you that Math must be Hard and you have to be Sitting There and Thinking Very Hard or you're not Doing Math.

Every day I'm using mathematical reasoning such as "I reached this line of code, and since this is a structured program I am guaranteed that this variable was initialized by the time I got here", "this function can only return either a non-empty string XOR an error and has nowhere it can throw an exception so if I handle those two cases I have fully handled everything this function can do", "the error string has the username in it, and values like that must come from somewhere, so even though I've been looking for an hour and can't find it, mathematically the thing generating the error message must have access to the username", "if I construct this as a pure function that does no IO, on the flip side, no users of this function will have to worry about what errors could arise during IO, reducing the mathematical cognitive load of using this function for users".

Then you start stringing together those steps by the dozens and hundreds and thousands and millions (and you get qualitative differences there too, but those don't fit into a little post like this anywhere near as well), and you can build software.

You don't have to realize you're reasoning mathematically (proof: look around), but you're leaving useful tools in the toolchest if you don't. Even if you won't believe me about building systems this way, I can assure you those magical stories about people who can debug systems at a glance that have defeated others for hours or days comes back to someone who either formally or by experience has a fairly mathematical understanding of the system in question and was able to apply some sort of logic, even if only intuitively, to arrive at that conclusion.

3 comments

But that's mostly logic, at best mathematical logic. I don't think anyone formally reasons when writing code anyway, we mostly rely on intuition. Maths isn't about numbers but it's not about intuition neither.

Programmers doing actual math would be modeling problems and creating proofs for their solutions. Usually we clasify those problems based on the field of math we use to model them.

Saying we do tons of math implies we use a lot of knowledge from a lot of those fields. But most of the time, programmers use only the introductory notions of those fields. We are usually guided by a domain expert anyway so that the math part is correct.

Programmers don't use a ton of math. They use some math.

I think most modern mathematicians would be taken aback if you told them logic is not math. You might be surprised what some logicians have gotten up to.

And sure, if you define what I talked about as not math, then you don't use math. If you don't want to use the tools of mathematical thought, be my guest. It's one of my competitive advantages in the marketplace.

But I think Dijkstra would be pretty surprised to hear that structured programming wasn't math, and you might be interested in budgeting six months or so to play with Coq or something like it, where you'll learn that the difference between proving code and what you do in just trying to make code work and debug code is much more a quantitative difference than the qualitative difference you think. There's no magic in how code proofs work... it's the same processes you use all the time if you code at any scale beyond a single screen of code, just taken to their logical conclusion.

Propositional logic / zeroth-order logic is like arithmetic. You didn't consider numbers (by which I gathered you meant arithmetic) as math, and I'm the same in saying this type of logic is not math.

Logic is a VAST field, and most programmers don't get to use most of it, that was my point.

I already played with Coq (that feels weird to say :)) ). It is a very specialized tool useful in very specific cases. I don't think it will ever be adopted as the standard way of programming since it's really unproductive.

Just because you use math that is really heavy does not mean you understand the math behind completely. We can view a ball throw as a complex quantum-mechanical physical process but we don't call ourselves theoretical physicists for being able to throw a ball.

Some of your points remind me of Underwood Dudley's 2010 article "What is Mathematics For?" [1]. Briefly, he argues that we greatly exaggerate how much math you actually need in most jobs that people usually think of as needing math, but nevertheless learning math is worthwhile and important because of what it teaches you about how to think.

[1] http://www.ams.org/notices/201005/rtx100500608p.pdf

I agree. It's (usually intuitively learned) reasoning that's very similar to the logical reasoning of mathematics. I think if you were to study, say, calculus in a manner typical of a first course in college, you'd be missing out on that sort of problem solving, but you'd definitely get that if you took a proofs-based class in analysis ("This function is continuous on this interval, so it must have a maximum. How can I use that to prove what's being asked?").