View All Release Announcements »

Launching Version 12.2 of Wolfram Language & Mathematica: 228 New Functions and Much More…

Yet Bigger than Ever Before

When we released Version 12.1 in March of this year, I was pleased to be able to say that with its 182 new functions it was the biggest .1 release we’d ever had. But just nine months later, we’ve got an even bigger .1 release! Version 12.2, launching today, has 228 completely new functions!

Launching Version 12.2 of Wolfram Language & Mathematica: 228 New Functions and Much More...

We always have a portfolio of development projects going on, with any given project taking anywhere from a few months to more than a decade to complete. And of course it’s a tribute to our whole Wolfram Language technology stack that we’re able to develop so much, so quickly. But Version 12.2 is perhaps all the more impressive for the fact that we didn’t concentrate on its final development until mid-June of this year. Because between March and June we were concentrating on 12.1.1, which was a “polishing release”. No new features, but more than a thousand outstanding bugs fixed:


More than a thousand bugs fixed in 12.2—click to enlarge

How did we design all those new functions and new features that are now in 12.2? It’s a lot of work! And it’s what I personally spend a lot of my time on (along with other “small items” like physics, etc.). But for the past couple of years we’ve done our language design in a very open way—livestreaming our internal design discussions, and getting all sorts of great feedback in real time. So far we’ve recorded about 550 hours—of which Version 12.2 occupied at least 150 hours.

Live CEOing

By the way, in addition to all of the fully integrated new functionality in 12.2, there’s also been significant activity in the Wolfram Function Repository—and even since 12.1 was released 534 new, curated functions for all sorts of specialized purposes have been added there.

Biomolecular Sequences: Symbolic DNA, Proteins, etc.

There are so many different things in so many areas in Version 12.2 that it’s hard to know where to start. But let’s talk about a completely new area: bio-sequence computation. Yes, we’ve had gene and protein data in the Wolfram Language for more than a decade. But what’s new in 12.2 is the beginning of the ability to do flexible, general computation with bio sequences. And to do it in a way that fits in with all the chemical computation capabilities we’ve been adding to the Wolfram Language over the past few years.

Here’s how we represent a DNA sequence (and, yes, this works with very long sequences too):

BioSequence
&#10005

BioSequence["DNA", "CTTTTCGAGATCTCGGCGTCA"]

This translates the sequence to a peptide (like a “symbolic ribosome”):

BioSequenceTranslate
&#10005

BioSequenceTranslate[%]

Now we can find out what the corresponding molecule is:

Molecule
&#10005

Molecule[%]

And visualize it in 3D (or compute lots of properties):

MoleculePlot3D
&#10005

MoleculePlot3D[%]

I have to say that I agonized a bit about the “non-universality” of putting the specifics of “our” biology into our core language… but it definitely swayed my thinking that, of course, all our users are (for now) definitively eukaryotes. Needless to say, though, we’re set up to deal with other branches of life too:

Entity
&#10005

Entity["GeneticTranslationTable", 
  "AscidianMitochondrial"]["StartCodons"]

You might think that handling genome sequences is “just string manipulation”—and indeed our string functions are now set up to work with bio sequences:

StringReverse
&#10005

StringReverse[BioSequence["DNA", "CTTTTCGAGATCTCGGCGTCA"]]

But there’s also a lot of biology-specific additional functionality. Like this finds a complementary base-pair sequence:

BioSequenceComplement
&#10005

BioSequenceComplement[BioSequence["DNA", "CTTTTCGAGATCTCGGCGTCA"]]

Actual, experimental sequences often have base pairs that are somehow uncertain—and there are standard conventions for representing this (e.g. “S” means C or G; “N” means any base). And now our string patterns also understand things like this for bio sequences:

StringMatchQ
&#10005

StringMatchQ[BioSequence["DNA", "CTTT"], "STTT"]

And there are new functions like BioSequenceInstances for resolving degenerate characters:

BioSequenceInstances
&#10005

BioSequenceInstances[BioSequence["DNA", "STTT"]]

BioSequence is also completely integrated with our built-in genome and protein data. Here’s a gene that we can ask for in natural language “Wolfram|Alpha style”:

BioSequence
&#10005

BioSequence[CloudGet["https://wolfr.am/ROWvGTNr"]]

Now we ask to do sequence alignment between these two genes (in this case, both human—which is, needless to say, the default):

BioSequence
&#10005


What’s in 12.2 is really just the beginning of what we’re planning for bio-sequence computation. But already you can do very flexible things with large datasets. And, for example, it’s now straightforward for me to read my genome in from FASTA files and start exploring it…

BioSequence
&#10005

BioSequence["DNA", 
 First[Import["Genome/Consensus/c1.fa.consensus.fa"]]]

 

Spatial Statistics & Modeling

Locations of birds’ nests, gold deposits, houses for sale, defects in a material, galaxies…. These are all examples of spatial point datasets. And in Version 12.2 we now have a broad collection of functions for handling such datasets.

Here’s the “spatial point data” for the locations of US state capitals:

SpatialPointData
&#10005

SpatialPointData[
 GeoPosition[EntityClass["City", "UnitedStatesCapitals"]]]

Since it’s geo data, it’s plotted on a map:

PointValuePlot
&#10005

PointValuePlot[%]

Let’s restrict our domain to the contiguous US:

capitals = SpatialPointData
&#10005

capitals = 
  SpatialPointData[
   GeoPosition[EntityClass["City", "UnitedStatesCapitals"]], 
   Entity["Country", "UnitedStates"]];

PointValuePlot
&#10005

PointValuePlot[%]

Now we can start computing spatial statistics. Like here’s the mean density of state capitals:

MeanPointDensity
&#10005

MeanPointDensity[capitals]

Assume you’re in a state capital. Here’s the probability to find the nearest other state capital a certain distance away:

NearestNeighborG
&#10005

NearestNeighborG[capitals]

Plot
&#10005

Plot[%[Quantity[r, "Miles"]], {r, 0, 400}]

This tests whether the state capitals are randomly distributed; needless to say, they’re not:

SpatialRandomnessTest
&#10005

SpatialRandomnessTest[capitals]

In addition to computing statistics from spatial data, Version 12.2 can also generate spatial data according to a wide range of models. Here’s a model that picks “center points” at random, then has other points clustered around them:

PointValuePlot
&#10005

PointValuePlot[
 RandomPointConfiguration[MaternPointProcess[.0001, 1, .1, 2], 
  CloudGet["https://wolfr.am/ROWwlIqR"]]]

You can also go the other way around, and fit a spatial model to data:

EstimatedPointProcess
&#10005

EstimatedPointProcess[capitals, 
 MaternPointProcess[\[Mu], \[Lambda], r, 2], {\[Mu], \[Lambda], r}]

 

Convenient Real-World PDEs

In some ways we’ve been working towards it for 30 years. We first introduced NDSolve back in Version 2.0, and we’ve been steadily enhancing it ever since. But our long-term goal has always been convenient handling of real-world PDEs of the kind that appear throughout high-end engineering. And in Version 12.2 we’ve finally got all the pieces of underlying algorithmic technology to be able to create a truly streamlined PDE-solving experience.

OK, so how do you specify a PDE? In the past, it was always done explicitly in terms of particular derivatives, boundary conditions, etc. But most PDEs used for example in engineering consist of higher-level components that “package together” derivatives, boundary conditions, etc. to represent features of physics, materials, etc.

The lowest level of our new PDE framework consists of symbolic “terms”, corresponding to common mathematical constructs that appear in real-world PDEs. For example, here’s a 2D “Laplacian term”:

LaplacianPDETerm
&#10005

LaplacianPDETerm[{u[x, y], {x, y}}]

And now this is all it takes to find the first 5 eigenvalues of the Laplacian in a regular polygon:

NDEigenvalues
&#10005

NDEigenvalues[LaplacianPDETerm[{u[x, y], {x, y}}], 
 u[x, y], {x, y} \[Element] RegularPolygon[5], 5]

And the important thing is that you can put this kind of operation into a whole pipeline. Like here we’re getting the region from an image, solving for the 10th eigenmode, and then 3D plotting the result:

NDEigensystem
&#10005

NDEigensystem[{LaplacianPDETerm[{u[x, y], {x, y}}]}, u[x, y],
  {x, y} \[Element] ImageMesh[CloudGet["https://wolfr.am/ROWwBtE7"]], 
  10][[2, -1]]

Plot3D
&#10005

Plot3D[%, {x, y} \[Element] 
  ImageMesh[CloudGet["https://wolfr.am/ROWwGqjg"]]]

In addition to LaplacianPDETerm, there are things like DiffusionPDETerm and ConvectionPDETerm that represent other terms that arise in real-world PDEs. Here’s a term for isotropic diffusion with unit diffusion coefficient:

DiffusionPDETerm
&#10005

DiffusionPDETerm[{\[Phi][x, y, z], {x, y, z}}]

Beyond individual terms, there are also “components” that combine multiple terms, usually with various parameters. Here’s a Helmholtz PDE component:

HelmholtzPDEComponent
&#10005

HelmholtzPDEComponent[{u[x, y], {x, y}}, <|"HelmholtzEigenvalue" -> k|>]

By the way, it’s worth pointing out that our “terms” and “components” are set up to represent the symbolic structure of PDEs in a form suitable for structural manipulation and for things like numerical analysis. And to ensure that they maintain their structure, they’re normally kept in an inactivated form. But you can always “activate” them if you want to do things like algebraic operations:

Activate
&#10005

Activate[%]

In real-world PDEs, one’s often dealing with actual, physical processes taking place in actual physical materials. And in Version 12.2 we’ve got immediate ways to deal not only with things like diffusion, but also with acoustics, heat transfer and mass transport—and to feed in properties of actual materials. Typically the structure is that there’s a PDE “component” that represents the bulk behavior of the material, together with a variety of PDE “values” or “conditions” that represent boundary conditions.

Here’s a typical PDE component, using material properties from the Wolfram Knowledgebase:

HeatTransferPDEComponent
&#10005

HeatTransferPDEComponent[{\[CapitalTheta][t, x, y], t, {x, y}}, <|
  "Material" -> CloudGet["https://wolfr.am/ROWwUQai"]|>]

There’s quite a bit of diversity and complexity to the possible boundary conditions. For example, for heat transfer, there’s HeatFluxValue, HeatInsulationValue and five other symbolic boundary condition specification constructs. In each case, the basic idea is to say where (geometrically) the condition applies, then what it applies to, and what parameters relate to it.

So, for example, here’s a condition that specifies that there’s a fixed “surface temperature” θ0 everywhere outside the (circular) region defined by x2 + y2 = 1:

HeatTemperatureCondition
&#10005

HeatTemperatureCondition[
 x^2 + y^2 > 1, {\[CapitalTheta][t, x, y], t, {x, y}}, <|
  "SurfaceTemperature" -> Subscript[\[Theta], 0]|>]

What’s basically happening here is that our high-level “physics” description is being “compiled” into explicit “mathematical” PDE structures—like Dirichlet boundary conditions.

OK, so how does all this fit together in a real-life situation? Let me show an example. But first, let me tell a story. Back in 2009 I was having tea with our lead PDE developer. I picked up a teaspoon and asked “When will we be able to model the stresses in this?” Our lead developer explained that there was quite a bit to build to get to that point. Well, I’m excited to say that after 11 years of work, in Version 12.2 we’re there. And to prove it, our lead developer just gave me… a (computational) spoon!

spoon = CloudGet
&#10005

spoon = CloudGet["https://wolfr.am/ROWx6wKF"];

The core of the computation is a 3D diffusion PDE term, with a “diffusion coefficient” given by a rank-4 tensor parametrized by Young’s modulus (here Y) and Poisson ratio (ν):

pdeterm = DiffusionPDETerm
&#10005

