Maths via Programming

A few weeks ago, Kristian Still invited me to write an article about my maths and programming blog on his website. I’m reproducing it here, slightly copy-edited.

My memory of being taught maths at school is of learning a technique and repeatedly applying it to lots of tiny, pure problems. Pure maths is an apt term: devoid of application and untainted by a relation to anything outside the bounds of the textbook. Other students would offer the classic complaint: “Sir, what’s this useful for? Why are we learning this?” I think their protests were dismissed, but they were right. Without an apparent practical application, students find material less motivating and harder to understand.

I don’t think I ever asked what maths was useful for. This was firstly because I loved it, but secondly because I was applying it. The classic nerdy bedroom programmer, I spent much of my teen years playing and creating games. I needed my spaceship to move at angle: that needs sine and cosine. My two asteroids were colliding: model them as circles and use Pythagoras to compare the distance to the sum of the two radiuses. Newtonian mechanics as the backdrop of my asteroids clone. Manipulating number representations to speed up the line-drawing algorithm for the ray-gun.

Now, my day job is developing a programming environment specifically aimed at teenage beginners to programming: Greenfoot. And still the same problems seem to occur in maths: What’s it useful for? So I began to try and write down all the uses I know for maths (well, geometry and mechanics at least) within the creation of computer games. It’s in a blog called the sinepost: sinepost.wordpress.com. You can use this list of posts to start at the beginning: sinepost.wordpress.com/sorted-posts/.

The Sinepost Blog

The idea behind the sinepost blog is to provide engaging examples of maths being applied. I think the idea is especially strong when the problem is real (at least in some domain) and maths is a necessary part of the solution: There is no way to move a spaceship in a game at an angle without using trigonometry. To see if a bullet has hit an asteroid (modelled as a circle), you must use Pythagoras. The basics of geometry are used over and over again in games.

While the blog focuses on explaining the use of the techniques, I believe there is scope to construct examples for the students to tackle. Examples where maths is no longer used in a microcosm, on a small artificial problem. Instead, students can tackle larger problems which involve several steps, and solving problems where the path has not been mapped out for them. Move this mouse five pixels towards that cheese (one answer: arctangent, then sine and cosine). Now make the mouse circle the cheese (answer: add ninety degrees after arctangent). Then change the mouse so that it can only notice the cheese from a certain distance (answer: Pythagoras). Now make it only notice the cheese when it has direct line of sight (answer: intersection of line and circle).

Ofsted on Maths

It turns out that Ofsted, the UK schools inspection agency, would quite like to see more problem-solving in maths too. Quoting their recent report into maths (original is available in PDF form; I made my own summary):

“In the very best schools, all lessons had a clear focus on thinking and understanding… Whole-class teaching was dynamic with pupils collaborating extensively with each other. It challenged them to think for themselves, for instance by suggesting how to tackle a new problem or comparing alternative approaches.

“A common feature of the satisfactory teaching observed was the use of examples followed by practice with many similar questions. This allowed consolidation of a skill or technique but did not develop problem-solving skills or understanding of concepts.”

(As schools well know, “satisfactory” is fast becoming Ofsted-speak for “bad”.)

“Inspectors continue to be concerned about the lack of emphasis on ‘using and applying mathematics’… In the very best schools, ‘using and applying mathematics’ was integrated into day-to-day teaching. For example, new topics were introduced by presenting a suitable problem and inviting pupils to use their existing knowledge in innovative ways. More generally, the lack of emphasis on using and applying mathematics remained a weakness that is persistent.”

Pros and Cons

There are examples of applying maths outside of programming and games, of course. But games are fun, and programming has an added benefit: students can test their answers. In microscopic problems, students could check their answers at the back of the book. But otherwise they are reliant on the same model as all the essay-writing humanities subjects: have a go, then wait for the teacher to take a look. Computers provide a new way: try it and see what happens! Program your mouse to head for the cheese, then execute the program. You can soon see if it works or not. Students can be freed of undue reliance on the teacher for verification, using the computer as their guide.

For those students who are strong in maths and programming, the ceiling is very high. Students can program more advanced collision detection, using polygons instead of circles, more complex collision resolution, rigid body physics, or move beyond 2D graphics to 3D, using things like intersection of line and a plane for tracing bullets, or matrix transformations to reposition the camera. Thus the applications can scale from basic trigonometry, up to the full range of 3D mathematics used in professional game development. A recent post rendered a simple 3D scene into 2D using (lots of) GCSE-level maths, and programming:

Maths via programming is not a silver bullet. Not all parts of maths will lend themselves to application in programming. And I am a little hesitant over some of the pragmatics. The techniques are universal: if Greenfoot is too advanced, Scratch can be used to showcase most of the techniques. But either way, understanding the application of maths in programming requires some knowledge of programming (in both the students, and the teacher!). I always recommend that programming not use mathematical examples, for fear of putting off or hindering the students who don’t like maths. By the same token, might my approach to maths alienate students who don’t like programming?

And finally: are games a gendered gambit? I always try to find examples that don’t involve shooting or killing, but will my tamer examples of a racing game or implementing balls on a pool table still put off a lot of girls? I lack the classroom experience to tell. But I still think there’s potential in using programming to support the teaching of maths.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s