14.15.5 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)

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

is_SingularElement( x)

reduce_load( )

reduce_load_Singular( )

singular_console( )

singular_version( )

Class: Singular

class Singular
Interface to the Singular interpreter.

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

Singular( self, [maxread=1000], [script_subdirectory=None], [logfile=None], [server=None], [server_tmpdir=None])

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

clear( self, var)

Clear the variable named var.

current_ring( 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

current_ring_name( 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

eval( self, x, [allow_semicolon=True], [strip=True])

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 a TypeError if the input line contains a semicolon.
strip
- ignored

sage: singular.eval('2 > 1')
'1'
sage: 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()))
'// 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()

get( self, var)

Get string representation of variable named var.

ideal( self)

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

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

LIB( 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).

lib( 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).

load( 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).

matrix( 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

option( self, [cmd=None], [val=None])

Access to Singular's options as follows:

Syntax: option() Return Type: string Purpose: lists all defined options.

Syntax: option( 'option_name' ) Return Type: none Purpose: sets an option. Note: To disable an option, use the prefix no.

Syntax: option( 'get' ) Return Type: intvec Purpose: dumps the state of all options to an intvec.

Syntax: option( 'set', intvec_expression ) Type: none Purpose: restores the state of all options from an intvec (produced by option(get)).

ring( self, [char=0], [vars=(x)], [order=lp], [check=True])

Create a Singular ring and makes it the current ring.

Input:

char
- characteristic of the base ring (see examples below), which must be either 0, prime (!), or one of several special codes (see examples below).
vars
- a tuple or string that defines the variable names
order
- string - the monomial order (default: 'lp')
check
- if True, check primality of the characteristic if it is an integer.

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).

We first declare $ \mathbf{Q}[x,y,z]$ 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 $ 7$ :

sage: R3 = singular.ring(7, '(x(1..10))', 'ds')

This is a polynomial ring over the transcendental extension $ \mathbf{Q}(a)$ of $ \mathbf{Q}$ :

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

set( self, type, name, value)

Set the variable with given name to the given value.

trait_names( self)

Return a list of all Singular commands.

Special Functions: __call__,$ \,$ __init__,$ \,$ __reduce__,$ \,$ _create,$ \,$ _equality_symbol,$ \,$ _false_symbol,$ \,$ _keyboard_interrupt,$ \,$ _quit_string,$ \,$ _read_in_file_command,$ \,$ _start,$ \,$ _true_symbol

__call__( 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

Class: SingularElement

class SingularElement
SingularElement( self, parent, type, value, [is_name=False])

Functions: attrib,$ \,$ sage_flattened_str_list,$ \,$ sage_matrix,$ \,$ sage_poly,$ \,$ sage_polystring,$ \,$ sage_structured_str_list,$ \,$ set_ring,$ \,$ trait_names,$ \,$ type

attrib( self, name, [value=None])

Get and set attributs for self.

Input:

name
- string to choose the attribute
value
- 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)

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'

sage_matrix( self, R, [sparse=True])

Returns SAGE matrix for self

sage_poly( self, R, [kcache=None])

Returns a SAGE polynomial in the ring r matching the provided poly which is a singular polynomial.

Input:

R
- PolynomialRing: you *must* take care it matches the current singular ring as, e.g., returned by singular.current_ring()
kcache
- (default: None); an optional dictionary for faster finite field lookups, this is mainly useful for finite extension fields

Output: MPolynomial

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

sage_polystring( 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'

sage_structured_str_list( 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']

type( 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__,$ \,$ __setitem__,$ \,$ _sage_,$ \,$ _singular_

__copy__( 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

__setitem__( self, n, value)

Set the n-th element of self to x.

Input:

n
- an integer *or* a 2-tuple (for setting matrix elements)
value
- anything (is coerced to a Singular object if it is not one already)

Output: Changes elements of self.

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

_sage_( self, [R=None])

Coerces self to SAGE.

Class: SingularFunction

class SingularFunction

Special Functions: _sage_doc_

Class: SingularFunctionElement

class SingularFunctionElement

Special Functions: _sage_doc_

See About this document... for information on suggesting changes.