Support MPFR floats in numkondo

Remove '-D' option (error tolerance) in numkondo
This commit is contained in:
Ian Jauslin 2015-10-07 12:51:41 +00:00
parent e7aa6859f0
commit 469bdc8071
34 changed files with 890 additions and 120 deletions

View File

@ -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:

View File

@ -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

165
LGPL3 Normal file
View File

@ -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.

View File

@ -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/

13
NOTICE
View File

@ -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.

View File

@ -69,10 +69,10 @@
</head>
<body>
<h1 style="margin-bottom:50pt;">meankondo <span style="margin-left:10pt;font-size:18pt">v1.3</span></h1>
<h1 style="margin-bottom:50pt;">meankondo <span style="margin-left:10pt;font-size:18pt">v1.4</span></h1>
<p>
This is the official documentation for <b>meankondo</b>, version 1.3. The aim of this document is not to give a technical description of how to use the various programs bundled with <b>meankondo</b>, nor is it to explain where hierarchical models come from and what their meaning is, but rather a conceptual overview of how <b>meankondo</b> 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 <b>meankondo</b> source code. For a more theoretical discussion of Fermionic hierarchical models, see <a href="http://ian.jauslin.org/publications/15bgj">[G.Benfatto, G.Gallavotti, I.Jauslin, 2015]</a>.
This is the official documentation for <b>meankondo</b>, version 1.4. The aim of this document is not to give a technical description of how to use the various programs bundled with <b>meankondo</b>, nor is it to explain where hierarchical models come from and what their meaning is, but rather a conceptual overview of how <b>meankondo</b> 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 <b>meankondo</b> source code. For a more theoretical discussion of Fermionic hierarchical models, see <a href="http://ian.jauslin.org/publications/15bgj">[G.Benfatto, G.Gallavotti, I.Jauslin, 2015]</a>.
</p>
<h2 style="margin-top:50pt;">Table of contents</h2>
@ -150,7 +150,7 @@
<li><b>external</b>: which are organized in pairs, and are denoted by \((\Psi_i^+,\Psi_i^-)\) for \(i\in\{1,\cdots,E\}\).
<li><b>super-external</b>: 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 <a href="#flow_equation_definition">Definition</a> below)).
</ul>
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 <i>polynomials over the fields</i> is well defined). Some of the fields (<i>Fermions</i>) anti-commute with each other (two fields \(a\) and \(b\) are said to anti-commute if \(ab\equiv-ba\)), and the rest (<i>Bosons</i>) commute. Which fields are Fermions and which are Bosons is specified in the <code>#!fields</code> entry in the configuration file. <b>(Warning: As of version 1.3, all internal fields must be Fermions.)</b>
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 <i>polynomials over the fields</i> is well defined). Some of the fields (<i>Fermions</i>) anti-commute with each other (two fields \(a\) and \(b\) are said to anti-commute if \(ab\equiv-ba\)), and the rest (<i>Bosons</i>) commute. Which fields are Fermions and which are Bosons is specified in the <code>#!fields</code> entry in the configuration file. <b>(Warning: As of version 1.4, all internal fields must be Fermions.)</b>
</p>
<p>
In the configuration file of the <b>meankondo</b> program, the fields are specified in the <code>#!fields</code> entry.
@ -286,7 +286,15 @@
Numerical evaluations are not exact. The numbers manipulated <b>meankondo</b> 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}\).
</p>-->
<p>
Numerical evaluations are not exact. The numbers manipulated <b>meankondo</b> 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 <b>meankondo</b> are either "long doubles" or "MPFR floats", depending on the options passed to <b>numkondo</b> (see <code>man numkondo</code>).
<ul>
<li>
Long doubles: 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}\).
</li>
<li>
MPFR floats: the precision and size of the exponent can be specified as options on the command line. The maximal precision and maximal value of the exponent are, on 64 bit systems, \(2^{63}\) bits and \(2^{62}\) respectively.
</li>
</ul>
</p>

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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.

View File

@ -18,6 +18,10 @@ limitations under the License.
#include <stdio.h>
#include <stdlib.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 "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;i<coef.length;i++){
@ -737,3 +741,44 @@ int evalcoef(RCC rccs, Coefficient coef, long double* out){
}
return(0);
}
// evaluate a coefficient on a vector (using mpfr floats)
int evalcoef_mpfr(RCC_mpfr rccs, Coefficient coef, mpfr_t out){
int i,j;
mpfr_t num_factor;
// tmp number (do not initialize Z)
mpfr_t x, y, Z;
// init numbers
mpfr_inits(num_factor, x, y, (mpfr_ptr) NULL);
mpfr_init(out);
mpfr_set_zero(out, 1);
// for each monomial
for(i=0;i<coef.length;i++){
// product of factors
mpfr_set_flt(num_factor, 1., MPFR_RNDN);
for(j=0;j<coef.factors[i].length;j++){
mpfr_mul(x,num_factor,rccs.values[intlist_find_err(rccs.indices,rccs.length,coef.factors[i].values[j])], MPFR_RNDN);
mpfr_set(num_factor,x, MPFR_RNDN);
}
// denominator
if(coef.denoms[i].power>0){
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);
}

View File

@ -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

View File

@ -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

View File

@ -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<niter;i++){
// compute a single step
step_flow(&rccs, flow_equation, tol);
step_flow(&rccs, flow_equation);
// convert ls to alphas
if(display_mode==DISPLAY_NUMERICAL){
// print the result
@ -83,14 +81,9 @@ int numerical_flow(Grouped_Polynomial flow_equation, RCC init, Labels labels, in
}
// single step in the flow no exponentials
// inputs: flow_equation, tol
// input/outputs: rccs
int step_flow(RCC* rccs, Grouped_Polynomial flow_equation, long double tol){
int step_flow(RCC* rccs, Grouped_Polynomial flow_equation){
int i;
long double* new_rccs=calloc((*rccs).length,sizeof(long double));
Int_Array computed;
init_Int_Array(&computed, (*rccs).length);
// initialize vectors to 0
for(i=0;i<(*rccs).length;i++){
@ -101,10 +94,6 @@ int step_flow(RCC* rccs, Grouped_Polynomial flow_equation, long double tol){
for(i=0;i<flow_equation.length;i++){
if(flow_equation.indices[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])<tol){
new_rccs[i]=0.;
}
(*rccs).values[i]=new_rccs[i];
}
}
@ -113,10 +102,6 @@ int step_flow(RCC* rccs, Grouped_Polynomial flow_equation, long double tol){
for(i=0;i<flow_equation.length;i++){
if(flow_equation.indices[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])<tol){
new_rccs[i]=0.;
}
}
}
@ -126,7 +111,6 @@ int step_flow(RCC* rccs, Grouped_Polynomial flow_equation, long double tol){
}
// free memory
free_Int_Array(computed);
free(new_rccs);
return(0);
}

View File

@ -21,14 +21,12 @@ Compute flow numerically
#ifndef NUMERICAL_FLOW_H
#define NUMERICAL_FLOW_H
#include "grouped_polynomial.h"
#include "rcc.h"
#include "types.h"
// compute flow
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);
// single step
int step_flow(RCC* rccs, Grouped_Polynomial flow_equation, long double tol);
int step_flow(RCC* rccs, Grouped_Polynomial flow_equation);
// print the label of an rcc (takes constants and derivatives into account)
int print_label(int index, Labels labels);

128
src/flow_mpfr.c Normal file
View File

@ -0,0 +1,128 @@
/*
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 "flow_mpfr.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
// 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 <mpfr.h>
#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<rccs.length;j++){
print_label(rccs.indices[j], labels);
}
printf("\n\n");
// print initial values
printf("%5d ",0);
for(j=0;j<rccs.length;j++){
mpfr_printf("% 14.7Re ",rccs.values[j]);
}
printf("\n");
}
for(i=0;i<niter;i++){
// compute a single step
step_flow_mpfr(&rccs, flow_equation);
// convert ls to alphas
if(display_mode==DISPLAY_NUMERICAL){
// print the result
printf("%5d ",i+1);
for(j=0;j<rccs.length;j++){
mpfr_printf("% 14.7Re ",rccs.values[j]);
}
printf("\n");
}
}
if(display_mode==DISPLAY_NUMERICAL){
// print labels
printf("\n");
printf("%5s ","n");
for(j=0;j<rccs.length;j++){
print_label(rccs.indices[j], labels);
}
printf("\n\n");
}
if(display_mode==DISPLAY_FINAL){
RCC_mpfr_print(rccs);
}
return(0);
}
// single step in the flow
int step_flow_mpfr(RCC_mpfr* rccs, Grouped_Polynomial flow_equation){
int i;
mpfr_t* res;
// security: this function assumes that the length of the rcc and the flow_equation are the same
if((*rccs).length!=flow_equation.length){
fprintf(stderr,"error: mismatch in the size of the flow equation and the rccs");
exit(-1);
}
res=calloc((*rccs).length,sizeof(mpfr_t));
// compute the constants first
for(i=0;i<flow_equation.length;i++){
if(flow_equation.indices[i]<0){
evalcoef_mpfr(*rccs, flow_equation.coefs[i], res[i]);
mpfr_set((*rccs).values[i], res[i], MPFR_RNDN);
}
}
// for each equation
for(i=0;i<flow_equation.length;i++){
if(flow_equation.indices[i]>=0){
evalcoef_mpfr(*rccs, flow_equation.coefs[i], res[i]);
}
}
// set new rccs
for(i=0;i<flow_equation.length;i++){
mpfr_set((*rccs).values[i], res[i], MPFR_RNDN);
mpfr_clear(res[i]);
}
// free memory
free(res);
return(0);
}

32
src/flow_mpfr.h Normal file
View File

@ -0,0 +1,32 @@
/*
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.
*/
/*
Compute flow numerically
*/
#ifndef NUMERICAL_FLOW_MPFR_H
#define NUMERICAL_FLOW_MPFR_H
#include "types.h"
// compute flow
int numerical_flow_mpfr(Grouped_Polynomial flow_equation, RCC_mpfr init, Labels labels, int niter, int display_mode);
// single step
int step_flow_mpfr(RCC_mpfr* rccs, Grouped_Polynomial flow_equation);
#endif

View File

@ -732,7 +732,7 @@ int char_array_to_Grouped_Polynomial(Char_Array str, Grouped_Polynomial* output)
}
// evaluate an equation on a vector
// eValuate an equation on a vector
int evaleq(RCC* rccs, Grouped_Polynomial poly){
int i;
long double* res=calloc((*rccs).length,sizeof(long double));
@ -762,4 +762,32 @@ int evaleq(RCC* rccs, Grouped_Polynomial poly){
return(0);
}
// evaluate an equation on a vector (using mpfr floats)
int evaleq_mpfr(RCC_mpfr* rccs, Grouped_Polynomial poly){
int i;
mpfr_t* res;
if((*rccs).length!=poly.length){
fprintf(stderr, "error: trying to evaluate an flow equation with %d components on an rcc with %d\n",poly.length,(*rccs).length);
exit(-1);
}
res=calloc((*rccs).length,sizeof(mpfr_t));
// for each equation
for(i=0;i<poly.length;i++){
evalcoef_mpfr(*rccs, poly.coefs[i], res[i]);
}
// copy res to rccs
for(i=0;i<(*rccs).length;i++){
mpfr_set((*rccs).values[i], res[i], MPFR_RNDN);
mpfr_clear(res[i]);
}
// free memory
free(res);
return(0);
}

View File

@ -70,5 +70,7 @@ int char_array_to_Grouped_Polynomial(Char_Array str, Grouped_Polynomial* output)
// evaluate an equation on an RCC
int evaleq(RCC* rccs, Grouped_Polynomial poly);
// evaluate an equation on a vector (using mpfr floats)
int evaleq_mpfr(RCC_mpfr* rccs, Grouped_Polynomial poly);
#endif

View File

@ -108,7 +108,7 @@ int read_args_meantools(int argc,const char* argv[], Str_Array* str_args, Meanto
// print usage message
int print_usage_meantools(){
printf("\nusage:\n meantools exp <filename>\n meantools derive [-d derivatives] -V <variables> <filename>\n meantools eval -R <rccs> <filename>\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);
}

View File

@ -18,16 +18,22 @@ limitations under the License.
#include <stdio.h>
#include <stdlib.h>
#include <mpfr.h>
#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<argc;i++){
@ -51,6 +60,14 @@ int tool_eval_read_args(int argc, const char* argv[], Str_Array* str_args, Meant
case 'R':
flag=CP_FLAG_RCCS;
break;
// mpfr precision
case 'P':
flag=CP_FLAG_MPFR_PREC;
break;
// mpfr emax
case 'E':
flag=CP_FLAG_MPFR_EXP;
break;
}
}
}
@ -59,6 +76,18 @@ int tool_eval_read_args(int argc, const char* argv[], Str_Array* str_args, Meant
str_to_char_array((char*)argv[i], &((*opts).eval_rccstring));
flag=0;
}
// mpfr precision
else if(flag==CP_FLAG_MPFR_PREC){
sscanf(argv[i],"%ld",&tmp_lint);
(*opts).mpfr_prec=(mpfr_prec_t)tmp_lint;
flag=0;
}
// mpfr emax
else if(flag==CP_FLAG_MPFR_EXP){
sscanf(argv[i],"%ld",&tmp_lint);
(*opts).mpfr_emax=(mpfr_exp_t)tmp_lint;
flag=0;
}
// read file name from command-line
else{
file=argv[i];
@ -78,9 +107,21 @@ int tool_eval(Str_Array str_args, Meantools_Options opts){
int arg_index;
// rccs
RCC rccs;
RCC_mpfr rccs_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 flow equation
// if there is a unique argument, assume it is the flow equation
@ -108,22 +149,33 @@ int tool_eval(Str_Array str_args, Meantools_Options opts){
}
// initialize the rccs
prepare_init(flow_equation.indices,flow_equation.length,&rccs);
if(mpfr_flag==0){
prepare_init(flow_equation.indices,flow_equation.length,&rccs);
}
else{
prepare_init_mpfr(flow_equation.indices,flow_equation.length,&rccs_mpfr);
}
// read rccs from string
if(opts.eval_rccstring.length!=-1){
parse_init_cd(opts.eval_rccstring, &rccs);
parse_init_cd(opts.eval_rccstring, &rccs, &rccs_mpfr, mpfr_flag);
free_Char_Array(opts.eval_rccstring);
}
// evaluate
evaleq(&rccs, flow_equation);
if(mpfr_flag==0){
evaleq(&rccs, flow_equation);
RCC_print(rccs);
free_RCC(rccs);
}
else{
evaleq_mpfr(&rccs_mpfr, flow_equation);
RCC_mpfr_print(rccs_mpfr);
free_RCC_mpfr(rccs_mpfr);
}
// print
RCC_print(rccs);
// free memory
free_Grouped_Polynomial(flow_equation);
free_RCC(rccs);
return(0);
}

View File

@ -18,6 +18,10 @@ limitations under the License.
#include <stdlib.h>
#include <stdio.h>
#include <math.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 "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<x.length;i++){
if(x.scalars[i].numerator!=0){
mpfr_sqrt_ui(b, x.base[i], MPFR_RNDN);
Q_mpfr_value(A, x.scalars[i]);
mpfr_mul(c, A, b, MPFR_RNDN);
mpfr_add(b, out, c, MPFR_RNDN);
mpfr_set(out, b, MPFR_RNDN);
}
}
mpfr_clears(A,b,c, (mpfr_ptr)NULL);
return(0);
}
// print to string

