Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Polynomial Interfaces to Singular
AUTHORS:
- Martin Albrecht <malb@informatik.uni-bremen.de> (2006-04-21) - Robert Bradshaw: Re-factor to avoid multiple inheritance vs. Cython (2007-09) - Syed Ahmad Lavasani: Added function field to _singular_init_ (2011-12-16) Added non-prime finite fields to _singular_init_ (2012-1-22)
TESTS::
sage: R = PolynomialRing(GF(2**8,'a'),10,'x', order='invlex') sage: R == loads(dumps(R)) True sage: P.<a,b> = PolynomialRing(GF(7), 2) sage: f = (a^3 + 2*b^2*a)^7; f a^21 + 2*a^7*b^14
"""
################################################################# # # Sage: System for Algebra and Geometry Experimentation # # Copyright (C) 2006 William Stein <wstein@gmail.com> # # Distributed under the terms of the GNU General Public License (GPL) # # This code is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # The full text of the GPL is available at: # # http://www.gnu.org/licenses/ # ######################################################################
import sage.rings.fraction_field import sage.rings.number_field as number_field
from sage.interfaces.all import singular from sage.rings.complex_field import is_ComplexField from sage.rings.real_mpfr import is_RealField from sage.rings.complex_double import is_ComplexDoubleField from sage.rings.finite_rings.integer_mod_ring import is_IntegerModRing from sage.rings.real_double import is_RealDoubleField from sage.rings.rational_field import is_RationalField from sage.rings.function_field.function_field import is_RationalFunctionField from sage.rings.finite_rings.finite_field_base import is_FiniteField from sage.rings.integer_ring import ZZ
import sage.arith.all import sage.rings.finite_rings.finite_field_constructor
class PolynomialRing_singular_repr: """ Implements methods to convert polynomial rings to Singular.
This class is a base class for all univariate and multivariate polynomial rings which support conversion from and to Singular rings. """ def _singular_(self, singular=singular): r""" Returns a singular ring for this polynomial ring. Currently `\QQ`, `{\rm GF}(p), {\rm GF}(p^n)`, `\CC`, `\RR`, `\ZZ` and `\ZZ/n\ZZ` are supported.
INPUT:
- ``singular`` - Singular instance
OUTPUT: Singular ring matching this ring
EXAMPLES::
sage: R.<x,y> = PolynomialRing(CC) sage: singular(R) polynomial ring, over a field, global ordering // coefficients: float[I](complex:15 digits, additional 0 digits)/(I^2+1) // number of vars : 2 // block 1 : ordering dp // : names x y // block 2 : ordering C sage: R.<x,y> = PolynomialRing(RealField(100)) sage: singular(R) polynomial ring, over a field, global ordering // coefficients: float // number of vars : 2 // block 1 : ordering dp // : names x y // block 2 : ordering C
sage: w = var('w') sage: R.<x> = PolynomialRing(NumberField(w^2+1,'s')) sage: singular(R) polynomial ring, over a field, global ordering // coefficients: QQ[s]/(s^2+1) // number of vars : 1 // block 1 : ordering lp // : names x // block 2 : ordering C
sage: R = PolynomialRing(GF(127), 'x', implementation="singular") sage: singular(R) polynomial ring, over a field, global ordering // coefficients: ZZ/127 // number of vars : 1 // block 1 : ordering lp // : names x // block 2 : ordering C
sage: R = PolynomialRing(QQ, 'x', implementation="singular") sage: singular(R) polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 1 // block 1 : ordering lp // : names x // block 2 : ordering C
sage: R = PolynomialRing(QQ,'x') sage: singular(R) polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 1 // block 1 : ordering lp // : names x // block 2 : ordering C
sage: R = PolynomialRing(GF(127),'x') sage: singular(R) polynomial ring, over a field, global ordering // coefficients: ZZ/127 // number of vars : 1 // block 1 : ordering lp // : names x // block 2 : ordering C
sage: R = Frac(ZZ['a,b'])['x,y'] sage: singular(R) polynomial ring, over a field, global ordering // coefficients: QQ(a, b) // number of vars : 2 // block 1 : ordering dp // : names x y // block 2 : ordering C
sage: R = IntegerModRing(1024)['x,y'] sage: singular(R) polynomial ring, over a ring (with zero-divisors), global ordering // coefficients: ZZ/(2^10) // number of vars : 2 // block 1 : ordering dp // : names x y // block 2 : ordering C
sage: R = IntegerModRing(15)['x,y'] sage: singular(R) polynomial ring, over a ring (with zero-divisors), global ordering // coefficients: ZZ/bigint(15) // number of vars : 2 // block 1 : ordering dp // : names x y // block 2 : ordering C
sage: R = ZZ['x,y'] sage: singular(R) polynomial ring, over a domain, global ordering // coefficients: ZZ // number of vars : 2 // block 1 : ordering dp // : names x y // block 2 : ordering C
sage: k.<a> = FiniteField(25) sage: R = k['x'] sage: K = R.fraction_field() sage: S = K['y'] sage: singular(S) polynomial ring, over a field, global ordering // coefficients: ZZ/5(x) // number of vars : 2 // block 1 : ordering lp // : names a y // block 2 : ordering C // quotient ring from ideal _[1]=a2-a+2
.. warning::
- If the base ring is a finite extension field or a number field the ring will not only be returned but also be set as the current ring in Singular. - Singular represents precision of floating point numbers base 10 while Sage represents floating point precision base 2. """ raise ValueError (number_field.number_field_base.is_NumberField(self.base_ring()) and self.base_ring().is_absolute()): R.set_ring() #sorry for that, but needed for minpoly if singular.eval('minpoly') != "(" + self.__minpoly + ")": singular.eval("minpoly=%s"%(self.__minpoly)) self.__minpoly = singular.eval('minpoly')[1:-1]
def _singular_init_(self, singular=singular): """ Return a newly created Singular ring matching this ring.
EXAMPLES::
sage: PolynomialRing(QQ,'u_ba')._singular_init_() polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 1 // block 1 : ordering lp // : names u_ba // block 2 : ordering C """
_vars = _vars.split("*")[1] else:
# singular converts to bits from base_10 in mpr_complex.cc by: # size_t bits = 1 + (size_t) ((float)digits * 3.5);
# singular converts to bits from base_10 in mpr_complex.cc by: # size_t bits = 1 + (size_t) ((float)digits * 3.5);
# singular converts to bits from base_10 in mpr_complex.cc by: # size_t bits = 1 + (size_t) ((float)digits * 3.5);
# singular converts to bits from base_10 in mpr_complex.cc by: # size_t bits = 1 + (size_t) ((float)digits * 3.5); self.__singular = singular.ring("(complex,15,0,I)", _vars, order=order, check=False)
# not the prime field! gen = str(base_ring.gen()) r = singular.ring( "(%s,%s)"%(self.characteristic(),gen), _vars, order=order, check=False)
self.__minpoly = (str(base_ring.modulus()).replace("x",gen)).replace(" ","") if singular.eval('minpoly') != "(" + self.__minpoly + ")": singular.eval("minpoly=%s"%(self.__minpoly) ) self.__minpoly = singular.eval('minpoly')[1:-1]
self.__singular = r
# not the rationals!
else:
else:
exp = ch.nbits() -1 self.__singular = singular.ring("(integer,2,%d)"%(exp,), _vars, order=order, check=False) else:
elif base_ring is ZZ: self.__singular = singular.ring("(integer)", _vars, order=order, check=False) else: raise TypeError("no conversion to a Singular ring defined")
def can_convert_to_singular(R): """ Returns True if this ring's base field or ring can be represented in Singular, and the polynomial ring has at least one generator. If this is True then this polynomial ring can be represented in Singular.
The following base rings are supported: finite fields, rationals, number fields, and real and complex fields.
EXAMPLES::
sage: from sage.rings.polynomial.polynomial_singular_interface import can_convert_to_singular sage: can_convert_to_singular(PolynomialRing(QQ, names=['x'])) True
sage: can_convert_to_singular(PolynomialRing(QQ, names=[])) False
TESTS:
Avoid non absolute number fields (see :trac:`23535`)::
sage: K.<a,b> = NumberField([x^2-2,x^2-5]) sage: can_convert_to_singular(K['s,t']) False """
or sage.rings.finite_rings.finite_field_constructor.is_FiniteField(base_ring) or is_RationalField(base_ring) or is_IntegerModRing(base_ring) or is_RealField(base_ring) or is_ComplexField(base_ring) or is_RealDoubleField(base_ring) or is_ComplexDoubleField(base_ring)): return base_ring.characteristic() <= 2147483647 else:
class Polynomial_singular_repr: """ Implements coercion of polynomials to Singular polynomials.
This class is a base class for all (univariate and multivariate) polynomial classes which support conversion from and to Singular polynomials.
Due to the incompatibility of Python extension classes and multiple inheritance, this just defers to module-level functions. """ def _singular_(self, singular=singular, have_ring=False):
def _singular_init_func(self, singular=singular, have_ring=False): return _singular_init_func(self, singular, have_ring)
def _singular_func(self, singular=singular, have_ring=False): """ Return Singular polynomial matching this polynomial.
INPUT:
- ``singular`` - Singular instance to use. - ``have_ring`` - if True we will not attempt to set this element's ring as the current Singular ring. This is useful to speed up a batch of ``f._singular_()`` calls. However, it's dangerous as it might lead to wrong results if another ring is ``singular.current_ring()``. (Default: False)
EXAMPLES::
sage: P.<a,b> = PolynomialRing(GF(7), 2) sage: f = (a^3 + 2*b^2*a)^7; f a^21 + 2*a^7*b^14 sage: h = f._singular_(); h a^21+2*a^7*b^14 sage: P(h) a^21 + 2*a^7*b^14 sage: P(h^20) == f^20 True
sage: R.<x> = PolynomialRing(GF(7)) sage: f = (x^3 + 2*x^2*x)^7 sage: f 3*x^21 sage: h = f._singular_(); h 3*x^21 sage: R(h) 3*x^21 sage: R(h^20) == f^20 True """
# return self._singular_init_(singular,have_ring=have_ring)
def _singular_init_func(self, singular=singular, have_ring=False): """ Return corresponding Singular polynomial but enforce that a new instance is created in the Singular interpreter.
Use ``self._singular_()`` instead. """
|