Ticket #10025: trac_10025smallfixes.patch
File trac_10025smallfixes.patch, 4.7 KB (added by , 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 50 50 We agree with the online database:: 51 51 52 52 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] 55 54 ... L = max(2, len(online_list) // 2) 56 55 ... sage_list = sloane.__getattribute__(t).list(L) 57 56 ... if online_list[:L] != sage_list: … … 8993 8992 return perm_mh(n, 4) 8994 8993 8995 8994 class 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/problem20052C.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/problem20052C.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 (20070113) 9042 """ 9043 9044 def __init__(self): 9045 r""" 9023 9046 EXAMPLES:: 9024 9047 9025 9048 sage: a = sloane.A109814; a … … 9032 9055 1 9033 9056 sage: a.list(9) 9034 9057 [1, 1, 2, 1, 2, 3, 2, 1, 3] 9035 9036 AUTHORS:9037 9038  Jaap Spies (20070113)9039 9058 """ 9040 9059 SloaneSequence.__init__(self, offset=1) 9041 9060 
sage/databases/sloane.py
diff r e894562da4d5 r 3832e843cc5d sage/databases/sloane.py
a b 458 458 list = signed 459 459 return [seqnum, description, [ZZ(n) for n in list]] 460 460 461 def sloane_sequence(number ):461 def sloane_sequence(number, verbose = True): 462 462 """ 463 463 Returns a list with the number, name, and values for the sequence 464 464 ``number`` in Sloane's online database of integer 465 465 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 466 476 467 477 EXAMPLES:: 468 478 … … 489 499 number = str(ZZ(number)) 490 500 except TypeError: 491 501 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) 493 503 if len(results) == 0: 494 504 raise ValueError, "sequence '%s' not found"%number 495 505 return results[0]