[4228] | 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 "RING"
|
---|
| 23 | (:use :cl)
|
---|
| 24 | (:export "RING"
|
---|
| 25 | "ADD-TO"
|
---|
| 26 | "SUBTRACT-FROM"
|
---|
| 27 | "MULTIPLY-BY"
|
---|
| 28 | "DIVIDE-BY"
|
---|
[4231] | 29 | "UNARY-MINUS"
|
---|
[4246] | 30 | "UNARY-INVERSE"
|
---|
[4249] | 31 | "UNIVERSAL-GCD"
|
---|
[4228] | 32 | "UNIVERSAL-EZGCD"
|
---|
| 33 | "UNIVERSAL-EQUALP"
|
---|
| 34 | "UNIVERSAL-ZEROP"
|
---|
| 35 | "->SEXP")
|
---|
| 36 | (:documentation "Defines an abstract ring class and ring operations."))
|
---|
| 37 |
|
---|
| 38 | (in-package "RING")
|
---|
| 39 |
|
---|
| 40 | (defclass ring () () (:documentation "An abstract ring."))
|
---|
| 41 |
|
---|
[4246] | 42 | (defgeneric multiply-by (self other)
|
---|
[4228] | 43 | (:documentation "Multiply SELF by OTHER."))
|
---|
| 44 |
|
---|
[4246] | 45 | (defgeneric divide-by (self other)
|
---|
| 46 | (:documentation "Divide SELF by OTHER."))
|
---|
| 47 |
|
---|
[4228] | 48 | (defgeneric add-to (self other)
|
---|
| 49 | (:documentation "Add OTHER to SELF."))
|
---|
| 50 |
|
---|
[4246] | 51 | (defgeneric subtract-from (self other)
|
---|
[4228] | 52 | (:documentation "Subtract OTHER from SELF."))
|
---|
| 53 |
|
---|
[4230] | 54 | (defgeneric unary-minus (self)
|
---|
[4234] | 55 | (:documentation "Changes SELF to its negative."))
|
---|
[4230] | 56 |
|
---|
[4246] | 57 | (defgeneric unary-inverse (self)
|
---|
| 58 | (:documentation "Returns the unary inverse of SELF."))
|
---|
| 59 |
|
---|
[4257] | 60 | (defgeneric universal-gcd (object other)
|
---|
| 61 | (:documentation "Return GCD(OBJECT, OTHER)"))
|
---|
[4228] | 62 |
|
---|
[4248] | 63 | (defgeneric universal-ezgcd (x y)
|
---|
| 64 | (:documentation "Solves the diophantine system: X=C*X1, Y=C*X2,
|
---|
[4258] | 65 | C=GCD(X,Y). It returns three values: C, X1 and Y1. The result may be obtained by
|
---|
[4248] | 66 | the Euclidean algorithm."))
|
---|
| 67 |
|
---|
[4228] | 68 | (defgeneric universal-equalp (self other)
|
---|
| 69 | (:documentation "Return T if objects SELF and OTHER are equal, NIL otherwise.")
|
---|
| 70 | (:method ((object1 cons) (object2 cons)) (every #'universal-equalp object1 object2)))
|
---|
| 71 |
|
---|
| 72 | (defgeneric universal-zerop (self)
|
---|
| 73 | (:documentation "Return T if SELF is a zero in the ring it belongs to."))
|
---|
| 74 |
|
---|
[4230] | 75 | (defgeneric ->sexp (self &optional vars)
|
---|
[4228] | 76 | (:documentation "Convert SELF to an S-expression."))
|
---|
[4248] | 77 |
|
---|