New Features of Mathematica 7

Rolf Mertig
rolfm@gluonvision.com

Outline

General News

Mathematics and Algorithm News

Core news

Parallel Computing with Mathematica

Accessing Integrated Data Sources

Final Thoughts

General News

Kernel & FrontEnd changes

New Help

New Palettes

New Functions and Options

Length[Names["System`*"]]

In Mathematica 6.0.3:  2959

Mathematics and Algorithm News

Product

?Product

Product[g[i],i]

DiscreteRatio is the inverse for indefinite products:

DiscreteRatio[Product[f[i],i],i]

Product[DiscreteRatio[f[i],i],i]

Sum

?Sum

Sum[i^3,i]

(∑_(i=1)^n)(1/(i^r))

Sum[(n^2) HarmonicNumber[n],{n, m}]

f[m_]=Sum[(n^(-2)) HarmonicNumber[n],{n, m}]

f[3]

DifferenceRoot

?DifferenceRoot

Define Pell numbers:

PellNumber=DifferenceRoot[Function[{y,n},{-y[n]-2y[1+n]+y[2+n]==0,y[0]==0,y[1]==1}]];

Table[PellNumber[n],{n,0,10}]

DifferenceDelta, DiscreteShift,DiscreteRatio

?DifferenceDelta

?DiscreteShift

?DiscreteRatio

GeneratingFunction

?GeneratingFunction

The generating function for the sequence whose n(^th) term is 1:

GeneratingFunction[1,n,x]

All coefficients in the series are 1:

Series[%,{x,0,10}]

Univariate generating function:

GeneratingFunction[(1/((n!)^2)),n,x]

Multivariate:

GeneratingFunction[(1/((n+1)! m!)),{n,m},{x,y}]

SumConvergence

?SumConvergence

Options@SumConvergence

Basic Examples  (2)

Test for convergence of the sum (∑_n^∞)(1/n):

SumConvergence[1/n,n]

Test the convergence of (∑_n^∞)(((3^n) (n^2))/(n!)):

SumConvergence[3^n n^2/n!,n]

Find the condition for convergence of (∑_n^∞)(1/(n^α)):

SumConvergence[1/n^α,n]

Casoratian

?Casoratian

The Casoratian determinant is defined as: Det[Table[DiscreteShift[(Subscript[y, i]),{n,j}],{i,m},{j,0,m-1}]].

Linear independence of the functions (Subscript[y, 1]),(Subscript[y, 2]),… is equivalent to the vanishing of the Casoratian.

The following sequences are linearly dependent:

Casoratian[{2^n,2^(n+3)},n]

ZTransform

?ZTransform

FindSequenceFunction

?FindSequenceFunction

FindSequenceFunction[{1,2,3,5,17,305,34865,24918065,125436246065,5056710181206065},n]

New Special Functions »

AngerJ  ▪  WeberE  ▪  DawsonF  ▪  BarnesG  ▪  LogBarnesG

HurwitzZeta  ▪  HurwitzLerchPhi  ▪  Haversine  ▪  InverseHaversine

Core News

Gather

?Gather

Gather[{a,b,a,c,d,c}]

Gather elements that have equal integer parts:

Gather[Range[0,3,1/3],Floor[#1]==Floor[#2]&]

GatherBy

?GatherBy

GatherBy[{1,2,3,4,5},OddQ]

GatherBy[{a,b,c,d,e,d,a}]

data=Transpose[{RandomReal[5,10],RandomChoice[{a,b,c},10],RandomReal[10,10]}]

Group elements based on the value of the second element:

gathered=GatherBy[data,#[[2]]&]

SplitBy

Tuples[{1,2},3]

SplitBy[%,First]

DeleteDuplicates

?DeleteDuplicates

DeleteDuplicates[{1,7,8,4,3,4,1,9,9,2}]

ArrayPad

?ArrayPad

ArrayPad[{a,b,c,d},1]

ArrayPad[{{1,2},{3,4}},2] // MatrixForm

Ratios

?Ratios

Ratios[{a,b,c,d,e}]

Second ratios:

Ratios[{a,b,c,d,e},2]

Quiet

Quiet[1/0]

({{, Quiet[expr,"name"]
quietens only the named group of messages.}})

$MessageGroups

$MessageGroups

$MessageGroups[[All,1]]

Applications:

Check for unpacking of arrays:

On["Packing"]

This produces rational numbers and has to unpack:

Range[5]/2

Using inexact numbers leaves the array packed:

Range[5]/2.

Off["Packing"]

Quiet the compiler warnings that allow the evaluation to proceed:

Quiet[Compile[{x},Log[10.,x]][1.*^1000],"Compiler"]

Parallel Computing with Mathematica

Mathematica 7 features built-in parallel computing capabilities.

Parallelize

Parallelize will automatically parallelize a computation, if possible.

Parallelize[(∑_(i=1)^250)i!]

Otherwise, it will perform a serial computation.

Parallelize[∫((1+x^4)/(x^9+3x))\[DifferentialD]x]

Parallel Computing with Mathematica

Scalable parallelization

Parallel computing scales across your available local 
cores or remote cores. Let's take six really large numbers.

nums={2949139351597575118259944040385088406471149304313950803916170,2745201680660241417682118990009429336956428174177365148868001,2233795066652699157538868797967201925661196164476818038296004,1811407300094750906313647154418422327145787739155366439445521,2945655125896943888734546306600095101787359723357126960817429,1993289517437145602616895020850006297493179390622764388547884};

And now we'll ask Mathematica to factor them using two different methods:

   1. Serial processing.
   2. Parallel processing.

Map[FactorInteger,nums]//AbsoluteTiming

Parallelize[Map[FactorInteger,nums]]//AbsoluteTiming

Grid[{
{Style["# of cores",FontFamily->"Arial",Bold],Style["Time elapsed",FontFamily->"Arial",Bold]},
{Style["1",FontFamily->"Arial"],Style["17.9487 sec",FontFamily->"Arial"]},
{Style["2",FontFamily->"Arial"],Style["14.1600 sec",FontFamily->"Arial"]},
{Style["4",FontFamily->"Arial"],Style["xx.xxxx sec",FontFamily->"Arial"]},
{Style["8",FontFamily->"Arial"],Style["xx.xxxx sec",FontFamily->"Arial"]},
{Style["16",FontFamily->"Arial"],Style["xx.xxxx sec",FontFamily->"Arial"]}

},
Dividers->{None,{2->Black}},Frame->{{11,2}->True},
Alignment->{{Left,Right}}]

Parallel Computing with Mathematica

ParallelTry

We can use ParallelTry to send multiple evaluations 
to kernels; this is useful when you want to pick a particular type of method, 
for example, but don't know which is the most efficient.

AbsoluteTiming[ParallelTry[
{#,FindMinimum[(E^(Sin[50 x]))+Sin[60 (E^y)]+Sin[70 Sin[x]]+Sin[Sin[80 y]]-Sin[10 (x+y)]+(1/4) ((x^2)+(y^2)),{x,y},Method->#]}&,{"Gradient","ConjugateGradient","InteriorPoint","QuasiNewton","Newton"}]]

Distributing function definitions

We can also define a function, distribute its 
definitions to the worker kernels, and then parallelize a computation.

factorsLength[n_]:=Length[FactorInteger[n]];
DistributeDefinitions[factorsLength]

Table[With[{n=n},ParallelSubmit[Length[FactorInteger[(10^n-1)/9]]]],{n,Range[45,64]}]

WaitAll[%]

Mathematica as a Programming Language

Wolfram Workbench

The Wolfram Workbench provides a powerful integrated development environment (IDE) that 
allows you to debug Mathematica code. Additionally, you can debug and work with mixed platform 
environments, such as Java, JLink, and gridMathematica.

Working with Data

Physical and chemical data:
	elements, isotopes, 
chemicals, particles

Row[{
Style[IsotopeData["Uranium235","FullSymbol"],FontFamily->"Arial",FontSize->"Large"],
Text["     "],
ChemicalData["Hexane"],
ChemicalData["Caffeine","MoleculePlot"],
Text["     "],
Style[ParticleData["BStarZeroBar","Symbol"],FontFamily->"Arial",FontSize->"Large"]
}]

Financial, economic, and sociological data

Row[{
DateListPlot[FinancialData["GOOG","2004"],Filling->Bottom,Joined->True,PlotLabel->"Stock ticker: GOOG"],
Text["         "],
DateListPlot[CountryData["France",{{"GDP"},{1970,2005}}],PlotLabel->"GDP of France"]
}]

Life sciences:
	genomes, proteins

Row[{
ProteinData["A2M","MoleculePlot"],
ProteinData["SERPINA3","MoleculePlot"]
}]

Mathematics:
	finite groups, graphs, knots, 
lattices, polyhedra

Row[{Style[Grid[FiniteGroupData["Quaternion","MultiplicationTable"]],FontFamily->"Arial",FontSize->Medium],
KnotData[{6,1}],
LatticeData["FaceCenteredCubic","Image"],
PolyhedronData["PentagonalHexecontahedron"]
}]

Geographical, meteorological, and astronomical data:

	weather, geodesy, cities, countries, astronomical objects

Row[{
CountryData["UnitedStates","Shape"],
AstronomicalData["Earth","Image"]
}]

Working with Data

Chemical and Physical Data Sources

ChemicalData

Get information about chemicals.

ChemicalData["Hexane"]

Row[{
Style[IsotopeData["Uranium235","FullSymbol"],FontFamily->"Arial",FontSize->"Large"],
"       ",
ChemicalData["Hexane"],
ChemicalData["Caffeine","MoleculePlot"],
Style[ParticleData["BStarZeroBar","Symbol"],FontFamily->"Arial",FontSize->"Large"]
}]

Look up all information about a specific chemical.

ChemicalData["Caffeine","Properties"]

A more advanced example...a decay network for 
Uranium-235.

DaughterNuclides[s_List]:=DeleteCases[Union[Join@@(IsotopeData[#1,"DaughterNuclides"]&)/@DeleteCases[s,_Missing]],_Missing]

ReachableNuclides[s_List]:=FixedPoint[Union[Join[#1,DaughterNuclides[#1]]]&,s]

DecayNetwork[iso_List]:=Join@@(Thread[#1->DaughterNuclides[{#1}]]&)/@ReachableNuclides[iso]

U235Decay=Map[IsotopeData[#1,"Symbol"]&,DecayNetwork[{"Uranium235"}],{2}]

Draw the graph.

LayeredGraphPlot[U235Decay,VertexLabeling->True]

Working with Data

Financial, Economic, and Sociological Data

FinancialData

Get current information about a particular stock or 
financial instrument.

FinancialData["GOOG"]

Data is delivered in a way that allows you to immediately feed it 
into other parts of Mathematica.

GraphicsRow[{
DateListPlot[FinancialData["IBM","2008"],Filling->Bottom,Joined->True,PlotLabel->"Stock: IBM 2008-today"],
DateListPlot[CountryData["Poland",{{"GDP"},{1990,2008}}],PlotLabel->"GDP of Poland"],
DateListPlot[CountryData["Germany",{{"GDP"},{1990,2008}}],PlotLabel->"GDP of Germany"]
},ImageSize->1000]

DateListPlot[FinancialData["GOOG","2005"],Filling->Bottom,Joined->True,FrameLabel->"Google stock"]

CountryData

Get information about a particular country.

CountryData["Greece","Shape"]

An incredible amount of properties are available.

CountryData["Greece","Properties"]

A more advanced example...plotting GDP vs. 
population.

Clear[lp,data]

data=(Tooltip[{CountryData[#1,"Population"],CountryData[#1,"GDP"]},CountryData[#1,"Name"]]&)/@CountryData[];
data=DeleteCases[data,Tooltip[{___,_Missing,___},_]];

Fit the logarithms to a line and show on the graph.

fit=Fit[Log[data[[All,1]]],{1,lp},lp]

Show the data and fit.

plot=ListLogLogPlot[data,AxesLabel->{"Population","GDP"}];Show[plot,Plot[fit,{lp,Log[(10^3)],Log[(10^9)]}],ImageSize->800]

Working with Data

Life Sciences Data Sources

ProteinData

Get information about proteins.

ProteinData[]

(*ProteinData["SERPINA3","MoleculePlot"]*)

ProteinData["NAT1","MolecularWeight"]

ProteinData["NAT1","Name"]

ProteinData["NAT1","BiologicalProcesses"]

GenomeData

Get a list of genes Mathematica knows about.

GenomeData[]

We can choose a particular gene and look up 
properties about it.

GenomeData["ZXDB","Chromosome"]

GenomeData["ZXDB","Name"]

Find the positions of a DNA sequence fragment:

(*GenomeLookup["CTCTCTAACTAAACT"]*)

Working with Data

Mathematical Data Sources

GraphData

Get information about graphs.

GraphData["PetersenGraph"]

Now we can look at some properties...

GraphData["PetersenGraph","Cubic"]

GraphData["PetersenGraph","Spectrum"]

GraphData["PetersenGraph","CycleCount"]

GraphData["PetersenGraph","AllImages"]

{,,,,,,,}

Working with Data

Geographical, Meteorological, and Astronomical Data 
Sources

WeatherData

Get weather information for a particular weather 
station.

(wd=WeatherData[])//Length

(* WeatherData[{{"Buenos Aires","Argentina"},10}] *)

(* WeatherData["SABE","Properties"] *)

(* WeatherData["SABE","Coordinates"] *)

(* FindGeoLocation[] *)

Graph the mean temperature  between 1990 and 2009

(*DateListPlot[WeatherData["SABE","MeanTemperature",{{1990,1,1},{2009,2,19},"Day"}],Joined->True,Filling->Bottom]*)

CityData

Search for information of a city.

CityData[{"Buenos Aires","Argentina"},"Properties"]

TableForm[({#1,CityData[{"Buenos Aires","Argentina"},#1]}&)/@CityData[All,"Properties"]]

A more advanced example...illustrating Kepler's Third 
Law.

Log-log plot of orbital period vs. distance for the 
planets.

ListLogLogPlot[Tooltip[{AstronomicalData[#,"OrbitPeriod"],AstronomicalData[#,"SemimajorAxis"]},#]&/@AstronomicalData["Planet"],PlotStyle->PointSize[Large],ImageSize->700]

Working with Data

Importing, Exporting, and Connecting to Other 
Programs

Mathematica's expressions allow anything to be represented in some way. A 
broad variety of file formats can be imported from or exported to a file.

Importing & Exporting »

$ImportFormats

Import[ToFileName[NotebookDirectory[],"chemtest.xls"]]

$ExportFormats

MathLink provides a general interface for connecting Mathematica to other programs. Links to Java (J/Link) and .NET (.NET/Link) have been built on top of MathLink to provide easy interactive connectivity to these runtimes.

External Programs »

Working with Data

Mathematica for Image Processing

Images can be imported, copied and pasted, or even dragged and 
dropped into Mathematica.

brain=Import[ToFileName[NotebookDirectory[],"brain.jpg"]]

We can sharpen the image for inspection.

Manipulate[Sharpen[brain,n],{n,1,5},SaveDefinitions->True]

Or we can extract the edges to determine contours.

Manipulate[ImageAdjust[GradientFilter[brain,n]],{n,Range[5]},SaveDefinitions->True]

We can even apply several effects to different parts 
of the image at the same time.

s=Sharpen[brain,4];
g=GradientFilter[brain,2]//ImageAdjust;
ds=UpperTriangularize[#,59]&/@ImageData[s,Interleaving->False];
dg=LowerTriangularize[#,-60]&/@ImageData[g,Interleaving->False];
dh=Normal@SparseArray[{i_,j_}/;Abs[i-j]<60:>#[[i,j]],Reverse@ImageDimensions@brain]&/@ImageData[brain,Interleaving->False];
Image[ds+dg+dh,Interleaving->False]

Many other effects are possible.

lena=ExampleData[{"TestImage","Lena"}];
Grid[{
{ColorNegate[lena],
ImageTake[lena,300],
ImagePad[lena,15,Red]},
{Image[GraphicsGrid[ImagePartition[lena,25]],ImageSize->180],
Image[ImageRotate[lena,45Degree]],
ImageEffect[lena,"Charcoal"]},
{Dilation[lena,3],
ImageApply[RotateRight,lena],
ImageAdjust[lena,6]}
}]

Working with Data

Statistics

Charting

Create a bar chart.

BarChart[{{1,3,2},{1,6,3}},ChartElementFunction->"GlassRectangle",ChartStyle->"Pastel"]

Add customizations, such as legends:

BarChart[{{1,3,2},{1,6,3}},ChartLegends->{"Set 1","Set 2","Set 3"}]

Or use your own graphics.

spikey=;
BarChart[Range[10],ChartElements->spikey]

Pie charts are interactive.

PieChart[Range[5]]

Bubble charts allow you to visualize data sets with 
varying magnitudes.

BubbleChart[RandomInteger[{10,80},{10,10,3}]]

There are also 3D analogues of the above functions.

BarChart3D[{{1,3,2},{1,6,3}},ChartLegends->{"Set 1","Set 2","Set 3"}]

PieChart3D[Range[5],ChartStyle->"Rainbow"]

BubbleChart3D[RandomInteger[{10,80},{10,10,4}]]

There is also a new palette to help with charting.

Open up Chart Element Schemes palette to show an 
example of this.

BarChart[Range[10]]

Final Thoughts

Mathematica as a Teaching and Research Environment

Can collect all relevant research information in Mathematica notebooks:

General notes

Typeset formulas for publication

Graphics

Code implementation

Direct conversion to HTML, TeX, PDF, etc.

Field-specific application packages

In Conclusion

A lot of new features in Mathematica 7

All components of Mathematica are integrated.

Instant interactivity makes exploring fast and fun.

Resources Available

Learning Center

Library

MathWorld

Blog

Forums