Beginning Magma

My PhD research will make use of a software package called Magma, used for computation in number theory, algebra, algebraic geometry, and algebraic combinatorics.

Although I had briefly looked into Magma earlier in the year, I gave it more of a serious start this week. It’s a bit odd for me, since it’s essentially a programming language designed for mathematicians, not computer scientists. There is one thing has caused me serious conceptual problems, Magma’s array-type classes all use 1-indexing.

Allow me to explain (for Bruce’s sake).

Most programming languages have some sort of array structure, whereby you store a list of elements and later refer to them by their index, a sequential number referring to their position within the array.

Almost all programming languages use 0-indexing, which means that the first element in the list is at index 0, the second at index 1, and so on. Now, put this way it seems counterintuitive, in fact for most people it probably is. However there is a good reason for this style.

On older computer systems, every small operation counted for a lot, and simplicity was always one of the most important aspects. When you store an array, you’re just storing all the elements of that array side by side. Let’s says your array of 3 integers (whole numbers) is stored at address 1000, and each integer takes up 4 units of space, so you’ve got one occupying 1000-1003, another occupying 1004-1007, and the third occupying 1008-1011.

Now all you have to do is multiply the size of the array element (our integer at 4 units) by the index (0, 1, or 2 using 0-indexing) and then add the start address. This way, the first element (index 0) starts at (0 x 4) + 1000, which is just 1000, the second element (index 1) starts at (1 x 4) + 1000, which is 1004, and so on.

1-indexing is more intuitive to a non-programmer, the first element is index 1, the second element is index 2, and following on from there, but it doesn’t have the computational simplicity of 0-indexing, and since programmers tend to conform to their computer far more than they expect their computer to conform to them, it’s the norm. (I’m going to write about why this makes most of us terrible at usability another day.)

I’ve been programming for not quite half my life, and so 0-indexing is well and truly ingrained in my computer science mind, and now I come across Magma and its 1-indexing and I’ve been thrown completely.

My first reaction is to use 0-indexing, and so when I wrote my psuedo-code out by hand earlier in the week that’s what I used, changing it turned out to be more complicated than I’d imagined, and I can see this as being an ongoing problem.

This entry was posted in Mathematics and tagged , . Bookmark the permalink.

One Response to Beginning Magma

Leave a Reply to Bruce Cancel reply

Your email address will not be published.