# Call Singular from GAP¶

Show the example from the Computeralgebra-Rundrief Nr. 55, Oktober 2014.

In :
LoadPackage( "JuliaExperimental", false );;


## Part 1: Just call the appropriate Julia functions from GAP.¶

Define the ring with the default monomial ordering. The syntax looks complicated; the reason is that the Julia syntax for specifying the monomial ordering ('named arguments') is not available in the low level interface. (As a workaround, we can provide some Julia code, see Part 2 below.)

In :
indetnames:= ConvertedToJulia( [ "x0", "x1", "x2", "x3" ] );
indetnames:= Julia.Base.convert( JuliaEvalString( "Array{String,1}" ),
indetnames );
Rinfo:= Julia.Singular.PolynomialRing( Julia.Singular.QQ, indetnames );
R:= Rinfo;
indets:= ConvertedFromJulia( Rinfo );
x0:= indets;;  x1:= indets;;  x2:= indets;;  x3:= indets;;

Out:
<Julia: Any["x0", "x1", "x2", "x3"]>
Out:
<Julia: String["x0", "x1", "x2", "x3"]>
Out:
<Julia: (Singular Polynomial Ring (QQ),(x0,x1,x2,x3),(dp(4),C), Singular.spoly{Singular.n_Q}[x0, x1, x2, x3])>
Out:
<Julia: Singular Polynomial Ring (QQ),(x0,x1,x2,x3),(dp(4),C)>
Out:
[ <Julia: x0>, <Julia: x1>, <Julia: x2>, <Julia: x3> ]

Define the polynomial $( x_1 + x_3 )^2$.

In :
p:= (x1+x3)^2;

Out:
<Julia: x1^2+2*x1*x3+x3^2>

Define the ideal in R generated by $x_0^2 - x_1 x_3$ and $x_0 x_1 - x_2 x_3$.

In :
I:= Julia.Singular.Ideal( R, x0^2 - x1*x3, x0*x1 - x2*x3 );

Out:
<Julia: Singular Ideal over Singular Polynomial Ring (QQ),(x0,x1,x2,x3),(dp(4),C) with generators (x0^2-x1*x3, x0*x1-x2*x3)>

The corresponding matrix $i$ (of ideal generators).

In :
i:= JuliaFunction( "Matrix", "Singular" )( I );

Out:
<Julia: [x0^2-x1*x3, x0*x1-x2*x3]>

The sum $I + I$ means the sum of ideals.

In :
J:= I + I;

Out:
<Julia: Singular Ideal over Singular Polynomial Ring (QQ),(x0,x1,x2,x3),(dp(4),C) with generators (x0^2-x1*x3, x0*x1-x2*x3)>

Whereas $i + i$ means the sum of Singular matrices.

In :
i + i;

Out:
<Julia: [2*x0^2-2*x1*x3, 2*x0*x1-2*x2*x3]>

The squared ideal $I^2$ inside $R$:

In :
I2 := I^2;

Out:
<Julia: Singular Ideal over Singular Polynomial Ring (QQ),(x0,x1,x2,x3),(dp(4),C) with generators (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$.

In :
G:= Julia.Base.std( I );

Out:
<Julia: Singular Ideal over Singular Polynomial Ring (QQ),(x0,x1,x2,x3),(dp(4),C) with generators (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 a Singular module.

In :
S:= Julia.Singular.syz( G );

Out:
<Julia: Singular Module over Singular Polynomial Ring (QQ),(x0,x1,x2,x3),(dp(4),C), with Generators:x0*gen(1)-x1*gen(2)-gen(3)x1*x3*gen(1)-x2*x3*gen(2)-x0*gen(3)>

To access the second column of $S$ use:

In :
S;

Out:
<Julia: x1*x3*gen(1)-x2*x3*gen(2)-x0*gen(3)>

To create a matrix in Singular.jl, use the following.

Singular.matrix( R, 3, 2, [ x0, x3, x1, x2, x3, x0 ] )'

Via the GAP interface, the following works. (We have to adjust the Julia type of the array, in order to make it acceptable for AbstractAlgebra.matrix.)

In :
arr1:= ConvertedToJulia( [ x0, x3, x1, x2, x3, x0 ] );;
arr2:= Julia.Base.convert(
JuliaEvalString( "Array{Singular.spoly{Singular.n_Q},1}" ),
arr1 );;
m:= Julia.AbstractAlgebra.matrix( R, 3, 2, arr2 );

Out:
<Julia: [x0 x3][x1 x2][x3 x0]>

To extract the $(2,1)$-entry from the matrix use the following. (Access to 'rows' or 'columns' of such a matrix is not supported.)

In :
m[ 2, 1 ];

Out:
<Julia: x1>

## Part 2: Use some GAP structures on top of the Julia interface.¶

Define the ring with the monomial ordering "degrevlex".

In :
R:= SingularPolynomialRing( Rationals, [ "x0", "x1", "x2", "x3" ] :
ordering:= "dp" );
AssignGeneratorVariables( R );

#I  Global variable x0' is already defined and will be overwritten
#I  Global variable x1' is already defined and will be overwritten
#I  Global variable x2' is already defined and will be overwritten
#I  Global variable x3' is already defined and will be overwritten
#I  Assigned the global variables [ x0, x1, x2, x3 ]

Out:
Singular_QQ[x0,x1,x2,x3]

Define the polynomial $( x_1 + x_3 )^2$.

In :
p:= (x1+x3)^2;
IsSingularPolynomial( p );

Out:
<<Julia: x1^2+2*x1*x3+x3^2>>
Out:
true

Define the ideal in $R$ generated by $x_0^2 - x_1 x_3$ and $x_0 x_1 - x_2 x_3$.

In :
I:= Ideal( R, [ x0^2 - x1*x3, x0*x1 - x2*x3 ] );

Out:
<semigroup>

Do not mix up the ideal and its list of generators.

In :
i:= GeneratorsOfIdeal( I );

Out:
[ <<Julia: x0^2-x1*x3>>, <<Julia: x0*x1-x2*x3>> ]

The Gröbner basis of the ideal $I$ is returned as a new different (but mathematically equal) ideal $G$.

In :
G:= GroebnerBasisIdeal( I );
GeneratorsOfIdeal( G );

Out:
<semigroup>
Out:
[ <<Julia: x0*x1-x2*x3>>, <<Julia: x0^2-x1*x3>>, <<Julia: x1^2*x3-x0*x2*x3>> ]