MATH 531: Introduction to Singular.
What follows is a compilation of the introductory Singular tutorial
(available in full at http://www.singular.uni-kl.de/Tutor-1-2/) with
some additions.
You may run singular either from command line by typing Singular or within
emacs by typing ESingular.
However, Singular in emacs does not have a capability of executing
files line-by-line. Personally, I prefer the emacs interface, which
allows you to have 2 windows: one with Singular, the other with the
list of commands you intend to execute, which you may do by cutting and
pasting them in the Singular window.
1. Getting started.
Once SINGULAR is started, it awaits an input after the prompt
>. Every statement has to be terminated by ;
.
37+5;
==> 42
All objects have a type, e.g., integer variables are defined by
the word int. An assignment is done by the symbol =
.
int k = 2;
Test for equality resp. inequality is done using ==
resp. != (or <>), where 0
represents the boolean
value FALSE, any other value represents TRUE.
k == 2;
==> 1
k != 2;
==> 0
The value of an object is displayed by simply typing its name.
k;
==> 2
On the other hand the output is suppressed if an assignment is made.
int j;
j = k+1;
The last displayed (!) result is always available
with the special symbol _ .
2*_; // the value from k displayed above
==> 4
Text starting with // denotes a comment and is ignored in
calculations, as seen in the previous example. Furthermore SINGULAR
maintains a history of the previous lines of input, which may be
accessed by
CTRL-P (previous) and CTRL-N (next) or the
arrows on the
keyboard. Note, that the history is not available on Macintosh systems.
The whole manual is available online by typing the command help;
.
Explanation on single topics, e.g., on intmat, which
defines a
matrix of integers, are obtained by
help intmat;
This shows the text from node intmat, in the printed
manual.
Next, we define a 3 x 3 matrix of integers and initialize it with some values, row by row from left to right:
intmat m[3][3] = 1,2,3,4,5,6,7,8,9;
A single matrix entry may be selected and changed using
square brackets [ and ].
m[1,2]=0;
m;
==> 1,0,3,
==> 4,5,6,
==> 7,8,9
To calculate the trace of this matrix, we use a for loop.
The
curly brackets ({ and }) denote the
beginning resp.
end of a block. If you define a variable without giving an initial
value, as the variable tr in the example below, SINGULAR
assigns a default value for the specific type. In this case, the
default
value for integers is 0. Note, that the integer variable j
has already been defined above.
int tr;
for ( j=1; j <= 3; j++ ) { tr=tr + m[j,j]; }
tr;
==> 15
Variables of type string can also be defined and used without a ring
being active. Strings are delimited by " (double quotes).
They
may be used to comment the output of a computation or to give it a nice
format. If a string contains valid SINGULAR commands, it can be
executed using the function execute. The result is the
same as if
the commands would have been written on the command line. This feature
is especially useful to define new rings inside procedures.
"example for strings:";
==> example for strings:
string s="The element of m ";
s = s + "at position [2,3] is:"; // concatenation of strings by +
s , m[2,3] , ".";
==> The element of m at position [3,2] is: 6 .
s="m[2,1]=0; m;";
execute(s);
==> 1,0,3,
==> 0,5,6,
==> 7,8,9
This example shows that expressions can be separated by ,
(comma)
giving a list of expressions. SINGULAR evaluates each expression in
this list and prints all results separated by spaces.
2. Rings and Grobner bases.
To calculate with objects as ideals, matrices, modules, and polynomial vectors, a ring has to be defined first.
ring r = 0,(x,y,z),dp;
The definition of a ring consists of three parts: the first part
determines the ground field, the second part determines the names of
the
ring variables, and the third part determines the monomial ordering to
be used. So the example above declares a polynomial ring called r
with a ground field of characteristic 0 (i.e., the rational
numbers) and ring variables called x, y,
and z. The
dp at the end means that the degree reverse
lexicographical
ordering should be used.
Other ring declarations:
ring r1=32003,(x,y,z),dp;
x, y,
and z and
ordering dp.
ring r2=32003,(a,b,c,d),lp;
a, b,
c,
d and lexicographical orderingTyping the name of a ring prints its definition. The example below shows, that the default ring in SINGULAR is Z/32003[x,y,z] with degree reverse lexicographical ordering:
ring r5;
r5;
==> // characteristic : 32003
==> // number of vars : 3
==> // block 1 : ordering dp
==> // : names x y z
==> // block 2 : ordering C
Defining a ring makes this ring the current active basering, so each ring definition above switches to a new basering. The concept of rings in SINGULAR is discussed in detail in the chapter "Rings and orderings" of the SINGULAR manual.
The basering now is r5. Since we want to calcualate in
the ring
r, which we defined first, we have to switch back to it.
This can
be done using the function setring:
setring r;
Once a ring is active, we can define polynomials. A monomial, say
x^3
may be entered in two ways: either using the power operator ^,
saying x^3, or in short-hand notation without operator,
saying
x3. Note, that the short-hand notation is forbidden if the
name
of the ring variable consists of more than one character. Note, that
SINGULAR always expands brackets and automatically sorts the terms
with respect to the monomial ordering of the basering.
poly f = x3+y3+(x-y)*x2y2+z2;
f;
==> x3y2-x2y3+x3+y3+z2
The command size determines in general the number of
"single
entries" in an object. In particular, for polynomials, size
determines the number of monomials.
size(f);
==> 5
A natural question is to ask if a point e.g. (x,y,z)=(1,2,0)
lies
on the variety defined by the polynomials f and g.
For
this we define an ideal generated by both polynomials, substitute the
coordinates of the point for the ring variables, and check if the
result
is zero:
poly g = f^2 *(2x-y);
ideal I = f,g;
ideal J= subst(I,var(1),1);
J = subst(J,var(2),2);
J = subst(J,var(3),0);
J;
==> J[1]=5
==> J[2]=0
Since the result is not zero, the point (1,2,0) does
not lye on the variety V(f,g).
Another question is to decide whether some function vanishes on a
variety, or in algebraic terms if a polynomial is contained in a given
ideal. For this we calculate a standard basis using the command
groebner and afterwards reduce the polynomial with respect
to
this standard basis.
ideal sI = groebner(f);
reduce(g,sI);
==> 0
As the result is 0 the polynomial g belongs
to the
ideal defined by f.
The function groebner, like many other functions in
SINGULAR, prints a protocol during calculation, if desired. The
command option(prot); enables protocoling whereas
option(noprot); turns it off.
The command kbase calculates a basis of the polynomial
ring
modulo an ideal, if the quotient ring is finite dimensional. As an
example we calculate the Milnor number of a
hypersurface singularity in the global and local case. This is the
vector space dimension of the polynomial ring modulo the Jacobian ideal
in the global case resp. of the power series ring modulo the Jacobian
ideal in the local case.
The Jacobian ideal is obtained with the command jacob.
ideal J = jacob(f);
==> // ** redefining J **
J;
==> J[1]=3x2y2-2xy3+3x2
==> J[2]=2x3y-3x2y2+3y2
==> J[3]=2z
SINGULAR prints the line // ** redefining J
**. This indicates that we have previously defined a variable
with name
J of type ideal (see above).
To obtain a representing set of the quotient vectorspace we first
calculate a standard basis, then we apply the function kbase
to
this standard basis.
J = groebner(J);
ideal K = kbase(J);
K;
==> K[1]=y4
==> K[2]=xy3
==> K[3]=y3
==> K[4]=xy2
==> K[5]=y2
==> K[6]=x2y
==> K[7]=xy
==> K[8]=y
==> K[9]=x3
==> K[10]=x2
==> K[11]=x
==> K[12]=1
Then
size(K);
==> 12
gives the desired vector space dimension K[x,y,z]/jacob(f). As in SINGULAR the functions may take the input directly from earlier calculations, the whole sequence of commands may be written in one single statement.
size(kbase(groebner(jacob(f))));
==> 12
When we are not interested in a basis of the quotient vector space, but
only in the resulting dimension we may even use the command vdim
and write:
vdim(groebner(jacob(f)));
==> 12
3. Standard bases for local orderings and multiplicities.
The following is an example of a ring with the so-called "negative degree reverse
lexicographical" local monomial ordering:
ring r=0,(x,y,z),ds;
Define an ideal in this ring:
poly s1=x3-y*z; poly s2=y3-x*z; poly s3=z3-x*y; ideal I=(s1,s2,s3);
A standard basis with respect to a local ordering is an anologue of a grobner
basis for global monomial orderings.
One can use a standard basis to compute the multiplicity of the origin:
ideal J=std(I); mult(J);
This multiplicity is the number of elements in the basis of standard monomials for the local quotient ring, which can be created as before:
ideal K = kbase(J); K;
4. Exercise.
For the ideal I = < x^2-2x+y^2, x^2-4x+4y^4 > find
(a) the standard monomial basis w.r.t grevlex;
(b) the multiplicity of the origin;
(c) approximations to all of the points of V(I); hint:
LIB "solve.lib";
list s = solve(I);
(d) the multiplicities of the integer points (compute using Singular); hint: move them to the origin;
(e) the multiplicities of the solutions different from the origin. (Hint: the sum of multiplicities of solutions of a 0-dimensional polynomial system is equal to the dimension of the global quotient ring.)