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?
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.
You pose two questions.
- 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.
- 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