Library of Assembled Shared Sources
polynomial.h
Go to the documentation of this file.
1/** @file
2 * @author Bram de Greve (bram@cocamware.com)
3 * @author Tom De Muer (tom@cocamware.com)
4 *
5 * *** BEGIN LICENSE INFORMATION ***
6 *
7 * The contents of this file are subject to the Common Public Attribution License
8 * Version 1.0 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://lass.sourceforge.net/cpal-license. The License is based on the
11 * Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover
12 * use of software over a computer network and provide for limited attribution for
13 * the Original Developer. In addition, Exhibit A has been modified to be consistent
14 * with Exhibit B.
15 *
16 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
17 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
18 * language governing rights and limitations under the License.
19 *
20 * The Original Code is LASS - Library of Assembled Shared Sources.
21 *
22 * The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
23 * The Original Developer is the Initial Developer.
24 *
25 * All portions of the code written by the Initial Developer are:
26 * Copyright (C) 2004-2011 the Initial Developer.
27 * All Rights Reserved.
28 *
29 * Contributor(s):
30 *
31 * Alternatively, the contents of this file may be used under the terms of the
32 * GNU General Public License Version 2 or later (the GPL), in which case the
33 * provisions of GPL are applicable instead of those above. If you wish to allow use
34 * of your version of this file only under the terms of the GPL and not to allow
35 * others to use your version of this file under the CPAL, indicate your decision by
36 * deleting the provisions above and replace them with the notice and other
37 * provisions required by the GPL License. If you do not delete the provisions above,
38 * a recipient may use your version of this file under either the CPAL or the GPL.
39 *
40 * *** END LICENSE INFORMATION ***
41 */
42
43
44
45/** @class lass::num::Polynomial
46 * @brief an univariate polynomial.
47 * @author Bram de Greve [BdG]
48 *
49 * <i>A polynomial is a mathematical expression involving a sum of powers in one or more variables
50 * multiplied by coefficients.</i>,
51 * Eric W. Weisstein. "Polynomial." From MathWorld--A Wolfram Web Resource.
52 * http://mathworld.wolfram.com/Polynomial.html
53 */
54
55#ifndef LASS_GUARDIAN_OF_INCLUSION_NUM_POLYNOMIAL_H
56#define LASS_GUARDIAN_OF_INCLUSION_NUM_POLYNOMIAL_H
57
58#include "num_common.h"
59#include "num_traits.h"
60
61namespace lass
62{
63namespace num
64{
65
66template <typename T>
67class Polynomial
68{
69public:
70
71 typedef Polynomial<T> TSelf;
72 typedef NumTraits<T> TNumTraits;
73 typedef typename util::CallTraits<T>::TValue TValue;
74 typedef typename util::CallTraits<T>::TParam TParam;
75 typedef typename util::CallTraits<T>::TReference TReference;
76 typedef typename util::CallTraits<T>::TConstReference TConstReference;
77
78 typedef std::vector<TValue> TCoefficients;
79 typedef typename TCoefficients::size_type size_type;
80 typedef typename TCoefficients::const_iterator const_iterator;
81
82 Polynomial();
83 explicit Polynomial(TParam iScalar);
84 explicit Polynomial(const TCoefficients& iCoefficients);
85 template <typename InputIterator> Polynomial(InputIterator iBegin, InputIterator iEnd);
86
87 const TCoefficients& coefficients() const;
88 const TValue operator[](size_t iIndex) const;
89 const TValue at(size_t iIndex) const;
90
91 const TValue operator()(TParam iX) const;
92
93 const Polynomial<T>& operator+() const;
94 const Polynomial<T> operator-() const;
95
96 Polynomial<T>& operator+=(const Polynomial<T>& iOther);
97 Polynomial<T>& operator-=(const Polynomial<T>& iOther);
98 Polynomial<T>& operator*=(const Polynomial<T>& iOther);
99
100 Polynomial<T>& operator+=(TParam iScalar);
101 Polynomial<T>& operator-=(TParam iScalar);
102 Polynomial<T>& operator*=(TParam iScalar);
103 Polynomial<T>& operator/=(TParam iScalar);
104
105 Polynomial<T> derivative() const;
106 Polynomial<T> integral() const;
107 Polynomial<T> pow(size_t iPower) const;
108
109 const size_type size() const;
110 const const_iterator begin() const;
111 const const_iterator end() const;
112
113 static Polynomial<T> one();
114 static Polynomial<T> x();
115
116private:
117
118 TCoefficients a_;
119};
120
121template <typename T> bool operator==(const Polynomial<T>& iA, const Polynomial<T>& iB);
122template <typename T> bool operator!=(const Polynomial<T>& iA, const Polynomial<T>& iB);
123
124template <typename T> Polynomial<T> operator+(const Polynomial<T>& iA, const Polynomial<T>& iB);
125template <typename T> Polynomial<T> operator-(const Polynomial<T>& iA, const Polynomial<T>& iB);
126template <typename T> Polynomial<T> operator*(const Polynomial<T>& iA, const Polynomial<T>& iB);
127
128template <typename T> Polynomial<T> operator+(const T& iA, const Polynomial<T>& iB);
129template <typename T> Polynomial<T> operator-(const T& iA, const Polynomial<T>& iB);
130template <typename T> Polynomial<T> operator*(const T& iA, const Polynomial<T>& iB);
131
132template <typename T> Polynomial<T> operator+(const Polynomial<T>& iA, const T& iB);
133template <typename T> Polynomial<T> operator-(const Polynomial<T>& iA, const T& iB);
134template <typename T> Polynomial<T> operator*(const Polynomial<T>& iA, const T& iB);
135template <typename T> Polynomial<T> operator/(const Polynomial<T>& iA, const T& iB);
136
137template <typename T, typename Char, typename Traits>
138std::basic_ostream<Char, Traits>&
139operator<<(std::basic_ostream<Char, Traits>& iS, const Polynomial<T>& iA);
140
141
142}
143}
144
145#include "polynomial.inl"
146
147#endif
148
149// EOF
an univariate polynomial.
Definition polynomial.h:68
const const_iterator end() const
return iterator to last (highest) coefficient
static Polynomial< T > x()
return linear polynomial x
static Polynomial< T > one()
return constant polynomial 1
const size_type size() const
return size of coefficients.
const const_iterator begin() const
return iterator to first (lowest) coefficient
numeric types and traits.
Definition basic_ops.h:70
Library for Assembled Shared Sources.
Definition config.h:53