Settings

Theme

Math topics useful for computer science/programming

matheducators.stackexchange.com

84 points by jackhammer2022 12 years ago · 68 comments

Reader

j2kun 12 years ago

I never liked these kinds of lists. The people who ask the question always seem to be under- or overwhelmed by the answer (programmers don't need any math?! theoretical computer scientists need all math?!). And the people who answer are almost always skewed toward whatever it is they do.

Even the top-voted response to the OP is obviously biased toward the logic flavor of computer science, with awkwardly scattered recommendations for non-logicish topics that are far more useful for all flavors of computer science ("perhaps even eigenvalues," seriously?!).

These lists even ignore the deeper question being asked: how do you figure out what sort of mathematics you need for the things you're interested in? Not all computer scientists (and programmers) like the same things in computer science and programming. It's much more advisable to figure out what you like before you go around trying to learn all the math there is to learn related to CS, and then ask about what math topics are related to that.

  • nraynaud 12 years ago

    I agree, I have had to learn Newton's methode for differential equations (for simulation), I've had to use logic and an automatic prover (for system validation), I've had to do some complexity analysis (for everything), I've had to play with linear applications, matrices and all the stuff around 3D, I've had to dig into geographical projection equations for another job (in GIS). I'm currently toying with computational geometry. I think what is important is some kind of math to understand how those people write (which far from obvious), and then random stuff to learn to switch.

  • tptacek 12 years ago

    This comment is a little frustrating, because part of the point of linking to the Stack Overflow post is to continue the discussion, which is obviously germane to our site. Why not dig into specifics of how you'd approach the intersection of math and CS?

    • j2kun 12 years ago

      It's actually inspired me to write my own article, but that will take time.

      Meanwhile, I actually write a blog called "Math Intersect Programming." Even though it's more about my specific interests than how a freshman should approach the topics, and I certainly emphasize the mathematical ideas over the engineering challenges, it still gives a good idea of what I would suggest:

      Orient the learning around applications in CS. Find a problem that requires the mathematics you want to learn, and learn it with the persistent contextual understanding that you are trying to do something more than just tinker with definitions. Do this for one application and repeat as desired.

      My view is that when this is done, you learn to focus on the things that matter over the things that are used to fill empty space in courses (calculus courses come to mind as a specifically abhorrent example of this). You get better at seeing the forest over the trees.

      The problem is this avoids the OP's question (and this ensuing discussion about the OP's questions and the purported answers), since you can't organize a single class around it. Another problem is that very few books are written this way, or are only superficially so.

  • Betelgeuse90 12 years ago

    I largely agree with your sentiments.

    However, you should keep in mind that these lists are intended as an answer to "What Math should we teach freshmen undergrads?", not an answer to "What Math do all the CS-people need to know?". The latter is naturally a very small subset of Math, the 'logicish' type.

    I do STRONGLY agree with you that we should help students figure out the areas that they find interesting, and let them know what kind of Math is useful for each.

    • j2kun 12 years ago

      But the question is one and the same in this instance: they're asking what should be taught in "the" math class for a CS degree. If that doesn't contain the math that all CS-people need to know, then what should it contain?

      The OP describes universal algebra and term rewriting, which is what I claim is the logicish type that is not as crucial as, say, linear algebra if you want to find widely applicable mathematics for CS/programming.

      • Betelgeuse90 12 years ago

        It may not be crucial for programming, but I'd say it's more crucial than Linear Algebra for finishing the degree at all, since there are CS subjects that you just can't really take unless you learn the logicish stuff.

        I can't imagine not taking calculus either... How do you comfortably take the logarithm of an inequality without it?

        This whole idea seems so ridiculously impossible to me...

stiff 12 years ago

This does not seem very informed, starting from the false premise in the question up to the random concepts listed in the answers.

Calculus is actually important for Computer Science, it's actually important for everything, it's where you learn how to handle the exponential function and the natural logarithm, how to do approximations and bounds, how to handle infinite series, etc., and those things then appear all over the place, unlike most things listed it's something that you can expect to encounter almost regardless of what domain you are interested in.

