close Warning: Can't synchronize with repository "(default)" (The repository directory has changed, you should resynchronize the repository with: trac-admin $ENV repository resync '(default)'). Look in the Trac log for more information.

source: branches/f4grobner/ring.lisp@ 4349

Last change on this file since 4349 was 4349, checked in by Marek Rychlik, 8 years ago

* empty log message *

File size: 3.7 KB
RevLine 
[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"
[4332]23 (:use :cl :copy)
[4228]24 (:export "RING"
[4342]25 "FIELD"
[4228]26 "ADD-TO"
27 "SUBTRACT-FROM"
28 "MULTIPLY-BY"
29 "DIVIDE-BY"
[4231]30 "UNARY-MINUS"
[4246]31 "UNARY-INVERSE"
[4249]32 "UNIVERSAL-GCD"
[4228]33 "UNIVERSAL-EZGCD"
34 "UNIVERSAL-EQUALP"
35 "UNIVERSAL-ZEROP"
[4279]36 "MAKE-ZERO-FOR"
37 "MAKE-UNIT-FOR"
[4323]38 "->SEXP"
39 "RATIONAL-FIELD"
40 "RATIONAL-FIELD-VALUE"
41 "MAKE-ZERO-FOR"
42 "MAKE-UNIT-FOR"
43 "INTEGER-RING"
44 "INTEGER-RING-VALUE"
[4349]45 "MULTIPLY"
[4323]46 )
47 (:documentation "Defines an abstract ring class and ring operations.")
48 )
[4228]49
50(in-package "RING")
51
52(defclass ring () () (:documentation "An abstract ring."))
[4342]53(defclass field (ring) () (:documentation "An abstract ring."))
[4228]54
[4246]55(defgeneric multiply-by (self other)
[4228]56 (:documentation "Multiply SELF by OTHER."))
57
[4246]58(defgeneric divide-by (self other)
59 (:documentation "Divide SELF by OTHER."))
60
[4228]61(defgeneric add-to (self other)
62 (:documentation "Add OTHER to SELF."))
63
[4246]64(defgeneric subtract-from (self other)
[4228]65 (:documentation "Subtract OTHER from SELF."))
66
[4230]67(defgeneric unary-minus (self)
[4234]68 (:documentation "Changes SELF to its negative."))
[4230]69
[4246]70(defgeneric unary-inverse (self)
[4273]71 (:documentation "Changes SELF to the unary inverse of SELF."))
[4246]72
[4257]73(defgeneric universal-gcd (object other)
[4274]74 (:documentation "Returns GCD(OBJECT, OTHER)"))
[4228]75
[4248]76(defgeneric universal-ezgcd (x y)
77 (:documentation "Solves the diophantine system: X=C*X1, Y=C*X2,
[4258]78C=GCD(X,Y). It returns three values: C, X1 and Y1. The result may be obtained by
[4248]79the Euclidean algorithm."))
80
[4228]81(defgeneric universal-equalp (self other)
82 (:documentation "Return T if objects SELF and OTHER are equal, NIL otherwise.")
[4311]83 (:method ((object1 cons) (object2 cons)) (every #'universal-equalp object1 object2))
84 (:method ((self number) (other number)) (= self other)))
[4228]85
86(defgeneric universal-zerop (self)
87 (:documentation "Return T if SELF is a zero in the ring it belongs to."))
88
[4230]89(defgeneric ->sexp (self &optional vars)
[4228]90 (:documentation "Convert SELF to an S-expression."))
[4248]91
[4278]92(defgeneric make-zero-for (self)
[4322]93 (:documentation "Create a zero in the ring of SELF. A fresh instance
94should be returned upon every call."))
[4278]95
96(defgeneric make-unit-for (self)
[4322]97 (:documentation "Create a unit in the ring of SELF. A fresh instance
98should be returned upon every call."))
[4349]99
100(defgeneric multiply (factor &rest more-factors)
101 (:documentation "Successively multiplies factor FACTOR by the remaining arguments
102MORE-FACTORS, using MULTIPLY-BY to multiply two factors. Thus
103FACTOR may be destructively modified.")
104 (:method ((factor t) & rest more-factors)
105 (reduce #'multiply-by more-factors :initial-value (copy-instance factor))))
106
Note: See TracBrowser for help on using the repository browser.