Call Singular from GAP

Run the examples from a blog post by Bill Hart.

First load the GAP package.

In [1]:
LoadPackage( "JuliaExperimental", false );;

A Nemo residue ring over Singular's ring of integers

In [2]:
R:= Julia.Nemo.ResidueRing( Julia.Singular.ZZ, 23 );
Out[2]:
<Julia: Residue Ring of Integer Ring modulo 23>
In [3]:
R(12) + R(7);
Out[3]:
<Julia: 19>
In [4]:
JuliaTypeInfo( R(12) );
Out[4]:
"Singular.n_Zn"
In [5]:
Julia.Base.parent( R(12) );
Out[5]:
<Julia: Residue Ring of Integer Ring modulo 23>

Polynomial rings

In [7]:
indetnames:= Julia.Base.convert( JuliaEvalString( "Array{String,1}" ),
ConvertedToJulia( [ "x", "y", "z", "t" ] ) );;
Rinfo:= Julia.Singular.PolynomialRing( Julia.Singular.QQ, indetnames );;
In [8]:
R:= Rinfo[1];
Out[8]:
<Julia: Singular Polynomial Ring (QQ),(x,y,z,t),(dp(4),C)>
In [9]:
indets:= ConvertedFromJulia( Rinfo[2] );
Out[9]:
[ <Julia: x>, <Julia: y>, <Julia: z>, <Julia: t> ]
In [13]:
x:= indets[1];; y:= indets[2];; z:= indets[3];; t:= indets[4];;

Polynomials

In [15]:
f:= (x+y+z)*(x^2*y + 2*x);
g:= (x+y+z)*(x+z+t);
Out[15]:
<Julia: x^3*y+x^2*y^2+x^2*y*z+2*x^2+2*x*y+2*x*z>
Out[15]:
<Julia: x^2+x*y+2*x*z+y*z+z^2+x*t+y*t+z*t>
In [16]:
Julia.Base.gcd( f, g );
Out[16]:
<Julia: x+y+z>

Ideals

In [17]:
I1:= Julia.Singular.Ideal( R );
Out[17]:
<Julia: Singular Ideal over Singular Polynomial Ring (QQ),(x,y,z,t),(dp(4),C) with generators ()>
In [18]:
I2:= Julia.Singular.Ideal( R, x, t*z + x );
Out[18]:
<Julia: Singular Ideal over Singular Polynomial Ring (QQ),(x,y,z,t),(dp(4),C) with generators (x, z*t+x)>
In [19]:
Julia.Singular.ngens( I2 );
Out[19]:
<Julia: 2>
In [20]:
I2[2];
Out[20]:
<Julia: z*t+x>

Groebner basis

In [21]:
I:= Julia.Singular.Ideal( R, x*y + 1, x+y, 2*x+y+z );
Out[21]:
<Julia: Singular Ideal over Singular Polynomial Ring (QQ),(x,y,z,t),(dp(4),C) with generators (x*y+1, x+y, 2*x+y+z)>
In [22]:
gbasis:= Julia.Base.std( I );
Out[22]:
<Julia: Singular Ideal over Singular Polynomial Ring (QQ),(x,y,z,t),(dp(4),C) with generators (y-z, 2*x+y+z, z^2-1)>
In [23]:
Julia.Singular.ngens( gbasis );
Out[23]:
<Julia: 3>

Syzygy matrix

In [24]:
M:= Julia.Singular.syz( I );
Out[24]:
<Julia: Singular Module over Singular Polynomial Ring (QQ),(x,y,z,t),(dp(4),C), with Generators:x*gen(3)-2*x*gen(2)+y*gen(3)-y*gen(2)-z*gen(2)y^2*gen(3)-y^2*gen(2)-y*z*gen(2)-y*gen(1)+z*gen(1)-gen(3)+2*gen(2)x*y*gen(2)-x*gen(1)-y*gen(1)+gen(2)>
In [25]:
# Currently there is no 'Julia.Singular.Matrix'.
JuliaFunction( "Matrix", "Singular" )( M );
Out[25]:
<Julia: [0, -y+z, -x-y-2*x-y-z, -y^2-y*z+2, x*y+1x+y, y^2-1, 0]>

