Ticket #14182: 14182_whitespace.patch

File 14182_whitespace.patch, 9.0 KB (added by jdemeyer, 8 years ago)
  • doc/en/thematic_tutorials/coercion_and_categories.rst

    # HG changeset patch
    # User Jeroen Demeyer <jdemeyer@cage.ugent.be>
    # Date 1361826806 -3600
    # Node ID d40bb6780315cf0e0acc7eb09b51ba56572bf4ca
    # Parent  31d4341b32cc4191638967f2d0bfac70ce94a5da
    Fix whitespace in coercion_and_categories.rst
    
    diff --git a/doc/en/thematic_tutorials/coercion_and_categories.rst b/doc/en/thematic_tutorials/coercion_and_categories.rst
    a b  
    8888elements. But some old stuff in Sage doesn't use it.  **Volunteers for
    8989refactoring are welcome!**
    9090
    91  
     91
    9292
    9393The parent
    9494----------
     
    387387
    388388Sage's category framework can differentiate the two cases::
    389389
    390     sage: Rings() 
     390    sage: Rings()
    391391    Category of rings
    392392    sage: MS1 in Rings()
    393393    False
     
    556556  "``Element``", whose value is a class.
    557557- The parent *automatically* obtains an attribute ``P.element_class``, that
    558558  subclasses both ``P.Element`` and ``P.category().element_class``.
    559  
     559
    560560Hence, for providing our fraction fields with their own element classes, **we
    561561just need to add a single line to our class**::
    562562
     
    696696
    697697.. end of output
    698698
    699 So,  *don't be afraid of using categories!* 
     699So,  *don't be afraid of using categories!*
    700700
    701701
    702702Coercion\---the basics
     
    789789      Hence, we only have a *partial* map. This is fine for a *conversion*,
    790790      but a partial map does not qualify as a *coercion*.
    791791
    792    B. Coercions are structure preserving. 
     792   B. Coercions are structure preserving.
    793793
    794794      Any real number can be converted to an integer, namely by
    795795      rounding. However, such a conversion is not useful in arithmetic
     
    17131713                raise ValueError, "The parent must be provided"
    17141714            B = parent.base()
    17151715            if d is None:
    1716                 # The default denominator is one
     1716                # The default denominator is one
    17171717                d = B.one_element()
    1718             # verify that both numerator and denominator belong to the base
     1718            # verify that both numerator and denominator belong to the base
    17191719            if n not in B or d not in B:
    17201720                raise ValueError, "Numerator and denominator must be elements of %s"%B
    17211721            # Numerator and denominator should not just be "in" B,
    17221722            # but should be defined as elements of B
    17231723            d = B(d)
    17241724            n = B(n)
    1725             # the denominator must not be zero
     1725            # the denominator must not be zero
    17261726            if d==0:
    17271727                raise ZeroDivisionError, "The denominator must not be zero"
    17281728            # normalize the denominator: WLOG, it shall be non-negative.
     
    17441744        def _repr_(self):
    17451745            return "(%s):(%s)"%(self.n,self.d)
    17461746
    1747         # Comparison: We can assume that both arguments are coerced
    1748         # into the same parent, which is a fraction field. Hence, we
    1749         # are allowed to use the denominator() and numerator() methods
    1750         # on the second argument.
     1747        # Comparison: We can assume that both arguments are coerced
     1748        # into the same parent, which is a fraction field. Hence, we
     1749        # are allowed to use the denominator() and numerator() methods
     1750        # on the second argument.
    17511751        def __cmp__(self, other):
    17521752            return cmp(self.n*other.denominator(), other.numerator()*self.d)
    1753         # Arithmetic methods, single underscore. We can assume that both
    1754         # arguments are coerced into the same parent.
    1755         # We return instances of self.__class__, because self.__class__ will
    1756         # eventually be a sub-class of MyElement.
     1753        # Arithmetic methods, single underscore. We can assume that both
     1754        # arguments are coerced into the same parent.
     1755        # We return instances of self.__class__, because self.__class__ will
     1756        # eventually be a sub-class of MyElement.
    17571757        def _add_(self, other):
    17581758            C = self.__class__
    17591759            D = self.d*other.denominator()
     
    17741774    # succeeds to look up the class definition).
    17751775    class MyFrac(UniqueRepresentation, Field):
    17761776        # Implement the category framework for elements, which also
    1777         # makes some basic conversions work.
     1777        # makes some basic conversions work.
    17781778        Element = MyElement
    17791779
    1780         # Allow to pass to a different category, by an optional argument
     1780        # Allow to pass to a different category, by an optional argument
    17811781        def __init__(self, base, category=None):
    1782             # Fraction fields only exist for integral domains
     1782            # Fraction fields only exist for integral domains
    17831783            if base not in IntegralDomains():
    17841784                raise ValueError, "%s is no integral domain"%base
    1785             # Implement the category framework for the parent
     1785            # Implement the category framework for the parent
    17861786            Field.__init__(self, base, category=category or QuotientFields())
    17871787
    1788         # Single-underscore method for string representation
     1788        # Single-underscore method for string representation
    17891789        def _repr_(self):
    17901790            return "NewFrac(%s)"%repr(self.base())
    17911791
    1792         # Two methods that are implicitly used in some tests
     1792        # Two methods that are implicitly used in some tests
    17931793        def base_ring(self):
    17941794            return self.base().base_ring()
    17951795        def characteristic(self):
    17961796            return self.base().characteristic()
    17971797
    1798         # Implement conversions. Do not override __call__!
     1798        # Implement conversions. Do not override __call__!
    17991799        def _element_constructor_(self, *args,**kwds):
    18001800            if len(args)!=1:
    18011801               return self.element_class(*args,parent=self,**kwds)
     
    18081808                return self.element_class(x.numerator(),x.denominator(),parent=self,**kwds)
    18091809            return self.element_class(x,parent=self,**kwds)
    18101810
    1811         # Implement coercion from the base and from fraction fields
    1812         # over a ring that coerces into the base
     1811        # Implement coercion from the base and from fraction fields
     1812        # over a ring that coerces into the base
    18131813        def _coerce_map_from_(self, S):
    18141814            if self.base().has_coerce_map_from(S):
    18151815                return True
     
    18181818                    return True
    18191819                if hasattr(S,'ring_of_integers') and self.base().has_coerce_map_from(S.ring_of_integers()):
    18201820                    return True
    1821         # Tell how this parent was constructed, in order to enable pushout constructions
     1821        # Tell how this parent was constructed, in order to enable pushout constructions
    18221822        def construction(self):
    18231823            return MyFracFunctor(), self.base()
    18241824
     
    18411841        rank = 5
    18421842        def __init__(self):
    18431843            # The fraction field construction is a functor
    1844             # from the category of integral domains into the category of
    1845             # fields
    1846             # NOTE: We could actually narrow the codomain and use the
    1847             # category QuotientFields()
     1844            # from the category of integral domains into the category of
     1845            # fields
     1846            # NOTE: We could actually narrow the codomain and use the
     1847            # category QuotientFields()
    18481848            ConstructionFunctor.__init__(self, IntegralDomains(), Fields())
    18491849        # Applying the functor to an object. Do not override __call__!
    18501850        def _apply_functor(self, R):
    18511851            return MyFrac(R)
    1852         # Note: To apply the functor to morphisms, implement
    1853         #       _apply_functor_to_morphism
     1852        # Note: To apply the functor to morphisms, implement
     1853        #       _apply_functor_to_morphism
    18541854
    1855         # Make sure that arithmetic involving elements of Frac(R) and
    1856         # MyFrac(R) works and yields elements of MyFrac(R)
     1855        # Make sure that arithmetic involving elements of Frac(R) and
     1856        # MyFrac(R) works and yields elements of MyFrac(R)
    18571857        def merge(self, other):
    18581858            if isinstance(other, (type(self), sage.categories.pushout.FractionField)):
    18591859                return self
     
    18681868    #   rather than from sage.categories.category.Category
    18691869    class QuotientFieldsWithTest(Category):
    18701870        # Our category is a sub-category of the category of quotient fields,
    1871         # by means of the following method.
     1871        # by means of the following method.
    18721872        def super_categories(self):
    18731873            return [QuotientFields()]
    18741874
    1875         # Here, we could implement methods that are available for
    1876         # all objects in this category.
     1875        # Here, we could implement methods that are available for
     1876        # all objects in this category.
    18771877        class ParentMethods:
    18781878            pass
    18791879
    1880         # Here, we add a new test that is available for all elements
    1881         # of any object in this category.
     1880        # Here, we add a new test that is available for all elements
     1881        # of any object in this category.
    18821882        class ElementMethods:
    18831883            def _test_factorisation(self, **options):
    18841884                P = self.parent()
    1885                 # The methods prod() and factor() are inherited from
    1886                 # some other categories.
     1885                # The methods prod() and factor() are inherited from
     1886                # some other categories.
    18871887                assert self == P.prod([P(b)**e for b,e in self.factor()])
    18881888
    18891889