Boost logo

Boost-Commit :

From: lord.zerom1nd_at_[hidden]
Date: 2008-08-20 09:28:44


Author: kieliszczyk
Date: 2008-08-20 09:28:43 EDT (Wed, 20 Aug 2008)
New Revision: 48262
URL: http://svn.boost.org/trac/boost/changeset/48262

Log:
libs
Added:
   sandbox/SOC/2008/polynomial/libs/docs/
   sandbox/SOC/2008/polynomial/libs/docs/boost.png (contents, props changed)
   sandbox/SOC/2008/polynomial/libs/docs/index.html (contents, props changed)
   sandbox/SOC/2008/polynomial/libs/test/
   sandbox/SOC/2008/polynomial/libs/test/test_arithmetics.cpp (contents, props changed)
   sandbox/SOC/2008/polynomial/libs/test/test_comparisons.cpp (contents, props changed)
   sandbox/SOC/2008/polynomial/libs/test/test_creating.cpp (contents, props changed)
   sandbox/SOC/2008/polynomial/libs/test/test_derivatives.cpp (contents, props changed)
   sandbox/SOC/2008/polynomial/libs/test/test_integrals.cpp (contents, props changed)
   sandbox/SOC/2008/polynomial/libs/test/test_special_forms.cpp (contents, props changed)

Added: sandbox/SOC/2008/polynomial/libs/docs/boost.png
==============================================================================
Binary file. No diff available.

Added: sandbox/SOC/2008/polynomial/libs/docs/index.html
==============================================================================
--- (empty file)
+++ sandbox/SOC/2008/polynomial/libs/docs/index.html 2008-08-20 09:28:43 EDT (Wed, 20 Aug 2008)
@@ -0,0 +1,649 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+<title>Polynomial Library</title>
+</head>
+<body>
+<img src="boost.png" alt="boost.png (6897 bytes)" align="middle" width="277" height="86">
+<h1>Polynomial Library</h1>
+
+<h2><a name="contents">Contents</a></h2>
+
+<ol>
+ <li>Introduction</li>
+ <li>Synopsis</li>
+ <li>Background</li>
+ <li>Interface
+ <ul>
+ <li>Constructors</li>
+ <li>Modification</li>
+ <li>Arithmetic operations</li>
+ <li>Greates Common Divisor</li>
+ <li>Evaluation</li>
+ <li>Derivatives and integrals</li>
+ <li>Special forms</li>
+ <li>Input and Output</li>
+ </ul></li>
+ <li>Performance</li>
+ <li>Header <boost/math/tools/polynomial/special_functions></li>
+ <li>Credits</li>
+</ol>
+
+<h2><a name="introduction">Introduction</a></h2>
+
+<p>The class and function templates in &lt;boost/math/tools/polynomial.hpp&gt; facilitate manipulation of polynomials. Special algorithms provide fast and faithful calculations that might be useful for many problems related to mathematics.</p>
+
+<h2><a name="synopsis">Synopsis</a></h2>
+
+<pre>
+ namespace boost {
+ namespace math {
+ namespace tools {
+
+ template&lt;typename FieldType&gt;
+ class polynomial {
+ public:
+ // typedefs:
+ typedef typename std::vector&lt;FieldType&gt;::value_type value_type;
+ typedef typename std::vector&lt;FieldType&gt;::size_type size_type;
+
+ // constructors:
+ polynomial();
+ template&lt;typename InputIterator&gt;
+ polynomial(InputIterator first, InputIterator last);
+ template&lt;typename U&gt;
+ polynomial(const U* coef, const size_type n);
+ template&lt;typename U&gt;
+ polynomial(const U&amp; v);
+ template&lt;typename InputIterator&gt;
+ polynomial(InputIterator first1, InputIterator last1, InputIterator first2);
+ polynomial(std::vector&lt;FieldType&gt;&amp; c);
+
+ // copy constructor:
+ template&lt;typename U&gt;
+ polynomial(const polynomial&lt;U&gt;&amp; poly);
+
+ // modification:
+ template&lt;typename U&gt;
+ polynomial&lt;FieldType&gt;&amp; operator=(const polynomial&lt;U&gt;&amp; poly);
+ polynomial&lt;FieldType&gt;&amp; operator=(std::vector&lt;FieldType&gt;&amp; c);
+ template&lt;typename InputIterator&gt;
+ void interpolate(InputIterator first1, InputIterator last1, InputIterator first2);
+ void swap(polynomial&lt;FieldType&gt;&amp; poly);
+
+ // access:
+ size_type size() const;
+ size_type degree() const;
+ const value_type&amp; operator[](const size_type i) const;
+ value_type&amp; operator[](const size_type i);
+ typename std::vector&lt;FieldType&gt;::const_iterator begin() const;
+ typename std::vector&lt;FieldType&gt;::iterator begin();
+ typename std::vector&lt;FieldType&gt;::const_iterator end() const;
+ typename std::vector&lt;FieldType&gt;::iterator end();
+
+ // evaluation:
+ FieldType operator()(const FieldType&amp; z) const;
+ FieldType evaluate(const FieldType&amp; z) const;
+ FieldType evaluate_faithfully(const FieldType&amp; z) const;
+ void precondition_coefficients();
+ FieldType evaluate_by_preconditioning(const FieldType&amp; z) const;
+
+ // derivatives and integrals:
+ polynomial&lt;FieldType&gt; derivative() const;
+ polynomial&lt;FieldType&gt; integral(const FieldType&amp; c) const;
+ FieldType definite_integral(const FieldType&amp; a, const FieldType&amp; b) const;
+
+ // operators:
+
+ const polynomial&lt;FieldType&gt;&amp; operator+() const;
+ polynomial&lt;FieldType&gt; operator-() const;
+
+ // addition:
+ template&lt;typename U&gt;
+ polynomial&lt;FieldType&gt;&amp; operator+=(const polynomial&lt;U&gt;&amp; poly);
+ template&lt;typename U&gt;
+ polynomial&lt;FieldType&gt;&amp; operator+=(const U&amp; v);
+
+ // substraction:
+ template&lt;typename U&gt;
+ polynomial&lt;FieldType&gt;&amp; operator-=(const polynomial&lt;U&gt;&amp; poly);
+ template&lt;typename U&gt;
+ polynomial&lt;FieldType&gt;&amp; operator-=(const U&amp; v);
+
+ // multiplication:
+ template&lt;typename U&gt;
+ polynomial&lt;FieldType&gt;&amp; operator*=(const polynomial&lt;U&gt;&amp; poly);
+ template&lt;typename U&gt;
+ polynomial&lt;FieldType&gt;&amp; operator*=(const U&amp; v);
+
+ // division:
+ template&lt;typename U&gt;
+ polynomial&lt;FieldType&gt;&amp; operator/=(const polynomial&lt;U&gt;&amp; poly);
+ template&lt;typename U&gt;
+ polynomial&lt;FieldType&gt;&amp; operator/=(const U&amp; v);
+
+ // modulo:
+ template&lt;typename U&gt;
+ polynomial&lt;FieldType&gt;&amp; operator%=(const polynomial&lt;U&gt;&amp; poly);
+ };
+
+ } // namespace tools
+ } // namespace math
+ } // namespace boost
+</pre>
+
+<h2><a name="background">Background</a></h2>
+
+<p>In the implementation of the <b>polynomial</b> class std::vector is used to contain the coefficients. You don't have to care about this but in some cases you can attain better performance if you call functions that use nested functions of std::vector. See Performance section.</p>
+
+<h2><a name="interface">Interface</a></h2>
+
+<h3><a name="constructors">Constructors</a></h3>
+
+<p>There are 6 constructors provided by <b>polynomial</b> class.</p>
+
+<p>Default constructor
+<pre>
+ polynomial();
+</pre>
+generates zero polynomial.</p>
+<br>
+<p>Constructor from a value type
+
+<pre>
+ template&lt;typename U&gt;
+ polynomial(const U&amp; v);
+</pre>
+
+initializes <b>polynomial</b> class instance to a constant polynomial (of degree 0) with the coefficient equal to v.</p>
+<br>
+<p>The class provides two constructors from prepared coefficients.
+
+<pre>
+ template&lt;typename U&gt;
+ polynomial(const U* coef, const size_type n);
+</pre>
+
+This constructor creates a polynomial of degree <b>n-1</b> where:
+<ul>
+ <li> <b>*coef</b> is the coefficient for <b>x^0</b> term,</li>
+ <li> <b>*(coef+1)</b> is the coefficient for <b>x^1</b> term,</li>
+ <li> ...</li>
+ <li> <b>*(coef+n-1)</b> is the coefficient for <b>x^(n-1)</b> term.</li>
+</ul>
+<br>
+<br>
+The constructor with two iterators
+
+<pre>
+ template&lt;typename InputIterator&gt;
+ polynomial(InputIterator first, InputIterator last);
+</pre>
+
+works same but the prepared coefficients are restricted by two iterator and:
+<ul>
+ <li> <b>*first</b> is the coefficient for <b>x^0</b> term,</li>
+ <li> <b>*(first+1)</b> is the coefficient for <b>x^1</b> term,</li>
+ <li> ...</li>
+ <li> <b>*(last-1)</b> is the coefficient for <b>x(n-1)</b> term where <b>n = std::distance(first, last)</b>.</li>
+</ul>
+</p>
+<br>
+<p>Next constructor
+
+<pre>
+ polynomial(InputIterator first1, InputIterator last1, InputIterator first2);
+</pre>
+
+creates a polynomial of the least possible degree by interpolation where:
+<ul>
+ <li> iterators <b>first1</b> and <b>last1</b> restrict the arguments,</li>
+ <li> iterator <b>first2</b> points at the value for <b>*first1</b> argument,</li>
+ <li> iterator <b>first2+1</b> points at the value for <b>*(first1+1)</b> argument,</li>
+ <li> ...</li>
+</ul>
+</p>
+<br>
+<p>
+The last constructor
+
+<pre>
+ polynomial(std::vector&lt;FieldType&gt;&amp; c);
+</pre>
+
+just uses the std::vector::swap() function to exchange contents of <b>c</b> vector and own vector where the <b>polynomial</b> keeps the coefficients.<br>
+Note that the <b>c</b> will be probably changed if you use this constructor. On the other hand this is the fastest way to initiate the class with many coefficients (more in Performance section).</p>
+
+<h4>Example</h4>
+
+<pre>
+ boost::math::tools::polynomial&lt;int&gt; poly1; // zero
+ int coefficients[3] = {3, 2, 1};
+ boost::math::tools::polynomial&lt;int&gt; poly2(coefficients, 3); // x^2 + 2x + 3
+ std::vector&lt;double&gt; v;
+ v.push_back(-1.0);
+ v.push_back(0.0);
+ v.push_back(3.5);
+ boost::math::tools::polynomial&lt;double&gt; poly3(v); // 3.5x^2 - 1.0
+</pre>
+
+<h3><a name="modification">Modification</a></h3>
+
+<p>You can simply modify your <b>polynomial</b> using the following functions:</p>
+
+<p>Standard modification:
+<pre>
+ template&lt;typename U&gt;
+ polynomial&lt;FieldType&gt;&amp; operator=(const polynomial&lt;U&gt;&amp; poly);
+</pre>
+</p>
+
+<br>
+
+<p>Modification from std::vector:
+<pre>
+ polynomial&lt;FieldType&gt;&amp; operator=(std::vector&lt;FieldType&gt;&amp; c);
+</pre>
+This function uses the nested std::vector::swap() function. The <b>c</b> vector should contain new coefficients.<br>
+</p>
+<br>
+<p>
+You can change the polynomial using interpolation method:
+<pre>
+ template&lt;typename InputIterator&gt;
+ void interpolate(InputIterator first1, InputIterator last1, InputIterator first2);
+</pre>
+This function works similar to the adequate constructor.
+</p>
+<br>
+<p>
+If you want to swap two <b>polynomials</b>, you can use:
+<pre>
+ void swap(polynomial&lt;FieldType&gt;&amp; poly);
+</pre>
+It uses std::vector::swap() function.
+</p>
+
+<h3><a name="arithmetic_operations">Arithmetic operations</a></h3>
+
+<p>The following numeric operators are defined for the <b>polynomial</b> class:</p>
+
+<pre>
+ + (unary)
+ - (unary)
+ +
+ +=
+ -
+ -=
+ *
+ *=
+ /
+ /=
+ %
+ %=
+</pre>
+
+<h3><a name="gcd">Greatest Common Divisor</a></h3>
+
+<p><b>polynomial</b> class provides special function for calculating greatest common divisor.</p>
+
+<pre>
+ namespace boost {
+ namespace math {
+ namespace tools {
+
+ template<typename IntegerType>
+ polynomial<IntegerType> gcd(polynomial<IntegerType> u, polynomial<IntegerType> v);
+
+ } // namespace tools
+ } // namespace math
+ } // namespace boost
+</pre>
+
+However this function to calculate the greatest common divisor faithfully, generates big numbers for big polynomials that are needed for such calculations. It's recommended to use some not built-in types like bigints, then. For smaller polynomials simple built-in types like int are sufficient enough.
+
+<h4>Example</h4>
+
+<pre>
+ int coefficients1[10] = {7, -10, 10, -11, 18, -7, -27, 10, 0, 4};
+ int coefficients2[7] = {-70, 30, 0, 3, 3, 0, 1};
+ boost::math::tools::polynomial&lt;int&gt; poly1(coefficients1, 10);
+ boost::math::tools::polynomial&lt;int&gt; poly2(coefficients2, 7);
+ std::cout &lt;&lt; gcd(poly1, poly2) &lt;&lt; std::endl;
+
+ // Output:
+ // {-7, 3, 0, 1}
+</pre>
+
+<h3><a name="evaluation">Evaluation</a></h3>
+
+<p>Polynomial evaluation can be done in 3 ways. These two functions:
+<pre>
+ FieldType operator()(const FieldType&amp; z) const;
+ FieldType evaluate(const FieldType&amp; z) const;
+</pre>
+use the simple Horner scheme to evaluate and will probably meet your needs in most cases.
+</p>
+<p>
+For programmers that need very faithful calculations on floating-point types the <b>polynomial</b> class provides:
+<pre>
+ FieldType evaluate_faithfully(const FieldType&amp; z) const;
+</pre>
+This functions uses slower algorithms than the Horner scheme but promises better faithfulness.
+</p>
+<p>
+The last way to evaluate a polynomial is provided for speed. Unfortunately it can be used only for polynomials of degree from 4 to 6 and is profitable only with floating-point coefficients. If you want to evaluate same polynomial many times it will be worth considering a use of this method.
+<pre>
+ void precondition_coefficients();
+ FieldType evaluate_by_preconditioning(const FieldType&amp; z) const;
+</pre>
+Before evaluating you should call precondition_coefficients() function once. Then you can evaluate the polynomial using evaluate_by_preconditioning() function many times and it will work probably faster than the simple Horner scheme.
+</p>
+
+<h4>Example</h4>
+
+<pre>
+ double coefficients[5] = {-3.1, 2.5, 0.0, -11.7, 5.9};
+ boost::math::tools::polynomial&lt;&lt;double&gt; poly(coefficients, 5);
+ std::cout &lt;&lt; poly(0.0) &lt;&lt; std::endl;
+ std::cout &lt;&lt; poly.evaluate(1.7) &lt;&lt; std::endl;
+ std::cout &lt;&lt; poly.evaluate(-4.37) &lt;&lt; std::endl;
+ poly.precondition_coefficients();
+ std::cout &lt;&lt; poly.evaluate(3.13) &lt;&lt; std::endl;
+
+ // Output:
+ // -3.1
+ // -7.05471
+ // 3114.06
+ // 212.23
+</pre>
+
+<h3><a name="derivatives_integrals">Derivatives and integrals</a></h3>
+
+<p>Calculating derivatives is very simple. Once you create your polynomial you can use this function:
+<pre>
+ polynomial&lt;FieldType&gt; derivative() const;
+</pre>
+It returns a new polynomial that is equal to the derivative of your polynomial.
+</p>
+<p>
+Two functions for integrals are provided by the <b>polynomial</b> class:
+<pre>
+ polynomial&lt;FieldType&gt; integral(const FieldType&amp; c) const;
+ FieldType definite_integral(const FieldType&amp; a, const FieldType&amp; b) const;
+</pre>
+The first of them returns indefinite integral where <b>c</b> is the coefficient for <b>x^0</b> term.
+The second function returns a definite integral over an interval <b>[a, b]</b>.
+</p>
+
+<h4>Example</h4>
+
+<pre>
+ int coefficients[7] = {2, -1278, 588, 0, -150, 0, 56};
+ boost::math::tools::polynomial&lt;int&gt; poly(coefficients, 7);
+ std::cout &lt;&lt; poly.derivative() &lt;&lt; std::endl;
+ std::cout &lt;&lt; poly.integral() &lt;&lt; std::endl;
+ std::cout &lt;&lt; poly.integral(47) &lt;&lt; std::endl;
+ std::cout &lt;&lt; poly.definite_integral(-1, 1) &lt;&lt; std::endl;
+
+ // Output:
+ // {-1278, 1176, 0, -600, 0, 336}
+ // {0, 2, -639, 196, 0, -30, 0, 8}
+ // {47, 2, -639, 196, 0, -30, 0, 8}
+ // 352
+</pre>
+
+<h3><a name="special_forms">Special forms</a></h3>
+
+<p>
+Sometimes in calculations special polynomial forms are needed. Header &lt;boost/math/tools/polynomial/special_forms&gt; simply includes the headers with functions that can calculate four forms: Chebyshev, Hermite, Laguerre and Legendre. The <b>polynomial</b> class uses these algorithms and make them very easy in use. The following functions are provided:
+<pre>
+ namespace boost {
+ namespace math {
+ namespace tools {
+
+ template<typename FieldType, typename Size>
+ polynomial<FieldType> chebyshev_form(const Size sz);
+
+ template<typename FieldType, typename Size>
+ polynomial<FieldType> hermite_form(const Size sz);
+
+ template<typename FieldType, typename Size>
+ polynomial<FieldType> laguerre_form(const Size sz);
+
+ template<typename FieldType, typename Size>
+ polynomial<FieldType> legendre_form(const Size sz);
+
+ } // namespace tools
+ } // namespace math
+ } // namespace boost
+</pre>
+</p>
+
+<h4>Example</h4>
+
+<pre>
+ boost::math::tools::polynomial&lt;int&gt; poly1 = boost::math::tools::chebyshev_form&lt;int&gt;(8);
+ boost::math::tools::polynomial&lt;int&gt; poly2 = boost::math::tools::hermite_form&lt;int&gt;(5);
+ boost::math::tools::polynomial&lt;double&gt; poly3 = boost::math::tools::laguerre_form&ltdouble&gt;(3);
+ boost::math::tools::polynomial&lt;double&gt; poly4 = boost::math::tools::legendre_form&lt;double&gt;(4);
+ std::cout &lt;&lt; poly1 &lt;&lt; std::endl;
+ std::cout &lt;&lt; poly2 &lt;&lt; std::endl;
+ std::cout &lt;&lt; poly3 &lt;&lt; std::endl;
+ std::cout &lt;&lt; poly4 &lt;&lt; std::endl;
+
+ // Output:
+ // {1, 0, -32, 0, 160, 0, -256, 0, 128}
+ // {0, 120, 0, -160, 0, 32}
+ // {1, -3, 1.5, -0.166667}
+ // {0.375, 0, -3.75, 0, 4.375}
+</pre>
+
+<h3><a name="input_output">Input and Output</a></h3>
+
+<p>No input operator is provided. You should create your polynomials using methods described in Constructors section.</p>
+
+<p>Output operator <tt>&lt;&lt;</tt> is provided.</p>
+
+<h2><a name="performance">Performance</a></h2>
+
+<p>
+Here is a table with summary performance of implemented functions and algorithms.<br>
+<b>n</b> is a degree of a polynomial.
+</p>
+
+
+
+<table>
+ <tr>
+ <th>Function</th>
+ <th>Implementation</th>
+ <th>Notice</th>
+ </tr>
+ <tr>
+ <td>polynomial()</td>
+ <td>O(1)</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>polynomial(const U&amp; v</td>
+ <td>O(1)</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>polynomial(InputIterator first, InputIterator last);</td>
+ <td>O(n)</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>polynomial(const U* coef, const size_type n);</td>
+ <td>O(n)</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>polynomial(InputIterator first1, InputIterator last1, InputIterator first2)</td>
+ <td>O(n<sup>2</sup>)</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>polynomial(std::vector&lt;FieldType&gt;&amp; c)</td>
+ <td>O(1)</td>
+ <td><b>c</b> vector may be changed</td>
+ </tr>
+ <tr>
+ <td>operator=(const polynomial&lt;U&gt;&amp; poly)</td>
+ <td>O(n)</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>operator=(std::vector&lt;FieldType&gt;&amp; c)</td>
+ <td>O(1)</td>
+ <td><b>c</b> vector may be changed</td>
+ </tr>
+ <tr>
+ <td>interpolate(InputIterator first1, InputIterator last1, InputIterator first2)</td>
+ <td>O(n<sup>2</sup>)</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>swap(polynomial&lt;FieldType&gt;&amp; poly)</td>
+ <td>O(1)</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>derivative()</td>
+ <td>O(n)</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>integral(const FieldType&amp; c)</td>
+ <td>O(n)</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>definite_integral(const FieldType&amp; a, const FieldType&amp; b)</td>
+ <td>O(n)</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>+ (unary)</td>
+ <td>O(1)</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>- (unary)</td>
+ <td>O(1)</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>+, +=</td>
+ <td>O(n)</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>-, -=</td>
+ <td>O(n)</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>*, *=</td>
+ <td>O(n*lg(n))</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>/, /=</td>
+ <td>O(n<sup>2</sup>)</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>/, /=</td>
+ <td>O(n<sup>2</sup>)</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>gcd(polynomial<IntegerType> u, polynomial<IntegerType> v)</td>
+ <td>O(n<sup>3</sup>)</td>
+ <td></td>
+ </tr>
+ <tr>
+ <td>creating special forms</td>
+ <td>O(n)</td>
+ <td></td>
+ </tr>
+</table>
+
+<h2><a name="header_special_functions">Header &lt;boost/math/tools/polynomial/special_functions&gt;</a></h2>
+
+<pre>
+ namespace boost {
+ namespace math {
+ namespace tools {
+
+ template&lt;typename InputIterator&gt;
+ inline typename std::iterator_traits&lt;InputIterator&gt;::value_type
+ evaluate_polynomial(InputIterator first, InputIterator last, typename std::iterator_traits&lt;InputIterator&gt;::value_type x);
+
+ template&lt;typename InputIterator&gt;
+ typename std::iterator_traits&lt;InputIterator&gt;::value_type
+ evaluate_polynomial_faithfully(InputIterator first, InputIterator last, typename std::iterator_traits&lt;InputIterator&gt;::value_type x);
+
+ template&lt;typename InputIterator, typename OutputIterator&gt;
+ OutputIterator precondition_polynomial_coefficients(InputIterator first, InputIterator last, OutputIterator result);
+
+ template&lt;typename InputIterator, typename ValueType&gt;
+ ValueType evaluate_polynomial_by_preconditioning(InputIterator first, InputIterator last, const ValueType& x);
+
+ template&lt;typename InputIterator, typename OutputIterator&gt;
+ OutputIterator copy_polynomial_derivative(InputIterator first, InputIterator last, OutputIterator result);
+
+ template&lt;typename InputIterator, typename OutputIterator&gt;
+ OutputIterator copy_polynomial_integral(InputIterator first, InputIterator last, OutputIterator result,
+ typename std::iterator_traits&lt;OutputIterator&gt;::value_type c
+ = (typename std::iterator_traits&lt;OutputIterator&gt;::value_type)(0.0)
+ );
+
+ template&lt;typename InputIterator&gt;
+ inline typename std::iterator_traits&lt;InputIterator&gt;::value_type
+ evaluate_polynomial_definite_integral(InputIterator first, InputIterator last,
+ typename std::iterator_traits&lt;InputIterator&gt;::value_type a,
+ typename std::iterator_traits&lt;InputIterator&gt;::value_type b
+ );
+
+ template&lt;typename InputIterator, typename OutputIterator&gt;
+ OutputIterator interpolate_polynomial(InputIterator first1, InputIterator last1, InputIterator first2, OutputIterator result);
+
+ } // namespace tools
+ } // namespace math
+ } // namespace boost
+</pre>
+
+These function were written especially for Polynomial Library but may be used separately as well. Usage of them should be clear but there is one thing that should be explained. If you want to use evaluate_polynomial() or evaluate_polynomial_faithfully() function, you should use the following representation of your coefficients:
+<ul>
+ <li> <b>*first</b> is the coefficient for <b>x(n-1)</b> term where <b>n = std::distance(first, last)</b>,</li>
+ <li> <b>*(first+1)</b> is the coefficient for <b>x^(n-1)</b> term,</li>
+ <li> ...</li>
+ <li> <b>*(last-1)</b> is the coefficient for <b>x^0</b> term.</li>
+</ul>
+For the rest of the functions:
+<ul>
+ <li> <b>*first</b> is the coefficient for <b>x^0</b> term,</li>
+ <li> <b>*(first+1)</b> is the coefficient for <b>x^1</b> term,</li>
+ <li> ...</li>
+ <li> <b>*(last-1)</b> is the coefficient for <b>x(n-1)</b> term where <b>n = std::distance(first, last)</b>,</li>
+ <li> A memory pointed by OutputIterator result (appears in some of functions) should be allocated before you call a function.</li>
+</ul>
+Be careful about this.
+
+<h2><a name="credits">Credits</a></h2>
+
+<p>The author of the library is Pawel Kieliszczyk. It was implemented as a Boost project for Google Summer of Code 2008.</p>
+<p>The mentor of the project was Fernando Cacciola whose notices and suggestions were very helpful.</p>
+<p>The previous version of the polynomial class was written by John Maddock and was a base for the current version.</p>
+<p>The structure of this documentation is based on Boost.Bigint documentation that was written by Arseny Kapoulkine.</p>
+<p>Revised August 15, 2008</p>
+<p>&copy; Copyright Pawel Kieliszczyk 2008. Permission to copy, use, modify, sell and distribute this document is granted provided this copyright notice appears in all copies. This document is provided &quot;as is&quot; without express or implied warranty, and with no claim as to its
+suitability for any purpose.</p>
+
+</body>
+</html>
+

Added: sandbox/SOC/2008/polynomial/libs/test/test_arithmetics.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2008/polynomial/libs/test/test_arithmetics.cpp 2008-08-20 09:28:43 EDT (Wed, 20 Aug 2008)
@@ -0,0 +1,993 @@
+#define BOOST_DISABLE_WIN32
+
+#include <boost/test/included/test_exec_monitor.hpp>
+#include "../../boost/polynomial.hpp"
+
+#define ARRAY_SIZE(array) sizeof(array) / sizeof(array[0])
+
+void test_plus() {
+ {
+ int p[] = {0};
+ boost::math::tools::polynomial<int> poly(p, ARRAY_SIZE(p));
+ int res[] = {0};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(+poly, result);
+ }
+ {
+ int p[] = {7};
+ boost::math::tools::polynomial<int> poly(p, ARRAY_SIZE(p));
+ int res[] = {7};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(+poly, result);
+ }
+ {
+ int p[] = {452, 93248, 237, -2392, -3432};
+ boost::math::tools::polynomial<int> poly(p, ARRAY_SIZE(p));
+ int res[] = {452, 93248, 237, -2392, -3432};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(+poly, result);
+ }
+}
+
+void test_minus() {
+ {
+ int p[] = {0};
+ boost::math::tools::polynomial<int> poly(p, ARRAY_SIZE(p));
+ int res[] = {0};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(-poly, result);
+ }
+ {
+ int p[] = {7};
+ boost::math::tools::polynomial<int> poly(p, ARRAY_SIZE(p));
+ int res[] = {-7};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(-poly, result);
+ }
+ {
+ int p[] = {452, 93248, 237, -2392, -3432};
+ boost::math::tools::polynomial<int> poly(p, ARRAY_SIZE(p));
+ int res[] = {-452, -93248, -237, 2392, 3432};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(-poly, result);
+ }
+}
+
+void test_addition() {
+ // same degrees:
+ {
+ int p1[] = {0};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {0};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 + poly2, result);
+ BOOST_CHECK_EQUAL(poly2 + poly1, result);
+ }
+ {
+ int p1[] = {1, 2, 3, 4, 5, 6, 7};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {3, 4, 5, 6, 7, 8, 9};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {4, 6, 8, 10, 12, 14, 16};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 + poly2, result);
+ BOOST_CHECK_EQUAL(poly2 + poly1, result);
+ }
+ {
+ int p1[] = {231463, -703, -9450, 190};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {403, 0, -289455, -8772};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {231866, -703, -298905, -8582};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 + poly2, result);
+ BOOST_CHECK_EQUAL(poly2 + poly1, result);
+ }
+ {
+ int p1[] = {4, -5, 3, 10};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {-7, 5, 0, -10};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {-3, 0, 3};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 + poly2, result);
+ BOOST_CHECK_EQUAL(poly2 + poly1, result);
+ }
+ {
+ int p1[] = {4325, -23427, -234827, 493, 1, -3442737, 3, -7347, 2};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {-4325, 23427, 234827, -493, -1, 3442737, -3, 7347, -2};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 + poly2, result);
+ BOOST_CHECK_EQUAL(poly2 + poly1, result);
+ }
+
+ // different degrees:
+ {
+ int p1[] = {-14, 7, 1};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {47, -7, 45, -113, 2};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {33, 0, 46, -113, 2};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 + poly2, result);
+ BOOST_CHECK_EQUAL(poly2 + poly1, result);
+ }
+ {
+ int p1[] = {0, 9773, -14857, 48274, -472438, 10};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {-403};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {-403, 9773, -14857, 48274, -472438, 10};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 + poly2, result);
+ BOOST_CHECK_EQUAL(poly2 + poly1, result);
+ }
+ {
+ int p1[] = {7, -113, 67, 539, 4922};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {-7, 113, -67, -539, -4922, 1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0, 0, 0, 0, 0, 1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 + poly2, result);
+ BOOST_CHECK_EQUAL(poly2 + poly1, result);
+ }
+
+ // polynomial vs value
+ {
+ int p[] = {0};
+ boost::math::tools::polynomial<int> poly(p, ARRAY_SIZE(p));
+ int val = 0;
+ int res[] = {0};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly + val, result);
+ BOOST_CHECK_EQUAL(val + poly, result);
+ }
+ {
+ int p[] = {5};
+ boost::math::tools::polynomial<int> poly(p, ARRAY_SIZE(p));
+ int val = 0;
+ int res[] = {5};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly + val, result);
+ BOOST_CHECK_EQUAL(val + poly, result);
+ }
+ {
+ int p[] = {8};
+ boost::math::tools::polynomial<int> poly(p, ARRAY_SIZE(p));
+ int val = -7;
+ int res[] = {1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly + val, result);
+ BOOST_CHECK_EQUAL(val + poly, result);
+ }
+ {
+ int p[] = {113, 48347, -3494278, 0, 382, 0, -37273, 219};
+ boost::math::tools::polynomial<int> poly(p, ARRAY_SIZE(p));
+ int val = 0;
+ int res[] = {113, 48347, -3494278, 0, 382, 0, -37273, 219};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly + val, result);
+ BOOST_CHECK_EQUAL(val + poly, result);
+ }
+ {
+ int p[] = {-24, 48392, -43};
+ boost::math::tools::polynomial<int> poly(p, ARRAY_SIZE(p));
+ int val = -2839;
+ int res[] = {-2863, 48392, -43};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly + val, result);
+ BOOST_CHECK_EQUAL(val + poly, result);
+ }
+}
+
+void test_substraction() {
+ // same degrees:
+ {
+ int p1[] = {0};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {0};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 - poly2, result);
+ BOOST_CHECK_EQUAL(poly2 - poly1, -result);
+ }
+ {
+ int p1[] = {1, 2, 3, 4, 5, 6, 7};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {3, 4, 5, 6, 7, 8, 9};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {-2, -2, -2, -2, -2, -2, -2};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 - poly2, result);
+ BOOST_CHECK_EQUAL(poly2 - poly1, -result);
+ }
+ {
+ int p1[] = {231463, -703, -9450, 190};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {403, 0, -289455, -8772};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {231060, -703, 280005, 8962};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 - poly2, result);
+ BOOST_CHECK_EQUAL(poly2 - poly1, -result);
+ }
+ {
+ int p1[] = {4325, -23427, -234827, 493, 1, -3442737, 3, -7347, 2};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {4325, -23427, -234827, 493, 1, -3442737, 3, -7347, 2};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 - poly2, result);
+ BOOST_CHECK_EQUAL(poly2 - poly1, -result);
+ }
+
+ // different degrees:
+ {
+ int p1[] = {-14, 7, 1};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {47, -7, 45, -113, 2};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {-61, 14, -44, 113, -2};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 - poly2, result);
+ BOOST_CHECK_EQUAL(poly2 - poly1, -result);
+ }
+ {
+ int p1[] = {0, 9773, -14857, 48274, -472438, 10};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {-403};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {403, 9773, -14857, 48274, -472438, 10};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 - poly2, result);
+ BOOST_CHECK_EQUAL(poly2 - poly1, -result);
+ }
+ {
+ int p1[] = {7, -113, 67, 539, 4922};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {7, -113, 67, 539, 4922, -1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0, 0, 0, 0, 0, 1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 - poly2, result);
+ BOOST_CHECK_EQUAL(poly2 - poly1, -result);
+ }
+
+ // polynomial vs value
+ {
+ int p[] = {0};
+ boost::math::tools::polynomial<int> poly(p, ARRAY_SIZE(p));
+ int val = 0;
+ int res[] = {0};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly - val, result);
+ BOOST_CHECK_EQUAL(val - poly, result);
+ }
+ {
+ int p[] = {5};
+ boost::math::tools::polynomial<int> poly(p, ARRAY_SIZE(p));
+ int val = 0;
+ int res[] = {5};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly - val, result);
+ BOOST_CHECK_EQUAL(val - poly, -result);
+ }
+ {
+ int p[] = {8};
+ boost::math::tools::polynomial<int> poly(p, ARRAY_SIZE(p));
+ int val = -7;
+ int res[] = {15};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly - val, result);
+ BOOST_CHECK_EQUAL(val - poly, -result);
+ }
+ {
+ int p[] = {113, 48347, -3494278, 0, 382, 0, -37273, 219};
+ boost::math::tools::polynomial<int> poly(p, ARRAY_SIZE(p));
+ int val = 0;
+ int res[] = {113, 48347, -3494278, 0, 382, 0, -37273, 219};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly - val, result);
+ BOOST_CHECK_EQUAL(val - poly, -result);
+ }
+ {
+ int p[] = {-24, 48392, -43};
+ boost::math::tools::polynomial<int> poly(p, ARRAY_SIZE(p));
+ int val = -2839;
+ int res[] = {2815, 48392, -43};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly - val, result);
+ BOOST_CHECK_EQUAL(val - poly, -result);
+ }
+}
+
+void test_multiplication() {
+ // same degrees:
+ {
+ int p1[] = {0};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {0};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 * poly2, result);
+ BOOST_CHECK_EQUAL(poly2 * poly1, result);
+ }
+ {
+ int p1[] = {0};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {5};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 * poly2, result);
+ BOOST_CHECK_EQUAL(poly2 * poly1, result);
+ }
+ {
+ int p1[] = {1};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 * poly2, result);
+ BOOST_CHECK_EQUAL(poly2 * poly1, result);
+ }
+ {
+ int p1[] = {1};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {-2391};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {-2391};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 * poly2, result);
+ BOOST_CHECK_EQUAL(poly2 * poly1, result);
+ }
+ {
+ int p1[] = {0, 1};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {0, 1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0, 0, 1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 * poly2, result);
+ BOOST_CHECK_EQUAL(poly2 * poly1, result);
+ }
+ {
+ int p1[] = {1, 1};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {1, 1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {1, 2, 1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 * poly2, result);
+ BOOST_CHECK_EQUAL(poly2 * poly1, result);
+ }
+ {
+ int p1[] = {1, 1};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {-1, 1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {-1, 0, 1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 * poly2, result);
+ BOOST_CHECK_EQUAL(poly2 * poly1, result);
+ }
+ {
+ int p1[] = {-1, 1};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {-1, 1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {1, -2, 1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 * poly2, result);
+ BOOST_CHECK_EQUAL(poly2 * poly1, result);
+ }
+ {
+ int p1[] = {0, 0, 0, 0, 0, 1};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {0, 0, 0, 0, 0, -29};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -29};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 * poly2, result);
+ BOOST_CHECK_EQUAL(poly2 * poly1, result);
+ }
+ {
+ int p1[] = {1, 1, 1, 1, 1, 1, 1};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {1, 1, 1, 1, 1, 1, 1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 * poly2, result);
+ BOOST_CHECK_EQUAL(poly2 * poly1, result);
+ }
+ {
+ int p1[] = {34, -12, 10, 0, 3, -8, 0, -2};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {-2, 44, 0, -1, 8, 31, -21, 50};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {-68, 1520, -548, 406, 278, 1096, -1358, 2263, -866, 529, -309, 302, -462, 42, -100};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 * poly2, result);
+ BOOST_CHECK_EQUAL(poly2 * poly1, result);
+ }
+
+ // different degrees:
+ {
+ int p1[] = {0};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {3, 4, 5, 6, 7, 8, 9};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 * poly2, result);
+ BOOST_CHECK_EQUAL(poly2 * poly1, result);
+ }
+ {
+ int p1[] = {1};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {403, 0, -289455, -8772};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {403, 0, -289455, -8772};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 * poly2, result);
+ BOOST_CHECK_EQUAL(poly2 * poly1, result);
+ }
+ {
+ int p1[] = {-2};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {12, -201, 0, 44, -1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {-24, 402, 0, -88, 2};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 * poly2, result);
+ BOOST_CHECK_EQUAL(poly2 * poly1, result);
+ }
+ {
+ int p1[] = {-14, 7, 1};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {47, -7, 45, -113, 2};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {-658, 427, -632, 1890, -774, -99, 2};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 * poly2, result);
+ BOOST_CHECK_EQUAL(poly2 * poly1, result);
+ }
+ {
+ int p1[] = {-23, -41, -19, -89, -43, -55, -94, -29, -12, -42, -66, -49};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {-71, -10, -59, -44, -78, -64, -39, -21, -41, -84, -74, -38, -20, -99, -46, -32, -10, -27};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {1633, 3141, 3116, 9940, 8662, 15092, 18680, 18376, 20703, 23474, 27413, 27624, 26508, 29216, 31604, 31008, 30653, 22835, 22701, 26312, 22624, 14215, 11245, 12658, 10134, 5110, 3362, 2272, 1323};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 * poly2, result);
+ BOOST_CHECK_EQUAL(poly2 * poly1, result);
+ }
+
+ // polynomial vs value
+ {
+ int p[] = {0};
+ boost::math::tools::polynomial<int> poly(p, ARRAY_SIZE(p));
+ int val = 0;
+ int res[] = {0};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly * val, result);
+ BOOST_CHECK_EQUAL(val * poly, result);
+ }
+ {
+ int p[] = {5};
+ boost::math::tools::polynomial<int> poly(p, ARRAY_SIZE(p));
+ int val = 0;
+ int res[] = {0};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly * val, result);
+ BOOST_CHECK_EQUAL(val * poly, result);
+ }
+ {
+ int p[] = {8};
+ boost::math::tools::polynomial<int> poly(p, ARRAY_SIZE(p));
+ int val = -7;
+ int res[] = {-56};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly * val, result);
+ BOOST_CHECK_EQUAL(val * poly, result);
+ }
+ {
+ int p[] = {113, 48347, -3494278, 0, 382, 0, -37273, 219};
+ boost::math::tools::polynomial<int> poly(p, ARRAY_SIZE(p));
+ int val = 301;
+ int res[] = {34013, 14552447, -1051777678, 0, 114982, 0, -11219173, 65919};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly * val, result);
+ BOOST_CHECK_EQUAL(val * poly, result);
+ }
+}
+
+void test_division() {
+ // some simple tests...
+ {
+ int p1[] = {1, 2, 3};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {1, 2, 3};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 / poly2, result);
+ }
+ {
+ int p1[] = {1, 2, 3};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {-1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {-1, -2, -3};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 / poly2, result);
+ }
+ {
+ int p1[] = {7, -21, 70, -14, 0, -42, 0, 7};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {7};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {1, -3, 10, -2, 0, -6, 0, 1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 / poly2, result);
+ }
+ {
+ int p1[] = {0, 0, 1};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {0, 1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0, 1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 / poly2, result);
+ }
+ {
+ int p1[] = {265, -45827, 2384, 0, 249, -4, 2838, 29, -652344, 237, 572, -238157, 238, -12487, 234789, -21347};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {265, -45827, 2384, 0, 249, -4, 2838, 29, -652344, 237, 572, -238157, 238, -12487, 234789, -21347};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 / poly2, result);
+ }
+ {
+ int p1[] = {1};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {0, 1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 / poly2, result);
+ }
+ {
+ int p1[] = {-2, 4, 0, 2};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {-1, 2, 0, 1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {2};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 / poly2, result);
+ }
+ {
+ int p1[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 / poly2, result);
+ }
+ {
+ int p1[] = {0, 0, 0, 0, -48, 1, -49, 999, 3791};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {0, 0, 0, 1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0, -48, 1, -49, 999, 3791};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 / poly2, result);
+ }
+ {
+ int p1[] = {0, 0, 0, 0, -48, 1, -49, 999, 3791};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {0, -48, 1, -49, 999, 3791};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0, 0, 0, 1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 / poly2, result);
+ }
+ {
+ int p1[] = {1, 2, 1};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {1, 1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {1, 1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 / poly2, result);
+ }
+ {
+ int p1[] = {-1, 0, 1};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {1, 1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {-1, 1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 / poly2, result);
+ }
+ // ...and some harder...
+ {
+ int p1[] = {4, 13, 28, 27, 18};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {1, 2, 3};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {4, 5, 6};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 / poly2, result);
+ }
+ {
+ int p1[] = {4, 13, 28, 27, 18};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {4, 5, 6};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {1, 2, 3};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 / poly2, result);
+ }
+ {
+ int p1[] = {5, 0, -10, -10, 5, 10, 0, 0, 5, 0, -10, -10, 5, 10, 5, 0, -5, -10, -5, 0, 5, 10, 5, 0, -5, -10, -5, 0, 5, 10, 5, -10, -10, 0, 5, 0, 0, 10, 5, -10, -10, 0, 5};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {5, 0, -5, 0, 5, 0, -5, 0, 5, 0, -5, 0, 5};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {1, 0, -1, -2, -1, 0, 1, 2, 1, 0, -1, -2, -1, 0, 1, 2, 1, 0, -1, -2, -1, 0, 1, 2, 1, 0, -1, -2, -1, 0, 1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 / poly2, result);
+ }
+ {
+ int p1[] = {5, 0, -10, -10, 5, 10, 0, 0, 5, 0, -10, -10, 5, 10, 5, 0, -5, -10, -5, 0, 5, 10, 5, 0, -5, -10, -5, 0, 5, 10, 5, -10, -10, 0, 5, 0, 0, 10, 5, -10, -10, 0, 5};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {1, 0, -1, -2, -1, 0, 1, 2, 1, 0, -1, -2, -1, 0, 1, 2, 1, 0, -1, -2, -1, 0, 1, 2, 1, 0, -1, -2, -1, 0, 1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {5, 0, -5, 0, 5, 0, -5, 0, 5, 0, -5, 0, 5};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 / poly2, result);
+ }
+ {
+ int p1[] = {0, 43, -53, 43, 20677, -36639, 15298, -14821, -198396, 592951, -296514, 3468169, -2050653, 312406, -2318916, 656030, 1764};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {0, 1, 0, 1, 482, -247, 28, -342, 98};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {43, -53, 0, 4, -472, 999, -87, 6757, 18};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 / poly2, result);
+ }
+ {
+ int p1[] = {0, 43, -53, 43, 20677, -36639, 15298, -14821, -198396, 592951, -296514, 3468169, -2050653, 312406, -2318916, 656030, 1764};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {43, -53, 0, 4, -472, 999, -87, 6757, 18};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0, 1, 0, 1, 482, -247, 28, -342, 98};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 / poly2, result);
+ }
+ // ...and now with rest (which is lost)
+ {
+ int p1[] = {3, 53, -11, 0, 49, 11};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {0, 0, 1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {-11, 0, 49, 11};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 / poly2, result);
+ }
+ {
+ int p1[] = {2, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {1, 0, 0, 0, 0, 0, 0, 0, 1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {1, 0, 0, 0, 1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 / poly2, result);
+ }
+ {
+ int p1[] = {1625, -940, -275, 734, 6942, -240, -4502, 188};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {14, -7, 0, 5, 94};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {74, 0, -48, 2};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 / poly2, result);
+ }
+ {
+ int p1[] = {0, -432, 1983, 14, 3252, -9085, 1431, -5055, 9609, -2421, 2710, 2708, 1015, -4503};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {48, -23, 0, -98, 37, -1, 0, 29, 57};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0, -9, 37, 18, 58, -79};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 / poly2, result);
+ }
+}
+
+void test_modulo() {
+ // rest = 0:
+ {
+ int p1[] = {0, 8};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {0, 4};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 % poly2, result);
+ }
+ {
+ int p1[] = {1, 2, 1};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {1, 1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 % poly2, result);
+ }
+ {
+ int p1[] = {-1, 0, 1};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {1, 1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 % poly2, result);
+ }
+ {
+ int p1[] = {-1, 0, 1};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {-1, 1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 % poly2, result);
+ }
+ {
+ int p1[] = {4, 0, -12, 6, -2};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {-2, 0, 6, -3, 1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 % poly2, result);
+ }
+ {
+ int p1[] = {4, 13, 28, 27, 18};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {1, 2, 3};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 % poly2, result);
+ }
+ {
+ int p1[] = {4, 13, 28, 27, 18};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {4, 5, 6};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 % poly2, result);
+ }
+ {
+ int p1[] = {0, 0, 0, 0, -48, 1, -49, 999, 3791};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {0, 0, 0, 1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 % poly2, result);
+ }
+ {
+ int p1[] = {0, 0, 0, 0, -48, 1, -49, 999, 3791};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {0, -48, 1, -49, 999, 3791};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 % poly2, result);
+ }
+ {
+ int p1[] = {0, 43, -53, 43, 20677, -36639, 15298, -14821, -198396, 592951, -296514, 3468169, -2050653, 312406, -2318916, 656030, 1764};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {43, -53, 0, 4, -472, 999, -87, 6757, 18};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 % poly2, result);
+ }
+ {
+ int p1[] = {0, 43, -53, 43, 20677, -36639, 15298, -14821, -198396, 592951, -296514, 3468169, -2050653, 312406, -2318916, 656030, 1764};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {0, 1, 0, 1, 482, -247, 28, -342, 98};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 % poly2, result);
+ }
+ // rest != 0:
+ {
+ int p1[] = {1};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {0, 1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 % poly2, result);
+ }
+ {
+ int p1[] = {1, 2, 3, 4, 5, 6, 7};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {1, 2, 3, 4, 5, 6, 7, 8};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {1, 2, 3, 4, 5, 6, 7};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 % poly2, result);
+ }
+ {
+ int p1[] = {2, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {1, 0, 0, 0, 1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {1, 0, 0, 1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 % poly2, result);
+ }
+ {
+ int p1[] = {1625, -940, -275, 734, 6942, -240, -4502, 188};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {14, -7, 0, 5, 94};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {589, -422, 397};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 % poly2, result);
+ }
+ {
+ int p1[] = {0, -432, 1983, 14, 3252, -9085, 1431, -5055, 9609, -2421, 2710, 2708, 1015, -4503};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {0, -9, 37, 18, 58, -79};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0, 0, 0, 1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(poly1 % poly2, result);
+ }
+}
+
+void test_gcd() {
+ {
+ int p1[] = {1};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(gcd(poly1, poly2), result);
+ BOOST_CHECK_EQUAL(gcd(poly2, poly1), result);
+ }
+ {
+ int p1[] = {47};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {94};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {47};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(gcd(poly1, poly2), result);
+ BOOST_CHECK_EQUAL(gcd(poly2, poly1), result);
+ }
+ {
+ int p1[] = {0, 1};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {0, 1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0, 1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(gcd(poly1, poly2), result);
+ BOOST_CHECK_EQUAL(gcd(poly2, poly1), result);
+ }
+ {
+ int p1[] = {0, 4};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {0, -8};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0, 4};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(gcd(poly1, poly2), result);
+ BOOST_CHECK_EQUAL(gcd(poly2, poly1), result);
+ }
+ {
+ int p1[] = {0, -4};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {0, 8};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0, 4};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(gcd(poly1, poly2), result);
+ BOOST_CHECK_EQUAL(gcd(poly2, poly1), result);
+ }
+ {
+ int p1[] = {0, -4};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {0, -8};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0, 4};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(gcd(poly1, poly2), result);
+ BOOST_CHECK_EQUAL(gcd(poly2, poly1), result);
+ }
+ {
+ int p1[] = {0, 0, 0, 1};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {0, 0, 1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0, 0, 1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(gcd(poly1, poly2), result);
+ BOOST_CHECK_EQUAL(gcd(poly2, poly1), result);
+ }
+ {
+ int p1[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -4};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, -11, 5, -23, 7, 9, -1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(gcd(poly1, poly2), result);
+ BOOST_CHECK_EQUAL(gcd(poly2, poly1), result);
+ }
+ {
+ int p1[] = {-5, 2, 8, -3, -3, 0, 1, 0, 1};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {21, -9, -4, 0, 5, 0, 3};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(gcd(poly1, poly2), result);
+ BOOST_CHECK_EQUAL(gcd(poly2, poly1), result);
+ poly1 *= 3;
+ poly2 *= 3;
+ result *= 3;
+ BOOST_CHECK_EQUAL(gcd(poly1, poly2), result);
+ BOOST_CHECK_EQUAL(gcd(poly2, poly1), result);
+ }
+ {
+ int p1[] = {7, -10, 10, -11, 18, -7, -27, 10, 0, 4};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {-70, 30, 0, 3, 3, 0, 1};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int res[] = {-7, 3, 0, 1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+ BOOST_CHECK_EQUAL(gcd(poly1, poly2), result);
+ BOOST_CHECK_EQUAL(gcd(poly2, poly1), result);
+ poly1 *= -37;
+ poly2 *= -37;
+ result *= 37;
+ BOOST_CHECK_EQUAL(gcd(poly1, poly2), result);
+ BOOST_CHECK_EQUAL(gcd(poly2, poly1), result);
+ }
+}
+
+int test_main(int argc, char* argv[]) {
+ test_plus();
+ test_minus();
+ test_addition();
+ test_substraction();
+ test_multiplication();
+ test_division();
+ test_modulo();
+ test_gcd();
+ return 0;
+}
+

Added: sandbox/SOC/2008/polynomial/libs/test/test_comparisons.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2008/polynomial/libs/test/test_comparisons.cpp 2008-08-20 09:28:43 EDT (Wed, 20 Aug 2008)
@@ -0,0 +1,117 @@
+#define BOOST_DISABLE_WIN32
+
+#include <iterator>
+#include <vector>
+#include <boost/test/included/test_exec_monitor.hpp>
+#include "../../boost/polynomial.hpp"
+
+#define ARRAY_SIZE(array) sizeof(array) / sizeof(array[0])
+
+template<typename T>
+struct test_entry {
+ boost::math::tools::polynomial<T> poly1;
+ boost::math::tools::polynomial<T> poly2;
+ bool equal;
+ test_entry(boost::math::tools::polynomial<T>& p1, boost::math::tools::polynomial<T>& p2, bool eq) {
+ poly1 = p1;
+ poly2 = p2;
+ equal = eq;
+ }
+};
+
+template<typename T>
+void test_different_degrees() {
+ std::vector<test_entry<T> > tests;
+
+ T p1[] = {T(4.0)};
+ boost::math::tools::polynomial<T> poly1(p1, ARRAY_SIZE(p1));
+ T p2[] = {T(3.1), T(2.4)};
+ boost::math::tools::polynomial<T> poly2(p2, ARRAY_SIZE(p2));
+ T p3[] = {T(2.7), T(-12.4), T(4.0)};
+ boost::math::tools::polynomial<T> poly3(p3, ARRAY_SIZE(p3));
+ T p4[] = {T(-11.1), T(-2.0), T(-0.1), T(9.7)};
+ boost::math::tools::polynomial<T> poly4(p4, ARRAY_SIZE(p4));
+ T p5[] = {T(45.2), T(-8.6), T(-5.9), T(3.2), T(-2.1)};
+ boost::math::tools::polynomial<T> poly5(p5, ARRAY_SIZE(p5));
+ T p6[] = {T(45.2), T(-8.6), T(-5.9), T(3.2), T(-2.1), T(10.0)};
+ boost::math::tools::polynomial<T> poly6(p6, ARRAY_SIZE(p6));
+ tests.push_back(test_entry<T>(poly1, poly1, true));
+ tests.push_back(test_entry<T>(poly1, poly2, false));
+ tests.push_back(test_entry<T>(poly1, poly3, false));
+ tests.push_back(test_entry<T>(poly1, poly4, false));
+ tests.push_back(test_entry<T>(poly1, poly5, false));
+ tests.push_back(test_entry<T>(poly1, poly6, false));
+ tests.push_back(test_entry<T>(poly2, poly2, true));
+ tests.push_back(test_entry<T>(poly2, poly3, false));
+ tests.push_back(test_entry<T>(poly2, poly4, false));
+ tests.push_back(test_entry<T>(poly2, poly5, false));
+ tests.push_back(test_entry<T>(poly2, poly6, false));
+ tests.push_back(test_entry<T>(poly3, poly3, true));
+ tests.push_back(test_entry<T>(poly3, poly4, false));
+ tests.push_back(test_entry<T>(poly3, poly5, false));
+ tests.push_back(test_entry<T>(poly3, poly6, false));
+ tests.push_back(test_entry<T>(poly4, poly4, true));
+ tests.push_back(test_entry<T>(poly4, poly5, false));
+ tests.push_back(test_entry<T>(poly4, poly6, false));
+ tests.push_back(test_entry<T>(poly5, poly5, true));
+ tests.push_back(test_entry<T>(poly5, poly6, false));
+ tests.push_back(test_entry<T>(poly6, poly6, true));
+
+ for(typename std::vector<test_entry<T> >::iterator it = tests.begin(); it != tests.end(); ++it) {
+ BOOST_CHECK_EQUAL(it->poly1 == it->poly2, !(it->poly1 != it->poly2));
+ BOOST_CHECK_EQUAL(it->poly1 == it->poly2, it->equal);
+ }
+}
+
+template<typename T>
+void test_same_degrees() {
+ std::vector<test_entry<T> > tests;
+
+ T p1[] = {T(4.0), T(3.1), T(-2.2), T(-8.8), T(2.0), T(-9.9)};
+ boost::math::tools::polynomial<T> poly1(p1, ARRAY_SIZE(p1));
+ T p2[] = {T(3.1), T(2.4), T(-9.9), T(0.0), T(3.0), T(12.1)};
+ boost::math::tools::polynomial<T> poly2(p2, ARRAY_SIZE(p2));
+ T p3[] = {T(2.7), T(-12.4), T(4.0), T(0.0), T(-12.2), T(-8.5)};
+ boost::math::tools::polynomial<T> poly3(p3, ARRAY_SIZE(p3));
+ T p4[] = {T(-11.1), T(-2.0), T(-0.1), T(9.7), T(-4.2), T(-1.0)};
+ boost::math::tools::polynomial<T> poly4(p4, ARRAY_SIZE(p4));
+ T p5[] = {T(45.2), T(-8.6), T(-5.9), T(3.2), T(-2.1), T(4.7)};
+ boost::math::tools::polynomial<T> poly5(p5, ARRAY_SIZE(p5));
+ T p6[] = {T(45.2), T(-8.6), T(-5.9), T(3.2), T(-2.1), T(10.0)};
+ boost::math::tools::polynomial<T> poly6(p6, ARRAY_SIZE(p6));
+ tests.push_back(test_entry<T>(poly1, poly1, true));
+ tests.push_back(test_entry<T>(poly1, poly2, false));
+ tests.push_back(test_entry<T>(poly1, poly3, false));
+ tests.push_back(test_entry<T>(poly1, poly4, false));
+ tests.push_back(test_entry<T>(poly1, poly5, false));
+ tests.push_back(test_entry<T>(poly1, poly6, false));
+ tests.push_back(test_entry<T>(poly2, poly2, true));
+ tests.push_back(test_entry<T>(poly2, poly3, false));
+ tests.push_back(test_entry<T>(poly2, poly4, false));
+ tests.push_back(test_entry<T>(poly2, poly5, false));
+ tests.push_back(test_entry<T>(poly2, poly6, false));
+ tests.push_back(test_entry<T>(poly3, poly3, true));
+ tests.push_back(test_entry<T>(poly3, poly4, false));
+ tests.push_back(test_entry<T>(poly3, poly5, false));
+ tests.push_back(test_entry<T>(poly3, poly6, false));
+ tests.push_back(test_entry<T>(poly4, poly4, true));
+ tests.push_back(test_entry<T>(poly4, poly5, false));
+ tests.push_back(test_entry<T>(poly4, poly6, false));
+ tests.push_back(test_entry<T>(poly5, poly5, true));
+ tests.push_back(test_entry<T>(poly5, poly6, false));
+ tests.push_back(test_entry<T>(poly6, poly6, true));
+
+ for(typename std::vector<test_entry<T> >::iterator it = tests.begin(); it != tests.end(); ++it) {
+ BOOST_CHECK_EQUAL(it->poly1 == it->poly2, !(it->poly1 != it->poly2));
+ BOOST_CHECK_EQUAL(it->poly1 == it->poly2, it->equal);
+ }
+}
+
+int test_main(int argc, char* argv[]) {
+ test_different_degrees<int>();
+ test_different_degrees<double>();
+ test_same_degrees<int>();
+ test_same_degrees<double>();
+ return 0;
+}
+

Added: sandbox/SOC/2008/polynomial/libs/test/test_creating.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2008/polynomial/libs/test/test_creating.cpp 2008-08-20 09:28:43 EDT (Wed, 20 Aug 2008)
@@ -0,0 +1,191 @@
+#define BOOST_DISABLE_WIN32
+
+#include <vector>
+#include <boost/test/included/test_exec_monitor.hpp>
+#include "../../boost/polynomial.hpp"
+
+#define ARRAY_SIZE(array) sizeof(array) / sizeof(array[0])
+
+void test_constructors() {
+ // zero:
+ {
+ // default:
+ boost::math::tools::polynomial<int> poly1;
+ // iterator + size:
+ int p2[] = {0};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ int p3[] = {0, 0};
+ boost::math::tools::polynomial<int> poly3(p3, ARRAY_SIZE(p3));
+ int p4[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
+ boost::math::tools::polynomial<int> poly4(p4, ARRAY_SIZE(p4));
+ boost::math::tools::polynomial<int> poly5(p4, 0); // strage but works
+ // two iterators:
+ int p6[] = {0, 0, 0, 0, 0, 0};
+ boost::math::tools::polynomial<int> poly6(p6, p6 + ARRAY_SIZE(p6));
+ boost::math::tools::polynomial<int> poly7(p6, p6); // strange but works
+ // value:
+ boost::math::tools::polynomial<int> poly8(0);
+ // std::vector:
+ std::vector<int> p9;
+ boost::math::tools::polynomial<int> poly9(p9);
+ std::vector<int> p10(1);
+ boost::math::tools::polynomial<int> poly10(p10);
+ std::vector<int> p11(47);
+ boost::math::tools::polynomial<int> poly11(p11);
+ // copy:
+ boost::math::tools::polynomial<int> poly12(poly1);
+
+ BOOST_CHECK_EQUAL(poly1, poly2);
+ BOOST_CHECK_EQUAL(poly2, poly3);
+ BOOST_CHECK_EQUAL(poly3, poly4);
+ BOOST_CHECK_EQUAL(poly4, poly5);
+ BOOST_CHECK_EQUAL(poly5, poly6);
+ BOOST_CHECK_EQUAL(poly6, poly7);
+ BOOST_CHECK_EQUAL(poly7, poly8);
+ BOOST_CHECK_EQUAL(poly8, poly9);
+ BOOST_CHECK_EQUAL(poly9, poly10);
+ BOOST_CHECK_EQUAL(poly10, poly11);
+ BOOST_CHECK_EQUAL(poly11, poly12);
+ }
+
+ // normalizing leading zeros:
+ {
+ int p1[] = {4, 3, 2, 1};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {4, 3, 2, 1, 0};
+ boost::math::tools::polynomial<int> poly2(p2, p2 + ARRAY_SIZE(p2)); // two iterators
+ int p3[] = {4, 3, 2, 1, 0, 0, 0, 0, 0};
+ boost::math::tools::polynomial<int> poly3(p3, ARRAY_SIZE(p3)); // iterator + size
+
+ BOOST_CHECK_EQUAL(poly1, poly2);
+ BOOST_CHECK_EQUAL(poly2, poly3);
+ }
+ {
+ int p1[] = {47};
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ int p2[] = {47, 0, 0, 0, 0, 0, 0, 0};
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ boost::math::tools::polynomial<int> poly3(47);
+
+ BOOST_CHECK_EQUAL(poly1, poly2);
+ BOOST_CHECK_EQUAL(poly2, poly3);
+ }
+}
+
+void test_interpolation() {
+ {
+ int x[] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
+ int y[] = {9, 45, 1013, 14757, 116505, 610349, 2418645, 7846533, 21913097};
+ // w(0) = 9, w(1) = 45 etc.
+ int res[] = {9, 8, 7, 6, 5, 4, 3, 2, 1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+
+ // constructor:
+ boost::math::tools::polynomial<int> poly1(x, x + ARRAY_SIZE(x), y);
+ BOOST_CHECK_EQUAL(poly1, result);
+
+ // nested function:
+ boost::math::tools::polynomial<int> poly2; // default now
+ poly2.interpolate(x, x + ARRAY_SIZE(x), y);
+ BOOST_CHECK_EQUAL(poly2, result);
+ }
+ {
+ int x[] = {-4, -3, -2, -1, 0, 1, 2, 3, 4};
+ int y[] = {65536, 6561, 256, 1, 0, 1, 256, 6561, 65536};
+ // w(-4) = 65536, w(-3) = 6561 etc.
+ int res[] = {0, 0, 0, 0, 0, 0, 0, 0, 1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+
+ // constructor:
+ boost::math::tools::polynomial<int> poly1(x, x + ARRAY_SIZE(x), y);
+ BOOST_CHECK_EQUAL(poly1, result);
+
+ // nested function:
+ boost::math::tools::polynomial<int> poly2; // default now
+ poly2.interpolate(x, x + ARRAY_SIZE(x), y);
+ BOOST_CHECK_EQUAL(poly2, result);
+ }
+ {
+ int x[] = {5, -7, -6, 0};
+ int y[] = {1, -23, -54, -954};
+ // w(5) = 1, w(-7) = -23 etc.
+ int res[] = {-954, -84, 35, 4};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+
+ // constructor:
+ boost::math::tools::polynomial<int> poly1(x, x + ARRAY_SIZE(x), y);
+ BOOST_CHECK_EQUAL(poly1, result);
+
+ // nested function:
+ boost::math::tools::polynomial<int> poly2; // default now
+ poly2.interpolate(x, x + ARRAY_SIZE(x), y);
+ BOOST_CHECK_EQUAL(poly2, result);
+ }
+ {
+ int x[] = {45, -113, 0, 4, -58, 1, 98, 47723, -3, -243854, 238, 99, -4949};
+ int y[] = {45, -113, 0, 4, -58, 1, 98, 47723, -3, -243854, 238, 99, -4949};
+ int res[] = {0, 1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+
+ // constructor:
+ boost::math::tools::polynomial<int> poly1(x, x + ARRAY_SIZE(x), y);
+ BOOST_CHECK_EQUAL(poly1, result);
+
+ // nested function:
+ boost::math::tools::polynomial<int> poly2; // default now
+ poly2.interpolate(x, x + ARRAY_SIZE(x), y);
+ BOOST_CHECK_EQUAL(poly2, result);
+ }
+ {
+ int x[] = {8, -15, 49, 112, -88, 1, 539, -449};
+ int y[] = {0, 0, 0, 0, 0, 0, 0, 0};
+ int res[] = {0};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+
+ // constructor:
+ boost::math::tools::polynomial<int> poly1(x, x + ARRAY_SIZE(x), y);
+ BOOST_CHECK_EQUAL(poly1, result);
+
+ // nested function:
+ boost::math::tools::polynomial<int> poly2; // default now
+ poly2.interpolate(x, x + ARRAY_SIZE(x), y);
+ BOOST_CHECK_EQUAL(poly2, result);
+ }
+ {
+ int x[] = {8, -15, 49, 112, -88, 1, 539, -449};
+ int y[] = {5, 5, 5, 5, 5, 5, 5, 5};
+ int res[] = {5};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+
+ // constructor:
+ boost::math::tools::polynomial<int> poly1(x, x + ARRAY_SIZE(x), y);
+ BOOST_CHECK_EQUAL(poly1, result);
+
+ // nested function:
+ boost::math::tools::polynomial<int> poly2; // default now
+ poly2.interpolate(x, x + ARRAY_SIZE(x), y);
+ BOOST_CHECK_EQUAL(poly2, result);
+ }
+ {
+ int x[] = {0, -1, 1, -2, 2, -3, 3};
+ int y[] = {1, 4, 4, 85, 85, 820, 820};
+ int res[] = {1, 0, 1, 0, 1, 0, 1};
+ boost::math::tools::polynomial<int> result(res, ARRAY_SIZE(res));
+
+ // constructor:
+ boost::math::tools::polynomial<int> poly1(x, x + ARRAY_SIZE(x), y);
+ BOOST_CHECK_EQUAL(poly1, result);
+
+ // nested function:
+ boost::math::tools::polynomial<int> poly2; // default now
+ poly2.interpolate(x, x + ARRAY_SIZE(x), y);
+ BOOST_CHECK_EQUAL(poly2, result);
+ }
+}
+
+int test_main(int argc, char* argv[]) {
+ test_constructors();
+ test_interpolation();
+ return 0;
+}
+

Added: sandbox/SOC/2008/polynomial/libs/test/test_derivatives.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2008/polynomial/libs/test/test_derivatives.cpp 2008-08-20 09:28:43 EDT (Wed, 20 Aug 2008)
@@ -0,0 +1,177 @@
+#define BOOST_DISABLE_WIN32
+
+#include <boost/test/included/test_exec_monitor.hpp>
+#include "../../boost/polynomial.hpp"
+
+#define ARRAY_SIZE(array) sizeof(array) / sizeof(array[0])
+
+void test() {
+ {
+ int p1[] = {0};
+ int p2[] = {0};
+
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+
+ BOOST_CHECK_EQUAL(poly1.derivative(), poly2);
+ }
+ {
+ int p1[] = {0, 0, 0, 0, 0, 0, 0, 1};
+ int p2[] = {0, 0, 0, 0, 0, 0, 7};
+ int p3[] = {0, 0, 0, 0, 0, 42};
+ int p4[] = {0, 0, 0, 0, 210};
+ int p5[] = {0, 0, 0, 840};
+ int p6[] = {0, 0, 2520};
+ int p7[] = {0, 5040};
+ int p8[] = {5040};
+ int p9[] = {0};
+
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ boost::math::tools::polynomial<int> poly3(p3, ARRAY_SIZE(p3));
+ boost::math::tools::polynomial<int> poly4(p4, ARRAY_SIZE(p4));
+ boost::math::tools::polynomial<int> poly5(p5, ARRAY_SIZE(p5));
+ boost::math::tools::polynomial<int> poly6(p6, ARRAY_SIZE(p6));
+ boost::math::tools::polynomial<int> poly7(p7, ARRAY_SIZE(p7));
+ boost::math::tools::polynomial<int> poly8(p8, ARRAY_SIZE(p8));
+ boost::math::tools::polynomial<int> poly9(p9, ARRAY_SIZE(p9));
+
+ BOOST_CHECK_EQUAL(poly1.derivative(), poly2);
+ BOOST_CHECK_EQUAL(poly2.derivative(), poly3);
+ BOOST_CHECK_EQUAL(poly3.derivative(), poly4);
+ BOOST_CHECK_EQUAL(poly4.derivative(), poly5);
+ BOOST_CHECK_EQUAL(poly5.derivative(), poly6);
+ BOOST_CHECK_EQUAL(poly6.derivative(), poly7);
+ BOOST_CHECK_EQUAL(poly7.derivative(), poly8);
+ BOOST_CHECK_EQUAL(poly8.derivative(), poly9);
+ }
+ {
+ int p1[] = {0, 0, 0, 0, 0, 0, 0, -1};
+ int p2[] = {0, 0, 0, 0, 0, 0, -7};
+ int p3[] = {0, 0, 0, 0, 0, -42};
+ int p4[] = {0, 0, 0, 0, -210};
+ int p5[] = {0, 0, 0, -840};
+ int p6[] = {0, 0, -2520};
+ int p7[] = {0, -5040};
+ int p8[] = {-5040};
+ int p9[] = {0};
+
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ boost::math::tools::polynomial<int> poly3(p3, ARRAY_SIZE(p3));
+ boost::math::tools::polynomial<int> poly4(p4, ARRAY_SIZE(p4));
+ boost::math::tools::polynomial<int> poly5(p5, ARRAY_SIZE(p5));
+ boost::math::tools::polynomial<int> poly6(p6, ARRAY_SIZE(p6));
+ boost::math::tools::polynomial<int> poly7(p7, ARRAY_SIZE(p7));
+ boost::math::tools::polynomial<int> poly8(p8, ARRAY_SIZE(p8));
+ boost::math::tools::polynomial<int> poly9(p9, ARRAY_SIZE(p9));
+
+ BOOST_CHECK_EQUAL(poly1.derivative(), poly2);
+ BOOST_CHECK_EQUAL(poly2.derivative(), poly3);
+ BOOST_CHECK_EQUAL(poly3.derivative(), poly4);
+ BOOST_CHECK_EQUAL(poly4.derivative(), poly5);
+ BOOST_CHECK_EQUAL(poly5.derivative(), poly6);
+ BOOST_CHECK_EQUAL(poly6.derivative(), poly7);
+ BOOST_CHECK_EQUAL(poly7.derivative(), poly8);
+ BOOST_CHECK_EQUAL(poly8.derivative(), poly9);
+ }
+ {
+ int p1[] = {1, 1, 1, 1, 1, 1, 1, 1};
+ int p2[] = {1, 2, 3, 4, 5, 6, 7};
+ int p3[] = {2, 6, 12, 20, 30, 42};
+ int p4[] = {6, 24, 60, 120, 210};
+ int p5[] = {24, 120, 360, 840};
+ int p6[] = {120, 720, 2520};
+ int p7[] = {720, 5040};
+ int p8[] = {5040};
+ int p9[] = {0};
+
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ boost::math::tools::polynomial<int> poly3(p3, ARRAY_SIZE(p3));
+ boost::math::tools::polynomial<int> poly4(p4, ARRAY_SIZE(p4));
+ boost::math::tools::polynomial<int> poly5(p5, ARRAY_SIZE(p5));
+ boost::math::tools::polynomial<int> poly6(p6, ARRAY_SIZE(p6));
+ boost::math::tools::polynomial<int> poly7(p7, ARRAY_SIZE(p7));
+ boost::math::tools::polynomial<int> poly8(p8, ARRAY_SIZE(p8));
+ boost::math::tools::polynomial<int> poly9(p9, ARRAY_SIZE(p9));
+
+ BOOST_CHECK_EQUAL(poly1.derivative(), poly2);
+ BOOST_CHECK_EQUAL(poly2.derivative(), poly3);
+ BOOST_CHECK_EQUAL(poly3.derivative(), poly4);
+ BOOST_CHECK_EQUAL(poly4.derivative(), poly5);
+ BOOST_CHECK_EQUAL(poly5.derivative(), poly6);
+ BOOST_CHECK_EQUAL(poly6.derivative(), poly7);
+ BOOST_CHECK_EQUAL(poly7.derivative(), poly8);
+ BOOST_CHECK_EQUAL(poly8.derivative(), poly9);
+ }
+ {
+ int p1[] = {-1, -1, -1, -1, -1, -1, -1, -1};
+ int p2[] = {-1, -2, -3, -4, -5, -6, -7};
+ int p3[] = {-2, -6, -12, -20, -30, -42};
+ int p4[] = {-6, -24, -60, -120, -210};
+ int p5[] = {-24, -120, -360, -840};
+ int p6[] = {-120, -720, -2520};
+ int p7[] = {-720, -5040};
+ int p8[] = {-5040};
+ int p9[] = {0};
+
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ boost::math::tools::polynomial<int> poly3(p3, ARRAY_SIZE(p3));
+ boost::math::tools::polynomial<int> poly4(p4, ARRAY_SIZE(p4));
+ boost::math::tools::polynomial<int> poly5(p5, ARRAY_SIZE(p5));
+ boost::math::tools::polynomial<int> poly6(p6, ARRAY_SIZE(p6));
+ boost::math::tools::polynomial<int> poly7(p7, ARRAY_SIZE(p7));
+ boost::math::tools::polynomial<int> poly8(p8, ARRAY_SIZE(p8));
+ boost::math::tools::polynomial<int> poly9(p9, ARRAY_SIZE(p9));
+
+ BOOST_CHECK_EQUAL(poly1.derivative(), poly2);
+ BOOST_CHECK_EQUAL(poly2.derivative(), poly3);
+ BOOST_CHECK_EQUAL(poly3.derivative(), poly4);
+ BOOST_CHECK_EQUAL(poly4.derivative(), poly5);
+ BOOST_CHECK_EQUAL(poly5.derivative(), poly6);
+ BOOST_CHECK_EQUAL(poly6.derivative(), poly7);
+ BOOST_CHECK_EQUAL(poly7.derivative(), poly8);
+ BOOST_CHECK_EQUAL(poly8.derivative(), poly9);
+ }
+ {
+ int p1[] = {655392, -80, 1, -213, 49, 0, -5, 0, 1};
+ int p2[] = {-80, 2, -639, 196, 0, -30, 0, 8};
+ int p3[] = {2, -1278, 588, 0, -150, 0, 56};
+ int p4[] = {-1278, 1176, 0, -600, 0, 336};
+ int p5[] = {1176, 0, -1800, 0, 1680};
+ int p6[] = {0, -3600, 0, 6720};
+ int p7[] = {-3600, 0, 20160};
+ int p8[] = {0, 40320};
+ int p9[] = {40320};
+ int p10[] = {0};
+
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ boost::math::tools::polynomial<int> poly3(p3, ARRAY_SIZE(p3));
+ boost::math::tools::polynomial<int> poly4(p4, ARRAY_SIZE(p4));
+ boost::math::tools::polynomial<int> poly5(p5, ARRAY_SIZE(p5));
+ boost::math::tools::polynomial<int> poly6(p6, ARRAY_SIZE(p6));
+ boost::math::tools::polynomial<int> poly7(p7, ARRAY_SIZE(p7));
+ boost::math::tools::polynomial<int> poly8(p8, ARRAY_SIZE(p8));
+ boost::math::tools::polynomial<int> poly9(p9, ARRAY_SIZE(p9));
+ boost::math::tools::polynomial<int> poly10(p10, ARRAY_SIZE(p10));
+
+ BOOST_CHECK_EQUAL(poly1.derivative(), poly2);
+ BOOST_CHECK_EQUAL(poly2.derivative(), poly3);
+ BOOST_CHECK_EQUAL(poly3.derivative(), poly4);
+ BOOST_CHECK_EQUAL(poly4.derivative(), poly5);
+ BOOST_CHECK_EQUAL(poly5.derivative(), poly6);
+ BOOST_CHECK_EQUAL(poly6.derivative(), poly7);
+ BOOST_CHECK_EQUAL(poly7.derivative(), poly8);
+ BOOST_CHECK_EQUAL(poly8.derivative(), poly9);
+ BOOST_CHECK_EQUAL(poly9.derivative(), poly10);
+ }
+}
+
+int test_main(int argc, char* argv[]) {
+ test();
+ return 0;
+}
+

Added: sandbox/SOC/2008/polynomial/libs/test/test_integrals.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2008/polynomial/libs/test/test_integrals.cpp 2008-08-20 09:28:43 EDT (Wed, 20 Aug 2008)
@@ -0,0 +1,200 @@
+#define BOOST_DISABLE_WIN32
+
+#include <boost/test/included/test_exec_monitor.hpp>
+#include "../../boost/polynomial.hpp"
+
+#define ARRAY_SIZE(array) sizeof(array) / sizeof(array[0])
+
+void test() {
+ // with default coefficient for x^0:
+ {
+ int p1[] = {0};
+ int p2[] = {0};
+
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+
+ BOOST_CHECK_EQUAL(poly1.integral(), poly2);
+ }
+ {
+ int p1[] = {5040};
+ int p2[] = {0, 5040};
+ int p3[] = {0, 0, 2520};
+ int p4[] = {0, 0, 0, 840};
+ int p5[] = {0, 0, 0, 0, 210};
+ int p6[] = {0, 0, 0, 0, 0, 42};
+ int p7[] = {0, 0, 0, 0, 0, 0, 7};
+ int p8[] = {0, 0, 0, 0, 0, 0, 0, 1};
+
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ boost::math::tools::polynomial<int> poly3(p3, ARRAY_SIZE(p3));
+ boost::math::tools::polynomial<int> poly4(p4, ARRAY_SIZE(p4));
+ boost::math::tools::polynomial<int> poly5(p5, ARRAY_SIZE(p5));
+ boost::math::tools::polynomial<int> poly6(p6, ARRAY_SIZE(p6));
+ boost::math::tools::polynomial<int> poly7(p7, ARRAY_SIZE(p7));
+ boost::math::tools::polynomial<int> poly8(p8, ARRAY_SIZE(p8));
+
+ BOOST_CHECK_EQUAL(poly1.integral(), poly2);
+ BOOST_CHECK_EQUAL(poly2.integral(), poly3);
+ BOOST_CHECK_EQUAL(poly3.integral(), poly4);
+ BOOST_CHECK_EQUAL(poly4.integral(), poly5);
+ BOOST_CHECK_EQUAL(poly5.integral(), poly6);
+ BOOST_CHECK_EQUAL(poly6.integral(), poly7);
+ BOOST_CHECK_EQUAL(poly7.integral(), poly8);
+ }
+ {
+ int p1[] = {-5040};
+ int p2[] = {0, -5040};
+ int p3[] = {0, 0, -2520};
+ int p4[] = {0, 0, 0, -840};
+ int p5[] = {0, 0, 0, 0, -210};
+ int p6[] = {0, 0, 0, 0, 0, -42};
+ int p7[] = {0, 0, 0, 0, 0, 0, -7};
+ int p8[] = {0, 0, 0, 0, 0, 0, 0, -1};
+
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ boost::math::tools::polynomial<int> poly3(p3, ARRAY_SIZE(p3));
+ boost::math::tools::polynomial<int> poly4(p4, ARRAY_SIZE(p4));
+ boost::math::tools::polynomial<int> poly5(p5, ARRAY_SIZE(p5));
+ boost::math::tools::polynomial<int> poly6(p6, ARRAY_SIZE(p6));
+ boost::math::tools::polynomial<int> poly7(p7, ARRAY_SIZE(p7));
+ boost::math::tools::polynomial<int> poly8(p8, ARRAY_SIZE(p8));
+
+ BOOST_CHECK_EQUAL(poly1.integral(), poly2);
+ BOOST_CHECK_EQUAL(poly2.integral(), poly3);
+ BOOST_CHECK_EQUAL(poly3.integral(), poly4);
+ BOOST_CHECK_EQUAL(poly4.integral(), poly5);
+ BOOST_CHECK_EQUAL(poly5.integral(), poly6);
+ BOOST_CHECK_EQUAL(poly6.integral(), poly7);
+ BOOST_CHECK_EQUAL(poly7.integral(), poly8);
+ }
+ // with some coefficients for x^0:
+ {
+ int p1[] = {0};
+ int p2[] = {0};
+
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+
+ BOOST_CHECK_EQUAL(poly1.integral(0), poly2);
+ }
+ {
+ int p1[] = {0};
+ int p2[] = {47};
+
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+
+ BOOST_CHECK_EQUAL(poly1.integral(47), poly2);
+ }
+ {
+ int p1[] = {0};
+ int p2[] = {-113};
+
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+
+ BOOST_CHECK_EQUAL(poly1.integral(-113), poly2);
+ }
+ {
+ int p1[] = {0};
+ int p2[] = {5040};
+ int p3[] = {720, 5040};
+ int p4[] = {120, 720, 2520};
+ int p5[] = {24, 120, 360, 840};
+ int p6[] = {6, 24, 60, 120, 210};
+ int p7[] = {2, 6, 12, 20, 30, 42};
+ int p8[] = {1, 2, 3, 4, 5, 6, 7};
+ int p9[] = {1, 1, 1, 1, 1, 1, 1, 1};
+
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ boost::math::tools::polynomial<int> poly3(p3, ARRAY_SIZE(p3));
+ boost::math::tools::polynomial<int> poly4(p4, ARRAY_SIZE(p4));
+ boost::math::tools::polynomial<int> poly5(p5, ARRAY_SIZE(p5));
+ boost::math::tools::polynomial<int> poly6(p6, ARRAY_SIZE(p6));
+ boost::math::tools::polynomial<int> poly7(p7, ARRAY_SIZE(p7));
+ boost::math::tools::polynomial<int> poly8(p8, ARRAY_SIZE(p8));
+ boost::math::tools::polynomial<int> poly9(p9, ARRAY_SIZE(p9));
+
+ BOOST_CHECK_EQUAL(poly1.integral(5040), poly2);
+ BOOST_CHECK_EQUAL(poly2.integral(720), poly3);
+ BOOST_CHECK_EQUAL(poly3.integral(120), poly4);
+ BOOST_CHECK_EQUAL(poly4.integral(24), poly5);
+ BOOST_CHECK_EQUAL(poly5.integral(6), poly6);
+ BOOST_CHECK_EQUAL(poly6.integral(2), poly7);
+ BOOST_CHECK_EQUAL(poly7.integral(1), poly8);
+ BOOST_CHECK_EQUAL(poly8.integral(1), poly9);
+ }
+ {
+ int p1[] = {0};
+ int p2[] = {-5040};
+ int p3[] = {-720, -5040};
+ int p4[] = {-120, -720, -2520};
+ int p5[] = {-24, -120, -360, -840};
+ int p6[] = {-6, -24, -60, -120, -210};
+ int p7[] = {-2, -6, -12, -20, -30, -42};
+ int p8[] = {-1, -2, -3, -4, -5, -6, -7};
+ int p9[] = {-1, -1, -1, -1, -1, -1, -1, -1};
+
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ boost::math::tools::polynomial<int> poly3(p3, ARRAY_SIZE(p3));
+ boost::math::tools::polynomial<int> poly4(p4, ARRAY_SIZE(p4));
+ boost::math::tools::polynomial<int> poly5(p5, ARRAY_SIZE(p5));
+ boost::math::tools::polynomial<int> poly6(p6, ARRAY_SIZE(p6));
+ boost::math::tools::polynomial<int> poly7(p7, ARRAY_SIZE(p7));
+ boost::math::tools::polynomial<int> poly8(p8, ARRAY_SIZE(p8));
+ boost::math::tools::polynomial<int> poly9(p9, ARRAY_SIZE(p9));
+
+ BOOST_CHECK_EQUAL(poly1.integral(-5040), poly2);
+ BOOST_CHECK_EQUAL(poly2.integral(-720), poly3);
+ BOOST_CHECK_EQUAL(poly3.integral(-120), poly4);
+ BOOST_CHECK_EQUAL(poly4.integral(-24), poly5);
+ BOOST_CHECK_EQUAL(poly5.integral(-6), poly6);
+ BOOST_CHECK_EQUAL(poly6.integral(-2), poly7);
+ BOOST_CHECK_EQUAL(poly7.integral(-1), poly8);
+ BOOST_CHECK_EQUAL(poly8.integral(-1), poly9);
+ }
+ {
+ int p1[] = {0};
+ int p2[] = {40320};
+ int p3[] = {0, 40320};
+ int p4[] = {-3600, 0, 20160};
+ int p5[] = {0, -3600, 0, 6720};
+ int p6[] = {1176, 0, -1800, 0, 1680};
+ int p7[] = {-1278, 1176, 0, -600, 0, 336};
+ int p8[] = {2, -1278, 588, 0, -150, 0, 56};
+ int p9[] = {-80, 2, -639, 196, 0, -30, 0, 8};
+ int p10[] = {655392, -80, 1, -213, 49, 0, -5, 0, 1};
+
+ boost::math::tools::polynomial<int> poly1(p1, ARRAY_SIZE(p1));
+ boost::math::tools::polynomial<int> poly2(p2, ARRAY_SIZE(p2));
+ boost::math::tools::polynomial<int> poly3(p3, ARRAY_SIZE(p3));
+ boost::math::tools::polynomial<int> poly4(p4, ARRAY_SIZE(p4));
+ boost::math::tools::polynomial<int> poly5(p5, ARRAY_SIZE(p5));
+ boost::math::tools::polynomial<int> poly6(p6, ARRAY_SIZE(p6));
+ boost::math::tools::polynomial<int> poly7(p7, ARRAY_SIZE(p7));
+ boost::math::tools::polynomial<int> poly8(p8, ARRAY_SIZE(p8));
+ boost::math::tools::polynomial<int> poly9(p9, ARRAY_SIZE(p9));
+ boost::math::tools::polynomial<int> poly10(p10, ARRAY_SIZE(p10));
+
+ BOOST_CHECK_EQUAL(poly1.integral(40320), poly2);
+ BOOST_CHECK_EQUAL(poly2.integral(), poly3);
+ BOOST_CHECK_EQUAL(poly3.integral(-3600), poly4);
+ BOOST_CHECK_EQUAL(poly4.integral(), poly5);
+ BOOST_CHECK_EQUAL(poly5.integral(1176), poly6);
+ BOOST_CHECK_EQUAL(poly6.integral(-1278), poly7);
+ BOOST_CHECK_EQUAL(poly7.integral(2), poly8);
+ BOOST_CHECK_EQUAL(poly8.integral(-80), poly9);
+ BOOST_CHECK_EQUAL(poly9.integral(655392), poly10);
+ }
+}
+
+int test_main(int argc, char* argv[]) {
+ test();
+ return 0;
+}
+

Added: sandbox/SOC/2008/polynomial/libs/test/test_special_forms.cpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2008/polynomial/libs/test/test_special_forms.cpp 2008-08-20 09:28:43 EDT (Wed, 20 Aug 2008)
@@ -0,0 +1,163 @@
+#define BOOST_DISABLE_WIN32
+
+#include <boost/test/included/test_exec_monitor.hpp>
+#include "../../boost/polynomial.hpp"
+
+#define ARRAY_SIZE(array) sizeof(array) / sizeof(array[0])
+
+void test_chebyshev_form() {
+ int p0[] = {1};
+ int p1[] = {0, 1};
+ int p2[] = {-1, 0, 2};
+ int p3[] = {0, -3, 0, 4};
+ int p4[] = {1, 0, -8, 0, 8};
+ int p5[] = {0, 5, 0, -20, 0, 16};
+ int p6[] = {-1, 0, 18, 0, -48, 0, 32};
+ int p7[] = {0, -7, 0, 56, 0, -112, 0, 64};
+ int p8[] = {1, 0, -32, 0, 160, 0, -256, 0, 128};
+ int p9[] = {0, 9, 0, -120, 0, 432, 0, -576, 0, 256};
+ int p10[] = {-1, 0, 50, 0, -400, 0, 1120, 0, -1280, 0, 512};
+ int p11[] = {0, -11, 0, 220, 0, -1232, 0, 2816, 0, -2816, 0, 1024};
+ int p12[] = {1, 0, -72, 0, 840, 0, -3584, 0, 6912, 0, -6144, 0, 2048};
+ int p13[] = {0, 13, 0, -364, 0, 2912, 0, -9984, 0, 16640, 0, -13312, 0, 4096};
+ int p14[] = {-1, 0, 98, 0, -1568, 0, 9408, 0, -26880, 0, 39424, 0, -28672, 0, 8192};
+ int p15[] = {0, -15, 0, 560, 0, -6048, 0, 28800, 0, -70400, 0, 92160, 0, -61440, 0, 16384};
+ int p16[] = {1, 0, -128, 0, 2688, 0, -21504, 0, 84480, 0, -180224, 0, 212992, 0, -131072, 0, 32768};
+ int p17[] = {0, 17, 0, -816, 0, 11424, 0, -71808, 0, 239360, 0, -452608, 0, 487424, 0, -278528, 0, 65536};
+ int p18[] = {-1, 0, 162, 0, -4320, 0, 44352, 0, -228096, 0, 658944, 0, -1118208, 0, 1105920, 0, -589824, 0, 131072};
+ int p19[] = {0, -19, 0, 1140, 0, -20064, 0, 160512, 0, -695552, 0, 1770496, 0, -2723840, 0, 2490368, 0, -1245184, 0, 262144};
+
+ boost::math::tools::polynomial<int> t0(p0, ARRAY_SIZE(p0));
+ boost::math::tools::polynomial<int> t1(p1, ARRAY_SIZE(p1));
+ boost::math::tools::polynomial<int> t2(p2, ARRAY_SIZE(p2));
+ boost::math::tools::polynomial<int> t3(p3, ARRAY_SIZE(p3));
+ boost::math::tools::polynomial<int> t4(p4, ARRAY_SIZE(p4));
+ boost::math::tools::polynomial<int> t5(p5, ARRAY_SIZE(p5));
+ boost::math::tools::polynomial<int> t6(p6, ARRAY_SIZE(p6));
+ boost::math::tools::polynomial<int> t7(p7, ARRAY_SIZE(p7));
+ boost::math::tools::polynomial<int> t8(p8, ARRAY_SIZE(p8));
+ boost::math::tools::polynomial<int> t9(p9, ARRAY_SIZE(p9));
+ boost::math::tools::polynomial<int> t10(p10, ARRAY_SIZE(p10));
+ boost::math::tools::polynomial<int> t11(p11, ARRAY_SIZE(p11));
+ boost::math::tools::polynomial<int> t12(p12, ARRAY_SIZE(p12));
+ boost::math::tools::polynomial<int> t13(p13, ARRAY_SIZE(p13));
+ boost::math::tools::polynomial<int> t14(p14, ARRAY_SIZE(p14));
+ boost::math::tools::polynomial<int> t15(p15, ARRAY_SIZE(p15));
+ boost::math::tools::polynomial<int> t16(p16, ARRAY_SIZE(p16));
+ boost::math::tools::polynomial<int> t17(p17, ARRAY_SIZE(p17));
+ boost::math::tools::polynomial<int> t18(p18, ARRAY_SIZE(p18));
+ boost::math::tools::polynomial<int> t19(p19, ARRAY_SIZE(p19));
+
+ boost::math::tools::polynomial<int> poly;
+
+ poly = boost::math::tools::chebyshev_form<int>(0);
+ BOOST_CHECK_EQUAL(poly, t0);
+ poly = boost::math::tools::chebyshev_form<int>(1);
+ BOOST_CHECK_EQUAL(poly, t1);
+ poly = boost::math::tools::chebyshev_form<int>(2);
+ BOOST_CHECK_EQUAL(poly, t2);
+ poly = boost::math::tools::chebyshev_form<int>(3);
+ BOOST_CHECK_EQUAL(poly, t3);
+ poly = boost::math::tools::chebyshev_form<int>(4);
+ BOOST_CHECK_EQUAL(poly, t4);
+ poly = boost::math::tools::chebyshev_form<int>(5);
+ BOOST_CHECK_EQUAL(poly, t5);
+ poly = boost::math::tools::chebyshev_form<int>(6);
+ BOOST_CHECK_EQUAL(poly, t6);
+ poly = boost::math::tools::chebyshev_form<int>(7);
+ BOOST_CHECK_EQUAL(poly, t7);
+ poly = boost::math::tools::chebyshev_form<int>(8);
+ BOOST_CHECK_EQUAL(poly, t8);
+ poly = boost::math::tools::chebyshev_form<int>(9);
+ BOOST_CHECK_EQUAL(poly, t9);
+ poly = boost::math::tools::chebyshev_form<int>(10);
+ BOOST_CHECK_EQUAL(poly, t10);
+ poly = boost::math::tools::chebyshev_form<int>(11);
+ BOOST_CHECK_EQUAL(poly, t11);
+ poly = boost::math::tools::chebyshev_form<int>(12);
+ BOOST_CHECK_EQUAL(poly, t12);
+ poly = boost::math::tools::chebyshev_form<int>(13);
+ BOOST_CHECK_EQUAL(poly, t13);
+ poly = boost::math::tools::chebyshev_form<int>(14);
+ BOOST_CHECK_EQUAL(poly, t14);
+ poly = boost::math::tools::chebyshev_form<int>(15);
+ BOOST_CHECK_EQUAL(poly, t15);
+ poly = boost::math::tools::chebyshev_form<int>(16);
+ BOOST_CHECK_EQUAL(poly, t16);
+ poly = boost::math::tools::chebyshev_form<int>(17);
+ BOOST_CHECK_EQUAL(poly, t17);
+ poly = boost::math::tools::chebyshev_form<int>(18);
+ BOOST_CHECK_EQUAL(poly, t18);
+ poly = boost::math::tools::chebyshev_form<int>(19);
+ BOOST_CHECK_EQUAL(poly, t19);
+}
+
+void test_hermite_form() {
+ int p0[] = {1};
+ int p1[] = {0, 2};
+ int p2[] = {-2, 0, 4};
+ int p3[] = {0, -12, 0, 8};
+ int p4[] = {12, 0, -48, 0, 16};
+ int p5[] = {0, 120, 0, -160, 0, 32};
+ int p6[] = {-120, 0, 720, 0, -480, 0, 64};
+ int p7[] = {0, -1680, 0, 3360, 0, -1344, 0, 128};
+ int p8[] = {1680, 0, -13440, 0, 13440, 0, -3584, 0, 256};
+ int p9[] = {0, 30240, 0, -80640, 0, 48384, 0, -9216, 0, 512};
+ int p10[] = {-30240, 0, 302400, 0, -403200, 0, 161280, 0, -23040, 0, 1024};
+ int p11[] = {0, -665280, 0, 2217600, 0, -1774080, 0, 506880, 0, -56320, 0, 2048};
+ int p12[] = {665280, 0, -7983360, 0, 13305600, 0, -7096320, 0, 1520640, 0, -135168, 0, 4096};
+ int p13[] = {0, 17297280, 0, -69189120, 0, 69189120, 0, -26357760, 0, 4392960, 0, -319488, 0, 8192};
+
+ boost::math::tools::polynomial<int> h0(p0, ARRAY_SIZE(p0));
+ boost::math::tools::polynomial<int> h1(p1, ARRAY_SIZE(p1));
+ boost::math::tools::polynomial<int> h2(p2, ARRAY_SIZE(p2));
+ boost::math::tools::polynomial<int> h3(p3, ARRAY_SIZE(p3));
+ boost::math::tools::polynomial<int> h4(p4, ARRAY_SIZE(p4));
+ boost::math::tools::polynomial<int> h5(p5, ARRAY_SIZE(p5));
+ boost::math::tools::polynomial<int> h6(p6, ARRAY_SIZE(p6));
+ boost::math::tools::polynomial<int> h7(p7, ARRAY_SIZE(p7));
+ boost::math::tools::polynomial<int> h8(p8, ARRAY_SIZE(p8));
+ boost::math::tools::polynomial<int> h9(p9, ARRAY_SIZE(p9));
+ boost::math::tools::polynomial<int> h10(p10, ARRAY_SIZE(p10));
+ boost::math::tools::polynomial<int> h11(p11, ARRAY_SIZE(p11));
+ boost::math::tools::polynomial<int> h12(p12, ARRAY_SIZE(p12));
+ boost::math::tools::polynomial<int> h13(p13, ARRAY_SIZE(p13));
+
+ boost::math::tools::polynomial<int> poly;
+
+ poly = boost::math::tools::hermite_form<int>(0);
+ BOOST_CHECK_EQUAL(poly, h0);
+ poly = boost::math::tools::hermite_form<int>(1);
+ BOOST_CHECK_EQUAL(poly, h1);
+ poly = boost::math::tools::hermite_form<int>(2);
+ BOOST_CHECK_EQUAL(poly, h2);
+ poly = boost::math::tools::hermite_form<int>(3);
+ BOOST_CHECK_EQUAL(poly, h3);
+ poly = boost::math::tools::hermite_form<int>(4);
+ BOOST_CHECK_EQUAL(poly, h4);
+ poly = boost::math::tools::hermite_form<int>(5);
+ BOOST_CHECK_EQUAL(poly, h5);
+ poly = boost::math::tools::hermite_form<int>(6);
+ BOOST_CHECK_EQUAL(poly, h6);
+ poly = boost::math::tools::hermite_form<int>(7);
+ BOOST_CHECK_EQUAL(poly, h7);
+ poly = boost::math::tools::hermite_form<int>(8);
+ BOOST_CHECK_EQUAL(poly, h8);
+ poly = boost::math::tools::hermite_form<int>(9);
+ BOOST_CHECK_EQUAL(poly, h9);
+ poly = boost::math::tools::hermite_form<int>(10);
+ BOOST_CHECK_EQUAL(poly, h10);
+ poly = boost::math::tools::hermite_form<int>(11);
+ BOOST_CHECK_EQUAL(poly, h11);
+ poly = boost::math::tools::hermite_form<int>(12);
+ BOOST_CHECK_EQUAL(poly, h12);
+ poly = boost::math::tools::hermite_form<int>(13);
+ BOOST_CHECK_EQUAL(poly, h13);
+}
+
+int test_main(int argc, char* argv[]) {
+ test_chebyshev_form();
+ test_hermite_form();
+ return 0;
+}
+


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk