Programmers Guide

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:

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:

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

euclideanspace program components

This allows the SPAD files to be parsed and modeled, however the structure is still a bit messy:

I would therefore like to convert it to a simpler and more powerful syntax which uses Xtend. I have called this 'Euclid'.


metadata block
see also:
Correspondence about this page

Book Shop - Further reading.

Where I can, I have put links to Amazon for books that are relevant to the subject, click on the appropriate country flag to get more details of the book or to buy it from them.

 

This site may have errors. Don't use for critical systems.

Copyright (c) 1998-2017 Martin John Baker - All rights reserved - privacy policy.