Counting $k$-sets with sum $n$ and xor-sum $0$.












3












$begingroup$


Given $k, n > 0$, how many ordered lists $a_1, a_2, dots, a_k$ are there such that $a_i geq 0$ for all $i$, such that $sum_i a_i = n$ and $oplus_i a_i = 0$, where the latter operation denotes bitwise xor (i.e. $15 oplus 3 = 12$).



It is likely there is no closed-form expression, in that case a reasonably fast algorithm would also be interesting.



EDIT: Context: this is the number of losing starting positions in a game of Nim with $k$ initial piles containing a total of $n$ stones.










share|cite|improve this question











$endgroup$








  • 2




    $begingroup$
    See section 5 of Tanya Khovanova and Joshua Xiong, "Nim Fractals", arxiv.org/abs/1405.5942, in particular Theorem 27.
    $endgroup$
    – Michael Lugo
    Jan 10 at 20:22










  • $begingroup$
    @MichaelLugo Thanks, that's pretty good. It only gives $n$ even though.
    $endgroup$
    – Timon Knigge
    Jan 10 at 21:32






  • 1




    $begingroup$
    Aha, but if $n equiv 1 mod 2$ then there is an odd number of odd sized piles and the nim sum is never $0$.
    $endgroup$
    – Timon Knigge
    Jan 10 at 21:36


















3












$begingroup$


Given $k, n > 0$, how many ordered lists $a_1, a_2, dots, a_k$ are there such that $a_i geq 0$ for all $i$, such that $sum_i a_i = n$ and $oplus_i a_i = 0$, where the latter operation denotes bitwise xor (i.e. $15 oplus 3 = 12$).



It is likely there is no closed-form expression, in that case a reasonably fast algorithm would also be interesting.



EDIT: Context: this is the number of losing starting positions in a game of Nim with $k$ initial piles containing a total of $n$ stones.










share|cite|improve this question











$endgroup$








  • 2




    $begingroup$
    See section 5 of Tanya Khovanova and Joshua Xiong, "Nim Fractals", arxiv.org/abs/1405.5942, in particular Theorem 27.
    $endgroup$
    – Michael Lugo
    Jan 10 at 20:22










  • $begingroup$
    @MichaelLugo Thanks, that's pretty good. It only gives $n$ even though.
    $endgroup$
    – Timon Knigge
    Jan 10 at 21:32






  • 1




    $begingroup$
    Aha, but if $n equiv 1 mod 2$ then there is an odd number of odd sized piles and the nim sum is never $0$.
    $endgroup$
    – Timon Knigge
    Jan 10 at 21:36
















3












3








3


1



$begingroup$


Given $k, n > 0$, how many ordered lists $a_1, a_2, dots, a_k$ are there such that $a_i geq 0$ for all $i$, such that $sum_i a_i = n$ and $oplus_i a_i = 0$, where the latter operation denotes bitwise xor (i.e. $15 oplus 3 = 12$).



It is likely there is no closed-form expression, in that case a reasonably fast algorithm would also be interesting.



EDIT: Context: this is the number of losing starting positions in a game of Nim with $k$ initial piles containing a total of $n$ stones.










share|cite|improve this question











$endgroup$




Given $k, n > 0$, how many ordered lists $a_1, a_2, dots, a_k$ are there such that $a_i geq 0$ for all $i$, such that $sum_i a_i = n$ and $oplus_i a_i = 0$, where the latter operation denotes bitwise xor (i.e. $15 oplus 3 = 12$).



It is likely there is no closed-form expression, in that case a reasonably fast algorithm would also be interesting.



EDIT: Context: this is the number of losing starting positions in a game of Nim with $k$ initial piles containing a total of $n$ stones.







combinatorics combinatorial-game-theory






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Jan 10 at 20:13







Timon Knigge

















asked Jan 10 at 19:49









Timon KniggeTimon Knigge

370110




370110








  • 2




    $begingroup$
    See section 5 of Tanya Khovanova and Joshua Xiong, "Nim Fractals", arxiv.org/abs/1405.5942, in particular Theorem 27.
    $endgroup$
    – Michael Lugo
    Jan 10 at 20:22










  • $begingroup$
    @MichaelLugo Thanks, that's pretty good. It only gives $n$ even though.
    $endgroup$
    – Timon Knigge
    Jan 10 at 21:32






  • 1




    $begingroup$
    Aha, but if $n equiv 1 mod 2$ then there is an odd number of odd sized piles and the nim sum is never $0$.
    $endgroup$
    – Timon Knigge
    Jan 10 at 21:36
















  • 2




    $begingroup$
    See section 5 of Tanya Khovanova and Joshua Xiong, "Nim Fractals", arxiv.org/abs/1405.5942, in particular Theorem 27.
    $endgroup$
    – Michael Lugo
    Jan 10 at 20:22










  • $begingroup$
    @MichaelLugo Thanks, that's pretty good. It only gives $n$ even though.
    $endgroup$
    – Timon Knigge
    Jan 10 at 21:32






  • 1




    $begingroup$
    Aha, but if $n equiv 1 mod 2$ then there is an odd number of odd sized piles and the nim sum is never $0$.
    $endgroup$
    – Timon Knigge
    Jan 10 at 21:36










2




2




$begingroup$
See section 5 of Tanya Khovanova and Joshua Xiong, "Nim Fractals", arxiv.org/abs/1405.5942, in particular Theorem 27.
$endgroup$
– Michael Lugo
Jan 10 at 20:22




