darioizzo / audi

Header only, C++ library (and the Python pyaudi package) implementing the algebra of Taylor truncated polynomials and a few algorithms useful for its applications (Differential Intelligence, automatic differentiation, Taylor Models, etc.)
http://darioizzo.github.io/audi/
GNU General Public License v2.0
71 stars 18 forks source link

Herratic behavior of vectorized type #57

Closed darioizzo closed 4 years ago

darioizzo commented 4 years ago

computations made by the vectorized type seem to be weirdly off in some cases:

from pyaudi import gdual_double as gdual
from pyaudi import gdual_vdouble as gdualv
def f(x,y):
    return x*y/(y-x)
x = gdual(1.1, "x", 2)
y = gdual(2.1, "y", 2)
xv = gdualv([1, 1.1], "x", 2)
yv = gdualv([1.1, 2.1], "y", 2)

note that the vectorized type has the x=1.1, y=2.1 point and thus it should be computing the same values of the non vectorized type in its second component.

then:

In [2]: f(x,y)                                                                                                                                                                   
Out[2]: -4.62*dx*dy-1.21*dy+2.31+4.41*dx+4.41*dx**2+1.21*dy**2

note that the mixed coefficient dx*dy is 4.62 but ...

In [4]: f(xv, yv)                                                                                                                                                                
Out[4]: [11, 2.31]+[121, 4.41]*dx+[-100, -1.21]*dy+[1210, 4.41]*dx**2+[1000, 1.21]*dy**2+[-2200, -220]*dx*dy

note that the mixed coefficient dx*dy is [-2200, -220], while its second component should be4.62. the mistake is not always there, it depends also from the value of the other coefficients!

darioizzo commented 4 years ago

Note that if, instead, we write:

xv = gdualv([1.1, 1.1], "x", 2) 
yv = gdualv([2.1, 2.1], "y", 2)   

the result stands correct:

In [4]: f(xv, yv)                                                                                                                                                                
Out[4]: [-1.21, -1.21]*dy+[2.31, 2.31]+[1.21, 1.21]*dy**2+[4.41, 4.41]*dx**2+[-4.62, -4.62]*dx*dy+[4.41, 4.41]*dx
darioizzo commented 4 years ago

will close this as #58 has fixed it implementing a new logic for fma3