I mean, the guy asks what should replace Calculus and then the first answer includes "Asymptotics", "basic limits, sequences and series", so actually calculus. In general I cringe a little every time I hear Computer Science people should focus on "discrete math", because without tools from analysis you can only solve the most trivial discrete problems. And yes, calculus by itself is hardly ever applicable in CS, yet you still have to learn it, tough luck. In general what is not stressed enough I think is that applying math is hard and you need to learn a lot of it before you have enough tools to tackle problems anywhere close to real-world complexity.

The top answer also lists random concepts. I am learning probability currently, for applications in machine learning. "Discrete spaces, Bayes theorem and expected values" you can learn in a day, "Markovs, Chebyshev and Chernoff inequalities" are mostly only useful for further theoretical work, so is "the law of large numbers". What will really be useful will depend a lot on the applications, if you are a theoretical computer scientist, mastery of generating functions and transforms will be useful, and it's one of those instances where discrete problems are solved via tools from calculus/analysis. For machine learning you need to know everything about the normal distribution by heart, and this means you have to know everything about the exponential function by heart, so again back to calculus. Notions from information theory are useful, but of course none of the ones he listed. The comment "This is a must for modern programmers." sounds just comic.

  • vukmir 12 years ago

    >Calculus is actually important for Computer Science, it's actually important for everything

    This.

    If you take a look at the MIT course "Mathematics for Computer Science"[1] you'll see that the only prerequisite for learning the math for cs is ... calculus!

    [1]http://ocw.mit.edu/courses/electrical-engineering-and-comput...

  • superuser2 12 years ago

    > Calculus is actually important for Computer Science, it's actually important for everything, it's where you learn how to handle the exponential function and the natural logarithm, how to do approximations and bounds, how to handle infinite series, etc., and those things then appear all over the place,

    It's still interesting to think about which branches of math are actually applicable to programming itself.

    People tend to talk about programming and math as very strongly related, and of course there is the obvious relationship that "some computer programs do particular kinds of math" like you're talking about here.

    But there is no (intuitive) overlap between writing, say, a web application and doing algebraic or calculus computation on paper. However, there are things like:

    - Set theory underpinning relational databases

    - Typed lambda calculus underpinning functional programming

    I'd be interested in other examples like this.

    • ThrustVectoring 12 years ago

      I have a couple simple ones off the top of my head:

      - You write a recursive program the same way you write an inductive proof

      - Abstract algebra and category theory are likely relevant, especially for metaprogramming. My math education hasn't included this, so I can't say much more.

      - Linear algebra is just ridiculously important

      - Statistics for machine learning. Also for figuring out how to combine data in a meaningful way. There are also a lot of people asking statistical questions directly, and writing programs is how you get those kinds of answers in a reasonable timeframe.

      • nmrm 12 years ago

        > Abstract algebra and category theory are likely relevant, especially for metaprogramming.

        In general, the whole "oh yeah CS people should know some category theory and abstract algebra" is pretty hilarious.

        First, it's a bit like saying "oh yeah CS people need to know the undegraduate basics and also the generalization that most mathematicians don't encounter until a couple years into grad school."

        Second, most people who say this really mean "a conceptual grasp on different types of morphisms is useful". But that's like saying you need calculus in order to drive a car; or, in the case of categories, it's like saying you need two semesters of real analysis in order to drive a car.

        Why not just say "knowing about different sorts of mappings is pretty useful in functional programming"? Knowing how this generalizes to more abstract mathematical objects is totally unnecessary.

        • shoki 12 years ago

          Well, frankly you can get along not knowing the "Gang of Four" design patterns and write Java. By the same token, you don't need to know about iterables and comprehensions to write Python, smart pointers to write C++, Graph theory to use a Graph database, macros to write LISP, etc.

          By analogy, you don't need to know abstract algebra and category theory to write Haskell. But as in the other cases, knowing helps.

          • nmrm 12 years ago

            I think you misunderstood my criticism.

            "Different sorts of mappings" is NOT synonymous with "category theory". Not even close. Heck, Euclid knew about "different sorts of mappings".

            Most everything in Gamma et al is arguably useful for everyday programming in Java. Maybe 5-10 pages of MacLane is useful for everyday programming in functional languages.

            Unless by "Category Theory" you mean "5-10 pages of MacLane", Category Theory -- on the whole -- is a horrendously inefficient way of teaching about "different sorts of mappings useful in functional programming."

            Unless you want to use functional programming as an environment for doing pure mathematics, there's no reason to actually study actual Category Theory.

            • shoki 12 years ago

              Functional Programming is a vast subject.

              I've really never needed an abstraction for semigroups, monoids, meet-semi-lattices, monads, comonads, arrows or catamorpisms in Clojure, Common Lisp, Scheme, or Hy.

              These concepts become more relevant when I program Haskell, Agda, Isabelle/HOL, or Coq.

              I'd say a stronger analogy can be made between reading MacLane's Catagories for the Working Mathematician and reading Hoyte's Let Over Lambda; you really only need to read a little bit of these books to get the core concepts. That being said, depending on what sort of functional programming you're doing, a strong background in category theory or meta-programming can enabling (or not).

              • nmrm 12 years ago

                > when I program Haskell, Agda, Isabelle/HOL, or Coq.

                That's fair. Although Haskell is a bit of an odd man out in that list, both in terms of its nature and in terms of its typical use case.

                > That being said, depending on what sort of functional programming you're doing, a strong background in category theory or meta-programming can enabling (or not).

                This is where the analogy between the two books breaks down. When you're using a functional programming language as a proof assistant, category theory can be helpful. But this is far less common than meta-programming.

                edit: 2nd paragraph.

        • j2kun 12 years ago

          More simply (but hard to appreciate without going through semesters of work): know that structure-preserving mappings are the important parts.

          • nmrm 12 years ago

            Yes. But my more important point is that you can tach about these mappings in isolation, in the context of functional programming. No Category Theory needed.

            You can teach about "different sorts of mappings" in just about any setting. In fact, that's kind of the whole reason Category Theory exists. So why teach the general result when all you care about is its application to functional programming?

            • j2kun 12 years ago

              The importance of structure preserving mappings shows up in many other places besides functional programming. I do believe context is important, but having multiple contexts is even better.

              • nmrm 12 years ago

                > but having multiple contexts is even better.

                Given the investment necessary to make this jump, I believe that the benefit outweighs the cost for most.

                • j2kun 12 years ago

                  You don't need to teach category theory proper to get the idea. So I think we are in agreement :)

      • tptacek 12 years ago

        As someone currently teaching themselves linear algebra (via Strang), I'm curious as to why you believe linear algebra is ridiculously important. I see its applications to graph programming and obviously to cryptography, but I've done a lot of work in both of those subjects and never strictly needed a background in linear algebra to be effective.

        • cabinpark 12 years ago

          Linear algebra is insanely important. I would consider the most important area of numerical mathematics to know. Any sort of mathematical modeling you do is going to involve linear algebra at some point.

          I have argued that almost all numerical mathematics, in some form, can be modeled as a linear algebra problem. Google's original page rank algorithm is linear algebra. Remember that Netflix challenge? All linear algebra. Optimisation? Linear algebra. Want to do any engineering of a system? Behind the scenes it is all linear algebra as every single numerical technique for solving PDEs, that I am aware of, can be thought of in a linear algebra sense. Fluid modeling is all linear algebra. A lot of the machine learning I've seen is just linear algebra. I would also that almost every simulation running on the world's supercomputers involves linear algebra.

          Do you absolutely need linear algebra to do this things? No. Just like I don't need to understand how my car works to drive it. But having an understanding how these systems operate can really help you use them in a more logical way.

        • platz 12 years ago

          `ridiculously` might be hyperbole, but the two biggest ones I can think of are computer graphics and machine learning; these of which you can't even sneeze at without getting in linear algebra.

          • tptacek 12 years ago

            I have some sense of the linear algebra implicated in machine learning (I lived for many years with a comp. neuroscience PhD), but I have no visibility into graphics. So with my ignorance pinned to my lapel: the linear algebra involved in computer graphics is pretty simple, right? Just knowing how to manipulate vectors and matrices? Not a lot of eigenvalues, or for that matter orthogonalization?

            I'm asking not to rebut but because I hope to prompt the sort of "sell us on linear algebra" statement that will make me study harder. :)

            • jfarmer 12 years ago

              Much of computer graphics operates in projective space (http://en.wikipedia.org/wiki/Projective_space), so it's a little bit more than cookie-cutter linear algebra. This is done so that translations in 3D space — which aren't linear transformations — can be represented as 4D linear transformations in projective space via homogeneous coordinates (http://en.wikipedia.org/wiki/Homogeneous_coordinates).

              Still, many folks use the APIs without really grokking that, so in practice it can be a bit cookie-cutter. I think of it similarly to how people can use crypto APIs without, say, really understanding what's going on under the hood.

              BTW, projective space is also intimately related to elliptic curves (as you may or may not know — not implying anything!). So that darn linear algebra is lurking all over the place.

              Likewise, any time you're talking about fields (even finite fields), vector spaces and linear algebra are right around the corner.

              • tptacek 12 years ago

                I'm familiar with projective coordinates for elliptic curves, but the funny thing about curves is that, for high-speed software, the math is tricky enough that you don't "need" to grok it: there's an "explicit formulas database" that you can just copy from:

                http://www.hyperelliptic.org/EFD/g1p/index.html

                Curves are what made algebra 'click' for me, getting me from my high school understanding of "algebra is math about unknown variables" to "algebra is about sets of related objects with operators that have identities and inverses".

            • platz 12 years ago

              Disclaimer: I'm not very experienced with CG, but I think your intuition is correct on CG, for lots of 'boilerplate' game or photoshop programming.

              However, I do think you can find plenty of examples in academia. For example, applying PCA

              http://cmp.felk.cvut.cz/~hlavac/TeachPresEn/11ImageProc/15PC...

              (Perhaps this is just the result of crossover between CG and ML/Statistics here).

              Not a good sell, but perhaps someone with more experience can chime in.

    • stplsd 12 years ago

      - number theory underpinning almost all modern cryptography

      - NFA/DFA underpinning regular expressions ( well practical regular exp are not in fact regular, but anyway)

      • tptacek 12 years ago

        Actually, although number theory touches a lot of "conventional" crypto (some of the design rationale for AES, polynomial MACs), most of workhorse cryptography in normal applications is not especially number-theoretic, and has more to do with information theory and statistics.

        The belief that number theory is essential for cryptography is due to its role in public-key cryptography. But even if you're comfortable with number theory, new applications of public-key cryptography are tremendously difficult to get right, and require subject-matter specific expertise.

    • joedavison 12 years ago

      Another example:

      - Linear algebra used in graphics and game programming

    • Dewie 12 years ago

      Well there is the Curry-Howard correspondence. Though I don't know if this correspondence is intuitive in the general case - I guess what this correspondence means is that programs can be translated to some computational model, which can then be translated to some formal logic, and then back again (but with these kinds of high-level facts, I'm bound to have misunderstood something, somewhere). Though this connection might be only intuitive for some kinds of languages - like statically typed functional languages.

      I think it's amazing that programming can leverage and express so many mathematical facts - from implementing a binary tree that is enforced to always be balanced by the type system in Haskell, to using linear types to safely use and free OS resources in ATS.

  • nextos 12 years ago

    I certainly agree. I'm trying to re-learn advanced calculus and analysis from a rigorous standpoint, as I think it is crucial for developing deep knowledge in probability theory, among other things.

    Slightly tangential but, while there are many lovely books for linear algebra (like Halmos, Axler or Hoffman & Kunze), as a newcomer I don't find analysis literature so exciting. The standard, Rudin, is really synthetic Bourbaki-style. I like short and precise books, but I found it really removes most intuition. Any good books you happen to like? Perhaps Pugh or Zorich?

    • stiff 12 years ago

      Among the many texts almost the only one I really liked and learnt from is Courant's "Differential and Integral calculus" and the newer edition "Introduction to Calculus and Analysis". It doesn't do the typical modern division of topics and instead treats single-variable calculus, multi-variable calculus and real analysis in its two volumes in a single long sequence, but the writing style is very pleasant and the exposition very intuitive, and it includes a lot of physics applications. Hardy "A course of pure mathematics" is great too, but it is much more, well, pure, but it stays relatively intuitive and the clarity with which he writes is unparalleled, many things I first really understood from this book. Those are old texts though and notation and details of exposition differ here and there from modern standards.

      I have the book by Pugh, but that one is pure^2, even as far as analysis texts go, the problems are difficult and there are no solutions, so I think it would work only for people very in love with absolutely pure mathematics and most likely only in an academic setting, while I am interested in applications and self-studying. From modern texts, given your interests, I would look at "Understanding analysis" by Abbott and "Measure, Integral and Probability" by Capinski, both pleasant to read and together providing a not too steep path toward measure-theoretic probability.

      • nextos 12 years ago

        Thanks for taking the time to write such a thorough reply. I find Abbott a bit imprecise sometimes, but Courant is a fantastic book. Could you also mention to some of your favorite math references, in particular those that deal with probability theory and statistics?

    • ekm2 12 years ago

      I found it easier to handle Analysis by following the sequence:Spivak ->Apostol->Rudin.

    • wyclif 12 years ago

      Interested in a range of book recommendations for Calculus on up.

  • anaphor 12 years ago

    Also I'm not sure how you can mention information theory in the context of programming and not mention PCM or the Shannon-Nyquist sampling theorem...

RogerL 12 years ago

I went to an engineering University. Besides having a wide variety of math required (3 semesters of Calc, 1 semester of either stats or probability, 1 semester of either linear algebra or matrices), we also had to take 3 semesters of physics, and 2 of chemistry. Most of us (those not just looking for a piece of paper) went considerable deeper in at least one area.

No, you don't need to understand organic chemistry to write a CRUD app. But, you don't need university to write a CRUD app.

I think I received an excellent education that prepared me for about any job out there. And, I've done it. I've done cancer statistics for the NIH. I've worked in avionics and simulation. Well, blah blah, no one cares about my resume, I'll just say I couldn't have done any of it without the education I received. I haven't done financial quant stuff, as an example, but how could I without the math background? Or how could I program a controller in a factory without understanding PID (done that)? How can I get a piece of that neat drone project (done that)? Hey, that computer vision stuff looks interesting, all I need to know is ...derivatives, statistics (done that too).

For most of us, university is the last and/or best chance to really understand how the world works. For that you need quite a bit of math and science. Another example. We have a voluntary Arduino robotics workshop going on at work, coupled with 3D printing. Naturally, people are excited, and have all kinds of ideas. But, how do you execute on that if you don't understand how to design an op amp circuit, or filter data with something more sophisticated than a moving average? Robotics spans a number of fields, and to actually produce something more than a gimmick requires a lot of knowledge. Knowledge that you can pretty easily pick up in University, but knowledge you mostly just long for as you have to rush home at 5:30 to pick up the kids and make dinner.

I guess this is a cranky rant from an old guy. But I hear about University programs that are nothing more than Java voc ed systems and I despair. $100K in debt to learn something most anyone on here could just pick up on their own. You don't need university for that stuff.

  • klibertp 12 years ago

    > but how could I without the math background?

    You could have just learned it as you went. Done that.

archena 12 years ago

I'd include combinatorics under 'useful' too - although the basics are usually covered in statistics courses. Odd that the list mentions differential equations but not basic calculus, which I'd think is more fundamental.

It's also interesting to consider the chapter headings in Concrete Mathematics (Graham, Knuth, Patashnik), a text designed with students of CS and programming in mind:

    Recurrent Problems
    Summation
    Integer Functions
    Number Theory
    Binomial Coefficients
    Special Numbers
    Generating Functions
    Discrete Probability
    Asymptotics
  • bainsfather 12 years ago

    I got Concrete Mathematics a few days ago, after someone recommended it. My background is physics, and I find the "mathematicians' style" to be very awkward to learn from. This book is excellent for me - concrete examples - it is always trying to solve specific problems, so if I don't follow the theory, I can always refer to a concrete example and try to understand that specific case. This the way I learn best/fastest.

jostylr 12 years ago

Why not teach math + programming together? I didn't seem to see anyone suggest that.

Calculus: simplify and iterate to solve a problem (like Newton's Method). Lots of issues to tackle with. Much more useful than learning formulas, but it can also be interesting to show how converting forms can take an unstable problem into a stable one.

Combinatorics: Explore the small side of a problem, code up the larger version, explore how far one can get, show methods for dealing with the problem beyond the scope.

Graphics, user interface design, etc., are also very big in math. In a course I teach to Enviro Science people, they come in scar(r)ed of math and by the end, they enjoy it. A big trick is getting them to use GeoGebra in an exploratory, visual fashion. It makes the math real.

The same approach in code can help make CS students get math while also getting the issues in CS. Anyone who thinks the exponential as 1+ x+ x^2/2 + .... is useful as is for x = 100 needs some actual experience with it. But at the same time, teaching them how to translate e^100 ~~ e^(43ln(10) + .98) ~~ 10^43 (1 + .98 + .98^2/2 + .98^3/6) = 10^43 * 2.62 has its value (compare to e^100 ~~ 2.69 * 10^43)

This is the kind of math that is useful. Exploratory math that struggles with mathematical truths and practical implementations. Students should get a sense of the limits of computers, what they can handle and not.

And designing a good math interface for these problems can be quite the UI learning experience. There are so many ways to explore math.

Stop teaching dry math and start teaching programming math.

weavie 12 years ago

Although I did mathematics to degree level, I have used so little of it in my professional career that I have largely forgotten it all now. Any such list is going to depend on what area of programming you want to get into.

For a lot of programming understanding user interaction and human psychology is much more important than mathematics.

ap22213 12 years ago

"Many students struggle with the idea of recursion..."

I still remember one of the worst bugs I'd ever introduced (in terms of pain to me). I was maybe 2-3 years out of my bachelors, and I thought recursion was so nifty that I'd use it where ever I could. I was coding C++, at the time. And, I got the dreaded 2am call after all of the production servers went down hard. Like terminate and corrupt data hard.

Lesson learned: it's good to know recursion, but it's also good to know maximum stack sizes.

brirush 12 years ago

I wrote the original question. I've always been interested in how much math various careers use, but I wrote this question the way I did in a shameless attempt to drive traffic to the site by appealing to the Stackoverflow and reddit communities. Everyone has given me a different answer so far, but that's to be expected, because there are ~1000 subcategories of computer programmers.

  • nmrm 12 years ago

    > I've always been interested in how much math various careers use

    > ... there are ~1000 subcategories of computer programmers.

    I'm curious: what about other careers? Are there fewer categories? Do they all do the same type of math? etc.

userbinator 12 years ago

In my experience, I've seen a lot of students entering CS not comfortable with even basic arithmetic and algebra, despite it not being mentioned in any of the linked responses.

As for calculus, I think its importance is overrated - unless you are specifically doing some numerical computation that requires it.

  • Bahamut 12 years ago

    Calculus gives you some of the intuition for figuring out a good big O bound for the computing time of an algorithm.

jules 12 years ago

Which area of math isn't useful for computer science/programming? Certainly some areas are more useful than others, but I think rather than looking at areas it matters more how in depth you go in one area. Going super deep into an area is often not a lot more useful than just knowing the basics. Complexity theory is useful, but it's not that practically useful to know deeply about all the complexity classes.

alok-g 12 years ago

What would be a good writeup for understanding term-rewriting? (My current background level: I understand most of what OP has listed in "actually useful" and "can run into", and "automata theory" from the third list.)

  • j2kun 12 years ago

    I wouldn't recommend it as being as important as the OP claims, but if you must: http://www21.in.tum.de/~nipkow/TRaAT/

    • alok-g 12 years ago

      Thanks!

      Could you also recommend something on how symbolic computation works? I have used computer algebra systems like Mathematica for long; would like to understand how it works internally.

      I currently understand some basics like DPLL, semantic first-order unification, methods of solving specific equation systems like linear systems, numerical differential equations, etc. I am missing at least how the "top-level" of symbolic computation works.

      For example, from what I currently understand, first-order semantic unification can find "x = Cos[y]" from "Sin[x] = Sin[Cos[y]]", but cannot solve "Sin[x] = Cos[x]" for x, and cannot simplify "[(Sin[x])^2 + (Cos[x])^2] = 1" to True.

      I am hoping to find something simpler than reading through SymPy source code. :-)

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection