by haberman · 4y ago · 0 comments
- Is "Wolfram Language" the language used in Mathematica notebooks? Or is Mathematica a separate language, implemented using Wolfram Language? What does Mathematica add to Wolfram Language?
- I assume the Mathematica language is interpreted (not compiled) so it can be used in interactive notebooks. Any info about what its interpreter is like? I'm guessing it is compiled to byte code prior to being interpreted?
- How are symbolic expressions represented? Are symbolic expressions a distinct data type? Can you write a function that takes a symbolic expression and computes the derivative (I'm sure such a function is built in, but does the language let you implement a thing like this yourself?)
- Is there any kind of static typing, or is everything dynamically typed?
2: It is usually interpreted but can be compiled. If you RTFA there’s plenty of information about new compiler functions.
3: All expressions in Mathematica have the same form. For example 1+2 is just shorthand for Add[1, 2]. Think of them as M-expressions from LISP (kind of). These can be evaluated or manipulated. Symbolic expressions are not fundamentally different from other types of expressions. Indeed everything is a “symbolic expression”.
4: Wolfram Language/Mathematica goes to great lengths to hide this from you. Indeed again if RTFA you’d have read mentions of this with reference to interfacing with C code.
The symbolic evaluation is pretty novel. I assume it's not _just_ an AST. What do those structures look like?
What is the scoping? It feels like the emphasis is on global variables everywhere, but is it more subtle than that?
Are the data structures what we expect? Just in this post, Threaded implies some abstractions there. I would assume that some kind of "deferred" values are pretty typical throughout, is there a formal notion of that? A lot of it is deliberately hidden in the language, but I assume you can write code that handles that stuff directly.
Speaking of derivatives, I assume you can indicate how to take the derivative of new kinds of functions. How does that work? Generic functions, object oriented, ad hoc registries, or something else?
Data structures: you have special syntax for lists and "associations" (dictionaries/maps/hashtables). Those are immutable objects, but in at least some cases the implementation has an optimization where it'll directly mutate the object if there is only one reference to it. There are other data structures with no special syntax in the language, for example numeric and sparse arrays. A number of mutable data structures have also been recently introduced: https://reference.wolfram.com/language/guide/DataStructures....
One thing that you might expect to be a special data structure but actually isn't are "pure functions" (anonymous functions). There are actually just the unevaluated expression, so you could programmatically inspect the body if you so wanted to.
Deferred values: You can apply the HoldFirst/HoldRest/HoldAll/HoldAllComplete attributes so during evaluation they receive the corresponding arguments unevaluated. You might think this would make metaprogramming be easy, but it's actually tricky because of the "infinite evaluation" (it keeps evaluating until a fixed point is reached) of the language.
Derivatives: It's a term rewriting language, so you just provide the rewrite rules like you would with any other user function. f /: D[f[x_]] := x^2 will define the derivative of f(x) to be x^2, and associates that definition with f so that rule won't have to be checked for all usages of D (this also saves you from having to unprotect D to add the rule).
Mathematica is the Wolfram Language plus a user interface similar to the Symbolics Dynamic Listener that acted as your command line front end. Jupyter Notebooks are quite similar since the idea of a scientist’s or engineer’s notebook where content is “live” is a pretty common one.
That can be seen by the clumsy implementation of lexical scope (renaming vars, etc.) in Mathematica or the limited compilation of the Mathematica language.
Mathematica is the star of the show. Its a large collection of specialty libraries and tools, with (mostly) very nice documentation, that all interoperate together well.
You can literally take a screenshot of something on your computer and copy paste it into a Mathematica function for image recognition or whatever and it will take it. It's a lot like a lisp machine in some ways. You can do advanced symbolic calculus, optimization, ML, 3D visualizations, audio processing, geographic visualizations, it has an import function that can handle practically anything, connect to databases...etc etc, all in a consistent way. Worth a look.