# Ticket #10025: trac10025-correct_sloane_sequences.patch

File trac10025-correct_sloane_sequences.patch, 6.8 KB (added by ylchapuy, 9 years ago)
• ## sage/combinat/sloane_functions.py

```# HG changeset patch
# User Yann Laigle-Chapuy <yannlaiglechapuy@gmail.com>
# Date 1285667923 -7200
# Node ID b6576fd05c394b4332a154a47c01fe6a1d80dce5
# Parent  6df06ea9d20eee8ed8264ea8e30111424d3fe175
#10025 correct differences with Sloane's OEIS

diff -r 6df06ea9d20e -r b6576fd05c39 sage/combinat/sloane_functions.py```
 a TESTS:: sage: a = sloane.A000001; sage: a = sloane.A000001 sage: a == loads(dumps(a)) True We agree with the online database:: sage: for t in sloane.trait_names(): # long time optional, requires internet ...       print t ...       online_list = sloane_sequence(ZZ(t[1:].lstrip('0')))[2] ...       L = max(2, len(online_list) // 2) ...       sage_list = sloane.__getattribute__(t).list(L) ...       if online_list[:L] != sage_list: ...           print t, 'seems wrong' AUTHORS: - William Stein: framework INPUT: -  ``n`` - positive integer -  ``n`` - integer OUTPUT: sage: a = sloane.A000272;a Number of labeled rooted trees with n nodes: n^(n-2). sage: a(0) Traceback (most recent call last): ... ValueError: input n (=0) must be a positive integer 1 sage: a(1) 1 sage: a(2) 1 sage: a(10) 100000000 sage: a.list(11) [1, 1, 3, 16, 125, 1296, 16807, 262144, 4782969, 100000000, 2357947691] AUTHORS: - Jaap Spies (2007-01-26) """ SloaneSequence.__init__(self, offset=1) sage: a.list(12) [1, 1, 1, 3, 16, 125, 1296, 16807, 262144, 4782969, 100000000, 2357947691] AUTHORS: - Jaap Spies (2007-01-26) """ SloaneSequence.__init__(self, offset=0) def _repr_(self): """ sage: [sloane.A000272._eval(n) for n in range(1,11)] [1, 1, 3, 16, 125, 1296, 16807, 262144, 4782969, 100000000] """ if n == 0: return 1 return Integer(ZZ(n)**(ZZ(n)-2)) [5, 21, 76, 246, 738, 2108, 5794, 15458, 40296, 103129] """ return perm_mh(n, 4) class A109814(SloaneSequence): def __init__(self): r""" The `n`th term of the sequence `a(n)` is the largest `k` such that `n` can be written as sum of `k` consecutive integers. `n` is the sum of at most `a(n)` consecutive positive integers. Suppose `n` is to be written as sum of `k` consecutive integers starting with `m`, then `2n = k(2m + k - 1)`. Only one of the factors is odd. For each odd divisor `d` of `n` there is a unique corresponding `k = min(d,2n/d)`. `a(n)` is the largest among those `k` . See: http://www.jaapspies.nl/mathfiles/problem2005-2C.pdf INPUT: -  ``n`` - non negative integer OUTPUT: -  ``integer`` - function value EXAMPLES:: sage: a = sloane.A109814; a a(n) is the largest k such that n can be written as sum of k consecutive positive integers. sage: a(0) Traceback (most recent call last): ... ValueError: input n (=0) must be a positive integer sage: a(2) 1 sage: a.list(9) [1, 1, 2, 1, 2, 3, 2, 1, 3] AUTHORS: - Jaap Spies (2007-01-13) """ SloaneSequence.__init__(self, offset=1) def _repr_(self): """ EXAMPLES:: sage: sloane.A109814._repr_() 'a(n) is the largest k such that n can be written as sum of k consecutive positive integers.' """ return "a(n) is the largest k such that n can be written as sum of k consecutive positive integers." def _eval(self, n): """ EXAMPLES:: sage: [sloane.A109814._eval(n) for n in range(1, 10)] [1, 1, 2, 1, 2, 3, 2, 1, 3] """ if n == 1: return 1 m = 0 for d in [i for i in arith.divisors(n) if i%2]: # d is odd divisor k = min(d, 2*n/d) if k > m: m = k return ZZ(m) class A111774(SloaneSequence): def __init__(self): r""" else: return k-2 class A111776(SloaneSequence): def __init__(self): r""" The `n`th term of the sequence `a(n)` is the largest `k` such that `n` can be written as sum of `k` consecutive integers. `n` is the sum of at most `a(n)` consecutive positive integers. Suppose `n` is to be written as sum of `k` consecutive integers starting with `m`, then `2n = k(2m + k - 1)`. Only one of the factors is odd. For each odd divisor `d` of `n` there is a unique corresponding `k = min(d,2n/d)`. `a(n)` is the largest among those `k` . See: http://www.jaapspies.nl/mathfiles/problem2005-2C.pdf INPUT: -  ``n`` - non negative integer OUTPUT: -  ``integer`` - function value EXAMPLES:: sage: a = sloane.A111776; a a(n) is the largest k such that n can be written as sum of k consecutive integers. sage: a(0) 1 sage: a(2) 1 sage: a.list(9) [1, 1, 1, 2, 1, 2, 3, 2, 1] AUTHORS: - Jaap Spies (2007-01-13) """ SloaneSequence.__init__(self, offset=0) def _repr_(self): """ EXAMPLES:: sage: sloane.A111776._repr_() 'a(n) is the largest k such that n can be written as sum of k consecutive integers.' """ return "a(n) is the largest k such that n can be written as sum of k consecutive integers." def _eval(self, n): """ EXAMPLES:: sage: [sloane.A111776._eval(n) for n in range(10)] [1, 1, 1, 2, 1, 2, 3, 2, 1, 3] """ if n == 1 or n == 0: return 1 m = 0 for d in [i for i in arith.divisors(n) if i%2]: # d is odd divisor k = min(d, 2*n/d) if k > m: m = k return ZZ(m) class A111787(SloaneSequence): def __init__(self): r"""