Bit-reversal permutation: Difference between revisions

Content deleted Content added
Applications: Added reference
Tag: Reverted
m Reverted edit by Mepperelf (talk) to last version by Joe in Australia
 
(33 intermediate revisions by 12 users not shown)
Line 1:
{{Short description|Permutation that reverses binary numbers}}
In applied mathematics, a '''bit-reversal permutation''' is a [[permutation]] of a [[sequence]] of ''n'' items, where ''n''&nbsp;=&nbsp;2<sup>''k''</sup> is a [[power of two]]. It is defined by indexing the elements of the sequence by the numbers from 0 to ''n''&nbsp;&minus;&nbsp;1 and then reversing the [[binary representation]]s of each of these numbers (padded so that each of these binary numbers has length exactly&nbsp;''k''). Each item is then mapped to the new position given by this reversed value. The bit reversal permutation is an [[Involution (mathematics)|involution]], so repeating the same permutation twice returns to the original ordering on the items.
[[File:Hammersley set 2D.svg|thumb|A [[Hammersley set]] whose coordinates are the integers from 0 to 255 and their bit-reversals]]
In applied mathematics, a '''bit-reversal permutation''' is a [[permutation]] of a [[sequence]] of ''<math>n''</math> items, where ''<math>n''&nbsp;=&nbsp;2<sup>''^k''</supmath> is a [[power of two]]. It is defined by indexing the elements of the sequence by the numbers from <math>0</math> to ''<math>n''&nbsp;&minus;&nbsp;-1</math>, andrepresenting theneach reversingof thethese numbers by its [[binary representation]]s of each of these numbers (padded soto that each of these binary numbers hashave length exactly&nbsp;'' <math>k''</math>)., Eachand itemmapping iseach then mappeditem to the newitem positionwhose givenrepresentation by this reversed value. The bit reversal permutation is an [[Involution (mathematics)|involution]], so repeatinghas the same permutationbits twice returns toin the originalreversed ordering on the itemsorder.
 
Repeating the same permutation twice returns to the original ordering on the items, so the bit reversal permutation is an [[Involution (mathematics)|involution]].
 
This permutation can be applied to any sequence in [[linear time]] while performing only simple index calculations. It has applications in the generation of [[low-discrepancy sequence]]s and in the evaluation of [[fast Fourier transform]]s.
Line 7 ⟶ 11:
Thus, the letter ''a'' in position 000 is mapped to the same position (000), the letter ''b'' in position 001 is mapped to the fifth position (the one numbered 100), etc., giving the new sequence ''{{not a typo|aecgbfdh}}''. Repeating the same permutation on this new sequence returns to the starting sequence.
 
Writing the index numbers in decimal (but, as above, starting with position 0 rather than the more conventional start of 1 for a permutation), the bit-reversal permutations ofon size 2<supmath>''n=2^k''</supmath> items, for ''<math>k''&nbsp;=&nbsp;0, 1, 2, 3, ...\dots</math>, are:<ref>{{cite OEIS|A030109|mode=cs2}}</ref>
{| class="wikitable" style="text-align: center;"
* k = 0: 0
|-
* k = 1: 0 1
! <math>k</math> !! <math>n=2^k</math> !! permutation
* k = 2: 0 2 1 3
|-
* k = 3: 0 4 2 6 1 5 3 7
| 0 || 1 || 0
* k = 4: 0 8 4 12 2 10 6 14 1 9 5 13 3 11 7 15
|-
{{OEIS|A030109}}<br>
*| k1 =|| 1:2 || 0 1
Each permutation in this sequence can be generated by concatenating two sequences of numbers: the previous permutation, doubled, and the same sequence with each value increased by one.
|-
Thus, for example doubling the length-4 permutation {{nowrap|0 2 1 3}} gives {{nowrap|0 4 2 6}}, adding one gives {{nowrap|1 5 3 7}}, and concatenating these two sequences gives the length-8 permutation {{nowrap|0 4 2 6 1 5 3 7}}.
*| k2 =|| 2:4 || 0 2 1 3
|-
*| k3 =|| 3:8 || 0 4 2 6 1 5 3 7
|-
*| k4 =|| 4:16 || 0 8 4 12 2 10 6 14 1 9 5 13 3 11 7 15
|}
Each permutation in this sequence can be generated by concatenating two sequences of numbers: the previous permutation, with its values doubled, and the same sequence with each value increased by one.
Thus, for example doubling the length-4 permutation {{nowrap|0 2 1 3}} gives {{nowrap|0 4 2 6}}, adding one gives {{nowrap|1 5 3 7}}, and concatenating these two sequences gives the length-8 permutation {{nowrap|0 4 2 6 1 5 3 7}}.<ref name="karp"/>
 
==Generalizations==
The generalization to ''n''&nbsp;=&nbsp;''b''[[radix]] <supmath>''m''b</supmath> representations, for an<math>b arbitrary> integer2</math>, ''and to <math>n=b''&nbsp;^k</math>&nbsp;1, is a [[radix|base]]-''b'' '''digit-reversal permutation''', in which the base-''<math>b'' (radix-''b'')</math> digits of the index of each element are reversed to obtain the permuted index. The same idea can also been generalized to [[mixed radix]] number systems. In such cases, the digit-reversal permutation should simultaneously reverse the digits of each item and the bases of the number system, so that each reversed digit remains within the range defined by its base.<ref>{{citation
| last = Elster | first = Anne C.
A further generalization to arbitrary [[composite number|composite]] sizes is a '''[[mixed-radix]] digit reversal''' (in which the elements of the sequence are indexed by a number expressed in a mixed radix, whose digits are reversed by the permutation).
| contribution = Fast bit-reversal algorithms
| doi = 10.1109/ICASSP.1989.266624
| pages = 1-111099–1102
| title = IEEE International Conference on Acoustics, Speech, and Signal Processing, ICASSP '89, Glasgow, Scotland, May 23-26, 1989
| year = 1989| s2cid = 15028026
}}</ref>
 
Permutations that generalize the bit-reversal permutation by reversing contiguous blocks of bits within the binary representations of their indices can be used to interleave two equal-length sequences of data in-place.<ref>{{citation
Line 25 ⟶ 43:
| last2 = Ellis | first2 = John
| last3 = Mamakani | first3 = Khalegh
| last4 = Ruskey | first4 = Frank | author4-link = Frank Ruskey
| doi = 10.1016/j.ipl.2013.02.017
| issue = 10–11
Line 33 ⟶ 51:
| title = In-place permuting and perfect shuffling using involutions
| volume = 113
| year = 2013}}.</ref>| s2cid = 14672841
| arxiv = 1204.1958
}}.</ref>
 
There are two extensions of the bit-reversal permutation to sequences of arbitrary length. These extensions coincide with bit-reversal for sequences whose length is a power of 2, and their purpose is to separate adjacent items in a sequence for the efficient operation of the [[Kaczmarz method|Kaczmarz algorithm]]. The first of these extensions, called ''Efficientefficient Orderingordering'',<ref>{{cite bookcitation|last1=Herman|first1=Gabor T.|author1-link=Gabor Herman|title=Fundamentals of Computerized Tomography|url=https://archive.org/details/fundamentalscomp00herm|url-access=limited|date=2009|publisher=Springer|___location=London|isbn=978-1-85233-617-2|page=[https://archive.org/details/fundamentalscomp00herm/page/n216 209]|edition=2nd}}</ref> operates on composite numbers, and it is based on decomposing the number into its prime components.
 
The second extension, called EBR (Extendedextended Bitbit-Reversalreversal)<ref>{{cite journal|last1=Gordon|first1=Dan|title=A derandomization approach to recovering bandlimited signals across a wide range of random sampling rates|journal=Numerical Algorithms|volume=77|issue=4|pages=1141–1157|date=June 2017|doi=10.1007/s11075-017-0356-3}}</ref>, is similar in spirit to bit-reversal. Given an array of size ''<math>n''</math>, EBR fills the array with a permutation of the numbers in the range <math>0\ldots n-1</math> in linear time. Successive numbers are separated in the permutation by at least <math>\lfloor n/4\rfloor</math> positions.<ref>{{citation|last1=Gordon|first1=Dan|title=A derandomization approach to recovering bandlimited signals across a wide range of random sampling rates|journal=Numerical Algorithms|volume=77|issue=4|pages=1141–1157|date=June 2017|doi=10.1007/s11075-017-0356-3|s2cid=254889989 }}</ref>
 
==Applications==
Line 52 ⟶ 72:
| year = 1984| title-link = Symposium on Theory of Computing
| isbn = 978-0897911337
| doi-access = free
}}.</ref>
 
