# HG changeset patch
# User Marco Streng
# Date 1297424101 0
# Node ID e73c3a56dfc7e8b926b914e6289c8d8f6d00756f
# Parent b995f0056e8f09421b141a642b0ef312807befd1
Trac 10772: 0**0 = 1 for number fields, matrices, and more
diff -r b995f0056e8f -r e73c3a56dfc7 sage/matrix/matrix0.pyx
--- a/sage/matrix/matrix0.pyx Mon Feb 07 12:25:34 2011 +0000
+++ b/sage/matrix/matrix0.pyx Fri Feb 11 11:35:01 2011 +0000
@@ -4105,6 +4105,20 @@
[ -3/11 -13/121 1436/1331]
[ 127/121 -337/1331 -4445/14641]
[ -13/121 1436/1331 -8015/14641]
+
+ Sage follows Python's convention 0^0 = 1, as each of the following
+ examples show::
+
+ sage: a = Matrix([[1,0],[0,0]]); a
+ [1 0]
+ [0 0]
+ sage: a^0 # lower right entry is 0^0
+ [1 0]
+ [0 1]
+ sage: Matrix([[0]])^0
+ [1]
+ sage: 0^0
+ 1
"""
if not self.is_square():
raise ArithmeticError("self must be a square matrix")
diff -r b995f0056e8f -r e73c3a56dfc7 sage/rings/number_field/number_field.py
--- a/sage/rings/number_field/number_field.py Mon Feb 07 12:25:34 2011 +0000
+++ b/sage/rings/number_field/number_field.py Fri Feb 11 11:35:01 2011 +0000
@@ -6129,6 +6129,19 @@
sage: L.base_field().base_field()
Rational Field
+ sage: L = K.relativize(K(0), 'a'); L
+ Number Field in a0 with defining polynomial x^4 + 2*x^2 + 2 over its base field
+ sage: L.base_field()
+ Number Field in a1 with defining polynomial x
+ sage: L.base_field().base_field()
+ Rational Field
+
+ We can relativize over morphisms returned by self.subfields()::
+
+ sage: L = NumberField(x^4 + 1, 'a')
+ sage: [L.relativize(h, 'c') for (f,h,i) in L.subfields()]
+ [Number Field in c0 with defining polynomial x^4 + 1 over its base field, Number Field in c0 with defining polynomial x^2 - 1/2*a1 over its base field, Number Field in c0 with defining polynomial x^2 - a2*x - 1 over its base field, Number Field in c0 with defining polynomial x^2 - a3*x + 1 over its base field, Number Field in c0 with defining polynomial x - a4 over its base field]
+
We can relativize over a relative field::
sage: K. = CyclotomicField(16)
diff -r b995f0056e8f -r e73c3a56dfc7 sage/rings/number_field/number_field_element.pyx
--- a/sage/rings/number_field/number_field_element.pyx Mon Feb 07 12:25:34 2011 +0000
+++ b/sage/rings/number_field/number_field_element.pyx Fri Feb 11 11:35:01 2011 +0000
@@ -1257,6 +1257,13 @@
sage: sqrt2^sqrt2
2^(1/2*sqrt(2))
+ Sage follows Python's convention 0^0 = 1::
+
+ sage: a = K(0)^0; a
+ 1
+ sage: a.parent()
+ Number Field in sqrt2 with defining polynomial x^2 - 2
+
TESTS::
sage: 2^I
diff -r b995f0056e8f -r e73c3a56dfc7 sage/rings/polynomial/polydict.pyx
--- a/sage/rings/polynomial/polydict.pyx Mon Feb 07 12:25:34 2011 +0000
+++ b/sage/rings/polynomial/polydict.pyx Fri Feb 11 11:35:01 2011 +0000
@@ -722,9 +722,7 @@
sage: f**0
PolyDict with representation {(0, 0): 1}
sage: (f-f)**0
- Traceback (most recent call last):
- ...
- ArithmeticError: 0^0 is undefined.
+ PolyDict with representation {0: 1}
"""
return generic_power(self, n, self.__one())
diff -r b995f0056e8f -r e73c3a56dfc7 sage/structure/element.pyx
--- a/sage/structure/element.pyx Mon Feb 07 12:25:34 2011 +0000
+++ b/sage/structure/element.pyx Fri Feb 11 11:35:01 2011 +0000
@@ -2888,15 +2888,7 @@
except TypeError:
raise NotImplementedError, "non-integral exponents not supported"
- # It's better to test first the equality to zero of the exponent. Indeed,
- # the following tests tree allows us be sure that "non a" is never called
- # if n is not 0, so that we can deals with this particular case before
- # calling generic_power. It is needed to handle the case of semi-groups
- # (without unit) where "not a" does not makes sense and there is no one to
- # return when n is 0.
if not n:
- if not a:
- raise ArithmeticError, "0^0 is undefined."
if one is None:
if PY_TYPE_CHECK(a, Element):
return (a)._parent(1)