]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | [section:polynomials Polynomials] |
2 | ||
3 | [h4 Synopsis] | |
4 | ||
5 | `` | |
6 | #include <boost/math/tools/polynomial.hpp> | |
7 | `` | |
8 | ||
9 | namespace boost { namespace math { | |
10 | namespace tools { | |
11 | ||
12 | template <class T> | |
13 | class polynomial | |
14 | { | |
15 | public: | |
16 | // typedefs: | |
17 | typedef typename std::vector<T>::value_type value_type; | |
18 | typedef typename std::vector<T>::size_type size_type; | |
19 | ||
20 | // construct: | |
21 | polynomial(){} | |
22 | template <class U> | |
23 | polynomial(const U* data, unsigned order); | |
24 | template <class I> | |
25 | polynomial(I first, I last); | |
26 | template <class U> | |
27 | explicit polynomial(const U& point); | |
28 | polynomial(std::initializer_list<T> l); // C++11 | |
29 | ||
30 | // access: | |
31 | size_type size()const; | |
32 | size_type degree()const; | |
33 | value_type& operator[](size_type i); | |
34 | const value_type& operator[](size_type i)const; | |
35 | std::vector<T> const& data() const; | |
36 | std::vector<T>& data(); | |
37 | explicit operator bool() const; | |
38 | ||
39 | // modify: | |
40 | void set_zero(); | |
41 | ||
42 | // operators: | |
43 | template <class U> | |
44 | polynomial& operator +=(const U& value); | |
45 | template <class U> | |
46 | polynomial& operator -=(const U& value); | |
47 | template <class U> | |
48 | polynomial& operator *=(const U& value); | |
49 | template <class U> | |
50 | polynomial& operator /=(const U& value); | |
51 | template <class U> | |
52 | polynomial& operator %=(const U& value); | |
53 | template <class U> | |
54 | polynomial& operator +=(const polynomial<U>& value); | |
55 | template <class U> | |
56 | polynomial& operator -=(const polynomial<U>& value); | |
57 | template <class U> | |
58 | polynomial& operator *=(const polynomial<U>& value); | |
59 | template <class U> | |
60 | polynomial& operator /=(const polynomial<U>& value); | |
61 | template <class U> | |
62 | polynomial& operator %=(const polynomial<U>& value); | |
63 | }; | |
64 | ||
65 | template <class T> | |
66 | polynomial<T> operator + (const polynomial<T>& a, const polynomial<T>& b); | |
67 | template <class T> | |
68 | polynomial<T> operator - (const polynomial<T>& a, const polynomial<T>& b); | |
69 | template <class T> | |
70 | polynomial<T> operator * (const polynomial<T>& a, const polynomial<T>& b); | |
71 | template <class T> | |
72 | polynomial<T> operator / (const polynomial<T>& a, const polynomial<T>& b); | |
73 | template <class T> | |
74 | polynomial<T> operator % (const polynomial<T>& a, const polynomial<T>& b); | |
75 | ||
76 | template <class T, class U> | |
77 | polynomial<T> operator + (const polynomial<T>& a, const U& b); | |
78 | template <class T, class U> | |
79 | polynomial<T> operator - (const polynomial<T>& a, const U& b); | |
80 | template <class T, class U> | |
81 | polynomial<T> operator * (const polynomial<T>& a, const U& b); | |
82 | template <class T, class U> | |
83 | polynomial<T> operator / (const polynomial<T>& a, const U& b); | |
84 | template <class T, class U> | |
85 | polynomial<T> operator % (const polynomial<T>& a, const U& b); | |
86 | ||
87 | template <class U, class T> | |
88 | polynomial<T> operator + (const U& a, const polynomial<T>& b); | |
89 | template <class U, class T> | |
90 | polynomial<T> operator - (const U& a, const polynomial<T>& b); | |
91 | template <class U, class T> | |
92 | polynomial<T> operator * (const U& a, const polynomial<T>& b); | |
93 | ||
94 | template <class T> | |
95 | polynomial<T> operator - (const polynomial<T>& a); | |
96 | ||
97 | template <class T> | |
98 | polynomial<T> operator >>= (const U& a); | |
99 | template <class T> | |
100 | polynomial<T> operator >> (polynomial<T> const &a, const U& b); | |
101 | template <class T> | |
102 | polynomial<T> operator <<= (const U& a); | |
103 | template <class T> | |
104 | polynomial<T> operator << (polynomial<T> const &a, const U& b); | |
105 | ||
106 | template <class T> | |
107 | bool operator == (const polynomial<T> &a, const polynomial<T> &b); | |
108 | template <class T> | |
109 | bool operator != (const polynomial<T> &a, const polynomial<T> &b); | |
110 | ||
111 | template <class T> | |
112 | polynomial<T> pow(polynomial<T> base, int exp); | |
113 | ||
114 | template <class charT, class traits, class T> | |
115 | std::basic_ostream<charT, traits>& operator << | |
116 | (std::basic_ostream<charT, traits>& os, const polynomial<T>& poly); | |
117 | ||
118 | template <typename T> | |
119 | std::pair< polynomial<T>, polynomial<T> > | |
120 | quotient_remainder(const polynomial<T>& a, const polynomial<T>& b); | |
121 | ||
122 | } // namespace tools | |
123 | }} // namespace boost { namespace math | |
124 | ||
125 | [h4 Description] | |
126 | ||
127 | This is a somewhat trivial class for polynomial manipulation. | |
128 | ||
129 | See | |
130 | ||
131 | * [@https://en.wikipedia.org/wiki/Polynomial Polynomial] and | |
132 | * Donald E. Knuth, The Art of Computer Programming: Volume 2, Third edition, (1998) | |
133 | Chapter 4.6.1, Algorithm D: Division of polynomials over a field. | |
134 | ||
135 | Implementation is currently of the "naive" variety, with [bigo](N[super 2]) | |
136 | multiplication, for example. This class should not be used in | |
137 | high-performance computing environments: it is intended for the | |
138 | simple manipulation of small polynomials, typically generated | |
139 | for special function approximation. | |
140 | ||
141 | It does has division for polynomials over a [@https://en.wikipedia.org/wiki/Field_%28mathematics%29 field] | |
142 | (here floating point, complex, etc) | |
143 | and over a unique factorization domain (integers). | |
144 | Division of polynomials over a field is compatible with | |
145 | [@https://en.wikipedia.org/wiki/Euclidean_algorithm Euclidean GCD]. | |
146 | ||
147 | Advanced manipulations: the FFT, factorisation etc are | |
148 | not currently provided. Submissions for these are of course welcome :-) | |
149 | ||
150 | [h4:polynomial_examples Polynomial Arithmetic Examples] | |
151 | ||
152 | [import ../../example/polynomial_arithmetic.cpp] | |
153 | ||
154 | [polynomial_arithmetic_0] | |
155 | [polynomial_arithmetic_1] | |
156 | ||
157 | [polynomial_arithmetic_2] | |
158 | for output: | |
159 | [polynomial_output_1] | |
160 | ||
161 | [polynomial_arithmetic_3] | |
162 | for output | |
163 | [polynomial_output_2] | |
164 | ||
165 | [h5 Division, Quotient and Remainder] | |
166 | [polynomial_arithmetic_4] | |
167 | ||
168 | The source code is at [@../../example/polynomial_arithmetic.cpp polynomial_arithmetic.cpp] | |
169 | ||
170 | [endsect] [/section:polynomials Polynomials] | |
171 | ||
172 | [/ | |
173 | Copyright 2006 John Maddock and Paul A. Bristow. | |
174 | Copyright 2015 Jeremy William Murphy. | |
175 | ||
176 | Distributed under the Boost Software License, Version 1.0. | |
177 | (See accompanying file LICENSE_1_0.txt or copy at | |
178 | http://www.boost.org/LICENSE_1_0.txt). | |
179 | ] |