What kind of mathematical order is this?

In summary, the conversation revolved around a program that counts the number of "1" bits in a 16-bit value. The initial approach was brute force, but the individual is now looking for a mathematical solution. The results show a relationship to hamming weights and population count, which counts the number of ways to select k bits out of 16 to be a 1.
  • #1
matthew180
2
0
What kind of mathematical "order" is this?

Disclaimer: Sorry if this question is off-topic, I really don't yet know where it "belongs".

I wrote a program that counts the number of "1" bits in a 16-bit value. My program is brute force right now (loop 0 to 65535, shift each number and count the bits), but I would like to understand the results and how this problem could be solved mathematically, i.e. with a formula vs brute force. Since any integer in the range 0 to 65535 will go into 1 of 17 "buckets", how can I make the determination without shifting and counting the bits?

Initially I thought the results were logarithmic, but the values rise and decline, so now I'm thinking they are more related to sine or cosine. Here are the results, can anyone explain to me the relationship I am looking at here?

Thanks,
Matthew

1 numbers had 0 1's
16 numbers had 1 1's
120 numbers had 2 1's
560 numbers had 3 1's
1820 numbers had 4 1's
4368 numbers had 5 1's
8008 numbers had 6 1's
11440 numbers had 7 1's
12870 numbers had 8 1's
11440 numbers had 9 1's
8008 numbers had 10 1's
4368 numbers had 11 1's
1820 numbers had 12 1's
560 numbers had 13 1's
120 numbers had 14 1's
16 numbers had 15 1's
1 numbers had 16 1's
 
Physics news on Phys.org
  • #3


The k-th entry (0-up counting) in your table counts the number of ways you can select k bits out of 16 to be a 1 (and the rest 0), right?
 
  • #4


@jedishrfu: Thanks! Population count, I should have realized that.

@Hurkyl: Yes, that seems to be another way to describe the idea.
 
  • #5


The mathematical "order" in this case could be described as a binomial distribution. This type of distribution is commonly used to model the number of successes in a series of independent trials, which is similar to your problem of counting the number of 1's in a 16-bit value. The shape of the distribution follows a bell curve, with the peak at the middle and the values declining on either side. This explains the pattern you are seeing in your results, where the number of 1's increases and then decreases as the number of 1's in each value increases.

To solve this problem mathematically, you could use the binomial distribution formula to calculate the probability of getting a certain number of 1's in a 16-bit value. This would involve using the binomial coefficient (n choose k) and the probability of getting a 1 (which is 1/2 for a binary value). This would give you a formula to determine the number of values with a certain number of 1's, rather than having to brute force count them.

Alternatively, you could also use other mathematical methods such as generating functions or recurrence relations to find a formula for the number of values with a certain number of 1's. These methods may be more complex but can also provide a more general formula that can be applied to larger values.

Overall, understanding the underlying mathematical order can help you solve this problem more efficiently and accurately without having to rely on brute force methods.
 

1. What is mathematical order?

Mathematical order is the arrangement or sequence of numbers or objects according to a specific rule or pattern.

2. How many types of mathematical order are there?

There are three main types of mathematical order: ascending order, descending order, and random order.

3. What is ascending order?

Ascending order is when a sequence of numbers or objects is arranged from smallest to largest.

4. What is descending order?

Descending order is when a sequence of numbers or objects is arranged from largest to smallest.

5. How can I determine the order of a given set of numbers?

To determine the order of a given set of numbers, you can arrange them in either ascending or descending order and see if they follow a specific pattern or rule.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
8
Views
1K
  • Linear and Abstract Algebra
Replies
13
Views
1K
Replies
11
Views
2K
  • Introductory Physics Homework Help
Replies
14
Views
2K
  • Math Proof Training and Practice
3
Replies
86
Views
9K
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • Advanced Physics Homework Help
Replies
6
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
3K
Replies
5
Views
3K
Back
Top