The [[Van der Corput sequence]], a [[low-discrepancy sequence]] of numbers in the [[unit interval]], is formed by reinterpreting the indexes of the bit-reversal permutation as the [[Fixed-point arithmetic|fixed-point binary representations]] of [[dyadic rational number]]s.<ref name = "NKS note d">''[[A New Kind of Science]]'' [https://wolframscience.com/nks/notes-4-2--digit-reversal/]</ref>
 
Bit-reversal permutations are often used in finding lower bounds on dynamic [[data structures]]. For example, subject to certain assumptions, the cost of looking up the integers between <math>0</math> and <math>n-1</math>, inclusive, in any [[binary search tree]] holding those values, is <math>\Omega(n \log n)</math> when those numbers are queried in bit-reversed order. This bound applies even to trees like [[splay trees]] that are allowed to rearrange their nodes between accesses.<ref>{{citation
In musical studies, the bit-reversal permutation has also been used to correlate ranking functions of metric weight and classical-corpus onset frequencies in a common-time (4/4) measure.<ref>{{citation
| last1 = MurphyWilber | first1 = ScottRobert
| contribution = CommonLower RhythmBounds asfor DiscreteAccessing DerivativeBinary ofSearch ItsTrees Common-TimeWith MeterRotations
| doi = 10.1109/SFCS.1986.28
| volume = 4
| issuepages = 161–70
| title = 27th Annual Symposium on Foundations of Computer Science (sfcs 1986)
| pages = 1-11
| contribution-url = https://musmatieeexplore.ieee.org/wp-contentdocument/uploads/2020/06/05-Scott.pdf4568196
| title = MusMat: Brazilian Journal of Music and Mathematics
| year = 1989| title-link = Symposium on Foundations of Computer Science
| contribution-url = https://musmat.org/wp-content/uploads/2020/06/05-Scott.pdf
| isbn = 0-8186-0740-8
| year = 2020| title-link = MusMat: Brazilian Journal of Music and Mathematics
}}.</ref>
 
Line 88 ⟶ 109:
| title = International Conference on Acoustics, Speech, and Signal Processing (ICASSP-90)
| volume = 3
| year = 1990}}.</ref>| s2cid = 122373780
}}.</ref> Because bit-reversal permutations may be repeated multiple times as part of a calculation, it may be helpful to separate out the steps of the algorithm that calculate index data used to represent the permutation (for instance, by using the doubling and concatenation method) from the steps that use the results of this calculation to permute the data (for instance, by scanning the data indexes in order and performing a swap whenever the swapped ___location is greater than the current index, or by using more sophisticated [[Vectored I/O|vector scatter–gather operations]]).<ref name="karp"/>
 
Another consideration that is even more important for the performance of these algorithms is the effect of the [[memory hierarchy]] on running time. Because of this effect, more sophisticated algorithms that consider the block structure of memory can be faster than this naive scan.<ref name="karp"/><ref name="cg98">{{citation|last1=Carter|first1=Larry|first2=Kang Su|last2=Gatlin|contribution=Towards an optimal bit-reversal permutation program|title=Proceedings of the 39th Annual Symposium on Foundations of Computer Science (FOCS)|pages=544–553|year=1998|doi=10.1109/SFCS.1998.743505|title-link=Symposium on Foundations of Computer Science|isbn=978-0-8186-9172-0|citeseerx=10.1.1.46.9319|s2cid=14307262 }}.</ref> An alternative to these techniques is special computer hardware that allows memory to be accessed both in normal and in bit-reversed order.<ref>{{citation
| last1 = Harley | first1 = T. R.
| last2 = Maheshwaramurthy | first2 = G. P.
Line 99 ⟶ 121:
| title = Address generators for mapping arrays in bit-reversed order
| volume = 52
| year = 2004}}| bibcode = 2004ITSP.</ref>..52.1693H
| s2cid = 10043478
}}.</ref>
 
Significant attention has been given to improving the performance of bit-reversal operations within the field of high-performance computing. Developing architecture-aware algorithms is crucial for enabling optimal use of hardware and system software resources such as caches, TLBs, and multicore processors.<ref>{{citation
| last1 = Zhang | first1 = Zhao
| last2 = Zhang | first2 = Xiaodong
| doi = 10.1137/S1064827599359709
| issue = 6
| journal = SIAM Journal on Scientific Computing
| mr = 1856305
| pages = 2113–2134
| title = Fast bit-reversals on uniprocessors and shared-memory multiprocessors
| volume = 422
| year = 2000}}</ref>
 
==References==