Changes

Jump to: navigation, search

Traversing Subsets of a Set

18 bytes added, 16:45, 20 June 2020
no edit summary
}
</pre>
This is how the Carry-Rippler, introduced by [[Marcel van Kervinck]] <ref>[httphttps://groups.google.com/groupd/msg/rec.games.chess/msgKnJvBnhgDKU/f4f0751cc8b928c8 Re: move generators in computer chess, yCi5yBx18PQJ Tricky bit tricks] by [[Marcel van Kervinck]], [[Computer Chess Forums|rgccrec.games.chess]], October 20, 1994</ref> and later by [[Steffan Westcott]] <ref>[http://www.stmintz.com/ccc/index.php?id=490129 Re: algorithm question] by [[Steffan Westcott]], [[CCC]], February 27, 2006</ref> works: we first set all "unused" bits of the set by oring the One's Complement of d. The increment ripples a possible carry through all unused bits - and finally we clear all unused bits again by intersection with the set d:
<pre>
n = ((n | ~d) + 1) & d;
</pre>
We add the [[General Setwise Operations#TheLeastSignificantOneBitLS1B|LS1B]] (smallest) to the set, to get a greater number. The former LS1B becomes zero with overflow. If the next higher bit was zero, it takes the carry and the number of set bits didn't change - two flipped bits. Otherwise, if the carry ripples through, leaving further zero(s), we need to set least significant bits accordingly, to keep the cardinality equal. Thus, we xor ripple to get the flipped bits as ones. We shift this sequence right, until it becomes the least significant bits (divide by smallest). To take the two compensating bits off, we need to further divide by 4 (leading or trailing shift right 2). Get the next higher number with the same number of one bits (Snoob) was devised by [[Bill Gosper]] as [[Bill Gosper#HAKMEM175|HAKMEM 175]] in [[PDP-6]] [[Assembly]] <ref>Michael Beeler, [[Bill Gosper]], [https://en.wikipedia.org/wiki/Richard_Schroeppel Rich Schroeppel] ('''1972'''). ''[http://home.pipeline.com/~hbaker1/hakmem/hakmem.html HAKMEM]'', Memo 239, Artificial Intelligence Laboratory''. [https://en.wikipedia.org/wiki/MIT_Computer_Science_and_Artificial_Intelligence_Laboratory CSAIL], [[Massachusetts Institute of Technology|MIT]]</ref> and elaborated in [[Henry S. Warren, Jr.#HackersDeligh|Hacker's Delight]] by [[Henry S. Warren, Jr.]] <ref>[http://www.hackersdelight.org/basics1.pdf Sample section of Hacker's Delight, Chapter 2 Basics] (pdf) by [[Henry S. Warren, Jr.]] pp.14 Figure 2–1. ''Next higher number with same number of 1-bits''.</ref> <ref>[http://www.hackersdelight.org/hdcodetxt/snoob.c.txt C code for most of the programs that appear in HD | Fig. 2-1. Next higher number with same number of 1-bits]</ref>.
==<span id="NextSnoob"></span>Snoobing the Universe==
=See also=
* [[Bitboard Serialization]]
* [[De Bruijn sequenceSequence]]
* [[Magic Bitboards]]
=Selected Publications=
* Michael Beeler, [[Bill Gosper]], [https://en.wikipedia.org/wiki/Richard_Schroeppel Rich Schroeppel] ('''1972'''). ''[http://home.pipeline.com/~hbaker1/hakmem/hakmem.html HAKMEM]'', Memo 239, Artificial Intelligence Laboratory''. [https://en.wikipedia.org/wiki/MIT_Computer_Science_and_Artificial_Intelligence_Laboratory CSAIL], [[Massachusetts Institute of Technology|MIT]], [http://home.pipeline.com/~hbaker1/hakmem/hacks.html#item175 ITEM 175 (Gosper)]
* [[Mathematician#FRuskey|Frank Ruskey]] ('''2003'''). ''Combinatorial Generation''. [https://en.wikipedia.org/wiki/University_of_Victoria University of Victoria], [http://www.1stworks.com/ref/ruskeycombgen.pdf pdf]
* [[Henry S. Warren, Jr.]] ('''2012'''). ''[http://hackersdelight.org/ Hacker's Delight, 2nd Edition]''. [https://en.wikipedia.org/wiki/Addison%E2%80%93Wesley Addison-Wesley]
* [http://groups.google.com/group/rec.games.chess/msg/f4f0751cc8b928c8 Re: move generators in computer chess, Tricky bit tricks] by [[Marcel van Kervinck]], [[Computer Chess Forums|rgcc]], October 20, 1994
* [http://www.stmintz.com/ccc/index.php?id=490129 Re: algorithm question] by [[Steffan Westcott]], [[CCC]], February 27, 2006
* [http://www.talkchess.com/forum3/viewtopic.php?f=7&t=73198 Don't understand CarryRippler] by [[Marcel Vanthoor]], [[CCC]], February 27, 2020 » [[#AllSubsetsofanySet|Carry-Rippler]], [[Rust]]
=External Links=
* [https://en.wikipedia.org/wiki/Partially_ordered_set Partially ordered set from Wikipedia]
* [https://en.wikipedia.org/wiki/Power_set Power set from Wikipedia]
* [[Videos#LedZeppelin|Led Zeppelin]] - [https://en.wikipedia.org/wiki/Dazed_and_Confused_%28song%29 Dazed and Confused], [https://en.wikipedia.org/wiki/YouTube YouTube] Video, Lost Performances (2/5)
: {{#evu:https://www.youtube.com/watch?v=gJXwwNeFFuU|alignment=left|valignment=top}}
=References=
<references />
 
'''[[Algorithms|Up one Level]]'''

Navigation menu