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

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

AUTHORS: David Joyner and William Stein

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

Functions: clear,$  $ console,$  $ current_ring,$  $ current_ring_name,$  $ eval,$  $ get,$  $ ideal,$  $ LIB,$  $ lib,$  $ list,$  $ load,$  $ matrix,$  $ ring,$  $ set,$  $ set_ring,$  $ setring,$  $ string,$  $ trait_names,$  $ version

clear( self, var)

Clear the variable named var.

(Not actually done right now since it causes too many problems.)

current_ring( self)

Returns the current ring of the runnging Singular session.

sage: r = MPolynomialRing(GF(127),3,'xyz', order="revlex")
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 = MPolynomialRing(GF(127),3,'xyz')
sage: r._singular_().name() == singular.current_ring_name()
True

eval( self, x, [allow_semicolon=False])

Send the code x to the Singular interpreter and return the output as a string.

sage: singular.eval('2 > 1')
'1'
sage: singular.eval('2 + 2')
'4'

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

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

Create a Singular ring and makes it the current ring.

INPUT:
    char -- characteristic of the base ring (see examples below)
    vars -- a tuple or string that defines the variable names
    order -- 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).

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 transcendtal 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__,$  $ __reduce__,$  $ _create,$  $ _equality_symbol,$  $ _false_symbol,$  $ _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: is_zero,$  $ sage_flattened_str_list,$  $ sage_poly,$  $ sage_polystring,$  $ sage_structured_str_list,$  $ set_ring,$  $ trait_names,$  $ type

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      -- MPolynomialRing: 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 = MPolynomialRing(GF(2**8),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),1,'x')
sage: f=R('a^20*x^3+x^2+a^10')
sage: f._singular_().sage_poly(R)==f
True

sage: R.<XxZaa5,y> = PolynomialRing(Q,2)
sage: f = XxZaa5 * y^3 -(1/9)* XxZaa5 + 1
sage: singular(f)
XxZaa5*y^3-1/9*XxZaa5+1
sage: R(singular(f))
1 - 1/9*XxZaa5 + XxZaa5*y^3

Author: Martin Albrecht (2006-05-18)

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.

type( self)

Returns the internal type of this element.

sage: R = MPolynomialRing(GF(2**8),2,'x')
sage: R._singular_().type()
'ring'
sage: fs = singular('x0^2','poly')
sage: fs.type()
'poly'

Special Functions: __len__,$  $ __reduce__,$  $ __setitem__

__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

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.