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

Last change on this file since 4356 was 4326, checked in by Marek Rychlik, 9 years ago

* empty log message *

File size: 2.4 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(in-package "RING")
23
24(defclass integer-ring (rational-field)
25 ((value :initarg :value :initform 0 :accessor integer-ring-value :type integer))
26 (:documentation "An object representing an integer.")
27 )
28
29(defmethod print-object ((self integer-ring) stream)
30 (print-unreadable-object (self stream :type t :identity t)
31 (with-accessors ((value integer-ring-value))
32 self
33 (format stream "VALUE=~A" value))))
34
35(defmethod unary-inverse ((self integer-ring))
36 "Invert SELF, possibly changing class to RATIONAL-FIELD."
37 (with-slots (value)
38 self
39 (case value
40 (1 self)
41 (-1 self)
42 (t
43 (unary-inverse (change-class self 'rational-field))))))
44
45(defmethod universal-gcd ((self integer-ring) (other integer-ring))
46 (with-slots (value)
47 self
48 (with-slots ((other-value value))
49 other
50 (make-instance 'integer-ring :value (gcd value other-value)))))
51
52(defmethod universal-ezgcd ((object integer-ring) (other integer-ring))
53 (with-slots (value)
54 object
55 (with-slots ((other-value value))
56 other
57 (let ((c (gcd value other-value)))
58 (values (make-instance 'integer-ring :value c)
59 (make-instance 'integer-ring :value (/ value c))
60 (make-instance 'integer-ring :value (/ other-value c)))))))
Note: See TracBrowser for help on using the repository browser.