Archive for the mathematics Category

Other People’s Code

Posted in Education, mathematics with tags , , , on March 16, 2018 by telescoper

I don’t know if this is just me being useless, but one of the things I’ve always found difficult is debugging or rewriting computer programs written by other people. This is not a complaint about people who fail to document their code sufficiently to see what’s going on, it’s that even when the code is documented it seems much more difficult to spot errors in code written by other people than it is when you’ve written the program yourself.

I’ve been thinking a lot since I’ve been teaching Computational Physics here in Maynooth University. One of the standard elements of the assessment for this module is a task wherein the students are given a Python script intended to perform a given task (e.g. a numerical integral) but which contains a number of errors and asked to identify and correct the errors. This is actually a pretty tough challenge, though it is likely to be one that a graduate might have to meet if they get a job in any environment that involves programming.

Another context in which this arises is our twice-weekly computing laboratory sessions. Twice in the last couple of weeks I’ve been asked for a bit of help by students with code that wasn’t working, only to stare at the offending script for ages and fiddling with a number of things that made no difference, without seeing what turned out to be an obvious mistake. Last week it was an incorrect indent in Python (always a hazard if you’ve been brought up on Fortran). This week it was even simpler, a sign error in a line that was just supposed to calculate the mid-point of an interval. I should have been able to spot these very quickly, but I couldn’t.

What makes this so difficult? When given a mathematical calculation to mark I can usually spot errors reasonably easily (unless the working is illegible), but with code it’s different (at least for me). If I’d been given it on a piece of paper as part of a formula, I reckon I would have spotted that minus sign almost immediately.

One possibility is just that I’m getting old. While that may well be true, it doesn’t explain why I found debugging other people’s code difficult even when I was working on software at British Gas when I was 18. In that context I quite often gave up trying to edit and correct software, and instead just deleted it all and wrote my own version from scratch. That’s fine if the task is quite small, but not practicable for large suites written by teams of programmers.

I think one problem is that other people rarely approach a programming task exactly the same way as one would oneself. I have written programs myself to do the tasks given to students in the computing lab, and I’m always conscious of the method I’ve used. That may make it harder to follow what others have tried to do. Perhaps I’d be better off not prejudicing my mind doing the exercises myself?

Anyway, I’d be interested to know if anyone else has the same with other people’s code and if they have any tips that might improve my ability to deal with it. The comments box is at your disposal…


A Problem involving Simpson’s Rule

Posted in Cute Problems, mathematics with tags , on March 9, 2018 by telescoper

Since I’m teaching a course on Computational Physics here in Maynooth and have just been doing methods of numerical integration (i.e. quadrature) I thought I’d add this little item to the Cute Problems folder. You might answer it by writing a short bit of code, but it’s easy enough to do with a calculator and a piece of paper if you prefer.

Use the above expression, displayed using my high-tech mathematical visualization software, to obtain an approximate value for π/4 (= 0.78539816339…) by estimating the integral on the left hand side using Simpson’s Rule at ordinates x =0, 0.25, 0.5, 0.75 and 1.

Comment on the accuracy of your result. Solutions and comments through the box please.

HINT 1: Note that the calculation just involves two applications of the usual three-point Simpson’s Rule with weights (1/3, 4/3, 1/3). Alternatively you could do it in one go using weights (1/3, 4/3, 2/3, 4/3, 1/3).

HINT 2: If you’ve written a bit of code to do this, you could try increasing the number of ordinates and see how the result changes…

P.S. Incidentally I learn that, in Germany, Simpson’s Rule is sometimes called called Kepler’s rule, or Keplersche Fassregel after Johannes Kepler, who used something very similar about a century before Simpson…

The de Valera connection

Posted in History, mathematics, Maynooth with tags , , on February 14, 2018 by telescoper

This morning I took the early flight to Dublin, which was on time, and thence via the Airport Hopper to Maynooth. There were only two passengers on the bus, both going to the terminus, so it made good time, travelling all the way along the motorway.