pdeterm = 
  DiffusionPDETerm[{{u[x, y, z], v[x, y, z], w[x, y, z]}, {x, y, z}}, 
   Y/(1 + \[Nu]) {
     {{
       {(1 - \[Nu])/(1 - 2 \[Nu]), 0, 0},
       {0, 1/2, 0},
       {0, 0, 1/2}
      }, {
       {0, \[Nu]/(1 - 2 \[Nu]), 0},
       {1/2, 0, 0},
       {0, 0, 0}
      }, {
       {0, 0, \[Nu]/(1 - 2 \[Nu])},
       {0, 0, 0},
       {1/2, 0, 0}
      }},
     {{
       {0, 1/2, 0},
       {\[Nu]/(1 - 2 \[Nu]), 0, 0},
       {0, 0, 0}
      }, {
       {1/2, 0, 0},
       {0, (1 - \[Nu])/(1 - 2 \[Nu]), 0},
       {0, 0, 1/2}
      }, {
       {0, 0, 0},
       {0, 0, \[Nu]/(1 - 2 \[Nu])},
       {0, 1/2, 0}
      }},
     {{
       {0, 0, 1/2},
       {0, 0, 0},
       {\[Nu]/(1 - 2 \[Nu]), 0, 0}
      }, {
       {0, 0, 0},
       {0, 0, 1/2},
       {0, \[Nu]/(1 - 2 \[Nu]), 0}
      }, {
       {1/2, 0, 0},
       {0, 1/2, 0},
       {0, 0, (1 - \[Nu])/(1 - 2 \[Nu])}
      }}
    }, <|Y -> 10^9, \[Nu] -> 33/100|>];

There are boundary conditions to specify how the spoon is being held, and pushed. Then solving the PDE (which takes just a few seconds) gives the displacement field for the spoon

dfield = NDSolveValue
&#10005

dfield = deformations = 
   NDSolveValue[{pdeterm == {0, NeumannValue[-1000, x <= -100], 0}, 
     DirichletCondition[{u[x, y, z] == 0., v[x, y, z] == 0., 
       w[x, y, z] == 0.}, x >= 100]}, {u, v, w}, {x, y, z} \[Element] 
     spoon];

which we can then use to find how the spoon would deform:

Show
&#10005

Show[MeshRegion[
  Table[Apply[if, m], {m, MeshCoordinates[spoon]}, {if, 
     deformations}] + MeshCoordinates[spoon], 
  MeshCells[spoon, MeshCells[spoon, {2, All}]]], 
 Graphics3D[Style[spoon, LightGray]]]

PDE modeling is a complicated area, and I consider it to be a major achievement that we’ve now managed to “package” it as cleanly as this. But in Version 12.2, in addition to the actual technology of PDE modeling, something else that’s important is a large collection of computational essays about PDE modeling—altogether about 400 pages of detailed explanation and application examples, currently in acoustics, heat transfer and mass transport, but with many other domains to come.

Just Type TEX

The Wolfram Language is all about expressing yourself in precise computational language. But in notebooks you can also express yourself with ordinary text in natural language. But what if you want to display math in there as well? For 25 years we’ve had the infrastructure to do the math display—through our box language. But the only convenient way to enter the math is through Wolfram Language math constructs—that in some sense have to have computational meaning.

But what about “math” that’s “for human eyes only”? That has a certain visual layout that you want to specify, but that doesn’t necessarily have any particular underlying computational meaning that’s been defined? Well, for many decades there’s been a good way to specify such math, thanks to my friend Don Knuth: just use TEX. And in Version 12.2 we’re now supporting direct entry of TEX math into Wolfram Notebooks, both on the desktop and in the cloud. Underneath, the TEX is being turned into our box representation, so it structurally interoperates with everything else. But you can just enter it—and edit it—as TEX.

The interface is very much like the += interface for Wolfram|Alpha-style natural language input. But for TEX (in a nod to standard TEX delimiters), it’s +$.

Type +$ and you get a TEX input box. When you’ve finished the TEX, just hit and it’ll be rendered:

TeX

Like with +=, if you click the rendered form, it’ll go back to text and you can edit again, just as TEX.

Entering TEX in text cells is the most common thing to want. But Version 12.2 also supports entering TEX in input cells:

TeX typing

What happens if you + evaluate? Your input will be treated as TraditionalForm, and at least an attempt will be made to interpret it. Though, of course, if you wrote “computationally meaningless math” that won’t work.

Just Draw Anything

Type Canvas[] and you’ll get a blank canvas to draw whatever you want:

Canvas[]
&#10005

Canvas[]

We’ve worked hard to make the drawing tools as ergonomic as possible.

Canvas[]
Canvas

Applying Normal gives you graphics that you can then use or manipulate:

Normal
&#10005

GraphicsGrid[
 Partition[
  Table[Rasterize[Rotate[Normal[%], \[Theta]], 
    ImageSize -> 50], {\[Theta], 0, 2 Pi, .4}], UpTo[8]], 
 ImageSize -> 500]

GraphicsGrid
&#10005

GraphicsGrid[
 Partition[
  Table[Rasterize[Rotate[Normal[%], \[Theta]], 
    ImageSize -> 50], {\[Theta], 0, 2 Pi, .4}], UpTo[8]], 
 ImageSize -> 500]

When you create a canvas, it can have any graphic as initial content—and it can have any background you want:

Canvas
&#10005

Canvas[Graphics[
  Style[Disk[], Opacity[.4, Red], EdgeForm[{Thick, Red}]]], 
 Background -> 
  GeoGraphics[
   Entity["MannedSpaceMission", "Apollo16"][
    EntityProperty["MannedSpaceMission", "LandingPosition"]]]]

On the subject of drawing anything, Version 12.2 has another new function: MoleculeDraw, for drawing (or editing) molecules. Start with the symbolic representation of a molecule:

Caffeine molecule
&#10005

Molecule[Entity["Chemical", "Caffeine"]]

Now use MoleculeDraw to bring up the interactive molecule drawing environment, make an edit, and return the result:

MoleculeDraw

It’s another molecule now:

New molecule

The Never-Ending Math Story

Math has been a core use case for the Wolfram Language (and Mathematica) since the beginning. And it’s been very satisfying over the past third of a century to see how much math we’ve been able to make computational. But the more we do, the more we realize is possible, and the further we can go. It’s become in a sense routine for us. There’ll be some area of math that people have been doing by hand or piecemeal forever. And we’ll figure out: yes, we can make an algorithm for that! We can use the giant tower of capabilities we’ve built over all these years to systematize and automate yet more mathematics; to make yet more math computationally accessible to anyone. And so it has been with Version 12.2. A whole collection of pieces of “math progress”.

Let’s start with something rather cut and dried: special functions. In a sense, every special function is an encapsulation of a certain nugget of mathematics: a way of defining computations and properties for a particular type of mathematical problem or system. Starting from Mathematica 1.0 we’ve achieved excellent coverage of special functions, steadily expanding to more and more complicated functions. And in Version 12.2 we’ve got another class of functions: the Lamé functions.

Lamé functions are part of the complicated world of handling ellipsoidal coordinates; they appear as solutions to the Laplace equation in an ellipsoid. And now we can evaluate them, expand them, transform them, and do all the other kinds of things that are involved in integrating a function into our language:

Plot
&#10005

Plot[Abs[LameS[3/2 + I, 3, z, 0.1 + 0.1 I]], {z, -8 EllipticK[1/3], 
  8 EllipticK[1/3]}]

Series
&#10005

Series[LameC[\[Nu], j, z, m], {z, 0, 3}]

Also in Version 12.2 we’ve done a lot on elliptic functions—dramatically speeding up their numerical evaluation and inventing algorithms doing this efficiently at arbitrary precision. We’ve also introduced some new elliptic functions, like JacobiEpsilon—which provides a generalization of EllipticE that avoids branch cuts and maintains the analytic structure of elliptic integrals:

ComplexPlot3D
&#10005

ComplexPlot3D[JacobiEpsilon[z, 1/2], {z, 6}]

We’ve been able to do many symbolic Laplace and inverse Laplace transforms for a couple of decades. But in Version 12.2 we’ve solved the subtle problem of using contour integration to do inverse Laplace transforms. It’s a story of knowing enough about the structure of functions in the complex plane to avoid branch cuts and other nasty singularities. A typical result effectively sums over an infinite number of poles:

InverseLaplaceTransform
&#10005

InverseLaplaceTransform[Coth[s \[Pi] /2 ]/(1 + s^2), s, t]

And between contour integration and other methods we’ve also added numerical inverse Laplace transforms. It all looks easy in the end, but there’s a lot of complicated algorithmic work needed to achieve this:

InverseLaplaceTransform
&#10005

InverseLaplaceTransform[1/(s + Sqrt[s] + 1), s, 1.5]

Another new algorithm made possible by finer “function understanding” has to do with asymptotic expansion of integrals. Here’s a complex function that becomes increasingly wiggly as λ increases:

Table
&#10005

Table[ReImPlot[(t^10 + 3) Exp[I  \[Lambda] (t^5 + t + 1)], {t, -2, 
   2}], {\[Lambda], 10, 30, 10}]

And here’s the asymptotic expansion for λ:

AsymptoticIntegrate
&#10005

AsymptoticIntegrate[(t^10 + 3) Exp[
   I  \[Lambda] (t^5 + t + 1)], {t, -2, 2}, {\[Lambda], Infinity, 2}]

 

Tell Me about That Function

It’s a very common calculus exercise to determine, for example, whether a particular function is injective. And it’s pretty straightforward to do this in easy cases. But a big step forward in Version 12.2 is that we can now systematically figure out these kinds of global properties of functions—not just in easy cases, but also in very hard cases. Often there are whole networks of theorems that depend on functions having such-and-such a property. Well, now we can automatically determine whether a particular function has that property, and so whether the theorems hold for it. And that means that we can create systematic algorithms that automatically use the theorems when they apply.

Here’s an example. Is Tan[x] injective? Not globally:

FunctionInjective
&#10005

FunctionInjective[Tan[x], x]

But over an interval, yes:

FunctionInjective
&#10005

FunctionInjective[{Tan[x], 0 < x < Pi/2}, x]

What about the singularities of Tan[x]? This gives a description of the set:

FunctionSingularities
&#10005

FunctionSingularities[Tan[x], x]

You can get explicit values with Reduce:

Reduce
&#10005

Reduce[%, x]

So far, fairly straightforward. But things quickly get more complicated:

FunctionSingularities
&#10005

FunctionSingularities[ArcTan[x^y], {x, y}, Complexes]

And there are more sophisticated properties you can ask about as well:

FunctionMeromorphic
&#10005

FunctionMeromorphic[Log[z], z]

FunctionMeromorphic
&#10005

FunctionMeromorphic[{Log[z], z > 0}, z]

We’ve internally used various kinds of function-testing properties for a long time. But with Version 12.2 function properties are much more complete and fully exposed for anyone to use. Want to know if you can interchange the order of two limits? Check FunctionSingularities. Want to know if you can do a multivariate change of variables in an integral? Check FunctionInjective.

And, yes, even in Plot3D we’re routinely using FunctionSingularities to figure out what’s going on:

Plot3D
&#10005

Plot3D[Re[ArcTan[x^y]], {x, -5, 5}, {y, -5, 5}]

 

Mainstreaming Video

In Version 12.1 we began the process of introducing video as a built-in feature of the Wolfram Language. Version 12.2 continues that process. In 12.1 we could only handle video in desktop notebooks; now it’s extended to cloud notebooks—so when you generate a video in Wolfram Language it’s immediately deployable to the cloud.

A major new video feature in 12.2 is VideoGenerator. Provide a function that makes images (and/or audio), and VideoGenerator will generate a video from them (here a 4-second video):

VideoGenerator
VideoGenerator
&#10005

