[Math] Factorial of 1,e+80

factorialvisualization

Recently I started being very fascinated in logistics, and out of the blue came the question into my head, what is the factorial of the amount of atoms in the observeable universe, which is said to be between 1,e+78 and 1,e+82 but the amount of ways you can arrange these atoms is unimaginably larger. So I played with this number and I thought it might be interesting to see how far I could get on calculating the factorial of 1,e+80, so I went ahead and created a simple java program:

import java.awt.Color;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.NumberFormat;

import javax.swing.JFrame;
import javax.swing.JLabel;

public class Factorial {

    public static void main(String[] args) {
        JFrame frame = new JFrame("Project Factorial");
        frame.setAlwaysOnTop(true);
        frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        frame.setLocation(0, 0);
        frame.setUndecorated(true);
        JLabel label = new JLabel();
        label.setForeground(Color.white);
        frame.getContentPane().setBackground(Color.BLUE);
        frame.getContentPane().add(label);
        frame.setVisible(true);
        BigDecimal atoms = new BigDecimal("1E+80");
        BigDecimal total = new BigDecimal("1");
        double increment = new BigDecimal("100.0").divide(atoms)
                .doubleValue();
        double percentage = increment;
        for (BigDecimal num = new BigDecimal("2"); num.compareTo(atoms) <= 0; num
                .add(BigDecimal.ONE)) {
            total = total.multiply(num);
            percentage += increment;
            label.setText("[" + String.format("%-10.3f%%", percentage) + "]"
                    + format(total, total.scale()));
            frame.pack();
            Thread.yield();
        }
    }

    private static String format(BigDecimal x, int scale) {
        NumberFormat formatter = new DecimalFormat("0.0E0");
        formatter.setRoundingMode(RoundingMode.HALF_UP);
        formatter.setMinimumFractionDigits(scale);
        return formatter.format(x);
    }

}

Quickly after running this program for about an hour I realized running this kind of calculation on any computer today would absolutely take ages, I was hopping to reach 0,001 % on the calculation but it is certainly too large to calculate, but then the question came up, exactly how long would it take? That question is not so easy to answer considering there is alot of factors involved, but really what I am trying to solve is the factorial of 1,e+80.

$$(1\times10^{80})!$$

The number can be very hard to understand just how big it is, so I'd like to visualise how big that number is, for instance, if you could calculate how long it would take for a computer to calculate the factorial of 1,e+80 that would be a cool visualization.

(EDIT: Thanks for the great answers, however, I wish to implement a way of calculating the factorial of 1,e+80 in a application despite I would need to use some kind of approximation formula, so I decided to use Stirling's approximation based on derpy's answer.
$$n! \sim \sqrt{2\pi n}\left(\frac{n}{e}\right)^n$$
So with Stirling's approximation and GMP library for C programming language it would be possible to make a quite accurate and efficient program to calculate the factorial of 1,e+80
)

Best Answer

Easiest way to estimate that number is to employ the Stirling approximation: you have

$$ n! \sim \sqrt{2\pi n}\left(\frac{n}{e}\right)^n $$

(this is asymptotic notation), or even more roughly speaking, $ n! \approx e^{n\ln n} $ as order of magnitude. In your case, say $ n = 10^{80} $, you have

$$ n! \approx e^{80\cdot\ln{10}\cdot10^{80}} \approx 10^{10^{81.9}}. $$

(EDIT: I had written 81 instead of 81.9 at the exponent; not only was the rounding incorrect, but especially, rounding exponents needs a lot of care when talking about orders of magnitude!)

By the way, this is also the plausible order of magnitude (in natural units) for the volume of the phase space of the observable universe.

Pictorially speaking, the decimal expansion of this number would need to convert every single particle in the observable universe into a digit in order to be written out.

For an even more pictorial comparison, the age of the universe is thought to be about $ 10^{17} $ seconds. This is far less than the number of digits you would need to write out the above number. Even if you could churn out, say, a billion of digits per seconds, you would still need about $ 10^{82}/10^9 = 10^{73} $ seconds to complete the task, which is a ridiculously prohibitory amount of time.

Related Question