CONTENT bug (rat3e.lisp)



Here is the bug (I assume that ALGEBRAIC and MODULUS are both set to
FALSE).

(C1) content(a,x);
(D1) 				    [1, a]

Note that the variable A should be regarded as polynomial in X with
coefficients in Z[A] (which has unique factorisation).  So the answer
should be [A, 1] (or [-A,-1]).  Specifying explicitly that A is a
(non-main) variable as in CONTENT(A,A,X) gives the same wrong result.

By contrast, say

(C2) content(a*x,x);
(D2) 				    [a, x]
(C3) content(2,x);
(D3) 				    [2, 1]

are both correct.  The reason for this bug is that the relevant
auxiliary functions called by $CONTENT don't care about the original
main variable given as last argument to $CONTENT.  Instead, they
receive the CRE representation of the polynomial in question without
the `header'.  If this representation is a list they assume that its
car is the main variable.  So in the first example above, Maxima
effectively regards A as a polynomial in A (instead of in X).

I propose the following bug fix.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cut ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Index: rat3e.lisp
===================================================================
RCS file: /cvsroot/maxima/maxima/src/rat3e.lisp,v
retrieving revision 1.3
diff -C2 -r1.3 rat3e.lisp
*** rat3e.lisp	13 Aug 2002 03:10:55 -0000	1.3
--- rat3e.lisp	27 Aug 2002 00:28:17 -0000
***************
*** 439,442 ****
--- 439,448 ----
  	      (NEWVAR X)
  	      (DESETQ (H X . Y) (RATREP* X))
+ 	      (unless (atom x)
+ 		;; (CAR X) => gensym corresponding to apparent main var.
+ 		;; MAIN-GENVAR => gensym corresponding to the genuine main var.
+ 		(let ((main-genvar (nth (1- (length varlist)) genvar)))
+ 		  (unless (eq (car x) main-genvar)
+ 		    (setq x `(,main-genvar 0 ,x)))))
  	      (SETQ X (RCONTENT X)
  		    Y (CONS 1 Y))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cut ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Wolfgang
-- 
wjenkner@inode.at