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

File 12511-I-pow.fixed.patch, 3.3 KB (added by jdemeyer, 4 years 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 b  
    5050from sage.libs.all import pari_gen, pari
    5151from sage.libs.pari.gen import PariError
    5252from sage.structure.element cimport Element, generic_power_c
     53from sage.structure.element import canonical_coercion
    5354
    5455QQ = sage.rings.rational_field.QQ
    5556ZZ = sage.rings.integer_ring.ZZ
     
    16211622            (PY_TYPE_CHECK(exp, Integer) or PY_TYPE_CHECK_EXACT(exp, int) or exp in ZZ)):
    16221623            return generic_power_c(base, exp, None)
    16231624        else:
     1625            cbase, cexp = canonical_coercion(base, exp)
     1626            if not isinstance(cbase, NumberFieldElement):
     1627                return cbase ** cexp
    16241628            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
    16261637
    16271638    cdef void _reduce_c_(self):
    16281639        """
  • sage/rings/rational.pyx

    diff --git a/sage/rings/rational.pyx b/sage/rings/rational.pyx
    a b  
    22622262                # this is the only sensible answer that avoids rounding and
    22632263                # an infinite recursion.
    22642264                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
    22662270
    22672271            if PY_TYPE_CHECK(n, Element):
    22682272                return (<Element>n)._parent(self)**n
  • sage/symbolic/expression.pyx

    diff --git a/sage/symbolic/expression.pyx b/sage/symbolic/expression.pyx
    a b  
    26252625            2.3^(x^3 - x^2 + 1/3)
    26262626            sage: complex(1,3)^(sqrt(2))
    26272627            (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)
    26282643        """
    26292644        cdef Expression base, nexp
    26302645
  • sage/symbolic/power_helper.pyx

    diff --git a/sage/symbolic/power_helper.pyx b/sage/symbolic/power_helper.pyx
    a b  
    1919    global __pynac_pow
    2020    if __pynac_pow:
    2121        __pynac_pow = False
    22         return None
     22        raise ValueError("recursion")
    2323    else:
    2424        try:
    2525            __pynac_pow = True