~ubuntu-branches/debian/squeeze/maxima/squeeze

« back to all changes in this revision

Viewing changes to src/spgcd.lisp

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2006-10-18 14:52:42 UTC
  • mto: (1.1.5 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20061018145242-vzyrm5hmxr8kiosf
ImportĀ upstreamĀ versionĀ 5.10.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
;;;   ** (C) COPYRIGHT 1982 MASSACHUSETTS INSTITUTE OF TECHNOLOGY *****
12
12
;;;   ****** THIS IS A READ-ONLY FILE! (ALL WRITES RESERVED) **********
13
13
;;;   *****************************************************************
14
 
(in-package "MAXIMA")
 
14
(in-package :maxima)
15
15
 
16
16
(macsyma-module spgcd)
17
17
 
18
18
(declare-top (special modulus temp genvar *alpha *which-factor*
19
 
                  $algebraic algfac* $GCD)
20
 
         (mapex t)
21
 
         (genprefix spgcd))
 
19
                      $algebraic algfac* $gcd)
 
20
             (mapex t)
 
21
             (genprefix spgcd))
22
22
 
23
23
(load-macsyma-macros ratmac)
24
24
 
25
25
(defvar *alpha nil) 
26
26
 
27
 
(defmvar $POINTBOUND *alpha)
 
27
(defmvar $pointbound *alpha)
28
28
 
29
29
(defmacro 0? (x) `(= ,x 0))
30
30
 
31
31
(defmacro melt (a . indices) `(arraycall fixnum ,a . ,indices))
32
32
 
33
 
(defmacro ARRAYTYPE (m) `(array-type ,m))
34
 
 
35
 
(defmacro NCOLS (m) `(array-dimension-n ,m 1))
36
 
 
37
 
(defmacro NROWS (m) `(array-dimension-n ,m 2))
38
 
 
39
 
(defmacro LEN (lobj) `(cadr ,lobj))
40
 
 
41
 
(defmacro SKEL (lobj) `(caddr ,lobj))
42
 
 
43
 
(defmacro MATRIX (lobj) `(cadddr ,lobj))
44
 
 
45
 
(defmacro CURROW (lobj) `(cadr (cdddr ,lobj)))
46
 
 
47
 
(defmacro BADROWS (lobj) `(cadr (cddddr ,lobj)))
 
33
(defmacro arraytype (m) `(array-type ,m))
 
34
 
 
35
(defmacro ncols (m) `(array-dimension-n ,m 1))
 
36
 
 
37
(defmacro nrows (m) `(array-dimension-n ,m 2))
 
38
 
 
39
(defmacro len (lobj) `(cadr ,lobj))
 
40
 
 
41
(defmacro skel (lobj) `(caddr ,lobj))
 
42
 
 
43
(defmacro matrix (lobj) `(cadddr ,lobj))
 
44
 
 
45
(defmacro currow (lobj) `(cadr (cdddr ,lobj)))
 
46
 
 
47
(defmacro badrows (lobj) `(cadr (cddddr ,lobj)))
48
48
 
49
49
 
50
 
(defun PINTERP (x pts vals)
51
 
       (do ((u (car vals)
52
 
               (pplus u (ptimes
53
 
                         (pctimes (crecip (pcsubstz (car xk) qk))
54
 
                                  qk)
55
 
                         (pdifference (car uk)
56
 
                                      (pcsubstz (car xk) u)))))
57
 
            (uk (cdr vals) (cdr uk))
58
 
            (qk (list x 1 1 0 (cminus (car pts)))
59
 
                (ptimes qk (list x 1 1 0 (cminus (car xk)))))
60
 
            (xk (cdr pts) (cdr xk)))
61
 
           ((null xk) u)))
 
50
(defun pinterp (x pts vals)
 
51
  (do ((u (car vals)
 
52
          (pplus u (ptimes
 
53
                    (pctimes (crecip (pcsubstz (car xk) qk))
 
54
                             qk)
 
55
                    (pdifference (car uk)
 
56
                                 (pcsubstz (car xk) u)))))
 
57
       (uk (cdr vals) (cdr uk))
 
58
       (qk (list x 1 1 0 (cminus (car pts)))
 
59
           (ptimes qk (list x 1 1 0 (cminus (car xk)))))
 
60
       (xk (cdr pts) (cdr xk)))
 
61
      ((null xk) u)))
62
62
 
63
 
(defun PCSUBSTZ (val p)
64
 
       (if (pcoefp p) p
65
 
           (do ((l (p-terms p) (pt-red l))
66
 
                (ans 0
67
 
                     (ctimes
68
 
                      (cplus ans (pt-lc l))
69
 
                      (cexpt val (f- (pt-le l) (pt-le (pt-red l)))))))
70
 
               ((null (pt-red l))
 
63
(defun pcsubstz (val p)
 
64
  (if (pcoefp p) p
 
65
      (do ((l (p-terms p) (pt-red l))
 
66
           (ans 0
71
67
                (ctimes
72
68
                 (cplus ans (pt-lc l))
73
 
                 (if (0? (pt-le l))
74
 
                     1
75
 
                     (cexpt val (pt-le l))))))))
76
 
 
77
 
;skeletons consist of list of exponent vectors
78
 
;lifting structures are as follows:
79
 
 
80
 
;(matrix <n>            ;length of <skel>
81
 
;        <skel>         ;skeleton of poly being lifted
82
 
;        <matrix>       ; partially diagonalized matrix used to obtain sol.
83
 
;        <row>          ;we have diagonalized this far
84
 
;        <bad rows>)    ; after we get 
85
 
 
86
 
(defun EVAL-MON (mon pt)
87
 
       (do ((l mon (cdr l))
88
 
            (ll pt (cdr ll))
89
 
            (ans 1 (ctimes
90
 
                    (if (0? (car l)) 1
91
 
                        (cexpt (car ll) (car l)))
92
 
                    ans)))
93
 
           ((null l) ans)))
 
69
                 (cexpt val (f- (pt-le l) (pt-le (pt-red l)))))))
 
70
          ((null (pt-red l))
 
71
           (ctimes
 
72
            (cplus ans (pt-lc l))
 
73
            (if (0? (pt-le l))
 
74
                1
 
75
                (cexpt val (pt-le l))))))))
 
76
 
 
77
;;skeletons consist of list of exponent vectors
 
78
;;lifting structures are as follows:
 
79
 
 
80
;;(matrix <n>            ;length of <skel>
 
81
;;        <skel>                ;skeleton of poly being lifted
 
82
;;        <matrix>       ; partially diagonalized matrix used to obtain sol.
 
83
;;        <row>          ;we have diagonalized this far
 
84
;;        <bad rows>)    ; after we get 
 
