Ticket #10772: trac_10772-0pow0.patch

File trac_10772-0pow0.patch, 4.4 KB (added by mstreng, 10 years ago)
  • sage/matrix/matrix0.pyx

    # 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  
    41054105            [      -3/11     -13/121   1436/1331]
    41064106            [    127/121   -337/1331 -4445/14641]
    41074107            [    -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
    41084122        """
    41094123        if not self.is_square():
    41104124            raise ArithmeticError("self must be a square matrix")
  • sage/rings/number_field/number_field.py

    diff -r b995f0056e8f -r e73c3a56dfc7 sage/rings/number_field/number_field.py
    a b  
    61296129            sage: L.base_field().base_field()
    61306130            Rational Field
    61316131
     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
    61326145        We can relativize over a relative field::
    61336146
    61346147            sage: K.<z> = CyclotomicField(16)
  • sage/rings/number_field/number_field_element.pyx

    diff -r b995f0056e8f -r e73c3a56dfc7 sage/rings/number_field/number_field_element.pyx
    a b  
    12571257            sage: sqrt2^sqrt2
    12581258            2^(1/2*sqrt(2))
    12591259
     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
    12601267        TESTS::
    12611268
    12621269            sage: 2^I
  • sage/rings/polynomial/polydict.pyx

    diff -r b995f0056e8f -r e73c3a56dfc7 sage/rings/polynomial/polydict.pyx
    a b  
    722722            sage: f**0
    723723            PolyDict with representation {(0, 0): 1}
    724724            sage: (f-f)**0
    725             Traceback (most recent call last):
    726             ...
    727             ArithmeticError: 0^0 is undefined.
     725            PolyDict with representation {0: 1}
    728726        """
    729727        return generic_power(self, n, self.__one())
    730728
  • sage/structure/element.pyx

    diff -r b995f0056e8f -r e73c3a56dfc7 sage/structure/element.pyx
    a b  
    28882888        except TypeError:
    28892889            raise NotImplementedError, "non-integral exponents not supported"
    28902890
    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.
    28972891    if not n:
    2898         if not a:
    2899             raise ArithmeticError, "0^0 is undefined."
    29002892        if one is None:
    29012893            if PY_TYPE_CHECK(a, Element):
    29022894                return (<Element>a)._parent(1)