diff --git a/Changelog b/Changelog index 0cf1bbb..2fed1bf 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,9 @@ +1.4: + * Support MPFR floats in numkondo. + + * Remove '-D' option (error tolerance) in numkondo. + + 1.3.1: * '-C' flag in meantools-derive: diff --git a/INSTALL b/INSTALL index 9594767..cac075d 100644 --- a/INSTALL +++ b/INSTALL @@ -6,6 +6,8 @@ * meankondo should work on any POSIX compliant system, such as GNU/Linux or OSX. +* meankondo is linked against the GNU MPFR and GNU GMP libraries. + * Compiling: Run make 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. + 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/Makefile b/Makefile index 19fc350..d0cd377 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ # if static=1 then link libkondo statically but other libraries dynamically STATIC=1 -VERSION=1.3.1 +VERSION=1.4 # products of the compilation PROJECT_BINS= meankondo numkondo meantools kondo_preprocess meantools-convert @@ -62,9 +62,9 @@ SRCDIR=./src OBJDIR=./objs # objects -LIBKONDO_OBJS = $(addprefix $(OBJDIR)/,array.o cli_parser.o coefficient.o fields.o grouped_polynomial.o idtable.o istring.o number.o parse_file.o polynomial.o rational_float.o rational_int.o rcc.o tools.o) +LIBKONDO_OBJS = $(addprefix $(OBJDIR)/,array.o cli_parser.o coefficient.o fields.o grouped_polynomial.o idtable.o istring.o number.o parse_file.o polynomial.o rational_float.o rational_int.o rcc.o rcc_mpfr.o tools.o) MEANKONDO_OBJS = $(addprefix $(OBJDIR)/,meankondo.o mean.o) -NUMKONDO_OBJS = $(addprefix $(OBJDIR)/,numkondo.o flow.o) +NUMKONDO_OBJS = $(addprefix $(OBJDIR)/,numkondo.o flow.o flow_mpfr.o) MEANTOOLS_OBJS = $(addprefix $(OBJDIR)/,meantools.o meantools_exp.o meantools_deriv.o meantools_eval.o) KONDO_PP_OBJS = $(addprefix $(OBJDIR)/,kondo_preprocess.o kondo.o) @@ -78,8 +78,8 @@ XTRA_LIBS= ifeq ($(STATIC),1) # compile libkondo.a PREREQ=static - # libkondo is linked against libm - XTRA_LIBS=-lm + # libkondo is linked against libm, libmpfr and libgmp + XTRA_LIBS=-lm -lmpfr -lgmp # link binaries using the static library LIBKONDO_FLAG=-l:libkondo.a # install static lib @@ -87,8 +87,8 @@ ifeq ($(STATIC),1) else ifeq ($(STATIC),2) # compile libkondo.a PREREQ=static - # libkondo is linked against libm - XTRA_LIBS=-lm + # libkondo is linked against libm, libmpfr and libgmp + XTRA_LIBS=-lm -lmpfr -lgmp # link binaries statically override LDFLAGS += -static INSTALLLIB=install-static @@ -119,17 +119,17 @@ libkondo.a: $(LIBKONDO_OBJS) $(AR) -rc $(BUILDDIR)/lib/$@ $^ libkondo.so.$(VERSION): $(LIBKONDO_OBJS) - $(LD) -shared -lm $(LDFLAGS) -o $(BUILDDIR)/lib/$@ $^ + $(LD) -shared -lm -lmpfr -lgmp $(LDFLAGS) -o $(BUILDDIR)/lib/$@ $^ ln -fs ./libkondo.so.$(VERSION) $(BUILDDIR)/lib/libkondo.so meankondo: $(MEANKONDO_OBJS) $(LD) -L$(BUILDDIR)/lib $(LDFLAGS) -o $(BUILDDIR)/bin/$@ $^ $(LIBKONDO_FLAG) -lpthread $(XTRA_LIBS) numkondo: $(NUMKONDO_OBJS) - $(LD) -L$(BUILDDIR)/lib $(LDFLAGS) -o $(BUILDDIR)/bin/$@ $^ $(LIBKONDO_FLAG) -lm $(XTRA_LIBS) + $(LD) -L$(BUILDDIR)/lib $(LDFLAGS) -o $(BUILDDIR)/bin/$@ $^ $(LIBKONDO_FLAG) -lm -lmpfr -lgmp $(XTRA_LIBS) meantools: $(MEANTOOLS_OBJS) - $(LD) -L$(BUILDDIR)/lib $(LDFLAGS) -o $(BUILDDIR)/bin/$@ $^ $(LIBKONDO_FLAG) $(XTRA_LIBS) + $(LD) -L$(BUILDDIR)/lib $(LDFLAGS) -o $(BUILDDIR)/bin/$@ $^ $(LIBKONDO_FLAG) -lmpfr -lgmp $(XTRA_LIBS) meantools-convert: cp scripts/meantools-convert $(BUILDDIR)/bin/ diff --git a/NOTICE b/NOTICE index 1469df9..6380709 100644 --- a/NOTICE +++ b/NOTICE @@ -1,2 +1,15 @@ meankondo Copyright 2015 Ian Jauslin + +The numerical values can 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/meankondo-doc.html b/doc/meankondo-doc.html index c4a7e2a..7074b56 100644 --- a/doc/meankondo-doc.html +++ b/doc/meankondo-doc.html @@ -69,10 +69,10 @@ -

