1 | head 1.4;
|
---|
2 | access;
|
---|
3 | symbols;
|
---|
4 | locks; strict;
|
---|
5 | comment @;;; @;
|
---|
6 |
|
---|
7 |
|
---|
8 | 1.4
|
---|
9 | date 2009.01.22.04.05.32; author marek; state Exp;
|
---|
10 | branches;
|
---|
11 | next 1.3;
|
---|
12 |
|
---|
13 | 1.3
|
---|
14 | date 2009.01.19.09.28.20; author marek; state Exp;
|
---|
15 | branches;
|
---|
16 | next 1.2;
|
---|
17 |
|
---|
18 | 1.2
|
---|
19 | date 2009.01.19.07.51.29; author marek; state Exp;
|
---|
20 | branches;
|
---|
21 | next 1.1;
|
---|
22 |
|
---|
23 | 1.1
|
---|
24 | date 2009.01.19.07.00.23; author marek; state Exp;
|
---|
25 | branches;
|
---|
26 | next ;
|
---|
27 |
|
---|
28 |
|
---|
29 | desc
|
---|
30 | @@
|
---|
31 |
|
---|
32 |
|
---|
33 | 1.4
|
---|
34 | log
|
---|
35 | @*** empty log message ***
|
---|
36 | @
|
---|
37 | text
|
---|
38 | @#|
|
---|
39 | $Id$
|
---|
40 | *--------------------------------------------------------------------------*
|
---|
41 | | Copyright (C) 1994, Marek Rychlik (e-mail: rychlik@@math.arizona.edu) |
|
---|
42 | | Department of Mathematics, University of Arizona, Tucson, AZ 85721 |
|
---|
43 | | |
|
---|
44 | | Everyone is permitted to copy, distribute and modify the code in this |
|
---|
45 | | directory, as long as this copyright note is preserved verbatim. |
|
---|
46 | *--------------------------------------------------------------------------*
|
---|
47 | |#
|
---|
48 | (defpackage "POLY-GCD"
|
---|
49 | (:export poly-gcd poly-content poly-pseudo-divide poly-primitive-part
|
---|
50 | poly-pseudo-remainder)
|
---|
51 | (:use "ORDER" "POLY" "DIVISION" "COMMON-LISP"))
|
---|
52 |
|
---|
53 | (in-package "POLY-GCD")
|
---|
54 |
|
---|
55 | #+debug(proclaim '(optimize (speed 0) (debug 3)))
|
---|
56 | #-debug(proclaim '(optimize (speed 3) (debug 0)))
|
---|
57 |
|
---|
58 | ;; This package calculates GCD of polynomials over integers.
|
---|
59 | ;; They are assumed to be ordered lexicographically.
|
---|
60 | ;;
|
---|
61 | ;; The algorithm is that on p. 57 of Geddes, Czapor, Labahn
|
---|
62 | ;; Given polynomials a(x),b(x) in D[x] where D is a UFD, we
|
---|
63 | ;; compute g(x)=GCD(a(x),b(x))
|
---|
64 | ;; Assume that the poly's are sorted lexicographically
|
---|
65 |
|
---|
66 | (defun poly-gcd (a b)
|
---|
67 | (cond
|
---|
68 | ((endp a) b)
|
---|
69 | ((endp b) a)
|
---|
70 | ((endp (caar a)) ;scalar
|
---|
71 | (list (cons nil (gcd (cdar a) (cdar b)))))
|
---|
72 | (t
|
---|
73 | (do* ((r nil (poly-pseudo-remainder c d))
|
---|
74 | (c (poly-primitive-part a) d)
|
---|
75 | (d (poly-primitive-part b) (poly-primitive-part r)))
|
---|
76 | ((endp d)
|
---|
77 | (poly* (poly-extend
|
---|
78 | (poly-gcd (poly-content a) (poly-content b)))
|
---|
79 | c))))))
|
---|
80 |
|
---|
81 | ;; Perform a pseudo-division in k[x2,....,xn][x1]
|
---|
82 | ;; Assume that the terms are sorted according to decreasing powers of x1
|
---|
83 | ;; p.297 of Cox
|
---|
84 | (defun poly-pseudo-divide (f g)
|
---|
85 | (multiple-value-bind (lg grest)
|
---|
86 | (lpart g)
|
---|
87 | (do* ((m (mdeg g))
|
---|
88 | (dm (poly-extend lg))
|
---|
89 | (lpart nil (multiple-value-list (lpart r)))
|
---|
90 | (lr nil (car lpart))
|
---|
91 | (lrest nil (cadr lpart))
|
---|
92 | (term nil (poly-extend lr (list (- (mdeg r) m))))
|
---|
93 | (r f (poly- (poly* dm lrest)
|
---|
94 | (poly* term grest)))
|
---|
95 | (q nil (append (poly* dm q) term)))
|
---|
96 | ((or (endp r) (< (mdeg r) m))
|
---|
97 | (values q r)))))
|
---|
98 |
|
---|
99 |
|
---|
100 | (defun poly-pseudo-remainder (f g)
|
---|
101 | (second (multiple-value-list (poly-pseudo-divide f g))))
|
---|
102 |
|
---|
103 | ;; Degree in main variable
|
---|
104 | (defun mdeg (b) (caaar b))
|
---|
105 |
|
---|
106 | ;; Leading coefficient in the first variable; a poly in k[x2,...,xn]
|
---|
107 | (defun lcoeff (b)
|
---|
108 | (first (multiple-value-list (lpart b))))
|
---|
109 |
|
---|
110 | (defun lrest (b)
|
---|
111 | (second (multiple-value-list (lpart b))))
|
---|
112 |
|
---|
113 | (defun lpart (b)
|
---|
114 | (do ((mdeg (mdeg b))
|
---|
115 | (b b (rest b))
|
---|
116 | (b1 nil (cons (cons (cdaar b) (cdar b)) b1)))
|
---|
117 | ((or (endp b) (/= (caaar b) mdeg))
|
---|
118 | (values (reverse b1) b))))
|
---|
119 |
|
---|
120 | ;; Divide f by its content
|
---|
121 | (defun poly-primitive-part (f)
|
---|
122 | (cond
|
---|
123 | ((endp (caar f)) ;scalar
|
---|
124 | f)
|
---|
125 | (t
|
---|
126 | (poly-exact-divide f (poly-extend (poly-content f))))))
|
---|
127 |
|
---|
128 |
|
---|
129 | (defun poly-content (f)
|
---|
130 | (cond
|
---|
131 | ((endp f) (error "Zero argument"))
|
---|
132 | (t (multiple-value-bind (lc r)
|
---|
133 | (lpart f)
|
---|
134 | (cond
|
---|
135 | ((endp r) lc)
|
---|
136 | ((and (= (length lc) 1)
|
---|
137 | (every #'zerop (caar lc))
|
---|
138 | (or (= (cdar lc) 1)
|
---|
139 | (= (cdar lc) -1))) ;lc is 1 or -1
|
---|
140 | lc)
|
---|
141 | (t (poly-gcd lc (poly-content r))))))))
|
---|
142 | @
|
---|
143 |
|
---|
144 |
|
---|
145 | 1.3
|
---|
146 | log
|
---|
147 | @*** empty log message ***
|
---|
148 | @
|
---|
149 | text
|
---|
150 | @d18 2
|
---|
151 | a19 2
|
---|
152 | ;;(proclaim '(optimize (speed 0) (debug 3)))
|
---|
153 | (proclaim '(optimize (speed 3) (debug 0)))
|
---|
154 | @
|
---|
155 |
|
---|
156 |
|
---|
157 | 1.2
|
---|
158 | log
|
---|
159 | @*** empty log message ***
|
---|
160 | @
|
---|
161 | text
|
---|
162 | @d18 2
|
---|
163 | a19 1
|
---|
164 | (proclaim '(optimize (speed 0) (debug 3)))
|
---|
165 | @
|
---|
166 |
|
---|
167 |
|
---|
168 | 1.1
|
---|
169 | log
|
---|
170 | @Initial revision
|
---|
171 | @
|
---|
172 | text
|
---|
173 | @d2 1
|
---|
174 | a2 1
|
---|
175 | $Id: poly-gcd.lisp,v 1.12 1997/12/13 07:11:59 marek Exp $
|
---|
176 | d18 1
|
---|
177 | @
|
---|