# HG changeset patch
# User Marco Streng <marco.streng@gmail.com>
# 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
|
b
|
|
4105 | 4105 | [ -3/11 -13/121 1436/1331] |
4106 | 4106 | [ 127/121 -337/1331 -4445/14641] |
4107 | 4107 | [ -13/121 1436/1331 -8015/14641] |
| 4108 | |
| 4109 | Sage follows Python's convention 0^0 = 1, as each of the following |
| 4110 | examples show:: |
| 4111 | |
| 4112 | sage: a = Matrix([[1,0],[0,0]]); a |
| 4113 | [1 0] |
| 4114 | [0 0] |
| 4115 | sage: a^0 # lower right entry is 0^0 |
| 4116 | [1 0] |
| 4117 | [0 1] |
| 4118 | sage: Matrix([[0]])^0 |
| 4119 | [1] |
| 4120 | sage: 0^0 |
| 4121 | 1 |
4108 | 4122 | """ |
4109 | 4123 | if not self.is_square(): |
4110 | 4124 | raise ArithmeticError("self must be a square matrix") |
diff -r b995f0056e8f -r e73c3a56dfc7 sage/rings/number_field/number_field.py
a
|
b
|
|
6129 | 6129 | sage: L.base_field().base_field() |
6130 | 6130 | Rational Field |
6131 | 6131 | |
| 6132 | sage: L = K.relativize(K(0), 'a'); L |
| 6133 | Number Field in a0 with defining polynomial x^4 + 2*x^2 + 2 over its base field |
| 6134 | sage: L.base_field() |
| 6135 | Number Field in a1 with defining polynomial x |
| 6136 | sage: L.base_field().base_field() |
| 6137 | Rational Field |
| 6138 | |
| 6139 | We can relativize over morphisms returned by self.subfields():: |
| 6140 | |
| 6141 | sage: L = NumberField(x^4 + 1, 'a') |
| 6142 | sage: [L.relativize(h, 'c') for (f,h,i) in L.subfields()] |
| 6143 | [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] |
| 6144 | |
6132 | 6145 | We can relativize over a relative field:: |
6133 | 6146 | |
6134 | 6147 | sage: K.<z> = CyclotomicField(16) |
diff -r b995f0056e8f -r e73c3a56dfc7 sage/rings/number_field/number_field_element.pyx
a
|
b
|
|
1257 | 1257 | sage: sqrt2^sqrt2 |
1258 | 1258 | 2^(1/2*sqrt(2)) |
1259 | 1259 | |
| 1260 | Sage follows Python's convention 0^0 = 1:: |
| 1261 | |
| 1262 | sage: a = K(0)^0; a |
| 1263 | 1 |
| 1264 | sage: a.parent() |
| 1265 | Number Field in sqrt2 with defining polynomial x^2 - 2 |
| 1266 | |
1260 | 1267 | TESTS:: |
1261 | 1268 | |
1262 | 1269 | sage: 2^I |
diff -r b995f0056e8f -r e73c3a56dfc7 sage/rings/polynomial/polydict.pyx
a
|
b
|
|
722 | 722 | sage: f**0 |
723 | 723 | PolyDict with representation {(0, 0): 1} |
724 | 724 | sage: (f-f)**0 |
725 | | Traceback (most recent call last): |
726 | | ... |
727 | | ArithmeticError: 0^0 is undefined. |
| 725 | PolyDict with representation {0: 1} |
728 | 726 | """ |
729 | 727 | return generic_power(self, n, self.__one()) |
730 | 728 | |
diff -r b995f0056e8f -r e73c3a56dfc7 sage/structure/element.pyx
a
|
b
|
|
2888 | 2888 | except TypeError: |
2889 | 2889 | raise NotImplementedError, "non-integral exponents not supported" |
2890 | 2890 | |
2891 | | # It's better to test first the equality to zero of the exponent. Indeed, |
2892 | | # the following tests tree allows us be sure that "non a" is never called |
2893 | | # if n is not 0, so that we can deals with this particular case before |
2894 | | # calling generic_power. It is needed to handle the case of semi-groups |
2895 | | # (without unit) where "not a" does not makes sense and there is no one to |
2896 | | # return when n is 0. |
2897 | 2891 | if not n: |
2898 | | if not a: |
2899 | | raise ArithmeticError, "0^0 is undefined." |
2900 | 2892 | if one is None: |
2901 | 2893 | if PY_TYPE_CHECK(a, Element): |
2902 | 2894 | return (<Element>a)._parent(1) |