meankondo v1.3

+

meankondo v1.4

- This is the official documentation for meankondo, version 1.3. The aim of this document is not to give a technical description of how to use the various programs bundled with meankondo, nor is it to explain where hierarchical models come from and what their meaning is, but rather a conceptual overview of how meankondo approaches the computation of flow equations, and how its programs can be made to interact with one another to compute various quantities. For a more technical description, see the man pages included with the meankondo source code. For a more theoretical discussion of Fermionic hierarchical models, see [G.Benfatto, G.Gallavotti, I.Jauslin, 2015]. + This is the official documentation for meankondo, version 1.4. The aim of this document is not to give a technical description of how to use the various programs bundled with meankondo, nor is it to explain where hierarchical models come from and what their meaning is, but rather a conceptual overview of how meankondo approaches the computation of flow equations, and how its programs can be made to interact with one another to compute various quantities. For a more technical description, see the man pages included with the meankondo source code. For a more theoretical discussion of Fermionic hierarchical models, see [G.Benfatto, G.Gallavotti, I.Jauslin, 2015].

Table of contents

@@ -150,7 +150,7 @@
  • external: which are organized in pairs, and are denoted by \((\Psi_i^+,\Psi_i^-)\) for \(i\in\{1,\cdots,E\}\).
  • super-external: which denoted by \(H_i\) for \(i\in\{1,\cdots,X\}\) (the only difference with external fields is that super-external fields are not in pairs, which is a seemingly innocuous difference; but super-external fields are meant to be used for different purposes as external fields (see Definition below)). - The fields are used as a basis for a complex algebra, so that we can take products and linear combinations of fields (in other words, the concept of polynomials over the fields is well defined). Some of the fields (Fermions) anti-commute with each other (two fields \(a\) and \(b\) are said to anti-commute if \(ab\equiv-ba\)), and the rest (Bosons) commute. Which fields are Fermions and which are Bosons is specified in the #!fields entry in the configuration file. (Warning: As of version 1.3, all internal fields must be Fermions.) + The fields are used as a basis for a complex algebra, so that we can take products and linear combinations of fields (in other words, the concept of polynomials over the fields is well defined). Some of the fields (Fermions) anti-commute with each other (two fields \(a\) and \(b\) are said to anti-commute if \(ab\equiv-ba\)), and the rest (Bosons) commute. Which fields are Fermions and which are Bosons is specified in the #!fields entry in the configuration file. (Warning: As of version 1.4, all internal fields must be Fermions.)

    In the configuration file of the meankondo program, the fields are specified in the #!fields entry. @@ -286,7 +286,15 @@ Numerical evaluations are not exact. The numbers manipulated meankondo are double precision floating point numbers ("doubles" for short), which are also system-dependent. On systems that follow the IEEE 754 standard, doubles have a precision of 53 bits, which implies they are accurate to 15 decimal places; and the absolute value of doubles is bounded above by \(2^{1024}-2^{1024-53}\) (that is the number whose binary expansion has \(1023\) digits and whose \(53\) left-most digits are \(1\) whereas the others are \(0\)) and below by \(2^{-1022}\).

    -->

    - Numerical evaluations are not exact. The numbers manipulated meankondo are "long doubles", which, when compiled for x86 processors, have a precision of 64 bits, which implies they are accurate to 19 decimal places; and the absolute value of doubles is bounded above by \(2^{16384}-2^{16384-64}\) (that is the number whose binary expansion has \(16383\) digits and whose \(64\) left-most digits are \(1\) whereas the others are \(0\)) and below by \(2^{-16382}\). + Numerical evaluations are not exact. The numbers manipulated meankondo are either "long doubles" or "MPFR floats", depending on the options passed to numkondo (see man numkondo). +

    diff --git a/man/kondo_preprocess.1 b/man/kondo_preprocess.1 index 99712b1..1e22cae 100644 --- a/man/kondo_preprocess.1 +++ b/man/kondo_preprocess.1 @@ -1,5 +1,5 @@ -.Dd $Mdocdate: April 14 2015 $ -.Dt kondo_preprocess 1.3.1 +.Dd $Mdocdate: September 22 2015 $ +.Dt kondo_preprocess 1.4 .Os .Sh NAME .Nm kondo_preprocess diff --git a/man/meankondo.1 b/man/meankondo.1 index 865659c..599be08 100644 --- a/man/meankondo.1 +++ b/man/meankondo.1 @@ -1,5 +1,5 @@ -.Dd $Mdocdate: April 13 2015 $ -.Dt meankondo 1.3.1 +.Dd $Mdocdate: September 22 2015 $ +.Dt meankondo 1.4 .Os .Sh NAME .Nm meankondo diff --git a/man/meantools-convert.1 b/man/meantools-convert.1 index f73f3ce..8393b28 100644 --- a/man/meantools-convert.1 +++ b/man/meantools-convert.1 @@ -1,5 +1,5 @@ -.Dd $Mdocdate: June 12 2015 $ -.Dt meantools-convert 1.3.1 +.Dd $Mdocdate: September 22 2015 $ +.Dt meantools-convert 1.4 .Os .Sh NAME .Nm meantools-convert diff --git a/man/meantools.1 b/man/meantools.1 index e361123..c4c73c6 100644 --- a/man/meantools.1 +++ b/man/meantools.1 @@ -1,5 +1,5 @@ -.Dd $Mdocdate: April 14 2015 $ -.Dt meantools 1.3.1 +.Dd $Mdocdate: September 22 2015 $ +.Dt meantools 1.4 .Os .Sh NAME .Nm meantools @@ -19,6 +19,8 @@ .Nm .Sy eval .Op Fl R Ar values +.Op Fl P Ar precision +.Op Fl E Ar max_exponent .Op Ar config_file .Pp .Sh DESCRIPTION @@ -136,6 +138,12 @@ The values of the rccs with which to evaluate the flow equation. .Ar values is formatted like an initial_condition (see .Sx numkondo Ns (1) ) . +.It Fl P Ar precision +Number of bits used for the significand of numerical values (see +.Sx numkondo Ns (1) ) . +.It Fl E Ar max_exponent +Largest allowed value for the exponent of numerical values (see +.Sx numkondo Ns (1) ) . .El .Pp .Sy Configuration file: diff --git a/man/numkondo.1 b/man/numkondo.1 index e7b4807..3af84df 100644 --- a/man/numkondo.1 +++ b/man/numkondo.1 @@ -1,5 +1,5 @@ -.Dd $Mdocdate: April 14 2015 $ -.Dt numkondo 1.3.1 +.Dd $Mdocdate: September 22 2015 $ +.Dt numkondo 1.4 .Os .Sh NAME .Nm numkondo @@ -8,8 +8,9 @@ .Nm .Op Fl F .Op Fl N Ar niter -.Op Fl D Ar tolerance .Op Fl I Ar initial_condition +.Op Fl P Ar precision +.Op Fl E Ar max_exponent .Op Ar config_file .Pp .Nm @@ -44,12 +45,12 @@ as well as the following pre-processors, which generate configuration files for Number of iterations .It Fl F Only print the last step of the computation, with full precision. The output can be used as an initial condition for further iterations. -.It Fl D Ar tolerance -If this option is provided, any number smaller than -.Ar tolerance -is set to 0. .It Fl I Ar initial_condition Set the initial condition from the command-line (overrides the initial condition in the configuration file). The format is the same as the '#!initial_configuration' entry, see below. +.It Fl P Ar precision +Number of bits used for the significand of numerical values (see the NUMERICAL PRECISION section). If this option is specified, then numerical values are represented as MPFR floats instead of long doubles, which requires more computating time. +.It Fl E Ar max_exponent +Largest allowed value for the exponent of numerical values (see the NUMERICAL PRECISION section). If this option is specified, then numerical values are represented as MPFR floats instead of long doubles, which requires more computating time. .It Fl v Print version information and exit. .El @@ -145,6 +146,19 @@ If the '-F' flag is provided, .Nm prints the last step of the iteration to stdout in a format that can be re-used as an initial condition for subsequent iterations. .Pp +.Sh NUMERICAL PRECISION +Numerical values are represented as floating point numbers, which consist in a significand (or mantissa) and an exponent. The number is given by +.D1 significand * 2^exponent +.Pp +If neither the '-P' nor the '-E' flags are specified, then numerical values are implemented using the 'long double' type, which allocates 64 bits to the significand and 15 to the exponent (this may change depending on the implementation of the C compiler used to compile +.Nm ) . +Numbers are therefore accurate to 19 decimal places, and the exponent must be in the interval [-16382 , 16383]. +.Pp +If one of the '-P' or '-E' flags are specified, then numerical values are implemented using the GNU MPFR library. The number of bits allocated to the significand and exponent can be set by the '-P' and '-E' flags, within the limits set by the MPFR library. These values depend on the implementation of the library. On 64-bit systems, the maximal precision and maximal value of the exponent should be of the order of 2^63 and 2^62 respectively. +.Pp +Note that using MPFR floats increases the computing time required to run +.Nm +.Pp .Sh RETURN CODE .Nm returns 0 on success and -1 on error. diff --git a/src/coefficient.c b/src/coefficient.c index c26b668..d4cb6eb 100644 --- a/src/coefficient.c +++ b/src/coefficient.c @@ -18,6 +18,10 @@ limitations under the License. #include #include +#include +// define MPFR_USE_VA_LIST to enable the use of mpfr_inits and mpfr_clears +#define MPFR_USE_VA_LIST +#include #include "definitions.cpp" #include "rational.h" #include "istring.h" @@ -721,7 +725,7 @@ int evalcoef(RCC rccs, Coefficient coef, long double* out){ int i,j; long double num_factor; - *out=0; + *out=0.; // for each monomial for(i=0;i0){ + mpfr_pow_si(y, rccs.values[intlist_find_err(rccs.indices,rccs.length,coef.denoms[i].index)], coef.denoms[i].power, MPFR_RNDN); + mpfr_div(x, num_factor, y, MPFR_RNDN); + mpfr_set(num_factor, x, MPFR_RNDN); + } + + number_mpfr_val(Z, coef.nums[i]); + mpfr_mul(x, num_factor, Z, MPFR_RNDN); + mpfr_add(y, x, out, MPFR_RNDN); + mpfr_set(out, y, MPFR_RNDN); + mpfr_clear(Z); + } + + // free numbers + mpfr_clears(num_factor, x, y, (mpfr_ptr)NULL); + + return(0); +} diff --git a/src/coefficient.h b/src/coefficient.h index a7a151c..43dd313 100644 --- a/src/coefficient.h +++ b/src/coefficient.h @@ -74,5 +74,7 @@ int coef_denom_cmp(coef_denom denom1, coef_denom denom2); // evaluate a coefficient on a vector int evalcoef(RCC rccs, Coefficient coef, long double* out); +// evaluate a coefficient on a vector (using mpfr floats) +int evalcoef_mpfr(RCC_mpfr rccs, Coefficient coef, mpfr_t out); #endif diff --git a/src/definitions.cpp b/src/definitions.cpp index 25715e5..30f021f 100644 --- a/src/definitions.cpp +++ b/src/definitions.cpp @@ -17,7 +17,7 @@ limitations under the License. #ifndef DEFINITIONS_GCC #define DEFINITIONS_GCC -#define VERSION "1.3.1" +#define VERSION "1.4" // number of entries in a configuration file #define ARG_COUNT 10 diff --git a/src/flow.c b/src/flow.c index d271e44..b294bb0 100644 --- a/src/flow.c +++ b/src/flow.c @@ -24,13 +24,11 @@ limitations under the License. #include "number.h" #include "array.h" #include "coefficient.h" - +#include "rcc.h" // compute flow numerically, no exponentials -// inputs: flow_equation -// init, niter, tol (the allowed error at each step), ls (whether to display the results in terms of ls), display_mode (what to print) -int numerical_flow(Grouped_Polynomial flow_equation, RCC init, Labels labels, int niter, long double tol, int display_mode){ +int numerical_flow(Grouped_Polynomial flow_equation, RCC init, Labels labels, int niter, int display_mode){ // running coupling contants RCC rccs=init; int i,j; @@ -53,7 +51,7 @@ int numerical_flow(Grouped_Polynomial flow_equation, RCC init, Labels labels, in for(i=0;i=0){ evalcoef(*rccs, flow_equation.coefs[i], new_rccs+i); - // if the new rcc is too small, then ignore it - if(fabs(new_rccs[i]) +#include +#include +// define MPFR_USE_VA_LIST to enable the use of mpfr_inits and mpfr_clears +#define MPFR_USE_VA_LIST +// define MPFR_USE_FILE to enable the use of mpfr_printf +#define MPFR_USE_FILE +#include +#include "tools.h" +#include "math.h" +#include "definitions.cpp" +#include "number.h" +#include "array.h" +#include "coefficient.h" +#include "flow.h" +#include "rcc_mpfr.h" + + + +// compute flow numerically +int numerical_flow_mpfr(Grouped_Polynomial flow_equation, RCC_mpfr init, Labels labels, int niter, int display_mode){ + // running coupling contants + RCC_mpfr rccs=init; + int i,j; + + if(display_mode==DISPLAY_NUMERICAL){ + // print labels + printf("%5s ","n"); + for(j=0;j=0){ + evalcoef_mpfr(*rccs, flow_equation.coefs[i], res[i]); + } + } + + // set new rccs + for(i=0;i\n meantools derive [-d derivatives] -V \n meantools eval -R \n\n"); + printf("\nusage:\n meantools exp [config_file]\n meantools derive [-d derivatives] [-V variables] [-C] [config_file]\n meantools eval [-R values] [-P precision] [-E max_exponent] [config_file]\n\n"); return(0); } diff --git a/src/meantools_eval.c b/src/meantools_eval.c index 50fff5b..4f166cd 100644 --- a/src/meantools_eval.c +++ b/src/meantools_eval.c @@ -18,16 +18,22 @@ limitations under the License. #include #include +#include #include "parse_file.h" #include "cli_parser.h" #include "grouped_polynomial.h" #include "array.h" #include "rcc.h" +#include "rcc_mpfr.h" #define CP_FLAG_RCCS 1 +#define CP_FLAG_MPFR_PREC 2 +#define CP_FLAG_MPFR_EXP 3 // read command line arguments int tool_eval_read_args(int argc, const char* argv[], Str_Array* str_args, Meantools_Options* opts){ + // temporary long int + long int tmp_lint; // file to read the polynomial from in flow mode const char* file=""; // whether a file was specified on the command-line @@ -40,6 +46,9 @@ int tool_eval_read_args(int argc, const char* argv[], Str_Array* str_args, Meant // defaults // mark rccstring so that it can be recognized whether it has been set or not (*opts).eval_rccstring.length=-1; + // no mpfr + (*opts).mpfr_prec=0; + (*opts).mpfr_emax=0; // loop over arguments for(i=2;i #include #include +#include +// define MPFR_USE_VA_LIST to enable the use of mpfr_inits and mpfr_clears +#define MPFR_USE_VA_LIST +#include #include "istring.h" #include "definitions.cpp" #include "tools.h" @@ -358,6 +362,30 @@ long double number_double_val(Number x){ } return(ret); } +// approximate numerical expression (as mpfr float) +int number_mpfr_val(mpfr_t out, Number x){ + int i; + // auxiliary variables (do not initialize A) + mpfr_t A,b,c; + mpfr_inits(b,c, (mpfr_ptr)NULL); + + mpfr_init(out); + mpfr_set_zero(out,1); + + for(i=0;i\n\n"); + printf("\nusage:\n numkondo [-F] [-N niter] [-I initial_condition] [-P precision] [-E exponent_range] \n\n"); return(0); } @@ -171,8 +188,22 @@ int numflow(Str_Array str_args, Numkondo_Options opts){ Labels labels; // initial condition RCC init_cd; + RCC_mpfr init_cd_mpfr; // flow equation Grouped_Polynomial flow_equation; + // whether or not to use mpfr floats + int mpfr_flag=0; + + // set mpfr defaults + if(opts.mpfr_prec!=0){ + mpfr_set_default_prec(opts.mpfr_prec); + mpfr_flag=1; + } + if(opts.mpfr_emax!=0){ + mpfr_set_emax(opts.mpfr_emax); + mpfr_flag=1; + } + // parse id table arg_index=find_str_arg("labels", str_args); @@ -207,20 +238,31 @@ int numflow(Str_Array str_args, Numkondo_Options opts){ } } // initialize the rccs - prepare_init(flow_equation.indices,flow_equation.length,&init_cd); + if(mpfr_flag==0){ + prepare_init(flow_equation.indices,flow_equation.length,&init_cd); + } + else{ + prepare_init_mpfr(flow_equation.indices,flow_equation.length,&init_cd_mpfr); + } + // read rccs from string if(opts.eval_rccstring.length!=-1){ - parse_init_cd(opts.eval_rccstring, &init_cd); + parse_init_cd(opts.eval_rccstring, &init_cd, &init_cd_mpfr, mpfr_flag); free_Char_Array(opts.eval_rccstring); } - numerical_flow(flow_equation, init_cd, labels, opts.niter, opts.tol, opts.display_mode); + if(mpfr_flag==0){ + numerical_flow(flow_equation, init_cd, labels, opts.niter, opts.display_mode); + free_RCC(init_cd); + } + else{ + numerical_flow_mpfr(flow_equation, init_cd_mpfr, labels, opts.niter, opts.display_mode); + free_RCC_mpfr(init_cd_mpfr); + } - free_RCC(init_cd); // free memory free_Labels(labels); free_Grouped_Polynomial(flow_equation); return(0); } - diff --git a/src/parse_file.c b/src/parse_file.c index 19b91c6..ae3a9af 100644 --- a/src/parse_file.c +++ b/src/parse_file.c @@ -18,12 +18,14 @@ limitations under the License. #include #include +#include #include "array.h" #include "fields.h" #include "rational.h" #include "number.h" #include "polynomial.h" #include "rcc.h" +#include "rcc_mpfr.h" #include "definitions.cpp" #include "istring.h" #include "tools.h" @@ -716,8 +718,8 @@ int parse_labels(Char_Array str_labels, Labels* labels){ } -// read initial condition for numerical computation -int parse_init_cd(Char_Array init_cd, RCC* init){ +// read initial condition for numerical computation (using either RCC or RCC_mpfr, as specified by mpfr_flag) +int parse_init_cd(Char_Array init_cd, RCC* init, RCC_mpfr* init_mpfr, int mpfr_flag){ char* buffer=calloc(init_cd.length+1,sizeof(char)); char* buffer_ptr=buffer; int index=0; @@ -738,7 +740,12 @@ int parse_init_cd(Char_Array init_cd, RCC* init){ // new term case ',': // write init - sscanf(buffer,"%Lf",(*init).values+intlist_find_err((*init).indices,(*init).length,index)); + if(mpfr_flag==0){ + sscanf(buffer,"%Lf",(*init).values+intlist_find_err((*init).indices,(*init).length,index)); + } + else{ + mpfr_strtofr((*init_mpfr).values[intlist_find_err((*init_mpfr).indices,(*init_mpfr).length,index)], buffer, &buffer_ptr, 10, MPFR_RNDN); + } // reset buffer buffer_ptr=buffer; *buffer_ptr='\0'; @@ -782,7 +789,12 @@ int parse_init_cd(Char_Array init_cd, RCC* init){ } // write init - sscanf(buffer,"%Lf",(*init).values+unlist_find((*init).indices,(*init).length,index)); + if(mpfr_flag==0){ + sscanf(buffer,"%Lf",(*init).values+intlist_find_err((*init).indices,(*init).length,index)); + } + else{ + mpfr_strtofr((*init_mpfr).values[intlist_find_err((*init_mpfr).indices,(*init_mpfr).length,index)], buffer, &buffer_ptr, 10, MPFR_RNDN); + } free(buffer); return(0); @@ -806,3 +818,20 @@ int prepare_init(int* indices, int length, RCC* init){ } return(0); } +// set indices and length of init for RCC_mpfr +int prepare_init_mpfr(int* indices, int length, RCC_mpfr* init){ + int i; + init_RCC_mpfr(init, length); + for(i=0;i-DOFFSET){ + mpfr_set_ui((*init).values[i],1,MPFR_RNDN); + } + else{ + mpfr_set_zero((*init).values[i],1); + } + + } + return(0); +} diff --git a/src/parse_file.h b/src/parse_file.h index b51103a..0430763 100644 --- a/src/parse_file.h +++ b/src/parse_file.h @@ -47,10 +47,12 @@ int parse_input_id_table(Char_Array str_idtable, Id_Table* idtable, Fields_Table // parse a list of labels int parse_labels(Char_Array str_labels, Labels* labels); -// parse the initial condition -int parse_init_cd(Char_Array init_cd, RCC* init); +// read initial condition for numerical computation (using either RCC or RCC_mpfr, as specified by mpfr_flag) +int parse_init_cd(Char_Array init_cd, RCC* init, RCC_mpfr* init_mpfr, int mpfr_flag); // set indices and length of init int prepare_init(int* indices, int length, RCC* init); +// set indices and length of init for RCC_mpfr +int prepare_init_mpfr(int* indices, int length, RCC_mpfr* init); #endif diff --git a/src/rational_float.c b/src/rational_float.c index eebc4f4..d6a6a4c 100644 --- a/src/rational_float.c +++ b/src/rational_float.c @@ -19,21 +19,14 @@ limitations under the License. #include "rational_float.h" #include #include +#include +// define MPFR_USE_VA_LIST to enable the use of mpfr_inits and mpfr_clears +#define MPFR_USE_VA_LIST +#include #include "istring.h" #include "array.h" #include "math.h" -Q quot(long double p, long double q){ - Q ret; - if(q==0){ - fprintf(stderr,"error: %Lf/%Lf is ill defined\n",p,q); - exit(-1); - } - ret.numerator=p; - ret.denominator=q; - return(ret); -} - // add Q Q_add(Q x1,Q x2){ Q ret; @@ -141,6 +134,16 @@ long double lcm(long double x,long double y){ double Q_double_value(Q q){ return(1.0*q.numerator/q.denominator); } +// approximate value as mpfr float +int Q_mpfr_value(mpfr_t out, Q q){ + mpfr_t x; + mpfr_init(out); + mpfr_init(x); + mpfr_set_ld(x, q.denominator, MPFR_RNDN); + mpfr_ld_div(out, q.numerator, x, MPFR_RNDN); + mpfr_clear(x); + return(0); +} // print to string diff --git a/src/rational_float.h b/src/rational_float.h index 931b5ec..02c4a22 100644 --- a/src/rational_float.h +++ b/src/rational_float.h @@ -54,6 +54,8 @@ long double lcm(long double x,long double y); // approximate value as double double Q_double_value(Q q); +// approximate value as mpfr float +int Q_mpfr_value(mpfr_t out, Q q); // print to string int Q_sprint(Q num, Char_Array* out); diff --git a/src/rational_int.c b/src/rational_int.c index ec601a8..7aab561 100644 --- a/src/rational_int.c +++ b/src/rational_int.c @@ -19,6 +19,10 @@ limitations under the License. #include "rational_int.h" #include #include +#include +// define MPFR_USE_VA_LIST to enable the use of mpfr_inits and mpfr_clears +#define MPFR_USE_VA_LIST +#include #include "istring.h" #include "array.h" @@ -135,6 +139,16 @@ long int lcm(long int x,long int y){ double Q_double_value(Q q){ return(1.0*q.numerator/q.denominator); } +// approximate value as mpfr float +int Q_mpfr_value(mpfr_t out, Q q){ + mpfr_t x; + mpfr_init(out); + mpfr_init(x); + mpfr_set_si(x, q.denominator, MPFR_RNDN); + mpfr_si_div(out, q.numerator, x, MPFR_RNDN); + mpfr_clear(x); + return(0); +} // print to string diff --git a/src/rational_int.h b/src/rational_int.h index a9f164d..a4dd000 100644 --- a/src/rational_int.h +++ b/src/rational_int.h @@ -49,6 +49,8 @@ long int lcm(long int x,long int y); // approximate value as double double Q_double_value(Q q); +// approximate value as mpfr float +int Q_mpfr_value(mpfr_t out, Q q); // print to string int Q_sprint(Q num, Char_Array* out); diff --git a/src/rcc_mpfr.c b/src/rcc_mpfr.c new file mode 100644 index 0000000..8a362e3 --- /dev/null +++ b/src/rcc_mpfr.c @@ -0,0 +1,124 @@ +/* +Copyright 2015 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 "rcc_mpfr.h" +#include +#include +#include +// define MPFR_USE_VA_LIST to enable the use of mpfr_inits and mpfr_clears +#define MPFR_USE_VA_LIST +// define MPFR_USE_FILE to enable the use of mpfr_printf +#define MPFR_USE_FILE +#include +#include +#include "array.h" + +// init +int init_RCC_mpfr(RCC_mpfr* rcc_mpfr, int size){ + int i; + (*rcc_mpfr).values=calloc(size,sizeof(mpfr_t)); + (*rcc_mpfr).indices=calloc(size,sizeof(int)); + (*rcc_mpfr).length=size; + for(i=0;i + // rational number typedef struct Q{ @@ -114,6 +116,12 @@ typedef struct RCC{ int* indices; int length; } RCC; +// rcc using mpfr floats +typedef struct RCC_mpfr{ + mpfr_t* values; + int* indices; + int length; +} RCC_mpfr; // identities between fields typedef struct Identities{ @@ -174,25 +182,6 @@ typedef struct Id_Table{ int memory; } Id_Table; -/* -// polynomial scalar and vectors -typedef struct Polynomial_Scalar{ - Coefficient coef; - int* indices; - int length; -} Polynomial_Scalar; -typedef struct Polynomial_Vector{ - Coefficient* coefv; - int* indices; - int length; -} Polynomial_Vector; -typedef struct Polynomial_Matrix{ - Coefficient** coefm; - int* indices; - int length; -} Polynomial_Matrix; -*/ - // command line options typedef struct Meankondo_Options{ @@ -203,8 +192,9 @@ typedef struct Meankondo_Options{ typedef struct Numkondo_Options{ int display_mode; int niter; - long double tol; Char_Array eval_rccstring; + mpfr_prec_t mpfr_prec; + mpfr_exp_t mpfr_emax; } Numkondo_Options; typedef struct Meantools_Options{ @@ -213,6 +203,8 @@ typedef struct Meantools_Options{ Int_Array deriv_vars; Char_Array eval_rccstring; int chain; + mpfr_prec_t mpfr_prec; + mpfr_exp_t mpfr_emax; } Meantools_Options; typedef struct Kondopp_Options{