Hacker News new | ask | show | jobs
by numlocked 5049 days ago
"...the user-level design of Mathematica has remained compatible from Version 1 on. Much functionality has been added, but programs created for Mathematica Version 1 will almost always run absolutely unchanged under Version 6."

I wonder if this is the case because of dedication to backwards compatibility or because the original syntax was based on some fundamental mathematical concepts that are sound and thus don't change the same way most APIs do. Can anyone with more Mathematica experience weigh in?

6 comments

The syntax is heavily influenced by M-expressions, which were used for the original version of Lisp in McCarthy's papers [1]. I believe the purity and power of the syntax is a major factor in the stability of the language.

I spent the summer of 2000 interning at Wolfram. I wrote coverage tests for over 60,000 lines of the Mathematica source code in areas ranging from functional programming operations to advanced numerical functions. My experience was that the source code was incredibly clean and well organized across the board.

[1] http://en.wikipedia.org/wiki/M-expression#Variants

I didn't understand as much as I'd have liked of the linked article. Let me check something. In Mathematica, are the M expressions the internal 'FullForm' representations of expressions? So, for example, I type:

    a = {1,2,3};
Which is represented internally as an 'M expression' of List[1,2,3] (obtainable through FullForm[a], or its head through Head[a])?

Is that it?

I didn't realise that was a named concept. It does make sense to have a completely unified internal representation underneath the syntactic sugar, since you'd need everything to be in that form for the term rewriting system to work.

Thanks!

Yes, and for completeness I'd like to point out that this doesn't just apply to the right-hand side of the equation you gave. The "=" is just syntactic sugar to let you do variable assignment using infix notation:

In[1]:= FullForm[Hold[a={1,2,3}]]

Out[1]//FullForm= Hold[Set[a,List[1,2,3]]]

Worth pointing out, thanks! I see how that works.
Don't think of it as an API. It's a complete and very rich language that supports functional and procedural (and declarative, and other) programming models.

To your question, it's not so much that V6 is opening documents written in V1, it's more that V6 of the language runs V1 code. Viewed through that lens, it's not such a surprise. K&R C still compiles, after all. (In fact, certain peripheral pieces of older code won't actually work in newer versions. It's not uncommon for old notebooks to require some changes.)

The fundamental heart of Mathematica and its language is quite unusual: it is a Term Rewriting System (TRS.) There's a good set of examples here [1] but basically a TRS works by the repeated application of matching patterns to expression terms and modifying them with replacement rules. The language's flexibility comes from the clever use of those rules.

You can do amazing things with it very easily if you follow its way. It's pretty unique in the world of programming languages and a 30 day trial will be fun for anyone interested in experimenting with languages.

[1] http://www.cs.swan.ac.uk/~csneal/SystemSpec/termrewriting.ht...

> I wonder if this is the case because of dedication to backwards compatibility or because the original syntax was based on some fundamental mathematical concepts that are sound and thus don't change the same way most APIs do.

I would say it's mostly the former. I don't see anything unusually mathematical about Mathematica syntax.

Also, a good, simple & versatile syntax was chosen in the first place, so there was little need to change it. The syntax doesn't look too remarkable now, but Mathematica is 24 years old, so clearly some very good decisions were made in its initial design.

This is how Wolfram described SMP which was the precursor to Mathmatica:

SMP is intended to be close to conventional mathematics. The fundamental operations of mathematics are included among the 100 or so primitives of the language, together with about 250 mathematical functions. Direct use of these primitives alone suffices in some simple calculations, such as those in Figure 1. However, as in mathematics itself, higher level constructs and operations must be defined to cover the immense variety of methods and calculations encountered in practice. SMP was designed at a fundamental level to make use of the notations and mechanisms developed in mathematics for such definitions.

http://www.stephenwolfram.com/publications/articles/computin...

It had good early iterations (Knuth said once that he didn't even have to submit his suggestions for documentation, they turned up in the next version [1]). Kind of the opposite of JavaScript... [2]

As a multi-paradigm language they can add new functionality without having to replace old. The global namespace has thousands of functions, being able to add to that makes fixing problems more a matter of finding good names than a matter of finding "the right way" of doing something. E.g. Block and Module [3].

These are small advantages that perhaps most API and language designers don't have.

[1] http://tex.loria.fr/historique/interviews/knuth-clb1993.html

[2] http://javascript.crockford.com/remedial.html

[3] http://forums.wolfram.com/mathgroup/archive/2010/Dec/msg0070...

I think this is a slightly different 'backwards compatibility' than uepsed elsewhere. I bet Mathematica has seen zillions of incompatible changes. For example, http://www.wolfram.com/mathematica/quick-revision-history.ht... lists "Many new automatic simplifications for derived distributions, including affine transformations, sums of variables, parameter mixtures, and censored and truncated distributions" for 8.0.1. I haven't used it, but I bet that there still is only one "Simplify" function, and that there aren't a zillion settings to make it behave 'just like version X for any X in 1.0, 1.01, …, 8.0.

Compare that to e.g. windows, with its BlaEx, BlaEx2, etc functions, or a typical database, where a zillion flags control what language dialect they follow, how exactly NULLs behave, etc, or filesystems (for example, Apple's HFS has a bug in its filename sorting that has been faithfully copied for decades now)