View File

@ -98,6 +98,8 @@ int number_is_zero(Number x);
// approximate numerical expression
long double number_double_val(Number x);
// approximate numerical expression (as mpfr float)
int number_mpfr_val(mpfr_t out, Number x);
// print to string
int number_sprint(Number number, Char_Array* out);

View File

@ -30,6 +30,7 @@ Compute the flow of a flow equation numerically
// rccs
#include "rcc.h"
#include "rcc_mpfr.h"
// grouped representation of polynomials
#include "grouped_polynomial.h"
// command line parser
@ -38,6 +39,7 @@ Compute the flow of a flow equation numerically
#include "parse_file.h"
// numerical flow
#include "flow.h"
#include "flow_mpfr.h"
// arrays
#include "array.h"
@ -68,10 +70,13 @@ int main (int argc, const char* argv[]){
// parse command-line arguments
#define CP_FLAG_NITER 1
#define CP_FLAG_TOL 2
#define CP_FLAG_RCCS 3
#define CP_FLAG_RCCS 2
#define CP_FLAG_MPFR_PREC 3
#define CP_FLAG_MPFR_EXP 4
int read_args_numkondo(int argc,const char* argv[], Str_Array* str_args, Numkondo_Options* opts){
int i;
// temporary long int
long int tmp_lint;
// pointers
char* ptr;
// file to read the polynomial from in flow mode
@ -92,10 +97,11 @@ int read_args_numkondo(int argc,const char* argv[], Str_Array* str_args, Numkond
(*opts).display_mode=DISPLAY_NUMERICAL;
// default niter
(*opts).niter=100;
// default to 0 tolerance
(*opts).tol=0;
// 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=1;i<argc;i++){
@ -111,14 +117,18 @@ for(i=1;i<argc;i++){
case 'N':
flag=CP_FLAG_NITER;
break;
// tolerance
case 'D':
flag=CP_FLAG_TOL;
break;
// initial condition
case 'I':
flag=CP_FLAG_RCCS;
break;
// mpfr precision
case 'P':
flag=CP_FLAG_MPFR_PREC;
break;
// mpfr emax
case 'E':
flag=CP_FLAG_MPFR_EXP;
break;
// print version
case 'v':
printf("numkondo " VERSION "\n");
@ -134,16 +144,23 @@ for(i=1;i<argc;i++){
// reset flag
flag=0;
}
// tolerance
else if (flag==CP_FLAG_TOL){
sscanf(argv[i],"%Lf",&((*opts).tol));
flag=0;
}
// init condition
else if(flag==CP_FLAG_RCCS){
str_to_char_array((char*)argv[i], &((*opts).eval_rccstring));
flag=0;
}
// mpfr precision
else if(flag==CP_FLAG_MPFR_PREC){
sscanf(argv[i],"%ld",&tmp_lint);
(*opts).mpfr_prec=(mpfr_prec_t)tmp_lint;
flag=0;
}
// mpfr emax
else if(flag==CP_FLAG_MPFR_EXP){
sscanf(argv[i],"%ld",&tmp_lint);
(*opts).mpfr_emax=(mpfr_exp_t)tmp_lint;
flag=0;
}
// read file name from command-line
else{
file=argv[i];
@ -158,7 +175,7 @@ for(i=1;i<argc;i++){
// print usage message
int print_usage_numkondo(){
printf("\nusage:\n numkondo [-F] [-N niter] [-D tolerance] [-I initial_condition] <filename>\n\n");
printf("\nusage:\n numkondo [-F] [-N niter] [-I initial_condition] [-P precision] [-E exponent_range] <filename>\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);
}

View File

@ -18,12 +18,14 @@ limitations under the License.
#include <stdio.h>
#include <stdlib.h>
#include <mpfr.h>
#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<length;i++){
(*init).indices[i]=indices[i];
// set constants to 1
if(indices[i]<0 && indices[i]>-DOFFSET){
mpfr_set_ui((*init).values[i],1,MPFR_RNDN);
}
else{
mpfr_set_zero((*init).values[i],1);
}
}
return(0);
}

View File

@ -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

View File

@ -19,21 +19,14 @@ limitations under the License.
#include "rational_float.h"
#include <stdio.h>
#include <stdlib.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 "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

View File

@ -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);

View File

@ -19,6 +19,10 @@ limitations under the License.
#include "rational_int.h"
#include <stdio.h>
#include <stdlib.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 "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

View File

@ -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);

124
src/rcc_mpfr.c Normal file
View File

@ -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 <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
// 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 <mpfr.h>
#include <math.h>
#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<size;i++){
mpfr_init((*rcc_mpfr).values[i]);
}
return(0);
}
int free_RCC_mpfr(RCC_mpfr rcc_mpfr){
int i;
for(i=0;i<rcc_mpfr.length;i++){
mpfr_clear(rcc_mpfr.values[i]);
}
free(rcc_mpfr.values);
free(rcc_mpfr.indices);
return(0);
}
// set a given element of an rcc_mpfr
int RCC_mpfr_set_elem(mpfr_t value, int index, RCC_mpfr* rcc_mpfr, int pos){
mpfr_set((*rcc_mpfr).values[pos], value, MPFR_RNDN);
(*rcc_mpfr).indices[pos]=index;
return(0);
}
int RCC_mpfr_cpy(RCC_mpfr input,RCC_mpfr* output){
int i;
init_RCC_mpfr(output,input.length);
for(i=0;i<input.length;i++){
RCC_mpfr_set_elem(input.values[i], input.indices[i], output, i);
}
return(0);
}
// concatenate rcc_mpfr
int RCC_mpfr_concat(RCC_mpfr rcc_mpfr1, RCC_mpfr rcc_mpfr2, RCC_mpfr* output){
int i;
init_RCC_mpfr(output,rcc_mpfr1.length+rcc_mpfr2.length);
for(i=0;i<rcc_mpfr1.length;i++){
RCC_mpfr_set_elem(rcc_mpfr1.values[i], rcc_mpfr1.indices[i], output, i);
}
for(i=0;i<rcc_mpfr2.length;i++){
RCC_mpfr_set_elem(rcc_mpfr2.values[i], rcc_mpfr2.indices[i], output, i+rcc_mpfr1.length);
}
return(0);
}
// append an rcc_mpfr at the end of another
int RCC_mpfr_append(RCC_mpfr input, RCC_mpfr* output){
int i;
for(i=0;i<input.length;i++){
RCC_mpfr_set_elem(input.values[i], input.indices[i], output, i+(*output).length);
}
(*output).length+=input.length;
return(0);
}
// print an rcc_mpfr vector with maximal precision
int RCC_mpfr_print(RCC_mpfr rcc_mpfr){
int j;
// the printf format
Char_Array printf_format;
// number of digits in output
int size;
// compute size
// WARNING: assumes mpfr_default_prec is an int
size=mpfr_get_default_prec()*log10(2)-1;
init_Char_Array(&printf_format,12);
char_array_snprintf(&printf_format,"%%d:%%.%dRe",size);
for(j=0;j<rcc_mpfr.length;j++){
mpfr_printf(printf_format.str,rcc_mpfr.indices[j],rcc_mpfr.values[j]);
if(j<rcc_mpfr.length-1){
printf(",\n");
}
else{
printf("\n");
}
}
free_Char_Array(printf_format);
return(0);
}

43
src/rcc_mpfr.h Normal file
View File

@ -0,0 +1,43 @@
/*
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.
*/
/*
RCC_mpfr struct
This data type is similar to RCC but the values of the rcc's are specified as mpfr floats
*/
#ifndef RCC_MPFR_H
#define RCC_MPFR_H
#include "types.h"
// init
int init_RCC_mpfr(RCC_mpfr* rcc_mpfr, int size);
int free_RCC_mpfr(RCC_mpfr rcc_mpfr);
// set an element of an rcc_mpfr
int RCC_mpfr_set_elem(mpfr_t value, int index, RCC_mpfr* rcc_mpfr, int pos);
// copy
int RCC_mpfr_cpy(RCC_mpfr input,RCC_mpfr* output);
// concatenate 2 rcc_mpfr_mpfr
int RCC_mpfr_concat(RCC_mpfr rcc_mpfr_mpfr1, RCC_mpfr rcc_mpfr_mpfr2, RCC_mpfr* output);
// append an rcc_mpfr to another
int RCC_mpfr_append(RCC_mpfr input, RCC_mpfr* output);
// print an rcc_mpfr vector with maximal precision
int RCC_mpfr_print(RCC_mpfr rcc_mpfr_mpfr);
#endif

View File

@ -21,6 +21,8 @@ limitations under the License.
#ifndef TYPES_H
#define TYPES_H
#include <mpfr.h>
// 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{