85
 
 
86
(defun eval-mon (mon pt)
 
87
  (do ((l mon (cdr l))
 
88
       (ll pt (cdr ll))
 
89
       (ans 1 (ctimes
 
90
               (if (0? (car l)) 1
 
91
                   (cexpt (car ll) (car l)))
 
92
               ans)))
 
93
      ((null l) ans)))
94
94
 
95
 
; ONE-STEP causes the  (row,col) element of mat to be made to be zero.  It is
96
 
; assumed that row > col, and that the matrix is diagonal above the row.  
97
 
; n indicates how wide the rows are suppoded to be.
 
95
;; ONE-STEP causes the  (row,col) element of mat to be made to be zero.  It is
 
96
;; assumed that row > col, and that the matrix is diagonal above the row.  
 
97
;; n indicates how wide the rows are suppoded to be.
98
98
 
99
 
(defun ONE-STEP (mat row col n)
100
 
       (do ((i col (f1+ i))
101
 
            (c (arraycall fixnum mat row col))) ;Got to save this away before it is 
 
99
(defun one-step (mat row col n)
 
100
  (do ((i col (f1+ i))
 
101
       (c (arraycall fixnum mat row col))) ;Got to save this away before it is 
102
102
                                        ;zeroed
103
 
           ((> i n) mat)
104
 
           (store (arraycall fixnum mat row i)
105
 
                  (cdifference (arraycall fixnum mat row i)
106
 
                               (ctimes c (arraycall fixnum mat col i))))))
107
 
 
108
 
; MONICIZE-ROW assumes the (row,row) element is non-zero and that this element
109
 
; is to be made equal to one.  It merely divides the entire row by the 
110
 
; (row,row) element.  It is assumed that the (row,n) elements with n < row are
111
 
; already zero.  Again n is the width of the rows.
112
 
 
113
 
(defun MONICIZE-ROW (mat row n)
114
 
       (do ((i n (f1- i))
115
 
            (c (CRECIP (arraycall fixnum mat row row))))
116
 
           ((= i row)
117
 
            (store (arraycall fixnum mat row row) 1))   ;Don't bother doing the
 
103
      ((> i n) mat)
 
104
    (store (arraycall fixnum mat row i)
 
105
           (cdifference (arraycall fixnum mat row i)
 
106
                        (ctimes c (arraycall fixnum mat col i))))))
 
107
 
 
108
;; MONICIZE-ROW assumes the (row,row) element is non-zero and that this element
 
109
;; is to be made equal to one.  It merely divides the entire row by the 
 
110
;; (row,row) element.  It is assumed that the (row,n) elements with n < row are
 
111
;; already zero.  Again n is the width of the rows.
 
112
 
 
113
(defun monicize-row (mat row n)
 
114
  (do ((i n (f1- i))
 
115
       (c (crecip (arraycall fixnum mat row row))))
 
116
      ((= i row)
 
117
       (store (arraycall fixnum mat row row) 1)) ;Don't bother doing the
118
118
                                        ;division on the diagonal
119
 
           (store (arraycall fixnum mat row i) (ctimes (arraycall fixnum mat row i) c))))
120
 
 
121
 
; FILL-ROW is given a point and the value of the skeleton at the point and
122
 
; fills the apropriate row in the matrix. with the values of the monomials
123
 
; n is the length of the skeleton
124
 
 
125
 
(defun FILL-ROW (skel mat n row pt val)
126
 
       (do ((i 0 (f1+ i))
127
 
            (l skel (cdr l)))
128
 
           ((= i n)                     ;l should be nil now,
129
 
            (if (not (null l))          ;but lets check just to make sure
130
 
                (merror "Skeleton too long in  FILL-ROW: ~S"
131
 
                        (list n '= skel)))
132
 
            (store (arraycall fixnum mat row n) val))   ;The value is stored in the
 
119
    (store (arraycall fixnum mat row i) (ctimes (arraycall fixnum mat row i) c))))
 
120
 
 
121
;; FILL-ROW is given a point and the value of the skeleton at the point and
 
122
;; fills the apropriate row in the matrix. with the values of the monomials
 
123
;; n is the length of the skeleton
 
124
 
 
125
(defun fill-row (skel mat n row pt val)
 
126
  (do ((i 0 (f1+ i))
 
127
       (l skel (cdr l)))
 
128
      ((= i n)                          ;l should be nil now,
 
129
       (if (not (null l))            ;but lets check just to make sure
 
130
           (merror "Skeleton too long in  `fill-row': ~S"
 
131
                   (list n '= skel)))
 
132
       (store (arraycall fixnum mat row n) val)) ;The value is stored in the
133
133
                                        ;last column
134
 
           (store (arraycall fixnum mat row i)
135
 
                  (eval-mon (car l) pt))))      ;Should think about a better
 
134
    (store (arraycall fixnum mat row i)
 
135
           (eval-mon (car l) pt))))     ;Should think about a better
136
136
                                        ;way to do this evaluation.
137
137
 
138
138
#-allegro
139
 
(defun SWAP-ROWS (mat m n)              ;Interchange row m and n
140
 
       (do ((k 0 (f1+ k))
141
 
            (l (ncols mat)))
142
 
           ((> k l) mat)
143
 
           (store (arraycall fixnum mat m k)
144
 
                  (prog2 0 (melt mat n k)
145
 
                         (store (melt mat n k) (melt mat m k))))))
 
139
(defun swap-rows (mat m n)              ;Interchange row m and n
 
140
  (do ((k 0 (f1+ k))
 
141
       (l (ncols mat)))
 
142
      ((> k l) mat)
 
143
    (store (arraycall fixnum mat m k)
 
144
           (prog2 0 (melt mat n k)
 
145
             (store (melt mat n k) (melt mat m k))))))
146
146
 
147
 
; PARTIAL-DIAG fills in one more row of the matrix and tries to diagonalize
148
 
; what it has so far.  If the row which has just been introduced has a 
149
 
; zero element on the diagonal then it is scanned for its first non-zero
150
 
; element and it is placed in the matrix so that the non-zero element is 
151
 
; on the diagonal.  The rows which are missing are added to the list in 
152
 
; badrows.  The current row pointer may skip a couple of numbers here, so
153
 
; when it is equal to n, the only empty rows to add thing to are on the
154
 
; bad rows list.
 
147
;; PARTIAL-DIAG fills in one more row of the matrix and tries to diagonalize
 
148
;; what it has so far.  If the row which has just been introduced has a 
 
149
;; zero element on the diagonal then it is scanned for its first non-zero
 
150
;; element and it is placed in the matrix so that the non-zero element is 
 
151
;; on the diagonal.  The rows which are missing are added to the list in 
 
152
;; badrows.  The current row pointer may skip a couple of numbers here, so
 
153
;; when it is equal to n, the only empty rows to add thing to are on the
 
154
;; bad rows list.
155
155
 
156
 
(defun PARTIAL-DIAG (lobj pt val)       ; Does one step of diagonalization of
157
 
   (let ((n (len lobj))         ;the matrix in lobj
158
 
         (skel (skel lobj))             
159
 
         (mat (matrix lobj))            ;The matrix, obviously
160
 
         (row (currow lobj))            ;This is the row which is to be 
 
156
(defun partial-diag (lobj pt val) ; Does one step of diagonalization of
 
157
  (let ((n (len lobj))                  ;the matrix in lobj
 
158
        (skel (skel lobj))              
 
159
        (mat (matrix lobj))             ;The matrix, obviously
 
160
        (row (currow lobj))           ;This is the row which is to be 
161
161
                                        ;introduced
162
 
         (badrows (badrows lobj))       ;Rows which could not be used when
 
162
        (badrows (badrows lobj))    ;Rows which could not be used when
163
163
                                        ;their time came, and will be used later
164
 
         crow)
165
 
       (cond ((= row n)                 ;All rows already done, must start
 
164
        crow)
 
165
    (cond ((= row n)                ;All rows already done, must start
166
166
                                        ;using the rows in badrows.
167
 
              (fill-row skel mat n (setq crow (car badrows)) pt val))
168
 
             ((fill-row skel mat n row pt val)  ;Fill up the data
169
 
              (setq crow row)))
170
 
 
171
 
;; This loop kills all the elements in the row up to the diagonal.
172
 
 
173
 
       (do ((i 0 (f1+ i))               ;runs over the columns of mat
174
 
            (l (setq badrows (cons nil badrows)))
175
 
            (flag))
176
 
           ((= i crow)
177
 
            (setq badrows (cdr badrows)))       ;update badrows
178
 
           (if (cdr l)                  ;Any bad rows around?
179
 
               (if (= (cadr l) i)       ;No one for this row,
180
 
                   (if (and (null flag) ;So if this guy can fill in
181
 
                            (not (0? (melt mat crow i))))
182
 
                       (progn
183
 
                        (swap-rows mat crow i)  ;Put this guy in the right spot
184
 
                        (rplacd l (cddr l))
185
 
                        (setq flag t crow i))   ; and make him a winner
186
 
                       (setq l (cdr l)))        ;At any rate this guy isn't 
 
167
           (fill-row skel mat n (setq crow (car badrows)) pt val))
 
168
          ((fill-row skel mat n row pt val) ;Fill up the data
 
169
           (setq crow row)))
 
170
 
 
171
    ;; This loop kills all the elements in the row up to the diagonal.
 
172
 
 
173
    (do ((i 0 (f1+ i))                  ;runs over the columns of mat
 
174
         (l (setq badrows (cons nil badrows)))
 
175
         (flag))
 
176
        ((= i crow)
 
177
         (setq badrows (cdr badrows)))  ;update badrows
 
178
      (if (cdr l)                       ;Any bad rows around?
 
179
          (if (= (cadr l) i)            ;No one for this row,
 
180
              (if (and (null flag)      ;So if this guy can fill in
 
181
                       (not (0? (melt mat crow i))))
 
182
                  (progn
 
183
                    (swap-rows mat crow i) ;Put this guy in the right spot
 
184
                    (rplacd l (cddr l))
 
185
                    (setq flag t crow i)) ; and make him a winner
 
186
                  (setq l (cdr l)))     ;At any rate this guy isn't 
187
187
                                        ;used any more.
188
 
                   (one-step mat crow i n))
189
 
               (one-step mat crow i n)))
 
188
              (one-step mat crow i n))
 
189
          (one-step mat crow i n)))
190
190
 
191
 
       (if (0? (melt mat crow crow))    ;diagonal is zero?
192
 
           (setq badrows (cons crow badrows))
193
 
           (progn
194
 
            (monicize-row mat crow n)   ;Monicize the diagonal element on this
 
191
    (if (0? (melt mat crow crow))       ;diagonal is zero?
 
192
        (setq badrows (cons crow badrows))
 
193
        (progn
 
194
          (monicize-row mat crow n) ;Monicize the diagonal element on this
195
195
                                        ;row
196
 
            (do ((j 0 (f1+ j)))         ;For each element in the rows above 
 
196
          (do ((j 0 (f1+ j)))     ;For each element in the rows above 
197
197
                                        ;this one zero the the crow column
198
 
                ((= j crow))            ;Don't zero the diagonal element
199
 
                (one-step mat j crow n))))
200
 
       (cond ((and (= (f1+ row) n)
201
 
                   (progn (setq row (f1- row)) t)       ;Decrement it just in case
202
 
                   (null (cdr badrows)))
203
 
              (do ((l nil (cons (melt mat i n) l))
204
 
                   (i (f1- n) (f1- i)))
205
 
                  ((< i 0)
206
 
                   (list 'SOLUTION n skel mat l))))
207
 
             (t (list 'MATRIX n skel mat (f1+ row) badrows)))))
 
198
              ((= j crow))            ;Don't zero the diagonal element
 
199
            (one-step mat j crow n))))
 
200
    (cond ((and (= (f1+ row) n)
 
201
                (progn (setq row (f1- row)) t) ;Decrement it just in case
 
202
                (null (cdr badrows)))
 
203
           (do ((l nil (cons (melt mat i n) l))
 
204
                (i (f1- n) (f1- i)))
 
205
               ((< i 0)
 
206
                (list 'solution n skel mat l))))
 
207
          (t (list 'matrix n skel mat (f1+ row) badrows)))))
208
208
 
209
 
(defun GEN-POINT (vars)
210
 
       (do ((l vars (cdr l))
211
 
            (ans nil (cons (cmod (random $POINTBOUND)) ans)))
212
 
           ((null l) ans)))
 
209
(defun gen-point (vars)
 
210
  (do ((l vars (cdr l))
 
211
       (ans nil (cons (cmod (random $pointbound)) ans)))
 
212
      ((null l) ans)))
213
213
 
214
 
; PDIAG-ALL introduces a new row in each matrix in the list of l-lobjs.
215
 
; The RHS of the equations is stripped off of poly.
 
214
;; PDIAG-ALL introduces a new row in each matrix in the list of l-lobjs.
 
215
;; The RHS of the equations is stripped off of poly.
216
216
 
217
 
(defun PDIAG-ALL (l-lobjs poly pt)
218
 
       (do ((l l-lobjs (cdr l))
219
 
            (lp (p-terms poly))
220
 
            (solved t) (c))
221
 
           ((null l)
222
 
            (if solved (cons 'SOLVED l-lobjs)
223
 
                l-lobjs))
224
 
           (if (and lp (= (caar l) (pt-le lp))) ;This term corresponds to the
 
217
(defun pdiag-all (l-lobjs poly pt)
 
218
  (do ((l l-lobjs (cdr l))
 
219
       (lp (p-terms poly))
 
220
       (solved t) (c))
 
221
      ((null l)
 
222
       (if solved (cons 'solved l-lobjs)
 
223
           l-lobjs))
 
224
    (if (and lp (= (caar l) (pt-le lp))) ;This term corresponds to the
225
225
                                        ;current lobj, set c to the coefficient
226
 
               (setq c (pt-lc lp) lp (pt-red lp))
227
 
               (setq c 0))
228
 
;FIXTHIS                                ;Should put it some check for extra 
 
226
        (setq c (pt-lc lp) lp (pt-red lp))
 
227
        (setq c 0))
 
228
    ;;FIXTHIS                           ;Should put it some check for extra 
229
229
                                        ;terms in the polynomial
230
 
           (if (not (eq (cadar l) 'SOLUTION))
231
 
               (progn (rplacd (car l)
232
 
                              (partial-diag (cdar l) pt c))
233
 
                      (and solved (null (eq (cadar l) 'SOLUTION)) 
234
 
                           (setq solved nil))))))
 
230
    (if (not (eq (cadar l) 'solution))
 
231
        (progn (rplacd (car l)
 
232
                       (partial-diag (cdar l) pt c))
 
233
               (and solved (null (eq (cadar l) 'solution)) 
 
234
                    (setq solved nil))))))
235
235
 
236
236
;; not currently called
237
237
;; (defun CREATE-INTVECT (h)
253
253
;;               (t (error '|Bad Evaluation point - MERGE-INTVECT|)))))
254
254
 
255
255
 
256
 
(defun MERGE-SKEL (mon poly)
257
 
       (cond ((pcoefp poly)
258
 
              (list (cons 0 mon)))
259
 
             ((do ((l (cdr poly) (cddr l))
260
 
                   (ans nil
261
 
                        (cons (cons (car l) mon) ans)))
262
 
                  ((null l) ans)))))
263
 
 
264
 
(defun NEW-SKEL (skel polys)
265
 
       (list
266
 
        (mapcan (fn (mon poly) (merge-skel mon poly))
267
 
                skel polys)
268
 
        (mapcan (fn (q)
269
 
                    (cond ((pcoefp q) (list q))
270
 
                          ((do ((l (cdr q) (cddr l))
271
 
                                (ans nil (cons (cadr l) ans)))
272
 
                               ((null l) ans)))))
273
 
                polys)))
274
 
 
275
 
(defun CREATE-LOBJS (prev-lift)
 
256
(defun merge-skel (mon poly)
 
257
  (cond ((pcoefp poly)
 
258
         (list (cons 0 mon)))
 
259
        ((do ((l (cdr poly) (cddr l))
 
260
              (ans nil
 
261
                   (cons (cons (car l) mon) ans)))
 
262
             ((null l) ans)))))
 
263
 
 
264
(defun new-skel (skel polys)
 
265
  (list
 
266
   (mapcan (fn (mon poly) (merge-skel mon poly))
 
267
           skel polys)
 
268
   (mapcan (fn (q)
 
269
               (cond ((pcoefp q) (list q))
 
270
                     ((do ((l (cdr q) (cddr l))
 
271
                           (ans nil (cons (cadr l) ans)))
 
272
                          ((null l) ans)))))
 
273
           polys)))
 
274
 
 
275
(defun create-lobjs (prev-lift)
276
276
  (mapcar #'(lambda (q)
277
277
              (let ((n (length (cadr q))))
278
278
                (cons (car q)
279
 
                      (list 'MATRIX n (cadr q)
 
279
                      (list 'matrix n (cadr q)
280
280
                            (*array nil 'fixnum n (f1+ n))
281
281
                            0 nil))))
282
282
          prev-lift))
283
283
 
284
 
(defun CLEAR-LOBJS (lobjs)
 
284
(defun clear-lobjs (lobjs)
285
285
  (mapcar #'(lambda (q)
286
286
              (cons (car q)
287
 
                    (list 'MATRIX (caddr q) (cadddr q)
 
287
                    (list 'matrix (caddr q) (cadddr q)
288
288
                          (caddr (cddr q)) 0 nil)))
289
289
          lobjs))
290
290
 
291
 
(defun SPARSE-LIFT (c f g l-lobjs vars)
292
 
       (do ((pt (gen-point vars) (gen-point vars))
293
 
            (gcd))
294
 
           ((eq (car l-lobjs) 'SOLVED)
295
 
            (cdr l-lobjs))
296
 
           (setq gcd (lifting-factors-image
297
 
                      (pcsub c pt vars) (pcsub f pt vars) (pcsub g pt vars)))
298
 
           (if (or (pcoefp gcd)
299
 
                   (not (= (pt-le (p-terms gcd)) (caar l-lobjs))))
300
 
               (throw 'Bad-Point nil)
301
 
               (setq l-lobjs (pdiag-all l-lobjs gcd pt)))))
 
291
(defun sparse-lift (c f g l-lobjs vars)
 
292
  (do ((pt (gen-point vars) (gen-point vars))
 
293
       (gcd))
 
294
      ((eq (car l-lobjs) 'solved)
 
295
       (cdr l-lobjs))
 
296
    (setq gcd (lifting-factors-image
 
297
               (pcsub c pt vars) (pcsub f pt vars) (pcsub g pt vars)))
 
298
    (if (or (pcoefp gcd)
 
299
            (not (= (pt-le (p-terms gcd)) (caar l-lobjs))))
 
300
        (throw 'bad-point nil)
 
301
        (setq l-lobjs (pdiag-all l-lobjs gcd pt)))))
302
302
 
303
 
(defun LIFTING-FACTORS-IMAGE (c f g)
304
 
       (let ((gcd (pgcdu f g)))
305
 
            (case *which-factor*
306
 
                   (1 (pctimes c gcd))
307
 
                   (2 (pquotient f gcd))
308
 
                   (3 (pquotient g gcd)))))
 
303
(defun lifting-factors-image (c f g)
 
304
  (let ((gcd (pgcdu f g)))
 
305
    (case *which-factor*
 
306
      (1 (pctimes c gcd))
 
307
      (2 (pquotient f gcd))
 
308
      (3 (pquotient g gcd)))))
309
309
 
310
 
(defun ZGCD-LIFT* (c f g vars degb)
311
 
       (do ((vals (gen-point vars) (gen-point vars))
312
 
            (ans))
313
 
           ((not (null ans))
314
 
            ans)
315
 
           (setq ans
316
 
                 (catch 'Bad-Point
317
 
                         (ZGCD-LIFT c f g vars vals degb)))))
318
 
 
319
 
; ZGCD-LIFT returns objects called lifts.  These have the the following 
320
 
; structure
321
 
;      ((n <skel> <poly>) ...  )
322
 
; n corresponds to the degree in the main variable to which this guy 
323
 
; corresponds.
324
 
 
325
 
(defun ZGCD-LIFT (c f g vars vals degb)
326
 
       (cond ((null vars)               ;No variables left, just the main one
327
 
              (let ((p (lifting-factors-image c f g)))  ;Compute factor and 
 
310
(defun zgcd-lift* (c f g vars degb)
 
311
  (do ((vals (gen-point vars) (gen-point vars))
 
312
       (ans))
 
313
      ((not (null ans))
 
314
       ans)
 
315
    (setq ans
 
316
          (catch 'bad-point
 
317
            (zgcd-lift c f g vars vals degb)))))
 
318
 
 
319
;; ZGCD-LIFT returns objects called lifts.  These have the the following 
 
320
;; structure
 
321
;;      ((n <skel> <poly>) ...  )
 
322
;; n corresponds to the degree in the main variable to which this guy 
 
323
;; corresponds.
 
324
 
 
325
(defun zgcd-lift (c f g vars vals degb)
 
326
  (cond ((null vars)             ;No variables left, just the main one
 
327
         (let ((p (lifting-factors-image c f g))) ;Compute factor and 
328
328
                                        ;enforce leading coefficient
329
 
                   (if (pcoefp p) (throw 'relprime 1)   ;if the GCD is 1 quit
330
 
                       (do ((l (p-terms p) (pt-red l))  ;otherwise march
 
329
           (if (pcoefp p) (throw 'relprime 1) ;if the GCD is 1 quit
 
330
               (do ((l (p-terms p) (pt-red l)) ;otherwise march
331
331
                                        ;though the polynomial
332
 
                            (ans nil    ;constructing a lift for each term.
333
 
                                 (cons (list (pt-le l) '(nil) (list (pt-lc l)))
334
 
                                       ans)))
335
 
                           ((null l)
336
 
                            (nreverse ans))))))
337
 
             ((let ((prev-lift          ;Recurse if possible
338
 
                     (zgcd-lift (pcsubsty (car vals) (car vars) c)
339
 
                                (pcsubsty (car vals) (car vars) f)
340
 
                                (pcsubsty (car vals) (car vars) g)
341
 
                                (cdr vars) (cdr vals) (cdr degb))))
342
 
                    (do ((i 0 (f1+ i))  ;counts to the degree bound
343
 
                         (lobjs (create-lobjs prev-lift)        ;need to create
 
332
                    (ans nil       ;constructing a lift for each term.
 
333
                         (cons (list (pt-le l) '(nil) (list (pt-lc l)))
 
334
                               ans)))
 
335
                   ((null l)
 
336
                    (nreverse ans))))))
 
337
        ((let ((prev-lift               ;Recurse if possible
 
338
                (zgcd-lift (pcsubsty (car vals) (car vars) c)
 
339
                           (pcsubsty (car vals) (car vars) f)
 
340
                           (pcsubsty (car vals) (car vars) g)
 
341
                           (cdr vars) (cdr vals) (cdr degb))))
 
342
           (do ((i 0 (f1+ i))           ;counts to the degree bound
 
343
                (lobjs (create-lobjs prev-lift) ;need to create
344
344
                                        ;the appropriate matrices
345
 
                                (clear-lobjs lobjs))    ;but reuse them at each
 
345
                       (clear-lobjs lobjs)) ;but reuse them at each
346
346
                                        ;step
347
 
                         (pts (add-point (list (car vals)))     ;List of random
348
 
                              (add-point pts))  ;points
349
 
                         (linsols (mapcar 'make-linsols prev-lift)
350
 
                                  (merge-sol-lin
351
 
                                   linsols
352
 
                                   (sparse-lift
353
 
                                    (pcsubsty (car pts) (car vars) c)
354
 
                                    (pcsubsty (car pts) (car vars) f)
355
 
                                    (pcsubsty (car pts) (car vars) g)
356
 
                                    lobjs (cdr vars)))))
357
 
                        ((= i (car degb))
358
 
                         (interp-polys linsols (cdr pts) (car vars))))))))
 
347
                (pts (add-point (list (car vals))) ;List of random
 
348
                     (add-point pts))   ;points
 
349
                (linsols (mapcar 'make-linsols prev-lift)
 
350
                         (merge-sol-lin
 
351
                          linsols
 
352
                          (sparse-lift
 
353
                           (pcsubsty (car pts) (car vars) c)
 
354
                           (pcsubsty (car pts) (car vars) f)
 
355
                           (pcsubsty (car pts) (car vars) g)
 
356
                           lobjs (cdr vars)))))
 
357
               ((= i (car degb))
 
358
                (interp-polys linsols (cdr pts) (car vars))))))))
359
359
 
360
 
(defun MAKE-LINSOLS (prev-lift)
 
360
(defun make-linsols (prev-lift)
361
361
  (list (car prev-lift)
362
362
        (cadr prev-lift)
363
363
        (mapcan #'(lambda (q)
367
367
                                 ((null l) ans)))))
368
368
                (caddr prev-lift))))
369
369
 
370
 
(defun ADD-POINT (l)
371
 
       (do ((try (cmod (random $pointbound))
372
 
                 (cmod (random $pointbound))))
373
 
           ((null (zl-MEMBER try l))
374
 
            (cons try l))))
 
370
(defun add-point (l)
 
371
  (do ((try (cmod (random $pointbound))
 
372
            (cmod (random $pointbound))))
 
373
      ((null (zl-member try l))
 
374
       (cons try l))))
375
375
 
376
 
(defun MERGE-SOL-LIN (l1 l2)
377
 
       (do ((l l1 (cdr l))
378
 
            (l2 l2 (cdr l2)))
379
 
           ((null l) l1)
380
 
           (cond ((= (caar l) (caar l2))
381
 
                  (rplaca (cddar l)
382
 
                          (mapcar 'cons (cadddr (cddar l2)) (caddar l)))))))
 
376
(defun merge-sol-lin (l1 l2)
 
377
  (do ((l l1 (cdr l))
 
378
       (l2 l2 (cdr l2)))
 
379
      ((null l) l1)
 
380
    (cond ((= (caar l) (caar l2))
 
381
           (rplaca (cddar l)
 
382
                   (mapcar 'cons (cadddr (cddar l2)) (caddar l)))))))
383
383
 
384
 
(defun INTERP-POLYS (l pts var)
 
384
(defun interp-polys (l pts var)
385
385
  (mapcar #'(lambda (q)
386
386
              (cons (car q)
387
387
                    (new-skel
390
390
                             (caddr q)))))
391
391
          l))
392
392
 
393
 
(defun ZGCD (f g &aux $algebraic algfac*)
394
 
   (let ((f (oldcontent f))                     ;This is a good spot to
395
 
         (g (oldcontent g))                     ;initialize random
396
 
         (gcd) (mon) 
397
 
         (*which-factor*))
398
 
 ;; *WHICH-FACTOR* is interpreted as follows.  It is set fairly deep in the
399
 
 ;; algorithm, inside ZGCD1.
400
 
 ;; 1 -> Lift the GCD
401
 
 ;; 2 -> Lift the cofactor of F
402
 
 ;; 3 -> Lift the cofactor of G
403
 
 
404
 
 
405
 
       (setq mon (pgcd (car f) (car g)) ;compute GCD of content
406
 
             f (cadr f) g (cadr g))     ;f and g are now primitive
407
 
       (if (or (pcoefp f) (pcoefp g)
408
 
                  (not (eq (car f) (car g))))
409
 
           (merror "Bad args to ZGCD"))
410
 
       (ptimes mon
411
 
               (do ((test))
412
 
                   (nil)
413
 
                   (setq gcd (catch 'relprime (zgcd1 f g)))
414
 
                   (setq test
415
 
                         (case *which-factor*
416
 
                                (1 (testdivide f gcd))
417
 
                                (2 (testdivide f gcd))
418
 
                                (3 (testdivide g gcd))))
419
 
                   (cond ((not (null test))
420
 
                          (return
421
 
                           (cond ((equal *which-factor* 1)
422
 
                                  gcd)
423
 
                                 (t test))))
424
 
                         ((not (null modulus))
425
 
                          (return (let (($GCD '$RED))
426
 
                                    (pgcd f g)))))))))
427
 
 
428
 
(defun ZGCD1 (f g)
429
 
   (let* ((modulus modulus)
430
 
          first-lift
431
 
          H degb c
432
 
          (vars (sort (union1 (listovars f) (listovars g))
433
 
                       #'pointergp))
434
 
          (GENVAR (REVERSE VARS))
435
 
 
436
 
 ;; the elements of the following degree vectors all correspond to the 
437
 
 ;; contents of var.  Thus there may be variables missing that are in 
438
 
 ;;GENVAR.
439
 
 ;; (f-degv (zpdegreevector f vars))  ;;WHY NOT JUST PUT GENVAR THE REVERSE
440
 
 ;; (g-degv (zpdegreevector g vars))  ;;THE REVERSE OF VARS AND JUST USE PDEGREEVECTOR--wfs
441
 
          (F-DEGV (PDEGREEVECTOR F))
442
 
          (G-DEGV (PDEGREEVECTOR G))
443
 
          (gcd-degv (gcd-degree-vector f g vars)))
444
 
 
445
 
;; First we try to decide which of the gcd and the cofactors of f and g 
446
 
;; is smallest.  The result of this decision is indicated by *which-factor*.
447
 
;; Then the leading coefficient that is to be enforced is changed if a 
448
 
;; cofactor has been chosen.
449
 
        (case (setq *which-factor*
450
 
                     (determine-lifting-factor f-degv g-degv gcd-degv))
451
 
               (1 (setq c (pgcd (p-lc f) (p-lc g))))
452
 
               (2 (setq c (p-lc f)))
453
 
               (3 (setq c (p-lc g))))
454
 
 
455
 
 ;; Next a degree bound must be chosen.
456
 
        (setq degb
457
 
              (reverse
458
 
               (mapcar #'+
459
 
                       (case *which-factor*
460
 
                              (1 gcd-degv)
461
 
                              (2 (mapcar #'- f-degv gcd-degv))
462
 
                              (3 (mapcar #'- g-degv gcd-degv)))
463
 
                       (zpdegreevector c vars))))
464
 
 
465
 
        (cond ((not (null modulus))
466
 
               (lobj->poly (car vars) (cdr vars)
467
 
                (zgcd-lift* c f g (cdr vars) (cdr degb))))
468
 
              (t
469
 
               (setq h (times (maxcoefficient f)
470
 
                              (maxcoefficient g)))
471
 
               (setq modulus *alpha)                ;Really should randomize
472
 
               (setq first-lift
473
 
                     (zgcd-lift* (pmod c) (pmod f) (pmod g)
474
 
                                 (cdr vars) (cdr degb)))
475
 
               (do ((linsols (mapcar #'(lambda (q)
476
 
                                         (cons (car q)
477
 
                                               (new-skel (cadr q) (caddr q))))
478
 
                                     first-lift)
479
 
                             (merge-sol-lin-z linsols
480
 
                                              (sparse-lift cm fm gm lobjs (cdr vars))
481
 
                                              (times coef-bound
482
 
                                                     (crecip (cmod coef-bound)))
483
 
                                              (times modulus coef-bound)))
484
 
                    (lobjs (create-lobjs first-lift)
485
 
                           (clear-lobjs lobjs))
486
 
                    (coef-bound *alpha (times modulus coef-bound))
487
 
                    (cm) (fm) (gm))
488
 
                   ((greaterp coef-bound H)
489
 
                    (setq modulus nil)
490
 
                    (lobj->poly (car vars) (cdr vars) linsols))
491
 
                   (setq modulus (newprime modulus))
492
 
                   (setq cm (pmod c)
493
 
                         fm (pmod f)
494
 
                         gm (pmod g)))))))
495
 
 
496
 
(defun LOBJ->POLY (var vars lobj)
497
 
       (primpart
498
 
        (cons var
499
 
              (mapcan
500
 
               #'(lambda (q) 
501
 
                    (list (car q)
502
 
                          (do ((x (cadr q) (cdr x))
503
 
                               (y (caddr q) (cdr y))
504
 
                               (ans 0
505
 
                                    (pplus ans
506
 
                                           (disrep-monom (cdar x) (car y)
507
 
                                                         vars))))
508
 
                              ((null x) ans))))
509
 
               lobj))))
510
 
 
511
 
(defun DISREP-MONOM (monom c vars)
512
 
       (cond ((null monom) c)
513
 
             ((equal 0 (car monom))
514
 
              (disrep-monom (cdr monom) c (cdr vars)))
515
 
             ((list (car vars) (car monom)
516
 
                    (disrep-monom (cdr monom) c (cdr vars))))))
517
 
 
518
 
(defun MERGE-SOL-LIN-Z (l1 l2 c new-coef-bound)
519
 
       (do ((l l1 (cdr l))
520
 
            (l2 l2 (cdr l2))
521
 
            (modulus new-coef-bound)
522
 
            (n))
523
 
           ((null l) l1)
524
 
           (cond ((= (caar l) (caar l2))
525
 
                  (rplaca (cddar l)
 
393
(defun zgcd (f g &aux $algebraic algfac*)
 
394
  (let ((f (oldcontent f))              ;This is a good spot to
 
395
        (g (oldcontent g))              ;initialize random
 
396
        (gcd) (mon) 
 
397
        (*which-factor*))
 
398
    ;; *WHICH-FACTOR* is interpreted as follows.  It is set fairly deep in the
 
399
    ;; algorithm, inside ZGCD1.
 
400
    ;; 1 -> Lift the GCD
 
401
    ;; 2 -> Lift the cofactor of F
 
402
    ;; 3 -> Lift the cofactor of G
 
403
 
 
404
 
 
405
    (setq mon (pgcd (car f) (car g))    ;compute GCD of content
 
406
          f (cadr f) g (cadr g))        ;f and g are now primitive
 
407
    (if (or (pcoefp f) (pcoefp g)
 
408
            (not (eq (car f) (car g))))
 
409
        (merror "Bad args to `zgcd'"))
 
410
    (ptimes mon
 
411
            (do ((test))
 
412
                (nil)
 
413
              (setq gcd (catch 'relprime (zgcd1 f g)))
 
414
              (setq test
 
415
                    (case *which-factor*
 
416
                      (1 (testdivide f gcd))
 
417
                      (2 (testdivide f gcd))
 
418
                      (3 (testdivide g gcd))))
 
419
              (cond ((not (null test))
 
420
                     (return
 
421
                       (cond ((equal *which-factor* 1)
 
422
                              gcd)
 
423
                             (t test))))
 
424
                    ((not (null modulus))
 
425
                     (return (let (($gcd '$red))
 
426
                               (pgcd f g)))))))))
 
427
 
 
428
(defun zgcd1 (f g)
 
429
  (let* ((modulus modulus)
 
430
         first-lift
 
431
         h degb c
 
432
         (vars (sort (union1 (listovars f) (listovars g))
 
433
                     #'pointergp))
 
434
         (genvar (reverse vars))
 
435
 
 
436
         ;; the elements of the following degree vectors all correspond to the 
 
437
         ;; contents of var.  Thus there may be variables missing that are in 
 
438
         ;;GENVAR.
 
439
         ;; (f-degv (zpdegreevector f vars))  ;;WHY NOT JUST PUT GENVAR THE REVERSE
 
440
         ;; (g-degv (zpdegreevector g vars))  ;;THE REVERSE OF VARS AND JUST USE PDEGREEVECTOR--wfs
 
441
         (f-degv (pdegreevector f))
 
442
         (g-degv (pdegreevector g))
 
443
         (gcd-degv (gcd-degree-vector f g vars)))
 
444
 
 
445
    ;; First we try to decide which of the gcd and the cofactors of f and g 
 
446
    ;; is smallest.  The result of this decision is indicated by *which-factor*.
 
447
    ;; Then the leading coefficient that is to be enforced is changed if a 
 
448
    ;; cofactor has been chosen.
 
449
    (case (setq *which-factor*
 
450
                (determine-lifting-factor f-degv g-degv gcd-degv))
 
451
      (1 (setq c (pgcd (p-lc f) (p-lc g))))
 
452
      (2 (setq c (p-lc f)))
 
453
      (3 (setq c (p-lc g))))
 
454
 
 
455
    ;; Next a degree bound must be chosen.
 
456
    (setq degb
 
457
          (reverse
 
458
           (mapcar #'+
 
459
                   (case *which-factor*
 
460
                     (1 gcd-degv)
 
461
                     (2 (mapcar #'- f-degv gcd-degv))
 
462
                     (3 (mapcar #'- g-degv gcd-degv)))
 
463
                   (zpdegreevector c vars))))
 
464
 
 
465
    (cond ((not (null modulus))
 
466
           (lobj->poly (car vars) (cdr vars)
 
467
                       (zgcd-lift* c f g (cdr vars) (cdr degb))))
 
468
          (t
 
469
           (setq h (times (maxcoefficient f)
 
470
                          (maxcoefficient g)))
 
471
           (setq modulus *alpha)        ;Really should randomize
 
472
           (setq first-lift
 
473
                 (zgcd-lift* (pmod c) (pmod f) (pmod g)
 
474
                             (cdr vars) (cdr degb)))
 
475
           (do ((linsols (mapcar #'(lambda (q)
 
476
                                     (cons (car q)
 
477
                                           (new-skel (cadr q) (caddr q))))
 
478
                                 first-lift)
 
479
                         (merge-sol-lin-z linsols
 
480
                                          (sparse-lift cm fm gm lobjs (cdr vars))
 
481
                                          (times coef-bound
 
482
                                                 (crecip (cmod coef-bound)))
 
483
                                          (times modulus coef-bound)))
 
484
                (lobjs (create-lobjs first-lift)
 
485
                       (clear-lobjs lobjs))
 
486
                (coef-bound *alpha (times modulus coef-bound))
 
487
                (cm) (fm) (gm))
 
488
               ((greaterp coef-bound h)
 
489
                (setq modulus nil)
 
490
                (lobj->poly (car vars) (cdr vars) linsols))
 
491
             (setq modulus (newprime modulus))
 
492
             (setq cm (pmod c)
 
493
                   fm (pmod f)
 
494
                   gm (pmod g)))))))
 
495
 
 
496
(defun lobj->poly (var vars lobj)
 
497
  (primpart
 
498
   (cons var
 
499
         (mapcan
 
500
          #'(lambda (q) 
 
501
              (list (car q)
 
502
                    (do ((x (cadr q) (cdr x))
 
503
                         (y (caddr q) (cdr y))
 
504
                         (ans 0
 
505
                              (pplus ans
 
506
                                     (disrep-monom (cdar x) (car y)
 
507
                                                   vars))))
 
508
                        ((null x) ans))))
 
509
          lobj))))
 
510
 
 
511
(defun disrep-monom (monom c vars)
 
512
  (cond ((null monom) c)
 
513
        ((equal 0 (car monom))
 
514
         (disrep-monom (cdr monom) c (cdr vars)))
 
515
        ((list (car vars) (car monom)
 
516
               (disrep-monom (cdr monom) c (cdr vars))))))
 
517
 
 
518
(defun merge-sol-lin-z (l1 l2 c new-coef-bound)
 
519
  (do ((l l1 (cdr l))
 
520
       (l2 l2 (cdr l2))
 
521
       (modulus new-coef-bound)
 
522
       (n))
 
523
      ((null l) l1)
 
524
    (cond ((= (caar l) (caar l2))
 
525
           (rplaca (cddar l)
526
526
                   (mapcar
527
527
                    #'(lambda (a b)
528
 
                          (cond ((greaterp
529
 
                                  (abs
530
 
                                   (setq n
531
 
                                         (cplus b (ctimes c (cdifference a b)))))
532
 
                                  new-coef-bound)
533
 
                                 (throw 'relprime 1))
534
 
                                (n)))
535
 
                           (cadddr (cddar l2)) (caddar l)))))))
 
528
                        (cond ((greaterp
 
529
                                (abs
 
530
                                 (setq n
 
531
                                       (cplus b (ctimes c (cdifference a b)))))
 
532
                                new-coef-bound)
 
533
                               (throw 'relprime 1))
 
534
                              (n)))
 
535
                    (cadddr (cddar l2)) (caddar l)))))))
536
536
 
537
537
;; The following function tries to determine the degree of gcd(f, g) in each
538
538
;; variable.  This is done in the following manner:  All but one of the
542
542
;;
543
543
;; The univariate gcd's are computed with modulus=*alpha.
544
544
 
545
 
(defun GCD-DEGREE-VECTOR (f g vars)
546
 
   (let ((modulus *alpha))
547
 
     (setq f (pmod f) g (pmod g))
548
 
     (do ((vn (cdr vars) (cdr vn))
549
 
          (vs (zl-DELETE (car vars) (copy1 vars))
550
 
              (zl-DELETE (car vn) (copy1 vars)))
551
 
          (l) (f*) (g*) (gcd*) (rand))
552
 
         (nil)
553
 
         (setq rand (gen-point vs))
554
 
         (setq f* (pcsub f rand vs)
555
 
               g* (pcsub g rand vs))
556
 
         (cond ((or (pcoefp f*) (pcoefp g*)
557
 
                    (pcoefp (setq gcd* (pgcdu f* g*))))
558
 
                (push 0 l))
559
 
               (t (push (pt-le (p-terms gcd*)) l)))
560
 
         (cond ((null vn)
561
 
                (return l))))))         ;No reverse needed here
 
545
(defun gcd-degree-vector (f g vars)
 
546
  (let ((modulus *alpha))
 
547
    (setq f (pmod f) g (pmod g))
 
548
    (do ((vn (cdr vars) (cdr vn))
 
549
         (vs (zl-delete (car vars) (copy1 vars))
 
550
             (zl-delete (car vn) (copy1 vars)))
 
551
         (l) (f*) (g*) (gcd*) (rand))
 
552
        (nil)
 
553
      (setq rand (gen-point vs))
 
554
      (setq f* (pcsub f rand vs)
 
555
            g* (pcsub g rand vs))
 
556
      (cond ((or (pcoefp f*) (pcoefp g*)
 
557
                 (pcoefp (setq gcd* (pgcdu f* g*))))
 
558
             (push 0 l))
 
559
            (t (push (pt-le (p-terms gcd*)) l)))
 
560
      (cond ((null vn)
 
561
             (return l))))))            ;No reverse needed here
562
562
 
563
 
; DETERMINE-LIFTING-FACTOR returns a number indicating which factor of f or g
564
 
; to which to lift 
 
563
;; DETERMINE-LIFTING-FACTOR returns a number indicating which factor of f or g
 
564
;; to which to lift 
565
565
 
566
566
(defun dlf-mumblify (a b)
567
 
  (sloop for x in a for y in b sum (difference x y)))
 
567
  (loop for x in a for y in b sum (difference x y)))
568
568
 
569
 
(defun DETERMINE-LIFTING-FACTOR (f-degv g-degv gcd-degv)
570
 
  (let* ((fv ;(apply '+ (mapcar '- f-degv gcd-degv))
571
 
             (dlf-mumblify f-degv gcd-degv))
572
 
         (gv ;(apply '+ (mapcar '- g-degv gcd-degv))
573
 
             (dlf-mumblify g-degv gcd-degv))
 
569
(defun determine-lifting-factor (f-degv g-degv gcd-degv)
 
570
  (let* ((fv                   ;(apply '+ (mapcar '- f-degv gcd-degv))
 
571
          (dlf-mumblify f-degv gcd-degv))
 
572
         (gv                   ;(apply '+ (mapcar '- g-degv gcd-degv))
 
573
          (dlf-mumblify g-degv gcd-degv))
574
574
         (gcdv (apply '+ gcd-degv)))
575
575
    (if (lessp fv gcdv)
576
576
        (if (lessp fv gv) 2 3)
577
577
        (if (lessp gv gcdv) 3 1))))
578
 
;(defun DETERMINE-LIFTING-FACTOR (f-degv g-degv gcd-degv)
579
 
;       (let* ((fv (apply '+ (mapcar '- f-degv gcd-degv)))
580
 
;             (gv (apply '+ (mapcar '- g-degv gcd-degv)))
581
 
;             (gcdv (apply '+ gcd-degv)))
582
 
;            (if (lessp fv gcdv)
583
 
;                (if (lessp fv gv) 2 3)
584
 
;                (if (lessp gv gcdv) 3 1))))
 
578
;;(defun DETERMINE-LIFTING-FACTOR (f-degv g-degv gcd-degv)
 
579
;;       (let* ((fv (apply '+ (mapcar '- f-degv gcd-degv)))
 
580
;;            (gv (apply '+ (mapcar '- g-degv gcd-degv)))
 
581
;;            (gcdv (apply '+ gcd-degv)))
 
582
;;           (if (lessp fv gcdv)
 
583
;;               (if (lessp fv gv) 2 3)
 
584
;;               (if (lessp gv gcdv) 3 1))))
585
585
  
586
586
 
587
 
(defun EXCISE-EXTRA-VARIABLES (degv vars)
588
 
       (do ((l (reverse degv) (cdr l))
589
 
            (lv (reverse genvar) (cdr lv))
590
 
            (ndegv))
591
 
           ((null l)
592
 
            ndegv)
593
 
           (cond ((eq (car lv) (car vars))
594
 
                  (push (car l) ndegv)
595
 
                  (setq vars (cdr vars))))))
 
587
(defun excise-extra-variables (degv vars)
 
588
  (do ((l (reverse degv) (cdr l))
 
589
       (lv (reverse genvar) (cdr lv))
 
590
       (ndegv))
 
591
      ((null l)
 
592
       ndegv)
 
593
    (cond ((eq (car lv) (car vars))
 
594
           (push (car l) ndegv)
 
595
           (setq vars (cdr vars))))))
596
596
 
597
 
(defun ZPDEGREEVECTOR (p vars)
598
 
       (excise-extra-variables (pdegreevector p) vars))
 
597
(defun zpdegreevector (p vars)
 
598
  (excise-extra-variables (pdegreevector p) vars))
599
599
 
600
600
;; Local Modes:
601
601
;; Mode:LISP