📜 ⬆️ ⬇️

Stephen Wolfram’s Book An Elementary Introduction to the Wolfram Language


Translation of Stephen Wolfram's post " I Wrote a Book — To Teach the Wolfram Language ".
Many thanks to Kirill Guzenko KirillGuzenko for his help in translating and preparing the publication.
The book "An elementary introduction to the Wolfram Language" is available to you in print form , for free on the Internet , as well as in other forms .



I was not sure that I would ever write another book. My last book, A New Type of Science , took me more than ten years of intense, focused work and is my biggest project I've ever done.
')
But some time ago, I realized that I would have to write another book - one that would introduce people who are not familiar with programming, the Wolfram Language, and the ways of thinking in the computing field that this language presents.

The result is the book An elementary introduction to the Wolfram Language , which was published today. It is also freely available on the Internet , and in other forms .



The goal of the book is to lead people from scratch to the point where they will know enough about the Wolfram Language to use it regularly to create programs for all that they want to do. And when I say “zero”, I mean “zero”. This book is for everyone. It does not imply any knowledge of the fields of programming, mathematics (except for the basics of arithmetic) or anything else. She just leads from scratch and explains a variety of things. I tried to make it suitable for both adults and children. I think it will fit perfectly for ordinary children aged about 12 years and older.

In the past, the existence of such a book would have been impossible. The technologies necessary for its implementation did not yet exist. Serious programming has always been hard work, and there were no good ways to connect with real concepts. But now we have the Wolfram Language. Its creation took three decades. But now it contains a sufficient amount of embedded knowledge, and the programming process is automated enough to actually be able to lead anyone from a point with zero knowledge to the limits of the computable.



But how to do that? What needs to be explained in which order? There were problems that led me to write this book. Some time ago I wrote a quick introduction for programmers , which in 30 pages or so introduces people who are already familiar with programming, with the main ideas of Wolfram Language. But what about people who know nothing about programming?

For many years I have found various opportunities to show for such people what the Wolfram Language is now. And so, I used my experience to explain in this book what needs to be done.

This is a dialogue


In essence, this book is a reader’s conversation with a computer. There are two important things about Wolfram Language that make everything work as it should. First, the language is symbolic, so that everything that it has to deal with, be it color , image , graph , or anything, can be represented in the dialog box. And secondly, that a language can be purely functional, so that everything in it is stable, and any input can be a self-contained construction.



It is also very important that the Wolfram Language contains built-in knowledge , which allows you to immediately start making calculations with real things.





Visualization is just as important - so it becomes easy to see what was calculated.



Where to begin?


Ok, so where do you start? The very first page of the book about arithmetic is in fact an area where anyone can see how calculations are performed:



There is a section called Vocabulary, which will help to deal with some " words " Wolfram Language. There are also exercises (Exercises), which I will shortly mention.

Well, we're done with arithmetic, and where do we go next? I decided to go directly to the representations of functions by entering them through arithmetic concepts. The advantage is that although the concept of a function may be new for the reader, but the operations (arithmetic) that they carry out are already familiar.



As soon as the Plus function becomes clear, it will be possible to go straight to functions such as Max , for which no special introduction is required. The Max function does nothing particularly interesting. A more interesting feature that I will introduce next is RandomInteger , which people like to use again and again to see what it gives out.

So what next? The answer is obvious - we must enter the lists. But what to do with the lists? Choosing elements from them does not seem to be particularly exciting, and the understanding that this is important does not come immediately. Thus, instead of it, the first function to work with lists, I decided to introduce ListPlot. It's great to start with visualizations - and this is also a good example of how you can enter only a small piece of code and end up with something more and more interesting.



In fact, the best of the simplest examples is the Range function, which I also demonstrated here. Range is a great way to show that a computer is actually calculating something, while producing a result that is easy to understand.

Well, well, now we need to fix the idea of ​​the functions and their joint work. The Reverse function is not very popular in practical use, but it is very easy to understand; Next, we introduce the Join function.



