modular-arithmetic

Changes On Branch chicken-5
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch chicken-5 Excluding Merge-Ins

This is equivalent to a diff from 0850058f44 to 22b1a91ebf

2018-08-18
16:34
Added license information Leaf check-in: 22b1a91ebf user: murphy tags: v1.0.3, chicken-5
16:30
Added release information file check-in: b47b80eccd user: murphy tags: chicken-5
16:26
Ported the egg to CHICKEN 5 check-in: 8bb517f3c0 user: murphy tags: chicken-5
15:58
imported v1.0.2 Leaf check-in: 0850058f44 user: murphy tags: trunk, v1.0.2
15:57
imported v1.0.1 check-in: 529ec5356a user: murphy tags: trunk, v1.0.1

Added LICENSE.txt.























































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Copyright (c) 2010, Thomas Chust
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright notice,
  this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
  notice, this list of conditions and the following disclaimer in the
  documentation and/or other materials provided with the distribution.
* Neither the name of the author nor the names of its contributors may
  be used to endorse or promote products derived from this software
  without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Added modular-arithmetic.egg.























>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
((category math)
 (synopsis "Modular Arithmetic on Finite Fields")
 (author "Thomas Chust")
 (license "BSD")
 (version "1.0.3")
 (dependencies srfi-1 matchable)
 (test-dependencies test)
 (components
   (extension modular-arithmetic)))

;; vim: set ai et ts=8 sts=2 sw=2 ft=scheme: ;;

Deleted modular-arithmetic.meta.

1
2
3
4
5
6
7
8
9
((egg "modular-arithmetic.egg")
 (files "modular-arithmetic.setup" "modular-arithmetic.meta" "modular-arithmetic.release-info" "modular-arithmetic.scm" "tests/run.scm")
 (needs numbers matchable)
 (test-depends test)
 (category math)
 (synopsis "Modular Arithmetic on Finite Fields")
 (author "Thomas Chust")
 (doc-from-wiki)
 (license "BSD"))
<
<
<
<
<
<
<
<
<


















Added modular-arithmetic.release-info.













>
>
>
>
>
>
1
2
3
4
5
6
(repo fossil "https://chust.org/repos/chicken-{egg-name}")

(uri targz "https://chust.org/repos/chicken-{egg-name}/tarball/{egg-name}.tar.gz?uuid=v{egg-release}")
(release "1.0.3")

;; vim: set ai et ts=8 sts=2 sw=2 ft=scheme: ;;

Changes to modular-arithmetic.scm.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26


27
28
29
30
31
32
33
(require-library
 srfi-1
 numbers matchable)

(module modular-arithmetic
  (xgcd mod+ mod- mod* mod/ modexpt with-modulus)
  (import
   (except scheme
	   + - * / = > < >= <=
	   number->string string->number
	   exp log sin cos tan asin acos atan expt sqrt
	   quotient modulo remainder numerator denominator
	   abs max min gcd lcm
	   positive? negative? odd? even? zero? exact? inexact?
	   floor ceiling truncate round
	   inexact->exact exact->inexact
	   number? complex? real? rational? integer?
	   real-part imag-part magnitude)
   (except chicken
	   add1 sub1 signum
	   bitwise-and bitwise-ior bitwise-xor bitwise-not
	   arithmetic-shift)
   srfi-1
   numbers)
  (import-for-syntax
   scheme chicken matchable)



;; Extended GCD
(define (xgcd a b)
  (let-values ([(q m) (quotient&modulo a b)])
    (if (zero? m)
	(values 0 1)
	(let-values ([(x y) (xgcd b m)])
<
<
<
<



|
<
<
<
<
<
<
<
<
<
<
|
<
|
<
|
<

|
>
>











1
2
3
4










5

6

7

8
9
10
11
12
13
14
15
16
17
18




(module modular-arithmetic
  (xgcd mod+ mod- mod* mod/ modexpt with-modulus)
  (import
    scheme










    (chicken base)

    (chicken bitwise)

    srfi-1)

  (import-for-syntax
    scheme
    (chicken base)
    matchable)

;; Extended GCD
(define (xgcd a b)
  (let-values ([(q m) (quotient&modulo a b)])
    (if (zero? m)
	(values 0 1)
	(let-values ([(x y) (xgcd b m)])
94
95
96
97
98
99
100


			[sub1 (lambda (n) (- n 1))]
			[* (,(rename 'mod*) ,~modulus)]
			[/ (,(rename 'mod/) ,~modulus)]
			[expt (,(rename 'modexpt) ,~modulus)])
               ,@body)))]))))

)









>
>
79
80
81
82
83
84
85
86
87
			[sub1 (lambda (n) (- n 1))]
			[* (,(rename 'mod*) ,~modulus)]
			[/ (,(rename 'mod/) ,~modulus)]
			[expt (,(rename 'modexpt) ,~modulus)])
               ,@body)))]))))

)

;; vim: set ai et ts=8 sts=2 sw=2 ft=scheme: ;;

Deleted modular-arithmetic.setup.

1
2
3
4
5
6
7
8
9
(compile -s -O2 -d1 "modular-arithmetic.scm" -j modular-arithmetic)
(compile -c -O2 -d1 "modular-arithmetic.scm" -j modular-arithmetic -unit modular-arithmetic)
(compile -s -O2 -d0 "modular-arithmetic.import.scm")

(install-extension
 'modular-arithmetic
 '("modular-arithmetic.so" "modular-arithmetic.o" "modular-arithmetic.import.so")
 '((version 1.0.2)
   (static "modular-arithmetic.o")))
<
<
<
<
<
<
<
<
<


















Changes to tests/run.scm.

1
2
3
4
5
6
7
8
9
(require-extension
 test modular-arithmetic)

(test-group "Modular Arithmetic"

  (test "Extended GCD"
    '(3 -2)
    (receive (xgcd 15 21)))

|
|







1
2
3
4
5
6
7
8
9
(import
  modular-arithmetic test)

(test-group "Modular Arithmetic"

  (test "Extended GCD"
    '(3 -2)
    (receive (xgcd 15 21)))