Quadruple precision computations (new in 1.3)

Qudruple precision floats

The class real128 in pyaudi ia a multiple precision float, basically wrapping the GNU C++ *__float128* type. It can be used outside of the whole differential algebra machinery (the gduals) to perform quadruple precision computations

[1]:
from pyaudi import real128
from pyaudi import sin, acos
[2]:
# Some simple math
x = real128("3")
print(1/x)
3.33333333333333333333333333333333317e-01
[3]:
# Trigonometry
print(sin(x))
1.41120008059867222100744802808110299e-01
[4]:
# The value of pi in double precision
print("Double precision:\t", 2*acos(0))
# The value of pi in quadruple precision
print("Quad precision:\t\t", 2*acos(real128("0")))
Double precision:        3.141592653589793
Quad precision:          3.14159265358979323846264338327950280e+00

Qudruple precision gdual

The gdual can also perform computations in quadruple precision.

[5]:
from pyaudi import gdual_real128 as gdual
from pyaudi import sin, acos, sqrt
[6]:
def easy_fun(x,y):
    return (1/x/y)**10

x = gdual("3", "x", 2)
y = gdual("2.12", "y", 2)
res = easy_fun(x,y)
print("A quadruple precision gdual computation: ")
res
A quadruple precision gdual computation:
[6]:
\[ -4.35605126899062478098382207778725168e-08{dy}-3.07827623008670817856190093496965737e-08{dx}+1.13010764054002057997221799187876804e-07{dy}^{2}+9.23482869026012453568570280490897241e-09+1.45201708966354159366127402592908378e-07{dx}{dy}+5.64350642182563166069681838077770461e-08{dx}^{2}+\mathcal{O}\left(3\right) \]

All quantities, that is the function value and its derivatives are in quadruple precision. Lets extract \(\frac{\partial^2 f}{\partial x \partial y}\):

[7]:
der = res.get_derivative({"dx": 1, "dy": 1})
print("value: ", der)
print("type: ", type(der))
value:  1.45201708966354159366127402592908378e-07
type:  <class 'pyaudi.core.real128'>
[8]:
from IPython.display import Image
from IPython.core.display import HTML
Image(url= "http://images6.fanpop.com/image/photos/38700000/That-s-All-Folks-the-looney-tunes-show-38740983-500-281.jpg")
[8]: