72e469da0a
[CI SKIP]
338 lines
56 KiB
HTML
338 lines
56 KiB
HTML
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
|
<title>Polynomials</title>
|
|
<link rel="stylesheet" href="../math.css" type="text/css">
|
|
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
|
|
<link rel="home" href="../index.html" title="Math Toolkit 2.11.0">
|
|
<link rel="up" href="../poly.html" title="Chapter 11. Polynomials and Rational Functions">
|
|
<link rel="prev" href="../poly.html" title="Chapter 11. Polynomials and Rational Functions">
|
|
<link rel="next" href="rational.html" title="Polynomial and Rational Function Evaluation">
|
|
</head>
|
|
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
|
<table cellpadding="2" width="100%"><tr>
|
|
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
|
|
<td align="center"><a href="../../../../../index.html">Home</a></td>
|
|
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
|
|
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
|
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
|
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
|
|
</tr></table>
|
|
<hr>
|
|
<div class="spirit-nav">
|
|
<a accesskey="p" href="../poly.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../poly.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="rational.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
|
</div>
|
|
<div class="section">
|
|
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
|
<a name="math_toolkit.polynomials"></a><a class="link" href="polynomials.html" title="Polynomials">Polynomials</a>
|
|
</h2></div></div></div>
|
|
<h5>
|
|
<a name="math_toolkit.polynomials.h0"></a>
|
|
<span class="phrase"><a name="math_toolkit.polynomials.synopsis"></a></span><a class="link" href="polynomials.html#math_toolkit.polynomials.synopsis">Synopsis</a>
|
|
</h5>
|
|
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">tools</span><span class="special">/</span><span class="identifier">polynomial</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
|
</pre>
|
|
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">math</span> <span class="special">{</span>
|
|
<span class="keyword">namespace</span> <span class="identifier">tools</span> <span class="special">{</span>
|
|
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
|
|
<span class="keyword">class</span> <span class="identifier">polynomial</span>
|
|
<span class="special">{</span>
|
|
<span class="keyword">public</span><span class="special">:</span>
|
|
<span class="comment">// typedefs:</span>
|
|
<span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">value_type</span> <span class="identifier">value_type</span><span class="special">;</span>
|
|
<span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span><span class="identifier">T</span><span class="special">>::</span><span class="identifier">size_type</span> <span class="identifier">size_type</span><span class="special">;</span>
|
|
|
|
<span class="comment">// construct:</span>
|
|
<span class="identifier">polynomial</span><span class="special">(){}</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">U</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">U</span><span class="special">*</span> <span class="identifier">data</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="identifier">order</span><span class="special">);</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">I</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special">(</span><span class="identifier">I</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">I</span> <span class="identifier">last</span><span class="special">);</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">U</span><span class="special">></span>
|
|
<span class="keyword">explicit</span> <span class="identifier">polynomial</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">U</span><span class="special">&</span> <span class="identifier">point</span><span class="special">,</span>
|
|
<span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">enable_if</span><span class="special"><</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_convertible</span><span class="special"><</span><span class="identifier">U</span><span class="special">,</span> <span class="identifier">T</span><span class="special">></span> <span class="special">>::</span><span class="identifier">type</span><span class="special">*</span> <span class="special">=</span> <span class="number">0</span><span class="special">);</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Range</span><span class="special">></span>
|
|
<span class="keyword">explicit</span> <span class="identifier">polynomial</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">Range</span><span class="special">&</span> <span class="identifier">r</span><span class="special">,</span>
|
|
<span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">enable_if</span><span class="special"><</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">tools</span><span class="special">::</span><span class="identifier">detail</span><span class="special">::</span><span class="identifier">is_const_iterable</span><span class="special"><</span><span class="identifier">Range</span><span class="special">></span> <span class="special">>::</span><span class="identifier">type</span><span class="special">*</span> <span class="special">=</span> <span class="number">0</span><span class="special">);</span> <span class="comment">// C++14</span>
|
|
<span class="identifier">polynomial</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">initializer_list</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="identifier">l</span><span class="special">);</span> <span class="comment">// C++11</span>
|
|
|
|
<span class="identifier">polynomial</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span><span class="identifier">T</span><span class="special">>&&</span> <span class="identifier">p</span><span class="special">);</span>
|
|
|
|
<span class="comment">// access:</span>
|
|
<span class="identifier">size_type</span> <span class="identifier">size</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
|
|
<span class="identifier">size_type</span> <span class="identifier">degree</span><span class="special">()</span><span class="keyword">const</span><span class="special">;</span>
|
|
<span class="identifier">value_type</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">[](</span><span class="identifier">size_type</span> <span class="identifier">i</span><span class="special">);</span>
|
|
<span class="keyword">const</span> <span class="identifier">value_type</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">[](</span><span class="identifier">size_type</span> <span class="identifier">i</span><span class="special">)</span><span class="keyword">const</span><span class="special">;</span>
|
|
<span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="keyword">const</span><span class="special">&</span> <span class="identifier">data</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
|
|
<span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span><span class="identifier">T</span><span class="special">>&</span> <span class="identifier">data</span><span class="special">();</span>
|
|
<span class="keyword">explicit</span> <span class="keyword">operator</span> <span class="keyword">bool</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
|
|
|
|
<span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="identifier">prime</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
|
|
|
|
<span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="identifier">integrate</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
|
|
|
|
<span class="identifier">T</span> <span class="keyword">operator</span><span class="special">()(</span><span class="identifier">T</span> <span class="identifier">z</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
|
|
|
|
|
|
|
|
<span class="comment">// modify:</span>
|
|
<span class="keyword">void</span> <span class="identifier">set_zero</span><span class="special">();</span>
|
|
|
|
<span class="comment">// operators:</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">U</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special">&</span> <span class="keyword">operator</span> <span class="special">+=(</span><span class="keyword">const</span> <span class="identifier">U</span><span class="special">&</span> <span class="identifier">value</span><span class="special">);</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">U</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special">&</span> <span class="keyword">operator</span> <span class="special">-=(</span><span class="keyword">const</span> <span class="identifier">U</span><span class="special">&</span> <span class="identifier">value</span><span class="special">);</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">U</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special">&</span> <span class="keyword">operator</span> <span class="special">*=(</span><span class="keyword">const</span> <span class="identifier">U</span><span class="special">&</span> <span class="identifier">value</span><span class="special">);</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">U</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special">&</span> <span class="keyword">operator</span> <span class="special">/=(</span><span class="keyword">const</span> <span class="identifier">U</span><span class="special">&</span> <span class="identifier">value</span><span class="special">);</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">U</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special">&</span> <span class="keyword">operator</span> <span class="special">%=(</span><span class="keyword">const</span> <span class="identifier">U</span><span class="special">&</span> <span class="identifier">value</span><span class="special">);</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">U</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special">&</span> <span class="keyword">operator</span> <span class="special">+=(</span><span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">U</span><span class="special">>&</span> <span class="identifier">value</span><span class="special">);</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">U</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special">&</span> <span class="keyword">operator</span> <span class="special">-=(</span><span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">U</span><span class="special">>&</span> <span class="identifier">value</span><span class="special">);</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">U</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special">&</span> <span class="keyword">operator</span> <span class="special">*=(</span><span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">U</span><span class="special">>&</span> <span class="identifier">value</span><span class="special">);</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">U</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special">&</span> <span class="keyword">operator</span> <span class="special">/=(</span><span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">U</span><span class="special">>&</span> <span class="identifier">value</span><span class="special">);</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">U</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special">&</span> <span class="keyword">operator</span> <span class="special">%=(</span><span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">U</span><span class="special">>&</span> <span class="identifier">value</span><span class="special">);</span>
|
|
<span class="special">};</span>
|
|
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="keyword">operator</span> <span class="special">+</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">>&</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">>&</span> <span class="identifier">b</span><span class="special">);</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="keyword">operator</span> <span class="special">-</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">>&</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">>&</span> <span class="identifier">b</span><span class="special">);</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="keyword">operator</span> <span class="special">*</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">>&</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">>&</span> <span class="identifier">b</span><span class="special">);</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="keyword">operator</span> <span class="special">/</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">>&</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">>&</span> <span class="identifier">b</span><span class="special">);</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="keyword">operator</span> <span class="special">%</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">>&</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">>&</span> <span class="identifier">b</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">U</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="keyword">operator</span> <span class="special">+</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">>&</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">U</span><span class="special">&</span> <span class="identifier">b</span><span class="special">);</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">U</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="keyword">operator</span> <span class="special">-</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">>&</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">U</span><span class="special">&</span> <span class="identifier">b</span><span class="special">);</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">U</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="keyword">operator</span> <span class="special">*</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">>&</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">U</span><span class="special">&</span> <span class="identifier">b</span><span class="special">);</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">U</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="keyword">operator</span> <span class="special">/</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">>&</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">U</span><span class="special">&</span> <span class="identifier">b</span><span class="special">);</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">U</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="keyword">operator</span> <span class="special">%</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">>&</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">U</span><span class="special">&</span> <span class="identifier">b</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">U</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="keyword">operator</span> <span class="special">+</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">U</span><span class="special">&</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">>&</span> <span class="identifier">b</span><span class="special">);</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">U</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="keyword">operator</span> <span class="special">-</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">U</span><span class="special">&</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">>&</span> <span class="identifier">b</span><span class="special">);</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">U</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="keyword">operator</span> <span class="special">*</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">U</span><span class="special">&</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">>&</span> <span class="identifier">b</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="keyword">operator</span> <span class="special">-</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">>&</span> <span class="identifier">a</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="keyword">operator</span> <span class="special">>>=</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">U</span><span class="special">&</span> <span class="identifier">a</span><span class="special">);</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="keyword">operator</span> <span class="special">>></span> <span class="special">(</span><span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">U</span><span class="special">&</span> <span class="identifier">b</span><span class="special">);</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="keyword">operator</span> <span class="special"><<=</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">U</span><span class="special">&</span> <span class="identifier">a</span><span class="special">);</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="keyword">operator</span> <span class="special"><<</span> <span class="special">(</span><span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">U</span><span class="special">&</span> <span class="identifier">b</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
|
|
<span class="keyword">bool</span> <span class="keyword">operator</span> <span class="special">==</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="special">&</span><span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="special">&</span><span class="identifier">b</span><span class="special">);</span>
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
|
|
<span class="keyword">bool</span> <span class="keyword">operator</span> <span class="special">!=</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="special">&</span><span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="special">&</span><span class="identifier">b</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
|
|
<span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="identifier">pow</span><span class="special">(</span><span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="identifier">base</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">exp</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">charT</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">traits</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
|
|
<span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_ostream</span><span class="special"><</span><span class="identifier">charT</span><span class="special">,</span> <span class="identifier">traits</span><span class="special">>&</span> <span class="keyword">operator</span> <span class="special"><<</span>
|
|
<span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_ostream</span><span class="special"><</span><span class="identifier">charT</span><span class="special">,</span> <span class="identifier">traits</span><span class="special">>&</span> <span class="identifier">os</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">>&</span> <span class="identifier">poly</span><span class="special">);</span>
|
|
|
|
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">></span>
|
|
<span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special"><</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">>,</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span> <span class="special">></span>
|
|
<span class="identifier">quotient_remainder</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">>&</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="identifier">T</span><span class="special">>&</span> <span class="identifier">b</span><span class="special">);</span>
|
|
|
|
<span class="special">}</span> <span class="comment">// namespace tools</span>
|
|
<span class="special">}}</span> <span class="comment">// namespace boost { namespace math</span>
|
|
</pre>
|
|
<h5>
|
|
<a name="math_toolkit.polynomials.h1"></a>
|
|
<span class="phrase"><a name="math_toolkit.polynomials.description"></a></span><a class="link" href="polynomials.html#math_toolkit.polynomials.description">Description</a>
|
|
</h5>
|
|
<p>
|
|
This is a somewhat trivial class for polynomial manipulation.
|
|
</p>
|
|
<p>
|
|
See
|
|
</p>
|
|
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
|
<li class="listitem">
|
|
<a href="https://en.wikipedia.org/wiki/Polynomial" target="_top">Polynomial</a>
|
|
and
|
|
</li>
|
|
<li class="listitem">
|
|
Donald E. Knuth, The Art of Computer Programming: Volume 2, Third edition,
|
|
(1998) Chapter 4.6.1, Algorithm D: Division of polynomials over a field.
|
|
</li>
|
|
</ul></div>
|
|
<p>
|
|
Implementation is currently of the "naive" variety, with 𝑶(N<sup>2</sup>) multiplication,
|
|
for example. This class should not be used in high-performance computing environments:
|
|
it is intended for the simple manipulation of small polynomials, typically
|
|
generated for special function approximation.
|
|
</p>
|
|
<p>
|
|
It does has division for polynomials over a <a href="https://en.wikipedia.org/wiki/Field_%28mathematics%29" target="_top">field</a>
|
|
(here floating point, complex, etc) and over a unique factorization domain
|
|
(integers). Division of polynomials over a field is compatible with <a href="https://en.wikipedia.org/wiki/Euclidean_algorithm" target="_top">Euclidean GCD</a>.
|
|
</p>
|
|
<p>
|
|
Division of polynomials over a UFD is compatible with the subresultant algorithm
|
|
for GCD (implemented as subresultant_gcd), but a serious word of warning is
|
|
required: the intermediate value swell of that algorithm will cause single-precision
|
|
integral types to overflow very easily. So although the algorithm will work
|
|
on single-precision integral types, an overload of the gcd function is only
|
|
provided for polynomials with multi-precision integral types, to prevent nasty
|
|
surprises. This is done somewhat crudely by disabling the overload for non-POD
|
|
integral types.
|
|
</p>
|
|
<p>
|
|
Advanced manipulations: the FFT, factorisation etc are not currently provided.
|
|
Submissions for these are of course welcome :-)
|
|
</p>
|
|
<h5>
|
|
<a name="math_toolkit.polynomials.h2"></a>
|
|
<span class="phrase"><a name="math_toolkit.polynomials.polynomial_examples"></a></span><a class="link" href="polynomials.html#math_toolkit.polynomials.polynomial_examples">Polynomial
|
|
Arithmetic Examples</a>
|
|
</h5>
|
|
<p>
|
|
First include the essential polynomial header (and others) to make the example:
|
|
</p>
|
|
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">tools</span><span class="special">/</span><span class="identifier">polynomial</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
|
</pre>
|
|
<p>
|
|
and some using statements are convenient:
|
|
</p>
|
|
<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">;</span>
|
|
<span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">exception</span><span class="special">;</span>
|
|
<span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span><span class="special">;</span>
|
|
<span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">abs</span><span class="special">;</span>
|
|
<span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special">;</span>
|
|
|
|
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">;</span>
|
|
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">tools</span><span class="special">;</span> <span class="comment">// for polynomial</span>
|
|
<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">lexical_cast</span><span class="special">;</span>
|
|
</pre>
|
|
<p>
|
|
Store the coefficients in a convenient way to access them, then create some
|
|
polynomials using construction from an iterator range, and finally output in
|
|
a 'pretty' formula format.
|
|
</p>
|
|
<div class="tip"><table border="0" summary="Tip">
|
|
<tr>
|
|
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../../../doc/src/images/tip.png"></td>
|
|
<th align="left">Tip</th>
|
|
</tr>
|
|
<tr><td align="left" valign="top"><p>
|
|
Although we might conventionally write a polynomial from left to right in
|
|
descending order of degree, Boost.Math stores in <span class="bold"><strong>ascending
|
|
order of degree</strong></span>.
|
|
</p></td></tr>
|
|
</table></div>
|
|
<pre class="programlisting"><span class="identifier">Read</span><span class="special">/</span><span class="identifier">write</span> <span class="keyword">for</span> <span class="identifier">humans</span><span class="special">:</span> <span class="number">3</span><span class="identifier">x</span><span class="special">^</span><span class="number">3</span> <span class="special">-</span> <span class="number">4</span><span class="identifier">x</span><span class="special">^</span><span class="number">2</span> <span class="special">-</span> <span class="number">6</span><span class="identifier">x</span> <span class="special">+</span> <span class="number">10</span>
|
|
<span class="identifier">Boost</span> <span class="identifier">polynomial</span> <span class="identifier">storage</span><span class="special">:</span> <span class="special">[</span> <span class="number">10</span><span class="special">,</span> <span class="special">-</span><span class="number">6</span><span class="special">,</span> <span class="special">-</span><span class="number">4</span><span class="special">,</span> <span class="number">3</span> <span class="special">]</span>
|
|
</pre>
|
|
<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">array</span><span class="special"><</span><span class="keyword">double</span><span class="special">,</span> <span class="number">4</span><span class="special">></span> <span class="keyword">const</span> <span class="identifier">d3a</span> <span class="special">=</span> <span class="special">{{</span><span class="number">10</span><span class="special">,</span> <span class="special">-</span><span class="number">6</span><span class="special">,</span> <span class="special">-</span><span class="number">4</span><span class="special">,</span> <span class="number">3</span><span class="special">}};</span>
|
|
<span class="identifier">polynomial</span><span class="special"><</span><span class="keyword">double</span><span class="special">></span> <span class="keyword">const</span> <span class="identifier">a</span><span class="special">(</span><span class="identifier">d3a</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">d3a</span><span class="special">.</span><span class="identifier">end</span><span class="special">());</span>
|
|
|
|
<span class="comment">// With C++11 and later, you can also use initializer_list construction.</span>
|
|
<span class="identifier">polynomial</span><span class="special"><</span><span class="keyword">double</span><span class="special">></span> <span class="keyword">const</span> <span class="identifier">b</span><span class="special">{{-</span><span class="number">2.0</span><span class="special">,</span> <span class="number">1.0</span><span class="special">}};</span>
|
|
|
|
<span class="comment">// formula_format() converts from Boost storage to human notation.</span>
|
|
<span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"a = "</span> <span class="special"><<</span> <span class="identifier">formula_format</span><span class="special">(</span><span class="identifier">a</span><span class="special">)</span>
|
|
<span class="special"><<</span> <span class="string">"\nb = "</span> <span class="special"><<</span> <span class="identifier">formula_format</span><span class="special">(</span><span class="identifier">b</span><span class="special">)</span> <span class="special"><<</span> <span class="string">"\n\n"</span><span class="special">;</span>
|
|
</pre>
|
|
<p>
|
|
for output:
|
|
</p>
|
|
<pre class="programlisting"><span class="identifier">a</span> <span class="special">=</span> <span class="number">3</span><span class="identifier">x</span><span class="special">^</span><span class="number">3</span> <span class="special">-</span> <span class="number">4</span><span class="identifier">x</span><span class="special">^</span><span class="number">2</span> <span class="special">-</span> <span class="number">6</span><span class="identifier">x</span> <span class="special">+</span> <span class="number">10</span>
|
|
<span class="identifier">b</span> <span class="special">=</span> <span class="identifier">x</span> <span class="special">-</span> <span class="number">2</span>
|
|
</pre>
|
|
<pre class="programlisting"><span class="comment">// Now we can do arithmetic with the usual infix operators: + - * / and %.</span>
|
|
<span class="identifier">polynomial</span><span class="special"><</span><span class="keyword">double</span><span class="special">></span> <span class="identifier">s</span> <span class="special">=</span> <span class="identifier">a</span> <span class="special">+</span> <span class="identifier">b</span><span class="special">;</span>
|
|
<span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"a + b = "</span> <span class="special"><<</span> <span class="identifier">formula_format</span><span class="special">(</span><span class="identifier">s</span><span class="special">)</span> <span class="special"><<</span> <span class="string">"\n"</span><span class="special">;</span>
|
|
<span class="identifier">polynomial</span><span class="special"><</span><span class="keyword">double</span><span class="special">></span> <span class="identifier">d</span> <span class="special">=</span> <span class="identifier">a</span> <span class="special">-</span> <span class="identifier">b</span><span class="special">;</span>
|
|
<span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"a - b = "</span> <span class="special"><<</span> <span class="identifier">formula_format</span><span class="special">(</span><span class="identifier">d</span><span class="special">)</span> <span class="special"><<</span> <span class="string">"\n"</span><span class="special">;</span>
|
|
<span class="identifier">polynomial</span><span class="special"><</span><span class="keyword">double</span><span class="special">></span> <span class="identifier">p</span> <span class="special">=</span> <span class="identifier">a</span> <span class="special">*</span> <span class="identifier">b</span><span class="special">;</span>
|
|
<span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"a * b = "</span> <span class="special"><<</span> <span class="identifier">formula_format</span><span class="special">(</span><span class="identifier">p</span><span class="special">)</span> <span class="special"><<</span> <span class="string">"\n"</span><span class="special">;</span>
|
|
<span class="identifier">polynomial</span><span class="special"><</span><span class="keyword">double</span><span class="special">></span> <span class="identifier">q</span> <span class="special">=</span> <span class="identifier">a</span> <span class="special">/</span> <span class="identifier">b</span><span class="special">;</span>
|
|
<span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"a / b = "</span> <span class="special"><<</span> <span class="identifier">formula_format</span><span class="special">(</span><span class="identifier">q</span><span class="special">)</span> <span class="special"><<</span> <span class="string">"\n"</span><span class="special">;</span>
|
|
<span class="identifier">polynomial</span><span class="special"><</span><span class="keyword">double</span><span class="special">></span> <span class="identifier">r</span> <span class="special">=</span> <span class="identifier">a</span> <span class="special">%</span> <span class="identifier">b</span><span class="special">;</span>
|
|
<span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"a % b = "</span> <span class="special"><<</span> <span class="identifier">formula_format</span><span class="special">(</span><span class="identifier">r</span><span class="special">)</span> <span class="special"><<</span> <span class="string">"\n"</span><span class="special">;</span>
|
|
</pre>
|
|
<p>
|
|
for output
|
|
</p>
|
|
<pre class="programlisting"><span class="identifier">a</span> <span class="special">+</span> <span class="identifier">b</span> <span class="special">=</span> <span class="number">3</span><span class="identifier">x</span><span class="special">^</span><span class="number">3</span> <span class="special">-</span> <span class="number">4</span><span class="identifier">x</span><span class="special">^</span><span class="number">2</span> <span class="special">-</span> <span class="number">5</span><span class="identifier">x</span> <span class="special">+</span> <span class="number">8</span>
|
|
<span class="identifier">a</span> <span class="special">-</span> <span class="identifier">b</span> <span class="special">=</span> <span class="number">3</span><span class="identifier">x</span><span class="special">^</span><span class="number">3</span> <span class="special">-</span> <span class="number">4</span><span class="identifier">x</span><span class="special">^</span><span class="number">2</span> <span class="special">-</span> <span class="number">7</span><span class="identifier">x</span> <span class="special">+</span> <span class="number">12</span>
|
|
<span class="identifier">a</span> <span class="special">*</span> <span class="identifier">b</span> <span class="special">=</span> <span class="number">3</span><span class="identifier">x</span><span class="special">^</span><span class="number">4</span> <span class="special">-</span> <span class="number">10</span><span class="identifier">x</span><span class="special">^</span><span class="number">3</span> <span class="special">+</span> <span class="number">2</span><span class="identifier">x</span><span class="special">^</span><span class="number">2</span> <span class="special">+</span> <span class="number">22</span><span class="identifier">x</span> <span class="special">-</span> <span class="number">20</span>
|
|
<span class="identifier">a</span> <span class="special">/</span> <span class="identifier">b</span> <span class="special">=</span> <span class="number">3</span><span class="identifier">x</span><span class="special">^</span><span class="number">2</span> <span class="special">+</span> <span class="number">2</span><span class="identifier">x</span> <span class="special">-</span> <span class="number">2</span>
|
|
<span class="identifier">a</span> <span class="special">%</span> <span class="identifier">b</span> <span class="special">=</span> <span class="number">6</span>
|
|
</pre>
|
|
<h6>
|
|
<a name="math_toolkit.polynomials.h3"></a>
|
|
<span class="phrase"><a name="math_toolkit.polynomials.division_quotient_and_remainder"></a></span><a class="link" href="polynomials.html#math_toolkit.polynomials.division_quotient_and_remainder">Division,
|
|
Quotient and Remainder</a>
|
|
</h6>
|
|
<p>
|
|
Division is a special case where you can calculate two for the price of one.
|
|
</p>
|
|
<p>
|
|
Actually, quotient and remainder are always calculated together due to the
|
|
nature of the algorithm: the infix operators return one result and throw the
|
|
other away.
|
|
</p>
|
|
<p>
|
|
If you are doing a lot of division and want both the quotient and remainder,
|
|
then you don't want to do twice the work necessary.
|
|
</p>
|
|
<p>
|
|
In that case you can call the underlying function, <code class="literal">quotient_remainder</code>,
|
|
to get both results together as a pair.
|
|
</p>
|
|
<pre class="programlisting"> <span class="identifier">pair</span><span class="special"><</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="keyword">double</span><span class="special">>,</span> <span class="identifier">polynomial</span><span class="special"><</span><span class="keyword">double</span><span class="special">></span> <span class="special">></span> <span class="identifier">result</span><span class="special">;</span>
|
|
<span class="identifier">result</span> <span class="special">=</span> <span class="identifier">quotient_remainder</span><span class="special">(</span><span class="identifier">a</span><span class="special">,</span> <span class="identifier">b</span><span class="special">);</span>
|
|
<span class="comment">// Reassure ourselves that the result is the same.</span>
|
|
<span class="identifier">BOOST_ASSERT</span><span class="special">(</span><span class="identifier">result</span><span class="special">.</span><span class="identifier">first</span> <span class="special">==</span> <span class="identifier">q</span><span class="special">);</span>
|
|
<span class="identifier">BOOST_ASSERT</span><span class="special">(</span><span class="identifier">result</span><span class="special">.</span><span class="identifier">second</span> <span class="special">==</span> <span class="identifier">r</span><span class="special">);</span>
|
|
</pre>
|
|
<p>
|
|
The source code is at <a href="../../../example/polynomial_arithmetic.cpp" target="_top">polynomial_arithmetic.cpp</a>
|
|
</p>
|
|
</div>
|
|
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
|
<td align="left"></td>
|
|
<td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar
|
|
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
|
|
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
|
|
Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
|
|
Daryle Walker and Xiaogang Zhang<p>
|
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
|
</p>
|
|
</div></td>
|
|
</tr></table>
|
|
<hr>
|
|
<div class="spirit-nav">
|
|
<a accesskey="p" href="../poly.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../poly.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="rational.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
|
</div>
|
|
</body>
|
|
</html>
|