SBCL中的bignum乘法

时间:2016-02-23 16:31:15

标签: lisp common-lisp sbcl

昨天我试图弄清楚新梅森素数的大小(http://www.mersenne.org/primes/?press=M74207281) 在我的SBCL盒子上(v.1.3.2(x64),Windows 10,戴尔酷睿i5 8GB内存) 差不多一个小时后,我放弃了,打断了计算。 在结果屏幕下方:

header('Content-Type: application/json');
echo json_encode($array);

对我来说这很有趣,因为我在同一台机器上的Racket 6.4上尝试了相同的表达方式, 并且(相对而言)开始吐痰数量仅需要1分08秒。 在Haskell中,再次使用

在同一台机器上
This is SBCL 1.3.2, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.

SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses.  See the CREDITS and COPYING files in the
distribution for more information.

WARNING: the Windows port is fragile, particularly for multithreaded
code.  Unfortunately, the development team currently lacks the time
and resources this platform demands.
* (- (expt 2 74207281) 1)


debugger invoked on a SB-SYS:INTERACTIVE-INTERRUPT in thread
 '#<THREAD "main thread" RUNNING {1002A9BD03}>:'
  Interactive interrupt at #x100008BD9E.

Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):

  0: [CONTINUE] Return from SB-WIN32::SIGINT.

  1: [ABORT   ] Exit debugger, returning to top level.
1

(SB-BIGNUM:MULTIPLY-BIGNUMS #<unavailable argument> #<unavailable argument>)
0] 1

只花了8秒才开始数字展览。

尽管它可能是一个错误,但有人知道SBCL如何进行bignum乘法?它的做法是否可能导致延误?

提前致谢!

*修改

在西尔维斯特的评论之后,也许正确的问题是:什么阻止了大数字的显示?是的,它确实很大(Racket和Haskell版本将其写入21 MB的文本文件),但似乎有一些不仅仅是它的大小阻止了任务的完成。

1 个答案:

答案 0 :(得分:6)

实际计算在我的机器上非常快,实际上不到一秒钟。

(defun make-prime ()
  (declare (optimize (safety 0)(debug 0)(speed 3)))
  (time (- (expt 2 74207281) 1)))

(defparameter *prime* (make-prime))

;Evaluation took:
;  0.000 seconds of real time
;  0.000017 seconds of total run time (0.000015 user, 0.000002 system)
;  100.00% CPU
;  1,292 processor cycles
;  0 bytes consed
; ==> *PRIME*

然而,打印号码是另一回事。