Kategoriarkiv: Mathematics

Number of atoms in the universe

I got a question about my last post. How can you calculate the number of atoms in the universe ? Looking around a bit I found two different ways of calulating (or estimate) it on wikipedia.

1. The horizon size of our universe is about 14 thousand million light years. If we neglect space curvature effects, the volume of visible space represents 4/3 π R3 = 8.8 × 1083 cubic centimeters. The critical density of the universe for this value of the Hubble constant is 3 H2/8 π G, which works out to be 1×10−29 grams/cubic centimeter or about 5×10−6 atoms of hydrogen/cc. It is believed that only 4 percent of the critical density is in the form of normal atoms, so this leaves 5×10−6 × 4×10−2 = 2×10−7 hydrogen atoms/cc. Multiplying this by the volume of the visible universe, you get about 1.7 × 1077 hydrogen atoms.

2. A typical star weighs about 2×1033 grams, which is about 1×1057 atoms of hydrogen per star. A typical galaxy has about 400 thousand million stars so that means each galaxy has 1×1057 × 4×1011 = 4×1068 hydrogen atoms. There are possibly 80 thousand million galaxies in the Universe, so that means that there are about 4×1068 × 8×1010 = 3×1079 hydrogen atoms in the Universe. But this is definitely a lower limit calculation, and ignores many possible atom sources.

So the first approach makes use of what we estimate the size to be and what we estimate the density of the universe to be, while the second makes use of the numbers of stars we estimate to exist and how many atoms a star consists of. Nothing is exact of course and both calculations are probably too low, but it gives you an idea about the numbers of atoms. Or does it ? Because there is no way anyone can really comprehend how large these numbers really are.

Algorithms and combinatorics

Today I tried out some programming in C++ where the problem was to find an algorithm to solve a problem. I notice that it was a while since I did stuff like this on the university so this was some good exercise to refresh some mathematics. The problem read as follows:

Given a set of n numbers (1…n) write them in r positions. In how many ways can you do this based on the following criterias:

Uniqueness or non uniqueness: If we have uniqueness (U) then we cannot chose the same number several times.
Ordered: If the list should be ordered (O) we must write the numbers in either decreasing or increasing ( non – strictly ) order.
Thus we have four different cases to solve:

!U and !O
!U and O
U and !O
U and O
One theorem that is very useful here is the binomial theorem (or more to the point the binomial coefficient), which I in a way rediscovered without realizing at first when I looked at these problems.

The binomial coefficient is often written like this: C(n,r) which means In how many ways can we select r objects from a set of n ?

1. But in the first case where we should find how many ways we can write r numbers from n where the numbers are not unique and the order do not matter we easily see that we can chose the first number in n ways, but as we do not have to care about the order and we can take the same number again the second number can also be selected in n ways. So the answer is simply nr which in C/C++ programming can be written pow(n,r).

2. In the second case one condition is changed, the number must now be in order. This one is a bit trickier, lets get back to it later.

3. For the third case the numbers are unique but we do not have to write them in order. This is simple, for the first number we can select it in n ways, the second in (n-1) ways as we have alredy taken one away. So the solution is n·(n-1)·(n-2)·…·(n-r-1).

4. Now we are quite restricted as the numbers are unique and also have to be in order. Now we can apply the binomial coefficient when we realize that this is the same as asking us to select r numbers from the collection of n numbers, because when we select r numbers we have also selected a specific order.

The binominal coefficient is expanded like this:

C(n,r) = n!/((n-r)!·r!)

where n! means n factorial ( n·(n-1)·(n-2)·…·1 ).

If we now look back at the second problem again where we are in the same position as the fourth case but with the difference that the numbers are not unique. If we take an example with n=5 and r=3 we are thus going to write numbers in the range 1-5 where the numbers must be in order. For example 1,1,4 is one such solution. If we now just write the three selected numbers as three x: xxx we can use four | symbols to divide the groups of different numbers. So if I write:

xx|||x|

I mean the sequence 114 mentioned earlier, the two leftmost x’s represent the two 1’s and the last x represent the four which is why it’s located in the fourth space between the | symbols. Realizing this we can see that this problem can also simply be expressed using the binomial coefficient as we can say in how many ways can we insert the | symbols among the x’s ? We see that we have n-1 | symbols and r x symbols, so we can express the problem as in how many ways can we select r from r+n-1 objects. Thus C(r+n-1,r).

By the way another thing that is important to remember when you calculate this on a computer is that the factorials can be insanely large numbers, for example if we in our problem use n=95 and r=10 and we just use the binomial coefficient on this we end up with 95!/(85!·10!). 95! is actually an amazingly insanely huge number: 1.03·10148. For comparison the estimated number of atoms in the universe is somewhere around 1·1079. The number is also greater than what the normal datatypes in C++ can handle. So to solve this it’s important to not do this calculation first but to eliminate a large part of the factorial expansion using the denominator.