Help for mapping a triplet of numbers

NicolasLegnazzi

New member
Joined
Aug 26, 2020
Messages
9
Hi! I am a physics student and creating a code I found the following problem.
I have to be able to map a triplet of numbers into an integer that goes from 1 to a certain value.
In this case I have the triplet {n, l, m} and I must make the mapping of these numbers go from 1 to [MATH] \begin{equation} {n+l+m+1 \choose 2} \end{equation} [/MATH].
It is very important not skip numbers and that the numbers are in the range mentioned above.
I hope you can help me (excuse my English, I write in a translator)
Thank you!
 
Let u = n+l+m+1

You want the number [math]\binom{u}{2}=\frac{u!}{2! \times (u-2)!} = \frac{1}{2} \times \frac{u!}{(u-2)!}[/math]
Can you simplify this further? Assume u≥2 and show a few terms of each factorial to see what cancels out.
 
Hi! I am a physics student and creating a code I found the following problem.
I have to be able to map a triplet of numbers into an integer that goes from 1 to a certain value.
In this case I have the triplet {n, l, m} and I must make the mapping of these numbers go from 1 to [MATH] \begin{equation} {n+l+m+1 \choose 2} \end{equation} [/MATH].
It is very important not skip numbers and that the numbers are in the range mentioned above.
I hope you can help me (excuse my English, I write in a translator)
Thank you!
Since we are not sure of your translation, it may help if you give an example of what you want to do with some specific numbers, which may help us be sure what you mean. In particular, I need to see whether you want to map each individual triplet into a number (which you seem already to have specified), or something else.
 
yes, excuse me, I see that I did not clarify everything. Given a MAXIMUM n + l + m, I must obtain a formula that maps each triplet into an integer that goes from 1 to [MATH] \begin{equation} {[n+l+m]_{max}+1 \choose 2} \end{equation} [/MATH].
For example, if we take at most that n + l + m is 2 we would obtain the triplets:
{0,0,0}
{1,0,0}
{0,1,0}
{0,0,1}
{2,0,0}
{0,2,0}
{0,0,2}
{1,1,0}
{1,0,1}
{0,1,1}

that is, all triplets {n, l, m} such that n + l + m 《2. I need an equation that depends on n, l, and m that maps each of these triplets to an integer between 1 and [MATH] \begin{equation} {3 \choose 2} \end{equation} [/MATH] in this case,since [MATH](n+l+m)_{max}+1=3 [/MATH].








 
I have thought of a formula that generates an ascending "index" number for such triples. Would this solve your problem?

For example, if the maximum n+l+m value is 3 then the formula would return...
Code:
{0,0,0} -> 0    {0,1,1} -> 5    {1,0,0} -> 10    {1,2,0} -> 15
{0,0,1} -> 1    {0,1,2} -> 6    {1,0,1} -> 11    {2,0,0} -> 16
{0,0,2} -> 2    {0,2,0} -> 7    {1,0,2} -> 12    {2,0,1} -> 17
{0,0,3} -> 3    {0,2,1} -> 8    {1,1,0} -> 13    {2,1,0} -> 18
{0,1,0} -> 4    {0,3,0} -> 9    {1,1,1} -> 14    {3,0,0} -> 19

You could simply limit the index value to a particular number if you wish to enforce some maximum return value.
 
yes, excuse me, I see that I did not clarify everything. Given a MAXIMUM n + l + m, I must obtain a formula that maps each triplet into an integer that goes from 1 to [MATH] \begin{equation} {[n+l+m]_{max}+1 \choose 2} \end{equation} [/MATH].
For example, if we take at most that n + l + m is 2 we would obtain the triplets:
{0,0,0}
{1,0,0}
{0,1,0}
{0,0,1}
{2,0,0}
{0,2,0}
{0,0,2}
{1,1,0}
{1,0,1}
{0,1,1}

that is, all triplets {n, l, m} such that n + l + m 《2. I need an equation that depends on n, l, and m that maps each of these triplets to an integer between 1 and [MATH] \begin{equation} {3 \choose 2} \end{equation} [/MATH] in this case,since [MATH](n+l+m)_{max}+1=3 [/MATH].
So in this case, with max = 2, you're saying that you would want a formula f(n,l,m) that takes values 1, 2, or 3 for each of the ten possible triplets. There has to be some triplet that will map to each of the three possible outputs, but you give no other constraint. Does that mean, for example, that this would be good enough? (Not saying this is my proposal, just that I want to be sure of the requirements.)

{0,0,0} -> 3
{1,0,0} -> 2
{0,1,0} -> 1
{0,0,1} -> 1
{2,0,0} -> 1
{0,2,0} -> 1
{0,0,2} -> 1
{1,1,0} -> 1
{1,0,1} -> 1
{0,1,1} -> 1
 

I have thought of a formula that generates an ascending "index" number for such triples. Would this solve your problem?

For example, if the maximum n+l+m value is 3 then the formula would return...
Code:
{0,0,0} -> 0    {0,1,1} -> 5    {1,0,0} -> 10    {1,2,0} -> 15
{0,0,1} -> 1    {0,1,2} -> 6    {1,0,1} -> 11    {2,0,0} -> 16
{0,0,2} -> 2    {0,2,0} -> 7    {1,0,2} -> 12    {2,0,1} -> 17
{0,0,3} -> 3    {0,2,1} -> 8    {1,1,0} -> 13    {2,1,0} -> 18
{0,1,0} -> 4    {0,3,0} -> 9    {1,1,1} -> 14    {3,0,0} -> 19

You could simply limit the index value to a particular number if you wish to enforce some maximum return value.
Yes! that solves my problem! But I need the equation through which you get those integers from the triplets (the equation that depends on n, l, m)
 
So in this case, with max = 2, you're saying that you would want a formula f(n,l,m) that takes values 1, 2, or 3 for each of the ten possible triplets. There has to be some triplet that will map to each of the three possible outputs, but you give no other constraint. Does that mean, for example, that this would be good enough? (Not saying this is my proposal, just that I want to be sure of the requirements.)

{0,0,0} -> 3
{1,0,0} -> 2
{0,1,0} -> 1
{0,0,1} -> 1
{2,0,0} -> 1
{0,2,0} -> 1
{0,0,2} -> 1
{1,1,0} -> 1
{1,0,1} -> 1
{0,1,1} -> 1
no, excuse me for having a hard time stating my problem. But the function must return different integers for each different argument. Those integers that it returns must go, in the case of max = 2 from 1 to 10.
 
But I need the equation through which you get those integers from the triplets (the equation that depends on n, l, m)

I would prefer to give you hints about how you can find this equation yourself, rather than giving you the answer directly. This way you would learn a lot more.

The equation actually depends on n, l, m and "a", where a is the maximum allowable sum of n+l+m.

Finding the "full equation" is a little bit tricky. So please don't ignore @Dr.Peterson post #6 since if his example would be good enough then a simpler equation can be found. In particular I think you'd only need l, m, and a as inputs (you could ignore the value of n). For now I'll assume that this IS OK and start giving you pointers towards finding the simpler solution yourself. See the following sets of {l,m} assuming a=2...
Code:
l m

0 0
0 1
0 2

1 0
1 1

2 0

How many sets of {l,m} exist where l=0? How many {l,m} sets exist where l=1? Do you see a pattern? Using this observation can you write an expression for how many {l,m} sets exist for arbitrary values of "a" and "l"?
 
Last edited:
Sorry I might not be around for a few hours, therefore I'll give you the a further pointer. After obtaining the expression I asked for in post#8, call it f(a, l), then the index "b", can be obtained with....
Code:
l m  index(b)

0 0    1
0 1    2
0 2    3

1 0    4
1 1    5

2 0    6

