Ticket #10025: trac_10025-smallfixes.patch

File trac_10025-smallfixes.patch, 4.7 KB (added by ncohen, 9 years ago)
  • sage/combinat/sloane_functions.py

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1287930693 -7200
    # Node ID 3832e843cc5df6e99984bfe57c29a8b91f081043
    # Parent  e894562da4d58ab43dcb43ba007c87453252ca9d
    trac 10025 -- some docstring/doctests problems in sloane.A109814
    
    diff -r e894562da4d5 -r 3832e843cc5d sage/combinat/sloane_functions.py
    a b  
    5050    We agree with the online database::
    5151
    5252    sage: for t in sloane.trait_names(): # long time optional, requires internet
    53     ...       print t
    54     ...       online_list = sloane_sequence(ZZ(t[1:].lstrip('0')))[2]
     53    ...       online_list = sloane_sequence(ZZ(t[1:].lstrip('0')), verbose = False)[2]
    5554    ...       L = max(2, len(online_list) // 2)
    5655    ...       sage_list = sloane.__getattribute__(t).list(L)
    5756    ...       if online_list[:L] != sage_list:
     
    89938992        return perm_mh(n, 4)
    89948993
    89958994class A109814(SloaneSequence):
    8996     def __init__(self):
    8997         r"""
    8998         The `n`th term of the sequence `a(n)` is the
    8999         largest `k` such that `n` can be written as sum of
    9000         `k` consecutive integers.
    9001 
    9002         `n` is the sum of at most `a(n)` consecutive
    9003         positive integers. Suppose `n` is to be written as sum of
    9004         `k` consecutive integers starting with `m`, then
    9005         `2n = k(2m + k - 1)`. Only one of the factors is odd. For
    9006         each odd divisor `d` of `n` there is a unique
    9007         corresponding `k = min(d,2n/d)`. `a(n)` is the
    9008         largest among those `k` . See:
    9009         http://www.jaapspies.nl/mathfiles/problem2005-2C.pdf
    9010 
    9011         INPUT:
    9012 
    9013 
    9014         -  ``n`` - non negative integer
    9015 
    9016 
    9017         OUTPUT:
    9018 
    9019 
    9020         -  ``integer`` - function value
    9021 
    9022 
     8995    r"""
     8996    The `n` th term of the sequence `a(n)` is the
     8997    largest `k` such that `n` can be written as sum of
     8998    `k` consecutive integers.
     8999   
     9000    By definition, `n` is the sum of at most `a(n)` consecutive
     9001    positive integers. Suppose `n` is to be written as sum of `k`
     9002    consecutive integers starting with `m`, then `2n = k(2m + k -
     9003    1)`. Only one of the factors is odd. For each odd divisor `d`
     9004    of `n` there is a unique corresponding `k =
     9005    min(d,2n/d)`. `a(n)` can be alternatively defined as the
     9006    largest among those `k` .
     9007   
     9008    .. SEEALSO::
     9009       
     9010        * `Wikipedia article on polite numbers
     9011          <http://en.wikipedia.org/wiki/Polite_number>`_.
     9012
     9013        * `An exercise sheet (with answers) about sums of
     9014          consecutive integers
     9015          <http://www.jaapspies.nl/mathfiles/problem2005-2C.pdf>`_.
     9016
     9017    INPUT:
     9018
     9019    -  ``n`` - non negative integer
     9020
     9021
     9022    OUTPUT:
     9023
     9024    -  ``integer`` - function value
     9025
     9026    EXAMPLES::
     9027
     9028        sage: a = sloane.A109814; a
     9029        a(n) is the largest k such that n can be written as sum of k consecutive positive integers.
     9030        sage: a(0)
     9031        Traceback (most recent call last):
     9032        ...
     9033        ValueError: input n (=0) must be a positive integer
     9034        sage: a(2)
     9035        1
     9036        sage: a.list(9)
     9037        [1, 1, 2, 1, 2, 3, 2, 1, 3]
     9038
     9039    AUTHORS:
     9040
     9041    - Jaap Spies (2007-01-13)
     9042        """
     9043
     9044    def __init__(self):
     9045        r"""
    90239046        EXAMPLES::
    90249047
    90259048            sage: a = sloane.A109814; a
     
    90329055            1
    90339056            sage: a.list(9)
    90349057            [1, 1, 2, 1, 2, 3, 2, 1, 3]
    9035 
    9036         AUTHORS:
    9037 
    9038         - Jaap Spies (2007-01-13)
    90399058        """
    90409059        SloaneSequence.__init__(self, offset=1)
    90419060
  • sage/databases/sloane.py

    diff -r e894562da4d5 -r 3832e843cc5d sage/databases/sloane.py
    a b  
    458458        list = signed
    459459    return [seqnum, description, [ZZ(n) for n in list]]
    460460
    461 def sloane_sequence(number):
     461def sloane_sequence(number, verbose = True):
    462462    """
    463463    Returns a list with the number, name, and values for the sequence
    464464    ``number`` in Sloane's online database of integer
    465465    sequences.
     466
     467    INPUT:
     468
     469    - ``number`` (integer) corresponding to the sequence.
     470
     471    -  ``verbose`` - (boolean) print a string to let the
     472       user know that it is working and not hanging.
     473
     474       Set to ``True`` by default.
     475
    466476   
    467477    EXAMPLES::
    468478   
     
    489499            number = str(ZZ(number))
    490500        except TypeError:
    491501            raise TypeError, "input must be an integer or string that specifies the id of the Sloane sequence to download"
    492     results = sloane_find('id:A%s'%number)
     502    results = sloane_find('id:A%s'%number, verbose = verbose)
    493503    if len(results) == 0:
    494504        raise ValueError, "sequence '%s' not found"%number
    495505    return results[0]