Ian Jauslin
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Jauslin <ian.jauslin@roma1.infn.it>2016-05-20 20:30:15 +0000
committerIan Jauslin <ian.jauslin@roma1.infn.it>2016-05-20 20:30:15 +0000
commit2125f01f97abfe343fc5e0cc078bf1d081b2e441 (patch)
tree932dc60739384224be31f9e894ae63055634435e
Initial commitv1.0
-rw-r--r--INSTALL43
-rw-r--r--LGPL3165
-rw-r--r--LICENSE202
-rw-r--r--Makefile120
-rw-r--r--NOTICE15
-rw-r--r--doc/libinum-doc.html2332
-rw-r--r--doc/libinum-doc.php1835
-rw-r--r--doc/libinum-examples/Makefile80
-rwxr-xr-xdoc/libinum-examples/build/integral_gauss-legendrebin0 -> 127104 bytes
-rwxr-xr-xdoc/libinum-examples/build/root_newtonbin0 -> 18712 bytes
-rw-r--r--doc/libinum-examples/objs/integral_gauss-legendre.obin0 -> 11072 bytes
-rw-r--r--doc/libinum-examples/objs/root_newton.obin0 -> 9048 bytes
-rw-r--r--doc/libinum-examples/src/integral_gauss-legendre.c92
-rw-r--r--doc/libinum-examples/src/root_newton.c58
-rw-r--r--include/libinum.h20
l---------include/libinum/array.h1
l---------include/libinum/array_2_mpfr.h1
l---------include/libinum/array_base.h1
l---------include/libinum/array_char.h1
l---------include/libinum/array_double.h1
l---------include/libinum/array_int.h1
l---------include/libinum/array_ldouble.h1
l---------include/libinum/array_mpfr.h1
l---------include/libinum/array_polynomial_double.h1
l---------include/libinum/array_polynomial_ldouble.h1
l---------include/libinum/array_polynomial_mpfr.h1
l---------include/libinum/array_pthread_t.h1
l---------include/libinum/array_str.h1
l---------include/libinum/array_type.h1
l---------include/libinum/array_uint.h1
l---------include/libinum/errors.h1
l---------include/libinum/integral.h1
l---------include/libinum/integral_base.h1
l---------include/libinum/integral_double.h1
l---------include/libinum/integral_ldouble.h1
l---------include/libinum/integral_mpfr.h1
l---------include/libinum/polynomial.h1
l---------include/libinum/polynomialMV.h1
l---------include/libinum/polynomialMV_base.h1
l---------include/libinum/polynomialMV_int.h1
l---------include/libinum/polynomialMV_mpz.h1
l---------include/libinum/polynomialMV_type.h1
l---------include/libinum/polynomial_base.h1
l---------include/libinum/polynomial_double.h1
l---------include/libinum/polynomial_ldouble.h1
l---------include/libinum/polynomial_mpfr.h1
l---------include/libinum/polynomial_type.h1
l---------include/libinum/root.h1
l---------include/libinum/root_base.h1
l---------include/libinum/root_double.h1
l---------include/libinum/root_ldouble.h1
l---------include/libinum/root_mpfr.h1
l---------include/libinum/types.h1
l---------include/libinum/utils.h1
-rw-r--r--src/array.c227
-rw-r--r--src/array.h150
-rw-r--r--src/array_2_mpfr.h54
-rw-r--r--src/array_base.c249
-rw-r--r--src/array_base.h78
-rw-r--r--src/array_char.h52
-rw-r--r--src/array_double.h52
-rw-r--r--src/array_int.h52
-rw-r--r--src/array_ldouble.h52
-rw-r--r--src/array_mpfr.h54
-rw-r--r--src/array_polynomial_double.h50
-rw-r--r--src/array_polynomial_ldouble.h50
-rw-r--r--src/array_polynomial_mpfr.h50
-rw-r--r--src/array_pthread_t.h50
-rw-r--r--src/array_str.h54
-rw-r--r--src/array_type.h28
-rw-r--r--src/array_uint.h52
-rw-r--r--src/errors.h29
-rw-r--r--src/integral.c52
-rw-r--r--src/integral.h53
-rw-r--r--src/integral_base.c506
-rw-r--r--src/integral_base.h48
-rw-r--r--src/integral_double.h81
-rw-r--r--src/integral_ldouble.h81
-rw-r--r--src/integral_mpfr.h84
-rw-r--r--src/polynomial.c55
-rw-r--r--src/polynomial.h55
-rw-r--r--src/polynomialMV.c30
-rw-r--r--src/polynomialMV.h34
-rw-r--r--src/polynomialMV_base.c293
-rw-r--r--src/polynomialMV_base.h67
-rw-r--r--src/polynomialMV_int.h62
-rw-r--r--src/polynomialMV_mpz.h66
-rw-r--r--src/polynomialMV_type.h29
-rw-r--r--src/polynomial_base.c337
-rw-r--r--src/polynomial_base.h67
-rw-r--r--src/polynomial_double.h117
-rw-r--r--src/polynomial_ldouble.h117
-rw-r--r--src/polynomial_mpfr.h121
-rw-r--r--src/polynomial_type.h27
-rw-r--r--src/root.c51
-rw-r--r--src/root.h57
-rw-r--r--src/root_base.c134
-rw-r--r--src/root_base.h27
-rw-r--r--src/root_double.h55
-rw-r--r--src/root_ldouble.h55
-rw-r--r--src/root_mpfr.h59
-rw-r--r--src/types.h84
-rw-r--r--src/utils.c79
-rw-r--r--src/utils.h36
104 files changed, 9403 insertions, 0 deletions
diff --git a/INSTALL b/INSTALL
new file mode 100644
index 0000000..bc9fa86
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1,43 @@
+#######################################################################
+## ##
+## Compiling and installing libinum. ##
+## ##
+#######################################################################
+
+* libinum should work on any POSIX compliant system, such as GNU/Linux or OSX.
+
+* libinum is linked against the GNU MPFR, GNU GMP and pthread libraries.
+
+* Compiling:
+ Run
+ make
+
+ The default paths can be modified by passing the appropriate arguments to
+ make, as specified in the following table
+ compiler : CC=/usr/bin/gcc
+ linker : LD=/usr/bin/gcc
+ archive : AR=/usr/bin/ar
+ include : INCLUDE=
+ lib paths : LIB=
+ optimize : OPT=-O3
+
+ For example,
+ make CC=/usr/local/bin/gcc INCLUDE=/usr/local/include LIBDIR=-L/usr/local/lib
+
+ In addition, libinum can be compiled as dynamic or static library, which is
+ controlled by the STATIC option of the makefile.
+ If STATIC=0 (default) then compile both
+ If STATIC=1 then compile the static library
+ If STATIC=2 then compile the dynamic library
+
+
+* Installing:
+ Run
+ make install
+
+ The default install prefix (/usr) can be changed by changing the PREFIX
+ variable.
+
+ For example
+ make install PREFIX=/usr/local
+
diff --git a/LGPL3 b/LGPL3
new file mode 100644
index 0000000..65c5ca8
--- /dev/null
+++ b/LGPL3
@@ -0,0 +1,165 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..d73250a
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,120 @@
+## Copyright 2016 Ian Jauslin
+##
+## Licensed under the Apache License, Version 2.0 (the "License");
+## you may not use this file except in compliance with the License.
+## You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+
+# whether to compile only the static library, only the dynamic library, or both
+# if static=0 then compile both
+# if static=2 then compile the dynamic library
+# if static=1 then compile the static library
+STATIC=0
+
+VERSION=1.0
+
+# products of the compilation
+PROJECT_SO=libinum.so.$(VERSION)
+PROJECT_LIBS=libinum.a
+PROJECT_DOCS=libinum-doc.html
+
+# debug and optimization flags
+#DB= -ggdb
+OPT= -O3
+
+# warning flags
+WARNINGS= -Wall -Wextra -Wno-strict-overflow -std=c99 -pedantic
+
+# installation dirs
+PREFIX=/usr
+LIBDIR=$(PREFIX)/lib
+INCLUDEDIR=$(PREFIX)/include
+DOCDIR=$(PREFIX)/share/doc/libinum
+
+# compiler
+CC=/usr/bin/gcc
+LD=$(CC)
+AR=/usr/bin/ar
+
+# directories
+INCLUDE =
+LIB =
+
+# flags
+override LDFLAGS +=$(LIB)
+override CFLAGS +=$(INCLUDE)$(DB) $(OPT) $(WARNINGS)
+
+# build directories
+BUILDDIR=./build
+SRCDIR=./src
+OBJDIR=./objs
+
+# objects
+LIBINUM_OBJS = $(addprefix $(OBJDIR)/, array.o integral.o utils.o polynomial.o polynomialMV.o root.o)
+
+
+ifeq ($(STATIC),1)
+ # compile libinum.a
+ PREREQ=static
+ # install static lib
+ INSTALLLIB=install-static
+else ifeq ($(STATIC),2)
+ # compile libinum.so.$(VERSION)
+ PREREQ=shared
+ # install shared lib
+ INSTALLLIB=install-shared
+else
+ # compile both
+ PREREQ=shared static
+ # install both
+ INSTALLLIB=install-shared install-static
+endif
+
+
+all: init $(PREREQ)
+
+# create dirs
+init:
+ @[ -d $(OBJDIR) ] || /bin/mkdir $(OBJDIR)
+ @[ -d $(BUILDDIR) ] || /bin/mkdir $(BUILDDIR)
+
+# static library
+static: $(PROJECT_LIBS)
+# shared library
+shared: $(PROJECT_SO)
+
+libinum.a: $(LIBINUM_OBJS)
+ $(AR) -rc $(BUILDDIR)/$@ $^
+
+libinum.so.$(VERSION): $(LIBINUM_OBJS)
+ $(LD) -shared -lm -lmpfr -lgmp -lpthread $(LDFLAGS) -o $(BUILDDIR)/$@ $^
+ ln -fs ./libinum.so.$(VERSION) $(BUILDDIR)/libinum.so
+
+%.o : ../$(SRCDIR)/%.c
+ $(CC) -c $(CFLAGS) -fPIC $< -o $@
+
+install: $(INSTALLLIB) all
+ mkdir -p $(MANDIR) $(DOCDIR) $(INCLUDEDIR)/libinum
+ cp -rL include/libinum/* $(INCLUDEDIR)/libinum/
+ install -Dm644 include/libinum.h $(INCLUDEDIR)/
+ cp -r doc/libinum-examples $(DOCDIR)/
+ install -Dm644 $(addprefix doc/,$(PROJECT_DOCS)) $(DOCDIR)/
+
+install-static: all
+ mkdir -p $(LIBDIR)
+ install -Dm755 $(addprefix $(BUILDDIR)/,$(PROJECT_LIBS)) $(LIBDIR)/
+install-shared: all
+ mkdir -p $(LIBDIR)
+ install -Dm755 $(addprefix $(BUILDDIR)/,$(PROJECT_SO)) $(LIBDIR)/
+ for lib in $(PROJECT_SO); do ln -fs ./$$lib $(LIBDIR)/$${lib%.so.*}.so; done
+
+clean:
+ @rm -rf $(OBJDIR)
+ @rm -rf $(BUILDDIR)
diff --git a/NOTICE b/NOTICE
new file mode 100644
index 0000000..ce0ac9d
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,15 @@
+libinum
+Copyright 2016 Ian Jauslin
+
+Numerical values may be represented as multi-precision floats using
+the GNU MPFR library, which is licensed under the GNU Lesser General
+Public License (LGPL) version 3 (see LGPL3 for a copy of the license).
+See
+ http://www.mpfr.org/
+for details.
+
+The GNU MPFR library is based on the GNU GMP library, which is licensed
+under the GNU Lesser General Public License (LGPL) version 3 (see LGPL3
+for a copy of the license). See
+ http://www.gmplib.org/
+for details.
diff --git a/doc/libinum-doc.html b/doc/libinum-doc.html
new file mode 100644
index 0000000..e50e8f7
--- /dev/null
+++ b/doc/libinum-doc.html
@@ -0,0 +1,2332 @@
+<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.
+ </p>
+
+ <ul>
+ <li id="func_root_newton">
+ <div style="vertical-align: top;">
+
+ <code>
+ <div style="margin-bottom:20pt">
+ <div id="func_root_newton_double" style="display: inline-block; vertical-align: top;">
+ int root_newton_double(
+ </div>
+ <div id="func_root_newton_double" style="display: inline-block; vertical-align: top;">
+ double* out,<br>
+ int (*func)(double*, double, void*),<br>
+ int (*deriv_func)(double*, double, void*),<br>
+ double init,<br>
+ double tolerance,<br>
+ int maxiter,<br>
+ void* extra_args)
+ </div>
+ </div>
+ </code>
+
+ <code>
+ <div style="margin-bottom:20pt">
+ <div id="func_root_newton_ldouble" style="display: inline-block; vertical-align: top;">
+ int root_newton_ldouble(
+ </div>
+ <div id="func_root_newton_ldouble" style="display: inline-block; vertical-align: top;">
+ long double* out,<br>
+ int (*func)(long double*, long double, void*),<br>
+ int (*deriv_func)(long double*, long double, void*),<br>
+ long double init,<br>
+ long double tolerance,<br>
+ int maxiter,<br>
+ void* extra_args)
+ </div>
+ </div>
+ </code>
+
+ <code>
+ <div style="margin-bottom:20pt">
+ <div id="func_root_newton_mpfr" style="display: inline-block; vertical-align: top;">
+ int root_newton_mpfr(
+ </div>
+ <div id="func_root_newton_mpfr" style="display: inline-block; vertical-align: top;">
+ mpfr_t* out,<br>
+ int (*func)(mpfr_t*, mpfr_t, void*),<br>
+ int (*deriv_func)(mpfr_t*, mpfr_t, void*),<br>
+ mpfr_t init,<br>
+ mpfr_t 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;">
+
+ <code>
+ <div style="margin-bottom:20pt">
+ <div id="func_root_newton_inplace_double" style="display: inline-block; vertical-align: top">
+ int root_newton_inplace_double(
+ </div>
+ <div style="display: inline-block; vertical-align: top">
+ double* out,<br>
+ int (*func)(double*, double, void*),<br>
+ int (*deriv_func)(double*, double, void*),<br>
+ double tolerance,<br>
+ int maxiter,<br>
+ void* extra_args)<br>
+ </div>
+ </div>
+ </code>
+
+ <code>
+ <div style="margin-bottom:20pt">
+ <div id="func_root_newton_inplace_ldouble" style="display: inline-block; vertical-align: top">
+ int root_newton_inplace_ldouble(
+ </div>
+ <div style="display: inline-block; vertical-align: top">
+ long double* out,<br>
+ int (*func)(long double*, long double, void*),<br>
+ int (*deriv_func)(long double*, long double, void*),<br>
+ long double tolerance,<br>
+ int maxiter,<br>
+ void* extra_args)<br>
+ </div>
+ </div>
+ </code>
+
+ <code>
+ <div style="margin-bottom:20pt">
+ <div id="func_root_newton_inplace_mpfr" style="display: inline-block; vertical-align: top">
+ int root_newton_inplace_mpfr(
+ </div>
+ <div style="display: inline-block; vertical-align: top">
+ mpfr_t* out,<br>
+ int (*func)(mpfr_t*, mpfr_t, void*),<br>
+ int (*deriv_func)(mpfr_t*, mpfr_t, void*),<br>
+ mpfr_t 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
+ <ul>
+
+ <li id="func_integrate_gauss">
+ <div style="vertical-align: top;">
+
+ <code>
+ <div style="margin-bottom:20pt">
+ <div id="func_integrate_gauss_double" style="display: inline-block; vertical-align: top">
+ int integrate_gauss_double(
+ </div>
+ <div style="display: inline-block; vertical-align: top">
+ double* out,<br>
+ int (*func)(double*, double, void*),<br>
+ double lower,<br>
+ double upper,<br>
+ array_double abcissa,<br>
+ array_double weights,<br>
+ void* extra_args)
+ </div>
+ </div>
+ </code>
+
+ <code>
+ <div style="margin-bottom:20pt">
+ <div id="func_integrate_gauss_ldouble" style="display: inline-block; vertical-align: top">
+ int integrate_gauss_ldouble(
+ </div>
+ <div style="display: inline-block; vertical-align: top">
+ long double* out,<br>
+ int (*func)(long double*, long double, void*),<br>
+ long double lower,<br>
+ long double upper,<br>
+ array_ldouble abcissa,<br>
+ array_ldouble weights,<br>
+ void* extra_args)
+ </div>
+ </div>
+ </code>
+
+ <code>
+ <div style="margin-bottom:20pt">
+ <div id="func_integrate_gauss_mpfr" style="display: inline-block; vertical-align: top">
+ int integrate_gauss_mpfr(
+ </div>
+ <div style="display: inline-block; vertical-align: top">
+ mpfr_t* out,<br>
+ int (*func)(mpfr_t*, mpfr_t, void*),<br>
+ mpfr_t lower,<br>
+ mpfr_t upper,<br>
+ array_mpfr abcissa,<br>
+ array_mpfr 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;">
+
+ <code>
+ <div style="margin-bottom:20pt">
+ <div id="func_integrate_gauss_multithread_double" style="display: inline-block; vertical-align: top">
+ int integrate_gauss_multithread_double(
+ </div>
+ <div style="display: inline-block; vertical-align: top;">
+ double* out,<br>
+ int (*func)(double*, double, void*),<br>
+ double lower,<br>
+ double upper,<br>
+ array_double abcissa,<br>
+ array_double weights,<br>
+ void* extra_args,<br>
+ unsigned int threads,<br>
+ array_pthread_t* thread_ids)
+ </div>
+ </div>
+ </code>
+
+ <code>
+ <div style="margin-bottom:20pt">
+ <div id="func_integrate_gauss_multithread_ldouble" style="display: inline-block; vertical-align: top">
+ int integrate_gauss_multithread_ldouble(
+ </div>
+ <div style="display: inline-block; vertical-align: top;">
+ long double* out,<br>
+ int (*func)(long double*, long double, void*),<br>
+ long double lower,<br>
+ long double upper,<br>
+ array_ldouble abcissa,<br>
+ array_ldouble weights,<br>
+ void* extra_args,<br>
+ unsigned int threads,<br>
+ array_pthread_t* thread_ids)
+ </div>
+ </div>
+ </code>
+
+ <code>
+ <div style="margin-bottom:20pt">
+ <div id="func_integrate_gauss_multithread_mpfr" style="display: inline-block; vertical-align: top">
+ int integrate_gauss_multithread_mpfr(
+ </div>
+ <div style="display: inline-block; vertical-align: top;">
+ mpfr_t* out,<br>
+ int (*func)(mpfr_t*, mpfr_t, void*),<br>
+ mpfr_t lower,<br>
+ mpfr_t upper,<br>
+ array_mpfr abcissa,<br>
+ array_mpfr 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;">
+
+ <code>
+ <div style="margin-bottom:20pt">
+ <div id="func_integrate_gauss_smarttmp_mpfr" style="display: inline-block; vertical-align: top">
+ int integrate_gauss_smarttmp_mpfr(
+ </div>
+ <div style="display: inline-block; vertical-align: top;">
+ mpfr_t* out,<br>
+ int (*func)(mpfr_t*, mpfr_t, void*),<br>
+ mpfr_t lower,<br>
+ mpfr_t upper,<br>
+ array_mpfr abcissa,<br>
+ array_mpfr weights,<br>
+ array_mpfr* 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;">
+
+ <code>
+ <div style="margin-bottom:20pt">
+ <div id="func_integrate_gauss_smarttmp_multithread_mpfr" style="display: inline-block; vertical-align: top">
+ int integrate_gauss_smarttmp_multithread_mpfr(
+ </div>
+ <div style="display: inline-block; vertical-align: top;">
+ mpfr_t* out,<br>
+ int (*func)(mpfr_t*, mpfr_t, void*),<br>
+ mpfr_t lower,<br>
+ mpfr_t upper,<br>
+ array_mpfr abcissa,<br>
+ array_mpfr 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;">
+
+ <code>
+ <div style="margin-bottom:20pt">
+ <div id="func_gauss_legendre_weights_double" style="display: inline-block; vertical-align: top">
+ gauss_legendre_weights_double(
+ </div>
+ <div style="display: inline-block; vertical-align: top">
+ unsigned int order,<br>
+ double tolerance,<br>
+ unsigned int maxiter,<br>
+ array_double* abcissa,<br>
+ array_double* weights)
+ </div>
+ </div>
+ </code>
+
+ <code>
+ <div style="margin-bottom:20pt">
+ <div id="func_gauss_legendre_weights_ldouble" style="display: inline-block; vertical-align: top">
+ gauss_legendre_weights_ldouble(
+ </div>
+ <div style="display: inline-block; vertical-align: top">
+ unsigned int order,<br>
+ long double tolerance,<br>
+ unsigned int maxiter,<br>
+ array_ldouble* abcissa,<br>
+ array_ldouble* weights)
+ </div>
+ </div>
+ </code>
+
+ <code>
+ <div style="margin-bottom:20pt">
+ <div id="func_gauss_legendre_weights_mpfr" style="display: inline-block; vertical-align: top">
+ gauss_legendre_weights_mpfr(
+ </div>
+ <div style="display: inline-block; vertical-align: top">
+ unsigned int order,<br>
+ mpfr_t tolerance,<br>
+ unsigned int maxiter,<br>
+ array_mpfr* abcissa,<br>
+ array_mpfr* 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>
+
+
+ <h4>Structure</h4>
+ Arrays of several types of objects are defined. They are structures, with the following keys:
+
+ <ul>
+
+ <li id="struct_array_int">
+ <code>array_int</code>:
+ <code>{ int* values, unsigned int length, unsigned int memory }</code>
+ </li>
+
+ <li id="struct_array_uint">
+ <code>array_uint</code>:
+ <code>{ unsigned int* values, unsigned int length, unsigned int memory }</code>
+ </li>
+
+ <li id="struct_array_double">
+ <code>array_double</code>:
+ <code>{ double* values, unsigned int length, unsigned int memory }</code>
+ </li>
+
+ <li id="struct_array_ldouble">
+ <code>array_ldouble</code>:
+ <code>{ long double* values, unsigned int length, unsigned int memory }</code>
+ </li>
+
+ <li id="struct_array_mpfr">
+ <code>array_mpfr</code>:
+ <code>{ mpfr_t* values, unsigned int length, unsigned int memory }</code>
+ </li>
+
+ <li id="struct_array_2_mpfr">
+ <code>array_2_mpfr</code>:
+ <code>{ array_mpfr* values, unsigned int length, unsigned int memory }</code>
+ </li>
+
+ <li id="struct_array_char">
+ <code>array_char</code>:
+ <code>{ char* values, unsigned int length, unsigned int memory }</code>
+ </li>
+
+ <li id="struct_array_str">
+ <code>array_str</code>:
+ <code>{ array_char* values, unsigned int length, unsigned int memory }</code>
+ </li>
+
+ <li id="struct_array_polynomial_double">
+ <code>array_polynomial_double</code>:
+ <code>{ polynomial_double* values, unsigned int length, unsigned int memory }</code>
+ </li>
+
+ <li id="struct_array_polynomial_ldouble">
+ <code>array_polynomial_ldouble</code>:
+ <code>{ polynomial_ldouble* values, unsigned int length, unsigned int memory }</code>
+ </li>
+
+ <li id="struct_array_polynomial_mpfr">
+ <code>array_polynomial_mpfr</code>:
+ <code>{ polynomial_mpfr* values, unsigned int length, unsigned int memory }</code>
+ </li>
+
+ <li id="struct_array_pthread_t">
+ <code>array_pthread_t</code>:
+ <code>{ pthread_t* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_init_int">int array_int_init(array_int* array, unsigned int memory)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_init_uint">int array_uint_init(array_uint* array, unsigned int memory)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_init_double">int array_double_init(array_double* array, unsigned int memory)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_init_ldouble">int array_ldouble_init(array_ldouble* array, unsigned int memory)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_init_mpfr">int array_mpfr_init(array_mpfr* array, unsigned int memory)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_init_2_mpfr">int array_2_mpfr_init(array_2_mpfr* array, unsigned int memory)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_init_char">int array_char_init(array_char* array, unsigned int memory)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_init_str">int array_str_init(array_str* array, unsigned int memory)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_init_polynomial_double">int array_polynomial_double_init(array_polynomial_double* array, unsigned int memory)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_init_polynomial_ldouble">int array_polynomial_ldouble_init(array_polynomial_ldouble* array, unsigned int memory)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_init_polynomial_mpfr">int array_polynomial_mpfr_init(array_polynomial_mpfr* array, unsigned int memory)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_init_pthread_t">int array_pthread_t_init(array_pthread_t* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_free_int">int array_int_free(array_int array)</code><br>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_free_uint">int array_uint_free(array_uint array)</code><br>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_free_double">int array_double_free(array_double array)</code><br>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_free_ldouble">int array_ldouble_free(array_ldouble array)</code><br>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_free_mpfr">int array_mpfr_free(array_mpfr array)</code><br>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_free_2_mpfr">int array_2_mpfr_free(array_2_mpfr array)</code><br>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_free_char">int array_char_free(array_char array)</code><br>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_free_str">int array_str_free(array_str array)</code><br>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_free_polynomial_double">int array_polynomial_double_free(array_polynomial_double array)</code><br>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_free_polynomial_ldouble">int array_polynomial_ldouble_free(array_polynomial_ldouble array)</code><br>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_free_polynomial_mpfr">int array_polynomial_mpfr_free(array_polynomial_mpfr array)</code><br>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_free_pthread_t">int array_pthread_t_free(array_pthread_t array)</code><br>
+ </div>
+ <br>
+ free the array <code>array</code>.
+ </li>
+ <br>
+ <li id="func_array_free_vects">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_free_vects_mpfr">int array_mpfr_free_vects(array_mpfr array)</code><br>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_free_vects_2_mpfr">int array_2_mpfr_free_vects(array_2_mpfr array)</code><br>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_free_vects_str">int array_str_free_vects(array_str array)</code><br>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_free_vects_polynomial_double">int array_polynomial_double_free_vects(array_polynomial_double array)</code><br>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_free_vects_polynomial_ldouble">int array_polynomial_ldouble_free_vects(array_polynomial_ldouble array)</code><br>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_free_vects_polynomial_mpfr">int array_polynomial_mpfr_free_vects(array_polynomial_mpfr 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_resize_int">int array_int_resize(array_int* array, unsigned int newsize)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_resize_uint">int array_uint_resize(array_uint* array, unsigned int newsize)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_resize_double">int array_double_resize(array_double* array, unsigned int newsize)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_resize_ldouble">int array_ldouble_resize(array_ldouble* array, unsigned int newsize)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_resize_mpfr">int array_mpfr_resize(array_mpfr* array, unsigned int newsize)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_resize_2_mpfr">int array_2_mpfr_resize(array_2_mpfr* array, unsigned int newsize)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_resize_char">int array_char_resize(array_char* array, unsigned int newsize)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_resize_str">int array_str_resize(array_str* array, unsigned int newsize)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_resize_polynomial_double">int array_polynomial_double_resize(array_polynomial_double* array, unsigned int newsize)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_resize_polynomial_ldouble">int array_polynomial_ldouble_resize(array_polynomial_ldouble* array, unsigned int newsize)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_resize_polynomial_mpfr">int array_polynomial_mpfr_resize(array_polynomial_mpfr* array, unsigned int newsize)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_resize_pthread_t">int array_pthread_t_resize(array_pthread_t* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_append_int">int array_int_append(int value, array_int* array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_append_uint">int array_uint_append(unsigned int value, array_uint* array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_append_double">int array_double_append(double value, array_double* array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_append_ldouble">int array_ldouble_append(long double value, array_ldouble* array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_append_mpfr">int array_mpfr_append(mpfr_t value, array_mpfr* array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_append_2_mpfr">int array_2_mpfr_append(array_mpfr value, array_2_mpfr* array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_append_char">int array_char_append(char value, array_char* array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_append_str">int array_str_append(array_char value, array_str* array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_append_polynomial_double">int array_polynomial_double_append(polynomial_double value, array_polynomial_double* array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_append_polynomial_ldouble">int array_polynomial_ldouble_append(polynomial_ldouble value, array_polynomial_ldouble* array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_append_polynomial_mpfr">int array_polynomial_mpfr_append(polynomial_mpfr value, array_polynomial_mpfr* array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_append_pthread_t">int array_pthread_t_append(pthread_t value, array_pthread_t* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_append_noinit_mpfr">int array_mpfr_append_noinit(int value, array_mpfr* array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_append_noinit_2_mpfr">int array_2_mpfr_append_noinit(unsigned int value, array_2_mpfr* array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_append_noinit_str">int array_str_append_noinit(double value, array_str* array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_append_noinit_polynomial_double">int array_polynomial_double_append_noinit(long double value, array_polynomial_double* array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_append_noinit_polynomial_ldouble">int array_polynomial_ldouble_append_noinit(mpfr_t value, array_polynomial_ldouble* array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_append_noinit_polynomial_mpfr">int array_polynomial_mpfr_append_noinit(array_mpfr value, array_polynomial_mpfr* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_concat_int">int array_int_concat(array_int input, array_int* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_concat_uint">int array_uint_concat(array_uint input, array_uint* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_concat_double">int array_double_concat(array_double input, array_double* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_concat_ldouble">int array_ldouble_concat(array_ldouble input, array_ldouble* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_concat_mpfr">int array_mpfr_concat(array_mpfr input, array_mpfr* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_concat_2_mpfr">int array_2_mpfr_concat(array_2_mpfr input, array_2_mpfr* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_concat_char">int array_char_concat(array_char input, array_char* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_concat_str">int array_str_concat(array_str input, array_str* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_concat_polynomial_double">int array_polynomial_double_concat(array_polynomial_double input, array_polynomial_double* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_concat_polynomial_ldouble">int array_polynomial_ldouble_concat(array_polynomial_ldouble input, array_polynomial_ldouble* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_concat_polynomial_mpfr">int array_polynomial_mpfr_concat(array_polynomial_mpfr input, array_polynomial_mpfr* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_concat_pthread_t">int array_pthread_t_concat(array_pthread_t input, array_pthread_t* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cpy_int">int array_int_cpy(array_int input, array_int* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cpy_uint">int array_uint_cpy(array_uint input, array_uint* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cpy_double">int array_double_cpy(array_double input, array_double* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cpy_ldouble">int array_ldouble_cpy(array_ldouble input, array_ldouble* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cpy_mpfr">int array_mpfr_cpy(array_mpfr input, array_mpfr* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cpy_2_mpfr">int array_2_mpfr_cpy(array_2_mpfr input, array_2_mpfr* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cpy_char">int array_char_cpy(array_char input, array_char* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cpy_str">int array_str_cpy(array_str input, array_str* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cpy_polynomial_double">int array_polynomial_double_cpy(array_polynomial_double input, array_polynomial_double* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cpy_polynomial_ldouble">int array_polynomial_ldouble_cpy(array_polynomial_ldouble input, array_polynomial_ldouble* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cpy_polynomial_mpfr">int array_polynomial_mpfr_cpy(array_polynomial_mpfr input, array_polynomial_mpfr* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cpy_pthread_t">int array_pthread_t_cpy(array_pthread_t input, array_pthread_t* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cpy_noinit_int">int array_int_cpy_noinit(array_int input, array_int* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cpy_noinit_uint">int array_uint_cpy_noinit(array_uint input, array_uint* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cpy_noinit_double">int array_double_cpy_noinit(array_double input, array_double* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cpy_noinit_ldouble">int array_ldouble_cpy_noinit(array_ldouble input, array_ldouble* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cpy_noinit_mpfr">int array_mpfr_cpy_noinit(array_mpfr input, array_mpfr* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cpy_noinit_2_mpfr">int array_2_mpfr_cpy_noinit(array_2_mpfr input, array_2_mpfr* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cpy_noinit_char">int array_char_cpy_noinit(array_char input, array_char* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cpy_noinit_str">int array_str_cpy_noinit(array_str input, array_str* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cpy_noinit_polynomial_double">int array_polynomial_double_cpy_noinit(array_polynomial_double input, array_polynomial_double* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cpy_noinit_polynomial_ldouble">int array_polynomial_ldouble_cpy_noinit(array_polynomial_ldouble input, array_polynomial_ldouble* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cpy_noinit_polynomial_mpfr">int array_polynomial_mpfr_cpy_noinit(array_polynomial_mpfr input, array_polynomial_mpfr* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cpy_noinit_pthread_t">int array_pthread_t_cpy_noinit(array_pthread_t input, array_pthread_t* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_subarray_int">int array_int_subarray(array_int array, unsigned int begin, unsigned int end, array_int* subarray)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_subarray_uint">int array_uint_subarray(array_uint array, unsigned int begin, unsigned int end, array_uint* subarray)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_subarray_double">int array_double_subarray(array_double array, unsigned int begin, unsigned int end, array_double* subarray)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_subarray_ldouble">int array_ldouble_subarray(array_ldouble array, unsigned int begin, unsigned int end, array_ldouble* subarray)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_subarray_mpfr">int array_mpfr_subarray(array_mpfr array, unsigned int begin, unsigned int end, array_mpfr* subarray)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_subarray_2_mpfr">int array_2_mpfr_subarray(array_2_mpfr array, unsigned int begin, unsigned int end, array_2_mpfr* subarray)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_subarray_char">int array_char_subarray(array_char array, unsigned int begin, unsigned int end, array_char* subarray)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_subarray_str">int array_str_subarray(array_str array, unsigned int begin, unsigned int end, array_str* subarray)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_subarray_polynomial_double">int array_polynomial_double_subarray(array_polynomial_double array, unsigned int begin, unsigned int end, array_polynomial_double* subarray)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_subarray_polynomial_ldouble">int array_polynomial_ldouble_subarray(array_polynomial_ldouble array, unsigned int begin, unsigned int end, array_polynomial_ldouble* subarray)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_subarray_polynomial_mpfr">int array_polynomial_mpfr_subarray(array_polynomial_mpfr array, unsigned int begin, unsigned int end, array_polynomial_mpfr* subarray)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_subarray_pthread_t">int array_pthread_t_subarray(array_pthread_t array, unsigned int begin, unsigned int end, array_pthread_t* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_print_int">int array_int_print(array_int array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_print_uint">int array_uint_print(array_uint array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_print_double">int array_double_print(array_double array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_print_ldouble">int array_ldouble_print(array_ldouble array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_print_mpfr">int array_mpfr_print(array_mpfr array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_print_2_mpfr">int array_2_mpfr_print(array_2_mpfr array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_print_char">int array_char_print(array_char array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_print_str">int array_str_print(array_str array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_print_polynomial_double">int array_polynomial_double_print(array_polynomial_double array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_print_polynomial_ldouble">int array_polynomial_ldouble_print(array_polynomial_ldouble array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_print_polynomial_mpfr">int array_polynomial_mpfr_print(array_polynomial_mpfr 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_append_unique_int">int array_int_append_unique(int value, array_int* array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_append_unique_uint">int array_uint_append_unique(unsigned int value, array_uint* array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_append_unique_double">int array_double_append_unique(double value, array_double* array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_append_unique_ldouble">int array_ldouble_append_unique(long double value, array_ldouble* array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_append_unique_mpfr">int array_mpfr_append_unique(mpfr_t value, array_mpfr* array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_append_unique_2_mpfr">int array_2_mpfr_append_unique(array_mpfr value, array_2_mpfr* array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_append_unique_char">int array_char_append_unique(char value, array_char* array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_append_unique_str">int array_str_append_unique(array_char value, array_str* array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_append_unique_pthread_t">int array_pthread_t_append_unique(pthread_t value, array_pthread_t* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_concat_unique_int">int array_int_concat_unique(array_int input, array_int* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_concat_unique_uint">int array_uint_concat_unique(array_uint input, array_uint* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_concat_unique_double">int array_double_concat_unique(array_double input, array_double* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_concat_unique_ldouble">int array_ldouble_concat_unique(array_ldouble input, array_ldouble* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_concat_unique_mpfr">int array_mpfr_concat_unique(array_mpfr input, array_mpfr* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_concat_unique_2_mpfr">int array_2_mpfr_concat_unique(array_2_mpfr input, array_2_mpfr* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_concat_unique_char">int array_char_concat_unique(array_char input, array_char* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_concat_unique_str">int array_str_concat_unique(array_str input, array_str* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_concat_unique_pthread_t">int array_pthread_t_concat_unique(array_pthread_t input, array_pthread_t* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_find_int">int array_int_find(int val, array_int array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_find_uint">int array_uint_find(unsigned int val, array_uint array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_find_double">int array_double_find(double val, array_double array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_find_ldouble">int array_ldouble_find(long double val, array_ldouble array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_find_mpfr">int array_mpfr_find(mpfr_t val, array_mpfr array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_find_2_mpfr">int array_2_mpfr_find(array_mpfr val, array_2_mpfr array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_find_char">int array_char_find(char val, array_char array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_find_str">int array_str_find(array_char val, array_str array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_find_pthread_t">int array_pthread_t_find(pthread_t val, array_pthread_t 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_sort_int">int array_int_sort(array_int array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_sort_uint">int array_uint_sort(array_uint array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_sort_double">int array_double_sort(array_double array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_sort_ldouble">int array_ldouble_sort(array_ldouble array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_sort_mpfr">int array_mpfr_sort(array_mpfr array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_sort_2_mpfr">int array_2_mpfr_sort(array_2_mpfr array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_sort_char">int array_char_sort(array_char array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_sort_str">int array_str_sort(array_str array)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_sort_pthread_t">int array_pthread_t_sort(array_pthread_t 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_sort_sub_int">int array_int_sort_sub(array_int array, unsigned int begin, unsigned int end)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_sort_sub_uint">int array_uint_sort_sub(array_uint array, unsigned int begin, unsigned int end)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_sort_sub_double">int array_double_sort_sub(array_double array, unsigned int begin, unsigned int end)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_sort_sub_ldouble">int array_ldouble_sort_sub(array_ldouble array, unsigned int begin, unsigned int end)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_sort_sub_mpfr">int array_mpfr_sort_sub(array_mpfr array, unsigned int begin, unsigned int end)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_sort_sub_2_mpfr">int array_2_mpfr_sort_sub(array_2_mpfr array, unsigned int begin, unsigned int end)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_sort_sub_char">int array_char_sort_sub(array_char array, unsigned int begin, unsigned int end)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_sort_sub_str">int array_str_sort_sub(array_str array, unsigned int begin, unsigned int end)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_sort_sub_pthread_t">int array_pthread_t_sort_sub(array_pthread_t 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cmp_int">int array_int_cmp(array_int array1, array_int array2)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cmp_uint">int array_uint_cmp(array_uint array1, array_uint array2)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cmp_double">int array_double_cmp(array_double array1, array_double array2)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cmp_ldouble">int array_ldouble_cmp(array_ldouble array1, array_ldouble array2)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cmp_mpfr">int array_mpfr_cmp(array_mpfr array1, array_mpfr array2)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cmp_2_mpfr">int array_2_mpfr_cmp(array_2_mpfr array1, array_2_mpfr array2)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cmp_char">int array_char_cmp(array_char array1, array_char array2)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cmp_str">int array_str_cmp(array_str array1, array_str array2)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_array_cmp_pthread_t">int array_pthread_t_cmp(array_pthread_t array1, array_pthread_t 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:
+
+
+ <ul>
+
+ <li id="struct_polynomial_double">
+ <code>polynomial_double</code>:
+ <code>{ array_double coefficients, array_uint orders }</code>
+ </li>
+
+ <li id="struct_polynomial_ldouble">
+ <code>polynomial_ldouble</code>:
+ <code>{ array_ldouble coefficients, array_uint orders }</code>
+ </li>
+
+ <li id="struct_polynomial_mpfr">
+ <code>polynomial_mpfr</code>:
+ <code>{ array_mpfr coefficients, array_uint 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_init_double">polynomial_double_init(polynomial_double* poly, unsigned int memory)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_init_ldouble">polynomial_ldouble_init(polynomial_ldouble* poly, unsigned int memory)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_init_mpfr">polynomial_mpfr_init(polynomial_mpfr* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_free_double">polynomial_double_free(polynomial_double poly)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_free_ldouble">polynomial_ldouble_free(polynomial_ldouble poly)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_free_mpfr">polynomial_mpfr_free(polynomial_mpfr poly)</code>
+ </div>
+ <br>
+ free the polynomial <code>poly</code>.
+ </li>
+ <br>
+ <li id="func_polynomial_resize">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_resize_double">polynomial_double_resize(polynomial_double* poly, unsigned int newsize)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_resize_ldouble">polynomial_ldouble_resize(polynomial_ldouble* poly, unsigned int newsize)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_resize_mpfr">polynomial_mpfr_resize(polynomial_mpfr* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_append_double">polynomial_double_add_monomial(double val, unsigned int order, polynomial_double* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_append_ldouble">polynomial_ldouble_add_monomial(long double val, unsigned int order, polynomial_ldouble* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_append_mpfr">polynomial_mpfr_add_monomial(mpfr_t val, unsigned int order, polynomial_mpfr* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_append_d_ldouble">polynomial_ldouble_add_monomial_dui(double val, unsigned int order, polynomial_ldouble* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_append_d_mpfr">polynomial_mpfr_add_monomial_dui(double val, unsigned int order, polynomial_mpfr* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_cpy_double">polynomial_double_cpy(polynomial_double input, polynomial_double* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_cpy_ldouble">polynomial_ldouble_cpy(polynomial_ldouble input, polynomial_ldouble* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_cpy_mpfr">polynomial_mpfr_cpy(polynomial_mpfr input, polynomial_mpfr* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_cpy_noinit_double">polynomial_double_cpy_noinit(polynomial_double input, polynomial_double* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_cpy_noinit_ldouble">polynomial_ldouble_cpy_noinit(polynomial_ldouble input, polynomial_ldouble* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_cpy_noinit_mpfr">polynomial_mpfr_cpy_noinit(polynomial_mpfr input, polynomial_mpfr* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_add_double">polynomial_double_add(polynomial poly1, polynomial_double poly2, polynomial_double* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_add_ldouble">polynomial_ldouble_add(polynomial poly1, polynomial_ldouble poly2, polynomial_ldouble* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_add_mpfr">polynomial_mpfr_add(polynomial poly1, polynomial_mpfr poly2, polynomial_mpfr* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_add_inplace_double">polynomial_double_add_inplace(polynomial_double poly1, polynomial_double* poly2)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_add_inplace_ldouble">polynomial_ldouble_add_inplace(polynomial_ldouble poly1, polynomial_ldouble* poly2)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_add_inplace_mpfr">polynomial_mpfr_add_inplace(polynomial_mpfr poly1, polynomial_mpfr* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_mul_scalar_double">polynomial_double_mul_scalar(double x, polynomial_double poly, polynomial_double* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_mul_scalar_ldouble">polynomial_ldouble_mul_scalar(long double x, polynomial_ldouble poly, polynomial_ldouble* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_mul_scalar_mpfr">polynomial_mpfr_mul_scalar(mpfr_t x, polynomial_mpfr poly, polynomial_mpfr* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_mul_scalar_inplace_double">polynomial_double_mul_scalar_inplace(double x, polynomial_double* poly)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_mul_scalar_inplace_ldouble">polynomial_ldouble_mul_scalar_inplace(long double x, polynomial_ldouble* poly)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_mul_scalar_inplace_mpfr">polynomial_mpfr_mul_scalar_inplace(mpfr_t x, polynomial_mpfr* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_mul_monomial_double">polynomial_double_mul_monomial(double x, unsigned int order, polynomial_double poly, polynomial_double* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_mul_monomial_ldouble">polynomial_ldouble_mul_monomial(long double x, unsigned int order, polynomial_ldouble poly, polynomial_ldouble* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_mul_monomial_mpfr">polynomial_mpfr_mul_monomial(mpfr_t x, unsigned int order, polynomial_mpfr poly, polynomial_mpfr* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_mul_monomial_inplace_double">polynomial_double_mul_monomial_inplace(double x, unsigned int order, polynomial_double* poly)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_mul_monomial_inplace_ldouble">polynomial_ldouble_mul_monomial_inplace(long double x, unsigned int order, polynomial_ldouble* poly)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_mul_monomial_inplace_mpfr">polynomial_mpfr_mul_monomial_inplace(mpfr_t x, unsigned int order, polynomial_mpfr* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_mul_double">polynomial_double_mul(polynomial_double poly1, polynomial_double poly2, polynomial_double* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_mul_ldouble">polynomial_ldouble_mul(polynomial_ldouble poly1, polynomial_ldouble poly2, polynomial_ldouble* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_mul_mpfr">polynomial_mpfr_mul(polynomial_mpfr poly1, polynomial_mpfr poly2, polynomial_mpfr* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_mul_inplace_double">polynomial_double_mul_inplace(polynomial_double poly1, polynomial_double* poly2)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_mul_inplace_ldouble">polynomial_ldouble_mul_inplace(polynomial_ldouble poly1, polynomial_ldouble* poly2)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_mul_inplace_mpfr">polynomial_mpfr_mul_inplace(polynomial_mpfr poly1, polynomial_mpfr* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_derive_double">polynomial_double_derive(polynomial_double poly, polynomial_double* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_derive_ldouble">polynomial_ldouble_derive(polynomial_ldouble poly, polynomial_ldouble* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_derive_mpfr">polynomial_mpfr_derive(polynomial_mpfr poly, polynomial_mpfr* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_derive_inplace_double">polynomial_double_derive_inplace(polynomial_double* poly)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_derive_inplace_ldouble">polynomial_ldouble_derive_inplace(polynomial_ldouble* poly)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_derive_inplace_mpfr">polynomial_mpfr_derive_inplace(polynomial_mpfr* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_evaluate_double">polynomial_double_evaluate(double* out, double x, polynomial_double poly)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_evaluate_ldouble">polynomial_ldouble_evaluate(long double* out, long double x, polynomial_ldouble poly)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_evaluate_mpfr">polynomial_mpfr_evaluate(mpfr_t* out, mpfr_t x, polynomial_mpfr 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_print_double">polynomial_double_print(polynomial_double poly)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_print_ldouble">polynomial_ldouble_print(polynomial_ldouble poly)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_print_mpfr">polynomial_mpfr_print(polynomial_mpfr poly)</code>
+ </div>
+ <br>
+ print <code>poly</code>.
+ </li>
+ <br>
+ <li id="func_polynomial_legendre">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_legendre_double">polynomial_double_legendre(unsigned int n, polynomial_double* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_legendre_ldouble">polynomial_ldouble_legendre(unsigned int n, polynomial_ldouble* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomial_legendre_mpfr">polynomial_mpfr_legendre(unsigned int n, polynomial_mpfr* 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>
+
+
+ <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>
+
+ <li id="struct_polynomialMV_int">
+ <code>polynomialMV_int</code>:
+ <code>{ int* coefficients, array_int factors, unsigned int length, unsigned int memory }</code>
+ </li>
+
+ <li id="struct_polynomialMV_mpz">
+ <code>polynomialMV_mpz</code>:
+ <code>{ mpz_t* coefficients, array_int 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_init_int">polynomialMV_int_init(polynomialMV_int* poly, unsigned int memory)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_init_mpz">polynomialMV_mpz_init(polynomialMV_mpz* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_free_int">polynomialMV_int_free(polynomialMV_int poly)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_free_mpz">polynomialMV_mpz_free(polynomialMV_mpz poly)</code>
+ </div>
+ <br>
+ free the polynomial <code>poly</code>.
+ </li>
+ <br>
+ <li id="func_polynomialMV_resize">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_resize_int">polynomialMV_int_resize(polynomialMV_int* poly, unsigned int newsize)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_resize_mpz">polynomialMV_mpz_resize(polynomialMV_mpz* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_cpy_int">polynomialMV_int_cpy(polynomialMV_int input, polynomialMV_int* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_cpy_mpz">polynomialMV_mpz_cpy(polynomialMV_mpz input, polynomialMV_mpz* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_cpy_noinit_int">polynomialMV_int_cpy_noinit(polynomialMV_int input, polynomialMV_int* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_cpy_noinit_mpz">polynomialMV_mpz_cpy_noinit(polynomialMV_mpz input, polynomialMV_mpz* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_append_int">polynomialMV_int_append(array_int factor, int coef, polynomialMV_int* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_append_mpz">polynomialMV_mpz_append(array_int factor, mpz_t coef, polynomialMV_mpz* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_append_inplace_int">polynomialMV_int_append_inplace(array_int factor, int coef, polynomialMV_int* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_append_inplace_mpz">polynomialMV_mpz_append_inplace(array_int factor, mpz_t coef, polynomialMV_mpz* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_append_noinit_int">polynomialMV_int_append_noinit(array_int factor, int coef, polynomialMV_int* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_append_noinit_mpz">polynomialMV_mpz_append_noinit(array_int factor, mpz_t coef, polynomialMV_mpz* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_append_noinitfactor_int">polynomialMV_int_append_noinitfactor(array_int factor, int coef, polynomialMV_int* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_append_noinitfactor_mpz">polynomialMV_mpz_append_noinitfactor(array_int factor, mpz_t coef, polynomialMV_mpz* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_append_noinit_inplace_int">polynomialMV_int_append_noinit_inplace(array_int factor, int coef, polynomial* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_append_noinit_inplace_mpz">polynomialMV_mpz_append_noinit_inplace(array_int factor, mpz_t 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_append_noinitfactor_inplace_int">polynomialMV_int_append_noinit_inplace(array_int factor, int coef, polynomial* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_append_noinitfactor_inplace_mpz">polynomialMV_mpz_append_noinit_inplace(array_int factor, mpz_t 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_add_int">polynomialMV_int_add(polynomialMV_int poly1, polynomialMV_int poly2, polynomialMV_int* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_add_mpz">polynomialMV_mpz_add(polynomialMV_mpz poly1, polynomialMV_mpz poly2, polynomialMV_mpz* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_add_inplace_int">polynomialMV_int_add_inplace(polynomialMV_int poly1, polynomialMV_int* poly2)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_add_inplace_mpz">polynomialMV_mpz_add_inplace(polynomialMV_mpz poly1, polynomialMV_mpz* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_multiply_scalar_int">polynomialMV_int_multiply_scalar(polynomial poly, int num)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_multiply_scalar_mpz">polynomialMV_mpz_multiply_scalar(polynomial poly, mpz_t 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_prod_int">polynomialMV_int_prod(polynomialMV_int poly1, polynomialMV_int poly2, polynomialMV_int* output)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_prod_mpz">polynomialMV_mpz_prod(polynomialMV_mpz poly1, polynomialMV_mpz poly2, polynomialMV_mpz* 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_order_int">polynomialMV_int_order(polynomialMV_int poly)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_order_mpz">polynomialMV_mpz_order(polynomialMV_mpz 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">
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_print_int">polynomialMV_int_print(polynomialMV_int poly)</code>
+ </div>
+
+ <div style="margin-bottom:5pt">
+ <code id="func_polynomialMV_print_mpz">polynomialMV_mpz_print(polynomialMV_mpz 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>
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>
diff --git a/doc/libinum-examples/Makefile b/doc/libinum-examples/Makefile
new file mode 100644
index 0000000..5c7ccc1
--- /dev/null
+++ b/doc/libinum-examples/Makefile
@@ -0,0 +1,80 @@
+# whether to link dynamically
+# if static=0 then link dynamically
+# if static=2 then link statically
+# if static=1 then link libkondo statically but other libraries dynamically
+STATIC=1
+
+VERSION=0.3.1
+
+# products of the compilation
+PROJECT_BINS= root_newton integral_gauss-legendre
+
+# debug and optimization flags
+#DB= -ggdb
+OPT= -O3
+
+# warning flags
+WARNINGS= -Wall -Wextra -Wno-strict-overflow -std=c99 -pedantic -Wno-unused-parameter
+
+# compiler
+CC=/usr/bin/gcc
+LD=$(CC)
+
+# directories
+INCLUDE =
+LIB =
+#INCLUDE = -I../../include
+#LIB = -L../../build
+
+# flags
+override LDFLAGS +=$(LIB)
+override CFLAGS +=$(INCLUDE) $(DB) $(OPT) $(WARNINGS)
+
+# build directories
+BUILDDIR=./build
+SRCDIR=./src
+OBJDIR=./objs
+
+# objects
+OBJS = $(addprefix $(OBJDIR)/, root_newton.o integral_gauss-legendre.o)
+
+# flags which depend on whether to link statically or dynamically
+# lib flag
+LIBINUM_FLAG=-linum
+# additional library required for static linking
+XTRA_LIBS=
+
+ifeq ($(STATIC),1)
+ # libinum is linked against libm, libmpfr, libgmp and libpthread
+ XTRA_LIBS=-lm -lmpfr -lgmp -lpthread
+ # link binaries using the static library
+ LIBINUM_FLAG=-l:libinum.a
+else ifeq ($(STATIC),2)
+ # libinum is linked against libm, libmpfr, libgmp and libpthread
+ XTRA_LIBS=-lm -lmpfr -lgmp -lpthread
+ # link binaries statically
+ override LDFLAGS += -static
+else
+ # required flag for subsequent dynamic linking
+ override CFLAGS += -fPIC
+endif
+
+
+all: init $(PROJECT_BINS)
+
+# create dirs
+init:
+ @[ -d $(OBJDIR) ] || /bin/mkdir $(OBJDIR)
+ @[ -d $(BUILDDIR) ] || /bin/mkdir $(BUILDDIR)
+
+root_newton:
+ $(CC) -c $(CFLAGS) src/$@.c -o objs/$@.o
+ $(LD) $(LDFLAGS) -o $(BUILDDIR)/$@ objs/$@.o $(LIBINUM_FLAG) $(XTRA_LIBS)
+
+integral_gauss-legendre:
+ $(CC) -c $(CFLAGS) src/$@.c -o objs/$@.o
+ $(LD) $(LDFLAGS) -o $(BUILDDIR)/$@ objs/$@.o $(LIBINUM_FLAG) $(XTRA_LIBS)
+
+clean:
+ @rm -rf $(OBJDIR)
+ @rm -rf $(BUILDDIR)
diff --git a/doc/libinum-examples/build/integral_gauss-legendre b/doc/libinum-examples/build/integral_gauss-legendre
new file mode 100755
index 0000000..b86cfe7
--- /dev/null
+++ b/doc/libinum-examples/build/integral_gauss-legendre
Binary files differ
diff --git a/doc/libinum-examples/build/root_newton b/doc/libinum-examples/build/root_newton
new file mode 100755
index 0000000..68a2e50
--- /dev/null
+++ b/doc/libinum-examples/build/root_newton
Binary files differ
diff --git a/doc/libinum-examples/objs/integral_gauss-legendre.o b/doc/libinum-examples/objs/integral_gauss-legendre.o
new file mode 100644
index 0000000..83841c9
--- /dev/null
+++ b/doc/libinum-examples/objs/integral_gauss-legendre.o
Binary files differ
diff --git a/doc/libinum-examples/objs/root_newton.o b/doc/libinum-examples/objs/root_newton.o
new file mode 100644
index 0000000..1e567f7
--- /dev/null
+++ b/doc/libinum-examples/objs/root_newton.o
Binary files differ
diff --git a/doc/libinum-examples/src/integral_gauss-legendre.c b/doc/libinum-examples/src/integral_gauss-legendre.c
new file mode 100644
index 0000000..f65465f
--- /dev/null
+++ b/doc/libinum-examples/src/integral_gauss-legendre.c
@@ -0,0 +1,92 @@
+#include <stdio.h>
+#include <stdarg.h>
+// define MPFR_USE_VA_LIST to enable the use of mpfr_inits and mpfr_clears
+#define MPFR_USE_VA_LIST
+#include <mpfr.h>
+#include <libinum.h>
+
+int func(mpfr_t* out, mpfr_t in, void* extra_args);
+
+int main(int argc, const char* argv[]){
+ int ret;
+ mpfr_t tolerance, val, lower, upper;
+ array_mpfr abcissa, weights;
+
+ // precision of MPFR floats
+ mpfr_set_default_prec(53);
+
+ // tolerance for computing weights
+ mpfr_init(tolerance);
+ mpfr_set_d(tolerance, 1.e-11, MPFR_RNDN);
+
+ // compute weights
+ ret=gauss_legendre_weights_mpfr(10, tolerance, 10000, &abcissa, &weights);
+ // return codes
+ if(ret==LIBINUM_ERROR_MAXITER){
+ printf("error: maximum number of iterations reached when computing the integration abcissa\n");
+ mpfr_clear(tolerance);
+ return(ret);
+ }
+ else if(ret==LIBINUM_ERROR_NAN){
+ printf("error: infinity encountered when computing the integration abcissa\n");
+ mpfr_clear(tolerance);
+ return(ret);
+ }
+ else{
+ printf("abcissa:\n");
+ array_mpfr_print(abcissa);
+ printf("\nweights:\n");
+ array_mpfr_print(weights);
+ printf("\n");
+ }
+
+ mpfr_clear(tolerance);
+
+ mpfr_inits(val, lower, upper, NULL);
+
+ mpfr_set_ui(lower, 0, MPFR_RNDN);
+ mpfr_set_ui(upper, 2, MPFR_RNDN);
+
+ ret=integrate_gauss_mpfr(&val, &func, lower, upper, abcissa, weights, NULL);
+ // return codes
+ if(ret==LIBINUM_ERROR_SIZE_MISMATCH){
+ printf("error: the mpfr_arrays 'abcissa' and 'weights' must have the same length\n");
+ mpfr_clears(val, upper, lower, NULL);
+ array_mpfr_free(abcissa);
+ array_mpfr_free(weights);
+ return(ret);
+ }
+ else if(ret==LIBINUM_ERROR_NAN){
+ printf("error: the integrand is singular\n");
+ array_mpfr_free(abcissa);
+ array_mpfr_free(weights);
+ mpfr_clears(val, upper, lower, NULL);
+ return(ret);
+ }
+ else{
+ printf("\\int_0^2 x/sin(x) dx = ");
+ fprint_mpfr(stdout, val);
+ printf("\n");
+ }
+
+ mpfr_clears(val, upper, lower, NULL);
+ array_mpfr_free(abcissa);
+ array_mpfr_free(weights);
+
+ return(0);
+}
+
+/*
+// e^x
+int func(mpfr_t* out, mpfr_t in, void* extra_args){
+ mpfr_exp(*out, in, MPFR_RNDN);
+ return(0);
+}
+*/
+
+// x/sin(x)
+int func(mpfr_t* out, mpfr_t in, void* extra_args){
+ mpfr_sin(*out, in, MPFR_RNDN);
+ mpfr_div(*out, in, *out, MPFR_RNDN);
+ return(0);
+}
diff --git a/doc/libinum-examples/src/root_newton.c b/doc/libinum-examples/src/root_newton.c
new file mode 100644
index 0000000..f307c58
--- /dev/null
+++ b/doc/libinum-examples/src/root_newton.c
@@ -0,0 +1,58 @@
+#include <stdio.h>
+#include <stdarg.h>
+// define MPFR_USE_VA_LIST to enable the use of mpfr_inits and mpfr_clears
+#define MPFR_USE_VA_LIST
+#include <mpfr.h>
+#include <libinum.h>
+
+int func(mpfr_t* out, mpfr_t in, void* extra_args);
+int dfunc(mpfr_t* out, mpfr_t in, void* extra_args);
+
+int main(int argc, const char* argv[]){
+ int ret;
+ mpfr_t init, prec, x;
+ unsigned int maxiter;
+ int extra_arg;
+
+ mpfr_inits(init, prec, x, NULL);
+
+ // start at 2
+ mpfr_set_ui(init, 2, MPFR_RNDN);
+ // precision
+ mpfr_set_d(prec, 1.e-30, MPFR_RNDN);
+ // maximum number of iterations before error
+ maxiter=10000;
+ // extra argument
+ extra_arg=4;
+
+ // compute root
+ ret=root_newton_mpfr(&x, &func, &dfunc, init, prec, maxiter, &extra_arg);
+
+ // return codes
+ if(ret==LIBINUM_ERROR_MAXITER){
+ printf("error: maximum number of iterations reached\n");
+ }
+ else if(ret==LIBINUM_ERROR_NAN){
+ printf("error: infinity encountered\n");
+ }
+ else{
+ mpfr_printf("% 14.7Re\n", x);
+ }
+
+ mpfr_clears(init, prec, x, NULL);
+
+ return(0);
+}
+
+// x^2-1
+int func(mpfr_t* out, mpfr_t in, void* extra_args){
+ mpfr_pow_ui(*out, in, 2, MPFR_RNDN);
+ mpfr_add_d(*out, *out, -1./ *((int*)extra_args), MPFR_RNDN);
+ return(0);
+}
+
+// 2*x
+int dfunc(mpfr_t* out, mpfr_t in, void* extra_args){
+ mpfr_mul_ui(*out, in, 2, MPFR_RNDN);
+ return(0);
+}
diff --git a/include/libinum.h b/include/libinum.h
new file mode 100644
index 0000000..bd510cc
--- /dev/null
+++ b/include/libinum.h
@@ -0,0 +1,20 @@
+#ifndef LIBINUM_H
+#define LIBINUM_H
+
+#define LIBINUM_VERSION "1.0"
+
+#include <libinum/types.h>
+
+#include <libinum/errors.h>
+
+#include <libinum/integral.h>
+#include <libinum/root.h>
+
+#include <libinum/utils.h>
+
+#include <libinum/array.h>
+#include <libinum/polynomial.h>
+#include <libinum/polynomialMV.h>
+
+
+#endif
diff --git a/include/libinum/array.h b/include/libinum/array.h
new file mode 120000
index 0000000..5071e5e
--- /dev/null
+++ b/include/libinum/array.h
@@ -0,0 +1 @@
+../../src/array.h \ No newline at end of file
diff --git a/include/libinum/array_2_mpfr.h b/include/libinum/array_2_mpfr.h
new file mode 120000
index 0000000..1538fe7
--- /dev/null
+++ b/include/libinum/array_2_mpfr.h
@@ -0,0 +1 @@
+../../src/array_2_mpfr.h \ No newline at end of file
diff --git a/include/libinum/array_base.h b/include/libinum/array_base.h
new file mode 120000
index 0000000..263b8eb
--- /dev/null
+++ b/include/libinum/array_base.h
@@ -0,0 +1 @@
+../../src/array_base.h \ No newline at end of file
diff --git a/include/libinum/array_char.h b/include/libinum/array_char.h
new file mode 120000
index 0000000..5023391
--- /dev/null
+++ b/include/libinum/array_char.h
@@ -0,0 +1 @@
+../../src/array_char.h \ No newline at end of file
diff --git a/include/libinum/array_double.h b/include/libinum/array_double.h
new file mode 120000
index 0000000..c53088c
--- /dev/null
+++ b/include/libinum/array_double.h
@@ -0,0 +1 @@
+../../src/array_double.h \ No newline at end of file
diff --git a/include/libinum/array_int.h b/include/libinum/array_int.h
new file mode 120000
index 0000000..3ebf9b3
--- /dev/null
+++ b/include/libinum/array_int.h
@@ -0,0 +1 @@
+../../src/array_int.h \ No newline at end of file
diff --git a/include/libinum/array_ldouble.h b/include/libinum/array_ldouble.h
new file mode 120000
index 0000000..64db9f3
--- /dev/null
+++ b/include/libinum/array_ldouble.h
@@ -0,0 +1 @@
+../../src/array_ldouble.h \ No newline at end of file
diff --git a/include/libinum/array_mpfr.h b/include/libinum/array_mpfr.h
new file mode 120000
index 0000000..ab0c709
--- /dev/null
+++ b/include/libinum/array_mpfr.h
@@ -0,0 +1 @@
+../../src/array_mpfr.h \ No newline at end of file
diff --git a/include/libinum/array_polynomial_double.h b/include/libinum/array_polynomial_double.h
new file mode 120000
index 0000000..fc99294
--- /dev/null
+++ b/include/libinum/array_polynomial_double.h
@@ -0,0 +1 @@
+../../src/array_polynomial_double.h \ No newline at end of file
diff --git a/include/libinum/array_polynomial_ldouble.h b/include/libinum/array_polynomial_ldouble.h
new file mode 120000
index 0000000..90eb96e
--- /dev/null
+++ b/include/libinum/array_polynomial_ldouble.h
@@ -0,0 +1 @@
+../../src/array_polynomial_ldouble.h \ No newline at end of file
diff --git a/include/libinum/array_polynomial_mpfr.h b/include/libinum/array_polynomial_mpfr.h
new file mode 120000
index 0000000..8529b91
--- /dev/null
+++ b/include/libinum/array_polynomial_mpfr.h
@@ -0,0 +1 @@
+../../src/array_polynomial_mpfr.h \ No newline at end of file
diff --git a/include/libinum/array_pthread_t.h b/include/libinum/array_pthread_t.h
new file mode 120000
index 0000000..5cd5570
--- /dev/null
+++ b/include/libinum/array_pthread_t.h
@@ -0,0 +1 @@
+../../src/array_pthread_t.h \ No newline at end of file
diff --git a/include/libinum/array_str.h b/include/libinum/array_str.h
new file mode 120000
index 0000000..894bc38
--- /dev/null
+++ b/include/libinum/array_str.h
@@ -0,0 +1 @@
+../../src/array_str.h \ No newline at end of file
diff --git a/include/libinum/array_type.h b/include/libinum/array_type.h
new file mode 120000
index 0000000..d33d613
--- /dev/null
+++ b/include/libinum/array_type.h
@@ -0,0 +1 @@
+../../src/array_type.h \ No newline at end of file
diff --git a/include/libinum/array_uint.h b/include/libinum/array_uint.h
new file mode 120000
index 0000000..8702167
--- /dev/null
+++ b/include/libinum/array_uint.h
@@ -0,0 +1 @@
+../../src/array_uint.h \ No newline at end of file
diff --git a/include/libinum/errors.h b/include/libinum/errors.h
new file mode 120000
index 0000000..813a959
--- /dev/null
+++ b/include/libinum/errors.h
@@ -0,0 +1 @@
+../../src/errors.h \ No newline at end of file
diff --git a/include/libinum/integral.h b/include/libinum/integral.h
new file mode 120000
index 0000000..8649ee4
--- /dev/null
+++ b/include/libinum/integral.h
@@ -0,0 +1 @@
+../../src/integral.h \ No newline at end of file
diff --git a/include/libinum/integral_base.h b/include/libinum/integral_base.h
new file mode 120000
index 0000000..b1e8d7e
--- /dev/null
+++ b/include/libinum/integral_base.h
@@ -0,0 +1 @@
+../../src/integral_base.h \ No newline at end of file
diff --git a/include/libinum/integral_double.h b/include/libinum/integral_double.h
new file mode 120000
index 0000000..4b6bf23
--- /dev/null
+++ b/include/libinum/integral_double.h
@@ -0,0 +1 @@
+../../src/integral_double.h \ No newline at end of file
diff --git a/include/libinum/integral_ldouble.h b/include/libinum/integral_ldouble.h
new file mode 120000
index 0000000..e2b597e
--- /dev/null
+++ b/include/libinum/integral_ldouble.h
@@ -0,0 +1 @@
+../../src/integral_ldouble.h \ No newline at end of file
diff --git a/include/libinum/integral_mpfr.h b/include/libinum/integral_mpfr.h
new file mode 120000
index 0000000..8b709df
--- /dev/null
+++ b/include/libinum/integral_mpfr.h
@@ -0,0 +1 @@
+../../src/integral_mpfr.h \ No newline at end of file
diff --git a/include/libinum/polynomial.h b/include/libinum/polynomial.h
new file mode 120000
index 0000000..b1969f9
--- /dev/null
+++ b/include/libinum/polynomial.h
@@ -0,0 +1 @@
+../../src/polynomial.h \ No newline at end of file
diff --git a/include/libinum/polynomialMV.h b/include/libinum/polynomialMV.h
new file mode 120000
index 0000000..ab198e6
--- /dev/null
+++ b/include/libinum/polynomialMV.h
@@ -0,0 +1 @@
+../../src/polynomialMV.h \ No newline at end of file
diff --git a/include/libinum/polynomialMV_base.h b/include/libinum/polynomialMV_base.h
new file mode 120000
index 0000000..f81b0d2
--- /dev/null
+++ b/include/libinum/polynomialMV_base.h
@@ -0,0 +1 @@
+../../src/polynomialMV_base.h \ No newline at end of file
diff --git a/include/libinum/polynomialMV_int.h b/include/libinum/polynomialMV_int.h
new file mode 120000
index 0000000..4ff8e55
--- /dev/null
+++ b/include/libinum/polynomialMV_int.h
@@ -0,0 +1 @@
+../../src/polynomialMV_int.h \ No newline at end of file
diff --git a/include/libinum/polynomialMV_mpz.h b/include/libinum/polynomialMV_mpz.h
new file mode 120000
index 0000000..dad4fb1
--- /dev/null
+++ b/include/libinum/polynomialMV_mpz.h
@@ -0,0 +1 @@
+../../src/polynomialMV_mpz.h \ No newline at end of file
diff --git a/include/libinum/polynomialMV_type.h b/include/libinum/polynomialMV_type.h
new file mode 120000
index 0000000..6a1e262
--- /dev/null
+++ b/include/libinum/polynomialMV_type.h
@@ -0,0 +1 @@
+../../src/polynomialMV_type.h \ No newline at end of file
diff --git a/include/libinum/polynomial_base.h b/include/libinum/polynomial_base.h
new file mode 120000
index 0000000..dbb75ea
--- /dev/null
+++ b/include/libinum/polynomial_base.h
@@ -0,0 +1 @@
+../../src/polynomial_base.h \ No newline at end of file
diff --git a/include/libinum/polynomial_double.h b/include/libinum/polynomial_double.h
new file mode 120000
index 0000000..43f3379
--- /dev/null
+++ b/include/libinum/polynomial_double.h
@@ -0,0 +1 @@
+../../src/polynomial_double.h \ No newline at end of file
diff --git a/include/libinum/polynomial_ldouble.h b/include/libinum/polynomial_ldouble.h
new file mode 120000
index 0000000..4d5e231
--- /dev/null
+++ b/include/libinum/polynomial_ldouble.h
@@ -0,0 +1 @@
+../../src/polynomial_ldouble.h \ No newline at end of file
diff --git a/include/libinum/polynomial_mpfr.h b/include/libinum/polynomial_mpfr.h
new file mode 120000
index 0000000..ab26be9
--- /dev/null
+++ b/include/libinum/polynomial_mpfr.h
@@ -0,0 +1 @@
+../../src/polynomial_mpfr.h \ No newline at end of file
diff --git a/include/libinum/polynomial_type.h b/include/libinum/polynomial_type.h
new file mode 120000
index 0000000..22cd70d
--- /dev/null
+++ b/include/libinum/polynomial_type.h
@@ -0,0 +1 @@
+../../src/polynomial_type.h \ No newline at end of file
diff --git a/include/libinum/root.h b/include/libinum/root.h
new file mode 120000
index 0000000..4bf0b8d
--- /dev/null
+++ b/include/libinum/root.h
@@ -0,0 +1 @@
+../../src/root.h \ No newline at end of file
diff --git a/include/libinum/root_base.h b/include/libinum/root_base.h
new file mode 120000
index 0000000..e66cb8e
--- /dev/null
+++ b/include/libinum/root_base.h
@@ -0,0 +1 @@
+../../src/root_base.h \ No newline at end of file
diff --git a/include/libinum/root_double.h b/include/libinum/root_double.h
new file mode 120000
index 0000000..338967e
--- /dev/null
+++ b/include/libinum/root_double.h
@@ -0,0 +1 @@
+../../src/root_double.h \ No newline at end of file
diff --git a/include/libinum/root_ldouble.h b/include/libinum/root_ldouble.h
new file mode 120000
index 0000000..59c64a4
--- /dev/null
+++ b/include/libinum/root_ldouble.h
@@ -0,0 +1 @@
+../../src/root_ldouble.h \ No newline at end of file
diff --git a/include/libinum/root_mpfr.h b/include/libinum/root_mpfr.h
new file mode 120000
index 0000000..bfd6182
--- /dev/null
+++ b/include/libinum/root_mpfr.h
@@ -0,0 +1 @@
+../../src/root_mpfr.h \ No newline at end of file
diff --git a/include/libinum/types.h b/include/libinum/types.h
new file mode 120000
index 0000000..6ca5d5d
--- /dev/null
+++ b/include/libinum/types.h
@@ -0,0 +1 @@
+../../src/types.h \ No newline at end of file
diff --git a/include/libinum/utils.h b/include/libinum/utils.h
new file mode 120000
index 0000000..64817bb
--- /dev/null
+++ b/include/libinum/utils.h
@@ -0,0 +1 @@
+../../src/utils.h \ No newline at end of file
diff --git a/src/array.c b/src/array.c
new file mode 100644
index 0000000..772cb39
--- /dev/null
+++ b/src/array.c
@@ -0,0 +1,227 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "array.h"
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include "errors.h"
+#include "polynomial.h"
+#include "utils.h"
+
+//--------------------------------------------------
+//
+// integer array (array_int)
+//
+//--------------------------------------------------
+#include "array_int.h"
+#include "array_base.c"
+
+
+//--------------------------------------------------
+//
+// unsigned integer array (array_uint)
+//
+//--------------------------------------------------
+#include "array_uint.h"
+#include "array_base.c"
+
+//--------------------------------------------------
+//
+// double array (array_double)
+//
+//--------------------------------------------------
+#include "array_double.h"
+#include "array_base.c"
+
+
+//--------------------------------------------------
+//
+// long double array (array_ldouble)
+//
+//--------------------------------------------------
+#include "array_ldouble.h"
+#include "array_base.c"
+
+
+//--------------------------------------------------
+//
+// MPFR array (array_mpfr)
+//
+//--------------------------------------------------
+#include "array_mpfr.h"
+#include "array_base.c"
+
+
+//--------------------------------------------------
+//
+// array of MPFR arrays (array_2_mpfr)
+//
+//--------------------------------------------------
+#include "array_2_mpfr.h"
+#include "array_base.c"
+
+
+//--------------------------------------------------
+//
+// character array (array_char)
+//
+//--------------------------------------------------
+#include "array_char.h"
+#include "array_base.c"
+
+// append a char*
+int array_char_append_str(char* str, array_char* output){
+ char* ptr;
+ for (ptr=str;*ptr!='\0';ptr++){
+ array_char_append(*ptr, output);
+ }
+ return(0);
+}
+
+// convert to char*
+int array_char_to_str(array_char input, char** output){
+ unsigned int i;
+ (*output)=calloc(input.length+1,sizeof(char));
+ for(i=0;i<input.length;i++){
+ (*output)[i]=input.values[i];
+ }
+ if((*output)[input.length-1]!='\0'){
+ (*output)[input.length]='\0';
+ }
+ return(0);
+}
+// noinit (changes the size of input if needed)
+char* array_char_to_str_noinit(array_char* input){
+ if(input->values[input->length-1]!='\0'){
+ if(input->length==input->memory){
+ array_char_resize(input,input->length+1);
+ }
+ // add final '\0'
+ input->values[input->length]='\0';
+ }
+ return(input->values);
+}
+
+// convert from char*
+int str_to_array_char(char* str, array_char* output){
+ char* ptr;
+ unsigned int str_len=0;
+ for(ptr=str;*ptr!='\0';ptr++){
+ str_len++;
+ }
+ array_char_init(output, str_len);
+ for(ptr=str;*ptr!='\0';ptr++){
+ array_char_append(*ptr,output);
+ }
+ return(0);
+}
+
+// compare an array_char and a char*
+int array_char_cmp_str(array_char array_char, char* str){
+ unsigned int j;
+ for(j=0;j<array_char.length && str[j]!='\0';j++){
+ if(array_char.values[j]!=str[j]){
+ return(0);
+ }
+ }
+ if(j==array_char.length && str[j]=='\0'){
+ return(1);
+ }
+ return(0);
+}
+
+// format strings
+int array_char_snprintf(array_char* output, char* fmt, ...){
+ size_t size=100;
+ unsigned int extra_size;
+ char* out_str=calloc(size,sizeof(char));
+ char* ptr;
+ va_list vaptr;
+
+ // initialize argument list starting after fmt
+ va_start(vaptr, fmt);
+ // print format
+ extra_size=vsnprintf(out_str, size, fmt, vaptr);
+ va_end(vaptr);
+
+ // if too large
+ if(extra_size>size){
+ // resize
+ free(out_str);
+ // +1 for '\0'
+ size=extra_size+1;
+ out_str=calloc(size,sizeof(char));
+ // read format again
+ va_start(vaptr, fmt);
+ vsnprintf(out_str,size,fmt,vaptr);
+ va_end(vaptr);
+ }
+
+ // write to char array
+ for(ptr=out_str;*ptr!='\0';ptr++){
+ array_char_append(*ptr, output);
+ }
+
+ free(out_str);
+
+ return(0);
+}
+
+
+//--------------------------------------------------
+//
+// string array (array_str)
+//
+//--------------------------------------------------
+#include "array_str.h"
+#include "array_base.c"
+
+
+//--------------------------------------------------
+//
+// mpfr polynomial array (array_polynomial_mpfr)
+//
+//--------------------------------------------------
+#include "array_polynomial_mpfr.h"
+#include "array_base.c"
+
+
+//--------------------------------------------------
+//
+// double polynomial array (array_polynomial_double)
+//
+//--------------------------------------------------
+#include "array_polynomial_double.h"
+#include "array_base.c"
+
+
+//--------------------------------------------------
+//
+// long double polynomial array (array_polynomial_ldouble)
+//
+//--------------------------------------------------
+#include "array_polynomial_ldouble.h"
+#include "array_base.c"
+
+
+//--------------------------------------------------
+//
+// pthread_t array (array_pthread_t)
+//
+//--------------------------------------------------
+#include "array_pthread_t.h"
+#include "array_base.c"
diff --git a/src/array.h b/src/array.h
new file mode 100644
index 0000000..63639a7
--- /dev/null
+++ b/src/array.h
@@ -0,0 +1,150 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Mutable arrays
+*/
+
+#ifndef LIBINUM_ARRAY_H
+#define LIBINUM_ARRAY_H
+
+#include "types.h"
+
+//--------------------------------------------------
+//
+// integer array (array_int)
+//
+//--------------------------------------------------
+#include "array_int.h"
+#include "array_base.h"
+
+
+//--------------------------------------------------
+//
+// unsigned integer array (array_uint)
+//
+//--------------------------------------------------
+#include "array_uint.h"
+#include "array_base.h"
+
+
+//--------------------------------------------------
+//
+// double array (array_double)
+//
+//--------------------------------------------------
+#include "array_double.h"
+#include "array_base.h"
+
+
+//--------------------------------------------------
+//
+// long double array (array_ldouble)
+//
+//--------------------------------------------------
+#include "array_ldouble.h"
+#include "array_base.h"
+
+
+//--------------------------------------------------
+//
+// MPFR array (array_mpfr)
+//
+//--------------------------------------------------
+#include "array_mpfr.h"
+#include "array_base.h"
+
+
+//--------------------------------------------------
+//
+// array of MPFR arrays (array_2_mpfr)
+//
+//--------------------------------------------------
+#include "array_2_mpfr.h"
+#include "array_base.h"
+
+
+//--------------------------------------------------
+//
+// character array (array_char)
+//
+//--------------------------------------------------
+#include "array_char.h"
+#include "array_base.h"
+
+// append a char*
+int array_char_append_str(char* str, array_char* output);
+
+// convert to char*
+int array_char_to_str(array_char input, char** output);
+// noinit (changes the size of input if needed)
+char* array_char_to_str_noinit(array_char* input);
+
+// convert from char*
+int str_to_array_char(char* str, array_char* output);
+
+// compare an array_char and a char*
+int array_char_cmp_str(array_char array_char, char* str);
+
+// format strings
+int array_char_snprintf(array_char* output, char* fmt, ...);
+
+
+//--------------------------------------------------
+//
+// string array (array_str)
+//
+//--------------------------------------------------
+#include "array_str.h"
+#include "array_base.h"
+
+
+//--------------------------------------------------
+//
+// mpfr polynomial array (array_polynomial_mpfr)
+//
+//--------------------------------------------------
+#include "array_polynomial_mpfr.h"
+#include "array_base.h"
+
+
+//--------------------------------------------------
+//
+// double polynomial array (array_polynomial_double)
+//
+//--------------------------------------------------
+#include "array_polynomial_double.h"
+#include "array_base.h"
+
+
+//--------------------------------------------------
+//
+// long double polynomial array (array_polynomial_ldouble)
+//
+//--------------------------------------------------
+#include "array_polynomial_ldouble.h"
+#include "array_base.h"
+
+
+//--------------------------------------------------
+//
+// pthread_t array (array_pthread_t)
+//
+//--------------------------------------------------
+#include "array_pthread_t.h"
+#include "array_base.h"
+
+#endif
diff --git a/src/array_2_mpfr.h b/src/array_2_mpfr.h
new file mode 100644
index 0000000..afd99d9
--- /dev/null
+++ b/src/array_2_mpfr.h
@@ -0,0 +1,54 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Preprocessor macros for arrays of MPFR float arrays
+*/
+
+
+// reset CPP macros
+#undef ARRAY_TYPENAME
+#undef ARRAY_FUNC
+#undef ARRAY_VAL_TYPE
+#undef ARRAY_VAL_FREE
+#undef ARRAY_VAL_SET
+#undef ARRAY_VAL_CPY
+#undef ARRAY_VAL_IFEQ
+#undef ARRAY_VAL_IFLT
+#undef ARRAY_VAL_IFGT
+#undef ARRAY_VAL_PRINT
+
+
+// name of the polynomial type
+#define ARRAY_TYPENAME array_2_mpfr
+// prefix of function names
+#define ARRAY_FUNC(NAME) array_2_mpfr_ ## NAME
+
+// type of values
+#define ARRAY_VAL_TYPE array_mpfr
+// free
+#define ARRAY_VAL_FREE(VAL) array_mpfr_free(VAL)
+// set values
+#define ARRAY_VAL_SET(VAL, NEWVAL) VAL=NEWVAL
+// copy values
+#define ARRAY_VAL_CPY(FROMVAL, TOVAL) array_mpfr_cpy(FROMVAL, &TOVAL);
+// compare values
+#define ARRAY_VAL_IFEQ(VAL1, VAL2) array_mpfr_cmp(VAL1, VAL2)==0
+#define ARRAY_VAL_IFLT(VAL1, VAL2) array_mpfr_cmp(VAL1, VAL2)<0
+#define ARRAY_VAL_IFGT(VAL1, VAL2) array_mpfr_cmp(VAL1, VAL2)>0
+// print values
+#define ARRAY_VAL_PRINT(VAL) array_mpfr_print(VAL)
+
diff --git a/src/array_base.c b/src/array_base.c
new file mode 100644
index 0000000..a70bd86
--- /dev/null
+++ b/src/array_base.c
@@ -0,0 +1,249 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Base functions for arrays
+
+ see polynomial_*.h for the values taken by ARRAY_FUNC, etc...
+*/
+
+
+// init
+int ARRAY_FUNC(init) (ARRAY_TYPENAME* array, unsigned int memory){
+ array->values=calloc(memory,sizeof(ARRAY_VAL_TYPE));
+ array->memory=memory;
+ array->length=0;
+ return(0);
+}
+int ARRAY_FUNC(free) (ARRAY_TYPENAME array){
+ #ifdef ARRAY_VAL_FREE
+ unsigned int i;
+ for(i=0;i<array.length;i++){
+ ARRAY_VAL_FREE(array.values[i]);
+ }
+ #endif
+ free(array.values);
+ return(0);
+}
+// do not free values, only free calloc'ed memory
+int ARRAY_FUNC(free_vects) (ARRAY_TYPENAME array){
+ free(array.values);
+ return(0);
+}
+
+// resize memory
+int ARRAY_FUNC(resize) (ARRAY_TYPENAME* array, unsigned int newsize){
+ unsigned int i;
+ ARRAY_TYPENAME new_array;
+ ARRAY_FUNC(init) (&new_array, newsize);
+ for(i=0;i<array->length;i++){
+ ARRAY_VAL_SET(new_array.values[i], array->values[i]);
+ }
+ free(array->values);
+ *array=new_array;
+ return(0);
+}
+
+// add a value
+int ARRAY_FUNC(append) (ARRAY_VAL_TYPE val, ARRAY_TYPENAME* output){
+ if(output->length >= output->memory){
+ ARRAY_FUNC(resize) (output,2*output->memory+1);
+ }
+ ARRAY_VAL_CPY(val, output->values[output->length]);
+ output->length++;
+ return(0);
+}
+// do not copy the value, instead let the last element of the array point to 'val'
+// only if the value requires initializing
+#ifdef ARRAY_VAL_FREE
+int ARRAY_FUNC(append_noinit) (ARRAY_VAL_TYPE val, ARRAY_TYPENAME* output){
+ if(output->length >= output->memory){
+ ARRAY_FUNC(resize) (output,2*output->memory+1);
+ }
+ ARRAY_VAL_SET(output->values[output->length], val);
+ output->length++;
+ return(0);
+}
+#endif
+// add a value only if it is not already present
+#ifdef ARRAY_VAL_IFEQ
+int ARRAY_FUNC(append_unique) (ARRAY_VAL_TYPE val, ARRAY_TYPENAME* output){
+ if(ARRAY_FUNC(find) (val, *output)<0){
+ ARRAY_FUNC(append) (val, output);
+ }
+ return(0);
+}
+#endif
+
+// copy
+int ARRAY_FUNC(cpy) (ARRAY_TYPENAME input, ARRAY_TYPENAME* output){
+ ARRAY_FUNC(init) (output, input.length);
+ ARRAY_FUNC(cpy_noinit) (input, output);
+ return(0);
+}
+// do not init output array
+int ARRAY_FUNC(cpy_noinit) (ARRAY_TYPENAME input, ARRAY_TYPENAME* output){
+ unsigned int i;
+ if(output->memory<input.length){
+ return(LIBINUM_ERROR_SIZE_MISMATCH);
+ }
+ for(i=0;i<input.length;i++){
+ ARRAY_VAL_CPY(input.values[i], output->values[i]);
+ }
+ output->length=input.length;
+ return(0);
+}
+
+
+// concatenate
+int ARRAY_FUNC(concat) (ARRAY_TYPENAME input, ARRAY_TYPENAME* output){
+ unsigned int i;
+ for(i=0;i<input.length;i++){
+ ARRAY_FUNC(append) (input.values[i], output);
+ }
+ return(0);
+}
+
+// concat but only add values that are not already present in the array
+#ifdef ARRAY_VAL_IFEQ
+int ARRAY_FUNC(concat_unique) (ARRAY_TYPENAME input, ARRAY_TYPENAME* output){
+ unsigned int i;
+ for(i=0;i<input.length;i++){
+ ARRAY_FUNC(append_unique) (input.values[i], output);
+ }
+ return(0);
+}
+#endif
+
+// sub-array
+int ARRAY_FUNC(subarray) (ARRAY_TYPENAME array, unsigned int begin, unsigned int end, ARRAY_TYPENAME* subarray){
+ unsigned int i;
+ if(begin>end || end>=array.length){
+ return(LIBINUM_ERROR_ILLEGAL_MEMORY_ACCESS);
+ }
+ ARRAY_FUNC(init) (subarray,end-begin);
+ for(i=begin;i<=end;i++){
+ ARRAY_FUNC(append) (array.values[i], subarray);
+ }
+ return(0);
+}
+
+// find (does not assume the array is sorted)
+#ifdef ARRAY_VAL_IFEQ
+int ARRAY_FUNC(find) (ARRAY_VAL_TYPE val, ARRAY_TYPENAME array){
+ unsigned int i;
+ for(i=0;i<array.length;i++){
+ if(ARRAY_VAL_IFEQ(array.values[i], val)){
+ return(i);
+ }
+ }
+ return(-1);
+}
+#endif
+
+// sort (quicksort)
+#ifdef ARRAY_VAL_IFLT
+int ARRAY_FUNC(sort) (ARRAY_TYPENAME array){
+ if(array.length>1){
+ ARRAY_FUNC(sort_sub) (array, 0, array.length-1);
+ }
+ return(0);
+}
+// sort a sub-array
+int ARRAY_FUNC(sort_sub) (ARRAY_TYPENAME array, unsigned int begin, unsigned int end){
+ unsigned int i;
+ unsigned int index;
+ ARRAY_VAL_TYPE tmp;
+ // the pivot: middle of the array
+ unsigned int pivot=(begin+end)/2;
+
+ // if the array is non trivial
+ if(begin<end){
+ // send pivot to the end
+ ARRAY_VAL_SET(tmp, array.values[pivot]);
+ ARRAY_VAL_SET(array.values[pivot], array.values[end]);
+ ARRAY_VAL_SET(array.values[end], tmp);
+
+ // loop over the others
+ for(i=begin, index=begin;i<end;i++){
+ // compare with pivot
+ if(ARRAY_VAL_IFLT(array.values[i], array.values[end])){
+ // if smaller, exchange with reference index
+ ARRAY_VAL_SET(tmp, array.values[index]);
+ ARRAY_VAL_SET(array.values[index], array.values[i]);
+ ARRAY_VAL_SET(array.values[i], tmp);
+ // move reference index
+ index++;
+ }
+ }
+ // put pivot (which we had sent to the end) in the right place
+ ARRAY_VAL_SET(tmp, array.values[end]);
+ ARRAY_VAL_SET(array.values[end], array.values[index]);
+ ARRAY_VAL_SET(array.values[index], tmp);
+
+ // recurse
+ if(index>0){
+ ARRAY_FUNC(sort_sub) (array, begin, index-1);
+ }
+ ARRAY_FUNC(sort_sub) (array, index+1, end);
+ }
+ return(0);
+}
+#endif
+
+// compare arrays
+#if defined ARRAY_VAL_IFLT && defined ARRAY_VAL_IFGT
+int ARRAY_FUNC(cmp) (ARRAY_TYPENAME array1, ARRAY_TYPENAME array2){
+ unsigned int i;
+
+ // compare lengths
+ if(array1.length<array2.length){
+ return(-1);
+ }
+ if(array1.length>array2.length){
+ return(1);
+ }
+
+ // compare terms
+ for(i=0;i<array1.length;i++){
+ if(ARRAY_VAL_IFLT(array1.values[i], array2.values[i])){
+ return(-1);
+ }
+ if(ARRAY_VAL_IFGT(array1.values[i], array2.values[i])){
+ return(1);
+ }
+ }
+
+ // if equal
+ return(0);
+}
+#endif
+
+// print array
+#ifdef ARRAY_VAL_PRINT
+int ARRAY_FUNC(print) (ARRAY_TYPENAME array){
+ unsigned int i;
+ printf("(");
+ for(i=0;i<array.length;i++){
+ ARRAY_VAL_PRINT(array.values[i]);
+ if(i<array.length-1){
+ printf(", ");
+ }
+ }
+ printf(")");
+ return(0);
+}
+#endif
diff --git a/src/array_base.h b/src/array_base.h
new file mode 100644
index 0000000..b9de5d2
--- /dev/null
+++ b/src/array_base.h
@@ -0,0 +1,78 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Base functions for arrays
+
+ see polynomial_*.h for the values taken by ARRAY_FUNC, etc...
+*/
+
+// init
+int ARRAY_FUNC(init) (ARRAY_TYPENAME* array, unsigned int memory);
+int ARRAY_FUNC(free) (ARRAY_TYPENAME array);
+// do not free values, only free calloc'ed memory
+int ARRAY_FUNC(free_vects) (ARRAY_TYPENAME array);
+
+// resize memory
+int ARRAY_FUNC(resize) (ARRAY_TYPENAME* array, unsigned int newsize);
+
+// add a value
+int ARRAY_FUNC(append) (ARRAY_VAL_TYPE val, ARRAY_TYPENAME* output);
+#ifdef ARRAY_VAL_FREE
+// do not copy the value, instead let the last element of the array point to 'val'
+int ARRAY_FUNC(append_noinit) (ARRAY_VAL_TYPE val, ARRAY_TYPENAME* output);
+#endif
+// add a value only if it is not already present
+#ifdef ARRAY_VAL_IFEQ
+int ARRAY_FUNC(append_unique) (ARRAY_VAL_TYPE val, ARRAY_TYPENAME* output);
+#endif
+
+// copy
+int ARRAY_FUNC(cpy) (ARRAY_TYPENAME input, ARRAY_TYPENAME* output);
+int ARRAY_FUNC(cpy_noinit) (ARRAY_TYPENAME input, ARRAY_TYPENAME* output);
+
+// concatenate
+int ARRAY_FUNC(concat) (ARRAY_TYPENAME input, ARRAY_TYPENAME* output);
+// concat but only add values that are not already present in the array
+#ifdef ARRAY_VAL_IFEQ
+int ARRAY_FUNC(concat_unique) (ARRAY_TYPENAME input, ARRAY_TYPENAME* output);
+#endif
+
+// sub-array
+int ARRAY_FUNC(subarray) (ARRAY_TYPENAME array, unsigned int begin, unsigned int end, ARRAY_TYPENAME* subarray);
+
+// find (does not assume the array is sorted)
+#ifdef ARRAY_VAL_IFEQ
+int ARRAY_FUNC(find) (ARRAY_VAL_TYPE val, ARRAY_TYPENAME array);
+#endif
+
+// sort (quicksort)
+#ifdef ARRAY_VAL_IFLT
+int ARRAY_FUNC(sort) (ARRAY_TYPENAME array);
+// sort a sub-array
+int ARRAY_FUNC(sort_sub) (ARRAY_TYPENAME array, unsigned int begin, unsigned int end);
+#endif
+
+// compare arrays
+#if defined ARRAY_VAL_IFLT && defined ARRAY_VAL_IFGT
+int ARRAY_FUNC(cmp) (ARRAY_TYPENAME array1, ARRAY_TYPENAME array2);
+#endif
+
+// print array
+#ifdef ARRAY_VAL_PRINT
+int ARRAY_FUNC(print) (ARRAY_TYPENAME array);
+#endif
+
diff --git a/src/array_char.h b/src/array_char.h
new file mode 100644
index 0000000..6c95174
--- /dev/null
+++ b/src/array_char.h
@@ -0,0 +1,52 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Preprocessor macros for char arrays
+*/
+
+
+// reset CPP macros
+#undef ARRAY_TYPENAME
+#undef ARRAY_FUNC
+#undef ARRAY_VAL_TYPE
+#undef ARRAY_VAL_FREE
+#undef ARRAY_VAL_SET
+#undef ARRAY_VAL_CPY
+#undef ARRAY_VAL_IFEQ
+#undef ARRAY_VAL_IFLT
+#undef ARRAY_VAL_IFGT
+#undef ARRAY_VAL_PRINT
+
+
+// name of the polynomial type
+#define ARRAY_TYPENAME array_char
+// prefix of function names
+#define ARRAY_FUNC(NAME) array_char_ ## NAME
+
+// type of values
+#define ARRAY_VAL_TYPE char
+// set values
+#define ARRAY_VAL_SET(VAL, NEWVAL) VAL = NEWVAL
+// copy values
+#define ARRAY_VAL_CPY(FROMVAL, TOVAL) TOVAL = FROMVAL
+// compare values
+#define ARRAY_VAL_IFEQ(VAL1, VAL2) VAL1==VAL2
+#define ARRAY_VAL_IFLT(VAL1, VAL2) VAL1<VAL2
+#define ARRAY_VAL_IFGT(VAL1, VAL2) VAL1>VAL2
+// print values
+#define ARRAY_VAL_PRINT(VAL) printf("%c",VAL)
+
diff --git a/src/array_double.h b/src/array_double.h
new file mode 100644
index 0000000..8d3c187
--- /dev/null
+++ b/src/array_double.h
@@ -0,0 +1,52 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Preprocessor macros for double arrays
+*/
+
+
+// reset CPP macros
+#undef ARRAY_TYPENAME
+#undef ARRAY_FUNC
+#undef ARRAY_VAL_TYPE
+#undef ARRAY_VAL_FREE
+#undef ARRAY_VAL_SET
+#undef ARRAY_VAL_CPY
+#undef ARRAY_VAL_IFEQ
+#undef ARRAY_VAL_IFLT
+#undef ARRAY_VAL_IFGT
+#undef ARRAY_VAL_PRINT
+
+
+// name of the polynomial type
+#define ARRAY_TYPENAME array_double
+// prefix of function names
+#define ARRAY_FUNC(NAME) array_double_ ## NAME
+
+// type of values
+#define ARRAY_VAL_TYPE double
+// set values
+#define ARRAY_VAL_SET(VAL, NEWVAL) VAL = NEWVAL
+// copy values
+#define ARRAY_VAL_CPY(FROMVAL, TOVAL) TOVAL = FROMVAL
+// compare values
+#define ARRAY_VAL_IFEQ(VAL1, VAL2) VAL1==VAL2
+#define ARRAY_VAL_IFLT(VAL1, VAL2) VAL1<VAL2
+#define ARRAY_VAL_IFGT(VAL1, VAL2) VAL1>VAL2
+// print values
+#define ARRAY_VAL_PRINT(VAL) fprint_double(stdout, VAL)
+
diff --git a/src/array_int.h b/src/array_int.h
new file mode 100644
index 0000000..9496b89
--- /dev/null
+++ b/src/array_int.h
@@ -0,0 +1,52 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Preprocessor macros for integer arrays
+*/
+
+
+// reset CPP macros
+#undef ARRAY_TYPENAME
+#undef ARRAY_FUNC
+#undef ARRAY_VAL_TYPE
+#undef ARRAY_VAL_FREE
+#undef ARRAY_VAL_SET
+#undef ARRAY_VAL_CPY
+#undef ARRAY_VAL_IFEQ
+#undef ARRAY_VAL_IFLT
+#undef ARRAY_VAL_IFGT
+#undef ARRAY_VAL_PRINT
+
+
+// name of the polynomial type
+#define ARRAY_TYPENAME array_int
+// prefix of function names
+#define ARRAY_FUNC(NAME) array_int_ ## NAME
+
+// type of values
+#define ARRAY_VAL_TYPE int
+// set values
+#define ARRAY_VAL_SET(VAL, NEWVAL) VAL = NEWVAL
+// copy values
+#define ARRAY_VAL_CPY(FROMVAL, TOVAL) TOVAL = FROMVAL
+// compare values
+#define ARRAY_VAL_IFEQ(VAL1, VAL2) VAL1==VAL2
+#define ARRAY_VAL_IFLT(VAL1, VAL2) VAL1<VAL2
+#define ARRAY_VAL_IFGT(VAL1, VAL2) VAL1>VAL2
+// print values
+#define ARRAY_VAL_PRINT(VAL) printf("%d",VAL)
+
diff --git a/src/array_ldouble.h b/src/array_ldouble.h
new file mode 100644
index 0000000..d314906
--- /dev/null
+++ b/src/array_ldouble.h
@@ -0,0 +1,52 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Preprocessor macros for long double arrays
+*/
+
+
+// reset CPP macros
+#undef ARRAY_TYPENAME
+#undef ARRAY_FUNC
+#undef ARRAY_VAL_TYPE
+#undef ARRAY_VAL_FREE
+#undef ARRAY_VAL_SET
+#undef ARRAY_VAL_CPY
+#undef ARRAY_VAL_IFEQ
+#undef ARRAY_VAL_IFLT
+#undef ARRAY_VAL_IFGT
+#undef ARRAY_VAL_PRINT
+
+
+// name of the polynomial type
+#define ARRAY_TYPENAME array_ldouble
+// prefix of function names
+#define ARRAY_FUNC(NAME) array_ldouble_ ## NAME
+
+// type of values
+#define ARRAY_VAL_TYPE long double
+// set values
+#define ARRAY_VAL_SET(VAL, NEWVAL) VAL = NEWVAL
+// copy values
+#define ARRAY_VAL_CPY(FROMVAL, TOVAL) TOVAL = FROMVAL
+// compare values
+#define ARRAY_VAL_IFEQ(VAL1, VAL2) VAL1==VAL2
+#define ARRAY_VAL_IFLT(VAL1, VAL2) VAL1<VAL2
+#define ARRAY_VAL_IFGT(VAL1, VAL2) VAL1>VAL2
+// print values
+#define ARRAY_VAL_PRINT(VAL) fprint_ldouble(stdout, VAL)
+
diff --git a/src/array_mpfr.h b/src/array_mpfr.h
new file mode 100644
index 0000000..46bc54b
--- /dev/null
+++ b/src/array_mpfr.h
@@ -0,0 +1,54 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Preprocessor macros for MPFR float arrays
+*/
+
+
+// reset CPP macros
+#undef ARRAY_TYPENAME
+#undef ARRAY_FUNC
+#undef ARRAY_VAL_TYPE
+#undef ARRAY_VAL_FREE
+#undef ARRAY_VAL_SET
+#undef ARRAY_VAL_CPY
+#undef ARRAY_VAL_IFEQ
+#undef ARRAY_VAL_IFLT
+#undef ARRAY_VAL_IFGT
+#undef ARRAY_VAL_PRINT
+
+
+// name of the polynomial type
+#define ARRAY_TYPENAME array_mpfr
+// prefix of function names
+#define ARRAY_FUNC(NAME) array_mpfr_ ## NAME
+
+// type of values
+#define ARRAY_VAL_TYPE mpfr_t
+// free
+#define ARRAY_VAL_FREE(VAL) mpfr_clear(VAL)
+// set values
+#define ARRAY_VAL_SET(VAL, NEWVAL) VAL[0]=NEWVAL[0]
+// copy values
+#define ARRAY_VAL_CPY(FROMVAL, TOVAL) mpfr_init(TOVAL); mpfr_set(TOVAL, FROMVAL, MPFR_RNDN)
+// compare values
+#define ARRAY_VAL_IFEQ(VAL1, VAL2) mpfr_cmp(VAL1, VAL2)==0
+#define ARRAY_VAL_IFLT(VAL1, VAL2) mpfr_cmp(VAL1, VAL2)<0
+#define ARRAY_VAL_IFGT(VAL1, VAL2) mpfr_cmp(VAL1, VAL2)>0
+// print values
+#define ARRAY_VAL_PRINT(VAL) fprint_mpfr(stdout, VAL)
+
diff --git a/src/array_polynomial_double.h b/src/array_polynomial_double.h
new file mode 100644
index 0000000..d25e689
--- /dev/null
+++ b/src/array_polynomial_double.h
@@ -0,0 +1,50 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Preprocessor macros for arrays of polynomials with double coefficients
+*/
+
+
+// reset CPP macros
+#undef ARRAY_TYPENAME
+#undef ARRAY_FUNC
+#undef ARRAY_VAL_TYPE
+#undef ARRAY_VAL_FREE
+#undef ARRAY_VAL_SET
+#undef ARRAY_VAL_CPY
+#undef ARRAY_VAL_IFEQ
+#undef ARRAY_VAL_IFLT
+#undef ARRAY_VAL_IFGT
+#undef ARRAY_VAL_PRINT
+
+
+// name of the polynomial type
+#define ARRAY_TYPENAME array_polynomial_double
+// prefix of function names
+#define ARRAY_FUNC(NAME) array_polynomial_double_ ## NAME
+
+// type of values
+#define ARRAY_VAL_TYPE polynomial_double
+// free
+#define ARRAY_VAL_FREE(VAL) polynomial_double_free(VAL)
+// set values
+#define ARRAY_VAL_SET(VAL, NEWVAL) VAL = NEWVAL
+// copy values
+#define ARRAY_VAL_CPY(FROMVAL, TOVAL) polynomial_double_cpy(FROMVAL, &TOVAL)
+// print values
+#define ARRAY_VAL_PRINT(VAL) polynomial_double_print(VAL)
+
diff --git a/src/array_polynomial_ldouble.h b/src/array_polynomial_ldouble.h
new file mode 100644
index 0000000..49c81cc
--- /dev/null
+++ b/src/array_polynomial_ldouble.h
@@ -0,0 +1,50 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Preprocessor macros for arrays of polynomials with long double coefficients
+*/
+
+
+// reset CPP macros
+#undef ARRAY_TYPENAME
+#undef ARRAY_FUNC
+#undef ARRAY_VAL_TYPE
+#undef ARRAY_VAL_FREE
+#undef ARRAY_VAL_SET
+#undef ARRAY_VAL_CPY
+#undef ARRAY_VAL_IFEQ
+#undef ARRAY_VAL_IFLT
+#undef ARRAY_VAL_IFGT
+#undef ARRAY_VAL_PRINT
+
+
+// name of the polynomial type
+#define ARRAY_TYPENAME array_polynomial_ldouble
+// prefix of function names
+#define ARRAY_FUNC(NAME) array_polynomial_ldouble_ ## NAME
+
+// type of values
+#define ARRAY_VAL_TYPE polynomial_ldouble
+// free
+#define ARRAY_VAL_FREE(VAL) polynomial_ldouble_free(VAL)
+// set values
+#define ARRAY_VAL_SET(VAL, NEWVAL) VAL = NEWVAL
+// copy values
+#define ARRAY_VAL_CPY(FROMVAL, TOVAL) polynomial_ldouble_cpy(FROMVAL, &TOVAL)
+// print values
+#define ARRAY_VAL_PRINT(VAL) polynomial_ldouble_print(VAL)
+
diff --git a/src/array_polynomial_mpfr.h b/src/array_polynomial_mpfr.h
new file mode 100644
index 0000000..8cfe6e8
--- /dev/null
+++ b/src/array_polynomial_mpfr.h
@@ -0,0 +1,50 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Preprocessor macros for arrays of polynomials with mpfr coefficients
+*/
+
+
+// reset CPP macros
+#undef ARRAY_TYPENAME
+#undef ARRAY_FUNC
+#undef ARRAY_VAL_TYPE
+#undef ARRAY_VAL_FREE
+#undef ARRAY_VAL_SET
+#undef ARRAY_VAL_CPY
+#undef ARRAY_VAL_IFEQ
+#undef ARRAY_VAL_IFLT
+#undef ARRAY_VAL_IFGT
+#undef ARRAY_VAL_PRINT
+
+
+// name of the polynomial type
+#define ARRAY_TYPENAME array_polynomial_mpfr
+// prefix of function names
+#define ARRAY_FUNC(NAME) array_polynomial_mpfr_ ## NAME
+
+// type of values
+#define ARRAY_VAL_TYPE polynomial_mpfr
+// free
+#define ARRAY_VAL_FREE(VAL) polynomial_mpfr_free(VAL)
+// set values
+#define ARRAY_VAL_SET(VAL, NEWVAL) VAL = NEWVAL
+// copy values
+#define ARRAY_VAL_CPY(FROMVAL, TOVAL) polynomial_mpfr_cpy(FROMVAL, &TOVAL)
+// print values
+#define ARRAY_VAL_PRINT(VAL) polynomial_mpfr_print(VAL)
+
diff --git a/src/array_pthread_t.h b/src/array_pthread_t.h
new file mode 100644
index 0000000..e200c5d
--- /dev/null
+++ b/src/array_pthread_t.h
@@ -0,0 +1,50 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Preprocessor macros for pthread_t arrays
+*/
+
+
+// reset CPP macros
+#undef ARRAY_TYPENAME
+#undef ARRAY_FUNC
+#undef ARRAY_VAL_TYPE
+#undef ARRAY_VAL_FREE
+#undef ARRAY_VAL_SET
+#undef ARRAY_VAL_CPY
+#undef ARRAY_VAL_IFEQ
+#undef ARRAY_VAL_IFLT
+#undef ARRAY_VAL_IFGT
+#undef ARRAY_VAL_PRINT
+
+
+// name of the polynomial type
+#define ARRAY_TYPENAME array_pthread_t
+// prefix of function names
+#define ARRAY_FUNC(NAME) array_pthread_t_ ## NAME
+
+// type of values
+#define ARRAY_VAL_TYPE pthread_t
+// set values
+#define ARRAY_VAL_SET(VAL, NEWVAL) VAL = NEWVAL
+// copy values
+#define ARRAY_VAL_CPY(FROMVAL, TOVAL) TOVAL = FROMVAL
+// compare values
+#define ARRAY_VAL_IFEQ(VAL1, VAL2) VAL1==VAL2
+#define ARRAY_VAL_IFLT(VAL1, VAL2) VAL1<VAL2
+#define ARRAY_VAL_IFGT(VAL1, VAL2) VAL1>VAL2
+
diff --git a/src/array_str.h b/src/array_str.h
new file mode 100644
index 0000000..2d35d1b
--- /dev/null
+++ b/src/array_str.h
@@ -0,0 +1,54 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Preprocessor macros for string arrays
+*/
+
+
+// reset CPP macros
+#undef ARRAY_TYPENAME
+#undef ARRAY_FUNC
+#undef ARRAY_VAL_TYPE
+#undef ARRAY_VAL_FREE
+#undef ARRAY_VAL_SET
+#undef ARRAY_VAL_CPY
+#undef ARRAY_VAL_IFEQ
+#undef ARRAY_VAL_IFLT
+#undef ARRAY_VAL_IFGT
+#undef ARRAY_VAL_PRINT
+
+
+// name of the polynomial type
+#define ARRAY_TYPENAME array_str
+// prefix of function names
+#define ARRAY_FUNC(NAME) array_str_ ## NAME
+
+// type of values
+#define ARRAY_VAL_TYPE array_char
+// free
+#define ARRAY_VAL_FREE(VAL) array_char_free(VAL)
+// set values
+#define ARRAY_VAL_SET(VAL, NEWVAL) VAL = NEWVAL
+// copy values
+#define ARRAY_VAL_CPY(FROMVAL, TOVAL) array_char_cpy(FROMVAL, &TOVAL)
+// compare values
+#define ARRAY_VAL_IFEQ(VAL1, VAL2) array_char_cmp(VAL1, VAL2)==0
+#define ARRAY_VAL_IFLT(VAL1, VAL2) array_char_cmp(VAL1, VAL2)<0
+#define ARRAY_VAL_IFGT(VAL1, VAL2) array_char_cmp(VAL1, VAL2)>0
+// print values
+#define ARRAY_VAL_PRINT(VAL) array_char_print(VAL)
+
diff --git a/src/array_type.h b/src/array_type.h
new file mode 100644
index 0000000..4aa63fc
--- /dev/null
+++ b/src/array_type.h
@@ -0,0 +1,28 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Structure definition for arrays
+
+ see array_*.h for the values taken by ARRAY_TYPENAME, etc...
+*/
+
+typedef struct ARRAY_TYPENAME {
+ ARRAY_VAL_TYPE* values;
+ unsigned int length;
+ unsigned int memory;
+} ARRAY_TYPENAME;
+
diff --git a/src/array_uint.h b/src/array_uint.h
new file mode 100644
index 0000000..b3cec85
--- /dev/null
+++ b/src/array_uint.h
@@ -0,0 +1,52 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Preprocessor macros for unsigned int arrays
+*/
+
+
+// reset CPP macros
+#undef ARRAY_TYPENAME
+#undef ARRAY_FUNC
+#undef ARRAY_VAL_TYPE
+#undef ARRAY_VAL_FREE
+#undef ARRAY_VAL_SET
+#undef ARRAY_VAL_CPY
+#undef ARRAY_VAL_IFEQ
+#undef ARRAY_VAL_IFLT
+#undef ARRAY_VAL_IFGT
+#undef ARRAY_VAL_PRINT
+
+
+// name of the polynomial type
+#define ARRAY_TYPENAME array_uint
+// prefix of function names
+#define ARRAY_FUNC(NAME) array_uint_ ## NAME
+
+// type of values
+#define ARRAY_VAL_TYPE unsigned int
+// set values
+#define ARRAY_VAL_SET(VAL, NEWVAL) VAL = NEWVAL
+// copy values
+#define ARRAY_VAL_CPY(FROMVAL, TOVAL) TOVAL = FROMVAL
+// compare values
+#define ARRAY_VAL_IFEQ(VAL1, VAL2) VAL1==VAL2
+#define ARRAY_VAL_IFLT(VAL1, VAL2) VAL1<VAL2
+#define ARRAY_VAL_IFGT(VAL1, VAL2) VAL1>VAL2
+// print values
+#define ARRAY_VAL_PRINT(VAL) printf("%u",VAL)
+
diff --git a/src/errors.h b/src/errors.h
new file mode 100644
index 0000000..ee26dd2
--- /dev/null
+++ b/src/errors.h
@@ -0,0 +1,29 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#ifndef LIBINUM_ERRORS_H
+#define LIBINUM_ERRORS_H
+
+// maximal number of iterations reached
+#define LIBINUM_ERROR_MAXITER -1
+// illegal memoru access
+#define LIBINUM_ERROR_ILLEGAL_MEMORY_ACCESS -2
+// size incompatibilities
+#define LIBINUM_ERROR_SIZE_MISMATCH -3
+// NaN or Inf
+#define LIBINUM_ERROR_NAN -4
+
+#endif
diff --git a/src/integral.c b/src/integral.c
new file mode 100644
index 0000000..43ccd82
--- /dev/null
+++ b/src/integral.c
@@ -0,0 +1,52 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "integral.h"
+
+#include <mpfr.h>
+#include <math.h>
+#include <stdlib.h>
+#include "root.h"
+#include "array.h"
+#include "polynomial.h"
+#include "errors.h"
+
+
+//--------------------------------------------------
+//
+// using doubles
+//
+//--------------------------------------------------
+#include "integral_double.h"
+#include "integral_base.c"
+
+
+//--------------------------------------------------
+//
+// using long doubles
+//
+//--------------------------------------------------
+#include "integral_ldouble.h"
+#include "integral_base.c"
+
+
+//--------------------------------------------------
+//
+// using mpfr floats
+//
+//--------------------------------------------------
+#include "integral_mpfr.h"
+#include "integral_base.c"
diff --git a/src/integral.h b/src/integral.h
new file mode 100644
index 0000000..01c1fe4
--- /dev/null
+++ b/src/integral.h
@@ -0,0 +1,53 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Integration of real functions
+*/
+
+#ifndef LIBINUM_INTEGRAL_H
+#define LIBINUM_INTEGRAL_H
+
+#include "types.h"
+
+
+//--------------------------------------------------
+//
+// using doubles
+//
+//--------------------------------------------------
+#include "integral_double.h"
+#include "integral_base.h"
+
+
+//--------------------------------------------------
+//
+// using long doubles
+//
+//--------------------------------------------------
+#include "integral_ldouble.h"
+#include "integral_base.h"
+
+//--------------------------------------------------
+//
+// using mpfr floats
+//
+//--------------------------------------------------
+
+#include "integral_mpfr.h"
+#include "integral_base.h"
+
+#endif
diff --git a/src/integral_base.c b/src/integral_base.c
new file mode 100644
index 0000000..da3f05a
--- /dev/null
+++ b/src/integral_base.c
@@ -0,0 +1,506 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Base functions for integration
+
+ see integral_*.h for the values taken by INTEGRAL_FUNC, etc...
+*/
+
+
+// compute the integral of a real function of 1 variable using the Gauss-Legendre scheme
+int INTEGRAL_FUNC(integrate_gauss) (INTEGRAL_FLOAT_TYPE* out, int (*func)(INTEGRAL_FLOAT_TYPE*, INTEGRAL_FLOAT_TYPE, void*), INTEGRAL_FLOAT_TYPE lower, INTEGRAL_FLOAT_TYPE upper, INTEGRAL_FLOATARRAY_TYPE abcissa, INTEGRAL_FLOATARRAY_TYPE weights, void* extra_args){
+ unsigned int i;
+ INTEGRAL_FLOAT_TYPE valf, delta, avg, x;
+ int ret;
+
+ // check arguments
+ if(abcissa.length != weights.length){
+ return(LIBINUM_ERROR_SIZE_MISMATCH);
+ }
+
+ #ifdef INTEGRAL_FLOAT_INIT
+ INTEGRAL_FLOAT_INIT(valf);
+ INTEGRAL_FLOAT_INIT(delta);
+ INTEGRAL_FLOAT_INIT(avg);
+ INTEGRAL_FLOAT_INIT(x);
+ #endif
+
+ // init to 0
+ INTEGRAL_FLOAT_SET_UI(*out, 0);
+
+ // half length of interval
+ INTEGRAL_FLOAT_SUB(delta, upper, lower);
+ INTEGRAL_FLOAT_DIV_UI(delta, delta, 2);
+ // average of interval
+ INTEGRAL_FLOAT_ADD(avg, upper, lower);
+ INTEGRAL_FLOAT_DIV_UI(avg, avg, 2);
+
+ for(i=0;i<abcissa.length;i++){
+ // evaluate at x
+ INTEGRAL_FLOAT_MUL(x, delta, abcissa.values[i]);
+ INTEGRAL_FLOAT_ADD(x, x, avg);
+
+ ret=(*func)(&valf, x, extra_args);
+ if(ret<0){
+ #ifdef INTEGRAL_FLOAT_FREE
+ INTEGRAL_FLOAT_FREE(valf);
+ INTEGRAL_FLOAT_FREE(delta);
+ INTEGRAL_FLOAT_FREE(avg);
+ INTEGRAL_FLOAT_FREE(x);
+ #endif
+ return(ret);
+ }
+ // check whether valf is a number
+ if(! INTEGRAL_FLOAT_ISNUMBER(valf)){
+ #ifdef INTEGRAL_FLOAT_FREE
+ INTEGRAL_FLOAT_FREE(valf);
+ INTEGRAL_FLOAT_FREE(delta);
+ INTEGRAL_FLOAT_FREE(avg);
+ INTEGRAL_FLOAT_FREE(x);
+ #endif
+ return(LIBINUM_ERROR_NAN);
+ }
+
+ INTEGRAL_FLOAT_MUL(valf, valf, weights.values[i]);
+ INTEGRAL_FLOAT_ADD(*out, *out, valf);
+ }
+
+ INTEGRAL_FLOAT_MUL(*out, *out, delta);
+
+ #ifdef INTEGRAL_FLOAT_FREE
+ INTEGRAL_FLOAT_FREE(valf);
+ INTEGRAL_FLOAT_FREE(delta);
+ INTEGRAL_FLOAT_FREE(avg);
+ INTEGRAL_FLOAT_FREE(x);
+ #endif
+
+ return(0);
+}
+
+// multithreaded version
+// arguments to pass to each thread
+struct INTEGRAL_FUNC(pthread_integrate_gauss_args) {
+ // partial sum of the values assigned to the thread
+ INTEGRAL_FLOAT_TYPE out;
+ // abcissa
+ INTEGRAL_FLOATARRAY_TYPE x;
+ // weights
+ INTEGRAL_FLOATARRAY_TYPE weights;
+ // pointer to the function to evaluate
+ int (*func)(INTEGRAL_FLOAT_TYPE*, INTEGRAL_FLOAT_TYPE, void*);
+ // extra arguments passed to func
+ void* extra_args;
+ // return value
+ int ret;
+};
+int INTEGRAL_FUNC(integrate_gauss_multithread) (INTEGRAL_FLOAT_TYPE* out, int (*func)(INTEGRAL_FLOAT_TYPE*, INTEGRAL_FLOAT_TYPE, void*), INTEGRAL_FLOAT_TYPE lower, INTEGRAL_FLOAT_TYPE upper, INTEGRAL_FLOATARRAY_TYPE abcissa, INTEGRAL_FLOATARRAY_TYPE weights, void* extra_args, unsigned int threads, array_pthread_t* thread_ids){
+ unsigned int i;
+ INTEGRAL_FLOAT_TYPE x, delta, avg;
+ struct INTEGRAL_FUNC(pthread_integrate_gauss_args) args[threads];
+ int ret=0;
+ unsigned int thread_nr;
+
+ array_pthread_t_init(thread_ids, threads);
+ thread_ids->length=threads;
+
+ // check arguments
+ if(abcissa.length != weights.length){
+ return(LIBINUM_ERROR_SIZE_MISMATCH);
+ }
+
+ #ifdef INTEGRAL_FLOAT_INIT
+ INTEGRAL_FLOAT_INIT(delta);
+ INTEGRAL_FLOAT_INIT(avg);
+ INTEGRAL_FLOAT_INIT(x);
+ #endif
+
+ // init to 0
+ INTEGRAL_FLOAT_SET_UI(*out, 0);
+
+ // half length of interval
+ INTEGRAL_FLOAT_SUB(delta, upper, lower);
+ INTEGRAL_FLOAT_DIV_UI(delta, delta, 2);
+ // average of interval
+ INTEGRAL_FLOAT_ADD(avg, upper, lower);
+ INTEGRAL_FLOAT_DIV_UI(avg, avg, 2);
+
+ // inits
+ for(thread_nr=0;thread_nr<threads;thread_nr++){
+ INTEGRAL_FLOATARRAY_FUNC(init) (&(args[thread_nr].x),abcissa.length/threads+1);
+ INTEGRAL_FLOATARRAY_FUNC(init) (&(args[thread_nr].weights),abcissa.length/threads+1);
+ #ifdef INTEGRAL_FLOAT_INIT
+ INTEGRAL_FLOAT_INIT(args[thread_nr].out);
+ #endif
+ }
+
+ // set abcissa and weights
+ for(i=0,thread_nr=0;i<abcissa.length;i++,thread_nr=(thread_nr+1)%threads){
+ INTEGRAL_FLOAT_MUL(x, delta, abcissa.values[i]);
+ INTEGRAL_FLOAT_ADD(x, x, avg);
+
+ INTEGRAL_FLOATARRAY_FUNC(append) (x, &(args[thread_nr].x));
+ INTEGRAL_FLOATARRAY_FUNC(append) (weights.values[i], &(args[thread_nr].weights));
+ }
+
+ for(thread_nr=0;thread_nr<threads;thread_nr++){
+ // set func
+ args[thread_nr].func=func;
+ // set extra_args
+ args[thread_nr].extra_args=extra_args;
+ // init ret
+ args[thread_nr].ret=0;
+ // run threads
+ pthread_create(thread_ids->values+thread_nr, NULL, INTEGRAL_FUNC(integrate_gauss_thread), (void*)(args+thread_nr));
+ }
+
+ // wait for completion and join
+ for(thread_nr=0;thread_nr<threads;thread_nr++){
+ pthread_join(thread_ids->values[thread_nr], NULL);
+
+ if(args[thread_nr].ret<0){
+ ret=args[thread_nr].ret;
+ }
+ else{
+ INTEGRAL_FLOAT_ADD(*out, *out, args[thread_nr].out);
+ }
+ }
+
+ // multiply by size of interval
+ INTEGRAL_FLOAT_MUL(*out, *out, delta);
+
+ for(thread_nr=0;thread_nr<threads;thread_nr++){
+ INTEGRAL_FLOATARRAY_FUNC(free) (args[thread_nr].x);
+ INTEGRAL_FLOATARRAY_FUNC(free) (args[thread_nr].weights);
+ #ifdef INTEGRAL_FLOAT_FREE
+ INTEGRAL_FLOAT_FREE(args[thread_nr].out);
+ #endif
+ }
+
+ #ifdef INTEGRAL_FLOAT_FREE
+ INTEGRAL_FLOAT_FREE(delta);
+ INTEGRAL_FLOAT_FREE(avg);
+ INTEGRAL_FLOAT_FREE(x);
+ #endif
+
+
+ return(ret);
+}
+// per-thread function
+void* INTEGRAL_FUNC(integrate_gauss_thread) (void* args){
+ unsigned int i;
+ INTEGRAL_FLOAT_TYPE valf;
+ int ret;
+ struct INTEGRAL_FUNC(pthread_integrate_gauss_args)* argument=((struct INTEGRAL_FUNC(pthread_integrate_gauss_args)*)args);
+ #ifdef INTEGRAL_FLOAT_INIT
+ INTEGRAL_FLOAT_INIT(valf);
+ #endif
+
+ INTEGRAL_FLOAT_SET_UI(argument->out, 0);
+
+ for(i=0;i<argument->x.length;i++){
+ // evaluate
+ ret=(*(argument->func))(&valf, argument->x.values[i], argument->extra_args);
+
+ if(ret<0){
+ #ifdef INTEGRAL_FLOAT_FREE
+ INTEGRAL_FLOAT_FREE(valf);
+ #endif
+ argument->ret=ret;
+ return(NULL);
+ }
+ // check whether valf is a number
+ if(! INTEGRAL_FLOAT_ISNUMBER(valf)){
+ #ifdef INTEGRAL_FLOAT_FREE
+ INTEGRAL_FLOAT_FREE(valf);
+ #endif
+ argument->ret=LIBINUM_ERROR_NAN;
+ return(NULL);
+ }
+
+ INTEGRAL_FLOAT_MUL(valf, valf, argument->weights.values[i]);
+ INTEGRAL_FLOAT_ADD(argument->out, argument->out, valf);
+ }
+ #ifdef INTEGRAL_FLOAT_FREE
+ INTEGRAL_FLOAT_FREE(valf);
+ #endif
+
+ return(NULL);
+}
+
+
+
+// smart management of temporary variables: initialize as many as needed but allow them to be re-used instead of freeing them
+#ifdef INTEGRAL_FLOAT_INIT
+int INTEGRAL_FUNC(integrate_gauss_smarttmp) (INTEGRAL_FLOAT_TYPE* out, int (*func)(INTEGRAL_FLOAT_TYPE*, INTEGRAL_FLOAT_TYPE, void*), INTEGRAL_FLOAT_TYPE lower, INTEGRAL_FLOAT_TYPE upper, INTEGRAL_FLOATARRAY_TYPE abcissa, INTEGRAL_FLOATARRAY_TYPE weights, INTEGRAL_FLOATARRAY_TYPE* tmps, void* extra_args){
+ unsigned int i;
+ int ret;
+
+ // check arguments
+ if(abcissa.length != weights.length){
+ return(LIBINUM_ERROR_SIZE_MISMATCH);
+ }
+
+ // allocate tmps if needed
+ if(tmps->memory<4){
+ // no need to resize since the values should not be kept
+ INTEGRAL_FLOATARRAY_FUNC(free)(*tmps);
+ INTEGRAL_FLOATARRAY_FUNC(init)(tmps, 4);
+ }
+ for (i=tmps->length;i<4;i++){
+ INTEGRAL_FLOAT_INIT(tmps->values[i]);
+ (tmps->length)++;
+ }
+
+ // init to 0
+ INTEGRAL_FLOAT_SET_UI(*out, 0);
+
+ // half length of interval
+ INTEGRAL_FLOAT_SUB(tmps->values[0], upper, lower);
+ INTEGRAL_FLOAT_DIV_UI(tmps->values[0], tmps->values[0], 2);
+ // average of interval
+ INTEGRAL_FLOAT_ADD(tmps->values[1], upper, lower);
+ INTEGRAL_FLOAT_DIV_UI(tmps->values[1], tmps->values[1], 2);
+
+ for(i=0;i<abcissa.length;i++){
+ // evaluation point
+ INTEGRAL_FLOAT_MUL(tmps->values[2], tmps->values[0], abcissa.values[i]);
+ INTEGRAL_FLOAT_ADD(tmps->values[2], tmps->values[2], tmps->values[1]);
+
+ ret=(*func)(tmps->values+3, tmps->values[2], extra_args);
+ if(ret<0){
+ return(ret);
+ }
+ // check whether tmps->values[3] is a number
+ if(! INTEGRAL_FLOAT_ISNUMBER(tmps->values[3])){
+ return(LIBINUM_ERROR_NAN);
+ }
+
+ INTEGRAL_FLOAT_MUL(tmps->values[3], tmps->values[3], weights.values[i]);
+ INTEGRAL_FLOAT_ADD(*out, *out, tmps->values[3]);
+ }
+
+ INTEGRAL_FLOAT_MUL(*out, *out, tmps->values[0]);
+
+ return(0);
+}
+#endif
+
+// multithreaded version with smart management of temporary variables (only for datatypes that need to be initialized)
+#ifdef INTEGRAL_FLOAT_INIT
+// arguments to pass to each thread
+struct INTEGRAL_FUNC(pthread_integrate_gauss_smarttmp_args) {
+ // partial sum of the values assigned to the thread
+ INTEGRAL_FLOAT_TYPE* out;
+ // abcissa
+ INTEGRAL_FLOATARRAY_TYPE x;
+ // weights
+ INTEGRAL_FLOATARRAY_TYPE weights;
+ // tmp
+ INTEGRAL_FLOAT_TYPE* tmp;
+ // pointer to the function to evaluate
+ int (*func)(INTEGRAL_FLOAT_TYPE*, INTEGRAL_FLOAT_TYPE, void*);
+ // extra arguments passed to func
+ void* extra_args;
+ // return value
+ int ret;
+};
+int INTEGRAL_FUNC(integrate_gauss_smarttmp_multithread) (INTEGRAL_FLOAT_TYPE* out, int (*func)(INTEGRAL_FLOAT_TYPE*, INTEGRAL_FLOAT_TYPE, void*), INTEGRAL_FLOAT_TYPE lower, INTEGRAL_FLOAT_TYPE upper, INTEGRAL_FLOATARRAY_TYPE abcissa, INTEGRAL_FLOATARRAY_TYPE weights, INTEGRAL_FLOATARRAY_TYPE* tmps, void* extra_args, unsigned int threads, array_pthread_t* thread_ids){
+ unsigned int i;
+ struct INTEGRAL_FUNC(pthread_integrate_gauss_smarttmp_args) args[threads];
+ int ret=0;
+ unsigned int thread_nr;
+
+ array_pthread_t_init(thread_ids, threads);
+ thread_ids->length=threads;
+
+ // check arguments
+ if(abcissa.length != weights.length){
+ return(LIBINUM_ERROR_SIZE_MISMATCH);
+ }
+
+ // allocate tmps if needed
+ if(tmps->memory<2+2*threads+abcissa.length){
+ // no need to resize since the values should not be kept
+ INTEGRAL_FLOATARRAY_FUNC(free)(*tmps);
+ INTEGRAL_FLOATARRAY_FUNC(init)(tmps, 2+2*threads+abcissa.length);
+ }
+ for (i=tmps->length;i<2+2*threads+abcissa.length;i++){
+ INTEGRAL_FLOAT_INIT(tmps->values[i]);
+ (tmps->length)++;
+ }
+
+
+ // init to 0
+ INTEGRAL_FLOAT_SET_UI(*out, 0);
+
+ // half length of interval
+ INTEGRAL_FLOAT_SUB(tmps->values[0], upper, lower);
+ INTEGRAL_FLOAT_DIV_UI(tmps->values[0], tmps->values[0], 2);
+ // average of interval
+ INTEGRAL_FLOAT_ADD(tmps->values[1], upper, lower);
+ INTEGRAL_FLOAT_DIV_UI(tmps->values[1], tmps->values[1], 2);
+
+ // inits
+ for(thread_nr=0;thread_nr<threads;thread_nr++){
+ INTEGRAL_FLOATARRAY_FUNC(init) (&(args[thread_nr].x),abcissa.length/threads+1);
+ INTEGRAL_FLOATARRAY_FUNC(init) (&(args[thread_nr].weights),abcissa.length/threads+1);
+ args[thread_nr].out=tmps->values+2+thread_nr;
+ args[thread_nr].tmp=tmps->values+2+threads+thread_nr;
+ }
+
+ // set abcissa and weights
+ for(i=0,thread_nr=0;i<abcissa.length;i++,thread_nr=(thread_nr+1)%threads){
+ INTEGRAL_FLOAT_MUL(tmps->values[2+2*threads+i], tmps->values[0], abcissa.values[i]);
+ INTEGRAL_FLOAT_ADD(tmps->values[2+2*threads+i], tmps->values[2+2*threads+i], tmps->values[1]);
+
+ INTEGRAL_FLOATARRAY_FUNC(append_noinit) (tmps->values[2+2*threads+i], &(args[thread_nr].x));
+ INTEGRAL_FLOATARRAY_FUNC(append_noinit) (weights.values[i], &(args[thread_nr].weights));
+ }
+
+ for(thread_nr=0;thread_nr<threads;thread_nr++){
+ // set func
+ args[thread_nr].func=func;
+ // set extra_args
+ args[thread_nr].extra_args=extra_args;
+ // init ret
+ args[thread_nr].ret=0;
+ // run threads
+ pthread_create(thread_ids->values+thread_nr, NULL, INTEGRAL_FUNC(integrate_gauss_smarttmp_thread), (void*)(args+thread_nr));
+ }
+
+ // wait for completion and join
+ for(thread_nr=0;thread_nr<threads;thread_nr++){
+ pthread_join(thread_ids->values[thread_nr], NULL);
+
+ if(args[thread_nr].ret<0){
+ ret=args[thread_nr].ret;
+ }
+ else{
+ INTEGRAL_FLOAT_ADD(*out, *out, *(args[thread_nr].out));
+ }
+ }
+
+ // multiply by size of interval
+ INTEGRAL_FLOAT_MUL(*out, *out, tmps->values[0]);
+
+ // free x and weights
+ for(thread_nr=0;thread_nr<threads;thread_nr++){
+ INTEGRAL_FLOATARRAY_FUNC(free_vects)(args[thread_nr].x);
+ INTEGRAL_FLOATARRAY_FUNC(free_vects)(args[thread_nr].weights);
+ }
+ return(ret);
+}
+// per-thread function
+void* INTEGRAL_FUNC(integrate_gauss_smarttmp_thread) (void* args){
+ unsigned int i;
+ int ret;
+ struct INTEGRAL_FUNC(pthread_integrate_gauss_smarttmp_args)* argument=((struct INTEGRAL_FUNC(pthread_integrate_gauss_smarttmp_args)*)args);
+
+ INTEGRAL_FLOAT_SET_UI(*(argument->out), 0);
+
+ for(i=0;i<argument->x.length;i++){
+ // evaluate
+ ret=(*(argument->func))(argument->tmp, argument->x.values[i], argument->extra_args);
+
+ if(ret<0){
+ argument->ret=ret;
+ return(NULL);
+ }
+ // check whether argument->tmp is a number
+ if(! INTEGRAL_FLOAT_ISNUMBER(*(argument->tmp))){
+ argument->ret=LIBINUM_ERROR_NAN;
+ return(NULL);
+ }
+
+ INTEGRAL_FLOAT_MUL(*(argument->tmp), *(argument->tmp), argument->weights.values[i]);
+ INTEGRAL_FLOAT_ADD(*(argument->out), *(argument->out), *(argument->tmp));
+ }
+
+ return(NULL);
+}
+#endif
+
+
+// compute the abcissa and weights for the Gauss-Legendre numerical integration scheme
+int INTEGRAL_FUNC(gauss_legendre_weights) (unsigned int order, INTEGRAL_FLOAT_TYPE tolerance, unsigned int maxiter, INTEGRAL_FLOATARRAY_TYPE* abcissa, INTEGRAL_FLOATARRAY_TYPE* weights){
+ unsigned int i;
+ INTEGRAL_FLOAT_TYPE x, tmp;
+ INTEGRAL_POLYNOMIALARRAY_TYPE legendre;
+ int ret;
+
+ INTEGRAL_FLOATARRAY_FUNC(init) (abcissa, order);
+ INTEGRAL_FLOATARRAY_FUNC(init) (weights, order);
+
+ #ifdef INTEGRAL_FLOAT_INIT
+ INTEGRAL_FLOAT_INIT(x);
+ INTEGRAL_FLOAT_INIT(tmp);
+ #endif
+
+ INTEGRAL_POLYNOMIALARRAY_FUNC(init) (&legendre, 2);
+ // compute the roots of the 'order'-th Legendre polynomial
+ INTEGRAL_POLYNOMIAL_FUNC(legendre) (order, legendre.values);
+ INTEGRAL_POLYNOMIAL_FUNC(derive) (legendre.values[0], legendre.values+1);
+ legendre.length=2;
+
+ for(i=0;i<order;i++){
+ // initial guess
+ INTEGRAL_FLOAT_SET_D(x, cos(3.1415926*(i+0.75)/(order+0.5)));
+ ret=INTEGRAL_FUNC(root_newton_inplace) (&x, &INTEGRAL_FUNC(legendre_wrapper), &INTEGRAL_FUNC(deriv_legendre_wrapper), tolerance, maxiter, &legendre);
+
+ if(ret<0){
+ #ifdef INTEGRAL_FLOAT_FREE
+ INTEGRAL_FLOAT_FREE(x);
+ INTEGRAL_FLOAT_FREE(tmp);
+ #endif
+ INTEGRAL_POLYNOMIALARRAY_FUNC(free) (legendre);
+ INTEGRAL_FLOATARRAY_FUNC(free) (*abcissa);
+ INTEGRAL_FLOATARRAY_FUNC(free) (*weights);
+ return(ret);
+ }
+
+ INTEGRAL_FLOATARRAY_FUNC(append) (x, abcissa);
+
+ // weight: 2/((1-x^2)*(deriv_Legendre(x)))^2
+ INTEGRAL_POLYNOMIAL_FUNC(evaluate) (&tmp, x, legendre.values[1]);
+ INTEGRAL_FLOAT_POW_UI(tmp, tmp, 2);
+ INTEGRAL_FLOAT_POW_UI(x, x, 2);
+ INTEGRAL_FLOAT_UI_SUB(x, 1, x);
+ INTEGRAL_FLOAT_MUL(x, x, tmp);
+ INTEGRAL_FLOAT_SET_UI(tmp, 2);
+ INTEGRAL_FLOAT_DIV(x, tmp, x);
+
+ INTEGRAL_FLOATARRAY_FUNC(append) (x, weights);
+ }
+
+ #ifdef INTEGRAL_FLOAT_FREE
+ INTEGRAL_FLOAT_FREE(x);
+ INTEGRAL_FLOAT_FREE(tmp);
+ #endif
+ INTEGRAL_POLYNOMIALARRAY_FUNC(free) (legendre);
+
+ return(0);
+}
+
+// wrapper functions to evaluate the legendre polynomial and its derivative
+int INTEGRAL_FUNC(legendre_wrapper) (INTEGRAL_FLOAT_TYPE* out, INTEGRAL_FLOAT_TYPE in, void* legendre){
+ INTEGRAL_POLYNOMIAL_FUNC(evaluate) (out, in, ((INTEGRAL_POLYNOMIALARRAY_TYPE*)legendre)->values[0]);
+ return(0);
+}
+int INTEGRAL_FUNC(deriv_legendre_wrapper) (INTEGRAL_FLOAT_TYPE* out, INTEGRAL_FLOAT_TYPE in, void* legendre){
+ INTEGRAL_POLYNOMIAL_FUNC(evaluate) (out, in, ((INTEGRAL_POLYNOMIALARRAY_TYPE*)legendre)->values[1]);
+ return(0);
+}
diff --git a/src/integral_base.h b/src/integral_base.h
new file mode 100644
index 0000000..4440a52
--- /dev/null
+++ b/src/integral_base.h
@@ -0,0 +1,48 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Base functions for integration
+
+ see integral_*.h for the values taken by INTEGRAL_FUNC, etc...
+*/
+
+#include <pthread.h>
+
+// compute the integral of a real function of 1 variable using the Gauss-Legendre scheme
+int INTEGRAL_FUNC(integrate_gauss) (INTEGRAL_FLOAT_TYPE* out, int (*func)(INTEGRAL_FLOAT_TYPE*, INTEGRAL_FLOAT_TYPE, void*), INTEGRAL_FLOAT_TYPE lower, INTEGRAL_FLOAT_TYPE upper, INTEGRAL_FLOATARRAY_TYPE abcissa, INTEGRAL_FLOATARRAY_TYPE weights, void* extra_args);
+
+// multithreaded version
+int INTEGRAL_FUNC(integrate_gauss_multithread) (INTEGRAL_FLOAT_TYPE* out, int (*func)(INTEGRAL_FLOAT_TYPE*, INTEGRAL_FLOAT_TYPE, void*), INTEGRAL_FLOAT_TYPE lower, INTEGRAL_FLOAT_TYPE upper, INTEGRAL_FLOATARRAY_TYPE abcissa, INTEGRAL_FLOATARRAY_TYPE weights, void* extra_args, unsigned int threads, array_pthread_t* thread_ids);
+// per-thread function
+void* INTEGRAL_FUNC(integrate_gauss_thread) (void* args);
+
+// smart management of temporary variables: initialize as many as needed but allow them to be re-used instead of freeing them
+#ifdef INTEGRAL_FLOAT_INIT
+int INTEGRAL_FUNC(integrate_gauss_smarttmp) (INTEGRAL_FLOAT_TYPE* out, int (*func)(INTEGRAL_FLOAT_TYPE*, INTEGRAL_FLOAT_TYPE, void*), INTEGRAL_FLOAT_TYPE lower, INTEGRAL_FLOAT_TYPE upper, INTEGRAL_FLOATARRAY_TYPE abcissa, INTEGRAL_FLOATARRAY_TYPE weights, INTEGRAL_FLOATARRAY_TYPE* tmps, void* extra_args);
+// multithreaded version with smart management of temporary variables (only for datatypes that need to be initialized)
+int INTEGRAL_FUNC(integrate_gauss_smarttmp_multithread) (INTEGRAL_FLOAT_TYPE* out, int (*func)(INTEGRAL_FLOAT_TYPE*, INTEGRAL_FLOAT_TYPE, void*), INTEGRAL_FLOAT_TYPE lower, INTEGRAL_FLOAT_TYPE upper, INTEGRAL_FLOATARRAY_TYPE abcissa, INTEGRAL_FLOATARRAY_TYPE weights, INTEGRAL_FLOATARRAY_TYPE* tmps, void* extra_args, unsigned int threads, array_pthread_t* thread_ids);
+// per-thread function
+void* INTEGRAL_FUNC(integrate_gauss_smarttmp_thread) (void* args);
+#endif
+
+// compute the abcissa and weights for the Gauss-Legendre numerical integration scheme
+int INTEGRAL_FUNC(gauss_legendre_weights) (unsigned int order, INTEGRAL_FLOAT_TYPE tolerance, unsigned int maxiter, INTEGRAL_FLOATARRAY_TYPE* abcissa, INTEGRAL_FLOATARRAY_TYPE* weights);
+
+// wrapper functions to evaluate the legendre polynomial and its derivative
+int INTEGRAL_FUNC(legendre_wrapper) (INTEGRAL_FLOAT_TYPE* out, INTEGRAL_FLOAT_TYPE in, void* legendre);
+int INTEGRAL_FUNC(deriv_legendre_wrapper) (INTEGRAL_FLOAT_TYPE* out, INTEGRAL_FLOAT_TYPE in, void* legendre);
+
diff --git a/src/integral_double.h b/src/integral_double.h
new file mode 100644
index 0000000..de179fb
--- /dev/null
+++ b/src/integral_double.h
@@ -0,0 +1,81 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Preprocessor macros for integration using with doubles
+*/
+
+
+// reset CPP macros
+#undef INTEGRAL_FUNC
+#undef INTEGRAL_FLOAT_TYPE
+#undef INTEGRAL_FLOAT_INIT
+#undef INTEGRAL_FLOAT_FREE
+#undef INTEGRAL_FLOAT_SET_D
+#undef INTEGRAL_FLOAT_SET_UI
+#undef INTEGRAL_FLOAT_ADD
+#undef INTEGRAL_FLOAT_SUB
+#undef INTEGRAL_FLOAT_UI_SUB
+#undef INTEGRAL_FLOAT_MUL
+#undef INTEGRAL_FLOAT_POW_UI
+#undef INTEGRAL_FLOAT_DIV
+#undef INTEGRAL_FLOAT_DIV_UI
+#undef INTEGRAL_FLOAT_ISNUMBER
+#undef INTEGRAL_FLOATARRAY_TYPE
+#undef INTEGRAL_FLOATARRAY_FUNC
+#undef INTEGRAL_POLYNOMIAL_FUNC
+#undef INTEGRAL_POLYNOMIALARRAY_TYPE
+#undef INTEGRAL_POLYNOMIALARRAY_FUNC
+
+// suffix of function names
+#define INTEGRAL_FUNC(NAME) NAME ## _double
+
+// type of floats
+#define INTEGRAL_FLOAT_TYPE double
+// set float from double
+#define INTEGRAL_FLOAT_SET_D(FLOAT, VAL) FLOAT=VAL
+// set float from unsigned int
+#define INTEGRAL_FLOAT_SET_UI(FLOAT, VAL) FLOAT=(double)VAL
+// add floats
+#define INTEGRAL_FLOAT_ADD(FLOAT, VAL1, VAL2) FLOAT=VAL1+VAL2
+// subtract floats
+#define INTEGRAL_FLOAT_SUB(FLOAT, VAL1, VAL2) FLOAT=VAL1-VAL2
+// subtract floats in which the first is specified as an unsigned int
+#define INTEGRAL_FLOAT_UI_SUB(FLOAT, VAL1, VAL2) FLOAT=(double)VAL1-VAL2
+// multiply floats
+#define INTEGRAL_FLOAT_MUL(FLOAT, VAL1, VAL2) FLOAT=VAL1*VAL2
+// power of a float, specified as an unsigned int
+#define INTEGRAL_FLOAT_POW_UI(FLOAT, VAL1, VAL2) FLOAT=pow(VAL1, (double)VAL2)
+// divide floats
+#define INTEGRAL_FLOAT_DIV(FLOAT, VAL1, VAL2) FLOAT=VAL1/VAL2
+// divide floats, one of which is specified as an unsigned int
+#define INTEGRAL_FLOAT_DIV_UI(FLOAT, VAL1, VAL2) FLOAT=VAL1/(double)VAL2
+// check whether a float is a regular number
+#define INTEGRAL_FLOAT_ISNUMBER(FLOAT) (fpclassify(FLOAT)>=FP_ZERO)
+
+// type of float arrays
+#define INTEGRAL_FLOATARRAY_TYPE array_double
+// prefix of float array function names
+#define INTEGRAL_FLOATARRAY_FUNC(NAME) array_double_ ## NAME
+
+// prefix of polynomial function names
+#define INTEGRAL_POLYNOMIAL_FUNC(NAME) polynomial_double_ ## NAME
+
+// type of polynomial arrays
+#define INTEGRAL_POLYNOMIALARRAY_TYPE array_polynomial_double
+// prefix of polynomial array function names
+#define INTEGRAL_POLYNOMIALARRAY_FUNC(NAME) array_polynomial_double_ ## NAME
+
diff --git a/src/integral_ldouble.h b/src/integral_ldouble.h
new file mode 100644
index 0000000..5b1d26f
--- /dev/null
+++ b/src/integral_ldouble.h
@@ -0,0 +1,81 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Preprocessor macros for integration using with long doubles
+*/
+
+
+// reset CPP macros
+#undef INTEGRAL_FUNC
+#undef INTEGRAL_FLOAT_TYPE
+#undef INTEGRAL_FLOAT_INIT
+#undef INTEGRAL_FLOAT_FREE
+#undef INTEGRAL_FLOAT_SET_D
+#undef INTEGRAL_FLOAT_SET_UI
+#undef INTEGRAL_FLOAT_ADD
+#undef INTEGRAL_FLOAT_SUB
+#undef INTEGRAL_FLOAT_UI_SUB
+#undef INTEGRAL_FLOAT_MUL
+#undef INTEGRAL_FLOAT_POW_UI
+#undef INTEGRAL_FLOAT_DIV
+#undef INTEGRAL_FLOAT_DIV_UI
+#undef INTEGRAL_FLOAT_ISNUMBER
+#undef INTEGRAL_FLOATARRAY_TYPE
+#undef INTEGRAL_FLOATARRAY_FUNC
+#undef INTEGRAL_POLYNOMIAL_FUNC
+#undef INTEGRAL_POLYNOMIALARRAY_TYPE
+#undef INTEGRAL_POLYNOMIALARRAY_FUNC
+
+// suffix of function names
+#define INTEGRAL_FUNC(NAME) NAME ## _ldouble
+
+// type of floats
+#define INTEGRAL_FLOAT_TYPE long double
+// set float from double
+#define INTEGRAL_FLOAT_SET_D(FLOAT, VAL) FLOAT=(long double)VAL
+// set float from unsigned int
+#define INTEGRAL_FLOAT_SET_UI(FLOAT, VAL) FLOAT=(long double)VAL
+// add floats
+#define INTEGRAL_FLOAT_ADD(FLOAT, VAL1, VAL2) FLOAT=VAL1+VAL2
+// subtract floats
+#define INTEGRAL_FLOAT_SUB(FLOAT, VAL1, VAL2) FLOAT=VAL1-VAL2
+// subtract floats in which the first is specified as an unsigned int
+#define INTEGRAL_FLOAT_UI_SUB(FLOAT, VAL1, VAL2) FLOAT=(long double)VAL1-VAL2
+// multiply floats
+#define INTEGRAL_FLOAT_MUL(FLOAT, VAL1, VAL2) FLOAT=VAL1*VAL2
+// power of a float, specified as an unsigned int
+#define INTEGRAL_FLOAT_POW_UI(FLOAT, VAL1, VAL2) FLOAT=powl(VAL1, (long double)VAL2)
+// divide floats
+#define INTEGRAL_FLOAT_DIV(FLOAT, VAL1, VAL2) FLOAT=VAL1/VAL2
+// divide floats, one of which is specified as an unsigned int
+#define INTEGRAL_FLOAT_DIV_UI(FLOAT, VAL1, VAL2) FLOAT=VAL1/(long double)VAL2
+// check whether a float is a regular number
+#define INTEGRAL_FLOAT_ISNUMBER(FLOAT) (fpclassify(FLOAT)>=FP_ZERO)
+
+// type of float arrays
+#define INTEGRAL_FLOATARRAY_TYPE array_ldouble
+// prefix of float array function names
+#define INTEGRAL_FLOATARRAY_FUNC(NAME) array_ldouble_ ## NAME
+
+// prefix of polynomial function names
+#define INTEGRAL_POLYNOMIAL_FUNC(NAME) polynomial_ldouble_ ## NAME
+
+// type of polynomial arrays
+#define INTEGRAL_POLYNOMIALARRAY_TYPE array_polynomial_ldouble
+// prefix of polynomial array function names
+#define INTEGRAL_POLYNOMIALARRAY_FUNC(NAME) array_polynomial_ldouble_ ## NAME
+
diff --git a/src/integral_mpfr.h b/src/integral_mpfr.h
new file mode 100644
index 0000000..30c9b1a
--- /dev/null
+++ b/src/integral_mpfr.h
@@ -0,0 +1,84 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Preprocessor macros for integration using with multi-precision floats (mpfr)
+*/
+
+
+// reset CPP macros
+#undef INTEGRAL_FUNC
+#undef INTEGRAL_FLOAT_TYPE
+#undef INTEGRAL_FLOAT_INIT
+#undef INTEGRAL_FLOAT_FREE
+#undef INTEGRAL_FLOAT_SET_D
+#undef INTEGRAL_FLOAT_SET_UI
+#undef INTEGRAL_FLOAT_ADD
+#undef INTEGRAL_FLOAT_SUB
+#undef INTEGRAL_FLOAT_UI_SUB
+#undef INTEGRAL_FLOAT_MUL
+#undef INTEGRAL_FLOAT_POW_UI
+#undef INTEGRAL_FLOAT_DIV
+#undef INTEGRAL_FLOAT_DIV_UI
+#undef INTEGRAL_FLOAT_ISNUMBER
+#undef INTEGRAL_FLOATARRAY_TYPE
+#undef INTEGRAL_FLOATARRAY_FUNC
+#undef INTEGRAL_POLYNOMIAL_FUNC
+#undef INTEGRAL_POLYNOMIALARRAY_TYPE
+#undef INTEGRAL_POLYNOMIALARRAY_FUNC
+
+// suffix of function names
+#define INTEGRAL_FUNC(NAME) NAME ## _mpfr
+
+// type of floats
+#define INTEGRAL_FLOAT_TYPE mpfr_t
+// init float
+#define INTEGRAL_FLOAT_INIT(VAR) mpfr_init(VAR)
+// free float
+#define INTEGRAL_FLOAT_FREE(VAR) mpfr_clear(VAR)
+// set float from double
+#define INTEGRAL_FLOAT_SET_D(FLOAT, VAL) mpfr_set_d(FLOAT, VAL, MPFR_RNDN)
+// set float from unsigned int
+#define INTEGRAL_FLOAT_SET_UI(FLOAT, VAL) mpfr_set_ui(FLOAT, VAL, MPFR_RNDN)
+// add floats
+#define INTEGRAL_FLOAT_ADD(FLOAT, VAL1, VAL2) mpfr_add(FLOAT, VAL1, VAL2, MPFR_RNDN)
+// subtract floats
+#define INTEGRAL_FLOAT_SUB(FLOAT, VAL1, VAL2) mpfr_sub(FLOAT, VAL1, VAL2, MPFR_RNDN)
+// subtract floats in which the first is specified as an unsigned int
+#define INTEGRAL_FLOAT_UI_SUB(FLOAT, VAL1, VAL2) mpfr_ui_sub(FLOAT, VAL1, VAL2, MPFR_RNDN)
+// multiply floats
+#define INTEGRAL_FLOAT_MUL(FLOAT, VAL1, VAL2) mpfr_mul(FLOAT, VAL1, VAL2, MPFR_RNDN)
+// power of a float, specified as an unsigned int
+#define INTEGRAL_FLOAT_POW_UI(FLOAT, VAL1, VAL2) mpfr_pow_ui(FLOAT, VAL1, VAL2, MPFR_RNDN)
+// divide floats
+#define INTEGRAL_FLOAT_DIV(FLOAT, VAL1, VAL2) mpfr_div(FLOAT, VAL1, VAL2, MPFR_RNDN)
+// divide floats, one of which is specified as an unsigned int
+#define INTEGRAL_FLOAT_DIV_UI(FLOAT, VAL1, VAL2) mpfr_div_ui(FLOAT, VAL1, VAL2, MPFR_RNDN)
+// check whether a float is a regular number
+#define INTEGRAL_FLOAT_ISNUMBER(FLOAT) mpfr_number_p(FLOAT)!=0
+
+// type of float arrays
+#define INTEGRAL_FLOATARRAY_TYPE array_mpfr
+// prefix of float array function names
+#define INTEGRAL_FLOATARRAY_FUNC(NAME) array_mpfr_ ## NAME
+
+// prefix of polynomial function names
+#define INTEGRAL_POLYNOMIAL_FUNC(NAME) polynomial_mpfr_ ## NAME
+
+// type of polynomial arrays
+#define INTEGRAL_POLYNOMIALARRAY_TYPE array_polynomial_mpfr
+// prefix of polynomial array function names
+#define INTEGRAL_POLYNOMIALARRAY_FUNC(NAME) array_polynomial_mpfr_ ## NAME
diff --git a/src/polynomial.c b/src/polynomial.c
new file mode 100644
index 0000000..9221241
--- /dev/null
+++ b/src/polynomial.c
@@ -0,0 +1,55 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "polynomial.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <mpfr.h>
+#include <math.h>
+#include "array.h"
+#include "utils.h"
+#include "errors.h"
+
+
+//--------------------------------------------------
+//
+// mpfr coefficients, unsigned int order (polynomial_mpfr)
+//
+//--------------------------------------------------
+
+#include "polynomial_mpfr.h"
+#include "polynomial_base.c"
+
+
+//--------------------------------------------------
+//
+// double coefficients, unsigned int order (polynomial_mpfr)
+//
+//--------------------------------------------------
+
+#include "polynomial_double.h"
+#include "polynomial_base.c"
+
+
+//--------------------------------------------------
+//
+// long double coefficients, unsigned int order (polynomial_mpfr)
+//
+//--------------------------------------------------
+
+#include "polynomial_ldouble.h"
+#include "polynomial_base.c"
diff --git a/src/polynomial.h b/src/polynomial.h
new file mode 100644
index 0000000..376149b
--- /dev/null
+++ b/src/polynomial.h
@@ -0,0 +1,55 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Real polynomial
+*/
+
+
+#ifndef LIBINUM_POLYNOMIAL_H
+#define LIBINUM_POLYNOMIAL_H
+
+#include "types.h"
+
+//--------------------------------------------------
+//
+// mpfr coefficients, unsigned int order (polynomial_mpfr)
+//
+//--------------------------------------------------
+#include "polynomial_mpfr.h"
+#include "polynomial_base.h"
+
+
+//--------------------------------------------------
+//
+// double coefficients, unsigned int order (polynomial_mpfr)
+//
+//--------------------------------------------------
+
+#include "polynomial_double.h"
+#include "polynomial_base.h"
+
+
+//--------------------------------------------------
+//
+// long double coefficients, unsigned int order (polynomial_mpfr)
+//
+//--------------------------------------------------
+
+#include "polynomial_ldouble.h"
+#include "polynomial_base.h"
+
+#endif
diff --git a/src/polynomialMV.c b/src/polynomialMV.c
new file mode 100644
index 0000000..2cafcf6
--- /dev/null
+++ b/src/polynomialMV.c
@@ -0,0 +1,30 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+
+#include "polynomialMV.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include "array.h"
+#include "errors.h"
+
+// multi-precision integer coefficients
+#include "polynomialMV_mpz.h"
+#include "polynomialMV_base.c"
+
+// integer coefficients
+#include "polynomialMV_int.h"
+#include "polynomialMV_base.c"
diff --git a/src/polynomialMV.h b/src/polynomialMV.h
new file mode 100644
index 0000000..e368d5b
--- /dev/null
+++ b/src/polynomialMV.h
@@ -0,0 +1,34 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Multi-variable polynomials
+*/
+
+#ifndef LIBINUM_POLYNOMIAL_MV_H
+#define LIBINUM_POLYNOMIAL_MV_H
+
+#include "types.h"
+
+// multi-precision integer coefficients
+#include "polynomialMV_mpz.h"
+#include "polynomialMV_base.h"
+
+// integer coefficients
+#include "polynomialMV_int.h"
+#include "polynomialMV_base.h"
+
+#endif
diff --git a/src/polynomialMV_base.c b/src/polynomialMV_base.c
new file mode 100644
index 0000000..814c499
--- /dev/null
+++ b/src/polynomialMV_base.c
@@ -0,0 +1,293 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Base functions for multivariable polynomials
+
+ see polynomialMV_*.h for the values taken by POLYNOMIALMV_FUNC, etc...
+*/
+
+// init
+int POLYNOMIALMV_FUNC(init) (POLYNOMIALMV_TYPENAME* polynomial, int size){
+ polynomial->factors=calloc(size, sizeof(POLYNOMIALMV_FACTOR_TYPE));
+ polynomial->coefficients=calloc(size, sizeof(POLYNOMIALMV_COEF_TYPE));
+ polynomial->length=0;
+ polynomial->memory=size;
+ return(0);
+}
+
+// free memory
+int POLYNOMIALMV_FUNC(free) (POLYNOMIALMV_TYPENAME polynomial){
+ unsigned int i;
+ for(i=0;i<polynomial.length;i++){
+ POLYNOMIALMV_FACTOR_FUNC(free) (polynomial.factors[i]);
+ #ifdef POLYNOMIALMV_COEF_FREE
+ POLYNOMIALMV_COEF_FREE(polynomial.coefficients[i]);
+ #endif
+ }
+ free(polynomial.factors);
+ free(polynomial.coefficients);
+ return(0);
+}
+
+// resize the memory allocated to a polynomial
+int POLYNOMIALMV_FUNC(resize) (POLYNOMIALMV_TYPENAME* polynomial, int new_size){
+ POLYNOMIALMV_TYPENAME new_poly;
+ unsigned int i;
+
+ POLYNOMIALMV_FUNC(init) (&new_poly, new_size);
+ for(i=0;i<polynomial->length;i++){
+ new_poly.factors[i]=polynomial->factors[i];
+ POLYNOMIALMV_COEF_SET(new_poly.coefficients[i], polynomial->coefficients[i]);
+ }
+ new_poly.length=polynomial->length;
+
+ free(polynomial->factors);
+ free(polynomial->coefficients);
+
+ *polynomial=new_poly;
+ return(0);
+}
+
+// copy a polynomial
+int POLYNOMIALMV_FUNC(cpy) (POLYNOMIALMV_TYPENAME input, POLYNOMIALMV_TYPENAME* output){
+ POLYNOMIALMV_FUNC(init) (output, input.length);
+ POLYNOMIALMV_FUNC(cpy_noinit) (input, output);
+ return(0);
+}
+int POLYNOMIALMV_FUNC(cpy_noinit) (POLYNOMIALMV_TYPENAME input, POLYNOMIALMV_TYPENAME* output){
+ unsigned int i;
+ if(output->memory<input.length){
+ return(LIBINUM_ERROR_ILLEGAL_MEMORY_ACCESS);
+ }
+ for(i=0;i<input.length;i++){
+ POLYNOMIALMV_FACTOR_FUNC(cpy) (input.factors[i],output->factors+i);
+ POLYNOMIALMV_COEF_CPY(output->coefficients[i], input.coefficients[i]);
+ }
+ output->length=input.length;
+
+ return(0);
+}
+
+// append an element to a polynomial
+int POLYNOMIALMV_FUNC(append) (POLYNOMIALMV_FACTOR_TYPE factor, POLYNOMIALMV_COEF_TYPE coef, POLYNOMIALMV_TYPENAME* output){
+ unsigned int offset=output->length;
+
+ if(output->length>=output->memory){
+ POLYNOMIALMV_FUNC(resize) (output,2*output->memory+1);
+ }
+
+ // copy and allocate
+ POLYNOMIALMV_FACTOR_FUNC(cpy) (factor, output->factors+offset);
+ POLYNOMIALMV_COEF_CPY(output->coefficients[offset], coef);
+ //increment length
+ output->length++;
+
+ return(0);
+}
+// if there already exists an element with the same factor, then just add coefficients
+// requires the factors to be ordered
+int POLYNOMIALMV_FUNC(append_inplace) (POLYNOMIALMV_FACTOR_TYPE factor, POLYNOMIALMV_COEF_TYPE coef, POLYNOMIALMV_TYPENAME* output){
+ unsigned int i;
+ unsigned short int foundit=0;
+ for(i=0;i<output->length;i++){
+ if(POLYNOMIALMV_FACTOR_FUNC(cmp) (factor, output->factors[i])==0){
+ POLYNOMIALMV_COEF_ADD(output->coefficients[i], output->coefficients[i], coef);
+ foundit=1;
+ break;
+ }
+ }
+ if(foundit==0){
+ POLYNOMIALMV_FUNC(append) (factor, coef, output);
+ }
+ return(0);
+}
+// do not allocate memory for the factor or the coefficient
+int POLYNOMIALMV_FUNC(append_noinit) (POLYNOMIALMV_FACTOR_TYPE factor, POLYNOMIALMV_COEF_TYPE coef, POLYNOMIALMV_TYPENAME* output){
+ int offset=output->length;
+
+ if(output->length>=output->memory){
+ POLYNOMIALMV_FUNC(resize) (output,2*output->memory+1);
+ }
+
+ // copy without allocating
+ output->factors[offset]=factor;
+ POLYNOMIALMV_COEF_SET(output->coefficients[offset], coef);
+ // increment length
+ output->length++;
+ return(0);
+}
+// noinit factor but init coefficient
+int POLYNOMIALMV_FUNC(append_noinitfactor) (POLYNOMIALMV_FACTOR_TYPE factor, POLYNOMIALMV_COEF_TYPE coef, POLYNOMIALMV_TYPENAME* output){
+ int offset=output->length;
+
+ if(output->length>=output->memory){
+ POLYNOMIALMV_FUNC(resize) (output,2*output->memory+1);
+ }
+
+ // copy without allocating
+ output->factors[offset]=factor;
+ POLYNOMIALMV_COEF_CPY(output->coefficients[offset], coef);
+ // increment length
+ output->length++;
+ return(0);
+}
+// noinit
+// if there already exists an element with the same factor, then just add coefficients
+// requires the factors to be ordered
+int POLYNOMIALMV_FUNC(append_noinit_inplace) (POLYNOMIALMV_FACTOR_TYPE factor, POLYNOMIALMV_COEF_TYPE coef, POLYNOMIALMV_TYPENAME* output){
+ unsigned int i;
+ unsigned short int foundit=0;
+ for(i=0;i<output->length;i++){
+ if(POLYNOMIALMV_FACTOR_FUNC(cmp) (factor, output->factors[i])==0){
+ POLYNOMIALMV_COEF_ADD(output->coefficients[i], output->coefficients[i], coef);
+ foundit=1;
+ // free
+ POLYNOMIALMV_FACTOR_FUNC(free) (factor);
+ #ifdef POLYNOMIALMV_COEF_FREE
+ POLYNOMIALMV_COEF_FREE(coef);
+ #endif
+ break;
+ }
+ }
+ if(foundit==0){
+ POLYNOMIALMV_FUNC(append_noinit) (factor, coef, output);
+ }
+ return(0);
+}
+// noinit factor but init coefficient
+// if there already exists an element with the same factor, then just add coefficients
+// requires the factors to be ordered
+int POLYNOMIALMV_FUNC(append_noinitfactor_inplace) (POLYNOMIALMV_FACTOR_TYPE factor, POLYNOMIALMV_COEF_TYPE coef, POLYNOMIALMV_TYPENAME* output){
+ unsigned int i;
+ unsigned short int foundit=0;
+ for(i=0;i<output->length;i++){
+ if(POLYNOMIALMV_FACTOR_FUNC(cmp) (factor, output->factors[i])==0){
+ POLYNOMIALMV_COEF_ADD(output->coefficients[i], output->coefficients[i], coef);
+ foundit=1;
+ // free factor
+ POLYNOMIALMV_FACTOR_FUNC(free) (factor);
+ break;
+ }
+ }
+ if(foundit==0){
+ POLYNOMIALMV_FUNC(append_noinitfactor) (factor, coef, output);
+ }
+ return(0);
+}
+
+// add polynomials (inplace)
+int POLYNOMIALMV_FUNC(add_inplace) (POLYNOMIALMV_TYPENAME input, POLYNOMIALMV_TYPENAME* inout){
+ unsigned int i;
+ for(i=0;i<input.length;i++){
+ POLYNOMIALMV_FUNC(append_inplace) (input.factors[i], input.coefficients[i], inout);
+ }
+ return(0);
+}
+// not inplace
+int POLYNOMIALMV_FUNC(add) (POLYNOMIALMV_TYPENAME input1, POLYNOMIALMV_TYPENAME input2, POLYNOMIALMV_TYPENAME* output){
+ POLYNOMIALMV_FUNC(cpy) (input1, output);
+ POLYNOMIALMV_FUNC(add_inplace) (input2, output);
+ return(0);
+}
+
+// multiply a polynomial by a scalar
+int POLYNOMIALMV_FUNC(multiply_scalar) (POLYNOMIALMV_TYPENAME polynomial, POLYNOMIALMV_COEF_TYPE num){
+ unsigned int i;
+ for(i=0;i<polynomial.length;i++){
+ POLYNOMIALMV_COEF_MUL(polynomial.coefficients[i], polynomial.coefficients[i], num);
+ }
+ return(0);
+}
+
+// multiply polynomials
+int POLYNOMIALMV_FUNC(prod) (POLYNOMIALMV_TYPENAME input1, POLYNOMIALMV_TYPENAME input2, POLYNOMIALMV_TYPENAME* output){
+ // position in polys
+ unsigned int pos1, pos2;
+ POLYNOMIALMV_FACTOR_TYPE out_factor;
+ POLYNOMIALMV_COEF_TYPE out_num;
+
+ POLYNOMIALMV_FUNC(init) (output, input1.length);
+ #ifdef POLYNOMIALMV_COEF_INIT
+ POLYNOMIALMV_COEF_INIT(out_num);
+ #endif
+
+ // loop over terms
+ for(pos1=0;pos1<input1.length;pos1++){
+ for(pos2=0;pos2<input2.length;pos2++){
+ // allocate
+ POLYNOMIALMV_FACTOR_FUNC(init) (&out_factor, input1.factors[pos1].length + input2.factors[pos2].length);
+
+ // concatenate factor
+ POLYNOMIALMV_FACTOR_FUNC(concat) (input1.factors[pos1],&out_factor);
+ POLYNOMIALMV_FACTOR_FUNC(concat) (input2.factors[pos2],&out_factor);
+ // sort factor
+ POLYNOMIALMV_FACTOR_FUNC(sort) (out_factor);
+ // multiply coefficient
+ POLYNOMIALMV_COEF_MUL(out_num, input1.coefficients[pos1], input2.coefficients[pos2]);
+
+ // write factor and coef
+ POLYNOMIALMV_FUNC(append_noinit_inplace) (out_factor, out_num, output);
+ }
+ }
+
+ #ifdef POLYNOMIALMV_COEF_FREE
+ POLYNOMIALMV_COEF_FREE(out_num);
+ #endif
+ return(0);
+}
+
+// order factors
+int POLYNOMIALMV_FUNC(order) (POLYNOMIALMV_TYPENAME polynomial){
+ unsigned int i,j;
+ for(i=0;i<polynomial.length;i++){
+ for(j=0;j<polynomial.factors[i].length-1;j++){
+ if(polynomial.factors[i].values[j] > polynomial.factors[i].values[j+1]){
+ POLYNOMIALMV_FACTOR_FUNC(sort) (polynomial.factors[i]);
+ break;
+ }
+ }
+ }
+ return(0);
+}
+
+// print
+int POLYNOMIALMV_FUNC(print) (POLYNOMIALMV_TYPENAME polynomial){
+ unsigned int i,j;
+
+ // for each monomial
+ for(i=0;i<polynomial.length;i++){
+ if(i==0){
+ printf(" ");
+ }
+ else{
+ printf("+ ");
+ }
+
+ // print num
+ POLYNOMIALMV_COEF_PRINT(polynomial.coefficients[i]);
+
+ // print factors
+ for(j=0;j<polynomial.factors[i].length;j++){
+ POLYNOMIALMV_FACTOR_ELT_PRINT(polynomial.factors[i].values[j]);
+ }
+
+ printf("\n");
+ }
+ return(0);
+}
+
+
diff --git a/src/polynomialMV_base.h b/src/polynomialMV_base.h
new file mode 100644
index 0000000..dde20ac
--- /dev/null
+++ b/src/polynomialMV_base.h
@@ -0,0 +1,67 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Base functions for multivariable polynomials
+
+ polynomialMV_*.h for the values taken by POLYNOMIALMV_FUNC, etc...
+*/
+
+// init
+int POLYNOMIALMV_FUNC(init) (POLYNOMIALMV_TYPENAME* polynomial, int size);
+int POLYNOMIALMV_FUNC(free) (POLYNOMIALMV_TYPENAME polynomial);
+
+// resize the memory allocated to a polynomial
+int POLYNOMIALMV_FUNC(resize) (POLYNOMIALMV_TYPENAME* polynomial, int new_size);
+
+// copy a polynomial
+int POLYNOMIALMV_FUNC(cpy) (POLYNOMIALMV_TYPENAME input, POLYNOMIALMV_TYPENAME* output);
+int POLYNOMIALMV_FUNC(cpy_noinit) (POLYNOMIALMV_TYPENAME input, POLYNOMIALMV_TYPENAME* output);
+
+// append an element to a polynomial
+int POLYNOMIALMV_FUNC(append) (POLYNOMIALMV_FACTOR_TYPE factor, POLYNOMIALMV_COEF_TYPE coef, POLYNOMIALMV_TYPENAME* output);
+// if there already exists an element with the same factor, then just add coefficients
+// requires the factors to be ordered
+int POLYNOMIALMV_FUNC(append_inplace) (POLYNOMIALMV_FACTOR_TYPE factor, POLYNOMIALMV_COEF_TYPE coef, POLYNOMIALMV_TYPENAME* output);
+// do not allocate memory for factor or coefficient
+int POLYNOMIALMV_FUNC(append_noinit) (POLYNOMIALMV_FACTOR_TYPE factor, POLYNOMIALMV_COEF_TYPE coef, POLYNOMIALMV_TYPENAME* output);
+// noinit factor but init coefficient
+int POLYNOMIALMV_FUNC(append_noinitfactor) (POLYNOMIALMV_FACTOR_TYPE factor, POLYNOMIALMV_COEF_TYPE coef, POLYNOMIALMV_TYPENAME* output);
+// noinit
+// if there already exists an element with the same factor, then just add coefficients
+// requires the factors to be ordered
+int POLYNOMIALMV_FUNC(append_noinit_inplace) (POLYNOMIALMV_FACTOR_TYPE factor, POLYNOMIALMV_COEF_TYPE coef, POLYNOMIALMV_TYPENAME* output);
+// noinit factors but init coefficient
+// if there already exists an element with the same factor, then just add coefficients
+// requires the factors to be ordered
+int POLYNOMIALMV_FUNC(append_noinitfactor_inplace) (POLYNOMIALMV_FACTOR_TYPE factor, POLYNOMIALMV_COEF_TYPE coef, POLYNOMIALMV_TYPENAME* output);
+
+// add polynomials (inplace)
+int POLYNOMIALMV_FUNC(add_inplace) (POLYNOMIALMV_TYPENAME input, POLYNOMIALMV_TYPENAME* inout);
+// not inplace
+int POLYNOMIALMV_FUNC(add) (POLYNOMIALMV_TYPENAME input1, POLYNOMIALMV_TYPENAME input2, POLYNOMIALMV_TYPENAME* output);
+
+// multiply a polynomial by a scalar
+int POLYNOMIALMV_FUNC(multiply_scalar) (POLYNOMIALMV_TYPENAME polynomial, POLYNOMIALMV_COEF_TYPE num);
+
+// multiply polynomials
+int POLYNOMIALMV_FUNC(prod) (POLYNOMIALMV_TYPENAME input1, POLYNOMIALMV_TYPENAME input2, POLYNOMIALMV_TYPENAME* output);
+
+// order factors
+int POLYNOMIALMV_FUNC(order) (POLYNOMIALMV_TYPENAME polynomial);
+
+// print
+int POLYNOMIALMV_FUNC(print) (POLYNOMIALMV_TYPENAME polynomial);
diff --git a/src/polynomialMV_int.h b/src/polynomialMV_int.h
new file mode 100644
index 0000000..cb25866
--- /dev/null
+++ b/src/polynomialMV_int.h
@@ -0,0 +1,62 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Preprocessor macros for multivariable polynomials with integer coefficients and integer-indexed variables
+*/
+
+
+// reset CPP macros
+#undef POLYNOMIALMV_TYPENAME
+#undef POLYNOMIALMV_FUNC
+#undef POLYNOMIALMV_COEF_TYPE
+#undef POLYNOMIALMV_COEF_INIT
+#undef POLYNOMIALMV_COEF_FREE
+#undef POLYNOMIALMV_COEF_SET
+#undef POLYNOMIALMV_COEF_CPY
+#undef POLYNOMIALMV_COEF_ADD
+#undef POLYNOMIALMV_COEF_MUL
+#undef POLYNOMIALMV_COEF_PRINT
+#undef POLYNOMIALMV_FACTOR_TYPE
+#undef POLYNOMIALMV_FACTOR_FUNC
+#undef POLYNOMIALMV_FACTOR_ELT_PRINT
+
+
+// name of the polynomial type
+#define POLYNOMIALMV_TYPENAME polynomialMV_int
+// prefix of function names
+#define POLYNOMIALMV_FUNC(NAME) polynomialMV_int_ ## NAME
+
+// type of the coefficient
+#define POLYNOMIALMV_COEF_TYPE int
+// set coefficient
+#define POLYNOMIALMV_COEF_SET(COEF, VAL) COEF = VAL
+// copy coefficient
+#define POLYNOMIALMV_COEF_CPY(COEF, VAL) COEF = VAL
+// add coefficients
+#define POLYNOMIALMV_COEF_ADD(COEF, VAL1, VAL2) COEF = VAL1 + VAL2
+// multiply coefficients
+#define POLYNOMIALMV_COEF_MUL(COEF, VAL1, VAL2) COEF = VAL1 * VAL2
+// print a coefficient
+#define POLYNOMIALMV_COEF_PRINT(COEF) printf("%d", COEF)
+
+// type of the factor (must be an array)
+#define POLYNOMIALMV_FACTOR_TYPE array_int
+// prefix of factor function names
+#define POLYNOMIALMV_FACTOR_FUNC(NAME) array_int_ ## NAME
+// print an element of a factor
+#define POLYNOMIALMV_FACTOR_ELT_PRINT(ELT) printf("[x%d]", ELT)
+
diff --git a/src/polynomialMV_mpz.h b/src/polynomialMV_mpz.h
new file mode 100644
index 0000000..4b99aa6
--- /dev/null
+++ b/src/polynomialMV_mpz.h
@@ -0,0 +1,66 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Preprocessor macros for multivariable polynomials with multi-precision integer (mpz) coefficients and integer-indexed variables
+*/
+
+
+// reset CPP macros
+#undef POLYNOMIALMV_TYPENAME
+#undef POLYNOMIALMV_FUNC
+#undef POLYNOMIALMV_COEF_TYPE
+#undef POLYNOMIALMV_COEF_INIT
+#undef POLYNOMIALMV_COEF_FREE
+#undef POLYNOMIALMV_COEF_SET
+#undef POLYNOMIALMV_COEF_CPY
+#undef POLYNOMIALMV_COEF_ADD
+#undef POLYNOMIALMV_COEF_MUL
+#undef POLYNOMIALMV_COEF_PRINT
+#undef POLYNOMIALMV_FACTOR_TYPE
+#undef POLYNOMIALMV_FACTOR_FUNC
+#undef POLYNOMIALMV_FACTOR_ELT_PRINT
+
+
+// name of the polynomial type
+#define POLYNOMIALMV_TYPENAME polynomialMV_mpz
+// prefix of function names
+#define POLYNOMIALMV_FUNC(NAME) polynomialMV_mpz_ ## NAME
+
+// type of the coefficient
+#define POLYNOMIALMV_COEF_TYPE mpz_t
+// init coefficient
+#define POLYNOMIALMV_COEF_INIT(VAR) mpz_init(VAR)
+// free coefficient
+#define POLYNOMIALMV_COEF_FREE(VAR) mpz_clear(VAR)
+// set coefficient
+#define POLYNOMIALMV_COEF_SET(COEF, VAL) COEF[0]=VAL[0]
+// copy coefficient
+#define POLYNOMIALMV_COEF_CPY(COEF, VAL) mpz_init(COEF); mpz_set(COEF, VAL)
+// add coefficients
+#define POLYNOMIALMV_COEF_ADD(COEF, VAL1, VAL2) mpz_add(COEF, VAL1, VAL2)
+// multiply coefficients
+#define POLYNOMIALMV_COEF_MUL(COEF, VAL1, VAL2) mpz_mul(COEF, VAL1, VAL2)
+// print a coefficient
+#define POLYNOMIALMV_COEF_PRINT(COEF) gmp_printf("%Zd", COEF)
+
+// type of the factor (must be an array)
+#define POLYNOMIALMV_FACTOR_TYPE array_int
+// prefix of factor function names
+#define POLYNOMIALMV_FACTOR_FUNC(NAME) array_int_ ## NAME
+// print an element of a factor
+#define POLYNOMIALMV_FACTOR_ELT_PRINT(ELT) printf("[x%d]", ELT)
+
diff --git a/src/polynomialMV_type.h b/src/polynomialMV_type.h
new file mode 100644
index 0000000..6fbf778
--- /dev/null
+++ b/src/polynomialMV_type.h
@@ -0,0 +1,29 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Structure definition for multivariable polynomials
+
+ see polynomialMV_*.h for the values taken by POLYNOMIALMV_TYPENAME, etc...
+*/
+
+typedef struct POLYNOMIALMV_TYPENAME {
+ POLYNOMIALMV_COEF_TYPE* coefficients;
+ POLYNOMIALMV_FACTOR_TYPE* factors;
+ unsigned int length;
+ unsigned int memory;
+} POLYNOMIALMV_TYPENAME;
+
diff --git a/src/polynomial_base.c b/src/polynomial_base.c
new file mode 100644
index 0000000..1b4137d
--- /dev/null
+++ b/src/polynomial_base.c
@@ -0,0 +1,337 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Base functions for real polynomials
+
+ see polynomial_*.h for the values taken by POLYNOMIAL_FUNC, etc...
+*/
+
+
+// init
+int POLYNOMIAL_FUNC(init) (POLYNOMIAL_TYPENAME* poly, unsigned int memory){
+ POLYNOMIAL_COEFSARRAY_FUNC(init) (&(poly->coefficients), memory);
+ POLYNOMIAL_ORDERSARRAY_FUNC(init) (&(poly->orders), memory);
+ return(0);
+}
+int POLYNOMIAL_FUNC(free) (POLYNOMIAL_TYPENAME poly){
+ POLYNOMIAL_COEFSARRAY_FUNC(free) (poly.coefficients);
+ POLYNOMIAL_ORDERSARRAY_FUNC(free) (poly.orders);
+ return(0);
+}
+
+// resize memory
+int POLYNOMIAL_FUNC(resize) (POLYNOMIAL_TYPENAME* poly, unsigned int newsize){
+ POLYNOMIAL_COEFSARRAY_FUNC(resize) (&(poly->coefficients), newsize);
+ POLYNOMIAL_ORDERSARRAY_FUNC(resize) (&(poly->orders), newsize);
+ return(0);
+}
+
+// add a monomial
+int POLYNOMIAL_FUNC(add_monomial) (POLYNOMIAL_COEF_TYPE val, POLYNOMIAL_ORDER_TYPE order, POLYNOMIAL_TYPENAME* output){
+ unsigned int i;
+ if((output->coefficients.length != output->orders.length) || (output->coefficients.memory != output->orders.memory)){
+ return(LIBINUM_ERROR_SIZE_MISMATCH);
+ }
+ // check whether the order already exists in the polynomial
+ for(i=0;i< output->coefficients.length;i++){
+ if(POLYNOMIAL_ORDER_CMP(order, output->orders.values[i])==0){
+ POLYNOMIAL_COEF_ADD(output->coefficients.values[i], output->coefficients.values[i], val);
+ return(0);
+ }
+ }
+ // if the order does not already exist
+ if(output->coefficients.length >= output->coefficients.memory){
+ POLYNOMIAL_FUNC(resize) (output,2*output->coefficients.memory+1);
+ }
+ POLYNOMIAL_COEF_CPY(val, output->coefficients.values[output->coefficients.length]);
+ POLYNOMIAL_ORDER_CPY(order, output->orders.values[output->coefficients.length]);
+ output->coefficients.length++;
+ output->orders.length++;
+ return(0);
+}
+// from a double-valued coefficient and an unsigned int order
+int POLYNOMIAL_FUNC(add_monomial_dui) (double val, unsigned int order, POLYNOMIAL_TYPENAME* output){
+ unsigned int i;
+ if((output->coefficients.length != output->orders.length) || (output->coefficients.memory != output->orders.memory)){
+ return(LIBINUM_ERROR_SIZE_MISMATCH);
+ }
+ // check whether the order already exists in the polynomial
+ for(i=0;i< output->coefficients.length;i++){
+ if(POLYNOMIAL_ORDER_CMP_UI(output->orders.values[i], order)==0){
+ POLYNOMIAL_COEF_ADD_D(output->coefficients.values[i], output->coefficients.values[i], val);
+ return(0);
+ }
+ }
+ // if the order does not already exist
+ if(output->coefficients.length >= output->coefficients.memory){
+ POLYNOMIAL_FUNC(resize) (output,2*output->coefficients.memory+1);
+ }
+ POLYNOMIAL_COEF_CPY_D(val, output->coefficients.values[output->coefficients.length]);
+ POLYNOMIAL_ORDER_CPY_UI(order, output->orders.values[output->coefficients.length]);
+ output->coefficients.length++;
+ output->orders.length++;
+ return(0);
+}
+
+// copy
+int POLYNOMIAL_FUNC(cpy) (POLYNOMIAL_TYPENAME input, POLYNOMIAL_TYPENAME* output){
+ POLYNOMIAL_COEFSARRAY_FUNC(cpy) (input.coefficients, &(output->coefficients));
+ POLYNOMIAL_ORDERSARRAY_FUNC(cpy) (input.orders, &(output->orders));
+ return(0);
+}
+int POLYNOMIAL_FUNC(cpy_noinit) (POLYNOMIAL_TYPENAME input, POLYNOMIAL_TYPENAME* output){
+ int ret;
+ ret=POLYNOMIAL_COEFSARRAY_FUNC(cpy_noinit) (input.coefficients, &(output->coefficients));
+ if(ret<0){
+ return(ret);
+ }
+ POLYNOMIAL_ORDERSARRAY_FUNC(cpy_noinit) (input.orders, &(output->orders));
+ return(ret);
+}
+
+// add
+int POLYNOMIAL_FUNC(add_inplace) (POLYNOMIAL_TYPENAME poly1, POLYNOMIAL_TYPENAME* poly2){
+ unsigned int i;
+ if(poly1.coefficients.length != poly1.orders.length){
+ return(LIBINUM_ERROR_SIZE_MISMATCH);
+ }
+ for(i=0;i<poly1.coefficients.length;i++){
+ POLYNOMIAL_FUNC(add_monomial) (poly1.coefficients.values[i], poly1.orders.values[i], poly2);
+ }
+ return(0);
+}
+int POLYNOMIAL_FUNC(add) (POLYNOMIAL_TYPENAME poly1, POLYNOMIAL_TYPENAME poly2, POLYNOMIAL_TYPENAME* output){
+ int ret;
+ POLYNOMIAL_FUNC(cpy) (poly2, output);
+ ret=POLYNOMIAL_FUNC(add_inplace) (poly1, output);
+ return(ret);
+}
+
+// multiply by a scalar
+int POLYNOMIAL_FUNC(mul_scalar_inplace) (POLYNOMIAL_COEF_TYPE x, POLYNOMIAL_TYPENAME* poly){
+ unsigned int i;
+ if(poly->coefficients.length != poly->orders.length){
+ return(LIBINUM_ERROR_SIZE_MISMATCH);
+ }
+ for(i=0;i<poly->coefficients.length;i++){
+ POLYNOMIAL_COEF_MUL(poly->coefficients.values[i], poly->coefficients.values[i], x);
+ }
+ return(0);
+}
+int POLYNOMIAL_FUNC(mul_scalar) (POLYNOMIAL_COEF_TYPE x, POLYNOMIAL_TYPENAME poly, POLYNOMIAL_TYPENAME* output){
+ int ret;
+ POLYNOMIAL_FUNC(cpy) (poly, output);
+ ret=POLYNOMIAL_FUNC(mul_scalar_inplace) (x, output);
+ return(ret);
+}
+
+// multiply by a monomial
+int POLYNOMIAL_FUNC(mul_monomial_inplace) (POLYNOMIAL_COEF_TYPE x, POLYNOMIAL_ORDER_TYPE order, POLYNOMIAL_TYPENAME* poly){
+ unsigned int i;
+ if(poly->coefficients.length != poly->orders.length){
+ return(LIBINUM_ERROR_SIZE_MISMATCH);
+ }
+ for(i=0;i<poly->coefficients.length;i++){
+ POLYNOMIAL_COEF_MUL(poly->coefficients.values[i], poly->coefficients.values[i], x);
+ POLYNOMIAL_ORDER_ADD(poly->orders.values[i], poly->orders.values[i], order);
+ }
+ return(0);
+}
+int POLYNOMIAL_FUNC(mul_monomial) (POLYNOMIAL_COEF_TYPE x, POLYNOMIAL_ORDER_TYPE order, POLYNOMIAL_TYPENAME poly, POLYNOMIAL_TYPENAME* output){
+ int ret;
+ POLYNOMIAL_FUNC(cpy) (poly,output);
+ ret=POLYNOMIAL_FUNC(mul_monomial_inplace) (x, order, output);
+ return(ret);
+}
+
+// multiply two polynomials
+int POLYNOMIAL_FUNC(mul_inplace) (POLYNOMIAL_TYPENAME poly1, POLYNOMIAL_TYPENAME* poly2){
+ unsigned int i;
+ int ret;
+ if(poly1.coefficients.length != poly1.orders.length){
+ return(LIBINUM_ERROR_SIZE_MISMATCH);
+ }
+ for(i=0;i<poly1.coefficients.length;i++){
+ ret=POLYNOMIAL_FUNC(mul_monomial_inplace) (poly1.coefficients.values[i], poly1.orders.values[i], poly2);
+ if(ret<0){
+ return(ret);
+ }
+ }
+ return(0);
+}
+int POLYNOMIAL_FUNC(mul) (POLYNOMIAL_TYPENAME poly1, POLYNOMIAL_TYPENAME poly2, POLYNOMIAL_TYPENAME* output){
+ int ret;
+ POLYNOMIAL_FUNC(cpy) (poly2, output);
+ ret=POLYNOMIAL_FUNC(mul_inplace) (poly1, output);
+ return(ret);
+}
+
+// derive
+int POLYNOMIAL_FUNC(derive_inplace) (POLYNOMIAL_TYPENAME* poly){
+ unsigned int i;
+ if(poly->coefficients.length != poly->orders.length){
+ return(LIBINUM_ERROR_SIZE_MISMATCH);
+ }
+ for(i=0;i<poly->coefficients.length;i++){
+ if(POLYNOMIAL_ORDER_CMP_UI(poly->orders.values[i], 0)>0){
+ POLYNOMIAL_COEF_MUL_ORDER(poly->coefficients.values[i], poly->coefficients.values[i], poly->orders.values[i]);
+ POLYNOMIAL_ORDER_SUB_UI(poly->orders.values[i], poly->orders.values[i], 1);
+ }
+ else{
+ // remove the term by setting it to the last term and reducing the length
+ #ifdef POLYNOMIAL_COEF_FREE
+ POLYNOMIAL_COEF_FREE(poly->coefficients.values[i]);
+ #endif
+ #ifdef POLYNOMIAL_ORDER_FREE
+ POLYNOMIAL_ORDER_FREE(poly->orders.values[i]);
+ #endif
+ if(i<poly->coefficients.length-1){
+ POLYNOMIAL_COEF_SET(poly->coefficients.values[i], poly->coefficients.values[poly->coefficients.length-1]);
+ POLYNOMIAL_ORDER_SET(poly->orders.values[i], poly->orders.values[poly->coefficients.length-1]);
+ i--;
+ }
+ poly->coefficients.length--;
+ poly->orders.length--;
+ }
+ }
+ return(0);
+}
+int POLYNOMIAL_FUNC(derive) (POLYNOMIAL_TYPENAME poly, POLYNOMIAL_TYPENAME* output){
+ int ret;
+ POLYNOMIAL_FUNC(cpy) (poly, output);
+ ret=POLYNOMIAL_FUNC(derive_inplace) (output);
+ return(ret);
+}
+
+// evaluate
+int POLYNOMIAL_FUNC(evaluate) (POLYNOMIAL_COEF_TYPE* out, POLYNOMIAL_COEF_TYPE x, POLYNOMIAL_TYPENAME poly){
+ unsigned int i;
+ POLYNOMIAL_COEF_TYPE tmp;
+
+ #ifdef POLYNOMIAL_COEF_INIT
+ POLYNOMIAL_COEF_INIT(tmp);
+ #endif
+
+ if(poly.coefficients.length != poly.orders.length){
+ return(LIBINUM_ERROR_SIZE_MISMATCH);
+ }
+
+ POLYNOMIAL_COEF_SET_UI(*out, 0);
+ for(i=0;i<poly.coefficients.length;i++){
+ POLYNOMIAL_COEF_POW_UI(tmp, x, poly.orders.values[i]);
+ POLYNOMIAL_COEF_MUL(tmp, tmp, poly.coefficients.values[i]);
+ POLYNOMIAL_COEF_ADD(*out, *out, tmp);
+ }
+ #ifdef POLYNOMIAL_COEF_FREE
+ POLYNOMIAL_COEF_FREE(tmp);
+ #endif
+ return(0);
+}
+
+// print
+int POLYNOMIAL_FUNC(print) (POLYNOMIAL_TYPENAME poly){
+ unsigned int j;
+
+ if(poly.coefficients.length != poly.orders.length){
+ return(LIBINUM_ERROR_SIZE_MISMATCH);
+ }
+
+ printf(" ");
+ for(j=0;j<poly.coefficients.length;j++){
+ if(j>0){
+ printf("+ ");
+ }
+ POLYNOMIAL_COEF_PRINT(poly.coefficients.values[j]);
+ printf(" x^");
+ POLYNOMIAL_ORDER_PRINT(poly.orders.values[j]);
+ printf("\n");
+ }
+
+ return(0);
+}
+
+
+// n-th Legendre polynomial
+int POLYNOMIAL_FUNC(legendre) (unsigned int n, POLYNOMIAL_TYPENAME* output){
+ POLYNOMIAL_TYPENAME prevpoly, tmppoly;
+ unsigned int i;
+ int j;
+ POLYNOMIAL_COEF_TYPE tmp;
+ POLYNOMIAL_ORDER_TYPE tmp_o;
+
+ if(n==0){
+ POLYNOMIAL_FUNC(init) (output, 1);
+ POLYNOMIAL_FUNC(add_monomial_dui) (1., 0, output);
+ return(0);
+ }
+ else if(n==1){
+ POLYNOMIAL_FUNC(init) (output, n);
+ POLYNOMIAL_FUNC(add_monomial_dui) (1., 1, output);
+ return(0);
+ }
+
+ #ifdef POLYNOMIAL_COEF_INIT
+ POLYNOMIAL_COEF_INIT(tmp);
+ #endif
+ #ifdef POLYNOMIAL_ORDER_INIT
+ POLYNOMIAL_ORDER_INIT(tmp_o);
+ #endif
+
+ // init: prevpoly=1
+ POLYNOMIAL_FUNC(init) (&prevpoly, n-1);
+ POLYNOMIAL_FUNC(add_monomial_dui) (1., 0, &prevpoly);
+ // init: output=x
+ POLYNOMIAL_FUNC(init) (output, n);
+ POLYNOMIAL_FUNC(add_monomial_dui) (1., 1, output);
+
+ // implement i*p_i=(2*i-1)*p_{i-1}-(i-1)*p_{i-2}
+ for(i=2;i<=n;i++){
+ // save current poly to copy it to prevpoly at the end of the loop
+ POLYNOMIAL_FUNC(cpy) (*output, &tmppoly);
+
+ // (2*i-1)/i*p_{i-1}
+ POLYNOMIAL_COEF_SET_UI(tmp, 2*i-1);
+ POLYNOMIAL_COEF_DIV_UI(tmp, tmp, i);
+ POLYNOMIAL_ORDER_SET_UI(tmp_o, 1);
+ POLYNOMIAL_FUNC(mul_monomial_inplace) (tmp, tmp_o, output);
+
+ // -(i-1)/i*p_{i-2}
+ // copy i to a signed int
+ j=i;
+ POLYNOMIAL_COEF_SET_SI(tmp, -j+1);
+ POLYNOMIAL_COEF_DIV_UI(tmp, tmp, i);
+ POLYNOMIAL_FUNC(mul_scalar_inplace) (tmp, &prevpoly);
+
+ // add it to p_n
+ POLYNOMIAL_FUNC(add_inplace) (prevpoly, output);
+
+ // replace prevpoly
+ POLYNOMIAL_FUNC(free) (prevpoly);
+ prevpoly=tmppoly;
+ }
+
+ POLYNOMIAL_FUNC(free) (prevpoly);
+ #ifdef POLYNOMIAL_COEF_FREE
+ POLYNOMIAL_COEF_FREE(tmp);
+ #endif
+ #ifdef POLYNOMIAL_ORDER_FREE
+ POLYNOMIAL_ORDER_FREE(tmp_o);
+ #endif
+
+ return(0);
+}
+
diff --git a/src/polynomial_base.h b/src/polynomial_base.h
new file mode 100644
index 0000000..3165a48
--- /dev/null
+++ b/src/polynomial_base.h
@@ -0,0 +1,67 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Base functions for real polynomials
+
+ see polynomial_*.h for the values taken by POLYNOMIAL_FUNC, etc...
+*/
+
+// init
+int POLYNOMIAL_FUNC(init) (POLYNOMIAL_TYPENAME* poly, unsigned int memory);
+int POLYNOMIAL_FUNC(free) (POLYNOMIAL_TYPENAME poly);
+
+// resize memory
+int POLYNOMIAL_FUNC(resize) (POLYNOMIAL_TYPENAME* poly, unsigned int newsize);
+
+// add a monomial
+int POLYNOMIAL_FUNC(add_monomial) (POLYNOMIAL_COEF_TYPE val, POLYNOMIAL_ORDER_TYPE order, POLYNOMIAL_TYPENAME* output);
+// from a double-valued coefficient and an unsigned int order
+int POLYNOMIAL_FUNC(add_monomial_dui) (double val, unsigned int order, POLYNOMIAL_TYPENAME* output);
+
+// copy
+int POLYNOMIAL_FUNC(cpy) (POLYNOMIAL_TYPENAME input, POLYNOMIAL_TYPENAME* output);
+int POLYNOMIAL_FUNC(cpy_noinit) (POLYNOMIAL_TYPENAME input, POLYNOMIAL_TYPENAME* output);
+
+// add
+int POLYNOMIAL_FUNC(add_inplace) (POLYNOMIAL_TYPENAME poly1, POLYNOMIAL_TYPENAME* poly2);
+int POLYNOMIAL_FUNC(add) (POLYNOMIAL_TYPENAME poly1, POLYNOMIAL_TYPENAME poly2, POLYNOMIAL_TYPENAME* output);
+
+// multiply by a scalar
+int POLYNOMIAL_FUNC(mul_scalar_inplace) (POLYNOMIAL_COEF_TYPE x, POLYNOMIAL_TYPENAME* poly);
+int POLYNOMIAL_FUNC(mul_scalar) (POLYNOMIAL_COEF_TYPE x, POLYNOMIAL_TYPENAME poly, POLYNOMIAL_TYPENAME* output);
+
+// multiply by a monomial
+int POLYNOMIAL_FUNC(mul_monomial_inplace) (POLYNOMIAL_COEF_TYPE x, POLYNOMIAL_ORDER_TYPE order, POLYNOMIAL_TYPENAME* poly);
+int POLYNOMIAL_FUNC(mul_monomial) (POLYNOMIAL_COEF_TYPE x, POLYNOMIAL_ORDER_TYPE order, POLYNOMIAL_TYPENAME poly, POLYNOMIAL_TYPENAME* output);
+
+// multiply two polynomials
+int POLYNOMIAL_FUNC(mul_inplace) (POLYNOMIAL_TYPENAME poly1, POLYNOMIAL_TYPENAME* poly2);
+int POLYNOMIAL_FUNC(mul) (POLYNOMIAL_TYPENAME poly1, POLYNOMIAL_TYPENAME poly2, POLYNOMIAL_TYPENAME* output);
+
+// derive
+int POLYNOMIAL_FUNC(derive_inplace) (POLYNOMIAL_TYPENAME* poly);
+int POLYNOMIAL_FUNC(derive) (POLYNOMIAL_TYPENAME poly, POLYNOMIAL_TYPENAME* output);
+
+// evaluate
+int POLYNOMIAL_FUNC(evaluate) (POLYNOMIAL_COEF_TYPE* out, POLYNOMIAL_COEF_TYPE x, POLYNOMIAL_TYPENAME poly);
+
+// print
+int POLYNOMIAL_FUNC(print) (POLYNOMIAL_TYPENAME poly);
+
+
+// n-th Legendre polynomial
+int POLYNOMIAL_FUNC(legendre) (unsigned int n, POLYNOMIAL_TYPENAME* output);
diff --git a/src/polynomial_double.h b/src/polynomial_double.h
new file mode 100644
index 0000000..f876119
--- /dev/null
+++ b/src/polynomial_double.h
@@ -0,0 +1,117 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Preprocessor macros for real polynomials with double coefficients and unsigned integer powers
+*/
+
+
+// reset CPP macros
+#undef POLYNOMIAL_TYPENAME
+#undef POLYNOMIAL_FUNC
+#undef POLYNOMIAL_COEF_TYPE
+#undef POLYNOMIAL_COEFSARRAY_TYPE
+#undef POLYNOMIAL_COEFSARRAY_FUNC
+#undef POLYNOMIAL_COEF_INIT
+#undef POLYNOMIAL_COEF_FREE
+#undef POLYNOMIAL_COEF_SET
+#undef POLYNOMIAL_COEF_SET_SI
+#undef POLYNOMIAL_COEF_SET_UI
+#undef POLYNOMIAL_COEF_CPY
+#undef POLYNOMIAL_COEF_CPY_D
+#undef POLYNOMIAL_COEF_ADD
+#undef POLYNOMIAL_COEF_ADD_D
+#undef POLYNOMIAL_COEF_MUL
+#undef POLYNOMIAL_COEF_MUL_ORDER
+#undef POLYNOMIAL_COEF_DIV_UI
+#undef POLYNOMIAL_COEF_POW_UI
+#undef POLYNOMIAL_COEF_PRINT
+#undef POLYNOMIAL_ORDER_TYPE
+#undef POLYNOMIAL_ORDERSARRAY_TYPE
+#undef POLYNOMIAL_ORDERSARRAY_FUNC
+#undef POLYNOMIAL_ORDER_INIT
+#undef POLYNOMIAL_ORDER_FREE
+#undef POLYNOMIAL_ORDER_SET
+#undef POLYNOMIAL_ORDER_SET_UI
+#undef POLYNOMIAL_ORDER_CPY
+#undef POLYNOMIAL_ORDER_CPY_UI
+#undef POLYNOMIAL_ORDER_ADD
+#undef POLYNOMIAL_ORDER_SUB_UI
+#undef POLYNOMIAL_ORDER_CMP
+#undef POLYNOMIAL_ORDER_CMP_UI
+#undef POLYNOMIAL_ORDER_PRINT
+
+// name of the polynomial type
+#define POLYNOMIAL_TYPENAME polynomial_double
+// prefix of function names
+#define POLYNOMIAL_FUNC(NAME) polynomial_double_ ## NAME
+
+// type of the coefficient
+#define POLYNOMIAL_COEF_TYPE double
+// type of coefficient arrays
+#define POLYNOMIAL_COEFSARRAY_TYPE array_double
+// prefix of coefficient array function names
+#define POLYNOMIAL_COEFSARRAY_FUNC(NAME) array_double_ ## NAME
+// set coefficient
+#define POLYNOMIAL_COEF_SET(COEF, VAL) COEF=VAL
+// set coefficient from signed int
+#define POLYNOMIAL_COEF_SET_SI(COEF, VAL) COEF=(double)VAL
+// set coefficient from unsigned int
+#define POLYNOMIAL_COEF_SET_UI(COEF, VAL) COEF=(double)VAL
+// copy coefficient
+#define POLYNOMIAL_COEF_CPY(VAL, COEF) COEF=VAL
+// copy coefficient from double
+#define POLYNOMIAL_COEF_CPY_D(VAL, COEF) COEF=VAL
+// add coefficients
+#define POLYNOMIAL_COEF_ADD(COEF, VAL1, VAL2) COEF=VAL1+VAL2
+// add coefficients, one of which is specified as a double
+#define POLYNOMIAL_COEF_ADD_D(COEF, VAL1, VAL2) COEF=VAL1+VAL2
+// multiply coefficients
+#define POLYNOMIAL_COEF_MUL(COEF, VAL1, VAL2) COEF=VAL1*VAL2
+// multiply coefficients, one of which is specified as a POLYNOMIAL_ORDER_TYPE
+#define POLYNOMIAL_COEF_MUL_ORDER(COEF, VAL1, VAL2) COEF=VAL1*(double)VAL2
+// divide coefficients, one of which is specified as an unsigned int
+#define POLYNOMIAL_COEF_DIV_UI(COEF, VAL1, VAL2) COEF=VAL1/(double)VAL2
+// power of a coefficient, specified as an unsigned int
+#define POLYNOMIAL_COEF_POW_UI(COEF, VAL1, VAL2) COEF=pow(VAL1, (double)VAL2)
+// print a coefficient
+#define POLYNOMIAL_COEF_PRINT(COEF) fprint_double(stdout, COEF)
+
+// type of the order
+#define POLYNOMIAL_ORDER_TYPE unsigned int
+// type of order arrays
+#define POLYNOMIAL_ORDERSARRAY_TYPE array_uint
+// prefix of order array function names
+#define POLYNOMIAL_ORDERSARRAY_FUNC(NAME) array_uint_ ## NAME
+// set order
+#define POLYNOMIAL_ORDER_SET(ORDER, VAL) ORDER=VAL
+// set order from unsigned int
+#define POLYNOMIAL_ORDER_SET_UI(ORDER, VAL) ORDER=VAL
+// copy order
+#define POLYNOMIAL_ORDER_CPY(VAL, ORDER) ORDER=VAL
+// copy order from unsigned int
+#define POLYNOMIAL_ORDER_CPY_UI(VAL, ORDER) ORDER=VAL
+// add orders
+#define POLYNOMIAL_ORDER_ADD(ORDER, VAL1, VAL2) ORDER=VAL1+VAL2
+// subtract an order and an unsigned integer
+#define POLYNOMIAL_ORDER_SUB_UI(ORDER, VAL1, VAL2) ORDER=VAL1-VAL2
+// compare orders (0 if equal, -1 if <, +1 if >)
+#define POLYNOMIAL_ORDER_CMP(VAL1, VAL2) (int)VAL1-(int)VAL2
+// compare orders, one of which is specified as an unsigned int (0 if equal, -1 if <, +1 if >)
+#define POLYNOMIAL_ORDER_CMP_UI(VAL1, VAL2) (int)VAL1-(int)VAL2
+// print orders
+#define POLYNOMIAL_ORDER_PRINT(ORDER) printf("%u",ORDER)
+
diff --git a/src/polynomial_ldouble.h b/src/polynomial_ldouble.h
new file mode 100644
index 0000000..54e5501
--- /dev/null
+++ b/src/polynomial_ldouble.h
@@ -0,0 +1,117 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Preprocessor macros for real polynomials with long double coefficients and unsigned integer powers
+*/
+
+
+// reset CPP macros
+#undef POLYNOMIAL_TYPENAME
+#undef POLYNOMIAL_FUNC
+#undef POLYNOMIAL_COEF_TYPE
+#undef POLYNOMIAL_COEFSARRAY_TYPE
+#undef POLYNOMIAL_COEFSARRAY_FUNC
+#undef POLYNOMIAL_COEF_INIT
+#undef POLYNOMIAL_COEF_FREE
+#undef POLYNOMIAL_COEF_SET
+#undef POLYNOMIAL_COEF_SET_SI
+#undef POLYNOMIAL_COEF_SET_UI
+#undef POLYNOMIAL_COEF_CPY
+#undef POLYNOMIAL_COEF_CPY_D
+#undef POLYNOMIAL_COEF_ADD
+#undef POLYNOMIAL_COEF_ADD_D
+#undef POLYNOMIAL_COEF_MUL
+#undef POLYNOMIAL_COEF_MUL_ORDER
+#undef POLYNOMIAL_COEF_DIV_UI
+#undef POLYNOMIAL_COEF_POW_UI
+#undef POLYNOMIAL_COEF_PRINT
+#undef POLYNOMIAL_ORDER_TYPE
+#undef POLYNOMIAL_ORDERSARRAY_TYPE
+#undef POLYNOMIAL_ORDERSARRAY_FUNC
+#undef POLYNOMIAL_ORDER_INIT
+#undef POLYNOMIAL_ORDER_FREE
+#undef POLYNOMIAL_ORDER_SET
+#undef POLYNOMIAL_ORDER_SET_UI
+#undef POLYNOMIAL_ORDER_CPY
+#undef POLYNOMIAL_ORDER_CPY_UI
+#undef POLYNOMIAL_ORDER_ADD
+#undef POLYNOMIAL_ORDER_SUB_UI
+#undef POLYNOMIAL_ORDER_CMP
+#undef POLYNOMIAL_ORDER_CMP_UI
+#undef POLYNOMIAL_ORDER_PRINT
+
+// name of the polynomial type
+#define POLYNOMIAL_TYPENAME polynomial_ldouble
+// prefix of function names
+#define POLYNOMIAL_FUNC(NAME) polynomial_ldouble_ ## NAME
+
+// type of the coefficient
+#define POLYNOMIAL_COEF_TYPE long double
+// type of coefficient arrays
+#define POLYNOMIAL_COEFSARRAY_TYPE array_ldouble
+// prefix of coefficient array function names
+#define POLYNOMIAL_COEFSARRAY_FUNC(NAME) array_ldouble_ ## NAME
+// set coefficient
+#define POLYNOMIAL_COEF_SET(COEF, VAL) COEF=VAL
+// set coefficient from signed int
+#define POLYNOMIAL_COEF_SET_SI(COEF, VAL) COEF=(long double)VAL
+// set coefficient from unsigned int
+#define POLYNOMIAL_COEF_SET_UI(COEF, VAL) COEF=(long double)VAL
+// copy coefficient
+#define POLYNOMIAL_COEF_CPY(VAL, COEF) COEF=VAL
+// copy coefficient from double
+#define POLYNOMIAL_COEF_CPY_D(VAL, COEF) COEF=(long double)VAL
+// add coefficients
+#define POLYNOMIAL_COEF_ADD(COEF, VAL1, VAL2) COEF=VAL1+VAL2
+// add coefficients, one of which is specified as a double
+#define POLYNOMIAL_COEF_ADD_D(COEF, VAL1, VAL2) COEF=VAL1+(long double)VAL2
+// multiply coefficients
+#define POLYNOMIAL_COEF_MUL(COEF, VAL1, VAL2) COEF=VAL1*VAL2
+// multiply coefficients, one of which is specified as a POLYNOMIAL_ORDER_TYPE
+#define POLYNOMIAL_COEF_MUL_ORDER(COEF, VAL1, VAL2) COEF=VAL1*(long double)VAL2
+// divide coefficients, one of which is specified as an unsigned int
+#define POLYNOMIAL_COEF_DIV_UI(COEF, VAL1, VAL2) COEF=VAL1/(long double)VAL2
+// power of a coefficient, specified as an unsigned int
+#define POLYNOMIAL_COEF_POW_UI(COEF, VAL1, VAL2) COEF=powl(VAL1, (long double)VAL2)
+// print a coefficient
+#define POLYNOMIAL_COEF_PRINT(COEF) fprint_ldouble(stdout, COEF)
+
+// type of the order
+#define POLYNOMIAL_ORDER_TYPE unsigned int
+// type of order arrays
+#define POLYNOMIAL_ORDERSARRAY_TYPE array_uint
+// prefix of order array function names
+#define POLYNOMIAL_ORDERSARRAY_FUNC(NAME) array_uint_ ## NAME
+// set order
+#define POLYNOMIAL_ORDER_SET(ORDER, VAL) ORDER=VAL
+// set order from unsigned int
+#define POLYNOMIAL_ORDER_SET_UI(ORDER, VAL) ORDER=VAL
+// copy order
+#define POLYNOMIAL_ORDER_CPY(VAL, ORDER) ORDER=VAL
+// copy order from unsigned int
+#define POLYNOMIAL_ORDER_CPY_UI(VAL, ORDER) ORDER=VAL
+// add orders
+#define POLYNOMIAL_ORDER_ADD(ORDER, VAL1, VAL2) ORDER=VAL1+VAL2
+// subtract an order and an unsigned integer
+#define POLYNOMIAL_ORDER_SUB_UI(ORDER, VAL1, VAL2) ORDER=VAL1-VAL2
+// compare orders (0 if equal, -1 if <, +1 if >)
+#define POLYNOMIAL_ORDER_CMP(VAL1, VAL2) (int)VAL1-(int)VAL2
+// compare orders, one of which is specified as an unsigned int (0 if equal, -1 if <, +1 if >)
+#define POLYNOMIAL_ORDER_CMP_UI(VAL1, VAL2) (int)VAL1-(int)VAL2
+// print orders
+#define POLYNOMIAL_ORDER_PRINT(ORDER) printf("%u",ORDER)
+
diff --git a/src/polynomial_mpfr.h b/src/polynomial_mpfr.h
new file mode 100644
index 0000000..f8bc983
--- /dev/null
+++ b/src/polynomial_mpfr.h
@@ -0,0 +1,121 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Preprocessor macros for real polynomials with multi-precision float (mpfr) coefficients and unsigned integer powers
+*/
+
+
+// reset CPP macros
+#undef POLYNOMIAL_TYPENAME
+#undef POLYNOMIAL_FUNC
+#undef POLYNOMIAL_COEF_TYPE
+#undef POLYNOMIAL_COEFSARRAY_TYPE
+#undef POLYNOMIAL_COEFSARRAY_FUNC
+#undef POLYNOMIAL_COEF_INIT
+#undef POLYNOMIAL_COEF_FREE
+#undef POLYNOMIAL_COEF_SET
+#undef POLYNOMIAL_COEF_SET_SI
+#undef POLYNOMIAL_COEF_SET_UI
+#undef POLYNOMIAL_COEF_CPY
+#undef POLYNOMIAL_COEF_CPY_D
+#undef POLYNOMIAL_COEF_ADD
+#undef POLYNOMIAL_COEF_ADD_D
+#undef POLYNOMIAL_COEF_MUL
+#undef POLYNOMIAL_COEF_MUL_ORDER
+#undef POLYNOMIAL_COEF_DIV_UI
+#undef POLYNOMIAL_COEF_POW_UI
+#undef POLYNOMIAL_COEF_PRINT
+#undef POLYNOMIAL_ORDER_TYPE
+#undef POLYNOMIAL_ORDERSARRAY_TYPE
+#undef POLYNOMIAL_ORDERSARRAY_FUNC
+#undef POLYNOMIAL_ORDER_INIT
+#undef POLYNOMIAL_ORDER_FREE
+#undef POLYNOMIAL_ORDER_SET
+#undef POLYNOMIAL_ORDER_SET_UI
+#undef POLYNOMIAL_ORDER_CPY
+#undef POLYNOMIAL_ORDER_CPY_UI
+#undef POLYNOMIAL_ORDER_ADD
+#undef POLYNOMIAL_ORDER_SUB_UI
+#undef POLYNOMIAL_ORDER_CMP
+#undef POLYNOMIAL_ORDER_CMP_UI
+#undef POLYNOMIAL_ORDER_PRINT
+
+// name of the polynomial type
+#define POLYNOMIAL_TYPENAME polynomial_mpfr
+// prefix of function names
+#define POLYNOMIAL_FUNC(NAME) polynomial_mpfr_ ## NAME
+
+// type of the coefficient
+#define POLYNOMIAL_COEF_TYPE mpfr_t
+// type of coefficient arrays
+#define POLYNOMIAL_COEFSARRAY_TYPE array_mpfr
+// prefix of coefficient array function names
+#define POLYNOMIAL_COEFSARRAY_FUNC(NAME) array_mpfr_ ## NAME
+// init coefficient
+#define POLYNOMIAL_COEF_INIT(VAR) mpfr_init(VAR)
+// free coefficient
+#define POLYNOMIAL_COEF_FREE(VAR) mpfr_clear(VAR)
+// set coefficient
+#define POLYNOMIAL_COEF_SET(COEF, VAL) COEF[0]=VAL[0]
+// set coefficient from signed int
+#define POLYNOMIAL_COEF_SET_SI(COEF, VAL) mpfr_set_si(COEF, VAL, MPFR_RNDN)
+// set coefficient from unsigned int
+#define POLYNOMIAL_COEF_SET_UI(COEF, VAL) mpfr_set_ui(COEF, VAL, MPFR_RNDN)
+// copy coefficient
+#define POLYNOMIAL_COEF_CPY(VAL, COEF) mpfr_init(COEF); mpfr_set(COEF, VAL, MPFR_RNDN)
+// copy coefficient from double
+#define POLYNOMIAL_COEF_CPY_D(VAL, COEF) mpfr_init(COEF); mpfr_set_d(COEF, VAL, MPFR_RNDN)
+// add coefficients
+#define POLYNOMIAL_COEF_ADD(COEF, VAL1, VAL2) mpfr_add(COEF, VAL1, VAL2, MPFR_RNDN)
+// add coefficients, one of which is specified as a double
+#define POLYNOMIAL_COEF_ADD_D(COEF, VAL1, VAL2) mpfr_add_d(COEF, VAL1, VAL2, MPFR_RNDN)
+// multiply coefficients
+#define POLYNOMIAL_COEF_MUL(COEF, VAL1, VAL2) mpfr_mul(COEF, VAL1, VAL2, MPFR_RNDN)
+// multiply coefficients, one of which is specified as a POLYNOMIAL_ORDER_TYPE
+#define POLYNOMIAL_COEF_MUL_ORDER(COEF, VAL1, VAL2) mpfr_mul_ui(COEF, VAL1, VAL2, MPFR_RNDN)
+// divide coefficients, one of which is specified as an unsigned int
+#define POLYNOMIAL_COEF_DIV_UI(COEF, VAL1, VAL2) mpfr_div_ui(COEF, VAL1, VAL2, MPFR_RNDN)
+// power of a coefficient, specified as an unsigned int
+#define POLYNOMIAL_COEF_POW_UI(COEF, VAL1, VAL2) mpfr_pow_ui(COEF, VAL1, VAL2, MPFR_RNDN)
+// print a coefficient
+#define POLYNOMIAL_COEF_PRINT(COEF) fprint_mpfr(stdout, COEF)
+
+// type of the order
+#define POLYNOMIAL_ORDER_TYPE unsigned int
+// type of order arrays
+#define POLYNOMIAL_ORDERSARRAY_TYPE array_uint
+// prefix of order array function names
+#define POLYNOMIAL_ORDERSARRAY_FUNC(NAME) array_uint_ ## NAME
+// set order
+#define POLYNOMIAL_ORDER_SET(ORDER, VAL) ORDER=VAL
+// set order from unsigned int
+#define POLYNOMIAL_ORDER_SET_UI(ORDER, VAL) ORDER=VAL
+// copy order
+#define POLYNOMIAL_ORDER_CPY(VAL, ORDER) ORDER=VAL
+// copy order from unsigned int
+#define POLYNOMIAL_ORDER_CPY_UI(VAL, ORDER) ORDER=VAL
+// add orders
+#define POLYNOMIAL_ORDER_ADD(ORDER, VAL1, VAL2) ORDER=VAL1+VAL2
+// subtract an order and an unsigned integer
+#define POLYNOMIAL_ORDER_SUB_UI(ORDER, VAL1, VAL2) ORDER=VAL1-VAL2
+// compare orders (0 if equal, -1 if <, +1 if >)
+#define POLYNOMIAL_ORDER_CMP(VAL1, VAL2) (int)VAL1-(int)VAL2
+// compare orders, one of which is specified as an unsigned int (0 if equal, -1 if <, +1 if >)
+#define POLYNOMIAL_ORDER_CMP_UI(VAL1, VAL2) (int)VAL1-(int)VAL2
+// print orders
+#define POLYNOMIAL_ORDER_PRINT(ORDER) printf("%u",ORDER)
+
diff --git a/src/polynomial_type.h b/src/polynomial_type.h
new file mode 100644
index 0000000..3361d67
--- /dev/null
+++ b/src/polynomial_type.h
@@ -0,0 +1,27 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Structure definition for real polynomials
+
+ see polynomial_*.h for the values taken by POLYNOMIAL_TYPENAME, etc...
+*/
+
+typedef struct POLYNOMIAL_TYPENAME {
+ POLYNOMIAL_COEFSARRAY_TYPE coefficients;
+ POLYNOMIAL_ORDERSARRAY_TYPE orders;
+} POLYNOMIAL_TYPENAME;
+
diff --git a/src/root.c b/src/root.c
new file mode 100644
index 0000000..c79745f
--- /dev/null
+++ b/src/root.c
@@ -0,0 +1,51 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "root.h"
+
+#include <mpfr.h>
+#include <math.h>
+#include "errors.h"
+
+
+//--------------------------------------------------
+//
+// using doubles
+//
+//--------------------------------------------------
+
+#include "root_double.h"
+#include "root_base.c"
+
+
+//--------------------------------------------------
+//
+// using long doubles
+//
+//--------------------------------------------------
+
+#include "root_ldouble.h"
+#include "root_base.c"
+
+
+//--------------------------------------------------
+//
+// using mpfr floats
+//
+//--------------------------------------------------
+
+#include "root_mpfr.h"
+#include "root_base.c"
diff --git a/src/root.h b/src/root.h
new file mode 100644
index 0000000..7106389
--- /dev/null
+++ b/src/root.h
@@ -0,0 +1,57 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Root finding
+*/
+
+#ifndef LIBINUM_ROOT_H
+#define LIBINUM_ROOT_H
+
+#include "types.h"
+
+
+//--------------------------------------------------
+//
+// using doubles
+//
+//--------------------------------------------------
+
+#include "root_double.h"
+#include "root_base.h"
+
+
+//--------------------------------------------------
+//
+// using long doubles
+//
+//--------------------------------------------------
+
+#include "root_ldouble.h"
+#include "root_base.h"
+
+
+//--------------------------------------------------
+//
+// using mpfr floats
+//
+//--------------------------------------------------
+
+#include "root_mpfr.h"
+#include "root_base.h"
+
+#endif
+
diff --git a/src/root_base.c b/src/root_base.c
new file mode 100644
index 0000000..b13d9db
--- /dev/null
+++ b/src/root_base.c
@@ -0,0 +1,134 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Base functions for root finding
+
+ see integral_*.h for the values taken by ROOT_FUNC, etc...
+*/
+
+
+// compute the root of a real function of 1 variable using the Newton method
+int ROOT_FUNC(root_newton_inplace) (ROOT_FLOAT_TYPE* out, int (*func)(ROOT_FLOAT_TYPE*, ROOT_FLOAT_TYPE, void*), int (*deriv_func)(ROOT_FLOAT_TYPE*, ROOT_FLOAT_TYPE, void*), ROOT_FLOAT_TYPE tolerance, unsigned int maxiter, void* extra_args){
+ unsigned int count=0;
+ ROOT_FLOAT_TYPE valf, valdf, delta, tmp;
+ int ret;
+
+ #ifdef ROOT_FLOAT_INIT
+ ROOT_FLOAT_INIT(valf);
+ ROOT_FLOAT_INIT(valdf);
+ ROOT_FLOAT_INIT(delta);
+ ROOT_FLOAT_INIT(tmp);
+ #endif
+
+ // evaluate at guess
+ ret=(*func)(&valf, *out, extra_args);
+ if(ret<0){
+ #ifdef ROOT_FLOAT_FREE
+ ROOT_FLOAT_FREE(valf);
+ ROOT_FLOAT_FREE(valdf);
+ ROOT_FLOAT_FREE(delta);
+ ROOT_FLOAT_FREE(tmp);
+ #endif
+ return(ret);
+ }
+ // check that valf is a number
+ if(! ROOT_FLOAT_ISNUMBER(valf)){
+ #ifdef ROOT_FLOAT_FREE
+ ROOT_FLOAT_FREE(valf);
+ ROOT_FLOAT_FREE(valdf);
+ ROOT_FLOAT_FREE(delta);
+ ROOT_FLOAT_FREE(tmp);
+ #endif
+ return(LIBINUM_ERROR_NAN);
+ }
+
+ ROOT_FLOAT_ABS(delta, valf);
+
+ // loop until tolerance is reached
+ while(ROOT_FLOAT_CMP(delta, tolerance) > 0 && count < maxiter){
+ // new guess
+ (*deriv_func)(&valdf, *out, extra_args);
+ if(ret<0){
+ #ifdef ROOT_FLOAT_FREE
+ ROOT_FLOAT_FREE(valf);
+ ROOT_FLOAT_FREE(valdf);
+ ROOT_FLOAT_FREE(delta);
+ ROOT_FLOAT_FREE(tmp);
+ #endif
+ return(ret);
+ }
+ // check that valdf is a number that is not 0
+ if(! ROOT_FLOAT_ISNUMBER(valdf) || ROOT_FLOAT_ISZERO(valdf)){
+ #ifdef ROOT_FLOAT_FREE
+ ROOT_FLOAT_FREE(valf);
+ ROOT_FLOAT_FREE(valdf);
+ ROOT_FLOAT_FREE(delta);
+ ROOT_FLOAT_FREE(tmp);
+ #endif
+ return(LIBINUM_ERROR_NAN);
+ }
+
+ ROOT_FLOAT_DIV(tmp, valf, valdf);
+ ROOT_FLOAT_SUB(*out, *out, tmp);
+
+ // evaluate at new guess
+ (*func)(&valf, *out, extra_args);
+ if(ret<0){
+ #ifdef ROOT_FLOAT_FREE
+ ROOT_FLOAT_FREE(valf);
+ ROOT_FLOAT_FREE(valdf);
+ ROOT_FLOAT_FREE(delta);
+ ROOT_FLOAT_FREE(tmp);
+ #endif
+ return(ret);
+ }
+ // check that valf is a number
+ if(! ROOT_FLOAT_ISNUMBER(valf)){
+ #ifdef ROOT_FLOAT_FREE
+ ROOT_FLOAT_FREE(valf);
+ ROOT_FLOAT_FREE(valdf);
+ ROOT_FLOAT_FREE(delta);
+ ROOT_FLOAT_FREE(tmp);
+ #endif
+ return(LIBINUM_ERROR_NAN);
+ }
+
+ ROOT_FLOAT_ABS(delta, valf);
+
+ // increase counter
+ count++;
+ }
+
+ // free variables
+ #ifdef ROOT_FLOAT_FREE
+ ROOT_FLOAT_FREE(valf);
+ ROOT_FLOAT_FREE(valdf);
+ ROOT_FLOAT_FREE(delta);
+ ROOT_FLOAT_FREE(tmp);
+ #endif
+
+ // fail if maxiter was reached
+ if(count==maxiter){
+ return(LIBINUM_ERROR_MAXITER);
+ }
+ return(0);
+}
+int ROOT_FUNC(root_newton) (ROOT_FLOAT_TYPE* out, int (*func)(ROOT_FLOAT_TYPE*, ROOT_FLOAT_TYPE, void*), int (*deriv_func)(ROOT_FLOAT_TYPE*, ROOT_FLOAT_TYPE, void*), ROOT_FLOAT_TYPE init, ROOT_FLOAT_TYPE tolerance, unsigned int maxiter, void* extra_args){
+ ROOT_FLOAT_SET(*out, init);
+ ROOT_FUNC(root_newton_inplace) (out, func, deriv_func, tolerance, maxiter, extra_args);
+ return(0);
+}
diff --git a/src/root_base.h b/src/root_base.h
new file mode 100644
index 0000000..7a69616
--- /dev/null
+++ b/src/root_base.h
@@ -0,0 +1,27 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Base functions for root finding
+
+ see integral_*.h for the values taken by ROOT_FUNC, etc...
+*/
+
+
+// compute the root of a real function of 1 variable using the Newton method
+int ROOT_FUNC(root_newton_inplace) (ROOT_FLOAT_TYPE* out, int (*func)(ROOT_FLOAT_TYPE*, ROOT_FLOAT_TYPE, void*), int (*deriv_func)(ROOT_FLOAT_TYPE*, ROOT_FLOAT_TYPE, void*), ROOT_FLOAT_TYPE tolerance, unsigned int maxiter, void* extra_args);
+int ROOT_FUNC(root_newton) (ROOT_FLOAT_TYPE* out, int (*func)(ROOT_FLOAT_TYPE*, ROOT_FLOAT_TYPE, void*), int (*deriv_func)(ROOT_FLOAT_TYPE*, ROOT_FLOAT_TYPE, void*), ROOT_FLOAT_TYPE init, ROOT_FLOAT_TYPE tolerance, unsigned int maxiter, void* extra_args);
+
diff --git a/src/root_double.h b/src/root_double.h
new file mode 100644
index 0000000..f564998
--- /dev/null
+++ b/src/root_double.h
@@ -0,0 +1,55 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Preprocessor macros for root finding using doubles
+*/
+
+
+// reset CPP macros
+#undef ROOT_FUNC
+#undef ROOT_FLOAT_TYPE
+#undef ROOT_FLOAT_INIT
+#undef ROOT_FLOAT_FREE
+#undef ROOT_FLOAT_SET
+#undef ROOT_FLOAT_SUB
+#undef ROOT_FLOAT_DIV
+#undef ROOT_FLOAT_CMP
+#undef ROOT_FLOAT_ABS
+#undef ROOT_FLOAT_ISNUMBER
+#undef ROOT_FLOAT_ISZERO
+
+
+// suffix of function names
+#define ROOT_FUNC(NAME) NAME ## _double
+
+// type of floats
+#define ROOT_FLOAT_TYPE double
+// set float
+#define ROOT_FLOAT_SET(FLOAT, VAL) FLOAT=VAL
+// subtract floats
+#define ROOT_FLOAT_SUB(FLOAT, VAL1, VAL2) FLOAT=VAL1-VAL2
+// divide floats
+#define ROOT_FLOAT_DIV(FLOAT, VAL1, VAL2) FLOAT=VAL1/VAL2
+// compare floats (0 if equal, -1 if <, +1 if >)
+#define ROOT_FLOAT_CMP(VAL1, VAL2) VAL1-VAL2
+// abs of float
+#define ROOT_FLOAT_ABS(FLOAT, VAL) FLOAT=fabs(VAL)
+// check whether a float is a regular number
+#define ROOT_FLOAT_ISNUMBER(FLOAT) (fpclassify(FLOAT)>=FP_ZERO)
+// whether float is 0
+#define ROOT_FLOAT_ISZERO(VAL) (VAL==0.)
+
diff --git a/src/root_ldouble.h b/src/root_ldouble.h
new file mode 100644
index 0000000..a20643b
--- /dev/null
+++ b/src/root_ldouble.h
@@ -0,0 +1,55 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Preprocessor macros for root finding using long doubles
+*/
+
+
+// reset CPP macros
+#undef ROOT_FUNC
+#undef ROOT_FLOAT_TYPE
+#undef ROOT_FLOAT_INIT
+#undef ROOT_FLOAT_FREE
+#undef ROOT_FLOAT_SET
+#undef ROOT_FLOAT_SUB
+#undef ROOT_FLOAT_DIV
+#undef ROOT_FLOAT_CMP
+#undef ROOT_FLOAT_ABS
+#undef ROOT_FLOAT_ISNUMBER
+#undef ROOT_FLOAT_ISZERO
+
+
+// suffix of function names
+#define ROOT_FUNC(NAME) NAME ## _ldouble
+
+// type of floats
+#define ROOT_FLOAT_TYPE long double
+// set float
+#define ROOT_FLOAT_SET(FLOAT, VAL) FLOAT=VAL
+// subtract floats
+#define ROOT_FLOAT_SUB(FLOAT, VAL1, VAL2) FLOAT=VAL1-VAL2
+// divide floats
+#define ROOT_FLOAT_DIV(FLOAT, VAL1, VAL2) FLOAT=VAL1/VAL2
+// compare floats (0 if equal, -1 if <, +1 if >)
+#define ROOT_FLOAT_CMP(VAL1, VAL2) VAL1-VAL2
+// abs of float
+#define ROOT_FLOAT_ABS(FLOAT, VAL) FLOAT=fabsl(VAL)
+// check whether a float is a regular number
+#define ROOT_FLOAT_ISNUMBER(FLOAT) (fpclassify(FLOAT)>=FP_ZERO)
+// whether float is 0
+#define ROOT_FLOAT_ISZERO(VAL) (VAL==0.)
+
diff --git a/src/root_mpfr.h b/src/root_mpfr.h
new file mode 100644
index 0000000..6535e0b
--- /dev/null
+++ b/src/root_mpfr.h
@@ -0,0 +1,59 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Preprocessor macros for root finding using multi-precision floats (mpfr)
+*/
+
+
+// reset CPP macros
+#undef ROOT_FUNC
+#undef ROOT_FLOAT_TYPE
+#undef ROOT_FLOAT_INIT
+#undef ROOT_FLOAT_FREE
+#undef ROOT_FLOAT_SET
+#undef ROOT_FLOAT_SUB
+#undef ROOT_FLOAT_DIV
+#undef ROOT_FLOAT_CMP
+#undef ROOT_FLOAT_ABS
+#undef ROOT_FLOAT_ISNUMBER
+#undef ROOT_FLOAT_ISZERO
+
+
+// suffix of function names
+#define ROOT_FUNC(NAME) NAME ## _mpfr
+
+// type of floats
+#define ROOT_FLOAT_TYPE mpfr_t
+// init float
+#define ROOT_FLOAT_INIT(VAR) mpfr_init(VAR)
+// free float
+#define ROOT_FLOAT_FREE(VAR) mpfr_clear(VAR)
+// set float
+#define ROOT_FLOAT_SET(FLOAT, VAL) mpfr_set(FLOAT, VAL, MPFR_RNDN)
+// subtract floats
+#define ROOT_FLOAT_SUB(FLOAT, VAL1, VAL2) mpfr_sub(FLOAT, VAL1, VAL2, MPFR_RNDN)
+// divide floats
+#define ROOT_FLOAT_DIV(FLOAT, VAL1, VAL2) mpfr_div(FLOAT, VAL1, VAL2, MPFR_RNDN)
+// compare floats (0 if equal, -1 if <, +1 if >)
+#define ROOT_FLOAT_CMP(VAL1, VAL2) mpfr_cmp(VAL1, VAL2)
+// abs of float
+#define ROOT_FLOAT_ABS(FLOAT, VAL) mpfr_abs(FLOAT, VAL, MPFR_RNDN)
+// check whether a float is a regular number
+#define ROOT_FLOAT_ISNUMBER(FLOAT) mpfr_number_p(FLOAT)!=0
+// whether float is 0
+#define ROOT_FLOAT_ISZERO(VAL) mpfr_zero_p(VAL)!=0
+
diff --git a/src/types.h b/src/types.h
new file mode 100644
index 0000000..e438133
--- /dev/null
+++ b/src/types.h
@@ -0,0 +1,84 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Types and structures
+*/
+
+#ifndef LIBINUM_TYPES_H
+#define LIBINUM_TYPES_H
+
+#include <mpfr.h>
+#include <pthread.h>
+
+// arrays
+#include "array_int.h"
+#include "array_type.h"
+
+#include "array_uint.h"
+#include "array_type.h"
+
+#include "array_double.h"
+#include "array_type.h"
+
+#include "array_ldouble.h"
+#include "array_type.h"
+
+#include "array_mpfr.h"
+#include "array_type.h"
+
+#include "array_2_mpfr.h"
+#include "array_type.h"
+
+#include "array_char.h"
+#include "array_type.h"
+
+#include "array_str.h"
+#include "array_type.h"
+
+#include "array_pthread_t.h"
+#include "array_type.h"
+
+
+// 1-variable polynomial
+#include "polynomial_mpfr.h"
+#include "polynomial_type.h"
+
+#include "polynomial_double.h"
+#include "polynomial_type.h"
+
+#include "polynomial_ldouble.h"
+#include "polynomial_type.h"
+
+// polynomial array
+#include "array_polynomial_mpfr.h"
+#include "array_type.h"
+
+#include "array_polynomial_double.h"
+#include "array_type.h"
+
+#include "array_polynomial_ldouble.h"
+#include "array_type.h"
+
+
+// multivariable polynomials
+#include "polynomialMV_mpz.h"
+#include "polynomialMV_type.h"
+
+#include "polynomialMV_int.h"
+#include "polynomialMV_type.h"
+
+#endif
diff --git a/src/utils.c b/src/utils.c
new file mode 100644
index 0000000..d1fad7e
--- /dev/null
+++ b/src/utils.c
@@ -0,0 +1,79 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+#include "utils.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+// define MPFR_USE_FILE to enable the use of mpfr_printf
+#define MPFR_USE_FILE
+#include <mpfr.h>
+#include <math.h>
+#include "array.h"
+
+// stringify macros
+#define STR(S) XSTR(S)
+#define XSTR(S) #S
+
+// print a double at maximal precision
+int fprint_double(FILE* file, double x){
+ fprintf(file, "% ." STR(__DBL_DIG__) "le",x);
+ return(0);
+}
+
+// print a long double at maximal precision
+int fprint_ldouble(FILE* file, long double x){
+ fprintf(file, "% ." STR(__LDBL_DIG__) "Le",x);
+ return(0);
+}
+
+// log10(2)
+#define LOG2 0.3010299956639812
+// print an mpfr at maximal precision
+int fprint_mpfr(FILE* file, mpfr_t x){
+ // the printf format
+ array_char printf_format;
+ array_char_init(&printf_format,12);
+ array_char_snprintf(&printf_format,"%% .%dRe\0", (int)((mpfr_get_default_prec()-1)*LOG2));
+ mpfr_fprintf(file, printf_format.values, x);
+ array_char_free(printf_format);
+ return(0);
+}
+
+
+// print information about data types
+int print_datatype_info(FILE* file){
+
+ fprintf(file, " int8_t = " STR(__INT8_TYPE__) "\n");
+ fprintf(file, " int16_t = " STR(__INT16_TYPE__) "\n");
+ fprintf(file, " int32_t = " STR(__INT32_TYPE__) "\n");
+ fprintf(file, " int64_t = " STR(__INT64_TYPE__) "\n");
+
+ fprintf(file, "\n");
+
+ fprintf(file, " double: precision: " STR(__DBL_MANT_DIG__) ", emax: " STR(__DBL_MAX_EXP__) ", emin: " STR(__DBL_MIN_EXP__) "\n");
+ fprintf(file, "long double: precision: " STR(__LDBL_MANT_DIG__) ", emax: " STR(__LDBL_MAX_EXP__) ", emin: " STR(__LDBL_MIN_EXP__) "\n");
+
+ fprintf(file, "\n");
+
+ #if _MPFR_PREC_FORMAT == 2
+ fprintf(file, "mpfr precision and emax: int\n");
+ #elif _MPFR_PREC_FORMAT == 3
+ fprintf(file, "mpfr precision and emax: long int\n");
+ #endif
+
+ return(0);
+}
diff --git a/src/utils.h b/src/utils.h
new file mode 100644
index 0000000..c3954b4
--- /dev/null
+++ b/src/utils.h
@@ -0,0 +1,36 @@
+/*
+Copyright 2016 Ian Jauslin
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+/*
+ Useful functions
+*/
+
+#ifndef LIBINUM_UTILS_H
+#define LIBINUM_UTILS_H
+
+#include <mpfr.h>
+#include <stdio.h>
+
+// print a double at maximal precision
+int fprint_double(FILE* file, double x);
+// print a long double at maximal precision
+int fprint_ldouble(FILE* file, long double x);
+// print an mpfr at maximal precision
+int fprint_mpfr(FILE* file, mpfr_t x);
+
+// print information about data types
+int print_datatype_info();
+#endif