Compute Differentiation Scaling Factor#

import minterpy as mp
import numpy as np

Differentiating a polynomial in Minterpy involves two main steps:

  • Differentiating the internal polynomial representation with respect to the variables of the internal reference domain (currently \([-1, 1]^m\)), given the specified orders of differentiation

  • Scaling the result by the differentiation factor, which accounts for the change of variables from \(\Omega\) to \([-1, 1]^m\) via the chain rule

While Minterpy handles this scaling automatically, this guide demonstrates how the differentiation scaling factor can be computed directly from a Domain instance.

Example: Four-dimensional rectangular domain#

Create a four-dimensional rectangular domain that corresponds to:

\[ \Omega = [0.0, 5.0] \times [10.0, 15.0] \times [5.0, 10.0] \times [3.0, 7.0] \]

Domain instance#

The rectangular domain is defined four pair of bounds, each of which forms and interval for a dimension. We can specify them in a single two-dimensional array of two rows:

bounds = np.array([
    [0.0, 5.0],
    [10.0, 15.0],
    [5.0, 10.0],
    [3.0, 7.0],
])

An instance of Domain given an array of bounds can be constructed using the default constructor:

dom = mp.Domain(bounds)

We can verify that the domain is indeed four dimensional:

print(dom.spatial_dimension)
4

and with the appropriate bounds:

print(dom.bounds)
[[ 0.  5.]
 [10. 15.]
 [ 5. 10.]
 [ 3.  7.]]

Differentiation factor#

The differentiation factor can be computed via the diff_factor() method, which takes the order of derivatives as an argument. Applying the chain rule to the affine separable transformation, the differentiation scaling factor is:

\[ c = \prod_{i=1}^m \left(\frac{1 - (-1)}{b_i - a_i}\right)^{k_i} = \left(\frac{2}{b_i - a_i}\right)^{k_i}, \]

where \(k_i\) is the order of derivative for dimension \(i\).

For instance, the factor for the mixed partial derivative of \(f\) with respect to \(x_1\) and \(x_4\) is obtained via:

deriv_order = np.array([1, 0, 0, 1])  # Differentiation w.r.t x_1 and x_4
print(dom.diff_factor(deriv_order))
0.2

As another example, the factor for the mixed partial derivative \(\frac{\partial^3 f}{\partial x_2^2 \partial x_3}\) is obtained via:

deriv_order = np.array([0, 2, 1, 0])  # Differentiation w.r.t x_1 and x_4
print(dom.diff_factor(deriv_order))
0.06400000000000002