请输入您要查询的百科知识:

 

词条 De Bruijn sequence
释义

  1. History

  2. Examples

  3. Construction

     Example using de Bruijn graph   Example using inverse Burrows—Wheeler transform   Algorithm 

  4. Uses

  5. f-fold de Bruijn sequences

  6. De Bruijn torus

  7. De Bruijn decoding

  8. See also

  9. Notes

  10. References

  11. External links

In combinatorial mathematics, a de Bruijn sequence of order n on a size-k alphabet A is a cyclic sequence in which every possible length-n string on A occurs exactly once as a substring (i.e., as a contiguous subsequence). Such a sequence is denoted by {{nowrap|B(k, n)}} and has length kn, which is also the number of distinct substrings of length n on A; de Bruijn sequences are therefore optimally short. There are distinct de Bruijn sequences {{nowrap|B(k, n)}}.

The sequences are named after the Dutch mathematician Nicolaas Govert de Bruijn. According to him,[1] the existence of de Bruijn sequences for each order together with the above properties were first proved, for the case of alphabets with two elements, by Camille Flye Sainte-Marie in 1894,[2] whereas the generalization to larger alphabets is originally due to Tatyana van Aardenne-Ehrenfest and himself.

In most applications, A = {0,1}.

History

The earliest known example of a de Bruijn sequence comes from Sanskrit prosody where, since the work of Pingala, each possible three-syllable pattern of long and short syllables is given a name, such as 'y' for short–long–long and 'm' for long–long–long. To remember these names, the mnemonic yamātārājabhānasalagām is used, in which each three-syllable pattern occurs starting at its name: 'yamātā' has a short–long–long pattern, 'mātārā' has a long–long–long pattern, and so on, until 'salagām' which has a short–short–long pattern. This mnemonic, equivalent to a de Bruijn sequence on binary 3-tuples, is of unknown antiquity, but is at least as old as Charles Philip Brown's 1869 book on Sanskrit prosody that mentions it and considers it "an ancient line, written by Pāṇini".[3][4][5][6][7]

In 1894, A. de Rivière raised the question in an issue of the French problem journal L'Intermédiaire des Mathématiciens, of the existence of a circular arrangement of zeroes and ones of size that contains all binary sequences of length . The problem was solved (in the affirmative), along with the count of distinct solutions, by Camille Flye Sainte-Marie in the same year.[1] This was largely forgotten, and {{harvtxt|Martin|1934}} proved the existence of such cycles for general alphabet size in place of 2, with an algorithm for constructing them. Finally, when in 1944 Kees Posthumus conjectured the count for binary sequences, de Bruijn proved the conjecture in 1946, through which the problem became well-known.[1]

Karl Popper independently describes these objects in his The Logic of Scientific Discovery (1934), calling them "shortest random-like sequences".[8]

Examples

  • Taking A = {0, 1}, there are two distinct B(2, 3): 00010111 and 11101000, one being the reverse or negation of the other.
  • Two of the 2048 possible B(2, 5) in the same alphabet are 00000100011001010011101011011111 and 00000101001000111110111001101011.

Construction

The de Bruijn sequences can be constructed by taking a Hamiltonian path of an n-dimensional de Bruijn graph over k symbols (or equivalently, an Eulerian cycle of an (n − 1)-dimensional de Bruijn graph).[9]

An alternative construction involves concatenating together, in lexicographic order, all the Lyndon words whose length divides n.[10]

An inverse Burrows—Wheeler transform can be used to generate the required Lyndon words in lexicographic order.[11]

De Bruijn sequences can also be constructed using shift registers[12] or via finite fields.[13]

Example using de Bruijn graph

Goal: to construct a B(2, 4) de Bruijn sequence of length 24 = 16 using Eulerian (n − 1 = 4 − 1 = 3) 3-D de Bruijn graph cycle.

Each edge in this 3-dimensional de Bruijn graph corresponds to a sequence of four digits: the three digits that label the vertex that the edge is leaving followed by the one that labels the edge. If one traverses the edge labeled 1 from 000, one arrives at 001, thereby indicating the presence of the subsequence 0001 in the de Bruijn sequence. To traverse each edge exactly once is to use each of the 16 four-digit sequences exactly once.

For example, suppose we follow the following Eulerian path through these vertices:

000, 000, 001, 011, 111, 111, 110, 101, 011,

110, 100, 001, 010, 101, 010, 100, 000.

These are the output sequences of length k:

0 0 0 0

_ 0 0 0 1

_ _ 0 0 1 1

This corresponds to the following de Bruijn sequence:

0 0 0 0 1 1 1 1 0 1 1 0 0 1 0 1

The eight vertices appear in the sequence in the following way:

       {0  0  0  0} 1  1  1  1  0  1  1  0  0  1  0  1        0 {0  0  0  1} 1  1  1  0  1  1  0  0  1  0  1        0  0 {0  0  1  1} 1  1  0  1  1  0  0  1  0  1        0  0  0 {0  1  1  1} 1  0  1  1  0  0  1  0  1        0  0  0  0 {1  1  1  1} 0  1  1  0  0  1  0  1        0  0  0  0  1 {1  1  1  0} 1  1  0  0  1  0  1        0  0  0  0  1  1 {1  1  0  1} 1  0  0  1  0  1        0  0  0  0  1  1  1 {1  0  1  1} 0  0  1  0  1        0  0  0  0  1  1  1  1 {0  1  1  0} 0  1  0  1        0  0  0  0  1  1  1  1  0 {1  1  0  0} 1  0  1        0  0  0  0  1  1  1  1  0  1 {1  0  0  1} 0  1        0  0  0  0  1  1  1  1  0  1  1 {0  0  1  0} 1        0  0  0  0  1  1  1  1  0  1  1  0 {0  1  0  1}        0} 0  0  0  1  1  1  1  0  1  1  0  0 {1  0  1 ...    ... 0  0} 0  0  1  1  1  1  0  1  1  0  0  1 {0  1 ...    ... 0  0  0} 0  1  1  1  1  0  1  1  0  0  1  0 {1 ...

...and then we return to the starting point. Each of the eight 3-digit sequences (corresponding to the eight vertices) appears exactly twice, and each of the sixteen 4-digit sequences (corresponding to the 16 edges) appears exactly once.

Example using inverse Burrows—Wheeler transform

Mathematically, an inverse Burrows—Wheeler transform on a word w generates a multi-set of equivalence classes consisting of strings and their rotations.[11] These equivalence classes of strings each contain a Lyndon word as a unique minimum element, so the inverse Burrows—Wheeler transform can be considered to generate a set of Lyndon words. It can be shown that if we perform the inverse Burrows—Wheeler transform on a word w consisting of the size-k alphabet repeated kn-1 times (so that it will produce a word the same length as the desired de Bruijn sequence), then the result will be the set of all Lyndon words whose length divides n. It follows that arranging these Lyndon words in lexicographic order will yield a de Bruijn sequence B(k,n), and that this will be the first de Bruijn sequence in lexicographic order. The following method can be used to perform the inverse Burrows—Wheeler transform, using its standard permutation:

  1. Sort the characters in the string w, yielding a new string w
  2. Position the string w' above the string w, and map each letter's position in w' to its position in w while preserving order. This process defines the standard permutation.
  3. Write this permutation in cycle notation with the smallest position in each cycle first, and the cycles sorted in increasing order.
  4. For each cycle, replace each number with the corresponding letter from string w in that position.
  5. Each cycle has now become a Lyndon word, and they are arranged in lexicographic order, so dropping the parentheses yields the first de Bruijn sequence.

For example, to construct the smallest B(2,4) de Bruijn sequence of length 24 = 16, repeat the alphabet (ab) 8 times yielding w=abababababababab. Sort the characters in w, yielding w'=aaaaaaaabbbbbbbb. Position w' above w as shown, and map each element in w' to the corresponding element in w by drawing a line. Number the columns as shown so we can read the cycles of the permutation:

Starting from the left, the cycles are: (1) (2 3 5 9) (4 7 13 10) (6 11) (8 15 14 12) (16).

Then, replacing each number by the corresponding letter in w' from that column yields: (a)(aaab)(aabb)(ab)(abbb)(b).

These are all of the Lyndon words whose length divides 4, in lexicographic order, so dropping the parentheses gives B(2,4) = aaaabaabbababbbb.

Algorithm

The following Python code calculates a de Bruijn sequence, given k and n, based on an algorithm from Frank Ruskey's Combinatorial Generation.[14]

def de_bruijn(k, n):

    """    de Bruijn sequence for alphabet k    and subsequences of length n.    """    try:        # let's see if k can be cast to an integer;        # if so, make our alphabet a list        _ = int(k)        alphabet = list(map(str, range(k)))
    except (ValueError, TypeError):        alphabet = k        k = len(k)
    a = [0] * k * n    sequence = []
    def db(t, p):        if t > n:            if n % p == 0:                sequence.extend(a[1:p + 1])        else:            a[t] = a[t - p]            db(t + 1, p)            for j in range(a[t - p] + 1, k):                a[t] = j                db(t + 1, t)    db(1, 1)    return "".join(alphabet[i] for i in sequence)

print(de_bruijn(2, 3))

print(de_bruijn("abcd", 2))

which prints

 00010111 aabacadbbcbdccdd

Note that these sequences are understood to "wrap around" in a cycle. For example, the first sequence contains 110 and 100 in this fashion.

Uses

The sequence can be used to shorten a brute-force attack on a PIN-like code lock that does not have an "enter" key and accepts the last n digits entered. For example, a digital door lock with a 4-digit code would have B (10, 4) solutions, with length {{val|10000}}. Therefore, only at most {{nowrap|{{val|10000}} + 3 {{=}} {{val|10003}}}} (as the solutions are cyclic) presses are needed to open the lock. Trying all codes separately would require {{nowrap|4 × {{val|10000}} {{=}} {{val|40000}}}} presses.

The symbols of a de Bruijn sequence written around a circular object (such as a wheel of a robot) can be used to identify its angle by examining the n consecutive symbols facing a fixed point. This angle-encoding problem is known as the "rotating drum problem".[15] Gray codes can be used as similar rotary positional encoding mechanisms.

De Bruijn cycles are of general use in neuroscience and psychology experiments that examine the effect of stimulus order upon neural systems,[16] and can be specially crafted for use with functional magnetic resonance imaging.[17]

A de Bruijn sequence can be used to quickly find the index of the least significant set bit ("right-most 1") or the most significant set bit ("left-most 1") in a word using bitwise operations.[18][19] An example of returning the index of the least significant bit from a 32 bit unsigned integer is given below using bit manipulation and multiplication.

unsigned int v;

int r;

static const int MultiplyDeBruijnBitPosition[32] =

{
  0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,   31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9

};

r = MultiplyDeBruijnBitPosition[((uint32_t)((v & -v) * 0x077CB531U)) >> 27];

The index of the LSB in v is stored in r and if v has no set bits the operation returns 0. The constant, 0x077CB531U, in the expression is the B (2, 5) sequence 0000 0111 0111 1100 1011 0101 0011 0001 (spaces added for clarity).

f-fold de Bruijn sequences

f-fold n-ary de Bruijn sequence' is an extension of the notion n-ary de Bruijn sequence, such that the sequence of the length contains every possible subsequence of the length n exactly f times. For example, for the cyclic sequences 11100010 and 11101000 are two-fold binary de Bruijn sequences. The number of two-fold de Bruijn sequences, for is , the other known numbers[20] are , , and .

De Bruijn torus

{{main article|De Bruijn torus}}

A de Bruijn torus is a toroidal array with the property that every k-ary m-by-n matrix occurs exactly once.

Such a pattern can be used for two-dimensional positional encoding in a fashion analogous to that described above for rotary encoding. Position can be determined by examining the m-by-n matrix directly adjacent to the sensor, and calculating its position on the de Bruijn torus.

De Bruijn decoding

Computing the position of a particular unique tuple or matrix in a de Bruijn sequence or torus is known as the de Bruijn Decoding Problem. Efficient {{nowrap|O(n log n)}} decoding algorithms exist for special, recursively constructed sequences[21] and extend to the two dimensional case.[22] De Bruijn decoding is of interest, e.g., in cases where large sequences or tori are used for positional encoding.

See also

  • De Bruijn graph
  • De Bruijn torus
  • Normal number
  • Linear feedback shift register
  • n-sequence

Notes

1. ^{{harvtxt|de Bruijn|1975}}.
2. ^{{cite journal |author-last=Flye Sainte-Marie |author-first=Camille |journal=L'Intermédiaire des Mathématiciens |pages=107–110 |title=Solution to question nr. 48 |volume=1 |date=1894}}
3. ^{{cite |author-first=C. P. |author-last=Brown |author-link=C. P. Brown |date=1869 |title=Sanskrit Prosody and Numerical Symbols Explained |url=https://archive.org/stream/sanskritprosody00browgoog#page/n44/mode/2up |page=28}}
4. ^{{cite journal |author-first=Subhash |author-last=Kak |date=2000 |title=Yamātārājabhānasalagāṃ an interesting combinatoric sūtra |url=http://202.41.82.144/rawdataupload/upload/insa/INSA_2/200059d2_123.pdf |dead-url=yes |archive-url=https://web.archive.org/web/20141029120230/http://202.41.82.144/rawdataupload/upload/insa/INSA_2/200059d2_123.pdf |archive-date=2014-10-29 |journal=Indian Journal of History of Science |volume=35 |issue=2 |pages=123–127}}
5. ^{{cite journal |author-first=Rachel W. |author-last=Hall |url=http://www.sju.edu/~rhall/mathforpoets.pdf |title=Math for poets and drummers |journal=Math Horizons |volume=15 |date=2008 |pages=10–11}}
6. ^{{Cite book |date=2006 |title=The Art of Computer Programming, Fascicle 4: Generating All Trees – History of Combinatorial Generation |author-first=Donald Ervin |author-last=Knuth |author-link=Donald Ervin Knuth |publisher=Addison–Wesley |isbn=978-0-321-33570-8 |page=50 |url=https://books.google.com/books?id=56LNfE2QGtYC&pg=PA50}}
7. ^{{citation |author-first=Sherman K. |author-last=Stein |author-link= Sherman K. Stein |contribution=Yamátárájabhánasalagám |date=1963 |title=The Man-made Universe: An Introduction to the Spirit of Mathematics |pages=110–118}}. Reprinted in Wardhaugh, Benjamin, ed. (2012), A Wealth of Numbers: An Anthology of 500 Years of Popular Mathematics Writing, Princeton University Press, pp. 139–144.
8. ^{{cite book |date=2002 |orig-year=1934 |title=The logic of scientific discovery |author-first=Karl |author-last=Popper |author-link=Karl Popper |publisher=Routledge |isbn=978-0-415-27843-0 |page=294 |url=https://books.google.com/books?id=0a5bLBbe_dMC&pg=PA295&cd=1#v=onepage&q=1111000010011010}}
9. ^{{cite book |title=Stream Ciphers |author-first=Andreas |author-last=Klein |publisher=Springer |date=2013 |isbn=978-1-44715079-4 |page=59 |url=https://books.google.com/books?id=GYpEAAAAQBAJ&pg=PA59}}
10. ^According to {{harvtxt|Berstel|Perrin|2007}}, the sequence generated in this way was first described (with a different generation method) by {{harvtxt|Martin|1934}}, and the connection between it and Lyndon words was observed by {{harvtxt|Fredricksen|Maiorana|1978}}.
11. ^{{cite web |url=http://www.macs.hw.ac.uk/~markl/Higgins.pdf |title=Burrows-Wheeler transforms and de Bruijn words |author-last=Higgins |author-first=Peter |date=November 2012 |access-date=2017-02-11}}
12. ^{{cite book |title=Algebraic Shift Register Sequences |author-first1=Mark |author-last1=Goresky |author-first2=Andrew |author-last2=Klapper |publisher=Cambridge University Press |date=2012 |isbn=978-1-10701499-2 |pages=174–175 |url=https://books.google.com/books?id=sd9AqHeeHh4C&pg=PA174 |contribution=8.2.5 Shift register generation of de Bruijn sequences}}
13. ^{{cite journal |author-last=Ralston |author-first=Anthony |doi=10.2307/2690079 |issue=3 |journal=Mathematics Magazine |mr=653429 |pages=131–143 |title=de Bruijn sequences—a model example of the interaction of discrete mathematics and computer science |volume=55 |date=1982}}. (NB. See in particular "the finite field approach", pp. 136–139.)
14. ^{{cite web |title=De Bruijn sequences |url=https://git.sagemath.org/sage.git/tree/src/sage/combinat/debruijn_sequence.pyx |work=Sage |access-date=2016-11-03}}
15. ^{{cite book |title=A Course in Combinatorics |author-first1=J. H. |author-last1=van Lint |author-first2=Richard Michael |author-last2=Wilson |publisher=Cambridge University Press |date=2001 |isbn=978-0-52100601-9 |page=71 |url=https://books.google.com/books?id=5l5ps2JkyT0C&pg=PA71}}
16. ^G. K. Aguirre, M. G. Mattar, L. Magis-Weinberg. (2011) {{cite web |url=https://cfn.upenn.edu/aguirre/wiki/public:de_bruijn |title=de Bruijn cycles for neural decoding}}. NeuroImage 56: 1293–1300
17. ^{{cite web |url=https://cfn.upenn.edu/aguirre/wiki/public:de_bruijn_software |title=De Bruijn cycle generator}}
18. ^{{cite web |url=http://graphics.stanford.edu/~seander/bithacks.html |title=Bit Twiddling Hacks |author-last=Anderson |author-first=Sean Eron |date=1997–2009 |publisher=Stanford University |access-date=2009-02-12}}
19. ^{{cite web |url=http://7ooo.mooo.com/text/ComputingTrailingZerosHOWTO.html |title=Computing Trailing Zeros HOWTO |author-last=Busch |author-first=Philip |date=2009 |access-date=2015-01-29}}
20. ^{{harvtxt|Osipov |2016}}.
21. ^{{harvtxt|Tuliani |2001}}.
22. ^{{harvtxt|Hurlbert|Isaak|1993}}.

References

{{Reflist}}
  • {{cite journal |author-last1=van Aardenne-Ehrenfest |author-first1=Tanja |author-link1=Tatyana Pavlovna Ehrenfest |author-last2=de Bruijn |author-first2=Nicolaas Govert |author-link2=Nicolaas Govert de Bruijn |journal=Simon Stevin |mr=0047311 |pages=203–217 |title=Circuits and trees in oriented linear graphs |url=http://alexandria.tue.nl/repository/freearticles/597493.pdf |volume=28 |date=1951|ref=harv}}
  • {{cite journal |author-last1=Berstel |author-first1=Jean |author-last2=Perrin |author-first2=Dominique |doi=10.1016/j.ejc.2005.07.019 |mr=2300777 |issue=3 |journal=European Journal of Combinatorics |pages=996–1022 |title=The origins of combinatorics on words |url=http://www-igm.univ-mlv.fr/~berstel/Articles/2007Origins.pdf |volume=28 |date=2007|ref=harv}}
  • {{cite journal |author-last=de Bruijn |author-first=Nicolaas Govert |author-link=Nicolaas Govert de Bruijn |journal=Proc. Koninklijke Nederlandse Akademie v. Wetenschappen |mr=0018142 |pages=758–764 |title=A combinatorial problem |url=http://www.dwc.knaw.nl/DL/publications/PU00018235.pdf |volume=49 |date=1946 |postscript=, Indagationes Mathematicae 8: 461–467|ref=harv}}
  • {{cite journal |author-last=de Bruijn |author-first=Nicolaas Govert |author-link=Nicolaas Govert de Bruijn |publisher=Technological University Eindhoven |series=T.H.-Report 75-WSK-06 |title=Acknowledgement of Priority to C. Flye Sainte-Marie on the counting of circular arrangements of 2n zeros and ones that show each n-letter word exactly once |url=http://alexandria.tue.nl/repository/books/252901.pdf |date=1975|ref=harv}}
  • {{cite journal |author-last1=Fredricksen |author-first1=Harold |author-last2=Maiorana |author-first2=James |doi=10.1016/0012-365X(78)90002-X |mr=523071 |issue=3 |journal=Discrete Mathematics |pages=207–210 |title=Necklaces of beads in k colors and k-ary de Bruijn sequences |volume=23 |date=1978|ref=harv}}
  • {{cite journal |author-last1=Hurlbert |author-first1=Glenn |author-last2=Isaak |author-first2=Garth |doi=10.1016/0097-3165(93)90087-O |issue=1 |journal=Journal of Combinatorial Theory |series=Series A |mr=1239511 |pages=50–62 |title=On the de Bruijn torus problem |url=http://math.la.asu.edu/~hurlbert/papers/DBTP.pdf |volume=64 |date=1993|ref=harv}}
  • {{cite journal |author-last=Martin |author-first=M. H. |doi=10.1090/S0002-9904-1934-05988-3 |mr=1562989 |issue=12 |journal=Bulletin of the American Mathematical Society |pages=859–864 |title=A problem in arrangements |url=http://www.ams.org/journals/bull/1934-40-12/S0002-9904-1934-05988-3/S0002-9904-1934-05988-3.pdf |volume=40 |date=1934|ref=harv}}
  • {{cite journal |author-last=Ralston |author-first=Anthony |doi=10.2307/2690079 |issue=3 |journal=Mathematics Magazine |mr=653429 |pages=131–143 |title=de Bruijn sequences—a model example of the interaction of discrete mathematics and computer science |volume=55 |date=1982|ref=harv}}
  • {{cite journal |author-last=Tuliani |author-first=Jonathan |doi=10.1016/S0012-365X(00)00117-5 |issue=1-3 |journal=Discrete Mathematics |mr=1802599 |pages=313–336 |title=de Bruijn sequences with efficient decoding algorithms |volume=226 |date=2001|ref=harv}}
  • {{cite journal |author-last=Osipov |author-first=Vladimir |doi=10.1007/s10955-016-1537-5 |journal=Journal of Statistical Physics |pages=1–24 |title=Wavelet Analysis on Symbolic Sequences and Two-Fold de Bruijn Sequences |issn=1572-9613 |url=https://dx.doi.org/10.1007/s10955-016-1537-5 |date=2016|ref=harv|arxiv=1601.02097 |bibcode=2016JSP...164..142O }}
  • {{cite book |author-first1=Megan |author-last1=Dewar |author-first2=Brett |author-last2=Stevens |title=Ordering Block Designs - Gray Codes, Universal Cycles and Configuration |publisher=Springer Science+Business Media |location=New York, USA |edition=1 |date=2012-08-29 |isbn=978-1-46144324-7 |id={{ISBN|1-46144324-5}} |series=CMS Books in Mathematics |issn=1613-5237 |doi=10.1007/978-1-4614-4325-4|ref=harv}}

External links

  • {{MathWorld|urlname=deBruijnSequence|title=de Bruijn Sequence}}
  • {{OEIS el|sequencenumber=A166315|name=Lexicographically smallest binary de Bruijn sequences|formalname= Lexicographically earliest binary de Bruijn sequences, B(2,n)}}
  • De Bruijn sequence
  • Combinatorial Object Server, includes a de Bruijn sequence generator among many others
  • CGI generator
  • Applet generator
  • [https://jgeisler0303.github.io/deBruijnDecode/ Javascript generator and decoder]. Implementation of J. Tuliani's algorithm.
  • Door code lock
  • [https://web.archive.org/web/20140527202958/http://lcni.uoregon.edu/~dow/Geek_art/Minimal_combinatorics/Minimal_arrays_containing_all_combinations.html Minimal arrays containing all sub-array combinations of symbols: De Bruijn sequences and tori]
{{DEFAULTSORT:Bruijn sequence, de}}

3 : Binary sequences|Enumerative combinatorics|Articles with example Python code

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/9/20 21:20:02