VideoGenerator[Graphics3D[AugmentedPolyhedron[Icosahedron[], # - 2],
   ImageSize -> {200, 200}] &, 4]

To add a sound track, we can just use VideoCombine:

VideoCombine
&#10005

VideoCombine[{%, \!\(\*
TagBox[
RowBox[{"CloudGet", "[", "\"\<https://wolfr.am/ROWzckqS\>\"", "]"}],
Audio`AudioBox["AudioClass" -> "AudioData"],
Editable->False,
Selectable->False]\)}]

So how would we edit this video? In Version 12.2 we have programmatic versions of standard video-editing functions. VideoSplit, for example, splits the video at particular times:

VideoSplit
&#10005

VideoSplit[%, {.3, .5, 2}]

But the real power of the Wolfram Language comes in systematically applying arbitrary functions to videos. VideoMap lets you apply a function to a video to get another video. For example, we could progressively blur the video we just made:

VideoMap
VideoMap
&#10005

VideoMap[Blur[#Image, 20 #Time] &, %%]

There are also two new functions for analyzing videos—VideoMapList and VideoMapTimeSeries—which respectively generate a list and a time series by applying a function to the frames in a video, and to its audio track.

Another new function—highly relevant for video processing and video editing—is VideoIntervals, which determines the time intervals over which any given criterion applies in a video:

VideoIntervals
&#10005

VideoIntervals[%, Length[DominantColors[#Image]] < 3 &]

Now, for example, we can delete those intervals in the video:

VideoDelete
&#10005

VideoDelete[%, %%]

A common operation in the practical handling of videos is transcoding. And in Version 12.2 the function VideoTranscode lets you convert a video among any of the over 300 containers and codecs that we support. By the way, 12.2 also has new functions ImageWaveformPlot and ImageVectorscopePlot that are commonly used in video color correction:

ImageVectorscopePlot
&#10005

ImageVectorscopePlot[CloudGet["https://wolfr.am/ROWzsGFw"]]

One of the main technical issues in handling video is dealing with the large amount of data in a typical video. In Version 12.2 there’s now finer control over where that data is stored. The option GeneratedAssetLocation (with default $GeneratedAssetLocation) lets you pick between different files, directories, local object stores, etc.

But there’s also a new function in Version 12.2 for handling “lightweight video”, in the form of AnimatedImage. AnimatedImage simply takes a list of images and produces an animation that immediately plays in your notebook—and has everything directly stored in your notebook:

AnimatedImage
&#10005

AnimatedImage[
 Table[Rasterize[Rotate[Style["W", 40], \[Theta]]], {\[Theta], 0, 
   2 Pi, .1}]]

 

Big Computations? Send Them to a Cloud Provider!

It comes up quite frequently for me—especially given our Physics Project. I’ve got a big computation I’d like to do, but I don’t want to (or can’t) do it on my computer. And instead what I’d like to do is run it as a batch job in the cloud.

This has been possible in principle for as long as cloud computation providers have been around. But it’s been very involved and difficult. Well, now, in Version 12.2 it’s finally easy. Given any piece of Wolfram Language code, you can just use RemoteBatchSubmit to send it to be run as a batch job in the cloud.

There’s a little bit of setup required on the batch computation provider side. First, you have to have an account with an appropriate provider—and initially we’re supporting AWS Batch and Charity Engine. Then you have to configure things with that provider (and we’ve got workflows that describe how to do that). But as soon as that’s done, you’ll get a remote batch submission environment that’s basically all you need to start submitting batch jobs:

env = RemoteBatchSubmissionEnvironment
&#10005

env = RemoteBatchSubmissionEnvironment[
  "AWSBatch", <|"JobQueue" -> 
    "arn:aws:batch:us-east-1:123456789012:job-queue/MyQueue", 
   "JobDefinition" -> 
    "arn:aws:batch:us-east-1:123456789012:job-definition/MyDefinition:\
1", "IOBucket" -> "my-job-bucket"|>]

OK, so what would be involved, say, in submitting a neural net training? Here’s how I would run it locally on my machine (and, yes, this is a very simple example):

NetTrain
&#10005

NetTrain[NetModel["LeNet"], "MNIST"]

And here’s the minimal way I would send it to run on AWS Batch:

job = RemoteBatchSubmit
&#10005

job = RemoteBatchSubmit[env, NetTrain[NetModel["LeNet"], "MNIST"]]

I get back an object that represents my remote batch job—that I can query to find out what’s happened with my job. At first it’ll just tell me that my job is “runnable”:

job
&#10005

job["JobStatus"]

Later on, it’ll say that it’s “starting”, then “running”, then (if all goes well) “succeeded”. And once the job is finished, you can get back the result like this:

job
&#10005

job["EvaluationResult"]

There’s lots of detail you can retrieve about what actually happened. Like here’s the beginning of the raw job log:

JobLog
&#10005

job["JobLog"]

But the real point of running your computations remotely in a cloud is that they can potentially be bigger and crunchier than the ones you can run on your own machines. Here’s how we could run the same computation as above, but now requesting the use of a GPU:

RemoteBatchSubmit
&#10005

RemoteBatchSubmit[env, 
 NetTrain[NetModel["LeNet"], "MNIST", TargetDevice -> "GPU"],
 RemoteProviderSettings -> <|"GPUCount" -> 1|>]

RemoteBatchSubmit can also handle parallel computations. If you request a multicore machine, you can immediately run ParallelMap etc. across its cores. But you can go even further with RemoteBatchMapSubmit—which automatically distributes your computation across a whole collection of separate machines in the cloud.

Here’s an example:

job = RemoteBatchMapSubmit
&#10005

job = RemoteBatchMapSubmit[env, ImageIdentify, 
  WebImageSearch["happy", 100]]

While it’s running, we can get a dynamic display of the status of each part of the job:

job
&#10005

job["DynamicStatusVisualization"]

About 5 minutes later, the job is finished:

job
&#10005

job["JobStatus"]

And here are our results:

ReverseSort
&#10005

ReverseSort[Counts[job["EvaluationResults"]]]

RemoteBatchSubmit and RemoteBatchMapSubmit give you high-level access to cloud compute services for general batch computation. But in Version 12.2 there is also a direct lower-level interface available, for example for AWS.

Connect to AWS:

aws = ServiceConnect
&#10005

aws = ServiceConnect["AWS"]

Once you’ve authenticated, you can see all the services that are available:

aws
&#10005

aws["Services"]

This gives a handle to the Amazon Translate service:

aws
&#10005

aws["GetService", "Name" -> "Translate"]

Now you can use this to call the service:

%
&#10005

%["TranslateText",
 "Text" -> "今日は良い一日だった",
 "SourceLanguageCode" -> "auto",
 "TargetLanguageCode" -> "en"
 ]

Of course, you can always do language translation directly through the Wolfram Language too:

TextTranslation
&#10005

TextTranslation["今日は良い一日だった"]

 

Can You Make a 10-Dimensional Plot?

It’s straightforward to plot data that involves one, two or three dimensions. For a few dimensions above that, you can use colors or other styling. But by the time you’re dealing with ten dimensions, that breaks down. And if you’ve got a lot of data in 10D, for example, then you’re probably going to have to use something like DimensionReduce to try to tease out “interesting features”.

But if you’re just dealing with a few “data points”, there are other ways to visualize things like 10-dimensional data. And in Version 12.2 we’re introducing several functions for doing this.

As a first example, let’s look at ParallelAxisPlot. The idea here is that every “dimension” is plotted on a “separate axis”. For a single point it’s not that exciting:

ParallelAxisPlot
&#10005

ParallelAxisPlot[{{10, 17, 19, 8, 7, 5, 17, 4, 8, 2}}, 
 PlotRange -> {0, 20}]

Here’s what happens if we plot three random “10D data points”:

ParallelAxisPlot
&#10005

ParallelAxisPlot[RandomInteger[20, {3, 10}], PlotRange -> {0, 20}]

But one of the important features of ParallelAxisPlot is that by default it automatically determines the scale on each axis, so there’s no need for the axes to be representing similar kinds of things. So, for example, here are 7 completely different quantities plotted for all the chemical elements:

ParallelAxisPlot
&#10005

ParallelAxisPlot[
 EntityValue[
  "Element", {EntityProperty["Element", "AtomicMass"], 
   EntityProperty["Element", "AtomicRadius"], 
   EntityProperty["Element", "BoilingPoint"], 
   EntityProperty["Element", "ElectricalConductivity"], 
   EntityProperty["Element", "MeltingPoint"], 
   EntityProperty["Element", "NeutronCrossSection"], 
   EntityProperty["Element", "ThermalConductivity"]}]]

Different kinds of high-dimensional data do best on different kinds of plots. Another new type of plot in Version 12.2 is RadialAxisPlot. (This type of plot also goes by names like radar plot, spider plot and star plot.)

RadialAxisPlot plots each dimension in a different direction:

RadialAxisPlot
&#10005

RadialAxisPlot[
 EntityValue[
  "Element", {EntityProperty["Element", "AtomicMass"], 
   EntityProperty["Element", "AtomicRadius"], 
   EntityProperty["Element", "BoilingPoint"], 
   EntityProperty["Element", "ElectricalConductivity"], 
   EntityProperty["Element", "MeltingPoint"], 
   EntityProperty["Element", "NeutronCrossSection"], 
   EntityProperty["Element", "ThermalConductivity"]}]]

It’s typically most informative when there aren’t too many data points:

RadialAxisPlot
&#10005

RadialAxisPlot[
 EntityValue[{Entity["City", {"Chicago", "Illinois", "UnitedStates"}],
    Entity["City", {"Dallas", "Texas", "UnitedStates"}], 
   Entity["City", {"NewYork", "NewYork", "UnitedStates"}], 
   Entity["City", {"LosAngeles", "California", 
     "UnitedStates"}]}, {EntityProperty["City", 
    "MedianHomeSalePrice"], 
   EntityProperty["City", "TotalSalesTaxRate"], 
   EntityProperty["City", "MedianHouseholdIncome"], 
   EntityProperty["City", "Population"], 
   EntityProperty["City", "Area"]}, "EntityAssociation"], 
 PlotLegends -> Automatic]

 

3D Array Plots

Back in 1984 I used a Cray supercomputer to make 3D pictures of 2D cellular automata evolving in time (yes, captured on 35 mm slides):

Slides of cellular automata

I’ve been waiting for 36 years to have a really streamlined way to reproduce these. And now finally in Version 12.2 we have it: ArrayPlot3D. Already in 2012 we introduced Image3D to represent and display 3D images composed of 3D voxels with specified colors and opacities. But its emphasis is on “radiology-style” work, in which there’s a certain assumption of continuity between voxels. And if you’ve really got a discrete array of discrete data (as in cellular automata) that won’t lead to crisp results.

And here it is, for a slightly more elaborate case of a 3D cellular automaton:

Table
&#10005

Table[ArrayPlot3D[
  CellularAutomaton[{14, {2, 1}, {1, 1, 1}}, {{{{1}}}, 
    0}, {{{t}}}]], {t, 20, 40, 10}]

Another new ArrayPlot-family function in 12.2 is ComplexArrayPlot, here applied to an array of values from Newton’s method:

ComplexArrayPlot
&#10005

Table[ArrayPlot3D[
  CellularAutomaton[{14, {2, 1}, {1, 1, 1}}, {{{{1}}}, 0}, {{{t}}}], 
  PlotTheme -> "Web"], {t, 10, 40, 10}]

 

Advancing the Computational Aesthetics of Visualization

One of our objectives in Wolfram Language is to have visualizations that just “automatically look good”—because they’ve got algorithms and heuristics that effectively implement good computational aesthetics. In Version 12.2 we’ve tuned up the computational aesthetics for a variety of types of visualization. For example, in 12.1 this is what a SliceVectorPlot3D looked like by default:

SliceVectorPlot3D
&#10005

SliceVectorPlot3D[{y + x, z, -y}, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}]

Now it looks like this:

Vector plot

Since Version 10, we’ve also been making increasing use of our PlotTheme option, to “bank switch” detailed options to make visualizations that are suitable for different purposes, and meet different aesthetic goals. So for example in Version 12.2 we’ve added plot themes to GeoRegionValuePlot. Here’s an example of the default (which has been updated, by the way):

GeoRegionValuePlot
&#10005

GeoRegionValuePlot[CloudGet["https://wolfr.am/ROWDoxAw"] -> "GDP"]

And here it is with the "Marketing" plot theme:

GeoRegionValuePlot
&#10005

GeoRegionValuePlot[CloudGet["https://wolfr.am/ROWDoxAw"] -> "GDP", 
 PlotTheme -> "Marketing"]

Another thing in Version 12.2 is the addition of new primitives and new “raw material” for creating aesthetic visual effects. In Version 12.1 we introduced things like HatchFilling for cross-hatching. In Version 12.2 we now also have LinearGradientFilling:

Graphics
&#10005

Graphics[Style[Disk[], 
  LinearGradientFilling[{RGBColor[1., 0.71, 0.75], RGBColor[0.64, 
Rational[182, 255], 
Rational[244, 255]]}]]]

And we can now add this kind of effect to the filling in a plot:

Plot
&#10005

Plot[2 Sin[x] + x, {x, 0, 15}, 
 FillingStyle -> LinearGradientFilling[{RGBColor[0.64, 
Rational[182, 255], 
Rational[244, 255]], RGBColor[1., 0.71, 0.75]}, Top], 
 Filling -> Bottom]

To be even more stylish, one can plot random points using the new ConicGradientFilling:

Graphics
&#10005

Graphics[Table[
  Style[Disk[RandomReal[20, 2]], 
   ConicGradientFilling[RandomColor[3]]], 100]]

 

Making Code Just a Bit More Beautiful

A core goal of the Wolfram Language is to define a coherent computational language that can readily be understood by both computers and humans. We (and I in particular!) put a lot of effort into the design of the language, and into things like picking the right names for functions. But in making the language as easy to read as possible, it’s also important to streamline its “non-verbal” or syntactic aspects. For function names, we’re basically leveraging people’s understanding of words in natural language. For syntactic structure, we want to leverage people’s “ambient understanding”, for example, from areas like math.

More than a decade ago we introduced as a way to specify Function functions, so instead of writing

Function
&#10005

Function[x, x^2]

(or #2&) you could write:

x |-> x^2
&#10005

x |-> x^2

But to enter you had to type \[Function] or at least  fn , which tended to feel “a bit difficult”.

Well, in Version 12.2, we’re “mainstreaming” by making it possible to type just as |->

x | - > x^2
&#10005

x | - > x^2

You can also do things like

{x, y} |-> x + y
&#10005

{x, y} |-> x + y

as well as things like:

SameTest
&#10005

SameTest -> ({x, y} |-> Mod[x - y, 2] == 0)

In Version 12.2, there’s also another new piece of “short syntax”: //=

Imagine you’ve got a result, say called res. Now you want to apply a function to res, and then “update res”. The new function ApplyTo (written //=) makes it easy to do that:

res = 10
&#10005

res = 10

res //= f
&#10005

res //= f

res
&#10005

res

We’re always on the lookout for repeated “lumps of computation” that we can “package” into functions with “easy-to-understand names”. And in Version 12.2 we have a couple of new such functions: FoldWhile and FoldWhileList. FoldList normally just takes a list and “folds” each successive element into the result it’s building up—until it gets to the end of the list:

FoldList
&#10005

FoldList[f, {1, 2, 3, 4}]

But what if you want to “stop early”? FoldWhileList lets you do that. So here we’re successively dividing by 1, 2, 3, …, stopping when the result isn’t an integer anymore:

FoldWhileList
&#10005

FoldWhileList[Divide, 5!, Range[10], IntegerQ]

 

More Array Gymnastics: Column Operations and Their Generalizations

Let’s say you’ve got an array, like:

{{a, b, c, d}, {x, y, z, w}} // MatrixForm
&#10005

{{a, b, c, d}, {x, y, z, w}} // MatrixForm

Map lets you map a function over the “rows” of this array:

Map
&#10005

Map[f, {{a, b, c, d}, {x, y, z, w}}]

But what if you want to operate on the “columns” of the array, effectively “reducing out” the first dimension of the array? In Version 12.2 the function ArrayReduce lets you do this:

ArrayReduce
&#10005

ArrayReduce[f, {{a, b, c, d}, {x, y, z, w}}, 1]

Here’s what happens if instead we tell ArrayReduce to “reduce out” the second dimension of the array:

ArrayReduce
&#10005

ArrayReduce[f, {{a, b, c, d}, {x, y, z, w}}, 2]

What’s really going on here? The array has dimensions 2×4:

Dimensions
&#10005

Dimensions[{{a, b, c, d}, {x, y, z, w}}]

ArrayReduce[f, ..., 1] “reduces out” the first dimension, leaving an array with dimensions {4}. ArrayReduce[f, ..., 2] reduces out the second dimension, leaving an array with dimensions {2}.

Let’s look at a slightly bigger case—a 2×3×4 array:

array = ArrayReshape
&#10005

array = ArrayReshape[Range[24], {2, 3, 4}]

This now eliminates the “first dimension”, leaving a 3×4 array:

ArrayReduce
&#10005

ArrayReduce[f, array, 1]

Dimensions
&#10005

Dimensions[%]

This, on the other hand, eliminates the “second dimension”, leaving a 2×4 array:

ArrayReduce
&#10005

ArrayReduce[f, array, 2]

Dimensions
&#10005

Dimensions[%]

Why is this useful? One example is when you have arrays of data where different dimensions correspond to different attributes, and then you want to “ignore” a particular attribute, and aggregate the data with respect to it. Let’s say that the attribute you want to ignore is at level n in your array. Then all you do to “ignore” it is to use ArrayReduce[f, ..., n], where f is the function that aggregates values (often something like Total or Mean).

You can achieve the same results as ArrayReduce by appropriate sequences of Transpose, Apply, etc. But it’s quite messy, and ArrayReduce provides an elegant “packaging” of these kinds of array operations.

ArrayReduce is quite general; it lets you not only “reduce out” single dimensions, but whole collections of dimensions:

ArrayReduce
&#10005

ArrayReduce[f, array, {2, 3}]

ArrayReduce
&#10005

ArrayReduce[f, array, {{2}, {3}}]

At the simplest level, ArrayReduce is a convenient way to apply functions “columnwise” on arrays. But in full generality it’s a way to apply functions to subarrays with arbitrary indices. And if you’re thinking in terms of tensors, ArrayReduce is a generalization of contraction, in which more than two indices can be involved, and elements can be “flattened” before the operation (which doesn’t have to be summation) is applied.

Watch Your Code Run: More in the Echo Family

It’s an old adage in debugging code: “put in a print statement”. But it’s more elegant in the Wolfram Language, thanks particularly to Echo. It’s a simple idea: Echo[expr] “echoes” (i.e. prints) the value of expr, but then returns that value. So the result is that you can put Echo anywhere into your code (often as Echo@…) without affecting what your code does.

In Version 12.2 there are some new functions that follow the “Echo” pattern. A first example is EchoLabel, which just adds a label to what’s echoed:

EchoLabel
&#10005

EchoLabel["a"]@5! + EchoLabel["b"]@10!

Aficionados might wonder why EchoLabel is needed. After all, Echo itself allows a second argument that can specify a label. The answer—and yes, it’s a mildly subtle piece of language design—is that if one’s going to just insert Echo as a function to apply (say with @), then it can only have one argument, so no label. EchoLabel is set up to have the operator form EchoLabel[label] so that EchoLabel[label][expr] is equivalent to Echo[expr,label].

Another new “echo function” in 12.2 is EchoTiming, which displays the timing (in seconds) of whatever it evaluates:

Table
&#10005

Table[Length[EchoTiming[Permutations[Range[n]]]], {n, 8, 10}]

It’s often helpful to use both Echo and EchoTiming:

Length
&#10005

Length[EchoTiming[Permutations[Range[Echo@10]]]]

And, by the way, if you always want to print evaluation time (just like Mathematica 1.0 did by default 32 years ago) you can always globally set $Pre=EchoTiming.

Another new “echo function” in 12.2 is EchoEvaluation which echoes the “before” and “after” for an evaluation:

EchoEvaluation
&#10005

EchoEvaluation[2 + 2]

You might wonder what happens with nested EchoEvaluation’s. Here’s an example:

EchoEvaluation
&#10005

EchoEvaluation[
 Accumulate[EchoEvaluation[Reverse[EchoEvaluation[Range[10]]]]]]

By the way, it’s quite common to want to use both EchoTiming and EchoEvaluation:

Table
&#10005

Table[EchoTiming@EchoEvaluation@FactorInteger[2^(50 n) - 1], {n, 2}]

Finally, if you want to leave echo functions in your code, but want your code to “run quiet”, you can use the new QuietEcho to “quiet” all the echoes (like Quiet “quiets” messages):

QuietEcho@Table
&#10005

QuietEcho@
 Table[EchoTiming@EchoEvaluation@FactorInteger[2^(50 n) - 1], {n, 2}]

 

Confirm/Enclose: Symbolic Exception Handling

Did something go wrong inside your program? And if so, what should the program do? It can be possible to write very elegant code if one ignores such things. But as soon as one starts to put in checks, and has logic for unwinding things if something goes wrong, it’s common for the code to get vastly more complicated, and vastly less readable.

What can one do about this? Well, in Version 12.2 we’ve developed a high-level symbolic mechanism for handling things going wrong in code. Basically the idea is that you insert Confirm (or related functions)—a bit like you might insert Echo—to “confirm” that something in your program is doing what it should. If the confirmation works, then your program just keeps going. But if it fails, then the program stops–and exits to the nearest enclosing Enclose. In a sense, Enclose “encloses” regions of your program, not letting anything that goes wrong inside immediately propagate out.

Let’s see how this works in a simple case. Here the Confirm successfully “confirms” y, just returning it, and the Enclose doesn’t really do anything:

Enclose
&#10005

Enclose[f[x, Confirm[y], z]]

But now let’s put $Failed in place of y. $Failed is something that Confirm by default considers to be a problem. So when it sees $Failed, it stops, exiting to the Enclose—which in turn yields a Failure object:

Enclose
&#10005

Enclose[f[x, Confirm[$Failed], z]]

If we put in some echoes, we’ll see that x is successfully reached, but z is not; as soon as the Confirm fails, it stops everything:

Enclose
&#10005

Enclose[f[Echo[x], Confirm[$Failed], Echo[z]]]

A very common thing is to want to use Confirm/Enclose when you define a function:

addtwo
&#10005

addtwo[x_] := Enclose[Confirm[x] + 2]

Use argument 5 and everything just works:

addtwo
&#10005

addtwo[5]

But if we instead use Missing[]—which Confirm by default considers to be a problem—we get back a Failure object:

addtwo
&#10005

addtwo[Missing[]]

We could achieve the same thing with If, Return, etc. But even in this very simple case, it wouldn’t look as nice.

Confirm has a certain default set of things that it considers “wrong” ($Failed, Failure[...], Missing[...] are examples). But there are related functions that allow you to specify particular tests. For example, ConfirmBy applies a function to test if an expression should be confirmed.

Here, ConfirmBy confirms that 2 is a number:

Enclose
&#10005

Enclose[f[1, ConfirmBy[2, NumberQ], 3]]

But x is not considered so by NumberQ:

Enclose
&#10005

Enclose[f[1, ConfirmBy[x, NumberQ], 3]]

OK, so let’s put these pieces together. Let’s define a function that’s supposed to operate on strings:

world
&#10005

world[x_] := Enclose[ConfirmBy[x, StringQ] <> " world!"]

If we give it a string, all is well:

world
&#10005

world["hello"]

But if we give it a number instead, the ConfirmBy fails:

world
&#10005

world[4]

But here’s where really nice things start to happen. Let’s say we want to map world over a list, always confirming that it gets a good result. Here everything is OK:

Enclose
&#10005

Enclose[Confirm[world[#]] & /@ {"a", "b", "c"}]

But now something has gone wrong:

Enclose
&#10005

Enclose[Confirm[world[#]] & /@ {"a", "b", 3}]

The ConfirmBy inside the definition of world failed, causing its enclosing Enclose to produce a Failure object. Then this Failure object caused the Confirm inside the Map to fail, and the enclosing Enclose gave a Failure object for the whole thing. Once again, we could have achieved the same thing with If, Throw, Catch, etc. But Confirm/Enclose do it more robustly, and more elegantly.

These are all very small examples. But where Confirm/Enclose really show their value is in large programs, and in providing a clear, high-level framework for handling errors and exceptions, and defining their scope.

In addition to Confirm and ConfirmBy, there’s also ConfirmMatch, which confirms that an expression matches a specified pattern. Then there’s ConfirmQuiet, which confirms that the evaluation of an expression doesn’t generate any messages (or, at least, none that you told it to test for). There’s also ConfirmAssert, which simply takes an “assertion” (like p>0) and confirms that it’s true.

When a confirmation fails, the program always exits to the nearest enclosing Enclose, delivering to the Enclose a Failure object with information about the failure that occurred. When you set up the Enclose, you can tell it how to handle failure objects it receives—either just returning them (perhaps to enclosing Confirm’s and Enclose’s), or applying functions to their contents.

Confirm and Enclose provide an elegant mechanism for handling errors, that are easy and clean to insert into programs. But—needless to say—there are definitely some tricky issues around them. Let me mention just one. The question is: which Confirm’s does a given Enclose really enclose? If you’ve written a piece of code that explicitly contains Enclose and Confirm, it’s pretty obvious. But what if there’s a Confirm that’s somehow generated—perhaps dynamically—deep inside some stack of functions? It’s similar to the situation with named variables. Module just looks for the variables directly (“lexically”) inside its body. Block looks for variables (“dynamically”) wherever they may occur. Well, Enclose by default works like Module, “lexically” looking for Confirm’s to enclose. But if you include tags in Confirm and Enclose, you can set them up to “find each other” even if they’re not explicitly “visible” in the same piece of code.

Function Robustification

Confirm/Enclose provide a good high-level way to handle the “flow” of things going wrong inside a program or a function. But what if there’s something wrong right at the get-go? In our built-in Wolfram Language functions, there’s a standard set of checks we apply. Are there the correct number of arguments? If there are options, are they allowed options, and are they in the correct place? In Version 12.2 we’ve added two functions that can perform these standard checks for functions you write.

This says that f should have two arguments, which here it doesn’t:

CheckArguments
&#10005

CheckArguments[f[x, y, z], 2]

Here’s a way to make CheckArguments part of the basic definition of a function:

f
&#10005

f[args___] := Null /; CheckArguments[f[args], 2] 

Give it the wrong number of arguments, and it’ll generate a message, and then return unevaluated, just like lots of built-in Wolfram Language functions do:

f
&#10005

f[7]

ArgumentsOptions is another new function in Version 12.2—that separates “positional arguments” from options in a function. Set up options for a function:

Options
&#10005

Options[f] = {opt -> Automatic};

This expects one positional argument, which it finds:

ArgumentsOptions
&#10005

ArgumentsOptions[f[x, opt -> 7], 1]

If it doesn’t find exactly one positional argument, it generates a message:

ArgumentsOptions
&#10005

ArgumentsOptions[f[x, y], 1]

 

Cleaning Up After Your Code

You run a piece of code and it does what it does—and typically you don’t want it to leave anything behind. Often you can use scoping constructs like Module, Block, BlockRandom, etc. to achieve this. But sometimes there’ll be something you set up that needs to be explicitly “cleaned up” when your code finishes.

For example, you might create a file in your piece of code, and want the file removed when that particular piece of code finishes. In Version 12.2 there’s a convenient new function for managing things like this: WithCleanup.

WithCleanup[expr, cleanup] evaluates expr, then cleanup—but returns the result from expr. Here’s a trivial example (which could really be achieved better with Block). You’re assigning a value to x, getting its square—then clearing x before returning the square:

WithCleanup
&#10005

WithCleanup[x = 7; x^2, Clear[x]]

It’s already convenient just to have a construct that does cleanup while still returning the main expression you were evaluating. But an important detail of WithCleanup is that it also handles the situation where you abort the main evaluation you were doing. Normally, issuing an abort would cause everything to stop. But WithCleanup is set up to make sure that the cleanup happens even if there’s an abort. So if the cleanup involves, for example, deleting a file, the file gets deleted, even if the main operation is aborted.

WithCleanup also allows an initialization to be given. So here the initialization is done, as is the cleanup, but the main evaluation is aborted:

WithCleanup
&#10005

WithCleanup[Echo[1], Abort[]; Echo[2], Echo[3]]

By the way, WithCleanup can also be used with Confirm/Enclose to ensure that even if a confirmation fails, certain cleanup will be done.

Dates—with 37 New Calendars

It’s December 16, 2020, today—at least according to the standard Gregorian calendar that’s usually used in the US. But there are many other calendar systems in use for various purposes around the world, and even more that have been used at one time or another historically.

In earlier versions of Wolfram Language we supported a few common calendar systems. But in Version 12.2 we’ve added very broad support for calendar systems—altogether 41 of them. One can think of calendar systems as being a bit like projections in geodesy or coordinate systems in geometry. You have a certain time: now you have to know how it is represented in whatever system you’re using. And much like GeoProjectionData, there’s now CalendarData which can give you a list of available calendar systems:

CalendarData
&#10005

CalendarData["DateCalendar"]

So here’s the representation of “now” converted to different calendars:

CalendarConvert
&#10005

CalendarConvert[Now, #] & /@ CalendarData["DateCalendar"]

There are many subtleties here. Some calendars are purely “arithmetic”; others rely on astronomical computations. And then there’s the matter of “leap variants”. With the Gregorian calendar, we’re used to just adding a February 29. But the Chinese calendar, for example, can add whole “leap months” within a year (so that, for example, there can be two “fourth months”). In the Wolfram Language, we now have a symbolic representation for such things, using LeapVariant:

DateObject
&#10005

DateObject[{72, 25, LeapVariant[4], 20}, CalendarType -> "Chinese"]

One reason to deal with different calendar systems is that they’re used to determine holidays and festivals in different cultures. (Another reason, particularly relevant to someone like me who studies history quite a bit, is in the conversion of historical dates: Newton’s birthday was originally recorded as December 25, 1642, but converting it to a Gregorian date it’s January 4, 1643.)

Given a calendar, something one often wants to do is to select dates that satisfy a particular criterion. And in Version 12.2 we’ve introduced the function DateSelect to do this. So, for example, we can select dates within a particular interval that satisfy the criterion that they are Wednesdays:

DateSelect
&#10005

DateSelect[DateInterval[{{{2020, 4, 1}, {2020, 4, 30}}}, "Day", 
  "Gregorian", -5.], #DayName == Wednesday &]

As a more complicated example, we can convert the current algorithm for selecting dates of US presidential elections to computable form, and then use it to determine dates for the next 50 years:

DateSelect
&#10005

DateSelect[DateInterval[{{2020}, {2070}}, "Day"], 
 Divisible[#Year, 4] && #Month == 11 && #DayName == Tuesday && 
   Or[#DayNameInstanceInMonth == 1 && #Day =!= 
      1, #DayNameInstanceInMonth == 2 && #Day == 8] &]

 

New in Geo

By now, the Wolfram Language has strong capabilities in geo computation and geo visualization. But we’re continuing to expand our geo functionality. In Version 12.2 an important addition is spatial statistics (mentioned above)—which is fully integrated with geo. But there are also a couple of new geo primitives. One is GeoBoundary, which computes boundaries of things:

GeoBoundary
&#10005

GeoBoundary[CloudGet["https://wolfr.am/ROWGPJ4I"]]

GeoLength
&#10005

GeoLength[%]

There’s also GeoPolygon, which is a full geo generalization of ordinary polygons. One of the tricky issues GeoPolygon has to handle is what counts as the “interior” of a polygon on the Earth. Here it’s picking the larger area (i.e. the one that wraps around the globe):

GeoGraphics
&#10005

GeoGraphics[
 GeoPolygon[{{-50, 70}, {30, -90}, {70, 50}}, "LargerArea"]]

GeoPolygon can also—like Polygon—handle holes, or in fact arbitrary levels of nesting:

GeoGraphics
&#10005

GeoGraphics[
 GeoPolygon[
  Entity["AdministrativeDivision", {"Illinois", "UnitedStates"}] -> 
   Entity["AdministrativeDivision", {"ChampaignCounty", "Illinois", 
     "UnitedStates"}]]]

But the biggest “coming attraction” of geo is completely new rendering of geo graphics and maps. It’s still preliminary (and unfinished) in Version 12.2, but there’s at least experimental support for vector-based map rendering. The most obvious payoff from this is maps that look much crisper and sharper at all scales. But another payoff is our ability to introduce new styling for maps, and in Version 12.2 we’re including eight new map styles.

Here’s our “old-style”map:

GeoGraphics
&#10005

GeoGraphics[Entity["Building", "EiffelTower::5h9w8"], 
 GeoRange -> Quantity[400, "Meters"]]

Here’s the new, vector version of this “classic” style:

GeoGraphics
&#10005

GeoGraphics[Entity["Building", "EiffelTower::5h9w8"], 
 GeoBackground -> "VectorClassic", 
 GeoRange -> Quantity[400, "Meters"]]

Here’s a new (vector) style, intended for the web:

GeoGraphics
&#10005

GeoGraphics[Entity["Building", "EiffelTower::5h9w8"], 
 GeoBackground -> "VectorWeb", GeoRange -> Quantity[400, "Meters"]]

And here’s a “dark” style, suitable for having information overlaid on it:

GeoGraphics
&#10005

GeoGraphics[Entity["Building", "EiffelTower::5h9w8"], 
 GeoBackground -> "VectorDark", GeoRange -> Quantity[400, "Meters"]]

 

Importing PDF

Want to analyze a document that’s in PDF? We’ve been able to extract basic content from PDF files for well over a decade. But PDF is a highly complex (and evolving) format, and many documents “in the wild” have complicated structures. In Version 12.2, however, we’ve dramatically expanded our PDF import capabilities, so that it becomes realistic to, for example, take a random paper from arXiv, and import it:

Import
&#10005

Import["https://arxiv.org/pdf/2011.12174.pdf"]

By default, what you’ll get is a high-resolution image for each page (in this particular case, all 100 pages).

If you want the text, you can import that with "Plaintext":

Import
&#10005

Import["https://arxiv.org/pdf/2011.12174.pdf", "Plaintext"]

Now you can immediately make a word cloud of the words in the paper:

WordCloud
&#10005

WordCloud[%]

This picks out all the images from the paper, and makes a collage of them:

ImageCollage
&#10005

ImageCollage[Import["https://arxiv.org/pdf/2011.12174.pdf", "Images"]]

You can get the URLs from each page:

Import
&#10005

Import["https://arxiv.org/pdf/2011.12174.pdf", "URLs"]

Now pick off the last two, and get images of those webpages:

WebImage /@ Take
&#10005

WebImage /@ Take[Flatten[Values[%]], -2]

Depending on how they’re produced, PDFs can have all sorts of structure. "ContentsGraph" gives a graph representing the overall structure detected for a document:

Import
&#10005

Import["https://arxiv.org/pdf/2011.12174.pdf", "ContentsGraph"]

And, yes, it really is a graph:

Graph
&#10005

Graph[EdgeList[%]]

For PDFs that are fillable forms, there’s more structure to import. Here I grabbed a random unfilled government form from the web. Import gives an association whose keys are the names of the fields—and if the form had been filled in, it would have given their values too, so you could immediately do analysis on them:

Import
&#10005

Import["https://www.fws.gov/forms/3-200-41.pdf", "FormFieldRules"]

 

The Latest in Industrial-Strength Convex Optimization

Starting in Version 12.0, we’ve been adding state-of-the-art capabilities for solving large-scale optimization problems. In Version 12.2 we’ve continued to round out these capabilities.

One new thing is the superfunction ConvexOptimization, which automatically handles the full spectrum of linear, linear-fractional, quadratic, semidefinite and conic optimization—giving both optimal solutions and their dual properties. In 12.1 we added support for integer variables (i.e. combinatorial optimization); in 12.2 we’re also adding support for complex variables.

But the biggest new things for optimization in 12.2 are the introduction of robust optimization and of parametric optimization. Robust optimization lets you find an optimum that’s valid across a whole range of values of some of the variables. Parametric optimization lets you get a parametric function that gives the optimum for any possible value of particular parameters. So for example this finds the optimum for x, y for any (positive) value of α:

ParametricConvexOptimization
&#10005

ParametricConvexOptimization[(x - 1)^2 + 
  Abs[y], {(x + \[Alpha])^2 <= 1, x + y >= \[Alpha]}, {x, 
  y}, {\[Alpha]}]

Now evaluate the parametric function for a particular α:

%
&#10005

%[.76]

As with everything in the Wolfram Language, we’ve put a lot of effort into making sure that convex optimization integrates seamlessly into the rest of the system—so you can set up models symbolically, and flow their results into other functions. We’ve also included some very powerful convex optimization solvers. But particularly if you’re doing mixed (i.e. real+integer) optimization, or you’re dealing with really huge (e.g. 10 million variables) problems, we’re also giving access to other, external solvers. So, for example, you can set up your problem using Wolfram Language as your “algebraic modeling language”, then (assuming you have the appropriate external licenses) just by setting Method to, say, “Gurobi” or “Mosek” you can immediately run your problem with an external solver. (And, by the way, we now have an open framework for adding more solvers.)

Supporting Combinators and Other Formal Building Blocks

One can say that the whole idea of symbolic expressions (and their transformations) on which we rely so much in the Wolfram Language originated with combinators—which just celebrated their centenary on December 7, 2020. The version of symbolic expressions that we have in Wolfram Language is in many ways vastly more advanced and usable than raw combinators. But in Version 12.2—partly by way of celebrating combinators—we wanted to add a framework for raw combinators.

So now for example we have CombinatorS, CombinatorK, etc., rendered appropriately:

CombinatorS
&#10005

CombinatorS[CombinatorK]

But how should we represent the application of one combinator to another? Today we write something like:

f@g@h@x
&#10005

f@g@h@x

But in the early days of mathematical logic there was a different convention—that involved left-associative application, in which one expected “combinator style” to generate “functions” not “values” from applying functions to things. So in Version 12.2 we’re introducing a new “application operator” Application, displayed as (and entered as \[Application] or  ap ):

Application
&#10005

Application[f, Application[g, Application[h, x]]]

Application
&#10005

Application[Application[Application[f, g], h], x]

And, by the way, I fully expect Application—as a new, basic “constructor”—to have a variety of uses (not to mention “applications”) in setting up general structures in the Wolfram Language.

The rules for combinators are trivial to specify using pattern transformations in the Wolfram Language:

{CombinatorS
&#10005

{CombinatorS\[Application]x_\[Application]y_\[Application]z_ :> 
  x\[Application]z\[Application](y\[Application]z), 
 CombinatorK\[Application]x_\[Application]y_ :> x}

But one can also think about combinators more “algebraically” as defining relations between expressions—and there’s now a theory in AxiomaticTheory for that.

And in 12.2 a few more other theories have been added to AxiomaticTheory, as well as several new properties.

Euclidean Geometry Goes Interactive

One of the major advances in Version 12.0 was the introduction of a symbolic representation for Euclidean geometry: you specify a symbolic GeometricScene, giving a variety of objects and constraints, and the Wolfram Language can “solve” it, and draw a diagram of a random instance that satisfies the constraints. In Version 12.2 we’ve made this interactive, so you can move the points in the diagram around, and everything will (if possible) interactively be rearranged so as to maintain the constraints.

Here’s a random instance of a simple geometric scene:

RandomInstance
&#10005

RandomInstance[
 GeometricScene[{a, b, c, d}, {CircleThrough[{a, b, c}, d], 
   Triangle[{a, b, c}], d == Midpoint[{a, c}]}]]

If you move one of the points, the other points will interactively be rearranged so as to maintain the constraints defined in the symbolic representation of the geometric scene:

RandomInstance
&#10005

RandomInstance[
 GeometricScene[{a, b, c, d}, {CircleThrough[{a, b, c}, d], 
   Triangle[{a, b, c}], d == Midpoint[{a, c}]}]]

What’s really going on inside here? Basically, the geometry is getting converted to algebra. And if you want, you can get the algebraic formulation:

%
&#10005

%["AlgebraicFormulation"]

And, needless to say, you can manipulate this using the many powerful algebraic computation capabilities of the Wolfram Language.

In addition to interactivity, another major new feature in 12.2 is the ability to handle not just complete geometric scenes, but also geometric constructions that involve building up a scene in multiple steps. Here’s an example—that happens to be taken directly from Euclid:

RandomInstance
&#10005

RandomInstance[GeometricScene[
  {{\[FormalCapitalA], \[FormalCapitalB], \[FormalCapitalC], \
\[FormalCapitalD], \[FormalCapitalE], \[FormalCapitalF]}, {}},
  {
   GeometricStep[{Line[{\[FormalCapitalA], \[FormalCapitalB]}], 
     Line[{\[FormalCapitalA], \[FormalCapitalC]}]}, 
    "Define an arbitrary angle BAC."],
   GeometricStep[{\[FormalCapitalD] \[Element] 
      Line[{\[FormalCapitalA], \[FormalCapitalB]}], \[FormalCapitalE] \
\[Element] Line[{\[FormalCapitalA], \[FormalCapitalC]}], 
     EuclideanDistance[\[FormalCapitalA], \[FormalCapitalD]] == 
      EuclideanDistance[\[FormalCapitalA], \[FormalCapitalE]]}, 
    "Put D and E on AB and AC equidistant from A."], 
   GeometricStep[{Line[{\[FormalCapitalD], \[FormalCapitalE]}], 
     GeometricAssertion[{\[FormalCapitalA], \[FormalCapitalF]}, \
{"OppositeSides", Line[{\[FormalCapitalD], \[FormalCapitalE]}]}], 
     GeometricAssertion[
      Triangle[{\[FormalCapitalE], \[FormalCapitalF], \
\[FormalCapitalD]}], "Equilateral"], 
     Line[{\[FormalCapitalA], \[FormalCapitalF]}]}, 
    "Construct an equilateral triangle on DE."]
   }
  ]]

The first image you get is basically the result of the construction. And—like all other geometric scenes—it’s now interactive. But if you mouse over it, you’ll get controls that allow you to move to earlier steps:

RandomInstance
&#10005


Move a point at an earlier step, and you’ll see what consequences that has for later steps in the construction.

Euclid’s geometry is the very first axiomatic system for mathematics that we know about. So—2000+ years later—it’s exciting that we can finally make it computable. (And, yes, it will eventually connect up with AxiomaticTheory, FindEquationalProof, etc.)

But in recognition of the significance of Euclid’s original formulation of geometry, we’ve added computable versions of his propositions (as well as a bunch of other “famous geometric theorems”). The example above turns out to be proposition 9 in Euclid’s book 1. And now, for example, we can get his original statement of it in Greek:

Entity
&#10005

Entity["GeometricScene", "EuclidBook1Proposition9"]["GreekStatement"]

And here it is in modern Wolfram Language—in a form that can be understood by both computers and humans:

Entity
&#10005

Entity["GeometricScene", "EuclidBook1Proposition9"]["Scene"]

 

Yet More Kinds of Knowledge for the Knowledgebase

An important part of the story of Wolfram Language as a full-scale computational language is its access to our vast knowledgebase of data about the world. The knowledgebase is continually being updated and expanded, and indeed in the time since Version 12.1 essentially all domains have had data (and often a substantial amount) updated, or entities added or modified.

But as examples of what’s been done, let me mention a few additions. One area that’s received a lot of attention is food. By now we have data about more than half a million foods (by comparison, a typical large grocery store stocks perhaps 30,000 types of items). Pick a random food:

RandomEntity
&#10005

RandomEntity["Food"]

Now generate a nutrition label:

%
&#10005

%["NutritionLabel"]

As another example, a new type of entity that’s been added is physical effects. Here are some random ones:

RandomEntity
&#10005

RandomEntity["PhysicalEffect", 10]

And as an example of something that can be done with all the data in this domain, here’s a histogram of the dates when these effects were discovered:

DateHistogram
&#10005

DateHistogram[EntityValue["PhysicalEffect", "DiscoveryDate"], "Year", 
 PlotRange -> {{DateObject[{1700}, "Year", "Gregorian", -5.`], 
    DateObject[{2000}, "Year", "Gregorian", -5.`]}, Automatic}]

As another sample of what we’ve been up to, there’s also now what one might (tongue-in-cheek) call a “heavy-lifting” domain—weight-training exercises:

BenchPress
&#10005

Entity["WeightTrainingExercise", "BenchPress"]["Dataset"]

An important feature of the Wolfram Knowledgebase is that it contains symbolic objects, which can represent not only “plain data”—like numbers or strings—but full computational content. And as an example of this, Version 12.2 allows one to access the Wolfram Demonstrations Project—with all its active Wolfram Language code and notebooks—directly in the knowledgebase. Here are some random Demonstrations:

RandomEntity
&#10005

RandomEntity["WolframDemonstration", 5]

The values of properties can be dynamic interactive objects:

Entity
&#10005

Entity["WolframDemonstration", "MooreSpiegelAttractor"]["Manipulate"]

And because everything is computable, one can for example immediately make an image collage of all Demonstrations on a particular topic:

ImageCollage
&#10005

ImageCollage[
 EntityValue[
  EntityClass["WolframDemonstration", "ChemicalEngineering"], 
  "Thumbnail"]]

 

The Continuing Story of Machine Learning

It’s been nearly 7 years since we first introduced Classify and Predict, and began the process of fully integrating neural networks into the Wolfram Language. There’ve been two major directions: the first is to develop “superfunctions”, like Classify and Predict, that—as automatically as possible—perform machine-learning-based operations. The second direction is to provide a powerful symbolic framework to take advantage of the latest advances with neural nets (notably through the Wolfram Neural Net Repository) and to allow flexible continued development and experimentation.

Version 12.2 has progress in both these areas. An example of a new superfunction is FaceRecognize. Give it a small number of tagged examples of faces, and it will try to identify them in images, videos, etc. Let’s get some training data from web searches (and, yes, it’s somewhat noisy):

AssociationMap
&#10005

faces = Image[#, ImageSize -> 30] & /@ AssociationMap[Flatten[
     FindFaces[#, "Image"] & /@ 
      WebImageSearch["star trek " <> #]] &, {"Jean-Luc Picard", 
    "William Riker", "Phillipa Louvois", "Data"}]

Now create a face recognizer with this training data:

FaceRecognize
&#10005

recognizer = FaceRecognize[faces]

Now we can use this to find out who’s on screen in each frame of a video:

VideoMapList
&#10005

VideoMapList[recognizer[FindFaces[#Image, "Image"]] &, Video[URLDownload["https://ia802900.us.archive.org/7/items/2000-promo-for-star-trek-the-next-generation/2000%20promo%20for%20Star%20Trek%20-%20The%20Next%20Generation.ia.mp4"]]] /. 
 m_Missing \[RuleDelayed] "Other"

Now plot the results:

ListPlot
&#10005

ListPlot[Catenate[
  MapIndexed[{First[#2], #1} &, ArrayComponents[%], {2}]], Sequence[
 ColorFunction -> ColorData["Rainbow"], Ticks -> {None, 
Thread[{
Range[
Max[
ArrayComponents[rec]]], 
DeleteDuplicates[
Flatten[rec]]}]}]]

In the Wolfram Neural Net Repository there’s a regular stream of new networks being added. Since Version 12.1 about 20 new kinds of networks have been added—including many new transformer nets, as well as EfficientNet and for example feature extractors like BioBERT and SciBERT specifically trained on text from scientific papers.

In each case, the networks are immediately accessible—and usable—through NetModel. Something that’s updated in Version 12.2 is the visual display of networks:

NetModel
&#10005

NetModel["ELMo Contextual Word Representations Trained on 1B Word \
Benchmark"]

There are lots of new icons, but there’s also now a clear convention that circles represent fixed elements of a net, while squares represent trainable ones. In addition, when there’s a thick border in an icon, it means there’s an additional network inside, that you can see by clicking.

Whether it’s a network that comes from NetModel or your construct yourself (or a combination of those two), it’s often convenient to extract the “summary graphic” for the network, for example so you can put it in documentation or a publication. Information provides several levels of summary graphics:

Information
&#10005

Information[
 NetModel["CapsNet Trained on MNIST Data"], "SummaryGraphic"]

There are several important additions to our core neural net framework that broaden the range of neural net functionality we can access. The first is that in Version 12.2 we have native encoders for graphs and for time series. So, here, for example, we’re making a feature space plot of 20 random named graphs:

FeatureSpacePlot
&#10005

FeatureSpacePlot[GraphData /@ RandomSample[GraphData[], 20]]

Another enhancement to the framework has to do with diagnostics for models. We introduced PredictorMeasurements and ClassifierMeasurements many years ago to provide a symbolic representation for the performance of models. In Version 12.2—in response to many requests—we’ve made it possible to feed final predictions, rather than a model, to create a PredictorMeasurements object, and we’ve streamlined the appearance and operation of PredictorMeasurements objects:

PredictorMeasurements
&#10005

PredictorMeasurements[{3.2, 3.5, 4.6, 5}, {3, 4, 5, 6}]

An important new feature of ClassifierMeasurements is the ability to compute a calibration curve that compares the actual probabilities observed from sampling a test set with the predictions from the classifier. But what’s even more important is that Classify automatically calibrates its probabilities, in effect trying to “sculpt” the calibration curve:

Row
&#10005

Row[{
  First@ClassifierMeasurements[
    Classify[training, Method -> "RandomForest", 
     "Calibration" -> False], test, "CalibrationCurve"],
  "  \[LongRightArrow]  ",
  First@ClassifierMeasurements[
    Classify[training, Method -> "RandomForest", 
     "Calibration" -> True], test, "CalibrationCurve"]
  }]

Version 12.2 also has the beginning of a major update to the way neural networks can be constructed. The fundamental setup has always been to put together a certain collection of layers that expose what amount to array indices that are connected by explicit edges in a graph. Version 12.2 now introduces FunctionLayer, which allows you to give something much closer to ordinary Wolfram Language code. As an example, here’s a particular function layer:

FunctionLayer
&#10005

FunctionLayer[
 2*(#v . #m . {0.25, 0.75}) . NetArray[<|"Array" -> {0.1, 0.9}|>] & ]

And here’s the representation of this function layer as an explicit NetGraph:

NetGraph
&#10005

NetGraph[%]

v and m are named “input ports”. The NetArray—indicated by the square icons in the net graph—is a learnable array, here containing just two elements.

There are cases where it’s easier to use the “block-based” (or “graphical”) programming approach of just connecting together layers (and we’ve worked hard to ensure that the connections can be made as automatically as possible). But there are also cases where it’s easier to use the “functional” programming approach of FunctionLayer. For now, FunctionLayer supports only a subset of the constructs available in the Wolfram Language—though this already includes many standard array and functional programming operations, and more will be added in the future.

An important feature of FunctionLayer is that the neural net it produces will be as efficient as any other neural net, and can run on GPUs etc. But what can you do about Wolfram Language constructs that are not yet natively supported by FunctionLayer? In Version 12.2 we’re adding another new experimental function—CompiledLayer—that extends the range of Wolfram Language code that can be handled efficiently.

It’s perhaps worth explaining a bit about what’s happening inside. Our main neural net framework is essentially a symbolic layer that organizes things for optimized low-level implementation, currently using MXNet. FunctionLayer is effectively translating certain Wolfram Language constructs directly to MXNet. CompiledLayer is translating Wolfram Language to LLVM and then to machine code, and inserting this into the execution process within MXNet. CompiledLayer makes use of the new Wolfram Language compiler, and its extensive type inference and type declaration mechanisms.

OK, so let’s say one’s built a magnificent neural net in our Wolfram Language framework. Everything is set up so that the network can immediately be used in a whole range of Wolfram Language superfunctions (Classify, FeatureSpacePlot, AnomalyDetection, FindClusters, …). But what if one wants to use the network “standalone” in an external environment? In Version 12.2 we’re introducing the capability to export essentially any network in the recently developed ONNX standard representation.

And once one has a network in ONNX form, one can use the whole ecosystem of external tools to deploy it in a wide variety of environments. A notable example—that’s now a fairly streamlined process—is to take a full Wolfram Language–created neural net and run it in CoreML on an iPhone, so that it can for example directly be included in a mobile app.

Form Notebooks

What’s the best way to collect structured material? If you just want to get a few items, an ordinary form created with FormFunction (and for example deployed in the cloud) can work well. But what if you’re trying to collect longer, richer material?

For example, let’s say you’re creating a quiz where you want students to enter a whole sequence of complex responses. Or let’s say you’re creating a template for people to fill in documentation for something. What you need in these cases is a new concept that we’re introducing in Version 12.2: form notebooks.

A form notebook is basically a notebook that is set up to be used as a complex “form”, where the inputs in the form can be all the kinds of things that you’re used to having in a notebook.

The basic workflow for form notebooks is the following. First you author a form notebook, defining the various “form elements” (or areas) that you want the user of the form notebook to fill in. As part of the authoring process, you define what you want to have happen to the material the user of the form notebook enters when they use the form notebook (e.g. put the material in a Wolfram Data Drop databin, send the material to a cloud API, send the material as a symbolic expression by email, etc.).

After you’ve authored the form notebook, you then generate an active version that can be sent to whoever will be using the form notebook. Once someone has filled in their material in their copy of the deployed form notebook, they press a button, typically “Submit”, and their material is then sent as a structured symbolic expression to whatever destination the author of the form notebook specified.

It’s perhaps worth mentioning how form notebooks relate to something that sounds similar: template notebooks. In a sense, a template notebook is doing the reverse of a form notebook. A form notebook is about having a user enter material that will then be processed. A template notebook, on the other hand, is about having the computer generate material which will then be used to populate a notebook whose structure is defined by the template notebook.

OK, so how do you get started with form notebooks? Just go to File > New > Programmatic Notebook > Form Notebook Authoring:

Form notebooks

This is just a notebook, where you can enter whatever content you want—say an explanation of what you want people to do when they “fill out” the form notebook. But then there are special cells or sequences of cells in the form notebook that we call “form elements” and “editable notebook areas”. These are what the user of the form notebook “fills out” to enter their “responses”, and the material they provide is what gets sent when they press the “Submit” button (or whatever final action has been defined).

In the authoring notebook, the toolbar gives you a menu of possible form elements that you can insert:

Form notebooks

Let’s pick Input Field as an example:

Form notebooks

What does all this mean? Basically a form element is represented by a very flexible symbolic Wolfram Language expression, and this is giving you a way to specify the expression you want. You can give a label and a hint to put in the input field. But it’s with the Interpreter that you start to see the power of Wolfram Language. Because the Interpreter is what takes whatever the user of the form notebook enters in this input field, and interprets it as a computable object. The default is just to treat it as a string. But it could for example be a “Country” or a “MathExpression”. And with these choices, the material will automatically be interpreted as a country, math expression, etc., with the user typically being prompted if their input can’t be interpreted as specified.

There are lots of options about the details of how even an input field can work. Some of them are provided in the Add Action menu:

Form notebooks

But so what actually “is” this form element? Press the CODE tab on the left to see:

Form notebooks

What would a user of the form notebook see here? Press the PREVIEW tab to find out:

Form notebooks

Beyond input fields, there are lots of other possible form elements. There are things like checkboxes, radio buttons and sliders. And in general it’s possible to use any of the rich symbolic user interface constructs that exist in the Wolfram Language.

Once you’ve finishing authoring, you press Generate to generate a form notebook that is ready to be provided to users to be filled in. The Settings define things like how the “submit” action should be specified, and what should be done when the form notebook is submitted:

Form notebooks

So what is the “result” of a submitted form notebook? Basically it’s an association that says what was filled into each area of the form notebook. (The areas are identified by keys in the association that were specified when the areas were first defined in the authoring notebook.)

Let’s see how this works in a simple case. Here’s the authoring notebook for a form notebook:

Form notebooks

Here’s the generated form notebook, ready to be filled in (assuming you have 12.2):
Form notebooks

Here’s a sample of how the form notebook might be filled in:
Form notebooks

And this is what “comes back” when Submit is pressed:

Form notebooks

For testing, you can just have this association placed interactively in a notebook. But in practice it’s more common to send the association to a databin, store it in a cloud object, or generally put it in a more “centralized” location.

Notice that at the end of this example we have an editable notebook area—where you can enter free-form notebook content (with cells, headings, code, output, etc.) that will all be captured when the form notebook is submitted.

Form notebooks are very powerful idea, and you’ll see them used all over the place. As a first example, the various submission notebooks for the Wolfram Function Repository, Wolfram Demonstrations Project, etc. are becoming form notebooks. We’re also expecting a lot of use of form notebooks in educational settings. And as part of that, we’re building a system that leverages Wolfram Language for assessing responses in form notebooks (and elsewhere).

You can see the beginnings of this in Version 12.2 with the experimental function AssessmentFunction—which can be hooked into form notebooks somewhat like Interpreter. But even without the full capabilities planned for AssessmentFunction there’s still an incredible amount that can be done—in educational settings and otherwise—using form notebooks.

It’s worth understanding, by the way, that form notebooks are ultimately very simple to use in any particular case. Yes, they have a lot of depth that allows them to do a very wide range of things. And they’re basically only possible because of the whole symbolic structure of the Wolfram Language, and the fact that Wolfram Notebooks are ultimately represented as symbolic expressions. But when it comes to using them for a particular purpose they’re very streamlined and straightforward, and it’s completely realistic to create a useful form notebook in just a few minutes.

Yet More Notebookery

We invented notebooks—with all their basic features of hierarchical cells, etc.—back in 1987. But for a third of a century, we’ve been progressively polishing and streamlining how they work. And in Version 12.2 there are all sorts of useful and convenient new notebook features.

Click to Copy

It’s a very simple feature, but it’s very useful. You see something in a notebook, and all you really want to be able to do with it is copy it (or perhaps copy something related to it). Well, then just use ClickToCopy:

ClickToCopy
&#10005

ClickToCopy[10!]

If you want to click-to-copy something unevaluated, use Defer:

ClickToCopy
&#10005

ClickToCopy[Plot[Sin[x], {x, 0, 10}], Defer[Plot[Sin[x], {x, 0, 10}]]]

Streamlined Hyperlinking (and Hyperlink Editing)

++h has inserted a hyperlink in a Wolfram Notebook since 1996. But in Version 12.2 there are two important new things with hyperlinks. First, automatic hyperlinking that handles a wide range of different situations. And second, a modernized and streamlined mechanism for hyperlink creation and editing.

Hyperlink creation and editing

Attached Cells

In Version 12.2 we’re exposing something that we’ve had internally for a while: the ability to attach a floating fully functional cell to any given cell (or box, or whole notebook). Accessing this feature needs symbolic notebook programming, but it lets you do very powerful things—particularly in introducing contextual and “just-in-time” interfaces. Here’s an example that puts a dynamic counter that counts in primes on the right-bottom part of the cell bracket:

AttachCell
&#10005

obj=AttachCell[EvaluationCell[],Panel[Dynamic[i]],{"CellBracket",Bottom},0,{Right,Bottom}];
Do[PrimeQ[i],{i,10^7}];
NotebookDelete[obj]

Template Box Infrastructure

Sometimes it’s useful for what you see not to be what you have. For example, you might want to display something in a notebook as J0(x) but have it really be BesselJ[0, x]. For many years, we’ve had Interpretation as a way to set this up for specific expressions. But we’ve also had a more general mechanism—TemplateBox—that lets you take expressions, and separately specify how they should be displayed, and interpreted.

In Version 12.2 we’ve further generalized—and streamlined—TemplateBox, allowing it to incorporate arbitrary user interface elements, as well as allowing it to specify things like copy behavior. Our new TEX input mechanism, for example, is basically just an application of the new TemplateBox.

In this case, "TeXAssistantTemplate" refers to a piece of functionality defined in the notebook stylesheet—whose parameters are specified by the association given in the TemplateBox:

RawBoxes
&#10005

RawBoxes[TemplateBox[<|
   "boxes" -> FormBox[FractionBox["1", "2"], TraditionalForm], 
   "errors" -> {}, "input" -> "\\frac{1}{2}", "state" -> "Boxes"|>, 
  "TeXAssistantTemplate"]]

 

The Desktop Interface to the Cloud

An important feature of Wolfram Notebooks is that they’re set up to operate both on the desktop and in the cloud. And even between versions of Wolfram Language there’s lots of continued enhancement in the way notebooks work in the cloud. But in Version 12.2 there’s been some particular streamlining of the interface for notebooks between desktop and cloud.

A particularly nice mechanism already available for a couple of years in any desktop notebook is the File > Publish to Cloud menu item, which allows you to take the notebook and immediately make it available as a published cloud notebook that can be accessed by anyone with a web browser. In Version 12.2 we’ve streamlined the process of notebook publishing.

When I’m giving a presentation I’ll usually be creating a desktop notebook as I go (or perhaps using one that already exists). And at the end of the presentation, it’s become my practice to publish it to the cloud, so anyone in the audience can interact with it. But how can I give everyone the URL for the notebook? In a virtual setting, you can just use chat. But in an actual physical presentation, that’s not an option. And in Version 12.2 we’ve provided a convenient alternative: the result of Publish to Cloud includes a QR code that people can capture with their phones, then immediately go to the URL and interact with the notebook on their phones.

Publish to cloud

There’s one other notable new item visible in the result of Publish to Cloud: “Direct JavaScript Embedding”. This is a link to the Wolfram Notebook Embedder which allows cloud notebooks to be directly embedded through JavaScript onto webpages.

It’s always easy to use an iframe to embed one webpage on another. But iframes have many limitations, such as requiring their sizes to be defined in advance. The Wolfram Notebook Embedder allows full-function fluid embedding of cloud notebooks—as well as scriptable control of the notebooks from other elements of a webpage. And since the Wolfram Notebook Embedder is set up to use the oEmbed embedding standard, it can immediately be used in basically all standard web content management systems.

We’ve talked about sending notebooks from the desktop to the cloud. But another thing that’s new in Version 12.2 is faster and easier browsing of your cloud file system from the desktop—as accessed from File > Open from Cloud and File > Save to Cloud.

Save to cloud

Cryptography & Security

One of the things we want to do with Wolfram Language is to make it as easy as possible to connect with pretty much any external system. And in modern times an important part of that is being able to conveniently handle cryptographic protocols. And ever since we started introducing cryptography directly into the Wolfram Language five years ago, I’ve been surprised at just how much the symbolic character of the Wolfram Language has allowed us to clarify and streamline things to do with cryptography.

A particularly dramatic example of this has been how we’ve been able to integrate blockchains into Wolfram Language (and Version 12.2 adds bloxberg with several more on the way). And in successive versions we’re handling different applications of cryptography. In Version 12.2 a major emphasis is symbolic capabilities for key management. Version 12.1 already introduced SystemCredential for dealing with local “keychain” key management (supporting, for example, “remember me” in authentication dialogs). In 12.2 we’re also dealing with PEM files.

If we import a PEM file containing a private key we get a nice, symbolic representation of the private key:

private = First
&#10005

private = First[Import["ExampleData/privatesecp256k1.pem"]]

Now we can derive a public key:

public = PublicKey
&#10005

public = PublicKey[%]

If we generate a digital signature for a message using the private key

GenerateDigitalSignature
&#10005

GenerateDigitalSignature["Hello there", private]

then this verifies the signature using the public key we’ve derived:

VerifyDigitalSignature
&#10005

VerifyDigitalSignature[{"Hello there", %}, public]

An important part of modern security infrastructure is the concept of a security certificate—a digital construct that allows a third party to attest to the authenticity of a particular public key. In Version 12.2 we now have a symbolic representation for security certificates—providing what’s needed for programs to establish secure communication channels with outside entities in the same kind of way that https does:

Import
&#10005

Import["ExampleData/client.pem"]

 

Just Type SQL

In Version 12.0 we introduced powerful functionality for querying relational databases symbolically within the Wolfram Language. Here’s how we connect to a database:

db = DatabaseReference
&#10005

db = DatabaseReference[
  FindFile["ExampleData/ecommerce-database.sqlite"]]

Here’s how we connect the database so that its tables can be treated just like entity types from the built-in Wolfram Knowledgebase:

EntityRegister
&#10005

EntityRegister[EntityStore[RelationalDatabase[db]]]

Now we can for example ask for a list of entities of a given type:

EntityList
&#10005

EntityList["offices"]

What’s new in 12.2 is that we can conveniently go “under” this layer, to directly execute SQL queries against the underlying database, getting the complete database table as a Dataset expression:

ExternalEvaluate
&#10005

ExternalEvaluate[db, "SELECT * FROM offices"]

These queries can not only read from the database, but also write to it. And to make things even more convenient, we can effectively treat SQL just like any other “external language” in a notebook.

First we have to register our database, to say what we want our SQL to be run against:

RegisterExternalEvaluator
&#10005

RegisterExternalEvaluator["SQL", db]

And now we can just type SQL as input—and get back Wolfram Language output, directly in the notebook:

Type SQL as input

Microcontroller Support Goes 32-Bit

You’ve developed a control system or signal processing in Wolfram Language. Now how do you deploy it to a piece of standalone electronics? In Version 12.0 we introduced the Microcontroller Kit for compiling from symbolic Wolfram Language structures directly to microcontroller code.

We’ve had lots of feedback on this, asking us to expand the range of microcontrollers that we support. So in Version 12.2 I’m happy to say that we’re adding support for 36 new microcontrollers, particularly 32-bit ones:

Supported microcontrollers

Here’s an example in which we deploy a symbolically defined digital filter to a particular kind of microcontroller, showing the simplified C source code generated for that particular microcontroller:

Needs
&#10005

Needs["MicrocontrollerKit`"]

ToDiscreteTimeModel
&#10005

ToDiscreteTimeModel[ButterworthFilterModel[{3, 2}], 0.6] // Chop

MicrocontrollerEmbedCode
&#10005

MicrocontrollerEmbedCode[%, <|"Target" -> "AdafruitGrandCentralM4", 
   "Inputs" -> 0 -> "Serial", "Outputs" -> 1 -> "Serial"|>, 
  "/dev/cu.usbmodem14101"]["SourceCode"]

 

WSTPServer: A New Deployment of Wolfram Engine

Our long-term goal is to make the Wolfram Language and the computational intelligence it provides as ubiquitous as possible. And part of doing this is to set up the Wolfram Engine which implements the language so that it can be deployed in as broad a range of computational infrastructure settings as possible.

Wolfram Desktop—as well as classic Mathematica—primarily provides a notebook interface to the Wolfram Engine, running on a local desktop system. It’s also possible to run Wolfram Engine directly—as a command-line program (e.g. through WolframScript)—on a local computer system. And, of course, one can run the Wolfram Engine in the cloud, either through the full Wolfram Cloud (public or private), or through more lightweight cloud and server offerings (both existing and forthcoming).

But with Version 12.2 there’s a new deployment of the Wolfram Engine: WSTPServer. If you use Wolfram Engine in the cloud, you’re typically communicating with it through http or related protocols. But for more than thirty years, the Wolfram Language has had its own dedicated protocol for transferring symbolic expressions and everything around them. Originally we called it MathLink, but in more recent years, as it’s progressively been extended, we’ve called it WSTP: the Wolfram Symbolic Transfer Protocol. What WSTPServer does, as its name suggests, is to give you a lightweight server that delivers Wolfram Engines and lets you communicate with them directly in native WSTP.

Why is this important? Basically because it gives you a way to manage pools of persistent Wolfram Language sessions that can operate as services for other applications. For example, normally each time you call WolframScript you get a new, fresh Wolfram Engine. But by using wolframscript -wstpserver with a particular “WSTP profile name” you can keep getting the same Wolfram Engine every time you call WolframScript. You can do this directly on your local machine—or on remote machines.

And an important use of WSTPServer is to expose pools of Wolfram Engines that can be accessed through the new RemoteEvaluate function in Version 12.2. It’s also possible to use WSTPServer to expose Wolfram Engines for use by ParallelMap, etc. And finally, since WSTP has (for nearly 30 years!) been the way the notebook front end communicates with the Wolfram Engine kernel, it’s now possible to use WSTPServer to set up a centralized kernel pool to which you can connect the notebook front end, allowing you, for example, to keep running a particular session (or even a particular computation) in the kernel even as you switch to a different notebook front end, on a different computer.

RemoteEvaluate: Compute Someplace Else…

Along the lines of “use Wolfram Language everywhere” another new function in Version 12.2 is RemoteEvaluate. We’ve got CloudEvaluate which does a computation in the Wolfram Cloud, or an Enterprise Private Cloud. We’ve got ParallelEvaluate which does computations on a predefined collection of parallel subkernels. And in Version 12.2 we’ve got RemoteBatchSubmit which submits batch computations to cloud computation providers.

RemoteEvaluate is a general, lightweight “evaluate now” function that lets you do a computation on any specified remote machine that has an accessible Wolfram Engine. You can connect to the remote machine using ssh or wstp (or http with a Wolfram Cloud endpoint).

RemoteEvaluate
&#10005

RemoteEvaluate["ssh://byblis67.wolfram.com", 
 Labeled[Framed[$MachineName], Now]]

Sometimes you’ll want to use RemoteEvaluate to do things like system administration across a range of machines. Sometimes you might want to collect or send data to remote devices. For example, you might have a network of Raspberry Pi computers which all have Wolfram Engine—and then you can use RemoteEvaluate to do something like retrieve data from these machines. By the way, you can also use ParallelEvaluate from within RemoteEvaluate, so you’re having a remote machine be the master for a collection of parallel subkernels.

Sometimes you’ll want RemoteEvaluate to start a fresh instance of Wolfram Engine whenever you do an evaluation. But with WSTPServer you can also have it use a persistent Wolfram Language session. RemoteEvaluate and WSTPServer are the beginning of a general symbolic framework for representing running Wolfram Engine processes. Version 12.2 already has RemoteKernelObject and $DefaultRemoteKernel which provide symbolic ways to represent remote Wolfram Language instances.

And Yet More (AKA “None of the Above”)

I’ve at least touched on many of the bigger new features of Version 12.2. But there’s a lot more. Additional functions, enhancements, fixes and general rounding out and polishing.

Like in computational geometry, ConvexHullRegion now deals with regions, not just points. And there are functions like CollinearPoints and CoplanarPoints that test for collinearity and coplanarity, or give conditions for achieving them.

There are more import and export formats. Like there’s now support for the archive formats: “7z”, “ISO”, “RAR”, “ZSTD”. There’s also FileFormatQ and ByteArrayFormatQ for testing whether things correspond to particular formats.

In terms of core language, there are things like updates to the complicated-to-define ValueQ. There’s also RandomGeneratorState that gives a symbolic representation of random generator states.

In the desktop package (i.e. .wl file) editor, there’s a new (somewhat experimental) Format Cell button, that reformats code—with a control on how “airy” it should be (i.e. how dense it should be in newlines).

In Wolfram|Alpha-Mode Notebooks (as used by default in Wolfram|Alpha Notebook Edition) there are other new features, like function documentation targeted for particular function usage.

There’s also more in TableView, as well as a large suite of new paclet authoring tools that are included on an experimental basis.

To me it’s rather amazing how much we’ve been able to bring together in Version 12.2, and, as always, I’m excited that it’s now out and available to everyone to use….

Stephen Wolfram (2020), "Launching Version 12.2 of Wolfram Language & Mathematica: 228 New Functions and Much More…," Stephen Wolfram Writings. writings.stephenwolfram.com/2020/12/launching-version-12-2-of-wolfram-language-mathematica-228-new-functions-and-much-more.
Text
Stephen Wolfram (2020), "Launching Version 12.2 of Wolfram Language & Mathematica: 228 New Functions and Much More…," Stephen Wolfram Writings. writings.stephenwolfram.com/2020/12/launching-version-12-2-of-wolfram-language-mathematica-228-new-functions-and-much-more.
CMS
Wolfram, Stephen. "Launching Version 12.2 of Wolfram Language & Mathematica: 228 New Functions and Much More…." Stephen Wolfram Writings. December 16, 2020. writings.stephenwolfram.com/2020/12/launching-version-12-2-of-wolfram-language-mathematica-228-new-functions-and-much-more.
APA
Wolfram, S. (2020, December 16). Launching version 12.2 of Wolfram Language & Mathematica: 228 new functions and much more…. Stephen Wolfram Writings. writings.stephenwolfram.com/2020/12/launching-version-12-2-of-wolfram-language-mathematica-228-new-functions-and-much-more.

Posted in: Mathematica, New Technology, Wolfram Language

6 comments

  1. Congratulations to ALL Wolfram Tem!!

  2. Congrats! Looking forward to Apple Silicon version

  3. I can see how the new functionality of Import[] can be used to build handy utility functions for, e.g., chasing up references in (arXiv) papers. In physics the common referencing style omits the paper’s title; the example code “WebImage /@ Take[Flatten[Values[%]], -2]” shows how a look at the web page gives more useful information (Title, Abstract). Just one example of the increasing power and functionality in 12.2. Congratulations to the whole Wolfram team.
    Barrie

  4. According to most of the documentation, Ctrl-$ was previously assigned to inputting Underscripts, and now it’s assigned to inputting TeX as described in the Just Type TEX section above. What am I missing, and how do I resolve this inconsistency?
    I frequently use Underscripts to type limits and would like to retain the old functionality.

    • Thanks for bringing this to our attention. The new shortcut is Ctrl+Shift+, (comma). This and other shortcuts are visible under Insert > Typesetting > … Although the keyboard shortcut was updated in the menus and in some 12.2 documentation, several documentation references were overlooked. We believe all documentation references should be updated in the upcoming 12.3 release, and in the online documentation at reference.wolfram.com once 12.3 ships.

  5. I’m glad that you are still working on improving the hyperlink UI, but you STILL have not fixed an essential part of this:
    When I print a Notebook to PDF (using macOS 11.4 Print Dialog Box and selecting “Save as PDF”, the hyperlinks are not printed in any sort of user-visible fashion, either in blue or underlined or whatever. And there appears to be no way to change this.
    The links are preserved, in the sense that clicking them in the PDF behaves as expected. But this does the reader precious little good if it’s not obvious that the link can be clicked!