Ticket #9880: trac_9880-fix_comparison.patch

File trac_9880-fix_comparison.patch, 3.5 KB (added by vbraun, 10 years ago)

Initial patch

  • sage/symbolic/expression.pxd

    # HG changeset patch
    # User Volker Braun <vbraun@stp.dias.ie>
    # Date 1308337530 25200
    # Node ID 3bc29f0e04a9d57031640ff4e6a2d433b5b28c9c
    # Parent  5cf0f514731031a8ae754415e7c393170b72f268
    Trac #9880: Fix for the x._cmp_add(1) crash.
    
    diff --git a/sage/symbolic/expression.pxd b/sage/symbolic/expression.pxd
    a b  
    1212    cpdef bint is_infinity(self)
    1313    cpdef object pyobject(self)
    1414    cpdef Expression _subs_expr(self, expr)
    15     cpdef int _cmp_add(left, CommutativeRingElement right) except -2
    16     cpdef int _cmp_mul(left, CommutativeRingElement right) except -2
     15    cpdef int _cmp_add(Expression left, Expression right) except -2
     16    cpdef int _cmp_mul(Expression left, Expression right) except -2
    1717   
    1818cdef Expression new_Expression_from_GEx(parent, GEx juice)
    1919cdef Expression new_Expression_from_pyobject(parent, x)
  • sage/symbolic/expression.pyx

    diff --git a/sage/symbolic/expression.pyx b/sage/symbolic/expression.pyx
    a b  
    25882588        return (<Element>left)._cmp(right)
    25892589
    25902590    cdef int _cmp_c_impl(left, Element right) except -2:
    2591         return -print_order_compare((<Expression>right)._gobj,left._gobj)
    2592 
    2593     cpdef int _cmp_add(left, CommutativeRingElement right) except -2:
    2594         return print_order(left._gobj,(<Expression>right)._gobj)
    2595 
    2596     cpdef int _cmp_mul(left, CommutativeRingElement right) except -2:
    2597         return print_order_mul(left._gobj,(<Expression>right)._gobj)
     2591        """
     2592        Compare ``left`` and ``right``.
     2593
     2594        INPUT:
     2595
     2596        - ``right`` -- A :class:`Expression` instance.
     2597
     2598        OUTPUT:
     2599
     2600        Boolean.
     2601
     2602        EXAMPLES::
     2603
     2604            sage: a = sqrt(3)
     2605            sage: b = x^2+1
     2606            sage: a.__cmp__(b)   # indirect doctest
     2607            -1
     2608        """
     2609        return -print_order_compare((<Expression>right)._gobj, left._gobj)
     2610
     2611    cpdef int _cmp_add(Expression left, Expression right) except -2:
     2612        """
     2613        Compare ``left`` and ``right`` in the print order.
     2614
     2615        INPUT:
     2616
     2617        - ``right`` -- A :class:`Expression` instance.
     2618
     2619        OUTPUT:
     2620
     2621        Boolean.
     2622
     2623        EXAMPLES::
     2624
     2625            sage: a = sqrt(3)
     2626            sage: b = x^2+1
     2627            sage: a._cmp_add(b)
     2628            -1
     2629            sage: b._cmp_add(a)
     2630            1
     2631            sage: b._cmp_add(1)
     2632            Traceback (most recent call last):
     2633            ...
     2634            TypeError: Argument 'right' has incorrect type (expected
     2635            sage.symbolic.expression.Expression, got sage.rings.integer.Integer)
     2636        """
     2637        return print_order(left._gobj, right._gobj)
     2638
     2639    cpdef int _cmp_mul(Expression left, Expression right) except -2:
     2640        """
     2641        Compare ``left`` and ``right`` in the print order for products.
     2642
     2643        INPUT:
     2644
     2645        - ``right`` -- A :class:`Expression` instance.
     2646
     2647        OUTPUT:
     2648
     2649        Boolean.
     2650
     2651        EXAMPLES::
     2652
     2653            sage: a = sqrt(3)
     2654            sage: b = x^2+1
     2655            sage: a._cmp_mul(b)
     2656            -1
     2657            sage: b._cmp_mul(a)
     2658            1
     2659            sage: b._cmp_mul(1)
     2660            Traceback (most recent call last):
     2661            ...
     2662            TypeError: Argument 'right' has incorrect type (expected
     2663            sage.symbolic.expression.Expression, got sage.rings.integer.Integer)
     2664        """
     2665        return print_order_mul(left._gobj, right._gobj)
    25982666
    25992667    def __pow__(self, exp, ignored):
    26002668        """