Intro to Singular Math 676 (Computational Algebraic Geometry)

advertisement
Intro to Singular
Math 676 (Computational Algebraic Geometry)
Dan Bates, CSU, Spring 2009
The point of this brief document is to get you computing in Singular quickly. For more advanced
topics, you should check out the user guide/manual or, even better, talk to an expert user.
Where to find help
Go to http://www.singular.uni-kl.de/ and click on ”Online manual.” In my experience, sections
1–7,A–E are well written and interesting, but the index (section F) is the place to go for specific
help on a given topic.
There are a few other tutorials out there, but those that I have seen contact information similar to
what I will include in this document. In particular, you could check out the notes by Luis David
Garcia–Puente (at Sam Houston St.), which depend on those by Anton Leykin (at UIC), which
depend on those on the Singular website and in the notes of Stefan Steidel (at Kaiserslautern,
Singular’s home base). These last two (Singular and Steidel) both contain lots of nice background
and implementation information, too.
Finally, you could always type “help TOPIC;” at the prompt. If you choose your wording correctly
and installed Singular correctly, this should open up a text help file (like a man page). Personally,
I like the online manual....
Getting started
Zube has graciously installed both Singular and Macaulay on nine machines in WB 205. Look for
the most recent machines (those with the largest screens and the name containing the letter nearest
Z (either O or P, as I recall).
To run Singular, open a terminal and type singular. If that doesn’t work, type cygwin and then
singular in the new terminal. You’ll know that singular has started when several lines identifying
the sofware, version, and authors are printed to the screen.
Zube, being the nice guy that he is, made it so that you can open Singular from the Start menu.
Point to Start/All Programs/Singular CAS, and click on “Singular (terminal).” This will open
Singular in a new terminal.
The other way of opening Singular in WB 205 is through Cygwin, though it is a bit nasty. First,
run “cmd” to get terminal access to your file system. Type “../cygwin” and then ”Cygwin” to
launch Cygwin. Cygwin is just a linux emulator for Windows, so you have just moved from one file
system to another (though one is technically contained in the other, blah, blah, blah). I suggest
that you then navigate to “My documents/” and create a new directory, tmp, by typing “mkdir
tmp”. Go into tmp (cd tmp) and type “Singular” to get Singular started. You’ll see later why I
am having you open Singular from a fresh directory.
By the way, there is a way to run Singular from within emacs, but I prefer vi (no emacs on my
machine), so I’ll stick to the command line interface.
Messing around
From here on, I will just provide some things to try and some running commentary. Type in the
commands that look
> like this
and see what happens. I neglected to include output so that you have to think a little.
1
As usual, feel free to veer off course and chase down topics of interest to you (with the caveat that
there will be at least a couple problems in the homework requiring the use of Singular).
> 2+2
Not 4? Try including a “;” at the end of the line (or on the next line). Singular will wait until you
provide this (or some other end-of-line character).
Singular has some nice data types which should remind you of C:
> int i=5;
> i;
> i++;
> i;
> i==3;
“0” means false.
> i==6;
“1” means true.
> i=3; i;
Be careful – “=” is assignment while “==” is comparison. Also, notice that you can put multiple
commands on one line.
> i:=3;
“:=” means nothing, so think of C rather than Maple.
Singular supports matrices:
> intmat m[2][2] = 1,2,3,4;
> m;
This gives you less attractive output with fewer keystrokes.
> print(m);
This gives you more attractive output with the cost of a few more keystrokes.
As you will see in all software packages, there are limitations and workarounds.
> m^2;
> m2;
> m*m;
Aha.
> m[1,2];
> m[1,2]=6; m;
“intvec” is similar.
By the way, if you make a mistake, just hit the up arrow to grab the latest line of input (and repeat
that for previous lines). “_” refers to the latest line of output.
2
> 2+2;
> _+672;
Also, in case I have bored you and you want to quit and go home, try
> quit; // Very polite software!
Oh yeah, ‘‘//’’ is the comment character in Singular.
WARNING: If you opened Singular from the Start menu, it is not so polite – the screen just
disappears. From Cygwin, it kindly says “Auf iedersehen.”
In case you care to play with strings, they are handled nicely:
> string s="Hey, how you"; s;
Oops:
> s=s+" doin’?"; s;
> s[5];
Why was there no output?
> s[4]; s[6];
Oh.
One last thing before we get to more serious math: You can write procedures (as in Maple). Here’s
one that I ripped from Steidel’s notes:
> proc GCD(int a, int b)
. {
.
int r = a%b;
.
while (r != 0)
.
{
.
a = b;
.
b = r;
.
r = a%b;
.
}
.
return(b);
. }
> GCD(21,15);
You can stick these sorts of things in text (ASCII) files and load them into singular by running, for
example, “singular FILENAME” (.sing is the standard suffix). This is why I had you go to a new
directory in which you have read/write permission. This won’t work if you open it from the Start
menu (or, at least, it is much more difficult for a few reasons).
You can load files on the fly, too. read(FILENAME); will grab the contents of the file and display
them to the screen (without execution, as in C). To execute them, use execute. To put it all
together, to run a script while Singular is open, try execute(read(FILENAME));.
In any case, this is a very nice way to collect and correct your input from session to session.
Rings and such
> 1.5;
3
Toto, we’re not in Maple anymore. One problem with Maple is that it was never clear which ring
was being used. There is no question in Singular – you have to pick one up front!
> ring R=0,(x,y,z),dp;
Let’s parse the syntax. We’re defining a ring, called R. It has three attributes – it has characteristic
zero (Q, unless we specify otherwise) and three variables. The “dp” refers to grevlex. lex is “lp”
and others may be found in the manual.
> R;
This gives you some information on the current ring. Singular is software for commutative algebra/algebraic geometry, so it wants to work over polynomial rings (or localizations of rings, quotient
rings, or tensor products).
Let’s define a polynomial:
> poly f=2x2+y3; f;
An integer immediately following a variable is an exponent for the variable only.
> 2x2; 2x^2;
Be careful! Also, I would advise that you do not use indexed variable names, or, if you do, use
x(1),x(2),....
OK, let’s change to the polynomial ring in variables a and b over the reals, with lex:
> ring R2=real,(a,b),lp;
> 1.5;
Ah, that’s better. You can get more precision by specifying “(real,25,50)” rather than “real” in
the declaration (for example). This would give you 50 digits of precision and 25 digits of accuracy.
What’s the difference? Ask me in class, or wait until we start in on numerical algebraic geometry
next week....
> f;
What happened? The instance “f” was in scope for the ring R, which is no longer the active ring.
Let’s switch back to R (from R2):
> setring R; f;
That’s better. Now go back.
> setring R2;
We can bring the definition of “f” into the current ring as follows:
> poly g=fetch(R,f);
By the way, you can work over a finite field by replacing “real” with a prime number (32003
is
√
nice) or over the complex numbers by replacing “real” with “complex.” Note that “i” is −1 in
Singular. You can also work over transcendental or algebraic extensions of rings....
Gröbner bases and Elimination
Now we can get serious. First though, a word about libraries. You’ll need to use these. For
example, many important procedures are included in the library “general.lib.”
4
> LIB ‘‘general.lib’’;
Notice that this includes library files like matrix.lib, poly.lib, ring.lib, and random.lib. It seems
that you may have access to some of the contents of these libraries (but not all!) without loading
them, though the help pages certainly require that the appropriate library be loaded.
Now then, let’s compute a Gröbner basis:
>
>
>
>
>
ring R=0,(x,y),dp;
poly f = x3-2xy;
poly g = x2y-2y2+x;
ideal I = f,g;
groebner(I);
Singular has two options for the computation of a Gröbner basis – Buchberger’s algorithm (no doubt
with the modifications in [CLO1], and others) and Mora’s algorithm (which we didn’t discuss). So
far, Faugère’s algorithms are only in Magma and Maple (as far as I know).
Straight from Garcia-Puente’s notes, let’s check and see if the point (x, y, z) = (1, 2, 0) lies on the
variety defined by a couple of polynomials. We’ll just substitute the values into the variables and
see whether the polynomials evaluate to 0. This is just a way of evaluating, really:
>
>
>
>
>
>
>
poly f = x3+y3+(x-y)*x2y2+z2; f;
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;
Neat, huh? We can also manage the division of a polynomial by a Gröbner basis:
> ideal K = groebner(f);
> reduce(g,K);
Now, let’s try elimination: > ring R = complex,(x,y,z),dp;
> ideal I = x2-y-z-1, x-y2-z-1, x-y-z2-1;
> ideal G = groebner(I);
> G;
Now we spot the univariate, solve it, and backtrack, right? Wait – where’s the univariate polynomial? What went wrong? Fix it, and then move along (once you get G). To solve the univariate
polynomial, just do the following:
> LIB "solve.lib";
> list L = laguerre_solve(G[1],100,100);
That puts the list of numerically-computed solutions into L. From there, you can backtrack (using
substitution).
5
Moving on
Cool stuff, huh? Now that you have the basics under your belt, why not play around a bit. Here
are a couple ideas:
1. Write a script to do elimination automatically (rather than doing each step manually). This
could be tricky – you’ll need to detect which polynomials are univariate.... Check out “eliminate,” “solve,” and such in the online manual.
2. Dig into the online manual to find a topic that interests you.
3. Dig into one of the tutorials that I mentioned above.
4. Find an example that chokes Maple (many primes in the coefficients, high degree, etc.) and
try it in Singular. Try several of these and keep track of the timings.
5. Type up one of our three-resolute serial-link planar robotic arm examples and try to solve
it....
6
Download