📜 ⬆️ ⬇️

Wolfram Research has launched the Tweet-a-Program service: interesting programs in Wolfram Language, the length of which does not exceed 140 characters



In the Wolfram Language language, small code can do a lot. Using this, we made a service that will allow you to get pleasure from it, today we open it - Tweet-a-Program .

This service combines programs in the Wolfram Language with a length of one twitter message and the possibility of their automatic sending to @WolframTaP . Our Twitter-bot will launch your program in the Wolfram Cloud (Wolfram Cloud), and then publish the result.
')
Hello World from Tweet-a-Program: GeoGraphics[Text[Style["Hello!",150]],GeoRange->"World"]

Anyone can make a Wolfram Language that is no longer than a single tweet. Let's say below you see a 78-character program that makes the cube fill with colored spheres:

Graphics3D[Table[{RGBColor[{i,j,k}/5],Sphere[{i,j,k},1/2]},{i,5},{j,5},{k,5}]]

You can easily make interesting ornaments:

Graphics[Riffle[NestList[Scale[Rotate[#,.1],.9]&,Rectangle[],40],{Black,White}]]

Below you see a program with a length of 44 characters, which looks like a small, calculated poem:

Graphics3D@Point@Tuples@Table[Range[20],{3}]

You can make the program even shorter, say this program with a length of 36 characters makes a similar to a fractal:

NestList[Subsuperscript[#,#,#]&,o,6]

By adding a bit of math you can get complex three-dimensional structures:

ContourPlot3D[Cos[{x,y,z}/Norm[{x,y,z}]^2]==0,{x,-0.5,0},{y,0,0.5},{z,-0.5,0}]

ReliefPlot[Arg[Fourier[Table[1/LCM[i,j],{i,512},{j,512}]]]]

You do not need to make pictures. Below, say, you see the first 1000 characters of the number π, the size of which is chosen depending on the size of their module (see how the nine follow each other!):

Row[Style[#,5#+1]& / @ First[RealDigits[Pi,10,1000]]]

The Wolfram Language knows not only how to calculate the number π, but also a great many other algorithms . It also has a huge amount of knowledge about the real world. So, directly in the language, you can ask about movies , countries , chemicals and many other things. Below you can see a program of 78 characters, which creates a collage of flags of Europe, while the size of the flag depends on the population of the country:

ImageCollage[CountryData["Europe","Population"]->CountryData["Europe","Flag"]]

We can make this program even shorter if we use some form of recording in natural language directly inside the program. In the usual Wolfram document interface, known to you by Mathematica, you can do this using the keyboard shortcut CTRL + = , but in Tweet-a-Program you can do it simply using the construction of the form = [...]:

ImageCollage[=[Europe populations]->=[Europe flags]]
ImageCollage[=[Europe populations]->=[Europe flags]]


Wolfram Language also knows about geography . Below is a program that displays circles of different radius (a sequence of degrees 10) in meters, with the center of each disc falling on the Eiffel Tower.

Table[GeoGraphics[GeoDisk[=[Eiffel Tower],Quantity[10^(n+1),"Meters"]],GeoProjection->"Bonne"],{n,6}]
Table[GeoGraphics[GeoDisk[=[Eiffel Tower],Quantity[10^(n+1),"Meters"]],GeoProjection->"Bonne"],{n,6}]


There are many types of real-world knowledge embedded in the Wolfram Language that may come as a surprise. Let's say the map below shows a wreck in the Atlantic Ocean:

GeoListPlot[GeoEntities[=[Atlantic Ocean],"Shipwreck"]]
GeoListPlot[GeoEntities[=[Atlantic Ocean],"Shipwreck"]]


Wolfram Language can also work with images. Below you see a program that takes images of the planets of the solar system , and then mixes them into the R, G, and B channels, giving you pretty exotic output.

ColorCombine[RandomSample[ColorSeparate[#]]]&/@EntityValue[=[planets],"Image"]
ColorCombine[RandomSample[ColorSeparate[#]]]&/@EntityValue[=[planets],"Image"]

Below you see my image, to which the border search algorithm on the image was applied several times:

NestList[EdgeDetect,=[Stephen Wolfram image],5]
NestList[EdgeDetect,=[Stephen Wolfram image],5]


Or, you can do something more related to “pop culture” (you can also use these images, applying various processing and analysis algorithms to them). Below you can see a table of posters of randomly selected films:

Grid[Partition[DeleteMissing[EntityValue[RandomSample[MovieData[],50],"Image"]],6]]

The Wolfram Language can also work very well with words and texts . Let's say the program below generates an “infographic” showing the relative frequencies of the first letters in the words of the English and Spanish languages:

Row[Style[#,#2/70]& @ @ @ Tally[ToUpperCase[StringTake[DictionaryLookup[{#,All}],1]]]]&/ @ {"English","Spanish"}

Here is a program exactly equal in size to a tweet that calculates a smoothed histogram of the frequency distribution of the words “Alice” and “Queen” in Alice's original text in Wonderland :

SmoothHistogram[Legended[First/ @ StringPosition[ExampleData @ {"Text","AliceInWonderland"},#],#]&/ @ {"Alice","Queen"},Filling->Axis]

Graphs and networks are also good to use for Tweet-a-Program. Here is a program that creates a sequence of graphs:

Table[Graph[Table[i->Mod[i^2,n],{i,n}]],{n,105,110}]

And here - and again the program length does not exceed the limit of characters in the Twitter message - a program that creates a cloud of random polyhedra:

Graphics3D[Table[{RandomColor[],Translate[PolyhedronData[RandomChoice[PolyhedronData[]]][[1]],RandomReal[20,3]]},{100}]]

What is the shortest “interesting program” in the Wolfram Language?

In some languages, this may be quine, a program that displays its own code. But in the Wolfram Language language, quine looks very trivial. Since all expressions are represented in symbolic form, in order to create a quine, simply enter any character:

x

By applying the built-in knowledge of the Wolfram Language language, you can create very short programs that do something interesting. As this program of 15 characters, which creates an image of a fragment of the embedded database on the nodes of the theory of nodes :

KnotData[{8,4}]

Some short programs are very easy to understand:

Grid[Array[Times,{12,12}]]

It's funny to create "mysterious" programs. Say what does this one do?

NestList[#^#&,x,5]

Or this one ?

FixedPointList[#/.{s[x_][y_][z_]->x[z][y[z]],k[x_][y_]->x}&,s[s[s]][s][s][s][k],10]//Column

Or, somewhat more complicated , such as this:

Style[\[FilledCircle],5#]&/@(If[#1>2,2#0[#1-#0[#1-2]],1]&/ @ Range[50])

I actually spent many years of my life studying short programs and what they do and I created the whole science of the universe of computation , which is described in my book A New Kind of Science . It all started over three decades ago with a computer experiment that I can do with just one tweet:

GraphicsGrid[Partition[Table[ArrayPlot[CellularAutomaton[n,{{1},0},{40,All}]],{n,0,255}],16]]

My favorite discovery can also be posted in one tweet:

ArrayPlot[CellularAutomaton[30,{{1},0},100]]

If you start exploring the universe of computation, you can easily find a lot of amazing things in it:

ArrayPlot[CellularAutomaton[{1635,{3,1}},{{1},0},500],ColorFunction->(Hue[#/3]&)]

The main question is whether there is a program somewhere deep in the computing universe that displays our entire physical universe. And is this program short enough to be recorded in a single tweet in the Wolfram Language?

But regardless of this, we already know that the Wolfram Language allows us to write amazing programs that are no longer than one tweet about an incredible amount of things. It took more than a quarter of a century to build a huge "building" of knowledge and automation, which now exist in the Wolfram Language. But it is precisely this wealth of language that made it possible to do so much even in the “world of twitter”.

In the past, only ordinary human languages ​​were rich enough to transmit meaningful information through the same Twitter. But what strikes today is that the Wolfram Language has apparently stepped over a sort of “expressiveness” threshold, and this allows it to so easily create interesting and complex things, even with the limitations of Twitter. Like ordinary human languages, it is possible to talk about all sorts of things and express all sorts of ideas. But it also has something else: in contrast to ordinary human languages, everything in it has a precisely defined meaning, and what we write is not only readable, but also computable.

Tweets in ordinary human language have (presumably) some effect on the mind of someone who reads them. But the result may be different depending on mental abilities, and it is usually difficult to know exactly what the effect is. But tweets in the Wolfram Language have a well defined effect that you see when you launch a program.

It is interesting to compare the Wolfram Language with ordinary human languages. Regular language, such as English, has several tens of thousands of fairly common embedded words, excluding proper names, etc. Wolfram Language has about 5000 named embedded objects , excluding constructions based on Entity (access keys to databases) that can be considered like proper names.

One important thing about the Wolfram Language - and which it shares with ordinary human languages ​​- is that it is not only written by people, but also read by them. There is a dictionary in it that needs to be remembered, as well as a few principles that need to be remembered - at that, a person will need only a little time to study them and begin to understand typical Wolfram Language programs.

Sometimes it is quite easy to give at least a rough translation (or “explanation”) of the Wolfram Language program into an ordinary human language. But very often it turns out that a program in the Wolfram Language expresses something that is rather difficult to talk about — at least briefly — in ordinary human language. And this inevitably means that there are things that are easier to think about in the Wolfram Language, but difficult in the ordinary language.

As in ordinary languages, in the language of the Wolfram Language there is something like the art of expressing one's thoughts and recording them. It has reading and reading comprehension. It has writing and writing sentences. It is always possible to say something in it in different ways, but at the same time it is absolutely accurate to say, and there is also a measure of the optimality of your sentences - the speed of their calculation.

As in ordinary human language, there is a concept of elegance. You can think of both the meaning and its external realization. And you can also think of something like “code poetry” in this language.

When I first encountered Tweet-a-Program, it seemed to me something trivial. But what I saw and understood is that this is actually a window into the world of a new kind of expression and a new form of interaction between people and computers.

Of course, this service is intended for entertainment. It really gives me great pleasure to create short, concise programs that create something amazing.

And now I'm looking forward to see what you can do in this service. What kinds of things will be created? What types of short codes will become popular? Who will be inspired by these short programs? What tasks will be proposed and solved? What competitions will be open and what prizes will be raffled? And what great "actors" and "poets" will appear in this world of code?

Now we have programs that fit in just one tweet, let's see what they can do ...

In order to develop and test programs for Tweet-a-Program , you can create a free account in Wolfram Programming Cloud ( Wolfram Programming Cloud ), or use any other systems working in the Wolfram language for both the desktop and the Cloud. You can learn more about Tweet-a-Program here .

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


All Articles