In mathematics, a Stanley sequence is an
integer sequence
In mathematics, an integer sequence is a sequence (i.e., an ordered list) of integers.
An integer sequence may be specified ''explicitly'' by giving a formula for its ''n''th term, or ''implicitly'' by giving a relationship between its terms. Fo ...
generated by a
greedy algorithm
A greedy algorithm is any algorithm that follows the problem-solving heuristic of making the locally optimal choice at each stage. In many problems, a greedy strategy does not produce an optimal solution, but a greedy heuristic can yield locall ...
that chooses the sequence members to avoid
arithmetic progression
An arithmetic progression or arithmetic sequence () is a sequence of numbers such that the difference between the consecutive terms is constant. For instance, the sequence 5, 7, 9, 11, 13, 15, . . . is an arithmetic progression with a common differ ...
s. If
is a finite set of non-negative integers on which no three elements form an arithmetic progression (that is, a
Salem–Spencer set), then the Stanley sequence generated from
starts from the elements of
, in sorted order, and then repeatedly chooses each successive element of the sequence to be a number that is larger than the already-chosen numbers and does not form any three-term arithmetic progression with them.
These sequences are named after
Richard P. Stanley.
Binary–ternary sequence
The Stanley sequence starting from the empty set consists of those numbers whose
ternary representations have only the digits 0 and 1. That is, when written in ternary, they look like
binary number
A binary number is a number expressed in the base-2 numeral system or binary numeral system, a method of mathematical expression which uses only two symbols: typically "0" ( zero) and "1" (one).
The base-2 numeral system is a positional notati ...
s. These numbers are
:0, 1, 3, 4, 9, 10, 12, 13, 27, 28, 30, 31, 36, 37, 39, 40, ...
By their construction as a Stanley sequence, this sequence is the
lexicographically
In mathematics, the lexicographic or lexicographical order (also known as lexical order, or dictionary order) is a generalization of the alphabetical order of the dictionaries to sequences of ordered symbols or, more generally, of elements of ...
first
arithmetic-progression-free sequence. Its elements are the sums of distinct
powers of three, the numbers
such that the
th central binomial coefficient is 1 mod 3, and the numbers whose
balanced ternary
Balanced ternary is a ternary numeral system (i.e. base 3 with three digits) that uses a balanced signed-digit representation of the integers in which the digits have the values −1, 0, and 1. This stands in contrast to the standard (unbalanc ...
representation is the same as their ternary representation.
The construction of this sequence from the ternary numbers is analogous to the construction of the
Moser–de Bruijn sequence
In number theory, the Moser–de Bruijn sequence is an integer sequence named after Leo Moser and Nicolaas Govert de Bruijn, consisting of the sums of distinct powers of 4, or equivalently the numbers whose binary representations are nonzero ...
, the sequence of numbers whose base-4 representations have only the digits 0 and 1, and the construction of the
Cantor set
In mathematics, the Cantor set is a set of points lying on a single line segment that has a number of unintuitive properties. It was discovered in 1874 by Henry John Stephen Smith and introduced by German mathematician Georg Cantor in 1883.
T ...
as the subset of real numbers in the interval