‣ Singular ( str ) | ( function ) |
‣ SingularLastOutput ( ) | ( function ) |
‣ SingularLastError ( ) | ( function ) |
Instructs the Singular interpreter to execute the command given by the string str. It returns true
in case Singular succeeds, otherwise false
(i.e. if an error occurred). These are not the return values of a computation done by Singular but merely an "exit code". A subsequent call to SingularLastOutput( )
returns a string containing the output of the Singular interpreter. Similarly SingularLastError( )
returns a string containing the last error message output by the Singular interpreter, if any.
gap> Singular( "1+1;" ); true gap> SingularLastOutput( ); "2\n" gap> SingularLastError( ); "" gap> Singular( "1+1;" );; gap> Display( SingularLastOutput( ) ); 2
‣ SI_LIB ( libname ) | ( function ) |
Instructs the Singular interpreter to load the library with the given name libname. For example, we can load matrix.lib
which provides the Singular function submat
, which is mapped to the GAP function SIL_submat
.
gap> SIL_submat; Error, Variable: 'SIL_submat' must have a value gap> SI_LIB( "matrix.lib" ); true gap> SIL_submat; function( arg ) ... end
Here is a short example in Singular 4.0.1 demonstrating some basic procedures. Singular uses =
for assignments and suppresses any output while GAP uses :=
for assignments and triggers the so-called View
-method, which gives a very brief description of the object (unless suppressed by a trailing ;;
). Basically, Singular's print procedure is mapped to the so-called Display
-method in GAP.
Start by loading SingularInterface in GAP.
gap> LoadPackage( "SingularInterface" ); true
Define the ring \(R := \mathbb{Q}[x_0, x_1, x_2, x_3]\) (with the monomial ordering degrevlex
):
gap> R := SI_ring( 0, "x0..3", [["dp",4]] ); <singular ring, 4 indeterminates> gap> ## short=0 is the default, disable by: Singular( "short=1" ); gap> SI_option( "redTail" ); true
Define the polynomial \((x_1+x_3)^2\):
gap> AssignGeneratorVariables( R ); #I Assigned the global variables [x0,x1,x2,x3] gap> p := (x1+x3)^2; x1^2+2*x1*x3+x3^2 gap> IsSI_poly( p ); true
Define the ideal \(I := \langle x_0^2-x_1 x_3,x_0 x_1-x_2 x_3 \rangle \lhd R\):
gap> I := SI_ideal([x0^2-x1*x3, x0*x1-x2*x3]); <singular ideal, 2 gens> gap> Display( I ); x0^2-x1*x3, x0*x1-x2*x3
The corresponding matrix \(i\):
gap> i := SI_matrix( I ); <singular matrix, 1x2> gap> Display( i ); x0^2-x1*x3,x0*x1-x2*x3
The sum \(I+I\) means the sum of ideals:
gap> J:=I+I; <singular ideal, 2 gens> gap> Display( J ); x0^2-x1*x3, x0*x1-x2*x3
Whereas \(i+i\) means the sum of matrices:
gap> Display( i + i ); 2*x0^2-2*x1*x3,2*x0*x1-2*x2*x3
The squared ideal \(I^2 \lhd R\):
gap> I2 := I^2; <singular ideal, 3 gens> gap> Display( I2 ); x0^4-2*x0^2*x1*x3+x1^2*x3^2, x0^3*x1-x0*x1^2*x3-x0^2*x2*x3+x1*x2*x3^2, x0^2*x1^2-2*x0*x1*x2*x3+x2^2*x3^2
The Gröbner basis of the ideal \(I\) is returned as a new different (but mathematically equal) ideal \(G\):
gap> G := SI_std( I ); <singular ideal, 3 gens> gap> Display( G ); x0*x1-x2*x3, x0^2-x1*x3, x1^2*x3-x0*x2*x3
The syzygies of the generators of \(G\) are the columns of the Singular datatype module
:
gap> S := SI_syz( G ); <singular module, 2 vectors in free module of rank 3> gap> Display( S ); x0, x1*x3, -x1,-x2*x3, -1, -x0
To access the second column of S
use:
gap> S[2]; <singular vector, 3 entries> gap> Display( S[2] ); [x1*x3,-x2*x3,-x0]
To access the first entry of the second column of S
use:
gap> S[2][1]; x1*x3 gap> p - S[2][1]; x1^2+x1*x3+x3^2
To create a matrix use:
gap> m := SI_matrix( R, 3, 2, "x0,x3,x1,x2,x3,x0" ); <singular matrix, 3x2> gap> Display( m ); x0,x3, x1,x2, x3,x0
To extract the (2,1)-entry from the matrix use:
gap> m[[2,1]]; x1
The sum of the module
S
and the matrix
m
is their augmentation:
gap> S + m; <singular module, 4 vectors in free module of rank 3> gap> Display( S + m ); x0, x1*x3, x0,x3, -x1,-x2*x3,x1,x2, -1, -x0, x3,x0
generated by GAPDoc2HTML