May I propose a few small Racket-style improvements? Otherwise follow Jens's suggestions and
#lang typed/racket
(provide
;; coming to a Typed Racket near you soon
#;
[jacobi-symbol (-> non-negative-integer? (and/c non-negative-integer? odd?) integer?)]
jacobi-symbol)
;; ------------------------------------------------------------------------------------
(require math/number-theory)
(module+ test
(require typed/rackunit))
(: jacobi-symbol (-> Nonnegative-Integer Positive-Integer Integer))
(define (jacobi-symbol a n)
(unless (odd? n)
(raise-argument-error 'jacobi "odd?" 1 a n))
(cond
[(= n 1) 1]
[else
(define prime-factors (factorize n))
(let next ([factor (first prime-factors)] [remaining-factors (rest prime-factors)])
(define p (first factor))
(define e (second factor))
(define qcap (quadratic-character a p))
(if (null? remaining-factors)
(expt qcap e)
(* (expt qcap e) (next (first remaining-factors) (rest remaining-factors)))))]))
(module+ test
(check-equal? (jacobi-symbol 0 23) 0)
(check-equal? (jacobi-symbol 1 1) 1)
(check-equal? (jacobi-symbol 2 1) 1)
(check-equal? (jacobi-symbol 4 1) 1)
(check-equal? (jacobi-symbol 2 3) -1)
(check-equal? (jacobi-symbol 4 5) 1)
(check-equal? (jacobi-symbol 7 5) -1)
(check-equal? (jacobi-symbol 5 3) -1)
(check-equal? (jacobi-symbol 25 53) 1)
(check-equal? (jacobi-symbol 21 1) 1)
(check-equal? (jacobi-symbol 21 21) 0)
(check-equal? (jacobi-symbol 12 3) 0)
(check-equal? (jacobi-symbol 30 59) -1)
(check-equal? (jacobi-symbol 7 51) -1)
(check-equal? (jacobi-symbol 22 55) 0))
> To view this discussion on the web visit
https://groups.google.com/d/msgid/racket-dev/CABefVgzpmfW7pieTs8cVaKbNwXZHVnhpjG6bTP6gHtg%3DJ0QenQ%40mail.gmail.com.