Ticket #12665: trac_12665.patch

File trac_12665.patch, 1.3 KB (added by mhansen, 9 years ago)
  • sage/symbolic/expression_conversions.py

    # HG changeset patch
    # User Mike Hansen <mhansen@gmail.com>
    # Date 1331707203 25200
    # Node ID 5a1fd656fe5aa957b5d839a0992b1fa6eae59544
    # Parent  8934271cb8daf29820bd9677f099ebeddda10ae8
    #12665: Coercion problem with QQbar
    
    diff --git a/sage/symbolic/expression_conversions.py b/sage/symbolic/expression_conversions.py
    a b  
    749749            0.500000000000000? + 0.866025403784439?*I
    750750            sage: a.composition(sin(pi/5), sin)
    751751            0.5877852522924731? + 0.?e-18*I
     752
     753        TESTS::
     754
     755            sage: QQbar(zeta(7))
     756            Traceback (most recent call last):
     757            ...
     758            TypeError: unable to convert zeta(7) to Algebraic Field
    752759        """
    753760        func = operator
    754761        operand, = ex.operands()
     
    787794            res = ~self.reciprocal_trig_functions[func_name](operand)._algebraic_(QQbar)
    788795        else:
    789796            res = func(operand._algebraic_(self.field))
     797            #We have to handle the case where we get the same symbolic
     798            #expression back.  For example, QQbar(zeta(7)).  See
     799            #ticket #12665.
     800            if cmp(res, ex) == 0:
     801                raise TypeError, "unable to convert %s to %s"%(ex, self.field)
    790802        return self.field(res)
    791803   
    792804def algebraic(ex, field):