Polynomial-time algorithm to generate the “opposite” of a binary Gray code?












2












$begingroup$


I'm seeking to implement a function $phi(n,k,i)$ of integers $n,k,i$ where $$1 leq k < n\1 leq i leq N\N = {n choose k}$$ that returns all possible $n$-element binary vectors containing $k$ $1$'s, in sequence, with $i$ specifying the index of the element to return. Additionally, the elements (words) of the sequence must be ordered in such a way that every word differs "as much as possible" from all prior words in terms of Hamming distance.



That is, letting the words of the sequence be $w_1, w_2, ldots, w_N$ with $$w_i = phi(n,k,i)$$ and $d(w_1,w_2)$ be the Hamming distance between $w_1$ and $w_2$, I'd like to maximize a function $$J = sum _{i = 2}^{N} D(i)$$ over the order of the words in the sequence, where $D(i)$ is a rough measure of the distance of the $i$'th word from all its predecessors, such as $$D(i) = sum_{j=1}^{i-1} d(w_i,w_j)$$ or perhaps a fancier weighted-by-recency version such as $$D(i) = sum_{j=1}^{i-1} d(w_i,w_j); r^{i-1-j}$$ for $0 < r < 1$.



I don't want to define "rough measure" more rigorously than this since any $D$ that yields values positively correlating to either of the above is also fine--the stronger the correlation, the better.



In a sense, I'm looking for the "opposite" of a binary Gray code (wherein successive words are designed to resemble their nearest predecessors as much as possible).



The motivation is to generate the sequence in a deterministic way so that when $phi$ is queried to return the first $p$ words of the sequence, with $p$ typically being $ll N$, the set of words is always diverse. In actuality, the words represent bit masks for the $k$-element subsets of an $n$-element set. Like creating $p$ dishes where $k$ ingredients are selected for each dish from a common pool of $n$, such that the diversity in combinations of ingredients is as high as possible even if $p$ is small.



Finally, while I know this problem can be brute-forced by evaluating $J$ for each one of the $2^N$ possible word orderings, $N$ will typically be $> 1000$, ruling this out as a practical option. An algorithm for implementing $phi$ with $O(N^2)$--or ideally $O(N log N)$, $O(N)$, or better--time and memory requirements is ultimately what I'm looking for.



It seems to me that with all the mathematical and computer science research going on out there, somebody must have come up with some ideas on this.










share|cite|improve this question









$endgroup$












  • $begingroup$
    Related: “Anti-Gray codes" that maximize the number of bits that change at each step
    $endgroup$
    – MJD
    Dec 7 '18 at 5:37
















2












$begingroup$


I'm seeking to implement a function $phi(n,k,i)$ of integers $n,k,i$ where $$1 leq k < n\1 leq i leq N\N = {n choose k}$$ that returns all possible $n$-element binary vectors containing $k$ $1$'s, in sequence, with $i$ specifying the index of the element to return. Additionally, the elements (words) of the sequence must be ordered in such a way that every word differs "as much as possible" from all prior words in terms of Hamming distance.



That is, letting the words of the sequence be $w_1, w_2, ldots, w_N$ with $$w_i = phi(n,k,i)$$ and $d(w_1,w_2)$ be the Hamming distance between $w_1$ and $w_2$, I'd like to maximize a function $$J = sum _{i = 2}^{N} D(i)$$ over the order of the words in the sequence, where $D(i)$ is a rough measure of the distance of the $i$'th word from all its predecessors, such as $$D(i) = sum_{j=1}^{i-1} d(w_i,w_j)$$ or perhaps a fancier weighted-by-recency version such as $$D(i) = sum_{j=1}^{i-1} d(w_i,w_j); r^{i-1-j}$$ for $0 < r < 1$.



I don't want to define "rough measure" more rigorously than this since any $D$ that yields values positively correlating to either of the above is also fine--the stronger the correlation, the better.



In a sense, I'm looking for the "opposite" of a binary Gray code (wherein successive words are designed to resemble their nearest predecessors as much as possible).



The motivation is to generate the sequence in a deterministic way so that when $phi$ is queried to return the first $p$ words of the sequence, with $p$ typically being $ll N$, the set of words is always diverse. In actuality, the words represent bit masks for the $k$-element subsets of an $n$-element set. Like creating $p$ dishes where $k$ ingredients are selected for each dish from a common pool of $n$, such that the diversity in combinations of ingredients is as high as possible even if $p$ is small.



