summaryrefslogtreecommitdiffstats
path: root/factor.scm
diff options
context:
space:
mode:
authorDavid N. Welton <davidw@efn.org>1998-11-09 21:18:01 -0800
committerBryan Newbold <bnewbold@robocracy.org>2017-02-20 00:05:27 -0800
commit926b1b647ac830660933a5e63eb52d4a2552e264 (patch)
treee25db5f6e1441d67f5d9af063432018ee20a5f51 /factor.scm
parentb21cac3362022718634f7086964208b2eed8e897 (diff)
parentfa3f23105ddcf07c5900de47f19af43d1db1b597 (diff)
downloadslib-926b1b647ac830660933a5e63eb52d4a2552e264.tar.gz
slib-926b1b647ac830660933a5e63eb52d4a2552e264.zip
Import Debian changes 2c3-3debian/2c3-3
slib (2c3-3) frozen unstable; urgency=low * Fixes #16235. * Fixes #19943. * Fixes #20265. * Fixes #24917. * Fixes #27389. slib (2c3-2) frozen unstable; urgency=low * Re-uploaded for slink freeze. slib (2c3-1) unstable; urgency=low * New upstream release.
Diffstat (limited to 'factor.scm')
-rw-r--r--factor.scm33
1 files changed, 18 insertions, 15 deletions
diff --git a/factor.scm b/factor.scm
index 6d7b38d..a5c7b44 100644
--- a/factor.scm
+++ b/factor.scm
@@ -130,21 +130,24 @@
(prime:f u (+ v b) (+ b b) (quotient (- n u) 2))))))
(define (prime:factor m)
- (if
- (negative? m) (cons -1 (prime:factor (- m)))
- (let* ((s (gcd m prime:product))
- (r (quotient m s)))
- (if (even? s)
- (append
- (if (= 1 r) '() (prime:factor r))
- (cons 2 (let ((s/2 (quotient s 2)))
- (if (= s/2 1) '()
- (or (prime:f 1 1 2 (quotient (- s/2 1) 2))
- (list s/2))))))
- (if (= 1 s) (or (prime:f 1 1 2 (quotient (- m 1) 2)) (list m))
- (append (if (= 1 r) '()
- (or (prime:f 1 1 2 (quotient (- r 1) 2)) (list r)))
- (or (prime:f 1 1 2 (quotient (- s 1) 2)) (list s))))))))
+ (case m
+ ((-1 0 1) (list m))
+ (else
+ (if (negative? m) (cons -1 (prime:factor (- m)))
+ (let* ((s (gcd m prime:product))
+ (r (quotient m s)))
+ (if (even? s)
+ (append
+ (if (= 1 r) '() (prime:factor r))
+ (cons 2 (let ((s/2 (quotient s 2)))
+ (if (= s/2 1) '()
+ (or (prime:f 1 1 2 (quotient (- s/2 1) 2))
+ (list s/2))))))
+ (if (= 1 s) (or (prime:f 1 1 2 (quotient (- m 1) 2)) (list m))
+ (append
+ (if (= 1 r) '()
+ (or (prime:f 1 1 2 (quotient (- r 1) 2)) (list r)))
+ (or (prime:f 1 1 2 (quotient (- s 1) 2)) (list s))))))))))
(define jacobi-symbol prime:jacobi-symbol)
(define prime? prime:prime?)