有哪些选项可以表示超过 2^81 位的数字?

发布于 2025-01-03 11:32:46 字数 514 浏览 0 评论 0原文

我遇到了一个有趣的数学问题,需要我对超过 281 位的数字进行一些算术运算。我知道在每个数字都有一个内存单元的系统中不可能表示这么大的数字,但我想知道是否有任何方法可以解决这个问题。

我最初的想法是使用一个非常大的基数而不是 10 基数(十进制)。经过一番思考,我相信(但无法验证)最佳基数是位数的平方根(因此,对于 281 位数字,您将使用基数 240ish),这是一个改进,但扩展性不佳,而且仍然不太实用。

那么我有什么选择呢?我知道有很多任意精度的库,但是有没有那种规模可以支持这种算术?

谢谢o7

编辑:经过更多思考,我意识到我可能完全错误地认为“最佳基数是位数的平方根”,但是a)这就是我问的原因,b)我太累了,记不起我最初的推理假设。

编辑2:10基数中的1000,000 = 16基数中的F4240 = 8基数中的364110。在基数16中,您需要20位来存储基数8中的数字,您需要21,因此似乎通过增加基数可以决定总数所需的位数。 (这也可能是错误的)

I came across an interesting math problem that would require me to do some artithmetic with numbers that have more than 281 digits. I know that its impossible to represent a number this large with a system where there is one memory unit for each digit but wondered if there were any ways around this.

My initial thought was to use a extremely large base instead of base 10 (decimal). After some thought I believe (but can't verify) that the optimal base would be the square root of the number of digits (so for a number with 281 digits you'd use base 240ish) which is a improvement but that doesn't scale well and still isn't really practical.

So what options do I have? I know of many arbitrary precision libraries, but are there any that scale to support this sort of arithmetic?

Thanks o7

EDIT: after thinking some more i realize i may be completely wrong about the "optimal base would be the square root of the number of digits" but a) that's why im asking and b) im too tired to remember my initial reasoning for assumption.

EDIT 2: 1000,000 in base ten = F4240 in base 16 = 364110 in base 8. In base 16 you need 20 bits to store the number in base 8 you need 21 so it would seem that by increasing the base you decrees the total number of bits needed. (again this could be wrong)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

安静被遗忘 2025-01-10 11:32:46

这实际上是一个伪装成算术问题的压缩问题。你能用这么大的数字做什么完全取决于它的Kolmogorov 复杂度。如果你需要对这么大的数字进行计算,它显然不会以 2^81 的十进制数字形式出现;在这种情况下,柯尔莫哥洛夫复杂度会太高,您甚至无法在太阳熄灭之前读完输入。处理这样的数字的最佳方法是通过诸如 之类的语言的延迟求值和符号理性类型方案提供。这样,程序就可以回答一些有关数字计算结果的问题,而无需实际将所有这些数字写入内存。

This is really a compression problem pretending to be an arithmetic problem. What you can do with such a large number depends entirely on its Kolmogorov complexity. If you're required to do computations on such a large number, it's obviously not going be arrive as 2^81 decimal digits; the Kolmogorov complexity would too high in that case and you can't even finish reading the input before the sun goes out. The best way to deal with such a number is via delayed evaluation and symbolic rational types that a language like Scheme provides. This way a program may be able to answer some questions about the result of computations on the number without actually having to write out all those digits to memory.

萌吟 2025-01-10 11:32:46

我认为你应该使用科学记数法。你会失去精度,但是你不能在不损失精度的情况下存储那么大的数字,因为存储 2^81 位数字将需要超过 10^24 位(大约千亿太字节),这比你现在可以拥有的要多得多。

I think you should just use scientific notation. You will lose precision, but you can not store numbers that large without losing precision, because storing 2^81 digits will require more than 10^24 bits(about thousand billion terabytes), which is much more that you can have nowadays.

生生漫 2025-01-10 11:32:46

超过 2^81 位数字

非小数(2^81 位)将占用 3*10^11 TB 的数据。每个数字。

这是假设您想要每一个数字并且数据不可压缩。

可以尝试压缩数据,将其存储在某种稀疏数组中,该数组仅为非零元素分配内存,但这并不能保证数据适合任何地方。

这种精度在现代硬件上是无用且不可能处理的。 2^81 位将花费大量时间来简单地遍历数字(9584 万亿年,假设 1 字节需要 1 毫秒),更不用说乘法/除法了。我也想不出任何需要如此精确的问题。

您唯一的选择是将精度降低到前 N 个有效数字并使用浮点数。由于数据不适合 double,因此您必须使用具有浮点支持的 bignum 库,它提供极大的浮点数。由于您可以用位表示 2^81(指数),因此您可以使用非常大的浮点来存储数字的开头。

十进制为 1000,000

无论您的基数如何,正数都至少需要 Floor(log2(number))+1 位来存储它。如果基数不是 2,则需要多于 Floor(log2(number))+1 位来存储它。数字基数不会减少所需位数。

that have more than 2^81 digits

Non-fractional number with 2^81 bits, will take 3*10^11 terabytes of data. Per number.

That's assuming you want every single digit and data isn't compressible.

You could attempt to compress the data storing it in some kind of sparse array that allocates memory only for non-zero elements, but that doesn't guarantee that data will be fit anywhere.

Such precision is useless and impossible to handle on modern hardware. 2^81 bits will take insane amount of time to simply walk through number (9584 trillion years, assuming 1 byte takes 1 millisecond), never mind multiplication/division. I also can't think of any problem that would require precision like that.

Your only option is to reduce precision to first N significant digits and use floating point numbers. Since data won't fit into double, you'll have to use bignum library with floating point support, that provides extremely large floating point numbers. Since you can represent 2^81 (exponent) in bits, you can store beginning of a number using very big floating point.

1000,000 in base ten

Regardless of your base, positive number will take at least floor(log2(number))+1 bits to store it. If base is not 2, then it will take more than floor(log2(number))+1 bits to store it. Numeric base won't reduce number of required bits.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文