# HG changeset patch
# User Florent Hivert <Florent.Hivert@univrouen.fr>
# Date 1322130745 3600
# Node ID 48aa1e58caea96e61fd6d79def8e18ae13445dfe
# Parent c93295b96d85921ef6ac14379071ad972cd60cd7
[mq]: trac_12068numer_denom_fixfh.patch
diff git a/sage/symbolic/expression.pyx b/sage/symbolic/expression.pyx
a

b

cdef class Expression(CommutativeRingEle 
6616  6616  ((x + 2)*x^2, 1) 
6617  6617  sage: g.numerator_denominator(normalize=False) 
6618  6618  ((x + 2)*x^2, 1) 
6619   """ 
6620   cdef GExVector vecnum, vecdenom 
 6619  
 6620  TESTS:: 
 6621  
 6622  sage: ((x+y)^2/(xy)^3*x^3).numerator_denominator(normalize=False) 
 6623  ((x + y)^2*x^3, (x  y)^3) 
 6624  sage: ((x+y)^2*x^3).numerator_denominator(normalize=False) 
 6625  ((x + y)^2*x^3, 1) 
 6626  sage: (y/x^3).numerator_denominator(normalize=False) 
 6627  (y, x^3) 
 6628  sage: t = y/x^3/(x+y)^(1/2); t 
 6629  y/(sqrt(x + y)*x^3) 
 6630  sage: t.numerator_denominator(normalize=False) 
 6631  (y, sqrt(x + y)*x^3) 
 6632  sage: (1/x^3).numerator_denominator(normalize=False) 
 6633  (1, x^3) 
 6634  sage: (x^3).numerator_denominator(normalize=False) 
 6635  (x^3, 1) 
 6636  sage: (y*x^sin(x)).numerator_denominator(normalize=False) 
 6637  Traceback (most recent call last): 
 6638  ... 
 6639  TypeError: self is not a rational expression 
 6640  """ 
 6641  cdef GExVector vecnumer, vecdenom 
6621  6642  cdef GEx oper, ex, power 
6622  6643  cdef int py_pow 
 6644  cdef GNumeric power_num 
6623  6645  if normalize: 
6624  6646  ex = self._gobj.numer_denom() 
6625  6647  return (new_Expression_from_GEx(self._parent, ex.op(0)), 
… 
… 
cdef class Expression(CommutativeRingEle 
6632  6654  power = oper.op(1) 
6633  6655  if not is_a_numeric(power): 
6634  6656  raise TypeError, "self is not a rational expression" 
6635   else: 
6636   py_pow = py_object_from_numeric(power) 
6637   if py_pow >= 0: 
6638   vecnum.push_back(oper) 
6639   elif py_pow == 1: 
6640   vecdenom.push_back(ex) 
 6657  elif is_a_numeric(power): 
 6658  power_num = ex_to_numeric(power) 
 6659  if power_num.is_positive(): 
 6660  vecnumer.push_back(oper) 
6641  6661  else: 
6642  6662  vecdenom.push_back(g_pow(ex, g_abs(power))) 
6643  6663  else: 
6644   vecnum.push_back(oper) 
 6664  vecnumer.push_back(oper) 
6645  6665  return (new_Expression_from_GEx(self._parent, 
6646   g_mul_construct(vecnum, False)), 
 6666  g_mul_construct(vecnumer, False)), 
6647  6667  new_Expression_from_GEx(self._parent, 
6648  6668  g_mul_construct(vecdenom, False))) 
 6669  elif is_a_power(self._gobj): 
 6670  power = self._gobj.op(1) 
 6671  if is_a_numeric(power) and ex_to_numeric(power).is_positive(): 
 6672  return (self, self._parent.one()) 
 6673  else: 
 6674  return (self._parent.one(), 
 6675  new_Expression_from_GEx(self._parent, 
 6676  g_pow(self._gobj.op(0), g_abs(power)))) 
6649  6677  else: 
6650  6678  return (self, self._parent.one()) 
6651  6679  