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/integer-ring.lisp@ 4224

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

* empty log message *

File size: 2.5 KB
Line 
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"
32 "UNIVERSAL-ZEROP"))
33
34
35(defclass integer-ring (ring)
36 ((value :initarg :value :initform 0 :accessor integer-ring-value))
37 (:documentation "An object representing an integer.")
38 )
39
40(defmethod print-object ((self integer-ring) stream)
41 (print-unreadable-object (self stream :type t :identity t)
42 (with-accessors ((value integer-ring-value))
43 self
44 (format stream "VALUE=~A" value))))
45
46(defmethod multiply-by ((self integer-ring) (other integer-ring))
47 (with-slots (value)
48 self
49 (with-slots ((other-value value))
50 other
51 (setf value (* value other-value))))
52 self)
53
54(defmethod add-to ((self integer-ring) (other integer-ring))
55 (with-slots (value)
56 self
57 (with-slots ((other-value value))
58 other
59 (setf value (+ value other-value))))
60 self)
61
62(defmethod subtract-from ((self integer-ring) (other integer-ring))
63 (with-slots (value)
64 self
65 (with-slots ((other-value value))
66 other
67 (setf value (- value other-value))))
68 self)
69
70(defmethod universal-ezgcd ((self integer-ring) (other integer-ring))
71 (with-slots (value)
72 self
73 (with-slots ((other-value value))
74 other
75 (setf value (gcd value other-value))))
76 self)
Note: See TracBrowser for help on using the repository browser.