This interface is extremely flexible, since it's exactly like typing into the Singular interpreter, and anything that works there should work here.
pexpect
module must be installed and the
Singular
command must be in your path.
Both pexpect and Singular
are built and installed
when you install SAGE.
AUTHORS: David Joyner and William Stein
First we illustrate multivariate polynomial factorization:
sage: R1 = singular.ring(0, '(x,y)', 'dp') sage: R1 // characteristic : 0 // number of vars : 2 // block 1 : ordering dp // : names x y // block 2 : ordering C sage: f = singular.new('9x16 - 18x13y2 - 9x12y3 + 9x10y4 - 18x11y2 + 36x8y4 + 18x7y5 - 18x5y6 + 9x6y4 - 18x3y6 - 9x2y7 + 9y8') sage: f 9x16-18x13y2-9x12y3+9x10y4-18x11y2+36x8y4+18x7y5-18x5y6+9x6y4-18x3y6-9x2y7+ 9y8 sage: f.parent() A running instance of singular
sage: F = f.factorize(); F [1]: _[1]=9 _[2]=x6-2x3y2-x2y3+y4 _[3]=-x5+y2 [2]: 1,1,2
sage: F[1] 9, x6-2x3y2-x2y3+y4, -x5+y2 sage: F[1][2] x6-2x3y2-x2y3+y4
We can convert f and each exponent back to SAGE objects as well.
sage: x, y = MPolynomialRing(RationalField(), 2).gens() sage: g = eval(f.sage_polystring()); g 9*x_1^8 - 9*x_0^2*x_1^7 - 18*x_0^3*x_1^6 - 18*x_0^5*x_1^6 + 9*x_0^6*x_1^4 + 18*x_0^7*x_1^5 + 36*x_0^8*x_1^4 + 9*x_0^10*x_1^4 - 18*x_0^11*x_1^2 - 9*x_0^12*x_1^3 - 18*x_0^13*x_1^2 + 9*x_0^16 sage: eval(F[1][2].sage_polystring()) x_1^4 - x_0^2*x_1^3 - 2*x_0^3*x_1^2 + x_0^6
This example illustrates polynomial GCD's:
sage: R2 = singular.ring(0, '(x,y,z)', 'lp') sage: a = singular.new('3x2*(x+y)') sage: b = singular.new('9x*(y2-x2)') sage: g = a.gcd(b) sage: g x2+xy
This example illustrates computation of a Groebner basis:
sage: R3 = singular.ring(0, '(a,b,c,d)', 'lp') sage: I = singular.ideal(['a+b+c+d', 'ab+ad+bc+cd', 'abc+abd+acd+bcd', 'abcd-1']) sage: I2 = I.groebner() sage: I2 c2d6-c2d2-d4+1, c3d2+c2d3-c-d, bd4-b+d5-d, bc-bd5+c2d4+cd-d6-d2, b2+2bd+d2, a+b+c+d
The following example is the same as the one in the Singular - Gap interface documentation:
sage: R = singular.ring(0, '(x0,x1,x2)', 'lp') sage: I1 = singular.ideal(['x0*x1*x2 -x0^2*x2', 'x0^2*x1*x2-x0*x1^2*x2-x0*x1*x2^2', 'x0*x1-x0*x2-x1*x2']) sage: I2 = I1.groebner() sage: I2 x1^2*x2^2, x0*x2^3-x1^2*x2^2+x1*x2^3, x0*x1-x0*x2-x1*x2, x0^2*x2-x0*x1*x2
This example illustrates moving a polynomial from one ring to another. It also illustrates calling a method of an object with an argument.
sage: R = singular.ring(0, '(x,y,z)', 'dp') sage: f = singular.new('x3+y3+(x-y)*x2y2+z2') sage: f x3y2-x2y3+x3+y3+z2 sage: R1 = singular.ring(0, '(x,y,z)', 'ds') sage: f = R.fetch(f) sage: f z2+x3+y3+x3y2-x2y3
We can calculate the Milnor number of
:
sage: _=singular('LIB "sing.lib";') # assign to _ to suppress printing sage: f.milnor() 4
The Jacobian applied twice yields the Hessian matrix of
,
with which we can compute.
sage: H = f.jacob().jacob() sage: H 6x+6xy2-2y3,6x2y-6xy2, 0, 6x2y-6xy2, 6y+2x3-6x2y,0, 0, 0, 2 sage: H.det() 72xy+24x4-72x3y+72xy3-24y4-48x4y2+64x3y3-48x2y4
The 1x1 and 2x2 minors:
sage: H.minor(1) 2, 6y+2x3-6x2y, 6x2y-6xy2, 6x2y-6xy2, 6x+6xy2-2y3 sage: H.minor(2) 12y+4x3-12x2y, 12x2y-12xy2, 12x2y-12xy2, 12x+12xy2-4y3, -36xy-12x4+36x3y-36xy3+12y4+24x4y2-32x3y3+24x2y4
sage: _=singular('option(redSB)') sage: H.minor(1).groebner() 1
The module interfaces.singular defines the following classes: