Wednesday, May 04, 2016

Computer Science Making Numbers More Interesting

Last night I lay awake thinking about numbers and programming languages. Yes I know – weird.  One of the first programming languages I was paid to write code in was called DIBOL – Digital’s Business Oriented Language. It was sort of a cross between FORTRAN and COBOL which probably doesn’t mean much to a lot of people these days but said a lot back in the late 1970s. One of the interesting things about DIBOL was that it didn’t use floating point numbers. It did have 18 digits (if I remember correctly) of accuracy in integer arithmetic though. That was highly useful even if it did force one to think a bit differently.

So why was I thinking about this? Well I have been playing with various ways of programming the BBC Micro:Bit and one way doesn’t seem to support real numbers.  I found out that the Micro:Bit can return an approximation of the temperature. Now the Micro:Bit is designed for the United Kingdom where they use Celsius temperatures. I live in the US where we use Fahrenheit so I decided to write some conversion code. It looked something like this:


And the answer it returned was wrong. A little experimentation and I realized that 1.8 was being treated as 1. Well that’s no good. I came up with a couple of different solutions. This one works pretty well. Multiplying the temperature by 9 and dividing the result by 5. That takes care of the problem of 9/5 being treated as 1 rather than 1.8.BTW I love the way nesting of things work in this block language.


Last night I remembered DIBOL and came up with this. Multiplying by 18 and dividing by 10.

image Pretty much the same as my previous solution but I think it opens the door for better results if I want to play with it some more. Plus it suggests a lot more possibilities for when I know the real number values I want to use.

There is a bigger issue for Computer Science teachers here though and probably for teachers of mathematics and that is limited understanding on the part of students about how numbers work.

I see this in several places in my teaching. One is talking about number base systems such as Binary. To me, at my advanced age and long experience using Binary, Hexadecimal, and Octal along with Decimal and it all seems pretty intuitive. For my students that is not so much the case. We spend a lot of time working on this topic.

The other place I see it is teaching the Modulus operator. Ask a student for the result of 5 divided by 2 and the answer you get will depend on their age. A young child first learning division will reply 2 with a remainder of 1. A secondary school student will reply 2.5.  Both answers are of course correct but when dealing with the modulus operator programmers deal with a remainder rather than a fractional part. It amazes me sometimes how hard it can be to get students to revert back to that “and a remainder of” thinking that was so natural several years earlier in their schooling. It’s as if they forget the value of whole numbers or integers.

In computing we have to understand a bit about how numbers work. Learning computer science taught me a lot about numbers and mathematics. In fact I think that my experience with computer science turned me from someone who hated math to someone who developed some real appreciation for mathematics and for numbers themselves. It makes me wonder if more CS at younger ages might lead to more students enjoying mathematics earlier in their school careers. I’m pretty certain it would help their understanding of mathematics.  

No comments: