Wolfram Research launched the Tweet-a-Program service: interesting Wolfram Language programs that are no longer than 140 characters

Original author: Stephen Wolfram
  • Transfer

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

This service combines Wolfram Language programs with a length of one twitter message and the ability to automatically send them to @WolframTaP . Our Twitter bot will launch your program on the Wolfram Cloud , and then publish the result. Everyone can do it in Wolfram Language, which will be no longer than one tweet. Say, below you see a program with a length of 78 characters, which makes it fill the cube with colored spheres: You can easily make interesting ornaments:

Hello World from Tweet-a-Program: GeoGraphics [Text [Style ["Hello!", 150]], GeoRange -> "World"]

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

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

Below you see a program with a length of 44 characters that looks like a small calculated poem: You can make the program even shorter, say this program with a length of 36 characters makes it look like a fractal: By adding a little math you can get complex three-dimensional structures: You do not have to make pictures. Below, let's say you see the first 1000 characters of the number π, the size of which is selected depending on the size of their module (see how the nines run one after another!): Wolfram Language knows not only how to calculate the number π, but also a huge many other algorithms . A huge amount of knowledge about the real world is also built into it . So, directly in the language, you can ask about films

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

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

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}]]]]

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

, countries , chemicals and much more. Below you can see a 78-character program that creates a collage of European flags, and the size of the flag depends on the country's population: We can make this program even shorter if we use some form of writing in natural language directly inside the program. In the regular interface of Wolfram documents that you know from Mathematica, you can do this using the keyboard shortcut , but in the Tweet-a-Program you can do this simply using the construction of the form = [...]: Wolfram Language knows about geography

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

CTRL + =

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

. Below is a program that displays circles of different radii (a sequence of degrees 10) in meters, with the center of each disk being the Eiffel Tower. There are many kinds of real-world knowledge built into Wolfram Language that may surprise you. Say, below is a map of a shipwreck in the Atlantic Ocean: 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 their R, G and B channels, giving the output quite exotic pictures. Below you see my image, to which the algorithm for searching for borders on the image has been applied several times:

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}]

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

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

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 by applying all kinds of processing and analysis algorithms to them). Below you see a table of posters of randomly selected films: Wolfram Language is also very good at working 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: Here is the program, exactly the same size as a tweet, which calculates the smoothed histogram of the frequency distribution of the words “Alice” and “Queen” in the original text Alice in Wonderland : Graphs and Networks

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

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

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

also good to use for Tweet-a-Program. Here is a program that creates a sequence of graphs: And here - and again the length of the program does not exceed the limit of characters in the Twitter message - a program that creates a cloud of random polyhedra: What is the shortest "interesting program" in Wolfram Language? In some languages, it may be Quine, a program that outputs its own code. But in Wolfram Language, a quine looks very trivial. Since all expressions are represented in symbolic form, in order to create a quine, just enter any character:

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

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


Using the knowledge built into the Wolfram Language, you can create very short programs that do something interesting. Like this 15-character program that creates an image of a fragment of an embedded database on nodes of node theory : Some short programs are very easy to understand: It's funny to create “cryptic” programs. Say what does this one do? Or this one ? Or, a little more complicated , such as this: I actually spent many years of my life studying short programs and what they do and I created a whole science about the universe of computing , which is described in my book A New Kind of Science

KnotData [{8,4}]

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

NestList [# ^ # &, x, 5]

FixedPointList [# /. {S [x _] [y _] [z _] -> x [z] [y [z]], k [x _] [y _] -> x} &, s [s [s]] [ s] [s] [s] [k], 10] // Column

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

. Все это началось более трёх десятилетий назад с компьютерного эксперимента, который я могу сделать с помощью всего лишь одного твита:

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

Мое самое любимое открытие также можно опубликовать в одном твите:

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

Если вы начнете изучать вселенную вычислений, вы сможете с легкостью обнаружить в ней множество потрясающих вещей:

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

Встает основной вопрос — существует ли где-то глубоко во вселенной вычислений программа, которая отображает всю нашу физическую вселенную. И является ли эта программа достаточно короткой, чтобы записать ее в одном твите на языке Wolfram Language?

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

In the past, only ordinary human languages ​​were rich enough to transmit meaningful information via Twitter. But what is striking today is that the Wolfram Language seems to have crossed a sort of threshold of “expressiveness," and this allows it to easily create interesting and complex things, even with the limitations of Twitter. Like ordinary human languages, it can talk about all kinds of things and express all kinds of ideas. But there is also something else in it: unlike ordinary human languages, everything in it has a precisely defined meaning, and what we write is not only readable, but also calculated.

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

It is interesting to compare Wolfram Language with ordinary human languages. A common language, such as English, has several tens of thousands of fairly common built-in words, excluding proper names, etc. The Wolfram Language language has about 5,000 named built-in objects , excluding Entity-based constructions (database access keys) that can be considered as 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. It contains a dictionary that you need to remember, as well as several principles that you need to remember - while a person needs only a little time to study them and begin to understand typical programs in the Wolfram Language language.

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

As in ordinary languages, Wolfram Language has a kind of art of expressing and writing down thoughts. It has reading and reading comprehension. It has the writing and writing of sentences. You can always say something in it in different ways, but at the same time say absolutely for sure, 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 meaning and its external realization. And you might also think of something like “code poetry” in that language.

When I first came across Tweet-a-Program, it seemed to me something commonplace. But what I saw and understood was that it 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 look forward to seeing what you can do in this service. What kinds of things will be created? What types of shortcodes 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 awarded? 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 the Wolfram Programming Cloud ( Wolfram Programming Cloud ), or use any other Wolfram-based systemsboth for the desktop and the Cloud. You can learn more about Tweet-a-Program here .

Also popular now: