WOLFRAM

49 What We Haven’t Discussed

There’s a lot more to the Wolfram Language than we’ve been able to cover in this book. Here’s a sampling of just a few of the many topics and areas that we’ve missed.

User Interface Construction

Set up a tabbed interface:
TabView[Table[ListPlot[Range[20]^n], {n, 5}]]
 
User interfaces are just another type of symbolic expression; make a grid of sliders:
Grid[Table[Slider[], 4, 3]]
 

Function Visualization

Plot a function:
Plot[Sin[x] + Sin[Sqrt[2] x], {x, 0, 20}]
 
3D contour plot:
ContourPlot3D[x^3 + y^2 - z^2, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}]
 

Mathematical Computation

Do symbolic computations, with x as an algebraic variable:
Factor[x^10 - 1]
 
Get symbolic solutions to equations:
Solve[x^3 - 2 x + 1 == 0, x]
 
Do calculus symbolically:
Integrate[Sqrt[x + Sqrt[x]], x]
 
Display results in traditional mathematical form:
Integrate[AiryAi[x], x] // TraditionalForm
 
Use 2D notation for input:
\!\( \*UnderoverscriptBox[\(\[Sum]\), \(i = 0\), \(n\)] \*FractionBox[\(Binomial[n, i]\ \(i!\)\), \(\((n + 1 + i)\)!\)]\)
 

Numerics

Minimize a function inside a spherical ball:
NMinimize[{x^4 + y^4 - z/(x + 1), y > 0}, {x, y, z} \[Element] Ball[ ]]
 
NDSolve[{y''[x] + Sin[y[x]] y[x] == 0, y[0] == 1, y'[0] == 0}, y, {x, 0, 30}]
 
Make a plot using the approximate function:
Plot[Evaluate[{y[x], y'[x], y''[x]} /. %], {x, 0, 30}]
 

Geometry

The area of a disk (filled circle) of radius r:
Area[Disk[{0, 0}, r]]
 
Find a circle going through three points:
CircleThrough[{{0, 0}, {1, 0}, {0, 1}}]
 
Make a shape by “shrinkwrapping” around 100 random points in 3D:
ConvexHullMesh[RandomReal[1, {100, 3}]]
 
FindDistribution[StringLength[WordList[]]]
 

Algorithms

Find the shortest tour of the capitals of Europe (traveling salesman problem):
With[{c = EntityValue[EntityClass["Country", "Europe"], EntityProperty["Country", "CapitalLocation"]]}, GeoListPlot[c[[Last@FindShortestTour[c]]], Joined -> True]]
 
Factor a big number:
FactorInteger[2^255 - 1]
 

Logic

Make a truth table:
BooleanTable[p || q && (p || ! q), {p}, {q}] // Grid
 
Find a minimal representation of a Boolean function:
BooleanMinimize[ BooleanCountingFunction[{2, 3}, {a, b, c, d}]] // TraditionalForm
 

The Computational Universe

Run my favorite example of a very simple program with very complex behavior:
ArrayPlot[CellularAutomaton[30, {{1}, 0}, 200]]
 
RulePlot shows the underlying rule:
RulePlot[CellularAutomaton[30]]
 

Chemical & Biological Computation

Enter a specification of a molecule:
Molecule["CC(CC)CC"]
 
Make a 3D representation of the molecule:
MoleculePlot3D[Molecule["CC(CC)CC"]]
 
BioSequence["AAGGT"]
 
Draw the corresponding molecule:
MoleculePlot[BioSequence["AAGGT"]]
 

Building APIs

Deploy a simple web API that finds the distance from a specified location:
CloudDeploy[ APIFunction[{"loc" -> "Location"}, GeoDistance[#loc, Here] &]]
 
Create embeddable code for an external Java program to call the API:
EmbedCode[%, "Java"]
 

Document Generation

Documents are symbolic expressions, like everything else:
DocumentNotebook[{Style["A Circle", "Section"], Style["How to make a circle"], Graphics[Circle[]]}]
 

Evaluation Control

Hold a computation unevaluated:
Hold[2 + 2 == 4]
 
Release the hold:
ReleaseHold[%]
 

Systems-Level Operations

Run an external process (not allowed in the cloud!):
RunProcess["ps", "StandardOutput"]
 
Encrypt anything:
Encrypt["sEcreTkey", "Read this if you can!"]
 

Parallel Computation

I’m running on a 28-core machine:
$ProcessorCount
 
Sequentially test a sequence of (big) numbers for primality, and find the total time taken:
Table[PrimeQ[2^Prime[n] - 1], {n, 500}] // Counts // AbsoluteTiming
 
Doing the same thing in parallel takes considerably less time:
ParallelTable[PrimeQ[2^Prime[n] - 1], {n, 500}] // Counts // AbsoluteTiming
 
Next Section