# Programming and Making Use of Structure in Math

A tweet from James Tanton caught my eye last night:

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<=10;i++) { for(j = 1;j<=10;j++) { sum+=i*j } } console.log(sum) 

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<=10;i++) { for(j = 5;j<=10;j++) { sum+=i*j } } console.log(sum) 

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.

# A computational approach to modeling projectile motion, continued.

Here is the activity I am looking at for tomorrow in Physics. The focus is on applying the ideas of projectile motion (constant velocity model in x, constant acceleration model in y) to a numerical model, and using that model to answer a question. In my last post, I detailed how I showed my students how to use a Geogebra model to solve projectile motion.

Let me know what I'm missing, or if something offends you.

A student is at one end of a basketball court. He wants to throw a basketball into the hoop at the opposite end.

• What information do you need to model this situation using the Geogebra model? Write down [______] = on your paper for any values you need to know to solve it using the model, and Mr. Weinberg will give you any information he has.
• Find a possible model in Geogebra that works for solving this problem.
• At what minimum speed he could throw the ball in order to get the ball into the hoop?

We are going to start the process today of constructing our model for projectile motion in the absence of air resistance. We discussed the following in the last class:

• Velocity is constant in the horizontal direction. (Constant velocity model)
• $x(t) = x_{0} + v t$

• Acceleration is constant in the vertical direction (Constant acceleration model)
• $v(t) = v_{0} + a t$
$x(t)=x_{0}+v t +frac{1}{2}a t^2$

• The magnitude of the acceleration is the acceleration due to gravity. The direction is downwards.

Consider the following situation of a ball rolling off of a 10.0 meter high platform. We are neglecting air resistance in order for our models to work.

Some questions:

• At what point will the ball's movement follow the models we described above?
• Let's set x=0 and y = 0 at the point at the bottom of the platform. What will be the y coordinate of the ball when the ball hits the ground? What are the components of velocity at the moment the ball becomes a projectile?
• How long do you think it will take for the ball to hit the ground? Make a guess that is too high, and a guess that is too low. Use units in your answer.
• How far do you think the ball will travel horizontally before it hits the ground? Again, make high and low guesses.

Let's model this information in a spreadsheet. The table of values is nothing more than repeated calculations of the algebraic models from the previous page. You will construct this yourself in a bit. NBD.

• Estimate the time when the ball hits the ground. What information from the table did you use?
• Find the maximum horizontal distance the ball travels before hitting the ground.

Here are the four sets of position/velocity graphs for the above situation. I'll let you figure out which is which. Confirm your answer from above using the graphs. Let me know if any of your numbers change after looking at the graphs.

Now I want you to recreate my template. Work to follow the guidelines for description and labels as I have in mine. All the tables should use the information in the top rows of the table to make all calculations.

Once your table is generating the values above, use your table to find the maximum height, the total time in the air, and the distance in the x-direction for a soccer ball kicked from the ground at 30° above the horizontal.

I'll be circulating to help you get there, but I'm not giving you my spreadsheet. You can piece this together using what you know.

Next steps (not for this lesson):

• The table of values really isn't necessary - it's more for us to get our bearings. A single cell can hold the algebraic model and calculate position/velocity from a single value for time. Goal seek is our friend for getting better solutions here.
• With goal seek, we are really solving an equation. We can see how the equation comes from the model itself when we ask for one value under different conditions. The usefulness of the equation is that we CAN get a more exact solution and perhaps have a more general solution, but this last part is a hazy one. So far, our computer solution works for many cases.

My point is motivating the algebra as a more efficient way to solve certain kinds of problems, but not all of them. I think there needs to be more on the 'demand' side of choosing an algebraic approach. Tradition is not a satisfying reason to choose one, though there are many - providing a need for algebra, and then feeding that need seems more natural than starting from algebra for a more arbitrary reason.

# Why computational thinking matters - Part I

Fatal error: Cannot redeclare class VideoPress_Video in /home/weinbergmath/webapps/blog/wp-content/plugins/jetpack/modules/videopress/class.videopress-video.php on line 6