乘法后 CLISP 溢出

发布于 2024-09-08 05:00:16 字数 220 浏览 12 评论 0原文

让第一个 lisp 程序使用 CLISP 实现来工作

(print (mod (+ (* 28433 (expt 2 7830457) 1)) (expt 10 10))))

我正在尝试通过输入REPL 来

。但它给了我*** - 大数乘法期间溢出。我认为 lisp 具有任意大小/精度的特点。那怎么会发生这种事呢?

i'm trying to get a first lisp program to work using the CLISP implementation, by typing

(print (mod (+ (* 28433 (expt 2 7830457) 1)) (expt 10 10))))

in the REPL.

but it gives me *** - overflow during multiplication of large numbers. i thought lisp features arbitrary size/precision. how could that ever happen then?

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

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

发布评论

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

评论(5

雨落星ぅ辰 2024-09-15 05:00:27

函数“mod-expt”(或 EXT:mod-expt)

[1]> (mod-expt 2 1000000 59)

53

CLIsp 提供了相当快的 。并且为了您的目的而有效。

CLisp provided the function "mod-expt" (or EXT:mod-expt)

[1]> (mod-expt 2 1000000 59)

53

which is pretty fast. And for your purpose that works.

阳光①夏 2024-09-15 05:00:26

Lisp 是一个语言家族,拥有数十种方言和数百种不同的实现。

计算机的内存是有限的。某些操作系统下的程序可能对内存大小有限制。不同的 Common Lisp 实现使用不同的数字库。

您可能需要查阅 CLISP 手册以了解其各种数据类型的限制。

Lisp is a family of languages with dozens of dialects and hundreds of different implementations.

Computers have finite memory. Programs under some operating systems may have limitations about the memory size. Different Common Lisp implementations use different numeric libraries.

You may want to consult your CLISP manual for its limitations of its various data types.

荭秂 2024-09-15 05:00:24

很可能有更好的方法来解决问题。我在体育方面还没有做到那么远,但我知道到目前为止我所做的少数人往往会发出“啊哈!”的感叹。解决似乎超出计算机程序范围的问题。

尤其是这个 - 2^7830457 是一个巨大的数字 - 尝试 (format t "~r" (expt 2 160))。您可能会尝试从新的角度看待问题,看看是否有一种您没有想到的看待问题的方法。

Chances are there's a better way to solve the problem. I haven't made it that far on PE, but I know the few that I've done so far tend to have "aha!" solutions to problems that seem out of a computer programs range.

This one especially - 2^7830457 is a huge number -- try (format t "~r" (expt 2 160)). You might try to look at the problem in a new light and see if there's a way to look at it that you haven't thought of.

呆头 2024-09-15 05:00:23

根据 http://clisp.cons.org/impnotes/num-concepts.html< /a> bignum 的最大大小是 (2^2097088 - 1) 而你的 2^7830457 比这个大得多。

也许你可以考虑分解这个数字 - 也许分离出一些较小的 2^X 因子......

According to http://clisp.cons.org/impnotes/num-concepts.html the maximum size for a bignum is (2^2097088 - 1) and your 2^7830457 is much larger than that.

Perhaps you can look at breaking down that number - perhaps separate out a number of smaller 2^X factors...

甜味拾荒者 2024-09-15 05:00:21

Lisp 的 bignum 可能包含非常大的数字,但它们也有其局限性。

在您的情况下,您可以将求幂和模数合并到一个过程中,例如 http://en.wikipedia.org/wiki/Modular_exponentiation#Right-to-left_binary_method

Lisp's bignums may hold really large numbers, but they too have their limits.

In your case, you can combine exponentiation and modulus into a single procedure, e.g. as in http://en.wikipedia.org/wiki/Modular_exponentiation#Right-to-left_binary_method.

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