Programming is Science not Maths

Sahil Hemnani
7 min readAug 10, 2021

This article is dedicated to the memories and discoveries of the great mathematicians and programmer Edsger Wybe Dijkstra.

E.W. Dijkstra

When we talk about programming in general- the first thought comes to our mind is of maths. For a long time we have been told that programming is deeply related to mathematics by our teachers, mentors and colleagues, but have you ever thought why programming is maths and not science?
In this article I am going to throw some light on few points which will at last prove that programming is science and not maths.

But there are few prerequisites that will help you in understanding the concept in a better way such as- programming paradigms, Mathematical induction, and some basic maths.

What are we going to discuss

  • Starting with the very beginning of programming, who was Dijkstra?
  • His discoveries and Idea of proving programming as math.
  • What is structured programming and why does it make sense in context of our topic of concern ?
  • What are the differences between science and math and how programming is science and not math?
  • How are tests related to scientific proofs- and how can we achieve that ?
  • Conclusion

Starting with the very beginning of programming, who was Dijkstra?

Back when Alan Turning wrote the very first line of code till now when we are writing complex programs to perform complex tasks- programming has been the exact same.

It is sequence, selection and iteration. Yes the programming languages have evolved, our processor speed has evolved, hardware has evolved a lot but the software is still the same- the programming is still the same.

You can write any complex program with those three (sequence, selection and iteration). So if programming has not evolved much it is relevant to look at the discoveries in the early stage and past to make our roots strong and to know how the things actually work at the level zero.

Edsger Wybe Dijkstra was born in Rotterdam in 1930. He survived the bombing in World War II, along with the German occupation of the Netherlands, and in 1948 graduated from high school with the highest marks possible in maths, physics, chemistry and biology. In March 1952, at the age of 21, Dijkstra took a job with the Mathematical Center of Amsterdam as the Netherlands’ very first programmer.

In 1955, having been a programmer for 3 years, and while still a student, Dijkstra concluded that the intellectual challenge of programming was greater than the intellectual challenges in theoretical physics. As a result of this he took programming as a long term career.

It was this environment that Dijkstra made his great discoveries.

His discoveries and Idea of proving programming as maths.

The problem that Dijkstra recognized, early on, was that programming is hard, and the programmers don’t do it very well. Program of any complexity contains too many details for a human brain to manage without help. Overlooking just one small detail results in a program that may seem to work but fail in surprising ways.

Dijkstra’s Solution was to apply the mathematical disciplines of proof. His vision was the construction of an Euclidean hierarchy of postulates theorem corollaries, and lemmas. Dijkstra thought that programming could use that hierarchy the way mathematician’s do. In other words programmers would use proven structures and tie them together with code that they would then prove correct themselves.

So Dijkstra realized that he would have to demonstrate the technique for writing basic rules of simple algorithms.

This he found to be quite challenging, but by that time Bohm and Jacopini, who proved that all programs can be constructed from just three structures sequence, selection and iteration were largely accepted. The discovery was remarkable: the very control structure that made a module provable were the same minimum set of control structures from which all programs can be built. Thus structured programming was born.

So he thought to prove the basic building unit of any program by proofs.

How he proved sequence

Dijkstra showed that sequential statements could be proved correct through simple enumeration. The technique mathematically traced the input of the sequence to the output of the sequence; this approach was no different from any normal mathematical proof.

How he proved selection

Dijkstra tackled selection through reapplication of enumeration. Each path through the selection was enumerated. If both paths eventually produce appropriate mathematical results then the proof was solid.

How he proved Iteration

Iteration was a bit different. To prove an iteration correct, Dijkstra had to use induction. He proved the case for 1 by enumeration. Then he proved the case that if N was assumed correct, N+1 was correct, again by enumeration. He also proved the starting and ending criteria of the iteration by enumeration.

Such proofs were laborious and complex — but they were proofs. With their development, the idea that Euclidean hierarchy of theorems could be constructed seemed reachable.

But what happened next ? Why did no one use these proofs to prove their own programs? Do you prove your own program after writing it? Obviously NO.

Answer is simple- It is complex for a programmer to every time prove that the program which he/she has written is correct.

So the proofs never came. The Euclidean hierarchy of theorems was never built. And programmers at large never saw the benefits of working through the complex process of writing proofs. In the end Dijkstra’s dream faded and died.

So how do we prove our programs are correct- THE SCIENTIFIC STRATEGY

What is Structured programming and why does it make sense in context of our topic of concern ?

Structured programming imposes discipline on direct transfer of control.

It was discovered by Dijkstra when he said not to use goto statements as they make it tough to prove the program mathematically.

Structured programming forces us to recursively decompose a program into a set of small provable functions.

Read that again- Provable Functions (makes sense)

Now we will actually see how we can prove small functions and how it is science.

What are the differences between science and maths and how programming is science and not maths?

Science is fundamentally Different from mathematics, in that scientific theories and laws can not be proven correct. I I cannot prove to you that Newton’s second law of motion, F= ma, or law of gravity, F= Gm1m2/r2, are correct. I can demonstrate these laws to you, and I can make measurements that show them correct to many decimal places, but I cannot prove them in the sense of mathematical proofs. No matter how many experiments I conduct or how much empirical evidence I gather, there is always the chance that some experiment will show that those Laws of Motion and gravity are incorrect.

That is the nature of scientific theories and laws: they are falsifiable but not provable.

Science does not work by proving statements true, but rather by proving statements false. those statements that we cannot true false, after much effort, we deem to be true enough for our purposes.

Of course, Not all statements are provable. The statement “This is a lie” is neither true nor false. It is one of the simplest examples of a statement that is not provable.

Ultimately, we can say that mathematics is the discipline of proving provable statements true. Science, in contrast, is the discipline of proving provable statements false.

So we can prove our programs correct by passing all the tests which we wrote to make our program fail. That means if the tests can not prove our program false, we have to accept that it is true and acceptable for our purpose.

So writing tests proves our code and program, and hence makes programming science not maths.

How are tests related to scientific proofs- and how can we achieve that ?

Dijkstra once said, “Testing shows the presence, not the absence, of bugs” In other words, A program can be proven incorrect by a test, but it cannot be proven correct. All that test can do, after sufficient testing effort, is allow us to deem a program to be correct enough for our purposes.

The implications of this fact are stunning. software development is not a mathematical Endeavour, even though it seems to manipulate mathematical constructs. Rather, software is like science. we show correctness by failing to prove in correctness, despite our best efforts.

Also structured programming forces us to recursively decompose a program into a set of small probable functions. We Can then use tests to try to prove the small probable function incorrect . If such tests fail to prove incorrectness, then we deem the function to be correct enough for our purpose.

Conclusion

We conclude that programming is deeply related with science and not with maths.

We also concluded that programming does not work by proving the program true, but rather by proving the program false, those programs that we cannot prove false, after much effort, we deem to be true enough for our purposes.

Also we can say that by the use of structured programming we can recursively decompose a program into a set of small provable functions, We Can then use tests to try to prove the small probable function incorrect . If such tests fail to prove incorrectness, then we deem the function to be correct enough for our purpose.

--

--