bugMIT/GNU Scheme - Bugs: bug #18328, modint:expt doesn't work

 
 

bug #18328: modint:expt doesn't work

Submitter:  None
Submitted:  Sun 19 Nov 2006 07:48:07 PM UTC
   
 
Category:  scmutils Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect behavior
Status:  None Privacy:  Public
Assigned to:  None Originator Name:  Dan Gildea
Originator Email:  -email is unavailable- Open/Closed:  Closed
Keywords: 
* Mandatory Fields

Add a New Comment Rich Markup
   

Sat 07 Mar 2009 09:06:13 PM UTC, comment #2: 

This appears to have been fixed shortly after it was submitted.

Taylor R. Campbell <riastradh>
Group Member
Sun 19 Nov 2006 09:49:54 PM UTC, comment #1: 

This is a bug in scmutils, which isn't really a part of the MIT/GNU Scheme system; it's an add-on library maintained by Gerry Sussman.  I'll forward the bug report to him, but in the future you should contact him directly: user "gjs", host "csail.mit.edu".

Chris Hanson <cph>
Group administrator
Sun 19 Nov 2006 07:48:07 PM UTC, original submission:  

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)))))

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by riastradh (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2009-03-07 riastradh Open/ClosedOpen Closed
    2006-11-19 cph Categoryruntime scmutils
    2006-11-19 None Carbon-Copy- Added -unavailable-

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code