Ticket #8420: trac_8420-perfect_matchings_review-fh.patch
File trac_8420-perfect_matchings_review-fh.patch, 25.3 KB (added by , 12 years ago) |
---|
-
doc/en/reference/combinat/index.rst
# HG changeset patch # User Florent Hivert <Florent.Hivert@univ-rouen.fr> # Date 1268045939 -3600 # Node ID 8480ffdf71d8ba3443662985cea81c3af91de408 # Parent 325fcf76b921d88667e6a342e189ddb659b7c6c4 #8420 review of Valentin's matching. diff --git a/doc/en/reference/combinat/index.rst b/doc/en/reference/combinat/index.rst
a b Combinatorics 28 28 ../sage/combinat/non_decreasing_parking_function 29 29 ../sage/combinat/partition 30 30 ../sage/combinat/permutation 31 ../sage/combinat/perfect_matching 31 32 ../sage/combinat/q_analogues 32 33 ../sage/combinat/set_partition_ordered 33 34 ../sage/combinat/set_partition -
sage/combinat/perfect_matching.py
diff --git a/sage/combinat/perfect_matching.py b/sage/combinat/perfect_matching.py
a b 1 """ 2 Perfect matchings 3 """ 4 1 5 #from sage.combinat.permutation import Permutation_Class 2 6 from sage.structure.unique_representation import UniqueRepresentation 3 7 from sage.structure.parent import Parent … … from sage.structure.element_wrapper impo 7 11 from sage.structure.element import Element 8 12 from sage.misc.cachefunc import cached_method 9 13 from sage.rings.integer import Integer 14 from sage.misc.flatten import flatten 15 from sage.combinat.permutation import Permutations, Permutation 16 from sage.sets.set import Set 17 from sage.combinat.partition import Partition 18 from sage.misc.misc_c import prod 19 from sage.matrix.constructor import Matrix 10 20 11 21 class PerfectMatching(ElementWrapper): 12 22 r""" 13 23 Class of perfect matching. 14 24 15 An instance of the class can be created from a list of pairs or from a fixed point-free involution as follows:: 25 An instance of the class can be created from a list of pairs or from a 26 fixed point-free involution as follows:: 16 27 17 28 sage: m=PerfectMatching([('a','e'),('b','c'),('d','f')]);m 18 29 PerfectMatching [('a', 'e'), ('b', 'c'), ('d', 'f')] … … class PerfectMatching(ElementWrapper): 21 32 sage: isinstance(m,PerfectMatching) 22 33 True 23 34 24 The parent, which is the set of perfect matching of the ground set, is automaticly created:: 35 The parent, which is the set of perfect matching of the ground set, is 36 automaticly created:: 25 37 26 38 sage: n.parent() 27 39 Set of perfect matchings of {1, 2, 3, 4, 5, 6, 7, 8} 28 40 29 If the ground set is ordered, one can, for example, ask if the matching is non crossing:: 41 If the ground set is ordered, one can, for example, ask if the matching is 42 non crossing:: 30 43 31 44 sage: PerfectMatching([(1, 4), (2, 3), (5, 6)]).is_non_crossing() 32 45 True 33 46 """ 34 47 #the data structure of the element is a list (accessible via x.value) 35 wrappe r_class = list48 wrapped_class = list 36 49 __lt__ = ElementWrapper._lt_by_value 37 50 #During the creation of the instance of the class, the function __classcall_private__ will be called instead of __init__ directly. 38 51 __metaclass__ = ClasscallMetaclass 39 52 40 53 @staticmethod 41 54 def __classcall_private__(cls,p): 42 from sage.combinat.permutation import Permutation43 from sage.misc.flatten import flatten44 55 r""" 45 This function tries to recognize the input (it can be either a list or a tuple of pairs, or a fix-point free involution given as a list or as a permutation), constructs the parent (enumerated set of PerfectMatchings of the ground set) and calls the __init__ function to construct our object. 56 This function tries to recognize the input (it can be either a list or 57 a tuple of pairs, or a fix-point free involution given as a list or as 58 a permutation), constructs the parent (enumerated set of 59 PerfectMatchings of the ground set) and calls the __init__ function to 60 construct our object. 46 61 47 62 EXAMPLES:: 48 63 … … class PerfectMatching(ElementWrapper): 56 71 Set of perfect matchings of {1, 2, 3, 4, 5, 6, 7, 8} 57 72 sage: PerfectMatching([(1, 4), (2, 3), (5, 6)]).is_non_crossing() 58 73 True 59 60 TESTS::61 62 sage: TestSuite(m).run()63 74 """ 64 #we have to extract from the argument p the set of objects of the matching and the list of pairs 65 #First case: p is a list (resp tuple) of lists (resp tuple). 75 # we have to extract from the argument p the set of objects of the 76 # matching and the list of pairs. 77 # First case: p is a list (resp tuple) of lists (resp tuple). 66 78 if (isinstance(p,list) or isinstance(p,tuple)) and ( 67 79 all([isinstance(x,list) or isinstance(x,tuple) for x in p])): 68 80 objects=flatten(p) 69 81 data=(map(tuple,p)) 70 #Second case: p is a permutation or a list of integers, we have to check if it is a fix-point-free involution. 82 # Second case: p is a permutation or a list of integers, we have to 83 # check if it is a fix-point-free involution. 71 84 elif ((isinstance(p,list) and all(map(lambda x: (isinstance(x,Integer) or isinstance(x,int)),p ))) 72 85 or isinstance(p,sage.combinat.permutation.Permutation_class)): 73 86 p=Permutation(p) … … class PerfectMatching(ElementWrapper): 76 89 raise ValueError, "The permutation p (= %s) is not a fix-point-free involution"%p 77 90 objects=range(1,n+1) 78 91 data=p.to_cycles() 79 # Third case: p is already a perfect matching92 # Third case: p is already a perfect matching 80 93 elif isinstance(p,PerfectMatching): 81 94 data=p.value 82 95 objects=flatten(data) 83 96 else: 84 97 raise ValueError, "cannot convert p (= %s) to a PerfectMatching"%p 85 #Finally, we create the parent and the element using the element class of the parent. Note: as this function is private, when we create an object via parent.element_class(...), __init__ is directly executed and we do not have an infinite loop. 98 # Finally, we create the parent and the element using the element 99 # class of the parent. Note: as this function is private, when we 100 # create an object via parent.element_class(...), __init__ is directly 101 # executed and we do not have an infinite loop. 86 102 parent=PerfectMatchings(objects) 87 return parent.element_class(data,parent) 103 return parent.element_class(data,parent) 88 104 89 105 def __init__(self,data,parent): 90 106 r""" 91 see __classcall_private__? 107 See :meth:`__classcall_private__` 108 109 TESTS:: 110 111 sage: m=PerfectMatching([('a','e'),('b','c'),('d','f')]) 112 sage: TestSuite(m).run() 92 113 """ 93 114 self.value=data 94 115 Element.__init__(self,parent=parent) … … class PerfectMatching(ElementWrapper): 107 128 return 'PerfectMatching %s'%self.value 108 129 109 130 def __eq__(self,other): 110 from sage.sets.set import Set111 131 r""" 112 132 Compares two perfect matchings 113 133 … … class PerfectMatching(ElementWrapper): 122 142 123 143 """ 124 144 try: 125 if other.parent() <>self.parent():145 if other.parent() != self.parent(): 126 146 return False 127 147 except AttributeError: 128 148 return False … … class PerfectMatching(ElementWrapper): 130 150 131 151 def size(self): 132 152 r""" 133 returns the size of the perfect matching, i.e. the number of elements in the ground set. 134 153 154 Returns the size of the perfect matching ``self``, i.e. the number of 155 elements in the ground set. 156 135 157 EXAMPLES:: 136 158 137 159 sage: m=PerfectMatching([(-3, 1), (2, 4), (-2, 7)]); m.size() 138 160 6 139 161 """ 140 162 return 2*len(self.value) 141 163 142 def partner(self, x):164 def partner(self, x): 143 165 r""" 144 Returns the element in the same pair than x in the mathching `self`.166 Returns the element in the same pair than ``x`` in the matching ``self``. 145 167 146 168 EXAMPLES:: 147 169 148 170 sage: m=PerfectMatching([(-3, 1), (2, 4), (-2, 7)]); m.partner(4) 149 171 2 150 172 sage: n=PerfectMatching([('c','b'),('d','f'),('e','a')]); n.partner('c') … … class PerfectMatching(ElementWrapper): 157 179 return self.value[i][0] 158 180 raise ValueError,"%s in not an element of the %s"%(x,self) 159 181 160 def loop_type(self,other=None): 161 from sage.combinat.permutation import Permutation 162 from sage.combinat.partition import Partition 182 def loop_type(self, other=None): 163 183 r""" 164 input:184 INPUT: 165 185 166 two perfect matchings of the same set (if the second argument is empty, the fonction an_element is called on the parent of the first) 186 - ``other`` -- a perfet matching of the same set of ``self``. 187 (if the second argument is empty, the method :meth:`an_element` is 188 called on the parent of the first) 167 189 168 output:190 OUTPUT: 169 191 170 if we draw the two perfect matchings simultaneously as edges of a graph, the graph obtained is a union of cycles of even lengths. The function returns the ordered list of the semi-length of these cycles (considered as a partition) 192 If we draw the two perfect matchings simultaneously as edges of a 193 graph, the graph obtained is a union of cycles of even 194 lengths. The function returns the ordered list of the semi-length 195 of these cycles (considered as a partition) 171 196 172 197 EXAMPLES:: 173 198 … … class PerfectMatching(ElementWrapper): 196 221 197 222 def number_of_loops(self,other=None): 198 223 r""" 199 input:224 INPUT: 200 225 201 two perfect matchings of the same set (if the second argument is empty, the fonction an_element is called on the parent of the first) 226 - ``other`` -- a perfet matching of the same set of ``self``. 227 (if the second argument is empty, the fonction an_element is 228 called on the parent of the first) 202 229 203 output:230 OUTPUT: 204 231 205 if we draw the two perfect matchings simultaneously as edges of a graph, the graph obtained is a union of cycles of even lengths. The function returns their numbers 232 If we draw the two perfect matchings simultaneously as edges of a 233 graph, the graph obtained is a union of cycles of even 234 lengths. The function returns their numbers. 206 235 207 236 EXAMPLES:: 208 237 … … class PerfectMatching(ElementWrapper): 213 242 """ 214 243 return len(self.loop_type(other)) 215 244 216 def crossings (self):245 def crossings_iterator(self): 217 246 r""" 218 input:247 INPUT: 219 248 220 249 A perfect matching on an *totally ordered* ground set. 221 250 222 output:251 OUTPUT: 223 252 224 We place the element of a ground set and draw the perfect matching by linking the elements of the same pair in the upper half-plane. This function returns the list of the pairs of crossing lines (as a line correspond to a pair, it returns a list of pairs of pairs). 253 We place the element of a ground set and draw the perfect matching 254 by linking the elements of the same pair in the upper 255 half-plane. This function returns an iterator over the pairs of 256 crossing lines (as a line correspond to a pair, it returns a list 257 of pairs of pairs). 258 259 EXAMPLES:: 260 261 sage: n=PerfectMatching([3,8,1,7,6,5,4,2]); n 262 PerfectMatching [(1, 3), (2, 8), (4, 7), (5, 6)] 263 sage: it = n.crossings_iterator(); 264 sage: it.next() 265 ((1, 3), (2, 8)) 266 sage: it.next() 267 Traceback (most recent call last): 268 ... 269 StopIteration 270 """ 271 x=self.value[:] 272 if len(x)==0: 273 return 274 (i,j)=x.pop(0) 275 for cr in PerfectMatching(x).crossings_iterator(): 276 yield cr 277 for (a,b) in x: 278 # if (i<a<j<b) or (i<b<j<a) or (j<a<i<b) or (j<b<i<a) or ( 279 # a<i<b<j) or (a<j<b<i) or (b<i<a<j) or (b<j<a<i): 280 labij = sorted([a,b,i,j]) 281 posij = sorted([labij.index(i), labij.index(j)]) 282 if posij == [0,2] or posij == [1,3]: 283 yield ((i,j),(a,b)) 284 285 def crossings(self): 286 r""" 287 INPUT: 288 289 A perfect matching on an *totally ordered* ground set. 290 291 OUTPUT: 292 293 We place the element of a ground set and draw the perfect matching 294 by linking the elements of the same pair in the upper 295 half-plane. This function returns the list of the pairs of 296 crossing lines (as a line correspond to a pair, it returns a list 297 of pairs of pairs). 225 298 226 299 EXAMPLES:: 227 300 … … class PerfectMatching(ElementWrapper): 230 303 sage: n.crossings() 231 304 [((1, 3), (2, 8))] 232 305 """ 233 x=self.value[:] 234 if len(x)==0: 235 return [] 236 (i,j)=x.pop(0) 237 res=PerfectMatching(x).crossings() 238 for (a,b) in x: 239 if (i<a<j<b) or (i<b<j<a) or (j<a<i<b) or (j<b<i<a) or ( 240 a<i<b<j) or (a<j<b<i) or (b<i<a<j) or (b<j<a<i): 241 res.append(((i,j),(a,b))) 242 return res 306 return list(self.crossings_iterator()) 243 307 244 308 def number_of_crossings(self): 245 309 r""" 246 input:310 INPUT: 247 311 248 312 A perfect matching on an *totally ordered* ground set. 249 313 250 output:314 OUTPUT: 251 315 252 We place the element of a ground set and draw the perfect matching by linking the elements of the same pair in the upper half-plane. This function returns the number the pairs of crossing lines. 316 We place the element of a ground set and draw the perfect matching 317 by linking the elements of the same pair in the upper 318 half-plane. This function returns the number the pairs of crossing 319 lines. 253 320 254 321 EXAMPLES:: 255 322 … … class PerfectMatching(ElementWrapper): 258 325 sage: n.number_of_crossings() 259 326 1 260 327 """ 261 x=self.value[:] 262 if len(x)==0: 263 return 0 264 (i,j)=x.pop(0) 265 res=PerfectMatching(x).number_of_crossings() 266 for (a,b) in x: 267 if (i<a<j<b) or (i<b<j<a) or (j<a<i<b) or (j<b<i<a) or ( 268 a<i<b<j) or (a<j<b<i) or (b<i<a<j) or (b<j<a<i): 269 res+=1 270 return res 328 c = Integer(0) 329 one = Integer(1) 330 for _ in self.crossings_iterator(): 331 c += one 332 return c 271 333 272 334 def is_non_crossing(self): 273 335 r""" 274 input:336 INPUT: 275 337 276 338 A perfect matching on an *totally ordered* ground set. 277 339 278 output:340 OUTPUT: 279 341 280 We place the element of a ground set and draw the perfect matching by linking the elements of the same pair in the upper half-plane. This function returns True if the picture obtained this way has no crossings. 342 We place the element of a ground set and draw the perfect matching 343 by linking the elements of the same pair in the upper 344 half-plane. This function returns ``True`` if the picture obtained 345 this way has no crossings. 281 346 282 347 EXAMPLES:: 283 348 … … class PerfectMatching(ElementWrapper): 288 353 sage: PerfectMatching([(1, 4), (2, 3), (5, 6)]).is_non_crossing() 289 354 True 290 355 """ 291 x=self.value[:] 292 if len(x)==0: 356 it = self.crossings_iterator() 357 try: 358 it.next() 359 except StopIteration: 293 360 return True 294 (i,j)=x.pop(0) 295 for (a,b) in x: 296 if (i<a<j<b) or (i<b<j<a) or (j<a<i<b) or (j<b<i<a) or ( 297 a<i<b<j) or (a<j<b<i) or (b<i<a<j) or (b<j<a<i): 298 return False 299 return PerfectMatching(x).is_non_crossing() 361 else: 362 return False 300 363 301 364 def Weingarten_function(self,other,N): 302 365 r""" 303 Returns the Weingarten function of two pairings. This function is the value of some integrals over the orhtogonal groups O_N. 366 Returns the Weingarten function of two pairings. This function is 367 the value of some integrals over the orhtogonal groups `O_N`. 304 368 305 369 EXAMPLES:: 306 370 307 sage: var('N')308 N309 sage: m=PerfectMatching([(1,3),(2,4)])310 sage: n=PerfectMatching([(1,2),(3,4)])311 sage: factor(m.Weingarten_function(n,N))312 -1/((N - 1)*(N + 2)*N)371 sage: var('N') 372 N 373 sage: m=PerfectMatching([(1,3),(2,4)]) 374 sage: n=PerfectMatching([(1,2),(3,4)]) 375 sage: factor(m.Weingarten_function(n,N)) 376 -1/((N - 1)*(N + 2)*N) 313 377 """ 314 378 W=self.parent().Weingarten_matrix(N) 315 379 return W[self.rank()][other.rank()] 316 380 317 381 class PerfectMatchings(UniqueRepresentation,Parent): 318 382 r""" 319 Class of perfect matchings of a ground set. At the creation, the set can be given as any iterable object. If the argument is an integer n, it will be transformed into [1 .. n]:: 383 Class of perfect matchings of a ground set. At the creation, the set 384 can be given as any iterable object. If the argument is an integer `n`, it 385 will be transformed into `[1 .. n]`:: 320 386 321 387 sage: M=PerfectMatchings(6);M 322 388 Set of perfect matchings of {1, 2, 3, 4, 5, 6} 323 389 sage: PerfectMatchings([-1, -3, 1, 2]) 324 390 Set of perfect matchings of {1, 2, -3, -1} 325 391 326 One can ask for the list, the cardinality or an element of a set of perfect matching:: 392 One can ask for the list, the cardinality or an element of a set of 393 perfect matching:: 327 394 328 395 sage: PerfectMatchings(4).list() 329 396 [PerfectMatching [(4, 1), (3, 2)], PerfectMatching [(4, 2), (3, 1)], PerfectMatching [(4, 3), (2, 1)]] … … class PerfectMatchings(UniqueRepresentat 338 405 339 406 @staticmethod 340 407 def _parse_input(objects): 341 from sage.sets.set import Set342 408 r""" 343 This function tries to recognize the argument and to transform into a set. It is not meant to be called manually, but only as the first of the creation of an enumerated set of PerfectMatchings. 344 409 This function tries to recognize the argument and to transform into a 410 set. It is not meant to be called manually, but only as the first of 411 the creation of an enumerated set of ``PerfectMatchings``. 412 345 413 EXAMPLES:: 346 414 347 415 sage: PerfectMatchings._parse_input(4) … … class PerfectMatchings(UniqueRepresentat 349 417 sage: PerfectMatchings._parse_input(['a','b','c','e']) 350 418 {'a', 'c', 'b', 'e'} 351 419 """ 352 # if the argument is a python integer n, we replace it by the list [1 .. n]420 # if the argument is a python integer n, we replace it by the list [1 .. n] 353 421 if isinstance(objects,int): 354 422 objects=range(1,objects+1) 355 # same thing if the argument is a sage integer.423 # same thing if the argument is a sage integer. 356 424 elif isinstance(objects,Integer): 357 425 objects=range(1,objects+1) 358 #Finally, if it is iterable, we return the corresponding set. Note that it is important to return a hashable object here (in particular, NOT A LIST), see comment below. 426 # Finally, if it is iterable, we return the corresponding set. 427 # Note that it is important to return a hashable object here (in 428 # particular, NOT A LIST), see comment below. 359 429 if not hasattr(objects,'__iter__'): 360 430 raise ValueError, "do not know how to construct a set of matchings from %s (it must be iterable)" 361 431 return Set(objects) … … class PerfectMatchings(UniqueRepresentat 363 433 @staticmethod 364 434 def __classcall__(cls, objects): 365 435 r""" 366 This function is called automatically when the user want to create an enumerated set of PerfectMatchings. 436 This function is called automatically when the user want to 437 create an enumerated set of PerfectMatchings. 367 438 368 439 EXAMPLES:: 369 440 … … class PerfectMatchings(UniqueRepresentat 372 443 sage: PerfectMatchings([-1, -3, 1, 2]) 373 444 Set of perfect matchings of {1, 2, -3, -1} 374 445 375 If one has already created a set of perfect matchings of the same set, it does not create a new object, but returns the already existing one:: 446 If one has already created a set of perfect matchings of the same set, 447 it does not create a new object, but returns the already existing 448 one:: 376 449 377 450 sage: N=PerfectMatchings((2, 3, 5, 4, 1, 6)) 378 451 sage: N is M 379 452 True 380 453 381 The class constructor does not check that the perfect matching is correct, one has to use the function __contains__ for that:: 454 The class constructor does not check that the perfect matching is 455 correct, one has to use the method :meth:`__contains__` for that:: 382 456 383 457 sage: m=PerfectMatching([(1,2,3),(4,5)]) 384 458 sage: isinstance(m,PerfectMatching) 385 459 True 386 460 sage: m in m.parent() 387 461 False 388 389 TEST::390 391 sage: TestSuite(M).run()392 462 """ 393 463 #we call the constructor of an other class, which will 394 # - check if the object has already been constructed (so the second argument, i.e. the output of _parse_input, must be hashable) 464 # - check if the object has already been constructed (so the 465 # second argument, i.e. the output of _parse_input, must be hashable) 395 466 # - look for a place in memory and call the __init__ function 396 467 return super(PerfectMatchings, cls).__classcall__( 397 468 cls, cls._parse_input(objects)) 398 469 399 470 def __init__(self,objects): 400 471 r""" 401 See __classcall__? 472 See :meth:`__classcall__` 473 474 TEST:: 475 476 sage: M=PerfectMatchings(6) 477 sage: TestSuite(M).run() 402 478 """ 403 479 self._objects=objects 404 480 Parent.__init__(self, category = FiniteEnumeratedSets()) 405 481 406 482 def _repr_(self): 407 483 r""" 408 Returns a description of ` self`484 Returns a description of ``self``. 409 485 410 486 EXAMPLES:: 411 487 412 488 sage: PerfectMatchings([-1, -3, 1, 2]) 413 489 Set of perfect matchings of {1, 2, -3, -1} 414 490 """ … … class PerfectMatchings(UniqueRepresentat 416 492 417 493 def __iter__(self): 418 494 r""" 419 Returns an iterator for the elements of self495 Returns an iterator for the elements of ``self``. 420 496 421 497 EXAMPLES:: 422 498 … … class PerfectMatchings(UniqueRepresentat 427 503 yield self([]) 428 504 elif len(self._objects) == 1: 429 505 pass 430 else: 506 else: 431 507 l=list(self._objects) 432 508 a=l.pop(-1) 433 509 for i in range(len(l)): … … class PerfectMatchings(UniqueRepresentat 438 514 439 515 440 516 def __contains__(self,x): 441 from sage.misc.flatten import flatten442 from sage.combinat.permutation import Permutations443 517 r""" 444 Tests if x is an element of self.518 Tests if ``x`` is an element of ``self``. 445 519 446 520 EXAMPLES:: 447 521 … … class PerfectMatchings(UniqueRepresentat 453 527 sage: all([m in PerfectMatchings(6) for m in PerfectMatchings(6)]) 454 528 True 455 529 456 Note that the class of x does not need to be PerfectMatching: if the data defines a perfect matching of the good set, the function returns True:: 530 Note that the class of ``x`` does not need to be ``PerfectMatching``: 531 if the data defines a perfect matching of the good set, the function 532 returns ``True``:: 457 533 458 534 sage: [(1, 4), (2, 3)] in PerfectMatchings(4) 459 535 True 460 536 461 The class constructor does not check that the perfect matching is correct, one has to use the function __contains__ for that:: 537 The class constructor does not check that the perfect matching is 538 correct, one has to use the function :meth:`__contains__` for that:: 462 539 463 540 sage: m=PerfectMatching([(1,2,3),(4,5)]) 464 541 sage: isinstance(m,PerfectMatching) … … class PerfectMatchings(UniqueRepresentat 479 556 if map(lambda a:A2N[a],flatten(x.value)) not in Permutations(x.size()): 480 557 return False 481 558 return True 482 559 483 560 def cardinality(self): 484 from sage.misc.misc_c import prod485 561 r""" 486 Returns the cardinality of the set of perfect matching `self`, that is 1*3*5*...*(2n-1), where 2n is the size of the ground set. 562 Returns the cardinality of the set of perfect matching ``self``, 563 that is `1*3*5*...*(2n-1)`, where `2n` is the size of the ground set. 487 564 488 565 EXAMPLES:: 489 566 … … class PerfectMatchings(UniqueRepresentat 509 586 True 510 587 """ 511 588 n=len(self._objects)//2 512 return PerfectMatching([(self._objects[i],self._objects[i+n]) for i in range(n)]) 589 return PerfectMatching([(self._objects[i],self._objects[i+n]) 590 for i in range(n)]) 513 591 514 592 @cached_method 515 593 def Weingarten_matrix(self,N): 516 from sage.matrix.constructor import Matrix517 594 r""" 518 Returns the Weingarten matrix corresponding to the set of PerfectMatchings `self`. It is a useful theoretical tool to compute polynomial integral over the orthogonal group O_N. 595 Returns the Weingarten matrix corresponding to the set of 596 PerfectMatchings ``self``. It is a useful theoretical tool to compute 597 polynomial integral over the orthogonal group `O_N`. 519 598 520 599 EXAMPLES:: 521 600