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@ 4240

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

* empty log message *

File size: 3.2 KB
RevLine 
[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"
[4233]30 "UNARY-MINUS"
[4224]31 "UNIVERSAL-EZGCD"
32 "UNIVERSAL-EQUALP"
[4227]33 "UNIVERSAL-ZEROP"
[4238]34 "->SEXP")
[4227]35 (:documentation "Wraps integers into an object."))
[4224]36
[4227]37(in-package "INTEGER-RING")
[4224]38
39(defclass integer-ring (ring)
40 ((value :initarg :value :initform 0 :accessor integer-ring-value))
41 (:documentation "An object representing an integer.")
42 )
43
44(defmethod print-object ((self integer-ring) stream)
45 (print-unreadable-object (self stream :type t :identity t)
46 (with-accessors ((value integer-ring-value))
47 self
48 (format stream "VALUE=~A" value))))
49
50(defmethod multiply-by ((self integer-ring) (other integer-ring))
51 (with-slots (value)
52 self
53 (with-slots ((other-value value))
54 other
55 (setf value (* value other-value))))
56 self)
57
[4227]58(defmethod divide-by ((self integer-ring) (other integer-ring))
59 (with-slots (value)
60 self
61 (with-slots ((other-value value))
62 other
63 (setf value (/ value other-value))))
64 self)
65
[4224]66(defmethod add-to ((self integer-ring) (other integer-ring))
67 (with-slots (value)
68 self
69 (with-slots ((other-value value))
70 other
71 (setf value (+ value other-value))))
72 self)
73
74(defmethod subtract-from ((self integer-ring) (other integer-ring))
75 (with-slots (value)
76 self
77 (with-slots ((other-value value))
78 other
79 (setf value (- value other-value))))
80 self)
81
[4232]82(defmethod unary-minus ((self integer-ring))
83 (with-slots (value)
84 self
85 (setf value (- value)))
86 self)
87
[4224]88(defmethod universal-ezgcd ((self integer-ring) (other integer-ring))
89 (with-slots (value)
90 self
91 (with-slots ((other-value value))
92 other
93 (setf value (gcd value other-value))))
94 self)
[4227]95
96(defmethod universal-equalp ((self integer-ring) (other integer-ring))
97 (with-slots (value)
98 self
99 (with-slots ((other-value value))
100 other
101 (= value other-value))))
102
[4229]103(defmethod ->sexp ((self integer-ring) &optional vars)
104 (declare (ignore vars))
[4227]105 (integer-ring-value self))
Note: See TracBrowser for help on using the repository browser.