Hacker News new | past | comments | ask | show | jobs | submit login
The Software Engineering of Mathematica (wolfram.com)
90 points by lf6648 on Aug 23, 2012 | hide | past | favorite | 21 comments



"...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?


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...


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)


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...


This just one part of a longer series: The Internals of Mathematica [1]. Overall a very interesting read.

[1] http://reference.wolfram.com/mathematica/tutorial/TheInterna...


Mathics has about 25K lines of python of which only about 10 lines are platform specific. There are also about 100K lines of JS, but much of it is automatically generated or libraries. Admittedly it is missing lots of the features of Mathematica, but I think its an interesting comparison to make.

Disclaimer: I'm a developer for Mathics


This looks cool. I am a big fan of the sympy's lightweight/modular approach to computer algebra, and so its great to see work on a nice front end. I have one random question. What was the rationale behind having "Apply" overwrite the head of an expression? If a function "f" takes a list to a list and I call "Apply[Plus,f[x]]" I would like the result to have "Plus" as the new head with "f[x]" as the tail. But as it it it feels like mixed semantics. Is there something I am missing?


Mathics links: use the online version at http://mathics.net/, download it and contribute at http://mathics.org/


Can we get permalinks to saved worksheets?


>Admittedly it is missing lots of the features of Mathematica

That's quite an understatement.


An interesting aspect of this is the "dogfooding" that seems to take place under Mathematica's covers. The internals use many of the same representation and communication techniques as are exposed to users.


"Mathematica is one of the more complex software systems ever constructed"

Wolfram, et al really thinks they are hot shit.


Yeah, they/he has that attitude. But to be fair, they kind of are. They power the most advanced computing software for the public, and they're a strong dependency for Siri.


This is an interesting series. I've always been fascinated with Matlab and Mathmatica ever since I took a class on floating point precision errors in college. I hope one day I get to work on a program that requires those algorithms to be used.


+1 for champaign il devs




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: