We all know that Mathematica is great, but it also often lacks critical functionality. What kind of external packages / tools / resources do you use with Mathematica?
I'll edit (and invite anyone else to do so too) this main post to include resources which are focused on general applicability in scientific research and which as many people as possible will find useful. Feel free to contribute anything, even small code snippets (as I did below for a timing routine).
Also, undocumented and useful features in Mathematica 7 and beyond you found yourself, or dug up from some paper/site are most welcome.
Please include a short description or comment on why something is great or what utility it provides. If you link to books on Amazon with affiliate links please mention it, e.g., by putting your name after the link.
Packages:
LevelScheme
is a package that greatly expands Mathematica's capability to produce good looking plots. I use it if not for anything else then for the much, much improved control over frame/axes ticks. Its newest version is called SciDraw, and it will be released sometime this year.- David Park's
Presentation Package
(US$50 - no charge for updates) - Jeremy Michelson's
grassmannOps
package provides resources for doing algebra and calculus with Grassmann variables and operators that have non trivial commutation relations. - John Brown's
GrassmannAlgebra
package and book for working with Grassmann and Clifford algebras. - RISC (Research Institute for Symbolic Computation) has a variety of packages for Mathematica (and other languages) available for download. In particular, there is Theorema for automated theorem proving, and the multitude of packages for symbolic summation, difference equations, etc. at the Algorithmic Combinatorics group's software page.
Tools:
MASH
is Daniel Reeves's excellent Perl script essentially providing scripting support for Mathematica v7. (Now built in as of Mathematica 8 with the-script
option.)- An
alternate Mathematica shell
with a GNU readline input (using python, *nix only) - ColourMaths package allows you to visually select parts of an expression and manipulate them. http://www.dbaileyconsultancy.co.uk/colour_maths/colour_maths.html
Resources:
Wolfram's own repository
MathSource
has a lot of useful if narrow notebooks for various applications. Also check out the other sections such asCurrent Documentation
,Courseware
for lectures,- and
Demos
for, well, demos.
The Mathematica Wikibook.
Books:
- Mathematica programming: an advanced introduction by Leonid Shifrin (
web
,pdf
) is a must read if you want to do anything more than For loops in Mathematica. We have the pleasure of havingLeonid
himself answering questions here. - Quantum Methods with Mathematica by James F. Feagin (amazon)
- The Mathematica Book by Stephen Wolfram (amazon) (
web
) - Schaum's Outline (amazon)
- Mathematica in Action by Stan Wagon (amazon) - 600 pages of neat examples and goes up to Mathematica version 7. Visualization techniques are especially good, you can see some of them on the author's
Demonstrations Page
. - Mathematica Programming Fundamentals by Richard Gaylord (
pdf
) - A good concise introduction to most of what you need to know about Mathematica programming. - Mathematica Cookbook by Sal Mangano published by O'Reilly 2010 832 pages. - Written in the well known O'Reilly Cookbook style: Problem - Solution. For intermediates.
- Differential Equations with Mathematica, 3rd Ed. Elsevier 2004 Amsterdam by Martha L. Abell, James P. Braselton - 893 pages For beginners, learn solving DEs and Mathematica at the same time.
Undocumented (or scarcely documented) features:
- How to customize Mathematica keyboard shortcuts. See
this question
. - How to inspect patterns and functions used by Mathematica's own functions. See
this answer
- How to achieve consistent size for GraphPlots in Mathematica? See
this question
. - How to produce documents and presentations with Mathematica. See
this question
.
Following function
format[expr_]
can be used to indent/format unformattedmathematica
expressions that spans over a pageref: https://codegolf.stackexchange.com/questions/3088/indent-a-string-using-given-parentheses
This one was written by Alberto Di Lullo, (who doesn't appear to be on Stack Overflow).
CopyToClipboard
, for Mathematica 7 (in Mathematica 8 it's built in)Original post: http://forums.wolfram.com/mathgroup/archive/2010/Jun/msg00148.html
I have found this routine useful for copying large real numbers to the clipboard in ordinary decimal form. E.g.
CopyToClipboard["123456789.12345"]
Cell[OutputFormData@expr]
neatly removes the quotes.This is not a complete resource, so I'm throwing it here in the answers section, but I have found it very useful when figuring out speed issues (which, unfortunately, is a large part of what Mathematica programming is about).
Usage is then simply
timeAvg@funcYouWantToTest
.EDIT: Mr. Wizard has provided a simpler version that does away with
Throw
andCatch
and is a bit easier to parse:EDIT: Here's a version from acl (taken from here):
Printing system symbol definitions without context prepended
The
contextFreeDefinition[]
function below will attempt to print the definition of a symbol without the most common context prepended. The definition then can be copied to Workbench and formatted for readability (select it, right click, Source -> Format)withRules[]
Caveat: This function does not localize variables the same way
With
andModule
do, which means that nested localization constructs won't work as expected.withRules[{a -> 1, b -> 2}, With[{a=3}, b_ :> b]]
will replacea
andb
in the nestedWith
andRule
, whileWith
doesn't do this.This is a variant of
With
that uses rules instead of=
and:=
:I found this useful while cleaning up code written during experimentation and localizing variables. Occasionally I end up with parameter lists in the form of
{par1 -> 1.1, par2 -> 2.2}
. WithwithRules
parameter values are easy to inject into code previously written using global variables.Usage is just like
With
:Antialiasing 3D graphics
This is a very simple technique to antialias 3D graphics even if your graphics hardware doesn't support it natively.
Here's an example:
Note that a large value for
n
or a large image size tends to expose graphics driver bugs or introduce artefacts.Notebook diff functionality
Notebook diff functionality is available in the
<<AuthorTools`
package, and (at least in version 8) in the undocumentedNotebookTools`
context. This is a little GUI to diff two notebooks that are currently open:This code makes a palette that uploads the selection to Stack Exchange as an image. On Windows, an extra button is provided that gives a more faithful rendering of the selection.
Copy the code into a notebook cell and evaluate. Then pop out the palette from the output, and install it using
Palettes -> Install Palette...
If you have any trouble with it, post a comment here. Download the notebook version here.
I'm sure a lot of people have encountered the situation where they run some stuff, realizing it not only stuck the program, but they also haven't saved for the last 10 minutes!
EDIT
After suffering from this for some time, I one day found out that one can create auto-save from within the Mathematica code. I think that using such auto-save have helped me a lot in the past, and I always felt that the possibility itself was something that not a lot of people are aware that they can do.
The original code I used is at the bottom. Thanks to the comments I've found out that it is problematic, and that it is much better to do it in an alternative way, using
ScheduledTask
(which will work only in Mathematica 8).Code for this can be found in this answer from
Sjoerd C. de Vries
(Since I'm not sure if it's OK to copy it to here, I'm leaving it as a link only.)The solution below is using
Dynamic
. It will save the notebook every 60 seconds, but apparently only if its cell is visible. I'm leaving it here only for completion reasons. (and for users of Mathematica 6 and 7)/EDIT
To solve it I use this code in the beginning of a notebook:
This will save your work every 60 seconds.
I prefer it to
NotebookAutoSave[]
because it saves before the input is processed, and because some files are more text than input.I originally found it here: http://en.wikipedia.org/wiki/Talk:Mathematica#Criticisms
Note that once running this line, saving will happen even if you close and re-open your file (as long as dynamic updating is enabled).
Also, since there is no undo in Mathematica, be careful not to delete all your content, since saving will make it irreversible (as a precaution move, I remove this code from every finished notebook)