You can query the OEIS (Online Database of Integer Sequences) through Sage in order to:
- identify a sequence from its first terms.
- obtain more terms, formulae, references, etc. for a given sequence.
AUTHORS:
- Thierry Monteil (2012-02-10 – 2013-06-21): initial version.
EXAMPLES:
sage: oeis
The On-Line Encyclopedia of Integer Sequences (http://oeis.org/)
What about a sequence starting with ?
sage: search = oeis([3, 7, 15, 1], max_results=4) ; search # optional -- internet
0: A001203: Continued fraction expansion of Pi.
1: A165416: Irregular array read by rows: The n-th row contains those distinct positive integers that each, when written in binary, occurs as a substring in binary n.
2: A193583: Number of fixed points under iteration of sum of squares of digits in base b.
3: A082495: (2^n-1) mod n.
sage: c = search[0] ; c # optional -- internet
A001203: Continued fraction expansion of Pi.
sage: c.first_terms(15) # optional -- internet
(3, 7, 15, 1, 292, 1, 1, 1, 2, 1, 3, 1, 14, 2, 1)
sage: c.examples() # optional -- internet
0: Pi = 3.1415926535897932384...
1: = 3 + 1/(7 + 1/(15 + 1/(1 + 1/(292 + ...))))
2: = [a_0; a_1, a_2, a_3, ...] = [3; 7, 15, 292, ...]
sage: c.comments() # optional -- internet
0: The first 5,821,569,425 terms were computed by _Eric W. Weisstein_ on Sep 18 2011.
1: The first 10,672,905,501 terms were computed by _Eric W. Weisstein_ on Jul 17 2013.
2: The first 15,000,000,000 terms were computed by _Eric W. Weisstein_ on Jul 27 2013.
sage: x = c.natural_object() ; x.parent() # optional -- internet
Field of all continued fractions
sage: x.convergents()[:7] # optional -- internet
[3, 22/7, 333/106, 355/113, 103993/33102, 104348/33215, 208341/66317]
sage: RR(x.value()) # optional -- internet
3.14159265358979
sage: RR(x.value()) == RR(pi) # optional -- internet
True
What about posets ? Are they hard to count ? To which other structures are they related ?
sage: [Posets(i).cardinality() for i in range(10)]
[1, 1, 2, 5, 16, 63, 318, 2045, 16999, 183231]
sage: oeis(_) # optional -- internet
0: A000112: Number of partially ordered sets ("posets") with n unlabeled elements.
sage: p = _[0] # optional -- internet
sage: 'hard' in p.keywords() # optional -- internet
True
sage: len(p.formulas()) # optional -- internet
0
sage: len(p.first_terms()) # optional -- internet
17
sage: p.cross_references(fetch=True) # optional -- internet
0: A000798: Number of different quasi-orders (or topologies, or transitive digraphs) with n labeled elements.
1: A001035: Number of partially ordered sets ("posets") with n labeled elements (or labeled acyclic transitive digraphs).
2: A001930: Number of topologies, or transitive digraphs with n unlabeled nodes.
3: A006057: Number of labeled topologies with n points.
4: A079263: Number of constrained mixed models with n factors.
5: A079265: Number of antisymmetric transitive binary relations on n unlabeled points.
What does the Taylor expansion of the function have to do with
primes ?
sage: x = var('x') ; f(x) = e^(e^x - 1)
sage: L = [a*factorial(b) for a,b in taylor(f(x), x, 0, 20).coeffs()] ; L
[1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147, 115975, 678570, 4213597,
27644437, 190899322, 1382958545, 10480142147, 82864869804, 682076806159,
5832742205057, 51724158235372]
sage: oeis(L) # optional -- internet
0: A000110: Bell or exponential numbers: ways of placing n labeled balls into n indistinguishable boxes.
sage: b = _[0] # optional -- internet
sage: b.formulas()[0] # optional -- internet
'E.g.f.: exp( exp(x) - 1).'
sage: b.comments()[89] # optional -- internet
'Number n is prime if mod(a(n)-2,n) = 0. [From _Dmitry Kruchinin_, Feb 14 2012]'
sage: [n for n in range(2, 20) if (b(n)-2) % n == 0] # optional -- internet
[2, 3, 5, 7, 11, 13, 17, 19]
See also
Todo
Bases: tuple
This class inherits from tuple, it allows to nicely print tuples whose elements have a one line representation.
EXAMPLES:
sage: from sage.databases.oeis import FancyTuple
sage: t = FancyTuple(['zero', 'one', 'two', 'three', 4]) ; t
0: zero
1: one
2: two
3: three
4: 4
sage: t[2]
'two'
The On-Line Encyclopedia of Integer Sequences.
OEIS is a class representing the On-Line Encyclopedia of Integer Sequences. You can query it using its methods, but OEIS can also be called directly with three arguments:
OUTPUT:
EXAMPLES:
sage: oeis
The On-Line Encyclopedia of Integer Sequences (http://oeis.org/)
A particular sequence can be called by its A-number or number:
sage: oeis('A000040') # optional -- internet
A000040: The prime numbers.
sage: oeis(45) # optional -- internet
A000045: Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.
The database can be searched by subsequence:
sage: search = oeis([1,2,3,5,8,13]) ; search # optional -- internet
0: A000045: Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.
1: A027926: Triangular array T read by rows: T(n,0)=T(n,2n)=1 for n >= 0; ...
2: A001129: Iccanobif numbers: reverse digits of two previous terms and add.
sage: fibo = search[0] # optional -- internet
sage: fibo.name() # optional -- internet
'Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.'
sage: fibo.first_terms() # optional -- internet
(0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987,
1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393,
196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887,
9227465, 14930352, 24157817, 39088169)
sage: fibo.cross_references()[0] # optional -- internet
'A039834'
sage: fibo == oeis(45) # optional -- internet
True
sage: sfibo = oeis('A039834') # optional -- internet
sage: sfibo.first_terms() # optional -- internet
(1, 1, 0, 1, -1, 2, -3, 5, -8, 13, -21, 34, -55, 89, -144, 233,
-377, 610, -987, 1597, -2584, 4181, -6765, 10946, -17711, 28657,
-46368, 75025, -121393, 196418, -317811, 514229, -832040, 1346269,
-2178309, 3524578, -5702887, 9227465, -14930352, 24157817)
sage: sfibo.first_terms(absolute_value=True)[2:20] == fibo.first_terms()[:18] # optional -- internet
True
sage: fibo.formulas()[3] # optional -- internet
'F(n) = F(n-1) + F(n-2) = -(-1)^n F(-n).'
sage: fibo.comments()[1] # optional -- internet
"F(n+2) = number of binary sequences of length n that have no
consecutive 0's."
sage: fibo.links()[0] # optional -- internet
'http://oeis.org/A000045/b000045.txt'
The database can be searched by description:
sage: oeis('prime gap factorization', max_results=4) # optional -- internet
0: A073491: Numbers having no prime gaps in their factorization.
1: A073490: Number of prime gaps in factorization of n.
2: A073492: Numbers having at least one prime gap in their factorization.
3: A073493: Numbers having exactly one prime gap in their factorization.
Warning
The following will fetch the OEIS database twice (once for searching the database, and once again for creating the sequence fibo):
sage: oeis([1,2,3,5,8,13]) # optional -- internet
0: A000045: Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.
1: A027926: Triangular array T read by rows: T(n,0)=T(n,2n)=1 for n >= 0; ...
2: A001129: Iccanobif numbers: reverse digits of two previous terms and add.
sage: fibo = oeis('A000045') # optional -- internet
Do not do this, it is slow, it costs bandwidth and server resources ! Instead, do the following, to reuse the result of the search to create the sequence:
sage: oeis([1,2,3,5,8,13]) # optional -- internet
0: A000045: Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.
1: A027926: Triangular array T read by rows: T(n,0)=T(n,2n)=1 for n >= 0; ...
2: A001129: Iccanobif numbers: reverse digits of two previous terms and add.
sage: fibo = _[0] # optional -- internet
Open the OEIS web page in a browser.
EXAMPLES:
sage: oeis.browse() # optional -- webbrowser
Search for OEIS sequences corresponding to the description.
INPUT:
OUTPUT:
EXAMPLES:
sage: oeis.find_by_description('prime gap factorization') # optional -- internet
0: A073491: Numbers having no prime gaps in their factorization.
1: A073490: Number of prime gaps in factorization of n.
2: A073492: Numbers having at least one prime gap in their factorization.
sage: prime_gaps = _[1] ; prime_gaps # optional -- internet
A073490: Number of prime gaps in factorization of n.
sage: oeis('beaver') # optional -- internet
0: A028444: Busy Beaver sequence, or Rado's sigma function: ...
1: A060843: Busy Beaver problem: a(n) = maximal number of steps ...
2: A131956: Busy Beaver variation: maximum number of steps for ...
sage: oeis('beaver', max_results=4, first_result=2) # optional -- internet
0: A131956: Busy Beaver variation: maximum number of steps for ...
1: A141475: Number of Turing machines with n states following ...
2: A131957: Busy Beaver sigma variation: maximum number of 1's ...
3: A052200: Number of n-state, 2-symbol, d+ in {LEFT, RIGHT}, ...
INPUT:
OUTPUT:
EXAMPLES:
sage: oeis.find_by_id('A000040') # optional -- internet
A000040: The prime numbers.
sage: oeis.find_by_id(40) # optional -- internet
A000040: The prime numbers.
Search for OEIS sequences containing the given subsequence.
INPUT:
OUTPUT:
EXAMPLES:
sage: oeis.find_by_subsequence([2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377]) # optional -- internet
0: A000045: Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.
1: A177194: Fibonacci numbers whose decimal expression does not contain any digit 0.
2: A020695: Pisot sequence E(2,3).
sage: fibo = _[0] ; fibo # optional -- internet
A000045: Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.
Bases: sage.structure.sage_object.SageObject
The class of OEIS sequences.
This class implements OEIS sequences. Such sequences are produced from a string in the OEIS format. They are usually produced by calls to the On-Line Encyclopedia of Integer Sequences, represented by the class OEIS.
Note
Since some sequences do not start with index 0, there is a difference between calling and getting item, see __call__() for more details
sage: sfibo = oeis('A039834') # optional -- internet
sage: sfibo.first_terms()[:10] # optional -- internet
(1, 1, 0, 1, -1, 2, -3, 5, -8, 13)
sage: sfibo(-2) # optional -- internet
1
sage: sfibo(3) # optional -- internet
2
sage: sfibo.offsets() # optional -- internet
(-2, 6)
sage: sfibo[0] # optional -- internet
1
sage: sfibo[6] # optional -- internet
-3
Returns the element of the sequence self whith index k.
INPUT:
OUTPUT:
Note
The first index of the sequence self is not necessarily zero, it depends on the first offset of self. If the sequence represents the decimal expansion of a real number, the index 0 corresponds to the digit right after the decimal point.
EXAMPLES:
sage: f = oeis(45) # optional -- internet
sage: f.first_terms()[:10] # optional -- internet
(0, 1, 1, 2, 3, 5, 8, 13, 21, 34)
sage: f(4) # optional -- internet
3
sage: sfibo = oeis('A039834') # optional -- internet
sage: sfibo.first_terms()[:10] # optional -- internet
(1, 1, 0, 1, -1, 2, -3, 5, -8, 13)
sage: sfibo(-2) # optional -- internet
1
sage: sfibo(4) # optional -- internet
-3
sage: sfibo.offsets() # optional -- internet
(-2, 6)
TESTS:
sage: s = oeis._imaginary_sequence()
sage: s(38)
1
sage: s(42)
-1
sage: s(2)
Traceback (most recent call last):
...
ValueError: Sequence A999999 is not defined (or known) for index 2
Returns the author of the sequence in the encyclopedia.
OUTPUT:
EXAMPLES:
sage: f = oeis(45) ; f # optional -- internet
A000045: Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.
sage: f.author() # optional -- internet
'_N. J. A. Sloane_.'
TESTS:
sage: s = oeis._imaginary_sequence()
sage: s.author()
'Anonymous.'
Open the OEIS web page associated to the sequence self in a browser.
EXAMPLES:
sage: f = oeis(45) ; f # optional -- internet, webbrowser
A000045: Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.
sage: f.browse() # optional -- internet, webbrowser
TESTS:
sage: s = oeis._imaginary_sequence() # optional -- webbrowser
sage: s.browse() # optional -- webbrowser
Return a tuple of comments associated to the sequence self.
OUTPUT:
EXAMPLES:
sage: f = oeis(45) ; f # optional -- internet
A000045: Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.
sage: f.comments()[:3] # optional -- internet
("Also called Lam{\\'e}'s sequence.",
"F(n+2) = number of binary sequences of length n that have no consecutive 0's.",
'F(n+2) = number of subsets of {1,2,...,n} that contain no consecutive integers.')
TESTS:
sage: s = oeis._imaginary_sequence()
sage: s.comments()
0: 42 is the product of the first 4 prime numbers, except 5 and perhaps 1.
1: Apart from that, i have no comment.
Return a tuple of cross references associated to the sequence self.
INPUT:
OUTPUT:
EXAMPLES:
sage: nbalanced = oeis("A005598") ; nbalanced # optional -- internet
A005598: a(n)=1+sum((n-i+1)*phi(i),i=1..n).
sage: nbalanced.cross_references() # optional -- internet
('A049703', 'A049695', 'A103116', 'A000010')
sage: nbalanced.cross_references(fetch=True) # optional -- internet
0: A049703: a(0) = 0; for n>0, a(n) = A005598(n)/2.
1: A049695: Array T read by diagonals; T(i,j)=number of nonnegative slopes of lines determined by 2 lattice points in [ 0,i ] X [ 0,j ] if i>0; T(0,j)=1 if j>0; T(0,0)=0.
2: A103116: A005598(n) - 1.
3: A000010: Euler totient function phi(n): count numbers <= n and prime to n.
sage: phi = _[3] # optional -- internet
TESTS:
sage: s = oeis._imaginary_sequence()
sage: s.cross_references()
('A000042', 'A000024')
Return a tuple of examples associated to the sequence self.
OUTPUT:
EXAMPLES:
sage: c = oeis(1203) ; c # optional -- internet
A001203: Continued fraction expansion of Pi.
sage: c.examples() # optional -- internet
0: Pi = 3.1415926535897932384...
1: = 3 + 1/(7 + 1/(15 + 1/(1 + 1/(292 + ...))))
2: = [a_0; a_1, a_2, a_3, ...] = [3; 7, 15, 292, ...]
TESTS:
sage: s = oeis._imaginary_sequence()
sage: s.examples()
0: s(42) + s(43) = 0.
Return a tuple of extensions or errors associated to the sequence self.
OUTPUT:
EXAMPLES:
sage: sfibo = oeis('A039834') ; sfibo # optional -- internet
A039834: a(n+2)=-a(n+1)+a(n) (signed Fibonacci numbers); or Fibonacci numbers (A000045) extended to negative indices.
sage: sfibo.extensions_or_errors()[0] # optional -- internet
'Signs corrected by Len Smiley (smiley(AT)math.uaa.alaska.edu) and _N. J. A. Sloane_.'
TESTS:
sage: s = oeis._imaginary_sequence()
sage: s.extensions_or_errors()
0: This sequence does not contain errors.
INPUT:
OUTPUT:
EXAMPLES:
sage: f = oeis(45) ; f # optional -- internet
A000045: Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.
sage: f.first_terms()[:10] # optional -- internet
(0, 1, 1, 2, 3, 5, 8, 13, 21, 34)
TESTS:
sage: s = oeis._imaginary_sequence()
sage: s.first_terms()
(1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
sage: s.first_terms(5)
(1, 1, 1, 1, -1)
sage: s.first_terms(5, absolute_value=True)
(1, 1, 1, 1, 1)
sage: s = oeis._imaginary_sequence(keywords='full')
sage: s(40)
Traceback (most recent call last):
...
TypeError: You found a sign inconsistency, please contact OEIS
sage: s = oeis._imaginary_sequence(keywords='sign,full')
sage: s(40)
1
sage: s = oeis._imaginary_sequence(keywords='nonn,full')
sage: s(42)
1
Return a tuple of formulas associated to the sequence self.
OUTPUT:
EXAMPLES:
sage: f = oeis(45) ; f # optional -- internet
A000045: Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.
sage: f.formulas()[1] # optional -- internet
'F(n) = ((1+sqrt(5))^n-(1-sqrt(5))^n)/(2^n*sqrt(5)).'
TESTS:
sage: s = oeis._imaginary_sequence()
sage: s.formulas()
0: For n big enough, s(n+1) - s(n) = 0.
The ID of the sequence self is the A-number that identifies self.
INPUT:
OUTPUT:
EXAMPLES:
sage: f = oeis(45) ; f # optional -- internet
A000045: Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.
sage: f.id() # optional -- internet
'A000045'
sage: f.id(format='int') # optional -- internet
45
TESTS:
sage: s = oeis._imaginary_sequence()
sage: s.id()
'A999999'
sage: s.id(format='int')
999999
Tells whether the sequence is finite.
Currently, OEIS only provides a keyword when the sequence is known to be finite. So, when this keyword is not there, we do not know whether it is infinite or not.
OUTPUT:
Todo
Ask OEIS for a keyword ensuring that a sequence is infinite.
EXAMPLES:
sage: s = oeis('A114288') ; s # optional -- internet
A114288: Lexicographically minimal solution of any 9 X 9 sudoku, read by rows.
sage: s.is_finite() # optional -- internet
True
sage: f = oeis(45) ; f # optional -- internet
A000045: Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.
sage: f.is_finite() # optional -- internet
Unknown
TESTS:
sage: s = oeis._imaginary_sequence()
sage: s.is_finite()
Unknown
sage: s = oeis._imaginary_sequence('nonn,finit')
sage: s.is_finite()
True
Tells whether the sequence self is full, that is, if all its elements are listed in self.first_terms().
Currently, OEIS only provides a keyword when the sequence is known to be full. So, when this keyword is not there, we do not know whether some elements are missing or not.
OUTPUT:
EXAMPLES:
sage: s = oeis('A114288') ; s # optional -- internet
A114288: Lexicographically minimal solution of any 9 X 9 sudoku, read by rows.
sage: s.is_full() # optional -- internet
True
sage: f = oeis(45) ; f # optional -- internet
A000045: Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.
sage: f.is_full() # optional -- internet
Unknown
TESTS:
sage: s = oeis._imaginary_sequence()
sage: s.is_full()
Unknown
sage: s = oeis._imaginary_sequence('nonn,full,finit')
sage: s.is_full()
True
Return the keywords associated to the sequence self.
OUTPUT:
EXAMPLES:
sage: f = oeis(45) ; f # optional -- internet
A000045: Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.
sage: f.keywords() # optional -- internet
('core', 'nonn', 'easy', 'nice', 'changed')
TESTS:
sage: s = oeis._imaginary_sequence()
sage: s.keywords()
('sign', 'easy')
sage: s = oeis._imaginary_sequence(keywords='nonn,hard')
sage: s.keywords()
('nonn', 'hard')
Return, display or browse links associated to the sequence self.
INPUT:
OUTPUT:
EXAMPLES:
sage: f = oeis(45) ; f # optional -- internet
A000045: Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.
sage: f.links(format='url') # optional -- internet
0: http://oeis.org/A000045/b000045.txt
1: http://www.schoolnet.ca/vp-pv/amof/e_fiboI.htm
...
sage: f.links(format='raw') # optional -- internet
0: N. J. A. Sloane, <a href="/A000045/b000045.txt">The first 2000 Fibonacci numbers: Table of n, F(n) for n = 0..2000</a>
1: Amazing Mathematical Object Factory, <a href="http://www.schoolnet.ca/vp-pv/amof/e_fiboI.htm">Information on the Fibonacci sequences</a>
...
TESTS:
sage: s = oeis._imaginary_sequence()
sage: s.links(format='raw')[2]
'Do not confuse with the sequence <a href="/A000042">A000042</a> or the sequence <a href="/A000024">A000024</a>'
sage: s.links(format='url')[3]
'http://oeis.org/A000024'
sage: s.links(format="html")
<html><font color='black'>0: Wikipedia, <a href="http://en.wikipedia.org/wiki/42_(number)">42 (number)</a>
1: See. also <a href="http://trac.sagemath.org/sage_trac/ticket/42">trac ticket #42</a>
...
Return the name of the sequence self.
OUTPUT:
EXAMPLES:
sage: f = oeis(45) ; f # optional -- internet
A000045: Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.
sage: f.name() # optional -- internet
'Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.'
TESTS:
sage: s = oeis._imaginary_sequence()
sage: s.name()
'The opposite of twice the characteristic sequence of 42 plus one, starting from 38.'
Return the natural object associated to the sequence self.
OUTPUT:
number, returns the associated real number (as an element of RealLazyField()).
continued fraction, returns the associated continued fraction (as an element of ContinuedFractionField()).
Warning
This method forgets the fact that the returned sequence may not be complete.
Todo
EXAMPLES:
sage: g = oeis("A002852") ; g # optional -- internet
A002852: Continued fraction for Euler's constant (or Euler-Mascheroni constant) gamma.
sage: x = g.natural_object() ; x.parent() # optional -- internet
Field of all continued fractions
sage: x[:20] == continued_fraction(euler_gamma, nterms=20) # optional -- internet
True
sage: ee = oeis('A001113') ; ee # optional -- internet
A001113: Decimal expansion of e.
sage: x = ee.natural_object() ; x # optional -- internet
2.718281828459046?
sage: x.parent() # optional -- internet
Real Lazy Field
sage: x == RR(e) # optional -- internet
True
sage: av = oeis('A087778') ; av # optional -- internet
A087778: Decimal expansion of Avogadro's constant.
sage: av.natural_object() # optional -- internet
6.022141000000000?e23
sage: fib = oeis('A000045') ; fib # optional -- internet
A000045: Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.
sage: x = fib.natural_object() ; x.parent() # optional -- internet
Category of sequences in Non negative integer semiring
sage: sfib = oeis('A039834') ; sfib # optional -- internet
A039834: a(n+2)=-a(n+1)+a(n) (signed Fibonacci numbers); or Fibonacci numbers (A000045) extended to negative indices.
sage: x = sfib.natural_object() ; x.parent() # optional -- internet
Category of sequences in Integer Ring
TESTS:
sage: s = oeis._imaginary_sequence('nonn,cofr')
sage: s.natural_object().parent()
Field of all continued fractions
sage: s = oeis._imaginary_sequence('nonn')
sage: s.natural_object().parent()
Category of sequences in Non negative integer semiring
sage: s = oeis._imaginary_sequence()
sage: s.natural_object().parent()
Category of sequences in Integer Ring
Return the offsets of the sequence self.
The first offset is the subscript of the first term in the sequence self. When, the sequence represents the decimal expansion of a real number, it corresponds to the number of digits of its integer part.
The second offset is the first term in the sequence self (starting from 1) whose absolute value is greater than 1. This is set to 1 if all the terms are 0 or +-1.
OUTPUT:
EXAMPLES:
sage: f = oeis(45) ; f # optional -- internet
A000045: Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.
sage: f.offsets() # optional -- internet
(0, 4)
sage: f.first_terms()[:4] # optional -- internet
(0, 1, 1, 2)
TESTS:
sage: s = oeis._imaginary_sequence()
sage: s.offsets()
(38, 4)
Returns the IDs of the sequence self corresponding to ancestors of OEIS.
OUTPUT:
EXAMPLES:
sage: f = oeis(45) ; f # optional -- internet
A000045: Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.
sage: f.old_IDs() # optional -- internet
('M0692', 'N0256')
TESTS:
sage: s = oeis._imaginary_sequence()
sage: s.old_IDs()
('M9999', 'N9999')
Returns programs implementing the sequence self in the given language.
INPUT:
OUTPUT:
Todo
ask OEIS to add a “Sage program” field in the database ;)
EXAMPLES:
sage: ee = oeis('A001113') ; ee # optional -- internet
A001113: Decimal expansion of e.
sage: ee.programs()[0] # optional -- internet
'(PARI) { default(realprecision, 50080); x=exp(1); for (n=1, 50000, d=floor(x); x=(x-d)*10; write("b001113.txt", n, " ", d)); } [From Harry J. Smith, Apr 15 2009]'
TESTS:
sage: s = oeis._imaginary_sequence()
sage: s.programs()
0: (Python)
1: def A999999(n):
2: assert(isinstance(n, (int, Integer))), "n must be an integer."
3: if n < 38:
4: raise ValueError("The value %s is not accepted." %str(n)))
5: elif n == 42:
6: return -1
7: else:
8: return 1
sage: s.programs('maple')
0: Do not even try, Maple is not able to produce such a sequence.
sage: s.programs('mathematica')
0: Mathematica neither.
Return the raw entry of the sequence self, in the OEIS format.
OUTPUT:
EXAMPLES:
sage: f = oeis(45) ; f # optional -- internet
A000045: Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.
sage: print f.raw_entry() # optional -- internet
%I A000045 M0692 N0256
%S A000045 0,1,1,2,3,5,8,13,21,34,55,89,144,...
%T A000045 10946,17711,28657,46368,...
...
TESTS:
sage: s = oeis._imaginary_sequence()
sage: s.raw_entry() == oeis._imaginary_entry('sign,easy')
True
Return a tuple of references associated to the sequence self.
OUTPUT:
EXAMPLES:
sage: w = oeis(7540) ; w # optional -- internet
A007540: Wilson primes: primes p such that (p-1)! == -1 (mod p^2).
sage: w.references() # optional -- internet
0: A. H. Beiler, Recreations in the Theory of Numbers, Dover, NY, 1964, p. 52.
1: C. Clawson, Mathematical Mysteries, Plenum Press, 1996, p. 180.
2: Edgar Costa, Robert Gerbicz, and David Harvey, <a href="http://arxiv.org/abs/1209.3436">A search for Wilson primes</a>, 2012
...
sage: _[0] # optional -- internet
'A. H. Beiler, Recreations in the Theory of Numbers, Dover, NY, 1964, p. 52.'
TESTS:
sage: s = oeis._imaginary_sequence()
sage: s.references()[1]
'Lewis Carroll, The Hunting of the Snark.'
Display most available informations about the sequence self.
EXAMPLES:
sage: s = oeis(12345) # optional -- internet
sage: s.show() # optional -- internet
ID
A012345
NAME
sinh(arcsin(x)*arcsin(x))=2/2!*x^2+8/4!*x^4+248/6!*x^6+11328/8!*x^8...
FIRST TERMS
(2, 8, 248, 11328, 849312, 94857600, 14819214720, 3091936512000, ...
KEYWORDS
('nonn',)
OFFSETS
(0, 1)
URL
http://oeis.org/A012345
AUTHOR
Patrick Demichel (patrick.demichel(AT)hp.com)
TESTS:
sage: s = oeis._imaginary_sequence()
sage: s.show()
ID
A999999
NAME
The opposite of twice the characteristic sequence of 42 plus ...
FIRST TERMS
(1, 1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...
COMMENTS
0: 42 is the product of the first 4 prime numbers, except ...
1: Apart from that, i have no comment.
...
Return the URL of the page associated to the sequence self.
OUTPUT:
EXAMPLES:
sage: f = oeis(45) ; f # optional -- internet
A000045: Fibonacci numbers: F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.
sage: f.url() # optional -- internet
'http://oeis.org/A000045'
TESTS:
sage: s = oeis._imaginary_sequence()
sage: s.url()
'http://oeis.org/A999999'
x.__init__(...) initializes x; see help(type(x)) for signature