Speak math, not code

March 01, 2020

SMU Office of Research & Tech Transfer - Have you ever followed a recipe to bake some bread? If you have, congratulations; you have executed an algorithm. The algorithms that follow us around the internet to suggest items we might like, and those that control what shows up in our Facebook feeds may seem mysterious and uncanny at times. Yet, an algorithm is simply a set of instructions to be completed in a specified sequence, whether by human bakers or computer programs.

The difference, however, lies in how the algorithm is expressed. Recipes are written in English or other spoken languages while computer programs are written in programming languages or code. According to Leslie Lamport, winner of the 2013 Turing Award, thinking mathematically can be a useful step to specifying the algorithm for computer programmes, as it can help programmers clarify their thinking and make programs more efficient.

"Most programmers just start writing code; they don't even know what the algorithm is. It's like starting to build without a blueprint," said Dr. Lamport, speaking at an exclusive dialogue at the Singapore Management University (SMU) on 14 January 2020, held in conjunction with the SMU-Global Young Scientists Summit 2020.

"And the result? The program is hard to debug and inefficient because you would be trying to optimise at the code level rather than at the algorithm level. We should do what almost every other field of science and engineering does: initially describe the problem with math instead."

Why math is better than code

Using Euclid's algorithm as an example, Dr. Lamport walked the audience through how an algorithm can be expressed precisely yet simply with mathematics. Described by ancient Greek mathematician Euclid in 300 BC, Euclid's algorithm is a method for identifying the greatest common divisor (GCD) of two numbers, that is, the largest number that can divide the two numbers without leaving a remainder. For example, the GCD of the numbers 15 and 12 is 3.

The method is simple: subtract the smaller number from the larger number, then repeat this till both numbers are the same; the resulting number is the GCD. The entire procedure can be described in a single mathematical formula, said Dr. Lamport, who is recognised for developing the widely used LaTex file format, in addition to his pioneering work on distributed computing systems.

In contrast, writing Euclid's algorithm in code is more time consuming and cumbersome, and therefore harder to debug if it is not working correctly. "Euclid's program would have to contain a lot of lower level details, like what you should do if either number is less than or equal to zero," Dr. Lamport said. "You would have to decide that if you are writing a computer program but it's not the algorithm's problem."

How much more efficient would using math instead of code be? When engineers used TLA+, a high level formal specification language based on mathematics developed by Dr. Lamport to model, document and verify concurrent computing systems, they were able to dramatically reduce the size of an operating system originally used to control some experiments on the Rosetta spacecraft. "One of the results of specifying the software logic with TLA+ was that the code size was able to be reduced to about ten times less than the original," Dr. Lamport said. "You don't reduce the code size by ten times by better coding; you do it by cleaner architecture, which is just another word for a better algorithm."

On top of being more efficient, taking a mathematical approach has the additional benefit of making de-bugging easier. Amazon Web Services and Microsoft Azure engineers use TLA+ for their cloud services, Dr. Lamport said, and through it have found bugs in their system designs that could not be found via any other technique.

Get comfortable with math

Although math is both powerful and elegant when it comes to describing algorithms, many people - including computer programmers and engineers - are intimidated by it and shy away from using it. "Some students have asked us when can they stop doing and reviewing the math and start the software programming," said Professor Steven Miller, Vice Provost (Research) at SMU and formerly the Founding Dean of the School of Information Systems.

Dr. Lamport believes that getting used to 'speaking' in mathematics is a matter of exposure. "Why is 'two plus two equals four' considered simple but a logical operation like 'an element of' is hard to understand for most people? Logical operations such as "element of" simply means that something is part of a bunch of other things. That concept doesn't require you to learn any complicated thing like counting, as counting is actually quite complicated," he said.

"Why should 'element of' seem frightening when 'plus' seems so easy? It's just a matter of not being familiar with it, and this is not all your own fault - mathematicians are terrible at teaching it."

For Dr. Lamport, becoming fluent in mathematics is the first step, but for mathematical thinking to truly impact the way algorithms are written, it has to change the way we think. "I want to emphasise that mathematics doesn't solve the problem for you; you have to solve the problem," he said. "Thinking mathematically will help you solve the problem; and mathematics helps to ensure that the solution was right."

Singapore Managment University

Related Mathematics Articles from Brightsurf:

A new method for boosting the learning of mathematics
How can mathematics learning in primary school be facilitated? UNIGE has developed an intervention to promote the learning of math in school.

Could mathematics help to better treat cancer?
Impaired information processing may prevent cells from perceiving their environment correctly; they then start acting in an uncontrolled way and this can lead to the development of cancer.

People can see beauty in complex mathematics, study shows
Ordinary people see beauty in complex mathematical arguments in the same way they can appreciate a beautiful landscape painting or a piano sonata.

Improving geothermal HVAC systems with mathematics
Sustainable heating, ventilation, and air conditioning systems, such as those that harness low-enthalpy geothermal energy, are needed to reduce collective energy use and mitigate the continued effects of a warming climate.

How the power of mathematics can help assess lung function
Researchers at the University of Southampton have developed a new computational way of analyzing X-ray images of lungs, which could herald a breakthrough in the diagnosis and assessment of chronic obstructive pulmonary disease (COPD) and other lung diseases.

Mathematics pushes innovation in 4-D printing
New mathematical results will provide a potential breakthrough in the design and the fabrication of the next generation of morphable materials.

More democracy through mathematics
For democratic elections to be fair, voting districts must have similar sizes.

How to color a lizard: From biology to mathematics
Skin color patterns in animals arise from microscopic interactions among colored cells that obey equations discovered by Alan Turing.

US educators awarded for exemplary teaching in mathematics
Janet Heine Barnett, Caren Diefenderfer, and Tevian Dray were named the 2017 Deborah and Franklin Tepper Haimo Award winners by the Mathematical Association of America (MAA) for their teaching effectiveness and influence beyond their institutions.

Authors of year's best books in mathematics honored
Prizes for the year's best books in mathematics were awarded to Ian Stewart and Tim Chartier by the Mathematical Association of America (MAA) on Jan.

Read More: Mathematics News and Mathematics Current Events
Brightsurf.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com.