Hacker News new | past | comments | ask | show | jobs | submit login
De Bruijn Sequences (2011) [video] (youtube.com)
46 points by Flamingo94 on Nov 1, 2020 | hide | past | favorite | 18 comments



A popular mnemonic for remembering the formulae of the basic units of Sanskrit metre is probably the first ever recorded example of De Bruijn Sequence. The phrase "Ya-Maa-Taa-Raa-Ja-Bhaa-Na-Sa-La-Gam" encodes all 8 possible combinations of syllables of length 3.

The basic unit of Sanskrit metre is called Gana and is composed of 3 syllables. Since a syllable can be either short (I) or long (U), we have 2^3 = 8 Ganas in total corresponding to UUU, UUI, UIU etc. To know the composition of a specific Gana say for example Ja Gana, one has to find the index of "Ja" in the aforementioned phrase and extract the next two syllables as well so Ja Gana equals Ja-Bhaa-Na => IUI (because Ja is short, Bhaa is long and Na is short again).

Code in Python if my explanation wasn't clear

  mnemonic = "Ya-Maa-Taa-Raa-Ja-Bhaa-Na-Sa-La-Gaam"

  def symbol(syllable):
      if syllable.count("a") == 1:
        return "I"
   else:
        return "U"

  def ganaSymbol(ganaName):
      mnerray = mnemonic.split("-")
      ganaIndex = mnerray.index(ganaName)
      return "".join([symbol(syllable) for syllable in mnerray[ganaIndex : ganaIndex + 3]])
Metres are then defined in terms of Ganas and the number of lines in a stanza, for example Utpala Mala metre can be defined simply as Na-Ja-Bhaa-Ja-Ja-Ja-Raa, 4 which means a stanza in that meter should comprise of 4 lines, with each line having 21 syllables corresponding to Na-Ja-Bhaa-Ja-Ja-Ja-Raa sequence

  utpalaMala = "Na-Ja-Bhaa-Ja-Ja-Ja-Raa"

  def printMetre(metreGanas, numLines):
    print("\n".join(["".join([ganaSymbol(ganaName) for ganaName in metreGanas.split("-")])]*numLines))

Edits: Formatting


Funnily enough, I learned of this mnemonic from TAOCP (I think; too lazy to go check now).


Interesting to know that. I've heard the books on Combinatorics in TAOCP are super fun with many interesting mathematical nuggets. About time I get a copy of those volumes.


A surprising bit twiddling trick[0] uses a De Bruijn sequence to calculate log base 2.

[0] https://graphics.stanford.edu/~seander/bithacks.html#Integer...


The colored variant of a De Bruijin graph is used extensive for high throughput sequencing alignment, assembly or quantification. For example, Pufferfish [1] has worked towards an efficient and compact index of these graphs.

[1] https://github.com/COMBINE-lab/pufferfish


A colleague and I used De Bruijn sequences as test input for comparing matches on recursively generated regexes between PCRE and our own regex engine. The sequence was guaranteed to give us a search hit regardless of the pattern so it was a nice way to control for good testing results.


I've found de bruijn sequences useful for generating test inputs, where you want to make sure every state transition is checked.


First time I came across this was when I was reading a chapter on genome assembly in a bioinformatics algorithms book. It seemed like such a great solution until it got to the section about practical complications with DNA sequencing: sequencing errors, the fact that that their are 2 strings being assembled (double stranded DNA), repeats in the genome, etc..


You've basically summarized the field.


Unfortunately, I can't find a reference at the moment, but there are two American mathematicians who perform card tricks in class and one of these tricks uses a de Bruijn sorted deck to allow to cut the deck many times and still be able to do the magic afterwards.


I figured one of the two had to be Persi Diaconis, and it looks like I wasn't far off the mark:

https://golem.ph.utexas.edu/category/2015/01/mathematics_and...

If I did get it right, Ron Graham as the second mathematician makes perfect sense too :)


Thanks, that is exactly the one!


De Bruijn sequences are useful in neuroimaging, too. My former lab: https://cfn.upenn.edu/aguirre/wiki/public:de_bruijn


I watched the video hoping to learn how to finally pronounce "de bruijin"


That's why someone invented Youglish [0]. However, I mostly use that site for words I know how to pronounce correctly, but have no idea how people expect them to be pronounced in their language. Did you know you are supposed to explicitly pronounce the "d" of LinkedIn in Spanish?

[0] https://youglish.com/pronounce/de%20%20Bruijn/dutch?


TIL about Youglish. Tested with Japanese, Portuguese, Spanish. All returned good examples! Thanks a lot, bookmarked! (obviously, also confirmed how to say de Brujin in Dutch!)


You also pronounce the "e". In most languages you pronounce the letter just because it's written.


Very nice video, though unbelievable that the presenter wrote out that 10,000 number solution in his notebook while he has a computer on his desk.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: