⬆️ ⬇️

Wolfram Language (Mathematica) is just a toy

I doubted my point of view, see more details in one of UPD.



I want to talk about Wolfram Language (hereinafter WL). I apologize for the confusion of the presentation, the post grew out of an attempt to respond to this comment from Nilis .



WL is still a highly specialized language. Just Wolfram decided to earn money, and for this he began to promote his WL also as a general-purpose language. If you really liked WL, it means that you have not yet learned other languages. Also note that WL is not free software, unlike heaps of other languages, including the same python.

')

About 6-10 years ago, when I was in school, I only knew BASIC, Pascal / Delphi, C / C ++ and WL. From OS dealt only with Windows. I didn’t know what scripting languages ​​are (perl, python, bash), didn’t know the very concept of “script”. I thought that the command interface is an outdated interface and that the only correct interface for the program is the graphic one. I programmed in Delphi and WL. Delphi programs have always been graphical. With the exception of Olympiad programming, there was in the program requirements that they should be textual, I wrote them in Delphi and C ++. When I found out about WL, I was fascinated by it, just like you. Because the WL code was much shorter than Delphi / C ++. And in general, because WL was completely different from Delphi and C ++. Because there was the ability to program functionally. I got acquainted with functional programming on the example of WL, I did not know that there are “standard” functional languages ​​- Haskell, Lisp and ML.



When I needed to write a program for any file manipulations, I wrote it in Delphi. And with gayom. He wrote windows, buttons. The fields “enter the folder with which you will work”, etc. I did not understand that this could be done as a one-liner on the bash.



For example, I was asked to write a program for converting file names in a folder from Latin to Cyrillic. I wrote a program with a Guy on Delphi. "Enter the folder where you want to convert." The code probably was 100 lines at a minimum, if not a thousand. Now I understand that this is done by a single command in GNU / Linux like this: prename 'y/abc.../.../' *.avi .



I had an idea to write a file manager for Windows (of course, for Windows, other OS I did not know), which would have the possibility of scripting on WL (I did not know the word “scripting”). So that, say, there was a function Flatten from WL, which would make Flatten for folders, that is, it would destroy the entire hierarchy of folders inside this folder and simply dump all the files into a heap.



Then, 6 years ago, I entered the university, met GNU / Linux, started programming in C / C ++ and bash under GNU / Linux. I realized that all my programming in Delphi and WL (except mathematics) is nonsense. That all my programs on Delphi could be implemented by one-liners on bash. And WL should be used only for math problems. I realized that the command interface is not outdated. And I realized that the idea of ​​the file manager is nonsense. Because the whole of GNU / Linux as a whole is such a file manager (and at the same time an IDE) with the possibility of scripting in all scripting languages.



There we started programming, the teacher's name is Bogachev. From him (and from other people) I learned that WL is just a toy, even for math problems. WL should be used when you need to quickly plot a function or find a derivative. For tasks it is more difficult to use it. Because:





In addition to his teaching activities, Bogachev works in one firm as a technical director, and I worked there for him. We did a simulator of oil fields there, I think, it is not necessary to explain that the money is spinning huge in this area. So, the simulator is written in C ++, including the code that performs the calculations (solving diffuros and systems of linear equations). And of course, not on WL, because there is no necessary speed, there is no proper confidence in this WL, and in general WL here would be frivolous to use.



Then I got acquainted with formal mathematics, including the Isabelle system. So, I will tell you that formal mathematics is the only way to carry out mathematical manipulations on a computer so as to be sure of their mathematical correctness. And all these jambs with Simplify, Solve, etc. in formal mathematics are not.



But such systems (i.e. systems for working with formal mathematics) are not like WL. Working with them happens this way: you enter a formal proof into the system, and she tells you whether it is correct or not. The question arises: is it possible to mix the way WL works with the correctness of formal mathematics? Yes you can.



