Singular

Home SINGULAR FAQs

Singular FAQs

Tricks & Pitfalls

C vs Singulars' programming language

Although many constructs from Singular' programming language are similar to those from the C programming language, there are some subtle differences. Most notably, this concerns:

  1. No rvalue of increments and assignments http://singular.mathematik.uni-kl.de/Manual/3-1-0/sing_346.htm
  2. Evaluation of logical expressions http://singular.mathematik.uni-kl.de/Manual/3-1-0/sing_347.htm
  3. No case or switch statement http://singular.mathematik.uni-kl.de/Manual/3-1-0/sing_348.htm
  4. Usage of commas http://singular.mathematik.uni-kl.de/Manual/3-1-0/sing_349.htm
  5. Usage of brackets http://singular.mathematik.uni-kl.de/Manual/3-1-0/sing_350.htm
  6. Behavior of continue http://singular.mathematik.uni-kl.de/Manual/3-1-0/sing_351.htm
  7. Return type of procedures http://singular.mathematik.uni-kl.de/Manual/3-1-0/sing_352.htm
  8. First index is 1 http://singular.mathematik.uni-kl.de/Manual/3-1-0/sing_353.htm
 

Identifier resolution

In Singular, an identifier (i.e., a "word") is resolved in the following way and order: It is checked for

  1. a reserved name (like ring, std, ...),
  2. a local variable (w.r.t. a procedure),
  3. a local ring variable (w.r.t. the current basering locally set in a procedure),
  4. a global variable,
  5. a global ring variable (w.r.t. the current basering)
  6. a monomial consisting of local ring variables written without operators,
  7. a monomial consisting of global ring variables written without operators.

Consequently, it is allowed to have general variables with the same name as ring variables. However, the above identifier resolution order must be kept in mind. Otherwise, surprising results may come up.

> ring r=0,(x,y),dp;
> int x;
> x*y;        // resolved product int*poly, i.e., 0*y
0
> xy;         // "xy" is one identifier and resolved to monomial xy
xy

For these reasons, we strongly recommend not to use variables which have the same name(s) as ring variables.

Moreover, we strongly recommend not to use ring variables whose name is fully contained in (i.e., is a substring of) another name of a ring variable. Otherwise, effects like the following might occur:

> ring r=0,(x, x1),dp; // name x is substring of name x1 !!!!!!!!!
> x;x1;        // resolved poly x
x
x1
> short=0; 2x1;     // resolved to monomial 2*x^1 !!!!!!
2*x
> 2*x1;       // resolved to product 2 times x1
2*x1
 

The mult command (interpretation of output)

For an arbitrary ideal or module I, mult(I) returns the multiplicity of the ideal generated by the leading monomials of the given generators of I, hence depends on the monomial ordering!

It frequently happened that the return value of degree(I) or mult(I) for an inhomogeneous ideal I has been misinterreted as the degree of the homogenization or as something like the 'degree of the affine part'.
But, this is not true (in general). For instance, if dp (degree reverse lexicographical ordering) was chosen as monomial ordering and if I is a Groebner basis, then mult(I) is the degree of the homogeneous ideal obtained by homogenizating I (w.r.t. a slack variable, say t) and then substituting t by 0. Hence, the result is the degree of the part at infinity (this can also be checked by looking at the initial ideal).

 

Mixing short and long notation (with *,^) in polys

The computation of a monomial has precedence over all operators. This leads to a strange behavior when mixing short and long notation in the definition of monomials:

> ring r=0,(x,y),dp;
> short=0;      // output in long format
> 7x2y3;
7*x^2*y^3
> 7*x^2*y^3;
7*x^2*y^3
> 7*x2y^3;     // same as 7*(x^2*y)^3
7*x^6*y^3
> 7x^2*y^3;   // same as (7*x)^2*y^3
49*x^2*y^3
 

Integer division and the / command

If two numerical constants (i.e., two sequences of digits) are divided using the / operator, the surrounding whitespace determines which division to use: if there is no space between the constants and the / operator (e.g., "3/2"), both numerical constants are treated as of type number and the current ring division is used. If there is at least one space surrounding the / operator (e.g., "3 / 2"), both numerical constants are treated as of type int and an integer division is performed. To avoid confusion, use the div operator instead of / for integer division and an explicit type cast to number for ring division. Note, that this problem does only occur for divisions of numerical constants.