Ideal arithmetic

In [26]:
I:= Julia.Singular.Ideal( R, x*y + 1, x+y, 2*x+y+z );
Out[26]:
<Julia: Singular Ideal over Singular Polynomial Ring (QQ),(x,y,z,t),(dp(4),C) with generators (x*y+1, x+y, 2*x+y+z)>
In [27]:
J:= Julia.Singular.Ideal( R, 2*x-y + 1, 2*z+x);
Out[27]:
<Julia: Singular Ideal over Singular Polynomial Ring (QQ),(x,y,z,t),(dp(4),C) with generators (2*x-y+1, x+2*z)>
In [28]:
I^2;
Out[28]:
<Julia: Singular Ideal over Singular Polynomial Ring (QQ),(x,y,z,t),(dp(4),C) with generators (x^2*y^2+2*x*y+1, x^2*y+x*y^2+x+y, 2*x^2*y+x*y^2+x*y*z+2*x+y+z, x^2+2*x*y+y^2, 2*x^2+3*x*y+y^2+x*z+y*z, 4*x^2+4*x*y+y^2+4*x*z+2*y*z+z^2)>
In [29]:
I * J;
Out[29]:
<Julia: Singular Ideal over Singular Polynomial Ring (QQ),(x,y,z,t),(dp(4),C) with generators (2*x^2*y-x*y^2+x*y+2*x-y+1, x^2*y+2*x*y*z+x+2*z, 2*x^2+x*y-y^2+x+y, x^2+x*y+2*x*z+2*y*z, 4*x^2-y^2+2*x*z-y*z+2*x+y+z, 2*x^2+x*y+5*x*z+2*y*z+2*z^2)>
In [30]:
Julia.Singular.lead( I );
Out[30]:
<Julia: Singular Ideal over Singular Polynomial Ring (QQ),(x,y,z,t),(dp(4),C) with generators (x*y, x, 2*x)>

Resolutions

In [31]:
I:= Julia.Singular.MaximalIdeal( R, 1 );
Out[31]:
<Julia: Singular Ideal over Singular Polynomial Ring (QQ),(x,y,z,t),(dp(4),C) with generators (x, y, z, t)>
In [32]:
I:= Julia.Base.std( I );
Out[32]:
<Julia: Singular Ideal over Singular Polynomial Ring (QQ),(x,y,z,t),(dp(4),C) with generators (t, z, y, x)>
In [33]:
r:= Julia.Singular.sres( I, 5 );
Out[33]:
<Julia: Singular Resolution:R^1 <- R^4 <- R^6 <- R^4 <- R^1>

Access to modules in the resolution

In [34]:
r[2];
Out[34]:
<Julia: Singular Module over Singular Polynomial Ring (QQ),(x,y,z,t),(dp(4),C), with Generators:-z*gen(1)+t*gen(2)-y*gen(1)+t*gen(3)-y*gen(2)+z*gen(3)-x*gen(1)+t*gen(4)-x*gen(2)+z*gen(4)-x*gen(3)+y*gen(4)>
In [35]:
r[3];
Out[35]:
<Julia: Singular Module over Singular Polynomial Ring (QQ),(x,y,z,t),(dp(4),C), with Generators:y*gen(1)-z*gen(2)+t*gen(3)x*gen(1)-z*gen(4)+t*gen(5)x*gen(2)-y*gen(4)+t*gen(6)x*gen(3)-y*gen(5)+z*gen(6)>
In [36]:
r[3][1];
Out[36]:
<Julia: y*gen(1)-z*gen(2)+t*gen(3)>

Arithmetic on module elements

In [37]:
r[2][1] * 3;
Out[37]:
<Julia: -3*z*gen(1)+3*t*gen(2)>
In [38]:
r[2][1] + r[2][2];
Out[38]:
<Julia: -y*gen(1)-z*gen(1)+t*gen(3)+t*gen(2)>

Standard bases and resolutions of modules

