Skip to content

Commit 594d398

Browse files
TomasRikerrtoy
authored andcommitted
factor.lisp: rename special variable P to *P*
P was at least partially used like a special variable, not purely lexical. There are probably some (or many) instances where it was used in a lexical way, but deciding that for every instance is tricky (nested function calls, poor documentation).
1 parent de14fda commit 594d398

1 file changed

Lines changed: 72 additions & 67 deletions

File tree

src/factor.lisp

Lines changed: 72 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,12 @@
601601
(or (numberp u) (alg u)))
602602
(t (quick-sqfr-check u var))))
603603

604-
(declare-top (special p))
604+
(declare-top (special *p*))
605+
606+
;; Note: *P* used to be P. In some functions below, *P* can probably be
607+
;; renamed back to P (lexical variable), but some do really need a special
608+
;; variable because they use it to transport state from one function to
609+
;; another.
605610

606611
(defun fixvl0 (l1 l2 ov)
607612
(prog (a b c)
@@ -633,8 +638,8 @@
633638

634639
(defun multfact (poly)
635640
(prog (*inl3 *i* *min* *mx* nn* *odr* lc elm listelm plim origenvar ne var valist val1
636-
ovarlist p subvar subvar1 subval1 subval dlp)
637-
;; (declare (special p))
641+
ovarlist *p* subvar subvar1 subval1 subval dlp)
642+
;; (declare (special *p*))
638643
(setq var (car poly) elm (listovars poly)
639644
origenvar genvar
640645
genvar (intersect genvar (if algfac*
@@ -652,7 +657,7 @@
652657
(> (cadddr subval) 1))
653658
(degvector nil 1 (car subval)))))))
654659
(setq subval nil)
655-
(setq p poly)
660+
(setq *p* poly)
656661
(when (null val1)
657662
(setq subvar1 ovarlist)
658663
(setq subval1 (polysubst (make-list (length subvar1) :initial-element 0) subvar1))
@@ -665,20 +670,20 @@
665670
(setq subval1 nil subvar1 nil)
666671
(fixvl0 subvar subval (reverse ovarlist))
667672
(when algfac* (push (car *alpha*) genvar))
668-
(setq poly (cpber3 poly p))
673+
(setq poly (cpber3 poly *p*))
669674
(setq genvar origenvar)
670675
(return poly)))
671676

672677
(defun polysubst (a b)
673678
(prog (lc *inl3 d n modulus)
674679
(when modulu* (setq modulus modulu*))
675-
(setq *inl3 t lc (caddr p) n (length a))
680+
(setq *inl3 t lc (caddr *p*) n (length a))
676681
loop (setq d (pcsubsty a b lc))
677682
(when (equal 0 d) (go inl))
678683
(let ((modulus nil))
679-
(setq d (pcsubsty a b p)))
684+
(setq d (pcsubsty a b *p*)))
680685
(when (sqfrp (pmod d) (car d))
681-
(setq p d) (return a))
686+
(setq *p* d) (return a))
682687
inl (setq a (increaselist a n))
683688
(go loop)))
684689

@@ -706,14 +711,14 @@
706711
(setq r (cdr r))
707712
(go loop)))
708713

709-
(defun maxcoef (p)
710-
(maxcoefficient p))
714+
(defun maxcoef (*p*)
715+
(maxcoefficient *p*))
711716

712-
(defun incrlimk (p)
717+
(defun incrlimk (*p*)
713718
(prog (v min-plim)
714719
(cond (modulu* (setq plim modulu* *prime modulu* limk -1) (return nil))
715720
((null limk)(setq plim *alpha *prime *alpha limk -1)(return nil)))
716-
(setq v (butlast (pdegreevector p)))
721+
(setq v (butlast (pdegreevector *p*)))
717722
(setq v
718723
(apply
719724
'*
@@ -727,7 +732,7 @@
727732
(expt b a)))))
728733
v
729734
valist)))
730-
(setq min-plim (* (max (maxcoef p) plim) v))
735+
(setq min-plim (* (max (maxcoef *p*) plim) v))
731736
loop (cond ((< min-plim plim) (return nil)))
732737
(incf limk)
733738
(setq plim (* plim plim))
@@ -798,12 +803,12 @@
798803
(go test)
799804
out (return ans)))
800805

801-
(defun multideg (p)
806+
(defun multideg (*p*)
802807
(prog (m d)
803-
(cond ((numberp p) (return 0)) ((onevarp p) (return (cadr p))))
804-
(setq p (cdr p) m (car p))
805-
loop (cond ((null p) (return m)))
806-
(setq d (+ (car p) (multideg (cadr p))) p (cddr p) m (max d m))
808+
(cond ((numberp *p*) (return 0)) ((onevarp *p*) (return (cadr *p*))))
809+
(setq *p* (cdr *p*) m (car *p*))
810+
loop (cond ((null *p*) (return m)))
811+
(setq d (+ (car *p*) (multideg (cadr *p*))) *p* (cddr *p*) m (max d m))
807812
(go loop)))
808813

809814
(defun oddelm (list)
@@ -1083,9 +1088,9 @@
10831088

10841089

10851090
(defun fact2z (u f g limk)
1086-
(prog (a a1 w pk mpk b c r p ql qlp h (k 0) b1)
1091+
(prog (a a1 w pk mpk b c r *p* ql qlp h (k 0) b1)
10871092
(declare (fixnum k))
1088-
(setq p modulus)
1093+
(setq *p* modulus)
10891094
(setq r (ppprog f g))
10901095
(setq a (car r))
10911096
(setq b (cadr r))
@@ -1119,69 +1124,69 @@
11191124
(setq b (pplus b (npctimes mpk b1)))
11201125
(setq h nil b1 nil qlp nil)
11211126
(go sharp)
1122-
on (set-modulus p)
1127+
on (set-modulus *p*)
11231128
(return (list f g))))
11241129

11251130

11261131

1127-
(defun npctimes (c p)
1128-
(setq p (npctimes1 c p))
1129-
(if (and (not (atom p)) (null (cdr p)))
1132+
(defun npctimes (c *p*)
1133+
(setq *p* (npctimes1 c *p*))
1134+
(if (and (not (atom *p*)) (null (cdr *p*)))
11301135
0
1131-
p))
1136+
*p*))
11321137

1133-
(defun npquo (p c)
1138+
(defun npquo (*p* c)
11341139
(prog (u modulus)
1135-
(cond ((equal c 1) (return p))
1136-
((pcoefp p) (return (quotient p c))))
1137-
(setq u p)
1138-
loop (cond ((null (cdr u)) (return p)))
1140+
(cond ((equal c 1) (return *p*))
1141+
((pcoefp *p*) (return (quotient *p* c))))
1142+
(setq u *p*)
1143+
loop (cond ((null (cdr u)) (return *p*)))
11391144
(setq u (cddr u))
11401145
(rplaca u (cond ((pcoefp (car u))
11411146
(quotient (car u) c))
11421147
(t (npquo (copy-list (car u)) c))))
11431148
(go loop)))
11441149

1145-
(defun npctimes1 (c p)
1150+
(defun npctimes1 (c *p*)
11461151
(prog (u a)
1147-
(cond((equal c 1)(return p))
1148-
((pcoefp p)(return (ctimes c p))))
1149-
(setq u p)
1150-
loop (cond ((null (cdr u))(return p)))
1152+
(cond((equal c 1)(return *p*))
1153+
((pcoefp *p*)(return (ctimes c *p*))))
1154+
(setq u *p*)
1155+
loop (cond ((null (cdr u))(return *p*)))
11511156
(setq a (cond ((pcoefp (caddr u)) (ctimes c (caddr u)))
11521157
(t (npctimes c (copy-list (caddr u))))))
11531158
(cond ((equal a 0) (rplacd u (cdddr u)))
11541159
(t (setq u (cddr u))
11551160
(rplaca u a)))
11561161
(go loop)))
11571162

1158-
(defun x**q1 (term u m p)
1163+
(defun x**q1 (term u m *p*)
11591164
(declare (fixnum m))
11601165
(prog ((i 1))
11611166
(declare (fixnum i))
11621167
(setq trl* (list term))
1163-
loop (when (= i m) (return (pexptmod term p u)))
1164-
(setq term (pexptmod term p u))
1168+
loop (when (= i m) (return (pexptmod term *p* u)))
1169+
(setq term (pexptmod term *p* u))
11651170
(setq trl* (cons term trl*))
11661171
(incf i)
11671172
(go loop)))
11681173

1169-
(defun cptomf (p u n)
1170-
(declare (fixnum n p))
1174+
(defun cptomf (*p* u n)
1175+
(declare (fixnum n *p*))
11711176
(prog (l s *xn (j 0) (i 0) ind (n-1 (1- n)) )
11721177
(declare (fixnum i j))
11731178
loop (incf j)
11741179
(cond ((= j n) (return nil))
11751180
(ind (go sa))
1176-
((> (* p j) n-1)
1181+
((> (* *p* j) n-1)
11771182
(setq *xn (mapcar #'- (p2cpol (cddr u) n-1))
11781183
s (copy-tree *xn)
11791184
ind t)
1180-
(setq i (- (* p j) n))
1185+
(setq i (- (* *p* j) n))
11811186
(go sa1)))
1182-
(setq s (p2cpol (list var (* p j) 1) n-1))
1187+
(setq s (p2cpol (list var (* *p* j) 1) n-1))
11831188
(go st)
1184-
sa (setq i p)
1189+
sa (setq i *p*)
11851190
sa1 (cond ((= i 0) (go st)))
11861191
(cptimesx s)
11871192
(decf i)
@@ -1200,25 +1205,25 @@
12001205
on (decf (aref *afixn* j j))
12011206
(go loop)))
12021207

1203-
(defun p2cpol (p n)
1208+
(defun p2cpol (*p* n)
12041209
(declare (fixnum n))
12051210
(prog (l)
1206-
(setq p (cdr p))
1211+
(setq *p* (cdr *p*))
12071212
loop (cond ((= n -1) (return (nreverse l)))
1208-
((or (null p) (> n (car p))) (setq l (cons 0 l)))
1209-
((= n (car p))
1210-
(setq l (cons (cadr p) l))
1211-
(setq p (cddr p))))
1213+
((or (null *p*) (> n (car *p*))) (setq l (cons 0 l)))
1214+
((= n (car *p*))
1215+
(setq l (cons (cadr *p*) l))
1216+
(setq *p* (cddr *p*))))
12121217
(decf n)
12131218
(go loop)))
12141219

1215-
(defun cptimesx (p)
1220+
(defun cptimesx (*p*)
12161221
(prog (xn q lc)
1217-
(setq xn *xn q p lc (car p))
1222+
(setq xn *xn q *p* lc (car *p*))
12181223
loop (cond ((cdr q)
12191224
(rplaca q (cplus (cadr q) (ctimes lc (car xn))))
12201225
(setq q (cdr q) xn (cdr xn)))
1221-
(t (rplaca q (ctimes lc (car xn))) (return p)))
1226+
(t (rplaca q (ctimes lc (car xn))) (return *p*)))
12221227
(go loop)))
12231228

12241229

@@ -1339,25 +1344,25 @@
13391344
(return (list linfac (cpbq1 u (cadr u)) u))))
13401345

13411346

1342-
(defun factor1972 (p)
1347+
(defun factor1972 (*p*)
13431348
(let ((modulu* modulus) many* *stop* modulus mcflag *negflag*)
1344-
(if (or (atom p) (numberp p) (and algfac* (alg p)))
1345-
(list p)
1346-
(factor72 p))))
1349+
(if (or (atom *p*) (numberp *p*) (and algfac* (alg *p*)))
1350+
(list *p*)
1351+
(factor72 *p*))))
13471352

1348-
(defun factor72 (p)
1353+
(defun factor72 (*p*)
13491354
(let ((sharpcont 1) plim)
1350-
(setq p (cond ((onevarp p)
1351-
(mapcar #'posize (fact5 p)))
1355+
(setq *p* (cond ((onevarp *p*)
1356+
(mapcar #'posize (fact5 *p*)))
13521357
(t
13531358
(setq many* t)
1354-
(multfact p))))
1359+
(multfact *p*))))
13551360
(if *negflag*
1356-
(cons (pminus (car p)) (cdr p))
1357-
p)))
1361+
(cons (pminus (car *p*)) (cdr *p*))
1362+
*p*)))
13581363

1359-
(defun posize (p)
1360-
(cond ((pminusp p)
1364+
(defun posize (*p*)
1365+
(cond ((pminusp *p*)
13611366
(setq *negflag* (not *negflag*))
1362-
(pminus p))
1363-
(t p)))
1367+
(pminus *p*))
1368+
(t *p*)))

0 commit comments

Comments
 (0)