Sage implements a C wrapper around the Singular interpreter which allows to call any function directly from Sage without string parsing or interprocess communication overhead. Users who do not want to call Singular functions directly, usually do not have to worry about this interface, since it is handled by higher level functions in Sage.
AUTHORS:
EXAMPLES:
The direct approach for loading a Singular function is to call the function singular_function() with the function name as parameter:
sage: from sage.libs.singular.function import singular_function
sage: P.<a,b,c,d> = PolynomialRing(GF(7))
sage: std = singular_function('std')
sage: I = sage.rings.ideal.Cyclic(P)
sage: std(I)
[a + b + c + d,
b^2 + 2*b*d + d^2,
b*c^2 + c^2*d - b*d^2 - d^3,
b*c*d^2 + c^2*d^2 - b*d^3 + c*d^3 - d^4 - 1,
b*d^4 + d^5 - b - d,
c^3*d^2 + c^2*d^3 - c - d,
c^2*d^4 + b*c - b*d + c*d - 2*d^2]
If a Singular library needs to be loaded before a certain function is available, use the lib() function as shown below:
sage: from sage.libs.singular.function import singular_function, lib as singular_lib
sage: primdecSY = singular_function('primdecSY')
...
NameError: Function 'primdecSY' is not defined.
sage: singular_lib('primdec.lib')
sage: primdecSY = singular_function('primdecSY')
There is also a short-hand notation for the above:
sage: primdecSY = sage.libs.singular.ff.primdec__lib.primdecSY
The above line will load “primdec.lib” first and then load the function primdecSY.
TESTS:
sage: from sage.libs.singular.function import singular_function
sage: std = singular_function('std')
sage: loads(dumps(std)) == std
True
Bases: object
A call handler is an abstraction which hides the details of the implementation differences between kernel and library functions.
Bases: sage.structure.sage_object.SageObject
A Converter interfaces between Sage objects and Singular interpreter objects.
Return the ring in which the arguments of this list live.
EXAMPLE:
sage: from sage.libs.singular.function import Converter
sage: P.<a,b,c> = PolynomialRing(GF(127))
sage: Converter([a,b,c],ring=P).ring()
Multivariate Polynomial Ring in a, b, c over Finite Field of size 127
Bases: sage.libs.singular.function.BaseCallHandler
A call handler is an abstraction which hides the details of the implementation differences between kernel and library functions.
This class implements calling a kernel function.
Note
Do not construct this class directly, use singular_function() instead.
Bases: sage.libs.singular.function.BaseCallHandler
A call handler is an abstraction which hides the details of the implementation differences between kernel and library functions.
This class implements calling a library function.
Note
Do not construct this class directly, use singular_function() instead.
Bases: object
A simple wrapper around Singular’s resolutions.
Bases: object
A simple wrapper around Singular’s rings.
Bases: sage.structure.sage_object.SageObject
The base class for Singular functions either from the kernel or from the library.
Bases: sage.libs.singular.function.SingularFunction
EXAMPLES:
sage: from sage.libs.singular.function import SingularKernelFunction
sage: R.<x,y> = PolynomialRing(QQ, order='lex')
sage: I = R.ideal(x, x+1)
sage: f = SingularKernelFunction("std")
sage: f(I)
[1]
Bases: sage.libs.singular.function.SingularFunction
EXAMPLES:
sage: from sage.libs.singular.function import SingularLibraryFunction
sage: R.<x,y> = PolynomialRing(QQ, order='lex')
sage: I = R.ideal(x, x+1)
sage: f = SingularLibraryFunction("groebner")
sage: f(I)
[1]
Tests for a sequence s, whether it consists of singular polynomials.
EXAMPLE:
sage: from sage.libs.singular.function import all_polynomials
sage: P.<x,y,z> = QQ[]
sage: all_polynomials([x+1, y])
True
sage: all_polynomials([x+1, y, 1])
False
Checks if a sequence s consists of free module elements over a singular ring.
EXAMPLE:
sage: from sage.libs.singular.function import all_vectors
sage: P.<x,y,z> = QQ[]
sage: M = P**2
sage: all_vectors([x])
False
sage: all_vectors([(x,y)])
False
sage: all_vectors([M(0), M((x,y))])
True
sage: all_vectors([M(0), M((x,y)),(0,0)])
False
Load the Singular library name.
INPUT:
EXAMPLE:
sage: from sage.libs.singular.function import singular_function
sage: from sage.libs.singular.function import lib as singular_lib
sage: singular_lib('general.lib')
sage: primes = singular_function('primes')
sage: primes(2,10, ring=GF(127)['x,y,z'])
(2, 3, 5, 7)
Return a list of all function names currently available.
INPUT:
EXAMPLE:
sage: 'groebner' in sage.libs.singular.function.list_of_functions()
True
Construct a new libSingular function object for the given name.
This function works both for interpreter and built-in functions.
INPUT:
EXAMPLE:
sage: from sage.libs.singular.function import singular_function
sage: P.<x,y,z> = PolynomialRing(QQ)
sage: f = 3*x*y + 2*z + 1
sage: g = 2*x + 1/2
sage: I = Ideal([f,g])
sage: number_foobar = singular_function('number_foobar');
...
NameError: Function 'number_foobar' is not defined.
sage: from sage.libs.singular.function import lib as singular_lib
sage: singular_lib('general.lib')
sage: number_e = singular_function('number_e')
sage: number_e(10r,ring=P)
67957045707/25000000000
sage: RR(number_e(10r,ring=P))
2.71828182828000
sage: std = singular_function("std")
sage: std(I)
[3*y - 8*z - 4, 4*x + 1]
sage: singular_list = singular_function("list")
sage: singular_list(2, 3, 6, ring=P)
[2, 3, 6]
sage: size = singular_function("size")
sage: size([2, 3, 3], ring=P)
3
sage: size("sage", ring=P)
4
sage: size(["hello", "sage"], ring=P)
2
sage: factorize = singular_function("factorize")
sage: factorize(f)
[[1, 3*x*y + 2*z + 1], (1, 1)]
sage: singular_lib('primdec.lib')
sage: primdecGTZ = singular_function("primdecGTZ")
sage: primdecGTZ(I)
[[[3*y - 8*z - 4, 4*x + 1], [3*y - 8*z - 4, 4*x + 1]]]
sage: singular_list((1,2,3),3,[1,2,3], ring=P)
[(1, 2, 3), 3, [1, 2, 3]]
sage: ringlist=singular_function("ringlist")
sage: l = ringlist(P)
sage: l[3].__class__
<class 'sage.structure.sequence.Sequence'>
sage: l
[0, ['x', 'y', 'z'], [['dp', (1, 1, 1)], ['C', (0,)]], [0]]
sage: ring=singular_function("ring")
sage: ring(l, ring=P)
<RingWrap>
sage: matrix = Matrix(P,2,2)
sage: matrix.randomize(terms=1)
sage: det = singular_function("det")
sage: det(matrix)
-3/5*x*y*z
sage: coeffs = singular_function("coeffs")
sage: coeffs(x*y+y+1,y)
[ 1]
[x + 1]
sage: F.<x,y,z> = GF(3)[]
sage: intmat = Matrix(ZZ, 2,2, [100,2,3,4])
sage: det(intmat, ring=F)
394
sage: random = singular_function("random")
sage: random(10,2,3, ring =F)
[-3 -3 -8]
[10 3 10]
sage: P.<x,y,z> = PolynomialRing(QQ)
sage: M=P**3
sage: leadcoef = singular_function("leadcoef")
sage: v=M((100*x,5*y,10*z*x*y))
sage: leadcoef(v)
10
sage: v = M([x+y,x*y+y**3,z])
sage: lead = singular_function("lead")
sage: lead(v)
(0, y^3)
sage: jet = singular_function("jet")
sage: jet(v, 2)
(x + y, x*y, z)
sage: syz = singular_function("syz")
sage: I = P.ideal([x+y,x*y-y, y*2,x**2+1])
sage: M = syz(I)
sage: M
[(-2*y, 2, y + 1, 0), (0, -2, x - 1, 0), (x*y - y, -y + 1, 1, -y), (x^2 + 1, -x - 1, -1, -x)]
sage: singular_lib("mprimdec.lib")
sage: syz(M)
[(-x - 1, y - 1, 2*x, -2*y)]
sage: GTZmod = singular_function("GTZmod")
sage: GTZmod(M)
[[[(-2*y, 2, y + 1, 0), (0, x + 1, 1, -y), (0, -2, x - 1, 0), (x*y - y, -y + 1, 1, -y), (x^2 + 1, 0, 0, -x - y)], [0]]]
sage: mres = singular_function("mres")
sage: resolution = mres(M, 0)
sage: resolution
<Resolution>
sage: singular_list(resolution)
[[(-2*y, 2, y + 1, 0), (0, -2, x - 1, 0), (x*y - y, -y + 1, 1, -y), (x^2 + 1, -x - 1, -1, -x)], [(-x - 1, y - 1, 2*x, -2*y)], [(0)]]