[math] b=\left( \sum_{i=0}^{l-1}{f(a,i)} \right) + m + 1[/math]
Next you should be able to eliminate the summation "loop" to give a direct expression for the index "b" (and the summation part should evaluate to 0 when l=0).

Work out the maximum index returned to verify that this will more than cover your requirement of choose(a+1, 2) therefore you'll have to impose an upper bound on the index.
 

Sorry I might not be around for a few hours, therefore I'll give you the a further pointer. After obtaining the expression I asked for in post#8, call it f(a, l), then the index "b", can be obtained with....
Code:
l m  index(b)

0 0    1
0 1    2
0 2    3

1 0    4
1 1    5

2 0    6

[math] b=\left( \sum_{i=0}^{l-1}{f(a,i)} \right) + m + 1[/math]
Next you should be able to eliminate the summation "loop" to give a direct expression for the index "b" (and the summation part should evaluate to 0 when l=0).

Work out the maximum index returned to verify that this will more than cover your requirement of choose(a+1, 2) therefore you'll have to impose an upper bound on the index.
yeah! There I got a lot of thanks to you and Dr Peterson! now I only mark the problem as resolved or I can like them and indicate that they helped me a lot
 
[MATH] [QUOTE="NicolasLegnazzi, post: 506347, member: 83157"] [SUB][SUB][SUB][/SUB][/SUB][/SUB][SUB][SUB][/SUB][/SUB] yeah! There I got a lot of thanks to you and Dr Peterson! now I only mark the problem as resolved or I can like them and indicate that they helped me a lot [/QUOTE] how did they find out? just with the pattern that Dr Peterson exposed? [/MATH]
 
no, excuse me for having a hard time stating my problem. But the function must return different integers for each different argument. Those integers that it returns must go, in the case of max = 2 from 1 to 10.
My goal has been only to find out what your real requirements are. (My example map was intended to be wrong.) What you say here totally confuses me, because you said that the output of the map in this case should be numbers only from 1 to 3, and it is impossible for 10 different triples to map to a smaller set of numbers one-to-one. So you apparently mean something other than what you said:
yes, excuse me, I see that I did not clarify everything. Given a MAXIMUM n + l + m, I must obtain a formula that maps each triplet into an integer that goes from 1 to [MATH] \begin{equation} {[n+l+m]_{max}+1 \choose 2} \end{equation} [/MATH].
For example, if we take at most that n + l + m is 2 we would obtain the triplets:
{0,0,0}
{1,0,0}
{0,1,0}
{0,0,1}
{2,0,0}
{0,2,0}
{0,0,2}
{1,1,0}
{1,0,1}
{0,1,1}

that is, all triplets {n, l, m} such that n + l + m 《2. I need an equation that depends on n, l, and m that maps each of these triplets to an integer between 1 and [MATH] \begin{equation} {3 \choose 2} \end{equation} [/MATH] in this case,since [MATH](n+l+m)_{max}+1=3 [/MATH].
Maybe others are interpreting this as you intend, but I don't yet know.

What role does [MATH]{[n+l+m]_{max}+1} \choose {2}[/MATH] actually play in your problem?
 
the function must return different integers for each different argument. Those integers that it returns must go, in the case of max = 2 from 1 to 10.

I had not seen the above post before I made posts #9 and #10. (I assume that the above post took a while to appear on the public forum because it was awaiting moderator approval.) It confuses me because it contradicts the following...

I need an equation ... that maps each of these triplets to an integer between 1 and [MATH] \begin{equation} {3 \choose 2} \end{equation} [/MATH] in this case,since [MATH](n+l+m)_{max}+1[/MATH]=3.


So, should the output go from 1 to 3 OR 1 to 10?

I'm very pleased that we seem to have helped you to find a solution, but I am very unsure whether you have found a complete answer to your problem. Due to the above concern I am no longer sure that my posts #9 and #10 are sufficient. If you wish to proceed then please clarify which of your above quoted posts is correct, and preferably supply some extra background info, perhaps with example cases of input triplets along with example(s) of acceptable output.
 
Last edited:
Top