Ticket #3927: sage-trac3927.patch

File sage-trac3927.patch, 2.4 kB (added by cremona, 5 months ago)
  • a/sage/structure/element.pyx

    old new  
    12331233     
    12341234 
    12351235    def __invert__(self): 
     1236        if self.is_one(): 
     1237            return self 
    12361238        return 1/self 
    12371239 
    12381240 
     
    15441546        return self 
    15451547 
    15461548    def __invert__(self): 
     1549        if self.is_one(): 
     1550            return self 
    15471551        return 1/self 
    15481552 
    15491553    ################################################## 
  • a/sage/structure/factorization.py

    old new  
    737737 
    738738    def __add__(self, other): 
    739739        """ 
    740         Return the sum of self and other. 
     740        Return the (unfactored) sum of self and other. 
    741741 
    742742        EXAMPLES: 
    743743            sage: factor(-10) + 16 
     
    754754 
    755755    def __sub__(self, other): 
    756756        """ 
    757         Return the sum of self and other. 
     757        Return the (unfactored) difference of self and other. 
    758758 
    759759        EXAMPLES: 
    760760            sage: factor(-10) + 16 
     
    883883        return Factorization([(p,-e) for p,e in reversed(self)], 
    884884            cr=self._cr(), unit=self.unit()**(-1)) 
    885885 
     886    def __div__(self, other): 
     887        r""" 
     888        Return the quotient of two factorizations, which is obtained by 
     889        multiplying the first by the inverse of the second. 
     890 
     891        EXAMPLES: 
     892            sage: factor(-10) / factor(-16) 
     893            2^-3 * 5 
     894            sage: factor(-10) / factor(16) 
     895            -1 * 2^-3 * 5 
     896 
     897            sage: R.<x,y> = FreeAlgebra(QQ, 2) 
     898            sage: F = Factorization([(x,3), (y, 2), (x,1)]); F 
     899            x^3 * y^2 * x 
     900            sage: G = Factorization([(y, 1), (x,1)],1); G 
     901            y * x 
     902            sage: F / G 
     903            x^3 * y 
     904        """ 
     905        if not isinstance(other, Factorization): 
     906            return self / Factorization([(other, 1)]) 
     907        return self * other**-1 
     908 
    886909    def value(self): 
    887910        """ 
    888911        Return the product of the factors in the factorization, multiplied out.