[section:polynomials Polynomials] [h4 Synopsis] `` #include `` namespace boost { namespace math { namespace tools { template class polynomial { public: // typedefs: typedef typename std::vector::value_type value_type; typedef typename std::vector::size_type size_type; // construct: polynomial(){} template polynomial(const U* data, unsigned order); template polynomial(I first, I last); template explicit polynomial(const U& point, typename boost::enable_if >::type* = 0); template explicit polynomial(const Range& r, typename boost::enable_if >::type* = 0); // C++14 polynomial(std::initializer_list l); // C++11 polynomial(std::vector&& p); // access: size_type size()const; size_type degree()const; value_type& operator[](size_type i); const value_type& operator[](size_type i)const; std::vector const& data() const; std::vector& data(); explicit operator bool() const; polynomial prime() const; polynomial integrate() const; T operator()(T z) const; // modify: void set_zero(); // operators: template polynomial& operator +=(const U& value); template polynomial& operator -=(const U& value); template polynomial& operator *=(const U& value); template polynomial& operator /=(const U& value); template polynomial& operator %=(const U& value); template polynomial& operator +=(const polynomial& value); template polynomial& operator -=(const polynomial& value); template polynomial& operator *=(const polynomial& value); template polynomial& operator /=(const polynomial& value); template polynomial& operator %=(const polynomial& value); }; template polynomial operator + (const polynomial& a, const polynomial& b); template polynomial operator - (const polynomial& a, const polynomial& b); template polynomial operator * (const polynomial& a, const polynomial& b); template polynomial operator / (const polynomial& a, const polynomial& b); template polynomial operator % (const polynomial& a, const polynomial& b); template polynomial operator + (const polynomial& a, const U& b); template polynomial operator - (const polynomial& a, const U& b); template polynomial operator * (const polynomial& a, const U& b); template polynomial operator / (const polynomial& a, const U& b); template polynomial operator % (const polynomial& a, const U& b); template polynomial operator + (const U& a, const polynomial& b); template polynomial operator - (const U& a, const polynomial& b); template polynomial operator * (const U& a, const polynomial& b); template polynomial operator - (const polynomial& a); template polynomial operator >>= (const U& a); template polynomial operator >> (polynomial const &a, const U& b); template polynomial operator <<= (const U& a); template polynomial operator << (polynomial const &a, const U& b); template bool operator == (const polynomial &a, const polynomial &b); template bool operator != (const polynomial &a, const polynomial &b); template polynomial pow(polynomial base, int exp); template std::basic_ostream& operator << (std::basic_ostream& os, const polynomial& poly); template std::pair< polynomial, polynomial > quotient_remainder(const polynomial& a, const polynomial& b); } // namespace tools }} // namespace boost { namespace math [h4 Description] This is a somewhat trivial class for polynomial manipulation. See * [@https://en.wikipedia.org/wiki/Polynomial Polynomial] and * Donald E. Knuth, The Art of Computer Programming: Volume 2, Third edition, (1998) Chapter 4.6.1, Algorithm D: Division of polynomials over a field. Implementation is currently of the "naive" variety, with [bigo](N[super 2]) multiplication, for example. This class should not be used in high-performance computing environments: it is intended for the simple manipulation of small polynomials, typically generated for special function approximation. It does has division for polynomials over a [@https://en.wikipedia.org/wiki/Field_%28mathematics%29 field] (here floating point, complex, etc) and over a unique factorization domain (integers). Division of polynomials over a field is compatible with [@https://en.wikipedia.org/wiki/Euclidean_algorithm Euclidean GCD]. Division of polynomials over a UFD is compatible with the subresultant algorithm for GCD (implemented as subresultant_gcd), but a serious word of warning is required: the intermediate value swell of that algorithm will cause single-precision integral types to overflow very easily. So although the algorithm will work on single-precision integral types, an overload of the gcd function is only provided for polynomials with multi-precision integral types, to prevent nasty surprises. This is done somewhat crudely by disabling the overload for non-POD integral types. Advanced manipulations: the FFT, factorisation etc are not currently provided. Submissions for these are of course welcome :-) [h4:polynomial_examples Polynomial Arithmetic Examples] [import ../../example/polynomial_arithmetic.cpp] [polynomial_arithmetic_0] [polynomial_arithmetic_1] [polynomial_arithmetic_2] for output: [polynomial_output_1] [polynomial_arithmetic_3] for output [polynomial_output_2] [h5 Division, Quotient and Remainder] [polynomial_arithmetic_4] The source code is at [@../../example/polynomial_arithmetic.cpp polynomial_arithmetic.cpp] [endsect] [/section:polynomials Polynomials] [/ Copyright 2006 John Maddock and Paul A. Bristow. Copyright 2015 Jeremy William Murphy. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt). ]