Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit 0807787

Browse files
committed
Revert "Trac #25218: NumberField attempts to evaluate fractional powers"
This reverts commit 75a46a0.
1 parent 3aae21d commit 0807787

File tree

1 file changed

+25
-38
lines changed

1 file changed

+25
-38
lines changed

src/sage/rings/number_field/number_field_element.pyx

+25-38
Original file line numberDiff line numberDiff line change
@@ -2295,12 +2295,8 @@ cdef class NumberFieldElement(FieldElement):
22952295
sage: (1+sqrt2)^-1
22962296
sqrt2 - 1
22972297
2298-
If the exponent is not integral, attempt this operation in the NumberField:
2299-
2300-
sage: K(2)^(1/2)
2301-
sqrt2
2302-
2303-
If this fails, perform this operation in the symbolic ring::
2298+
If the exponent is not integral, perform this operation in
2299+
the symbolic ring::
23042300
23052301
sage: sqrt2^(1/5)
23062302
2^(1/10)
@@ -2332,39 +2328,30 @@ cdef class NumberFieldElement(FieldElement):
23322328
"""
23332329
if (isinstance(base, NumberFieldElement) and
23342330
(isinstance(exp, Integer) or type(exp) is int or exp in ZZ)):
2335-
return generic_power_c(base, exp)
2336-
2337-
if (isinstance(base, NumberFieldElement) and exp in QQ):
2338-
qqexp=QQ(exp)
2339-
n = qqexp.numerator()
2340-
d = qqexp.denominator()
2341-
try:
2342-
return base.nth_root(d)**n
2343-
except ValueError:
2344-
pass
2345-
2346-
cbase, cexp = canonical_coercion(base, exp)
2347-
if not isinstance(cbase, NumberFieldElement):
2348-
return cbase ** cexp
2349-
# Return a symbolic expression.
2350-
# We use the hold=True keyword argument to prevent the
2351-
# symbolics library from trying to simplify this expression
2352-
# again. This would lead to infinite loops otherwise.
2353-
from sage.symbolic.ring import SR
2354-
try:
2355-
res = QQ(base)**QQ(exp)
2356-
except TypeError:
2357-
pass
2331+
return generic_power(base, exp)
23582332
else:
2359-
if res.parent() is not SR:
2360-
return parent(cbase)(res)
2361-
return res
2362-
sbase = SR(base)
2363-
if sbase.operator() is operator.pow:
2364-
nbase, pexp = sbase.operands()
2365-
return nbase.power(pexp * exp, hold=True)
2366-
else:
2367-
return sbase.power(exp, hold=True)
2333+
cbase, cexp = canonical_coercion(base, exp)
2334+
if not isinstance(cbase, NumberFieldElement):
2335+
return cbase ** cexp
2336+
# Return a symbolic expression.
2337+
# We use the hold=True keyword argument to prevent the
2338+
# symbolics library from trying to simplify this expression
2339+
# again. This would lead to infinite loops otherwise.
2340+
from sage.symbolic.ring import SR
2341+
try:
2342+
res = QQ(base)**QQ(exp)
2343+
except TypeError:
2344+
pass
2345+
else:
2346+
if res.parent() is not SR:
2347+
return parent(cbase)(res)
2348+
return res
2349+
sbase = SR(base)
2350+
if sbase.operator() is operator.pow:
2351+
nbase, pexp = sbase.operands()
2352+
return nbase.power(pexp * exp, hold=True)
2353+
else:
2354+
return sbase.power(exp, hold=True)
23682355

23692356
cdef void _reduce_c_(self):
23702357
"""

0 commit comments

Comments
 (0)