> ring r=32002,x,dp;
> 3/2;    // ring division
-15994
> 3 / 2;  // integer division
1
> 3 div 2;
1
>  number(3) / number(2);
-15994
> number a=3;
> number b=2;
> a/b;
-15994
> int c=3;
> int d=2;
> c/d;
1
>  c / d;
1
 

Attributes lost under type conversion

Note that attributes assigned to objects usually are lost under type conversion.
For instance:
> ring r=0,x,dp;
> ideal I=x;
> I=std(x);
> attrib(I);
attr:isSB, type int
> vdim(I);
1
> I=module(I); 
> attrib(I);
no attributes
> vdim(I);
// ** I is no standard basis
1
This also applies to automatic type conversion (e.g. from resolution to list, from number to poly, or from module to matrix).
 

Limitations in Singular

Singular has the following limitations:

  1. the characteristic of a prime field must be less than or equal to 2147483629 (2^31)
  2. the characteristic of a prime field in the factory routines must be less than 536870912 (2^29))
  3. the characteristic of a prime field in the NTL routines must be less than NTL_SP_BOUND (2^30) on 32bit machines - This is always the case since currently, only factory uses NTL.)
  4. the number of elements in GF(p,n) must be less than 65536
  5. the (weighted) degree of a monomial must be less or equal than 2147483647
  6. the rank of any free module must be less or equal than 2147483647
  7. the maximal allowed exponent of a ring variable depends on the ordering of the ring and is at least 32767.
  8. the precision of long floating point numbers (for ground field real) must be less or equal than 32767
  9. integers (of type int) have the limited range from -2147483648 to 2147483647
  10. floating point numbers (type number from field real) have a limited range which is machine dependent. A typical range is -1.0e-38 to 1.0e+38. The string representation of overflow and underflow is machine dependent, as well. For example "Inf" on Linux, or "+.+00e+00" on HPUX. Their input syntax is given by scanf, but must start with a digit.
  11. floating point numbers (type number from field real with a precision p larger then 3) use internally mpf_set_default_prec(3.5*p+1). Their input syntax is given by mpf_set_str from GMP, but must start with a digit.
  12. the length of an identifier is unlimited but listvar displays only the first 20 characters
  13. statements may not contain more than 10000 tokens
  14. All input to Singular must be 7-bit clean, i.e. special characters like the the German Umlaute (ä, ö, etc.), or the French accent characters may neither appear as input to SINGULAR, nor in libraries or procedure definitions.

This information is also provided by the Singular manual. Entering

help Limitations;

in a Singular session should guide you to the relevant section of the manual.

 

 

 
Howtos

How to pause Singular LIB-code?

  1. You will need to modify the LIB. Hence, you need to find out where it is situated on your computer. The easiest way to do so is by loading the LIB inside Singular. Singular will then tell you from where exactly it has been loaded.
  2. Go to the LIB and open it in a text editor.
  3. Find the appropriate line of Singular code where you want to pause execution.
  4. Now you can control the library's behaviour by adding some code:
    • You can simply insert a print statement which will of course not pause execution but provide some more useful output.
    • You put a "pause()" which will halt execution and wait for you to hit "return".
    • You may also put a "~;". This halts execution and allows you to execute any SINGULAR command before you go on by simply hitting "return" right after the prompt.
 

How to get the runtime of a command?

See our manual: http://www.singular.uni-kl.de/Manual/3-1-1/sing_340.htm.
There you find a description of the system variable timer with examples how to use it for kernel commands and procedures.

 

Manual in "chm" format

The Singular documentation is also available in a single file for the Microsoft HTML Help system. 

Since Singular 3.0.0 you can choose HTML Help as a Help browser from within Singular by just typing:

system("--browser", "htmlhelp");

Now Singular will launch the MS Html Help Browser whenever you use the command "help". Please note that this browser is only available in the Windows version of Singular.

If you use a version before 3.0.0 you can open the file through double click on all MS Windows system having an Internet Explorer 4.x or higher.

But there are also viewers avaible for different OS, such as Linux, Unix or Mac OS X.

Viewers for other platforms

Oliver Wienand
Singular Team

 

Syntax highlighter for ConTEXT

You can also use third party editors to access singular. I will describe the process exemplary for ConTEXT, a neat little programmers editor.

1. Download this highlighter definition file for ConTEXT and copy it to:

C:Program FilesConTEXTHighlighters

You may also download the manual in "chm" format and set the key "HelpFile: C:ProgrammeConTEXTsingular.chm" to the location you stored the file. Then you can call the singular help by pressing F1.

