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)
TESTS: We test an automatic coercion:
sage: a = 3*singular('2'); a
6
sage: type(a)
<class 'sage.interfaces.singular.SingularElement'>
sage: a = singular('2')*3; a
6
sage: type(a)
<class 'sage.interfaces.singular.SingularElement'>
Module-level Functions
| x) |
Returns True is x is of type SingularElement.
sage: from sage.interfaces.singular import is_SingularElement sage: is_SingularElement(singular(2)) True sage: is_SingularElement(2) False
| ) |
Note that this returns an invalid Singular object!
sage: from sage.interfaces.singular import reduce_load sage: reduce_load() (invalid object -- defined in terms of closed session)
| ) |
sage: from sage.interfaces.singular import reduce_load_Singular sage: reduce_load_Singular() Singular
| ) |
Spawn a new Singular command-line session.
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
| ) |
Returns the version of Singular being used.
Class: Singular
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*x1*x2
Author: David Joyner and William Stein
| self, [maxread=1000], [script_subdirectory=None], [logfile=None], [server=None], [server_tmpdir=None]) |
sage: singular == loads(dumps(singular)) True
Functions: clear,
console,
cputime,
current_ring,
current_ring_name,
eval,
get,
ideal,
LIB,
lib,
list,
load,
matrix,
option,
ring,
set,
set_ring,
setring,
string,
trait_names,
version
| self, var) |
Clear the variable named var.
sage: singular.set('int', 'x', '2')
sage: singular.get('x')
'2'
sage: singular.clear('x')
sage: singular.get('x')
'`x`'
| self) |
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
| self, [t=None]) |
Returns 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 and t.
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
| self) |
Returns the current ring of the runnging Singular session.
sage: r = PolynomialRing(GF(127),3,'xyz', order='invlex') sage: r._singular_() // characteristic : 127 // number of vars : 3 // block 1 : ordering rp // : names x y z // block 2 : ordering C sage: singular.current_ring() // characteristic : 127 // number of vars : 3 // block 1 : ordering rp // : names x y z // block 2 : ordering C
| self) |
Returns the Singular name of the currently active ring in Singular.
Output: currently active ring's name
sage: r = PolynomialRing(GF(127),3,'xyz') sage: r._singular_().name() == singular.current_ring_name() True
| self, x, [allow_semicolon=True], [strip=True]) |
Send the code x to the Singular interpreter and return the output as a string.
Input:
sage: singular.eval('2 > 1')
'1'
sage: singular.eval('2 + 2')
'4'
if the verbosity level is
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()))
'// 1 t^0\n// -3 t^2\n// 3 t^4\n// -1 t^6\n\n// 1 t^0\n//
3 t^1\n// 3 t^2\n// 1 t^3\n// dimension (affine) = 0\n//
degree (affine) = 8'
sage: set_verbose(1)
sage: o = singular.eval('hilb(%s)'%(s.name()))
// 1 t^0
// -3 t^2
// 3 t^4
// -1 t^6
// 1 t^0
// 3 t^1
// 3 t^2
// 1 t^3
// 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() // 1 t^0 // -3 t^2 // 3 t^4 // -1 t^6 // 1 t^0 // 3 t^1 // 3 t^2 // 1 t^3 // 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()
| self, var) |
Get string representation of variable named var.
sage: singular.set('int', 'x', '2')
sage: singular.get('x')
'2'
| self) |
Return the ideal generated by gens.
Input:
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
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*x1*x2
| self, lib, [reload=False]) |
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).
sage: singular.lib('sing.lib')
sage: singular.lib('sing.lib', reload=True)
| self, lib, [reload=False]) |
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).
sage: singular.lib('sing.lib')
sage: singular.lib('sing.lib', reload=True)
| self, x) |
Creates a list in Singular from a Sage list x.
sage: singular.list([1,2]) [1]: 1 [2]: 2
| self, lib, [reload=False]) |
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).
sage: singular.lib('sing.lib')
sage: singular.lib('sing.lib', reload=True)
| self, nrows, ncols, [entries=None]) |
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
Author: - Martin Albrecht (malb@informatik.uni-bremen.de), 2006-01-14
| self, [cmd=None], [val=None]) |
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')).
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
| self, [char=0], [vars=(x)], [order=lp], [check=True]) |
Create a Singular ring and makes it the current ring.
Input:
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).
We first declare
with degree reverse lexicographic ordering.
sage: R = singular.ring(0, '(x,y,z)', 'dp') sage: R // characteristic : 0 // 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')
This is a ring in variables named x(1) through x(10) over the finite
field of order
:
sage: R3 = singular.ring(7, '(x(1..10))', 'ds')
This is a polynomial ring over the transcendental extension
of
:
sage: 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')
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')
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
| self, type, name, value) |
Set the variable with given name to the given value.
sage: singular.set('int', 'x', '2')
sage: singular.get('x')
'2'
| self, R) |
Sets the current Singular ring to R.
sage: R = singular.ring(7, '(a,b)', 'ds')
sage: S = singular.ring('real', '(a,b)', 'lp')
sage: singular.current_ring()
// characteristic : 0 (real)
// number of vars : 2
// block 1 : ordering lp
// : names a b
// block 2 : ordering C
sage: singular.set_ring(R)
sage: singular.current_ring()
// characteristic : 7
// number of vars : 2
// block 1 : ordering ds
// : names a b
// block 2 : ordering C
| self, R) |
Sets the current Singular ring to R.
sage: R = singular.ring(7, '(a,b)', 'ds')
sage: S = singular.ring('real', '(a,b)', 'lp')
sage: singular.current_ring()
// characteristic : 0 (real)
// number of vars : 2
// block 1 : ordering lp
// : names a b
// block 2 : ordering C
sage: singular.set_ring(R)
sage: singular.current_ring()
// characteristic : 7
// number of vars : 2
// block 1 : ordering ds
// : names a b
// block 2 : ordering C
| self, x) |
Creates a Singular string from a Sage string. Note that the Sage string has to be "double-quoted".
sage: singular.string('"Sage"')
Sage
| self) |
Return a list of all Singular commands.
sage: singular.trait_names() ['headStand', ... 'stdfglm']
| self) |
Special Functions: __call__,
__init__,
__reduce__,
_create,
_equality_symbol,
_false_symbol,
_function_class,
_function_element_class,
_keyboard_interrupt,
_quit_string,
_read_in_file_command,
_start,
_true_symbol
| self, x, [type=def]) |
Create a singular object X with given type determined by the string x. This returns var, where var is built using the Singular statement type var = ... x ... Note that the actual name of var could be anything, and can be recovered using X.name().
The object X returned can be used like any Sage object, and wraps an object in self. The standard arithmetic operators work. Morever if foo is a function then X.foo(y,z,...) calls foo(X, y, z, ...) and returns the corresponding object.
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 -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: type(I) <class 'sage.interfaces.singular.SingularElement'> sage: I.parent() Singular
| self) |
sage: singular.__reduce__() (<function reduce_load_Singular at 0x...>, ())
| self, value, [type=def]) |
Creates a new variable in the Singular session and returns the name of that variable.
sage: singular._create('2', type='int')
'sage...'
sage: singular.get(_)
'2'
| self) |
sage: singular._equality_symbol() '=='
| self) |
sage: singular._false_symbol() '0'
| self) |
sage: singular._function_class() <class 'sage.interfaces.singular.SingularFunction'>
| self) |
sage: singular._function_element_class() <class 'sage.interfaces.singular.SingularFunctionElement'>
| self) |
sage: singular._quit_string() 'quit'
| self, filename) |
sage: singular._read_in_file_command('test')
'< "test";'
sage: filename = tmp_filename()
sage: f = open(filename, 'w')
sage: f.write('int x = 2;
')
sage: f.close()
sage: singular.read(filename)
sage: singular.get('x')
'2'
| self, [alt_message=None]) |
sage: s = Singular() sage: s.is_running() False sage: s._start() sage: s.is_running() True sage: s.quit()
| self) |
sage: singular._true_symbol() '1'
Class: SingularElement
| self, parent, type, value, [is_name=False]) |
sage: a = singular(2) sage: loads(dumps(a)) (invalid object -- defined in terms of closed session)
Functions: attrib,
sage_flattened_str_list,
sage_matrix,
sage_poly,
sage_polystring,
sage_structured_str_list,
set_ring,
trait_names,
type
| self, name, [value=None]) |
Get and set attributs for self.
Input:
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)
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'
| self) |
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']
| self, R, [sparse=True]) |
Returns Sage matrix for self
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]
| self, R, [kcache=None]) |
Returns a SAGE polynomial in the ring r matching the provided poly which is a singular polynomial.
Input:
sage: R = PolynomialRing(GF(2^8,'a'),2,'xy')
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'),1,'x')
sage: f=R('a^20*x^3+x^2+a^10')
sage: 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
Author: Martin Albrecht (2006-05-18)
oteFor 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
| self) |
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
using ring_name.set_ring().
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'
| self) |
If self is a Singular list of lists of Singular elements, returns corresponding SAGE list of lists of strings.
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,
1 '], ['C', '0 ']], '0']
| self) |
Sets the current ring in Singular to be self.
sage: R = singular.ring(7, '(a,b)', 'ds')
sage: S = singular.ring('real', '(a,b)', 'lp')
sage: singular.current_ring()
// characteristic : 0 (real)
// number of vars : 2
// block 1 : ordering lp
// : names a b
// block 2 : ordering C
sage: R.set_ring()
sage: singular.current_ring()
// characteristic : 7
// number of vars : 2
// block 1 : ordering ds
// : names a b
// block 2 : ordering C
| self) |
Returns the possible tab-completions for self. In this case, we just return all the tab completions for the Singular object.
sage: R = singular.ring(0,'(x,y)','dp') sage: R.trait_names() ['headStand', ... 'stdfglm']
| self) |
Returns the internal type of this element.
sage: R = PolynomialRing(GF(2^8,'a'),2,'x')
sage: R._singular_().type()
'ring'
sage: fs = singular('x0^2','poly')
sage: fs.type()
'poly'
Special Functions: __copy__,
__init__,
__iter__,
__len__,
__reduce__,
__repr__,
__setitem__,
_sage_,
_singular_
| self) |
Returns a copy of self.
sage: R=singular.ring(0,'(x,y)','dp')
sage: M=singular.matrix(3,3,'0,0,-x, 0,y,0, x*y,0,0')
sage: N=copy(M)
sage: N[1,1]=singular('x+y')
sage: N
x+y,0,-x,
0, y,0,
x*y,0,0
sage: M
0, 0,-x,
0, y,0,
x*y,0,0
sage: L=R.ringlist()
sage: L[4]=singular.ideal('x**2-5')
sage: Q=L.ring()
sage: otherR=singular.ring(5,'(x)','dp')
sage: cpQ=copy(Q)
sage: cpQ.set_ring()
sage: cpQ
// characteristic : 0
// number of vars : 2
// block 1 : ordering dp
// : names x y
// block 2 : ordering C
// quotient ring from ideal
_[1]=x^2-5
sage: R.fetch(M)
0, 0,-x,
0, y,0,
x*y,0,0
| self) |
sage: R = singular.ring(0, '(x,y,z)', 'dp') sage: A = singular.matrix(2,2) sage: list(iter(A)) [[0], [0]] sage: A[1,1] = 1; A[1,2] = 2 sage: A[2,1] = 3; A[2,2] = 4 sage: list(iter(A)) [[1,3], [2,4]]
| self) |
Returns the size of this Singular element.
sage: R = singular.ring(0, '(x,y,z)', 'dp') sage: A = singular.matrix(2,2) sage: len(A) 4
| self) |
Note that the result of the returned reduce_load is an invalid Singular object.
sage: singular(2).__reduce__() (<function reduce_load at 0x...>, ())
| self) |
Return string representation of self.
sage: r = singular.ring(0,'(x,y)','dp')
sage: singular(0)
0
sage: singular('x') # indirect doctest
x
sage: singular.matrix(2,2)
0,0,
0,0
sage: singular.matrix(2,2,"(25/47*x^2*y^4 + 63/127*x + 27)^3,y,0,1")
15625/103823*x^6*y.., y,
0, 1
Note that the output is truncated
sage: M= singular.matrix(2,2,"(25/47*x^2*y^4 + 63/127*x + 27)^3,y,0,1")
sage: M.rename('T')
sage: M
T[1,1],y,
0, 1
if self has a custom name, it is used to print
the matrix, rather than abbreviating its contents
| self, n, value) |
Set the n-th element of self to x.
Input:
sage: R = singular.ring(0, '(x,y,z)', 'dp') sage: A = singular.matrix(2,2) sage: A 0,0, 0,0 sage: A[1,1] = 5 sage: A 5,0, 0,0 sage: A[1,2] = '5*x + y + z3' sage: A 5,z^3+5*x+y, 0,0
| self, [R=None]) |
Coerces self to Sage.
sage: R = singular.ring(0, '(x,y,z)', 'dp') sage: A = singular.matrix(2,2) sage: A._sage_(ZZ) [0 0] [0 0]
| self) |
sage: R = singular.ring(0, '(x,y,z)', 'dp') sage: A = singular.matrix(2,2) sage: A._singular_() is A True
Class: SingularFunction
Special Functions: _sage_doc_
| self) |
sage: singular.groebner._sage_doc_() 'The SAGE interface to the Singular help system is not implemented.'
Class: SingularFunctionElement
Special Functions: _sage_doc_
| self) |
sage: R = singular.ring(0, '(x,y,z)', 'dp') sage: A = singular.matrix(2,2) sage: A.nrows._sage_doc_() 'The SAGE interface to the Singular help system is not implemented.'
See About this document... for information on suggesting changes.