# hermite_exactness

hermite_exactness, a Python code which investigates the polynomial exactness of a Gauss-Hermite quadrature rule for the infinite interval (-oo,+oo).

The Gauss Hermite quadrature assumes that the integrand we are considering has a form like:

```        Integral ( -oo < x < +oo ) f(x) * rho(x) dx
```
where the factor rho(x) is regarded as a weight factor.

We consider variations of the rule, depending on the form of the weight factor rho(x):

• option = 0, the unweighted rule:
```            rho(x) = 1
```
• option = 1, the physicist weighted rule:
```            rho(x) = exp(-x*x)
```
• option = 2, the probabilist weighted rule:
```            rho(x) = exp(-x*x/2)
```
• option = 3, the physicist normalized weighted rule:
```            rho(x) = exp(-x*x) / sqrt(pi)
```
• option = 4, the probabilist normalized weighted rule:
```            rho(x) = exp(-x*x/2) / sqrt(2 pi)
```

The corresponding Gauss-Hermite rule that uses order points will approximate the integral by

```        sum ( 1 <= i <= order ) w(i) * f(x(i))
```

When using a Gauss-Hermite quadrature rule, it's important to know whether the rule has been developed for the unweighted, physicist weighted or probabilist weighted cases.

For an unweighted Gauss-Hermite rule, polynomial exactness may be defined by assuming that f(x) has the form f(x) = exp(-x*x) * x^n for some nonnegative integer exponent n. We say an unweighted Gauss-Hermite rule is exact for polynomials up to degree DEGREE_MAX if the quadrature rule will produce the correct value of the integrals of such integrands for all exponents n from 0 to DEGREE_MAX.

For a physicist or probabilist weighted Gauss-Hermite rules, polynomial exactness may be defined by assuming that f(x) has the form f(x) = x^n for some nonnegative integer exponent n. We say the physicist or probabilist weighted Gauss-Hermite rule is exact for polynomials up to degree DEGREE_MAX if the quadrature rule will produce the correct value of the integrals of such integrands for all exponents n from 0 to DEGREE_MAX.

To test the polynomial exactness of a Gauss-Hermite quadrature rule of one of these three forms, the program starts at n = 0, and then proceeds to n = 1, 2, and so on up to a maximum degree DEGREE_MAX specified by the user. At each value of n, the program generates the appropriate corresponding integrand function (either exp(-x*x)*x^n or x^n), applies the quadrature rule to it, and determines the quadrature error. The program uses a scaling factor on each monomial so that the exact integral should always be 1; therefore, each reported error can be compared on a fixed scale.

The program is very flexible and interactive. The quadrature rule is defined by three files, to be read at input, and the maximum degree top be checked is specified by the user as well.

Note that the three files that define the quadrature rule are assumed to have related names, of the form

• prefix_x.txt
• prefix_w.txt
• prefix_r.txt
When running the program, the user only enters the common prefix part of the file names, which is enough information for the program to find all three files.

Note that when approximating these kinds of integrals, or even when evaluating an exact formula for these integrals, numerical inaccuracies can become overwhelming. The formula for the exact integral of x^n*exp(-x*x) (which we use to test for polynomial exactness) involves the double factorial function, which "blows up" almost as fast as the ordinary factorial. Thus, even for formulas of order 16, where we would like to consider monomials up to degree 31, the evaluation of the exact formula loses significant accuracy.

For information on the form of these files, see the QUADRATURE_RULES_HERMITE directory.

### Usage:

hermite_exactness ( 'prefix', degree_max, option )
where
• 'prefix' is a quoted string containing the common prefix for the files containing the abscissa, weight and region information of the quadrature rule;
• degree_max is the maximum monomial degree to check. This would normally be a relatively small nonnegative number, such as 5, 10 or 15.
• option: the weight option
0, rho(x) = 1,
1, rho(x) = exp(-x*x),
2, rho(x) = exp(-x*x/2),
3, rho(x) = exp(-x*x)/sqrt(pi),
4, rho(x) = exp(-x*x/2)/sqrt(2 pi).

If the arguments are not supplied on the command line, the program will prompt for them.

### Languages:

hermite_exactness is available in a C version and a C++ version and a Fortran90 version and a MATLAB version and an Octave version and a Python version.

### Related Data and Programs:

exactness, a Python code which investigates the exactness of quadrature rules that estimate the integral of a function with a density, such as 1, exp(-x) or exp(-x^2), over an interval such as [-1,+1], [0,+oo) or (-oo,+oo).

hermite_rule, a Python code which generates a Gauss-Hermite quadrature rule on request.

laguerre_exactness, a Python code which tests the polynomial exactness of Gauss-Laguerre quadrature rules for integration over [0,+oo) with density function exp(-x).

legendre_exactness, a Python code which tests the monomial exactness of quadrature rules for the Legendre problem of integrating a function with density 1 over the interval [-1,+1].

### Reference:

1. Philip Davis, Philip Rabinowitz,
Methods of Numerical Integration,
Second Edition,
Dover, 2007,
ISBN: 0486453391,
LC: QA299.3.D28.

### Source Code:

Last revised on 22 May 2023.