Ticket #9880: trac_9880_pynac_ordersage_5_10_beta2.patch
File trac_9880_pynac_ordersage_5_10_beta2.patch, 4.7 KB (added by , 8 years ago) 


sage/libs/ginac.pxd
# HG changeset patch # User JeanPierre 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 91 91 GEx rhs() except + 92 92 GEx lhs() except + 93 93 int nops() except + 94 GEx op (int i)except +94 GEx op "sorted_op" (int i) except + 95 95 GEx eval(int level) except + 96 96 GEx evalf(int level, object parent) except + 97 97 GEx conjugate() except + … … 528 528 object (*py_rational_power_parts)(object basis, object exp) 529 529 530 530 py_funcs_struct py_funcs "GiNaC::py_funcs" 531 532 cdef 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 2 2 3 3 from sage.structure.element cimport CommutativeRingElement 4 4 5 6 5 cdef class Expression(CommutativeRingElement): 7 6 cdef GEx _gobj 8 7 cdef Expression coerce_in(self, z) … … 13 12 cpdef bint is_infinity(self) 14 13 cpdef object pyobject(self) 15 14 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 16 17 17 18 cpdef bint is_Expression(x) 18 19 cdef 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 2778 2778 return (<Element>left)._cmp(right) 2779 2779 2780 2780 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) 2782 2856 2783 2857 def __pow__(self, exp, ignored): 2784 2858 """ … … 3997 4071 while itr.is_not_equal(sym_set.end()): 3998 4072 res.append(new_Expression_from_GEx(SR, itr.obj())) 3999 4073 itr.inc() 4074 res.sort(cmp=lambda x,y: cmp(x,y)) 4000 4075 return tuple(res) 4001 4076 4002 4077 def arguments(self):