Ticket #9880: trac_9880_pynac_order-sage_5_10_beta2.patch

File trac_9880_pynac_order-sage_5_10_beta2.patch, 4.7 KB (added by burcin, 8 years ago)
  • sage/libs/ginac.pxd

    # HG changeset patch
    # User Jean-Pierre Flori <flori@enst.fr>
    # Date 1298990841 -3600
    # Node ID 7df8578a7485990d3c6dbb49b94c16b352c5781d
    # Parent  e2e213b4648d38681f7ba0e41f895565a152c5cc
    Trac #9880: Give Sage access to the PyNaC printing order
    
    This allows automated doctests to check the PyNaC printing
    sort order.
    
    Use printing order for operands access and comparison of symbolic expressions.
    
    diff --git a/sage/libs/ginac.pxd b/sage/libs/ginac.pxd
    a b  
    9191        GEx rhs()                     except +
    9292        GEx lhs()                     except +
    9393        int nops()                    except +
    94         GEx op(int i)                 except +
     94        GEx op "sorted_op" (int i)    except +
    9595        GEx eval(int level)           except +
    9696        GEx evalf(int level, object parent) except +
    9797        GEx conjugate()               except +
     
    528528        object (*py_rational_power_parts)(object basis, object exp)
    529529
    530530    py_funcs_struct py_funcs "GiNaC::py_funcs"
     531
     532cdef extern from "pynac/order.h":
     533    bint print_order_compare "GiNaC::print_order().compare" \
     534            (GEx left, GEx right) except +
     535    bint print_order_compare_mul "GiNaC::print_order_mul().compare" \
     536            (GEx left, GEx right) except +
     537    bint print_order "GiNaC::print_order()" \
     538            (GEx left, GEx right) except +
     539    bint print_order_mul "GiNaC::print_order_mul()" \
     540            (GEx left, GEx right) except +
  • sage/symbolic/expression.pxd

    diff --git a/sage/symbolic/expression.pxd b/sage/symbolic/expression.pxd
    a b  
    22
    33from sage.structure.element cimport CommutativeRingElement
    44
    5 
    65cdef class Expression(CommutativeRingElement):
    76    cdef GEx _gobj
    87    cdef Expression coerce_in(self, z)
     
    1312    cpdef bint is_infinity(self)
    1413    cpdef object pyobject(self)
    1514    cpdef Expression _subs_expr(self, expr)
     15    cpdef int _cmp_add(Expression left, Expression right) except -2
     16    cpdef int _cmp_mul(Expression left, Expression right) except -2
    1617   
    1718cpdef bint is_Expression(x)
    1819cdef Expression new_Expression_from_GEx(parent, GEx juice)
  • sage/symbolic/expression.pyx

    diff --git a/sage/symbolic/expression.pyx b/sage/symbolic/expression.pyx
    a b  
    27782778        return (<Element>left)._cmp(right)
    27792779
    27802780    cdef int _cmp_c_impl(left, Element right) except -2:
    2781         return left._gobj.compare((<Expression>right)._gobj)
     2781        """
     2782        Compare ``left`` and ``right``.
     2783
     2784        INPUT:
     2785
     2786        - ``right`` -- A :class:`Expression` instance.
     2787
     2788        OUTPUT:
     2789
     2790        Boolean.
     2791
     2792        EXAMPLES::
     2793
     2794            sage: a = sqrt(3)
     2795            sage: b = x^2+1
     2796            sage: a.__cmp__(b)   # indirect doctest
     2797            -1
     2798        """
     2799        return print_order_compare(left._gobj, (<Expression>right)._gobj)
     2800
     2801    cpdef int _cmp_add(Expression left, Expression right) except -2:
     2802        """
     2803        Compare ``left`` and ``right`` in the print order.
     2804
     2805        INPUT:
     2806
     2807        - ``right`` -- A :class:`Expression` instance.
     2808
     2809        OUTPUT:
     2810
     2811        Boolean.
     2812
     2813        EXAMPLES::
     2814
     2815            sage: a = sqrt(3)
     2816            sage: b = x^2+1
     2817            sage: a._cmp_add(b)
     2818            -1
     2819            sage: b._cmp_add(a)
     2820            1
     2821            sage: b._cmp_add(1)
     2822            Traceback (most recent call last):
     2823            ...
     2824            TypeError: Argument 'right' has incorrect type (expected
     2825            sage.symbolic.expression.Expression, got sage.rings.integer.Integer)
     2826        """
     2827        return print_order_compare(left._gobj, right._gobj)
     2828
     2829    cpdef int _cmp_mul(Expression left, Expression right) except -2:
     2830        """
     2831        Compare ``left`` and ``right`` in the print order for products.
     2832
     2833        INPUT:
     2834
     2835        - ``right`` -- A :class:`Expression` instance.
     2836
     2837        OUTPUT:
     2838
     2839        Boolean.
     2840
     2841        EXAMPLES::
     2842
     2843            sage: a = sqrt(3)
     2844            sage: b = x^2+1
     2845            sage: a._cmp_mul(b)
     2846            -1
     2847            sage: b._cmp_mul(a)
     2848            1
     2849            sage: b._cmp_mul(1)
     2850            Traceback (most recent call last):
     2851            ...
     2852            TypeError: Argument 'right' has incorrect type (expected
     2853            sage.symbolic.expression.Expression, got sage.rings.integer.Integer)
     2854        """
     2855        return print_order_compare_mul(left._gobj, right._gobj)
    27822856
    27832857    def __pow__(self, exp, ignored):
    27842858        """
     
    39974071        while itr.is_not_equal(sym_set.end()):
    39984072            res.append(new_Expression_from_GEx(SR, itr.obj()))
    39994073            itr.inc()
     4074        res.sort(cmp=lambda x,y: -cmp(x,y))
    40004075        return tuple(res)
    40014076
    40024077    def arguments(self):