Ticket #11139: 11139_alternative.patch

File 11139_alternative.patch, 4.2 KB (added by jdemeyer, 2 years ago)

Alternative patch, apply only this

  • sage/rings/ring.pyx

    # HG changeset patch
    # User Jeroen Demeyer <jdemeyer@cage.ugent.be>
    # Date 1303738393 -7200
    # Node ID 7511eedd5abe347a81a20fa0214b594d388bc37b
    # Parent  222174f7513688d3d429869a83cec4d7304f3433
    Allow rings to define an ideal with an empty list of generators
    
    diff -r 222174f75136 -r 7511eedd5abe sage/rings/ring.pyx
    a b  
    4040 
    4141- David Harvey (2006-10-16): changed :class:`CommutativeAlgebra` to derive from 
    4242  :class:`CommutativeRing` instead of from :class:`Algebra` 
     43 
    4344- David Loeffler (2009-07-09): documentation fixes, added to reference manual 
     45 
    4446""" 
    4547 
    4648#***************************************************************************** 
    47 #       Copyright (C) 2005,2007 William Stein <wstein@gmail.com> 
     49#       Copyright (C) 2005, 2007 William Stein <wstein@gmail.com> 
    4850# 
    4951#  Distributed under the terms of the GNU General Public License (GPL) 
    50 # 
    51 #    This code is distributed in the hope that it will be useful, 
    52 #    but WITHOUT ANY WARRANTY; without even the implied warranty of 
    53 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
    54 #    General Public License for more details. 
    55 # 
    56 #  The full text of the GPL is available at: 
    57 # 
     52#  as published by the Free Software Foundation; either version 2 of 
     53#  the License, or (at your option) any later version. 
    5854#                  http://www.gnu.org/licenses/ 
    5955#***************************************************************************** 
    6056 
     
    315311            Ideal (y^2 + x) of Multivariate Polynomial Ring in x, y over Rational Field 
    316312            sage: R.ideal( [x^3,y^3+x^3] ) 
    317313            Ideal (x^3, x^3 + y^3) of Multivariate Polynomial Ring in x, y over Rational Field 
     314 
     315        TESTS: 
     316 
     317        Make sure that ticket #11139 is fixed:: 
     318 
     319            sage: R.<x> = QQ[] 
     320            sage: R.ideal([]) 
     321            Principal ideal (0) of Univariate Polynomial Ring in x over Rational Field 
     322            sage: R.ideal(()) 
     323            Principal ideal (0) of Univariate Polynomial Ring in x over Rational Field 
     324            sage: R.ideal() 
     325            Principal ideal (0) of Univariate Polynomial Ring in x over Rational Field 
    318326        """ 
    319327        if kwds.has_key('coerce'): 
    320328            coerce = kwds['coerce'] 
     
    323331            coerce = True 
    324332 
    325333        from sage.rings.ideal import Ideal_generic 
    326         if len(args) == 0: 
     334        gens = args 
     335        while isinstance(gens, (list, tuple)) and len(gens) == 1: 
     336            first = gens[0] 
     337            if isinstance(first, Ideal_generic): 
     338                R = first.ring() 
     339                m = self.convert_map_from(R) 
     340                if m is not None: 
     341                    gens = [m(g) for g in first.gens()] 
     342                    coerce = False 
     343                else: 
     344                    m = R.convert_map_from(self) 
     345                    if m is not None: 
     346                        raise NotImplementedError 
     347                    else: 
     348                        raise TypeError 
     349                break 
     350            elif isinstance(first, (list, tuple)): 
     351                gens = first 
     352            else: 
     353                break 
     354 
     355        if len(gens) == 0: 
    327356            gens = [self(0)] 
    328         else: 
    329             gens = args 
    330             while isinstance(gens, (list, tuple, GeneratorType)) and len(gens) == 1: 
    331                 first = gens[0] 
    332                 if isinstance(first, Ideal_generic): 
    333                     R = first.ring() 
    334                     m = self.convert_map_from(R) 
    335                     if m is not None: 
    336                         gens = [m(g) for g in first.gens()] 
    337                         coerce = False 
    338                     else: 
    339                         m = R.convert_map_from(self) 
    340                         if m is not None: 
    341                             raise NotImplementedError 
    342                         else: 
    343                             raise TypeError 
    344                     break 
    345                 elif isinstance(first, (list, tuple, GeneratorType)): 
    346                     gens = first 
    347                 else: 
    348                     break 
     357 
    349358        if coerce: 
    350359            #print [type(g) for g in gens] 
    351360            gens = [self(g) for g in gens]