$begingroup$
See section 5 of Tanya Khovanova and Joshua Xiong, "Nim Fractals", arxiv.org/abs/1405.5942, in particular Theorem 27.
$endgroup$
– Michael Lugo
Jan 10 at 20:22












$begingroup$
@MichaelLugo Thanks, that's pretty good. It only gives $n$ even though.
$endgroup$
– Timon Knigge
Jan 10 at 21:32




$begingroup$
@MichaelLugo Thanks, that's pretty good. It only gives $n$ even though.
$endgroup$
– Timon Knigge
Jan 10 at 21:32




1




1




$begingroup$
Aha, but if $n equiv 1 mod 2$ then there is an odd number of odd sized piles and the nim sum is never $0$.
$endgroup$
– Timon Knigge
Jan 10 at 21:36






$begingroup$
Aha, but if $n equiv 1 mod 2$ then there is an odd number of odd sized piles and the nim sum is never $0$.
$endgroup$
– Timon Knigge
Jan 10 at 21:36












1 Answer
1






active

oldest

votes


















0












$begingroup$

Let $F(n,k,x)$ denote the amount of ordered lists $a_1,...,a_k$ such that $a_igeq0$, $sum a_i=n$ and $oplus a_i=x$. Then considering all possible values of $a_k$ we find the recursive formula $$F(n,k,x)=sum_{i=0}^nF(n-i,k-1,xoplus i).$$ This gives us an $mathcal{O}(n^3k)$ time algorithm. Not very fast, but at least polynomial in $n$ and $k$.






share|cite|improve this answer









$endgroup$









  • 1




    $begingroup$
    One can use binary doubling (as in squaring by exponentiation) to get this to $O(n^3 log k)$. Still very slow though.
    $endgroup$
    – Timon Knigge
    Jan 10 at 20:15











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%2f3069098%2fcounting-k-sets-with-sum-n-and-xor-sum-0%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









0












$begingroup$

Let $F(n,k,x)$ denote the amount of ordered lists $a_1,...,a_k$ such that $a_igeq0$, $sum a_i=n$ and $oplus a_i=x$. Then considering all possible values of $a_k$ we find the recursive formula $$F(n,k,x)=sum_{i=0}^nF(n-i,k-1,xoplus i).$$ This gives us an $mathcal{O}(n^3k)$ time algorithm. Not very fast, but at least polynomial in $n$ and $k$.






share|cite|improve this answer









$endgroup$









  • 1




    $begingroup$
    One can use binary doubling (as in squaring by exponentiation) to get this to $O(n^3 log k)$. Still very slow though.
    $endgroup$
    – Timon Knigge
    Jan 10 at 20:15
















0












$begingroup$

Let $F(n,k,x)$ denote the amount of ordered lists $a_1,...,a_k$ such that $a_igeq0$, $sum a_i=n$ and $oplus a_i=x$. Then considering all possible values of $a_k$ we find the recursive formula $$F(n,k,x)=sum_{i=0}^nF(n-i,k-1,xoplus i).$$ This gives us an $mathcal{O}(n^3k)$ time algorithm. Not very fast, but at least polynomial in $n$ and $k$.






share|cite|improve this answer









$endgroup$









  • 1




    $begingroup$
    One can use binary doubling (as in squaring by exponentiation) to get this to $O(n^3 log k)$. Still very slow though.
    $endgroup$
    – Timon Knigge
    Jan 10 at 20:15














0












0








0





$begingroup$

Let $F(n,k,x)$ denote the amount of ordered lists $a_1,...,a_k$ such that $a_igeq0$, $sum a_i=n$ and $oplus a_i=x$. Then considering all possible values of $a_k$ we find the recursive formula $$F(n,k,x)=sum_{i=0}^nF(n-i,k-1,xoplus i).$$ This gives us an $mathcal{O}(n^3k)$ time algorithm. Not very fast, but at least polynomial in $n$ and $k$.






share|cite|improve this answer









$endgroup$



Let $F(n,k,x)$ denote the amount of ordered lists $a_1,...,a_k$ such that $a_igeq0$, $sum a_i=n$ and $oplus a_i=x$. Then considering all possible values of $a_k$ we find the recursive formula $$F(n,k,x)=sum_{i=0}^nF(n-i,k-1,xoplus i).$$ This gives us an $mathcal{O}(n^3k)$ time algorithm. Not very fast, but at least polynomial in $n$ and $k$.







share|cite|improve this answer












share|cite|improve this answer



share|cite|improve this answer










answered Jan 10 at 20:12









SmileyCraftSmileyCraft

3,571518




3,571518








  • 1




    $begingroup$
    One can use binary doubling (as in squaring by exponentiation) to get this to $O(n^3 log k)$. Still very slow though.
    $endgroup$
    – Timon Knigge
    Jan 10 at 20:15














  • 1




    $begingroup$
    One can use binary doubling (as in squaring by exponentiation) to get this to $O(n^3 log k)$. Still very slow though.
    $endgroup$
    – Timon Knigge
    Jan 10 at 20:15








1




1




$begingroup$
One can use binary doubling (as in squaring by exponentiation) to get this to $O(n^3 log k)$. Still very slow though.
$endgroup$
– Timon Knigge
Jan 10 at 20:15




$begingroup$
One can use binary doubling (as in squaring by exponentiation) to get this to $O(n^3 log k)$. Still very slow though.
$endgroup$
– Timon Knigge
Jan 10 at 20:15


















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%2f3069098%2fcounting-k-sets-with-sum-n-and-xor-sum-0%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

Human spaceflight

Can not write log (Is /dev/pts mounted?) - openpty in Ubuntu-on-Windows?

File:DeusFollowingSea.jpg