1 | head 1.3;
|
---|
2 | access;
|
---|
3 | symbols;
|
---|
4 | locks; strict;
|
---|
5 | comment @;;; @;
|
---|
6 |
|
---|
7 |
|
---|
8 | 1.3
|
---|
9 | date 2009.01.22.04.06.12; author marek; state Exp;
|
---|
10 | branches;
|
---|
11 | next 1.2;
|
---|
12 |
|
---|
13 | 1.2
|
---|
14 | date 2009.01.19.09.29.25; author marek; state Exp;
|
---|
15 | branches;
|
---|
16 | next 1.1;
|
---|
17 |
|
---|
18 | 1.1
|
---|
19 | date 2009.01.19.06.48.27; author marek; state Exp;
|
---|
20 | branches;
|
---|
21 | next ;
|
---|
22 |
|
---|
23 |
|
---|
24 | desc
|
---|
25 | @@
|
---|
26 |
|
---|
27 |
|
---|
28 | 1.3
|
---|
29 | log
|
---|
30 | @*** empty log message ***
|
---|
31 | @
|
---|
32 | text
|
---|
33 | @#|
|
---|
34 | $Id$
|
---|
35 | *--------------------------------------------------------------------------*
|
---|
36 | | Copyright (C) 1994, Marek Rychlik (e-mail: rychlik@@math.arizona.edu) |
|
---|
37 | | Department of Mathematics, University of Arizona, Tucson, AZ 85721 |
|
---|
38 | | |
|
---|
39 | | Everyone is permitted to copy, distribute and modify the code in this |
|
---|
40 | | directory, as long as this copyright note is preserved verbatim. |
|
---|
41 | *--------------------------------------------------------------------------*
|
---|
42 | |#
|
---|
43 | (defpackage "POLY-WITH-SUGAR"
|
---|
44 | (:export poly-with-sugar-poly
|
---|
45 | poly-with-sugar-tail
|
---|
46 | poly-with-sugar-sugar
|
---|
47 | monom-sugar
|
---|
48 | term-sugar
|
---|
49 | monom-times-poly-with-sugar
|
---|
50 | scalar-times-poly-with-sugar
|
---|
51 | term-times-poly-with-sugar
|
---|
52 | minus-poly-with-sugar
|
---|
53 | poly-with-sugar+
|
---|
54 | poly-with-sugar-
|
---|
55 | poly-with-sugar-op
|
---|
56 | poly-with-sugar-zerop
|
---|
57 | poly-with-sugar-nreverse
|
---|
58 | poly-with-sugar-append
|
---|
59 | poly-with-sugar-lm
|
---|
60 | poly-with-sugar-lc
|
---|
61 | poly-with-sugar-lt
|
---|
62 | poly-add-sugar)
|
---|
63 | (:use "ORDER" "MONOM" "TERM" "TERM" "POLY" "COEFFICIENT-RING" "COMMON-LISP"))
|
---|
64 |
|
---|
65 | (in-package "POLY-WITH-SUGAR")
|
---|
66 |
|
---|
67 | #+debug(proclaim '(optimize (speed 0) (debug 3)))
|
---|
68 | #-debug(proclaim '(optimize (speed 3) (debug 0)))
|
---|
69 |
|
---|
70 | ;;----------------------------------------------------------------
|
---|
71 | ;; BASIC OPERATIONS ON POLYNOMIALS of many variables WITH SUGAR
|
---|
72 | ;; Hybrid operations involving polynomials and monomials or terms
|
---|
73 | ;;----------------------------------------------------------------
|
---|
74 | ;; The representation is as follows:
|
---|
75 | ;;
|
---|
76 | ;; polynomial-with-sugar: (poly . sugar)
|
---|
77 | ;;
|
---|
78 | ;;----------------------------------------------------------------
|
---|
79 |
|
---|
80 | (eval-when (compile)
|
---|
81 | (proclaim '(inline poly-with-sugar-poly
|
---|
82 | poly-with-sugar-sugar
|
---|
83 | poly-with-sugar-tail)))
|
---|
84 |
|
---|
85 | (defun poly-with-sugar-poly (p) (car p))
|
---|
86 | (defun poly-with-sugar-sugar (p) (cdr p))
|
---|
87 | (defun poly-with-sugar-tail (p) (cons (cdar p) (cdr p)))
|
---|
88 |
|
---|
89 | (defsetf poly-with-sugar-poly (p) (poly)
|
---|
90 | `(setf (car ,p) ,poly))
|
---|
91 |
|
---|
92 | (defsetf poly-with-sugar-sugar (p) (sugar)
|
---|
93 | `(setf (cdr ,p) ,sugar))
|
---|
94 |
|
---|
95 | (defsetf poly-with-sugar-tail (p) (tail)
|
---|
96 | `(setf (cdar ,p) ,tail))
|
---|
97 |
|
---|
98 | ;;----------------------------------------------------------------
|
---|
99 | ;; Sugar of monomials and terms
|
---|
100 | ;; The total degree is used
|
---|
101 | ;;----------------------------------------------------------------
|
---|
102 | (defun monom-sugar (m)
|
---|
103 | (total-degree m))
|
---|
104 |
|
---|
105 | (defun coefficient-sugar (c ring)
|
---|
106 | (funcall (ring-length ring) c))
|
---|
107 |
|
---|
108 | (defun term-sugar (term ring)
|
---|
109 | (declare (ignore ring))
|
---|
110 | (monom-sugar (term-monom term)))
|
---|
111 |
|
---|
112 | ;;----------------------------------------------------------------
|
---|
113 | ;; Initialize sugar of an ordinary polynomial
|
---|
114 | ;;----------------------------------------------------------------
|
---|
115 | (defun poly-add-sugar (poly ring)
|
---|
116 | (cons poly
|
---|
117 | (apply #'max (mapcar #'(lambda (term) (term-sugar term ring)) poly))))
|
---|
118 |
|
---|
119 | ;; Multiplies scalar c by a polynomial p
|
---|
120 | (defun scalar-times-poly-with-sugar (c p ring)
|
---|
121 | (cons (scalar-times-poly c (poly-with-sugar-poly p) ring)
|
---|
122 | (poly-with-sugar-sugar p)))
|
---|
123 |
|
---|
124 | ;; Multiplies term m by a poly-with-sugar f
|
---|
125 | (defun term-times-poly-with-sugar (term f ring)
|
---|
126 | (cons (term-times-poly term (poly-with-sugar-poly f) ring)
|
---|
127 | (+ (poly-with-sugar-sugar f) (term-sugar term ring))))
|
---|
128 |
|
---|
129 | ;; Multiply a monom by a poly-with-sugarnomial
|
---|
130 | (defun monom-times-poly-with-sugar (m f)
|
---|
131 | (cons
|
---|
132 | (monom-times-poly m (poly-with-sugar-poly f))
|
---|
133 | (+ (poly-with-sugar-sugar f) (monom-sugar m))))
|
---|
134 |
|
---|
135 | ;; Changes the sign of the polynomial f with sugar
|
---|
136 | (defun minus-poly-with-sugar (f ring)
|
---|
137 | (cons
|
---|
138 | (minus-poly (poly-with-sugar-poly f) ring)
|
---|
139 | (poly-with-sugar-poly f)))
|
---|
140 |
|
---|
141 | ;; Addition and subtraction of polynomials with sugar
|
---|
142 | (defun poly-with-sugar+ (p q pred ring)
|
---|
143 | (cons
|
---|
144 | (poly+ (poly-with-sugar-poly p) (poly-with-sugar-poly q) pred ring)
|
---|
145 | (max (poly-with-sugar-sugar p) (poly-with-sugar-sugar q))))
|
---|
146 |
|
---|
147 | ;; Addition and subtraction of polynomials with sugar
|
---|
148 | (defun poly-with-sugar- (p q pred ring)
|
---|
149 | (cons
|
---|
150 | (poly- (poly-with-sugar-poly p) (poly-with-sugar-poly q) pred ring)
|
---|
151 | (max (poly-with-sugar-sugar p) (poly-with-sugar-sugar q))))
|
---|
152 |
|
---|
153 | ;; Implement f-term*g
|
---|
154 | (defun poly-with-sugar-op (f term g pred ring)
|
---|
155 | (poly-with-sugar- f (term-times-poly-with-sugar term g ring) pred ring))
|
---|
156 |
|
---|
157 |
|
---|
158 | (eval-when (compile)
|
---|
159 | (proclaim '(inline poly-with-sugar-nreverse poly-with-sugar-append
|
---|
160 | poly-with-sugar-zerop poly-with-sugar-lm
|
---|
161 | poly-with-sugar-lt poly-with-sugar-lc)))
|
---|
162 | ;; Destructively reverse the order of terms in a polynomial with sugar
|
---|
163 | (defun poly-with-sugar-nreverse (p)
|
---|
164 | (setf (poly-with-sugar-poly p) (nreverse (poly-with-sugar-poly p)))
|
---|
165 | p)
|
---|
166 |
|
---|
167 | ;; Append two polynomials with sugar, which are assumed to be
|
---|
168 | ;; sorted and all terms of q are smaller than terms of p
|
---|
169 | (defun poly-with-sugar-append (p q)
|
---|
170 | (cons (append (poly-with-sugar-poly p) (poly-with-sugar-poly q))
|
---|
171 | (max (poly-with-sugar-sugar p) (poly-with-sugar-sugar q))))
|
---|
172 |
|
---|
173 | (defun poly-with-sugar-zerop (p)
|
---|
174 | (poly-zerop (poly-with-sugar-poly p)))
|
---|
175 |
|
---|
176 | (defun poly-with-sugar-lm (p)
|
---|
177 | (lm (poly-with-sugar-poly p)))
|
---|
178 |
|
---|
179 | (defun poly-with-sugar-lc (p)
|
---|
180 | (lc (poly-with-sugar-poly p)))
|
---|
181 |
|
---|
182 | (defun poly-with-sugar-lt (p)
|
---|
183 | (lt (poly-with-sugar-poly p)))
|
---|
184 | @
|
---|
185 |
|
---|
186 |
|
---|
187 | 1.2
|
---|
188 | log
|
---|
189 | @*** empty log message ***
|
---|
190 | @
|
---|
191 | text
|
---|
192 | @d35 2
|
---|
193 | a36 2
|
---|
194 | ;;(proclaim '(optimize (speed 0) (debug 3)))
|
---|
195 | (proclaim '(optimize (speed 3) (debug 0)))
|
---|
196 | @
|
---|
197 |
|
---|
198 |
|
---|
199 | 1.1
|
---|
200 | log
|
---|
201 | @Initial revision
|
---|
202 | @
|
---|
203 | text
|
---|
204 | @d2 1
|
---|
205 | a2 1
|
---|
206 | $Id: poly-with-sugar.lisp,v 1.33 1997/11/28 23:26:18 marek Exp $
|
---|
207 | d35 2
|
---|
208 | a36 4
|
---|
209 | (eval-when (compile)
|
---|
210 | (proclaim '(optimize (speed 3) (safety 0)))
|
---|
211 | (proclaim '(inline monom-times-poly-with-sugar scalar-times-poly-with-sugar
|
---|
212 | term-times-poly-with-sugar minus-poly-with-sugar poly-with-sugar-op)))
|
---|
213 | @
|
---|