# HG changeset patch
# User Yann LaigleChapuy
# 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/sage/combinat/sloane_functions.py Mon Sep 27 14:51:15 2010 +0200
+++ b/sage/combinat/sloane_functions.py Tue Sep 28 11:58:43 2010 +0200
@@ 43,10 +43,21 @@
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
@@ 1486,7 +1497,7 @@
INPUT:
  ``n``  positive integer
+  ``n``  integer
OUTPUT:
@@ 1500,23 +1511,21 @@
sage: a = sloane.A000272;a
Number of labeled rooted trees with n nodes: n^(n2).
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 (20070126)
 """
 SloaneSequence.__init__(self, offset=1)
+ sage: a.list(12)
+ [1, 1, 1, 3, 16, 125, 1296, 16807, 262144, 4782969, 100000000, 2357947691]
+
+ AUTHORS:
+
+  Jaap Spies (20070126)
+ """
+ SloaneSequence.__init__(self, offset=0)
def _repr_(self):
"""
@@ 1534,6 +1543,8 @@
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))
@@ 8989,8 +9000,79 @@
[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/problem20052C.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 (20070113)
+ """
+ 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"""
@@ 9246,76 +9328,6 @@
else:
return k2
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/problem20052C.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 (20070113)
 """
 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"""