For centuries, people have fought over a simple question ! Do we really need Mathematics for Programming? Okay, maybe not centuries, but decades! (since computers didn’t exist centuries back). And let’s face it: Yes! But you don’t have to be Richard Feynman to Program! (though it certainly helps)
What do computers do?
Before we can answer that question, let’s think about what you do on a computer? Browse the internet, play cat videos, play porn, download from torrent, play CSGO and all of that is true. But what does a computer do at the most basic level? It just calculates! It does billions and billions of calculations every second! And all it can do is compute.
Right now, you’re reading some text on a web page! And all your computer (or phone) is doing is calculations. It is doing calculations! Each of the letters appear here due to calculations, the page looks like this because of calculations! Philosophically, that’s profound! But it also answers that, computers do calculations.
And it’s no wonder that, to teach a computer something, you need to tell that to compute something! Mathematics!
How advanced Maths do I need to know to program?
Fortunately, lot of the maths that you need to program basic things, you don’t need to go very far! In fact, your intuition and logic is often enough to do programming. That is, thanks to modern High level programming languages.
Back in the days, people couldn’t do much without mathematical knowledge, from punched cards to assembly, the road wasn’t easy! Even C, FORTRAN and COBOL wasn’t very intuitive I’d say (compared to opcodes and assembly, they’re a piece of cake).
1 2 3 4 5 6 7
pi = 3.141592653589793 # Define value of pi r = raw_input("Enter the radius of a circle"); # ask for radius r = float(r) # Convert the input into a number circ = 2*pi*r # calculate circumference area = pi*r*r # calculate area print "The circumference of the circle is", circ # output circumference print "The area of the circle is", area #output area
Now, this above program calculates the circumference of a circle, given it’s radius. It is pretty simple, and I’ve added some comments, you take an input using raw_input, convert into a float using the float function. From there, you calculate the circumference, area and output the result.
The mathematics was there in the formulas of the circumference and area. If you didn’t know the formulas, you’d be out of luck! But that’s in python. In a language like assembly, you had to do everything from IO to parsing to calculation and output. And I think finding the circumference and area would’ve been the easiest part. So, while it does take mathematics, it is becoming easier and easier, thanks to High Level Languages.
Which of the fields do I need to know to Program?
Depending on the program you’re writing, it varies. Programming is the easiest job, as well as the hardest. And learning a language is only part of the equation. Let us think deeply, Let’s look at a few different problems.
Building a game: Mathematics
Let’s suppose you’re building the next market leading game, like Angry Birds. How much of mathematics would you need? Well, building games are easily one of the hardest tasks mathematically, as it is a compilation of design, mathematics and tactics. You need a gameplay, which depends on underlying mathematics, and then on top of that, you need visually appealing graphics. See, how deceivingly hard it is to build games? So, things that would help mathematically to build 2D games are
- Cartesian co-ordinate geometry: We divide the screen in co-ordinates, so, to draw anything, we need coordinates, to specify the position, measure distances, we need co-ordinate geometry.
- Trigonometry: Trigonometry has to be here, how would you calculate rotation otherwise?
- Vectors: Vectors are pretty powerful, and without them, making a game? Good luck with that.
Apart from that, you’d definitely need to have a overall good understanding of programming, and there are some game specific things like game loop, heads up display, user interface and all of that! I built the demo Tic Tac Toe using Processing, which uses Java and it is around 150 lines of code. In case of the Tic Tac Toe, you wouldn’t need that much maths. Still I needed co-ordinate geometry! You can find the source code here.
Web Development: Mathematics
Fortunately, Web development doesn’t need a lot of mathematics, if you’re just connecting to a database, displaying some content. But if you’re building complex layouts, and making any sort of web app, Mathematics is necessary. You can do a lot without needing mathematics, but as soon as you need something complicated, you need mathematics.
Web development has a different set of challenges! Building an interface is no easy task. Frameworks, dependencies, and if you are trying to do something without them, you need, well, Mathematics! The challenges in Web Development are even greater, specially due to security, which is primarily based on mathematics!
So, the next time you try to build the next Facebook, or Microsoft, practice maths, it is easy and it is cool!
What if you’re trying to make the next Adobe Creative Suite or Creative Cloud? How much math do you think softwares need? Apart from the algorithm specific challenges (which I can’t even predict), the following are quite used
- Set theory: I think set theory has it all, it’s simple and it’s useful.
- Algebra: Due to variables, algebra is pretty significant for programming. Abstract Algebra can help, but basic algebra is kinda like a must know.
- Trigonometry: Not every app will need trigonometry, but most of them does. And knowing Trigonometry makes you able to solve many problems.
- Statistics: Most applications need some sort of data management. Without statistics, you’ll be figuring out algorithms that are weaker and take more time.
- Logarithms and Exponents: It’s unbelievable that logs and exponents are quite common here, but I have surprised myself many times by using logarithms here and there. And in fact, due to programming I’ve learnt Logarithms quite well.
- Vectors and Matrices: You wouldn’t trust me now, but once you learn how easy can certain things be made by using vectors, you would give it to me. Using matrices, we can rewrite many formulae and we can have speed ups by doing that! (due to most hardware accelerators does that)
So, be it a small application or a full-fledged software suite. Knowing the above is important! They are all easy, high school grade mathematical concepts, and can get you pretty far, if you don’t know them, keep programming, you’ll learn maths along the way. And yes, Maths makes things easy, not hard!
Data Processing/Machine Learning/Artificial Intelligence
If you haven’t heard about Big Data, Machine Learning or AI, then you have complete desolation with current affairs, but if you want to take part in any one of them, you got to beat your fear of, calculus.
See, Machine Learning, AI all these are essentially simple statistical calculations. Interpolation, Extrapolation, Integrals, Derivatives, Maxima, Minima, Regression and all that easy maths. They are comparatively easy to understand intuitively.
If you find a reason to not learn mathematics, let me give you a counter argument. If you learn it, money will follow you, not lead you! And it’s not just about money. You have a new perspective of the world.
How to conquer the fear of mathematics?
I know this is an entire topic rather than a sub-topic, and I will dedicate an article entirely on its own. But for now, let’s get the fear of mathematics out-of-the-way from Programming.
Yes, all that I’ve written above is absolutely true, but there’s something more. I think our elders have ruined mathematics for us. You see, the problem is, from a very tender age, our parents taught us to be afraid of mathematics. “Mathematics is hard, but you can do it”. Even before we have the feeling that mathematics is hard, they taught us to be afraid of mathematics. And fear is not good.
I remember nobody taught me to hate mathematics. My family explained how mathematics explains things. As a kid, I was curious just like you. And my family gave those answer mathematically. I see problems as a challenge, and not as a “trouble”.
I urge you to start programming. Python, Java, C, Kotlin, language doesn’t matter, allow yourself to face the difficulty, the reward is promising! Allow yourself to be challenged. Start the algorithmic thinking.
If you think I should start a series on programming, please leave a comment. And there is a bell icon in the bottom-right corner of your browser (on android, use Chrome/Firefox to see that). Click that to start receiving notifications!