Quick start

Python

My first program

If you have successfully compiled and installed pyaudi following the Python bindings you will be able to test its use typing the following script.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from pyaudi import gdual_double as gdual
from pyaudi import exp, log, cbrt

# We want to compute the Taylor expansion of a function f (and thus all derivatives) at x=2, y=3
# 1 - Define the generalized dual numbers (7 is the truncation order, i.e.
# the maximum order of derivation we will need)

x = gdual(2, "x", 7)
y = gdual(3, "y", 7)

# 2 - Compute your function as usual
f = exp(x * x + cbrt(y) / log(x * y))

# 3 - Inspect the results (this does not require any more computations)
# This is the Taylor expansion of f (truncated at the 7th order)
print("Taylor polynomial: " + str(f))
# This is the value of the derivative (d / dx)
print("Derivative value [1,0]: " + str(f.get_derivative([1, 0])))
# This is the value of the mixed derivative (d^7 / dx^4dy^3)
print("Derivative value [4,3]: " + str(f.get_derivative([4, 3])))

# 4 - Using the dictionary interface (note the presence of the "d" before
# all variables)
# This is the value of the derivative (d / dx)
print("Derivative value [1,0]: " + str(f.get_derivative({"dx": 1})))
# This is the value of the mixed derivative (d^7 / dx^4dy^3)
print("Derivative value [4,3]: " + str(f.get_derivative({"dx": 4, "dy": 3})))

Place it into a getting_started.py text file and run it with

python getting_started.py

We recommend the use of Jupyter or ipython do enjoy pyaudi the most.


C++

My first program

After following the Packages you will be able to compile and run your first C++ AuDi program:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <audi/gdual.hpp>
#include <audi/functions.hpp>
#include <iostream>

using namespace audi;

int main()
{
    // We want to compute the Taylor expansion of a function f (and thus all derivatives) at x=2, y=3
    using gdual = gdual<double>;
    // 1 - Define the generalized dual numbers (over doubles, 7 is the truncation order, i.e. the maximum
    // order of derivation we will need)
    gdual x(2, "x", 7);
    gdual y(3, "y", 7);

    // 2 - Compute your function as usual
    auto f = exp(x * x + cbrt(y) / log(x * y));

    // 3 - Inspect the results (this has a constant complexity now as all computations have been made already)
    std::cout << "Taylor polynomial: " << f
              << std::endl; // This is the Taylor expansion of f (truncated at the 7th order)
    std::cout << "Derivative value: " << f.get_derivative({1, 0})
              << std::endl; // This is the value of the derivative (d / dx)
    std::cout << "Derivative value: " << f.get_derivative({4, 3})
              << std::endl; // This is the value of the mixed derivative (d^7 / dx^4dy^3)

    // 4 - Using the dictionary interface (note the presence of the "d" before all variables)
    std::cout << "Derivative value: " << f.get_derivative({{"dx", 1}})
              << std::endl; // This is the value of the derivative (d / dx)
    std::cout << "Derivative value: " << f.get_derivative({{"dx", 4}, {"dy", 3}})
              << std::endl; // This is the value of the mixed derivative (d^7 / dx^4dy^3)
}

Place it into a getting_started.cpp text file and compile it with:

g++ -std=c++11 getting_started.cpp -lmpfr -lgmp -pthread