How one of the 21st century’s most reviled inventions is actually a piece of mathematical genius