@@ -57,9 +57,9 @@ An integer sequence need not necessarily be a degree sequence. Indeed, in a
5757degree sequence of length `n` no integer can be larger than `n-1` -- the degree
5858of a vertex is at most `n-1` -- and the sum of them is at most `n( n-1) `.
5959
60- Degree sequences are completely characterized by a result from Erdos and Gallai:
60+ Degree sequences are completely characterized by a result from Erdős and Gallai:
6161
62- ** Erdos and Gallai:** * The sequence of integers* `d_1 \g eq \c dots \g eq d_n`
62+ ** Erdős and Gallai:** * The sequence of integers* `d_1 \g eq \c dots \g eq d_n`
6363* is a degree sequence if and only if* `\s um_i d_i` is even and `\f orall i`
6464
6565.. MATH::
@@ -281,6 +281,7 @@ from cysignals.signals cimport sig_on, sig_off
281281cdef unsigned char * seq
282282cdef list sequences
283283
284+
284285class DegreeSequences :
285286
286287 def __init__ (self , n ):
@@ -307,16 +308,16 @@ class DegreeSequences:
307308 sage: DegreeSequences( -1)
308309 Traceback ( most recent call last) :
309310 ...
310- ValueError: The input parameter must be >= 0.
311+ ValueError: the input parameter must be >= 0
311312 """
312313 if n < 0 :
313- raise ValueError (" The input parameter must be >= 0. " )
314+ raise ValueError (" the input parameter must be >= 0" )
314315 self ._n = n
315316
316317 def __contains__ (self , seq ):
317318 """
318- Checks whether a given integer sequence is the degree sequence
319- of a graph on `n` elements
319+ Check whether a given integer sequence is the degree sequence
320+ of a graph on `n` elements.
320321
321322 EXAMPLES::
322323
@@ -342,7 +343,7 @@ class DegreeSequences:
342343 [[0]]
343344 """
344345 cdef int n = self ._n
345- if len (seq)! = n:
346+ if len (seq) ! = n:
346347 return False
347348
348349 # Is the sum even ?
@@ -352,13 +353,13 @@ class DegreeSequences:
352353 # Partial represents the left side of Erdos and Gallai's inequality,
353354 # i.e. the sum of the i first integers.
354355 cdef int partial = 0
355- cdef int i,d, dd, right
356+ cdef int i, d, dd, right
356357
357358 # Temporary variable to ensure that the sequence is indeed
358359 # non-increasing
359- cdef int prev = n- 1
360+ cdef int prev = n - 1
360361
361- for i,d in enumerate (seq):
362+ for i, d in enumerate (seq):
362363
363364 # Non-increasing ?
364365 if d > prev:
@@ -370,9 +371,9 @@ class DegreeSequences:
370371 partial += d
371372
372373 # Evaluating the right hand side
373- right = i* (i + 1 )
374- for dd in seq[i+ 1 :]:
375- right += min (dd,i + 1 )
374+ right = i * (i + 1 )
375+ for dd in seq[i + 1 :]:
376+ right += min (dd, i + 1 )
376377
377378 # Comparing the two
378379 if partial > right:
@@ -404,14 +405,15 @@ class DegreeSequences:
404405 sage: all(seq in DS for seq in DS)
405406 True
406407 """
407- return iter ( init(self ._n) )
408+ yield from init(self ._n)
408409
409410 def __dealloc__ ():
410411 """
411412 Freeing the memory
412413 """
413414 sig_free(seq)
414415
416+
415417cdef init(int n) noexcept:
416418 """
417419 Initializes the memory and starts the enumeration algorithm.
@@ -432,7 +434,7 @@ cdef init(int n) noexcept:
432434
433435 N = n
434436 sequences = []
435- enum (1 ,0 )
437+ enum (1 , 0 )
436438 sig_free(seq)
437439 return sequences
438440
@@ -467,7 +469,7 @@ cdef void enum(int k, int M) noexcept:
467469 - ``k`` -- depth of the partial degree sequence
468470 - ``M`` -- value of a maximum element in the partial degree sequence
469471 """
470- cdef int i,j
472+ cdef int i, j
471473 global seq
472474 cdef int taken = 0
473475 cdef int current_box
@@ -491,21 +493,21 @@ cdef void enum(int k, int M) noexcept:
491493 if M == 0 :
492494
493495 seq[0 ] += 1
494- enum (k+ 1 , M)
496+ enum (k + 1 , M)
495497 seq[0 ] -= 1
496498
497499 # We need not automatically increase the degree at each step. In this case,
498500 # we have no other choice but to link the new vertex of degree M to vertices
499501 # of degree M-1, which will become vertices of degree M too.
500- elif seq[M- 1 ] >= M:
502+ elif seq[M - 1 ] >= M:
501503
502- seq[M] += M+ 1
503- seq[M- 1 ] -= M
504+ seq[M] += M + 1
505+ seq[M - 1 ] -= M
504506
505- enum (k+ 1 , M)
507+ enum (k + 1 , M)
506508
507- seq[M] -= M+ 1
508- seq[M- 1 ] += M
509+ seq[M] -= M + 1
510+ seq[M - 1 ] += M
509511
510512 # ##############################################
511513 # Creating vertices of Vertices of degree > M #
@@ -542,13 +544,13 @@ cdef void enum(int k, int M) noexcept:
542544 seq[current_box] -= i
543545 seq[current_box+ 1 ] += i
544546
545- for max (0 ,((M+ 1 )- taken- i)) <= j <= n_previous_box:
547+ for max (0 , ((M+ 1 )- taken- i)) <= j <= n_previous_box:
546548 seq[current_box- 1 ] -= j
547549 seq[current_box] += j
548550
549551 new_vertex = taken + i + j
550552 seq[new_vertex] += 1
551- enum (k+ 1 ,new_vertex)
553+ enum (k+ 1 , new_vertex)
552554 seq[new_vertex] -= 1
553555
554556 seq[current_box- 1 ] += j
@@ -566,7 +568,7 @@ cdef void enum(int k, int M) noexcept:
566568 # Now current_box = 0. All the vertices of nonzero degree are taken, we just
567569 # want to know how many vertices of degree 0 will be neighbors of the new
568570 # vertex.
569- for max (0 ,((M+ 1 )- taken)) <= i <= seq[0 ]:
571+ for max (0 , ((M+ 1 )- taken)) <= i <= seq[0 ]:
570572
571573 seq[1 ] += i
572574 seq[0 ] -= i
0 commit comments