Does Math Help Programming Or Programming Help Math?

Written by Mike James

Tuesday, 07 June 2016

There is currently a small debate going on about the relationship between programming and math. Not "do you need math" to be a programmer but "does teaching programming help math or vice versa"?

The relationship between programming and math is something that both sides of the fence discuss from time to time, but mostly it is the programmers who think about it. The reason I suppose is that many programmers don't consider themselves good at math and therefore the assertion that math is essential to programming is threatening. If it is true how can you be a good programmer and not be good at math?

First we need to clear up a small point, one that I often find myself having to reiterate - even to mathematicians.

What most people refer to as math isn't - it is arithmetic.

Want to know the difference?

A calculator does arithmetic, but it can't do math.

OK my age old example might be about to lose some of its obvious truth because advances in AI might well allow a computer do do math in the very near future. But for the moment let us just accept that being able to do arithmetic, to add up and multiply in ones head, might be a useful skill but it isn't math.

Difficult math:

isn't the same as:

difficult sums.

What is more an ability to do mental, or paper and pen arithmetic, doesn't mark one out to be a mathematician and not being able to do it doesn't rule out mathematical ability - or it shouldn't. In practice even mathematicians, and math teachers, who should know better often say "you can't do math so you can't be a mathematician" when what they really mean is "you can't do mental arithmetic so you can't be a mathematician". Put correctly it clearly becomes clear how silly the position is.

A common difficulty is that mathematicians often don't notice what they are saying and what damaging ideas they are espousing. The reason is that most mathematicians are selected by teachers who honestly believe that if you are good at arithmetic you should become a mathematician. It is almost as if students were selected for art school because they could spell and had nice clear handwriting - remember handwriting? Having been through the mill most mathematicians cannot conceive that a student who cannot do mental arithmetic could be a mathematician - it's the very stuff of math. Well no it isn't. Knowing how to do arithmetic and hence algebra is the very stuff of math, being able to actually do arithmetic is the very stuff of a pocket calculator.

credit: frankies

An almost bigger problem is that the general public may well be exposed to arithmetic but they encounter almost zero real mathematics. If they have been lucky enough to encounter something that is real math then the chances are they fail to see any connection with the real world and how it might help them.

Using calculus to find the maximum of a function is all well and good but how many people have a function they desperately want to maximize?

Now enters programming.

Years ago I was lucky, or unlucky, enough to teach the introductory course on general topics in computing to the new intake of Computer Science students - yes I drew the short straw. This was supposed to be a diet of computers in society, art and history but this was the up-swing of the home computer revolution and all they wanted to talk about was how to program different things, mostly relating to games.

So whenever I finished my attempt at being a humanities teacher and asked for questions there would usually be none on whatever topic it was I'd just poured my life blood into, but plenty on how to program some topic or another.

One lecture the question was a simple one - how do you draw a circle?

I launched into sin and cos and how x and y was worked out for any angle. After the basic parametric equation of a circle I went into details about how to avoid calculating sin and cos and how to speed things up. All good stuff and very enjoyable with lots of supplementary questions but one comment has stayed in my mind ever since:

"so that's what sin and cos are for?!"

Someone at the back of the lecture hall had suddenly got the point of trigonometry! I quickly regrouped and started to outline a few other uses for trig in programming - mainly projectiles, well mainly the path a banana thrown by an over-sized gorilla would take. The lecture overran and there were a few puzzled questions about why the board was full of trig formulae from the next lecturer.

So is math good for programming?

Of course it is, but math can often lack a motivation and this means that many programmers get to start to program without really seeing the need to learn the math at all.

So is programming good for math?

Of course it is, but programming often provides the motivation for mathematical tools and you have to be prepared to teach the math.

if programming were taught in schools then the enthusiastic students would beat a door to the math class to find out how to do what they were trying to do.

All of these musings were triggered by the essay How Programming Supports Math Class, Not the Other Way Around by Chris Bartlo, a computer science and math teacher. And this is how it should be - math and computer science should be taught by the same person because there is a synergy between them.

Synergy might be an overused term, but in this case it is more than true. Programming not only provides motivation for math, it also provides the mental skills needed to think mathematically. A program is an algorithm and so are mathematical equations and procedures.

How can you not understand the equation for the solution to a quadratic when you know that it is just the specification for a program in a language called math.

To get a program to work you have to have an attention to detail - one semi-colon out of place and nothing works. This is the same in mathematics, where writing down a slightly wrong equation or function will result in the wrong answer or no answer at all.

We need to teach programming in school not because we need more programmers. We need to teach it because it provides the mental skills necessary to design and implement algorithms, and this is what clear thinking is all about.

If only all our politicians and law makers had been taught to program the world would be a very different place as the result of effective policies and laws.

This year's 10th anniversary Pwn2Own spanned over thee days rather than the previous two and was won by the team from 360 Security who achieved a full virtual machine escape through Microsoft Edge.

The list of mentoring organizations for this year's Google Summer of Code has been posted and there's a record number of them. The list includes large and well known projects together with smaller and [ ... ]