Final 12 months we launched Model 13.0 of the Wolfram Language. Listed here are the updates in listability since then, together with the newest options in 13.1.
Past Listability: Introducing Threaded
From the very starting of Mathematica and the Wolfram Language we’ve had the idea of listability: if you happen to add two lists, for instance, their corresponding components will likely be added:
![]() |
It’s a really handy mechanism, that sometimes does precisely what you’d need. And for 35 years we haven’t actually thought-about extending it. But when we have a look at code that will get written, it typically occurs that there are elements that mainly implement one thing very very like listability, however barely extra common. And in Model 13.1 we’ve a brand new symbolic assemble, Threaded, that successfully permits you to simply generalize listability.
Take into account:
![]() |
This makes use of strange listability, successfully computing:
![]() |
However what in order for you as an alternative to “go down a stage” and thread {x,y} into the bottom elements of the primary listing? Effectively, now you should use Threaded to try this:
![]() |
By itself, Threaded is only a symbolic wrapper:
![]() |
However as quickly because it seems in a perform—like Plus—that has attribute Listable, it specifies that the listability ought to be utilized after what’s specified inside Threaded is “threaded” on the lowest stage.
Right here’s one other instance. Create a listing:
![]() |
How ought to we then multiply every ingredient by {1,–1}? We may do that with:
![]() |
However now we’ve acquired Threaded, and so as an alternative we are able to simply say:
![]() |
You may give Threaded as an argument to any listable perform, not simply Plus and Instances:
![]() |
You need to use Threaded and strange listability collectively:
![]() |
You possibly can have a number of Threadeds collectively as nicely:
![]() |
Threaded, by the best way, will get its title from the perform Thread, which explicitly does “threading”, as in:
![]() |
By default, Threaded will all the time thread into the bottom stage of a listing:
![]() |
![]() |
Right here’s a “real-life” instance of utilizing Threaded like this. The information in a 3D colour picture consists of a rank-3 array of triples of RGB values:
![]() |
This multiplies each RGB triple by {0,1,2}:
![]() |
More often than not you both need to use strange listability that operates on the prime stage of a listing, otherwise you need to use the default type of Threaded, that operates on the lowest stage of a listing. However Threaded has a extra common type, in which you’ll be able to explicitly say what stage you need it to function at.
Right here’s the default case:
![]() |
Right here’s stage 1, which is rather like strange listability:
![]() |
And right here’s threading into stage 2:
![]() |
Threaded gives a really handy method to do all types of array-combining operations. There’s extra complexity when the article being “threaded in” itself has a number of ranges. The default on this case is to align the bottom stage within the factor being threaded in with the bottom stage of the factor into which it’s being threaded:
![]() |
Right here now could be “strange listability” conduct:
![]() |
For the arrays we’re right here, the default conduct is equal to:
![]() |
Generally it’s clearer to write down this out in a type like
![]() |
which says that the primary stage of the array contained in the Threaded is to be aligned with the second stage of the surface array. Usually, the default case is equal to –1 → –1, specifying that the underside stage of the array contained in the Threaded ought to be aligned with the underside stage of the array outdoors.