Tuesday, December 17, 2013

A first and naive look at Mathematica 10.0

I am quite curious about what's new in Mathematica 10. Fortunately now some of them are no longer secret. In the last blog post I introduced how to install Mathematica 10 in a virtual machine. Here let me share some findings.

The findings are based on a list of new functions, as pointed out in http://www.walkingrandomly.com/?p=5220.

Sometime in the future there will be an official summary for the new features. But as of writing, the links inside here are not available yet.
http://reference.wolfram.com/search/?q=new%20in%2010.0

The on-going manual for Mathematica 10, or rather they uplift it to the Wolfram Language (interestingly, the non-GUI way to run Mathematica is now no longer "math", but "wolfram"), can be found on Wolfram's official site:
http://reference.wolfram.com/language/

Association Data Structure

Now there is a set of new functions -- Association, Lookup, Keys, Values, KeyExistQ, CountBy, ..., which works with a new type of data structure, similar to dictionary in Python and Map in C++ 11.

Previously, I use function rules to mimic association in Mathematica. This works -- however now there are a whole package of operations acting on associations, either on its values or keys. This is powerful and make the language more expressive. For example,
appleData=<| "name"->"apple","color"->"red","weight"->100gram |> ;
{appleData["name"],appleData["weight"]}
[output] {apple,100 gram}
Associations can be generated by CountBy, GroupBy or PositionIndex (note that SortBy is another meaning. This is confusing). For example,
CountBy[RandomInteger[{0,1},10]]
[output] <|1->6,0->4|> 
PositionIndex[RandomInteger[{0,1},10]]
[output] <|0->{1,3,7,9,10},1->{2,4,5,6,8}|>
This new data structure works well with some previous functions
Map[f,appleData]
[output] <|name->f[apple],color->f[red],weight->f[100 gram]|>
But not for the rest, even other Listable ones.
Sin[appleData]
[output] Sin[<|name->apple,color->red,weight->100 gram|>]
It's easy to convert an association into a list of rules
"name"/.Normal[appleData]
[output] apple
Device Operations

There are lots of new functions added to operate device directly. For example,         Mathematica can now directly read a photo from a camera and operation on the result directly. My virtual machine does not allow me to do such tests though.

Cloud Integration

There are interesting cloud related new functions such as CloudConnect, CloudGet, CloudEvaluate, CloudPut, CloudSave,... The documentation for those functions are not ready though.

Logging into social media, Mathematica can now interact with them directly:
SendMessage["Twitter", "I sent this tweet from Mathematica."]
Or process on a list of Facebook friends
SocialMediaData["Facebook", "Friends"] // Short
Knowledge Based Computing

This may have already existed in earlier versions of Mathematica. However here lots of further convenience are made. For example, concept of Entity is raised and an entity can have different names (CanonicalName, CommonName, etc.) Other examples include FormulaData and FormulaLookup.

There are a few new functions which operates bar code. It is not hard to imagine we scan the bar code of goods in a supermarket and use Mathematica (yes, on arm cpus) to process the data.

Machine Learning

Now one can train Mathematica using existing data, and use the experience for future data sets. For example Classify and Predict. More can be found at
http://reference.wolfram.com/language/guide/MachineLearning.html

trainingData = {1 -> False, 2 -> True, 3 -> False, 4 -> False, 5 -> True, 6 -> True};
cfunc = Classify[trainingData]

cfunc[0] then gives False, which is inferred from the above set.

Activate / Inactive
testSin=Inactive[Sin][π/2]
[output] Sin[π/2] 
Activate[testSin]
[output] 1
I haven't got the point -- isn't it yet another HoldForm / ReleaseHold? If so, why not let them support tags instead of inventing another pair?
However, I highly trust the intellengence of the Mathematica  team believe there should be something that I missed. Here is how to do it the old way:

testCos=HoldForm[Cos][π]
[output] Cos[π] 
ReleaseHold[testCos]
[output] -1
Other Interesting new functions

Lots of functions are added in different areas, e.g.
URLDecode["Hello%2C+World%21"]
[output] Hello, World!
URL functions as such aims to make Mathematica more cloud-ready.

And there are a whole lot of new image processing functions. Also, lots of new functions for computational geometry (http://reference.wolfram.com/language/guide/ComputationalGeometry.html).

In the field of statistics, a number of functions are added to help process time series data, like heart rates, network traffic, etc. Also, now random processes can get transformed using TransformedProcess (similar to TransformedDistribution, which already existed in previous versions).

Among those new functions are also some additional math convenience. For example, FunctionDomain[x/(x^4 - 1), x] gives on which domain is the given function defined. Similarly one can also find the range on y-axis using FunctionRange[func[x], x, y].

There are improvements on matrix processing. For example, a lot of matrix properties added such as AntihermitianMatrixQ, AntisymmetricMatrixQ, DiagonalizableMatrixQ, IndefiniteMatrixQ, NegativeDefiniteMatrixQ, NegativeSemidefiniteMatrixQ, NormalMatrixQ, OrthogonalMatrixQ, PositiveSemidefiniteMatrixQ, SquareMatrixQ, UnitaryMatrixQ.

There is now an easier way to run external commands -- RunProcess. Compared with previous ways, now RunProcess returns an association <| ExitCode->0, Output->... |>. So extracting data from external command is easier then ever! A related new function is StartProcess, which starts an external process, but does not block Mathematica from doing other things. A started process can interact with Mathematica with ReadLine, WriteLine, ProcessStatus, ...

No comments:

Post a Comment