|
A.1.2 Writing procedures and libraries
The user may add their own commands to the commands already available in
SINGULAR by writing SINGULAR procedures. There are basically
two kinds of procedures:
- procedures written in the SINGULAR programming language (which are
usually collected in SINGULAR libraries).
- procedures written in C/C++ (collected in dynamic modules).
At this point, we restrict ourselves to describing the first kind of
(library) procedures, which are sufficient for most applications. The
syntax and general structure of a library (procedure) is described in
Procedures, and Libraries.
The probably most efficient way of
writing a new library is to use one of the official SINGULAR
libraries, say ring.lib as a sample. On a Unix-like operating
system, type LIB "ring.lib"; to get information on where the
libraries are stored on your disk.
SINGULAR provides several commands and tools, which may be useful
when writing a procedure, for instance, to have a look at intermediate
results (see Debugging tools).
We give short examples of procedures to demonstrate the following:
-
Write procedures which return an integer (ring independent), see also
Milnor and Tjurina number. (Here we restrict ourselves to the main
body of the procedures).
-
The procedure
milnorNumber must be called with one parameter, a
polynomial.
The name g is local to the procedure and is killed automatically when
leaving the procedure.
milnorNumber returns the Milnor number (and displays a comment).
-
The procedure
tjurinaNumber has no specified number of
parameters. Here, the parameters are referred to by #[1] for
the 1st, #[2] for the 2nd parameter, etc.
tjurinaNumber returns the Tjurina number (and displays a comment).
-
the procedure
milnor_tjurina which returns a list consisting of two
integers, the Milnor and the Tjurina number.
-
Write a procedure which creates a new ring and returns data dependent on
this new ring (two numbers) and an int. In this example, we also show
how to write a help text for the procedure (which is optional, but
recommended).
Writing a dynamic module is not as simple as writing a library
procedure, since it does not only require some knowledge of C/C++, but
also about the way the SINGULAR kernel works.
See also Dynamic modules.
|