Mathematica, Maple, etc., refer to the so-called computer algebra systems. So, all such systems sin the lack of mathematical rigor. In this regard, there is the idea of ​​writing a truly correct computer algebra system based on formal mathematics. Here, experts in formal mathematics show the results of the first experiments in this direction: www.cs.ru.nl/~freek/pubs/holcas.pdf , please read at least the first two pages.



So, regarding the mathematics on WL: if you need to quickly build a graph, calculate the derivative, etc. - use WL. If you have serious mathematical calculations, write the code yourself in general-purpose languages ​​(like C ++), as Bogachev does, or use professional libraries, again for general-purpose languages. If you need to carry out mathematical manipulations that are not computation, that is, are not numerical, then do your manipulations manually, either using formal mathematics (for example, Isabelle), or using formal computer algebra systems, for example, presented in the article above (although such systems are currently at the initial stage of development).



For non-mathematical tasks, WL cannot be used at all. Use any other language, including scripting. If you like WL, then look at functional languages. In particular, look at Lisp, the WL is most similar to it.



Total. WL is just a toy. This is a student tool, but not a scientist. It is unlikely, for example, data from the Large Hadron Collider is calculated on the WL. WL as 1C: bad, highly specialized, commercial, non-free language.



If something interested in this post (formal mathematics, functional programming, etc.), ask, I will answer.



UPD of July 20, 2015. Why WL is similar to Lisp: habrahabr.ru/post/263015/#comment_8506383 .



UPD of July 22, 2015. A little more about the similarity of WL and Lisp, namely about the principle “program is data”: habrahabr.ru/post/263015/#comment_8506389 .



It is a little about areas where it is possible to apply WL and about heading of this post. I do not like that there are a lot of people who take WL seriously. That is, they perceive it as a tool that can play a major role in scientific research, or, worse, as a general-purpose language. People who are fascinated by the merits of WL (as I did at one time) and do not know that, say, WL is far from the only functional programming language. Which do not know that in general there are scripting programming languages ​​(Perl, Python, Bash) and that there are functional ones from which this WL is ripped off (Lisp, Haskell, ML). So, to open these people eyes, I wrote my post. And to be as convincing as possible, I used a screaming headline (“WL is a toy”). Of course, I understand that WL still has its scope. It is needed to create prototypes in order to quickly find a derivative, etc., in order to carry out some calculations where errors are not critical (for example, when doing homework at the university and writing coursework), to carry out some calculations, which will then be tested in another, more reliable way. My comment on this topic: habrahabr.ru/post/263015/#comment_8506387 .



My comment about numerical and analytical problems: habrahabr.ru/post/263015/#comment_8507849 .



About a bunch of details from my life and Windows vs GNU / Linux. I wrote about GNU / Linux, etc., not because I wanted to say that GNU / Linux is better than Windows, and Gui is better than a text interface. And I did not write about Bogachev in order to promote it. I just wanted to tell a little about my life in order to make my story more convincing so that it would be clear how my ideas changed. And I do not think that GNU / Linux is much superior to Windows in technical terms. And I understand that GUI and CLI are just two different interfaces with their applications.



About free software. Specifically, in the case of WL, its lack of freedom is a significant disadvantage, since it reduces the credibility of the results obtained.



