A preliminary Symbolic Toolbox for Scilab


December 2006.

TUTORIAL TOOLBOXES


Introduction

The proposed toolbox is an interface between Scilab and Maxima. The objective is to make available some Maxima routines directly in Scilab workspace using Scilab syntax.

Warning: this is a preliminary version. There are probably a lot of bugs and many useful functions are still missing. The main trouble is that some operations are quite slow on account of the way both packages communicate.

The function restartserver is a must to know in this preliminary version. In case of irrelevant replies to your commands (usually replies to former commands) type restartserver in order to re-initialize Maxima workspace and the Scilab / Maxima communication process.

The symbolic object. Symbolic objects are Scilab mlists consisting of a string in Maxima syntax. Symbolic objects can be manipulated mostly like matrices (operations, concatenation, insertion, extraction). They are displayed without indentation permitting us in particular to distinguish between symbolic numbers and Scilab floating point numbers. The function typeof applied to a symbolic object returns the string 'sym'.

Function overloading. Only some Scilab built-in functions can be applied to user-defined objects (e.g., abs(x) where x is a symbolic object). We have developed a module (OVLD, which must be installed independently of the Symbolic Toolbox) in order to make overloading feasible for most non built-in functions.

This tutorial assumes that this module is installed, otherwise some functions must be invoked with the prefix %sym_ (e.g., %sym_factor instead of factor).

Even if OVLD is installed, the prefix %sym_ can be useful in order to force the use of a function of the symbolic toolbox. For example, %sym_cos(1/3) is the cosine of the symbolic number 1/3 (result much more precise than using cos(1/3)), %sym_expand((3*%s+2)^4) or %sym_expand('(3*a+b)^5') expand a Scilab polynomial or a string and return a symbolic object.

Comparison with the Matlab Symbolic Toolbox. Most functions have a syntax similar to the Matlab Symbolic Toolbox. Some functions of the Matlab Toolbox are not available because missing in Maxima (e.g., exponentials of matrices, z-transform,...) in addition some functions cannot be easily overloaded, so, have a different name (double -> dbl, int -> integ). Functions for plotting and functions related to numerical precision are not available (and will not be available unless written by someone else).

Symbolic types are not similar in both toolboxes. List of supported types: even, odd, integer, rational, irrational, real, imaginary, complex (default).

On-line help. There is an on-line "help" function (hlp). For displaying help of non-overloaded functions, type hlp followed by a function name, for example hlp numden. For overloaded functions use the prefix sym/ for example hlp sym/gcd.

Global variables. Loading the Symbolic Toolbox defines global variables (MAX, PERL, SYMDIR). These variables are the paths to used external programs, so, must not be cleared.

TOP


If you want to contribute.

The sym-object structure: it is a mlist with at that time only one field denoted str1. This field is the string which would be used in Maxima for generating the considered object. e.g.,

a = mlist(['sym';'str1'],'a').

This object might be enriched if necessary.

Server: The main step for improving the toolbox will consist of improving the communication between Maxima and Scilab. The server stuff is in the sub-directory server of the installation directory. It consists of three programs:

  • serveur (Perl script). This server listen to Maxima on port 2001 and listen to the interface program on port 2000.
  • interface (Perl script or compiled program). This script/program is used as follows from Scilab: maxima_response = unix_g('interface instruction_for_maxima').
  • serveur.sce (Scilab script). Searches Maxima and Perl, then launches the server and connects maxima in "server mode" (client mode in fact). This script is executed by loader.sce.

The function str2max2sym is the interface between Scilab and Maxima. It is this function which invokes the interface program via unix_g. It might be invoked many times even for simple operations inducing sometimes very slow computation. This function depends on

  • strsci2max: transforms a string with Scilab syntax into a string with Maxima syntax.
  • max2strsci: transforms a string with Maxima syntax into a string with Scilab syntax.

Improvements expected:

  • Check if the interface script/program is replaced by a program which is not re-launched each time Scilab and Maxima communicate will improve the speed.
  • Find a way to kill the interface program if Maxima doesn't reply after a fixed amount of seconds (otherwise, Scilab freezes).

Maxima: A good knowledge of Maxima will improve several functions and help to define important missing functions. In particular, it might be wise to add to Maxima a module specialized in matrix manipulations (for example, there is no exponential of matrices at that time).

TOP


Installation.

Tested on several Unix flavours and Windows. You must have Perl, Maxima and Scilab installed (maxima and perl should preferably be in the path variable).

For checking that Maxima is in your path and that you have the right version, type maxima --version in some command tool. The version should be 5.9.3 or higher. Binaries of Maxima can be downloaded from here (note that Fedora Core rpm's work well on other rpm-based Linux distributions and can also be used on Debian-based distributions via alien).

Perl is usually available on Unix platforms. For Windows, Perl binaries can be downloaded from here.

Installation of the Symbolic Toolbox for a single user. It is assumed that the module OVLD and the Symbolic toolbox were unzipped in a directory where you have write access. Installation requires four steps.

  • Add the following line in the scilab.quit file located in the Scilab installation directory (path given by typing SCI in Scilab):
    if exists('MAX'); killserver(%t); end;
    If you don't have write access to this file, you must type killserver each time before leaving Scilab.
  • From the 'file' menu of a Scilab window, navigate to the directory SYM where the symbolic toolbox was unzipped and execute builder.sce, then, loader.sce.
  • Install the module for overloading functions: From the 'file' menu of a Scilab window, navigate to the directory OVLD where this module was unzipped and execute builder.sce and then, loader.sce.
  • From Scilab, invoke the function restartserver. Note that this function will kill all already running Maxima tasks.
Next time you start Scilab, it suffices to execute both loader.sce scripts (/OVLD/loader.sce and /SYM/loader.sce). It is better to execute these scripts from the .scilab startup file for automatic loading. This file should be in <HOME DIRECTORY>\Scilab\scilab-x.x\ (Windows) or in ~/.Scilab/scilab-x.x/ (Unixes).

TOP


In case of problems.

Communication Scilab / Maxima. Scilab and Maxima communicate through a server which is launched by the loader.sce script. Maxima is also launched in client mode by this script. The proposed server is provisional, it must be shut down by editing the scilab.quit file (see above) or manually by invoking the function killserver from Scilab.

In case of problem, you can re-initialize Maxima and the server by invoking the function restartserver. If Scilab freezes you should re-initialize by killing manually maxima and perl/serveur tasks. On Unixes you can identify PID's of tasks to be killed by invoking the function findpid.

If it doesn't work. Known issues (assuming that invoking the function restartserver didn't solve the problem):

  • Check that the script SYM/server/serveur.sce can find Maxima. It is better to add the path to the Maxima binary in you PATH variable. Alternatively, for Windows users, modify the string array search_maxima of SYM/server/serveur.sce by adding the actual path to the Maxima binary (step required for versions of Maxima higher than 5.9.3).
  • This provisional version of the toolbox uses two ports (2000 and 2001) without checking availability. In some cases these ports are already opened by other programs. So, on Unix(es) check in the /etc/services file if these ports are available. You can change manually the values 2000 and 2001 in the Scilab scripts SYM/server/serveur and SYM/server/perl/interface (don't switch to pre-compiled interfaces). Thanks to Yann Collette for bug report.
  • For only one out of the numerous tested platforms (FreeBSD 6.0) the connection of Maxima to the server (used for communication between Maxima and Scilab) might be launched before the server is started. In this case, add the halt; instruction just after the server is launched (see script SYM/server/serveur.sce).
  • For *BSD platforms, replace ps -edf by ps -xa in the function SYM/macros/findpid.sci (then, execute again builder.sce, loader.sce and run restartserver).
  • The Maxima Debian package available mid-2006 is broken (xMaxima and wxMaxima doesn't work too). I suggest to install via alien and dpkg the rpm packages available here (maxima-xxx.rpm and maxima-exec-clisp-xxx.rpm).
  • November 2006: the Perl/socket communication process is broken in Fedora Core 6. No known solution to this problem (xMaxima and wxMaxima doesn't work too).

It is slow. The principle used for communication between Maxima and Scilab is not optimal. Obtaining faster responses is the main issue before further developments. It is however possible to accelerate responses by setting the Scilab global variable INTERFACE to

  • INTERFACE = "sparc" on Solaris Sparc.
  • INTERFACE = "lin86" on Linux x86.
  • INTERFACE = "bsd86" on *BSD x86.
  • INTERFACE = "perl" to go back to the default settings.
a Perl script is replaced by a compiled interface (don't use if you modified port numbers, see the second item of the previous list).

TOP