Finally, while I know this problem can be brute-forced by evaluating $J$ for each one of the $2^N$ possible word orderings, $N$ will typically be $> 1000$, ruling this out as a practical option. An algorithm for implementing $phi$ with $O(N^2)$--or ideally $O(N log N)$, $O(N)$, or better--time and memory requirements is ultimately what I'm looking for.



It seems to me that with all the mathematical and computer science research going on out there, somebody must have come up with some ideas on this.










share|cite|improve this question









$endgroup$












  • $begingroup$
    Related: “Anti-Gray codes" that maximize the number of bits that change at each step
    $endgroup$
    – MJD
    Dec 7 '18 at 5:37














2












2








2


1



$begingroup$


I'm seeking to implement a function $phi(n,k,i)$ of integers $n,k,i$ where $$1 leq k < n\1 leq i leq N\N = {n choose k}$$ that returns all possible $n$-element binary vectors containing $k$ $1$'s, in sequence, with $i$ specifying the index of the element to return. Additionally, the elements (words) of the sequence must be ordered in such a way that every word differs "as much as possible" from all prior words in terms of Hamming distance.



That is, letting the words of the sequence be $w_1, w_2, ldots, w_N$ with $$w_i = phi(n,k,i)$$ and $d(w_1,w_2)$ be the Hamming distance between $w_1$ and $w_2$, I'd like to maximize a function $$J = sum _{i = 2}^{N} D(i)$$ over the order of the words in the sequence, where $D(i)$ is a rough measure of the distance of the $i$'th word from all its predecessors, such as $$D(i) = sum_{j=1}^{i-1} d(w_i,w_j)$$ or perhaps a fancier weighted-by-recency version such as $$D(i) = sum_{j=1}^{i-1} d(w_i,w_j); r^{i-1-j}$$ for $0 < r < 1$.



I don't want to define "rough measure" more rigorously than this since any $D$ that yields values positively correlating to either of the above is also fine--the stronger the correlation, the better.



In a sense, I'm looking for the "opposite" of a binary Gray code (wherein successive words are designed to resemble their nearest predecessors as much as possible).



The motivation is to generate the sequence in a deterministic way so that when $phi$ is queried to return the first $p$ words of the sequence, with $p$ typically being $ll N$, the set of words is always diverse. In actuality, the words represent bit masks for the $k$-element subsets of an $n$-element set. Like creating $p$ dishes where $k$ ingredients are selected for each dish from a common pool of $n$, such that the diversity in combinations of ingredients is as high as possible even if $p$ is small.



Finally, while I know this problem can be brute-forced by evaluating $J$ for each one of the $2^N$ possible word orderings, $N$ will typically be $> 1000$, ruling this out as a practical option. An algorithm for implementing $phi$ with $O(N^2)$--or ideally $O(N log N)$, $O(N)$, or better--time and memory requirements is ultimately what I'm looking for.



It seems to me that with all the mathematical and computer science research going on out there, somebody must have come up with some ideas on this.










share|cite|improve this question









$endgroup$




I'm seeking to implement a function $phi(n,k,i)$ of integers $n,k,i$ where $$1 leq k < n\1 leq i leq N\N = {n choose k}$$ that returns all possible $n$-element binary vectors containing $k$ $1$'s, in sequence, with $i$ specifying the index of the element to return. Additionally, the elements (words) of the sequence must be ordered in such a way that every word differs "as much as possible" from all prior words in terms of Hamming distance.



That is, letting the words of the sequence be $w_1, w_2, ldots, w_N$ with $$w_i = phi(n,k,i)$$ and $d(w_1,w_2)$ be the Hamming distance between $w_1$ and $w_2$, I'd like to maximize a function $$J = sum _{i = 2}^{N} D(i)$$ over the order of the words in the sequence, where $D(i)$ is a rough measure of the distance of the $i$'th word from all its predecessors, such as $$D(i) = sum_{j=1}^{i-1} d(w_i,w_j)$$ or perhaps a fancier weighted-by-recency version such as $$D(i) = sum_{j=1}^{i-1} d(w_i,w_j); r^{i-1-j}$$ for $0 < r < 1$.



I don't want to define "rough measure" more rigorously than this since any $D$ that yields values positively correlating to either of the above is also fine--the stronger the correlation, the better.



In a sense, I'm looking for the "opposite" of a binary Gray code (wherein successive words are designed to resemble their nearest predecessors as much as possible).



The motivation is to generate the sequence in a deterministic way so that when $phi$ is queried to return the first $p$ words of the sequence, with $p$ typically being $ll N$, the set of words is always diverse. In actuality, the words represent bit masks for the $k$-element subsets of an $n$-element set. Like creating $p$ dishes where $k$ ingredients are selected for each dish from a common pool of $n$, such that the diversity in combinations of ingredients is as high as possible even if $p$ is small.



Finally, while I know this problem can be brute-forced by evaluating $J$ for each one of the $2^N$ possible word orderings, $N$ will typically be $> 1000$, ruling this out as a practical option. An algorithm for implementing $phi$ with $O(N^2)$--or ideally $O(N log N)$, $O(N)$, or better--time and memory requirements is ultimately what I'm looking for.



It seems to me that with all the mathematical and computer science research going on out there, somebody must have come up with some ideas on this.







combinatorics coding-theory gray-code






share|cite|improve this question













share|cite|improve this question











share|cite|improve this question




share|cite|improve this question










asked Dec 7 '18 at 5:18









COTOCOTO

15112




15112












  • $begingroup$
    Related: “Anti-Gray codes" that maximize the number of bits that change at each step
    $endgroup$
    – MJD
    Dec 7 '18 at 5:37


















  • $begingroup$
    Related: “Anti-Gray codes" that maximize the number of bits that change at each step
    $endgroup$
    – MJD
    Dec 7 '18 at 5:37
















$begingroup$
Related: “Anti-Gray codes" that maximize the number of bits that change at each step
$endgroup$
– MJD
Dec 7 '18 at 5:37




$begingroup$
Related: “Anti-Gray codes" that maximize the number of bits that change at each step
$endgroup$
– MJD
Dec 7 '18 at 5:37










1 Answer
1






active

oldest

votes


















1












$begingroup$

The algorithm linked to in the comments takes the $n-$ bit standard Gray code, appends a 0 to the left and then uses complementation to every other pattern in order to obtain maximal change in consecutive words. This would seem to address your requirements.



Donald Knuth's Pre-Fascicle 2A, available here discusses a number of different gray code algorithms and introduces the idea of a delta sequence which can be used for efficient generation of the next Gray codeword.






share|cite|improve this answer









