Skip to main content

[JScience-Users] Re: [Bug in JScience]: problem with multiplication of polynomials

  • From: Jean-Marie Dautelle <dautelle@...>
  • To: users@...
  • Subject: [JScience-Users] Re: [Bug in JScience]: problem with multiplication of polynomials
  • Date: Sat, 15 Dec 2012 20:07:04 +0100

Hi,
Could you enter the issue in JIRA to ensure it get processed for the JScience release scheduled at the end of the year.
Thanks,
Jean-Marie.


On Sat, Dec 15, 2012 at 1:13 PM, Maciej Piechotka <uzytkownik2@...> wrote:
Hi,

I tried to use JScience for multiplication of polynomials. During
debugging of program I discovered that such code (this is reproduction
example, not actual code) produce wrong result:

x = Variable.Local("x")
curr = Polynomial.valueOf(Float64.valueOf(-0.69098300562505266),
x).plus(Float64.valueOf(0.30901699437494745))
prev = Polynomial.valueOf(Float64.valueOf(-1.8090169943749472),
x).plus(Float64.valueOf(-0.8090169943749473))
next = curr.times(prev)

next #==>
[1.25]x² + [-0.5590169943749474]x + [-0.25]

To compare results from:

numpy: 1.25 x² - 0.25
maxima: 1.25 x² - 0.25
wolfram alpha: 1.25 x² - 0.25

I'm not sure what causes this problem but it looks that either I use
JScience incorrectly or there is some serious bug in polynomial
multiplication.

Best regards

EDIT:

It looks like the term is not removed after it is zeroed. Patch is
below:

Index:
mathematics/src/main/java/org/jscience/mathematics/function/Polynomial.java
===================================================================
---
mathematics/src/main/java/org/jscience/mathematics/function/Polynomial.java(revision 694)
+++
mathematics/src/main/java/org/jscience/mathematics/function/Polynomial.java(working copy)
@@ -229,6 +229,7 @@
                 R coef = (prev != null) ? prev.plus(c) : c;
                 if (isZero(coef)) {
                     zero = coef;
+                    result._termToCoef.remove(t);
                 } else {
                     result._termToCoef.put(t, coef);
                 }





--
As a well spent day brings happy sleep, so life well used brings happy death - ‹(•¿•)› Leonardo da Vinci 


[JScience-Users] [Bug in JScience]: problem with multiplication of polynomials

Maciej Piechotka 12/15/2012

[JScience-Users] Re: [Bug in JScience]: problem with multiplication of polynomials

Jean-Marie Dautelle 12/15/2012
 
 
Close
loading
Please Confirm
Close