Ticket #12511: 12511-I-pow.fixed.patch

File 12511-I-pow.fixed.patch, 3.3 KB (added by jdemeyer, 15 months ago)

Rebased to sage-5.0.beta4, apply only this

• sage/rings/number_field/number_field_element.pyx

```# 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 from sage.libs.all import pari_gen, pari from sage.libs.pari.gen import PariError from sage.structure.element cimport Element, generic_power_c from sage.structure.element import canonical_coercion QQ = sage.rings.rational_field.QQ ZZ = sage.rings.integer_ring.ZZ (PY_TYPE_CHECK(exp, Integer) or PY_TYPE_CHECK_EXACT(exp, int) or exp in ZZ)): return generic_power_c(base, exp, None) else: cbase, cexp = canonical_coercion(base, exp) if not isinstance(cbase, NumberFieldElement): return cbase ** cexp from sage.symbolic.power_helper import try_symbolic_power return try_symbolic_power(base, exp) try: return try_symbolic_power(base, exp) except ValueError: if isinstance(exp, Rational): # pynac can handle this case return None else: raise cdef void _reduce_c_(self): """
• sage/rings/rational.pyx

`diff --git a/sage/rings/rational.pyx b/sage/rings/rational.pyx`
 a # this is the only sensible answer that avoids rounding and # an infinite recursion. from sage.symbolic.power_helper import try_symbolic_power return try_symbolic_power(self, n) try: return try_symbolic_power(self, n) except ValueError: # pynac recognizes this and holds the value return None if PY_TYPE_CHECK(n, Element): return (n)._parent(self)**n
• sage/symbolic/expression.pyx

`diff --git a/sage/symbolic/expression.pyx b/sage/symbolic/expression.pyx`
 a 2.3^(x^3 - x^2 + 1/3) sage: complex(1,3)^(sqrt(2)) (1+3j)^sqrt(2) Test complex numeric powers:: sage: I^0.5 0.707106781186548 + 0.707106781186547*I sage: (I + 1) ^ (0.5 + I) 0.400667052375828 + 0.365310866736929*I sage: I^I I^I sage: I^x I^x sage: I^(1/2) sqrt(I) sage: I^(2/3) I^(2/3) """ cdef Expression base, nexp
• sage/symbolic/power_helper.pyx

`diff --git a/sage/symbolic/power_helper.pyx b/sage/symbolic/power_helper.pyx`
 a global __pynac_pow if __pynac_pow: __pynac_pow = False return None raise ValueError("recursion") else: try: __pynac_pow = True