Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Thue–Morse sequence
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Characterization using bitwise negation === The Thue–Morse sequence in the form given above, as a sequence of [[bit]]s, can be defined [[recursion|recursively]] using the operation of [[bitwise negation]]. So, the first element is 0. Then once the first 2<sup>''n''</sup> elements have been specified, forming a string ''s'', then the next 2<sup>''n''</sup> elements must form the bitwise negation of ''s''. Now we have defined the first 2<sup>''n''+1</sup> elements, and we recurse. Spelling out the first few steps in detail: * We start with 0. * The bitwise negation of 0 is 1. * Combining these, the first 2 elements are 01. * The bitwise negation of 01 is 10. * Combining these, the first 4 elements are 0110. * The bitwise negation of 0110 is 1001. * Combining these, the first 8 elements are 01101001. * And so on. So * ''T''<sub>0</sub> = 0. * ''T''<sub>1</sub> = 01. * ''T''<sub>2</sub> = 0110. * ''T''<sub>3</sub> = 01101001. * ''T''<sub>4</sub> = 0110100110010110. * ''T''<sub>5</sub> = 01101001100101101001011001101001. * ''T''<sub>6</sub> = 0110100110010110100101100110100110010110011010010110100110010110. * And so on. In [[Python (programming language)|Python]]: <syntaxhighlight lang="python"> def thue_morse_bits(n): """Return an int containing the first 2**n bits of the Thue-Morse sequence, low-order bit 1st.""" bits = 0 for i in range(n): bits |= ((1 << (1 << i)) - 1 - bits) << (1 << i) return bits </syntaxhighlight> Which can then be converted to a (reversed) string as follows: <syntaxhighlight lang="python"> n = 7 print(f"{thue_morse_bits(n):0{1<<n}b}") </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)