bug-mit-scheme
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-mit-scheme] [bug #18328] modint:expt doesn't work


From: anonymous
Subject: [Bug-mit-scheme] [bug #18328] modint:expt doesn't work
Date: Sun, 19 Nov 2006 19:48:08 +0000
User-agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/312.8 (KHTML, like Gecko) Safari/312.6

URL:
  <http://savannah.gnu.org/bugs/?18328>

                 Summary: modint:expt doesn't work
                 Project: MIT/GNU Scheme
            Submitted by: None
            Submitted on: Sunday 11/19/2006 at 19:48 UTC
                Category: runtime
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: Incorrect behavior
                  Status: None
                 Privacy: Public
             Assigned to: None
         Originator Name: Dan Gildea
        Originator Email: address@hidden
             Open/Closed: Open
                Keywords: 

    _______________________________________________________

Details:

The expt operator doesn't work for modular integers.

1 ]=> (expt (mod:make 3 10) (mod:make 7 10))

;The procedure #[compiled-closure 12 ("modarith" #x9) #x60 #x1de6008
#x1de683c] has been called with 3 arguments; it requires exactly (2 . 2)
;To continue, call RESTART with an option number:
; (RESTART 1) => Return to read-eval-print level 1.

I think this should fix the problem:

 (define (modint:expt base exponent p)
   (define (square x)
-    (mod:* x x p))
+    (modint:* x x p))
   (let lp ((exponent exponent))
     (cond ((int:= exponent 0) 1)
          ((even? exponent)
           (square (lp (quotient exponent 2))))
          (else
-          (mod:* base (lp (int:- exponent 1)) p)))))
+          (modint:* base (lp (int:- exponent 1)) p)))))




    _______________________________________________________

Carbon-Copy List:

CC Address                          | Comment
------------------------------------+-----------------------------
Available only the item webpage     | Originator Email




    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?18328>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]