Is there a function for mapping 1 to 1, 2 to 2…n to n, 1,2 to n+1, 1,3 to n+2…1,n-1 to 2n-1 for n...
$begingroup$
So I'm programming something and I need to create this mapping. This is my rough idea of how it will work.
I have a list of variables, $x_1$ to $x_n$.
$x_1$ maps to $1$, $x_1$ maps to $2$, so on until $x_n$ which maps to $n$. This has $n$ terms.
For 2 variables together, I need to map $x_1x_2$ to $n+1$, all the way to $x_1x_n$ which will map to $2n-1$. This has $n-1$ terms. Note that I'm not considering $x_1x_1$.
As I go along to $x_2x_3$ to $x_2x_n$, I will be mapping it to the additional $n-2$ terms. For 2 variables, I should have a total of $frac{(n)(n+1)}{2}-n$ terms mapped to.
For 3 variables and beyond, I know the number of terms that it needs to get mapped to. It is $n$ choose 3, and so on for 4 variables. But is there a function which perhaps takes in the indicies of $x$ and spits out where it should be along this long chain? I can't seem to find it.
Thanks.
combinatorics generating-functions
$endgroup$
add a comment |
$begingroup$
So I'm programming something and I need to create this mapping. This is my rough idea of how it will work.
I have a list of variables, $x_1$ to $x_n$.
$x_1$ maps to $1$, $x_1$ maps to $2$, so on until $x_n$ which maps to $n$. This has $n$ terms.
For 2 variables together, I need to map $x_1x_2$ to $n+1$, all the way to $x_1x_n$ which will map to $2n-1$. This has $n-1$ terms. Note that I'm not considering $x_1x_1$.
As I go along to $x_2x_3$ to $x_2x_n$, I will be mapping it to the additional $n-2$ terms. For 2 variables, I should have a total of $frac{(n)(n+1)}{2}-n$ terms mapped to.
For 3 variables and beyond, I know the number of terms that it needs to get mapped to. It is $n$ choose 3, and so on for 4 variables. But is there a function which perhaps takes in the indicies of $x$ and spits out where it should be along this long chain? I can't seem to find it.
Thanks.
combinatorics generating-functions
$endgroup$
add a comment |
$begingroup$
So I'm programming something and I need to create this mapping. This is my rough idea of how it will work.
I have a list of variables, $x_1$ to $x_n$.
$x_1$ maps to $1$, $x_1$ maps to $2$, so on until $x_n$ which maps to $n$. This has $n$ terms.
For 2 variables together, I need to map $x_1x_2$ to $n+1$, all the way to $x_1x_n$ which will map to $2n-1$. This has $n-1$ terms. Note that I'm not considering $x_1x_1$.
As I go along to $x_2x_3$ to $x_2x_n$, I will be mapping it to the additional $n-2$ terms. For 2 variables, I should have a total of $frac{(n)(n+1)}{2}-n$ terms mapped to.
For 3 variables and beyond, I know the number of terms that it needs to get mapped to. It is $n$ choose 3, and so on for 4 variables. But is there a function which perhaps takes in the indicies of $x$ and spits out where it should be along this long chain? I can't seem to find it.
Thanks.
combinatorics generating-functions
$endgroup$
So I'm programming something and I need to create this mapping. This is my rough idea of how it will work.
I have a list of variables, $x_1$ to $x_n$.
$x_1$ maps to $1$, $x_1$ maps to $2$, so on until $x_n$ which maps to $n$. This has $n$ terms.
For 2 variables together, I need to map $x_1x_2$ to $n+1$, all the way to $x_1x_n$ which will map to $2n-1$. This has $n-1$ terms. Note that I'm not considering $x_1x_1$.
As I go along to $x_2x_3$ to $x_2x_n$, I will be mapping it to the additional $n-2$ terms. For 2 variables, I should have a total of $frac{(n)(n+1)}{2}-n$ terms mapped to.
For 3 variables and beyond, I know the number of terms that it needs to get mapped to. It is $n$ choose 3, and so on for 4 variables. But is there a function which perhaps takes in the indicies of $x$ and spits out where it should be along this long chain? I can't seem to find it.
Thanks.
combinatorics generating-functions
combinatorics generating-functions
asked Jan 7 at 8:31
Yip Jung HonYip Jung Hon
47411
47411
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
The following bijection takes a set of $k$ distinct indices $a_1<a_2<dots<a_k$ and returns a number between $0$ and $binom{n}k-1$, so that every set gets a different number.
$$
S={a_1<a_2<dots<a_k}implies f(S)=binom{n-a_1}k+binom{n-a_2}{k-1}+dots+binom{n-a_k}1
$$
However, this is exactly the opposite of the order you want, so you should instead use $binom{n}k-f(S)$.
Therefore, given an arbitrary set $S$ of $k$ indices, your desired indexing operation is
$$
g(S) = binom{n}1+dots+binom{n}{k-1}+binom{n}k-f(S)
$$
For example, when $n=10$ and your set of indices is $x_2x_5x_7$, the place in the list is
$$
g({2,5,7})=binom{10}1+binom{10}2+binom{10}3-binom{10-2}3-binom{10-5}2-binom{10-7}1=
$$
As a sanity check, the place of $x_1x_n$ in the list is $binom{n}1+binom{n}2-binom{n-1}2-binom{n-n}1=n+(n-1)+0=2n-1$, which agrees with your example. The position of $x_1x_2$ is $binom{n}1+binom{n}2-binom{n-1}2-binom{n-2}1=n+1$.
$endgroup$
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3064762%2fis-there-a-function-for-mapping-1-to-1-2-to-2-n-to-n-1-2-to-n1-1-3-to-n2%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
$begingroup$
The following bijection takes a set of $k$ distinct indices $a_1<a_2<dots<a_k$ and returns a number between $0$ and $binom{n}k-1$, so that every set gets a different number.
$$
S={a_1<a_2<dots<a_k}implies f(S)=binom{n-a_1}k+binom{n-a_2}{k-1}+dots+binom{n-a_k}1
$$
However, this is exactly the opposite of the order you want, so you should instead use $binom{n}k-f(S)$.
Therefore, given an arbitrary set $S$ of $k$ indices, your desired indexing operation is
$$
g(S) = binom{n}1+dots+binom{n}{k-1}+binom{n}k-f(S)
$$
For example, when $n=10$ and your set of indices is $x_2x_5x_7$, the place in the list is
$$
g({2,5,7})=binom{10}1+binom{10}2+binom{10}3-binom{10-2}3-binom{10-5}2-binom{10-7}1=
$$
As a sanity check, the place of $x_1x_n$ in the list is $binom{n}1+binom{n}2-binom{n-1}2-binom{n-n}1=n+(n-1)+0=2n-1$, which agrees with your example. The position of $x_1x_2$ is $binom{n}1+binom{n}2-binom{n-1}2-binom{n-2}1=n+1$.
$endgroup$
add a comment |
$begingroup$
The following bijection takes a set of $k$ distinct indices $a_1<a_2<dots<a_k$ and returns a number between $0$ and $binom{n}k-1$, so that every set gets a different number.
$$
S={a_1<a_2<dots<a_k}implies f(S)=binom{n-a_1}k+binom{n-a_2}{k-1}+dots+binom{n-a_k}1
$$
However, this is exactly the opposite of the order you want, so you should instead use $binom{n}k-f(S)$.
Therefore, given an arbitrary set $S$ of $k$ indices, your desired indexing operation is
$$
g(S) = binom{n}1+dots+binom{n}{k-1}+binom{n}k-f(S)
$$
For example, when $n=10$ and your set of indices is $x_2x_5x_7$, the place in the list is
$$
g({2,5,7})=binom{10}1+binom{10}2+binom{10}3-binom{10-2}3-binom{10-5}2-binom{10-7}1=
$$
As a sanity check, the place of $x_1x_n$ in the list is $binom{n}1+binom{n}2-binom{n-1}2-binom{n-n}1=n+(n-1)+0=2n-1$, which agrees with your example. The position of $x_1x_2$ is $binom{n}1+binom{n}2-binom{n-1}2-binom{n-2}1=n+1$.
$endgroup$
add a comment |
$begingroup$
The following bijection takes a set of $k$ distinct indices $a_1<a_2<dots<a_k$ and returns a number between $0$ and $binom{n}k-1$, so that every set gets a different number.
$$
S={a_1<a_2<dots<a_k}implies f(S)=binom{n-a_1}k+binom{n-a_2}{k-1}+dots+binom{n-a_k}1
$$
However, this is exactly the opposite of the order you want, so you should instead use $binom{n}k-f(S)$.
Therefore, given an arbitrary set $S$ of $k$ indices, your desired indexing operation is
$$
g(S) = binom{n}1+dots+binom{n}{k-1}+binom{n}k-f(S)
$$
For example, when $n=10$ and your set of indices is $x_2x_5x_7$, the place in the list is
$$
g({2,5,7})=binom{10}1+binom{10}2+binom{10}3-binom{10-2}3-binom{10-5}2-binom{10-7}1=
$$
As a sanity check, the place of $x_1x_n$ in the list is $binom{n}1+binom{n}2-binom{n-1}2-binom{n-n}1=n+(n-1)+0=2n-1$, which agrees with your example. The position of $x_1x_2$ is $binom{n}1+binom{n}2-binom{n-1}2-binom{n-2}1=n+1$.
$endgroup$
The following bijection takes a set of $k$ distinct indices $a_1<a_2<dots<a_k$ and returns a number between $0$ and $binom{n}k-1$, so that every set gets a different number.
$$
S={a_1<a_2<dots<a_k}implies f(S)=binom{n-a_1}k+binom{n-a_2}{k-1}+dots+binom{n-a_k}1
$$
However, this is exactly the opposite of the order you want, so you should instead use $binom{n}k-f(S)$.
Therefore, given an arbitrary set $S$ of $k$ indices, your desired indexing operation is
$$
g(S) = binom{n}1+dots+binom{n}{k-1}+binom{n}k-f(S)
$$
For example, when $n=10$ and your set of indices is $x_2x_5x_7$, the place in the list is
$$
g({2,5,7})=binom{10}1+binom{10}2+binom{10}3-binom{10-2}3-binom{10-5}2-binom{10-7}1=
$$
As a sanity check, the place of $x_1x_n$ in the list is $binom{n}1+binom{n}2-binom{n-1}2-binom{n-n}1=n+(n-1)+0=2n-1$, which agrees with your example. The position of $x_1x_2$ is $binom{n}1+binom{n}2-binom{n-1}2-binom{n-2}1=n+1$.
answered Jan 7 at 19:41


Mike EarnestMike Earnest
21.8k12051
21.8k12051
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3064762%2fis-there-a-function-for-mapping-1-to-1-2-to-2-n-to-n-1-2-to-n1-1-3-to-n2%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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