We are pleased with the fact that with Reverse , Range and Join we have some micro-language of our own, which is completely self-sufficient and allows us to do various calculations. And, of course, conducting any calculations, you can immediately see the results in symbolic or graphical form.



The next pair of sections is about visualization and working with lists that reinforce what was said earlier and introduce various functions useful in practice. This is followed by Table - a very powerful and common function that contains loops and other useful things.

I start with simple versions of Table without any iterators. I take for granted that Table can represent a list of graphic elements as well as a list of numbers (of course, the fact that he can do this is a consequence of the fundamentally symbolic nature of the Wolfram Language).



The next big step is to enter a variable in the Table . I thought a lot about how to do this, and decided that it was best to first show it in a purely symbolic version. In the end, we have already introduced functions, and in the symbol version you can immediately see where the variable comes from. But now that we have entered the Table with variables, we can break loose and start doing what some might call “real calculations.”



Gates leading to the book


In the first few sections of the book, the material for our calculations was mainly numbers and lists. Next, I would like to show that there are other things that can be used in calculations. As in the first example, I chose colors . Colors are a good choice, because (a) everyone knows about their existence, (b) you can carry out calculations on them (c) with their help you can get a colorful result (!).



After the colors we are ready to go to the graphic objects . I did not introduce the concept of coordinates, because I can only show individual graphic objects without information about their position.



And there is absolutely no reason not to touch the three-dimensional figures, and then we touch them.



Now we are ready for something “advanced”: interactive manipulation . In terms of syntax, there is a lot of similarity with Table , with the exception that here we get a full-fledged interactive user interface. And since we entered the graphics, it can be part of the interface. People have seen interactive interfaces in a large number of different programs. My experience is that they will be very impressed with the opportunity to create them from scratch on their own.



The next thing I present in this book, and perhaps it will be somewhat surprising is image processing. Yes, behind image processing lies a large number of complex calculations. But in the Wolfram Language everything is hidden inside. And people just see features like Blur , ColorNegate — and their purpose is easy to understand.

Also pleased with the fact that people, and especially children, can perform calculations with images, simply by dragging them where necessary. And in fact, this is the first example in the book, when a large amount of data enters the program from the outside (I needed a sample image for the section, so I just took myself working on the book on a webcam).



Then I talked about lines and text . String operations are quite boring. But there are many interesting things in the Wolfram Language that can be done with them, whether it be a word cloud visualization from an article on Wikipedia or a search for popular words in different languages.



Then I talked about sound and how you can create sequences from musical notes. Of course, in the printed book you will not be able to hear them, although the small icons give some idea of ​​what we are dealing with.



One may ask: “Why not touch the sound right after the graphics?” Well, first of all, I thought it would be nice to mix some things a little to maintain interest. However, there is a certain chain of dependencies between different areas. For example, the names of musical notes are specified as strings, so we must first mention the strings.

Next are arrays, or lists of lists . Then - coordinates and graphs . Firstly, I was worried that the coordinates are something too “mathematical”. But especially after we looked at arrays, the coordinates no longer seem like a very complicated concept. And since we considered the idea of ​​two-dimensional coordinates, it is not difficult to move to three-dimensional.



At this point in the book, people already know how to do some really useful things with the help of the Wolfram Language. So in the next section, I brought some interlude - a kind of meta-section, giving an idea of ​​the volume of the Wolfram Language, and also showing how to find information on specific topics and functions.



Now that we have presented some abstract calculations, it's time to talk about real data and also show how to access the huge amount of data that Wolfram Language presents with Wolfram | Alpha.



Many real data include units, so the next section is about working with units . After we are done with this, we can touch the geocomputation section (calculations associated with geography) - search for distances between points on the Earth, for example, or drawing maps.



After that we'll talk about dates and times . One would think that this is not a particularly interesting and useful topic. But this is actually a very good example of real-world computing, which occurs everywhere.



Wolfram Language is a very voluminous language. But it is based on a small number of ideas that are constantly used again and again. One of the most important tasks of the book is to embrace these ideas. And in the next section - on options - covers one simple idea that constantly arises in practice.



After the options, we are ready to talk about something that is often viewed as a complex topic: graphs and networks . But my experience shows that in our time, people face a fairly large number of graphs and networks in their daily lives, so that they will not have big problems with understanding them in the Wolfram Language. Of course, it helps a little that the language allows you to manipulate them directly. , which is another example of character objects.



After graphs and networks, we are ready to begin a seemingly very complex topic: machine learning . But even if the internal machine learning algorithms are complex, the functions themselves that implement it in the Wolfram Language are absolutely easy to understand. And the great thing is that by feeling a large number of examples with them, you can get a very good intuitive idea of ​​the key ideas of machine learning.



Throughout the book, I try to present things in the simplest possible way. But sometimes this leads to the need to consider in more detail the topic already covered. “Details about numbers” and “Other visualizations” are two examples illustrating this fact, which tell about already passed concepts, but for a more complete understanding of these areas we need to return to them at a new level.

Functional programming


The next few sections cover the important and incredibly powerful topic of functional programming . Previously, functional programming, as a rule, was considered as something complicated and not at all what people who only started to master programming should learn. However, I think that Wolfram Language has changed the situation, and now there is an opportunity to explain functional programming in a much more understandable language. I decided to start with an abstract talk about the process of applying the function.



First of all, I would like to talk about pure anonymous functions . In principle, I could have talked about them much earlier, but I think that before this, it is important to show people how functions are generally used, citing examples from various fields, in order to motivate them to use pure functions.



In the next section, you can already notice some manifestations of the real power of functional programming. In general, functions such as NestList and NestGraph may seem rather complicated and abstract. But at this point in the book, we looked at a sufficient number of Wolfram Language constructs, so we have a lot of concrete examples with the help of which everything can be easily explained.



The next few sections cover the areas of the language that open when an understanding of pure functions comes. There are many powerful programming techniques that arise from fewer ideas.



After functional programming, the next big topic is templates and template-oriented programming. I could have talked about them earlier, but so far there has been no need for them.



There is something fundamental that makes patterns so powerful in Wolfram Language: a single structure for anything in a language, based on symbolic expressions. If I wrote the Wolfram Language specification, I would start with symbolic expressions. And I probably would have done the same if I had written a book for specialists in theoretical computer science or pure mathematics.

Not that symbolic expressions are difficult to understand. Just not seeing how the Wolfram Language actually works in practice, it is difficult to motivate yourself to study its theoretical foundations. But now it makes sense to talk about them, and not least because they allow you to see in all its glory work with templates.

Whole stack


At this point in the book, we are ready to consider how to deploy, say, a web application. But before that you need to consider something else. I will talk about associations , and then about natural language recognition . Inside, the language recognition system is a very complicated thing. However, at the Wolfram Language level, recognition is easy to use, but to see how it relates to other things, you need to talk about pure functions.



Well, now everything is ready to talk about deployment on the Internet . And at this moment people have the opportunity to create useful application software constructs that they can share with the world.



All this took 220 pages or so. But for me this is an amazingly small number of pages, allowing you to move from scratch to, in fact, the professional field of web application development. If we talked only about some very specific kind of applications, it would not be so impressive. But we are talking about applications of a very general form, which can make calculations of almost any kind.



Assigning Values ​​to Variables


If you open a book about a traditional programming language, like, say, C ++ or Java, then one of the first topics you'll encounter will be the assignment of values ​​to variables. But in my book I cite this topic only in the 38th section . In a sense, this may seem strange, but in reality it is not. After all, in the Wolfram Language you can do an amazing amount, including, for example, deploying a full-fledged web application without ever assigning values ​​to variables.

And, in fact, this is one of the reasons why the Wolfram Language is so easy to learn. After all, if you do not assign values ​​to variables, then each piece of code will be independent and always demonstrate the same behavior. But as soon as you start assigning values ​​to variables, hidden states appear, and your code will do different things depending on the current values ​​of the variables.

Nevertheless, when we talked about the assignment of values ​​to variables and templates, we are ready to move on to defining our own functions , which will allow us to introduce more and more complex functionality in the Wolfram Language.



At this point, the reader is fully aware of the terms and basic concepts of the Wolfram Language. But the last few sections of the book tell about some important applied points. There is a section on string patterns and replacements . Next, the section on storing data and code locally and in the cloud. Then the section on import and export . Then the section on collections (sets) of data . Not everyone who uses Wolfram Language will ever need data collections (sets), but if you have to deal with large volumes of structured data, this section will be very useful for you. And all of them are interesting examples of how different ideas are implemented in the Wolfram Language.

Sections from the essay


At the end of the book there are sections with essays on various topics: about writing good code, debugging , and what it is like to be a programmer . The purpose of these sections is to develop the ways of thinking that, I hope, originated from reading this book, and then add to some abstract ideas.



Presentation structuring


As I said at the beginning, the book is essentially written in a conversational style. In almost every section, I added two additional parts - questions and answers and technical details . The purpose of the part with questions and answers is to give answers to those questions that people most often encounter, without being distracted from the main story line.



There are several different types of questions. Some are about previously discussed extensions to functionality. Some - about what is behind all this. And some questions (“What does exponentiation mean?”) May seem too simple for some readers, but not for everyone.

In addition to the question and answer part, it seemed reasonable to include a part with technical details. Their goal is to provide some technical information to those people who are already well-versed in a particular area so that they can match their knowledge with the materials of the book.

Exercises


The other part presented in most sections is a collection of exercises. The vast majority of them are represented in the format " write a piece of code that makes N ", and a few - " find a simpler equivalent of this piece of code ."



At the end of the printed book contains answers to all the exercises, and in the web version there are additional exercises. Of course, the answers presented there are only one of the possible, and there is almost never a situation when this is the only correct answer.



Writing exercises was an interesting experience for me, which, in fact, is very important in the context of my reflections on how, say, to communicate with artificial intelligence . After all, most of the exercises essentially tell us: " Take this text in English and turn it into a code on the Wolfram Language ." For something simple, English quite copes well with the description. But the more difficult the task, the harder it is to explain them in English. In general, when writing a book, I often came across a situation where it was much easier to give an answer to the exercise on the Wolfram Language than to write it in English.

In a sense, this is very good, because it means that the Wolfram Language is very well suited for expressing ideas. Some things that are easily expressed in English can be passed on to Wolfram | Alpha for interpretation. But there are many things that need a great deal of structure and accuracy that the Wolfram Language has.

Book?


In a sense, it may seem strange to write a book that can be printed out, instead of creating something with a much more flexible structure and in a web format. But for myself, I found out that the concept of a book can be quite useful. Yes, you can have a website from which we can, following the links, get a lot of information. - , , , , .

, - . - , - . , , - — — .

, Wolfram Language, . , , ( ), , .. , . , : , Wolfram Language .


« ». . Wolfram Language — . , , , , . , .

, , , , . , ; , .

, , , Wolfram Language, . , , .



A bit of background


Wolfram Language. 1988 , Mathematica, . : , . 767 . 10 , «» 1488 . , — , .



, , , , . , , , 50 000 .

, Mathematica , , , , . , Wolfram Language , , .

, , Wolfram Language ( Mathematica) . , , , . , , Wolfram Language Mathematica , .

?


, - , . , , , Wolfram Language , , . , . , , , . .

: " ? ". , , , , , . . .

I enjoyed writing the book. I hope people will be interested in reading it , and what they will learn from it, how to create amazing things together with the Wolfram Language!

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


All Articles