source: CGBLisp/trunk/src/coefficient-ring.lisp@ 14

Last change on this file since 14 was 14, checked in by Marek Rychlik, 15 years ago

Moving sources to trunk

File size: 3.5 KB
Line 
1;;; -*- Mode: Lisp; Syntax: Common-Lisp; Package: Grobner; Base: 10 -*-
2#|
3 $Id: coefficient-ring.lisp,v 1.4 2009/01/22 03:59:21 marek Exp $
4 *--------------------------------------------------------------------------*
5 | Copyright (C) 1994, Marek Rychlik (e-mail: rychlik@math.arizona.edu) |
6 | Department of Mathematics, University of Arizona, Tucson, AZ 85721 |
7 | |
8 | Everyone is permitted to copy, distribute and modify the code in this |
9 | directory, as long as this copyright note is preserved verbatim. |
10 *--------------------------------------------------------------------------*
11|#
12
13(defpackage "COEFFICIENT-RING"
14 (:export ring
15 ring-+
16 ring--
17 ring-*
18 ring-/
19 ring-gcd
20 ring-lcm
21 ring-signum
22 ring-zerop
23 ring-unit
24 ring-length
25 ring-numerator
26 ring-denominator
27 make-ring
28 *coefficient-ring*
29 *ring-of-integers*
30 *field-of-rationals*
31 field-modulo-prime
32 )
33 (:use "MODULAR" "COMMON-LISP"))
34
35(in-package "COEFFICIENT-RING")
36
37(proclaim '(optimize (speed 0) (debug 3)))
38
39(defstruct ring
40 "The structure whose slots are bound to functions
41performing usual ring operations. In addition to usual arithmetical
42operations, bindings for other common operations
43which increase efficiency of Grobner basis calculations are also
44included. They are as follows:
45 GCD - greatest common divisor;
46 LCM - least common multiple;
47 ZEROP - test whether an element is zero;
48 SIGNUM - the sign of a ring element (+1, -1 or zero);
49 UNIT - the unit of the ring;
50 NUMERATOR - the numerator, if a ring of fractions
51 DENOMINATOR - the denominator, if a ring of fractions
52 LENGTH - an integer giving the approximate length
53 of the representation; for example, for integers
54 its default binding is #'integer-length;
55"
56 + - * / gcd lcm zerop unit length signum numerator denominator)
57
58(defvar *ring-of-integers*
59 (make-ring :+ #'+
60 :- #'-
61 :* #'*
62 :/ #'floor
63 :gcd #'gcd
64 :lcm #'lcm
65 :zerop #'zerop
66 :signum #'signum
67 :unit 1
68 :length #'integer-length
69 :numerator #'numerator
70 :denominator #'denominator)
71 "Operations in the ring of integers.")
72
73(defvar *field-of-rationals*
74 (make-ring
75 :+ #'+
76 :- #'-
77 :* #'*
78 :/ #'/
79 :gcd #'(lambda (&rest r) (declare (ignore r)) 1)
80 :lcm #'(lambda (&rest r) (apply #'* r))
81 :zerop #'zerop
82 :signum #'signum
83 :unit 1
84 :length #'(lambda (x) (+ (integer-length (numerator x))
85 (integer-length (denominator x))))
86 :numerator #'numerator
87 :denominator #'denominator)
88 "Operations on the field of rational numbers.")
89
90(defun field-modulo-prime (modulus)
91 "Return a RING structure with operations bound
92to the arithmetical operations modulo MODULUS, which
93should be a prime."
94 (make-ring
95 :+ #'(lambda (&rest r) (mod (apply #'+ r) modulus))
96 :- #'(lambda (&rest r) (mod (apply #'- r) modulus))
97 :* #'(lambda (&rest r) (mod (apply #'* r) modulus))
98 :/ (make-modular-division modulus)
99 :gcd #'(lambda (&rest r) (declare (ignore r)) 1)
100 :lcm #'(lambda (&rest r) (mod (apply #'* r) modulus))
101 :zerop #'zerop
102 :signum #'(lambda (x) (if (zerop x) 0 1))
103 :unit 1
104 :length #'(lambda (x) (declare (ignore x)) 1)
105 :numerator #'identity
106 :denominator #'(lambda (x) (declare (ignore x)) 1)))
107
108
109(defvar *coefficient-ring* *ring-of-integers*
110 "The default RING structure, used in most operations
111on the coefficients of polynomials. It should be carefully
112set if rings other than the default ring is used.")
113
Note: See TracBrowser for help on using the repository browser.