# HG changeset patch
# User Robert Bradshaw <robertwb@math.washington.edu>
# Date 1329294690 28800
# Node ID 77250d51896e3c7e9e1f1ceb630bb8294aafddd4
# Parent a6792a0d86dda4b3139f9a2024c97ebb8f18ae38
Trac 12511: raising I to a power returns "None"
diff git a/sage/rings/number_field/number_field_element.pyx b/sage/rings/number_field/number_field_element.pyx
a

b


50  50  from sage.libs.all import pari_gen, pari 
51  51  from sage.libs.pari.gen import PariError 
52  52  from sage.structure.element cimport Element, generic_power_c 
 53  from sage.structure.element import canonical_coercion 
53  54  
54  55  QQ = sage.rings.rational_field.QQ 
55  56  ZZ = sage.rings.integer_ring.ZZ 
… 
… 

1621  1622  (PY_TYPE_CHECK(exp, Integer) or PY_TYPE_CHECK_EXACT(exp, int) or exp in ZZ)): 
1622  1623  return generic_power_c(base, exp, None) 
1623  1624  else: 
 1625  cbase, cexp = canonical_coercion(base, exp) 
 1626  if not isinstance(cbase, NumberFieldElement): 
 1627  return cbase ** cexp 
1624  1628  from sage.symbolic.power_helper import try_symbolic_power 
1625   return try_symbolic_power(base, exp) 
 1629  try: 
 1630  return try_symbolic_power(base, exp) 
 1631  except ValueError: 
 1632  if isinstance(exp, Rational): 
 1633  # pynac can handle this case 
 1634  return None 
 1635  else: 
 1636  raise 
1626  1637  
1627  1638  cdef void _reduce_c_(self): 
1628  1639  """ 
diff git a/sage/rings/rational.pyx b/sage/rings/rational.pyx
a

b


2262  2262  # this is the only sensible answer that avoids rounding and 
2263  2263  # an infinite recursion. 
2264  2264  from sage.symbolic.power_helper import try_symbolic_power 
2265   return try_symbolic_power(self, n) 
 2265  try: 
 2266  return try_symbolic_power(self, n) 
 2267  except ValueError: 
 2268  # pynac recognizes this and holds the value 
 2269  return None 
2266  2270  
2267  2271  if PY_TYPE_CHECK(n, Element): 
2268  2272  return (<Element>n)._parent(self)**n 
diff git a/sage/symbolic/expression.pyx b/sage/symbolic/expression.pyx
a

b


2625  2625  2.3^(x^3  x^2 + 1/3) 
2626  2626  sage: complex(1,3)^(sqrt(2)) 
2627  2627  (1+3j)^sqrt(2) 
 2628  
 2629  Test complex numeric powers:: 
 2630  
 2631  sage: I^0.5 
 2632  0.707106781186548 + 0.707106781186547*I 
 2633  sage: (I + 1) ^ (0.5 + I) 
 2634  0.400667052375828 + 0.365310866736929*I 
 2635  sage: I^I 
 2636  I^I 
 2637  sage: I^x 
 2638  I^x 
 2639  sage: I^(1/2) 
 2640  sqrt(I) 
 2641  sage: I^(2/3) 
 2642  I^(2/3) 
2628  2643  """ 
2629  2644  cdef Expression base, nexp 
2630  2645  
diff git a/sage/symbolic/power_helper.pyx b/sage/symbolic/power_helper.pyx
a

b


19  19  global __pynac_pow 
20  20  if __pynac_pow: 
21  21  __pynac_pow = False 
22   return None 
 22  raise ValueError("recursion") 
23  23  else: 
24  24  try: 
25  25  __pynac_pow = True 