[4224] | 1 | ;;; -*- Mode: Lisp -*-
|
---|
| 2 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 3 | ;;;
|
---|
| 4 | ;;; Copyright (C) 1999, 2002, 2009, 2015 Marek Rychlik <rychlik@u.arizona.edu>
|
---|
| 5 | ;;;
|
---|
| 6 | ;;; This program is free software; you can redistribute it and/or modify
|
---|
| 7 | ;;; it under the terms of the GNU General Public License as published by
|
---|
| 8 | ;;; the Free Software Foundation; either version 2 of the License, or
|
---|
| 9 | ;;; (at your option) any later version.
|
---|
| 10 | ;;;
|
---|
| 11 | ;;; This program is distributed in the hope that it will be useful,
|
---|
| 12 | ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 14 | ;;; GNU General Public License for more details.
|
---|
| 15 | ;;;
|
---|
| 16 | ;;; You should have received a copy of the GNU General Public License
|
---|
| 17 | ;;; along with this program; if not, write to the Free Software
|
---|
| 18 | ;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
| 19 | ;;;
|
---|
| 20 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
---|
| 21 |
|
---|
| 22 | (defpackage "INTEGER-RING"
|
---|
| 23 | (:use :cl :copy :ring)
|
---|
| 24 | (:export "INTEGER-RING"
|
---|
| 25 | "INTEGER-RING-VALUE"
|
---|
| 26 | "ADD-TO"
|
---|
| 27 | "SUBTRACT-FROM"
|
---|
| 28 | "MULTIPLY-BY"
|
---|
| 29 | "DIVIDE-BY"
|
---|
| 30 | "UNIVERSAL-EZGCD"
|
---|
| 31 | "UNIVERSAL-EQUALP"
|
---|
[4227] | 32 | "UNIVERSAL-ZEROP"
|
---|
| 33 | "->SEXP")
|
---|
| 34 | (:documentation "Wraps integers into an object."))
|
---|
[4224] | 35 |
|
---|
[4227] | 36 | (in-package "INTEGER-RING")
|
---|
[4224] | 37 |
|
---|
| 38 | (defclass integer-ring (ring)
|
---|
| 39 | ((value :initarg :value :initform 0 :accessor integer-ring-value))
|
---|
| 40 | (:documentation "An object representing an integer.")
|
---|
| 41 | )
|
---|
| 42 |
|
---|
| 43 | (defmethod print-object ((self integer-ring) stream)
|
---|
| 44 | (print-unreadable-object (self stream :type t :identity t)
|
---|
| 45 | (with-accessors ((value integer-ring-value))
|
---|
| 46 | self
|
---|
| 47 | (format stream "VALUE=~A" value))))
|
---|
| 48 |
|
---|
| 49 | (defmethod multiply-by ((self integer-ring) (other integer-ring))
|
---|
| 50 | (with-slots (value)
|
---|
| 51 | self
|
---|
| 52 | (with-slots ((other-value value))
|
---|
| 53 | other
|
---|
| 54 | (setf value (* value other-value))))
|
---|
| 55 | self)
|
---|
| 56 |
|
---|
[4227] | 57 | (defmethod divide-by ((self integer-ring) (other integer-ring))
|
---|
| 58 | (with-slots (value)
|
---|
| 59 | self
|
---|
| 60 | (with-slots ((other-value value))
|
---|
| 61 | other
|
---|
| 62 | (setf value (/ value other-value))))
|
---|
| 63 | self)
|
---|
| 64 |
|
---|
[4224] | 65 | (defmethod add-to ((self integer-ring) (other integer-ring))
|
---|
| 66 | (with-slots (value)
|
---|
| 67 | self
|
---|
| 68 | (with-slots ((other-value value))
|
---|
| 69 | other
|
---|
| 70 | (setf value (+ value other-value))))
|
---|
| 71 | self)
|
---|
| 72 |
|
---|
| 73 | (defmethod subtract-from ((self integer-ring) (other integer-ring))
|
---|
| 74 | (with-slots (value)
|
---|
| 75 | self
|
---|
| 76 | (with-slots ((other-value value))
|
---|
| 77 | other
|
---|
| 78 | (setf value (- value other-value))))
|
---|
| 79 | self)
|
---|
| 80 |
|
---|
| 81 | (defmethod universal-ezgcd ((self integer-ring) (other integer-ring))
|
---|
| 82 | (with-slots (value)
|
---|
| 83 | self
|
---|
| 84 | (with-slots ((other-value value))
|
---|
| 85 | other
|
---|
| 86 | (setf value (gcd value other-value))))
|
---|
| 87 | self)
|
---|
[4227] | 88 |
|
---|
| 89 | (defmethod universal-equalp ((self integer-ring) (other integer-ring))
|
---|
| 90 | (with-slots (value)
|
---|
| 91 | self
|
---|
| 92 | (with-slots ((other-value value))
|
---|
| 93 | other
|
---|
| 94 | (= value other-value))))
|
---|
| 95 |
|
---|
[4229] | 96 | (defmethod ->sexp ((self integer-ring) &optional vars)
|
---|
| 97 | (declare (ignore vars))
|
---|
[4227] | 98 | (integer-ring-value self))
|
---|