$endgroup$













  • $begingroup$
    An added complication is that only words with a specific weight (number of $1$'s) can be used in my application, which isn't the case for the anti-Gray code in MJD's link. Furthermore, while each word's distance to its predecessor (and near odd-numbered predecessors) is large, its distance to near even-numbered predecessors is small. I'm looking to maximize the sum total difference over all predecessors, especially when $p$ is small. Obviously, by the time $p$ is anywhere close to $N$, word order matters little.
    $endgroup$
    – COTO
    Dec 10 '18 at 17:22











Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "69"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3029492%2fpolynomial-time-algorithm-to-generate-the-opposite-of-a-binary-gray-code%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1












$begingroup$

The algorithm linked to in the comments takes the $n-$ bit standard Gray code, appends a 0 to the left and then uses complementation to every other pattern in order to obtain maximal change in consecutive words. This would seem to address your requirements.



Donald Knuth's Pre-Fascicle 2A, available here discusses a number of different gray code algorithms and introduces the idea of a delta sequence which can be used for efficient generation of the next Gray codeword.






share|cite|improve this answer









$endgroup$













  • $begingroup$
    An added complication is that only words with a specific weight (number of $1$'s) can be used in my application, which isn't the case for the anti-Gray code in MJD's link. Furthermore, while each word's distance to its predecessor (and near odd-numbered predecessors) is large, its distance to near even-numbered predecessors is small. I'm looking to maximize the sum total difference over all predecessors, especially when $p$ is small. Obviously, by the time $p$ is anywhere close to $N$, word order matters little.
    $endgroup$
    – COTO
    Dec 10 '18 at 17:22
















1












$begingroup$

The algorithm linked to in the comments takes the $n-$ bit standard Gray code, appends a 0 to the left and then uses complementation to every other pattern in order to obtain maximal change in consecutive words. This would seem to address your requirements.



Donald Knuth's Pre-Fascicle 2A, available here discusses a number of different gray code algorithms and introduces the idea of a delta sequence which can be used for efficient generation of the next Gray codeword.






share|cite|improve this answer









$endgroup$













  • $begingroup$
    An added complication is that only words with a specific weight (number of $1$'s) can be used in my application, which isn't the case for the anti-Gray code in MJD's link. Furthermore, while each word's distance to its predecessor (and near odd-numbered predecessors) is large, its distance to near even-numbered predecessors is small. I'm looking to maximize the sum total difference over all predecessors, especially when $p$ is small. Obviously, by the time $p$ is anywhere close to $N$, word order matters little.
    $endgroup$
    – COTO
    Dec 10 '18 at 17:22














1












1








1





$begingroup$

The algorithm linked to in the comments takes the $n-$ bit standard Gray code, appends a 0 to the left and then uses complementation to every other pattern in order to obtain maximal change in consecutive words. This would seem to address your requirements.



Donald Knuth's Pre-Fascicle 2A, available here discusses a number of different gray code algorithms and introduces the idea of a delta sequence which can be used for efficient generation of the next Gray codeword.






share|cite|improve this answer









$endgroup$



The algorithm linked to in the comments takes the $n-$ bit standard Gray code, appends a 0 to the left and then uses complementation to every other pattern in order to obtain maximal change in consecutive words. This would seem to address your requirements.



Donald Knuth's Pre-Fascicle 2A, available here discusses a number of different gray code algorithms and introduces the idea of a delta sequence which can be used for efficient generation of the next Gray codeword.







share|cite|improve this answer












share|cite|improve this answer



share|cite|improve this answer










answered Dec 9 '18 at 21:49









kodlukodlu

3,390716




3,390716












  • $begingroup$
    An added complication is that only words with a specific weight (number of $1$'s) can be used in my application, which isn't the case for the anti-Gray code in MJD's link. Furthermore, while each word's distance to its predecessor (and near odd-numbered predecessors) is large, its distance to near even-numbered predecessors is small. I'm looking to maximize the sum total difference over all predecessors, especially when $p$ is small. Obviously, by the time $p$ is anywhere close to $N$, word order matters little.
    $endgroup$
    – COTO
    Dec 10 '18 at 17:22


















  • $begingroup$
    An added complication is that only words with a specific weight (number of $1$'s) can be used in my application, which isn't the case for the anti-Gray code in MJD's link. Furthermore, while each word's distance to its predecessor (and near odd-numbered predecessors) is large, its distance to near even-numbered predecessors is small. I'm looking to maximize the sum total difference over all predecessors, especially when $p$ is small. Obviously, by the time $p$ is anywhere close to $N$, word order matters little.
    $endgroup$
    – COTO
    Dec 10 '18 at 17:22
















$begingroup$
An added complication is that only words with a specific weight (number of $1$'s) can be used in my application, which isn't the case for the anti-Gray code in MJD's link. Furthermore, while each word's distance to its predecessor (and near odd-numbered predecessors) is large, its distance to near even-numbered predecessors is small. I'm looking to maximize the sum total difference over all predecessors, especially when $p$ is small. Obviously, by the time $p$ is anywhere close to $N$, word order matters little.
$endgroup$
– COTO
Dec 10 '18 at 17:22




$begingroup$
An added complication is that only words with a specific weight (number of $1$'s) can be used in my application, which isn't the case for the anti-Gray code in MJD's link. Furthermore, while each word's distance to its predecessor (and near odd-numbered predecessors) is large, its distance to near even-numbered predecessors is small. I'm looking to maximize the sum total difference over all predecessors, especially when $p$ is small. Obviously, by the time $p$ is anywhere close to $N$, word order matters little.
$endgroup$
– COTO
Dec 10 '18 at 17:22


















draft saved

draft discarded




















































Thanks for contributing an answer to Mathematics Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3029492%2fpolynomial-time-algorithm-to-generate-the-opposite-of-a-binary-gray-code%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents