Why Mathematica?
A lot of people, particularly in economics /econometrics, are used to other languages. Therefore they find the Mathematica way of doing things a bit strange. This is a pity, because Mathematica has the potential to offer economists much more than the alternatives, such as GAUSS. Not only does it combine computer-algebra capabilities with fast numerics, but it’s cross platform, and the manual makes sense!
Advantages of the Mathematica Programming Language
-
Functional programming: Mathematica’s functional programming constructs,
Map[]
andApply[]
allow you to do many things in one line that would normally take several loops in other languages. Remember, “if you aren’t programming functionally, you’re programming dysfunctionally”! When you addFold[]
andNest[]
into the mix, you can do some pretty powerful things in a couple of lines. -
Sensible bracketing: Mathematica is smart enough that you don’t use the same type of brackets for different things. Parentheses are for grouping and enforcing your preferred precedence, as in
a*(b+c)
, curly brackets are for lists{a,b,c}
and square braces are for functions and FullFormHead[object,object]
. By contrast, in Gauss you never know whether you are multiplying or applying a function, it seems – they both use parentheses (). -
Bracket matching: If Excel, Mathematica, and most good text editors can do it, why not Gauss? Highlighting the opening bracket when you have just typed the closing bracket is extremely useful in avoiding syntax errors.
-
Code parsimony: I can write things in one or two lines that take many more in other languages. For example, one function I translated was 40 lines in the original Matlab, and only 10 in Mathematica.
-
Pattern matching: It’s so much easier to do a sophisticated pattern-match like
xs:{__{_,_Integer}}
, instead writing a zillion nestedIf[]
statements. -
Data typing: Because of the ability to pattern-matching, you can write different cases of functions for different inputs, which is much easier and more efficient.
-
Treatment of local variables: Unlike GAUSS, for example, Mathematica can distinguish between local variables and local constants (
Module
versusWith
) -
Upvalues: If you’ve never created a definition for a statistical distribution, you won’t understand how useful this can be.
Advantages of the Mathematica Front end
The front end is streets ahead of competing products commonly used in economics, with the GAUSS editor being a particular offender! Her are some of the key features
-
Built-in math notation including 2D math typesetting and Greek letters. Programs can be self-documented.
-
HTML and TeX Export: Unlike its competitors, Mathematica integrates with other packages remarkably well. (See also this MathSource package for a cool extension that implements CSS)
-
Export to other formats: Whether it’s copying and pasting text, or saving as EPS, or even creating QuickTime animations (Mac only), there are lots of ways to integrate Mathematica stuff with other stuff.
-
You can have autonumbering headings and text-equations in a Mathematica notebook, complete with cross-references. It’s clunkier than Microsoft Word’s Captions, but it works.