# Changeset 2780:42946f8405f4

Ignore:
Timestamp:
02/05/07 23:10:29 (6 years ago)
Branch:
default
Children:
2781:66859ef2393c, 2896:182f6837300c
Message:

renamed some functions to reflect that an ideal != an ideal basis in SAGE in constrast to e.g. Singular

File:
1 edited

### Legend:

Unmodified
 r2485 s.option("redSB") R = self.ring() ret = [ R(f) for f in self._singular_().interred() ] ret = Sequence([ R(f) for f in self._singular_().interred() ], R, check=False, immutable=True) s.option("set",o) return ret def is_groebner(self): def basis_is_groebner(self): """ Returns true if self.gens() form a Groebner Basis. This is done by sage: R. = PolynomialRing(GF(127),10) sage: I = sage.rings.ideal.Cyclic(R,4) sage: I.is_groebner() sage: I.basis_is_groebner() False sage: I2 = Ideal(I.groebner_basis()) sage: I2.is_groebner() sage: I2.basis_is_groebner() True return False return True class MPolynomialIdeal_macaulay2_repr: """ An ideal in a multivariate polynomial ring, which has an underlying Macaulay2 ring associated to it. EXAMPLES: sage: R. = PolynomialRing(ZZ, 4) # optional sage: I = ideal(x*y-z^2, y^2-w^2)       # optional sage: I                                 # optional Ideal (-1*w^2 + y^2, -1*z^2 + x*y) of Polynomial Ring in x, y, z, w over Integer Ring """ #def __init__(self, ring, gens, coerce=True): #    MPolynomialIdeal.__init__(self, ring, gens, coerce=coerce) def _macaulay2_(self, macaulay2=None): """ Return Macaulay2 ideal corresponding to this ideal. """ if macaulay2 is None: macaulay2 = macaulay2_default try: self.ring()._macaulay2_(macaulay2) I = self.__macaulay2 if not (I.parent() is macaulay2): raise ValueError I._check_valid() return I except (AttributeError, ValueError): self.ring()._macaulay2_(macaulay2) gens = [str(x) for x in self.gens()] if len(gens) == 0: gens = ['0'] self.__macaulay2 = macaulay2.ideal(gens) return self.__macaulay2 def _macaulay2_groebner_basis(self): r""" Return the Groebner basis for this ideal, computed using Macaulay2. ALGORITHM: Computed using Macaulay2.  A big advantage of Macaulay2 is that it can compute Groebner basis of ideals in polynomial rings over the integers. EXAMPLE: sage: R. = PolynomialRing(ZZ, 4) sage: I = ideal(x*y-z^2, y^2-w^2) sage: I.groebner_basis()                                     # optional -- requires macaulay2 [-1*w^2 + y^2, -1*z^2 + x*y, y*z^2 - x*w^2, z^4 - x^2*w^2] Groebner basis can be used to compute in $\Z/n\Z[x,\ldots]$. sage: R. = ZZ[] sage: I = ideal([y^2*z - x^3 - 19*x*z, y^2, 19^2]) sage: I.groebner_basis()                                     # optional -- requires macaulay2 [361, y^2, 19*x*z + x^3] sage: I = ideal([y^2*z - x^3 - 19^2*x*z, y^2, 19^2]) sage: I.groebner_basis()                                     # optional -- requires macaulay2 [361, y^2, x^3] """ try: return self.__groebner_basis except AttributeError: I = self._macaulay2_() G = str(I.gb().generators().str()).replace('\n','') i = G.rfind('{{') j = G.rfind('}}') G = G[i+2:j].split(',') L = self.ring().var_dict() B = [sage_eval(f, L) for f in G] B = Sequence(B, self.ring(), check=False, immutable=True) B.sort() self.__groebner_basis = B return B class MPolynomialIdeal( MPolynomialIdeal_singular_repr, \ MPolynomialIdeal_macaulay2_repr, \ MPolynomialIdeal_magma_repr, \ Ideal_generic ): """ An ideal of a multivariate polynomial ring. """ def __init__(self, ring, gens, coerce=True): """ Create an ideal in a multivariate polynomial ring. EXAMPLES: sage: R. = PolynomialRing(IntegerRing(), 2, order='lex') sage: R.ideal([x, y]) Ideal (y, x) of Polynomial Ring in x, y over Integer Ring sage: R. = GF(3)[] sage: R.ideal([x0^2, x1^3]) Ideal (x0^2, x1^3) of Polynomial Ring in x0, x1 over Finite Field of size 3 """ Ideal_generic.__init__(self, ring, gens, coerce=coerce) def groebner_fan(self, is_groebner_basis=False, symmetry=None, verbose=False): r""" Return the Groebner fan of this ideal. The base ring must be $\Q$ or a finite field $\F_p$ of with $p \leq 32749$. INPUT: is_groebner_basis -- bool (default False).  if True, then I.gens() must be a Groebner basis with respect to the standard degree lexicographic term order. symmetry -- default: None; if not None, describes symmetries of the ideal verbose -- default: False; if True, printout useful info during computations """ import groebner_fan return groebner_fan.GroebnerFan(self, is_groebner_basis=is_groebner_basis, symmetry=symmetry, verbose=verbose) def groebner_basis(self, algorithm=None): """ Return a Groebner basis of this ideal. INPUT: algorithm -- determines the algorithm to use, available are: * None - autoselect (default) * 'singular:groebner' - Singular's groebner command * 'singular:std' - Singular's std command * 'singular:stdhilb' - Singular's stdhib command * 'singular:stdfglm' - Singular's stdfglm command * 'singular:slimgb' - Singular's slimgb command * 'macaulay2:gb' (if available) - Macaulay2's gb command * 'magma:GroebnerBasis' (if available) - MAGMA's Groebnerbasis command ALGORITHM: Uses Singular, MAGMA, or Macaulay2 (if available) """ if algorithm is None: if self.ring().base_ring() == sage.rings.integer_ring.ZZ: return self._macaulay2_groebner_basis() else: return self._singular_groebner_basis("groebner") elif algorithm.startswith('singular:'): return self._singular_groebner_basis(algorithm[9:]) elif algorithm == 'macaulay2:gb': return self._macaulay2_groebner_basis() elif algorithm == 'magma:GroebnerBasis': return self._magma_groebner_basis() else: raise TypeError, "algorithm '%s' unknown"%algorithm def transformed_basis(self,algorithm="gwalk", other_ring=None): raise TypeError, "Cannot convert basis with given algorithm" class MPolynomialIdeal_macaulay2_repr: """ An ideal in a multivariate polynomial ring, which has an underlying Macaulay2 ring associated to it. EXAMPLES: sage: R. = PolynomialRing(ZZ, 4) # optional sage: I = ideal(x*y-z^2, y^2-w^2)       # optional sage: I                                 # optional Ideal (-1*w^2 + y^2, -1*z^2 + x*y) of Polynomial Ring in x, y, z, w over Integer Ring """ #def __init__(self, ring, gens, coerce=True): #    MPolynomialIdeal.__init__(self, ring, gens, coerce=coerce) def _macaulay2_(self, macaulay2=None): """ Return Macaulay2 ideal corresponding to this ideal. """ if macaulay2 is None: macaulay2 = macaulay2_default try: self.ring()._macaulay2_(macaulay2) I = self.__macaulay2 if not (I.parent() is macaulay2): raise ValueError I._check_valid() return I except (AttributeError, ValueError): self.ring()._macaulay2_(macaulay2) gens = [str(x) for x in self.gens()] if len(gens) == 0: gens = ['0'] self.__macaulay2 = macaulay2.ideal(gens) return self.__macaulay2 def _macaulay2_groebner_basis(self): r""" Return the Groebner basis for this ideal, computed using Macaulay2. ALGORITHM: Computed using Macaulay2.  A big advantage of Macaulay2 is that it can compute Groebner basis of ideals in polynomial rings over the integers. EXAMPLE: sage: R. = PolynomialRing(ZZ, 4) sage: I = ideal(x*y-z^2, y^2-w^2) sage: I.groebner_basis()                                     # optional -- requires macaulay2 [-1*w^2 + y^2, -1*z^2 + x*y, y*z^2 - x*w^2, z^4 - x^2*w^2] Groebner basis can be used to compute in $\Z/n\Z[x,\ldots]$. sage: R. = ZZ[] sage: I = ideal([y^2*z - x^3 - 19*x*z, y^2, 19^2]) sage: I.groebner_basis()                                     # optional -- requires macaulay2 [361, y^2, 19*x*z + x^3] sage: I = ideal([y^2*z - x^3 - 19^2*x*z, y^2, 19^2]) sage: I.groebner_basis()                                     # optional -- requires macaulay2 [361, y^2, x^3] """ try: return self.__groebner_basis except AttributeError: I = self._macaulay2_() G = str(I.gb().generators().str()).replace('\n','') i = G.rfind('{{') j = G.rfind('}}') G = G[i+2:j].split(',') L = self.ring().var_dict() B = [sage_eval(f, L) for f in G] B = Sequence(B, self.ring(), check=False, immutable=True) B.sort() self.__groebner_basis = B return B class MPolynomialIdeal( MPolynomialIdeal_singular_repr, \ MPolynomialIdeal_macaulay2_repr, \ MPolynomialIdeal_magma_repr, \ Ideal_generic ): """ An ideal of a multivariate polynomial ring. """ def __init__(self, ring, gens, coerce=True): """ Create an ideal in a multivariate polynomial ring. EXAMPLES: sage: R. = PolynomialRing(IntegerRing(), 2, order='lex') sage: R.ideal([x, y]) Ideal (y, x) of Polynomial Ring in x, y over Integer Ring sage: R. = GF(3)[] sage: R.ideal([x0^2, x1^3]) Ideal (x0^2, x1^3) of Polynomial Ring in x0, x1 over Finite Field of size 3 """ Ideal_generic.__init__(self, ring, gens, coerce=coerce) def groebner_fan(self, is_groebner_basis=False, symmetry=None, verbose=False): r""" Return the Groebner fan of this ideal. The base ring must be $\Q$ or a finite field $\F_p$ of with $p \leq 32749$. INPUT: is_groebner_basis -- bool (default False).  if True, then I.gens() must be a Groebner basis with respect to the standard degree lexicographic term order. symmetry -- default: None; if not None, describes symmetries of the ideal verbose -- default: False; if True, printout useful info during computations """ import groebner_fan return groebner_fan.GroebnerFan(self, is_groebner_basis=is_groebner_basis, symmetry=symmetry, verbose=verbose) def groebner_basis(self, algorithm=None): """ Return a Groebner basis of this ideal. INPUT: algorithm -- determines the algorithm to use, available are: * None - autoselect (default) * 'singular:groebner' - Singular's groebner command * 'singular:std' - Singular's std command * 'singular:stdhilb' - Singular's stdhib command * 'singular:stdfglm' - Singular's stdfglm command * 'singular:slimgb' - Singular's slimgb command * 'macaulay2:gb' (if available) - Macaulay2's gb command * 'magma:GroebnerBasis' (if available) - MAGMA's Groebnerbasis command ALGORITHM: Uses Singular, MAGMA, or Macaulay2 (if available) """ if algorithm is None: if self.ring().base_ring() == sage.rings.integer_ring.ZZ: return self._macaulay2_groebner_basis() else: return self._singular_groebner_basis("groebner") elif algorithm.startswith('singular:'): return self._singular_groebner_basis(algorithm[9:]) elif algorithm == 'macaulay2:gb': return self._macaulay2_groebner_basis() elif algorithm == 'magma:GroebnerBasis': return self._magma_groebner_basis() else: raise TypeError, "algorithm '%s' unknown"%algorithm