diff options
author | Masaya Tojo <masaya@tojo.tokyo> | 2024-06-12 02:43:00 +0900 |
---|---|---|
committer | Masaya Tojo <masaya@tojo.tokyo> | 2024-06-12 02:43:00 +0900 |
commit | a1b1d10ad5fc505f8b83ac6976e5eb68b87427ff (patch) | |
tree | fc178e36cbd7bbb45f9043062a74e4e6cab1ed94 | |
parent | 7e9013fc2ae5d82dfc0b152089c94d6c78e245b3 (diff) |
Add group modules
-rw-r--r-- | algebraic-structures.egg | 3 | ||||
-rw-r--r-- | algebraic-structures.group.make.scm | 16 | ||||
-rw-r--r-- | algebraic-structures.group.number.product.scm | 8 | ||||
-rw-r--r-- | algebraic-structures.group.number.sum.scm | 8 | ||||
-rw-r--r-- | tests/run.scm | 13 |
5 files changed, 48 insertions, 0 deletions
diff --git a/algebraic-structures.egg b/algebraic-structures.egg index 9b21678..bf62bd3 100644 --- a/algebraic-structures.egg +++ b/algebraic-structures.egg @@ -16,6 +16,9 @@ (extension algebraic-structures.monoid.number.product.base) (extension algebraic-structures.monoid.number.product) (extension algebraic-structures.monoid.make.fold) + (extension algebraic-structures.group.make) + (extension algebraic-structures.group.number.sum) + (extension algebraic-structures.group.number.product) (extension algebraic-structures.foldable.make) (extension algebraic-structures.foldable.list.base) (extension algebraic-structures.foldable.list) diff --git a/algebraic-structures.group.make.scm b/algebraic-structures.group.make.scm new file mode 100644 index 0000000..7568ac9 --- /dev/null +++ b/algebraic-structures.group.make.scm @@ -0,0 +1,16 @@ +(functor ((algebraic-structures group make) (M (<> unit inv))) + (<> unit inv pow) + (import M + scheme + (chicken base)) + + (define (pow x n) + (assert (exact-integer? n)) + (if (negative? n) + (pow (inv x) (- n)) + (let loop ((i n) + (acc unit)) + (if (= i 0) + acc + (loop (sub1 i) + (<> acc x))))))) diff --git a/algebraic-structures.group.number.product.scm b/algebraic-structures.group.number.product.scm new file mode 100644 index 0000000..a57cdf6 --- /dev/null +++ b/algebraic-structures.group.number.product.scm @@ -0,0 +1,8 @@ +(import (only (algebraic-structures group make))) +(module (algebraic-structures group number product) = (algebraic-structures group make) + (import scheme + (chicken module) + (algebraic-structures monoid number product)) + (export <> unit inv) + + (define (inv x) (/ x))) diff --git a/algebraic-structures.group.number.sum.scm b/algebraic-structures.group.number.sum.scm new file mode 100644 index 0000000..2bb7331 --- /dev/null +++ b/algebraic-structures.group.number.sum.scm @@ -0,0 +1,8 @@ +(import (only (algebraic-structures group make))) +(module (algebraic-structures group number sum) = (algebraic-structures group make) + (import scheme + (chicken module) + (algebraic-structures monoid number sum)) + (export <> unit inv) + + (define (inv x) (- x))) diff --git a/tests/run.scm b/tests/run.scm index ed2cd8f..6b6a74e 100644 --- a/tests/run.scm +++ b/tests/run.scm @@ -107,6 +107,19 @@ (test-end "monoid") +(test-begin "group") + +(import (prefix (algebraic-structures group number product) product:)) +(import (prefix (algebraic-structures group number sum) sum:)) + +(test -9 (sum:inv 9)) +(test 9 (sum:pow 3 3)) + +(test 1/9 (product:inv 9)) +(test 9 (product:pow 3 2)) + +(test-end "group") + (test-begin "functor") (test '((a) (b) (c)) (list:map list '(a b c))) |