Changeset 2780:42946f8405f4
- Timestamp:
- 02/05/07 23:10:29 (6 years ago)
- Branch:
- default
- Children:
- 2781:66859ef2393c, 2896:182f6837300c
- File:
-
- 1 edited
-
sage/rings/multi_polynomial_ideal.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sage/rings/multi_polynomial_ideal.py
r2485 r2780 558 558 s.option("redSB") 559 559 R = self.ring() 560 ret = [ R(f) for f in self._singular_().interred() ] 560 ret = Sequence([ R(f) for f in self._singular_().interred() ], R, 561 check=False, immutable=True) 561 562 s.option("set",o) 562 563 return ret 563 564 564 def is_groebner(self):565 def basis_is_groebner(self): 565 566 """ 566 567 Returns true if self.gens() form a Groebner Basis. This is done by … … 574 575 sage: R.<a,b,c,d,e,f,g,h,i,j> = PolynomialRing(GF(127),10) 575 576 sage: I = sage.rings.ideal.Cyclic(R,4) 576 sage: I. is_groebner()577 sage: I.basis_is_groebner() 577 578 False 578 579 sage: I2 = Ideal(I.groebner_basis()) 579 sage: I2. is_groebner()580 sage: I2.basis_is_groebner() 580 581 True 581 582 … … 601 602 return False 602 603 return True 603 604 class MPolynomialIdeal_macaulay2_repr:605 """606 An ideal in a multivariate polynomial ring, which has an underlying607 Macaulay2 ring associated to it.608 609 EXAMPLES:610 sage: R.<x,y,z,w> = PolynomialRing(ZZ, 4) # optional611 sage: I = ideal(x*y-z^2, y^2-w^2) # optional612 sage: I # optional613 Ideal (-1*w^2 + y^2, -1*z^2 + x*y) of Polynomial Ring in x, y, z, w over Integer Ring614 """615 #def __init__(self, ring, gens, coerce=True):616 # MPolynomialIdeal.__init__(self, ring, gens, coerce=coerce)617 618 def _macaulay2_(self, macaulay2=None):619 """620 Return Macaulay2 ideal corresponding to this ideal.621 """622 if macaulay2 is None: macaulay2 = macaulay2_default623 try:624 self.ring()._macaulay2_(macaulay2)625 I = self.__macaulay2626 if not (I.parent() is macaulay2):627 raise ValueError628 I._check_valid()629 return I630 except (AttributeError, ValueError):631 self.ring()._macaulay2_(macaulay2)632 gens = [str(x) for x in self.gens()]633 if len(gens) == 0:634 gens = ['0']635 self.__macaulay2 = macaulay2.ideal(gens)636 return self.__macaulay2637 638 def _macaulay2_groebner_basis(self):639 r"""640 Return the Groebner basis for this ideal, computed using Macaulay2.641 642 ALGORITHM: Computed using Macaulay2. A big advantage of643 Macaulay2 is that it can compute Groebner basis of ideals in644 polynomial rings over the integers.645 646 EXAMPLE:647 sage: R.<x,y,z,w> = PolynomialRing(ZZ, 4)648 sage: I = ideal(x*y-z^2, y^2-w^2)649 sage: I.groebner_basis() # optional -- requires macaulay2650 [-1*w^2 + y^2, -1*z^2 + x*y, y*z^2 - x*w^2, z^4 - x^2*w^2]651 652 Groebner basis can be used to compute in $\Z/n\Z[x,\ldots]$.653 654 sage: R.<x,y,z> = ZZ[]655 sage: I = ideal([y^2*z - x^3 - 19*x*z, y^2, 19^2])656 sage: I.groebner_basis() # optional -- requires macaulay2657 [361, y^2, 19*x*z + x^3]658 sage: I = ideal([y^2*z - x^3 - 19^2*x*z, y^2, 19^2])659 sage: I.groebner_basis() # optional -- requires macaulay2660 [361, y^2, x^3]661 """662 try:663 return self.__groebner_basis664 except AttributeError:665 I = self._macaulay2_()666 G = str(I.gb().generators().str()).replace('\n','')667 i = G.rfind('{{')668 j = G.rfind('}}')669 G = G[i+2:j].split(',')670 L = self.ring().var_dict()671 B = [sage_eval(f, L) for f in G]672 B = Sequence(B, self.ring(), check=False, immutable=True)673 B.sort()674 self.__groebner_basis = B675 return B676 677 678 679 class MPolynomialIdeal( MPolynomialIdeal_singular_repr, \680 MPolynomialIdeal_macaulay2_repr, \681 MPolynomialIdeal_magma_repr, \682 Ideal_generic ):683 """684 An ideal of a multivariate polynomial ring.685 """686 def __init__(self, ring, gens, coerce=True):687 """688 Create an ideal in a multivariate polynomial ring.689 690 EXAMPLES:691 sage: R.<x,y> = PolynomialRing(IntegerRing(), 2, order='lex')692 sage: R.ideal([x, y])693 Ideal (y, x) of Polynomial Ring in x, y over Integer Ring694 sage: R.<x0,x1> = GF(3)[]695 sage: R.ideal([x0^2, x1^3])696 Ideal (x0^2, x1^3) of Polynomial Ring in x0, x1 over Finite Field of size 3697 """698 Ideal_generic.__init__(self, ring, gens, coerce=coerce)699 700 def groebner_fan(self, is_groebner_basis=False, symmetry=None, verbose=False):701 r"""702 Return the Groebner fan of this ideal.703 704 The base ring must be $\Q$ or a finite field $\F_p$ of with705 $p \leq 32749$.706 707 INPUT:708 is_groebner_basis -- bool (default False). if True, then I.gens() must be709 a Groebner basis with respect to the standard710 degree lexicographic term order.711 symmetry -- default: None; if not None, describes symmetries of the ideal712 verbose -- default: False; if True, printout useful info during computations713 """714 import groebner_fan715 return groebner_fan.GroebnerFan(self, is_groebner_basis=is_groebner_basis,716 symmetry=symmetry, verbose=verbose)717 718 def groebner_basis(self, algorithm=None):719 """720 Return a Groebner basis of this ideal.721 722 INPUT:723 algorithm -- determines the algorithm to use, available are:724 * None - autoselect (default)725 * 'singular:groebner' - Singular's groebner command726 * 'singular:std' - Singular's std command727 * 'singular:stdhilb' - Singular's stdhib command728 * 'singular:stdfglm' - Singular's stdfglm command729 * 'singular:slimgb' - Singular's slimgb command730 * 'macaulay2:gb' (if available) - Macaulay2's gb command731 * 'magma:GroebnerBasis' (if available) - MAGMA's Groebnerbasis command732 733 ALGORITHM: Uses Singular, MAGMA, or Macaulay2 (if available)734 735 """736 if algorithm is None:737 if self.ring().base_ring() == sage.rings.integer_ring.ZZ:738 return self._macaulay2_groebner_basis()739 else:740 return self._singular_groebner_basis("groebner")741 elif algorithm.startswith('singular:'):742 return self._singular_groebner_basis(algorithm[9:])743 elif algorithm == 'macaulay2:gb':744 return self._macaulay2_groebner_basis()745 elif algorithm == 'magma:GroebnerBasis':746 return self._magma_groebner_basis()747 else:748 raise TypeError, "algorithm '%s' unknown"%algorithm749 604 750 605 def transformed_basis(self,algorithm="gwalk", other_ring=None): … … 814 669 raise TypeError, "Cannot convert basis with given algorithm" 815 670 671 672 class MPolynomialIdeal_macaulay2_repr: 673 """ 674 An ideal in a multivariate polynomial ring, which has an underlying 675 Macaulay2 ring associated to it. 676 677 EXAMPLES: 678 sage: R.<x,y,z,w> = PolynomialRing(ZZ, 4) # optional 679 sage: I = ideal(x*y-z^2, y^2-w^2) # optional 680 sage: I # optional 681 Ideal (-1*w^2 + y^2, -1*z^2 + x*y) of Polynomial Ring in x, y, z, w over Integer Ring 682 """ 683 #def __init__(self, ring, gens, coerce=True): 684 # MPolynomialIdeal.__init__(self, ring, gens, coerce=coerce) 685 686 def _macaulay2_(self, macaulay2=None): 687 """ 688 Return Macaulay2 ideal corresponding to this ideal. 689 """ 690 if macaulay2 is None: macaulay2 = macaulay2_default 691 try: 692 self.ring()._macaulay2_(macaulay2) 693 I = self.__macaulay2 694 if not (I.parent() is macaulay2): 695 raise ValueError 696 I._check_valid() 697 return I 698 except (AttributeError, ValueError): 699 self.ring()._macaulay2_(macaulay2) 700 gens = [str(x) for x in self.gens()] 701 if len(gens) == 0: 702 gens = ['0'] 703 self.__macaulay2 = macaulay2.ideal(gens) 704 return self.__macaulay2 705 706 def _macaulay2_groebner_basis(self): 707 r""" 708 Return the Groebner basis for this ideal, computed using Macaulay2. 709 710 ALGORITHM: Computed using Macaulay2. A big advantage of 711 Macaulay2 is that it can compute Groebner basis of ideals in 712 polynomial rings over the integers. 713 714 EXAMPLE: 715 sage: R.<x,y,z,w> = PolynomialRing(ZZ, 4) 716 sage: I = ideal(x*y-z^2, y^2-w^2) 717 sage: I.groebner_basis() # optional -- requires macaulay2 718 [-1*w^2 + y^2, -1*z^2 + x*y, y*z^2 - x*w^2, z^4 - x^2*w^2] 719 720 Groebner basis can be used to compute in $\Z/n\Z[x,\ldots]$. 721 722 sage: R.<x,y,z> = ZZ[] 723 sage: I = ideal([y^2*z - x^3 - 19*x*z, y^2, 19^2]) 724 sage: I.groebner_basis() # optional -- requires macaulay2 725 [361, y^2, 19*x*z + x^3] 726 sage: I = ideal([y^2*z - x^3 - 19^2*x*z, y^2, 19^2]) 727 sage: I.groebner_basis() # optional -- requires macaulay2 728 [361, y^2, x^3] 729 """ 730 try: 731 return self.__groebner_basis 732 except AttributeError: 733 I = self._macaulay2_() 734 G = str(I.gb().generators().str()).replace('\n','') 735 i = G.rfind('{{') 736 j = G.rfind('}}') 737 G = G[i+2:j].split(',') 738 L = self.ring().var_dict() 739 B = [sage_eval(f, L) for f in G] 740 B = Sequence(B, self.ring(), check=False, immutable=True) 741 B.sort() 742 self.__groebner_basis = B 743 return B 744 745 746 747 class MPolynomialIdeal( MPolynomialIdeal_singular_repr, \ 748 MPolynomialIdeal_macaulay2_repr, \ 749 MPolynomialIdeal_magma_repr, \ 750 Ideal_generic ): 751 """ 752 An ideal of a multivariate polynomial ring. 753 """ 754 def __init__(self, ring, gens, coerce=True): 755 """ 756 Create an ideal in a multivariate polynomial ring. 757 758 EXAMPLES: 759 sage: R.<x,y> = PolynomialRing(IntegerRing(), 2, order='lex') 760 sage: R.ideal([x, y]) 761 Ideal (y, x) of Polynomial Ring in x, y over Integer Ring 762 sage: R.<x0,x1> = GF(3)[] 763 sage: R.ideal([x0^2, x1^3]) 764 Ideal (x0^2, x1^3) of Polynomial Ring in x0, x1 over Finite Field of size 3 765 """ 766 Ideal_generic.__init__(self, ring, gens, coerce=coerce) 767 768 def groebner_fan(self, is_groebner_basis=False, symmetry=None, verbose=False): 769 r""" 770 Return the Groebner fan of this ideal. 771 772 The base ring must be $\Q$ or a finite field $\F_p$ of with 773 $p \leq 32749$. 774 775 INPUT: 776 is_groebner_basis -- bool (default False). if True, then I.gens() must be 777 a Groebner basis with respect to the standard 778 degree lexicographic term order. 779 symmetry -- default: None; if not None, describes symmetries of the ideal 780 verbose -- default: False; if True, printout useful info during computations 781 """ 782 import groebner_fan 783 return groebner_fan.GroebnerFan(self, is_groebner_basis=is_groebner_basis, 784 symmetry=symmetry, verbose=verbose) 785 786 def groebner_basis(self, algorithm=None): 787 """ 788 Return a Groebner basis of this ideal. 789 790 INPUT: 791 algorithm -- determines the algorithm to use, available are: 792 * None - autoselect (default) 793 * 'singular:groebner' - Singular's groebner command 794 * 'singular:std' - Singular's std command 795 * 'singular:stdhilb' - Singular's stdhib command 796 * 'singular:stdfglm' - Singular's stdfglm command 797 * 'singular:slimgb' - Singular's slimgb command 798 * 'macaulay2:gb' (if available) - Macaulay2's gb command 799 * 'magma:GroebnerBasis' (if available) - MAGMA's Groebnerbasis command 800 801 ALGORITHM: Uses Singular, MAGMA, or Macaulay2 (if available) 802 803 """ 804 if algorithm is None: 805 if self.ring().base_ring() == sage.rings.integer_ring.ZZ: 806 return self._macaulay2_groebner_basis() 807 else: 808 return self._singular_groebner_basis("groebner") 809 elif algorithm.startswith('singular:'): 810 return self._singular_groebner_basis(algorithm[9:]) 811 elif algorithm == 'macaulay2:gb': 812 return self._macaulay2_groebner_basis() 813 elif algorithm == 'magma:GroebnerBasis': 814 return self._magma_groebner_basis() 815 else: 816 raise TypeError, "algorithm '%s' unknown"%algorithm 817
Note: See TracChangeset
for help on using the changeset viewer.
