Ticket #14355: trac_14355.patch

File trac_14355.patch, 4.7 KB (added by ncohen, 9 years ago)
  • doc/en/reference/combinat/developer.rst

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1364157682 -3600
    # Node ID 49e82f606f2dbced6645bd9269aded348054e0eb
    # Parent  0399181d5e5197389d2ec99b14ed43e02c016ab0
    Removes sage.combinat.generator
    
    diff --git a/doc/en/reference/combinat/developer.rst b/doc/en/reference/combinat/developer.rst
    a b  
    1111   ../sage/combinat/choose_nk
    1212   ../sage/combinat/multichoose_nk
    1313   ../sage/combinat/tools
    14    ../sage/combinat/generator
    1514   ../sage/combinat/ranker
    16    
    17  No newline at end of file
     15   
  • deleted file sage/combinat/generator.py

    diff --git a/sage/combinat/generator.py b/sage/combinat/generator.py
    deleted file mode 100644
    + -  
    1 """
    2 Generators
    3 """
    4 #*****************************************************************************
    5 #       Copyright (C) 2007 Mike Hansen <mhansen@gmail.com>,
    6 #
    7 #  Distributed under the terms of the GNU General Public License (GPL)
    8 #
    9 #    This code is distributed in the hope that it will be useful,
    10 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
    11 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    12 #    General Public License for more details.
    13 #
    14 #  The full text of the GPL is available at:
    15 #
    16 #                  http://www.gnu.org/licenses/
    17 #*****************************************************************************
    18 
    19 def concat(gens):
    20     r"""
    21     Returns a generator that is the concatenation of the generators in
    22     the list.
    23    
    24     EXAMPLES::
    25    
    26         sage: list(sage.combinat.generator.concat([[1,2,3],[4,5,6]]))
    27         [1, 2, 3, 4, 5, 6]
    28     """
    29 
    30     for gen in gens:
    31         for element in gen:
    32             yield element
    33 
    34 
    35 def map(f, gen):
    36     """
    37     Returns a generator that returns f(g) for g in gen.
    38    
    39     EXAMPLES::
    40    
    41         sage: f = lambda x: x*2
    42         sage: list(sage.combinat.generator.map(f,[4,5,6]))
    43         [8, 10, 12]
    44     """
    45     for element in gen:
    46         yield f(element)
    47 
    48 def element(element, n = 1):
    49     """
    50     Returns a generator that yield a single element n times.
    51    
    52     EXAMPLES::
    53    
    54         sage: list(sage.combinat.generator.element(1))
    55         [1]
    56         sage: list(sage.combinat.generator.element(1, n=3))
    57         [1, 1, 1]
    58     """
    59     for i in range(n):
    60         yield element
    61 
    62 def select(f, gen):
    63     """
    64     Returns a generator for all the elements g of gen such that f(g) is
    65     True.
    66    
    67     EXAMPLES::
    68    
    69         sage: f = lambda x: x % 2 == 0
    70         sage: list(sage.combinat.generator.select(f,range(7)))
    71         [0, 2, 4, 6]
    72     """
    73     for element in gen:
    74         if f(element):
    75             yield element
    76 
    77 
    78 def successor(initial, succ):
    79     """
    80     Given an initial value and a successor function, yield the initial
    81     value and each following successor. The generator will continue to
    82     generate values until the successor function yields None.
    83    
    84     EXAMPLES::
    85    
    86         sage: f = lambda x: x+1 if x < 10 else None
    87         sage: list(sage.combinat.generator.successor(0,f))
    88         [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    89     """
    90     yield initial
    91 
    92     s = succ(initial)
    93     while s:
    94         yield s
    95         s = succ(s)
    96 
    97        
  • sage/combinat/integer_list.py

    diff --git a/sage/combinat/integer_list.py b/sage/combinat/integer_list.py
    a b  
    3131#                  http://www.gnu.org/licenses/
    3232#*****************************************************************************
    3333
    34 import generator
    3534from sage.rings.arith import binomial
    3635from sage.rings.integer_ring import ZZ
    3736from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
     
    389388
    390389    #Handle the case where n is a list of integers
    391390    if isinstance(n, __builtin__.list):
    392         iterators = [iterator(i, min_length, max_length, floor, ceiling, min_slope, max_slope) for i in range(n[0], min(n[1]+1,upper_bound(min_length, max_length, floor, ceiling, min_slope, max_slope)))]
    393        
    394         return generator.concat(iterators)
     391        for i in range(n[0], min(n[1]+1,upper_bound(min_length, max_length, floor, ceiling, min_slope, max_slope))):
     392            for el in iterator(i, min_length, max_length, floor, ceiling, min_slope, max_slope):
     393                yield el
    395394    else:
    396395        f = first(n, min_length, max_length, floor, ceiling, min_slope, max_slope)
    397         if f == None:
    398             return generator.element(None, 0)
    399         return generator.successor(f, succ)
     396        while not f is None:
     397            yield f
     398            f = succ(f)
    400399
    401400def list(n, min_length, max_length, floor, ceiling, min_slope, max_slope):
    402401    """