Ticket #13566: trac_13566cna.patch
File trac_13566cna.patch, 6.7 KB (added by , 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:: 46 46 47 47 See the documentation for ``simplicial_complexes`` and for each 48 48 particular type of example for full details. 49 50 TESTS: 51 52 Test uniqueness for these examples: each type should construct only 53 one 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 49 91 """ 50 92 51 93 from sage.homology.simplicial_complex import SimplicialComplex, Simplex … … from sage.sets.set import Set 53 95 from sage.misc.functional import is_even 54 96 from sage.combinat.subset import Subsets 55 97 import sage.misc.prandom as random 98 from sage.misc.cachefunc import cached_method 56 99 57 100 def matching(A, B): 58 101 r""" … … class SimplicialComplexExamples(): 189 232 {0: 0, 1: Z^16, 2: 0} 190 233 """ 191 234 235 @cached_method 192 236 def Sphere(self,n): 193 237 """ 194 238 A minimal triangulation of the `n`dimensional sphere. … … class SimplicialComplexExamples(): 217 261 facets = S.faces() 218 262 return SimplicialComplex(facets, is_mutable=False) 219 263 264 @cached_method 220 265 def Simplex(self, n): 221 266 """ 222 267 An `n`dimensional simplex, as a simplicial complex. … … class SimplicialComplexExamples(): 237 282 """ 238 283 return SimplicialComplex([Simplex(n)], is_mutable=False) 239 284 285 @cached_method 240 286 def Torus(self): 241 287 """ 242 288 A minimal triangulation of the torus. … … class SimplicialComplexExamples(): 252 298 [4,5,6], [0,4,6]], 253 299 is_mutable=False) 254 300 301 @cached_method 255 302 def RealProjectivePlane(self): 256 303 """ 257 304 A minimal triangulation of the real projective plane. … … class SimplicialComplexExamples(): 278 325 279 326 ProjectivePlane = RealProjectivePlane 280 327 328 @cached_method 281 329 def KleinBottle(self): 282 330 """ 283 331 A minimal triangulation of the Klein bottle, as presented for example … … class SimplicialComplexExamples(): 300 348 [3,5,6], [5,6,0], [2,5,0], [2,5,7]], 301 349 is_mutable=False) 302 350 351 @cached_method 303 352 def SurfaceOfGenus(self, g, orientable=True): 304 353 """ 305 354 A surface of genus `g`. … … class SimplicialComplexExamples(): 340 389 S = S.connected_sum(T, is_mutable=False) 341 390 return S 342 391 392 @cached_method 343 393 def MooreSpace(self, q): 344 394 """ 345 395 Triangulation of the mod `q` Moore space. … … class SimplicialComplexExamples(): 395 445 facets.append(["A0", Ai, Aiplus]) 396 446 return SimplicialComplex(facets, is_immutable=True) 397 447 448 @cached_method 398 449 def ComplexProjectivePlane(self): 399 450 """ 400 451 A minimal triangulation of the complex projective plane. … … class SimplicialComplexExamples(): 432 483 [9, 7, 2, 3, 6], [7, 8, 3, 1, 4], [8, 9, 1, 2, 5]], 433 484 is_mutable=False) 434 485 486 @cached_method 435 487 def PoincareHomologyThreeSphere(self): 436 488 """ 437 489 A triangulation of the Poincare homology 3sphere. … … class SimplicialComplexExamples(): 484 536 [11, 13, 14, 16], [12, 13, 14, 15], [13, 14, 15, 16]], 485 537 is_mutable=False) 486 538 539 @cached_method 487 540 def RealProjectiveSpace(self, n): 488 541 r""" 489 542 A triangulation of `\Bold{R}P^n` for any `n \geq 0`. … … class SimplicialComplexExamples(): 688 741 facets.add(tuple(new)) 689 742 return SimplicialComplex(list(facets), is_mutable=False) 690 743 744 @cached_method 691 745 def K3Surface(self): 692 746 """ 693 747 Returns a minimal triangulation of the K3 surface. … … class SimplicialComplexExamples(): 821 875 ############################################################### 822 876 # examples from graph theory: 823 877 878 @cached_method 824 879 def NotIConnectedGraphs(self, n, i): 825 880 """ 826 881 The simplicial complex of all graphs on `n` vertices which are … … class SimplicialComplexExamples(): 889 944 facets.append(facet) 890 945 return SimplicialComplex(facets, is_mutable=False) 891 946 947 @cached_method 892 948 def MatchingComplex(self, n): 893 949 """ 894 950 The matching complex of graphs on `n` vertices. … … class SimplicialComplexExamples(): 968 1024 facets.append(facet) 969 1025 return SimplicialComplex(facets, is_mutable=False) 970 1026 1027 @cached_method 971 1028 def ChessboardComplex(self, n, i): 972 1029 r""" 973 1030 The chessboard complex for an `n \times i` chessboard.