# Programming and Making Use of Structure in Math

A tweet from James Tanton caught my eye last night:

Quickie: What is the sum of all products in a 10-by-10 multiplication table? What is sum of all products axbxc in 10-by-10-by-10 table?

— James Tanton (@jamestanton) October 13, 2013

Frequent readers likely know about my obsession with playing around the borders of computational thinking and mathematical reasoning. This question from James has some richness that I think brings out the strengths of considering both approaches quite nicely. For one of the few times I can remember since starting my teaching career, I went to a computational solution before analyzing it analytically.

A computational approach is pretty simple. In Python:

sum = 0

for i in range(1,11):

for j in range(1,11):

sum += i*j

print(sum)

…and in Javascript:

sum = 0

for(i=1;i

The basic idea is the same in both languages. We iterate over each number in the first row and column of the multiplication table and add them up. From a first look, one could call this a brute force way to a solution, and therefore not elegant from a mathematical standpoint.

Taking this approach does, however, reveal some of the underlying mathematical structure that is needed to resolve this using other techniques. The sequence below is exactly how I analyzed the problem once I had written the program to solve it:

- For a single row of the table, we are adding together the elements of that row. Instead of adding the individual elements together one by one, we could instead think about finding the sum of the elements of a single row, and then add together all of the rows. For example: \(1 + 2 + 3 + ... + 10 = 55\). This is a simple arithmetic series.
- Each row is the same as the row before it, aside from each element being multiplied by the first element in the row. Every row's
*sum*therefore is being multiplied by the numbers in the first column of the table. \(1(1+2+3...+10)+2(1+2+3...+10)+3(1+2+3+...+10)+...+10(1+2+3+...+10)\). - Taking this one step further, this is equivalent to the sum of that first row multiplying the sum of the first column: \((1 + 2 + 3 + ... + 10)(1 + 2 + 3 + ... + 10)\). In other words, the answer to our problem is really the square of the sum of that first row (or column), or 55*55.

I bring up this problem because I think it suggests a useful connection between a practical method of solving a problem, and what we often expect in the world of classroom mathematics. This is clearly a great application of concepts behind a traditional presentation of arithmetic series, and a teacher might give this as part of such a unit to see if students are able to see the structure of the arithmetic series formulas within it.

My question is what a teacher does if he or she presents this problem and the students *don't* make that connection. Is the next step a whole class discussion about how to proceed? Is it a leading question asking how arithmetic series applies here? This, by the way, zaps the whole point of the activity if the goal was to see if students see that underlying structure based on what they already know. Once this happens, it becomes yet another 'example' presented to the class.

I wonder what happens if a computer/spreadsheet solution is consistently recognized throughout the class as a viable tool to investigate problems like this. A computer solution is really nothing more than an abstraction of the process of adding the numbers together one by one. If a student did actually do this by hand, we'd groan and ask if they thought there was a better way, and the response inevitably is 'yes, but I don't know a better way'. In the way I found myself thinking about this problem last night, I started from the computational method, discovered the structure from those computations, and then found a path toward a more elegant solution using algebraic techniques.

In other words, I made use of the structure of my program to identify an analytical approach. Contrast this with a more traditional approach where we start with an abstract definition of an arithmetic series (by hand), do practice problems (by hand) and once we understand how it works, use computational shortcuts.

The consistent power that I see in approaching and developing ideas with students from a computational standpoint first is not that it often makes it easier to find an answer, though that can be a good thing when the goal __is__ to find an answer. Computational methods can make it easy to change things around and generalize a problem - what Polya termed generalization. It's easy to change the Javascript program to this and ask what multiplication table it models:

sum = 0

for(i=5;i

Computation makes the process of finding a more elegant way seems much more natural - in the best situations, it builds intellectual need for an easier way. It is arbitrary to say that a student should be able to do a problem without a calculator. Computational tools demand that we find a more compelling reason to solve problems by hand if computers are able to do them rapidly once they are set up to solve them through programming. It is a realistic motivation to show that an easier way speeds up finding a solution to a problem by a factor of 10. It means less waiting for a web page to load or an image to post.

The language of mathematics is difficult enough to throw in the additional complications of computer language syntax. I fully acknowledge that this is a hurdle. I also think, however, that this syntax is more closely related to the concepts that we are trying to teach our students (3*x is three times x) than we sometimes think. The power of computer programming to be a bridge between the hand calculations that our students do and the abstractions of the mathematical content we teach is too great to ignore.

I hope you don’t mind if I use this example in a presentation I’ve been tinkering with and doing for a while. I keep looking for specific examples from the field to try and explain how I see the intersection of programming and mathematical thinking.

Please do – I think getting these examples out there is important.