Walking into the Maynooth campus I remembered an interesting little historical fact that I stumbled across last week, concerning Éamon de Valera, founder of Fianna Fáil (one of the two largest political parties in Ireland) and architect of the Irish constitution. De Valera (nickname `Dev’) is an enigmatic figure, who was a Commandant in the Irish Republican Army during the 1916 Easter Rising, but despite being captured he somehow evaded execution by the British. He subsequently became Taoiseach (Prime Minister) and then President (Head of State) of the Irish Republic.

Eamon de Valera, photographed sometime during the 1920s.

The point of connection with Maynooth, however, is less about Dev’s political career than his educational background: he was a mathematics graduate, and for a short time (1912-13) he was Head of the Department of Mathematics and Mathematical Physics at St Patrick’s College, Maynooth, which was then a recognised college of the National University of Ireland. The Department became incorporated in Maynooth University, when it was created in 1997. It is said that one of the spare gowns available to be borrowed by staff for graduation ceremonies belonged to de Valera. Mathematical Physics is no longer a part of the Mathematics Department at Maynooth, having become a Department in its own right and it recently changed its name to the Department of Theoretical Physics.

De Valera missed out on a Professorship in Mathematical Physics at University College Cork in 1913. He joined the the Irish Volunteers, when it was established the same year. And the rest is history. I wonder how differently things would have turned out had he got the job in Cork?

That’s one connection, but when I arrived in the office this morning I found another. An email had arrived announcing a conference later this year in honour of Erwin Schrödinger.  It was de Valera – a notable advocate for science – who in 1940 set up the Dublin Institute for Advanced Studies (DIAS); Schrödinger became the first Director of the School of Theoretical Physics, one of the three Schools in DIAS.

Planes, Trains and Quaternions

Posted in Biographical, History, mathematics, Maynooth with tags , , , , , , , , on January 4, 2018 by telescoper

Well, here I am in Maynooth for the first time in 2018. I flew over from Cardiff yesterday. The flight was rather bumpy owing to the strong winds following Storm Eleanor, and it was rather chilly waiting for the bus to Maynooth from Dublin Airport; nevertheless I got to my flat safely and on time and found everything in order after the Christmas break.

This morning I had to make a trip by train to Dublin city  to keep an appointment at the Intreo Centre in Parnell Street, which is about 15 minutes walk from Dublin Connolly train station. I bought an Adult Day Return which costs the princely sum of €8.80. Trains, stations and track in Ireland are maintained and operated by Irish Rail (Iarnród Éireann), which is publicly owned. Just saying.

The distance between Maynooth and Dublin about 25 km, which takes about 40 minutes on the local stopping train or about 25 minutes on the longer distance trains which run nonstop from Maynooth to Dublin. As it happens I took one of the fast trains this morning, which arrived on schedule, as did the return journey on a commuter train. My first experience of the Irish railway system was therefore rather positive.

I had thought of having a bit of a wander around the city on my way to Parnell Street but it was raining and very cold so I headed straight there. I arrived about 20 minutes ahead of my scheduled appointment, but was seen straight away.

The reason for the interview was to acquire a Personal Public Services Number (PPSN), which is the equivalent of the National Insurance Number we have in the United Kingdom. This number is needed to be registered properly on the tax and benefit system in Ireland and is the key to access a host of public services, the electoral roll, and so on. You have to present yourself in person to get a PPSN, presumably to reduce the opportunity for fraud, and I was told the interview would take 15 minutes. In fact, it only took about 5 minutes and at the end a photograph was taken to go on the ID card that is issued with the number on it.

So there I was, all finished before I was even due to start. The staff were very friendly and it all seems rather easy. Fingers crossed that the letter informing me of my number will arrive soon. It should take a week or so, so I’m told. After that I should be able to access as many personal services as I want whenever I want them. (Are you sure you have the right idea? Ed.)

For  the return trip  to Maynooth I got one of the slower commuter trains, stopping at intermediate stations and running right next to the Royal Canal, which runs from Dublin for 90 miles through  Counties Dublin, Kildare, Meath and Westmeath before entering County Longford, where it joins the River Shannon. One of the intermediate stations along the route next to the canal is Broombridge, the name of which stirred a distant memory.

A quick application of Google reminded me that the town of Broombridge is the site of the bridge (Broom Bridge) beside which William Rowan Hamilton first wrote down the fundamental result of quaternions (on 16th October 1843). Apparently he was walking from Dunsink Observatory into town when he had a sudden flash of inspiration  and wrote the result down on the spot, now marked by a plaque:

Picture Credit: Brian Dolan


This episode  is commemorated on 16th October each year by an annual Hamilton Walk. I look forward to reporting from the 2018 walk in due course!

P.S. Maynooth is home to the Hamilton Institute which promotes and facilitates research links between mathematics and other fields.


Trees, Graphs and the Leaving Certificate

Posted in Biographical, mathematics, Maynooth, The Universe and Stuff with tags , , , , , , on December 15, 2017 by telescoper

I’m starting to get the hang of some of the differences between things here in Ireland and the United Kingdom, both domestically and in the world of work.

One of the most important points of variation that concerns academic life is the school system students go through before going to University. In the system operating in England and Wales the standard qualification for entry is the GCE A-level. Most students take A-levels in three subjects, which gives them a relatively narrow focus although the range of subjects to choose from is rather large. In Ireland the standard qualification is the Leaving Certificate, which comprises a minimum of six subjects, giving students a broader range of knowledge at the sacrifice (perhaps) of a certain amount of depth; it has been decreed for entry into this system that an Irish Leaving Certificate counts as about 2/3 of an A-level for admissions purposes, so Irish students do the equivalent of at least four A-levels, and many do more than this.

There’s a lot to be said for the increased breadth of subjects undertaken for the leaving certificate, but I have no direct experience of teaching first-year university students here yet so I can’t comment on their level of preparedness.

Coincidentally, though, one of the first emails I received this week referred to a consultation about proposed changes to the Leaving Certificate in Applied Mathematics. Not knowing much about the old syllabus, I didn’t feel there was much I could add but I had a look at the new one and was surprised to see a whole `Strand’, on Mathematical Modelling with netwworks and graphs.

The introductory blurb reads:

In this strand students learn about networks or graphs as mathematical models which can be used to investigate a wide range of real-world problems. They learn about graphs and adjacency matrices and how useful these are in solving problems. They are given further opportunity to consolidate their understanding that mathematical ideas can be represented in multiple ways. They are introduced to dynamic programming as a quantitative analysis technique used to solve large, complex problems that involve the need to make a sequence of decisions. As they progress in their understanding they will explore and appreciate the use of algorithms in problem solving as well as considering some of the wider issues involved with the use of such techniques.


Among the specific topics listed you will find:

  • Minimal Spanning trees applied to problems involving optimising networks and algorithms associated with finding these (Kruskal, Prim);  
  • Bellman’s Optimality Principal to find the shortest paths in a weighted directed network, and to be able to formulate the process algebraically;
  •  Dijkstra’s algorithm to find shortest paths in a weighted directed network; etc.


For the record I should say that I’ve actually used Minimal Spanning Trees in a research context (see, e.g., this paper) and have read (and still have) a number of books on graph theory, which I find a truly fascinating subject. It seems to me that the topics all listed above  are all interesting and they’re all useful in a range of contexts, but they do seem rather advanced topics to me for a pre-university student and will be unfamiliar to a great many potential teachers of Applied Mathematics too. It may turn out, therefore, that the students will end up getting a very superficial knowledge of this very trendy subject, when they would actually be better off getting a more solid basis in more traditional mathematical methods  so I wonder what the reaction will be to this proposal!




Joseph Bertrand and the Monty Hall Problem

Posted in Bad Statistics, History, mathematics with tags , , , , on October 4, 2017 by telescoper

The death a few days ago of Monty Hall reminded me of something I was going to write about the Monty Hall Problem, as it did with another blogger I follow, namely that (unsrurprisingly) Stigler’s Law of Eponymy applies to this problem.

The earliest version of the problem now called the Monty Hall Problem dates from a book, first published in 1889, called Calcul des probabilités written by Joseph Bertrand. It’s a very interesting book, containing much of specific interest to astronomers as well as general things for other scientists. Ypu can read it all online here, if you can read French.

As it happens, I have a copy of the book and here is the relevant problem. If you click on the image it should be legible.

It’s actually Problem 2 of Chapter 1, suggesting that it’s one of the easier, introductory questions. Interesting that it has endured so long, even if it has evolved slightly!

I won’t attempt a full translation into English, but the problem is worth describing as it is actually more interesting than the Monty Hall Problem (with the three doors). In the Bertrand version there are three apparently identical boxes (coffrets) each of which has two drawers (tiroirs). In each drawer of each box there is a medal. In the first box there are two gold medals. The second box contains two silver medals. The third box contains one gold and one silver.

The boxes are shuffled, and you pick a box `at random’ and open one drawer `randomly chosen’ from the two. What is the probability that the other drawer of the same box contains a medal that differs from the first?

Now the probability that you select a box with two different medals in the first place is just 1/3, as it has to be the third box: the other two contain identical medals.

However, once you open one drawer and find (say) a silver medal then the probability of the other one being different (i.e. gold) changes because the knowledge gained by opening the drawer eliminates (in this case) the possibility that you selected the first box (which has only gold medals in it). The probability of the two medals being different is therefore 1/2.

That’s a very rough translation of the part of Bertrand’s discussion on the first page. I leave it as an exercise for the reader to translate the second part!

I just remembered that this is actually the same as the three-card problem I posted about here.

R.I.P. Maryam Mirzakhani (1977-2017)

Posted in mathematics with tags , , on July 18, 2017 by telescoper

Very sad news arrived at the weekend of the death of the brilliant Iranian-born mathematician Maryam Mirzakhani of breast cancer at the age of just 40. Let me first of all express my heartfelt condolences to her family, friends and colleagues on this devastating loss.

A uniquely creative and inspirational figure, Maryam Mirzakhani was the first woman ever to win the coveted Fields Medal; her citation for that award picks out her work on the dynamics and geometry of Riemann surfaces and their moduli spaces.  Here’s a short video of her talking about her life and work. It’s fascinating not only because of the work itself, but the insight it gives into the way she did it – using very large sheets of paper covered in drawings and notes!

R.I.P. Maryam Mirzakhani (1977-2017).