MADNESS  0.10.1
Public Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
slymer::PolynomialCoeffs Class Reference

Array for storing coefficients of a polynomial of three variables with specified degree. More...

#include <polynomial.h>

Public Member Functions

 PolynomialCoeffs ()=delete
 
 PolynomialCoeffs (const double constant, const double x, const double y, const double z)
 Create a linear function with the specified coefficients. More...
 
 PolynomialCoeffs (const unsigned N)
 Create a polynomial of degree N. More...
 
unsigned get_degree () const
 Get the degree of the polynomial. More...
 
double operator() (const std::array< double, 3 > &pt) const
 Evaluate the polynomial at the specified point. More...
 
PolynomialCoeffs operator* (const double c) const
 Multiply a polynomial by a constant value. More...
 
PolynomialCoeffs operator* (const PolynomialCoeffs &rhs) const
 Multiply two polynomials together. More...
 
PolynomialCoeffsoperator*= (const double c)
 Scale the polynomial by a constant. More...
 
PolynomialCoeffs operator+ (const PolynomialCoeffs &rhs) const
 Add two polynomials together. More...
 
PolynomialCoeffsoperator+= (const PolynomialCoeffs &rhs)
 Adds another polynomial to this one. More...
 
double & operator[] (const std::array< unsigned, 3 > &pows)
 Access the coefficient for the specified term. More...
 
double operator[] (const std::array< unsigned, 3 > &pows) const
 Access the coefficient for the specified term. More...
 
PolynomialCoeffs pow (const unsigned j) const
 Expands a linear polynomial raised to a power. More...
 

Static Protected Member Functions

static unsigned polyIndex (const std::array< unsigned, 3 > &pows)
 Gets the array index for the coefficient of a particular term. More...
 

Protected Attributes

std::vector< double > coeffs
 Array storing the coefficients. More...
 
unsigned degree
 The degree of the polynomial. More...
 

Detailed Description

Array for storing coefficients of a polynomial of three variables with specified degree.

The general polynomial of three variables is written as

\[ \sum_{i,j,k} c_{i,j,k} x^i y^j z^k, \]

where $0\le i+j+k\le N$. This data structure stores the coefficients in a vector and provides access routines in terms of the exponents $i$, $j$, and $k$.

Note
This class is not designed for polynomials with a large degree.

Constructor & Destructor Documentation

◆ PolynomialCoeffs() [1/3]

slymer::PolynomialCoeffs::PolynomialCoeffs ( )
delete

◆ PolynomialCoeffs() [2/3]

slymer::PolynomialCoeffs::PolynomialCoeffs ( const double  constant,
const double  x,
const double  y,
const double  z 
)
inline

Create a linear function with the specified coefficients.

Parameters
[in]constantThe constant term.
[in]xThe coefficient on x.
[in]yThe coefficient on y.
[in]zThe coefficient on z.

References coeffs, constant(), and polyIndex().

◆ PolynomialCoeffs() [3/3]

slymer::PolynomialCoeffs::PolynomialCoeffs ( const unsigned  N)
inline

Create a polynomial of degree N.

Parameters
[in]NThe degree of the polynomial.

References coeffs.

Member Function Documentation

◆ get_degree()

unsigned slymer::PolynomialCoeffs::get_degree ( ) const
inline

Get the degree of the polynomial.

Returns
The degree of the polynomial.

References degree.

Referenced by slymer::PrimitiveGaussian::PrimitiveGaussian().

◆ operator()()

double slymer::PolynomialCoeffs::operator() ( const std::array< double, 3 > &  pt) const

Evaluate the polynomial at the specified point.

Note
This implemention is a bit naive; it is not intended for polynomials with a large degree.
Parameters
[in]ptThe point at which the polynomial is evaluated.
Returns
The value of the polynomial at the point.

References coeffs, degree, k, polyIndex(), and pow().

◆ operator*() [1/2]

PolynomialCoeffs slymer::PolynomialCoeffs::operator* ( const double  c) const

Multiply a polynomial by a constant value.

*this is one of the polynomials.

Parameters
[in]cThe constant value.
Returns
The product of c and the polynomial.

References c, and coeffs.

◆ operator*() [2/2]

PolynomialCoeffs slymer::PolynomialCoeffs::operator* ( const PolynomialCoeffs rhs) const

Multiply two polynomials together.

*this is one of the polynomials.

Parameters
[in]rhsThe other polynomial.
Returns
The product of *this and rhs.

References degree, and operator[]().

◆ operator*=()

PolynomialCoeffs & slymer::PolynomialCoeffs::operator*= ( const double  c)

Scale the polynomial by a constant.

Parameters
[in]cThe scale factor.
Returns
The scaled polynomial (*this).

References c, and coeffs.

◆ operator+()

PolynomialCoeffs slymer::PolynomialCoeffs::operator+ ( const PolynomialCoeffs rhs) const

Add two polynomials together.

*this is one of the polynomials.

Parameters
[in]rhsThe other polynomial.
Returns
The sum of *this and rhs.

References coeffs, and degree.

◆ operator+=()

PolynomialCoeffs & slymer::PolynomialCoeffs::operator+= ( const PolynomialCoeffs rhs)

Adds another polynomial to this one.

Parameters
[in]rhsThe other polynomial.
Returns
The sum of *this and rhs, in *this.

References coeffs, degree, and madness::swap().

◆ operator[]() [1/2]

double& slymer::PolynomialCoeffs::operator[] ( const std::array< unsigned, 3 > &  pows)
inline

Access the coefficient for the specified term.

Parameters
[in]powsThe powers of x, y, and z for this term.
Returns
Reference to the array term.

References coeffs, and polyIndex().

Referenced by operator*().

◆ operator[]() [2/2]

double slymer::PolynomialCoeffs::operator[] ( const std::array< unsigned, 3 > &  pows) const
inline

Access the coefficient for the specified term.

Parameters
[in]powsThe powers of x, y, and z for this term.
Returns
The array term.

References coeffs, and polyIndex().

◆ polyIndex()

static unsigned slymer::PolynomialCoeffs::polyIndex ( const std::array< unsigned, 3 > &  pows)
inlinestaticprotected

Gets the array index for the coefficient of a particular term.

Terms of degree 0 are stored before those of degree 1, etc.

Within a particular degree, think of the problem in the combinatorial "stars and bars" idea: there are n stars and two bars dividing them into three parts. (Each part corresponds to the number of x, y, or z factors.) The first array element will be bars in the 0 and 1 positions, then 0 and 2, ..., 0 and n+1, then 1 and 2, etc.

Parameters
[in]powsThe powers of x, y, and z for this term.
Returns
The array offset, as described above.

Referenced by PolynomialCoeffs(), operator()(), and operator[]().

◆ pow()

PolynomialCoeffs slymer::PolynomialCoeffs::pow ( const unsigned  j) const

Expands a linear polynomial raised to a power.

Essentially expands the polynomial

\[ (coeffs[0] + coeffs[1]*x + coeffs[2]*y + coeffs[3]*z)^j \]

into a new PolynomialCoeffs object. That is, output[{{p,q,r}}] is the coefficient on the $x^p y^q z^r$ term.

This function requires multinomial coefficients, which involve factorials. We assume that the arguments to the factorials will not be large and hard-code small values. An error will be thrown if the maximum value is exceeded.

Exceptions
std::runtime_errorif the polynomial does not have degree 1.
Parameters
[in]jThe exponent of the expansion.
Returns
The polynomial, ordered using the polyIndex scheme.

References degree.

Referenced by operator()().

Member Data Documentation

◆ coeffs

std::vector<double> slymer::PolynomialCoeffs::coeffs
protected

Array storing the coefficients.

For a given degree n, there are $(n+1)(n+2)/2$ monomials. The total array thus has $(n+1)*(n+2)*(n+3)/6$ terms. The array stores all terms with degree 0, then degree 1, then degree 2, etc.

Referenced by PolynomialCoeffs(), operator()(), operator*(), operator*=(), operator+(), operator+=(), and operator[]().

◆ degree

unsigned slymer::PolynomialCoeffs::degree
protected

The degree of the polynomial.

Referenced by get_degree(), operator()(), operator*(), operator+(), operator+=(), and pow().


The documentation for this class was generated from the following files: