# What is the role of mathematics in programming?

I am almost totally uneducated in programming and computer science in general, though I am really fascinated by these topics. I read that mathematics is important in programming and that nowadays many mathematicians specialise in applied mathematics in this field. So, I wonder how these two branches are linked with each other. What are the fields of mathematics that are useful (maybe unavoidable?) in writing a computer program?

• This feels rather broad to me, though svick's answer does a good job of explaining how "it depends". One thing to which I would draw attention is that programming and computer science are somewhat separate. A lot of computer science is mathematics, whereas programming is a tool that computer scientists sometimes use (and, conversely, mathematics is a tool that programmers sometimes use). – David Richerby Feb 15 '16 at 23:31
• The relationship of mathematics to programming is the same as the relationship of chemistry to chemical engineering, or physics to mechanical engineering, or, for that matter, art to industrial design. The job of the engineer is to build useful (safe, on time, on budget, etc) systems out of the raw tools of science. For software engineers, that science is computer science and, as David rightly said, that can be thought of as a branch of (or allied art of) mathematics. – Pseudonym Feb 15 '16 at 23:42
• The role of mathematics in programming is, in general, nil. On a day-in, day-out basis someone developing software does not use "mathematics" (which I'll define as anything more complex than basic algebra) at all. Now and then you'll need to use something more "math-ey" - but it seldom rises beyond trigonometry. In my career as a software developer I've used calculus TWICE - and in at least one of the cases I could have used trig, but it was easier to use calculus when I recognized that I needed the integral (area under the curve) of a known function. – Bob Jarvis - Reinstate Monica Feb 16 '16 at 2:59
• @Pseudonym "The relationship of mathematics to programming is the same as the relationship of chemistry to chemical engineering, or physics to mechanical engineering" -- I disagree. Mathematics is to CS the way mathematics is to physics. CS is to software engineering the way physics is to mechanical/electrical/... engineering. – Raphael Feb 16 '16 at 10:51
• @BobJarvis If you've ever written a recursive function and convinced yourself through thinking (as opposed to testing) that it always terminats, you've probably engaged in (informal) mathematics. If you've ever optimized SQL queries, you've probably used rules of relational algebra without realizing you did so. (And that's ignoring that compilers are magnificent works of mathematics, CS and engineering.) – Raphael Feb 16 '16 at 10:52

You don't need any math to write a Hello World or a very simple website.

You will need to know some discrete mathematics and algorithm analysis to write a program that finds a route between two cities.

You will need to know matrix transformations and quaternions to write a game engine.

You will need to know a lot about all kinds of mathematical fields to write the next Wolfram Mathematica.

What I'm trying to say, what fields of mathematics you will need to know and to what degree will depend a lot on what kind of programs do you want to write. But the ones that tend to be most widely useful are data structures, algorithms and their analysis.

• This is a good answer. I'd say that probability theory is probably the biggest mathematical subject you've missed, as some understanding of it is essential if you're going to write any kind of randomized algorithm. Those are important because many problems are hard to solve exactly so you have to use some sort of (typically randomized) approximation. – David Richerby Feb 15 '16 at 23:33
• Another big one - encryption relies on mathematical operations of very large primary numbers – HorusKol Feb 16 '16 at 4:32
• Don't forget machine learning often involves probability or regression etc... – user541686 Feb 16 '16 at 5:26
• Thank you and thank you all for the answers. I am just approaching to the world of programming which fascinate me quite a lot though. I am going to post another question, more specific, with an example of I program I would like to try to write as an exercise. – user98139 Feb 21 '16 at 18:21

You pose two questions.

1. Which is the role of mathematics in programming?

Quite fundamental. It is the universe of computers and programs. I mean no exaggeration. It describes the framework in which they exists. It provides the tools to analyze computer programs, e.g. it is used to prove the correctness of computer programs, completeness, all sorts of other properties. It is important to know that a program will work as expected, or will finish. Even a simple "hello world". You can really break it down and prove it, to the logical level. There are formal definitions of what a program is, and what a computer is.

1. Which are the fields of mathematics that are useful (maybe unavoidable?) in writing a computer program?

Unavoidable? None. Just as you don't need physics and engineering to build simple stuff.

Useful? Depends, and opinionated. The beauty of it is, to abstract and reuse tools. Some people create algorithms, some people use them to write libraries, some people use them to write services or games. Math is useful on a pretty low level, unless it is directly related to the task that a program is solving.

I would say, that fields that give a nice set of general soft skills useful for programming are logic, combinatorics and algebra, because they develop the ability to complex abstract thinking, organize things and transforming problems. I'd say skills that are very useful in seeing a "bigger picture". It's always nice to spot common functionality, reduce complex problems/tasks and avoid caveats as a programmer.

One can write a computer program without mathematics. However, when you start wanting to demonstrate that you wrote the right program, you typically have to turn to mathematics to prove it. For example, many parts of a program are terribly hard to prove out without using mathematical induction. Now that's not to say you're using complex mathematics. Not many programmers have to use differential equations on a daily basis, but you do need to understand the basics, such as how to make a proof.

The specialists in the field push the limits of what computing could theoretically do. For example, cryptographers make some rather demanding statements about what their algorithms can do. Many claims in that field could require eons of computing power to prove by doing it, but can be proven using a few pages of mathematics. However, that is a case by case thing. Most developers never dabble in cryptography (in fact, cryptographers bristle when you suggest it, because it's so unbelievably easy to write bad crypto if you don't have the background).

As svick mentioned, it depends on what you do. I can add some insights from my experience. If you are interested in just using machine learning (ML), then some math is recommended to understand what's going on. If you want to develop ML, then your math must be much more advanced, you need: advanced calculus, probability theory and linear algebra. But all this math can be learned online

Good luck

• I think this is more of a comment than an answer. Community votes, please! – Raphael Feb 16 '16 at 10:55