fjames86 / fpoly

Manipulate dense multivariate polynomials
0 stars 0 forks source link

bug in fpoly-add #14

Closed fjames86 closed 11 years ago

fjames86 commented 11 years ago

adding a polynomial of degree 0 (nil vars) doesn't work correctly

(fpoly-add (make-fpoly nil 0 '(1)) (make-fpoly 'x 2 '(1 1 1)))

<FPOLY :VARS (X) :DEGREE 2 :COEFFS #(1 1 1)>

I.e. it doesn't add the 0 coeff (for the constant). Comes in from merge-powers which returns NIL on (merge-powers '(X) '(0) NIL) Probably we shouldn't allow polynomials of degree 0 (i.e. constants) and just cast them to numbers but unfortunately doing this creates problems elsewhere.

fjames86 commented 11 years ago

correction: (project-powers NIL) -> NIL Should it instead return (0) if all are zero? This would be consistent with the decision to set the powers list of NIL variable poly objects to ((0))

fjames86 commented 11 years ago

fixing project-powers in the way above by adding a degree check (if (and (null target-vars) (zerop (reduce #'+ source-powers))) (list 0) (nreverse (rec source-vars source-powers nil))))) Fixes the above issue and is consistent with the docoeffs hack, i.e. setting the powers list of a null variable poly to '((0))

fjames86 commented 11 years ago

done