In [39]:
J:= Julia.Base.std( r[3] );
Out[39]:
<Julia: Singular Module over Singular Polynomial Ring (QQ),(x,y,z,t),(dp(4),C), with Generators:y*gen(1)-z*gen(2)+t*gen(3)x*gen(1)-z*gen(4)+t*gen(5)x*gen(2)-y*gen(4)+t*gen(6)x*gen(3)-y*gen(5)+z*gen(6)>
In [40]:
J1:= Julia.Singular.sres( J, 4 );
Out[40]:
<Julia: Singular Resolution:R^6 <- R^4 <- R^1>
In [41]:
J1[2];
Out[41]:
<Julia: Singular Module over Singular Polynomial Ring (QQ),(x,y,z,t),(dp(4),C), with Generators:-x*gen(1)+y*gen(2)-z*gen(3)+t*gen(4)>

Generic multivariate polynomial code in Nemo, over a Singular coefficient ring

In [50]:
Rinfo:= Julia.Nemo.PolynomialRing( Julia.Singular.ZZ, indetnames );;
R:= Rinfo[1];;
indets:= ConvertedFromJulia( Rinfo[2] );;
x:= indets[1];; y:= indets[2];; z:= indets[3];; t:= indets[4];;
f:= (2*t^2078*z^15*y^53-28*t^1080*z^15*y^44+98*t^82*z^15*y^35)*x^9
+(t^2003*y^40-14*t^1005*y^31+49*t^7*y^22)*x^7
+((t^2100+t^2000)*y^40 +(-4*t^1079*z^16+156*t^1078*z^15)*y^33
+(-14*t^1102-14*t^1002)*y^31+(28*t^81*z^16-1092*t^80*z^15)*y^24
+(49*t^104+49*t^4)*y^22)*x^6
+((-2*t^1004*z+78*t^1003)*y^20+(14*t^6*z-546*t^5)*y^11)*x^4
+(((-2*t^1101-2*t^1001)*z+(78*t^1100+78*t^1000))*y^20
+(2*t^80*z^17-156*t^79*z^16+3042*t^78*z^15)*y^13
+((14*t^103+14*t^3)*z+(-546*t^102-546*t^2))*y^11)*x^3
+(t^5*z^2-78*t^4*z+1521*t^3)*x
+((t^102+t^2)*z^2+(-78*t^101-78*t)*z+(1521*t^100+1521));;
g:= (4*t^1156*z^30*y^46-28*t^158*z^30*y^37)*x^9
+(4*t^1081*z^15*y^33-28*t^83*z^15*y^24)*x^7
+((4*t^1178+4*t^1078)*z^15*y^33+(-4*t^157*z^31+156*t^156*z^30)*y^26
+(-28*t^180-28*t^80)*z^15*y^24)*x^6
+(t^1006*y^20-7*t^8*y^11)*x^5
+((2*t^1103+2*t^1003)*y^20+(-4*t^82*z^16+156*t^81*z^15)*y^13
+(-14*t^105-14*t^5)*y^11)*x^4
+((t^1200+2*t^1100+t^1000)*y^20+((-4*t^179-4*t^79)*z^16
+(156*t^178+156*t^78)*z^15)*y^13+(-7*t^202-14*t^102-7*t^2)*y^11)*x^3
+(-t^7*z+39*t^6)*x^2
+((-2*t^104-2*t^4)*z+(78*t^103+78*t^3))*x
+((-t^201-2*t^101-t)*z+(39*t^200+78*t^100+39));;
In [51]:
p:= Julia.Base.gcd( f, g );
Out[51]:
<Julia: -2*x^6*y^33*z^15*t^1078+14*x^6*y^24*z^15*t^80-x^4*y^20*t^1003+7*x^4*y^11*t^5-x^3*y^20*t^1100-x^3*y^20*t^1000+2*x^3*y^13*z^16*t^79-78*x^3*y^13*z^15*t^78+7*x^3*y^11*t^102+7*x^3*y^11*t^2+x*z*t^4-39*x*t^3+z*t^101+z*t-39*t^100-39>