I
I
Igor Vasiliev2020-04-25 05:35:13
Programming
Igor Vasiliev, 2020-04-25 05:35:13

How to count very large numbers, and in what programming language?

Hello.

I beg you to take this matter seriously. I want to know the expert opinion of programmers and mathematicians. So here's the crux of the matter. There are very huge numbers in the world, and they are probably somehow counted so that you understand that there are an astronomically huge number of zeros in these numbers, not one modern calculator is able to enter at least one number, not to mention multiply, add , divide, subtract, or exponentiate the second number. In order not to spend a whole day writing just one number for an example, I am attaching

the entire list of numbers that could be found

Единица
Десять
Сто
Тысяча
Миллион
Миллиард
Триллион
Квадриллион
Квинтиллион
Сикстиллион
Септиллион
Октиллион
Нониллион
Дециллион
Вигинтиллион
Центиллион
Миллеиллион
Мириада
Гугол
Асанкхейя
Гуголплекс
Второе число Скьюза
Мега
Мегистон
Мозер
Число Грэма
Стасплекс
Авогадро.

I don't know if there could be anything more than the last number on this list. So, something tells me that the usual computing power of a computer may not be enough to calculate such numbers. Accordingly, an appropriate programming language is also needed, which will be able to count at least Graham numbers, not to mention the gramaplex.

For you to understand, I'm not talking about small numbers like:
263.130.854.592.673.365.047.218.012.160.000.000.000.000.000.000

And about numbers in which there can be a million and a quintillion digits. I have not yet tried to calculate such numbers in Python - but it is very interesting if it can be calculated. In php, I took a chance only with numbers not exceeding 50 characters. And the code considers this simple operation to be very long. And often inserts the letter "e" in the number. There should not be any letters in the calculation. If I enter a number in which there are a million digits, I'm afraid to burn the CPU with this))
Maybe there won't even be enough memory.
Let me explain that simple operations with numbers are a test, if I find a way to count huge numbers, then I will need it to calculate matrices, powers, triangulation solutions and get roots.
To assess the complexity of this task, I will show not very large numbers that fit on the screen.
561325_original.png
You might have seen them before, but who knows, who has no idea.
The ultimate goal is to measure areas, distances and 3D uneven spaces.

Thanks to everyone who took this matter seriously and with understanding. I hope there is someone among us who knows how to count it all.
Perhaps it will be familiar, understandable and interesting to those who study astronomy.
https://spacegid.com/interaktivnaya-shkala-masshta...

Answer the question

In order to leave comments, you need to log in

9 answer(s)
V
Vladimir Korotenko, 2020-04-25
@firedragon

Not so big numbers :)
https://github.com/aleaxit/gmpy
In addition, look towards Fortran, there are many ready-made libraries for scientific computing.
In general, there are libraries for any PL

6
6yntar05, 2020-04-25
@6yntar05

I do not pretend to be a solution, but I think that it is better to write the number in a String or a similar string and count it as parts

M
mayton2019, 2020-04-25
@mayton2019

Any library with arbitrary-precission support will do.
But it seems to me that the author does not need it. Physical quantities (distances) cannot be changed so precisely that even 40 minor signs make sense.

G
Griboks, 2020-04-25
@Griboks

In short, it's impossible.
In detail, they use all sorts of tricks:
1. symbolic calculations (when we simplify formulas instead of numbers)
2. relative precision (when we set unnecessary signs to zero)
So, Avogdaro's number = R / k = 6e23, and there is no huge number of digits there.
But if you want to make sure that the solution is impossible, then just go from the binary / decimal number system to, for example, bytes. Then your number can be written as a BigInt:

sign*(type_size^n*array[n]+...+type_size^1*array[1]+type_size^0*array[0])

Note that the length of an array is also of a certain type, so you'll have to use lists. It remains only to implement the operations you need. Look at the implementation of BigInt in your language.

R
Ronald McDonald, 2020-04-25
@Zoominger

Use math packages like Maple or Matlab.
There are free alternatives.

H
HemulGM, 2020-04-26
@HemulGM

I made an app like this a long time ago. Though, did only addition of numbers. I had to make a 64bit version in order to consider numbers "long" in more than millions of characters. Made in Delphi. The code is rather modest.
https://github.com/HemulGM/HandleSumm
5ea521552cd17785359902.png

Y
Yermack, 2020-05-06
@Yermack

So try python: the only thing that limits it is the RAM. Almost half a million characters weighing almost four hundred MB counted in 3 seconds

import sys

X = 124456**78901

sys.getsizeof(str(X))/1024, len(str(X))
# (392.6279296875, 402002)

Although it turned out faster on Julia
julia> @time X = BigInt(124456)^7890123;
  0.848368 seconds (6.49 k allocations: 146.362 MiB, 9.79% gc time)

julia> length(string(X))
40200302

L
Lyoshik, 2020-04-25
@Kot1que

Even if you take the first of the Top-500 supercomputers and, discarding the entire computer device, you can use all of its RAM ( 250 petabytes ) to encode a single number, then the maximum will have (very rough estimate) only 6.7 * 10^17 characters. Not even close to googolplex :)

E
evgeniy_lm, 2020-04-26
@evgeniy_lm

The concept of "calculation accuracy" is well illustrated by an anecdote:
Guide in the museum:
- This exhibit is about 3005 years old.
Excursionist:
- How did you define it so precisely!?
Guide:
- 5 years ago, when I got a job, the director said that this exhibit is about 3000 years old
. In real life, large exact numbers are needed only in encryption algorithms and nowhere else.
As a rule, a large number is represented as an array of bytes and there are corresponding functions for processing them. I even dabbled in it myself for a long time, there is nothing complicated there.
Your GOOGOL is only 42 bytes, and RSA algorithms use numbers 64 or more bytes long
There are also algorithms for calculating the number pi, but this is a slightly different story that has no practical use.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question