UPD, July 26, 2015. Example with Simplify and other examples. I have a little unfortunate example of that with Simplify. I meant the following: Simplify[(x^2 + x) / x] is x + 1 , and this is wrong, because the case when x is equal to zero is not taken into account. Further, x / x collapses simply to 1, although, again, it does not take into account that x can be equal to zero. Further, a very indicative, in my opinion, example directly from the WL documentation ( reference.wolfram.com/language/ref/Simplify.html ):

 In[5]:= hiddenzero = x^2 + 2 x + 1 - (x + 1)^2; anotherhiddenzero = Sin[x]^2 + Cos[x]^2 - 1; betterhiddenzero = Gamma[x + 1] - x Gamma[x]; In[6]:= {hiddenzero/anotherhiddenzero, anotherhiddenzero/hiddenzero, hiddenzero/betterhiddenzero, betterhiddenzero/hiddenzero} Syntax::sntxf: "hiddenzero/anotherhiddenzero" cannot be followed by ", anotherhiddenzero/hiddenzero, ". Syntax::sntxf: "" cannot be followed by "hiddenzero/anotherhiddenzero, anotherhiddenzero/hiddenzero, ". In[8]:= Map[Simplify, {hiddenzero/anotherhiddenzero, anotherhiddenzero/hiddenzero, hiddenzero/betterhiddenzero, betterhiddenzero/hiddenzero}] 2 2 -1 + Cos[x] + Sin[x] Simplify::infd: Expression ----------------------- simplified to Indeterminate. 2 2 1 + 2 x + x - (1 + x) -(x Gamma[x]) + Gamma[1 + x] Simplify::infd: Expression ---------------------------- simplified to ComplexInfinity. 2 2 1 + 2 x + x - (1 + x) Out[8]= {0, Indeterminate, 0, ComplexInfinity} In[9]:= Map[FullSimplify, {hiddenzero/anotherhiddenzero, anotherhiddenzero/hiddenzero, hiddenzero/betterhiddenzero, betterhiddenzero/hiddenzero}] 2 2 -1 + Cos[x] + Sin[x] FullSimplify::infd: Expression ----------------------- simplified to Indeterminate. 2 2 1 + 2 x + x - (1 + x) -(x Gamma[x]) + Gamma[1 + x] FullSimplify::infd: Expression ---------------------------- simplified to ComplexInfinity. 2 2 1 + 2 x + x - (1 + x) Out[9]= {0, Indeterminate, 0, ComplexInfinity} 


An example was given in the section Possible Issues, in general, I will tell you, this is a great place where you can look for any illogicalities of WL. Next, take an example from the article above (about formal mathematics) and transfer it from Maple to WL, changing it a bit:

 In[11]:= N[Integrate[E^(-(x-1)^2)/Sqrt[x], {x, 0, Infinity}]] Out[11]= 0. + 0.411862 I In[12]:= NIntegrate[E^(-(x-1)^2)/Sqrt[x], {x, 0, Infinity}] Out[12]= 1.97373 


I have a strong suspicion that the answer received by NIntegrate [...] is correct, and N [Integrate [...]] is not. Because NIntegrate performed a simple, blunt algorithm for numerical differentiation. Unlike Integrate, which is an unknown monster of algebraic manipulation without formal rigor, error-prone. Finally, I believe that one of these results is correct only if I independently write a program in C / C ++ that will integrate numerically. Or if I find (or at least check) this integral on a piece of paper. (And yet this integral must obviously be valid.)



And finally, I began to doubt my position, you influenced me, gentlemen commentators. Perhaps (perhaps!), WL is a really high-quality product, suitable for serious scientific and other applications. At the same time, I do not change my opinion to the opposite, finally decide for myself whether a good WL or not, I can only use it well, but I don’t want to do that now.



And still add: if you want to get reliable results on the WL, you need to be able to use it (however, the same applies to any other technology). For example, understand how WL works with all sorts of particular cases like the zero denominator (see the examples in this post above). Further, it is important to understand that WL is a high-level language, that it is possible to work with computer math using low-level languages ​​(like C ++) too. Finally, it is important to know that WL is not the only language that allows writing relatively compressed code, that there are scripting languages ​​(Perl, Python, Bash). And that WL is not the only language that supports functional programming, that Lisp, ML and Haskell exist.



I love Habr, Habr will show you how wrong you are! :)



The examples given were on Mathematica 10.0.2.



UPD of July 26, 2015. As noted correctly here , “almost the entire value of this post is in the comments”. :)



UPD dated July 26, 2015. Bug with Integrate fixed .

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



All Articles