Interface to Singular#
Introduction#
This interface is extremely flexible, since it’s exactly like typing into the Singular interpreter, and anything that works there should work here.
The Singular interface will only work if Singular is installed on your computer; this should be the case, since Singular is included with Sage. The interface offers three pieces of functionality:
singular_console()
– A function that dumps you into an interactive command-line Singular session.singular(expr, type='def')
– Creation of a Singular object. This provides a Pythonic interface to Singular. For example, iff=singular(10)
, thenf.factorize()
returns the factorization of \(10\) computed using Singular.singular.eval(expr)
– Evaluation of arbitrary Singular expressions, with the result returned as a string.
Of course, there are polynomial rings and ideals in Sage as well
(often based on a C-library interface to Singular). One can convert
an object in the Singular interpreter interface to Sage by the
method sage()
.
Tutorial#
EXAMPLES: First we illustrate multivariate polynomial factorization:
sage: R1 = singular.ring(0, '(x,y)', 'dp')
sage: R1
polynomial ring, over a field, global ordering
// coefficients: QQ
// number of vars : 2
// block 1 : ordering dp
// : names x y
// block 2 : ordering C
sage: f = singular('9x16 - 18x13y2 - 9x12y3 + 9x10y4 - 18x11y2 + 36x8y4 + 18x7y5 - 18x5y6 + 9x6y4 - 18x3y6 - 9x2y7 + 9y8')
sage: f
9*x^16-18*x^13*y^2-9*x^12*y^3+9*x^10*y^4-18*x^11*y^2+36*x^8*y^4+18*x^7*y^5-18*x^5*y^6+9*x^6*y^4-18*x^3*y^6-9*x^2*y^7+9*y^8
sage: f.parent()
Singular
>>> from sage.all import *
>>> R1 = singular.ring(Integer(0), '(x,y)', 'dp')
>>> R1
polynomial ring, over a field, global ordering
// coefficients: QQ
// number of vars : 2
// block 1 : ordering dp
// : names x y
// block 2 : ordering C
>>> f = singular('9x16 - 18x13y2 - 9x12y3 + 9x10y4 - 18x11y2 + 36x8y4 + 18x7y5 - 18x5y6 + 9x6y4 - 18x3y6 - 9x2y7 + 9y8')
>>> f
9*x^16-18*x^13*y^2-9*x^12*y^3+9*x^10*y^4-18*x^11*y^2+36*x^8*y^4+18*x^7*y^5-18*x^5*y^6+9*x^6*y^4-18*x^3*y^6-9*x^2*y^7+9*y^8
>>> f.parent()
Singular
sage: F = f.factorize(); F
[1]:
_[1]=9
_[2]=x^6-2*x^3*y^2-x^2*y^3+y^4
_[3]=-x^5+y^2
[2]:
1,1,2
>>> from sage.all import *
>>> F = f.factorize(); F
[1]:
_[1]=9
_[2]=x^6-2*x^3*y^2-x^2*y^3+y^4
_[3]=-x^5+y^2
[2]:
1,1,2
sage: F[1]
9,
x^6-2*x^3*y^2-x^2*y^3+y^4,
-x^5+y^2
sage: F[1][2]
x^6-2*x^3*y^2-x^2*y^3+y^4
>>> from sage.all import *
>>> F[Integer(1)]
9,
x^6-2*x^3*y^2-x^2*y^3+y^4,
-x^5+y^2
>>> F[Integer(1)][Integer(2)]
x^6-2*x^3*y^2-x^2*y^3+y^4
We can convert \(f\) and each exponent back to Sage objects as well.
sage: g = f.sage(); g
9*x^16 - 18*x^13*y^2 - 9*x^12*y^3 + 9*x^10*y^4 - 18*x^11*y^2 + 36*x^8*y^4 + 18*x^7*y^5 - 18*x^5*y^6 + 9*x^6*y^4 - 18*x^3*y^6 - 9*x^2*y^7 + 9*y^8
sage: F[1][2].sage()
x^6 - 2*x^3*y^2 - x^2*y^3 + y^4
sage: g.parent()
Multivariate Polynomial Ring in x, y over Rational Field
>>> from sage.all import *
>>> g = f.sage(); g
9*x^16 - 18*x^13*y^2 - 9*x^12*y^3 + 9*x^10*y^4 - 18*x^11*y^2 + 36*x^8*y^4 + 18*x^7*y^5 - 18*x^5*y^6 + 9*x^6*y^4 - 18*x^3*y^6 - 9*x^2*y^7 + 9*y^8
>>> F[Integer(1)][Integer(2)].sage()
x^6 - 2*x^3*y^2 - x^2*y^3 + y^4
>>> g.parent()
Multivariate Polynomial Ring in x, y over Rational Field
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
x^2+x*y
>>> from sage.all import *
>>> R2 = singular.ring(Integer(0), '(x,y,z)', 'lp')
>>> a = singular.new('3x2*(x+y)')
>>> b = singular.new('9x*(y2-x2)')
>>> g = a.gcd(b)
>>> g
x^2+x*y
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', 'a*b + a*d + b*c + c*d', 'a*b*c + a*b*d + a*c*d + b*c*d', 'a*b*c*d - 1'])
sage: I2 = I.groebner()
sage: I2
c^2*d^6-c^2*d^2-d^4+1,
c^3*d^2+c^2*d^3-c-d,
b*d^4-b+d^5-d,
b*c-b*d^5+c^2*d^4+c*d-d^6-d^2,
b^2+2*b*d+d^2,
a+b+c+d
>>> from sage.all import *
>>> R3 = singular.ring(Integer(0), '(a,b,c,d)', 'lp')
>>> I = singular.ideal(['a + b + c + d', 'a*b + a*d + b*c + c*d', 'a*b*c + a*b*d + a*c*d + b*c*d', 'a*b*c*d - 1'])
>>> I2 = I.groebner()
>>> I2
c^2*d^6-c^2*d^2-d^4+1,
c^3*d^2+c^2*d^3-c-d,
b*d^4-b+d^5-d,
b*c-b*d^5+c^2*d^4+c*d-d^6-d^2,
b^2+2*b*d+d^2,
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*x2^2-x1*x2^2
sage: I2.sage()
Ideal (x1^2*x2^2, x0*x2^3 - x1^2*x2^2 + x1*x2^3, x0*x1 - x0*x2 - x1*x2, x0^2*x2 - x0*x2^2 - x1*x2^2) of Multivariate Polynomial Ring in x0, x1, x2 over Rational Field
>>> from sage.all import *
>>> R = singular.ring(Integer(0), '(x0,x1,x2)', 'lp')
>>> 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'])
>>> I2 = I1.groebner()
>>> 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*x2^2-x1*x2^2
>>> I2.sage()
Ideal (x1^2*x2^2, x0*x2^3 - x1^2*x2^2 + x1*x2^3, x0*x1 - x0*x2 - x1*x2, x0^2*x2 - x0*x2^2 - x1*x2^2) of Multivariate Polynomial Ring in x0, x1, x2 over Rational Field
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('x3+y3+(x-y)*x2y2+z2')
sage: f
x^3*y^2-x^2*y^3+x^3+y^3+z^2
sage: R1 = singular.ring(0, '(x,y,z)', 'ds')
sage: f = R.fetch(f)
sage: f
z^2+x^3+y^3+x^3*y^2-x^2*y^3
>>> from sage.all import *
>>> R = singular.ring(Integer(0), '(x,y,z)', 'dp')
>>> f = singular('x3+y3+(x-y)*x2y2+z2')
>>> f
x^3*y^2-x^2*y^3+x^3+y^3+z^2
>>> R1 = singular.ring(Integer(0), '(x,y,z)', 'ds')
>>> f = R.fetch(f)
>>> f
z^2+x^3+y^3+x^3*y^2-x^2*y^3
We can calculate the Milnor number of \(f\):
sage: _=singular.LIB('sing.lib') # assign to _ to suppress printing
sage: f.milnor()
4
>>> from sage.all import *
>>> _=singular.LIB('sing.lib') # assign to _ to suppress printing
>>> f.milnor()
4
The Jacobian applied twice yields the Hessian matrix of \(f\), with which we can compute.
sage: H = f.jacob().jacob()
sage: H
6*x+6*x*y^2-2*y^3,6*x^2*y-6*x*y^2, 0,
6*x^2*y-6*x*y^2, 6*y+2*x^3-6*x^2*y,0,
0, 0, 2
sage: H.sage()
[6*x + 6*x*y^2 - 2*y^3 6*x^2*y - 6*x*y^2 0]
[ 6*x^2*y - 6*x*y^2 6*y + 2*x^3 - 6*x^2*y 0]
[ 0 0 2]
sage: H.det() # This is a polynomial in Singular
72*x*y+24*x^4-72*x^3*y+72*x*y^3-24*y^4-48*x^4*y^2+64*x^3*y^3-48*x^2*y^4
sage: H.det().sage() # This is the corresponding polynomial in Sage
72*x*y + 24*x^4 - 72*x^3*y + 72*x*y^3 - 24*y^4 - 48*x^4*y^2 + 64*x^3*y^3 - 48*x^2*y^4
>>> from sage.all import *
>>> H = f.jacob().jacob()
>>> H
6*x+6*x*y^2-2*y^3,6*x^2*y-6*x*y^2, 0,
6*x^2*y-6*x*y^2, 6*y+2*x^3-6*x^2*y,0,
0, 0, 2
>>> H.sage()
[6*x + 6*x*y^2 - 2*y^3 6*x^2*y - 6*x*y^2 0]
[ 6*x^2*y - 6*x*y^2 6*y + 2*x^3 - 6*x^2*y 0]
[ 0 0 2]
>>> H.det() # This is a polynomial in Singular
72*x*y+24*x^4-72*x^3*y+72*x*y^3-24*y^4-48*x^4*y^2+64*x^3*y^3-48*x^2*y^4
>>> H.det().sage() # This is the corresponding polynomial in Sage
72*x*y + 24*x^4 - 72*x^3*y + 72*x*y^3 - 24*y^4 - 48*x^4*y^2 + 64*x^3*y^3 - 48*x^2*y^4
The 1x1 and 2x2 minors:
sage: H.minor(1)
2,
6*y+2*x^3-6*x^2*y,
6*x^2*y-6*x*y^2,
6*x^2*y-6*x*y^2,
6*x+6*x*y^2-2*y^3,
0,
0,
0,
0
sage: H.minor(2)
12*y+4*x^3-12*x^2*y,
12*x^2*y-12*x*y^2,
12*x^2*y-12*x*y^2,
12*x+12*x*y^2-4*y^3,
-36*x*y-12*x^4+36*x^3*y-36*x*y^3+12*y^4+24*x^4*y^2-32*x^3*y^3+24*x^2*y^4,
0,
0,
0,
0
>>> from sage.all import *
>>> H.minor(Integer(1))
2,
6*y+2*x^3-6*x^2*y,
6*x^2*y-6*x*y^2,
6*x^2*y-6*x*y^2,
6*x+6*x*y^2-2*y^3,
0,
0,
0,
0
>>> H.minor(Integer(2))
12*y+4*x^3-12*x^2*y,
12*x^2*y-12*x*y^2,
12*x^2*y-12*x*y^2,
12*x+12*x*y^2-4*y^3,
-36*x*y-12*x^4+36*x^3*y-36*x*y^3+12*y^4+24*x^4*y^2-32*x^3*y^3+24*x^2*y^4,
0,
0,
0,
0
sage: _=singular.eval('option(redSB)')
sage: H.minor(1).groebner()
1
>>> from sage.all import *
>>> _=singular.eval('option(redSB)')
>>> H.minor(Integer(1)).groebner()
1
Computing the Genus#
We compute the projective genus of ideals that define curves over
\(\QQ\). It is very important to load the
normal.lib
library before calling the
genus
command, or you’ll get an error message.
EXAMPLES:
sage: singular.lib('normal.lib')
sage: R = singular.ring(0,'(x,y)','dp')
sage: i2 = singular.ideal('y9 - x2*(x-1)^9 + x')
sage: i2.genus()
40
>>> from sage.all import *
>>> singular.lib('normal.lib')
>>> R = singular.ring(Integer(0),'(x,y)','dp')
>>> i2 = singular.ideal('y9 - x2*(x-1)^9 + x')
>>> i2.genus()
40
Note that the genus can be much smaller than the degree:
sage: i = singular.ideal('y9 - x2*(x-1)^9')
sage: i.genus()
0
>>> from sage.all import *
>>> i = singular.ideal('y9 - x2*(x-1)^9')
>>> i.genus()
0
An Important Concept#
The following illustrates an important concept: how Sage interacts with the data being used and returned by Singular. Let’s compute a Groebner basis for some ideal, using Singular through Sage.
sage: singular.lib('polylib.lib')
sage: singular.ring(32003, '(a,b,c,d,e,f)', 'lp')
polynomial ring, over a field, global ordering
// coefficients: ZZ/32003
// number of vars : 6
// block 1 : ordering lp
// : names a b c d e f
// block 2 : ordering C
sage: I = singular.ideal('cyclic(6)')
sage: g = singular('groebner(I)')
Traceback (most recent call last):
...
TypeError: Singular error:
...
>>> from sage.all import *
>>> singular.lib('polylib.lib')
>>> singular.ring(Integer(32003), '(a,b,c,d,e,f)', 'lp')
polynomial ring, over a field, global ordering
// coefficients: ZZ/32003
// number of vars : 6
// block 1 : ordering lp
// : names a b c d e f
// block 2 : ordering C
>>> I = singular.ideal('cyclic(6)')
>>> g = singular('groebner(I)')
Traceback (most recent call last):
...
TypeError: Singular error:
...
We restart everything and try again, but correctly.
sage: singular.quit()
sage: singular.lib('polylib.lib'); R = singular.ring(32003, '(a,b,c,d,e,f)', 'lp')
sage: I = singular.ideal('cyclic(6)')
sage: I.groebner()
f^48-2554*f^42-15674*f^36+12326*f^30-12326*f^18+15674*f^12+2554*f^6-1,
...
>>> from sage.all import *
>>> singular.quit()
>>> singular.lib('polylib.lib'); R = singular.ring(Integer(32003), '(a,b,c,d,e,f)', 'lp')
>>> I = singular.ideal('cyclic(6)')
>>> I.groebner()
f^48-2554*f^42-15674*f^36+12326*f^30-12326*f^18+15674*f^12+2554*f^6-1,
...
It’s important to understand why the first attempt at computing a
basis failed. The line where we gave singular the input
‘groebner(I)’ was useless because Singular has no idea what ‘I’ is!
Although ‘I’ is an object that we computed with calls to Singular
functions, it actually lives in Sage. As a consequence, the name
‘I’ means nothing to Singular. When we called
I.groebner()
, Sage was able to call the groebner
function on ‘I’ in Singular, since ‘I’ actually means something to
Sage.
Long Input#
The Singular interface reads in even very long input (using files) in a robust manner, as long as you are creating a new object.
sage: t = '"%s"'%10^15000 # 15 thousand character string (note that normal Singular input must be at most 10000)
sage: a = singular.eval(t)
sage: a = singular(t)
>>> from sage.all import *
>>> t = '"%s"'%Integer(10)**Integer(15000) # 15 thousand character string (note that normal Singular input must be at most 10000)
>>> a = singular.eval(t)
>>> a = singular(t)
AUTHORS:
David Joyner and William Stein (2005): first version
Neal Harris (unknown): perhaps added “An Important Concept”
Martin Albrecht (2006-03-05): code so singular.[tab] and x = singular(…), x.[tab] includes all singular commands.
Martin Albrecht (2006-03-06): This patch adds the equality symbol to singular. Also fix a problem in which “ “ as prompt means comparison will break all further communication with Singular.
Martin Albrecht (2006-03-13): added current_ring() and current_ring_name()
William Stein (2006-04-10): Fixed problems with ideal constructor
Martin Albrecht (2006-05-18): added sage_poly.
Simon King (2010-11-23): Reduce the overhead caused by waiting for the Singular prompt by doing garbage collection differently.
Simon King (2011-06-06): Make conversion from Singular to Sage more flexible.
Simon King (2015): Extend pickling capabilities.
- class sage.interfaces.singular.Singular(maxread=None, script_subdirectory=None, logfile=None, server=None, server_tmpdir=None, seed=None)[source]#
Bases:
ExtraTabCompletion
,Expect
Interface to the Singular interpreter.
EXAMPLES: A Groebner basis example.
sage: R = singular.ring(0, '(x0,x1,x2)', 'lp') sage: I = 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: I.groebner() x1^2*x2^2, x0*x2^3-x1^2*x2^2+x1*x2^3, x0*x1-x0*x2-x1*x2, x0^2*x2-x0*x2^2-x1*x2^2
>>> from sage.all import * >>> R = singular.ring(Integer(0), '(x0,x1,x2)', 'lp') >>> I = 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']) >>> I.groebner() x1^2*x2^2, x0*x2^3-x1^2*x2^2+x1*x2^3, x0*x1-x0*x2-x1*x2, x0^2*x2-x0*x2^2-x1*x2^2
AUTHORS:
David Joyner and William Stein
- LIB(lib, reload=False)[source]#
Load the Singular library named lib.
Note that if the library was already loaded during this session it is not reloaded unless the optional reload argument is True (the default is False).
EXAMPLES:
sage: singular.lib('sing.lib') sage: singular.lib('sing.lib', reload=True)
>>> from sage.all import * >>> singular.lib('sing.lib') >>> singular.lib('sing.lib', reload=True)
- clear(var)[source]#
Clear the variable named
var
.EXAMPLES:
sage: singular.set('int', 'x', '2') sage: singular.get('x') '2' sage: singular.clear('x')
>>> from sage.all import * >>> singular.set('int', 'x', '2') >>> singular.get('x') '2' >>> singular.clear('x')
“Clearing the variable” means to allow to free the memory that it uses in the Singular sub-process. However, the actual deletion of the variable is only committed when the next element in the Singular interface is created:
sage: singular.get('x') '2' sage: a = singular(3) sage: singular.get('x') '`x`'
>>> from sage.all import * >>> singular.get('x') '2' >>> a = singular(Integer(3)) >>> singular.get('x') '`x`'
- console()[source]#
EXAMPLES:
sage: singular_console() #not tested SINGULAR / Development A Computer Algebra System for Polynomial Computations / version 3-0-4 0< by: G.-M. Greuel, G. Pfister, H. Schoenemann \ Nov 2007 FB Mathematik der Universitaet, D-67653 Kaiserslautern \
>>> from sage.all import * >>> singular_console() #not tested SINGULAR / Development A Computer Algebra System for Polynomial Computations / version 3-0-4 0< by: G.-M. Greuel, G. Pfister, H. Schoenemann \ Nov 2007 FB Mathematik der Universitaet, D-67653 Kaiserslautern \
- cputime(t=None)[source]#
Return the amount of CPU time that the Singular session has used. If
t
is not None, then it returns the difference between the current CPU time andt
.EXAMPLES:
sage: t = singular.cputime() sage: R = singular.ring(0, '(x0,x1,x2)', 'lp') sage: I = 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: gb = I.groebner() sage: singular.cputime(t) #random 0.02
>>> from sage.all import * >>> t = singular.cputime() >>> R = singular.ring(Integer(0), '(x0,x1,x2)', 'lp') >>> I = 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']) >>> gb = I.groebner() >>> singular.cputime(t) #random 0.02
- current_ring()[source]#
Return the current ring of the running Singular session.
EXAMPLES:
sage: r = PolynomialRing(GF(127),3,'xyz', order='invlex') sage: r._singular_() polynomial ring, over a field, global ordering // coefficients: ZZ/127 // number of vars : 3 // block 1 : ordering ip // : names x y z // block 2 : ordering C sage: singular.current_ring() polynomial ring, over a field, global ordering // coefficients: ZZ/127 // number of vars : 3 // block 1 : ordering ip // : names x y z // block 2 : ordering C
>>> from sage.all import * >>> r = PolynomialRing(GF(Integer(127)),Integer(3),'xyz', order='invlex') >>> r._singular_() polynomial ring, over a field, global ordering // coefficients: ZZ/127 // number of vars : 3 // block 1 : ordering ip // : names x y z // block 2 : ordering C >>> singular.current_ring() polynomial ring, over a field, global ordering // coefficients: ZZ/127 // number of vars : 3 // block 1 : ordering ip // : names x y z // block 2 : ordering C
- current_ring_name()[source]#
Return the Singular name of the currently active ring in Singular.
OUTPUT: currently active ring’s name
EXAMPLES:
sage: r = PolynomialRing(GF(127),3,'xyz') sage: r._singular_().name() == singular.current_ring_name() True
>>> from sage.all import * >>> r = PolynomialRing(GF(Integer(127)),Integer(3),'xyz') >>> r._singular_().name() == singular.current_ring_name() True
- eval(x, allow_semicolon=True, strip=True, **kwds)[source]#
Send the code x to the Singular interpreter and return the output as a string.
INPUT:
x
– string (of code)allow_semicolon
– default:False
; if False then raise aTypeError
if the input line contains a semicolon.strip
– ignored
EXAMPLES:
sage: singular.eval('2 > 1') '1' sage: singular.eval('2 + 2') '4'
>>> from sage.all import * >>> singular.eval('2 > 1') '1' >>> singular.eval('2 + 2') '4'
if the verbosity level is \(> 1\) comments are also printed and not only returned.
sage: r = singular.ring(0,'(x,y,z)','dp') sage: i = singular.ideal(['x^2','y^2','z^2']) sage: s = i.std() sage: singular.eval('hilb(%s)'%(s.name())) '...// dimension (affine) = 0\n// degree (affine) = 8'
>>> from sage.all import * >>> r = singular.ring(Integer(0),'(x,y,z)','dp') >>> i = singular.ideal(['x^2','y^2','z^2']) >>> s = i.std() >>> singular.eval('hilb(%s)'%(s.name())) '...// dimension (affine) = 0\n// degree (affine) = 8'
sage: from sage.misc.verbose import set_verbose sage: set_verbose(1) sage: o = singular.eval('hilb(%s)'%(s.name())) ...// dimension (affine) = 0 // degree (affine) = 8
>>> from sage.all import * >>> from sage.misc.verbose import set_verbose >>> set_verbose(Integer(1)) >>> o = singular.eval('hilb(%s)'%(s.name())) ...// dimension (affine) = 0 // degree (affine) = 8
This is mainly useful if this method is called implicitly. Because then intermediate results, debugging outputs and printed statements are printed
sage: o = s.hilb() ...// dimension (affine) = 0 // degree (affine) = 8 // ** right side is not a datum, assignment ignored ...
>>> from sage.all import * >>> o = s.hilb() ...// dimension (affine) = 0 // degree (affine) = 8 // ** right side is not a datum, assignment ignored ...
rather than ignored
sage: set_verbose(0) sage: o = s.hilb()
>>> from sage.all import * >>> set_verbose(Integer(0)) >>> o = s.hilb()
- get(var)[source]#
Get string representation of variable named var.
EXAMPLES:
sage: singular.set('int', 'x', '2') sage: singular.get('x') '2'
>>> from sage.all import * >>> singular.set('int', 'x', '2') >>> singular.get('x') '2'
- ideal(*gens)[source]#
Return the ideal generated by gens.
INPUT:
gens
– list or tuple of Singular objects (or objects that can be made into Singular objects via evaluation)
OUTPUT: the Singular ideal generated by the given list of gens
EXAMPLES: A Groebner basis example done in a different way.
sage: _ = singular.eval("ring R=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: i1 -x0^2*x2+x0*x1*x2, x0^2*x1*x2-x0*x1^2*x2-x0*x1*x2^2, x0*x1-x0*x2-x1*x2
>>> from sage.all import * >>> _ = singular.eval("ring R=0,(x0,x1,x2),lp") >>> 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']) >>> i1 -x0^2*x2+x0*x1*x2, x0^2*x1*x2-x0*x1^2*x2-x0*x1*x2^2, x0*x1-x0*x2-x1*x2
sage: i2 = singular.ideal('groebner(%s);'%i1.name()) 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*x2^2-x1*x2^2
>>> from sage.all import * >>> i2 = singular.ideal('groebner(%s);'%i1.name()) >>> 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*x2^2-x1*x2^2
- lib(lib, reload=False)[source]#
Load the Singular library named lib.
Note that if the library was already loaded during this session it is not reloaded unless the optional reload argument is True (the default is False).
EXAMPLES:
sage: singular.lib('sing.lib') sage: singular.lib('sing.lib', reload=True)
>>> from sage.all import * >>> singular.lib('sing.lib') >>> singular.lib('sing.lib', reload=True)
- list(x)[source]#
Creates a list in Singular from a Sage list
x
.EXAMPLES:
sage: singular.list([1,2]) [1]: 1 [2]: 2 sage: singular.list([1,2,[3,4]]) [1]: 1 [2]: 2 [3]: [1]: 3 [2]: 4 sage: R.<x,y> = QQ[] sage: singular.list([1,2,[x,ideal(x,y)]]) [1]: 1 [2]: 2 [3]: [1]: x [2]: _[1]=x _[2]=y
>>> from sage.all import * >>> singular.list([Integer(1),Integer(2)]) [1]: 1 [2]: 2 >>> singular.list([Integer(1),Integer(2),[Integer(3),Integer(4)]]) [1]: 1 [2]: 2 [3]: [1]: 3 [2]: 4 >>> R = QQ['x, y']; (x, y,) = R._first_ngens(2) >>> singular.list([Integer(1),Integer(2),[x,ideal(x,y)]]) [1]: 1 [2]: 2 [3]: [1]: x [2]: _[1]=x _[2]=y
Strings have to be escaped before passing them to this method:
sage: singular.list([1,2,'"hi"']) [1]: 1 [2]: 2 [3]: hi
>>> from sage.all import * >>> singular.list([Integer(1),Integer(2),'"hi"']) [1]: 1 [2]: 2 [3]: hi
- load(lib, reload=False)[source]#
Load the Singular library named lib.
Note that if the library was already loaded during this session it is not reloaded unless the optional reload argument is True (the default is False).
EXAMPLES:
sage: singular.lib('sing.lib') sage: singular.lib('sing.lib', reload=True)
>>> from sage.all import * >>> singular.lib('sing.lib') >>> singular.lib('sing.lib', reload=True)
- matrix(nrows, ncols, entries=None)[source]#
EXAMPLES:
sage: singular.lib("matrix") sage: R = singular.ring(0, '(x,y,z)', 'dp') sage: A = singular.matrix(3,2,'1,2,3,4,5,6') sage: A 1,2, 3,4, 5,6 sage: A.gauss_col() 2,-1, 1,0, 0,1
>>> from sage.all import * >>> singular.lib("matrix") >>> R = singular.ring(Integer(0), '(x,y,z)', 'dp') >>> A = singular.matrix(Integer(3),Integer(2),'1,2,3,4,5,6') >>> A 1,2, 3,4, 5,6 >>> A.gauss_col() 2,-1, 1,0, 0,1
AUTHORS:
Martin Albrecht (2006-01-14)
- option(cmd=None, val=None)[source]#
Access to Singular’s options as follows:
Syntax: option() Returns a string of all defined options.
Syntax: option( ‘option_name’ ) Sets an option. Note to disable an option, use the prefix no.
Syntax: option( ‘get’ ) Returns an intvec of the state of all options.
Syntax: option( ‘set’, intvec_expression ) Restores the state of all options from an intvec (produced by option(‘get’)).
EXAMPLES:
sage: singular.option() //options: redefine loadLib usage prompt sage: singular.option('get') 0, 10321 sage: old_options = _ sage: singular.option('noredefine') sage: singular.option() //options: loadLib usage prompt sage: singular.option('set', old_options) sage: singular.option('get') 0, 10321
>>> from sage.all import * >>> singular.option() //options: redefine loadLib usage prompt >>> singular.option('get') 0, 10321 >>> old_options = _ >>> singular.option('noredefine') >>> singular.option() //options: loadLib usage prompt >>> singular.option('set', old_options) >>> singular.option('get') 0, 10321
- ring(char=0, vars='(x)', order='lp', check=None)[source]#
Create a Singular ring and makes it the current ring.
INPUT:
char
(string) – a string specifying the characteristic of the base ring, in the format accepted by Singular (see examples below).vars
– a tuple or string defining the variable namesorder
(string) – the monomial order (default: “lp”)
OUTPUT: a Singular ring
Note
This function is not identical to calling the Singular
ring
function. In particular, it also attempts to “kill” the variable names, so they can actually be used without getting errors, and it sets printing of elements for this range to short (i.e., with *’s and carets).EXAMPLES: We first declare \(\QQ[x,y,z]\) with degree reverse lexicographic ordering.
sage: R = singular.ring(0, '(x,y,z)', 'dp') sage: R polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 3 // block 1 : ordering dp // : names x y z // block 2 : ordering C
>>> from sage.all import * >>> R = singular.ring(Integer(0), '(x,y,z)', 'dp') >>> R polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 3 // block 1 : ordering dp // : names x y z // block 2 : ordering C
sage: R1 = singular.ring(32003, '(x,y,z)', 'dp') sage: R2 = singular.ring(32003, '(a,b,c,d)', 'lp')
>>> from sage.all import * >>> R1 = singular.ring(Integer(32003), '(x,y,z)', 'dp') >>> R2 = singular.ring(Integer(32003), '(a,b,c,d)', 'lp')
This is a ring in variables named x(1) through x(10) over the finite field of order \(7\):
sage: R3 = singular.ring(7, '(x(1..10))', 'ds')
>>> from sage.all import * >>> R3 = singular.ring(Integer(7), '(x(1..10))', 'ds')
This is a polynomial ring over the transcendental extension \(\QQ(a)\) of \(\QQ\):
sage: R4 = singular.ring('(0,a)', '(mu,nu)', 'lp')
>>> from sage.all import * >>> R4 = singular.ring('(0,a)', '(mu,nu)', 'lp')
This is a ring over the field of single-precision floats:
sage: R5 = singular.ring('real', '(a,b)', 'lp')
>>> from sage.all import * >>> R5 = singular.ring('real', '(a,b)', 'lp')
This is over 50-digit floats:
sage: R6 = singular.ring('(real,50)', '(a,b)', 'lp') sage: R7 = singular.ring('(complex,50,i)', '(a,b)', 'lp')
>>> from sage.all import * >>> R6 = singular.ring('(real,50)', '(a,b)', 'lp') >>> R7 = singular.ring('(complex,50,i)', '(a,b)', 'lp')
To use a ring that you’ve defined, use the set_ring() method on the ring. This sets the ring to be the “current ring”. For example,
sage: R = singular.ring(7, '(a,b)', 'ds') sage: S = singular.ring('real', '(a,b)', 'lp') sage: singular.new('10*a') (1.000e+01)*a sage: R.set_ring() sage: singular.new('10*a') 3*a
>>> from sage.all import * >>> R = singular.ring(Integer(7), '(a,b)', 'ds') >>> S = singular.ring('real', '(a,b)', 'lp') >>> singular.new('10*a') (1.000e+01)*a >>> R.set_ring() >>> singular.new('10*a') 3*a
- set(type, name, value)[source]#
Set the variable with given name to the given value.
REMARK:
If a variable in the Singular interface was previously marked for deletion, the actual deletion is done here, before the new variable is created in Singular.
EXAMPLES:
sage: singular.set('int', 'x', '2') sage: singular.get('x') '2'
>>> from sage.all import * >>> singular.set('int', 'x', '2') >>> singular.get('x') '2'
We test that an unused variable is only actually deleted if this method is called:
sage: a = singular(3) sage: n = a.name() sage: del a sage: singular.eval(n) '3' sage: singular.set('int', 'y', '5') sage: singular.eval('defined(%s)'%n) '0'
>>> from sage.all import * >>> a = singular(Integer(3)) >>> n = a.name() >>> del a >>> singular.eval(n) '3' >>> singular.set('int', 'y', '5') >>> singular.eval('defined(%s)'%n) '0'
- set_ring(R)[source]#
Sets the current Singular ring to R.
EXAMPLES:
sage: R = singular.ring(7, '(a,b)', 'ds') sage: S = singular.ring('real', '(a,b)', 'lp') sage: singular.current_ring() polynomial ring, over a field, global ordering // coefficients: Float() // number of vars : 2 // block 1 : ordering lp // : names a b // block 2 : ordering C sage: singular.set_ring(R) sage: singular.current_ring() polynomial ring, over a field, local ordering // coefficients: ZZ/7 // number of vars : 2 // block 1 : ordering ds // : names a b // block 2 : ordering C
>>> from sage.all import * >>> R = singular.ring(Integer(7), '(a,b)', 'ds') >>> S = singular.ring('real', '(a,b)', 'lp') >>> singular.current_ring() polynomial ring, over a field, global ordering // coefficients: Float() // number of vars : 2 // block 1 : ordering lp // : names a b // block 2 : ordering C >>> singular.set_ring(R) >>> singular.current_ring() polynomial ring, over a field, local ordering // coefficients: ZZ/7 // number of vars : 2 // block 1 : ordering ds // : names a b // block 2 : ordering C
- set_seed(seed=None)[source]#
Set the seed for singular interpreter.
The seed should be an integer at least 1 and not more than 30 bits. See http://www.singular.uni-kl.de/Manual/html/sing_19.htm#SEC26 and http://www.singular.uni-kl.de/Manual/html/sing_283.htm#SEC323
EXAMPLES:
sage: s = Singular() sage: s.set_seed(1) 1 sage: [s.random(1,10) for i in range(5)] [8, 10, 4, 9, 1]
>>> from sage.all import * >>> s = Singular() >>> s.set_seed(Integer(1)) 1 >>> [s.random(Integer(1),Integer(10)) for i in range(Integer(5))] [8, 10, 4, 9, 1]
- setring(R)[source]#
Sets the current Singular ring to R.
EXAMPLES:
sage: R = singular.ring(7, '(a,b)', 'ds') sage: S = singular.ring('real', '(a,b)', 'lp') sage: singular.current_ring() polynomial ring, over a field, global ordering // coefficients: Float() // number of vars : 2 // block 1 : ordering lp // : names a b // block 2 : ordering C sage: singular.set_ring(R) sage: singular.current_ring() polynomial ring, over a field, local ordering // coefficients: ZZ/7 // number of vars : 2 // block 1 : ordering ds // : names a b // block 2 : ordering C
>>> from sage.all import * >>> R = singular.ring(Integer(7), '(a,b)', 'ds') >>> S = singular.ring('real', '(a,b)', 'lp') >>> singular.current_ring() polynomial ring, over a field, global ordering // coefficients: Float() // number of vars : 2 // block 1 : ordering lp // : names a b // block 2 : ordering C >>> singular.set_ring(R) >>> singular.current_ring() polynomial ring, over a field, local ordering // coefficients: ZZ/7 // number of vars : 2 // block 1 : ordering ds // : names a b // block 2 : ordering C
- class sage.interfaces.singular.SingularElement(parent, type, value, is_name=False)[source]#
Bases:
ExtraTabCompletion
,ExpectElement
,SingularElement
EXAMPLES:
sage: a = singular(2) sage: loads(dumps(a)) 2
>>> from sage.all import * >>> a = singular(Integer(2)) >>> loads(dumps(a)) 2
- attrib(name, value=None)[source]#
Get and set attributes for self.
INPUT:
name
– string to choose the attributevalue
– boolean value or None for reading, (default:None)
VALUES: isSB - the standard basis property is set by all commands computing a standard basis like groebner, std, stdhilb etc.; used by lift, dim, degree, mult, hilb, vdim, kbase isHomog - the weight vector for homogeneous or quasihomogeneous ideals/modules isCI - complete intersection property isCM - Cohen-Macaulay property rank - set the rank of a module (see nrows) withSB - value of type ideal, resp. module, is std withHilb - value of type intvec is hilb(_,1) (see hilb) withRes - value of type list is a free resolution withDim - value of type int is the dimension (see dim) withMult - value of type int is the multiplicity (see mult)
EXAMPLES:
sage: P.<x,y,z> = PolynomialRing(QQ) sage: I = Ideal([z^2, y*z, y^2, x*z, x*y, x^2]) sage: Ibar = I._singular_() sage: Ibar.attrib('isSB') 0 sage: singular.eval('vdim(%s)'%Ibar.name()) # sage7 name is random // ** sage7 is no standard basis 4 sage: Ibar.attrib('isSB',1) sage: singular.eval('vdim(%s)'%Ibar.name()) '4'
>>> from sage.all import * >>> P = PolynomialRing(QQ, names=('x', 'y', 'z',)); (x, y, z,) = P._first_ngens(3) >>> I = Ideal([z**Integer(2), y*z, y**Integer(2), x*z, x*y, x**Integer(2)]) >>> Ibar = I._singular_() >>> Ibar.attrib('isSB') 0 >>> singular.eval('vdim(%s)'%Ibar.name()) # sage7 name is random // ** sage7 is no standard basis 4 >>> Ibar.attrib('isSB',Integer(1)) >>> singular.eval('vdim(%s)'%Ibar.name()) '4'
- is_string()[source]#
Tell whether this element is a string.
EXAMPLES:
sage: singular('"abc"').is_string() True sage: singular('1').is_string() False
>>> from sage.all import * >>> singular('"abc"').is_string() True >>> singular('1').is_string() False
- sage_flattened_str_list()[source]#
EXAMPLES:
sage: R=singular.ring(0,'(x,y)','dp') sage: RL = R.ringlist() sage: RL.sage_flattened_str_list() ['0', 'x', 'y', 'dp', '1,1', 'C', '0', '_[1]=0']
>>> from sage.all import * >>> R=singular.ring(Integer(0),'(x,y)','dp') >>> RL = R.ringlist() >>> RL.sage_flattened_str_list() ['0', 'x', 'y', 'dp', '1,1', 'C', '0', '_[1]=0']
- sage_global_ring()[source]#
Return the current basering in Singular as a polynomial ring or quotient ring.
EXAMPLES:
sage: singular.eval('ring r1 = (9,x),(a,b,c,d,e,f),(M((1,2,3,0)),wp(2,3),lp)') '' sage: R = singular('r1').sage_global_ring() sage: R Multivariate Polynomial Ring in a, b, c, d, e, f over Finite Field in x of size 3^2 sage: R.term_order() Block term order with blocks: (Matrix term order with matrix [1 2] [3 0], Weighted degree reverse lexicographic term order with weights (2, 3), Lexicographic term order of length 2)
>>> from sage.all import * >>> singular.eval('ring r1 = (9,x),(a,b,c,d,e,f),(M((1,2,3,0)),wp(2,3),lp)') '' >>> R = singular('r1').sage_global_ring() >>> R Multivariate Polynomial Ring in a, b, c, d, e, f over Finite Field in x of size 3^2 >>> R.term_order() Block term order with blocks: (Matrix term order with matrix [1 2] [3 0], Weighted degree reverse lexicographic term order with weights (2, 3), Lexicographic term order of length 2)
sage: singular.eval('ring r2 = (0,x),(a,b,c),dp') '' sage: singular('r2').sage_global_ring() Multivariate Polynomial Ring in a, b, c over Fraction Field of Univariate Polynomial Ring in x over Rational Field
>>> from sage.all import * >>> singular.eval('ring r2 = (0,x),(a,b,c),dp') '' >>> singular('r2').sage_global_ring() Multivariate Polynomial Ring in a, b, c over Fraction Field of Univariate Polynomial Ring in x over Rational Field
sage: singular.eval('ring r3 = (3,z),(a,b,c),dp') '' sage: singular.eval('minpoly = 1+z+z2+z3+z4') '' sage: singular('r3').sage_global_ring() Multivariate Polynomial Ring in a, b, c over Finite Field in z of size 3^4
>>> from sage.all import * >>> singular.eval('ring r3 = (3,z),(a,b,c),dp') '' >>> singular.eval('minpoly = 1+z+z2+z3+z4') '' >>> singular('r3').sage_global_ring() Multivariate Polynomial Ring in a, b, c over Finite Field in z of size 3^4
Real and complex fields in both Singular and Sage are defined with a precision. The precision in Singular is given in terms of digits, but in Sage it is given in terms of bits. So, the digit precision is internally converted to a reasonable bit precision:
sage: singular.eval('ring r4 = (real,20),(a,b,c),dp') '' sage: singular('r4').sage_global_ring() Multivariate Polynomial Ring in a, b, c over Real Field with 70 bits of precision
>>> from sage.all import * >>> singular.eval('ring r4 = (real,20),(a,b,c),dp') '' >>> singular('r4').sage_global_ring() Multivariate Polynomial Ring in a, b, c over Real Field with 70 bits of precision
The case of complex coefficients is not fully supported, yet, since the generator of a complex field in Sage is always called “I”:
sage: singular.eval('ring r5 = (complex,15,j),(a,b,c),dp') '' sage: R = singular('r5').sage_global_ring(); R Multivariate Polynomial Ring in a, b, c over Complex Field with 54 bits of precision sage: R.base_ring()('k') Traceback (most recent call last): ... ValueError: given string 'k' is not a complex number sage: R.base_ring()('I') 1.00000000000000*I
>>> from sage.all import * >>> singular.eval('ring r5 = (complex,15,j),(a,b,c),dp') '' >>> R = singular('r5').sage_global_ring(); R Multivariate Polynomial Ring in a, b, c over Complex Field with 54 bits of precision >>> R.base_ring()('k') Traceback (most recent call last): ... ValueError: given string 'k' is not a complex number >>> R.base_ring()('I') 1.00000000000000*I
An example where the base ring is a polynomial ring over an extension of the rational field:
sage: singular.eval('ring r7 = (0,a), (x,y), dp') '' sage: singular.eval('minpoly = a2 + 1') '' sage: singular('r7').sage_global_ring() Multivariate Polynomial Ring in x, y over Number Field in a with defining polynomial a^2 + 1
>>> from sage.all import * >>> singular.eval('ring r7 = (0,a), (x,y), dp') '' >>> singular.eval('minpoly = a2 + 1') '' >>> singular('r7').sage_global_ring() Multivariate Polynomial Ring in x, y over Number Field in a with defining polynomial a^2 + 1
In our last example, the base ring is a quotient ring:
sage: singular.eval('ring r6 = (9,a), (x,y,z),lp') '' sage: Q = singular('std(ideal(x^2,x+y^2+z^3))', type='qring') sage: Q.sage_global_ring() Quotient of Multivariate Polynomial Ring in x, y, z over Finite Field in a of size 3^2 by the ideal (y^4 - y^2*z^3 + z^6, x + y^2 + z^3)
>>> from sage.all import * >>> singular.eval('ring r6 = (9,a), (x,y,z),lp') '' >>> Q = singular('std(ideal(x^2,x+y^2+z^3))', type='qring') >>> Q.sage_global_ring() Quotient of Multivariate Polynomial Ring in x, y, z over Finite Field in a of size 3^2 by the ideal (y^4 - y^2*z^3 + z^6, x + y^2 + z^3)
AUTHOR:
Simon King (2011-06-06)
- sage_matrix(R, sparse=True)[source]#
Return Sage matrix for
self
.INPUT:
R
– (default: None); an optional ring, over which the resulting matrix is going to be defined. By default, the output ofsage_global_ring()
is used.sparse
– (default:True
); determines whether the resulting matrix is sparse or not.
EXAMPLES:
sage: R = singular.ring(0, '(x,y,z)', 'dp') sage: A = singular.matrix(2,2) sage: A.sage_matrix(ZZ) [0 0] [0 0] sage: A.sage_matrix(RDF) [0.0 0.0] [0.0 0.0]
>>> from sage.all import * >>> R = singular.ring(Integer(0), '(x,y,z)', 'dp') >>> A = singular.matrix(Integer(2),Integer(2)) >>> A.sage_matrix(ZZ) [0 0] [0 0] >>> A.sage_matrix(RDF) [0.0 0.0] [0.0 0.0]
- sage_poly(R=None, kcache=None)[source]#
Return a Sage polynomial in the ring r matching the provided poly which is a singular polynomial.
INPUT:
R
– (default: None); an optional polynomial ring. If it is provided, then you have to make sure that it matches the current singular ring as, e.g., returned by singular.current_ring(). By default, the output ofsage_global_ring()
is used.kcache
– (default: None); an optional dictionary for faster finite field lookups, this is mainly useful for finite extension fields
OUTPUT: MPolynomial
EXAMPLES:
sage: R = PolynomialRing(GF(2^8,'a'), 'x,y') sage: f = R('a^20*x^2*y+a^10+x') sage: f._singular_().sage_poly(R) == f True sage: R = PolynomialRing(GF(2^8,'a'), 'x', implementation="singular") sage: f = R('a^20*x^3+x^2+a^10') sage: f._singular_().sage_poly(R) == f True
>>> from sage.all import * >>> R = PolynomialRing(GF(Integer(2)**Integer(8),'a'), 'x,y') >>> f = R('a^20*x^2*y+a^10+x') >>> f._singular_().sage_poly(R) == f True >>> R = PolynomialRing(GF(Integer(2)**Integer(8),'a'), 'x', implementation="singular") >>> f = R('a^20*x^3+x^2+a^10') >>> f._singular_().sage_poly(R) == f True
sage: P.<x,y> = PolynomialRing(QQ, 2) sage: f = x*y**3 - 1/9 * x + 1; f x*y^3 - 1/9*x + 1 sage: singular(f) x*y^3-1/9*x+1 sage: P(singular(f)) x*y^3 - 1/9*x + 1
>>> from sage.all import * >>> P = PolynomialRing(QQ, Integer(2), names=('x', 'y',)); (x, y,) = P._first_ngens(2) >>> f = x*y**Integer(3) - Integer(1)/Integer(9) * x + Integer(1); f x*y^3 - 1/9*x + 1 >>> singular(f) x*y^3-1/9*x+1 >>> P(singular(f)) x*y^3 - 1/9*x + 1
AUTHORS:
Martin Albrecht (2006-05-18)
Simon King (2011-06-06): Deal with Singular’s short polynomial representation, automatic construction of a polynomial ring, if it is not explicitly given.
Note
For very simple polynomials
eval(SingularElement.sage_polystring())
is faster than SingularElement.sage_poly(R), maybe we should detect the crossover point (in dependence of the string length) and choose an appropriate conversion strategy
- sage_polystring()[source]#
If this Singular element is a polynomial, return a string representation of this polynomial that is suitable for evaluation in Python. Thus * is used for multiplication and ** for exponentiation. This function is primarily used internally.
The short=0 option must be set for the parent ring or this function will not work as expected. This option is set by default for rings created using
singular.ring
or set usingring_name.set_ring()
.EXAMPLES:
sage: R = singular.ring(0,'(x,y)') sage: f = singular('x^3 + 3*y^11 + 5') sage: f x^3+3*y^11+5 sage: f.sage_polystring() 'x**3+3*y**11+5'
>>> from sage.all import * >>> R = singular.ring(Integer(0),'(x,y)') >>> f = singular('x^3 + 3*y^11 + 5') >>> f x^3+3*y^11+5 >>> f.sage_polystring() 'x**3+3*y**11+5'
- sage_structured_str_list()[source]#
If self is a Singular list of lists of Singular elements, returns corresponding Sage list of lists of strings.
EXAMPLES:
sage: R=singular.ring(0,'(x,y)','dp') sage: RL=R.ringlist() sage: RL [1]: 0 [2]: [1]: x [2]: y [3]: [1]: [1]: dp [2]: 1,1 [2]: [1]: C [2]: 0 [4]: _[1]=0 sage: RL.sage_structured_str_list() ['0', ['x', 'y'], [['dp', '1,\n1'], ['C', '0']], '0']
>>> from sage.all import * >>> R=singular.ring(Integer(0),'(x,y)','dp') >>> RL=R.ringlist() >>> RL [1]: 0 [2]: [1]: x [2]: y [3]: [1]: [1]: dp [2]: 1,1 [2]: [1]: C [2]: 0 [4]: _[1]=0 >>> RL.sage_structured_str_list() ['0', ['x', 'y'], [['dp', '1,\n1'], ['C', '0']], '0']
- set_ring()[source]#
Sets the current ring in Singular to be self.
EXAMPLES:
sage: R = singular.ring(7, '(a,b)', 'ds') sage: S = singular.ring('real', '(a,b)', 'lp') sage: singular.current_ring() polynomial ring, over a field, global ordering // coefficients: Float() // number of vars : 2 // block 1 : ordering lp // : names a b // block 2 : ordering C sage: R.set_ring() sage: singular.current_ring() polynomial ring, over a field, local ordering // coefficients: ZZ/7 // number of vars : 2 // block 1 : ordering ds // : names a b // block 2 : ordering C
>>> from sage.all import * >>> R = singular.ring(Integer(7), '(a,b)', 'ds') >>> S = singular.ring('real', '(a,b)', 'lp') >>> singular.current_ring() polynomial ring, over a field, global ordering // coefficients: Float() // number of vars : 2 // block 1 : ordering lp // : names a b // block 2 : ordering C >>> R.set_ring() >>> singular.current_ring() polynomial ring, over a field, local ordering // coefficients: ZZ/7 // number of vars : 2 // block 1 : ordering ds // : names a b // block 2 : ordering C
- type()[source]#
Return the internal type of this element.
EXAMPLES:
sage: R = PolynomialRing(GF(2^8,'a'),2,'x') sage: R._singular_().type() 'ring' sage: fs = singular('x0^2','poly') sage: fs.type() 'poly'
>>> from sage.all import * >>> R = PolynomialRing(GF(Integer(2)**Integer(8),'a'),Integer(2),'x') >>> R._singular_().type() 'ring' >>> fs = singular('x0^2','poly') >>> fs.type() 'poly'
- exception sage.interfaces.singular.SingularError[source]#
Bases:
RuntimeError
Raised if Singular printed an error message
- class sage.interfaces.singular.SingularFunction(parent, name)[source]#
Bases:
ExpectFunction
- class sage.interfaces.singular.SingularFunctionElement(obj, name)[source]#
Bases:
FunctionElement
- class sage.interfaces.singular.SingularGBDefaultContext(singular=None)[source]#
Bases:
object
Within this context all Singular Groebner basis calculations are reduced automatically.
AUTHORS:
Martin Albrecht
Simon King
- class sage.interfaces.singular.SingularGBLogPrettyPrinter(verbosity=1)[source]#
Bases:
object
A device which prints Singular Groebner basis computation logs more verbatim.
- cri_hilb = re.compile('h')#
- crt_lne1 = re.compile('product criterion:(\\d+) chain criterion:(\\d+)')#
- crt_lne2 = re.compile('NF:(\\d+) product criterion:(\\d+), ext_product criterion:(\\d+)')#
- deg_lead = re.compile('\\d+')#
- flush()[source]#
EXAMPLES:
sage: from sage.interfaces.singular import SingularGBLogPrettyPrinter sage: s3 = SingularGBLogPrettyPrinter(verbosity=3) sage: s3.flush()
>>> from sage.all import * >>> from sage.interfaces.singular import SingularGBLogPrettyPrinter >>> s3 = SingularGBLogPrettyPrinter(verbosity=Integer(3)) >>> s3.flush()
- global_pattern = re.compile('(\\[\\d+:\\d+\\]|s|-|\\.|h|H\\(\\d+\\)|\\(\\d+\\)|\\(S:\\d+\\)|\\d+|M\\[\\d+,[b,e]*\\d+\\]|b|e).*')#
- hig_corn = re.compile('H\\(\\d+\\)')#
- new_elem = re.compile('s')#
- non_mini = re.compile('e')#
- num_crit = re.compile('\\(\\d+\\)')#
- pat_sync = re.compile('1\\+(\\d+);')#
- red_betr = re.compile('b')#
- red_num = re.compile('\\(S:\\d+\\)')#
- red_para = re.compile('M\\[(\\d+),(\\d+)\\]')#
- red_post = re.compile('\\.')#
- red_zero = re.compile('-')#
- rng_chng = re.compile('\\[\\d+:\\d+\\]')#
- write(s)[source]#
EXAMPLES:
sage: from sage.interfaces.singular import SingularGBLogPrettyPrinter sage: s3 = SingularGBLogPrettyPrinter(verbosity=3) sage: s3.write("(S:1337)") Performing complete reduction of 1337 elements. sage: s3.write("M[389,12]") Parallel reduction of 389 elements with 12 non-zero output elements.
>>> from sage.all import * >>> from sage.interfaces.singular import SingularGBLogPrettyPrinter >>> s3 = SingularGBLogPrettyPrinter(verbosity=Integer(3)) >>> s3.write("(S:1337)") Performing complete reduction of 1337 elements. >>> s3.write("M[389,12]") Parallel reduction of 389 elements with 12 non-zero output elements.
- sage.interfaces.singular.generate_docstring_dictionary()[source]#
Generate global dictionaries which hold the docstrings for Singular functions.
EXAMPLES:
sage: from sage.interfaces.singular import generate_docstring_dictionary sage: generate_docstring_dictionary()
>>> from sage.all import * >>> from sage.interfaces.singular import generate_docstring_dictionary >>> generate_docstring_dictionary()
- sage.interfaces.singular.get_docstring(name)[source]#
Return the docstring for the function
name
.INPUT:
name
– a Singular function name
EXAMPLES:
sage: from sage.interfaces.singular import get_docstring sage: 'groebner' in get_docstring('groebner') True sage: 'standard.lib' in get_docstring('groebner') True
>>> from sage.all import * >>> from sage.interfaces.singular import get_docstring >>> 'groebner' in get_docstring('groebner') True >>> 'standard.lib' in get_docstring('groebner') True
- sage.interfaces.singular.is_SingularElement(x)[source]#
Return True is
x
is of typeSingularElement
.This function is deprecated; use
isinstance()
(ofsage.interfaces.abc.SingularElement
) instead.EXAMPLES:
sage: from sage.interfaces.singular import is_SingularElement sage: is_SingularElement(singular(2)) doctest:...: DeprecationWarning: the function is_SingularElement is deprecated; use isinstance(x, sage.interfaces.abc.SingularElement) instead See https://github.com/sagemath/sage/issues/34804 for details. True sage: is_SingularElement(2) False
>>> from sage.all import * >>> from sage.interfaces.singular import is_SingularElement >>> is_SingularElement(singular(Integer(2))) doctest:...: DeprecationWarning: the function is_SingularElement is deprecated; use isinstance(x, sage.interfaces.abc.SingularElement) instead See https://github.com/sagemath/sage/issues/34804 for details. True >>> is_SingularElement(Integer(2)) False
- sage.interfaces.singular.reduce_load_Singular()[source]#
EXAMPLES:
sage: from sage.interfaces.singular import reduce_load_Singular sage: reduce_load_Singular() Singular
>>> from sage.all import * >>> from sage.interfaces.singular import reduce_load_Singular >>> reduce_load_Singular() Singular
- sage.interfaces.singular.singular_console()[source]#
Spawn a new Singular command-line session.
EXAMPLES:
sage: singular_console() #not tested SINGULAR / Development A Computer Algebra System for Polynomial Computations / version 3-0-4 0< by: G.-M. Greuel, G. Pfister, H. Schoenemann \ Nov 2007 FB Mathematik der Universitaet, D-67653 Kaiserslautern \
>>> from sage.all import * >>> singular_console() #not tested SINGULAR / Development A Computer Algebra System for Polynomial Computations / version 3-0-4 0< by: G.-M. Greuel, G. Pfister, H. Schoenemann \ Nov 2007 FB Mathematik der Universitaet, D-67653 Kaiserslautern \