Ian Jauslin
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'doc/libinum-doc.php')
-rw-r--r--doc/libinum-doc.php1835
1 files changed, 1835 insertions, 0 deletions
diff --git a/doc/libinum-doc.php b/doc/libinum-doc.php
new file mode 100644
index 0000000..2daf429
--- /dev/null
+++ b/doc/libinum-doc.php
@@ -0,0 +1,1835 @@
+<html>
+ <head>
+ <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> </script>
+ <!--<script type="text/javascript" src="/usr/share/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> </script>-->
+
+ <style>
+ body {
+ margin-top:40pt;
+ margin-bottom:40pt;
+ margin-left:40pt;
+ margin-right:40pt;
+
+ text-align:justify;
+ }
+
+ p {
+ text-indent:20pt;
+ }
+
+ .codeblock {
+ display:block;
+ margin-left:40pt;
+ margin-top:10pt;
+ margin-bottom:15pt;
+ text-indent:0pt;
+ }
+
+ li {
+ margin-top:10pt;
+ }
+
+ .toc {
+ font-weight:bold;
+ }
+ .toc ul {
+ list-style-type:none;
+ }
+ .toc li {
+ margin-top:0pt;
+ }
+ .toc_sec {
+ counter-increment: tocsec;
+ counter-reset: tocsub 0;
+ }
+ .toc_sec:before {
+ content: counter(tocsec) ". ";
+ }
+ .toc_sub {
+ counter-increment: tocsub;
+ }
+ .toc_sub:before {
+ content: counter(tocsec) "." counter(tocsub) ". ";
+ }
+
+ body {
+ counter-reset: section 0;
+ }
+ .section:before {
+ counter-increment: section;
+ content: counter(section) ". ";
+ }
+ .section {
+ margin-top:50pt;
+ counter-reset: subsection 0;
+ }
+ .subsection:before {
+ counter-increment: subsection;
+ content: counter(section) "." counter(subsection) ". ";
+ }
+ .subsection {
+ margin-top:30pt;
+ }
+
+ </style>
+
+ </head>
+
+ <body>
+ <h1 style="margin-bottom:50pt;">libinum <span style="margin-left:10pt;font-size:18pt">v1.0</span></h1>
+
+ <p>
+ This is the official documentation for <b>libinum</b>, version 1.0.
+ </p>
+
+ <h2 style="margin-top:50pt;">Table of contents</h2>
+ <div class="toc">
+ <ul>
+ <li class="toc_sec"><a href="#sec_description">Description</a></li>
+ <li class="toc_sec"><a href="#sec_datatypes">Data types</a></li>
+ <li class="toc_sec"><a href="#sec_algorithms">Algorithms</a></li>
+ <ul>
+ <li class="toc_sub"><a href="#subsec_root_finding">Root finding</a></li>
+ <ul>
+ <li><a href="#func_root_newton"><code>root_newton</code></a></li>
+ <li><a href="#func_root_newton_inplace"><code>root_newton_inplace</code></a></li>
+ </ul>
+ <li class="toc_sub"><a href="#subsec_integrals">Integrals</a></li>
+ <ul>
+ <li><a href="#func_integrate_gauss"><code>integrate_gauss</code></a></li>
+ <li><a href="#func_integrate_gauss_multithread"><code>integrate_gauss_multithread</code></a></li>
+ <li><a href="#func_integrate_gauss_smarttmp"><code>integrate_gauss_smarttmp</code></a></li>
+ <li><a href="#func_integrate_gauss_smarttmp_multithread"><code>integrate_gauss_smarttmp_multithread</code></a></li>
+ <li><a href="#func_gauss_legendre_weights"><code>gauss_legendre_weights</code></a></li>
+ </ul>
+ </ul>
+ <li class="toc_sec"><a href="#sec_types">Types</a></li>
+ <ul>
+ <li class="toc_sub"><a href="#subsec_array"><code>array</code></a></li>
+ <li class="toc_sub"><a href="#subsec_polynomial"><code>polynomial</code></a></li>
+ <li class="toc_sub"><a href="#subsec_polynomialMV"><code>polynomialMV</code></a></li>
+ <li class="toc_sub"><a href="#subsec_functions">Functions</a></li>
+ </ul>
+ <li class="toc_sec"><a href="#sec_utilities">Utilities</a></li>
+ <li class="toc_sec"><a href="#sec_examples">Examples</a></li>
+ <li class="toc_sec"><a href="#sec_authors">Authors</a></li>
+ </ul>
+ </div>
+
+ <h2 class="section" id="sec_description">Description</h2>
+ <p>
+ <b>libinum</b> is a C library that implements several algorithms, intended for applications in numerical and symbolic computations.
+ </p>
+ <p>
+ <b>libinum</b> defines functions to perform the following tasks:
+ <ul>
+ <li>Compute roots of smooth real functions numerically using the Newton-Raphson algorithm.</li>
+ <li>Compute definite integrals of smooth real functions numerically using Gauss-Legendre quadratures.</li>
+ </ul>
+ In addition, <b>libinum</b> defines the following structures:
+ <ul>
+ <li>Variable-length arrays.</li>
+ <li>Single variable and multivariate polynomials.</li>
+ </ul>
+ </p>
+
+ <p>
+ As a general rule, the functions and structures can be used with several different data types. For instance, the root finding and integration functions can manipulate double precision, extended precision, or multi-precision floating point numbers. See <a href="#sec_datatypes">Data types</a> for details.
+ </p>
+
+ <h2 class="section" id="sec_datatypes">Data types</h2>
+ <p>
+ One of the guiding principles of <b>libinum</b> is that it should should not push a specific data type on users. If, hypothetically, the computation being carried out requires the precision of the floating point numbers to be large, then multi-precision floating point numbers might be preferable to double precision numbers. If, instead, computation time is more important than precision, then extended precision floats may be preferred. The structures and functions defined in <b>libinum</b>, therefore, support various data types.
+ </p>
+
+ <p>
+ We will now briefly discuss the data types that may be used to represent numbers.
+ </p>
+
+
+ <h3 class="subsection" id="subsec_int">Integers</h3>
+ <h4>Fixed-precision integers</h4>
+ <p>
+ The standard integer types of the C language are <code>char</code>, <code>short int</code>, <code>int</code>, <code>long int</code> and <code>long long int</code>, as well as their <code>unsigned</code> counterparts. The number of bits, and, in consequence, the available range of integers, of each of these types, is platform-dependent. In cases where this could be problematic, fixed-precision integers can be used: with 8 bits: <code>int8_t</code>, 16: <code>int16_t</code>, 32: <code>int32_t</code> and 64: <code>int64_t</code>.
+ </p>
+ <p>
+ <b>libinum</b> provides a function, <code>print_datatype_info()</code>, that prints the equivalence table between <code>char</code>, <code>short int</code>, <code>int</code>, <code>long int</code> and <code>long long int</code> and <code>int8_t</code>, <code>int16_t</code>, <code>int32_t</code> and <code>int64_t</code> for the implementation of the C library used to compile <b>libinum</b>.
+ </p>
+
+ <h4>Multi-precision integers</h4>
+ <p>
+ In cases where the required number of bits of integers exceeds 64, one can use <i>multi-precision integers</i>, which can be as large as will fit in memory. However, computation times can greatly increase when using multi-precision integers. The implementation used in <b>libinum</b> is provided by the <a href="http://gmplib.org">GNU GMP</a> library.
+ </p>
+
+
+
+ <h3 class="subsection" id="subsec_float">Floating point numbers</h3>
+ <p>
+ Let us first start with a description of floating point numbers. A real number \(x\) is approximated, with a <i>precision</i> of \(m\) bits, as a collection of three numbers: the <i>sign</i> \(s\in\{-1,1\}\); <i>mantissa</i>, whose binary expansion is denoted by \(a_1\cdots a_m\); and <i>exponent</i> \(e\in\mathbb Z\). The approximate value of the number \(x\) is obtained from its sign, mantissa and exponent by
+ $$
+ x=s\times a_1.a_2\cdots a_m\times2^e.
+ $$
+ The <i>precision</i> of a floating point number is the number of bits allocated to its sign and mantissa (since \(a_1\) is necessarily equal to \(1\), it is not stored, so the precision of \(x\) is \(m\) instead of \(m+1\)).
+ </p>
+ <p> In <b>libinum</b>, floating point number may either be double, extended or multi-precision numbers.
+
+ <h4>Double precision floating point numbers</h4>
+ <p>
+ Double precision floats are represented using the <code>double</code> type.
+ </p>
+ <p>
+ The precision and maximal and minimal values of the exponent of <code>double</code> floats depends on the compiler. Their values can be printed using the <b>libinum</b> function <code>print_datatype_info()</code>.
+ </p>
+ <p>
+ For example, using version 5.3.0 of the <a href="https://gcc.gnu.org/">GNU GCC</a> compiler on the x86-64 architecture, the precision is of 53 bits (i.e. 15 decimal digits), and the maximal and minimal values of the exponent are 1024 and -1021.
+ </p>
+
+ <h4>Extended precision floating point numbers</h4>
+ <p>
+ Extended precision floats are represented using the <code>long double</code> type. They require more memory than double precision floats, and, as a consequence, slightly more computation time.
+ </p>
+ <p>
+ The precision and maximal and minimal values of the exponent of <code>long double</code> floats depends on the compiler. Their values can be printed using the <b>libinum</b> function <code>print_datatype_info()</code>.
+ </p>
+ <p>
+ For example, using version 5.3.0 of the <a href="https://gcc.gnu.org/">GNU GCC</a> compiler on the x86-64 architecture, the precision is of 64 bits (i.e. 18 decimal digits), and the maximal and minimal values of the exponent are 16384 and -16381.
+ </p>
+
+ <h4>Multi-precision floating point numbers</h4>
+ <p>
+ A multi-precision floating point number is a floating point number whose precision can be set to an arbitrary value (until the number fills up the entire memory of the computer). In <b>libinum</b>, multi-precision floats are implemented using the <a href="http://mpfr.org">GNU MPFR</a> library, and will be called <i> MPFR floats</i>.
+ </p>
+ <p>
+ The precision of MPFR floats can be set using the function <code>mpfr_set_default_prec</code> (see the MPFR library <a href="http://www.mpfr.org/mpfr-current/mpfr.html#index-mpfr_005fset_005fdefault_005fprec">documentation</a> for details). The default value of the precision is 53 bits (as of version 3.1.4 of the MPFR library).
+ </p>
+ <p>
+ In addition, the maximal value (in absolute value) of the exponent can be controlled by setting <i>emax</i> using the function <code>mpfr_set_emax</code> (see the MPFR library <a href="http://www.mpfr.org/mpfr-current/mpfr.html#index-mpfr_005fset_005femax">documentation</a> for details).
+ </p>
+ <p>
+ Depending on the MPFR implementation, the precision and emax can either be an <code>int</code> or a <code>long int</code>, so its maximal and minimal values are platform dependent. The <b>libinum</b> function <code>print_datatype_info()</code> prints which it is.
+ </p>
+
+
+ <h2 class="section" id="sec_algorithms">Algorithms</h2>
+ <p>
+ What follows is a detailed description of the functions that implement the algorithms supported by <b>libinum</b>.
+ </p>
+
+ <h3 class="subsection" id="subsec_root_finding">Root finding</h3>
+ <p>
+ <b>libinum</b> can compute the root of smooth real functions using the Newton-Raphson algorithm. The algorithm converges quickly, provided an adequate approximation of the root in provided, and that the root is not located at a minimum of the function.
+ </p>
+
+ <h4>Description</h4>
+ <p>
+ Given a function \(f\) and a real number \(x_0\), the algorithm produces a sequence \((x_n)\) which, provided the algorithm converges, tends to a root of \(f\). The sequence is defined as
+ $$
+ x_{n+1}=x_n-\frac{f(x_{n})}{f'(x_{n})}
+ $$
+ where \(f'\) denotes the derivative of \(f\). The following estimate holds:
+ $$
+ |x_{n+1}-x_n|\leqslant \frac12|x_n-x_{n-1}|^2\sup_{\xi\in[x_{n+1},x_n]}\frac{f''(\xi)}{f'(\xi)}
+ $$
+ so that, provided \(f\) is smooth and its derivative does not vanish in the intervals \([x_{n+1},x_n]\), the algorithm converges <i>quadratically</i>.
+ </p>
+
+ <h4>Implementation</h4>
+ <p>
+ This algorithm has been implemented using double, extended and multi-precision floats.
+ <?php
+ $typenames=["double", "ldouble", "mpfr"];
+ $floattypes=["double", "long double", "mpfr_t"];
+ ?>
+ </p>
+
+ <ul>
+ <li id="func_root_newton">
+ <div style="vertical-align: top;">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $FLOATTYPE=$floattypes[$i];
+ print("
+ <code>
+ <div style=\"margin-bottom:20pt\">
+ <div id=\"func_root_newton_${TYPENAME}\" style=\"display: inline-block; vertical-align: top;\">
+ int root_newton_${TYPENAME}(
+ </div>
+ <div id=\"func_root_newton_${TYPENAME}\" style=\"display: inline-block; vertical-align: top;\">
+ ${FLOATTYPE}* out,<br>
+ int (*func)(${FLOATTYPE}*, ${FLOATTYPE}, void*),<br>
+ int (*deriv_func)(${FLOATTYPE}*, ${FLOATTYPE}, void*),<br>
+ ${FLOATTYPE} init,<br>
+ ${FLOATTYPE} tolerance,<br>
+ int maxiter,<br>
+ void* extra_args)
+ </div>
+ </div>
+ </code>
+ ");
+ }
+ ?>
+ </div>
+
+ <br>
+ <b>Description</b>: Compute a numerical approximation for the root.<br>
+ <br>
+
+ <b>Arguments</b>:
+ <ul>
+ <li>
+ <code>out</code>: pointer to the number to which the result will be written. If the number requires initialization (e.g. if it is an <code>mpfr_t</code>), then it must be initialized.
+ </li>
+ <li>
+ <code>func</code>: pointer to the function that computes \(f(x)\). It must be in the format specified in <a href="#subsec_functions">functions</a>.
+ </li>
+ <li>
+ <code>deriv_func</code>: pointer to the function that computes the derivative of \(f\). It must be in the format specified in <a href="#subsec_functions">functions</a>.
+ </li>
+ <li>
+ <code>init</code>: the value of \(x_0\).
+ </li>
+ <li>
+ <code>tolerance</code>: the algorithm halts when \(|x_{n+1}-x_n|\leqslant\)<code>tolerance</code>. <code>tolerance</code> thus provides control over the error of the algorithm.
+ </li>
+ <li>
+ <code>maxiter</code>: maximum number of iterations. The algorithm gives up if this number is reached and throws a <code>LIBINUM_ERROR_MAXITER</code> exception.
+ </li>
+ <li>
+ <code>extra_args</code>: pointer to the extra arguments to be passed to the functions <code>*func</code> and <code>*deriv_func</code> when they are evaluated.
+ </li>
+ </ul>
+ <br>
+ <b>Return value</b>: returns <code>0</code> on success, and
+ <ul>
+ <li><code>LIBINUM_ERROR_MAXITER</code> if the maximal number of iterations was reached.</li>
+ <li><code>LIBINUM_ERROR_NAN</code> if any of the evaluations of <code>*func</code> or <code>*deriv_func</code> returned <code>nan</code> or <code>infinity</code>, or if any of the evaluations of <code>*deriv_func</code> returned <code>0</code>.</li>
+ </ul>
+ </li>
+ <br><br>
+
+ <li id="func_root_newton_inplace">
+ <div style="vertical-align: top;">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $FLOATTYPE=$floattypes[$i];
+ print("
+ <code>
+ <div style=\"margin-bottom:20pt\">
+ <div id=\"func_root_newton_inplace_${TYPENAME}\" style=\"display: inline-block; vertical-align: top\">
+ int root_newton_inplace_${TYPENAME}(
+ </div>
+ <div style=\"display: inline-block; vertical-align: top\">
+ ${FLOATTYPE}* out,<br>
+ int (*func)(${FLOATTYPE}*, ${FLOATTYPE}, void*),<br>
+ int (*deriv_func)(${FLOATTYPE}*, ${FLOATTYPE}, void*),<br>
+ ${FLOATTYPE} tolerance,<br>
+ int maxiter,<br>
+ void* extra_args)<br>
+ </div>
+ </div>
+ </code>
+ ");
+ }
+ ?>
+ </div>
+
+ <br>
+ <b>Description</b>: Similar to <a href="#func_root_newton"><code>root_newton_*</code></a> except that the value of \(x_0\) is passed to the function in the argument <code>out</code>.
+ </li>
+ </ul>
+
+ <h3 class="subsection" id="subsec_integrals">Integrals</h3>
+ <p>
+ <b>libinum</b> can compute definite integrals of smooth real functions using Gauss-Legendre quadratures.
+ </p>
+
+ <h4>Description</h4>
+ <p>
+ The main idea of Gauss-Legendre quadratures is to find a set of <i>abcissa</i> \(\{t_1,\cdots,t_N\}\in[-1,1]^N\) and <i>weights</i> \(\{w_1,\cdots,w_N\}\in\mathbb R^N\) such that, if \(f\) were a polynomial of degree \(\leqslant2N-1\), then the integral would be equal to a discrete sum:
+ $$
+ \int_{a}^bdx\ f(x)=\sum_{i=1}^Nw_if\left(\frac{a+b}2+t_i\frac{b-a}2\right).
+ $$
+ In the general case, if \(f\) is \(\mathcal C^{2N}\), then
+ $$
+ \left|\int_{a}^bdx\ f(x)-\sum_{i=1}^Nw_if\left(\frac{a+b}2+t_i\frac{b-a}2\right)\right|
+ \leqslant \frac{N!^4}{(2N+1)(2N)!^3}\sup_{x\in[a,b]}\frac{d^{2N}f(x)}{dx^{2N}}.
+ $$
+ The number \(N\) is called the <i>order</i> of the integration.
+ </p>
+
+ <p>
+ As it turns out, the abcissa are the roots of the \(N\)-th Legendre polynomial \(L_N\), defined by the recursive equation
+ $$
+ (N+1)L_{N+1}(x)=(2N+1)xL_N(x)-NL_{N-1}(x),\quad
+ L_0(x)=1,\quad L_1(x)=x
+ $$
+ and the weights are
+ $$
+ w_i=\frac2{(1-x_i^2)L_N'(t_i)}.
+ $$
+ </p>
+
+ <h4>Implementation</h4>
+ <p>
+ This algorithm has been implemented using double, extended and multi-precision floats
+ <?php
+ $typenames=["double", "ldouble", "mpfr"];
+ $floattypes=["double", "long double", "mpfr_t"];
+ $typenames_init=["mpfr"];
+ $floattypes_init=["mpfr_t"];
+ ?>
+ <ul>
+
+ <li id="func_integrate_gauss">
+ <div style="vertical-align: top;">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $FLOATTYPE=$floattypes[$i];
+ print("
+ <code>
+ <div style=\"margin-bottom:20pt\">
+ <div id=\"func_integrate_gauss_${TYPENAME}\" style=\"display: inline-block; vertical-align: top\">
+ int integrate_gauss_${TYPENAME}(
+ </div>
+ <div style=\"display: inline-block; vertical-align: top\">
+ ${FLOATTYPE}* out,<br>
+ int (*func)(${FLOATTYPE}*, ${FLOATTYPE}, void*),<br>
+ ${FLOATTYPE} lower,<br>
+ ${FLOATTYPE} upper,<br>
+ array_${TYPENAME} abcissa,<br>
+ array_${TYPENAME} weights,<br>
+ void* extra_args)
+ </div>
+ </div>
+ </code>
+ ");
+ }
+ ?>
+ </div>
+
+ <br>
+ <b>Description</b>: Compute a numerical approximation for the integral of a real function using Gauss quadratures.<br>
+ <br>
+
+ <b>Arguments</b>:
+ <ul>
+ <li>
+ <code>out</code>: pointer to the number to which the result will be written. If the number requires initialization (e.g. if it is an <code>mpfr_t</code>), then it must be initialized.
+ </li>
+ <li>
+ <code>func</code>: pointer to the function that computes the integrand \(f(x)\). It must be in the format specified in <a href="#subsec_functions">functions</a>.
+ </li>
+ <li>
+ <code>lower</code>: lower bound of the integration.
+ </li>
+ <li>
+ <code>upper</code>: upper bound of the integration.
+ </li>
+ <li>
+ <code>abcissa</code>: the abcissa used to compute the integral using Gauss quadratures. For Gauss-Legendre integration, they can be computed by the function <a href="#func_gauss_legendre_weights"><code>gauss_legendre_weights</code></a>.
+ </li>
+ <li>
+ <code>weights</code>: the weights used to compute the integral using Gauss quadratures. For Gauss-Legendre integration, they can be computed by the function <a href="#func_gauss_legendre_weights"><code>gauss_legendre_weights</code></a>.
+ </li>
+ <li>
+ <code>extra_args</code>: pointer to the extra arguments to be passed to the function <code>*func</code> when it is evaluated (see <a href="#subsec_functions">functions</a>).
+ </li>
+ </ul>
+ <br>
+ <b>Return value</b>: returns <code>0</code> on success, and
+ <ul>
+ <li><code>LIBINUM_ERROR_NAN</code> if any of the evaluations of <code>*func</code> returned <code>nan</code> or <code>infinity</code>.</li>
+ <li><code>LIBINUM_ERROR_SIZE_MISMATCH</code> if the lengths of the vectors <code>abcissa</code> and <code>weights</code> are different.</li>
+ </ul>
+ </li>
+ <br><br>
+
+ <li id="func_integrate_gauss_multithread">
+ <div style="vertical-align: top;">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $FLOATTYPE=$floattypes[$i];
+ print("
+ <code>
+ <div style=\"margin-bottom:20pt\">
+ <div id=\"func_integrate_gauss_multithread_${TYPENAME}\" style=\"display: inline-block; vertical-align: top\">
+ int integrate_gauss_multithread_${TYPENAME}(
+ </div>
+ <div style=\"display: inline-block; vertical-align: top;\">
+ ${FLOATTYPE}* out,<br>
+ int (*func)(${FLOATTYPE}*, ${FLOATTYPE}, void*),<br>
+ ${FLOATTYPE} lower,<br>
+ ${FLOATTYPE} upper,<br>
+ array_${TYPENAME} abcissa,<br>
+ array_${TYPENAME} weights,<br>
+ void* extra_args,<br>
+ unsigned int threads,<br>
+ array_pthread_t* thread_ids)
+ </div>
+ </div>
+ </code>
+ ");
+ }
+ ?>
+ </div>
+
+ <b>Description</b>: Multithreaded version of <a href="#func_integrate_gauss"><code>integrate_gauss_*</code></a>, in which function calls are performed in parallel.<br>
+ <br>
+
+ <b>Arguments</b>: Same as <a href="#func_integrate_gauss"><code>integrate_gauss_*</code></a>, except for
+ <ul>
+ <li>
+ <code>threads</code>: number of threads to use for the computation.
+ </li>
+ <li>
+ <code>thread_ids</code>: pointer to an array in which the id of each thread is written to. The array must not be initialized. This array can then be used by each thread to identify themselves.
+ </li>
+ </ul>
+ <br>
+ <b>Return value</b>: Same as <a href="#func_integrate_gauss"><code>integrate_gauss_*</code></a>.
+ </li>
+ <br><br>
+
+ <li id="func_integrate_gauss_smarttmp">
+ <div style="vertical-align: top;">
+ <?php
+ for ($i=0; $i<count($typenames_init); $i++){
+ $TYPENAME=$typenames_init[$i];
+ $FLOATTYPE=$floattypes_init[$i];
+ print("
+ <code>
+ <div style=\"margin-bottom:20pt\">
+ <div id=\"func_integrate_gauss_smarttmp_${TYPENAME}\" style=\"display: inline-block; vertical-align: top\">
+ int integrate_gauss_smarttmp_${TYPENAME}(
+ </div>
+ <div style=\"display: inline-block; vertical-align: top;\">
+ ${FLOATTYPE}* out,<br>
+ int (*func)(${FLOATTYPE}*, ${FLOATTYPE}, void*),<br>
+ ${FLOATTYPE} lower,<br>
+ ${FLOATTYPE} upper,<br>
+ array_${TYPENAME} abcissa,<br>
+ array_${TYPENAME} weights,<br>
+ array_${TYPENAME}* tmps,<br>
+ void* extra_args)
+ </div>
+ </div>
+ </code>
+ ");
+ }
+ ?>
+ </div>
+
+ <b>Description</b>: Similar to <a href="#func_integrate_gauss"><code>integrate_gauss_*</code></a>, except that, if temporary floats are needed during the computation, they are saved to an array so that they can be re-used later on. This is useful to perform repeated integrations, in which it would be costly to re-allocate memory for temporary floats. When using this function, temporary floats are allocated as needed, but they are not discarded.<br>
+ <br>
+
+ <b>Arguments</b>: Same as <a href="#func_integrate_gauss"><code>integrate_gauss_*</code></a>, except for
+ <ul>
+ <li>
+ <code>tmps</code>: pointer to an array that is used to store temporary floats. The array must be initialized beforehand. When temporary floats are needed, the array is checked for available floats. If enough of them are already present in the array, then the routine uses them, if not, it enlarges the array and allocates as many extra floats as is needed. The floats in the array can then be re-used for other purposes.
+ </li>
+ </ul>
+ <br>
+ <b>Return value</b>: Same as <a href="#func_integrate_gauss"><code>integrate_gauss_*</code></a>.
+ </li>
+ <br><br>
+
+ <li id="func_integrate_gauss_smarttmp_multithread">
+ <div style="vertical-align: top;">
+ <?php
+ for ($i=0; $i<count($typenames_init); $i++){
+ $TYPENAME=$typenames_init[$i];
+ $FLOATTYPE=$floattypes_init[$i];
+ print("
+ <code>
+ <div style=\"margin-bottom:20pt\">
+ <div id=\"func_integrate_gauss_smarttmp_multithread_${TYPENAME}\" style=\"display: inline-block; vertical-align: top\">
+ int integrate_gauss_smarttmp_multithread_${TYPENAME}(
+ </div>
+ <div style=\"display: inline-block; vertical-align: top;\">
+ ${FLOATTYPE}* out,<br>
+ int (*func)(${FLOATTYPE}*, ${FLOATTYPE}, void*),<br>
+ ${FLOATTYPE} lower,<br>
+ ${FLOATTYPE} upper,<br>
+ array_${TYPENAME} abcissa,<br>
+ array_${TYPENAME} weights,<br>
+ void* extra_args,<br>
+ unsigned int threads,<br>
+ array_pthread_t* thread_ids)
+ </div>
+ </div>
+ </code>
+ ");
+ }
+ ?>
+ </div>
+
+ <b>Description</b>: Multithreaded version of <a href="#func_integrate_gauss_smarttmp"><code>integrate_gauss_smarttmp_*</code></a>, in which function calls are performed in parallel.<br>
+ <br>
+
+ <b>Arguments</b>: Same as <a href="#func_integrate_gauss"><code>integrate_gauss_smarttmp_*</code></a>, except for
+ <ul>
+ <li>
+ <code>threads</code>: number of threads to use for the computation.
+ </li>
+ <li>
+ <code>thread_ids</code>: pointer to an array in which the id of each thread is written to. The array must not be initialized. This array can then be used by each thread to identify themselves.
+ </li>
+ </ul>
+ <br>
+ <b>Return value</b>: Same as <a href="#func_integrate_gauss"><code>integrate_gauss_*</code></a>.
+ </li>
+ <br><br>
+
+
+ <li id="func_gauss_legendre_weights">
+ <div style="vertical-align: top;">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $FLOATTYPE=$floattypes[$i];
+ print("
+ <code>
+ <div style=\"margin-bottom:20pt\">
+ <div id=\"func_gauss_legendre_weights_${TYPENAME}\" style=\"display: inline-block; vertical-align: top\">
+ gauss_legendre_weights_${TYPENAME}(
+ </div>
+ <div style=\"display: inline-block; vertical-align: top\">
+ unsigned int order,<br>
+ ${FLOATTYPE} tolerance,<br>
+ unsigned int maxiter,<br>
+ array_${TYPENAME}* abcissa,<br>
+ array_${TYPENAME}* weights)
+ </div>
+ </div>
+ </code>
+ ");
+ }
+ ?>
+ </div>
+
+ <b>Description</b>: Compute the Gauss-Legendre abcissa and weights.<br>
+ <br>
+
+ <b>Arguments</b>:
+ <ul>
+ <li>
+ <code>order</code>: the order \(N\) of the integration.
+ </li>
+ <li>
+ <code>tolerance</code>: tolerance for the Newton algorithm used to compute the roots of the Legendre polynomial (see <a href="#func_root_newton"><code>root_newton</code></a>).
+ </li>
+ <li>
+ <code>maxiter</code>: the maximal number of steps to compute before giving up.
+ </li>
+ <li>
+ <code>abcissa</code>: pointer to the <a href="#subsec_array">array</a> in which to write the abcissa. It must not be initialized.
+ </li>
+ <li>
+ <code>weights</code>: pointer to the <a href="#subsec_array">array</a> in which to write the weights. It must not be initialized.
+ </li>
+ </ul>
+ <br>
+ <b>Return value</b>: returns <code>0</code> on success, and
+ <ul>
+ <li><code>LIBINUM_ERROR_MAXITER</code> if, when computing the roots of the Legendre polynomial using a Newton iteration, the maximal number of iterations was reached.</li>
+ </ul>
+ </li>
+ </ul>
+
+ <h2 class="section" id="sec_types">Types</h2>
+ <p>
+ What follows is a detailed description of the C types defined in <b>libinum</b>.
+ </p>
+
+ <h3 class="subsection" id="subsec_array"><code>array</code></h3>
+ <p>Array that can be dynamically resized.</p>
+
+ <?php
+ $typenames=["int", "uint", "double", "ldouble", "mpfr", "2_mpfr", "char", "str", "polynomial_double", "polynomial_ldouble", "polynomial_mpfr", "pthread_t"];
+ $types=["int", "unsigned int", "double", "long double", "mpfr_t", "array_mpfr", "char", "array_char", "polynomial_double", "polynomial_ldouble", "polynomial_mpfr", "pthread_t"];
+
+ $typenames_init=["mpfr", "2_mpfr", "str", "polynomial_double", "polynomial_ldouble", "polynomial_mpfr"];
+ $types_init=["mpfr_t", "array_mpfr", "array_char", "polynomial_double", "polynomial_ldouble", "polynomial_mpfr"];
+
+ $typenames_print=["int", "uint", "double", "ldouble", "mpfr", "2_mpfr", "char", "str", "polynomial_double", "polynomial_ldouble", "polynomial_mpfr"];
+ $types_print=["int", "unsigned int", "double", "long double", "mpfr_t", "array_mpfr", "char", "array_char", "polynomial_double", "polynomial_ldouble", "polynomial_mpfr"];
+
+ $typenames_ifeq=["int", "uint", "double", "ldouble", "mpfr", "2_mpfr", "char", "str", "pthread_t"];
+ $types_ifeq=["int", "unsigned int", "double", "long double", "mpfr_t", "array_mpfr", "char", "array_char", "pthread_t"];
+ $typenames_iflt=["int", "uint", "double", "ldouble", "mpfr", "2_mpfr", "char", "str", "pthread_t"];
+ $types_iflt=["int", "unsigned int", "double", "long double", "mpfr_t", "array_mpfr", "char", "array_char", "pthread_t"];
+ $typenames_ifgt=["int", "uint", "double", "ldouble", "mpfr", "2_mpfr", "char", "str", "pthread_t"];
+ $types_ifgt=["int", "unsigned int", "double", "long double", "mpfr_t", "array_mpfr", "char", "array_char", "pthread_t"];
+ $typenames_ifltgt=["int", "uint", "double", "ldouble", "mpfr", "2_mpfr", "char", "str", "pthread_t"];
+ $types_ifltgt=["int", "unsigned int", "double", "long double", "mpfr_t", "array_mpfr", "char", "array_char", "pthread_t"];
+ ?>
+
+ <h4>Structure</h4>
+ Arrays of several types of objects are defined. They are structures, with the following keys:
+
+ <ul>
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $TYPE=$types[$i];
+ print("
+ <li id=\"struct_array_${TYPENAME}\">
+ <code>array_${TYPENAME}</code>:
+ <code>{ ${TYPE}* values, unsigned int length, unsigned int memory }</code>
+ </li>
+ ");
+ }
+ ?>
+ </ul>
+ where the keys correspond to
+ <ul>
+ <li><code>values</code>: the array in which the objects are stored</li>
+ <li><code>length</code>: the number of elements in the array</li>
+ <li><code>memory</code>: the number of elements allocated to the array</li>
+ </ul>
+ <code>array_*</code>'s must be initialized before they are used, and freed when they are no longer needed. khen the array is freed, the objects it contains are freed as well.
+
+ <h4>Functions</h4>
+ <ul>
+ <li id="func_array_init">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $TYPE=$types[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_array_init_${TYPENAME}\">int array_${TYPENAME}_init(array_${TYPENAME}* array, unsigned int memory)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ initialize the array pointed to by <code>array</code>, and allocate <code>memory</code> elements.
+ </li>
+ <br>
+ <li id="func_array_free">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $TYPE=$types[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_array_free_${TYPENAME}\">int array_${TYPENAME}_free(array_${TYPENAME} array)</code><br>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ free the array <code>array</code>.
+ </li>
+ <br>
+ <li id="func_array_free_vects">
+ <?php
+ for ($i=0; $i<count($typenames_init); $i++){
+ $TYPENAME=$typenames_init[$i];
+ $TYPE=$types_init[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_array_free_vects_${TYPENAME}\">int array_${TYPENAME}_free_vects(array_${TYPENAME} array)</code><br>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ free the memory pointed to by <code>array.values</code>, but do not free the elements of the array.
+ </li>
+ <br>
+ <li id="func_array_resize">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $TYPE=$types[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_array_resize_${TYPENAME}\">int array_${TYPENAME}_resize(array_${TYPENAME}* array, unsigned int newsize)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ copy the array pointed to by <code>array</code> to another with memory <code>newsize</code>.
+ </li>
+ <br>
+ <li id="func_array_append">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $TYPE=$types[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_array_append_${TYPENAME}\">int array_${TYPENAME}_append(${TYPE} value, array_${TYPENAME}* array)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ append <code>value</code> to the end of the array pointed to by <code>array</code>. Resize the array if needed.
+ </li>
+ <br>
+ <li id="func_array_append_noinit">
+ <?php
+ for ($i=0; $i<count($typenames_init); $i++){
+ $TYPENAME=$typenames_init[$i];
+ $TYPE=$types[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_array_append_noinit_${TYPENAME}\">int array_${TYPENAME}_append_noinit(${TYPE} value, array_${TYPENAME}* array)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ append <code>value</code> to the end of the array pointed to by <code>array</code>. Do not initialize the new value, instead, copy <code>value</code> to the end of <code>*array</code>. <code>value</code> must not be freed, since it will be freed when <code>*array</code> is. Resize the array if needed.
+ </li>
+ <br>
+ <li id="func_array_concat">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $TYPE=$types[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_array_concat_${TYPENAME}\">int array_${TYPENAME}_concat(array_${TYPENAME} input, array_${TYPENAME}* output)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ append the values in <code>input</code> to the end of the array pointed to by <code>output</code>. Resize the array if needed.
+ </li>
+ <br>
+ <li id="func_array_cpy">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $TYPE=$types[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_array_cpy_${TYPENAME}\">int array_${TYPENAME}_cpy(array_${TYPENAME} input, array_${TYPENAME}* output)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ copy <code>input</code> to the array pointed to by <code>output</code>. Initializes <code>*output</code>.
+ </li>
+ <br>
+ <li id="func_array_cpy_noinit">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $TYPE=$types[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_array_cpy_noinit_${TYPENAME}\">int array_${TYPENAME}_cpy_noinit(array_${TYPENAME} input, array_${TYPENAME}* output)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ copy <code>input</code> to the array pointed to by <code>output</code>. Does not initialize <code>*output</code>, so <code>*output</code> must be initialized ahead of time, and its memory must be larger or equal to the length of <code>input</code>. Returns <code>LIBINUM_ERROR_SIZE_MISMATCH</code> if the memory of <code>*output</code> is smaller than the length of <code>input</code>.
+ </li>
+ <br>
+ <li id="func_array_subarray">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $TYPE=$types[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_array_subarray_${TYPENAME}\">int array_${TYPENAME}_subarray(array_${TYPENAME} array, unsigned int begin, unsigned int end, array_${TYPENAME}* subarray)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ extract the sub-array of <code>array</code> whose indices are larger or equal to <code>begin</code> and smaller or equal to <code>end</code>. Returns <code>LIBINUM_ERROR_ILLEGAL_MEMORY_ACCESS</code> if the subarray does not exist.
+ </li>
+ <br>
+ <li id="func_array_print">
+ <?php
+ for ($i=0; $i<count($typenames_print); $i++){
+ $TYPENAME=$typenames_print[$i];
+ $TYPE=$types_print[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_array_print_${TYPENAME}\">int array_${TYPENAME}_print(array_${TYPENAME} array)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ print the elements of <code>array</code>.
+ </li>
+ </ul>
+
+ <h4>Extra functions for arrays of ordered objects</h4>
+ In addition, we define the following ordering for the possible objects in an array:
+ <ul>
+ <li>the obvious ordering for <code>int, unsigned int, double, long double, mpfr, char</code></li>
+ <li>lexicographical ordering for <code>array_char</code></li>
+ <li>no ordering for <code>polynomial_*</code>.</li>
+ </ul>
+ If the ordering is defined, then the following functions are defined:
+
+ <ul>
+ <li id="func_array_append_unique">
+ <?php
+ for ($i=0; $i<count($typenames_ifeq); $i++){
+ $TYPENAME=$typenames_ifeq[$i];
+ $TYPE=$types_ifeq[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_array_append_unique_${TYPENAME}\">int array_${TYPENAME}_append_unique(${TYPE} value, array_${TYPENAME}* array)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ if <code>value</code> is not already present in the array pointed to by <code>array</code>, then append it. Resize the array if needed.
+ </li>
+ <br>
+ <li id="func_array_concat_unique">
+ <?php
+ for ($i=0; $i<count($typenames_ifeq); $i++){
+ $TYPENAME=$typenames_ifeq[$i];
+ $TYPE=$types_ifeq[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_array_concat_unique_${TYPENAME}\">int array_${TYPENAME}_concat_unique(array_${TYPENAME} input, array_${TYPENAME}* output)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ append the values in <code>input</code> that are not already present in the array pointed to by <code>output</code>. Resize the array if needed.
+ </li>
+ <br>
+ <li id="func_array_find">
+ <?php
+ for ($i=0; $i<count($typenames_ifeq); $i++){
+ $TYPENAME=$typenames_ifeq[$i];
+ $TYPE=$types_ifeq[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_array_find_${TYPENAME}\">int array_${TYPENAME}_find(${TYPE} val, array_${TYPENAME} array)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ search for <code>val</code> in <code>array</code>. Returns the index of <code>val</code> in <code>array</code> if it is present, and <code>-1</code> if it is not.
+ </li>
+ <br>
+ <li id="func_array_sort">
+ <?php
+ for ($i=0; $i<count($typenames_iflt); $i++){
+ $TYPENAME=$typenames_iflt[$i];
+ $TYPE=$types_iflt[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_array_sort_${TYPENAME}\">int array_${TYPENAME}_sort(array_${TYPENAME} array)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ sort the elements of <code>array</code> from smallest to largest (for numerical values, the ordering relation is the usual one, for characters and strings, the lexicographical ordering is used). The sorting is performed in place. The <i>quicksort</i> algorithm is used.
+ </li>
+ <br>
+ <li id="func_array_sort_sub">
+ <?php
+ for ($i=0; $i<count($typenames_iflt); $i++){
+ $TYPENAME=$typenames_iflt[$i];
+ $TYPE=$types_iflt[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_array_sort_sub_${TYPENAME}\">int array_${TYPENAME}_sort_sub(array_${TYPENAME} array, unsigned int begin, unsigned int end)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ sort the elements of the sub-array of <code>array</code> consisting of the elements whose index is larger or equal than <code>begin</code> and smaller or equal than <code>end</code>. The sorting is performed in place. The <i>quicksort</i> algorithm is used.
+ </li>
+ <br>
+ <li id="func_array_cmp">
+ <?php
+ for ($i=0; $i<count($typenames_ifltgt); $i++){
+ $TYPENAME=$typenames_ifltgt[$i];
+ $TYPE=$types_ifltgt[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_array_cmp_${TYPENAME}\">int array_${TYPENAME}_cmp(array_${TYPENAME} array1, array_${TYPENAME} array2)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ compare <code>array1</code> and <code>array2</code>. Returns <code>0</code> if both arrays are equal (that is, if their elements are the same, and in the same order), <code>-1</code> if <code>array1</code> is smaller than <code>array2</code> in lexicographical order, and <code>1</code> if <code>array1</code> is smaller than <code>array2</code> in lexicographical order.
+ </li>
+ </ul>
+
+ <h4>Extra functions for <code>array_char</code></h4>
+ In addition, the following functions are defined for <code>array_char</code>.
+ <ul>
+ <li id="func_array_char_append_str">
+ <code>int array_char_append_str(char* str, array_char* output)</code><br>
+ append the characters in <code>str</code> to the end of the array pointed to by <code>output</code>. Resize the array if needed.
+ </li>
+ <li id="func_array_char_to_str">
+ <code>int array_char_to_str(array_char input, char** output)</code><br>
+ copy the string in <code>input</code> to the string pointed to by <code>output</code>. Initializes <code>*output</code>.
+ </li>
+ <li id="func_array_char_to_str_noinit">
+ <code>char* array_char_to_str(array_char* input)</code><br>
+ convert the array pointed to by <code>input</code> to a string, and return it. Appends <code>'\0'</code> at the end of <code>*input</code>. The string thus generated should not be freed, since it is actually a pointer to <code>input->str</code>, which is freed when <code>*input</code> is.
+ </li>
+ <li id="func_str_to_array_char">
+ <code>int str_to_array_char(char* str, array_char* output)</code><br>
+ copy the string <code>input</code> to the array pointed to by <code>output</code>. Initializes <code>*output</code>.
+ </li>
+ <li id="func_array_char_cmp_str">
+ <code>int array_char_cmp_str(array_char array_char, char* str)</code><br>
+ compare the string in <code>array_char</code> and the string <code>str</code>. Returns <code>1</code> if the strings are identical, and <code>0</code> if not.
+ </li>
+ <li id="func_array_char_snprintf">
+ <code>int array_char_snprintf(array_char* output, char* fmt)</code><br>
+ reads the format <code>fmt</code> and appends the output to the array pointed to by <code>output</code>. The format should follow the specifications of the standard C function <code>printf</code>.
+ </li>
+ </ul>
+
+
+ <h3 class="subsection" id="subsec_polynomial"><code>polynomial</code></h3>
+ <p>A polynomial with real coefficients. A <code>polynomial</code> is represented as an array of coefficients and an array of exponents. For example \(1+x+2x^2\) is represented as <code>({1.,1.,2.},{0,1,2})</code>.</p>
+
+ <h4>Structure</h4>
+ The coefficients of polynomials can be double, extended, or multi-precision floats, and their exponents are unsigned integers. Polynomials are represented as structures, with the following keys:
+
+ <?php
+ $typenames=["double", "ldouble", "mpfr"];
+ $coeftypes=["double", "long double", "mpfr_t"];
+ $coeftypenames=["double", "ldouble", "mpfr"];
+ $exptypes=["unsigned int", "unsigned int", "unsigned int"];
+ $exptypenames=["uint", "uint", "uint"];
+ ?>
+
+ <ul>
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $COEFTYPENAME=$coeftypenames[$i];
+ $EXPTYPE=$exptypes[$i];
+ $EXPTYPENAME=$exptypenames[$i];
+ print("
+ <li id=\"struct_polynomial_${TYPENAME}\">
+ <code>polynomial_${TYPENAME}</code>:
+ <code>{ array_${COEFTYPENAME} coefficients, array_${EXPTYPENAME} orders }</code>
+ </li>
+ ");
+ }
+ ?>
+ </ul>
+ where the keys correspond to
+ <ul>
+ <li><code>coefficients</code>: array of coefficients</li>
+ <li><code>orders</code>: array of exponents.</li>
+ </ul>
+ <code>polynomial_*</code>'s must be initialized before they are used, and freed when they are no longer needed.
+
+ <h4>Functions</h4>
+ <ul>
+ <li id="func_polynomial_init">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $COEFTYPENAME=$coeftypenames[$i];
+ $EXPTYPE=$exptypes[$i];
+ $EXPTYPENAME=$exptypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomial_init_${TYPENAME}\">polynomial_${TYPENAME}_init(polynomial_${TYPENAME}* poly, unsigned int memory)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ initialize the polynomial pointed to by <code>poly</code>, and allocate <code>memory</code> terms.
+ </li>
+ <br>
+ <li id="func_polynomial_free">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $COEFTYPENAME=$coeftypenames[$i];
+ $EXPTYPE=$exptypes[$i];
+ $EXPTYPENAME=$exptypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomial_free_${TYPENAME}\">polynomial_${TYPENAME}_free(polynomial_${TYPENAME} poly)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ free the polynomial <code>poly</code>.
+ </li>
+ <br>
+ <li id="func_polynomial_resize">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $COEFTYPENAME=$coeftypenames[$i];
+ $EXPTYPE=$exptypes[$i];
+ $EXPTYPENAME=$exptypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomial_resize_${TYPENAME}\">polynomial_${TYPENAME}_resize(polynomial_${TYPENAME}* poly, unsigned int newsize)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ copy the array polynomial to by <code>poly</code> to another with memory <code>newsize</code>.
+ </li>
+ <br>
+ <li id="func_polynomial_append">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $COEFTYPENAME=$coeftypenames[$i];
+ $EXPTYPE=$exptypes[$i];
+ $EXPTYPENAME=$exptypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomial_append_${TYPENAME}\">polynomial_${TYPENAME}_add_monomial(${COEFTYPE} val, ${EXPTYPE} order, polynomial_${TYPENAME}* output)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ add a term with coefficient <code>val</code> and exponent <code>order</code> to the polynomial pointed to by <code>output</code>. Resize the polynomial if needed.
+ </li>
+ <br>
+ <li id="func_polynomial_append_d">
+ <?php
+ for ($i=1; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $COEFTYPENAME=$coeftypenames[$i];
+ $EXPTYPE=$exptypes[$i];
+ $EXPTYPENAME=$exptypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomial_append_d_${TYPENAME}\">polynomial_${TYPENAME}_add_monomial_dui(double val, unsigned int order, polynomial_${TYPENAME}* output)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ add a term with coefficient <code>val</code> (converted from a <code>double</code>) and exponent <code>order</code> (converted from an <code>unsigned int</code>) to the polynomial pointed to by <code>output</code>. Resize the polynomial if needed.
+ </li>
+ <br>
+ <li id="func_polynomial_cpy">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $COEFTYPENAME=$coeftypenames[$i];
+ $EXPTYPE=$exptypes[$i];
+ $EXPTYPENAME=$exptypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomial_cpy_${TYPENAME}\">polynomial_${TYPENAME}_cpy(polynomial_${TYPENAME} input, polynomial_${TYPENAME}* output)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ copy <code>input</code> to the polynomial pointed to by <code>output</code>. Initializes <code>*output</code>.
+ </li>
+ <br>
+ <li id="func_polynomial_cpy_noinit">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $COEFTYPENAME=$coeftypenames[$i];
+ $EXPTYPE=$exptypes[$i];
+ $EXPTYPENAME=$exptypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomial_cpy_noinit_${TYPENAME}\">polynomial_${TYPENAME}_cpy_noinit(polynomial_${TYPENAME} input, polynomial_${TYPENAME}* output)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ copy <code>input</code> to the polynomial pointed to by <code>output</code>. Does not initialize <code>*output</code>, so <code>*output</code> must be initialized ahead of time, and its memory must be larger or equal to the length of <code>input</code>. Returns <code>LIBINUM_ERROR_SIZE_MISMATCH</code> if the memory of <code>*output</code> is smaller than the length of <code>input</code>.
+ </li>
+ <br>
+ <li id="func_polynomial_add">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $COEFTYPENAME=$coeftypenames[$i];
+ $EXPTYPE=$exptypes[$i];
+ $EXPTYPENAME=$exptypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomial_add_${TYPENAME}\">polynomial_${TYPENAME}_add(polynomial poly1, polynomial_${TYPENAME} poly2, polynomial_${TYPENAME}* output)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ add <code>poly1</code> and <code>poly2</code> and write the result to the polynomial pointed to by <code>output</code>. Initializes <code>*output</code>.
+ </li>
+ <br>
+ <li id="func_polynomial_add_inplace">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $COEFTYPENAME=$coeftypenames[$i];
+ $EXPTYPE=$exptypes[$i];
+ $EXPTYPENAME=$exptypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomial_add_inplace_${TYPENAME}\">polynomial_${TYPENAME}_add_inplace(polynomial_${TYPENAME} poly1, polynomial_${TYPENAME}* poly2)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ add <code>poly1</code> and <code>*poly2</code> and write the result to the polynomial pointed to by <code>poly2</code>.
+ </li>
+ <br>
+ <li id="func_polynomial_mul_scalar">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $COEFTYPENAME=$coeftypenames[$i];
+ $EXPTYPE=$exptypes[$i];
+ $EXPTYPENAME=$exptypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomial_mul_scalar_${TYPENAME}\">polynomial_${TYPENAME}_mul_scalar(${COEFTYPE} x, polynomial_${TYPENAME} poly, polynomial_${TYPENAME}* output)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ multiply <code>x</code> and <code>poly</code> and write the result to the polynomial pointed to by <code>output</code>. Initializes <code>*output</code>.
+ </li>
+ <br>
+ <li id="func_polynomial_mul_scalar_inplace">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $COEFTYPENAME=$coeftypenames[$i];
+ $EXPTYPE=$exptypes[$i];
+ $EXPTYPENAME=$exptypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomial_mul_scalar_inplace_${TYPENAME}\">polynomial_${TYPENAME}_mul_scalar_inplace(${COEFTYPE} x, polynomial_${TYPENAME}* poly)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ multiply <code>x</code> and <code>*poly</code> and write the result to the polynomial pointed to by <code>poly</code>.
+ </li>
+ <br>
+ <li id="func_polynomial_mul_monomial">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $COEFTYPENAME=$coeftypenames[$i];
+ $EXPTYPE=$exptypes[$i];
+ $EXPTYPENAME=$exptypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomial_mul_monomial_${TYPENAME}\">polynomial_${TYPENAME}_mul_monomial(${COEFTYPE} x, ${EXPTYPE} order, polynomial_${TYPENAME} poly, polynomial_${TYPENAME}* output)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ multiply <code>poly</code> and the monomial whose coefficient and exponent are <code>x</code> and <code>order</code>, and write the result to the polynomial pointed to by <code>output</code>. Initializes <code>*output</code>.
+ </li>
+ <br>
+ <li id="func_polynomial_mul_monomial_inplace">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $COEFTYPENAME=$coeftypenames[$i];
+ $EXPTYPE=$exptypes[$i];
+ $EXPTYPENAME=$exptypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomial_mul_monomial_inplace_${TYPENAME}\">polynomial_${TYPENAME}_mul_monomial_inplace(${COEFTYPE} x, ${EXPTYPE} order, polynomial_${TYPENAME}* poly)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ multiply <code>*poly</code> and the monomial whose coefficient and exponent are <code>x</code> and <code>order</code>, and write the result to the polynomial pointed to by <code>poly</code>.
+ </li>
+ <br>
+ <li id="func_polynomial_mul">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $COEFTYPENAME=$coeftypenames[$i];
+ $EXPTYPE=$exptypes[$i];
+ $EXPTYPENAME=$exptypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomial_mul_${TYPENAME}\">polynomial_${TYPENAME}_mul(polynomial_${TYPENAME} poly1, polynomial_${TYPENAME} poly2, polynomial_${TYPENAME}* output)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ multiply <code>poly1</code> and <code>poly2</code> and write the result to the polynomial pointed to by <code>output</code>. Initializes <code>*output</code>.
+ </li>
+ <br>
+ <li id="func_polynomial_mul_inplace">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $COEFTYPENAME=$coeftypenames[$i];
+ $EXPTYPE=$exptypes[$i];
+ $EXPTYPENAME=$exptypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomial_mul_inplace_${TYPENAME}\">polynomial_${TYPENAME}_mul_inplace(polynomial_${TYPENAME} poly1, polynomial_${TYPENAME}* poly2)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ multiply <code>poly1</code> and <code>*poly2</code> and write the result to the polynomial pointed to by <code>poly2</code>.
+ </li>
+ <br>
+ <li id="func_polynomial_derive">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $COEFTYPENAME=$coeftypenames[$i];
+ $EXPTYPE=$exptypes[$i];
+ $EXPTYPENAME=$exptypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomial_derive_${TYPENAME}\">polynomial_${TYPENAME}_derive(polynomial_${TYPENAME} poly, polynomial_${TYPENAME}* output)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ derive <code>poly</code> and write the result to the polynomial pointed to by <code>output</code>. Initializes <code>*output</code>.
+ </li>
+ <br>
+ <li id="func_polynomial_derive_inplace">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $COEFTYPENAME=$coeftypenames[$i];
+ $EXPTYPE=$exptypes[$i];
+ $EXPTYPENAME=$exptypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomial_derive_inplace_${TYPENAME}\">polynomial_${TYPENAME}_derive_inplace(polynomial_${TYPENAME}* poly)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ derive <code>*poly</code> and write the result to the polynomial pointed to by <code>poly</code>.
+ </li>
+ <br>
+ <li id="func_polynomial_evaluate">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $COEFTYPENAME=$coeftypenames[$i];
+ $EXPTYPE=$exptypes[$i];
+ $EXPTYPENAME=$exptypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomial_evaluate_${TYPENAME}\">polynomial_${TYPENAME}_evaluate(${COEFTYPE}* out, ${COEFTYPE} x, polynomial_${TYPENAME} poly)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ evaluate <code>poly</code> at <code>x</code>, and write the result to <code>out</code>. <code>out</code> must be initialized if its type requires it.
+ </li>
+ <br>
+ <li id="func_polynomial_print">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $COEFTYPENAME=$coeftypenames[$i];
+ $EXPTYPE=$exptypes[$i];
+ $EXPTYPENAME=$exptypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomial_print_${TYPENAME}\">polynomial_${TYPENAME}_print(polynomial_${TYPENAME} poly)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ print <code>poly</code>.
+ </li>
+ <br>
+ <li id="func_polynomial_legendre">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $COEFTYPENAME=$coeftypenames[$i];
+ $EXPTYPE=$exptypes[$i];
+ $EXPTYPENAME=$exptypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomial_legendre_${TYPENAME}\">polynomial_${TYPENAME}_legendre(unsigned int n, polynomial_${TYPENAME}* output)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ compute the <code>n</code>-th Legendre polynomial, and write the output to the polynomial pointed to by <code>poly</code>. Initializes <code>*poly</code>.
+ </li>
+ </ul>
+
+ <h3 class="subsection" id="subsec_polynomialMV"><code>polynomialMV</code></h3>
+ <p>Multi-variable polynomials. A <code>polynomial</code> is represented as an array of coefficients and an array of arrays of indices, each of which represents a variable. For example, \(3x_1^2+x_1x_2\) is represented as <code>({3,1},{{1,1},{1,2}})</code>.</p>
+
+ <?php
+ $typenames=["int", "mpz"];
+ $coeftypes=["int", "mpz_t"];
+ $indextypes=["int", "int"];
+ $indextypenames=["int", "int"];
+ ?>
+
+ <h4>Structure</h4>
+ The coefficients of multi-variable polynomials can be integers or multiprecision integers, and the indices are integers. Multi-variable polynomials are represented as structures, with the following keys:
+ <ul>
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $INDEXTYPE=$indextypes[$i];
+ $INDEXTYPENAME=$indextypenames[$i];
+ print("
+ <li id=\"struct_polynomialMV_${TYPENAME}\">
+ <code>polynomialMV_${TYPENAME}</code>:
+ <code>{ ${COEFTYPE}* coefficients, array_${INDEXTYPENAME} factors, unsigned int length, unsigned int memory }</code>
+ </li>
+ ");
+ }
+ ?>
+ </ul>
+ where the keys correspond to
+ <ul>
+ <li><code>coefficients</code>: array of coefficients</li>
+ <li><code>factors</code>: array of <i>factors</i>, i.e. arrays of indices of variables</li>
+ <li><code>length</code>: the number of terms in the polynomial</li>
+ <li><code>memory</code>: the number of terms allocated to the polynomial</li>
+ </ul>
+ <code>polynomialMV_*</code>'s must be initialized before they are used, and freed when they are no longer needed. When the polynomial is freed, its coefficients and factors are freed as well.
+
+ <h4>Functions</h4>
+ <ul>
+ <li id="func_polynomialMV_init">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $INDEXTYPE=$indextypes[$i];
+ $INDEXTYPENAME=$indextypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomialMV_init_${TYPENAME}\">polynomialMV_${TYPENAME}_init(polynomialMV_${TYPENAME}* poly, unsigned int memory)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ initialize the polynomial pointed to by <code>poly</code>, and allocate <code>memory</code> terms.
+ </li>
+ <br>
+ <li id="func_polynomialMV_free">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $INDEXTYPE=$indextypes[$i];
+ $INDEXTYPENAME=$indextypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomialMV_free_${TYPENAME}\">polynomialMV_${TYPENAME}_free(polynomialMV_${TYPENAME} poly)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ free the polynomial <code>poly</code>.
+ </li>
+ <br>
+ <li id="func_polynomialMV_resize">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $INDEXTYPE=$indextypes[$i];
+ $INDEXTYPENAME=$indextypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomialMV_resize_${TYPENAME}\">polynomialMV_${TYPENAME}_resize(polynomialMV_${TYPENAME}* poly, unsigned int newsize)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ copy the array polynomial to by <code>poly</code> to another with memory <code>newsize</code>.
+ </li>
+ <br>
+ <li id="func_polynomialMV_cpy">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $INDEXTYPE=$indextypes[$i];
+ $INDEXTYPENAME=$indextypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomialMV_cpy_${TYPENAME}\">polynomialMV_${TYPENAME}_cpy(polynomialMV_${TYPENAME} input, polynomialMV_${TYPENAME}* output)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ copy <code>input</code> to the polynomial pointed to by <code>output</code>. Initializes <code>*output</code>.
+ </li>
+ <br>
+ <li id="func_polynomialMV_cpy_noinit">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $INDEXTYPE=$indextypes[$i];
+ $INDEXTYPENAME=$indextypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomialMV_cpy_noinit_${TYPENAME}\">polynomialMV_${TYPENAME}_cpy_noinit(polynomialMV_${TYPENAME} input, polynomialMV_${TYPENAME}* output)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ copy <code>input</code> to the polynomial pointed to by <code>output</code>. Does not initialize <code>*output</code>, so <code>*output</code> must be initialized ahead of time, and its memory must be larger or equal to the length of <code>input</code>. Returns <code>LIBINUM_ERROR_SIZE_MISMATCH</code> if the memory of <code>*output</code> is smaller than the length of <code>input</code>.
+ </li>
+ <br>
+ <li id="func_polynomialMV_append">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $INDEXTYPE=$indextypes[$i];
+ $INDEXTYPENAME=$indextypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomialMV_append_${TYPENAME}\">polynomialMV_${TYPENAME}_append(array_${INDEXTYPENAME} factor, ${COEFTYPE} coef, polynomialMV_${TYPENAME}* output)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ add a term with coefficient <code>coef</code> and factor <code>factor</code> to the polynomial pointed to by <code>output</code>. Resize the polynomial if needed.
+ </li>
+ <br>
+ <li id="func_polynomialMV_append_inplace">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $INDEXTYPE=$indextypes[$i];
+ $INDEXTYPENAME=$indextypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomialMV_append_inplace_${TYPENAME}\">polynomialMV_${TYPENAME}_append_inplace(array_${INDEXTYPENAME} factor, ${COEFTYPE} coef, polynomialMV_${TYPENAME}* output)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ same as <a href="#func_polynomialMV_append"><code>polynomialMV_*_append</code></a> except that if the factor is already present in the polynomial pointed to by <code>output</code>, then add <code>coef</code> to the coefficient of that factor, instead of appending it to the end of the polynomial. Resize the polynomial if needed.
+ </li>
+ <br>
+ <li id="func_polynomialMV_append_noinit">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $INDEXTYPE=$indextypes[$i];
+ $INDEXTYPENAME=$indextypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomialMV_append_noinit_${TYPENAME}\">polynomialMV_${TYPENAME}_append_noinit(array_${INDEXTYPENAME} factor, ${COEFTYPE} coef, polynomialMV_${TYPENAME}* output)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ same as <a href="#func_polynomialMV_append"><code>polynomialMV_*_append</code></a> except that the new factor and coefficient to be appended to the polynomial pointed to by <code>output</code> are not allocated. Instead, pointers to <code>factor</code> and <code>coef</code> are appended. <code>factor</code> and <code>coef</code> must therefore not be freed (since they will be freed when <code>output</code> is). Resize the polynomial if needed.
+ </li>
+ <br>
+ <li id="func_polynomialMV_append_noinitfactor">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $INDEXTYPE=$indextypes[$i];
+ $INDEXTYPENAME=$indextypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomialMV_append_noinitfactor_${TYPENAME}\">polynomialMV_${TYPENAME}_append_noinitfactor(array_${INDEXTYPENAME} factor, ${COEFTYPE} coef, polynomialMV_${TYPENAME}* output)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ same as <a href="#func_polynomialMV_append"><code>polynomialMV_*_append</code></a> except that the new factor to be appended to the polynomial pointed to by <code>output</code> is not allocated. Instead, a pointer to <code>factor</code> is appended. <code>factor</code> must therefore not be freed (since it will be freed when <code>output</code> is). <code>coef</code> is, however, copied and must be freed. Resize the polynomial if needed.
+ </li>
+ <br>
+ <li id="func_polynomialMV_append_noinit_inplace">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $INDEXTYPE=$indextypes[$i];
+ $INDEXTYPENAME=$indextypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomialMV_append_noinit_inplace_${TYPENAME}\">polynomialMV_${TYPENAME}_append_noinit_inplace(array_${INDEXTYPENAME} factor, ${COEFTYPE} coef, polynomial* output)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ same as <a href="#func_polynomialMV_append_noinit"><code>polynomialMV_*_append_noinit</code></a> except that if the factor is already present in the polynomial pointed to by <code>output</code>, then add <code>coef</code> to the coefficient of that factor, instead of appending it to the end of the polynomial. Resize the polynomial if needed.
+ </li>
+ <br>
+ <li id="func_polynomialMV_append_noinitfactor_inplace">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $INDEXTYPE=$indextypes[$i];
+ $INDEXTYPENAME=$indextypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomialMV_append_noinitfactor_inplace_${TYPENAME}\">polynomialMV_${TYPENAME}_append_noinit_inplace(array_${INDEXTYPENAME} factor, ${COEFTYPE} coef, polynomial* output)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ same as <a href="#func_polynomialMV_append_noinitfactor"><code>polynomialMV_*_append_noinitfactor</code></a> except that if the factor is already present in the polynomial pointed to by <code>output</code>, then add <code>coef</code> to the coefficient of that factor, instead of appending it to the end of the polynomial. Resize the polynomial if needed.
+ </li>
+ <br>
+ <li id="func_polynomialMV_add">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $INDEXTYPE=$indextypes[$i];
+ $INDEXTYPENAME=$indextypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomialMV_add_${TYPENAME}\">polynomialMV_${TYPENAME}_add(polynomialMV_${TYPENAME} poly1, polynomialMV_${TYPENAME} poly2, polynomialMV_${TYPENAME}* output)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ add <code>poly1</code> and <code>poly2</code> and write the result to the polynomial pointed to by <code>output</code>. Initializes <code>*output</code>.
+ </li>
+ <br>
+ <li id="func_polynomialMV_add_inplace">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $INDEXTYPE=$indextypes[$i];
+ $INDEXTYPENAME=$indextypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomialMV_add_inplace_${TYPENAME}\">polynomialMV_${TYPENAME}_add_inplace(polynomialMV_${TYPENAME} poly1, polynomialMV_${TYPENAME}* poly2)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ add <code>poly1</code> and <code>*poly2</code> and write the result to the polynomial pointed to by <code>poly2</code>.
+ </li>
+ <br>
+ <li id="func_polynomialMV_multiply_scalar">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $INDEXTYPE=$indextypes[$i];
+ $INDEXTYPENAME=$indextypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomialMV_multiply_scalar_${TYPENAME}\">polynomialMV_${TYPENAME}_multiply_scalar(polynomial poly, ${COEFTYPE} num)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ multiply <code>num</code> and <code>poly</code> and write the result to <code>poly</code>.
+ </li>
+ <br>
+ <li id="func_polynomialMV_prod">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $INDEXTYPE=$indextypes[$i];
+ $INDEXTYPENAME=$indextypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomialMV_prod_${TYPENAME}\">polynomialMV_${TYPENAME}_prod(polynomialMV_${TYPENAME} poly1, polynomialMV_${TYPENAME} poly2, polynomialMV_${TYPENAME}* output)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ multiply <code>poly1</code> and <code>poly2</code> and write the result to the polynomial pointed to by <code>output</code>. Initializes <code>*output</code>.
+ </li>
+ <br>
+ <li id="func_polynomialMV_order">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $INDEXTYPE=$indextypes[$i];
+ $INDEXTYPENAME=$indextypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomialMV_order_${TYPENAME}\">polynomialMV_${TYPENAME}_order(polynomialMV_${TYPENAME} poly)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ order the factors in <code>poly</code>, using <a href="#func_array_sort">array_*_sort</a>.
+ </li>
+ <br>
+ <li id="func_polynomialMV_print">
+ <?php
+ for ($i=0; $i<count($typenames); $i++){
+ $TYPENAME=$typenames[$i];
+ $COEFTYPE=$coeftypes[$i];
+ $INDEXTYPE=$indextypes[$i];
+ $INDEXTYPENAME=$indextypenames[$i];
+ print("
+ <div style=\"margin-bottom:5pt\">
+ <code id=\"func_polynomialMV_print_${TYPENAME}\">polynomialMV_${TYPENAME}_print(polynomialMV_${TYPENAME} poly)</code>
+ </div>
+ ");
+ }
+ ?>
+ <br>
+ print <code>poly</code>.
+ </li>
+ </ul>
+
+
+ <h3 class="subsection" id="subsec_functions">Functions</h3>
+ <p>
+ Functions are not, strictly speaking, a C type. Instead, in this section, we describe how functions whose pointers are to be passed to the various algorithms of <b>libinum</b>, should be formatted.
+ </p>
+
+ <p>
+ Functions must take 3 arguments, and return an integer (a return code):
+ <code class="codeblock">int f(TYPE* out, TYPE in, void* extra_args)</code>
+ where <code>TYPE</code> is the appropriate data type, e.g. <code>double</code> or <code>mpfr_t</code>. <code>in</code> is the argument of the function, <code>out</code> is made to point to \(f(\)<code>in</code>\()\), and <code>extra_args</code> is a pointer to void, which may contain extra arguments to be passed to the function, for example a parameter that the function depends on. For example, to implement the function \(f_\alpha(x)=x^\alpha\) using MPFR floats,
+ <code class=codeblock>
+<pre>
+int f(mpfr_t out, mpfr_t in, void* extra_args){
+ int alpha=*((*int)extra_args);
+ mpfr_pow_ui(out, in, alpha, MPFR_RNDN);
+ return(0);
+}
+</pre>
+ </code>
+ </p>
+
+ <h2 class="section" id="sec_utilities">Utilities</h2>
+ <p>
+ In addition, the following functions are defined
+ </p>
+ <ul>
+ <li id="func_fprint_double">
+ <code>fprint_double(FILE* file, double x)</code><br>
+ print <code>x</code> to <code>file</code>, with as many digits as possible.
+ </li>
+ <li id="func_fprint_ldouble">
+ <code>fprint_ldouble(FILE* file, long double x)</code><br>
+ print <code>x</code> to <code>file</code>, with as many digits as possible.
+ </li>
+ <li id="func_fprint_mpfr">
+ <code>fprint_mpfr(FILE* file, mpfr_t x)</code><br>
+ print <code>x</code> to <code>file</code>, with as many digits as allowed by the MPFR precision.
+ </li>
+ <li id="func_print_datatype_info">
+ <code>print_datatype_info()</code><br>
+ print miscellaneous information about integers and floats. Namely, the number of bits used in <code>char</code>, <code>short int</code>, <code>int</code>, <code>long int</code> and <code>long long int</code>; the precision and maximal and minimal exponents of <code>double</code> and <code>long double</code>; the type used to store the precision and emax of MPFR floats.
+ </li>
+ </ul>
+
+
+ <h2 class="section" id="sec_examples">Examples</h2>
+ <p>
+ Examples of programs using <b>libinum</b> are provided with the source code, in the <code>doc/libinum-examples</code> directory. If <b>libinum</b> is installed on the filesystem, then the examples can also be found at <code>/usr/share/doc/libinum/libinum-examples</code>.
+ </p>
+
+
+ <h2 class="section" id="sec_authors">Authors</h2>
+ <p>
+ <b>libinum</b> was written by Ian Jauslin.
+ </p>
+ </body>
+</html>