- For a tutorial about how I created the Xtext components see this page.
- For a tutorial about how I created the 'builder' plugin see this page.
SPAD
The Axiom/Fricas program uses a language called SPAD. I have defined the syntax of this language on this page.
Why Use a Domain Specific Language (DSL)?
Why not program our maths library in a mainstream language? After all many programs have maths libraries for trig functions or for matrix or complex algebras, however what we are trying to do here is a bit different than that. What we are trying to implement here is a Computer Algebra System (CAS) which can include symbolic values and do things like solve equations or differentiate functions. In fact we want to be able work with many types of algebra, however abstract, such as:
- group theory.
- graph theory.
- rings and fields.
- category theory.
The list could be endless and if a given algebra is not in the code library, then I want users to be able to write it.
To do this we need to have a very powerful type system, even more powerful than languages like Haskell and Scala.
For instance we need some form of 'dependent types', no mainstream languages allows dependent types (with good reason, it breaks type safety) however we need some (possibly weaker) form of dependent types.
We also need to be able to have 'type expressions' which can combine types in various ways to get new types such as:
- product of types (tuple or record)
- sum of types (union)
- exponent of types (function types - first class functions)
- combine partial types
- recursively defined types
- ... and so on.
There are many other requirements and so I think a mainstream language won't work.
I'm a bit wary of calling this a domain specific language (DSL), it seems to me that maths is more general than programming and therefore programming should be called domain specific maths, rather than the other way round.
Application Design
It would require an impractically large programming effort to code a significant part of maths into such a language. Therefore I would like to base this on an existing maths library, that is the library in the FriCAS project, this is a fork of the Axiom project. These programs use a language called SPAD (which is itself written in Lisp).
I have therefore written an SPAD syntax so that Xtext can generate a model and editor for it. This is not yet complete and it may not be possible to reverse engineer FriCAS exactly but I am hoping that I can eventually get it good enough. The syntax of SPAD as used by FriCAS is not very well documented, whitespace is significant and it uses macros so it is hard to model in Xtext. To make this a bit easier I have written a simple program to insert braces and apply macros, here I have called it a preprocessor but it makes permanent changes to the files, its not just a preprocessor to the compiler (more information about this code on this page).
This allows the SPAD files to be parsed and modeled, however the structure is still a bit messy:
- whitespace is still significant.
- declarations and definitions are separated
- it uses unusual conventions
I would therefore like to convert it to a simpler and more powerful syntax which uses Xtend. I have called this 'Euclid'.