Ticket #13566: trac_13566cna.patch

File trac_13566cna.patch, 6.7 KB (added by jhpalmieri, 7 years ago)
  • sage/homology/examples.py

    # HG changeset patch
    # User Christian Nassau <nassau@nullhomotopie.de>
    # Date 1354972828 -3600
    # Node ID 7949f4900f2612032c92817364befc22ed30e524
    # Parent  2a36275dc484fc651e6ed45a23ae29a30d5dad7b
    Cache the constructors in the SimplicialComplexExamples class
    
    diff --git a/sage/homology/examples.py b/sage/homology/examples.py
    a b TAB key:: 
    4646
    4747See the documentation for ``simplicial_complexes`` and for each
    4848particular type of example for full details.
     49
     50TESTS:
     51
     52Test uniqueness for these examples: each type should construct only
     53one instance, not multiple instances each time it is called::
     54
     55    sage: simplicial_complexes.Sphere(5) is simplicial_complexes.Sphere(5)
     56    True
     57    sage: simplicial_complexes.Sphere(5) is simplicial_complexes.Sphere(3)
     58    False
     59    sage: simplicial_complexes.Simplex(2) is simplicial_complexes.Simplex(2)
     60    True
     61    sage: simplicial_complexes.Torus() is simplicial_complexes.Torus()
     62    True
     63    sage: simplicial_complexes.RealProjectivePlane() is simplicial_complexes.RealProjectivePlane()
     64    True
     65    sage: simplicial_complexes.KleinBottle() is simplicial_complexes.KleinBottle()
     66    True
     67    sage: simplicial_complexes.SurfaceOfGenus(1, orientable=False) is simplicial_complexes.SurfaceOfGenus(1, orientable=False)
     68    True
     69    sage: simplicial_complexes.SurfaceOfGenus(1, orientable=False) is simplicial_complexes.SurfaceOfGenus(1, orientable=True)
     70    False
     71    sage: simplicial_complexes.MooreSpace(11) is simplicial_complexes.MooreSpace(11)
     72    True
     73    sage: simplicial_complexes.MooreSpace(11) is simplicial_complexes.MooreSpace(12)
     74    False
     75    sage: simplicial_complexes.ComplexProjectivePlane() is simplicial_complexes.ComplexProjectivePlane()
     76    True
     77    sage: simplicial_complexes.PoincareHomologyThreeSphere() is simplicial_complexes.PoincareHomologyThreeSphere()
     78    True
     79    sage: simplicial_complexes.RealProjectiveSpace(3) is simplicial_complexes.RealProjectiveSpace(3)
     80    True
     81    sage: simplicial_complexes.RealProjectiveSpace(3) is simplicial_complexes.RealProjectiveSpace(4)
     82    False
     83    sage: simplicial_complexes.K3Surface() is simplicial_complexes.K3Surface()
     84    True
     85    sage: simplicial_complexes.NotIConnectedGraphs(5,2) is simplicial_complexes.NotIConnectedGraphs(5,2)
     86    True
     87    sage: simplicial_complexes.MatchingComplex(7) is simplicial_complexes.MatchingComplex(7)
     88    True
     89    sage: simplicial_complexes.ChessboardComplex(4,5) is simplicial_complexes.ChessboardComplex(4,5)
     90    True
    4991"""
    5092
    5193from sage.homology.simplicial_complex import SimplicialComplex, Simplex
    from sage.sets.set import Set 
    5395from sage.misc.functional import is_even
    5496from sage.combinat.subset import Subsets
    5597import sage.misc.prandom as random
     98from sage.misc.cachefunc import cached_method
    5699
    57100def matching(A, B):
    58101    r"""
    class SimplicialComplexExamples(): 
    189232        {0: 0, 1: Z^16, 2: 0}
    190233    """
    191234
     235    @cached_method
    192236    def Sphere(self,n):
    193237        """
    194238        A minimal triangulation of the `n`-dimensional sphere.
    class SimplicialComplexExamples(): 
    217261        facets = S.faces()
    218262        return SimplicialComplex(facets, is_mutable=False)
    219263
     264    @cached_method
    220265    def Simplex(self, n):
    221266        """
    222267        An `n`-dimensional simplex, as a simplicial complex.
    class SimplicialComplexExamples(): 
    237282        """
    238283        return SimplicialComplex([Simplex(n)], is_mutable=False)
    239284
     285    @cached_method
    240286    def Torus(self):
    241287        """
    242288        A minimal triangulation of the torus.
    class SimplicialComplexExamples(): 
    252298                                  [4,5,6], [0,4,6]],
    253299                                 is_mutable=False)
    254300
     301    @cached_method
    255302    def RealProjectivePlane(self):
    256303        """
    257304        A minimal triangulation of the real projective plane.
    class SimplicialComplexExamples(): 
    278325
    279326    ProjectivePlane = RealProjectivePlane
    280327
     328    @cached_method
    281329    def KleinBottle(self):
    282330        """
    283331        A minimal triangulation of the Klein bottle, as presented for example
    class SimplicialComplexExamples(): 
    300348                                  [3,5,6], [5,6,0], [2,5,0], [2,5,7]],
    301349                                 is_mutable=False)
    302350
     351    @cached_method
    303352    def SurfaceOfGenus(self, g, orientable=True):
    304353        """
    305354        A surface of genus `g`.
    class SimplicialComplexExamples(): 
    340389            S = S.connected_sum(T, is_mutable=False)
    341390        return S
    342391
     392    @cached_method
    343393    def MooreSpace(self, q):
    344394        """
    345395        Triangulation of the mod `q` Moore space.
    class SimplicialComplexExamples(): 
    395445            facets.append(["A0", Ai, Aiplus])
    396446        return SimplicialComplex(facets, is_immutable=True)
    397447
     448    @cached_method
    398449    def ComplexProjectivePlane(self):
    399450        """
    400451        A minimal triangulation of the complex projective plane.
    class SimplicialComplexExamples(): 
    432483             [9, 7, 2, 3, 6], [7, 8, 3, 1, 4], [8, 9, 1, 2, 5]],
    433484            is_mutable=False)
    434485
     486    @cached_method
    435487    def PoincareHomologyThreeSphere(self):
    436488        """
    437489        A triangulation of the Poincare homology 3-sphere.
    class SimplicialComplexExamples(): 
    484536             [11, 13, 14, 16], [12, 13, 14, 15], [13, 14, 15, 16]],
    485537            is_mutable=False)
    486538
     539    @cached_method
    487540    def RealProjectiveSpace(self, n):
    488541        r"""
    489542        A triangulation of `\Bold{R}P^n` for any `n \geq 0`.
    class SimplicialComplexExamples(): 
    688741                facets.add(tuple(new))
    689742            return SimplicialComplex(list(facets), is_mutable=False)
    690743
     744    @cached_method
    691745    def K3Surface(self):
    692746        """
    693747        Returns a minimal triangulation of the K3 surface.
    class SimplicialComplexExamples(): 
    821875    ###############################################################
    822876    # examples from graph theory:
    823877
     878    @cached_method
    824879    def NotIConnectedGraphs(self, n, i):
    825880        """
    826881        The simplicial complex of all graphs on `n` vertices which are
    class SimplicialComplexExamples(): 
    889944                    facets.append(facet)
    890945        return SimplicialComplex(facets, is_mutable=False)
    891946               
     947    @cached_method
    892948    def MatchingComplex(self, n):
    893949        """
    894950        The matching complex of graphs on `n` vertices.
    class SimplicialComplexExamples(): 
    9681024                        facets.append(facet)
    9691025        return SimplicialComplex(facets, is_mutable=False)
    9701026               
     1027    @cached_method
    9711028    def ChessboardComplex(self, n, i):
    9721029        r"""
    9731030        The chessboard complex for an `n \times i` chessboard.