📜 ⬆️ ⬇️

Hacker mathematician

Translation of an article by Evan Miller - The Mathematiclal Hacker .

The programmer profession is blessed with a large number of gifted authors. Today I will focus on three of my favorites - Erica Raymond, Paul Graham and Steve Yegg. I will do this because they, it seems to me, do not agree with me in the opinion that mathematics has (and will have) meaning for a programmer-practitioner.

Their thoughts can be reduced to the following:


All these statements I consider myopic.
')
In a sense, each of these points of view is true. If you are a system or network programmer like Raymond, you can do your job without using anything other than multiplication and modulo division. Graham, in turn, is right that mathematics can be a source of metaphors, and Jegge is that calculations can be reduced to mathematical formalism (which hackers who use Lisp often like to repeat).

They all agree on one thing: from the point of view of solving everyday problems, mathematics is almost useless. Lisp programmers (as we are told) should be grateful that mathematics was used to develop lambda computations , but today mathematics is more of a form of personal enlightenment than a tool with which you can do something.

This opinion is wrong. It has become common because you can be a productive and well-paid programmer — not even a top-notch hacker — without scientific and mathematical knowledge. But I think that most programmers who take seriously what they are doing should understand the calculations (real ones), linear algebra and statistics. The reason for this has nothing to do with “programming” as such — compilers, data structures, and everything else — but, rather, is related to the role of programming in economics.

The history of twentieth-century business is a series of transformations through which industries that “did not need mathematics” suddenly became very dependent on it. Statistical quality control has brought industry to a new level, farming has transformed farming, analysis of variance revolutionized the chemical and pharmaceutical industries, linear programming has changed the face of supply chain management in logistics, and the Black-Scholes equation has made the market out of nothing. Recently, the methods of “Moneyball” began to be used in sports management. And there are many more such examples.

What is the connection between these innovations and computer programming? Consider how Eric Raymond defines the word “hack” ( hack ), such a welcome and being the meaning of the existence of any self-respecting hacker: a hack is an incredibly good and perhaps time-consuming piece of work that does exactly what you need . In this sense, applied mathematicians have been engaged in “hacker” activities for over a hundred years.

In the end, the computer was invented to solve mathematical problems, and not to implement compilers and word processors. Computer solutions for social problems in engineering, mining, agriculture, transport and defense have been of great value to society over the past seventy years. I would venture to bet a trillion dollars, that if we add the defeat of Germany due to the achievements of computer cryptanalysis, and the surrender of Japan due to the success of numerical calculations, this value will be immeasurable.

However, our great hacker authors rarely mention this kind of mathematical “hacks”. The reason, I think, is that “hacker literature” is mostly written by Lisp programmers, and they are often in the dark about the possibilities of applied mathematics. Although I am grateful for the fact that we have so many good articles written by Lisp programmers, yet I tend to draw a distorted picture of what current programming is and what it should be. Reading Raymond, Graham and Yegge it seems (and they all consider themselves Lisp hackers) that the ultimate goal of programming is to make the program more powerful than those that preceded it, usually by adding layers of abstraction. Let's call it “Lisp programming school”.

There is another school that has not been very well represented in literature for many years, but which undoubtedly made a more positive impact on the economy. Let's call it “Fortran programming school”. Which I think is well summarized by Dr. Adam Rosenberg, who calls himself the last bison of industrial mathematics . Instead of seeing mathematics as an advanced tool reserved for extremely specialized computer applications, the Fortran programmer’s school sees the computer as an advanced tool for performing mathematical operations. Historically, Fortran programmers have worked in industry or government institutions with a more technical focus (NASA, the defense department, etc.). They are often ridiculed by Lisp programmers for their inability to use recursion. (See the satirical article Real Programmers Don't Use PASCAL and if it seems to you that this satire is unfair, then see Dr. Rosenberg's Style Guide ).

The ridicule, I think, should be directed in a completely different direction. Unlike the traditions of Fortran (which can be proud of having “sent a man to the moon” and supports critical infrastructure in banking, communications, etc.), the Lisp culture almost deliberately ignores mathematics. This disregard is masked by talk of formalism and instinctive admiration for lambda computations, which, unlike Summa Theology, are a closed computational Universe that sheds little light on the surrounding world.

To assess how actively the lack of knowledge of mathematics is perpetuated in the Lisp culture, consider the traditional introduction to recursion in any functional programming. There are only two options - the calculation of the Fibonacci numbers and the calculation of factorial.

The most common solution in a textbook is recursive: we calculate the value of a number based on the number in front of it, and the value in front of it - based on the number in front of the number in front of it, and so on, until we reach the “basic case” that has a definite solution. This is a classic example of didactic programming, demonstrating the intended utility of recursive methods.

An “advanced” discussion could take into account technical considerations, such as the behavior of a call tail or the ability to memorize the results.

But in these discussions, you rarely find sound mathematical considerations. If the goal is to calculate Fibonacci numbers or factorial, then the correct solution is not a recursive function, but knowledge of mathematics.
The calculation of the Fibonacci numbers can be implemented as follows in C:

long int fib(unsigned long int n) { return lround((pow(0.5 + 0.5 * sqrt(5.0), n) - pow(0.5 - 0.5 * sqrt(5.0), n)) / sqrt(5.0)); } 

Neither recursion nor even a cycle is required, since an analytical solution was found as early as the seventeenth century. Similarly, if you want to calculate factorial, the programmer must be able to use the system log-gamma functions, as shown in the following code in C:

 long int fac(unsigned long int n) { return lround(exp(lgamma(n + 1))); } 

Again, recursion is not required for those who know that factorial is actually a special case of the gamma function. (The implementation of the log-gamma function is usually a polynomial approximation, the computation of which takes constant time).

In spite of the aesthetic advantages attributed to functional programming, I find the solutions given more elegant than their recursive counterparts. They are executed in constant (rather than linear) time, and they are easily adapted to work with incoming data with a floating point. Moreover, they push the programmer to ask questions: why does the Fibonacci equation contain the square root of five? What does it mean to take factorial fractions? These questions have fascinating answers that are not so easy to comprehend, based on the recurrence relation alone.

After writing my recursive solution, the Lisp programmer will most likely ask the next pointless question: how can I reduce these two functions to one?

Problems with Lisp programming traditions are related to the fact that they are too focused on the programming task — compilers, abstractions, editors, etc. — rather than problems outside the workplace of the programmer. I assume that the dogma of Lisp’s programming school — Raymond, Graham, and Yegge — do not need math, because they only spend their time worrying about how to make the code more abstract. Such thinking can lead to a compact and powerful source code base, but, in the language of economics, it has an opportunity cost. If you think about your code, then you do not think about the world and the equations that describe it.

Although the first years of the twenty-first century speak in favor of the philosophy of the Lisp programming school, I predict that the mid-century will belong to Fortran school programmers who are able to successfully use mathematics to solve practical problems. It is very tempting to say that to solve most problems in programming “mathematics is not needed”, but it’s just as much as it’s true that production, supply chain management or baseball “do not need mathematics”. Higher mathematics seems completely unnecessary for modern practitioners, but only until it becomes clear that a specific mathematical concept is the right way to solve a problem here and now. After that, mathematics becomes vital.

There are two reasons why I am optimistic about the future of mathematics in computer programming. The first is related to the growth in the amount of data generated by Web companies (“Big Data”). With the advent of new types of information, the number of equations that can be used to process this data is increasing. For this reason, there is great interest in advanced methods of machine learning, but even simple statistical methods can be useful in many applications. Mathematics applied to business data will provide a deeper understanding of business, more efficient financial operations, better products (for example, recommendations), new products (for example, forecasting services).

The second reason why I am optimistic about the future of mathematics in programming is that the average buyer now has more information than ever before, and mathematics will help to put things in order or at least make it more attractive. Applications that have traditionally been considered “scientific computing” (for example, geographic information systems or image processing) are now of interest to the average user, who has, let's say, his collection of digital images with geo-tagging data. Instagram, for example, was built on several equations that convert the color channels of an image. Understanding of mathematics can help the programmer in solving practical problems for the user, as well as provide him with invaluable experience.

Mathematics, ultimately, does not help in understanding computer programming. This is not about finding metaphors or understanding the “basics” that will never be put into practice. Mathematics, rather, is a tool for understanding the structure of the world: the movements of the planets, the construction of a data structure, the perception of colors, or something else out of many things that can become more understandable if we apply equations to them. And this is directly related to the work of the hacker - to find out how the piece of code that will be used again and again works.

Should we go back to the good old days when people were programming in Fortran and everything was built on arrays? Hardly. All we need is to include applied mathematics in the education of hackers. Hackers, who grew up only on the principles of Lisp programming school, had only one parent. (The other parent seems to have been too busy at work). We need examples, tutorials and military histories where non-trivial mathematics are successfully used in practice in computer programs. Although boasting is not common to most programmers, we need hackers to cheer whenever a new and interesting application of mathematics is found. We need a celebration of scientific curiosity.

Finally, we need a new generation of novice hackers who need to incorporate math into their self-training program. We need students with knowledge of physics, technology, linear algebra, statistics and numerical calculations. And we need them to teach their older colleagues who have grown up in the dark about such things. With the tireless dissemination of data and the imminent disappearance of the Fortran old guard, there are ample opportunities for beginning hackers-mathematicians to change this world with their more strict thinking.

Source: https://habr.com/ru/post/272371/


All Articles