Package sage :: Package rings :: Package polynomial :: Module polynomial_ring_constructor
[hide private]
[frames] | no frames]

Module polynomial_ring_constructor

source code

Functions [hide private]
 
PolynomialRing(base_ring, arg1=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., arg2=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., sparse=False, order='degrevlex', names=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., name=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., implementation=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)
Return the globally unique univariate or multivariate polynomial ring with given properties and variable name or names.
source code
 
MPolynomialRing(*args, **kwds)
This function is deprecated and will be removed in a future version of Sage.
source code
 
_get_from_cache(key) source code
 
_save_in_cache(key, R) source code
 
_single_variate(base_ring, name, sparse, implementation) source code
 
_multi_variate(base_ring, names, n, sparse, order) source code
 
BooleanPolynomialRing_constructor(n=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., names=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., order='lex')
Construct a boolean polynomial ring with the following...
source code
Variables [hide private]
  _cache = {(Algebraic Field, ('x'), False, None): <weakref at 0...
Function Details [hide private]

PolynomialRing(base_ring, arg1=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., arg2=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., sparse=False, order='degrevlex', names=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., name=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., implementation=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a...)

source code 

Return the globally unique univariate or multivariate polynomial
ring with given properties and variable name or names.

There are four ways to call the polynomial ring constructor:
      1. PolynomialRing(base_ring, name,    sparse=False)
      2. PolynomialRing(base_ring, names,   order='degrevlex')
      3. PolynomialRing(base_ring, name, n, order='degrevlex')
      4. PolynomialRing(base_ring, n, name, order='degrevlex')

The optional arguments sparse and order *must* be explicitly
named, and the other arguments must be given positionally.

INPUT:
     base_ring -- a commutative ring
     name -- a string
     names -- a list or tuple of names, or a comma separated string
     n -- an integer
     sparse -- bool (default: False), whether or not elements are sparse
     order -- string or TermOrder, e.g.,
             'degrevlex' (default) -- degree reverse lexicographic
             'lex'  -- lexicographic
             'deglex' -- degree lexicographic
             TermOrder('deglex',3) + TermOrder('deglex',3) -- block ordering
     implementation -- string or None; selects an implementation
             in cases where Sage includes multiple choices
             (currently ZZ[x] can be implemented with 'NTL' or 'FLINT';
             default is 'FLINT')
             
OUTPUT:
    PolynomialRing(base_ring, name, sparse=False) returns a univariate
    polynomial ring; all other input formats return a multivariate
    polynomial ring.

UNIQUENESS and IMMUTABILITY: In SAGE there is exactly one
single-variate polynomial ring over each base ring in each choice
of variable, sparseness, and implementation.  There is also exactly
one multivariate polynomial ring over each base ring for each
choice of names of variables and term order.  The names of the
generators can only be temporarily changed after the ring has been
created.  Do this using the localvars context:

    EXAMPLES of VARIABLE NAME CONTEXT:
        sage: R.<x,y> = PolynomialRing(QQ,2); R
        Multivariate Polynomial Ring in x, y over Rational Field
        sage: f = x^2 - 2*y^2

    You can't just globally change the names of those variables.
    This is because objects all over SAGE could have pointers to
    that polynomial ring.
        sage: R._assign_names(['z','w'])
        Traceback (most recent call last):
        ...
        ValueError: variable names cannot be changed after object creation.

    However, you can very easily change the names within a "with" block:
        sage: with localvars(R, ['z','w']):
        ...     print f
        ...     
        z^2 - 2*w^2

    After the with block the names revert to what they were before. 
        sage: print f
        x^2 - 2*y^2
        

SQUARE BRACKETS NOTATION: You can alternatively create a single or
multivariate polynomial ring over a ring $R$ by writing
\code{R['varname']} or \code{R['var1,var2,var3,...']}.  This
square brackets notation doesn't allow for setting any of the
optional arguments.   

EXAMPLES:
1. PolynomialRing(base_ring, name,    sparse=False):
    sage: PolynomialRing(QQ, 'w')
    Univariate Polynomial Ring in w over Rational Field

Use the diamond brackets notation to make the variable
ready for use after you define the ring:
    sage: R.<w> = PolynomialRing(QQ)
    sage: (1 + w)^3
    w^3 + 3*w^2 + 3*w + 1
    
You must specify a name:
    sage: PolynomialRing(QQ)
    Traceback (most recent call last):
    ...
    TypeError: You must specify the names of the variables.

    sage: R.<abc> = PolynomialRing(QQ, sparse=True); R
    Sparse Univariate Polynomial Ring in abc over Rational Field

    sage: R.<w> = PolynomialRing(PolynomialRing(GF(7),'k')); R
    Univariate Polynomial Ring in w over Univariate Polynomial Ring in k over Finite Field of size 7

The square bracket notation:
    sage: R.<y> = QQ['y']; R
    Univariate Polynomial Ring in y over Rational Field
    sage: y^2 + y
    y^2 + y

In fact, since the diamond brackets on the left determine the
variable name, you can omit the variable from the square brackets:
    sage: R.<zz> = QQ[]; R
    Univariate Polynomial Ring in zz over Rational Field
    sage: (zz + 1)^2
    zz^2 + 2*zz + 1

This is exactly the same ring as what PolynomialRing returns:
    sage: R is PolynomialRing(QQ,'zz')
    True

However, rings with different variables are different:
    sage: QQ['x'] == QQ['y']
    False
    
\sage has two implementations of univariate polynomials over the
integers, one based on NTL and one based on FLINT.  The default
is FLINT. Note that FLINT uses a "more dense" representation for
its polynomials than NTL, so in particular, creating a polynomial
like 2^1000000 * x^1000000 in FLINT may be unwise.
    sage: ZxNTL = PolynomialRing(ZZ, 'x', implementation='NTL'); ZxNTL
    Univariate Polynomial Ring in x over Integer Ring (using NTL)
    sage: ZxFLINT = PolynomialRing(ZZ, 'x', implementation='FLINT'); ZxFLINT
    Univariate Polynomial Ring in x over Integer Ring
    sage: ZxFLINT is ZZ['x']
    True
    sage: ZxFLINT is PolynomialRing(ZZ, 'x')
    True
    sage: xNTL = ZxNTL.gen()
    sage: xFLINT = ZxFLINT.gen()
    sage: xNTL.parent()
    Univariate Polynomial Ring in x over Integer Ring (using NTL)
    sage: xFLINT.parent()
    Univariate Polynomial Ring in x over Integer Ring

There is a coercion between the two rings, so the values can be
mixed in a single expression.
    sage: (xNTL + xFLINT^2)
    x^2 + x

Unfortunately, it is unpredictable whether the result of such an
expression will use the NTL or FLINT implementation.
    sage: (xNTL + xFLINT^2).parent()        # random output
    Univariate Polynomial Ring in x over Integer Ring

2. PolynomialRing(base_ring, names,   order='degrevlex'):
    sage: R = PolynomialRing(QQ, 'a,b,c'); R
    Multivariate Polynomial Ring in a, b, c over Rational Field

    sage: S = PolynomialRing(QQ, ['a','b','c']); S
    Multivariate Polynomial Ring in a, b, c over Rational Field

    sage: T = PolynomialRing(QQ, ('a','b','c')); T
    Multivariate Polynomial Ring in a, b, c over Rational Field

All three rings are identical.
    sage: (R is S) and  (S is T)
    True

There is a unique polynomial ring with each term order:
    sage: R = PolynomialRing(QQ, 'x,y,z', order='degrevlex'); R
    Multivariate Polynomial Ring in x, y, z over Rational Field
    sage: S = PolynomialRing(QQ, 'x,y,z', order='invlex'); S
    Multivariate Polynomial Ring in x, y, z over Rational Field
    sage: S is PolynomialRing(QQ, 'x,y,z', order='invlex')
    True
    sage: R == S
    False


3. PolynomialRing(base_ring, name, n, order='degrevlex'):

If you specify a single name as a string and a number of
variables, then variables labeled with numbers are created.
    sage: PolynomialRing(QQ, 'x', 10)
    Multivariate Polynomial Ring in x0, x1, x2, x3, x4, x5, x6, x7, x8, x9 over Rational Field
    
    sage: PolynomialRing(GF(7), 'y', 5)
    Multivariate Polynomial Ring in y0, y1, y2, y3, y4 over Finite Field of size 7

    sage: PolynomialRing(QQ, 'y', 3, sparse=True)
    Multivariate Polynomial Ring in y0, y1, y2 over Rational Field

It is easy in Python to create fairly aribtrary variable names.
For example, here is a ring with generators labeled by the first
100 primes:

    sage: R = PolynomialRing(ZZ, ['x%s'%p for p in primes(100)]); R
    Multivariate Polynomial Ring in x2, x3, x5, x7, x11, x13, x17, x19, x23, x29, x31, x37, x41, x43, x47, x53, x59, x61, x67, x71, x73, x79, x83, x89, x97 over Integer Ring

By calling the \code{inject_variables()} method all those variable
names are available for interactive use:
    sage: R.inject_variables()
    Defining x2, x3, x5, x7, x11, x13, x17, x19, x23, x29, x31, x37, x41, x43, x47, x53, x59, x61, x67, x71, x73, x79, x83, x89, x97        
    sage: (x2 + x41 + x71)^2
    x2^2 + 2*x2*x41 + x41^2 + 2*x2*x71 + 2*x41*x71 + x71^2

You can also call \code{injvar}, which is a convenient shortcut for \code{inject_variables()}.
    sage: R = PolynomialRing(GF(7),15,'w'); R
    Multivariate Polynomial Ring in w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14 over Finite Field of size 7        
    sage: R.injvar()
    Defining w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14
    sage: (w0 + 2*w8 + w13)^2
    w0^2 - 3*w0*w8 - 3*w8^2 + 2*w0*w13 - 3*w8*w13 + w13^2

MPolynomialRing(*args, **kwds)

source code 

This function is deprecated and will be removed in a future version of
Sage. Please use PolynomialRing instead.

If you have questions regarding this function and it's replacement,
please send your comments to sage-support@googlegroups.com.


Return the globally unique univariate or multivariate polynomial
ring with given properties and variable name or names.

There are four ways to call the polynomial ring constructor:
      1. PolynomialRing(base_ring, name,    sparse=False)
      2. PolynomialRing(base_ring, names,   order='degrevlex')
      3. PolynomialRing(base_ring, name, n, order='degrevlex')
      4. PolynomialRing(base_ring, n, name, order='degrevlex')

The optional arguments sparse and order *must* be explicitly
named, and the other arguments must be given positionally.

INPUT:
     base_ring -- a commutative ring
     name -- a string
     names -- a list or tuple of names, or a comma separated string
     n -- an integer
     sparse -- bool (default: False), whether or not elements are sparse
     order -- string or TermOrder, e.g.,
             'degrevlex' (default) -- degree reverse lexicographic
             'lex'  -- lexicographic
             'deglex' -- degree lexicographic
             TermOrder('deglex',3) + TermOrder('deglex',3) -- block ordering
     implementation -- string or None; selects an implementation
             in cases where Sage includes multiple choices
             (currently ZZ[x] can be implemented with 'NTL' or 'FLINT';
             default is 'FLINT')
             
OUTPUT:
    PolynomialRing(base_ring, name, sparse=False) returns a univariate
    polynomial ring; all other input formats return a multivariate
    polynomial ring.

UNIQUENESS and IMMUTABILITY: In SAGE there is exactly one
single-variate polynomial ring over each base ring in each choice
of variable, sparseness, and implementation.  There is also exactly
one multivariate polynomial ring over each base ring for each
choice of names of variables and term order.  The names of the
generators can only be temporarily changed after the ring has been
created.  Do this using the localvars context:

    EXAMPLES of VARIABLE NAME CONTEXT:
        sage: R.<x,y> = PolynomialRing(QQ,2); R
        Multivariate Polynomial Ring in x, y over Rational Field
        sage: f = x^2 - 2*y^2

    You can't just globally change the names of those variables.
    This is because objects all over SAGE could have pointers to
    that polynomial ring.
        sage: R._assign_names(['z','w'])
        Traceback (most recent call last):
        ...
        ValueError: variable names cannot be changed after object creation.

    However, you can very easily change the names within a "with" block:
        sage: with localvars(R, ['z','w']):
        ...     print f
        ...     
        z^2 - 2*w^2

    After the with block the names revert to what they were before. 
        sage: print f
        x^2 - 2*y^2
        

SQUARE BRACKETS NOTATION: You can alternatively create a single or
multivariate polynomial ring over a ring $R$ by writing
\code{R['varname']} or \code{R['var1,var2,var3,...']}.  This
square brackets notation doesn't allow for setting any of the
optional arguments.   

EXAMPLES:
1. PolynomialRing(base_ring, name,    sparse=False):
    sage: PolynomialRing(QQ, 'w')
    Univariate Polynomial Ring in w over Rational Field

Use the diamond brackets notation to make the variable
ready for use after you define the ring:
    sage: R.<w> = PolynomialRing(QQ)
    sage: (1 + w)^3
    w^3 + 3*w^2 + 3*w + 1
    
You must specify a name:
    sage: PolynomialRing(QQ)
    Traceback (most recent call last):
    ...
    TypeError: You must specify the names of the variables.

    sage: R.<abc> = PolynomialRing(QQ, sparse=True); R
    Sparse Univariate Polynomial Ring in abc over Rational Field

    sage: R.<w> = PolynomialRing(PolynomialRing(GF(7),'k')); R
    Univariate Polynomial Ring in w over Univariate Polynomial Ring in k over Finite Field of size 7

The square bracket notation:
    sage: R.<y> = QQ['y']; R
    Univariate Polynomial Ring in y over Rational Field
    sage: y^2 + y
    y^2 + y

In fact, since the diamond brackets on the left determine the
variable name, you can omit the variable from the square brackets:
    sage: R.<zz> = QQ[]; R
    Univariate Polynomial Ring in zz over Rational Field
    sage: (zz + 1)^2
    zz^2 + 2*zz + 1

This is exactly the same ring as what PolynomialRing returns:
    sage: R is PolynomialRing(QQ,'zz')
    True

However, rings with different variables are different:
    sage: QQ['x'] == QQ['y']
    False
    
\sage has two implementations of univariate polynomials over the
integers, one based on NTL and one based on FLINT.  The default
is FLINT. Note that FLINT uses a "more dense" representation for
its polynomials than NTL, so in particular, creating a polynomial
like 2^1000000 * x^1000000 in FLINT may be unwise.
    sage: ZxNTL = PolynomialRing(ZZ, 'x', implementation='NTL'); ZxNTL
    Univariate Polynomial Ring in x over Integer Ring (using NTL)
    sage: ZxFLINT = PolynomialRing(ZZ, 'x', implementation='FLINT'); ZxFLINT
    Univariate Polynomial Ring in x over Integer Ring
    sage: ZxFLINT is ZZ['x']
    True
    sage: ZxFLINT is PolynomialRing(ZZ, 'x')
    True
    sage: xNTL = ZxNTL.gen()
    sage: xFLINT = ZxFLINT.gen()
    sage: xNTL.parent()
    Univariate Polynomial Ring in x over Integer Ring (using NTL)
    sage: xFLINT.parent()
    Univariate Polynomial Ring in x over Integer Ring

There is a coercion between the two rings, so the values can be
mixed in a single expression.
    sage: (xNTL + xFLINT^2)
    x^2 + x

Unfortunately, it is unpredictable whether the result of such an
expression will use the NTL or FLINT implementation.
    sage: (xNTL + xFLINT^2).parent()        # random output
    Univariate Polynomial Ring in x over Integer Ring

2. PolynomialRing(base_ring, names,   order='degrevlex'):
    sage: R = PolynomialRing(QQ, 'a,b,c'); R
    Multivariate Polynomial Ring in a, b, c over Rational Field

    sage: S = PolynomialRing(QQ, ['a','b','c']); S
    Multivariate Polynomial Ring in a, b, c over Rational Field

    sage: T = PolynomialRing(QQ, ('a','b','c')); T
    Multivariate Polynomial Ring in a, b, c over Rational Field

All three rings are identical.
    sage: (R is S) and  (S is T)
    True

There is a unique polynomial ring with each term order:
    sage: R = PolynomialRing(QQ, 'x,y,z', order='degrevlex'); R
    Multivariate Polynomial Ring in x, y, z over Rational Field
    sage: S = PolynomialRing(QQ, 'x,y,z', order='invlex'); S
    Multivariate Polynomial Ring in x, y, z over Rational Field
    sage: S is PolynomialRing(QQ, 'x,y,z', order='invlex')
    True
    sage: R == S
    False


3. PolynomialRing(base_ring, name, n, order='degrevlex'):

If you specify a single name as a string and a number of
variables, then variables labeled with numbers are created.
    sage: PolynomialRing(QQ, 'x', 10)
    Multivariate Polynomial Ring in x0, x1, x2, x3, x4, x5, x6, x7, x8, x9 over Rational Field
    
    sage: PolynomialRing(GF(7), 'y', 5)
    Multivariate Polynomial Ring in y0, y1, y2, y3, y4 over Finite Field of size 7

    sage: PolynomialRing(QQ, 'y', 3, sparse=True)
    Multivariate Polynomial Ring in y0, y1, y2 over Rational Field

It is easy in Python to create fairly aribtrary variable names.
For example, here is a ring with generators labeled by the first
100 primes:

    sage: R = PolynomialRing(ZZ, ['x%s'%p for p in primes(100)]); R
    Multivariate Polynomial Ring in x2, x3, x5, x7, x11, x13, x17, x19, x23, x29, x31, x37, x41, x43, x47, x53, x59, x61, x67, x71, x73, x79, x83, x89, x97 over Integer Ring

By calling the \code{inject_variables()} method all those variable
names are available for interactive use:
    sage: R.inject_variables()
    Defining x2, x3, x5, x7, x11, x13, x17, x19, x23, x29, x31, x37, x41, x43, x47, x53, x59, x61, x67, x71, x73, x79, x83, x89, x97        
    sage: (x2 + x41 + x71)^2
    x2^2 + 2*x2*x41 + x41^2 + 2*x2*x71 + 2*x41*x71 + x71^2

You can also call \code{injvar}, which is a convenient shortcut for \code{inject_variables()}.
    sage: R = PolynomialRing(GF(7),15,'w'); R
    Multivariate Polynomial Ring in w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14 over Finite Field of size 7        
    sage: R.injvar()
    Defining w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14
    sage: (w0 + 2*w8 + w13)^2
    w0^2 - 3*w0*w8 - 3*w8^2 + 2*w0*w13 - 3*w8*w13 + w13^2

BooleanPolynomialRing_constructor(n=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., names=['4ti2-20061025', 'R-2.6.0', 'atlas-3.7.37', 'atlas-3.8.1', 'a..., order='lex')

source code 

Construct a boolean polynomial ring with the following
parameters:

INPUT:
    n -- number of variables (an integer > 1)
    names -- names of ring variables, may be a string of
             list/tuple
    order -- term order (default: lex)

EXAMPLES:
    sage: R.<x, y, z> = BooleanPolynomialRing() # indirect doctest
    sage: R
    Boolean PolynomialRing in x, y, z

    sage: p = x*y + x*z + y*z
    sage: x*p
    x*y*z + x*y + x*z

    sage: R.term_order()
    Lexicographic term order

    sage: R = BooleanPolynomialRing(5,'x',order='deglex(3),deglex(2)')
    sage: R.term_order()
    deglex(3),deglex(2) term order

    sage: R = BooleanPolynomialRing(3,'x',order='degrevlex')
    sage: R.term_order()
    Degree reverse lexicographic term order

    sage: BooleanPolynomialRing(names=('x','y'))
    Boolean PolynomialRing in x, y

    sage: BooleanPolynomialRing(names='x,y')
    Boolean PolynomialRing in x, y

TESTS:
    sage: P.<x,y> = BooleanPolynomialRing(2,order='degrevlex')
    sage: x > y
    True

    sage: P.<x0, x1, x2, x3> = BooleanPolynomialRing(4,order='degrevlex(2),degrevlex(2)')
    sage: x0 > x1
    True
    sage: x2 > x3
    True


Variables Details [hide private]

_cache

Value:
{(Algebraic Field, ('x'), False, None): <weakref at 0x1a33e68; to 'Pol\
ynomialRing_field' at 0x1a2b128>,
 (Algebraic Real Field, ('x'), False, None): <weakref at 0x1a33fc8; to\
 'PolynomialRing_field' at 0x1a2b200>,
 (Integer Ring, ('t'), False, None): <weakref at 0x4a69cb0; to 'Polyno\
mialRing_integral_domain' at 0x4a1e8c0>,
 (Integer Ring, ('t'), False, 'FLINT'): <weakref at 0x4a69cb0; to 'Pol\
ynomialRing_integral_domain' at 0x4a1e8c0>,
...