2. Now you have highlighting for files ending with ".sgr" and ".LIB". Further you can make ConTEXT to call singular with hotkeys.

a) Open Options -> Environment Options ... -> Execute Keys.

b) Click on the add button and enter "sgr" or whatever extension you want to have associated with singular.

c) Choose the key and enter the following data:

Execute: C:Program FilesCygWinusrlocalSingular2-0-5ix86-WinSingular.exe

Start in: C:Program FilesCygWinusrlocalSingular2-0-5ix86-Win

Parameters: -t %n

Hint: You might be creative.

Dependent on what behavior you like, you may choose the "Capture console output" or the "Scroll console ..." option.

End the file by an exit; statement, if you use the "Capture console ..." option, because if not, ConTEXT will prompt you for termination of singular. (It thinks it may be in an infinite loop.)

Oliver Wienand
Singular Team

 

Cygwin paths and a way to run Singular from the explorer

To run Singular independent of the provided icons and Cygwin shells, you must set several environment variables to tell Singular where to find the necessary Cygwin dlls and its own libraries, documentations, etc.

You can access these variables in the following matter:

    1. Go to the control panel and start "System Properties"
    2. Choose the tab "Advanced" (upper rightmost)
    3. Click "Environment variables"
    4. Add "SINGULAR_BIN_DIR" = "/usr/lib/Singular"
    5. Add "SINGULAR_ROOT_DIR" = "/usr/share/Singular"
    6. Add "SINGULAR_INFO_FILE" = "/usr/share/info/singular.info"
    7. Add "SINGULAR_IDX_FILE" = "/usr/share/doc/Singular-3.0.0/doc/singular.idx"
    8. Add "SINGULAR_CHM_FILE" = "/usr/share/doc/Singular-3.0.0/doc/Manual.chm"
    9. Add "SINGULAR_EXAMPLES_DIR" = "/usr/share/doc/Singular-3.0.0/examples"


Further you must add the following directory to the path, i.e.
select the variable "Path" in the dialog and choose "Edit". Now add at the end of the line

[old path];C:cygwinbin;C:cygwinusrX11R6bin

provided you installed Cygwin to "C:cygwin". The latter is only needed if you will use ESingular or other X applications.

When you have done this, you can start nearly all Cygwin based applications by just clicking on the executeables within the windows explorer.

Further you can arrange to start Singular from every Microsoft Shell, if you also add

[old path];C:cygwinlibSingular

to your path variable.

Oliver Wienand
Singular Team

 

Uninstalling Singular for Windows

Since 3.0.0 every Singular installation ships with a correct and full fledged Cygwin installation. Therefore you may use the Cygwin setup routine to uninstall Singular.

If you installed Singular from a Package For The Web distribution or if you have chosen the package singular-icons during installation, you can start Cygwin setup from the start menu:

Singular CAS -> Cygwin -> Setup (Cygwin)

If you have installed Singular differently or if you cannot find the above link anymore, the most recent version of Cygwin setup is available from

http://www.cygwin.com/setup.exe.

Please note that there is no entry in the Windows Software dialog, as known from version prior to 3.0.0.

Furthermore, the deinstallation process described above may miss to delete Singular shortcuts from both your desktop and Windows start menu. Provided you have the appropriate rights, you can safely delete them by hand.

 

Accessing Singular from Maple

Dear Singular users,

one of you, Rafal Ablamowicz, has provided a Maple worksheet which allows an easy access from Maple 8, 9, 9.5 and 10 to Singular 2 or 3 on Windows and Linux systems.

After you have installed installed Singular as described in the Download section you just have to load the Maple worksheet

Maple worksheet with Singular link (Updated 04.08.2006)

Maple worksheet with Singular link (Original version)

and execute it step by step. Please note that you have to enter the correct path to your Singular and Maple installation in the second step.

Please direct questions concerning the worksheet to

rablamowicz (at) tntech edu

and

singular (at) mathematik uni-kl de

Oliver Wienand
Singular Team

 

ESingular Problems

If you encounter the following problem:

    i) Singular (rxvt) or Singular (Terminal) is working
    ii) ESingular starts the Emacs editor but fails to load Singular

Please try the following steps:

    1) Exit all Cygwin processes (including the X-Server, which you can find in the tray area)
    2) Start c:cygwinbinash.exe from the Explorer
    3) Type
/bin/rebaseall


Now ESingular should be working. If not, please contact us at

singular (at) mathematik.uni-kl.de

Oliver Wienand
Singular Team