From af94c444756dc01b1a3ef27554ade92ef6ccfe0f Mon Sep 17 00:00:00 2001 From: hjwLab Date: Mon, 10 Apr 2023 21:32:25 +0800 Subject: [PATCH 01/32] Detect NumOpt error initially --- detectErrorAll.sh | 4 + detectErrorOneFPEDParallelNumOpt.sh | 77 ++ includeNumOpt/backend/gamma.h | 118 +++ includeNumOpt/backend/points.h | 52 ++ includeNumOpt/backend/self_math.h | 22 + includeNumOpt/iRRAM/COMPLEX.h | 131 +++ includeNumOpt/iRRAM/DYADIC.h | 192 +++++ includeNumOpt/iRRAM/FUNCTION.h | 626 +++++++++++++++ includeNumOpt/iRRAM/GMP_intrat.h | 237 ++++++ includeNumOpt/iRRAM/INTEGER.h | 555 +++++++++++++ includeNumOpt/iRRAM/INTERVAL.h | 127 +++ includeNumOpt/iRRAM/LAZYBOOLEAN.h | 84 ++ includeNumOpt/iRRAM/MPFR_interface.h | 313 ++++++++ includeNumOpt/iRRAM/RATIONAL.h | 167 ++++ includeNumOpt/iRRAM/REAL.h | 838 ++++++++++++++++++++ includeNumOpt/iRRAM/REALMATRIX.h | 136 ++++ includeNumOpt/iRRAM/SPARSEREALMATRIX.h | 134 ++++ includeNumOpt/iRRAM/STREAMS.h | 184 +++++ includeNumOpt/iRRAM/SWITCHES.h | 115 +++ includeNumOpt/iRRAM/cache.h | 138 ++++ includeNumOpt/iRRAM/core.h | 605 ++++++++++++++ includeNumOpt/iRRAM/errno.h | 10 + includeNumOpt/iRRAM/lib.h | 265 +++++++ includeNumOpt/iRRAM/limit_templates.h | 438 ++++++++++ includeNumOpt/iRRAM/mpfr_extension.h | 24 + includeNumOpt/iRRAM/version.h | 12 + src/main.cpp | 4 + src/tools.cpp | 3 + srcNumOpt/points.cpp | 185 +++++ srcTest/Bsplines3/expr_Bsplines3_NumOpt.cpp | 46 ++ 30 files changed, 5842 insertions(+) create mode 100644 detectErrorAll.sh create mode 100755 detectErrorOneFPEDParallelNumOpt.sh create mode 100644 includeNumOpt/backend/gamma.h create mode 100644 includeNumOpt/backend/points.h create mode 100644 includeNumOpt/backend/self_math.h create mode 100644 includeNumOpt/iRRAM/COMPLEX.h create mode 100644 includeNumOpt/iRRAM/DYADIC.h create mode 100644 includeNumOpt/iRRAM/FUNCTION.h create mode 100644 includeNumOpt/iRRAM/GMP_intrat.h create mode 100644 includeNumOpt/iRRAM/INTEGER.h create mode 100644 includeNumOpt/iRRAM/INTERVAL.h create mode 100644 includeNumOpt/iRRAM/LAZYBOOLEAN.h create mode 100644 includeNumOpt/iRRAM/MPFR_interface.h create mode 100644 includeNumOpt/iRRAM/RATIONAL.h create mode 100644 includeNumOpt/iRRAM/REAL.h create mode 100644 includeNumOpt/iRRAM/REALMATRIX.h create mode 100644 includeNumOpt/iRRAM/SPARSEREALMATRIX.h create mode 100644 includeNumOpt/iRRAM/STREAMS.h create mode 100644 includeNumOpt/iRRAM/SWITCHES.h create mode 100644 includeNumOpt/iRRAM/cache.h create mode 100644 includeNumOpt/iRRAM/core.h create mode 100644 includeNumOpt/iRRAM/errno.h create mode 100644 includeNumOpt/iRRAM/lib.h create mode 100644 includeNumOpt/iRRAM/limit_templates.h create mode 100644 includeNumOpt/iRRAM/mpfr_extension.h create mode 100644 includeNumOpt/iRRAM/version.h create mode 100644 srcNumOpt/points.cpp create mode 100644 srcTest/Bsplines3/expr_Bsplines3_NumOpt.cpp diff --git a/detectErrorAll.sh b/detectErrorAll.sh new file mode 100644 index 0000000..2f2f63a --- /dev/null +++ b/detectErrorAll.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -x +target=NumOpt +./detectErrorOneFPEDParallel${target}.sh Bsplines3 0 1 500000 0 0 2e-06 expr_Bsplines3 0_1_500000 ${target} \ No newline at end of file diff --git a/detectErrorOneFPEDParallelNumOpt.sh b/detectErrorOneFPEDParallelNumOpt.sh new file mode 100755 index 0000000..268f95e --- /dev/null +++ b/detectErrorOneFPEDParallelNumOpt.sh @@ -0,0 +1,77 @@ +# Usage: ./detectErrorOneFPEDParallel.sh ${uniqueLabel} ${x0Start} ${x0End} ${x0Size} ${prefix} ${middle} ${suffix} ${errfile} +# set -x + +path=`pwd` +cd ${path} +CC=gcc +CPP=g++ + +uniqueLabel=${1} # unique number +x0Start=${2} +x0End=${3} +if [ $# -eq 11 ]; then + x0Size=${4} + x0startNowIdx=${5} # the index of the start point of the current interval. + x0startOriginInterval=${6} # the value of the start point of the origin interval. + stepX0=${7} # the step for sampling points. + prefix=${8} # expr_${uniqueLabel}. Eg: expr_20221030155958 + middle=${9} # intervalsInfo_sizes. Eg: 3.8_7.8_500000 + suffix=${10} # different version. Eg: herbie daisy origin temp_0_3 final + errfile=${11} # 1 or 0: TRUE or False +elif [ $# -eq 10 ]; then + x0Size=${4} + x0startNowIdx=${5} # the index of the start point of the current interval. + x0startOriginInterval=${6} # the value of the start point of the origin interval. + stepX0=${7} # the step for sampling points. + prefix=${8} # expr_${uniqueLabel}. Eg: expr_20221030155958 + middle=${9} # intervalsInfo_sizes. Eg: 3.8_7.8_500000 + suffix=${10} # different version. Eg: herbie daisy origin temp_0_3 final + errfile=0 +elif [ $# -eq 9 ]; then + x0Size=500000 + x0startNowIdx=${5} # the index of the start point of the current interval. + x0startOriginInterval=${6} # the value of the start point of the origin interval. + stepX0=${7} # the step for sampling points. + prefix=${8} + middle=${9} + suffix=${10} + errfile=0 +else + echo "detectErrorOneFPEDParallel: Invalid input parameters" + exit +fi + +testFileName=test1paramFPEDParallel +numProcs=32 + +# echo "Detecting error: ${uniqueLabel} ${x0Start} ${x0End} ${x0Size} ${prefix} ${middle} ${suffix} ${errfile}" +directory="./srcTest"/${uniqueLabel} +sourceFile=${prefix}_${suffix} +fileNameKernel=${prefix}__${middle}_${suffix} + +# compile the NumOpt version +${CPP} -c -IincludeNumOpt -o objs/points.o srcNumOpt/points.cpp +${CPP} -c -IincludeNumOpt -o objs/${sourceFile}.o ${directory}/${sourceFile}.cpp +${CC} -c -o objs/${prefix}_mpfr.o ${directory}/${prefix}_mpfr.c +${CC} -c -IincludeTEST -o objs/computeULP.o ./srcTest/computeULP.c +mpicc -c -IincludeTEST -DEXPRESSION=${prefix}_ -DSUFFIX=${suffix} -DERRFILE=${errfile} -o objs/${testFileName}.o ./srcTest/${testFileName}.c +mpic++ objs/${testFileName}.o objs/${sourceFile}.o objs/${prefix}_mpfr.o objs/computeULP.o objs/points.o -Xlinker -rpath -Xlinker libs -Llibs -liRRAM -lgmp -lpthread -Llibs -lTGen -lmpfr -lm -lqd -o ${testFileName}.exe + +# run the NumOpt version +# echo "mpirun -n ${numProcs} ./${testFileName}.exe ${x0Start} ${x0End} ${x0Size} ${fileNameKernel}" +mpirun -n ${numProcs} ./${testFileName}.exe ${x0Start} ${x0End} ${x0Size} ${x0startNowIdx} ${x0startOriginInterval} ${stepX0} ${fileNameKernel} ${uniqueLabel} +rm ${testFileName}.exe + +# combine files +if [ ${errfile} -eq 1 ]; then + cd ./outputs/${uniqueLabel} + findWord="${fileNameKernel}_sample_*.txt" + # echo "For suffix = ${suffix}, Find and combine by shell command cat: ${findWord}" + find . -name "${findWord}" | sort -h | xargs cat > sample_${uniqueLabel}_${suffix}.txt + # echo "sample file: `pwd`/sample_${uniqueLabel}_${suffix}.txt" + rm ${findWord} + cd - > /dev/null +fi + +echo "end detecting error ${uniqueLabel}" +echo diff --git a/includeNumOpt/backend/gamma.h b/includeNumOpt/backend/gamma.h new file mode 100644 index 0000000..f02bfc6 --- /dev/null +++ b/includeNumOpt/backend/gamma.h @@ -0,0 +1,118 @@ +#include "iRRAM/lib.h" + +#define euler_gamma (0.577215664901532860606512090082402431042159335) + +using namespace iRRAM; + +/* Experimental, treat with care */ + +/* Bernoulli numbers (modern definition, "even-index") */ +/* program is only able to compute bernoulli_max=... value (see below) */ + +/* time for the Bernoulli numbers Pentium III-1200 : + B_1000 = 2 sec + B_2000 = 20 sec + B_4000 = 246 sec + so the complexity of B_n seems to be about O(n^3.3) and + B_20000 ~ 10 h + + The values are evaluated only once, then cached... An implementaion with variable sized arrays would surely be + better than just using a fixed size array... +*/ + +/* Gamma function is just an approximation, not an exact value! */ +/* see below */ + +/* Bernoulli numbers (modern definition, "even-index") */ + +const unsigned int bernoulli_max=20000; +RATIONAL bernoulli_saved[bernoulli_max/2]; +INTEGER binomial_saved[bernoulli_max]; +unsigned int bernoulli_min_unknown=0; + + +RATIONAL bernoulli(const unsigned int index) +{ +if (index >= bernoulli_max ){ fprintf(stderr,"noch nicht implementiert\n"); exit(1); } + + if ( index == 1 ) return RATIONAL(-1,2); + if ( index%2 == 1 ) return RATIONAL(0); + if (bernoulli_min_unknown == 0){ + bernoulli_saved[0]=RATIONAL(1); + binomial_saved[0]=1; + binomial_saved[1]=2; + binomial_saved[2]=1; + bernoulli_min_unknown=2; + } + while ( bernoulli_min_unknown <= index ) { + INTEGER saved_value=1; + INTEGER old_saved_value; + for (unsigned int i = 1; i <= bernoulli_min_unknown; i++ ){ + old_saved_value=saved_value; + saved_value=binomial_saved[i]; + binomial_saved[i] += old_saved_value; + } + + binomial_saved[bernoulli_min_unknown+1]=1; + + if ( bernoulli_min_unknown%2==0 ){ + RATIONAL summe=bernoulli_saved[0]+binomial_saved[1]*RATIONAL(-1,2); + for (unsigned int i = 2; i < bernoulli_min_unknown; i+=2 ){ + summe=summe + bernoulli_saved[i/2]*binomial_saved[i]; + } + summe= -1*summe/binomial_saved[bernoulli_min_unknown]; + bernoulli_saved[bernoulli_min_unknown/2]= summe; + } + bernoulli_min_unknown++; + } + return bernoulli_saved[index/2]; +} + +// Approximations to the log of the Gamma function +// Problem: The series is alternating, but does not converge.... +// We just compute a few terms: + +REAL ln_gamma_approx(int max_index, const REAL& z) +{ + REAL result= (z-REAL(1)/2)*log(z)-z+log(2*pi())/2; + + REAL coefficient; + REAL inv_power_z=1/z; + REAL inv_square_z=1/(z*z); + for (int index =1;index <= max_index; index ++ ){ + coefficient = REAL(bernoulli(2*index))/(2*index-1)/(2*index) * inv_power_z; + result += coefficient; + inv_power_z= inv_power_z*inv_square_z; + }; + return result; +} + +// An experiment to compute the Gamma function +// We make unproven(!) guesses on +// - how to do the range reduction +// - how to approximate the log_gamma function + +// TREAT THIS WITH CARE! +// The result looks ok for small value of x and p, +// but e.g. for x=150 and p~-3000, about 300 bits seem to be wrong! +// Again: TREAT THIS WITH CARE! + +REAL gamma_approx(int p, const REAL& x){ + if (p>0) p=0; + REAL y=x; + int x_red = y.as_double(53); + REAL y_factorial = 1; + for ( int j = x_red; j < -p/5; j++) + { + y_factorial *= y; + y += 1; + } + return exp(ln_gamma_approx(-p/10, y))/y_factorial; +} + +REAL gamma(const REAL& x){ + return limit(gamma_approx,x); +} + + + diff --git a/includeNumOpt/backend/points.h b/includeNumOpt/backend/points.h new file mode 100644 index 0000000..8fa32c8 --- /dev/null +++ b/includeNumOpt/backend/points.h @@ -0,0 +1,52 @@ +#ifndef POINTS_H +#define POINTS_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +// 生成随机双精度浮点数 +double generate_random_double(); + +// 生成[begin, end)之间随机的双精度浮点数 +double generate_random_double(double begin, double end); + +// 统计[begin, end)之间双精度浮点数个数 +uint64_t double_num_between(double begin, double end); + +// 生成双精度浮点数d后面第offset个浮点数 +double generate_double_by_offset(double d, uint64_t offset); + +// 将一个长度为64的01字符串转为double +double binary2double(std::string str); + +// 将一个double转换为64位长的01字符串 +std::string double2binary(double d); + +// 将一个长度为32位的01字符串转换为int +int binary2int(std::string str); + +// 将一个int转换为32位长的01字符串 +std::string int2binary(int i); + +// 计算两个以二进制表示的双精度浮点数的相对误差 +double relative_error(std::string irram_res, std::string herbie_res); + +// Herbie定义的两个浮点数的误差 +int herbie_error(std::string irram_res, std::string herbie_res); + +// 对一个字符转以特定分隔符进行分割 +template +void split(const std::string &s, char delim, Out result); + +std::vector split(const std::string &s, char delim); + +#endif diff --git a/includeNumOpt/backend/self_math.h b/includeNumOpt/backend/self_math.h new file mode 100644 index 0000000..98be65c --- /dev/null +++ b/includeNumOpt/backend/self_math.h @@ -0,0 +1,22 @@ +#ifndef SELF_MATH_H +#define SELF_MATH_H + +#include +#include "iRRAM/lib.h" +/** +input (a, b) represents a vector +get the angle between vector (a, b) and vector (1, 0) +the return value is in [-pi/2, 3*pi/2) +**/ + +//extern bool iRRAM::enableReiterate; +//extern int iRRAM::MAXiterationnum; +//extern bool iRRAM::alwaysenableReiterate; + +double get_arc(double a, double b); + +double fac(int n); + +iRRAM::REAL fac_real(int n); + +#endif diff --git a/includeNumOpt/iRRAM/COMPLEX.h b/includeNumOpt/iRRAM/COMPLEX.h new file mode 100644 index 0000000..b81383a --- /dev/null +++ b/includeNumOpt/iRRAM/COMPLEX.h @@ -0,0 +1,131 @@ +/* + +iRRAM_COMPLEX.h -- header file for the COMPLEX number part of the iRRAM library + +Copyright (C) 2003/2006 Norbert Mueller + +This file is part of the iRRAM Library. + +The iRRAM Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Library General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at your +option) any later version. + +The iRRAM Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public +License for more details. + +You should have received a copy of the GNU Library General Public License +along with the iRRAM Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, +MA 02111-1307, USA. +*/ + +#ifndef iRRAM_COMPLEX_H +#define iRRAM_COMPLEX_H + +namespace iRRAM { + +class COMPLEX +{ +public: + +// Constructors: ------------------------------- + +COMPLEX(); +COMPLEX(const int real_part); +COMPLEX(const double real_part); +COMPLEX(const INTEGER& real_part); +COMPLEX(const DYADIC& real_part); +COMPLEX(const RATIONAL& real_part); +COMPLEX(const REAL& real_part); + +COMPLEX(const REAL& real_part, const REAL& imag_part); +COMPLEX(const COMPLEX& z); + +// Copy Constructor: --------------------------- + +COMPLEX& operator = (const COMPLEX& y); + +// Standard Arithmetic: ------------------------ + +friend COMPLEX operator + (const COMPLEX& x, + const COMPLEX& y); +friend COMPLEX operator - (const COMPLEX& x, + const COMPLEX& y); +friend COMPLEX operator - (const COMPLEX& x); +friend COMPLEX operator * (const COMPLEX& x, + const COMPLEX& y); +friend COMPLEX operator / (const COMPLEX& x, + const COMPLEX& y); + +friend REAL real(const COMPLEX& z); +friend REAL imag(const COMPLEX& z); +friend REAL abs (const COMPLEX& z); + +friend REAL arg (const COMPLEX& z); +// (1) arg(z) is not defined for z=0, +// (2) arg(z) is multivalued giving values between -pi and pi + 2^(-10), +// so for values z close to the negative half of the real axis, +// arg(z) may give one of two possible values! + +void adderror (sizetype error); +void seterror (sizetype error); +void geterror (sizetype& error) const; +REAL _real,_imag; +}; + +/****************************************************************************/ +// complex functions +/****************************************************************************/ + +COMPLEX sqrt(const COMPLEX& z); +// defined for any complex number: + +COMPLEX csqrt(const COMPLEX& z); +// only defined for |z| > 0 (faster if |z| >> 0 ) : + +COMPLEX log(const COMPLEX& z); +// log is multivalued and gives the principal value, +// except for arguments z close to the negative half of the real axis +// (compare to arg(z) !) + +COMPLEX exp(const COMPLEX& z); + +/****************************/ +/* trigonometric functions */ +/****************************/ + +COMPLEX sin(const COMPLEX& z); +COMPLEX cos(const COMPLEX& z); +COMPLEX tan(const COMPLEX& z); +COMPLEX cotan(const COMPLEX& z); +COMPLEX sec(const COMPLEX& z); +COMPLEX cosec(const COMPLEX& z); + +COMPLEX sinh(const COMPLEX& z); +COMPLEX cosh(const COMPLEX& z); +COMPLEX tanh(const COMPLEX& z); +COMPLEX coth(const COMPLEX& z); +COMPLEX sech(const COMPLEX& z); +COMPLEX cosech(const COMPLEX& z); + +COMPLEX asin(const COMPLEX& z); +COMPLEX acos(const COMPLEX& z); +COMPLEX atan(const COMPLEX& z); +COMPLEX acotan(const COMPLEX& z); +COMPLEX asec(const COMPLEX& z); +COMPLEX acosec(const COMPLEX& z); + +COMPLEX asinh(const COMPLEX& z); +COMPLEX acosh(const COMPLEX& z); +COMPLEX atanh(const COMPLEX& z); +COMPLEX acoth(const COMPLEX& z); +COMPLEX asech(const COMPLEX& z); +COMPLEX acosech(const COMPLEX& z); + + +} // namespace iRRAM + +#endif diff --git a/includeNumOpt/iRRAM/DYADIC.h b/includeNumOpt/iRRAM/DYADIC.h new file mode 100644 index 0000000..7f7aa7e --- /dev/null +++ b/includeNumOpt/iRRAM/DYADIC.h @@ -0,0 +1,192 @@ +/* + +iRRAM_DYADIC.h -- header file for the DYADIC part of the iRRAM library + +Copyright (C) 2001-2004 Norbert Mueller + +This file is part of the iRRAM Library. + +The iRRAM Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Library General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at your +option) any later version. + +The iRRAM Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public +License for more details. + +You should have received a copy of the GNU Library General Public License +along with the iRRAM Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, +MA 02111-1307, USA. +*/ + +#ifndef iRRAM_DYADIC_H +#define iRRAM_DYADIC_H + +namespace iRRAM { + + extern __thread int iRRAM_DYADIC_precision; + +class DYADIC +{ +public: + +friend class DYADIC_precision; +static int getprec() {return iRRAM_DYADIC_precision;}; +// Constructors: ------------------------------- + +DYADIC (); +DYADIC (const int i); +DYADIC (const double y); +DYADIC (const INTEGER& y); +DYADIC (const DYADIC& y); + +// Copy Constructor: --------------------------- + +DYADIC& operator = (const DYADIC& y); + +// Destructor: --------------------------------- + +~DYADIC(); + +// Standard Arithmetic: ------------------------ + +friend DYADIC ADD (const DYADIC& x, const DYADIC& y, int p); +friend DYADIC operator + (const DYADIC& x, const DYADIC& y); +friend DYADIC operator + (const int x, const DYADIC& y); +friend DYADIC operator + (const DYADIC& x, const int y); +friend DYADIC operator + (const double x, const DYADIC& y); +friend DYADIC operator + (const DYADIC& x, const double y); +friend DYADIC operator + (const INTEGER& x, const DYADIC& y); +friend DYADIC operator + (const DYADIC& x, const INTEGER& y); + +friend DYADIC SUB (const DYADIC& x, const DYADIC& y, int p); +friend DYADIC operator - (const DYADIC& x, const DYADIC& y); +friend DYADIC operator - (const int x, const DYADIC& y); +friend DYADIC operator - (const DYADIC& x, const int y); +friend DYADIC operator - (const double x, const DYADIC& y); +friend DYADIC operator - (const DYADIC& x, const double y); +friend DYADIC operator - (const INTEGER& x, const DYADIC& y); +friend DYADIC operator - (const DYADIC& x, const INTEGER& y); + +friend DYADIC operator - (const DYADIC& x); + +friend DYADIC MULT (const DYADIC& x, const DYADIC& y, int p); +friend DYADIC operator * (const DYADIC& x, const DYADIC& y); +friend DYADIC operator * (const int x, const DYADIC& y); +friend DYADIC operator * (const DYADIC& x, const int y); +friend DYADIC operator * (const double x, const DYADIC& y); +friend DYADIC operator * (const DYADIC& x, const double y); +friend DYADIC operator * (const INTEGER& x, const DYADIC& y); +friend DYADIC operator * (const DYADIC& x, const INTEGER& y); + +friend DYADIC DIV (const DYADIC& x, const DYADIC& y, int p); +friend DYADIC operator / (const DYADIC& x, const DYADIC& y); +friend DYADIC operator / (const int x, const DYADIC& y); +friend DYADIC operator / (const DYADIC& x, const int y); +friend DYADIC operator / (const double x, const DYADIC& y); +friend DYADIC operator / (const DYADIC& x, const double y); +friend DYADIC operator / (const INTEGER& x, const DYADIC& y); +friend DYADIC operator / (const DYADIC& x, const INTEGER& y); + +// Comparisons: -------------------------------- + +friend bool operator < (const DYADIC& x, const DYADIC& y); +friend bool operator < (const DYADIC& x, const int y); +friend bool operator < (const int x, const DYADIC& y); +friend bool operator < (const DYADIC& x, const double y); +friend bool operator < (const double x, const DYADIC& y); +friend bool operator < (const DYADIC& x, const INTEGER& y); +friend bool operator < (const INTEGER& x, const DYADIC& y); + + +friend bool operator > (const DYADIC& x, const DYADIC& y); +friend bool operator > (const DYADIC& x, const int y); +friend bool operator > (const int x, const DYADIC& y); +friend bool operator > (const DYADIC& x, const double y); +friend bool operator > (const double x, const DYADIC& y); +friend bool operator > (const DYADIC& x, const INTEGER& y); +friend bool operator > (const INTEGER& x, const DYADIC& y); + + +friend bool operator <= (const DYADIC& x, const DYADIC& y); +friend bool operator <= (const DYADIC& x, const int y); +friend bool operator <= (const int x, const DYADIC& y); +friend bool operator <= (const DYADIC& x, const double y); +friend bool operator <= (const double x, const DYADIC& y); +friend bool operator <= (const DYADIC& x, const INTEGER& y); +friend bool operator <= (const INTEGER& x, const DYADIC& y); + + +friend bool operator >= (const DYADIC& x, const DYADIC& y); +friend bool operator >= (const DYADIC& x, const int y); +friend bool operator >= (const int x, const DYADIC& y); +friend bool operator >= (const DYADIC& x, const double y); +friend bool operator >= (const double x, const DYADIC& y); +friend bool operator >= (const DYADIC& x, const INTEGER& y); +friend bool operator >= (const INTEGER& x, const DYADIC& y); + + +friend bool operator == (const DYADIC& x, const DYADIC& y); +friend bool operator == (const DYADIC& x, const int y); +friend bool operator == (const int x, const DYADIC& y); +friend bool operator == (const DYADIC& x, const double y); +friend bool operator == (const double x, const DYADIC& y); +friend bool operator == (const DYADIC& x, const INTEGER& y); +friend bool operator == (const INTEGER& x, const DYADIC& y); + + +friend bool operator != (const DYADIC& x, const DYADIC& y); +friend bool operator != (const DYADIC& x, const int y); +friend bool operator != (const int x, const DYADIC& y); +friend bool operator != (const DYADIC& x, const double y); +friend bool operator != (const double x, const DYADIC& y); +friend bool operator != (const DYADIC& x, const INTEGER& y); +friend bool operator != (const INTEGER& x, const DYADIC& y); + +// Output: ------------------------------------- + +friend std::string swrite (const DYADIC& x, const int w); + +// miscellaneous: ------------------------------ + +friend int size (const DYADIC& x); +friend DYADIC abs (const DYADIC& x); +friend DYADIC scale (const DYADIC& x, const int k); + +// coexistence with other classes: ------------- + +friend class REAL; +friend class INTEGER; +friend class RATIONAL; + +friend DYADIC approx (const REAL& x, const int p); + +INTEGER as_INTEGER(); + +// implementational issues: -------------------- + +MP_type value; + + +private: + +DYADIC(MP_type y); + +}; + +class DYADIC_precision{ +public: +DYADIC_precision(int p) + {precision=iRRAM_DYADIC_precision;iRRAM_DYADIC_precision=p;} +~DYADIC_precision() + {iRRAM_DYADIC_precision=precision;}; +private: +int precision; +}; + +} /* ! namespace iRRAM */ + +#endif diff --git a/includeNumOpt/iRRAM/FUNCTION.h b/includeNumOpt/iRRAM/FUNCTION.h new file mode 100644 index 0000000..2aece75 --- /dev/null +++ b/includeNumOpt/iRRAM/FUNCTION.h @@ -0,0 +1,626 @@ +/* + +iRRAM_FUNCTION.h -- header file for the FUNCTION part of the iRRAM library + +Copyright (C) 2001-2013 Norbert Mueller + +This file is part of the iRRAM Library. + +The iRRAM Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Library General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at your +option) any later version. + +The iRRAM Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public +License for more details. + +You should have received a copy of the GNU Library General Public License +along with the iRRAM Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, +MA 02111-1307, USA. +*/ + +#ifndef iRRAM_FUNCTION_H +#define iRRAM_FUNCTION_H +#include +#include +#include /* std::function */ +#include /* std::shared_ptr */ + +namespace iRRAM { + + +template +class FUNCTION; + +template +class FUNCTIONAL_object +{ +public: + FUNCTIONAL_object() {} + virtual ~FUNCTIONAL_object() {} + + virtual RESULT eval(const PARAM &... z) {RESULT r; return r;} +}; + +template +class FUNCTIONAL_algorithm :public FUNCTIONAL_object +{ +public: + std::function _eval; + + FUNCTIONAL_algorithm(const std::function &evalp) : _eval(evalp) {} + FUNCTIONAL_algorithm(std::function &&evalp) : _eval(evalp) {} + + RESULT eval(const PARAM &... z){return _eval(z...);}; +}; + + +template +class FUNCTIONAL_value :public FUNCTIONAL_object +{ +public: + RESULT _value; + + FUNCTIONAL_value( + const RESULT &value + ) {_value=value;} + + RESULT eval(const PARAM&...z) {return _value;}; +}; + +//******************************************************************************** + + +template +class FUNCTION { +public: + std::shared_ptr> _fobject; + + FUNCTION( + FUNCTIONAL_object * fobject + ) : _fobject(fobject) {} + + FUNCTION() : _fobject(new FUNCTIONAL_object) {} + + FUNCTION(RESULT (*evalp)(const PARAM &... z)) + : _fobject(new FUNCTIONAL_algorithm(evalp)) {} + + FUNCTION( + const FUNCTION &z + ) : _fobject(z._fobject) {} + + inline FUNCTION& operator = ( + const FUNCTION &z + ) { + _fobject = z._fobject; + return (*this); + } + + template + inline auto bind(Args &&... args) -> decltype(from_algorithm(std::bind(*_fobject, args...))) + { + return from_algorithm(std::bind(*_fobject, args...)); + } + + inline RESULT operator()( + const PARAM &... z + ) const { return _fobject->eval(z...); } + + template inline FUNCTION operator () ( + const FUNCTION &inner + ) const { + return compose(*this, inner); + } +}; + +//******************************************************************************** + +template +inline FUNCTION from_algorithm( + RESULT (evalp)(const PARAM &... z) +) { + return new FUNCTIONAL_algorithm(evalp); +} + +template +inline FUNCTION from_algorithm( + const std::function &evalp +) { + return new FUNCTIONAL_algorithm(evalp); +} + +template +inline FUNCTION from_value(const RESULT &value) +{ + return new FUNCTIONAL_value(value); +} + +template +inline FUNCTION compose( + const FUNCTION&outer, + const FUNCTION &inner +) { + return from_algorithm( + std::function( + [=](const PARAM &... z) + { + return outer(inner(z...)); + } + ) + ); +} + + + + +template +inline FUNCTION,std::pair> product( + const FUNCTION &f_1, + const FUNCTION &f_2 +) { + return from_algorithm( + std::function(const std::pair &)>( + [=](const std::pair &z) + { + return std::make_pair(f_1(z.first), f_2(z.second)); + } + ) + ); +} + +template +inline FUNCTION,PARAM... > juxtaposition( + const FUNCTION &f_1, + const FUNCTION &f_2 +) { + return from_algorithm( + std::function(const PARAM &...)>( + [=](const PARAM &... z) + { + return std::make_pair(f_1(z...),f_2(z...)); + } + ) + ); +} + +template +inline FUNCTION first( + const FUNCTION,PARAM... > &f +) { + return from_algorithm( + std::function( + [=](const PARAM &... z) + { + return f(z...).first; + } + ) + ); +} + +template +inline FUNCTION second( + const FUNCTION,PARAM... > &f +) { + return from_algorithm( + std::function( + [=](const PARAM &... z) + { + return f(z...).second; + } + ) + ); +} +/* +template +inline FUNCTION bind_first ( + const FUNCTION,RESULT > &f, + const PARAM1& x + ){ + return new FUNCTIONAL_bind_first(f._fobject,x); + } + +template +inline FUNCTION bind_second ( + const FUNCTION,RESULT > &f, + const PARAM2& y + ){ + return new FUNCTIONAL_bind_second(f._fobject,y); + } +*/ +template +inline FUNCTION projection( + const FUNCTION,PARAM... > &f, + const int i +) { + return from_algorithm( + std::function( + [=](const PARAM &... z) + { + return f(z...)[i]; + } + ) + ); +} + +//******************************************************************************** + + +template +inline FUNCTION polynomial( + const std::vector &coeff +) { + return from_algorithm( + std::function( + [=](const PARAM &z) + { + PARAM sum = 0; + PARAM factor = 1; + for (unsigned int i=0; i +inline FUNCTION addition( + const FUNCTION,PARAM... > &a +) { + return from_algorithm( + std::function( + [=](const PARAM &... z) + { + std::pair r = a(z...); + return r.first + r.second; + } + ) + ); +} + +template +inline FUNCTION operator + ( + const FUNCTION &a, + const FUNCTION &b + ){ + return addition(juxtaposition(a,b)); + } + + +//******************************************************************************** + + +template +inline FUNCTION subtraction( + const FUNCTION,PARAM... > &a +) { + return from_algorithm( + std::function( + [=](const PARAM &... z) + { + std::pair r = a(z...); + return r.first - r.second; + } + ) + ); +} + +template +inline FUNCTION operator - ( + const FUNCTION &a, + const FUNCTION &b + ){ + return subtraction(juxtaposition(a,b)); + } + + +//******************************************************************************** + + +template +inline FUNCTION multiplication( + const FUNCTION,PARAM... > &a +) { + return from_algorithm( + std::function( + [=](const PARAM &... z) + { + std::pair r = a(z...); + return r.first * r.second; + } + ) + ); +} + +template +inline FUNCTION operator * ( + const FUNCTION &a, + const FUNCTION &b + ){ + return multiplication(juxtaposition(a,b)); + } + + +//******************************************************************************** + + +template +inline FUNCTION division( + const FUNCTION,PARAM... > &a +) { + return from_algorithm( + std::function( + [=](const PARAM &... z) + { + std::pair r = a(z...); + return r.first / r.second; + } + ) + ); +} + +template +inline FUNCTION operator / ( + const FUNCTION &a, + const FUNCTION &b + ){ + return division(juxtaposition(a,b)); + } + + +//******************************************************************************** + + +template +inline FUNCTION operator + ( + const FUNCTION &a, + const RESULT &b + ){ + return addition(juxtaposition(a,from_value (b))); + } + +template +inline FUNCTION operator + ( + const RESULT &a, + const FUNCTION &b + ){ + return addition(juxtaposition(from_value (a) ,b)); + } + + +//******************************************************************************** + + +template +inline FUNCTION operator * ( + const FUNCTION &a, + const RESULT &b + ){ + return multiplication(juxtaposition(a,from_value (b))); + } + +template +inline FUNCTION operator * ( + const RESULT &a, + const FUNCTION &b + ){ + return multiplication(juxtaposition(from_value (a) ,b)); + } + + +//******************************************************************************** + + +template +inline FUNCTION operator - ( + const FUNCTION &a, + const RESULT &b + ){ + return subtraction(juxtaposition(a,from_value (b))); + } + +template +inline FUNCTION operator - ( + const RESULT &a, + const FUNCTION &b + ){ + return subtraction(juxtaposition(from_value (a) ,b)); + } + + +//******************************************************************************** + + +template +inline FUNCTION operator / ( + const FUNCTION &a, + const RESULT &b + ){ + return division(juxtaposition(a,from_value (b))); + } + +template +inline FUNCTION operator / ( + const RESULT &a, + const FUNCTION &b + ){ + return division(juxtaposition(from_value (a) ,b)); + } + + +//******************************************************************************** + + +// Be careful: The following operator "f f(x) +inline FUNCTION less_than( + const FUNCTION,PARAM... > &a +) { + // return new FUNCTIONAL_less_than(a._fobject); + return from_algorithm( + std::function( + [=](const PARAM &... z) + { + std::pair r = a(z...); + return (r.first) < (r.second); + } + ) + ); +} + +template +inline FUNCTION operator < ( + const FUNCTION &a, + const FUNCTION &b + ){ + return less_than(juxtaposition(a,b)); + } + +template +inline FUNCTION operator > ( + const FUNCTION &a, + const FUNCTION &b + ){ + return less_than(juxtaposition(b,a)); + } + + +//******************************************************************************** + + +template +inline FUNCTION operator < ( + const FUNCTION &a, + const RESULT &b + ){ + return less_than(juxtaposition(a,from_value (b))); + } + +template +inline FUNCTION operator < ( + const RESULT &a, + const FUNCTION &b + ){ + return less_than(juxtaposition(from_value (a) ,b)); + } + +template +inline FUNCTION operator > ( + const FUNCTION &a, + const RESULT &b + ){ + return less_than(juxtaposition(from_value (b),a)); + } + +template +inline FUNCTION operator > ( + const RESULT &a, + const FUNCTION &b + ){ + return less_than(juxtaposition(b,from_value (a))); + } + +//******************************************************************************** + + +template +inline FUNCTION LAZY_BOOLEAN_FUNCTION_and( + const FUNCTION,PARAM... > &a +) { + return from_algorithm( + std::function( + [=](const PARAM &... z) + { + std::pair r = a(z...); + return (r.first) && (r.second); + } + ) + ); +} + +template +inline FUNCTION operator && ( + const FUNCTION &a, + const FUNCTION &b + ){ + return LAZY_BOOLEAN_FUNCTION_and(juxtaposition(a,b)); + } + + +template +inline FUNCTION LAZY_BOOLEAN_FUNCTION_or( + const FUNCTION,PARAM... > &a +) { + return from_algorithm( + std::function( + [=](const PARAM &... z) + { + std::pair r = a(z...); + return (r.first) || (r.second); + } + ) + ); +} + +template +inline FUNCTION operator || ( + const FUNCTION &a, + const FUNCTION &b + ){ + return LAZY_BOOLEAN_FUNCTION_or(juxtaposition(a,b)); + } + + +template +inline FUNCTION LAZY_BOOLEAN_FUNCTION_not( + const FUNCTION &a +) { + // return new FUNCTIONAL_not(a._fobject); + return from_algorithm( + std::function( + [=](const PARAM &... z) + { + return !a(z...); + } + ) + ); +} + +template +inline FUNCTION operator ! ( + const FUNCTION &a + ){ + return LAZY_BOOLEAN_FUNCTION_not(a); + } + + +//******************************************************************************** +// Special additional operators for functions +//******************************************************************************** + + +//******************************************************************************** +// general limit operator for FUNCTION objects on REAL numbers +// +// REAL limit ( FUNCTION f ) +// if FUNCTION f defines a normed Cauchy sequence, i.e. |f(i)-x|<= 2^{i} +// then limit(f) returns x +//******************************************************************************** + +REAL limit (const FUNCTION& f ); + + +} //namespace iRRAM + +#endif diff --git a/includeNumOpt/iRRAM/GMP_intrat.h b/includeNumOpt/iRRAM/GMP_intrat.h new file mode 100644 index 0000000..a0c6545 --- /dev/null +++ b/includeNumOpt/iRRAM/GMP_intrat.h @@ -0,0 +1,237 @@ +/* + +GMP_intrat.h -- extension to the GMP integer/rationals for the iRRAM library + +Copyright (C) 2001-2004 Norbert Mueller + +This file is part of the iRRAM Library. + +The iRRAM Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Library General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at your +option) any later version. + +The iRRAM Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public +License for more details. + +You should have received a copy of the GNU Library General Public License +along with the iRRAM Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, +MA 02111-1307, USA. +*/ + +/* +Changelog: (initial version by Tom van Diessen) + + 2001-09-10 removal of several unneeded functions by Norbert + 2004-12-20 transformation to inline by Norbert +*/ + +#ifndef iRRAM_GMP_INT_RAT_H +#define iRRAM_GMP_INT_RAT_H + +#include +#include +#include + +#include +#ifdef __cplusplus +extern "C" { +#endif + +/*GMP_min and GMP_max should go to the interface definitions!*/ + +#define GMP_min -1000000000 +#define GMP_max 1000000000 + +/********** MP integer type definition **********/ +typedef mpz_ptr int_gmp_type; +typedef struct {unsigned int body;} int_gmp_sizetype; + +/********** counting vars **********/ +#define MaxFreeVars 1000 +extern __thread int_gmp_type gmp_FreeVarsi[MaxFreeVars]; +extern __thread int gmp_FreeVarCounti; +extern __thread int int_gmp_var_count; + + +/********** initialization function **********/ + +static inline int_gmp_type int_gmp_init() +{ + int_gmp_type z; + if (gmp_FreeVarCounti>0) { + gmp_FreeVarCounti--; + z = gmp_FreeVarsi[gmp_FreeVarCounti]; + }else{ + z = (int_gmp_type) malloc(sizeof(__mpz_struct)); + mpz_init(z); + } + int_gmp_var_count++; + return z; +} + +static inline void int_gmp_free(int_gmp_type z) +{ + if (gmp_FreeVarCounti < MaxFreeVars){ + gmp_FreeVarsi[gmp_FreeVarCounti]=z; + gmp_FreeVarCounti++; + }else{ + mpz_clear(z); + free(z); + } + int_gmp_var_count--; +} + +/********** Conversion functions **********/ + +static inline void int_gmp_int2integer(const int i, int_gmp_type z){mpz_set_si(z,i);} +static inline void int_gmp_double2int(const double d, int_gmp_type z){mpz_set_d(z,d);} +static inline void int_gmp_string2int(const char* s, int_gmp_type z, int b){mpz_set_str(z,s,b);} +static inline int int_gmp_integer2int(const int_gmp_type z){return mpz_get_si(z);} + +/********** standard arithmetic functions for MP integer **********/ + +static inline void int_gmp_add(const int_gmp_type z1, const int_gmp_type z2, int_gmp_type z){mpz_add(z,z1,z2);} +static inline void int_gmp_sub(const int_gmp_type z1, const int_gmp_type z2, int_gmp_type z){mpz_sub(z,z1,z2);} +static inline void int_gmp_mul(const int_gmp_type z1, const int_gmp_type z2, int_gmp_type z){mpz_mul(z,z1,z2);} +static inline void int_gmp_div(const int_gmp_type z1, const int_gmp_type z2, int_gmp_type z){mpz_tdiv_q(z,z1,z2);} + +static inline void int_gmp_add_ui(const int_gmp_type z1, const unsigned int z2, int_gmp_type z){mpz_add_ui(z,z1,z2);} +static inline void int_gmp_sub_ui(const int_gmp_type z1, const unsigned int z2,int_gmp_type z){mpz_sub_ui(z,z1,z2);} +static inline void int_gmp_mul_si(const int_gmp_type z1, const int z2, int_gmp_type z){mpz_mul_si(z,z1,z2);} +static inline void int_gmp_div_ui(const int_gmp_type z1, const unsigned int z2, int_gmp_type z){mpz_tdiv_q_ui(z,z1,z2);} + +static inline void int_gmp_abs(const int_gmp_type z1, int_gmp_type z){mpz_abs(z, z1);} +static inline void int_gmp_neg(const int_gmp_type z1, int_gmp_type z){mpz_neg(z, z1);} + + + +/********** more MP integer functions *********/ + +void int_gmp_root(int_gmp_type z1, unsigned int z2, int_gmp_type z); +void int_gmp_power_i(int_gmp_type z1, unsigned int z2, int_gmp_type z); +void int_gmp_power_ii(unsigned int z1, unsigned int z2, int_gmp_type z); +void int_gmp_fac(unsigned int z1, int_gmp_type z); +void int_gmp_modulo(int_gmp_type z1, int_gmp_type z2, int_gmp_type z3); +void int_gmp_sqrt(int_gmp_type z1, int_gmp_type z); +void int_gmp_shift(int_gmp_type z1, int_gmp_type z, int p); +int int_gmp_log(int_gmp_type z); + + +/********** output functions for MP integers **********/ + +void int_gmp_writee(int_gmp_type z, int w); +char* int_gmp_swritee(int_gmp_type z, int w); +void int_gmp_write(int_gmp_type z, int w); +void int_gmp_outstr(int_gmp_type z, int w); +void int_gmp_printf(int_gmp_type z); +char* int_gmp_sprintf(int_gmp_type z); + + +/********** copying MP integers with/without initializing **********/ + +static inline void int_gmp_duplicate_w_init(const int_gmp_type z1, int_gmp_type *z2){ + *z2=int_gmp_init(); + mpz_set(*z2,z1); +} + +static inline void int_gmp_duplicate_wo_init(const int_gmp_type z1, int_gmp_type z2){mpz_set(z2,z1);} + +/********* sign, size, and comparison of integer*/ +static inline int int_gmp_sgn(const int_gmp_type z){return mpz_sgn(z);} +static inline int int_gmp_cmp(const int_gmp_type z1,const int_gmp_type z2){return mpz_cmp(z1,z2);} +static inline int int_gmp_size(const int_gmp_type z){ + if (mpz_sgn(z) == 0 ) return 0; else return mpz_sizeinbase(z,2);} + +/********** MP rational type definition **********/ +typedef mpq_ptr rat_gmp_type; + +/********** counting vars **********/ +#define rat_MaxFreeVars 1000 +extern __thread int rat_gmp_var_count; +extern __thread rat_gmp_type rat_gmp_FreeVarsi[rat_MaxFreeVars]; +extern __thread int rat_gmp_FreeVarCount; + +/********** initialization function **********/ + +static inline rat_gmp_type rat_gmp_init(){ + rat_gmp_type z; + if (rat_gmp_FreeVarCount>0){ + rat_gmp_FreeVarCount--; + z = rat_gmp_FreeVarsi[rat_gmp_FreeVarCount]; + }else{ + z = (rat_gmp_type) malloc(sizeof(__mpq_struct)); + mpq_init(z); + } + rat_gmp_var_count++; + return z; +} + +static inline void rat_gmp_free(rat_gmp_type z){ + if(rat_gmp_FreeVarCount < rat_MaxFreeVars){ + rat_gmp_FreeVarsi[rat_gmp_FreeVarCount]=z; + rat_gmp_FreeVarCount++; + }else{ + mpq_clear(z); + free(z); + } + rat_gmp_var_count--; +} + +/* canonicalize the given rational, used for used defined rationals */ +static inline void rat_gmp_canon(rat_gmp_type z){mpq_canonicalize(z);} + + +/********** standard arithmetic functions for MP rational **********/ +/********** + - * / *********/ + +static inline void rat_gmp_add(const rat_gmp_type z1, const rat_gmp_type z2, rat_gmp_type z){mpq_add(z,z1,z2);} +static inline void rat_gmp_sub(const rat_gmp_type z1, const rat_gmp_type z2, rat_gmp_type z){mpq_sub(z,z1,z2);} +static inline void rat_gmp_mul(const rat_gmp_type z1, const rat_gmp_type z2, rat_gmp_type z){mpq_mul(z,z1,z2);} +static inline void rat_gmp_div(const rat_gmp_type z1, const rat_gmp_type z2, rat_gmp_type z){mpq_div(z,z1,z2);} +void rat_gmp_add_ui(const rat_gmp_type z1, const unsigned int z2, rat_gmp_type z); +void rat_gmp_sub_ui(const rat_gmp_type z1, const unsigned int z2, rat_gmp_type z); +void rat_gmp_mul_si(const rat_gmp_type z1, const int z2, rat_gmp_type z); +void rat_gmp_div_si(const rat_gmp_type z1, const int z2, rat_gmp_type z); +void rat_gmp_si_div(const int z1, const rat_gmp_type z2, rat_gmp_type z); +static inline void rat_gmp_abs(const rat_gmp_type z1, rat_gmp_type z){mpq_abs(z,z1);} + + +/********** more MP rational functions *********/ +/********** ^!%>>... **********/ + +void rat_gmp_power(rat_gmp_type z1, unsigned int z2, rat_gmp_type z); +void rat_gmp_powerr(rat_gmp_type z1, rat_gmp_type z2, rat_gmp_type z); +void rat_gmp_shift(rat_gmp_type z1, rat_gmp_type z, int p); + + +/********** output functions for MP rationals ************/ + +char* rat_gmp_swritee(const rat_gmp_type z, const int w); +char* rat_gmp_sprintf(const rat_gmp_type z); + + +void rat_gmp_string_2_rat(rat_gmp_type z, const char* s); +void rat_gmp_double_2_rat(rat_gmp_type z, const double d); + +static inline void rat_gmp_get_numerator(int_gmp_type z, const rat_gmp_type z1){mpq_get_num(z,z1);} +static inline void rat_gmp_get_denominator(int_gmp_type z, const rat_gmp_type z1){mpq_get_den(z,z1);} + + +/********** copying MP rationals with/without initializing ***********/ +static inline void rat_gmp_duplicate_w_init(const rat_gmp_type z1, rat_gmp_type *z2){ + *z2=rat_gmp_init(); mpq_set(*z2,z1);} +static inline void rat_gmp_duplicate_wo_init(const rat_gmp_type z1, rat_gmp_type z2){mpq_set(z2,z1);} + +/********* sign and comparison of integer and rational */ +static inline int rat_gmp_sgn(const rat_gmp_type z){return mpq_sgn(z);} +static inline int rat_gmp_cmp(const rat_gmp_type z1,const rat_gmp_type z2){return mpq_cmp(z1,z2);} + +#ifdef __cplusplus +} +#endif + +#endif /* ifndef iRRAM_GMP_INT_RAT_H */ diff --git a/includeNumOpt/iRRAM/INTEGER.h b/includeNumOpt/iRRAM/INTEGER.h new file mode 100644 index 0000000..8995ead --- /dev/null +++ b/includeNumOpt/iRRAM/INTEGER.h @@ -0,0 +1,555 @@ +/* + +iRRAM_INTEGER.h -- header file for the INTEGER part of the iRRAM library + +Copyright (C) 2001-2003 Norbert Mueller + +This file is part of the iRRAM Library. + +The iRRAM Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Library General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at your +option) any later version. + +The iRRAM Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public +License for more details. + +You should have received a copy of the GNU Library General Public License +along with the iRRAM Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, +MA 02111-1307, USA. +*/ + +#ifndef iRRAM_INTEGER_H +#define iRRAM_INTEGER_H + +namespace iRRAM { + +class INTEGER +{ +public: + +friend class REAL; +friend class DYADIC; +friend class RATIONAL; + +/****** Constructors ******/ + +INTEGER(MP_int_type y); + +INTEGER(); +INTEGER(const int i); +INTEGER(const std::string s); +INTEGER(const char* s); +INTEGER(const INTEGER& y); +INTEGER(const double d); + +/****** Copy constructor ******/ + +INTEGER& operator = (const int y); +INTEGER& operator = (const INTEGER& y); + + /****** Destructor ******/ + +~INTEGER(); + + /****** Standard arithmetic ******/ + +friend INTEGER operator + (const INTEGER& x, const INTEGER& y); +friend INTEGER operator + (const INTEGER& x, const int y); +friend INTEGER operator + (const int x, const INTEGER& y); + +friend INTEGER operator - (const INTEGER& x, const INTEGER& y); +friend INTEGER operator - (const INTEGER& x, const int y); +friend INTEGER operator - (const int x, const INTEGER& y); + +friend INTEGER operator - (const INTEGER& x); + +friend INTEGER operator * (const INTEGER& x, const INTEGER& y); +friend INTEGER operator * (const INTEGER& x, const int y); +friend INTEGER operator * (const int x, const INTEGER& y); + +friend INTEGER operator / (const INTEGER& x, const INTEGER& y); +friend INTEGER operator / (const INTEGER& x, const int y); +friend INTEGER operator / (const int x, const INTEGER& y); + +friend INTEGER operator ^ (const INTEGER& x, const INTEGER& y); +friend INTEGER operator ^ (const INTEGER& x, const unsigned int y); +friend INTEGER operator << (const INTEGER& x, const int y); +friend INTEGER operator >> (const INTEGER& x, const int y); +friend INTEGER operator % (const INTEGER& x, const INTEGER& y); + +friend INTEGER& operator += ( INTEGER& x, const INTEGER& y); +friend INTEGER& operator += ( INTEGER& x, const int y); + +friend INTEGER& operator -= ( INTEGER& x, const INTEGER& y); +friend INTEGER& operator -= ( INTEGER& x, const int y); + +friend INTEGER& operator *= ( INTEGER& x, const INTEGER& y); +friend INTEGER& operator *= ( INTEGER& x, const int y); + +friend INTEGER& operator /= ( INTEGER& x, const INTEGER& y); +friend INTEGER& operator /= ( INTEGER& x, const int y); + + + +friend INTEGER sqrt (const INTEGER& x); +friend INTEGER scale (const INTEGER& x, const int k); +friend INTEGER abs (const INTEGER& x); + +/****** Comparisons ******/ + +friend bool operator < (const INTEGER& x, const INTEGER& y); +friend bool operator < (const INTEGER& x, const int y); +friend bool operator < (const int x, const INTEGER& y); + +friend bool operator <= (const INTEGER& x, const INTEGER& y); +friend bool operator <= (const INTEGER& x, const int y); +friend bool operator <= (const int x, const INTEGER& y); + +friend bool operator > (const INTEGER& x, const INTEGER& y); +friend bool operator > (const INTEGER& x, const int y); +friend bool operator > (const int x, const INTEGER& y); + +friend bool operator >= (const INTEGER& x, const INTEGER& y); +friend bool operator >= (const INTEGER& x, const int y); +friend bool operator >= (const int x, const INTEGER& y); + +friend bool operator == (const INTEGER& x, const INTEGER& y); +friend bool operator == (const INTEGER& x, const int y); +friend bool operator == (const int x, const INTEGER& y); + +friend bool operator != (const INTEGER& x, const INTEGER& y); +friend bool operator != (const INTEGER& x, const int y); +friend bool operator != (const int x, const INTEGER& y); + +friend int size(const INTEGER& x); +friend int sign(const INTEGER& x); + +/* conversion */ +friend std::string swrite (const INTEGER& x, const int w); +friend std::string swrite (const INTEGER& x); + +operator int() const ; + + +/****** Private ******/ +//private: + +MP_int_type value; + +}; + +inline INTEGER::~INTEGER(){ MP_int_clear(value);} + +inline INTEGER::INTEGER::INTEGER(MP_int_type y){ value = y; ;} + +inline INTEGER::INTEGER(const int i){ + MP_int_init(value); + MP_int_to_INTEGER(i,value); +} + +inline INTEGER::INTEGER(){ + MP_int_init(value); + MP_int_to_INTEGER(0,value); +} + + +inline INTEGER& INTEGER::operator = (const INTEGER& y){ + MP_int_duplicate_wo_init(y.value, value); + return (*this); +} + +inline INTEGER& INTEGER::operator = (const int y){ + MP_int_to_INTEGER(y,value); + return (*this); +} + + +#ifdef MP_shift + +inline INTEGER scale(const INTEGER& x, const int n) +{ + MP_int_type zvalue; + MP_int_init(zvalue); + MP_int_shift(x.value,zvalue,n); + return zvalue; +} + +#else + +inline INTEGER scale(const INTEGER& x, const int n) +{ + if (n==0) return x; + if (n==1) return 2*x; + INTEGER y=1; + INTEGER xc=2; + if (n<0) {xc=y/2;n=-n;} + if (n==1) return xc*x; + for (int k=n;k>0;k=k/2) + { + if (k%2==1) y*=xc; + if (k==1) break; + xc*=xc; + } + return y*x; +} + +#endif +//**************************************************************************************** +// Returns the sign of INTEGER objects (-1/0/1): +// sign(i)= -1, iff i<0, sign(i)=1 iff i>0, and sign(0)=0 +//**************************************************************************************** +inline int sign(const INTEGER& x){ return MP_int_sign(x.value); } + +//**************************************************************************************** +// Returns the size of INTEGER objects: The smallest i>0 such that |x| < 2^i, +// e.g. size(0)=size(1)=1;size(2)=size(3)=2,size(4)=...size(7)=3 +//**************************************************************************************** + +inline int size(const INTEGER& x){ return MP_int_size(x.value);} + +//**************************************************************************************** +// Addition: returns x + y +//**************************************************************************************** + +inline INTEGER operator + (const INTEGER& x, const INTEGER& y){ + MP_int_type zvalue; + MP_int_init(zvalue); + MP_int_add(x.value,y.value,zvalue); + return zvalue; +} + +inline INTEGER operator + (const INTEGER& x, const int y){ + MP_int_type zvalue; + MP_int_init(zvalue); + if (y<0) MP_int_sub_ui(x.value,-y,zvalue); + else MP_int_add_ui(x.value,y,zvalue); + return zvalue; +} + +inline INTEGER operator + (const int x, const INTEGER& y) {return y+x;} + +inline INTEGER::INTEGER(const double d){ + MP_int_init(value); + MP_double_to_INTEGER(d,value); +} + +inline INTEGER::INTEGER(const INTEGER& i){ + MP_int_init(value); + MP_int_duplicate_wo_init(i.value, value); +} + + +//**************************************************************************************** +// Constructing INTEGER from character string +// The base is set to 10 (decimal) +//**************************************************************************************** + +inline INTEGER::INTEGER(const char* s){ + MP_int_init(value); + MP_string_to_INTEGER(s,value,10); +} + +inline INTEGER::INTEGER(const std::string s){ + MP_int_init(value); + MP_string_to_INTEGER(s.c_str(),value,10); +} + + + + + +//**************************************************************************************** +// Power: return = x ^ n +//**************************************************************************************** + +inline INTEGER operator ^ (const INTEGER& x, const int n) +{ + MP_int_type zvalue; + MP_int_init(zvalue); + MP_int_power_i(x.value,n,zvalue); + return zvalue; +} + +//**************************************************************************************** +// Power: return = x ^ y, where 0<=y<= (1u<<32) +//**************************************************************************************** + +inline INTEGER operator ^ (const INTEGER& x, const INTEGER& y) +{ + if (y==0 || x==1) return 1; + if (y==1) return x; + if( y> (int((1u<<31)-1 )) ) throw iRRAM_Numerical_Exception(iRRAM_integer_error); + if(sign(y)<0 ) throw iRRAM_Numerical_Exception(iRRAM_integer_error); + return x^(unsigned int)(MP_INTEGER_to_int(y.value)); +} + + +//**************************************************************************************** +// Shifter: returns x << n +// shifts n bits to the left +//**************************************************************************************** + +inline INTEGER operator << (const INTEGER& x, const int n){ + return scale(x,n); +} + +//**************************************************************************************** +// Shifter: returns x >> n +// shifts n bits to the right +//**************************************************************************************** + +inline INTEGER operator >> (const INTEGER& x, const int n){ + return scale(x,-n); +} + + + + +//**************************************************************************************** +// Addition: returns x += y +//**************************************************************************************** + +inline INTEGER& operator += (INTEGER& x, const INTEGER& y){ + MP_int_add(x.value,y.value,x.value); + return x; +} + +inline INTEGER& operator += (INTEGER& x, const int n ){ return x=x+n; } + +//**************************************************************************************** +// Subtraction: returns x - y +//**************************************************************************************** + +inline INTEGER operator - (const INTEGER& x, const INTEGER& y){ + MP_int_type zvalue; + MP_int_init(zvalue); + MP_int_sub(x.value,y.value,zvalue); + return zvalue; +} + +inline INTEGER operator - (const INTEGER& x, const int y){ + MP_int_type zvalue; + MP_int_init(zvalue); + if(y<0) MP_int_add_ui(x.value,-y,zvalue); + else MP_int_sub_ui(x.value,y,zvalue); + return zvalue; +} + +inline INTEGER operator - (const int x, const INTEGER& y){ + return -(y-x); +} + +//**************************************************************************************** +// Subtraction: returns x -= y +//**************************************************************************************** + +inline INTEGER& operator -= (INTEGER& x, const INTEGER& y){ + MP_int_sub(x.value,y.value,x.value); + return x; +} + +inline INTEGER& operator -= (INTEGER& x, const int n){ return x=x-n; } + +//**************************************************************************************** +// Negative: returns -x +//**************************************************************************************** + +inline INTEGER operator - (const INTEGER& x){ + MP_int_type zvalue; + INTEGER y=INTEGER(0); + MP_int_init(zvalue); + MP_int_sub(y.value,x.value,zvalue); + return zvalue; +} + +//**************************************************************************************** +// Multiplication: returns x * y +//**************************************************************************************** + +inline INTEGER operator * (const INTEGER& x, const INTEGER& y){ + MP_int_type zvalue; + MP_int_init(zvalue); + MP_int_mul(x.value,y.value,zvalue); + return zvalue; +} + +inline INTEGER operator * (const INTEGER& x, const int y){ + MP_int_type zvalue; + MP_int_init(zvalue); + MP_int_mul_si(x.value,y,zvalue); + return(zvalue); +} + +inline INTEGER operator * (const int x, const INTEGER& y){ + MP_int_type zvalue; + MP_int_init(zvalue); + MP_int_mul_si(y.value,x,zvalue); + return(zvalue); +} + +//**************************************************************************************** +// Multiplication: returns x *= y +//**************************************************************************************** + +inline INTEGER& operator *= (INTEGER& x, const INTEGER& y){ + MP_int_mul(x.value,y.value,x.value); + return x; +} + +inline INTEGER& operator *= (INTEGER& x, const int n ){ + MP_int_mul_si(x.value,n,x.value); + return x; } + +//**************************************************************************************** +// Division: returns x / y +//**************************************************************************************** + + +inline INTEGER operator / (const INTEGER& x, const INTEGER& y){ + MP_int_type zvalue; + MP_int_init(zvalue); + MP_int_div(x.value,y.value,zvalue); + return zvalue; +} + + +inline INTEGER operator / (const INTEGER& x, const int n){ + MP_int_type zvalue; + MP_int_init(zvalue); + if(n<0){ + MP_int_div_ui(x.value,-n,zvalue); + MP_int_mul_si(zvalue,-1,zvalue); + } + else MP_int_div_ui(x.value,n,zvalue); + return zvalue; +} + +inline INTEGER operator / (const int x, const INTEGER& y) {return INTEGER(x)/y;} + +//**************************************************************************************** +// Division: returns x /= y +//**************************************************************************************** + +inline INTEGER& operator /= (INTEGER& x, const INTEGER& y){ + MP_int_div(x.value,y.value,x.value); + return x; +} + +inline INTEGER& operator /= (INTEGER& x, const int n){ return x=x/n; } + +//**************************************************************************************** +// Modulo: returns x % y +//**************************************************************************************** + +inline INTEGER operator % (const INTEGER& x, const INTEGER& y){ + MP_int_type zvalue; + MP_int_init(zvalue); + MP_int_modulo(x.value,y.value,zvalue); + return zvalue; +} + + +//**************************************************************************************** +// Square-root: returns SQRT(x) +// Returns the truncated square-root of the given argument +//**************************************************************************************** + +inline INTEGER sqrt (const INTEGER& x) +{ + MP_int_type zvalue; + MP_int_init(zvalue); + MP_int_sqrt(x.value, zvalue); + return zvalue; +} + +//**************************************************************************************** +// Absolute value: |x| +// returns the positive part of the object +// 1. argument: INTEGER +// return value: INTEGER +//**************************************************************************************** + +inline INTEGER abs (const INTEGER& x) +{ + MP_int_type zvalue; + MP_int_init(zvalue); + MP_int_abs(x.value,zvalue); + return zvalue; +} + + +//**************************************************************************************** +// boolean operators +// Last change: 2004-12-20 +//**************************************************************************************** + +//**************************************************************************************** +// Less than: x < y +//**************************************************************************************** + +inline bool operator < (const INTEGER& x, const INTEGER& y){ + return (MP_int_compare(x.value,y.value) < 0 ); +} +inline bool operator < (const INTEGER& x, const int y){ return x (const INTEGER& x, const INTEGER& y){ return y (const INTEGER& x, const int y){ return y (const int x, const INTEGER& y){ return y= (const INTEGER& x, const INTEGER& y){ return !(x= (const INTEGER& x, const int y){ return !(x= (const int x, const INTEGER& y){ return !(x +INTERVAL(const T& x):INTERVAL(REAL(x)){} + +// value: interval [ min(l,r), max(l,r) ], for types that can be cast to REAL +template +INTERVAL(const T1& l,const T2& r):INTERVAL(REAL(l),REAL(r)){} + +// Fast construction of an interval from an ordered(!) pair of reals +INTERVAL(const REAL& l, const REAL& r, bool dummy){ low=l; upp=r;} + + +// Standard Arithmetic: ------------------------ + +friend INTERVAL operator + (const INTERVAL& x, const INTERVAL& y); +friend INTERVAL& operator += (INTERVAL& x, const INTERVAL& y){x=x+y; return x;} + +friend INTERVAL operator - (const INTERVAL& x, const INTERVAL& y); +friend INTERVAL& operator -= (INTERVAL& x, const INTERVAL& y){x=x-y; return x;} + +friend INTERVAL operator - (const INTERVAL& x); + +friend INTERVAL operator * (const INTERVAL& x, const INTERVAL& y); +friend INTERVAL& operator *= (INTERVAL& x, const INTERVAL& y){x=x*y; return x;} + +friend INTERVAL operator / (const INTERVAL& x, const INTERVAL& y); +friend INTERVAL& operator /= (INTERVAL& x, const INTERVAL& y){x=x/y; return x;} + +friend REAL wid(const INTERVAL& x); +friend REAL inf(const INTERVAL& x); +friend REAL sup(const INTERVAL& x); +friend REAL mid(const INTERVAL& x); +friend REAL mag(const INTERVAL& x); +friend REAL mig(const INTERVAL& x); + +friend LAZY_BOOLEAN superset (const INTERVAL& x, + const INTERVAL& y); +friend LAZY_BOOLEAN proper_superset (const INTERVAL& x, + const INTERVAL& y); +friend LAZY_BOOLEAN subset (const INTERVAL& x, + const INTERVAL& y); +friend LAZY_BOOLEAN proper_subset (const INTERVAL& x, + const INTERVAL& y); +friend LAZY_BOOLEAN in_interior (const INTERVAL& x, + const INTERVAL& y); +friend LAZY_BOOLEAN disjoint (const INTERVAL& x, + const INTERVAL& y); +friend LAZY_BOOLEAN in (const REAL& x, + const INTERVAL& y); + +friend INTERVAL interval_hull (const INTERVAL& x, + const INTERVAL& y); +friend INTERVAL intersect (const INTERVAL& x, + const INTERVAL& y); + +friend INTERVAL fabs(const INTERVAL& x); + +friend INTERVAL power(const INTERVAL& x,int n); +friend INTERVAL square(const INTERVAL& x); +friend INTERVAL exp(const INTERVAL& x); +friend INTERVAL log(const INTERVAL& x); +friend INTERVAL sin(const INTERVAL& x); +friend INTERVAL cos(const INTERVAL& x); +friend INTERVAL tan(const INTERVAL& x); +friend INTERVAL asin(const INTERVAL& x); +friend INTERVAL acos(const INTERVAL& x); +friend INTERVAL atan(const INTERVAL& x); + +//private : +REAL low; +REAL upp; +}; + +} /* ! namespace iRRAM */ + +#endif diff --git a/includeNumOpt/iRRAM/LAZYBOOLEAN.h b/includeNumOpt/iRRAM/LAZYBOOLEAN.h new file mode 100644 index 0000000..20e89c8 --- /dev/null +++ b/includeNumOpt/iRRAM/LAZYBOOLEAN.h @@ -0,0 +1,84 @@ +/* + +iRRAM_LAZYBOOLEAN.h -- header file for LAZYBOOLEAN class of the iRRAM library + +Copyright (C) 2001-2012 Norbert Mueller + +This file is part of the iRRAM Library. + +The iRRAM Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Library General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at your +option) any later version. + +The iRRAM Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public +License for more details. + +You should have received a copy of the GNU Library General Public License +along with the iRRAM Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, +MA 02111-1307, USA. +*/ +/****************************************************************************/ +// Definition of class LAZY_BOOLEAN +/****************************************************************************/ + +#ifndef iRRAM_LAZYBOOLEAN_H +#define iRRAM_LAZYBOOLEAN_H + +namespace iRRAM { + +class LAZY_BOOLEAN +{ + + +public: +LAZY_BOOLEAN(){value=false;}; +LAZY_BOOLEAN(const LAZY_BOOLEAN& y){value=y.value;}; +LAZY_BOOLEAN& operator = (const LAZY_BOOLEAN& y){value=y.value; return *this;}; +LAZY_BOOLEAN(bool b){value=b;}; + + +friend LAZY_BOOLEAN operator && (const LAZY_BOOLEAN& x, const LAZY_BOOLEAN& y); +friend LAZY_BOOLEAN operator || (const LAZY_BOOLEAN& x, const LAZY_BOOLEAN& y); +friend LAZY_BOOLEAN operator ! ( const LAZY_BOOLEAN& x); +friend int choose(const LAZY_BOOLEAN& x1, + const LAZY_BOOLEAN& x2, + const LAZY_BOOLEAN& x3, + const LAZY_BOOLEAN& x4, + const LAZY_BOOLEAN& x5, + const LAZY_BOOLEAN& x6 ); + +operator bool() const; +friend int check (const LAZY_BOOLEAN& x); + +friend REAL maximum ( const REAL& x, const REAL& y); +friend REAL minimum ( const REAL& x, const REAL& y); + +friend LAZY_BOOLEAN operator < (const REAL&, const REAL&); +friend LAZY_BOOLEAN positive (const REAL& x, int k); +friend LAZY_BOOLEAN bound (const REAL& x, const int k); + +friend class REAL; + +private: + +LAZY_BOOLEAN(int b){value=b;}; +int value; +const static int BOTTOM = -1; +}; + +int choose(const LAZY_BOOLEAN& x1= false, + const LAZY_BOOLEAN& x2= false, + const LAZY_BOOLEAN& x3= false, + const LAZY_BOOLEAN& x4= false, + const LAZY_BOOLEAN& x5= false, + const LAZY_BOOLEAN& x6= false ); + + + +} // namespace iRRAM + +#endif diff --git a/includeNumOpt/iRRAM/MPFR_interface.h b/includeNumOpt/iRRAM/MPFR_interface.h new file mode 100644 index 0000000..feffa4c --- /dev/null +++ b/includeNumOpt/iRRAM/MPFR_interface.h @@ -0,0 +1,313 @@ +/* + +MPFR_interface.h -- interface to the MPFR float functions for the iRRAM library + +Copyright (C) 2002-2004 Norbert Mueller + +This file is part of the iRRAM Library. + +The iRRAM Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Library General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at your +option) any later version. + +The iRRAM Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public +License for more details. + +You should have received a copy of the GNU Library General Public License +along with the iRRAM Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, +MA 02111-1307, USA. +*/ +#ifndef MPFR_INTERFACE_H +#define MPFR_INTERFACE_H + +#include +#include +#include + + +# ifndef BITS_PER_MP_LIMB +# define BITS_PER_MP_LIMB GMP_LIMB_BITS +# endif + + +#define MP_min GMP_min +#define MP_max GMP_max + + +/****** Type definitions ******/ + +#define MP_type ext_mpfr_type +#define MP_int_type int_gmp_type +#define MP_rat_type rat_gmp_type + + +/****** Initialization functions ******/ + +/* Backend initialization (if necessary) */ +#define MP_initialize ext_mpfr_initialize() + +/* Initialization of MP/integer/rational variables */ +#define MP_init(z) do { z = ext_mpfr_init(); } while (0) +#define MP_int_init(z) do { z = int_gmp_init(); } while (0) +#define MP_rat_init(z) do { z = rat_gmp_init(); } while (0) + +/* Deletion of MP/integer/rational variables */ +#define MP_clear(z) ext_mpfr_free(z) +#define MP_int_clear(z) int_gmp_free(z) +#define MP_rat_clear(z) rat_gmp_free(z) + + +/****** typechanging functions ******/ +#define MP_mp_to_double(z) mpfr_get_d(z,GMP_RNDN) +#define MP_double_to_mp(d,z) \ + do { \ + mpfr_set_prec(z,53); \ + mpfr_set_d(z,d,iRRAM_mpfr_rounding_mode); \ + } while (0) + +#define MP_int_to_mp(i,z) \ + do { \ + mpfr_set_prec(z,32); \ + mpfr_set_si(z,i,iRRAM_mpfr_rounding_mode); \ + } while (0) +#define MP_int_to_INTEGER(i,z) mpz_set_si(z,i) + +#define MP_INTEGER_to_mp(i,r) ext_mpfr_set_z(r,i) +#define MP_INTEGER_to_int(z) mpz_get_si(z) + +#define MP_mp_to_INTEGER(r,i) mpfr_get_z(i,r,MPFR_RNDZ) +/* here MPFR_RNDZ is chosen as GMP does a truncation in the corresponding function */ + +#define MP_double_to_INTEGER(i,z) mpz_set_d(z,i) +#define MP_string_to_INTEGER(s,z,b) mpz_set_str(z,s,b) + +#define MP_int_to_RATIONAL(i,z) mpq_set_si(z,i,1) +#define MP_intint_to_RATIONAL(i,j,z) \ + do { \ + mpq_set_si(z,i,j); \ + mpq_canonicalize(z); \ + } while (0) +#define MP_double_to_RATIONAL(d,z) mpq_set_d(z,d) +#define MP_string_to_RATIONAL(s,z) rat_gmp_string_2_rat(z,s) +#define MP_INTEGER_to_RATIONAL(i,r) mpq_set_z(r,i) +#define MP_INTINTEGER_to_RATIONAL(i,j,r) \ + do { \ + mpq_set_num(r,i); \ + mpq_set_den(r,j); \ + mpq_canonicalize(r); \ + } while (0) + + +/* duplicate value z1 to z2, with/without initialization of z2 */ + +#define MP_duplicate_w_init(z1,z2) ext_mpfr_duplicate_w_init(z1,&(z2)) +#define MP_duplicate_wo_init(z1,z2) ext_mpfr_duplicate_wo_init(z1,z2) + +#define MP_int_duplicate_w_init(z1,z2) int_gmp_duplicate_w_init(z1,&(z2)) +#define MP_int_duplicate_wo_init(z1,z2) int_gmp_duplicate_wo_init(z1,z2) + +#define MP_rat_duplicate_w_init(z1,z2) rat_gmp_duplicate_w_init(z1,&(z2)) +#define MP_rat_duplicate_wo_init(z1,z2) rat_gmp_duplicate_wo_init(z1,z2) + +/* copy z1 to z2, but precision p is sufficient */ +#define MP_copy(z1,z2,p) ext_mpfr_duplicate_wo_init(z1,z2) + + +/* Multiple precision arithmetic, deterministic results */ +#define MP_add(z1,z2,z,p) ext_mpfr_add(z1,z2,z,p) +#define MP_sub(z1,z2,z,p) ext_mpfr_sub(z1,z2,z,p) +#define MP_mul(z1,z2,z,p) ext_mpfr_mul(z1,z2,z,p) +#define MP_div(z1,z2,z,p) ext_mpfr_div(z1,z2,z,p) +#define MP_addi(z1,z2,z,p) ext_mpfr_add_i(z1,z2,z,p) +#define MP_subi(z1,z2,z,p) ext_mpfr_sub_i(z1,z2,z,p) +#define MP_isub(z1,z2,z,p) ext_mpfr_i_sub(z1,z2,z,p) +#define MP_muli(z1,z2,z,p) ext_mpfr_mul_i(z1,z2,z,p) +#define MP_divi(z1,z2,z,p) ext_mpfr_div_i(z1,z2,z,p) +#define MP_idiv(z1,z2,z,p) ext_mpfr_i_div(z1,z2,z,p); +#define MP_abs(z1,z) ext_mpfr_abs(z1,z) + +/* Multiple precision arithmetic with multi-valued results: + The following versions of the arithmetic operations + are allowed to be multi-valued, here in the sense that + even for absolutely identical parameters there can be + different results. +*/ +#define MP_mv_add(z1,z2,z,p) MP_add(z1,z2,z,p) +#define MP_mv_sub(z1,z2,z,p) MP_sub(z1,z2,z,p) +#define MP_mv_mul(z1,z2,z,p) MP_mul(z1,z2,z,p) +#define MP_mv_div(z1,z2,z,p) MP_div(z1,z2,z,p) +#define MP_mv_addi(z1,z2,z,p) MP_addi(z1,z2,z,p) +#define MP_mv_subi(z1,z2,z,p) MP_subi(z1,z2,z,p) +#define MP_mv_isub(z1,z2,z,p) MP_isub(z1,z2,z,p) +#define MP_mv_muli(z1,z2,z,p) MP_muli(z1,z2,z,p) +#define MP_mv_divi(z1,z2,z,p) MP_divi(z1,z2,z,p) +#define MP_mv_idiv(z1,z2,z,p) MP_idiv(z1,z2,z,p) + +/* INTEGER arithmetic, deterministic results */ +#define MP_int_add(z1,z2,z) int_gmp_add(z1,z2,z) +#define MP_int_sub(z1,z2,z) int_gmp_sub(z1,z2,z) +#define MP_int_mul(z1,z2,z) int_gmp_mul(z1,z2,z) +#define MP_int_div(z1,z2,z) int_gmp_div(z1,z2,z) +#define MP_int_add_ui(z1,z2,z) int_gmp_add_ui(z1,z2,z) +#define MP_int_sub_ui(z1,z2,z) int_gmp_sub_ui(z1,z2,z) +#define MP_int_mul_si(z1,z2,z) int_gmp_mul_si(z1,z2,z) +#define MP_int_div_ui(z1,z2,z) int_gmp_div_ui(z1,z2,z) +#define MP_int_abs(z1,z) int_gmp_abs(z1,z) +#define MP_int_neg(z1,z) int_gmp_neg(z1,z) + +/* RATIONAL arithmetic, deterministic results */ +#define MP_rat_add(z1,z2,z) rat_gmp_add(z1,z2,z) +#define MP_rat_sub(z1,z2,z) rat_gmp_sub(z1,z2,z) +#define MP_rat_mul(z1,z2,z) rat_gmp_mul(z1,z2,z) +#define MP_rat_div(z1,z2,z) rat_gmp_div(z1,z2,z) +#define MP_rat_add_ui(z1,z2,z) rat_gmp_add_ui(z1,z2,z) +#define MP_rat_sub_ui(z1,z2,z) rat_gmp_sub_ui(z1,z2,z) +#define MP_rat_mul_si(z1,z2,z) rat_gmp_mul_si(z1,z2,z) +#define MP_rat_div_si(z1,z2,z) rat_gmp_div_si(z1,z2,z) +#define MP_rat_si_div(z1,z2,z) rat_gmp_si_div(z1,z2,z) +#define MP_rat_abs(z1,z) rat_gmp_abs(z1,z) + + +/* Additional integer/rational arithmetic */ +#define MP_int_sqrt(z1,z) int_gmp_sqrt(z1,z); +#define MP_int_root(z1,z2,z) int_gmp_root(z1,z2,z); +#define MP_int_power_i(z1,z2,z) int_gmp_power_i(z1,z2,z); +#define MP_int_power_ii(z1,z2,z) int_gmp_power_ii(z1,z2,z); +#define MP_int_fac(z1,z) int_gmp_fac(z1,z); +#define MP_int_modulo(z1,z2,z) int_gmp_modulo(z1,z2,z); +#define MP_int_log(z) int_gmp_log(z); +#define MP_rat_power(z1,z2,z) rat_gmp_power(z1,z2,z); +#define MP_rat_power2(z1,z2,z) rat_gmp_power_ii(z1,z2,z); +#define MP_rat_get_numerator(z1,z) mpq_get_num(z,z1) +#define MP_rat_get_denominator(z1,z) mpq_get_den(z,z1) +#define MP_rat_canon(z) mpq_canonicalize(z) + +/* MP_compare: values -1 (lessthan), 0 (equal), or 1 (greater than) */ +#define MP_compare(z1,z2) mpfr_cmp(z1,z2) +#define MP_int_compare(z1,z2) int_gmp_cmp(z1,z2) +#define MP_rat_compare(z1,z2) rat_gmp_cmp(z1,z2) + +/* MP_sign: values -1 (negative), 0 (zero), or 1 (positive) */ +#define MP_sign(z) mpfr_sgn(z) +#define MP_int_sign(z) int_gmp_sgn(z) +#define MP_rat_sign(z) rat_gmp_sgn(z) + +/* MP_equality for rational values: 0 (not equal), or nonzero (equal) */ +#define MP_rat_equal(z1,z2) mpq_equal (z1,z2) + + +/****** size information ******/ +/* int MP_size : smallest(?) value k such that 2**k > |z| */ +#define MP_size(z) ext_mpfr_size(z) +#define MP_getsize(z,s) ext_mpfr_getsize(z,(ext_mpfr_sizetype*)&s) +#define MP_int_size(z) int_gmp_size(z) + +/* truncate z1 yielding z2 */ +#define MP_truncate(z1,z) ext_mpfr_truncate(z1,z) + +/*Conversion to strings */ +#define MP_swrite(z,w) ext_mpfr_swritee(z,w) + +/* In/Out */ +#define MP_writee(z,w) ext_mpfr_writee(z,w) +#define MP_writef(z,w,d) mpfr_out_str(stdout,10,w,z,iRRAM_mpfr_rounding_mode) +#define MP_write(z,c) ext_mpfr_write(z,c) + +#define MP_int_writee(z,w) int_gmp_writee(z,w) +#define MP_int_swritee(z,w) int_gmp_swritee(z,w) +#define MP_int_writef(z,w) int_gmp_outstr(z,w) +#define MP_int_write(z,c) int_gmp_write(z,c) +#define MP_int_printf(z) int_gmp_printf(z) +#define MP_int_sprintf(z) int_gmp_sprintf(z) + +#define MP_rat_writee(z,w) rat_gmp_writee(z,w) +#define MP_rat_writef(z,w) rat_gmp_outstr(z,w) +#define MP_rat_swritee(z,w) rat_gmp_swritee(z,w) +#define MP_rat_sprintf(z) rat_gmp_sprintf(z) + +/* Statistics, optional */ + +#define MP_var_count ext_mpfr_var_count +/* #define MP_space_count */ +/* #define MP_max_space_count */ + + +/* special functions, optional for the backends */ +#define MP_sqrt(z1,z,p) ext_mpfr_sqrt(z1,z,p) +#define MP_mv_sqrt(z1,z,p) MP_sqrt(z1,z,p) +#define MP_shift(z1,z,n) ext_mpfr_shift(z1,z,n) +#define MP_int_shift(z1,z,n) int_gmp_shift(z1,z,n) +#define MP_rat_shift(z1,z,n) rat_gmp_shift(z1,z,n) + + +/***********************************************************/ +/* Declaration of those types/functions that are necessary */ +/* for user programs: */ +/***********************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef __mpfr_struct * ext_mpfr_type; +typedef struct {unsigned int mantissa; int exponent; } ext_mpfr_sizetype; +typedef mpz_ptr int_mpfr_type; + +extern __thread int ext_mpfr_var_count; +#define MaxFreeVars 1000 +extern __thread ext_mpfr_type mpfr_FreeVars[]; +extern __thread int mpfr_FreeVarCount; + +#define MPFR_PREC(x) ((x)->_mpfr_prec) +#define MPFR_SIZE(x) ((MPFR_PREC(x)-1)/BITS_PER_MP_LIMB+1) +#define MPFR_MSW_INDEX(x) ((MPFR_PREC(x)-1)/BITS_PER_MP_LIMB) + +void ext_mpfr_remove_trailing_zeroes (mpfr_t x); + +void ext_mpfr_initialize(void); + +void ext_mpfr_getsize(ext_mpfr_type z,ext_mpfr_sizetype* s); + +#ifdef __cplusplus +} +#endif + + +ext_mpfr_type ext_mpfr_init(void); + +inline ext_mpfr_type ext_mpfr_init() +{ ext_mpfr_type z; + if (mpfr_FreeVarCount > 0) { + mpfr_FreeVarCount -=1; + z =mpfr_FreeVars[mpfr_FreeVarCount]; + } else { + z = (ext_mpfr_type) malloc(sizeof (__mpfr_struct)); + mpfr_init(z); + } + ext_mpfr_var_count +=1; + +/* fprintf(stderr,"create %x\n",z); */ + + return z; +} + +void ext_mpfr_free(ext_mpfr_type z); + +inline void ext_mpfr_free(ext_mpfr_type z) +{ +/* fprintf(stderr,"delete %x\n",z); */ + if ( mpfr_FreeVarCount < MaxFreeVars ) { + mpfr_FreeVars[mpfr_FreeVarCount]=z; + mpfr_FreeVarCount +=1; + } else { + mpfr_clear(z); + free (z); + } + ext_mpfr_var_count -=1; +} + +#endif /*ifndef MPFR_INTERFACE_H */ diff --git a/includeNumOpt/iRRAM/RATIONAL.h b/includeNumOpt/iRRAM/RATIONAL.h new file mode 100644 index 0000000..92585a4 --- /dev/null +++ b/includeNumOpt/iRRAM/RATIONAL.h @@ -0,0 +1,167 @@ +/* + +iRRAM_RATIONAL.h -- declaration of the interface to rational numbers for the iRRAM library + +Copyright (C) 2005 Norbert Mueller + +This file is part of the iRRAM Library. + +The iRRAM Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Library General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at your +option) any later version. + +The iRRAM Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public +License for more details. + +You should have received a copy of the GNU Library General Public License +along with the iRRAM Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, +MA 02111-1307, USA. +*/ + +#ifndef iRRAM_RATIONAL_H +#define iRRAM_RATIONAL_H + +namespace iRRAM { + +class RATIONAL +{ +public: + +friend class INTEGER; +friend class DYADIC; +friend class REAL; + +/****** Constructors ******/ + +RATIONAL(MP_rat_type y); + +RATIONAL(); +RATIONAL(const int i); +RATIONAL(const double d); +RATIONAL(const char* s); +RATIONAL(const INTEGER& y); +//RATIONAL(const DYADIC& y); +RATIONAL(const RATIONAL& y); + +RATIONAL(const int i, const int j); +RATIONAL(const INTEGER& x, const INTEGER& y); + +/****** Copy constructor ******/ + +RATIONAL& operator = (const RATIONAL& y); +RATIONAL& operator = (const INTEGER& y); +RATIONAL& operator = (const int y); + +/****** Destructor ******/ + +~RATIONAL(); + +/****** Standard arithmetic ******/ + +friend RATIONAL operator + (const RATIONAL& x, const RATIONAL& y); +friend RATIONAL operator + (const RATIONAL& x, const int y); +friend RATIONAL operator + (const RATIONAL& x, const INTEGER& y); +friend RATIONAL operator + (const int x, const RATIONAL& y); +friend RATIONAL operator + (const INTEGER& x, const RATIONAL& y); + +friend RATIONAL& operator += ( RATIONAL& x, const RATIONAL& y); +friend RATIONAL& operator += ( RATIONAL& x, const INTEGER& y); +friend RATIONAL& operator += ( RATIONAL& x, const int y); + + +friend RATIONAL operator - (const RATIONAL& x, const RATIONAL& y); +friend RATIONAL operator - (const RATIONAL& x, const int y); +friend RATIONAL operator - (const RATIONAL& x, const INTEGER& y); +friend RATIONAL operator - (const int x, const RATIONAL& y); +friend RATIONAL operator - (const INTEGER& x, const RATIONAL& y); + +friend RATIONAL& operator -= ( RATIONAL& x, const RATIONAL& y); +friend RATIONAL& operator -= ( RATIONAL& x, const INTEGER& y); +friend RATIONAL& operator -= ( RATIONAL& x, const int y); + +friend RATIONAL operator - (const RATIONAL& x); + +friend RATIONAL operator * (const RATIONAL& x, const RATIONAL& y); +friend RATIONAL operator * (const RATIONAL& x, const int y); +friend RATIONAL operator * (const RATIONAL& x, const INTEGER& y); +friend RATIONAL operator * (const int x, const RATIONAL& y); +friend RATIONAL operator * (const INTEGER& x, const RATIONAL& y); + +friend RATIONAL& operator *= ( RATIONAL& x, const RATIONAL& y); +friend RATIONAL& operator *= ( RATIONAL& x, const INTEGER& y); +friend RATIONAL& operator *= ( RATIONAL& x, const int y); + +friend RATIONAL operator / (const RATIONAL& x, const RATIONAL& y); +friend RATIONAL operator / (const RATIONAL& x, const int y); +friend RATIONAL operator / (const RATIONAL& x, const INTEGER& y); +friend RATIONAL operator / (const int x, const RATIONAL& y); +friend RATIONAL operator / (const INTEGER& x, const RATIONAL& y); + +friend RATIONAL& operator /= ( RATIONAL& x, const RATIONAL& y); +friend RATIONAL& operator /= ( RATIONAL& x, const INTEGER& y); +friend RATIONAL& operator /= ( RATIONAL& x, const int y); + +friend RATIONAL scale (const RATIONAL& x, const int k); +friend RATIONAL abs (const RATIONAL& x); + +friend INTEGER numerator (const RATIONAL& x); +friend INTEGER denominator (const RATIONAL& x); +friend int sign (const RATIONAL& x); + +/****** Comparisons ******/ + +friend bool operator < (const RATIONAL& x, const RATIONAL& y); +friend bool operator < (const RATIONAL& x, const INTEGER& y); +friend bool operator < (const INTEGER& x, const RATIONAL& y); +friend bool operator < (const RATIONAL& x, const int y); +friend bool operator < (const int x, const INTEGER& y); + +friend bool operator <= (const RATIONAL& x, const RATIONAL& y); +friend bool operator <= (const RATIONAL& x, const INTEGER& y); +friend bool operator <= (const INTEGER& x, const RATIONAL& y); +friend bool operator <= (const RATIONAL& x, const int y); +friend bool operator <= (const int x, const INTEGER& y); + +friend bool operator > (const RATIONAL& x, const RATIONAL& y); +friend bool operator > (const RATIONAL& x, const INTEGER& y); +friend bool operator > (const INTEGER& x, const RATIONAL& y); +friend bool operator > (const RATIONAL& x, const int y); +friend bool operator > (const int x, const INTEGER& y); + +friend bool operator >= (const RATIONAL& x, const RATIONAL& y); +friend bool operator >= (const RATIONAL& x, const INTEGER& y); +friend bool operator >= (const INTEGER& x, const RATIONAL& y); +friend bool operator >= (const RATIONAL& x, const int y); +friend bool operator >= (const int x, const INTEGER& y); + +friend bool operator == (const RATIONAL& x, const RATIONAL& y); +friend bool operator == (const RATIONAL& x, const INTEGER& y); +friend bool operator == (const INTEGER& x, const RATIONAL& y); +friend bool operator == (const RATIONAL& x, const int y); +friend bool operator == (const int x, const INTEGER& y); + +friend bool operator != (const RATIONAL& x, const RATIONAL& y); +friend bool operator != (const RATIONAL& x, const INTEGER& y); +friend bool operator != (const INTEGER& x, const RATIONAL& y); +friend bool operator != (const RATIONAL& x, const int y); +friend bool operator != (const int x, const INTEGER& y); + +/****** String conversion ******/ + +friend std::string swrite (const RATIONAL& x); +friend std::string swrite (const RATIONAL& x, const int w); + +/****** Private ******/ +private: + +MP_rat_type value; +RATIONAL(MP_int_type y); +}; + +} /* ! namespace iRRAM */ + +#endif diff --git a/includeNumOpt/iRRAM/REAL.h b/includeNumOpt/iRRAM/REAL.h new file mode 100644 index 0000000..7d1d6a6 --- /dev/null +++ b/includeNumOpt/iRRAM/REAL.h @@ -0,0 +1,838 @@ +/* + +iRRAM_REAL.h -- header file for the REAL class of the iRRAM library + +Copyright (C) 2001-2013 Norbert Mueller + +This file is part of the iRRAM Library. + +The iRRAM Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Library General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at your +option) any later version. + +The iRRAM Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public +License for more details. + +You should have received a copy of the GNU Library General Public License +along with the iRRAM Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, +MA 02111-1307, USA. +*/ + +#ifndef iRRAM_REAL_H +#define iRRAM_REAL_H + +#include + +#ifdef __SSE2__at_the_moment_not_used_due_to_alignment_problems_in_gcc_4_3 +#include +#define _use_SSE2_ +#endif + +//#include + +namespace iRRAM { + +class iRRAM_double_pair{ + public: +#ifdef _use_SSE2__ + union {struct{double lower_pos,upper_neg;}; __m128d sse_data;}; +#else + double lower_pos,upper_neg; +#endif + iRRAM_double_pair(const double l,const double u) + {lower_pos=l;upper_neg=u;}; + iRRAM_double_pair(){}; +}; + + +class REAL +{ +public: + +// Constructors: ------------------------------- + +REAL(); +REAL(const int i); +REAL(const std::string s); +REAL(const char* s); +REAL(const DYADIC& y); +REAL(const REAL& y); +REAL(const double d); +REAL(const INTEGER& y); +REAL(const RATIONAL& y); + +// Copy Constructor: --------------------------- + +REAL& operator = (const REAL& y); + +// Destructor: --------------------------------- + +~REAL(); + +// Standard Arithmetic: ------------------------ + +friend REAL operator + (const REAL& x, const REAL& y); +friend REAL operator + (const REAL& x, const int n); +friend REAL operator + (const int n, const REAL& x); +friend REAL operator + (const REAL& x, const double y); +friend REAL operator + (const double y, const REAL& x); +friend REAL& operator += (REAL& x, const REAL& y); + +friend REAL operator - (const REAL& x, const REAL& y); +friend REAL operator - (const REAL& x, const int n); +friend REAL operator - (const int n, const REAL& x); +friend REAL operator - (const REAL& x, const double y); +friend REAL operator - (const double y, const REAL& x); +friend REAL operator - (const REAL& x); +friend REAL& operator -= (REAL& x, const REAL& y); + +friend REAL operator * (const REAL& x, const REAL& y); +friend REAL operator * (const REAL& x, const int n); +friend REAL operator * (const int n, const REAL& x); +friend REAL operator * (const REAL& x, const double y); +friend REAL operator * (const double y, const REAL& x); +friend REAL& operator *= (REAL& x, const REAL& y); + +friend REAL operator / (const REAL& x, const REAL& y); +friend REAL operator / (const REAL& x, const int n); +friend REAL operator / (const int n, const REAL& x); +friend REAL operator / (const REAL& x, const double y); +friend REAL operator / (const double y, const REAL& x); +friend REAL& operator /= (REAL& x, const REAL& y); + +friend REAL operator << (const REAL& x, const int n); +friend REAL operator >> (const REAL& x, const int n); + + +friend REAL sqrt (const REAL& x); + +friend REAL square (const REAL& x); + +friend REAL scale (const REAL& x, + const int k); + +// Comparisons: -------------------------------- + +friend LAZY_BOOLEAN operator < (const REAL& x, const REAL& y); +friend LAZY_BOOLEAN operator < (const REAL& x, const int y); +friend LAZY_BOOLEAN operator < (const REAL& x, const double y); +friend LAZY_BOOLEAN operator < (const REAL& x, const INTEGER& y); +friend LAZY_BOOLEAN operator < (const REAL& x, const DYADIC& y); +friend LAZY_BOOLEAN operator < (const int x, const REAL& y); +friend LAZY_BOOLEAN operator < (const double x, const REAL& y); +friend LAZY_BOOLEAN operator < (const INTEGER& x, const REAL& y); +friend LAZY_BOOLEAN operator < (const DYADIC& x, const REAL& y); + +friend LAZY_BOOLEAN operator <= (const REAL& x, const REAL& y); +friend LAZY_BOOLEAN operator <= (const REAL& x, const int y); +friend LAZY_BOOLEAN operator <= (const REAL& x, const double y); +friend LAZY_BOOLEAN operator <= (const REAL& x, const INTEGER& y); +friend LAZY_BOOLEAN operator <= (const REAL& x, const DYADIC& y); +friend LAZY_BOOLEAN operator <= (const int x, const REAL& y); +friend LAZY_BOOLEAN operator <= (const double x, const REAL& y); +friend LAZY_BOOLEAN operator <= (const INTEGER& x, const REAL& y); +friend LAZY_BOOLEAN operator <= (const DYADIC& x, const REAL& y); + +friend LAZY_BOOLEAN operator > (const REAL& x, const REAL& y); +friend LAZY_BOOLEAN operator > (const REAL& x, const int y); +friend LAZY_BOOLEAN operator > (const REAL& x, const double y); +friend LAZY_BOOLEAN operator > (const REAL& x, const INTEGER& y); +friend LAZY_BOOLEAN operator > (const REAL& x, const DYADIC& y); +friend LAZY_BOOLEAN operator > (const int x, const REAL& y); +friend LAZY_BOOLEAN operator > (const double x, const REAL& y); +friend LAZY_BOOLEAN operator > (const INTEGER& x, const REAL& y); +friend LAZY_BOOLEAN operator > (const DYADIC& x, const REAL& y); + +friend LAZY_BOOLEAN operator >= (const REAL& x, const REAL& y); +friend LAZY_BOOLEAN operator >= (const REAL& x, const int y); +friend LAZY_BOOLEAN operator >= (const REAL& x, const double y); +friend LAZY_BOOLEAN operator >= (const REAL& x, const INTEGER& y); +friend LAZY_BOOLEAN operator >= (const REAL& x, const DYADIC& y); +friend LAZY_BOOLEAN operator >= (const int x, const REAL& y); +friend LAZY_BOOLEAN operator >= (const double x, const REAL& y); +friend LAZY_BOOLEAN operator >= (const INTEGER& x, const REAL& y); +friend LAZY_BOOLEAN operator >= (const DYADIC& x, const REAL& y); + +friend LAZY_BOOLEAN operator == (const REAL& x, const REAL& y); +friend LAZY_BOOLEAN operator == (const REAL& x, const int y); +friend LAZY_BOOLEAN operator == (const REAL& x, const double y); +friend LAZY_BOOLEAN operator == (const REAL& x, const INTEGER& y); +friend LAZY_BOOLEAN operator == (const REAL& x, const DYADIC& y); +friend LAZY_BOOLEAN operator == (const int x, const REAL& y); +friend LAZY_BOOLEAN operator == (const double x, const REAL& y); +friend LAZY_BOOLEAN operator == (const INTEGER& x, const REAL& y); +friend LAZY_BOOLEAN operator == (const DYADIC& x, const REAL& y); + +friend LAZY_BOOLEAN operator != (const REAL& x, const REAL& y); +friend LAZY_BOOLEAN operator != (const REAL& x, const int y); +friend LAZY_BOOLEAN operator != (const REAL& x, const double y); +friend LAZY_BOOLEAN operator != (const REAL& x, const INTEGER& y); +friend LAZY_BOOLEAN operator != (const REAL& x, const DYADIC& y); +friend LAZY_BOOLEAN operator != (const int x, const REAL& y); +friend LAZY_BOOLEAN operator != (const double x, const REAL& y); +friend LAZY_BOOLEAN operator != (const INTEGER& x, const REAL& y); +friend LAZY_BOOLEAN operator != (const DYADIC& x, const REAL& y); + + +friend LAZY_BOOLEAN positive (const REAL& x, const int k); + +friend LAZY_BOOLEAN bound (const REAL& x, const int k); + +friend DYADIC approx (const REAL& x, const int p); +DYADIC as_DYADIC (const int p) const; +DYADIC as_DYADIC () const; + +double as_double (const int p) const; +double as_double () const { return this->as_double(53); }; + +INTEGER as_INTEGER() const; +friend REAL round2 (const REAL& x); +friend int round (const REAL& x); +friend REAL floor (const REAL& x); + +#define iRRAM_float_absolute 0 +#define iRRAM_float_relative 1 +#define iRRAM_float_show 2 +friend std::string swrite (const REAL& x, const int p, const int form); + +// Output: ------------------------------------- + +friend void rwrite (const REAL& x, const int w); +friend void rwritee (const REAL& x, const int w); +friend void rshow (const REAL& x, const int w); + +void rcheck(int n=50) const; + +friend int upperbound (const REAL& x); +friend int size (const REAL& x); + +friend REAL abs (const REAL& x); + + +// limit operators: ------------------------ + +//friend REAL limit (REAL f(int, const REAL&), +// const REAL& x); + +friend REAL limit (REAL f(int, const REAL&, const REAL&), + const REAL& x, + const REAL& y); + +friend REAL limit (REAL f(int)); + +friend REAL limit_hint (REAL f(int, const REAL&), + int hint, + const REAL& x); + +friend REAL limit_hint (REAL f(int, const REAL&, const REAL&), + int hint, + const REAL& x, + const REAL& y); + +friend REAL limit_hint (REAL f(int), + int hint); + +friend REAL limit_lip (REAL f(int, const REAL&), + int lip, + bool on_domain(const REAL&), + const REAL& x); + +friend REAL limit_lip (REAL f(int, const REAL&), + int lip(const REAL&), + const REAL& x); + +friend REAL limit_lip (REAL f(int, const REAL&, const REAL&), + int lip, + bool on_domain(const REAL&,const REAL&), + const REAL& x, + const REAL& y); + +friend REAL iterate (REAL (*)(REAL&, REAL&, const REAL&), + const REAL&, const REAL&, const REAL&); + +friend REAL iterate (REAL (*)(REAL&, REAL&), + const REAL&, const REAL&); + +friend REAL iteration (void (*)(REAL&, REAL&,const int&), + const REAL&, const REAL&,const int&); + +// reduced error propagation: ------------------------ + +friend REAL lipschitz (REAL f(const REAL&), + int lip, + bool on_domain(const REAL&), + const REAL& x); + +friend REAL lipschitz (REAL f(const REAL&), + REAL lip_f(const REAL&), + bool on_domain(const REAL&), + const REAL& x); + +friend REAL lipschitz (REAL f(const REAL&,const REAL&), + int lip, + bool on_domain(const REAL&,const REAL&), + const REAL& x, + const REAL& y); + +friend REAL lipschitz (REAL f(int, const REAL&), + int lip, + bool on_domain(int k,const REAL&), + int k, + const REAL& x); + +friend REAL lipschitz (REAL f(int, const REAL&,const REAL&), + int lip, + bool on_domain(int k,const REAL&,const REAL&), + int k, + const REAL& x, + const REAL& y); + +friend REAL lipschitz (REAL f(const REAL&), + REAL lip_f(const REAL&), + const REAL& x); + +// coexistence with other classes: ------------- + +friend class REALMATRIX; +friend class SPARSEREALMATRIX; +friend class INTEGER; +friend class DYADIC; +friend class RATIONAL; + +// for the sake of proving computational adequacy: +// if q=module(f,x,p), then |z-x|<2^q => |f(z)-f(x)| < 2^p +friend int module(REAL f(const REAL&),const REAL& x, int p); + +//friend REAL fmod (const REAL& x, const REAL& y); +// implementational issues: -------------------- + +iRRAM_double_pair dp; +MP_type value; +sizetype error; +sizetype vsize; + +public: +REAL(MP_type y, const sizetype errorinfo); +REAL(const iRRAM_double_pair& ydp); +#ifdef _use_SSE2__ +REAL(const __m128d& y_sse); +#endif +void adderror (sizetype error); +void seterror (sizetype error); +void geterror (sizetype& error) const; +void getsize (sizetype& error) const; +void to_formal_ball (DYADIC&,sizetype& error) const; +friend REAL intervall_join (const REAL& x,const REAL& y); + +// internal use: +void mp_copy(const REAL&); +void mp_copy_init(const REAL&); +void mp_make_mp(); +void mp_from_mp(const REAL& y); +void mp_from_int(const int i); +void mp_from_double(const double d); +REAL& mp_conv ()const; +REAL mp_addition (const REAL& y)const; +REAL mp_addition (const int i)const; +REAL& mp_eqaddition (const REAL& y); +REAL mp_addition (const double i)const;//fehlt noch +REAL mp_subtraction (const REAL& y)const; +REAL mp_subtraction (const int i)const; +REAL mp_invsubtraction (const int i)const; +REAL mp_multiplication (const REAL& y)const; +REAL mp_multiplication (const int y)const; +REAL& mp_eqmultiplication (const REAL& y); +REAL& mp_eqmultiplication (const int i); +REAL mp_multiplication (const double y)const; //fehlt noch +REAL mp_division (const REAL& y)const; +REAL mp_division (const int y)const; +REAL mp_division (const double y)const; +REAL mp_square()const; +REAL mp_absval()const; +REAL mp_intervall_join (const REAL& y)const; +LAZY_BOOLEAN mp_less (const REAL& y)const; + +}; + +std::string swrite(const REAL& x, const int p, const int form=iRRAM_float_absolute); + +#define USE_HIGH_LEVEL iRRAM_unlikely(iRRAM_highlevel) +// inlined versions of most important functions: + +//"private" internal constructor +inline REAL::REAL(MP_type y,const sizetype errorinfo) +{ + value=y; + error=errorinfo; + MP_getsize(value,vsize); +} + +//"private" internal constructor +inline REAL::REAL(const iRRAM_double_pair& ydp) +{ + value=NULL; + dp = ydp; +} + +#ifdef _use_SSE2__ +inline REAL::REAL(const __m128d& y_sse) +{ + value=NULL; + dp.sse_data=y_sse; +} +#endif + +inline REAL::~REAL() +{ + if ( iRRAM_unlikely(value) ) { MP_clear(value); value=NULL;} +} + +inline REAL::REAL() +{ + value=NULL; + dp.lower_pos=0.0; + dp.upper_neg=0.0; + if ( USE_HIGH_LEVEL ) mp_from_int(0); +} + +inline REAL::REAL(const int i) +{ + value=NULL; + dp.lower_pos=i; + dp.upper_neg=-dp.lower_pos; + if ( USE_HIGH_LEVEL ) mp_from_int(i); +} + +inline REAL::REAL(const double d) +{ + if ( !std::isfinite(d) ) throw iRRAM_Numerical_Exception(iRRAM_conversion_from_infinite); + value=NULL; + dp.lower_pos=d; + dp.upper_neg=-dp.lower_pos; + if ( USE_HIGH_LEVEL ) mp_from_double(d); +} + +inline REAL::REAL(const REAL& y){ + value=NULL; + dp=y.dp; + if ( iRRAM_unlikely(y.value) ) mp_copy_init(y); +} + +inline REAL& REAL::mp_conv()const{ + if (! value) (const_cast(*this)).mp_make_mp(); + return const_cast(*this); +} + +inline REAL& REAL::operator = (const REAL& y) { + if ( iRRAM_unlikely(value||y.value) ){ + if ( value&&y.value ){ + this->mp_copy(y); + return (*this); + } + if ( y.value ){ + if (ACTUAL_STACK.prec_step==0) this->mp_from_mp(y); + else this->mp_copy_init(y); + return (*this); + } + dp=y.dp; + mp_make_mp(); + return (*this); + } + dp=y.dp; + return (*this); +} + +inline REAL operator << (const REAL& x, const int n) { + return scale(x,n); +} + +inline REAL operator >> (const REAL& x, const int n) { + return scale(x,-n); +} + +inline REAL operator + (const REAL& x, const REAL& y) +{ + if ( iRRAM_unlikely ( x.value||y.value ) ) + { return x.mp_conv().mp_addition(y.mp_conv()); } +#ifdef _use_SSE2__ + return REAL(_mm_add_pd(x.dp.sse_data,y.dp.sse_data)); +#else + return REAL(iRRAM_double_pair(x.dp.lower_pos+y.dp.lower_pos,x.dp.upper_neg+y.dp.upper_neg)); +#endif +} + +inline REAL operator + (const REAL& x, const int i) +{ + if (iRRAM_unlikely( x.value ) ) + { return x.mp_addition(i); } + iRRAM_double_pair z(x.dp.lower_pos+i,x.dp.upper_neg-i); + return REAL(z); +} + +inline REAL operator + (const REAL& x, const double d) +{ + return x+(REAL)d; +// if (iRRAM_unlikely( x.value ) ) +// { return x.mp_addition(d); } +// iRRAM_double_pair z(x.dp.lower_pos+d,x.dp.upper_neg-d); +// return REAL(z); +} + +inline REAL& operator += (REAL& x,const REAL& y) +{ + if ( iRRAM_unlikely ( x.value||y.value ) ) + { x.mp_conv().mp_eqaddition(y.mp_conv()); return x;} +#ifdef _use_SSE2__ + x.dp.sse_data = _mm_add_pd(x.dp.sse_data,y.dp.sse_data); +#else + x.dp.lower_pos+=y.dp.lower_pos; + x.dp.upper_neg+=y.dp.upper_neg; +#endif + return x; +} + +inline REAL operator + (const int i, const REAL& x) +{ + return (x+i); +} + +inline REAL operator + (const double d, const REAL& x) +{ + return (x+d); +} + +inline REAL operator - (const REAL& x, const REAL& y) +{ + if ( iRRAM_unlikely ( x.value||y.value ) ) + { return x.mp_conv().mp_subtraction(y.mp_conv()); } + iRRAM_double_pair z(x.dp.lower_pos+y.dp.upper_neg,x.dp.upper_neg+y.dp.lower_pos); + return REAL(z); +} + +inline REAL operator - (const REAL& x, const int n) +{ + if ( iRRAM_unlikely ( x.value ) ) + { return x.mp_subtraction(n); } + iRRAM_double_pair z(x.dp.lower_pos-n,x.dp.upper_neg+n); + return REAL(z); +} + +inline REAL operator - (const int n, const REAL& x) +{ + if ( iRRAM_unlikely ( x.value ) ) + { return x.mp_invsubtraction(n); } + iRRAM_double_pair z(x.dp.upper_neg+n,x.dp.lower_pos-n); + return REAL(z); +} + +inline REAL operator - (const REAL& x) +{ + if ( iRRAM_unlikely ( x.value ) ) + { return x.mp_invsubtraction(int(0)); } + iRRAM_double_pair z(-x.dp.lower_pos,-x.dp.upper_neg); + return REAL(z); +} + +//not optimized yet, maybe MPFR contains "x-d" +inline REAL operator - (const REAL& x, const double d) +{ + return x - REAL(d); +} + +//not optimized yet, maybe MPFR contains "d-x" +inline REAL operator - (const double d, const REAL& x) +{ + return REAL(d) - x; +} + +inline REAL& operator -= (REAL& x, const REAL& y){ + x=x-y; + return x; +} + + +// inline double my_fmin(const double& x,const double& y) +// { return x= 0 && y.dp.lower_pos >= 0) { + z.lower_pos = x.dp.lower_pos * y.dp.lower_pos; + z.upper_neg = (-x.dp.upper_neg) * y.dp.upper_neg; + } else if (x.dp.upper_neg >= 0 && y.dp.upper_neg >= 0) { + z.lower_pos = x.dp.upper_neg * y.dp.upper_neg; + z.upper_neg = (-x.dp.lower_pos) * y.dp.lower_pos; + } else if (x.dp.upper_neg >= 0 && y.dp.lower_pos >= 0) { + z.lower_pos = x.dp.lower_pos * (-y.dp.upper_neg); + z.upper_neg = x.dp.upper_neg * y.dp.lower_pos; + } else if (x.dp.lower_pos >= 0 && y.dp.upper_neg >= 0 ) { + z.lower_pos = (-x.dp.upper_neg) * y.dp.lower_pos; + z.upper_neg = x.dp.lower_pos * y.dp.upper_neg; + } else { + z.lower_pos = fmin((-x.dp.upper_neg)*y.dp.lower_pos,x.dp.lower_pos*(-y.dp.upper_neg)); + z.upper_neg = fmin((-x.dp.upper_neg)*y.dp.upper_neg,x.dp.lower_pos*(-y.dp.lower_pos)); + } + return REAL(z); +} + +inline REAL operator * (const REAL& x, const int n) +{ + if ( iRRAM_unlikely ( x.value) ) + { return x.mp_multiplication(n); } + iRRAM_double_pair z; + if ( n >= 0) { + z.lower_pos = x.dp.lower_pos * n; + z.upper_neg = x.dp.upper_neg * n; + } else { + z.lower_pos = (-x.dp.upper_neg) * n; + z.upper_neg = (-x.dp.lower_pos) * n; + } + return REAL(z); +} + + +inline REAL operator * (const int n, const REAL& x){ + return (x*n); +} + +inline REAL& operator *= (REAL& x, const REAL& y){ + x=x*y; + return x; +} + +//not optimized yet, maybe MPFR contains "x*d" +inline REAL operator * (const REAL& x, const double d) +{ + return x * REAL(d); +} + +inline REAL operator * (const double d, const REAL& x) +{ + return x * d; +} + +inline REAL& operator *= (REAL& x, const int n){ + if ( iRRAM_unlikely ( x.value) ) + { x=x.mp_multiplication(n); return x;} + if ( n >= 0) { + x.dp.lower_pos = x.dp.lower_pos * n; + x.dp.upper_neg = x.dp.upper_neg * n; + } else { + double tmp = (-x.dp.upper_neg) * n; + x.dp.upper_neg = (-x.dp.lower_pos) * n; + x.dp.lower_pos = tmp; + } + return x; +} + +inline REAL operator / (const REAL& x, const REAL& y) { + if ( iRRAM_unlikely ( x.value||y.value ) ) + { return x.mp_conv().mp_division(y.mp_conv()); } + iRRAM_double_pair z; + if (y.dp.lower_pos > 0.0 ) { + if (x.dp.lower_pos > 0.0 ) { + z.lower_pos = x.dp.lower_pos/(-y.dp.upper_neg); + z.upper_neg = x.dp.upper_neg/y.dp.lower_pos; + } else if (x.dp.upper_neg > 0.0){ + z.lower_pos = x.dp.lower_pos/y.dp.lower_pos; + z.upper_neg = x.dp.upper_neg/(-y.dp.upper_neg); + } else { + z.lower_pos = x.dp.lower_pos/y.dp.lower_pos; + z.upper_neg = x.dp.upper_neg/y.dp.lower_pos; + } + } else if (y.dp.upper_neg > 0.0) { + if (x.dp.lower_pos > 0.0 ) { + z.lower_pos = x.dp.upper_neg/y.dp.upper_neg; + z.upper_neg = (-x.dp.lower_pos)/y.dp.lower_pos; + } else if (x.dp.upper_neg > 0.0){ + z.lower_pos = (-x.dp.upper_neg)/y.dp.lower_pos; + z.upper_neg = x.dp.lower_pos/y.dp.upper_neg; + } else { + z.lower_pos = x.dp.upper_neg/y.dp.upper_neg; + z.upper_neg = x.dp.lower_pos/y.dp.upper_neg; + } + } else { + return x.mp_conv().mp_division(y.mp_conv()); // containing zero... + } + return REAL(z); +} + +inline REAL operator / (const int n, const REAL& y) { + return REAL(n)/y; +} +inline REAL operator / (const REAL& x, const int n) { + if ( iRRAM_unlikely ( x.value ) ) + { return x.mp_division(n); } + iRRAM_double_pair z; + if (n > 0 ) { +#ifdef _use_SSE2__ + __m128d n_sse= _mm_set_pd1(double(n)); + n_sse=_mm_div_pd(x.dp.sse_data,n_sse); + return REAL(n_sse); +#else + z.lower_pos = x.dp.lower_pos/n, + z.upper_neg = x.dp.upper_neg/n; +#endif + } else if (n < 0) { + z.lower_pos = (-x.dp.upper_neg)/n; + z.upper_neg = (-x.dp.lower_pos)/n; + } else { + return x.mp_conv().mp_division(0); // containing zero... + } + return REAL(z); +} + + +//not optimized yet, maybe MPFR contains "x/d" +inline REAL operator / (const REAL& x, const double d) +{ + return x / REAL(d); +} + +//not optimized yet, maybe MPFR contains "d/x" +inline REAL operator / (const double d, const REAL& x) +{ + return REAL(d) / x; +} + +inline REAL& operator /= (REAL& x, const REAL& y){ + x=x/y; + return x; +} + +inline REAL& operator /= (REAL& x, const int n){ + x=x/n; + return x; +} + +inline REAL square (const REAL& x) +{ + if ( iRRAM_unlikely ( x.value ) ) + { return x.mp_square(); } + iRRAM_double_pair z; + if (x.dp.lower_pos >= 0 ) { + z.lower_pos = x.dp.lower_pos * x.dp.lower_pos; + z.upper_neg = (-x.dp.upper_neg) * x.dp.upper_neg; + } else if (x.dp.upper_neg >= 0 ) { + z.lower_pos = x.dp.upper_neg * x.dp.upper_neg; + z.upper_neg = (-x.dp.lower_pos) * x.dp.lower_pos; + } else if (x.dp.lower_pos (-y.dp.upper_neg)) return false; + return LAZY_BOOLEAN::BOTTOM; +} + + +inline LAZY_BOOLEAN operator < (const REAL& x, const int y){ return (x (const REAL& x, const REAL& y){ return (y (const REAL& x, const int y){ return (x>REAL(y)); } +inline LAZY_BOOLEAN operator > (const REAL& x, const double y){ return (x>REAL(y)); } +inline LAZY_BOOLEAN operator > (const REAL& x, const INTEGER& y){ return (x>REAL(y)); } +inline LAZY_BOOLEAN operator > (const REAL& x, const DYADIC& y){ return (x>REAL(y)); } +inline LAZY_BOOLEAN operator > (const int x, const REAL& y){ return (REAL(x)>y); } +inline LAZY_BOOLEAN operator > (const double x, const REAL& y){ return (REAL(x)>y); } +inline LAZY_BOOLEAN operator > (const INTEGER& x, const REAL& y){ return (REAL(x)>y); } +inline LAZY_BOOLEAN operator > (const DYADIC& x, const REAL& y){ return (REAL(x)>y); } + +inline LAZY_BOOLEAN operator >= (const REAL& x, const REAL& y){ return (y= (const REAL& x, const int y){ return (x>=REAL(y)); } +inline LAZY_BOOLEAN operator >= (const REAL& x, const double y){ return (x>=REAL(y)); } +inline LAZY_BOOLEAN operator >= (const REAL& x, const INTEGER& y){ return (x>=REAL(y)); } +inline LAZY_BOOLEAN operator >= (const REAL& x, const DYADIC& y){ return (x>=REAL(y)); } +inline LAZY_BOOLEAN operator >= (const int x, const REAL& y){ return (REAL(x)>=y); } +inline LAZY_BOOLEAN operator >= (const double x, const REAL& y){ return (REAL(x)>=y); } +inline LAZY_BOOLEAN operator >= (const INTEGER& x, const REAL& y){ return (REAL(x)>=y); } +inline LAZY_BOOLEAN operator >= (const DYADIC& x, const REAL& y){ return (REAL(x)>=y); } + +inline LAZY_BOOLEAN operator == (const REAL& x, const REAL& y){ return (y 0.0 ) + return REAL(iRRAM_double_pair(x.dp.lower_pos,x.dp.upper_neg)); + if (x.dp.upper_neg > 0.0 ) + return REAL(iRRAM_double_pair(x.dp.upper_neg,x.dp.lower_pos)); + if (x.dp.lower_pos > x.dp.upper_neg) + return REAL(iRRAM_double_pair(0.0,x.dp.upper_neg)); + return REAL(iRRAM_double_pair(0.0,x.dp.lower_pos)); +} + +// #include "INTEGER.h" +// +// REAL fmod (const REAL& x, const REAL& y); // 不需要, 直接调用modulo + +// inline REAL intervall_join (const REAL& x,const REAL& y){ +// if ( iRRAM_unlikely ( x.value||y.value ) ) +// { return x.mp_conv().mp_intervall_join(y.mp_conv()); } +// iRRAM_double_pair z; +// if (x.dp.lower_pos < y.dp.lower_pos ) +// z.dp.lower_pos=x.dp.lower_pos +// else +// z.dp.lower_pos=y.dp.lower_pos; +// if (x.dp.upper_neg < y.dp.upper_neg ) +// z.dp.upper_neg=x.dp.upper_neg +// else +// z.dp.upper_neg=y.dp.upper_neg; +// return REAL(z); +// } + +} // namespace iRRAM + +#endif diff --git a/includeNumOpt/iRRAM/REALMATRIX.h b/includeNumOpt/iRRAM/REALMATRIX.h new file mode 100644 index 0000000..2d033bb --- /dev/null +++ b/includeNumOpt/iRRAM/REALMATRIX.h @@ -0,0 +1,136 @@ +/* + +iRRAM_REALMATRIX.h -- header file for the REALMATRIX class of the iRRAM library + +Copyright (C) 2001-2004 Norbert Mueller + +This file is part of the iRRAM Library. + +The iRRAM Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Library General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at your +option) any later version. + +The iRRAM Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public +License for more details. + +You should have received a copy of the GNU Library General Public License +along with the iRRAM Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, +MA 02111-1307, USA. +*/ + +#ifndef iRRAM_REALMATRIX_H +#define iRRAM_REALMATRIX_H + +namespace iRRAM { + +class REALMATRIX +{ +public: +// Constructors: ------------------------------- + +REALMATRIX(unsigned int rows,unsigned int columns); +REALMATRIX(); +REALMATRIX(const REALMATRIX& y); +// Copy Constructor: --------------------------- + +REALMATRIX& operator = (const REALMATRIX& y); + +// Destructor: --------------------------------- + +~REALMATRIX(); + +// Access to matrix elements: ------------------ + +REAL& operator () (unsigned int row, + unsigned int column) const; + +REAL& element (unsigned int row, + unsigned int column) const; + +// Standard Arithmetic: ------------------------ + +friend REALMATRIX operator + (const REALMATRIX& x, + const REALMATRIX& y); +friend REALMATRIX operator - (const REALMATRIX& x, + const REALMATRIX& y); +friend REALMATRIX operator * (const REALMATRIX& x, + const REALMATRIX& y); +friend REALMATRIX operator / (const REALMATRIX& x, + const REALMATRIX& y); + +// Arithmetic with Scalar: --------------------- +friend REALMATRIX operator * (const REALMATRIX& x, + const REAL& y); +inline friend REALMATRIX operator * (const REAL& y, + const REALMATRIX& x) + {return x*y;}; + +friend REALMATRIX operator / (const REALMATRIX& x, + const REAL& y); + +// Information on Dimensions: ------------------ + +friend inline unsigned int rows (const REALMATRIX& x) + {return x.maxrow;}; +friend inline unsigned int columns (const REALMATRIX& x) + {return x.maxcolumn;}; + +friend int bound (const REALMATRIX& x, + const int k); + +// Linear Algebra: ----------------------------- + +friend REALMATRIX eye (unsigned int rows); +friend REALMATRIX zeroes (unsigned int rows, + unsigned int columns); +friend REALMATRIX ones (unsigned int rows, + unsigned int columns); +friend REAL maxnorm (const REALMATRIX& x); +friend REAL rowsumnorm (const REALMATRIX& x); +friend REAL colsumnorm (const REALMATRIX& x); + +friend REALMATRIX solve ( + REALMATRIX& lside, + REALMATRIX& rside, + int use_pivot); + +// Limits: -------------------------- + +friend REALMATRIX limit_lip (REALMATRIX f(int, const REALMATRIX&), + int lip, + bool on_domain(const REALMATRIX&), + const REALMATRIX& x); + + +public: +REAL* values; +unsigned int maxrow,maxcolumn; +void adderror (sizetype error); +void seterror (sizetype error); +void geterror (sizetype& error) const; +}; + +REALMATRIX eye (unsigned int rows); +REALMATRIX zeroes (unsigned int rows, + unsigned int columns); +REALMATRIX ones (unsigned int rows, + unsigned int columns); +REAL maxnorm (const REALMATRIX& x); +REAL rowsumnorm (const REALMATRIX& x); +REAL colsumnorm (const REALMATRIX& x); +REALMATRIX solve ( + REALMATRIX& lside, + REALMATRIX& rside, + int use_pivot); +REALMATRIX limit_lip (REALMATRIX f(int, const REALMATRIX&), + int lip, + bool on_domain(const REALMATRIX&), + const REALMATRIX& x); + +} // namespace iRRAM + +#endif diff --git a/includeNumOpt/iRRAM/SPARSEREALMATRIX.h b/includeNumOpt/iRRAM/SPARSEREALMATRIX.h new file mode 100644 index 0000000..709e24f --- /dev/null +++ b/includeNumOpt/iRRAM/SPARSEREALMATRIX.h @@ -0,0 +1,134 @@ +/* + +iRRAM_SPARSEREALMATRIX.h -- header file for the SPARSEREALMATRIX class + of the iRRAM library + +Copyright (C) 2001-2004 Norbert Mueller + +This file is part of the iRRAM Library. + +The iRRAM Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Library General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at your +option) any later version. + +The iRRAM Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public +License for more details. + +You should have received a copy of the GNU Library General Public License +along with the iRRAM Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, +MA 02111-1307, USA. +*/ + +#ifndef iRRAM_SPARSEREALMATRIX_H +#define iRRAM_SPARSEREALMATRIX_H + +namespace iRRAM { + +class SPM_ELEMENT +{ public: +REAL value; +unsigned int rowindex; +unsigned int colindex; +SPM_ELEMENT* nextcol; +SPM_ELEMENT* nextrow; +}; + + +class SPARSEREALMATRIX +{ +public: +// Constructors: ------------------------------- + +SPARSEREALMATRIX(unsigned int rows,unsigned int columns); +SPARSEREALMATRIX(); +SPARSEREALMATRIX(const SPARSEREALMATRIX& y); +// Copy Constructor: --------------------------- + +SPARSEREALMATRIX& operator = (const SPARSEREALMATRIX& y); + +// Destructor: --------------------------------- + +~SPARSEREALMATRIX(); +void clear(); +void free(); + +// Access to matrix elements: ------------------ + +friend void sparse_set(SPARSEREALMATRIX& m,unsigned int i,unsigned int j,const REAL& x); +friend void sparse_unset(SPARSEREALMATRIX& m,unsigned int i,unsigned int j); +friend SPM_ELEMENT* sparse_get_ptr(SPARSEREALMATRIX& m,unsigned int i,unsigned int j); + +REAL operator () (unsigned int row, + unsigned int column); + + +// Standard Arithmetic: ------------------------ + +friend SPARSEREALMATRIX operator + (const SPARSEREALMATRIX& x, + const SPARSEREALMATRIX& y); +friend SPARSEREALMATRIX operator - (const SPARSEREALMATRIX& x, + const SPARSEREALMATRIX& y); +friend SPARSEREALMATRIX operator * (const SPARSEREALMATRIX& x, + const SPARSEREALMATRIX& y); +friend SPARSEREALMATRIX operator / (const SPARSEREALMATRIX& x, + const SPARSEREALMATRIX& y); + +// Arithmetic with Scalar: --------------------- +friend SPARSEREALMATRIX operator * (const SPARSEREALMATRIX& x, + const REAL& y); +inline friend SPARSEREALMATRIX operator * (const REAL& y, + const SPARSEREALMATRIX& x) + {return x*y;}; + +friend SPARSEREALMATRIX operator / (const SPARSEREALMATRIX& x, + const REAL& y); + +// Information on Dimensions: ------------------ + +friend inline unsigned int rows (const SPARSEREALMATRIX& x) + {return x.maxrow;}; +friend inline unsigned int columns (const SPARSEREALMATRIX& x) + {return x.maxcolumn;}; + +friend int bound (const SPARSEREALMATRIX& x, + const int k); + +// Linear Algebra: -------------------------- + +friend SPARSEREALMATRIX sparse_eye (unsigned int rows); +friend SPARSEREALMATRIX sparse_zeroes (unsigned int rows, + unsigned int columns); +friend SPARSEREALMATRIX sparse_ones (unsigned int rows, + unsigned int columns); +friend REAL maxnorm (const SPARSEREALMATRIX& x); +friend REAL rowsumnorm (const SPARSEREALMATRIX& x); +friend REAL colsumnorm (const SPARSEREALMATRIX& x); + +friend SPARSEREALMATRIX solve ( + SPARSEREALMATRIX& lside, + SPARSEREALMATRIX& rside, + int use_pivot); + +// Limits: -------------------------- + +friend SPARSEREALMATRIX limit_lip (SPARSEREALMATRIX f(int, const SPARSEREALMATRIX&), + int lip, + const SPARSEREALMATRIX& x); + +//private: +SPM_ELEMENT** rowvector; +SPM_ELEMENT** colvector; +SPM_ELEMENT* hotspot; +unsigned int maxrow,maxcolumn,filled; +void adderror (sizetype error); +void seterror (sizetype error); +void geterror (sizetype& error) const; +}; + +} // namespace iRRAM + +#endif diff --git a/includeNumOpt/iRRAM/STREAMS.h b/includeNumOpt/iRRAM/STREAMS.h new file mode 100644 index 0000000..4210dcd --- /dev/null +++ b/includeNumOpt/iRRAM/STREAMS.h @@ -0,0 +1,184 @@ +/* + +iRRAM_STREAMS.h -- interface to the C++-style IO for the iRRAM library + +Copyright (C) 2004-2009 Norbert Mueller + +This file is part of the iRRAM Library. + +The iRRAM Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Library General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at your +option) any later version. + +The iRRAM Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public +License for more details. + +You should have received a copy of the GNU Library General Public License +along with the iRRAM Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, +MA 02111-1307, USA. +*/ + +#ifndef iRRAM_STREAMS_H +#define iRRAM_STREAMS_H + +#include +#include +#include +#include +#include + +namespace iRRAM { + +struct _SetRwidth { int _M_n; }; + +inline _SetRwidth setRwidth(int __n) { + _SetRwidth __x; + __x._M_n = __n; + return __x; +} + +struct _SetRflags { int _M_n; }; + +inline _SetRflags setRflags(int __n) { + _SetRflags __x; + __x._M_n = __n; + return __x; +} + +class rstream { +public: + static __thread long long requests; + static __thread long long outputs; + // the two counters are used to determine whether + // output is actually produced. +}; + +class orstream :public rstream +{ +public: + bool fail(); + bool eof(); + bool bad(); + bool good(); + operator bool(); + friend bool operator !(orstream&); + unsigned int real_w; + unsigned int real_f; + + orstream(std::string s, std::ios::openmode mod=std::ios::out); + ~orstream(); + + bool is_open(); + void open(std::string s, std::ios::openmode mod=std::ios::out); + void close(); + + orstream& operator<<(const bool b); + orstream& operator<<(const char* ch); + orstream& operator<<(const short i); + orstream& operator<<(const unsigned short i); + orstream& operator<<(const int i); + orstream& operator<<(const unsigned int i); + orstream& operator<<(const long i); + orstream& operator<<(const unsigned long i); + orstream& operator<<(const long long i); + orstream& operator<<(const unsigned long long i); + orstream& operator<<(const double d); + orstream& operator<<(const float d); + orstream& operator<<(const std::string& s); + orstream& operator<<(const REAL& r); + orstream& operator<<(const RATIONAL& r); + orstream& operator<<(const INTEGER& r); + orstream& operator<<(const DYADIC& d); + + orstream& operator<<(decltype(std::setw(0))); + orstream& operator<<(decltype(std::setprecision(0))); + orstream& operator<<(decltype(std::setfill('*'))); + orstream& operator<<(decltype(std::setiosflags(std::ios_base::dec))); + orstream& operator<<(decltype(std::resetiosflags(std::ios_base::dec))); + orstream& operator<<(decltype(std::setbase(0))); + + orstream& operator<<(_SetRwidth); + orstream& operator<<(_SetRflags); + orstream& operator<<(std::ostream&(std::ostream&) ); + +// the following should be "private:" + + orstream(); + // Default constructor, only for "rout": Will select cout as target. + + orstream(std::ostream *target, bool respect_iteration); + // Internal constructor, only for "cout", "cerr", and "clog". + + void rewind(); + // this will reset the requests counter. + void reset(); + // this will reset both counters. + + std::ostream *target; + bool _respect_iteration; + + + +}; + +class irstream :public rstream +{ +public: + bool fail(); + bool eof(); + bool bad(); + bool good(); + operator bool(); + friend bool operator !(irstream&); + + irstream(std::string s, std::ios::openmode mod=std::ios::in); + ~irstream(); + + bool is_open(); + void open(std::string s, std::ios::openmode mod=std::ios::in); + void close(); + + irstream& operator>>(bool& i); + irstream& operator>>(short& i); + irstream& operator>>(unsigned short& i); + irstream& operator>>(int& i); + irstream& operator>>(unsigned int& i); + irstream& operator>>(long& i); + irstream& operator>>(unsigned long& i); + irstream& operator>>(double& d); + irstream& operator>>(float& d); + irstream& operator>>(long long& d); + irstream& operator>>(unsigned long long& d); + irstream& operator>>(std::string& s); + irstream& operator>>(REAL& d); + irstream& operator>>(INTEGER& d); + irstream& operator>>(DYADIC& d); + + /* these are not implemented: */ + irstream& operator>>(decltype(std::setw(0))); + irstream& operator>>(decltype(std::setprecision(0))); + irstream& operator>>(decltype(std::setfill('*'))); + irstream& operator>>(decltype(std::setiosflags(std::ios_base::dec))); + irstream& operator>>(decltype(std::resetiosflags(std::ios_base::dec))); + irstream& operator>>(decltype(std::setbase(0))); + +// the following should be "private:" + irstream(); + +private: + std::istream *target; + +}; + +extern irstream cin; +extern orstream cout; +extern orstream cerr; +extern orstream clog; + +} + +#endif diff --git a/includeNumOpt/iRRAM/SWITCHES.h b/includeNumOpt/iRRAM/SWITCHES.h new file mode 100644 index 0000000..5135845 --- /dev/null +++ b/includeNumOpt/iRRAM/SWITCHES.h @@ -0,0 +1,115 @@ +/* + +iRRAM/SWITCHES.h -- header file for SWITCHES class of the iRRAM library + +Copyright (C) 2001-2013 Norbert Mueller + +This file is part of the iRRAM Library. + +The iRRAM Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Library General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at your +option) any later version. + +The iRRAM Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public +License for more details. + +You should have received a copy of the GNU Library General Public License +along with the iRRAM Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, +MA 02111-1307, USA. +*/ +/****************************************************************************/ +// Definition of switches +// +// The iRRAM uses "switches" that start with a default behaviour. +// Their value can be changed by declaring a variable of the corresponding type. +// This change is effective until an other variable of the type is declared or the +// variable is destroyed. +// With the end of the lifetime of a variable, the previous behaviour will be restored. +// +// Such switches exist for: +// - explicit declaration of single_valued behaviour of a code section despite multi-valued operations +// - switching the precision policy to absolute or relative precision +// - temporary increase or decrease of the working precision for REAL +// - declaration of the working precision of DYADIC operators (see DYACIC.h) +// +// The switches are thread-specific. +// +/****************************************************************************/ + +#ifndef iRRAM_SWITCHES_H +#define iRRAM_SWITCHES_H + +#include + +namespace iRRAM { + + extern int iRRAM_prec_array[]; + extern const int iRRAM_prec_steps; + +// explicit declaration of single_valued behaviour of a code section despite multi-valued operations +// +// single_valued code --> all possible computation paths again lead to single-valued function +// +// obsoletes continous_begin(), continous_end +class single_valued +{ +int saved; +public: + inline single_valued(){ saved=ACTUAL_STACK.inlimit++; } + inline ~single_valued(){ ACTUAL_STACK.inlimit=saved; } +}; + + +// switching the precision policy to absolute or relative precision +// +// precision_mode code(0) --> work with error control based on absolute precision +// precision_mode code(1) --> work with error control based on relative precision +// +// obsoletes precision_policy() +class precision_mode +{ +int saved; +public: + inline precision_mode(int policy){ + saved=ACTUAL_STACK.prec_policy; + ACTUAL_STACK.prec_policy=policy; } + inline ~precision_mode(){ACTUAL_STACK.prec_policy=saved; } +}; + +// temporary increase of the working precision +// +// stiff code --> temporarily work with next precision step +// stiff code(n) --> temporarily work with precision n steps higher (n>0) or lower (n<0) +// +// obsoletes stiff_begin(), stiff_end() +class stiff +{ + int saved; + + static inline void set_prec_step(int n) + { + if (n<1) n=1; + if (iRRAM_prec_steps <= n) n = iRRAM_prec_steps-1; + ACTUAL_STACK.prec_step = n; + ACTUAL_STACK.actual_prec = iRRAM_prec_array[ACTUAL_STACK.prec_step]; + iRRAM_highlevel = (ACTUAL_STACK.prec_step > 1); + } +public: + explicit inline stiff(int n = 1) { + saved = ACTUAL_STACK.prec_step; + set_prec_step(ACTUAL_STACK.prec_step + n); + } + inline ~stiff() { + set_prec_step(saved); + } + stiff(const stiff &) = delete; + stiff operator=(const stiff &) = delete; +}; + +} // namespace iRRAM + +#endif diff --git a/includeNumOpt/iRRAM/cache.h b/includeNumOpt/iRRAM/cache.h new file mode 100644 index 0000000..bd304e5 --- /dev/null +++ b/includeNumOpt/iRRAM/cache.h @@ -0,0 +1,138 @@ +/* + +iRRAM_cache.h -- caching routines for the iterative structure of the iRRAM library + +Copyright (C) 2001-2003 Norbert Mueller + +This file is part of the iRRAM Library. + +The iRRAM Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Library General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at your +option) any later version. + +The iRRAM Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public +License for more details. + +You should have received a copy of the GNU Library General Public License +along with the iRRAM Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, +MA 02111-1307, USA. +*/ + +#ifndef iRRAM_CACHE_H +#define iRRAM_CACHE_H + +#include + +namespace iRRAM { + +inline void noclearfct(void*){} +inline void MPclear(void* x){MP_clear(*(MP_type*)(x));} +inline void MPIclear(void* x){MP_int_clear(*(MP_int_type*)(x));} + +class iRRAM_cache_type{ +public: +virtual void clear()=0; +virtual void rewind()=0; +}; + +class cachelist{public: +iRRAM_cache_type* id[50]; +}; + +extern __thread cachelist * cache_active; +extern __thread int max_active; + +template class iRRAM_cache : public iRRAM_cache_type +{ +public: +DATA *data; +unsigned int current,end,size; +bool active; + +iRRAM_cache(){active=false;data=NULL;size=0;end=0;current=0;}; + +void put(const DATA& x){ + if (iRRAM_unlikely(!active)){activate();} + if ( iRRAM_unlikely(end>=size)){ + if ( iRRAM_unlikely(size> 1000000000) ) + throw iRRAM_Numerical_Exception(iRRAM_cacheerror_test); + DATA* temp=data; + data=new DATA[2*size]; + for (unsigned int i=0; i< size;i++) data[i]=temp[i]; + size=2*size; + delete []temp; + } + data[end++]=x; + current++; +}; + +bool get(DATA& x){ + if (current>=end)return false; + x=data[current++]; + return true; +} + +void modify(DATA& x){ + data[current-1]=x; +} + +void rewind(){ + current=0; +}; + +void clear(){ +#if clearfct!=noclearfct + //if (clearfct!=noclearfct) { + for (current=0;currentid[max_active++]=this; + current=0; + end=0; +}; + +}; + +class iRRAM_thread_data_class { public: + +iRRAM_cache cache_b; +iRRAM_cache cache_sh; +iRRAM_cache cache_ush; +iRRAM_cache cache_i; +iRRAM_cache cache_l; +iRRAM_cache cache_ul; +iRRAM_cache cache_d; +iRRAM_cache cache_ll; +iRRAM_cache cache_ui; +iRRAM_cache cache_ull; +iRRAM_cache cache_s; +iRRAM_cache cache_f; +iRRAM_cache cache_v; +iRRAM_cache cache_mp; +iRRAM_cache cache_mpi; +iRRAM_cache cache_os; +iRRAM_cache cache_is; + +}; + +extern __thread iRRAM_thread_data_class *iRRAM_thread_data_address; + + +} // namespace iRRAM + +#endif //define iRRAM_CACHE_H diff --git a/includeNumOpt/iRRAM/core.h b/includeNumOpt/iRRAM/core.h new file mode 100644 index 0000000..f75bc8f --- /dev/null +++ b/includeNumOpt/iRRAM/core.h @@ -0,0 +1,605 @@ +/* + +iRRAM_core.h -- basic file for the errorsize arithmetic + and for the templates in the iRRAM library + +Copyright (C) 2001-2009 Norbert Mueller + +This file is part of the iRRAM Library. + +The iRRAM Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Library General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at your +option) any later version. + +The iRRAM Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public +License for more details. + +You should have received a copy of the GNU Library General Public License +along with the iRRAM Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, +MA 02111-1307, USA. +*/ +#ifndef IRRAM_CORE_H +#define IRRAM_CORE_H + +#include +#include +#include //#include +#include + +#include +#include +#include + +namespace iRRAM { + +inline int min(const int a, const int b) + { return (a < b ? a : b); } +inline int max(const int a, const int b) + { return (a >= b ? a : b); } +inline int max3(const int a,const int b,const int c) + { return max(max(a,b),c); } +inline int max4(const int a,const int b,const int c,const int d) + { return max(max(a,b),max(c,d)); } + +extern __thread int iRRAM_debug; +extern __thread int iRRAM_infinite; +extern void resources(double&,unsigned int&); +extern double ln2_time; +extern double pi_time; +void show_statistics(); + +extern const int iRRAM_prec_steps; +extern int iRRAM_prec_array[]; +extern __thread int iRRAM_prec_skip; +extern __thread int iRRAM_max_prec; +extern __thread int iRRAM_prec_start; + +#ifndef NODEBUG + #define iRRAM_DEBUG0(level,...) \ + do { \ + if (iRRAM_unlikely(iRRAM_debug>=ACTUAL_STACK.inlimit+(level))) {\ + __VA_ARGS__; \ + } \ + } while (0) +#else + #define iRRAM_DEBUG0(level,...) +#endif +#define iRRAM_DEBUG1(level,p) iRRAM_DEBUG0((level),cerr << p) +#define iRRAM_DEBUG2(level,...) iRRAM_DEBUG0((level),fprintf(stderr,__VA_ARGS__)) + + +struct Iteration {int prec_diff; Iteration (int p){prec_diff=p;}; }; + +extern bool enableReiterate; +extern bool alwaysenableReiterate; +// inline void REITERATE(int p_diff){inReiterate = true; throw Iteration(p_diff); } +#define REITERATE(x) { if(iRRAM::enableReiterate && alwaysenableReiterate){inReiterate = true;throw Iteration(x);}}; + +//std::cout<<"enableiter:"<>p):0); } + +const SIZETYPEMANTISSA max_mantissa= 1 << GUARD_BITS ; +const SIZETYPEMANTISSA min_mantissa= 1 << (GUARD_BITS-BIT_RANGE); + +/* if the exponent of value is smaller than MP_min, it should be increased(!) to (1,min_exponent) */ +const SIZETYPEEXPONENT min_exponent=MP_min + MANTISSA_BITS; + + +// sizetype_normalize(e) ********************************************** +// Try to keep the mantissa between max_mantissa and min_mantissa. +// It may not be larger than max_mantissa. +// It still may stay smaller than min_mantissa afterwards. +// The value of e may slighty increase during this operation! +// The value of e must never decrease! +// If the resulting exponent is out of range (MP_min,MP_max) +// correct it with an increase in value or produce an error. +// ******************************************************************** + + +inline void sizetype_normalize( sizetype& e) { + if (iRRAM_unlikely(e.mantissa < min_mantissa)) { + e.mantissa <<= BIT_RANGE; + e.exponent -= BIT_RANGE; + } + if (iRRAM_unlikely( e.mantissa >= max_mantissa ) ) { + e.mantissa = ( e.mantissa>> DIFF_BITS ) + 1; + e.exponent += DIFF_BITS; + } + if (iRRAM_unlikely( e.exponent < MP_min ) ){ + e.exponent = min_exponent; + } + if (iRRAM_unlikely( e.exponent >= MP_max ) ) + { + iRRAM_DEBUG1(1,"exponent too big in sizetype_normalize "); + REITERATE(0); + } +} + +// sizetype_inc(x,y) ************************************************** +// Increment x by y +// Arguments x and y must differ! +// The resulting value may be a bit larger than the exact value, +// The resulting value may never be smaller than the exact value +// ******************************************************************** + +inline void sizetype_inc(sizetype& x,const sizetype& y) +{ + if ( y.exponent > x.exponent) { + x.mantissa=scale(x.mantissa,(y.exponent-x.exponent)) + +y.mantissa +1 ; + x.exponent=y.exponent; + } else { + x.mantissa += + scale(y.mantissa,(x.exponent-y.exponent)) +1 ; + } + sizetype_normalize(x); +} + +// sizetype_add_one(x,y) ************************************************** +// Let x = y + 1*2^z +// Arguments x and y must differ! +// The resulting value may be a bit larger than the exact value, +// The resulting value may never be smaller than the exact value +// ******************************************************************** + +inline void sizetype_add_one(sizetype& x,const sizetype& y,const SIZETYPEEXPONENT zexp) +{ +// replace 1*2^(-zexp) by 1048576*2^(-zexp-20) +// this is still the same numerical value! +// if zexp is larger than y.exponent, the result is closer to the intended result + SIZETYPEEXPONENT zexp_scale= zexp-20; + if ( y.exponent > zexp_scale) { + x.exponent= y.exponent; + x.mantissa= y.mantissa + 1048576 ; + } else { + x.exponent= zexp_scale; + x.mantissa= (scale(y.mantissa,(zexp_scale-y.exponent))+1) + 1048576 ; + } + sizetype_normalize(x); +} + +// sizetype_inc_one(x,y) ************************************************** +// Let x = x + 1*2^z +// The resulting value may be a bit larger than the exact value, +// The resulting value may never be smaller than the exact value +// ******************************************************************** + +inline void sizetype_inc_one(sizetype& x,const SIZETYPEEXPONENT zexp) +{ + if ( x.exponent > zexp) { + x.mantissa ++ ; + } else { + x.mantissa=scale(x.mantissa,(zexp-x.exponent)) + 2 ; + x.exponent= zexp; + } + sizetype_normalize(x); +} + + +// sizetype_inc2(x,y,z) ************************************************** +// Increment x by y and z +// Arguments x, y and z must differ! +// The resulting value may be a bit larger than the exact value, +// The resulting value may never be smaller than the exact value +// ******************************************************************** + +inline void sizetype_inc2(sizetype& x,const sizetype& y,const sizetype& z) +{ SIZETYPEEXPONENT exponent; + exponent=max3(x.exponent,y.exponent,z.exponent); + x.mantissa=scale(x.mantissa,(exponent-x.exponent)) + +scale(y.mantissa,(exponent-y.exponent)) + +scale(z.mantissa,(exponent-z.exponent)) +2 ; + x.exponent=exponent; + sizetype_normalize(x); +} + + +// sizetype_add_wo_norm(x,y,z) ************************************************** +// Add y and z yielding x +// Argument x must be different from y and z! +// The resulting value may be a bit larger than the exact value, +// The resulting value may never be smaller than the exact value +// ******************************************************************** + +inline void sizetype_add_wo_norm(sizetype& x,const sizetype& y,const sizetype& z) +{ + if ( y.exponent > z.exponent) { + x.exponent= y.exponent; + x.mantissa= y.mantissa + scale(z.mantissa,(x.exponent-z.exponent)) + 1 ; + } else { + x.exponent= z.exponent; + x.mantissa= z.mantissa + scale(y.mantissa,(x.exponent-y.exponent)) + 1 ; + } +} + + +// sizetype_add(x,y,z) ************************************************** +// Add y and z yielding x +// Argument x must be different from y and z! +// The resulting value may be a bit larger than the exact value, +// The resulting value may never be smaller than the exact value +// ******************************************************************** + +inline void sizetype_add(sizetype& x,const sizetype& y,const sizetype& z) +{ + sizetype_add_wo_norm(x,y,z); + sizetype_normalize(x); +} + + +inline void sizetype_copy(sizetype& x,const sizetype& y) +{ + x.exponent=y.exponent; + x.mantissa=y.mantissa; +} + +// sizetype_shift(x,y,s) ************************************************** +// Shift y and s yielding x +// Arguments x,y may be identical! +// The resulting value may be a bit larger than the exact value, +// The resulting value may never be smaller than the exact value +// ******************************************************************** + +inline void sizetype_shift(sizetype& x,const sizetype& y,const int s) +{ + x.exponent=y.exponent+s; + x.mantissa=y.mantissa; + + if (iRRAM_unlikely( x.exponent < MP_min ) ) { + iRRAM_DEBUG1(1,"warning: small exponent found in sizetype_shift\n"); + x.exponent = min_exponent; +// x.mantissa = 1; + } else if ( iRRAM_unlikely(x.exponent >= MP_max) ) + { + iRRAM_DEBUG1(1,"exponent too big in sizetype_shift "); + REITERATE(0); + } +} + +// sizetype_mult(x,y,z) ************************************************** +// Multiply y and z yielding x +// Argument x must be different from y and z! +// The resulting value may be a bit larger than the exact value, +// The resulting value may never be smaller than the exact value +// ******************************************************************** + +inline void sizetype_mult(sizetype& x,const sizetype& y,const sizetype& z) +{ unsigned long long lmantissa= + ((unsigned long long)(y.mantissa))*z.mantissa; + x.exponent=y.exponent+z.exponent; + + while (iRRAM_unlikely(lmantissa >= max_mantissa) ) + { lmantissa=lmantissa>>BIT_RANGE2;x.exponent+=BIT_RANGE2;} + + x.mantissa=lmantissa+1; + sizetype_normalize(x); +} + +// sizetype_max(x,y,z) ************************************************** +// Compute maximum of y and z in x +// Arguments x,y, and z may all be identical! +// The resulting value is exactly the maximum +// ******************************************************************** + +inline void sizetype_max(sizetype& x,const sizetype& y,const sizetype& z) +{ if (y.exponent>z.exponent) + { + if (scale(z.mantissa,y.exponent-z.exponent)>=y.mantissa) x=z; else x=y; + } else { + if (scale(y.mantissa,z.exponent-y.exponent)>=z.mantissa) x=y; else x=z; + } +} + +// sizetype_set(x,m,e) ************************************************** +// Construct a sizetype value x from mantissa m and exponent e +// The resulting value is allowed to be larger than the exact value +// ******************************************************************** + +inline void sizetype_set(sizetype& x,const int mantissa,const int exponent) +{ + x.exponent=exponent; + x.mantissa=mantissa; + sizetype_normalize(x); +} + +inline void sizetype_exact(sizetype& x) +{ + x.exponent=min_exponent; + x.mantissa=0; +} + +/*Test whether yz.exponent) + { + mantissa=scale(z.mantissa,y.exponent-z.exponent); + return (mantissa>=y.mantissa); + } else { + mantissa=scale(y.mantissa,z.exponent-y.exponent); + return (mantissa>1; + x.mantissa=y.mantissa <<1; + } else { + x.exponent=y.exponent>>1; + x.mantissa=y.mantissa; + } + x.mantissa=int(std::sqrt(double(x.mantissa)))+1; +} + +inline void sizetype_div(sizetype& x,const sizetype& y,const sizetype& z) +{ unsigned long long lmantissa= + (((unsigned long long)(y.mantissa))<= max_mantissa ) + { lmantissa=lmantissa>>BIT_RANGE2;x.exponent+=BIT_RANGE2;} + + x.mantissa=lmantissa+1; + sizetype_normalize(x); +} + + + + +/*****************************************/ +// iRRAM_exec template +extern int MAXiterationnum; +template +RESULT iRRAM_exec( + RESULT (*iRRAM_compute)(const ARGUMENT&...), const ARGUMENT&... x +) { +iRRAM_thread_data_address= new iRRAM_thread_data_class; + +ITERATION_STACK SAVED_STACK; + +ACTUAL_STACK.prec_step=iRRAM_prec_start; +ACTUAL_STACK.actual_prec=iRRAM_prec_array[ACTUAL_STACK.prec_step]; +iRRAM_highlevel = (ACTUAL_STACK.prec_step > 1); +fesetround(FE_DOWNWARD); +// set the correct rounding mode for REAL using double intervals): + +cache_active = new cachelist; + +if ( iRRAM_unlikely(iRRAM_debug>0) ) { + cerr <<"\niRRAM (version "<id[n]->rewind();} + inReiterate = false; + ACTUAL_STACK.inlimit=0; + + iRRAM_highlevel = (ACTUAL_STACK.prec_step > 1); + + int p_end=0; + try { result=iRRAM_compute(x...); if ( iRRAM_likely(!iRRAM_infinite) ) break;} + catch ( Iteration it) { p_end=ACTUAL_STACK.actual_prec+it.prec_diff; } + catch ( const iRRAM_Numerical_Exception exc) + { + cerr << "iRRAM exception: "< p_end) && (prec_skip != iRRAM_prec_skip) ); + + ACTUAL_STACK.inlimit=0; + if ( iRRAM_unlikely(iRRAM_debug>0) ) { + show_statistics(); + if (iRRAM_max_prec <= ACTUAL_STACK.prec_step) + iRRAM_max_prec = ACTUAL_STACK.prec_step; + cerr << "increasing precision bound to "<=MAXiterationnum){ enableReiterate=false; result=iRRAM_compute(x...); break;} + ++increasenum; + } + +iRRAM::cout.reset(); +for (int n=0;nid[n]->clear();} + +max_active=0; +ACTUAL_STACK.inlimit=-1; +delete cache_active; +delete iRRAM_thread_data_address; + +if ( iRRAM_unlikely (iRRAM_debug>0) ) { + show_statistics(); + cerr << "iRRAM ending \n"; +} + +return result; +} + + +/*****************************************/ +// templates needed for iRRAM_thread_exec +extern unsigned int iRRAM_thread_maxid; + +template class iRRAM_thread_data{public: +ARGUMENT argument; +RESULT result; +RESULT (*f) (const ARGUMENT&); +pthread_t thread; +bool finished; +unsigned int id; +}; + +template void* iRRAM_thread_wrapper (iRRAM_thread_data *_data){ + +iRRAM_thread_data_address= new iRRAM_thread_data_class; + +ITERATION_STACK SAVED_STACK; + +ACTUAL_STACK.prec_step=iRRAM_prec_start; +ACTUAL_STACK.actual_prec=iRRAM_prec_array[ACTUAL_STACK.prec_step]; +iRRAM_highlevel = (ACTUAL_STACK.prec_step > 1); +fesetround(FE_DOWNWARD); +// set the correct rounding mode for REAL using double intervals): + +cache_active = new cachelist; + +if ( iRRAM_unlikely(iRRAM_debug>0) ) { + cerr <<"\niRRAM (version "<id<<") starting...\n"; + iRRAM_max_prec=ACTUAL_STACK.prec_step; +} + + +while (true) { + + iRRAM::cout.rewind(); + for (int n=0;nid[n]->rewind();} + inReiterate = false; + ACTUAL_STACK.inlimit=0; + + iRRAM_highlevel = (ACTUAL_STACK.prec_step > 1); + + int p_end=0; + + try {_data->result = _data-> f(_data->argument); + if ( iRRAM_likely(!iRRAM_infinite) ) break;} + catch ( Iteration it) { p_end=ACTUAL_STACK.actual_prec+it.prec_diff; } + catch ( const iRRAM_Numerical_Exception exc) + { + cerr << "iRRAM exception: "< p_end) && (prec_skip != iRRAM_prec_skip) ); + + ACTUAL_STACK.inlimit=0; + iRRAM_prec_start=ACTUAL_STACK.prec_step; + if ( iRRAM_unlikely(iRRAM_debug>0) ) { + show_statistics(); + if (iRRAM_max_prec <= ACTUAL_STACK.prec_step) + iRRAM_max_prec = ACTUAL_STACK.prec_step; + cerr << "increasing precision bound to "<id << "\n"; + } + } + +iRRAM::cout.reset(); +for (int n=0;nid[n]->clear();} + +max_active=0; +ACTUAL_STACK.inlimit=-1; +delete cache_active; +delete iRRAM_thread_data_address; + +if ( iRRAM_unlikely (iRRAM_debug>0) ) { + show_statistics(); + cerr << "iRRAM thread "<< _data->id << " ending \n"; +} + +_data->finished=true; + +return NULL; +} + + +template + void iRRAM_thread_exec +(RESULT iRRAM_compute(const ARGUMENT&), const ARGUMENT& x, iRRAM_thread_data& data) +{ +typedef void*(*testf)(void*) ; +data.argument = x; +data.f = iRRAM_compute; +data.id = ++iRRAM_thread_maxid; +data.finished = false; + +void* (*my_f)(iRRAM_thread_data*) = &iRRAM_thread_wrapper; +void*(*my_function)(void*) = reinterpret_cast (my_f); +if (int errcode=pthread_create(&(data.thread),/* thread struct */ + NULL, /* default thread attributes */ + my_function, /* start routine */ + &data)) /* arg to routine */ + { cerr << "Error " << errcode << " in pthread_create"; } + +return; +} + + +template +RESULT iRRAM_thread_wait(const iRRAM_thread_data& data){ + if ( iRRAM_unlikely (iRRAM_debug>0) ) { + cerr << "Waiting for termination of thread "<< data.id << "\n"; + } + pthread_join(data.thread,NULL); + if ( iRRAM_unlikely (iRRAM_debug>0) ) { + cerr << "Thread "<< data.id << " now terminated.\n"; + } + return data.result; +} + + + +template +bool iRRAM_thread_finished(const iRRAM_thread_data& data){ + return data.finished; +} + + +} /* ! namespace iRRAM */ + +//*************************************************************************************/ +// predefined instantiations of some iRRAM_exec routines can be found in stack.cc +//*************************************************************************************/ +#endif /* ! iRRAM_CORE_H */ diff --git a/includeNumOpt/iRRAM/errno.h b/includeNumOpt/iRRAM/errno.h new file mode 100644 index 0000000..e4133d3 --- /dev/null +++ b/includeNumOpt/iRRAM/errno.h @@ -0,0 +1,10 @@ +ERRORDEFINE(iRRAM_overflow_error, "iRRAM_overflow_error") +ERRORDEFINE(iRRAM_underflow_error, "iRRAM_underflow_error") +ERRORDEFINE(iRRAM_integer_error, "iRRAM_integer_error") +ERRORDEFINE(iRRAM_interval_divide_by_zero, "iRRAM_interval_divide_by_zero") +ERRORDEFINE(iRRAM_cacheerror_test, "iRRAM_cacheerror_test") +ERRORDEFINE(iRRAM_cacheerror_rkonvert, "iRRAM_cacheerror_rkonvert") +ERRORDEFINE(iRRAM_cacheerror_skonvert, "iRRAM_cacheerror_skonvert") +ERRORDEFINE(iRRAM_cacheerror_ikonvert, "iRRAM_cacheerror_ikonvert") +ERRORDEFINE(iRRAM_conversion_from_infinite,"iRRAM_conversion_from_infinite") +ERRORDEFINE(iRRAM_general_divide_by_zero, "iRRAM_general_divide_by_zero") diff --git a/includeNumOpt/iRRAM/lib.h b/includeNumOpt/iRRAM/lib.h new file mode 100644 index 0000000..1c63550 --- /dev/null +++ b/includeNumOpt/iRRAM/lib.h @@ -0,0 +1,265 @@ +/* + +iRRAM_lib.h -- central header file for the iRRAM library + +Copyright (C) 2001-2013 Norbert Mueller + +This file is part of the iRRAM Library. + +The iRRAM Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Library General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at your +option) any later version. + +The iRRAM Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public +License for more details. + +You should have received a copy of the GNU Library General Public License +along with the iRRAM Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, +MA 02111-1307, USA. +*/ + + +/* +Authors: all by Norbert, except: + + 2003-07 INTERVAL extensions partly by Shao Qi + + 2001-07 INTEGER and RATIONAL partly by Tom van Diessen + + +*/ + +#ifndef iRRAM_LIB_H +#define iRRAM_LIB_H + +#include + +#if defined(__GNUC__) || defined(__clang__) || defined(__builtin_expect) +/* Don't need to check version of compilers, they all support __builtin_expect() + * since the time they know of C++11 */ +# define iRRAM_expect(e,n) __builtin_expect((e),(n)) +#else +# define iRRAM_expect(e,n) (e) +#endif +#define iRRAM_likely(x) iRRAM_expect(!!(x), 1) +#define iRRAM_unlikely(x) iRRAM_expect(!!(x), 0) + +#include + +#ifndef iRRAM_BACKENDS +# error error: no usable backend, defined iRRAM_BACKENDS +#endif + +#if iRRAM_BACKEND_MPFR +# include +#else +# error "Currently no additional backend!" +#endif + +extern "C" void iRRAM_initialize(int argc,char** argv); + +namespace iRRAM{ + +template + RESULT iRRAM_exec (RESULT (*f)(const ARGUMENT&...), const ARGUMENT&...); + + +// forward declaration of some classes + +class INTEGER; +class RATIONAL; +class DYADIC; +class LAZY_BOOLEAN; +class REAL; +class COMPLEX; + +extern char* iRRAM_error_msg[]; +class iRRAM_Numerical_Exception +{ +public: +iRRAM_Numerical_Exception(const int msg){type=msg;}; +//private: +int type; +}; +#define ERRORDEFINE(x,y) x, +enum iRRAM_exception_list { +#include +}; + + + +typedef unsigned int SIZETYPEMANTISSA; +typedef int SIZETYPEEXPONENT; + +struct sizetype { SIZETYPEMANTISSA mantissa; SIZETYPEEXPONENT exponent; } ; + +struct ITERATION_DATA { + int prec_policy; + int inlimit; + int actual_prec; + int prec_step; +}; + +class ITERATION_STACK { +public: + ITERATION_STACK(); + ~ITERATION_STACK(); + ITERATION_DATA data; +}; + + +extern __thread ITERATION_DATA ACTUAL_STACK; +extern __thread bool iRRAM_highlevel; +extern __thread bool inReiterate; + +inline ITERATION_STACK::ITERATION_STACK(){ + this->data=ACTUAL_STACK; + } +inline ITERATION_STACK::~ITERATION_STACK(){ + ACTUAL_STACK= this->data; + iRRAM_highlevel = (ACTUAL_STACK.prec_step > 1); + } + +} // namespace iRRAM + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +namespace iRRAM { + +#define iRRAM_ABSOLUTE 0 +#define iRRAM_RELATIVE 1 +void precision_policy (int policy); + +REAL atoREAL(const char* s); + + +/****************************************************************************/ +// arithmetic functions +/****************************************************************************/ +REAL power(const REAL& x, const REAL& y); +REAL power(const REAL& x, int n); +REAL modulo (const REAL& x, const REAL& y); +REAL maximum (const REAL& x, const REAL& y); +REAL minimum (const REAL& x, const REAL& y); + +/****************************************************************************/ +// roots +/****************************************************************************/ +REAL sqrt (const REAL& x); +REAL root (const REAL& x,int n); + +/****************************************************************************/ +// trigonometric functions +/****************************************************************************/ +REAL sin (const REAL& x); +REAL cos (const REAL& x); +REAL tan (const REAL& x); +REAL cotan (const REAL& x); +REAL sec (const REAL& x); +REAL cosec (const REAL& x); + +/****************************************************************************/ +// inverse trigonometric functions +/****************************************************************************/ +REAL atan (const REAL& x); +REAL asin (const REAL& x); +REAL acos (const REAL& x); +REAL acotan (const REAL& x); +REAL asec (const REAL& x); +REAL acosec (const REAL& x); + +/****************************************************************************/ +//hyperbolic functions +/****************************************************************************/ +REAL sinh (const REAL& x); +REAL cosh (const REAL& x); +REAL tanh (const REAL& x); +REAL coth (const REAL& x); +REAL sech (const REAL& x); +REAL cosech (const REAL& x); + +/****************************************************************************/ +// inverse hyperbolic functions +/****************************************************************************/ +REAL asinh (const REAL& x); +REAL acosh (const REAL& x); +REAL atanh (const REAL& x); +REAL acoth (const REAL& x); +REAL asech (const REAL& x); +REAL acosech (const REAL& x); + +/****************************************************************************/ +// exponentiation + logarithm +/****************************************************************************/ +REAL exp (const REAL& x); +REAL log (const REAL& x); + +/****************************************************************************/ +// special constants values +/****************************************************************************/ +REAL pi (); // = 3.141592653... +REAL euler (); // = 2.718281828... +REAL ln2 (); // = 0.693147180... + +/****************************************************************************/ +// a few vector functions +/****************************************************************************/ +REAL abs (const std::vector& x); + +/****************************************************************************/ +// matrix functions +/****************************************************************************/ +REALMATRIX exp (const REALMATRIX& x); + +REALMATRIX steady_state (const REALMATRIX& x); + +REALMATRIX steady_state (const SPARSEREALMATRIX& x); +REALMATRIX equilib (const SPARSEREALMATRIX& x); +void equilib_del (SPARSEREALMATRIX& x,REALMATRIX& z); + +/****************************************************************************/ +// a few inlined functions +/****************************************************************************/ +inline REAL round2 (const REAL& x){ return REAL(x.as_INTEGER()); } +inline int round (const REAL& x){ return int (x.as_INTEGER()); } +inline REAL floor (const REAL& x){ return (x>0)?(round2(x-0.5)):(round2(x+0.5)); } + + +/****************************************************************************/ +// templates for limit operators +/****************************************************************************/ + +template +RESULT limit_mv (RESULT f(int prec, + int* choice, + const ARGUMENT&), + const ARGUMENT& x); + +template +RESULT limit (RESULT f(int prec,const ARGUMENT&), + const ARGUMENT& x); + + +template +RESULT limit (RESULT f(int prec,const ARGUMENT&, DISCRETE), + const ARGUMENT& x, DISCRETE param); + +} // namespace iRRAM + +#endif /* ! iRRAM_LIB_H */ diff --git a/includeNumOpt/iRRAM/limit_templates.h b/includeNumOpt/iRRAM/limit_templates.h new file mode 100644 index 0000000..67fd23a --- /dev/null +++ b/includeNumOpt/iRRAM/limit_templates.h @@ -0,0 +1,438 @@ +/* + +iRRAM_limit_templates.h -- template definitions file for the limit operators of the iRRAM library + +Copyright (C) 2005 Norbert Mueller + +This file is part of the iRRAM Library. + +The iRRAM Library is free software; you can redistribute it and/or modify +it under the terms of the GNU Library General Public License as published by +the Free Software Foundation; either version 2 of the License, or (at your +option) any later version. + +The iRRAM Library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public +License for more details. + +You should have received a copy of the GNU Library General Public License +along with the iRRAM Library; see the file COPYING.LIB. If not, write to +the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, +MA 02111-1307, USA. +*/ +#ifndef iRRAM_LIMIT_TEMPLATES_H +#define iRRAM_LIMIT_TEMPLATES_H + +#include + +namespace iRRAM { + +inline void limit_debug(const char* c){ + if ( iRRAM_unlikely(iRRAM_debug > 0) ){ + if (iRRAM_debug >=ACTUAL_STACK.inlimit + 2 ) + cerr << c <<"...\n"; + if (iRRAM_max_prec <= ACTUAL_STACK.prec_step) + iRRAM_max_prec = ACTUAL_STACK.prec_step; + } +} + +inline void limit_debug2(const char* c){ + if ( iRRAM_unlikely(iRRAM_debug > 0) ) { + if (iRRAM_debug >=ACTUAL_STACK.inlimit + 2 ) + cerr << c <<", increasing precision locally to " + < +RESULT limit (RESULT f(int prec,const ARGUMENT&), + const ARGUMENT& x) + +{ + ITERATION_STACK SAVED_STACK; + ACTUAL_STACK.inlimit+=1; + ACTUAL_STACK.prec_step++; + ACTUAL_STACK.actual_prec=iRRAM_prec_array[ACTUAL_STACK.prec_step]; + iRRAM_highlevel = (ACTUAL_STACK.prec_step > 1); + + RESULT lim,limnew; + sizetype limnew_error,element_error; + sizetype lim_error,x_error; + + int element=SAVED_STACK.data.actual_prec; + int element_step=SAVED_STACK.data.prec_step; + int firsttime=2; + + x.geterror(x_error); + + limit_debug("starting limit_gen1"); + + while (1) { + try { + iRRAM_DEBUG2(2,"trying to compute limit_gen1 with precicion 2^(%d)...\n",element); + limnew=f(element,x); + sizetype_set(element_error,1,element); + limnew.geterror(limnew_error); + sizetype_inc(limnew_error,element_error); + if (firsttime ==2 ) if ( limnew_error.exponent > iRRAM_prec_array[SAVED_STACK.data.prec_step-1] + && limnew_error.exponent > x_error.exponent -iRRAM_prec_array[SAVED_STACK.data.prec_step-1]) { + iRRAM_DEBUG0(2,{cerr<<"computation not precise enough (" + << limnew_error.mantissa <<"*2^"<< limnew_error.exponent + <<"), trying normal p-sequence\n";}); + element_step=1; + element=4+iRRAM_prec_array[element_step]; + firsttime=1; + } + if ( firsttime != 0 || sizetype_less(limnew_error,lim_error) ) { + lim=limnew; + lim_error=limnew_error; + iRRAM_DEBUG2(2,"getting result with error %d*2^(%d)\n", + lim_error.mantissa, lim_error.exponent); + } else { + iRRAM_DEBUG1(2,"computation successful, but no improvement\n"); + } + firsttime=0; + if (element<=SAVED_STACK.data.actual_prec)break; + element_step+=4; + element=iRRAM_prec_array[element_step]; + } + catch ( Iteration it) { + if ( firsttime==0) { + iRRAM_DEBUG1(2,"computation failed, using best success\n"); + break; + } else + if ( firsttime==2) { + iRRAM_DEBUG1(2,"computation failed, trying normal p-sequence\n"); + element_step=1; + element=4+iRRAM_prec_array[element_step]; + firsttime=1; + } else { + iRRAM_DEBUG1(1,"computation of limit_gen1 failed totally\n"); + REITERATE(0); + }} + } + lim.seterror(lim_error); + iRRAM_DEBUG0(2,{cerr<<"end of limit_gen1 with error " + << lim_error.mantissa <<"*2^("<< lim_error.exponent<<")\n";}); + return lim; +} + +template +RESULT limit (RESULT f(int prec,const ARGUMENT&,DISCRETE param), + const ARGUMENT& x,DISCRETE param) + +{ + ITERATION_STACK SAVED_STACK; + ACTUAL_STACK.inlimit+=1; + ACTUAL_STACK.prec_step++; + ACTUAL_STACK.actual_prec=iRRAM_prec_array[ACTUAL_STACK.prec_step]; + iRRAM_highlevel = (ACTUAL_STACK.prec_step > 1); + + RESULT lim,limnew; + sizetype limnew_error,element_error; + sizetype lim_error,x_error; + + int element=SAVED_STACK.data.actual_prec; + int element_step=SAVED_STACK.data.prec_step; + int firsttime=2; + + x.geterror(x_error); + + limit_debug("starting limit_gen1"); + + while (1) { + try { + iRRAM_DEBUG2(2,"trying to compute limit_gen1 with precicion 2^(%d)...\n",element); + limnew=f(element,x,param); + sizetype_set(element_error,1,element); + limnew.geterror(limnew_error); + sizetype_inc(limnew_error,element_error); + if (firsttime ==2 ) if ( limnew_error.exponent > iRRAM_prec_array[SAVED_STACK.data.prec_step-1] + && limnew_error.exponent > x_error.exponent -iRRAM_prec_array[SAVED_STACK.data.prec_step-1]) { + iRRAM_DEBUG0(2,{cerr<<"computation not precise enough (" + << limnew_error.mantissa <<"*2^"<< limnew_error.exponent + <<"), trying normal p-sequence\n";}); + element_step=1; + element=4+iRRAM_prec_array[element_step]; + firsttime=1; + } + if ( firsttime != 0 || sizetype_less(limnew_error,lim_error) ) { + lim=limnew; + lim_error=limnew_error; + iRRAM_DEBUG2(2,"getting result with error %d*2^(%d)\n", + lim_error.mantissa, lim_error.exponent); + } else { + iRRAM_DEBUG1(2,"computation successful, but no improvement\n"); + } + firsttime=0; + if (element<=SAVED_STACK.data.actual_prec)break; + element_step+=4; + element=iRRAM_prec_array[element_step]; + } + catch ( Iteration it) { + if ( firsttime==0) { + iRRAM_DEBUG1(2,"computation failed, using best success\n"); + break; + } else + if ( firsttime==2) { + iRRAM_DEBUG1(2,"computation failed, trying normal p-sequence\n"); + element_step=1; + element=4+iRRAM_prec_array[element_step]; + firsttime=1; + } else { + iRRAM_DEBUG1(1,"computation of limit_gen1 failed totally\n"); + REITERATE(0); + }} + } + lim.seterror(lim_error); + iRRAM_DEBUG0(2,{fprintf(stderr,"end of limit_gen1 with error %d*2^(%d)\n", + lim_error.mantissa,lim_error.exponent);}); + return lim; +} + +template +RESULT limit_mv (RESULT f(int prec, + int* choice, + const ARGUMENT&), + const ARGUMENT& x) +{ + ITERATION_STACK SAVED_STACK; + ACTUAL_STACK.inlimit+=1; + ACTUAL_STACK.prec_step++; + ACTUAL_STACK.actual_prec=iRRAM_prec_array[ACTUAL_STACK.prec_step]; + iRRAM_highlevel = (ACTUAL_STACK.prec_step > 1); + + RESULT lim,limnew; + sizetype limnew_error,element_error; + int choice=0; + sizetype lim_error,x_error; + + int element=SAVED_STACK.data.actual_prec; + int element_step=SAVED_STACK.data.prec_step; + int firsttime=2; + + if ( (ACTUAL_STACK.inlimit==0) && !iRRAM_thread_data_address->cache_i.get(choice)) iRRAM_thread_data_address->cache_i.put(choice); + + x.geterror(x_error); + + limit_debug("starting limit_mv"); + + while (1) { + try { + iRRAM_DEBUG2(2,"trying to compute limit_mv with precicion 2^(%d)...\n",element); + limnew=f(element,&choice,x); + if ( SAVED_STACK.data.inlimit==0 ) iRRAM_thread_data_address->cache_i.modify(choice); + sizetype_set(element_error,1,element); + limnew.geterror(limnew_error); + sizetype_inc(limnew_error,element_error); + if (firsttime ==2 ) if ( limnew_error.exponent > iRRAM_prec_array[SAVED_STACK.data.prec_step-1] + && limnew_error.exponent > x_error.exponent -iRRAM_prec_array[SAVED_STACK.data.prec_step-1]) { + iRRAM_DEBUG0(2,{fprintf(stderr,"computation not precise enough (%d*2^%d), trying normal p-sequence\n", + limnew_error.mantissa,limnew_error.exponent);}); + element_step=1; + element=4+iRRAM_prec_array[element_step]; + firsttime=1; + }} + catch ( Iteration it) { + if ( firsttime==0) { + iRRAM_DEBUG1(2,"computation failed, using best success\n"); + break; + } else + if ( firsttime==2) { + iRRAM_DEBUG1(2,"computation failed, trying normal p-sequence\n"); + element_step=1; + element=4+iRRAM_prec_array[element_step]; + firsttime=1; + } else { + iRRAM_DEBUG1(1,"computation of limit_gen1 failed totally\n"); + REITERATE(0); + }} + if ( firsttime != 0 || sizetype_less(limnew_error,lim_error) ) { + lim=limnew; + lim_error=limnew_error; + iRRAM_DEBUG2(2,"getting result with error %d*2^(%d)\n", + lim_error.mantissa, lim_error.exponent); + } else { + iRRAM_DEBUG1(2,"computation successful, but no improvement\n"); + } + firsttime=0; + if (element<=SAVED_STACK.data.actual_prec)break; + element_step+=4; + element=iRRAM_prec_array[element_step]; + } + lim.seterror(lim_error); + iRRAM_DEBUG0(2,{fprintf(stderr,"end of limit_mv with error %d*2^(%d)\n", + lim_error.mantissa,lim_error.exponent);}); + return lim; +} + +template +RESULT limit_lip (RESULT f(int,const ARGUMENT&,DISCRETE param), + int lip_value, + bool on_domain(const ARGUMENT&), + const ARGUMENT& x,DISCRETE param) +{ + if ( on_domain(x) != true ) REITERATE(0); + + ITERATION_STACK SAVED_STACK; + ACTUAL_STACK.inlimit+=1; + ACTUAL_STACK.prec_step+=1; + ACTUAL_STACK.actual_prec=iRRAM_prec_array[ACTUAL_STACK.prec_step]; + iRRAM_highlevel = (ACTUAL_STACK.prec_step > 1); + + ARGUMENT x_new; + RESULT lim; + sizetype lim_error,x_error; + + x_new=x; + x_new.geterror(x_error); + sizetype_exact(lim_error); + x_new.seterror(lim_error); + + limit_debug("starting limit_lip"); + + while (1) { + try{ + iRRAM_DEBUG2(2,"trying to compute limit_lip with precision %d...\n",ACTUAL_STACK.actual_prec); + lim=f(SAVED_STACK.data.actual_prec,x_new,param); + lim.geterror(lim_error); + if (lim_error.exponent > SAVED_STACK.data.actual_prec ) { + ACTUAL_STACK.prec_step+=2; + ACTUAL_STACK.actual_prec=iRRAM_prec_array[ACTUAL_STACK.prec_step]; + limit_debug2("limit_lip too imprecise"); + + } else { + iRRAM_DEBUG2(2,"getting result with local error %d*2^(%d)\n", + lim_error.mantissa, lim_error.exponent); + break; + }} + catch ( Iteration it){ + ACTUAL_STACK.prec_step+=2; + ACTUAL_STACK.actual_prec=iRRAM_prec_array[ACTUAL_STACK.prec_step]; + limit_debug2("limit_lip failed"); + } } + sizetype_set(lim_error,1,SAVED_STACK.data.actual_prec); + lim.adderror(lim_error); + sizetype_shift(lim_error,x_error,lip_value); + lim.adderror(lim_error); + iRRAM_DEBUG0(2,{lim.geterror(lim_error); + fprintf(stderr,"end of limit_lip with error %d*2^(%d)\n", + lim_error.mantissa,lim_error.exponent); + fprintf(stderr," error of argument: %d*2^(%d)\n", + x_error.mantissa,x_error.exponent);}); + return lim; +} + + + + +// template +// RESULT lipschitz (RESULT f(const PARAM& param,const ARGUMENT& ), +// REAL lip_f(const PARAM& param, const ARGUMENT&), +// bool on_domain(const PARAM& param, const ARGUMENT&), +// const PARAM& param, const ARGUMENT& x) +// { +// if ( on_domain(param,x) != true ) REITERATE(0); +// +// ITERATION_STACK SAVED_STACK; +// +// single_valued code; +// iRRAM_DEBUG1(2,"starting lipschitz1b ...\n"); +// +// // for the computation of the Lipschitz bound, we work with +// // reduced precision: +// ACTUAL_STACK.prec_step=(ACTUAL_STACK.prec_step+1)/2; +// ACTUAL_STACK.actual_prec=iRRAM_prec_array[ACTUAL_STACK.prec_step]; +// iRRAM_highlevel = (ACTUAL_STACK.prec_step > 1); +// +// lip_bound=lip_f(param,x); +// +// ACTUAL_STACK.prec_step=SAVED_STACK.prec_step; +// ACTUAL_STACK.actual_prec=iRRAM_prec_array[ACTUAL_STACK.prec_step]; +// iRRAM_highlevel = (ACTUAL_STACK.prec_step > 1); +// +// ARGUMENT x_new; +// RESULT lip_result,lip_bound; +// sizetype lip_error,lip_size,tmp_size,x_error; +// +// bool try_it=true; +// x_new=x; +// x_new.geterror(x_error); +// sizetype_exact(x_new.error); +// +// +// while (try_it) { +// try { try_it=false; +// lip_result=f(param,x_new); } +// catch ( Iteration it) { try_it=true; +// ACTUAL_STACK.prec_step+=2; +// ACTUAL_STACK.actual_prec=iRRAM_prec_array[ACTUAL_STACK.prec_step]; +// iRRAM_highlevel = (ACTUAL_STACK.prec_step > 1); +// iRRAM_DEBUG2(2,"limit_lip2 failed, increasing precision locally to %d...\n",ACTUAL_STACK.actual_prec); +// } +// } +// +// iRRAM_DEBUG2(2,"getting result with local error %d*2^(%d)\n", +// lip_result.error.mantissa, lip_result.error.exponent); +// lip_size=lip_bound.vsize; +// lip_bound.geterror(tmp_size); +// sizetype_inc(lip_size,tmp_size); +// sizetype_mult(lip_error,lip_size,x_error); +// lip_result.adderror(lip_error); +// iRRAM_DEBUG0(2,{lip_result.geterror(lip_error); +// fprintf(stderr,"end of lipschitz_1b with error %d*2^(%d)\n", +// lip_error.mantissa,lip_error.exponent); +// fprintf(stderr," for argument with error %d*2^(%d)\n", +// x_error.mantissa,x_error.exponent);}); +// return lip_result; +// } + +template +RESULT lipschitz_1p_1a (RESULT f(const DISCRETE_ARGUMENT&, const PARAM& param), + int lip, + bool on_domain(const CONT_ARGUMENT&, const PARAM& param), + const CONT_ARGUMENT& x, const PARAM& param ) +{ + if ( on_domain(param,x) != true ) REITERATE(0); + + ITERATION_STACK SAVED_STACK; + + single_valued code; + iRRAM_DEBUG1(2,"starting lipschitz_1p_1a ...\n"); + + DISCRETE_ARGUMENT x_center; + RESULT lip_result; + sizetype lip_error,x_error; + + bool try_it=true; + x.to_formal_ball(x_center,x_error); + + for (unsigned prec_step_add = 0; try_it; prec_step_add += 2) { + stiff code(prec_step_add); + try { try_it=false; + lip_result=f(x_center,param); } + catch ( Iteration it) { try_it=true; + iRRAM_DEBUG2(2,"lipschitz_1p_1a failed, increasing precision locally to %d...\n",ACTUAL_STACK.actual_prec+2); + } + } + + iRRAM_DEBUG2(2,"getting result with local error %d*2^(%d)\n", + lip_result.error.mantissa, lip_result.error.exponent); + sizetype_shift(lip_error,x_error,lip); + lip_result.adderror(lip_error); + iRRAM_DEBUG0(2,{lip_result.geterror(lip_error); + fprintf(stderr,"end of lipschitz_1p_1a with error %d*2^(%d)\n", + lip_error.mantissa,lip_error.exponent); + fprintf(stderr," for argument with error %d*2^(%d)\n", + x_error.mantissa,x_error.exponent);}); + return lip_result; +} + + +} /* ! namespace iRRAM */ + + +#endif /* ! iRRAM_LIMIT_TEMPLATES_H */ diff --git a/includeNumOpt/iRRAM/mpfr_extension.h b/includeNumOpt/iRRAM/mpfr_extension.h new file mode 100644 index 0000000..9b77848 --- /dev/null +++ b/includeNumOpt/iRRAM/mpfr_extension.h @@ -0,0 +1,24 @@ + +#ifndef iRRAM_MPFR_EXTENSION_H +#define iRRAM_MPFR_EXTENSION_H + +#ifndef GMP_RNDN +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +void mpfr_ext_exp (mpfr_ptr r, mpfr_srcptr u,int p); +void mpfr_ext_log (mpfr_ptr r, mpfr_srcptr u,int p); +void mpfr_ext_sin (mpfr_ptr r, mpfr_srcptr u,int p); +void mpfr_ext_cos (mpfr_ptr r, mpfr_srcptr u,int p); +void mpfr_ext_tan (mpfr_ptr r, mpfr_srcptr u,int p); +void mpfr_ext_test (mpfr_ptr r, mpfr_srcptr u,int p,mp_rnd_t rnd_mode); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/includeNumOpt/iRRAM/version.h b/includeNumOpt/iRRAM/version.h new file mode 100644 index 0000000..cd1b861 --- /dev/null +++ b/includeNumOpt/iRRAM/version.h @@ -0,0 +1,12 @@ + +#ifndef iRRAM_VERSION_H +#define iRRAM_VERSION_H + +namespace iRRAM { +#define iRRAM_VERSION_ct "2014_01" +#define iRRAM_BACKENDS "MPFR" +#define iRRAM_BACKEND_MPFR 1 +extern const char* iRRAM_VERSION_rt; +} + +#endif diff --git a/src/main.cpp b/src/main.cpp index 5a84163..44251e6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -361,6 +361,10 @@ int main() auto timeTmp1 = std::chrono::high_resolution_clock::now(); // init over init_seconds = timeTmp1 - timeStart; cout << BLUE << "init time: " << init_seconds.count() << " s" << RESET << endl; + + fprintf(stderr, GREEN "ready> " RESET); + continue; + auto &initExprMaxError = initExprInfo.maxError; if (initExprMaxError <= 0.5) { diff --git a/src/tools.cpp b/src/tools.cpp index 412a650..0a2185d 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -422,6 +422,9 @@ exprInfo testError(string uniqueLabel, string suffix, const vector &inte // cout << "fileNameKernel: " << fileNameKernel << "\n"; cout << "command: " << commandStr << "\n"; + + return tempError; + // cout << "testName: " << testName << "\n"; char command[512] = {0}; strcat(command, commandStr.c_str()); diff --git a/srcNumOpt/points.cpp b/srcNumOpt/points.cpp new file mode 100644 index 0000000..aecf70d --- /dev/null +++ b/srcNumOpt/points.cpp @@ -0,0 +1,185 @@ +#include "backend/points.h" + +// 生成随机双精度浮点数 +double generate_random_double() { + + std::random_device rd; + std::default_random_engine generator(rd()); + std::bernoulli_distribution distribution(0.5); + + uint64_t n = 0; + for (uint64_t i = 0; i < 64; i++) { + bool b = distribution(generator); + if (!b) { + n = n & ~((uint64_t)1 << i); + } + else { + n = n | ((uint64_t)1 << i); + } + } + + double d = *(double *)(&n); + + if (d == d) { + return d; + } + return generate_random_double(); +} + +// 统计[begin, end)之间双精度浮点数个数 +uint64_t double_num_between(double begin, double end) { + + if (end == begin) return 0; + if (end < begin) return double_num_between(end, begin); + + //uint64_t u_begin = *(uint64_t *)(&begin); + uint64_t u_end = *(uint64_t *)(&end); + + //uint64_t sign_mask = uint64_t(1) << 63; + uint64_t frac_mask = 0; + for (int i = 0; i < 52; ++i) { + frac_mask |= uint64_t(1) << i; + } + uint64_t exp_mask = 0; + for (int i = 52; i < 63; ++i) { + exp_mask |= uint64_t(1) << i; + } + + //std::cout << "sign mask:" << std::bitset<64>(sign_mask) << std::endl; + //std::cout << "exp mask:" << std::bitset<64>(exp_mask) << std::endl; + //std::cout << "frac mask:" << std::bitset<64>(frac_mask) << std::endl; + + //std::cout << std::bitset<64>(u_begin) << std::endl; + //std::cout << std::bitset<64>(u_end) << std::endl; + + if (begin == 0.0) { + return (u_end&exp_mask)+(u_end&frac_mask); + } + if (begin < 0 && 0 < end) { + return double_num_between(0.0, -begin)+double_num_between(0.0, end); + } + if (0 < begin) { + return double_num_between(0.0, end)-double_num_between(0.0, begin); + } + if (end <= 0) { + return double_num_between(0.0, -begin)-double_num_between(0.0, -end); + } + return std::numeric_limits::max()-1; +} + +// 生成双精度浮点数d后面第offset个浮点数 +double generate_double_by_offset(double d, uint64_t offset) { + + if (d == 0.0) { + return *(double *)(&offset); + } + + if (d > 0) { + return generate_double_by_offset(0.0, offset+double_num_between(0.0, d)); + } + + if (d < 0) { + if (offset >= double_num_between(d, 0.0)) { + return generate_double_by_offset(0.0, offset-double_num_between(d, 0.0)); + } else { + return -generate_double_by_offset(0.0,double_num_between(0.0, -d)-offset); + } + } + return 0; +} + +// 生成[begin, end)之间随机的双精度浮点数 +double generate_random_double(double begin, double end) { + + if (begin >= end) { + std::cerr << "Can't sample a double between [" << begin << ", " << end << "]" << std::endl; + return 0; + } + + uint64_t distance = double_num_between(begin, end); + std::random_device rd; + std::mt19937_64 generator(rd()); + std::uniform_int_distribution distribution(0, distance); + + uint64_t offset = distribution(generator); + return generate_double_by_offset(begin, offset); +} + +// 将一个长度为64的01字符串转为double +double binary2double(std::string str) { + std::bitset<64> bitset64(str); + uint64_t u = bitset64.to_ulong(); + return *(double *)(&u); +} + +// 将一个double转换为64位长的01字符串 +std::string double2binary(double d) { + uint64_t u = *(uint64_t *)(&d); + std::bitset<64> bitset64(u); + return bitset64.to_string(); +} + +// 将一个长度为32位的01字符串转换为int +int binary2int(std::string str) { + std::bitset<32> bitset32(str); + return (int)(bitset32.to_ulong()); +} + +// 将一个int转换为32位长的01字符串 +std::string int2binary(int i) { + uint32_t u = *(uint32_t *)(&i); + std::bitset<32> bitset32(u); + return bitset32.to_string(); +} + +// 计算两个以二进制表示的双精度浮点数的相对误差 +double relative_error(std::string irram_res, std::string herbie_res) { + double irram = binary2double(irram_res); + double herbie = binary2double(herbie_res); + if (std::isnan(herbie) || std::isnan(irram)) { + return std::numeric_limits::infinity(); + } + if (irram == 0) { + if (herbie == 0) { + return 0; + } + return std::numeric_limits::infinity(); + } + return std::abs((irram-herbie)/irram); +} + +int log2_64(uint64_t value) { + std::bitset<64> b(value); + std::string s = b.to_string(); + for (unsigned i = 0; i < b.size(); ++i) { + if (s[i] == '1') { + return 63 - i; + } + } + return 0; +} + +// Herbie定义的两个浮点数的误差 +int herbie_error(std::string irram_res, std::string herbie_res) { + uint64_t u = double_num_between(binary2double(irram_res), binary2double(herbie_res)); + return log2_64(u+1); +} + +// 对一个字符转以特定分隔符进行分割 +template +void split(const std::string &s, char delim, Out result) { + std::stringstream ss(s); + std::string item; + while (std::getline(ss, item, delim)) { + *(result++) = item; + } +} + +std::vector split(const std::string &s, char delim) { + std::vector elems; + split(s, delim, std::back_inserter(elems)); + return elems; +} + + + diff --git a/srcTest/Bsplines3/expr_Bsplines3_NumOpt.cpp b/srcTest/Bsplines3/expr_Bsplines3_NumOpt.cpp new file mode 100644 index 0000000..4aa0cc6 --- /dev/null +++ b/srcTest/Bsplines3/expr_Bsplines3_NumOpt.cpp @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_Bsplines3_CPP(double x) +{ + REAL x_real(x); + + REAL pp(6); + double r; + REAL r_real; + + if((0<=x)&&(x<=1)&&(7.046648899479229e-308<=x)&&(x<=0.012096578909536646)) { + r = -x*x*x/6; + return r; + } + + if((0<=x)&&(x<=1)) { + r_real = -x_real*x_real*x_real/6; + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_Bsplines3_NumOpt(double x) + { + return expr_Bsplines3_CPP(x); + } +} -- Gitee From beb081608ae09a8330f55e0b571c8f80240c5dee Mon Sep 17 00:00:00 2001 From: hjwLab Date: Tue, 11 Apr 2023 09:27:05 +0800 Subject: [PATCH 02/32] occur some problems about running --- detectErrorOneFPEDParallelNumOpt.sh | 2 +- srcTest/Bsplines3/expr_Bsplines3_NumOpt.cpp | 15 ++-- srcTest/exp1x/expr_exp1x_NumOpt.cpp | 83 +++++++++++++++++++++ srcTest/test1paramFPEDParallel.c | 40 ++++++++-- 4 files changed, 125 insertions(+), 15 deletions(-) create mode 100644 srcTest/exp1x/expr_exp1x_NumOpt.cpp diff --git a/detectErrorOneFPEDParallelNumOpt.sh b/detectErrorOneFPEDParallelNumOpt.sh index 268f95e..f106d7c 100755 --- a/detectErrorOneFPEDParallelNumOpt.sh +++ b/detectErrorOneFPEDParallelNumOpt.sh @@ -54,7 +54,7 @@ ${CPP} -c -IincludeNumOpt -o objs/points.o srcNumOpt/points.cpp ${CPP} -c -IincludeNumOpt -o objs/${sourceFile}.o ${directory}/${sourceFile}.cpp ${CC} -c -o objs/${prefix}_mpfr.o ${directory}/${prefix}_mpfr.c ${CC} -c -IincludeTEST -o objs/computeULP.o ./srcTest/computeULP.c -mpicc -c -IincludeTEST -DEXPRESSION=${prefix}_ -DSUFFIX=${suffix} -DERRFILE=${errfile} -o objs/${testFileName}.o ./srcTest/${testFileName}.c +mpic++ -c -IincludeNumOpt -IincludeTEST -DEXPRESSION=${prefix}_ -DSUFFIX=${suffix} -DERRFILE=${errfile} -o objs/${testFileName}.o ./srcTest/${testFileName}.c mpic++ objs/${testFileName}.o objs/${sourceFile}.o objs/${prefix}_mpfr.o objs/computeULP.o objs/points.o -Xlinker -rpath -Xlinker libs -Llibs -liRRAM -lgmp -lpthread -Llibs -lTGen -lmpfr -lm -lqd -o ${testFileName}.exe # run the NumOpt version diff --git a/srcTest/Bsplines3/expr_Bsplines3_NumOpt.cpp b/srcTest/Bsplines3/expr_Bsplines3_NumOpt.cpp index 4aa0cc6..65c3c04 100644 --- a/srcTest/Bsplines3/expr_Bsplines3_NumOpt.cpp +++ b/srcTest/Bsplines3/expr_Bsplines3_NumOpt.cpp @@ -4,14 +4,14 @@ #include #include -#include "backend/points.h" -#include "backend/self_math.h" -#include "backend/gamma.h" -#include "iRRAM/lib.h" +// #include "backend/points.h" +// #include "backend/self_math.h" +// #include "backend/gamma.h" +// #include "iRRAM/lib.h" -int iRRAM::MAXiterationnum = 30; -bool iRRAM::enableReiterate = true; -bool iRRAM::alwaysenableReiterate = true; +// int iRRAM::MAXiterationnum = 30; +// bool iRRAM::enableReiterate = true; +// bool iRRAM::alwaysenableReiterate = true; using namespace std; using namespace iRRAM; @@ -20,7 +20,6 @@ double expr_Bsplines3_CPP(double x) { REAL x_real(x); - REAL pp(6); double r; REAL r_real; diff --git a/srcTest/exp1x/expr_exp1x_NumOpt.cpp b/srcTest/exp1x/expr_exp1x_NumOpt.cpp new file mode 100644 index 0000000..d6a9a5f --- /dev/null +++ b/srcTest/exp1x/expr_exp1x_NumOpt.cpp @@ -0,0 +1,83 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_exp1x_CPP(double x) +{ + REAL x_real(x); + + REAL pp(6); + double r; + REAL r_real; + + + if((0.01<=x)&&(x<=0.5)&&(0.09366259775907677<=x)&&(x<=0.0941941332009637)) { + r = (exp(x) - 1)/x; + return r; + } + + if((0.01<=x)&&(x<=0.5)&&(0.09454738790927672<=x)&&(x<=0.09491809413862791)) { + r = (exp(x) - 1)/x; + return r; + } + + if((0.01<=x)&&(x<=0.5)&&(0.09525975290515465<=x)&&(x<=0.0954117393966348)) { + r = (exp(x) - 1)/x; + return r; + } + + if((0.01<=x)&&(x<=0.5)&&(0.09644493151181782<=x)&&(x<=0.09931031525795438)) { + r = (exp(x) - 1)/x; + return r; + } + + if((0.01<=x)&&(x<=0.5)&&(0.11032798079699918<=x)&&(x<=0.11662856329740823)) { + r = (exp(x) - 1)/x; + return r; + } + + if((0.01<=x)&&(x<=0.5)&&(0.11690526661881576<=x)&&(x<=0.11815799959930169)) { + r = (exp(x) - 1)/x; + return r; + } + + if((0.01<=x)&&(x<=0.5)&&(0.1202218966511988<=x)&&(x<=0.12988518668611435)) { + r = (exp(x) - 1)/x; + return r; + } + + if((0.01<=x)&&(x<=0.5)&&(0.13039248351007793<=x)&&(x<=0.493319707285482)) { + r = (exp(x) - 1)/x; + return r; + } + + if((0.01<=x)&&(x<=0.5)) { + r_real = (iRRAM::exp((REAL)x_real) - 1)/x_real; + return r_real.as_double(); + } + double result = (exp(x) - 1)/x; + return result; + return r; +} + +extern "C" +{ + double expr_exp1x_NumOpt(double x) + { + return expr_exp1x_CPP(x); + } +} diff --git a/srcTest/test1paramFPEDParallel.c b/srcTest/test1paramFPEDParallel.c index 8e9f5a2..d7e80a7 100644 --- a/srcTest/test1paramFPEDParallel.c +++ b/srcTest/test1paramFPEDParallel.c @@ -1,3 +1,22 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "iRRAM/lib.h" + +using namespace std; +using namespace iRRAM; +// int iRRAM::MAXiterationnum = 30; +// bool iRRAM::enableReiterate = true; +// bool iRRAM::alwaysenableReiterate = true; + +extern "C" +{ #include "common.h" #include "mpi.h" @@ -24,6 +43,7 @@ struct errorInfo { #ifndef ERRFILE #define ERRFILE 0 #endif + double EXPRESSIONMPFR(double, mpfr_t); double EXPRESSIONMINE(double); @@ -41,6 +61,7 @@ int computeResult1param(double x0, mpfr_t mpfrResult) return status; } +} struct errorInfo test1FPEDparamParallel(DL x0Start, DL x0End, unsigned long int testNumX0, const char* uniqueLabel, const char* fileNameKernel, int myid, int i0StartLocal, int i0EndLocal, double x0startOriginInterval, double stepX0) { DL maxInputX0; @@ -83,6 +104,10 @@ struct errorInfo test1FPEDparamParallel(DL x0Start, DL x0End, unsigned long int // x0 = ii0.d; for(i0 = i0StartLocal; i0 <= i0EndLocal; i0++) { x0 = x0startOriginInterval + stepX0 * i0; + if(myid == 2) + { + printf("i0 = %d, x0 = %lf\n", i0, x0); + } computeResult1param(x0, mpfrResult); computeOrcle1param(x0, mpfrOrcle); #ifdef SINGLE @@ -137,6 +162,9 @@ struct errorInfo test1FPEDparamParallel(DL x0Start, DL x0End, unsigned long int int main(int argc, char **argv) { + // NumOpt + iRRAM_initialize(argc,argv); + // parallel int myid, numProcs; MPI_Init(&argc, &argv); @@ -158,9 +186,9 @@ int main(int argc, char **argv) testNumX0 = TESTNUMX0; char *fileNameKernel; - fileNameKernel = calloc(256, sizeof(char)); + fileNameKernel = (char *)calloc(256, sizeof(char)); char *uniqueLabel; - uniqueLabel = calloc(256, sizeof(char)); + uniqueLabel = (char *)calloc(256, sizeof(char)); if (argc == 9) { x0Start.d = strtod(argv[1], NULL); @@ -198,10 +226,10 @@ int main(int argc, char **argv) printf("Usage: \tthe fixed inputs [%g %g %lu] will be used\n", x0Start.d, x0End.d, testNumX0); } - // if(myid == 0) { - // printf("\n---------------------------------------------------start test1paramFPEDParallel\n"); - // printf("Parameters: x0Start: %lg, x0End: %lg, testNumX0 = %lu, fileNameKernel: %s\n", x0Start.d, x0End.d, testNumX0, fileNameKernel); - // } + if(myid == 0) { + printf("\n---------------------------------------------------start test1paramFPEDParallel\n"); + printf("Parameters: x0Start: %lg, x0End: %lg, testNumX0 = %lu, fileNameKernel: %s\n", x0Start.d, x0End.d, testNumX0, fileNameKernel); + } // local parameters init int lenX0Local = testNumX0 / numProcs; -- Gitee From 3acae379db9fe86b31e2514af1a607fcbec37402 Mon Sep 17 00:00:00 2001 From: hjwLab Date: Wed, 12 Apr 2023 01:47:30 +0800 Subject: [PATCH 03/32] Fix the running bug --- detectErrorOneFPEDParallelNumOpt.sh | 4 +- srcTest/Bsplines3/expr_Bsplines3_NumOpt.cpp | 16 +- srcTest/exp1x/expr_exp1x_NumOpt.cpp | 2 - srcTest/test1paramFPEDParallelNumOpt.cpp | 318 ++++++++++++++++++++ 4 files changed, 328 insertions(+), 12 deletions(-) create mode 100644 srcTest/test1paramFPEDParallelNumOpt.cpp diff --git a/detectErrorOneFPEDParallelNumOpt.sh b/detectErrorOneFPEDParallelNumOpt.sh index f106d7c..b2b3b11 100755 --- a/detectErrorOneFPEDParallelNumOpt.sh +++ b/detectErrorOneFPEDParallelNumOpt.sh @@ -41,7 +41,7 @@ else exit fi -testFileName=test1paramFPEDParallel +testFileName=test1paramFPEDParallelNumOpt numProcs=32 # echo "Detecting error: ${uniqueLabel} ${x0Start} ${x0End} ${x0Size} ${prefix} ${middle} ${suffix} ${errfile}" @@ -54,7 +54,7 @@ ${CPP} -c -IincludeNumOpt -o objs/points.o srcNumOpt/points.cpp ${CPP} -c -IincludeNumOpt -o objs/${sourceFile}.o ${directory}/${sourceFile}.cpp ${CC} -c -o objs/${prefix}_mpfr.o ${directory}/${prefix}_mpfr.c ${CC} -c -IincludeTEST -o objs/computeULP.o ./srcTest/computeULP.c -mpic++ -c -IincludeNumOpt -IincludeTEST -DEXPRESSION=${prefix}_ -DSUFFIX=${suffix} -DERRFILE=${errfile} -o objs/${testFileName}.o ./srcTest/${testFileName}.c +mpic++ -c -IincludeNumOpt -IincludeTEST -DEXPRESSION=${prefix}_ -DSUFFIX=${suffix} -DERRFILE=${errfile} -o objs/${testFileName}.o ./srcTest/${testFileName}.cpp mpic++ objs/${testFileName}.o objs/${sourceFile}.o objs/${prefix}_mpfr.o objs/computeULP.o objs/points.o -Xlinker -rpath -Xlinker libs -Llibs -liRRAM -lgmp -lpthread -Llibs -lTGen -lmpfr -lm -lqd -o ${testFileName}.exe # run the NumOpt version diff --git a/srcTest/Bsplines3/expr_Bsplines3_NumOpt.cpp b/srcTest/Bsplines3/expr_Bsplines3_NumOpt.cpp index 65c3c04..eae50f0 100644 --- a/srcTest/Bsplines3/expr_Bsplines3_NumOpt.cpp +++ b/srcTest/Bsplines3/expr_Bsplines3_NumOpt.cpp @@ -4,14 +4,14 @@ #include #include -// #include "backend/points.h" -// #include "backend/self_math.h" -// #include "backend/gamma.h" -// #include "iRRAM/lib.h" - -// int iRRAM::MAXiterationnum = 30; -// bool iRRAM::enableReiterate = true; -// bool iRRAM::alwaysenableReiterate = true; +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; using namespace std; using namespace iRRAM; diff --git a/srcTest/exp1x/expr_exp1x_NumOpt.cpp b/srcTest/exp1x/expr_exp1x_NumOpt.cpp index d6a9a5f..eb65eed 100644 --- a/srcTest/exp1x/expr_exp1x_NumOpt.cpp +++ b/srcTest/exp1x/expr_exp1x_NumOpt.cpp @@ -20,11 +20,9 @@ double expr_exp1x_CPP(double x) { REAL x_real(x); - REAL pp(6); double r; REAL r_real; - if((0.01<=x)&&(x<=0.5)&&(0.09366259775907677<=x)&&(x<=0.0941941332009637)) { r = (exp(x) - 1)/x; return r; diff --git a/srcTest/test1paramFPEDParallelNumOpt.cpp b/srcTest/test1paramFPEDParallelNumOpt.cpp new file mode 100644 index 0000000..a1961e3 --- /dev/null +++ b/srcTest/test1paramFPEDParallelNumOpt.cpp @@ -0,0 +1,318 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "iRRAM/lib.h" + +using namespace std; +using namespace iRRAM; +// int iRRAM::MAXiterationnum = 30; +// bool iRRAM::enableReiterate = true; +// bool iRRAM::alwaysenableReiterate = true; + +extern "C" +{ +#include "common.h" +#include "mpi.h" + +struct errorInfo { + double sumError; + double maxError; + double maxInputX0; +}; + +#ifndef SUFFIX +#define SUFFIX orgin +#endif +#ifndef EXPRESSION +#define EXPRESSION NMSEproblem334 +#endif + +#define EXPRESSIONMINE ADDSUFFIX(EXPRESSION, SUFFIX) +#define SUFFIX1 mpfr +#define EXPRESSIONMPFR ADDSUFFIX(EXPRESSION, SUFFIX1) + +#define TESTNUMX0 500000 +// #define FP +// #define DEBUG +#ifndef ERRFILE +#define ERRFILE 0 +#endif + +double EXPRESSIONMPFR(double, mpfr_t); +double EXPRESSIONMINE(double); + +int computeOrcle1param(double x0, mpfr_t orcle) +{ + return EXPRESSIONMPFR(x0, orcle); +} + +int computeResult1param(double x0, mpfr_t mpfrResult) +{ + int status = 1; + + double result = EXPRESSIONMINE(x0); + mpfr_set_d(mpfrResult, result, MPFR_RNDN); + + return status; +} +} + +struct errorInfo test1FPEDparamParallel(unsigned long int testNumX0, const char* uniqueLabel, const char* fileNameKernel, int myid, int i0StartLocal, int i0EndLocal, double x0startOriginInterval, double stepX0) { + DL maxInputX0; + int i0; + // int flag; + double x0, reUlp, sumError, aveReUlp, maxReUlp, lenX0; + + // mpfr + mpfr_t mpfrOrcle, mpfrResult; + mpfr_inits2(PRECISION, mpfrOrcle, mpfrResult, (mpfr_ptr) 0); + + // write error data to file + #if ERRFILE + char *directory = "./outputs"; + char *suffix = "sample"; + char *fileNameSample; + FILE *f; + fileNameSample = (char *) calloc(strlen(directory) + strlen(uniqueLabel) + strlen(fileNameKernel) + strlen(suffix) + 128, sizeof(char)); + sprintf(fileNameSample, "%s/%s/%s_%s_%02d.txt", directory, uniqueLabel, fileNameKernel, suffix, myid); + // printf("%s\n", fileNameSample); + if ((f = fopen(fileNameSample, "w")) == NULL) { + printf("Error opening file %s.\n", fileNameSample); + exit(0); + } + + // printf("test expression: %s\n", STR2(EXPRESSION)); + // printf("x0Start : %lg 0x%016lx\nx0End : %lg 0x%016lx\n", x0Start.d, x0Start.l, x0End.d, x0End.l); + // fprintf(f, "x0Start : %lg 0x%016lx\nx0End : %lg 0x%016lx\n", x0Start.d, x0Start.l, x0End.d, x0End.l); + // fprintf(f, "\nxInput\t\txInput (Hex)\t\tresult\t\tresult (Hex)\t\torcle\t\torcle (Hex)\t\tulp error\n"); + // printf("testNum : %lu 0x%lx\n", testNumX0, testNumX0); + #endif + + // Real number average + maxReUlp = 0; + aveReUlp = 0; + // flag = 1; + sumError = 0; + // for(i0 = 0; i0 < testNumX0; i0++) { + // ii0.d = x0startOriginInterval.d + stepX0 * i0; + // x0 = ii0.d; + for(i0 = i0StartLocal; i0 <= i0EndLocal; i0++) { + x0 = x0startOriginInterval + stepX0 * i0; + // if(myid == 2) + // { + // printf("i0 = %d, x0 = %lf\n", i0, x0); + // } + computeResult1param(x0, mpfrResult); + computeOrcle1param(x0, mpfrOrcle); + #ifdef SINGLE + reUlp = computeUlpDiffF(mpfrOrcle, mpfrResult); + #else // compute Double ULP as default + reUlp = computeUlpDiff(mpfrOrcle, mpfrResult); + #endif + // if(reUlp <= 0.5) { + // reUlp = 0; + // } + // if(isfinite(reUlp) == 0) { + // printf("happen to NaN or inf\n"); + // exit(1); + // } + + if (isnormal(reUlp) != 0) + { + #if ERRFILE + fprintf(f, "%le\t%le\n", x0, reUlp); + #endif + sumError += reUlp; + if (reUlp > maxReUlp) { + // flag = 0; + maxInputX0.d = x0; + maxReUlp = reUlp; + } + } + + } + // aveReUlp = aveReUlp / (testNumX0); + // if(flag == 1) { + // printf("all error are 0!!\n"); + // } else { + // printf("average ulp\tmax ulp\n"); + // printf("%le\t%le\n", aveReUlp, maxReUlp); + // printf("\naveReUlp = %lg\nmaxInputX0 = 0x%016lx %lg, maxReUlp = %lg\n", aveReUlp, maxInputX0.l, maxInputX0.d, maxReUlp); + // } + #if ERRFILE + // fprintf(f, "\n"); + + // clear + fclose(f); + free(fileNameSample); + #endif + mpfr_clears(mpfrOrcle, mpfrResult, (mpfr_ptr) 0); + struct errorInfo err; + err.sumError = sumError; + err.maxError = maxReUlp; + err.maxInputX0 = maxInputX0.d; + return err; +} + +int main_inner(const unsigned long int &testNumX0, const string &uniqueLabelStr, const string &fileNameKernelStr, const int &myid, const int &numProcs, const int &i0StartLocal, const int &i0EndLocal, const double &x0startOriginInterval, const double &stepX0) +{ + std::fesetround(FE_TONEAREST); + std::cout << std::scientific << std::setprecision(6); + iRRAM::cout << iRRAM::setRwidth(30); + + MPI_Datatype MPI_errorInfo; + MPI_Type_contiguous(3, MPI_DOUBLE, &MPI_errorInfo); + MPI_Type_commit(&MPI_errorInfo); + char *fileNameKernel; + fileNameKernel = (char *)calloc(256, sizeof(char)); + sprintf(fileNameKernel, "%s", fileNameKernelStr.c_str()); + char *uniqueLabel; + uniqueLabel = (char *)calloc(256, sizeof(char)); + sprintf(uniqueLabel, "%s", uniqueLabelStr.c_str()); + // call the error test function + struct errorInfo err = test1FPEDparamParallel(testNumX0, uniqueLabel, fileNameKernel, myid, i0StartLocal, i0EndLocal, x0startOriginInterval, stepX0); + + // gather errors and find the max + struct errorInfo *errs; + errs = (struct errorInfo *)calloc(numProcs, sizeof(struct errorInfo)); + MPI_Gather(&err, 1, MPI_errorInfo, errs, 1, MPI_errorInfo, 0, MPI_COMM_WORLD); + if(myid == 0) + { + double maxError = -1; + double aveError = 0; + double errTmp = -1; + int maxErrorIdx = -1; + for(int i = 0; i < numProcs; i++) + { + errTmp = errs[i].maxError; + if(errTmp > maxError) + { + maxError = errTmp; + maxErrorIdx = i; + } + aveError += errs[i].sumError; + } + aveError = aveError / (testNumX0); + DL maxInputX0; + maxInputX0.d = errs[maxErrorIdx].maxInputX0; + + FILE *fErr; + char *directory = "./outputs"; + char *suffixErr = "error.txt"; + char *fileNameErr; + fileNameErr = (char *) calloc(strlen(directory) + strlen(uniqueLabel) + strlen(fileNameKernel) + strlen(suffixErr) + 128, sizeof(char)); + sprintf(fileNameErr, "%s/%s/%s_%s", directory, uniqueLabel, fileNameKernel, suffixErr); + if ((fErr = fopen(fileNameErr, "w")) == NULL) + { + printf("Error opening file %s.\n", fileNameErr); + exit(0); + } + printf("average ulp\tmax ulp\n"); + printf("%.16le\t%.16le\n", aveError, maxError); + // printf("\naveReUlp = %lg\nmaxInputX0 = 0x%016lx %lg, maxReUlp = %lg\n", aveError, maxInputX0.l, maxInputX0.d, maxError); + fprintf(fErr, "average ulp\tmax ulp\n"); + fprintf(fErr, "%.16le\t%.16le\n", aveError, maxError); + fprintf(fErr, "\naveReUlp = %lg\nmaxInputX0 = 0x%016lx %lg, maxReUlp = %lg\n", aveError, maxInputX0.l, maxInputX0.d, maxError); + + free(fileNameErr); + free(uniqueLabel); + fclose(fErr); + } + + // clear + free(fileNameKernel); + free(errs); + MPI_Type_free(&MPI_errorInfo); + + return 0; +} + +int main(int argc, char **argv) +{ + // parallel + int myid, numProcs; + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &myid); + MPI_Comm_size(MPI_COMM_WORLD, &numProcs); + + // parameters init + DL x0Start, x0End; + unsigned long int testNumX0; + x0Start.d = 1; + x0End.d = 2; + int x0startNowIdx; + double x0startOriginInterval; + double stepX0; + + testNumX0 = TESTNUMX0; + + char *fileNameKernel; + fileNameKernel = (char *)calloc(256, sizeof(char)); + char *uniqueLabel; + uniqueLabel = (char *)calloc(256, sizeof(char)); + if (argc == 9) + { + x0Start.d = strtod(argv[1], NULL); + x0End.d = strtod(argv[2], NULL); + testNumX0 = strtod(argv[3], NULL); + x0startNowIdx = atoi(argv[4]); + x0startOriginInterval = strtod(argv[5], NULL); + stepX0 = strtod(argv[6], NULL); + strcpy(fileNameKernel, argv[7]); + strcpy(uniqueLabel, argv[8]); + } + else if (argc == 8) + { + x0Start.d = strtod(argv[1], NULL); + x0End.d = strtod(argv[2], NULL); + x0startNowIdx = atoi(argv[3]); + x0startOriginInterval = strtod(argv[4], NULL); + stepX0 = strtod(argv[5], NULL); + strcpy(fileNameKernel, argv[6]); + strcpy(uniqueLabel, argv[7]); + } + else if (argc == 7) + { + testNumX0 = strtod(argv[1], NULL); + x0startNowIdx = atoi(argv[2]); + x0startOriginInterval = strtod(argv[3], NULL); + stepX0 = strtod(argv[4], NULL); + strcpy(fileNameKernel, argv[5]); + strcpy(uniqueLabel, argv[6]); + } + else + { + printf("Usage: ./test1paramFPEDParallel.exe [x0Start x0End testNumX0 fileNameKernel]\n"); + printf("Usage: if no correct input:\n"); + printf("Usage: \tthe fixed inputs [%g %g %lu] will be used\n", x0Start.d, x0End.d, testNumX0); + } + + if(myid == 0) { + printf("\n---------------------------------------------------start test1paramFPEDParallel\n"); + printf("Parameters: x0Start: %lg, x0End: %lg, testNumX0 = %lu, fileNameKernel: %s\n", x0Start.d, x0End.d, testNumX0, fileNameKernel); + } + + // local parameters init + int lenX0Local = testNumX0 / numProcs; + int i0StartLocal; + i0StartLocal = x0startNowIdx + myid * lenX0Local; + int i0EndLocal; + if(myid != numProcs - 1) { + i0EndLocal = x0startNowIdx + (myid + 1) * lenX0Local - 1; + } else { + i0EndLocal = x0startNowIdx + testNumX0; + } + string uniqueLabelStr(uniqueLabel); + string fileNameKernelStr(fileNameKernel); + iRRAM_initialize(argc, argv); + iRRAM::iRRAM_exec(main_inner, testNumX0, uniqueLabelStr, fileNameKernelStr, myid, numProcs, i0StartLocal, i0EndLocal, x0startOriginInterval, stepX0); + + MPI_Finalize(); + return 0; +} \ No newline at end of file -- Gitee From 4afbab76234edc0ae19c5dad3f72c8a609542880 Mon Sep 17 00:00:00 2001 From: hjwLab Date: Wed, 12 Apr 2023 09:53:51 +0800 Subject: [PATCH 04/32] revert ./srcTest/test1paramFPEDParallel.c --- srcTest/test1paramFPEDParallel.c | 40 +++++--------------------------- 1 file changed, 6 insertions(+), 34 deletions(-) diff --git a/srcTest/test1paramFPEDParallel.c b/srcTest/test1paramFPEDParallel.c index d7e80a7..8e9f5a2 100644 --- a/srcTest/test1paramFPEDParallel.c +++ b/srcTest/test1paramFPEDParallel.c @@ -1,22 +1,3 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "iRRAM/lib.h" - -using namespace std; -using namespace iRRAM; -// int iRRAM::MAXiterationnum = 30; -// bool iRRAM::enableReiterate = true; -// bool iRRAM::alwaysenableReiterate = true; - -extern "C" -{ #include "common.h" #include "mpi.h" @@ -43,7 +24,6 @@ struct errorInfo { #ifndef ERRFILE #define ERRFILE 0 #endif - double EXPRESSIONMPFR(double, mpfr_t); double EXPRESSIONMINE(double); @@ -61,7 +41,6 @@ int computeResult1param(double x0, mpfr_t mpfrResult) return status; } -} struct errorInfo test1FPEDparamParallel(DL x0Start, DL x0End, unsigned long int testNumX0, const char* uniqueLabel, const char* fileNameKernel, int myid, int i0StartLocal, int i0EndLocal, double x0startOriginInterval, double stepX0) { DL maxInputX0; @@ -104,10 +83,6 @@ struct errorInfo test1FPEDparamParallel(DL x0Start, DL x0End, unsigned long int // x0 = ii0.d; for(i0 = i0StartLocal; i0 <= i0EndLocal; i0++) { x0 = x0startOriginInterval + stepX0 * i0; - if(myid == 2) - { - printf("i0 = %d, x0 = %lf\n", i0, x0); - } computeResult1param(x0, mpfrResult); computeOrcle1param(x0, mpfrOrcle); #ifdef SINGLE @@ -162,9 +137,6 @@ struct errorInfo test1FPEDparamParallel(DL x0Start, DL x0End, unsigned long int int main(int argc, char **argv) { - // NumOpt - iRRAM_initialize(argc,argv); - // parallel int myid, numProcs; MPI_Init(&argc, &argv); @@ -186,9 +158,9 @@ int main(int argc, char **argv) testNumX0 = TESTNUMX0; char *fileNameKernel; - fileNameKernel = (char *)calloc(256, sizeof(char)); + fileNameKernel = calloc(256, sizeof(char)); char *uniqueLabel; - uniqueLabel = (char *)calloc(256, sizeof(char)); + uniqueLabel = calloc(256, sizeof(char)); if (argc == 9) { x0Start.d = strtod(argv[1], NULL); @@ -226,10 +198,10 @@ int main(int argc, char **argv) printf("Usage: \tthe fixed inputs [%g %g %lu] will be used\n", x0Start.d, x0End.d, testNumX0); } - if(myid == 0) { - printf("\n---------------------------------------------------start test1paramFPEDParallel\n"); - printf("Parameters: x0Start: %lg, x0End: %lg, testNumX0 = %lu, fileNameKernel: %s\n", x0Start.d, x0End.d, testNumX0, fileNameKernel); - } + // if(myid == 0) { + // printf("\n---------------------------------------------------start test1paramFPEDParallel\n"); + // printf("Parameters: x0Start: %lg, x0End: %lg, testNumX0 = %lu, fileNameKernel: %s\n", x0Start.d, x0End.d, testNumX0, fileNameKernel); + // } // local parameters init int lenX0Local = testNumX0 / numProcs; -- Gitee From bd7bf3b70a2c61b9fcd25c2b6d43b82af17fdeef Mon Sep 17 00:00:00 2001 From: hjwLab Date: Wed, 12 Apr 2023 10:08:45 +0800 Subject: [PATCH 05/32] Implement geneErrorDetectScript --- include/tools.hpp | 2 ++ src/tools.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/include/tools.hpp b/include/tools.hpp index 3da62f3..ecbcfdc 100644 --- a/include/tools.hpp +++ b/include/tools.hpp @@ -38,6 +38,8 @@ exprInfo testError(string uniqueLabel, string suffix, double x0Start, double x0E exprInfo testError(string uniqueLabel, string suffix, double x0Start, double x0End, double x1Start, double x1End, double x2Start, double x2End, int x0Size, int x1Size, int x2Size); +void geneErrorDetectScript(string uniqueLabel, string suffix, const vector &intervals, const vector &scales, const vector &startNowIdxs, const vector &startOriginIntervals, const vector &steps); + double testPerformance(string uniqueLabel, string suffix, const vector &intervals); string geneBoundaryData(string uniqueLabel, string suffix, double &costTime); diff --git a/src/tools.cpp b/src/tools.cpp index 0a2185d..30f6ea7 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -531,6 +531,71 @@ void sampleError(string uniqueLabel, string suffix, const vector &interv } } +void geneErrorDetectScript(string uniqueLabel, string suffix, const vector &intervals, const vector &scales, const vector &startNowIdxs, const vector &startOriginIntervals, const vector &steps) +{ + size_t size = scales.size(); + + if (size < 4) + { + string prefix = "expr_" + uniqueLabel; + vector params; + for(const auto &interval : intervals) + { + auto paraTmp = fmt::format("{}", interval); + params.push_back(paraTmp); + } + for(const auto &scale : scales) + { + auto scaleTmp = fmt::format("{}", scale); + params.push_back(scaleTmp); + } + string middle; // do not need to add startNowIdx and startOriginInterval to middle + for(size_t i = 0; i < params.size(); ++i) + { + if(i == 0) + { + middle = params.at(i); + } + else + { + middle = middle + "_" + params.at(i); + } + } + for(const auto &startNowIdx : startNowIdxs) + { + auto startNowIdxTmp = fmt::format("{}", startNowIdx); + params.push_back(startNowIdxTmp); + } + for(const auto &startOriginInterval : startOriginIntervals) + { + auto startOriginIntervalTmp = fmt::format("{}", startOriginInterval); + params.push_back(startOriginIntervalTmp); + } + for(const auto &step : steps) + { + auto stepTmp = fmt::format("{}", step); + params.push_back(stepTmp); + } + string fileNameKernel = prefix + "__" + middle + "_" + suffix; + namespace fs = std::filesystem; + string currentPath = fs::current_path(); + string testName = currentPath + "/outputs/" + uniqueLabel + "/" + fileNameKernel + "_error.txt"; // get the output of error detecting + string number[3] = {"One", "Two", "Three"}; + string scriptName = "./detectError" + number[size - 1] + "FPEDParallel${suffix}.sh"; + stringstream ss; + ss << scriptName << " " << uniqueLabel; + for(const auto & param : params) + { + ss << " " << param; + } + ss << " " << prefix << " " << middle << " " << "${target}" << " "; + string commandStr = ss.str(); + + // cout << "fileNameKernel: " << fileNameKernel << "\n"; + cout << commandStr << "\n"; + } +} + double testPerformance(string uniqueLabel, string suffix, const vector &intervals) { size_t size = intervals.size() / 2; -- Gitee From 9536b726a0a5086511dbff888ecef243ff9cbea4 Mon Sep 17 00:00:00 2001 From: hjwLab Date: Wed, 12 Apr 2023 10:09:56 +0800 Subject: [PATCH 06/32] Improve code style --- src/main.cpp | 24 +++++++++++++++++++----- srcTest/test1paramFPEDParallelNumOpt.cpp | 8 ++++---- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 44251e6..a984af6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -166,8 +166,8 @@ int main() fprintf(stderr, GREEN "ready> " RESET); string inputStr = ""; - // while (getline(infile, inputStr)) // read line from file's input - while (getline(cin, inputStr)) // read line from keyboard input + while (getline(infile, inputStr)) // read line from file's input + // while (getline(cin, inputStr)) // read line from keyboard input { // only rewrite // getlineCount++; @@ -293,6 +293,23 @@ int main() system(mkdirCommand.c_str()); auto exprOrigin = geneExprCodeKernel(inputStr, vars, uniqueLabel, "origin"); + + vector startNowIdxsTmp(dimension, 0); + vector startOriginIntervalsTmp; + vector stepsTmp; + for (int i = 0; i < dimension; i++) + { + auto &startOriginInterval = intervals.at(i * 2); + auto &endOriginInterval = intervals.at(i * 2 + 1); + startOriginIntervalsTmp.push_back(startOriginInterval); + double width = endOriginInterval - startOriginInterval; + double step = width / (double)scales.at(i); + stepsTmp.push_back(step); + } + geneErrorDetectScript(uniqueLabel, "tmp", intervals, scales, startNowIdxsTmp, startOriginIntervalsTmp, stepsTmp); + fprintf(stderr, GREEN "ready> " RESET); + continue; + // auto funcNameOrigin = geneExprCode(inputStr, uniqueLabel, "origin"); // auto funcNameHerbie = geneHerbieCode(inputStr, uniqueLabel, "herbie"); auto exprHerbie = geneHerbieCode(uniqueLabel); @@ -362,9 +379,6 @@ int main() init_seconds = timeTmp1 - timeStart; cout << BLUE << "init time: " << init_seconds.count() << " s" << RESET << endl; - fprintf(stderr, GREEN "ready> " RESET); - continue; - auto &initExprMaxError = initExprInfo.maxError; if (initExprMaxError <= 0.5) { diff --git a/srcTest/test1paramFPEDParallelNumOpt.cpp b/srcTest/test1paramFPEDParallelNumOpt.cpp index a1961e3..c8d7da9 100644 --- a/srcTest/test1paramFPEDParallelNumOpt.cpp +++ b/srcTest/test1paramFPEDParallelNumOpt.cpp @@ -202,12 +202,12 @@ int main_inner(const unsigned long int &testNumX0, const string &uniqueLabelStr, DL maxInputX0; maxInputX0.d = errs[maxErrorIdx].maxInputX0; + std::string directory{"./outputs"}; + std::string suffixErr("error.txt"); FILE *fErr; - char *directory = "./outputs"; - char *suffixErr = "error.txt"; char *fileNameErr; - fileNameErr = (char *) calloc(strlen(directory) + strlen(uniqueLabel) + strlen(fileNameKernel) + strlen(suffixErr) + 128, sizeof(char)); - sprintf(fileNameErr, "%s/%s/%s_%s", directory, uniqueLabel, fileNameKernel, suffixErr); + fileNameErr = (char *) calloc(directory.length() + strlen(uniqueLabel) + strlen(fileNameKernel) + suffixErr.length() + 128, sizeof(char)); + sprintf(fileNameErr, "%s/%s/%s_%s", directory.c_str(), uniqueLabel, fileNameKernel, suffixErr.c_str()); if ((fErr = fopen(fileNameErr, "w")) == NULL) { printf("Error opening file %s.\n", fileNameErr); -- Gitee From cbd2d4612b83722b6cfe9a8970f05c4879bd57e5 Mon Sep 17 00:00:00 2001 From: hjwLab Date: Wed, 12 Apr 2023 10:10:24 +0800 Subject: [PATCH 07/32] Improve detectErrorAll.sh --- detectErrorAll.sh | 69 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 66 insertions(+), 3 deletions(-) mode change 100644 => 100755 detectErrorAll.sh diff --git a/detectErrorAll.sh b/detectErrorAll.sh old mode 100644 new mode 100755 index 2f2f63a..6fa6180 --- a/detectErrorAll.sh +++ b/detectErrorAll.sh @@ -1,4 +1,67 @@ #!/bin/bash -set -x -target=NumOpt -./detectErrorOneFPEDParallel${target}.sh Bsplines3 0 1 500000 0 0 2e-06 expr_Bsplines3 0_1_500000 ${target} \ No newline at end of file +# set -x +if [ $# -eq 1 ]; then + target=${1} +else + target=origin +fi + +if [ $target == "origin" ]; then + suffix="" +elif [ $target == "NumOpt" ]; then + suffix="NumOpt" +else + echo "Invalid target" + exit +fi + +./detectErrorOneFPEDParallel${suffix}.sh Bsplines3 0 1 500000 0 0 2e-06 expr_Bsplines3 0_1_500000 ${target} +./detectErrorOneFPEDParallel${suffix}.sh exp1x 0.01 0.5 500000 0 0.01 9.8e-07 expr_exp1x 0.01_0.5_500000 ${target} +./detectErrorOneFPEDParallel${suffix}.sh exp1x_log 0.01 0.5 500000 0 0.01 9.8e-07 expr_exp1x_log 0.01_0.5_500000 ${target} +./detectErrorOneFPEDParallel${suffix}.sh intro_example 0 999 500000 0 0 0.001998 expr_intro_example 0_999_500000 ${target} +./detectErrorOneFPEDParallel${suffix}.sh logexp -8 8 500000 0 -8 3.2e-05 expr_logexp -8_8_500000 ${target} +./detectErrorOneFPEDParallel${suffix}.sh NMSEexample31 0.01 100 500000 0 0.01 0.00019998 expr_NMSEexample31 0.01_100_500000 ${target} +./detectErrorOneFPEDParallel${suffix}.sh NMSEexample310 -1 1 500000 0 -1 4e-06 expr_NMSEexample310 -1_1_500000 ${target} +./detectErrorOneFPEDParallel${suffix}.sh NMSEexample34 0.01 3 500000 0 0.01 5.98e-06 expr_NMSEexample34 0.01_3_500000 ${target} +./detectErrorOneFPEDParallel${suffix}.sh NMSEexample35 0.01 100 500000 0 0.01 0.00019998 expr_NMSEexample35 0.01_100_500000 ${target} +./detectErrorOneFPEDParallel${suffix}.sh NMSEexample36 0.01 100 500000 0 0.01 0.00019998 expr_NMSEexample36 0.01_100_500000 ${target} +./detectErrorOneFPEDParallel${suffix}.sh NMSEexample37 0.01 100 500000 0 0.01 0.00019998 expr_NMSEexample37 0.01_100_500000 ${target} +./detectErrorOneFPEDParallel${suffix}.sh NMSEexample38 0.01 100 500000 0 0.01 0.00019998 expr_NMSEexample38 0.01_100_500000 ${target} +./detectErrorOneFPEDParallel${suffix}.sh NMSEexample39 0.01 1 500000 0 0.01 1.98e-06 expr_NMSEexample39 0.01_1_500000 ${target} +./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem331 0.01 100 500000 0 0.01 0.00019998 expr_NMSEproblem331 0.01_100_500000 ${target} +./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem333 0.01 0.99 500000 0 0.01 1.96e-06 expr_NMSEproblem333 0.01_0.99_500000 ${target} +./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem334 0.01 100 500000 0 0.01 0.00019998 expr_NMSEproblem334 0.01_100_500000 ${target} +./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem336 0.01 100 500000 0 0.01 0.00019998 expr_NMSEproblem336 0.01_100_500000 ${target} +./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem337 0.01 100 500000 0 0.01 0.00019998 expr_NMSEproblem337 0.01_100_500000 ${target} +./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem341 0.01 100 500000 0 0.01 0.00019998 expr_NMSEproblem341 0.01_100_500000 ${target} +./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem343 -1 1 500000 0 -1 4e-06 expr_NMSEproblem343 -1_1_500000 ${target} +./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem344 0.01 100 500000 0 0.01 0.00019998 expr_NMSEproblem344 0.01_100_500000 ${target} +./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem345 0.01 100 500000 0 0.01 0.00019998 expr_NMSEproblem345 0.01_100_500000 ${target} +./detectErrorOneFPEDParallel${suffix}.sh NMSEsection311 0.01 100 500000 0 0.01 0.00019998 expr_NMSEsection311 0.01_100_500000 ${target} +./detectErrorOneFPEDParallel${suffix}.sh predatorPrey 0.1 0.3 500000 0 0.1 4e-07 expr_predatorPrey 0.1_0.3_500000 ${target} +./detectErrorOneFPEDParallel${suffix}.sh sine -1.57079632679 1.57079632679 500000 0 -1.57079632679 6.28318530716e-06 expr_sine -1.57079632679_1.57079632679_500000 ${target} +./detectErrorOneFPEDParallel${suffix}.sh sineorder3 -2 2 500000 0 -2 8e-06 expr_sineorder3 -2_2_500000 ${target} +./detectErrorOneFPEDParallel${suffix}.sh sqroot 0 1 500000 0 0 2e-06 expr_sqroot 0_1_500000 ${target} +./detectErrorOneFPEDParallel${suffix}.sh sqrt_add 1 1000 500000 0 1 0.001998 expr_sqrt_add 1_1000_500000 ${target} +./detectErrorOneFPEDParallel${suffix}.sh test05_nonlin1_r4 1.00001 2 500000 0 1.00001 1.9999799999999998e-06 expr_test05_nonlin1_r4 1.00001_2_500000 ${target} +./detectErrorOneFPEDParallel${suffix}.sh test05_nonlin1_test2 1.00001 2 500000 0 1.00001 1.9999799999999998e-06 expr_test05_nonlin1_test2 1.00001_2_500000 ${target} +./detectErrorOneFPEDParallel${suffix}.sh verhulst 0.1 0.3 500000 0 0.1 4e-07 expr_verhulst 0.1_0.3_500000 ${target} +./detectErrorTwoFPEDParallel${suffix}.sh ComplexSinCos 0 1 0 1 1024 1024 0 0 0 0 0.0009765625 0.0009765625 expr_ComplexSinCos 0_1_0_1_1024_1024 ${target} +./detectErrorTwoFPEDParallel${suffix}.sh ComplexSquareRoot 0 1 0 1 1024 1024 0 0 0 0 0.0009765625 0.0009765625 expr_ComplexSquareRoot 0_1_0_1_1024_1024 ${target} +./detectErrorThreeFPEDParallel${suffix}.sh doppler1 -30 50 -100 100 20 20000 256 256 256 0 0 0 -30 -100 20 0.3125 0.78125 78.046875 expr_doppler1 -30_50_-100_100_20_20000_256_256_256 ${target} +./detectErrorThreeFPEDParallel${suffix}.sh doppler2 -40 60 -125 125 15 25000 256 256 256 0 0 0 -40 -125 15 0.390625 0.9765625 97.59765625 expr_doppler2 -40_60_-125_125_15_25000_256_256_256 ${target} +./detectErrorThreeFPEDParallel${suffix}.sh doppler3 -50 30 -30 120 320 20300 256 256 256 0 0 0 -50 -30 320 0.3125 0.5859375 78.046875 expr_doppler3 -50_30_-30_120_320_20300_256_256_256 ${target} +./detectErrorTwoFPEDParallel${suffix}.sh hypot32 1 100 1 100 1024 1024 0 0 1 1 0.0966796875 0.0966796875 expr_hypot32 1_100_1_100_1024_1024 ${target} +./detectErrorTwoFPEDParallel${suffix}.sh i4 0.1 10 -5 5 1024 1024 0 0 0.1 -5 0.00966796875 0.009765625 expr_i4 0.1_10_-5_5_1024_1024 ${target} +./detectErrorTwoFPEDParallel${suffix}.sh i6 0.1 10 -5 5 1024 1024 0 0 0.1 -5 0.00966796875 0.009765625 expr_i6 0.1_10_-5_5_1024_1024 ${target} +./detectErrorTwoFPEDParallel${suffix}.sh NMSEexample33 0 100 0 100 1024 1024 0 0 0 0 0.09765625 0.09765625 expr_NMSEexample33 0_100_0_100_1024_1024 ${target} +./detectErrorTwoFPEDParallel${suffix}.sh NMSEproblem332 0 100 0 100 1024 1024 0 0 0 0 0.09765625 0.09765625 expr_NMSEproblem332 0_100_0_100_1024_1024 ${target} +./detectErrorTwoFPEDParallel${suffix}.sh NMSEproblem335 0 100 0 100 1024 1024 0 0 0 0 0.09765625 0.09765625 expr_NMSEproblem335 0_100_0_100_1024_1024 ${target} +./detectErrorTwoFPEDParallel${suffix}.sh NMSEproblem346 1 2 0 1 1024 1024 0 0 1 0 0.0009765625 0.0009765625 expr_NMSEproblem346 1_2_0_1_1024_1024 ${target} +./detectErrorTwoFPEDParallel${suffix}.sh NMSEsection35 0 1 0 1 1024 1024 0 0 0 0 0.0009765625 0.0009765625 expr_NMSEsection35 0_1_0_1_1024_1024 ${target} +./detectErrorTwoFPEDParallel${suffix}.sh polarToCarthesianX 1 10 0 360 1024 1024 0 0 1 0 0.0087890625 0.3515625 expr_polarToCarthesianX 1_10_0_360_1024_1024 ${target} +./detectErrorTwoFPEDParallel${suffix}.sh polarToCarthesianY 1 10 0 360 1024 1024 0 0 1 0 0.0087890625 0.3515625 expr_polarToCarthesianY 1_10_0_360_1024_1024 ${target} +./detectErrorTwoFPEDParallel${suffix}.sh sec4example 1.001 2 1.001 2 1024 1024 0 0 1.001 1.001 0.0009755859375000001 0.0009755859375000001 expr_sec4example 1.001_2_1.001_2_1024_1024 ${target} +./detectErrorTwoFPEDParallel${suffix}.sh test03_nonlin2 0 1 -1 -0.1 1024 1024 0 0 0 -1 0.0009765625 0.00087890625 expr_test03_nonlin2 0_1_-1_-0.1_1024_1024 ${target} +./detectErrorTwoFPEDParallel${suffix}.sh theta 1 100 1 100 1024 1024 0 0 1 1 0.0966796875 0.0966796875 expr_theta 1_100_1_100_1024_1024 ${target} +./detectErrorThreeFPEDParallel${suffix}.sh turbine1 3.8 7.8 -4.5 -0.3 0.4 0.9 256 256 256 0 0 0 3.8 -4.5 0.4 0.015625 0.01640625 0.001953125 expr_turbine1 3.8_7.8_-4.5_-0.3_0.4_0.9_256_256_256 ${target} -- Gitee From a3e250d642579de7dfe959131df47ac87dc1c294 Mon Sep 17 00:00:00 2001 From: hjwLab Date: Wed, 12 Apr 2023 15:32:02 +0800 Subject: [PATCH 08/32] Add NumOpt code and the transfer scripts, update detectErrorAll.sh --- .gitignore | 1 + detectErrorAll.sh | 109 ++--- script/input/ComplexSinCos_opt.cc | 56 +++ script/input/ComplexSquareRoot_opt.cc | 51 +++ script/input/NMSEexample310_opt.cc | 44 ++ script/input/NMSEexample31_opt.cc | 94 ++++ script/input/NMSEexample33_opt.cc | 276 ++++++++++++ script/input/NMSEexample34_opt.cc | 59 +++ script/input/NMSEexample35_opt.cc | 59 +++ script/input/NMSEexample36_opt.cc | 69 +++ script/input/NMSEexample37_opt.cc | 69 +++ script/input/NMSEexample38_opt.cc | 124 ++++++ script/input/NMSEexample39_opt.cc | 79 ++++ script/input/NMSEproblem331_opt.cc | 109 +++++ script/input/NMSEproblem332_opt.cc | 296 +++++++++++++ script/input/NMSEproblem333_opt.cc | 49 +++ script/input/NMSEproblem335_opt.cc | 156 +++++++ script/input/NMSEproblem336_opt.cc | 74 ++++ script/input/NMSEproblem337_opt.cc | 54 +++ script/input/NMSEproblem341_opt.cc | 79 ++++ script/input/NMSEproblem343_opt.cc | 49 +++ script/input/NMSEproblem344_opt.cc | 109 +++++ script/input/NMSEsection311_opt.cc | 64 +++ script/input/NMSEsection35_opt.cc | 301 +++++++++++++ script/input/doppler1_opt.cc | 53 +++ script/input/doppler2_opt.cc | 53 +++ script/input/doppler3_opt.cc | 53 +++ script/input/i4_opt.cc | 46 ++ script/input/i6_opt.cc | 401 ++++++++++++++++++ script/input/intro_example_opt.cc | 49 +++ script/input/logexp_opt.cc | 49 +++ script/input/polarToCarthesianX_opt.cc | 51 +++ script/input/predatorPrey_opt.cc | 49 +++ script/input/sine_opt.cc | 49 +++ script/input/sineorder3_opt.cc | 49 +++ script/input/sqroot_opt.cc | 49 +++ script/input/sqrt_add_opt.cc | 49 +++ script/input/test05_nonlin1_r4_opt.cc | 59 +++ script/input/test05_nonlin1_test2_opt.cc | 49 +++ script/input/verhulst_opt.cc | 49 +++ script/prefix.cpp | 18 + script/replace.sh | 11 + script/replaceAll.sh | 38 ++ script/suffix.cpp | 8 + .../expr_ComplexSinCos_NumOpt.cpp | 50 +++ .../expr_ComplexSquareRoot_NumOpt.cpp | 45 ++ .../expr_NMSEexample31_NumOpt.cpp | 89 ++++ .../expr_NMSEexample310_NumOpt.cpp | 39 ++ .../expr_NMSEexample33_NumOpt.cpp | 270 ++++++++++++ .../expr_NMSEexample34_NumOpt.cpp | 54 +++ .../expr_NMSEexample35_NumOpt.cpp | 54 +++ .../expr_NMSEexample36_NumOpt.cpp | 64 +++ .../expr_NMSEexample37_NumOpt.cpp | 64 +++ .../expr_NMSEexample38_NumOpt.cpp | 119 ++++++ .../expr_NMSEexample39_NumOpt.cpp | 74 ++++ .../expr_NMSEproblem331_NumOpt.cpp | 104 +++++ .../expr_NMSEproblem332_NumOpt.cpp | 290 +++++++++++++ .../expr_NMSEproblem333_NumOpt.cpp | 44 ++ .../expr_NMSEproblem335_NumOpt.cpp | 150 +++++++ .../expr_NMSEproblem336_NumOpt.cpp | 69 +++ .../expr_NMSEproblem337_NumOpt.cpp | 49 +++ .../expr_NMSEproblem341_NumOpt.cpp | 74 ++++ .../expr_NMSEproblem343_NumOpt.cpp | 44 ++ .../expr_NMSEproblem344_NumOpt.cpp | 104 +++++ .../expr_NMSEsection311_NumOpt.cpp | 59 +++ .../expr_NMSEsection35_NumOpt.cpp | 295 +++++++++++++ srcTest/doppler1/expr_doppler1_NumOpt.cpp | 46 ++ srcTest/doppler2/expr_doppler2_NumOpt.cpp | 46 ++ srcTest/doppler3/expr_doppler3_NumOpt.cpp | 46 ++ srcTest/exp1x/expr_exp1x_NumOpt.cpp | 3 +- srcTest/i4/expr_i4_NumOpt.cpp | 40 ++ srcTest/i6/expr_i6_NumOpt.cpp | 395 +++++++++++++++++ .../expr_intro_example_NumOpt.cpp | 44 ++ srcTest/logexp/expr_logexp_NumOpt.cpp | 44 ++ .../expr_polarToCarthesianX_NumOpt.cpp | 45 ++ .../predatorPrey/expr_predatorPrey_NumOpt.cpp | 44 ++ srcTest/sine/expr_sine_NumOpt.cpp | 44 ++ srcTest/sineorder3/expr_sineorder3_NumOpt.cpp | 44 ++ srcTest/sqroot/expr_sqroot_NumOpt.cpp | 44 ++ srcTest/sqrt_add/expr_sqrt_add_NumOpt.cpp | 44 ++ .../expr_test05_nonlin1_r4_NumOpt.cpp | 54 +++ .../expr_test05_nonlin1_test2_NumOpt.cpp | 44 ++ srcTest/verhulst/expr_verhulst_NumOpt.cpp | 44 ++ 83 files changed, 6884 insertions(+), 53 deletions(-) create mode 100644 script/input/ComplexSinCos_opt.cc create mode 100644 script/input/ComplexSquareRoot_opt.cc create mode 100644 script/input/NMSEexample310_opt.cc create mode 100644 script/input/NMSEexample31_opt.cc create mode 100644 script/input/NMSEexample33_opt.cc create mode 100644 script/input/NMSEexample34_opt.cc create mode 100644 script/input/NMSEexample35_opt.cc create mode 100644 script/input/NMSEexample36_opt.cc create mode 100644 script/input/NMSEexample37_opt.cc create mode 100644 script/input/NMSEexample38_opt.cc create mode 100644 script/input/NMSEexample39_opt.cc create mode 100644 script/input/NMSEproblem331_opt.cc create mode 100644 script/input/NMSEproblem332_opt.cc create mode 100644 script/input/NMSEproblem333_opt.cc create mode 100644 script/input/NMSEproblem335_opt.cc create mode 100644 script/input/NMSEproblem336_opt.cc create mode 100644 script/input/NMSEproblem337_opt.cc create mode 100644 script/input/NMSEproblem341_opt.cc create mode 100644 script/input/NMSEproblem343_opt.cc create mode 100644 script/input/NMSEproblem344_opt.cc create mode 100644 script/input/NMSEsection311_opt.cc create mode 100644 script/input/NMSEsection35_opt.cc create mode 100644 script/input/doppler1_opt.cc create mode 100644 script/input/doppler2_opt.cc create mode 100644 script/input/doppler3_opt.cc create mode 100644 script/input/i4_opt.cc create mode 100644 script/input/i6_opt.cc create mode 100644 script/input/intro_example_opt.cc create mode 100644 script/input/logexp_opt.cc create mode 100644 script/input/polarToCarthesianX_opt.cc create mode 100644 script/input/predatorPrey_opt.cc create mode 100644 script/input/sine_opt.cc create mode 100644 script/input/sineorder3_opt.cc create mode 100644 script/input/sqroot_opt.cc create mode 100644 script/input/sqrt_add_opt.cc create mode 100644 script/input/test05_nonlin1_r4_opt.cc create mode 100644 script/input/test05_nonlin1_test2_opt.cc create mode 100644 script/input/verhulst_opt.cc create mode 100644 script/prefix.cpp create mode 100755 script/replace.sh create mode 100644 script/replaceAll.sh create mode 100644 script/suffix.cpp create mode 100644 srcTest/ComplexSinCos/expr_ComplexSinCos_NumOpt.cpp create mode 100644 srcTest/ComplexSquareRoot/expr_ComplexSquareRoot_NumOpt.cpp create mode 100644 srcTest/NMSEexample31/expr_NMSEexample31_NumOpt.cpp create mode 100644 srcTest/NMSEexample310/expr_NMSEexample310_NumOpt.cpp create mode 100644 srcTest/NMSEexample33/expr_NMSEexample33_NumOpt.cpp create mode 100644 srcTest/NMSEexample34/expr_NMSEexample34_NumOpt.cpp create mode 100644 srcTest/NMSEexample35/expr_NMSEexample35_NumOpt.cpp create mode 100644 srcTest/NMSEexample36/expr_NMSEexample36_NumOpt.cpp create mode 100644 srcTest/NMSEexample37/expr_NMSEexample37_NumOpt.cpp create mode 100644 srcTest/NMSEexample38/expr_NMSEexample38_NumOpt.cpp create mode 100644 srcTest/NMSEexample39/expr_NMSEexample39_NumOpt.cpp create mode 100644 srcTest/NMSEproblem331/expr_NMSEproblem331_NumOpt.cpp create mode 100644 srcTest/NMSEproblem332/expr_NMSEproblem332_NumOpt.cpp create mode 100644 srcTest/NMSEproblem333/expr_NMSEproblem333_NumOpt.cpp create mode 100644 srcTest/NMSEproblem335/expr_NMSEproblem335_NumOpt.cpp create mode 100644 srcTest/NMSEproblem336/expr_NMSEproblem336_NumOpt.cpp create mode 100644 srcTest/NMSEproblem337/expr_NMSEproblem337_NumOpt.cpp create mode 100644 srcTest/NMSEproblem341/expr_NMSEproblem341_NumOpt.cpp create mode 100644 srcTest/NMSEproblem343/expr_NMSEproblem343_NumOpt.cpp create mode 100644 srcTest/NMSEproblem344/expr_NMSEproblem344_NumOpt.cpp create mode 100644 srcTest/NMSEsection311/expr_NMSEsection311_NumOpt.cpp create mode 100644 srcTest/NMSEsection35/expr_NMSEsection35_NumOpt.cpp create mode 100644 srcTest/doppler1/expr_doppler1_NumOpt.cpp create mode 100644 srcTest/doppler2/expr_doppler2_NumOpt.cpp create mode 100644 srcTest/doppler3/expr_doppler3_NumOpt.cpp create mode 100644 srcTest/i4/expr_i4_NumOpt.cpp create mode 100644 srcTest/i6/expr_i6_NumOpt.cpp create mode 100644 srcTest/intro_example/expr_intro_example_NumOpt.cpp create mode 100644 srcTest/logexp/expr_logexp_NumOpt.cpp create mode 100644 srcTest/polarToCarthesianX/expr_polarToCarthesianX_NumOpt.cpp create mode 100644 srcTest/predatorPrey/expr_predatorPrey_NumOpt.cpp create mode 100644 srcTest/sine/expr_sine_NumOpt.cpp create mode 100644 srcTest/sineorder3/expr_sineorder3_NumOpt.cpp create mode 100644 srcTest/sqroot/expr_sqroot_NumOpt.cpp create mode 100644 srcTest/sqrt_add/expr_sqrt_add_NumOpt.cpp create mode 100644 srcTest/test05_nonlin1_r4/expr_test05_nonlin1_r4_NumOpt.cpp create mode 100644 srcTest/test05_nonlin1_test2/expr_test05_nonlin1_test2_NumOpt.cpp create mode 100644 srcTest/verhulst/expr_verhulst_NumOpt.cpp diff --git a/.gitignore b/.gitignore index 5927ad7..3b424da 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,7 @@ build/ srcGen/ libs/ +script/output/ main *.txt __pycache__/ diff --git a/detectErrorAll.sh b/detectErrorAll.sh index 6fa6180..74906ed 100755 --- a/detectErrorAll.sh +++ b/detectErrorAll.sh @@ -3,7 +3,7 @@ if [ $# -eq 1 ]; then target=${1} else - target=origin + target=NumOpt fi if [ $target == "origin" ]; then @@ -15,53 +15,60 @@ else exit fi -./detectErrorOneFPEDParallel${suffix}.sh Bsplines3 0 1 500000 0 0 2e-06 expr_Bsplines3 0_1_500000 ${target} -./detectErrorOneFPEDParallel${suffix}.sh exp1x 0.01 0.5 500000 0 0.01 9.8e-07 expr_exp1x 0.01_0.5_500000 ${target} -./detectErrorOneFPEDParallel${suffix}.sh exp1x_log 0.01 0.5 500000 0 0.01 9.8e-07 expr_exp1x_log 0.01_0.5_500000 ${target} -./detectErrorOneFPEDParallel${suffix}.sh intro_example 0 999 500000 0 0 0.001998 expr_intro_example 0_999_500000 ${target} -./detectErrorOneFPEDParallel${suffix}.sh logexp -8 8 500000 0 -8 3.2e-05 expr_logexp -8_8_500000 ${target} -./detectErrorOneFPEDParallel${suffix}.sh NMSEexample31 0.01 100 500000 0 0.01 0.00019998 expr_NMSEexample31 0.01_100_500000 ${target} -./detectErrorOneFPEDParallel${suffix}.sh NMSEexample310 -1 1 500000 0 -1 4e-06 expr_NMSEexample310 -1_1_500000 ${target} -./detectErrorOneFPEDParallel${suffix}.sh NMSEexample34 0.01 3 500000 0 0.01 5.98e-06 expr_NMSEexample34 0.01_3_500000 ${target} -./detectErrorOneFPEDParallel${suffix}.sh NMSEexample35 0.01 100 500000 0 0.01 0.00019998 expr_NMSEexample35 0.01_100_500000 ${target} -./detectErrorOneFPEDParallel${suffix}.sh NMSEexample36 0.01 100 500000 0 0.01 0.00019998 expr_NMSEexample36 0.01_100_500000 ${target} -./detectErrorOneFPEDParallel${suffix}.sh NMSEexample37 0.01 100 500000 0 0.01 0.00019998 expr_NMSEexample37 0.01_100_500000 ${target} -./detectErrorOneFPEDParallel${suffix}.sh NMSEexample38 0.01 100 500000 0 0.01 0.00019998 expr_NMSEexample38 0.01_100_500000 ${target} -./detectErrorOneFPEDParallel${suffix}.sh NMSEexample39 0.01 1 500000 0 0.01 1.98e-06 expr_NMSEexample39 0.01_1_500000 ${target} -./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem331 0.01 100 500000 0 0.01 0.00019998 expr_NMSEproblem331 0.01_100_500000 ${target} -./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem333 0.01 0.99 500000 0 0.01 1.96e-06 expr_NMSEproblem333 0.01_0.99_500000 ${target} -./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem334 0.01 100 500000 0 0.01 0.00019998 expr_NMSEproblem334 0.01_100_500000 ${target} -./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem336 0.01 100 500000 0 0.01 0.00019998 expr_NMSEproblem336 0.01_100_500000 ${target} -./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem337 0.01 100 500000 0 0.01 0.00019998 expr_NMSEproblem337 0.01_100_500000 ${target} -./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem341 0.01 100 500000 0 0.01 0.00019998 expr_NMSEproblem341 0.01_100_500000 ${target} -./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem343 -1 1 500000 0 -1 4e-06 expr_NMSEproblem343 -1_1_500000 ${target} -./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem344 0.01 100 500000 0 0.01 0.00019998 expr_NMSEproblem344 0.01_100_500000 ${target} -./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem345 0.01 100 500000 0 0.01 0.00019998 expr_NMSEproblem345 0.01_100_500000 ${target} -./detectErrorOneFPEDParallel${suffix}.sh NMSEsection311 0.01 100 500000 0 0.01 0.00019998 expr_NMSEsection311 0.01_100_500000 ${target} -./detectErrorOneFPEDParallel${suffix}.sh predatorPrey 0.1 0.3 500000 0 0.1 4e-07 expr_predatorPrey 0.1_0.3_500000 ${target} -./detectErrorOneFPEDParallel${suffix}.sh sine -1.57079632679 1.57079632679 500000 0 -1.57079632679 6.28318530716e-06 expr_sine -1.57079632679_1.57079632679_500000 ${target} -./detectErrorOneFPEDParallel${suffix}.sh sineorder3 -2 2 500000 0 -2 8e-06 expr_sineorder3 -2_2_500000 ${target} -./detectErrorOneFPEDParallel${suffix}.sh sqroot 0 1 500000 0 0 2e-06 expr_sqroot 0_1_500000 ${target} -./detectErrorOneFPEDParallel${suffix}.sh sqrt_add 1 1000 500000 0 1 0.001998 expr_sqrt_add 1_1000_500000 ${target} -./detectErrorOneFPEDParallel${suffix}.sh test05_nonlin1_r4 1.00001 2 500000 0 1.00001 1.9999799999999998e-06 expr_test05_nonlin1_r4 1.00001_2_500000 ${target} -./detectErrorOneFPEDParallel${suffix}.sh test05_nonlin1_test2 1.00001 2 500000 0 1.00001 1.9999799999999998e-06 expr_test05_nonlin1_test2 1.00001_2_500000 ${target} -./detectErrorOneFPEDParallel${suffix}.sh verhulst 0.1 0.3 500000 0 0.1 4e-07 expr_verhulst 0.1_0.3_500000 ${target} -./detectErrorTwoFPEDParallel${suffix}.sh ComplexSinCos 0 1 0 1 1024 1024 0 0 0 0 0.0009765625 0.0009765625 expr_ComplexSinCos 0_1_0_1_1024_1024 ${target} -./detectErrorTwoFPEDParallel${suffix}.sh ComplexSquareRoot 0 1 0 1 1024 1024 0 0 0 0 0.0009765625 0.0009765625 expr_ComplexSquareRoot 0_1_0_1_1024_1024 ${target} -./detectErrorThreeFPEDParallel${suffix}.sh doppler1 -30 50 -100 100 20 20000 256 256 256 0 0 0 -30 -100 20 0.3125 0.78125 78.046875 expr_doppler1 -30_50_-100_100_20_20000_256_256_256 ${target} -./detectErrorThreeFPEDParallel${suffix}.sh doppler2 -40 60 -125 125 15 25000 256 256 256 0 0 0 -40 -125 15 0.390625 0.9765625 97.59765625 expr_doppler2 -40_60_-125_125_15_25000_256_256_256 ${target} -./detectErrorThreeFPEDParallel${suffix}.sh doppler3 -50 30 -30 120 320 20300 256 256 256 0 0 0 -50 -30 320 0.3125 0.5859375 78.046875 expr_doppler3 -50_30_-30_120_320_20300_256_256_256 ${target} -./detectErrorTwoFPEDParallel${suffix}.sh hypot32 1 100 1 100 1024 1024 0 0 1 1 0.0966796875 0.0966796875 expr_hypot32 1_100_1_100_1024_1024 ${target} -./detectErrorTwoFPEDParallel${suffix}.sh i4 0.1 10 -5 5 1024 1024 0 0 0.1 -5 0.00966796875 0.009765625 expr_i4 0.1_10_-5_5_1024_1024 ${target} -./detectErrorTwoFPEDParallel${suffix}.sh i6 0.1 10 -5 5 1024 1024 0 0 0.1 -5 0.00966796875 0.009765625 expr_i6 0.1_10_-5_5_1024_1024 ${target} -./detectErrorTwoFPEDParallel${suffix}.sh NMSEexample33 0 100 0 100 1024 1024 0 0 0 0 0.09765625 0.09765625 expr_NMSEexample33 0_100_0_100_1024_1024 ${target} -./detectErrorTwoFPEDParallel${suffix}.sh NMSEproblem332 0 100 0 100 1024 1024 0 0 0 0 0.09765625 0.09765625 expr_NMSEproblem332 0_100_0_100_1024_1024 ${target} -./detectErrorTwoFPEDParallel${suffix}.sh NMSEproblem335 0 100 0 100 1024 1024 0 0 0 0 0.09765625 0.09765625 expr_NMSEproblem335 0_100_0_100_1024_1024 ${target} -./detectErrorTwoFPEDParallel${suffix}.sh NMSEproblem346 1 2 0 1 1024 1024 0 0 1 0 0.0009765625 0.0009765625 expr_NMSEproblem346 1_2_0_1_1024_1024 ${target} -./detectErrorTwoFPEDParallel${suffix}.sh NMSEsection35 0 1 0 1 1024 1024 0 0 0 0 0.0009765625 0.0009765625 expr_NMSEsection35 0_1_0_1_1024_1024 ${target} -./detectErrorTwoFPEDParallel${suffix}.sh polarToCarthesianX 1 10 0 360 1024 1024 0 0 1 0 0.0087890625 0.3515625 expr_polarToCarthesianX 1_10_0_360_1024_1024 ${target} -./detectErrorTwoFPEDParallel${suffix}.sh polarToCarthesianY 1 10 0 360 1024 1024 0 0 1 0 0.0087890625 0.3515625 expr_polarToCarthesianY 1_10_0_360_1024_1024 ${target} -./detectErrorTwoFPEDParallel${suffix}.sh sec4example 1.001 2 1.001 2 1024 1024 0 0 1.001 1.001 0.0009755859375000001 0.0009755859375000001 expr_sec4example 1.001_2_1.001_2_1024_1024 ${target} -./detectErrorTwoFPEDParallel${suffix}.sh test03_nonlin2 0 1 -1 -0.1 1024 1024 0 0 0 -1 0.0009765625 0.00087890625 expr_test03_nonlin2 0_1_-1_-0.1_1024_1024 ${target} -./detectErrorTwoFPEDParallel${suffix}.sh theta 1 100 1 100 1024 1024 0 0 1 1 0.0966796875 0.0966796875 expr_theta 1_100_1_100_1024_1024 ${target} -./detectErrorThreeFPEDParallel${suffix}.sh turbine1 3.8 7.8 -4.5 -0.3 0.4 0.9 256 256 256 0 0 0 3.8 -4.5 0.4 0.015625 0.01640625 0.001953125 expr_turbine1 3.8_7.8_-4.5_-0.3_0.4_0.9_256_256_256 ${target} +# DONE +# ./detectErrorOneFPEDParallel${suffix}.sh Bsplines3 0 1 500000 0 0 2e-06 expr_Bsplines3 0_1_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh exp1x 0.01 0.5 500000 0 0.01 9.8e-07 expr_exp1x 0.01_0.5_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh logexp -8 8 500000 0 -8 3.2e-05 expr_logexp -8_8_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh NMSEexample31 0.01 100 500000 0 0.01 0.00019998 expr_NMSEexample31 0.01_100_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh NMSEexample34 0.01 3 500000 0 0.01 5.98e-06 expr_NMSEexample34 0.01_3_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh NMSEexample35 0.01 100 500000 0 0.01 0.00019998 expr_NMSEexample35 0.01_100_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh NMSEexample36 0.01 100 500000 0 0.01 0.00019998 expr_NMSEexample36 0.01_100_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh NMSEexample37 0.01 100 500000 0 0.01 0.00019998 expr_NMSEexample37 0.01_100_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh NMSEexample38 0.01 100 500000 0 0.01 0.00019998 expr_NMSEexample38 0.01_100_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh NMSEexample39 0.01 1 500000 0 0.01 1.98e-06 expr_NMSEexample39 0.01_1_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem331 0.01 100 500000 0 0.01 0.00019998 expr_NMSEproblem331 0.01_100_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem333 0.01 0.99 500000 0 0.01 1.96e-06 expr_NMSEproblem333 0.01_0.99_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem336 0.01 100 500000 0 0.01 0.00019998 expr_NMSEproblem336 0.01_100_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem337 0.01 100 500000 0 0.01 0.00019998 expr_NMSEproblem337 0.01_100_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem341 0.01 100 500000 0 0.01 0.00019998 expr_NMSEproblem341 0.01_100_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem343 -1 1 500000 0 -1 4e-06 expr_NMSEproblem343 -1_1_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem344 0.01 100 500000 0 0.01 0.00019998 expr_NMSEproblem344 0.01_100_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh NMSEsection311 0.01 100 500000 0 0.01 0.00019998 expr_NMSEsection311 0.01_100_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh predatorPrey 0.1 0.3 500000 0 0.1 4e-07 expr_predatorPrey 0.1_0.3_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh sine -1.57079632679 1.57079632679 500000 0 -1.57079632679 6.28318530716e-06 expr_sine -1.57079632679_1.57079632679_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh sineorder3 -2 2 500000 0 -2 8e-06 expr_sineorder3 -2_2_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh sqroot 0 1 500000 0 0 2e-06 expr_sqroot 0_1_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh test05_nonlin1_r4 1.00001 2 500000 0 1.00001 1.9999799999999998e-06 expr_test05_nonlin1_r4 1.00001_2_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh test05_nonlin1_test2 1.00001 2 500000 0 1.00001 1.9999799999999998e-06 expr_test05_nonlin1_test2 1.00001_2_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh verhulst 0.1 0.3 500000 0 0.1 4e-07 expr_verhulst 0.1_0.3_500000 ${target} + +# problem error are too big +# ./detectErrorOneFPEDParallel${suffix}.sh intro_example 0 999 500000 0 0 0.001998 expr_intro_example 0_999_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh sqrt_add 1 1000 500000 0 1 0.001998 expr_sqrt_add 1_1000_500000 ${target} + +# TODO +# ./detectErrorOneFPEDParallel${suffix}.sh exp1x_log 0.01 0.5 500000 0 0.01 9.8e-07 expr_exp1x_log 0.01_0.5_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh NMSEexample310 -1 1 500000 0 -1 4e-06 expr_NMSEexample310 -1_1_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem334 0.01 100 500000 0 0.01 0.00019998 expr_NMSEproblem334 0.01_100_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem345 0.01 100 500000 0 0.01 0.00019998 expr_NMSEproblem345 0.01_100_500000 ${target} + +# DOING +# ./detectErrorTwoFPEDParallel${suffix}.sh ComplexSinCos 0 1 0 1 1024 1024 0 0 0 0 0.0009765625 0.0009765625 expr_ComplexSinCos 0_1_0_1_1024_1024 ${target} +# ./detectErrorTwoFPEDParallel${suffix}.sh ComplexSquareRoot 0 1 0 1 1024 1024 0 0 0 0 0.0009765625 0.0009765625 expr_ComplexSquareRoot 0_1_0_1_1024_1024 ${target} +# ./detectErrorThreeFPEDParallel${suffix}.sh doppler1 -30 50 -100 100 20 20000 256 256 256 0 0 0 -30 -100 20 0.3125 0.78125 78.046875 expr_doppler1 -30_50_-100_100_20_20000_256_256_256 ${target} +# ./detectErrorThreeFPEDParallel${suffix}.sh doppler2 -40 60 -125 125 15 25000 256 256 256 0 0 0 -40 -125 15 0.390625 0.9765625 97.59765625 expr_doppler2 -40_60_-125_125_15_25000_256_256_256 ${target} +# ./detectErrorThreeFPEDParallel${suffix}.sh doppler3 -50 30 -30 120 320 20300 256 256 256 0 0 0 -50 -30 320 0.3125 0.5859375 78.046875 expr_doppler3 -50_30_-30_120_320_20300_256_256_256 ${target} +# ./detectErrorTwoFPEDParallel${suffix}.sh hypot32 1 100 1 100 1024 1024 0 0 1 1 0.0966796875 0.0966796875 expr_hypot32 1_100_1_100_1024_1024 ${target} +# ./detectErrorTwoFPEDParallel${suffix}.sh i4 0.1 10 -5 5 1024 1024 0 0 0.1 -5 0.00966796875 0.009765625 expr_i4 0.1_10_-5_5_1024_1024 ${target} +# ./detectErrorTwoFPEDParallel${suffix}.sh i6 0.1 10 -5 5 1024 1024 0 0 0.1 -5 0.00966796875 0.009765625 expr_i6 0.1_10_-5_5_1024_1024 ${target} +# ./detectErrorTwoFPEDParallel${suffix}.sh NMSEexample33 0 100 0 100 1024 1024 0 0 0 0 0.09765625 0.09765625 expr_NMSEexample33 0_100_0_100_1024_1024 ${target} +# ./detectErrorTwoFPEDParallel${suffix}.sh NMSEproblem332 0 100 0 100 1024 1024 0 0 0 0 0.09765625 0.09765625 expr_NMSEproblem332 0_100_0_100_1024_1024 ${target} +# ./detectErrorTwoFPEDParallel${suffix}.sh NMSEproblem335 0 100 0 100 1024 1024 0 0 0 0 0.09765625 0.09765625 expr_NMSEproblem335 0_100_0_100_1024_1024 ${target} +# ./detectErrorTwoFPEDParallel${suffix}.sh NMSEproblem346 1 2 0 1 1024 1024 0 0 1 0 0.0009765625 0.0009765625 expr_NMSEproblem346 1_2_0_1_1024_1024 ${target} +# ./detectErrorTwoFPEDParallel${suffix}.sh NMSEsection35 0 1 0 1 1024 1024 0 0 0 0 0.0009765625 0.0009765625 expr_NMSEsection35 0_1_0_1_1024_1024 ${target} +# ./detectErrorTwoFPEDParallel${suffix}.sh polarToCarthesianX 1 10 0 360 1024 1024 0 0 1 0 0.0087890625 0.3515625 expr_polarToCarthesianX 1_10_0_360_1024_1024 ${target} +# ./detectErrorTwoFPEDParallel${suffix}.sh polarToCarthesianY 1 10 0 360 1024 1024 0 0 1 0 0.0087890625 0.3515625 expr_polarToCarthesianY 1_10_0_360_1024_1024 ${target} +# ./detectErrorTwoFPEDParallel${suffix}.sh sec4example 1.001 2 1.001 2 1024 1024 0 0 1.001 1.001 0.0009755859375000001 0.0009755859375000001 expr_sec4example 1.001_2_1.001_2_1024_1024 ${target} +# ./detectErrorTwoFPEDParallel${suffix}.sh test03_nonlin2 0 1 -1 -0.1 1024 1024 0 0 0 -1 0.0009765625 0.00087890625 expr_test03_nonlin2 0_1_-1_-0.1_1024_1024 ${target} +# ./detectErrorTwoFPEDParallel${suffix}.sh theta 1 100 1 100 1024 1024 0 0 1 1 0.0966796875 0.0966796875 expr_theta 1_100_1_100_1024_1024 ${target} +# ./detectErrorThreeFPEDParallel${suffix}.sh turbine1 3.8 7.8 -4.5 -0.3 0.4 0.9 256 256 256 0 0 0 3.8 -4.5 0.4 0.015625 0.01640625 0.001953125 expr_turbine1 3.8_7.8_-4.5_-0.3_0.4_0.9_256_256_256 ${target} diff --git a/script/input/ComplexSinCos_opt.cc b/script/input/ComplexSinCos_opt.cc new file mode 100644 index 0000000..1031c85 --- /dev/null +++ b/script/input/ComplexSinCos_opt.cc @@ -0,0 +1,56 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double r, double i) +{ + REAL r_real(r); + REAL i_real(i); + double y; + REAL y_real; + + if((0<=r)&&(r<=1)&&(0<=i)&&(i<=1)&&(7.194192609125759e-245<=r)&&(r<=7.196891728795075e-245)) { + y = 1.0/2.0*sin(r)*(exp(-i) - exp(i)); + return y; + } + + if((0<=r)&&(r<=1)&&(0<=i)&&(i<=1)&&(7.685580509673756e-70<=r)&&(r<=7.703374426214096e-70)) { + y = 1.0/2.0*sin(r)*(exp(-i) - exp(i)); + return y; + } + + if((0<=r)&&(r<=1)&&(0<=i)&&(i<=1)) { + y_real = REAL(1.0)/REAL(2.0)*iRRAM::sin((REAL)r_real)*(iRRAM::exp((REAL)-i_real) -iRRAM::exp((REAL)i_real)); + return y_real.as_double(); + } + + return y; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string r_str,i_str; + iRRAM::cin >> r_str >> i_str; + double r_double = binary2double(r_str); + double i_double = binary2double(i_str); + double r_double = irram_sintan(r_double, i_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/ComplexSquareRoot_opt.cc b/script/input/ComplexSquareRoot_opt.cc new file mode 100644 index 0000000..03d428e --- /dev/null +++ b/script/input/ComplexSquareRoot_opt.cc @@ -0,0 +1,51 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x1, double x2) +{ + REAL x1_real(x1); + REAL x2_real(x2); + double r; + REAL r_real; + + if((0<=x1)&&(x1<=1)&&(0<=x2)&&(x2<=1)&&(1.275086505940163e-308<=x1)&&(x1<=4.657495262892392e-06)) { + r = 1.0/2.0*sqrt(2.0*(sqrt(x1*x1+x2*x2)+x1)); + return r; + } + + if((0<=x1)&&(x1<=1)&&(0<=x2)&&(x2<=1)) { + r_real = REAL(1.0)/REAL(2.0)*iRRAM::sqrt((REAL)REAL(2.0)*(iRRAM::sqrt((REAL)x1_real*x1_real+x2_real*x2_real)+x1_real)); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x1_str,x2_str; + iRRAM::cin >> x1_str >> x2_str; + double x1_double = binary2double(x1_str); + double x2_double = binary2double(x2_str); + double r_double = irram_sintan(x1_double, x2_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/NMSEexample310_opt.cc b/script/input/NMSEexample310_opt.cc new file mode 100644 index 0000000..25de3e5 --- /dev/null +++ b/script/input/NMSEexample310_opt.cc @@ -0,0 +1,44 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((-1<=x)&&(x<=1)) { + r_real = iRRAM::log((REAL)1-x_real)/iRRAM::log((REAL)1+x_real); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/NMSEexample31_opt.cc b/script/input/NMSEexample31_opt.cc new file mode 100644 index 0000000..a0f04ba --- /dev/null +++ b/script/input/NMSEexample31_opt.cc @@ -0,0 +1,94 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.01<=x)&&(x<=100)&&(0.01033204425169536<=x)&&(x<=3.5786479018381825)) { + r = sqrt(x+1)-sqrt(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(4.194470440466919<=x)&&(x<=4.454459669337519)) { + r = sqrt(x+1)-sqrt(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(5.086463095261279<=x)&&(x<=5.494538771451066)) { + r = sqrt(x+1)-sqrt(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(5.599975109497048<=x)&&(x<=5.726539993141816)) { + r = sqrt(x+1)-sqrt(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(6.588006724737285<=x)&&(x<=7.231828001818615)) { + r = sqrt(x+1)-sqrt(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(7.685840646771626<=x)&&(x<=8.810461536106247)) { + r = sqrt(x+1)-sqrt(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(9.773739960540086<=x)&&(x<=10.715677981948954)) { + r = sqrt(x+1)-sqrt(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(12.276570111213195<=x)&&(x<=12.982537102167978)) { + r = sqrt(x+1)-sqrt(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(14.68601137308409<=x)&&(x<=14.84871472009893)) { + r = sqrt(x+1)-sqrt(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(55.10931785603222<=x)&&(x<=55.10931786223146)) { + r = sqrt(x+1)-sqrt(x); + return r; + } + + if((0.01<=x)&&(x<=100)) { + r_real = iRRAM::sqrt((REAL)x_real+1)-iRRAM::sqrt((REAL)x_real); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/NMSEexample33_opt.cc b/script/input/NMSEexample33_opt.cc new file mode 100644 index 0000000..42348e0 --- /dev/null +++ b/script/input/NMSEexample33_opt.cc @@ -0,0 +1,276 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double eps, double x) +{ + REAL eps_real(eps); + REAL x_real(x); + double r; + REAL r_real; + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(7.434734209367829e-295<=eps)&&(eps<=8.067147183600915e-295)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.8773066864894313e-252<=eps)&&(eps<=4.296923398836829e-252)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(7.292982820860915e-247<=eps)&&(eps<=4.2093941912301484e-246)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(7.439134699417557e-245<=eps)&&(eps<=3.451357033511687e-244)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.5629818809612405e-243<=eps)&&(eps<=1.749549226446628e-243)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(8.547944083624428e-242<=eps)&&(eps<=1.9135205006649776e-241)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.456150995024938e-236<=eps)&&(eps<=1.2530976124527013e-235)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.940192906463652e-222<=eps)&&(eps<=2.5233710184953186e-221)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.10584813090912e-215<=eps)&&(eps<=1.1177005878997507e-215)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.958213543508275e-214<=eps)&&(eps<=3.035842818004483e-214)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.283586601882369e-212<=eps)&&(eps<=4.971468737886205e-212)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(6.298269576390221e-205<=eps)&&(eps<=7.021665925957399e-202)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(4.9416485868453986e-200<=eps)&&(eps<=2.0633038726037926e-199)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(5.9225919784203144e-198<=eps)&&(eps<=7.71695143609805e-198)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(5.865050872406589e-192<=eps)&&(eps<=8.350952230606281e-191)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.5273432789945824e-186<=eps)&&(eps<=2.5963024681959457e-186)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.075517320567907e-184<=eps)&&(eps<=1.0881780473271177e-184)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.3982558177714916e-181<=eps)&&(eps<=8.418691105024768e-181)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(4.698921537507404e-179<=eps)&&(eps<=1.4561260987656107e-175)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.406006231055905e-173<=eps)&&(eps<=1.642061578747113e-173)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.2371439167223059e-167<=eps)&&(eps<=1.4836079964423097e-167)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(6.4605279497621005e-167<=eps)&&(eps<=1.0367565562744443e-166)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(8.196198439286282e-165<=eps)&&(eps<=4.2164099155356946e-159)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(4.767856708299514e-157<=eps)&&(eps<=5.736729788778377e-157)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.8984484362845337e-155<=eps)&&(eps<=8.750539427998615e-155)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(9.00880171098746e-153<=eps)&&(eps<=1.6801884003904512e-151)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.5021247214735642e-147<=eps)&&(eps<=2.724268953477039e-147)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.4779921920129862e-145<=eps)&&(eps<=3.2954631442243097e-143)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.3537520997688223e-136<=eps)&&(eps<=5.4971274033141563e-135)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(5.245392262412381e-132<=eps)&&(eps<=1.7793896213428044e-130)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.4440435724332697e-126<=eps)&&(eps<=5.546018879285196e-122)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(4.201105631704275e-119<=eps)&&(eps<=1.050870047393311e-118)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(5.570725412228856e-116<=eps)&&(eps<=1.9443199258523357e-114)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.1171459485515486e-112<=eps)&&(eps<=1.1637929873374265e-111)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.108708060002273e-110<=eps)&&(eps<=5.209767174467671e-110)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(5.39402231747422e-109<=eps)&&(eps<=8.826602772123591e-103)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.3802083625741864e-101<=eps)&&(eps<=9.418828959099321e-101)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.2155818321423112e-98<=eps)&&(eps<=2.807433808214297e-97)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.5061298504327682e-96<=eps)&&(eps<=1.2818341631171205e-95)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(4.211203409411544e-94<=eps)&&(eps<=5.723623564850643e-83)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.662671903138479e-80<=eps)&&(eps<=7.12104770074523e-54)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(7.045892075217811e-53<=eps)&&(eps<=1.6416534859934596e-50)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(8.493703732142176e-49<=eps)&&(eps<=1.3664606924288116e-42)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.1892890898562904e-41<=eps)&&(eps<=3.088334301914156e-38)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.1780907232134085e-36<=eps)&&(eps<=6.212899569162941e-20)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(5.7025994319818814e-15<=eps)&&(eps<=0.08788607496239624)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)) { + r_real = iRRAM::sin((REAL)x_real+eps_real) -iRRAM::sin((REAL)x_real); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string eps_str,x_str; + iRRAM::cin >> eps_str >> x_str; + double eps_double = binary2double(eps_str); + double x_double = binary2double(x_str); + double r_double = irram_sintan(eps_double, x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/NMSEexample34_opt.cc b/script/input/NMSEexample34_opt.cc new file mode 100644 index 0000000..457e381 --- /dev/null +++ b/script/input/NMSEexample34_opt.cc @@ -0,0 +1,59 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.01<=x)&&(x<=3)&&(0.24350074632789553<=x)&&(x<=0.243501436280844)) { + r = (1-cos(x))/sin(x); + return r; + } + + if((0.01<=x)&&(x<=3)&&(0.24877069789885864<=x)&&(x<=0.2816733445771115)) { + r = (1-cos(x))/sin(x); + return r; + } + + if((0.01<=x)&&(x<=3)&&(0.2816733569658207<=x)&&(x<=2.924004589698516)) { + r = (1-cos(x))/sin(x); + return r; + } + + if((0.01<=x)&&(x<=3)) { + r_real = (1-iRRAM::cos((REAL)x_real))/iRRAM::sin((REAL)x_real); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/NMSEexample35_opt.cc b/script/input/NMSEexample35_opt.cc new file mode 100644 index 0000000..fe58209 --- /dev/null +++ b/script/input/NMSEexample35_opt.cc @@ -0,0 +1,59 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.01<=x)&&(x<=100)&&(0.010626357637108582<=x)&&(x<=2.4216457747634084)) { + r = atan(x+1)-atan(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(2.4675257629085374<=x)&&(x<=2.929090134073094)) { + r = atan(x+1)-atan(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(2.96296978663543<=x)&&(x<=3.362233496533575)) { + r = atan(x+1)-atan(x); + return r; + } + + if((0.01<=x)&&(x<=100)) { + r_real = iRRAM::atan((REAL)x_real+1)-iRRAM::atan((REAL)x_real); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/NMSEexample36_opt.cc b/script/input/NMSEexample36_opt.cc new file mode 100644 index 0000000..a87d71d --- /dev/null +++ b/script/input/NMSEexample36_opt.cc @@ -0,0 +1,69 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.01<=x)&&(x<=100)&&(0.010673067477198568<=x)&&(x<=1.5958251267616936)) { + r = 1/(sqrt(x))-1/sqrt(1+x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(1.5958251309025289<=x)&&(x<=2.0621189828509077)) { + r = 1/(sqrt(x))-1/sqrt(1+x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(2.206460837078387<=x)&&(x<=2.2495889543715917)) { + r = 1/(sqrt(x))-1/sqrt(1+x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(4.579100276778099<=x)&&(x<=4.686225042548934)) { + r = 1/(sqrt(x))-1/sqrt(1+x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(5.273357509397678<=x)&&(x<=5.273359899623165)) { + r = 1/(sqrt(x))-1/sqrt(1+x); + return r; + } + + if((0.01<=x)&&(x<=100)) { + r_real = 1/(iRRAM::sqrt((REAL)x_real))-1/iRRAM::sqrt((REAL)1+x_real); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/NMSEexample37_opt.cc b/script/input/NMSEexample37_opt.cc new file mode 100644 index 0000000..1ffa45a --- /dev/null +++ b/script/input/NMSEexample37_opt.cc @@ -0,0 +1,69 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.01<=x)&&(x<=100)&&(0.06722497868733401<=x)&&(x<=0.06725235096169693)) { + r = exp(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.11786006198612779<=x)&&(x<=0.13864989446981987)) { + r = exp(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.141488869668345<=x)&&(x<=0.18389725264762594)) { + r = exp(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.18718203291301166<=x)&&(x<=0.2017189063726586)) { + r = exp(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.20382590581321117<=x)&&(x<=99.12853872052801)) { + r = exp(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)) { + r_real = iRRAM::exp((REAL)x_real)-1; + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/NMSEexample38_opt.cc b/script/input/NMSEexample38_opt.cc new file mode 100644 index 0000000..d260059 --- /dev/null +++ b/script/input/NMSEexample38_opt.cc @@ -0,0 +1,124 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.01<=x)&&(x<=100)&&(0.010437469457944472<=x)&&(x<=0.3604339271759145)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.8871511248989055<=x)&&(x<=0.8874171326284639)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(1.1751887785480812<=x)&&(x<=1.415667007213509)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(1.458089294902233<=x)&&(x<=1.6865102059147628)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(1.6865344487760252<=x)&&(x<=1.7153206052609768)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(1.7479678878719356<=x)&&(x<=1.9087480406358917)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(1.9122839797370013<=x)&&(x<=1.9740300295334035)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(1.9931971810641311<=x)&&(x<=3.1877653850291634)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(3.1979651413073538<=x)&&(x<=4.213377740669251)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(4.237602197231224<=x)&&(x<=4.702916612374459)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(4.957614040315142<=x)&&(x<=6.474333065779055)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(6.898192685270763<=x)&&(x<=7.073384818146711)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(7.395087638773861<=x)&&(x<=7.422516993951036)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(7.818647478830652<=x)&&(x<=10.805647243398507)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(10.90936836311555<=x)&&(x<=11.621957942764213)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(59.36938744810223<=x)&&(x<=59.57610366236027)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)) { + r_real = (x_real+1)*iRRAM::log((REAL)x_real+1)-x_real*iRRAM::log((REAL)x_real)-1; + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/NMSEexample39_opt.cc b/script/input/NMSEexample39_opt.cc new file mode 100644 index 0000000..2553ba7 --- /dev/null +++ b/script/input/NMSEexample39_opt.cc @@ -0,0 +1,79 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.01<=x)&&(x<=1)&&(0.3752304551929883<=x)&&(x<=0.3782631882078102)) { + r = 1/x-1/tan(x); + return r; + } + + if((0.01<=x)&&(x<=1)&&(0.38197192351353915<=x)&&(x<=0.38339280567489276)) { + r = 1/x-1/tan(x); + return r; + } + + if((0.01<=x)&&(x<=1)&&(0.3906040016481666<=x)&&(x<=0.3908873003167046)) { + r = 1/x-1/tan(x); + return r; + } + + if((0.01<=x)&&(x<=1)&&(0.41124914167390286<=x)&&(x<=0.4272101777696732)) { + r = 1/x-1/tan(x); + return r; + } + + if((0.01<=x)&&(x<=1)&&(0.458640562116811<=x)&&(x<=0.45959711531029157)) { + r = 1/x-1/tan(x); + return r; + } + + if((0.01<=x)&&(x<=1)&&(0.47477447784129195<=x)&&(x<=0.5588437133375577)) { + r = 1/x-1/tan(x); + return r; + } + + if((0.01<=x)&&(x<=1)&&(0.5588549067302485<=x)&&(x<=0.9927948509853173)) { + r = 1/x-1/tan(x); + return r; + } + + if((0.01<=x)&&(x<=1)) { + r_real = 1/x_real-1/iRRAM::tan((REAL)x_real); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/NMSEproblem331_opt.cc b/script/input/NMSEproblem331_opt.cc new file mode 100644 index 0000000..73eee36 --- /dev/null +++ b/script/input/NMSEproblem331_opt.cc @@ -0,0 +1,109 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.01<=x)&&(x<=100)&&(0.010168746512177272<=x)&&(x<=7.506099159368052)) { + r = 1/(x+1)-1/x; + return r; + } + + if((0.01<=x)&&(x<=100)&&(7.999930601070934<=x)&&(x<=10.861793248757207)) { + r = 1/(x+1)-1/x; + return r; + } + + if((0.01<=x)&&(x<=100)&&(11.073762383621652<=x)&&(x<=11.946056632198577)) { + r = 1/(x+1)-1/x; + return r; + } + + if((0.01<=x)&&(x<=100)&&(12.63633448852667<=x)&&(x<=13.108698126263626)) { + r = 1/(x+1)-1/x; + return r; + } + + if((0.01<=x)&&(x<=100)&&(13.961079927820576<=x)&&(x<=13.988194316081476)) { + r = 1/(x+1)-1/x; + return r; + } + + if((0.01<=x)&&(x<=100)&&(14.903645384885676<=x)&&(x<=15.072351500800046)) { + r = 1/(x+1)-1/x; + return r; + } + + if((0.01<=x)&&(x<=100)&&(16.627975680630563<=x)&&(x<=17.170042573570754)) { + r = 1/(x+1)-1/x; + return r; + } + + if((0.01<=x)&&(x<=100)&&(18.346556947226322<=x)&&(x<=18.839229212497735)) { + r = 1/(x+1)-1/x; + return r; + } + + if((0.01<=x)&&(x<=100)&&(18.895993618078137<=x)&&(x<=19.48144169206383)) { + r = 1/(x+1)-1/x; + return r; + } + + if((0.01<=x)&&(x<=100)&&(20.265252047716615<=x)&&(x<=21.833391961226663)) { + r = 1/(x+1)-1/x; + return r; + } + + if((0.01<=x)&&(x<=100)&&(26.911051511249386<=x)&&(x<=26.911051737877717)) { + r = 1/(x+1)-1/x; + return r; + } + + if((0.01<=x)&&(x<=100)&&(35.06295977463821<=x)&&(x<=35.06295977463821)) { + r = 1/(x+1)-1/x; + return r; + } + + if((0.01<=x)&&(x<=100)&&(36.87094614503849<=x)&&(x<=36.91473783652938)) { + r = 1/(x+1)-1/x; + return r; + } + + if((0.01<=x)&&(x<=100)) { + r_real = 1/(x_real+1)-1/x_real; + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/NMSEproblem332_opt.cc b/script/input/NMSEproblem332_opt.cc new file mode 100644 index 0000000..21984ef --- /dev/null +++ b/script/input/NMSEproblem332_opt.cc @@ -0,0 +1,296 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double eps, double x) +{ + REAL eps_real(eps); + REAL x_real(x); + double r; + REAL r_real; + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.5108525710296906e-259<=eps)&&(eps<=1.3810372471893627e-258)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.2837283298644606e-257<=eps)&&(eps<=1.485693192901714e-257)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.5937379220003817e-250<=eps)&&(eps<=2.6338577988520412e-250)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.5873253771292057e-243<=eps)&&(eps<=4.3137968058495976e-243)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.258410397322062e-240<=eps)&&(eps<=1.070461965396641e-239)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.8116174241174647e-236<=eps)&&(eps<=4.502548001200871e-235)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.8668774180497522e-233<=eps)&&(eps<=4.059126848953666e-233)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.0380679275377245e-232<=eps)&&(eps<=1.8130696239647908e-230)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(4.4115886009494417e-228<=eps)&&(eps<=7.348039670501258e-228)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.296366325211081e-214<=eps)&&(eps<=5.202244574733544e-214)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.2990911370343056e-211<=eps)&&(eps<=2.900358433758034e-211)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(6.796385350766496e-201<=eps)&&(eps<=1.058184120660101e-200)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(5.872957808587388e-199<=eps)&&(eps<=7.722773529155683e-198)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.396128270401295e-197<=eps)&&(eps<=6.934932706648367e-197)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.3452190080741407e-194<=eps)&&(eps<=6.522728310635985e-193)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.3423510789598074e-185<=eps)&&(eps<=2.3979572245317566e-185)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(4.1608154753405134e-185<=eps)&&(eps<=4.203138335661809e-185)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.942787053495008e-180<=eps)&&(eps<=4.339783455751588e-180)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.8426023458269196e-176<=eps)&&(eps<=3.4305606070893033e-175)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.856378759585273e-173<=eps)&&(eps<=8.383318704711661e-173)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.3358948833316437e-164<=eps)&&(eps<=5.583945808137087e-163)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(7.658939752271011e-161<=eps)&&(eps<=1.2215141607506556e-160)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(4.141841651104984e-160<=eps)&&(eps<=1.0458026362338476e-159)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.769600169155007e-157<=eps)&&(eps<=3.9010899624253364e-150)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.990755229480191e-143<=eps)&&(eps<=2.017765760240066e-140)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.4616015127320596e-137<=eps)&&(eps<=1.2445066320222767e-136)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(8.735155558193516e-136<=eps)&&(eps<=1.3124173303111485e-135)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.6159948666980727e-134<=eps)&&(eps<=7.502428578473285e-134)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.5037755696477674e-131<=eps)&&(eps<=3.556800900319338e-130)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(8.124511117424646e-125<=eps)&&(eps<=4.591928032598656e-121)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(8.001268481853495e-121<=eps)&&(eps<=2.5800394856144636e-120)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(7.545526506227277e-119<=eps)&&(eps<=7.71784359835738e-112)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(9.72296697448404e-109<=eps)&&(eps<=5.511761180031092e-108)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.569352435377055e-104<=eps)&&(eps<=3.955947809938828e-96)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.5811022041334388e-95<=eps)&&(eps<=1.0290556941081322e-92)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.894108265478157e-92<=eps)&&(eps<=1.7541545378895835e-91)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(6.346060764557866e-91<=eps)&&(eps<=1.8143292138843098e-90)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(6.30398962710292e-90<=eps)&&(eps<=5.3790146277372494e-89)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(5.788085951764226e-88<=eps)&&(eps<=3.240135597120385e-85)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.1899051677613604e-84<=eps)&&(eps<=3.1780907922141284e-84)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.5565651946838346e-83<=eps)&&(eps<=3.0079477103113185e-80)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(9.347152145490561e-78<=eps)&&(eps<=1.5274832674456632e-76)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.0869520731939839e-75<=eps)&&(eps<=8.425083932230819e-75)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(6.394161166053848e-74<=eps)&&(eps<=2.3187369376982203e-73)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.615442602928697e-71<=eps)&&(eps<=4.609688418154432e-60)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.2695680292935905e-59<=eps)&&(eps<=9.682701544335003e-55)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(6.541818920111603e-54<=eps)&&(eps<=1.8725260274596118e-53)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.9384543331209372e-50<=eps)&&(eps<=2.1759563993712245e-24)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.0439747553056098e-23<=eps)&&(eps<=0.00022010511756444742)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(0.00082707746975666<=eps)&&(eps<=1.346717182916112)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)) { + r_real = iRRAM::tan((REAL)x_real+eps_real) -iRRAM::tan((REAL)x_real); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string eps_str,x_str; + iRRAM::cin >> eps_str >> x_str; + double eps_double = binary2double(eps_str); + double x_double = binary2double(x_str); + double r_double = irram_sintan(eps_double, x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/NMSEproblem333_opt.cc b/script/input/NMSEproblem333_opt.cc new file mode 100644 index 0000000..52e72da --- /dev/null +++ b/script/input/NMSEproblem333_opt.cc @@ -0,0 +1,49 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.01<=x)&&(x<=0.99)&&(0.010391799439447024<=x)&&(x<=0.9778015263847194)) { + r = 1/(x+1)-2/x + 1/(x-1); + return r; + } + + if((0.01<=x)&&(x<=0.99)) { + r_real = 1/(x_real+1)-2/x_real + 1/(x_real-1); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/NMSEproblem335_opt.cc b/script/input/NMSEproblem335_opt.cc new file mode 100644 index 0000000..cf38e72 --- /dev/null +++ b/script/input/NMSEproblem335_opt.cc @@ -0,0 +1,156 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double eps, double x) +{ + REAL eps_real(eps); + REAL x_real(x); + double r; + REAL r_real; + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(6.836365780936997e-307<=eps)&&(eps<=3.424964247987962e-286)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.4726572749881702e-284<=eps)&&(eps<=4.899721680844785e-276)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(9.80094852128588e-274<=eps)&&(eps<=1.3220756303131204e-273)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.341152635398035e-273<=eps)&&(eps<=2.918900847028547e-271)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(9.29909937817375e-271<=eps)&&(eps<=2.897571946081135e-268)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.621387621444098e-268<=eps)&&(eps<=1.1810455403243362e-262)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.514498316088665e-261<=eps)&&(eps<=3.098643090316515e-237)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.1653601092697618e-236<=eps)&&(eps<=1.3277313550692224e-234)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.4228950186893905e-232<=eps)&&(eps<=3.6394307297982443e-231)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.6441878125343605e-230<=eps)&&(eps<=3.481499204600951e-230)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.9298247866138715e-228<=eps)&&(eps<=9.663047728349257e-228)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(4.857761876152504e-225<=eps)&&(eps<=4.879029707768337e-225)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(5.071205544053575e-225<=eps)&&(eps<=7.091595230411618e-215)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.5762797129048622e-213<=eps)&&(eps<=3.5282659320622263e-211)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.0591935467739667e-207<=eps)&&(eps<=2.8599597521194703e-200)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.9584125502794065e-199<=eps)&&(eps<=2.231979479424809e-198)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.193289562872563e-194<=eps)&&(eps<=1.1553953239314083e-188)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.0905545118199726e-186<=eps)&&(eps<=6.688161258098464e-185)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.441837659122788e-182<=eps)&&(eps<=2.461687324698518e-182)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.8064388963675838e-177<=eps)&&(eps<=7.585816439837246e-176)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(4.585873421513115e-171<=eps)&&(eps<=7.329270630732846e-168)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(4.275566960818706<=eps)&&(eps<=52.008103578053365)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)) { + r_real = iRRAM::cos((REAL)x_real+eps_real) -iRRAM::cos((REAL)x_real); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string eps_str,x_str; + iRRAM::cin >> eps_str >> x_str; + double eps_double = binary2double(eps_str); + double x_double = binary2double(x_str); + double r_double = irram_sintan(eps_double, x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/NMSEproblem336_opt.cc b/script/input/NMSEproblem336_opt.cc new file mode 100644 index 0000000..03d7bff --- /dev/null +++ b/script/input/NMSEproblem336_opt.cc @@ -0,0 +1,74 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.01<=x)&&(x<=100)&&(0.010135723879275712<=x)&&(x<=3.6176135153984816)) { + r = log(x+1)-log(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(3.6176135157657585<=x)&&(x<=5.136334826947236)) { + r = log(x+1)-log(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(5.1363348269486195<=x)&&(x<=6.399636245177773)) { + r = log(x+1)-log(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(6.479433154387088<=x)&&(x<=6.8201106928635555)) { + r = log(x+1)-log(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(7.174341807867794<=x)&&(x<=7.509392298899693)) { + r = log(x+1)-log(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(12.572681689919902<=x)&&(x<=12.576213687473984)) { + r = log(x+1)-log(x); + return r; + } + + if((0.01<=x)&&(x<=100)) { + r_real = iRRAM::log((REAL)x_real+1)-iRRAM::log((REAL)x_real); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/NMSEproblem337_opt.cc b/script/input/NMSEproblem337_opt.cc new file mode 100644 index 0000000..63835d8 --- /dev/null +++ b/script/input/NMSEproblem337_opt.cc @@ -0,0 +1,54 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.01<=x)&&(x<=100)&&(0.4479715718522299<=x)&&(x<=0.44842734433069176)) { + r = exp(x)+(-2)+exp(-x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.49358419750059995<=x)&&(x<=96.8690865155957)) { + r = exp(x)+(-2)+exp(-x); + return r; + } + + if((0.01<=x)&&(x<=100)) { + r_real = iRRAM::exp((REAL)x_real)+(-2)+iRRAM::exp((REAL)-x_real); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/NMSEproblem341_opt.cc b/script/input/NMSEproblem341_opt.cc new file mode 100644 index 0000000..add0e99 --- /dev/null +++ b/script/input/NMSEproblem341_opt.cc @@ -0,0 +1,79 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.01<=x)&&(x<=100)&&(0.2989954160583664<=x)&&(x<=0.3040578669088568)) { + r = (1 - cos(x))/(x*x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.31285789704270733<=x)&&(x<=0.3282430725719571)) { + r = (1 - cos(x))/(x*x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.34870518609020895<=x)&&(x<=6.034636508320054)) { + r = (1 - cos(x))/(x*x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(6.574480063196469<=x)&&(x<=49.988447914427496)) { + r = (1 - cos(x))/(x*x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(50.545623864527215<=x)&&(x<=56.3274051305552)) { + r = (1 - cos(x))/(x*x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(56.77482997906461<=x)&&(x<=94.04557348534465)) { + r = (1 - cos(x))/(x*x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(94.50957064205821<=x)&&(x<=97.81728977191308)) { + r = (1 - cos(x))/(x*x); + return r; + } + + if((0.01<=x)&&(x<=100)) { + r_real = (1 -iRRAM::cos((REAL)x_real))/(x_real*x_real); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/NMSEproblem343_opt.cc b/script/input/NMSEproblem343_opt.cc new file mode 100644 index 0000000..d1036c8 --- /dev/null +++ b/script/input/NMSEproblem343_opt.cc @@ -0,0 +1,49 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((-1<=x)&&(x<=1)&&(0.0580610989033317<=x)&&(x<=0.8393067263745277)) { + r = log((1 - x)/(1 + x)); + return r; + } + + if((-1<=x)&&(x<=1)) { + r_real = iRRAM::log((REAL)(1 - x_real)/(1 + x_real)); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/NMSEproblem344_opt.cc b/script/input/NMSEproblem344_opt.cc new file mode 100644 index 0000000..68c7348 --- /dev/null +++ b/script/input/NMSEproblem344_opt.cc @@ -0,0 +1,109 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.01<=x)&&(x<=100)&&(0.013357758595457445<=x)&&(x<=0.013385753711132663)) { + r = sqrt((exp(2*x) - 1)/(exp(x) - 1)); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.02645968602728466<=x)&&(x<=0.02645980091091372)) { + r = sqrt((exp(2*x) - 1)/(exp(x) - 1)); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.0308420310518845<=x)&&(x<=0.030958041677699714)) { + r = sqrt((exp(2*x) - 1)/(exp(x) - 1)); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.03450520733174101<=x)&&(x<=0.03493048023928692)) { + r = sqrt((exp(2*x) - 1)/(exp(x) - 1)); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.03648830890925827<=x)&&(x<=0.037239332545066846)) { + r = sqrt((exp(2*x) - 1)/(exp(x) - 1)); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.03788666905979504<=x)&&(x<=0.03880369998557144)) { + r = sqrt((exp(2*x) - 1)/(exp(x) - 1)); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.042739541918337405<=x)&&(x<=0.045849343864546734)) { + r = sqrt((exp(2*x) - 1)/(exp(x) - 1)); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.047851128580444706<=x)&&(x<=0.04888244798170545)) { + r = sqrt((exp(2*x) - 1)/(exp(x) - 1)); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.04895292466058827<=x)&&(x<=0.053780429681729275)) { + r = sqrt((exp(2*x) - 1)/(exp(x) - 1)); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.054387927814817334<=x)&&(x<=0.05630020054267815)) { + r = sqrt((exp(2*x) - 1)/(exp(x) - 1)); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.05630374551650564<=x)&&(x<=0.05808592715342758)) { + r = sqrt((exp(2*x) - 1)/(exp(x) - 1)); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.058318470703043156<=x)&&(x<=0.06031276239723299)) { + r = sqrt((exp(2*x) - 1)/(exp(x) - 1)); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.06045652094587757<=x)&&(x<=98.60588550090255)) { + r = sqrt((exp(2*x) - 1)/(exp(x) - 1)); + return r; + } + + if((0.01<=x)&&(x<=100)) { + r_real = iRRAM::sqrt((REAL)(iRRAM::exp((REAL)2*x_real) - 1)/(iRRAM::exp((REAL)x_real) - 1)); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/NMSEsection311_opt.cc b/script/input/NMSEsection311_opt.cc new file mode 100644 index 0000000..cf2939b --- /dev/null +++ b/script/input/NMSEsection311_opt.cc @@ -0,0 +1,64 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.01<=x)&&(x<=100)&&(0.08776050680208015<=x)&&(x<=0.09169948774645326)) { + r = exp(x)/(exp(x) - 1); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.10275257911692376<=x)&&(x<=0.1415960752103245)) { + r = exp(x)/(exp(x) - 1); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.14621514922976026<=x)&&(x<=0.15438859275988195)) { + r = exp(x)/(exp(x) - 1); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.15506122639664188<=x)&&(x<=91.61769657003777)) { + r = exp(x)/(exp(x) - 1); + return r; + } + + if((0.01<=x)&&(x<=100)) { + r_real = iRRAM::exp((REAL)x_real)/(iRRAM::exp((REAL)x_real) - 1); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/NMSEsection35_opt.cc b/script/input/NMSEsection35_opt.cc new file mode 100644 index 0000000..a0b2abe --- /dev/null +++ b/script/input/NMSEsection35_opt.cc @@ -0,0 +1,301 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double a, double x) +{ + REAL a_real(a); + REAL x_real(x); + double r; + REAL r_real; + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(4.426373699520133e-308<=a)&&(a<=9.64641178539536e-308)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(1.6948708374261012e-307<=a)&&(a<=3.9249341671776736e-284)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(4.649806262146611e-284<=a)&&(a<=3.4356324368853e-283)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(5.906542297452248e-282<=a)&&(a<=2.755134209599056e-274)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(2.0318943730762596e-272<=a)&&(a<=2.7738693844230365e-271)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(3.3315755901300146e-269<=a)&&(a<=2.6548839261917256e-254)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(4.21696697671564e-253<=a)&&(a<=5.311576461986012e-253)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(3.557980324973411e-249<=a)&&(a<=7.333672713124773e-246)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(4.923454646654538e-240<=a)&&(a<=2.4061062418431877e-232)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(4.272696623841612e-231<=a)&&(a<=6.462408199985713e-230)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(4.29761774789014e-226<=a)&&(a<=5.798260580495262e-225)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(3.967510616744351e-224<=a)&&(a<=1.5997196082822979e-223)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(4.9038714382828537e-222<=a)&&(a<=9.4258671998903e-222)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(7.885285658528457e-217<=a)&&(a<=2.4582235253511398e-216)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(7.473669641528526e-214<=a)&&(a<=2.3074504388938207e-212)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(2.8175377090049797e-212<=a)&&(a<=7.320924502826052e-210)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(6.596850714120958e-209<=a)&&(a<=7.373701142864517e-209)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(1.0868874069389249e-206<=a)&&(a<=3.6297312271521133e-202)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(1.0444615897969181e-201<=a)&&(a<=1.1313898239841612e-201)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(1.218926513538059e-201<=a)&&(a<=2.238794931718217e-200)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(2.438847349661079e-199<=a)&&(a<=1.8638298136405453e-197)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(6.187473189394183e-195<=a)&&(a<=2.4179431708363923e-194)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(7.147228547210765e-193<=a)&&(a<=1.0556621508935791e-192)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(3.2693627627277624e-185<=a)&&(a<=1.5488962169710398e-183)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(9.065424123450533e-182<=a)&&(a<=1.6148243079533043e-180)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(1.0934680498544342e-179<=a)&&(a<=6.143055294468906e-179)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(2.0452078591736813e-177<=a)&&(a<=5.246383557371332e-177)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(2.7095574315168934e-174<=a)&&(a<=1.8863566328857507e-172)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(1.050886346755769e-168<=a)&&(a<=1.9069551156895272e-168)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(2.702333059655267e-159<=a)&&(a<=4.9934519412223734e-158)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(9.40725411246587e-157<=a)&&(a<=1.757871640370579e-156)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(2.1669089161143363e-149<=a)&&(a<=3.8905962201375516e-149)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(1.1624849687866556e-146<=a)&&(a<=5.003542481100123e-146)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(4.736261956112328e-143<=a)&&(a<=1.0734127479087532e-141)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(3.4413611179089185e-140<=a)&&(a<=2.3220924752490645e-133)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(2.495492460711346e-132<=a)&&(a<=5.912179201129228e-132)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(2.2981744918168988e-129<=a)&&(a<=3.387528007535946e-129)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(8.154123062603018e-128<=a)&&(a<=1.953495545504702e-118)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(6.293402389701233e-113<=a)&&(a<=6.382375629617307e-113)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(1.1114129271377846e-107<=a)&&(a<=1.134133197038909e-107)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(7.29206165132118e-105<=a)&&(a<=7.550127481531e-102)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(1.793285316300961e-100<=a)&&(a<=2.015354578447418e-100)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(4.252005104708829e-99<=a)&&(a<=7.325399104906234e-98)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(3.986283749270394e-94<=a)&&(a<=7.487162872529241e-94)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(7.939187086126673e-86<=a)&&(a<=1.502822334887249e-85)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(1.6189174735842615e-84<=a)&&(a<=4.373721508859242e-83)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(1.0832536067257414e-81<=a)&&(a<=1.1360161629319568e-81)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(6.749829020803986e-73<=a)&&(a<=9.886163559335155e-73)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(2.942296925238574e-59<=a)&&(a<=3.785510202018267e-59)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(1.8142400579696498e-56<=a)&&(a<=4.4289420443586965e-55)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(8.478927914741885e-32<=a)&&(a<=8.478959252545897e-32)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)) { + r_real = iRRAM::exp((REAL)a_real*x_real) - 1; + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string a_str,x_str; + iRRAM::cin >> a_str >> x_str; + double a_double = binary2double(a_str); + double x_double = binary2double(x_str); + double r_double = irram_sintan(a_double, x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/doppler1_opt.cc b/script/input/doppler1_opt.cc new file mode 100644 index 0000000..2b5a6bf --- /dev/null +++ b/script/input/doppler1_opt.cc @@ -0,0 +1,53 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double T, double v, double u) +{ + REAL T_real(T); + REAL v_real(v); + REAL u_real(u); + double r; + REAL r_real; + + if((-30<=T)&&(T<=50)&&(-100<=v)&&(v<=100)&&(20<=u)&&(u<=20000)&&(-7.338559287692092<=T)&&(T<=3.8325674523602244)) { + r = ((-(1657.0/5.0+3.0/5.0*T))*v)/(((1657.0/5.0+3.0/5.0*T)+u)*((1657.0/5.0+3.0/5.0*T)+u)); + return r; + } + + if((-30<=T)&&(T<=50)&&(-100<=v)&&(v<=100)&&(20<=u)&&(u<=20000)) { + r_real = ((-(REAL(1657.0)/REAL(5.0)+REAL(3.0)/REAL(5.0)*T_real))*v_real)/(((REAL(1657.0)/REAL(5.0)+REAL(3.0)/REAL(5.0)*T_real)+u_real)*((REAL(1657.0)/REAL(5.0)+REAL(3.0)/REAL(5.0)*T_real)+u_real)); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string T_str,v_str,u_str; + iRRAM::cin >> T_str >> v_str >> u_str; + double T_double = binary2double(T_str); + double v_double = binary2double(v_str); + double u_double = binary2double(u_str); + double r_double = irram_sintan(T_double, v_double, u_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/doppler2_opt.cc b/script/input/doppler2_opt.cc new file mode 100644 index 0000000..56b86d0 --- /dev/null +++ b/script/input/doppler2_opt.cc @@ -0,0 +1,53 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double T, double v, double u) +{ + REAL T_real(T); + REAL v_real(v); + REAL u_real(u); + double r; + REAL r_real; + + if((-40<=T)&&(T<=60)&&(-125<=v)&&(v<=125)&&(15<=u)&&(u<=25000)&&(-10.915844254234749<=T)&&(T<=4.702493440196151)) { + r = ((-(1657.0/5.0+3.0/5.0*T))*v)/(((1657.0/5.0+3.0/5.0*T)+u)*((1657.0/5.0+3.0/5.0*T)+u)); + return r; + } + + if((-40<=T)&&(T<=60)&&(-125<=v)&&(v<=125)&&(15<=u)&&(u<=25000)) { + r_real = ((-(REAL(1657.0)/REAL(5.0)+REAL(3.0)/REAL(5.0)*T_real))*v_real)/(((REAL(1657.0)/REAL(5.0)+REAL(3.0)/REAL(5.0)*T_real)+u_real)*((REAL(1657.0)/REAL(5.0)+REAL(3.0)/REAL(5.0)*T_real)+u_real)); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string T_str,v_str,u_str; + iRRAM::cin >> T_str >> v_str >> u_str; + double T_double = binary2double(T_str); + double v_double = binary2double(v_str); + double u_double = binary2double(u_str); + double r_double = irram_sintan(T_double, v_double, u_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/doppler3_opt.cc b/script/input/doppler3_opt.cc new file mode 100644 index 0000000..960e3e8 --- /dev/null +++ b/script/input/doppler3_opt.cc @@ -0,0 +1,53 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double T, double v, double u) +{ + REAL T_real(T); + REAL v_real(v); + REAL u_real(u); + double r; + REAL r_real; + + if((-50<=T)&&(T<=30)&&(-30<=v)&&(v<=120)&&(320<=u)&&(u<=20300)&&(-37.47075088910655<=T)&&(T<=0.011584792119040614)) { + r = ((-(1657.0/5.0+3.0/5.0*T))*v)/(((1657.0/5.0+3.0/5.0*T)+u)*((1657.0/5.0+3.0/5.0*T)+u)); + return r; + } + + if((-50<=T)&&(T<=30)&&(-30<=v)&&(v<=120)&&(320<=u)&&(u<=20300)) { + r_real = ((-(REAL(1657.0)/REAL(5.0)+REAL(3.0)/REAL(5.0)*T_real))*v_real)/(((REAL(1657.0)/REAL(5.0)+REAL(3.0)/REAL(5.0)*T_real)+u_real)*((REAL(1657.0)/REAL(5.0)+REAL(3.0)/REAL(5.0)*T_real)+u_real)); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string T_str,v_str,u_str; + iRRAM::cin >> T_str >> v_str >> u_str; + double T_double = binary2double(T_str); + double v_double = binary2double(v_str); + double u_double = binary2double(u_str); + double r_double = irram_sintan(T_double, v_double, u_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/i4_opt.cc b/script/input/i4_opt.cc new file mode 100644 index 0000000..dfcf645 --- /dev/null +++ b/script/input/i4_opt.cc @@ -0,0 +1,46 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x, double y) +{ + REAL x_real(x); + REAL y_real(y); + double r; + REAL r_real; + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)) { + r_real = sqrtf(x_real+y_real*y_real); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str,y_str; + iRRAM::cin >> x_str >> y_str; + double x_double = binary2double(x_str); + double y_double = binary2double(y_str); + double r_double = irram_sintan(x_double, y_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/i6_opt.cc b/script/input/i6_opt.cc new file mode 100644 index 0000000..a534901 --- /dev/null +++ b/script/input/i6_opt.cc @@ -0,0 +1,401 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x, double y) +{ + REAL x_real(x); + REAL y_real(y); + double r; + REAL r_real; + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.10071491596713421<=x)&&(x<=0.10071491596713421)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.1053836042303186<=x)&&(x<=0.11051040864515872)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.11404379252993174<=x)&&(x<=0.11406869570369474)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.1196878553177557<=x)&&(x<=0.11986688576062991)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.12083587909163973<=x)&&(x<=0.12416293781052298)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.1296710046377132<=x)&&(x<=0.13484524434417502)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.14313795199598728<=x)&&(x<=0.1478777196008121)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.14977974703933164<=x)&&(x<=0.1500838967372697)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.1541275384399594<=x)&&(x<=0.15931090695614844)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.16824693156849477<=x)&&(x<=0.16884078479729456)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.17661468695067525<=x)&&(x<=0.19793692952398442)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.21718413845690715<=x)&&(x<=0.2176411575340831)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.2181257385146177<=x)&&(x<=0.219499117908284)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.23310775934179803<=x)&&(x<=0.2331295350020998)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.24500503898672796<=x)&&(x<=0.24500503898672796)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.24637465786642831<=x)&&(x<=0.24781016981116571)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.2544006416562272<=x)&&(x<=0.26047750839558453)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.2828445408731395<=x)&&(x<=0.29243556599806314)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.33581043186371723<=x)&&(x<=0.3559051129481395)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.400288067707727<=x)&&(x<=0.40164267990617997)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.4219954372665478<=x)&&(x<=0.43584177131273044)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.44402330344912366<=x)&&(x<=0.44919938132558623)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.46147408643102317<=x)&&(x<=0.4630811151169514)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.4681589985783008<=x)&&(x<=0.47302471195299833)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.495833574566849<=x)&&(x<=0.49846998665107684)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.5273540624174293<=x)&&(x<=0.5392204058663272)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.7149300704487647<=x)&&(x<=0.7160382828581658)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.7336493480662737<=x)&&(x<=0.7457343323443442)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.7919388096673368<=x)&&(x<=0.8116135819159088)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.8148283304581184<=x)&&(x<=0.8258402664340495)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.9031044568989568<=x)&&(x<=0.9053785555613282)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.926411151571593<=x)&&(x<=0.9478161897040787)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.9763839106738912<=x)&&(x<=0.9862591020770785)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.9991329443123417<=x)&&(x<=1.0037513940462461)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(1.0522465407925807<=x)&&(x<=1.0663380945015626)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(1.1027709786499862<=x)&&(x<=1.3426316575541892)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(1.4145740129882527<=x)&&(x<=1.4423462196367673)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(1.453973275213065<=x)&&(x<=1.4681095327053475)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(1.6702083036290236<=x)&&(x<=1.6848830943200692)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(1.7012757309418471<=x)&&(x<=1.7390026344770144)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(1.769177640509429<=x)&&(x<=1.784851665947586)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(1.8167886403940527<=x)&&(x<=1.8226656129670942)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(1.839620997515629<=x)&&(x<=1.854829027820515)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(1.8739736153523887<=x)&&(x<=1.9304490736232036)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(1.9445442510611082<=x)&&(x<=1.9667152436948379)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(1.9817191818260296<=x)&&(x<=1.9818749989331292)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(2.002942721014129<=x)&&(x<=2.0301779382900538)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(2.1270173964484447<=x)&&(x<=2.1666448035815424)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(2.1913411549838444<=x)&&(x<=2.2078197970764095)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(2.218733399361363<=x)&&(x<=2.2741307848917405)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(2.3884601195484763<=x)&&(x<=2.4450511101848047)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(2.487155136961458<=x)&&(x<=2.5170836757499604)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(2.739859490179255<=x)&&(x<=2.822666613230787)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(2.9483361767971203<=x)&&(x<=2.977393894118924)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(3.0611523577555175<=x)&&(x<=3.1095019994613793)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(3.2345581686444076<=x)&&(x<=3.252183466986562)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(3.414243828589088<=x)&&(x<=3.464131191759912)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(3.554530400881847<=x)&&(x<=3.5817318264062292)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(3.840439149041625<=x)&&(x<=3.954029120776398)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(4.059685641963536<=x)&&(x<=4.099125595914213)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(4.134632353471027<=x)&&(x<=4.175148212175961)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(4.401757978892964<=x)&&(x<=4.41458614251811)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(4.7701808208116505<=x)&&(x<=4.8151994570154075)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(5.265369322407071<=x)&&(x<=5.501040319901122)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(6.616168463794458<=x)&&(x<=6.616168463794458)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(6.705095306902486<=x)&&(x<=6.709713292976247)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(6.927630510520447<=x)&&(x<=6.92891271935972)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(6.964379871125361<=x)&&(x<=7.112392338955565)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(7.676171132487572<=x)&&(x<=8.302694302006753)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(8.815716091702747<=x)&&(x<=8.970952538901194)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(9.27087203999151<=x)&&(x<=9.987484065255082)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)) { + r_real = sinf(x_real*y_real); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str,y_str; + iRRAM::cin >> x_str >> y_str; + double x_double = binary2double(x_str); + double y_double = binary2double(y_str); + double r_double = irram_sintan(x_double, y_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/intro_example_opt.cc b/script/input/intro_example_opt.cc new file mode 100644 index 0000000..bf3e6c7 --- /dev/null +++ b/script/input/intro_example_opt.cc @@ -0,0 +1,49 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0<=x)&&(x<=999)&&(4.006327493609276e-308<=x)&&(x<=627.2207225851557)) { + r = x/(x+1); + return r; + } + + if((0<=x)&&(x<=999)) { + r_real = x_real/(x_real+1); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/logexp_opt.cc b/script/input/logexp_opt.cc new file mode 100644 index 0000000..bcf48aa --- /dev/null +++ b/script/input/logexp_opt.cc @@ -0,0 +1,49 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((-8<=x)&&(x<=8)&&(-1.3012690852733133<=x)&&(x<=0.042406208954006805)) { + r = log(exp(x)+1); + return r; + } + + if((-8<=x)&&(x<=8)) { + r_real = iRRAM::log((REAL)iRRAM::exp((REAL)x_real)+1); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/polarToCarthesianX_opt.cc b/script/input/polarToCarthesianX_opt.cc new file mode 100644 index 0000000..1522571 --- /dev/null +++ b/script/input/polarToCarthesianX_opt.cc @@ -0,0 +1,51 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double radius, double theta) +{ + REAL radius_real(radius); + REAL theta_real(theta); + double r; + REAL r_real; + + if((1<=radius)&&(radius<=10)&&(0<=theta)&&(theta<=360)&&(1.010047581718489<=radius)&&(radius<=9.95152096691238)) { + r = radius*cos(3.14159265359/180*theta); + return r; + } + + if((1<=radius)&&(radius<=10)&&(0<=theta)&&(theta<=360)) { + r_real = radius_real*iRRAM::cos((REAL)REAL(3.14159265359)/180*theta_real); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string radius_str,theta_str; + iRRAM::cin >> radius_str >> theta_str; + double radius_double = binary2double(radius_str); + double theta_double = binary2double(theta_str); + double r_double = irram_sintan(radius_double, theta_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/predatorPrey_opt.cc b/script/input/predatorPrey_opt.cc new file mode 100644 index 0000000..1586fd3 --- /dev/null +++ b/script/input/predatorPrey_opt.cc @@ -0,0 +1,49 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.1<=x)&&(x<=0.3)&&(0.10017796345245293<=x)&&(x<=0.29895279590701196)) { + r = ((4.0 * x) * x) / (1.0 + ((x / 1.11) * (x / 1.11))); + return r; + } + + if((0.1<=x)&&(x<=0.3)) { + r_real = ((REAL(4.0) * x_real) * x_real) / (REAL(1.0) + ((x_real / REAL(1.11)) * (x_real / REAL(1.11)))); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/sine_opt.cc b/script/input/sine_opt.cc new file mode 100644 index 0000000..9a16bcd --- /dev/null +++ b/script/input/sine_opt.cc @@ -0,0 +1,49 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((-1.57079632679<=x)&&(x<=1.57079632679)&&(-0.8284989478914876<=x)&&(x<=0.00033896859562810124)) { + r = x - (1.0/6.0)*x*x*x+(1.0/120.0)*x*x*x*x*x - (1.0/5040.0)*x*x*x*x*x*x*x; + return r; + } + + if((-1.57079632679<=x)&&(x<=1.57079632679)) { + r_real = x_real - (REAL(1.0)/REAL(6.0))*x_real*x_real*x_real+(REAL(1.0)/REAL(120.0))*x_real*x_real*x_real*x_real*x_real - (REAL(1.0)/REAL(5040.0))*x_real*x_real*x_real*x_real*x_real*x_real*x_real; + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/sineorder3_opt.cc b/script/input/sineorder3_opt.cc new file mode 100644 index 0000000..c237157 --- /dev/null +++ b/script/input/sineorder3_opt.cc @@ -0,0 +1,49 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((-2<=x)&&(x<=2)&&(-0.7637160874038874<=x)&&(x<=0.1979489862799192)) { + r = (238732414637843.0/250000000000000.0)*x - (6450306886639899.0/50000000000000000.0)*x*x*x; + return r; + } + + if((-2<=x)&&(x<=2)) { + r_real = (REAL(238732414637843.0)/REAL(250000000000000.0))*x_real - (REAL(6450306886639899.0)/REAL(50000000000000000.0))*x_real*x_real*x_real; + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/sqroot_opt.cc b/script/input/sqroot_opt.cc new file mode 100644 index 0000000..134faf8 --- /dev/null +++ b/script/input/sqroot_opt.cc @@ -0,0 +1,49 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0<=x)&&(x<=1)&&(5.917017099304835e-308<=x)&&(x<=0.48856674503851)) { + r = 1.0 + 0.5*x - 0.125*x*x + 0.0625*x*x*x - 0.0390625*x*x*x*x; + return r; + } + + if((0<=x)&&(x<=1)) { + r_real = REAL(1.0) + REAL(0.5)*x_real - REAL(0.125)*x_real*x_real + REAL(0.0625)*x_real*x_real*x_real - REAL(0.0390625)*x_real*x_real*x_real*x_real; + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/sqrt_add_opt.cc b/script/input/sqrt_add_opt.cc new file mode 100644 index 0000000..5d3b9aa --- /dev/null +++ b/script/input/sqrt_add_opt.cc @@ -0,0 +1,49 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((1<=x)&&(x<=1000)&&(1.0360717432848836<=x)&&(x<=974.7054355731744)) { + r = 1/(sqrt(x + 1) + sqrt(x)); + return r; + } + + if((1<=x)&&(x<=1000)) { + r_real = 1/(iRRAM::sqrt((REAL)x_real + 1) +iRRAM::sqrt((REAL)x_real)); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/test05_nonlin1_r4_opt.cc b/script/input/test05_nonlin1_r4_opt.cc new file mode 100644 index 0000000..6ad0d9c --- /dev/null +++ b/script/input/test05_nonlin1_r4_opt.cc @@ -0,0 +1,59 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((1.00001<=x)&&(x<=2)&&(1.0552419072003931<=x)&&(x<=1.0552419120606928)) { + r = (x - 1)/(x*x - 1); + return r; + } + + if((1.00001<=x)&&(x<=2)&&(1.0741413908227626<=x)&&(x<=1.0771392064647325)) { + r = (x - 1)/(x*x - 1); + return r; + } + + if((1.00001<=x)&&(x<=2)&&(1.0867648158267522<=x)&&(x<=1.9975838929838903)) { + r = (x - 1)/(x*x - 1); + return r; + } + + if((1.00001<=x)&&(x<=2)) { + r_real = (x_real - 1)/(x_real*x_real - 1); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/test05_nonlin1_test2_opt.cc b/script/input/test05_nonlin1_test2_opt.cc new file mode 100644 index 0000000..7b51317 --- /dev/null +++ b/script/input/test05_nonlin1_test2_opt.cc @@ -0,0 +1,49 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((1.00001<=x)&&(x<=2)&&(1.0052412782421196<=x)&&(x<=1.9962575350666676)) { + r = 1.0/(1+x); + return r; + } + + if((1.00001<=x)&&(x<=2)) { + r_real = REAL(1.0)/(1+x_real); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/verhulst_opt.cc b/script/input/verhulst_opt.cc new file mode 100644 index 0000000..616e365 --- /dev/null +++ b/script/input/verhulst_opt.cc @@ -0,0 +1,49 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.1<=x)&&(x<=0.3)&&(0.10016810202123817<=x)&&(x<=0.29944364568656406)) { + r = (4*x)/(1+x/1.11); + return r; + } + + if((0.1<=x)&&(x<=0.3)) { + r_real = (4*x_real)/(1+x_real/REAL(1.11)); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/prefix.cpp b/script/prefix.cpp new file mode 100644 index 0000000..433b4b5 --- /dev/null +++ b/script/prefix.cpp @@ -0,0 +1,18 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + diff --git a/script/replace.sh b/script/replace.sh new file mode 100755 index 0000000..4500f6f --- /dev/null +++ b/script/replace.sh @@ -0,0 +1,11 @@ +uniqueLabel=logexp +if [ $# -eq 1 ]; then + uniqueLabel=$1 +fi +sed -n '/double irram_sintan/,/^}/{p}' input/${uniqueLabel}_opt.cc > middle.cpp +cat prefix.cpp middle.cpp suffix.cpp > ${uniqueLabel}.tmp.cpp +sed -i "s/irram_sintan/expr_${uniqueLabel}_CPP/g" ${uniqueLabel}.tmp.cpp +sed -i "s/replacement/${uniqueLabel}/g" ${uniqueLabel}.tmp.cpp +cp ${uniqueLabel}.tmp.cpp ../srcTest/${uniqueLabel}/expr_${uniqueLabel}_NumOpt.cpp +mv ${uniqueLabel}.tmp.cpp ./output/expr_${uniqueLabel}_NumOpt.cpp +rm middle.cpp diff --git a/script/replaceAll.sh b/script/replaceAll.sh new file mode 100644 index 0000000..db1fb65 --- /dev/null +++ b/script/replaceAll.sh @@ -0,0 +1,38 @@ +./replace.sh ComplexSinCos +./replace.sh ComplexSquareRoot +./replace.sh doppler1 +./replace.sh doppler2 +./replace.sh doppler3 +./replace.sh i4 +./replace.sh i6 +./replace.sh intro_example +./replace.sh logexp +./replace.sh NMSEexample310 +./replace.sh NMSEexample31 +./replace.sh NMSEexample33 +./replace.sh NMSEexample34 +./replace.sh NMSEexample35 +./replace.sh NMSEexample36 +./replace.sh NMSEexample37 +./replace.sh NMSEexample38 +./replace.sh NMSEexample39 +./replace.sh NMSEproblem331 +./replace.sh NMSEproblem332 +./replace.sh NMSEproblem333 +./replace.sh NMSEproblem335 +./replace.sh NMSEproblem336 +./replace.sh NMSEproblem337 +./replace.sh NMSEproblem341 +./replace.sh NMSEproblem343 +./replace.sh NMSEproblem344 +./replace.sh NMSEsection311 +./replace.sh NMSEsection35 +./replace.sh polarToCarthesianX +./replace.sh predatorPrey +./replace.sh sine +./replace.sh sineorder3 +./replace.sh sqroot +./replace.sh sqrt_add +./replace.sh test05_nonlin1_r4 +./replace.sh test05_nonlin1_test2 +./replace.sh verhulst diff --git a/script/suffix.cpp b/script/suffix.cpp new file mode 100644 index 0000000..6a756ea --- /dev/null +++ b/script/suffix.cpp @@ -0,0 +1,8 @@ + +extern "C" +{ + double expr_replacement_NumOpt(double x) + { + return expr_replacement_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/ComplexSinCos/expr_ComplexSinCos_NumOpt.cpp b/srcTest/ComplexSinCos/expr_ComplexSinCos_NumOpt.cpp new file mode 100644 index 0000000..d34ac85 --- /dev/null +++ b/srcTest/ComplexSinCos/expr_ComplexSinCos_NumOpt.cpp @@ -0,0 +1,50 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_ComplexSinCos_CPP(double r, double i) +{ + REAL r_real(r); + REAL i_real(i); + double y; + REAL y_real; + + if((0<=r)&&(r<=1)&&(0<=i)&&(i<=1)&&(7.194192609125759e-245<=r)&&(r<=7.196891728795075e-245)) { + y = 1.0/2.0*sin(r)*(exp(-i) - exp(i)); + return y; + } + + if((0<=r)&&(r<=1)&&(0<=i)&&(i<=1)&&(7.685580509673756e-70<=r)&&(r<=7.703374426214096e-70)) { + y = 1.0/2.0*sin(r)*(exp(-i) - exp(i)); + return y; + } + + if((0<=r)&&(r<=1)&&(0<=i)&&(i<=1)) { + y_real = REAL(1.0)/REAL(2.0)*iRRAM::sin((REAL)r_real)*(iRRAM::exp((REAL)-i_real) -iRRAM::exp((REAL)i_real)); + return y_real.as_double(); + } + + return y; +} + +extern "C" +{ + double expr_ComplexSinCos_NumOpt(double x) + { + return expr_ComplexSinCos_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/ComplexSquareRoot/expr_ComplexSquareRoot_NumOpt.cpp b/srcTest/ComplexSquareRoot/expr_ComplexSquareRoot_NumOpt.cpp new file mode 100644 index 0000000..4b02997 --- /dev/null +++ b/srcTest/ComplexSquareRoot/expr_ComplexSquareRoot_NumOpt.cpp @@ -0,0 +1,45 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_ComplexSquareRoot_CPP(double x1, double x2) +{ + REAL x1_real(x1); + REAL x2_real(x2); + double r; + REAL r_real; + + if((0<=x1)&&(x1<=1)&&(0<=x2)&&(x2<=1)&&(1.275086505940163e-308<=x1)&&(x1<=4.657495262892392e-06)) { + r = 1.0/2.0*sqrt(2.0*(sqrt(x1*x1+x2*x2)+x1)); + return r; + } + + if((0<=x1)&&(x1<=1)&&(0<=x2)&&(x2<=1)) { + r_real = REAL(1.0)/REAL(2.0)*iRRAM::sqrt((REAL)REAL(2.0)*(iRRAM::sqrt((REAL)x1_real*x1_real+x2_real*x2_real)+x1_real)); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_ComplexSquareRoot_NumOpt(double x) + { + return expr_ComplexSquareRoot_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/NMSEexample31/expr_NMSEexample31_NumOpt.cpp b/srcTest/NMSEexample31/expr_NMSEexample31_NumOpt.cpp new file mode 100644 index 0000000..f704703 --- /dev/null +++ b/srcTest/NMSEexample31/expr_NMSEexample31_NumOpt.cpp @@ -0,0 +1,89 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_NMSEexample31_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.01<=x)&&(x<=100)&&(0.01033204425169536<=x)&&(x<=3.5786479018381825)) { + r = sqrt(x+1)-sqrt(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(4.194470440466919<=x)&&(x<=4.454459669337519)) { + r = sqrt(x+1)-sqrt(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(5.086463095261279<=x)&&(x<=5.494538771451066)) { + r = sqrt(x+1)-sqrt(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(5.599975109497048<=x)&&(x<=5.726539993141816)) { + r = sqrt(x+1)-sqrt(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(6.588006724737285<=x)&&(x<=7.231828001818615)) { + r = sqrt(x+1)-sqrt(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(7.685840646771626<=x)&&(x<=8.810461536106247)) { + r = sqrt(x+1)-sqrt(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(9.773739960540086<=x)&&(x<=10.715677981948954)) { + r = sqrt(x+1)-sqrt(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(12.276570111213195<=x)&&(x<=12.982537102167978)) { + r = sqrt(x+1)-sqrt(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(14.68601137308409<=x)&&(x<=14.84871472009893)) { + r = sqrt(x+1)-sqrt(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(55.10931785603222<=x)&&(x<=55.10931786223146)) { + r = sqrt(x+1)-sqrt(x); + return r; + } + + if((0.01<=x)&&(x<=100)) { + r_real = iRRAM::sqrt((REAL)x_real+1)-iRRAM::sqrt((REAL)x_real); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_NMSEexample31_NumOpt(double x) + { + return expr_NMSEexample31_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/NMSEexample310/expr_NMSEexample310_NumOpt.cpp b/srcTest/NMSEexample310/expr_NMSEexample310_NumOpt.cpp new file mode 100644 index 0000000..c1544b0 --- /dev/null +++ b/srcTest/NMSEexample310/expr_NMSEexample310_NumOpt.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_NMSEexample310_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((-1<=x)&&(x<=1)) { + r_real = iRRAM::log((REAL)1-x_real)/iRRAM::log((REAL)1+x_real); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_NMSEexample310_NumOpt(double x) + { + return expr_NMSEexample310_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/NMSEexample33/expr_NMSEexample33_NumOpt.cpp b/srcTest/NMSEexample33/expr_NMSEexample33_NumOpt.cpp new file mode 100644 index 0000000..1a71b1a --- /dev/null +++ b/srcTest/NMSEexample33/expr_NMSEexample33_NumOpt.cpp @@ -0,0 +1,270 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_NMSEexample33_CPP(double eps, double x) +{ + REAL eps_real(eps); + REAL x_real(x); + double r; + REAL r_real; + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(7.434734209367829e-295<=eps)&&(eps<=8.067147183600915e-295)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.8773066864894313e-252<=eps)&&(eps<=4.296923398836829e-252)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(7.292982820860915e-247<=eps)&&(eps<=4.2093941912301484e-246)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(7.439134699417557e-245<=eps)&&(eps<=3.451357033511687e-244)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.5629818809612405e-243<=eps)&&(eps<=1.749549226446628e-243)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(8.547944083624428e-242<=eps)&&(eps<=1.9135205006649776e-241)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.456150995024938e-236<=eps)&&(eps<=1.2530976124527013e-235)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.940192906463652e-222<=eps)&&(eps<=2.5233710184953186e-221)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.10584813090912e-215<=eps)&&(eps<=1.1177005878997507e-215)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.958213543508275e-214<=eps)&&(eps<=3.035842818004483e-214)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.283586601882369e-212<=eps)&&(eps<=4.971468737886205e-212)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(6.298269576390221e-205<=eps)&&(eps<=7.021665925957399e-202)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(4.9416485868453986e-200<=eps)&&(eps<=2.0633038726037926e-199)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(5.9225919784203144e-198<=eps)&&(eps<=7.71695143609805e-198)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(5.865050872406589e-192<=eps)&&(eps<=8.350952230606281e-191)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.5273432789945824e-186<=eps)&&(eps<=2.5963024681959457e-186)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.075517320567907e-184<=eps)&&(eps<=1.0881780473271177e-184)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.3982558177714916e-181<=eps)&&(eps<=8.418691105024768e-181)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(4.698921537507404e-179<=eps)&&(eps<=1.4561260987656107e-175)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.406006231055905e-173<=eps)&&(eps<=1.642061578747113e-173)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.2371439167223059e-167<=eps)&&(eps<=1.4836079964423097e-167)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(6.4605279497621005e-167<=eps)&&(eps<=1.0367565562744443e-166)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(8.196198439286282e-165<=eps)&&(eps<=4.2164099155356946e-159)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(4.767856708299514e-157<=eps)&&(eps<=5.736729788778377e-157)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.8984484362845337e-155<=eps)&&(eps<=8.750539427998615e-155)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(9.00880171098746e-153<=eps)&&(eps<=1.6801884003904512e-151)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.5021247214735642e-147<=eps)&&(eps<=2.724268953477039e-147)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.4779921920129862e-145<=eps)&&(eps<=3.2954631442243097e-143)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.3537520997688223e-136<=eps)&&(eps<=5.4971274033141563e-135)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(5.245392262412381e-132<=eps)&&(eps<=1.7793896213428044e-130)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.4440435724332697e-126<=eps)&&(eps<=5.546018879285196e-122)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(4.201105631704275e-119<=eps)&&(eps<=1.050870047393311e-118)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(5.570725412228856e-116<=eps)&&(eps<=1.9443199258523357e-114)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.1171459485515486e-112<=eps)&&(eps<=1.1637929873374265e-111)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.108708060002273e-110<=eps)&&(eps<=5.209767174467671e-110)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(5.39402231747422e-109<=eps)&&(eps<=8.826602772123591e-103)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.3802083625741864e-101<=eps)&&(eps<=9.418828959099321e-101)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.2155818321423112e-98<=eps)&&(eps<=2.807433808214297e-97)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.5061298504327682e-96<=eps)&&(eps<=1.2818341631171205e-95)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(4.211203409411544e-94<=eps)&&(eps<=5.723623564850643e-83)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.662671903138479e-80<=eps)&&(eps<=7.12104770074523e-54)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(7.045892075217811e-53<=eps)&&(eps<=1.6416534859934596e-50)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(8.493703732142176e-49<=eps)&&(eps<=1.3664606924288116e-42)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.1892890898562904e-41<=eps)&&(eps<=3.088334301914156e-38)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.1780907232134085e-36<=eps)&&(eps<=6.212899569162941e-20)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(5.7025994319818814e-15<=eps)&&(eps<=0.08788607496239624)) { + r = sin(x+eps) - sin(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)) { + r_real = iRRAM::sin((REAL)x_real+eps_real) -iRRAM::sin((REAL)x_real); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_NMSEexample33_NumOpt(double x) + { + return expr_NMSEexample33_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/NMSEexample34/expr_NMSEexample34_NumOpt.cpp b/srcTest/NMSEexample34/expr_NMSEexample34_NumOpt.cpp new file mode 100644 index 0000000..b01d1bf --- /dev/null +++ b/srcTest/NMSEexample34/expr_NMSEexample34_NumOpt.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_NMSEexample34_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.01<=x)&&(x<=3)&&(0.24350074632789553<=x)&&(x<=0.243501436280844)) { + r = (1-cos(x))/sin(x); + return r; + } + + if((0.01<=x)&&(x<=3)&&(0.24877069789885864<=x)&&(x<=0.2816733445771115)) { + r = (1-cos(x))/sin(x); + return r; + } + + if((0.01<=x)&&(x<=3)&&(0.2816733569658207<=x)&&(x<=2.924004589698516)) { + r = (1-cos(x))/sin(x); + return r; + } + + if((0.01<=x)&&(x<=3)) { + r_real = (1-iRRAM::cos((REAL)x_real))/iRRAM::sin((REAL)x_real); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_NMSEexample34_NumOpt(double x) + { + return expr_NMSEexample34_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/NMSEexample35/expr_NMSEexample35_NumOpt.cpp b/srcTest/NMSEexample35/expr_NMSEexample35_NumOpt.cpp new file mode 100644 index 0000000..b31b4fd --- /dev/null +++ b/srcTest/NMSEexample35/expr_NMSEexample35_NumOpt.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_NMSEexample35_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.01<=x)&&(x<=100)&&(0.010626357637108582<=x)&&(x<=2.4216457747634084)) { + r = atan(x+1)-atan(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(2.4675257629085374<=x)&&(x<=2.929090134073094)) { + r = atan(x+1)-atan(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(2.96296978663543<=x)&&(x<=3.362233496533575)) { + r = atan(x+1)-atan(x); + return r; + } + + if((0.01<=x)&&(x<=100)) { + r_real = iRRAM::atan((REAL)x_real+1)-iRRAM::atan((REAL)x_real); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_NMSEexample35_NumOpt(double x) + { + return expr_NMSEexample35_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/NMSEexample36/expr_NMSEexample36_NumOpt.cpp b/srcTest/NMSEexample36/expr_NMSEexample36_NumOpt.cpp new file mode 100644 index 0000000..9f48fd8 --- /dev/null +++ b/srcTest/NMSEexample36/expr_NMSEexample36_NumOpt.cpp @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_NMSEexample36_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.01<=x)&&(x<=100)&&(0.010673067477198568<=x)&&(x<=1.5958251267616936)) { + r = 1/(sqrt(x))-1/sqrt(1+x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(1.5958251309025289<=x)&&(x<=2.0621189828509077)) { + r = 1/(sqrt(x))-1/sqrt(1+x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(2.206460837078387<=x)&&(x<=2.2495889543715917)) { + r = 1/(sqrt(x))-1/sqrt(1+x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(4.579100276778099<=x)&&(x<=4.686225042548934)) { + r = 1/(sqrt(x))-1/sqrt(1+x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(5.273357509397678<=x)&&(x<=5.273359899623165)) { + r = 1/(sqrt(x))-1/sqrt(1+x); + return r; + } + + if((0.01<=x)&&(x<=100)) { + r_real = 1/(iRRAM::sqrt((REAL)x_real))-1/iRRAM::sqrt((REAL)1+x_real); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_NMSEexample36_NumOpt(double x) + { + return expr_NMSEexample36_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/NMSEexample37/expr_NMSEexample37_NumOpt.cpp b/srcTest/NMSEexample37/expr_NMSEexample37_NumOpt.cpp new file mode 100644 index 0000000..7e9c29e --- /dev/null +++ b/srcTest/NMSEexample37/expr_NMSEexample37_NumOpt.cpp @@ -0,0 +1,64 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_NMSEexample37_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.01<=x)&&(x<=100)&&(0.06722497868733401<=x)&&(x<=0.06725235096169693)) { + r = exp(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.11786006198612779<=x)&&(x<=0.13864989446981987)) { + r = exp(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.141488869668345<=x)&&(x<=0.18389725264762594)) { + r = exp(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.18718203291301166<=x)&&(x<=0.2017189063726586)) { + r = exp(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.20382590581321117<=x)&&(x<=99.12853872052801)) { + r = exp(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)) { + r_real = iRRAM::exp((REAL)x_real)-1; + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_NMSEexample37_NumOpt(double x) + { + return expr_NMSEexample37_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/NMSEexample38/expr_NMSEexample38_NumOpt.cpp b/srcTest/NMSEexample38/expr_NMSEexample38_NumOpt.cpp new file mode 100644 index 0000000..60d256c --- /dev/null +++ b/srcTest/NMSEexample38/expr_NMSEexample38_NumOpt.cpp @@ -0,0 +1,119 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_NMSEexample38_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.01<=x)&&(x<=100)&&(0.010437469457944472<=x)&&(x<=0.3604339271759145)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.8871511248989055<=x)&&(x<=0.8874171326284639)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(1.1751887785480812<=x)&&(x<=1.415667007213509)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(1.458089294902233<=x)&&(x<=1.6865102059147628)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(1.6865344487760252<=x)&&(x<=1.7153206052609768)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(1.7479678878719356<=x)&&(x<=1.9087480406358917)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(1.9122839797370013<=x)&&(x<=1.9740300295334035)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(1.9931971810641311<=x)&&(x<=3.1877653850291634)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(3.1979651413073538<=x)&&(x<=4.213377740669251)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(4.237602197231224<=x)&&(x<=4.702916612374459)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(4.957614040315142<=x)&&(x<=6.474333065779055)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(6.898192685270763<=x)&&(x<=7.073384818146711)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(7.395087638773861<=x)&&(x<=7.422516993951036)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(7.818647478830652<=x)&&(x<=10.805647243398507)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(10.90936836311555<=x)&&(x<=11.621957942764213)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)&&(59.36938744810223<=x)&&(x<=59.57610366236027)) { + r = (x+1)*log(x+1)-x*log(x)-1; + return r; + } + + if((0.01<=x)&&(x<=100)) { + r_real = (x_real+1)*iRRAM::log((REAL)x_real+1)-x_real*iRRAM::log((REAL)x_real)-1; + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_NMSEexample38_NumOpt(double x) + { + return expr_NMSEexample38_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/NMSEexample39/expr_NMSEexample39_NumOpt.cpp b/srcTest/NMSEexample39/expr_NMSEexample39_NumOpt.cpp new file mode 100644 index 0000000..a019667 --- /dev/null +++ b/srcTest/NMSEexample39/expr_NMSEexample39_NumOpt.cpp @@ -0,0 +1,74 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_NMSEexample39_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.01<=x)&&(x<=1)&&(0.3752304551929883<=x)&&(x<=0.3782631882078102)) { + r = 1/x-1/tan(x); + return r; + } + + if((0.01<=x)&&(x<=1)&&(0.38197192351353915<=x)&&(x<=0.38339280567489276)) { + r = 1/x-1/tan(x); + return r; + } + + if((0.01<=x)&&(x<=1)&&(0.3906040016481666<=x)&&(x<=0.3908873003167046)) { + r = 1/x-1/tan(x); + return r; + } + + if((0.01<=x)&&(x<=1)&&(0.41124914167390286<=x)&&(x<=0.4272101777696732)) { + r = 1/x-1/tan(x); + return r; + } + + if((0.01<=x)&&(x<=1)&&(0.458640562116811<=x)&&(x<=0.45959711531029157)) { + r = 1/x-1/tan(x); + return r; + } + + if((0.01<=x)&&(x<=1)&&(0.47477447784129195<=x)&&(x<=0.5588437133375577)) { + r = 1/x-1/tan(x); + return r; + } + + if((0.01<=x)&&(x<=1)&&(0.5588549067302485<=x)&&(x<=0.9927948509853173)) { + r = 1/x-1/tan(x); + return r; + } + + if((0.01<=x)&&(x<=1)) { + r_real = 1/x_real-1/iRRAM::tan((REAL)x_real); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_NMSEexample39_NumOpt(double x) + { + return expr_NMSEexample39_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/NMSEproblem331/expr_NMSEproblem331_NumOpt.cpp b/srcTest/NMSEproblem331/expr_NMSEproblem331_NumOpt.cpp new file mode 100644 index 0000000..9d71253 --- /dev/null +++ b/srcTest/NMSEproblem331/expr_NMSEproblem331_NumOpt.cpp @@ -0,0 +1,104 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_NMSEproblem331_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.01<=x)&&(x<=100)&&(0.010168746512177272<=x)&&(x<=7.506099159368052)) { + r = 1/(x+1)-1/x; + return r; + } + + if((0.01<=x)&&(x<=100)&&(7.999930601070934<=x)&&(x<=10.861793248757207)) { + r = 1/(x+1)-1/x; + return r; + } + + if((0.01<=x)&&(x<=100)&&(11.073762383621652<=x)&&(x<=11.946056632198577)) { + r = 1/(x+1)-1/x; + return r; + } + + if((0.01<=x)&&(x<=100)&&(12.63633448852667<=x)&&(x<=13.108698126263626)) { + r = 1/(x+1)-1/x; + return r; + } + + if((0.01<=x)&&(x<=100)&&(13.961079927820576<=x)&&(x<=13.988194316081476)) { + r = 1/(x+1)-1/x; + return r; + } + + if((0.01<=x)&&(x<=100)&&(14.903645384885676<=x)&&(x<=15.072351500800046)) { + r = 1/(x+1)-1/x; + return r; + } + + if((0.01<=x)&&(x<=100)&&(16.627975680630563<=x)&&(x<=17.170042573570754)) { + r = 1/(x+1)-1/x; + return r; + } + + if((0.01<=x)&&(x<=100)&&(18.346556947226322<=x)&&(x<=18.839229212497735)) { + r = 1/(x+1)-1/x; + return r; + } + + if((0.01<=x)&&(x<=100)&&(18.895993618078137<=x)&&(x<=19.48144169206383)) { + r = 1/(x+1)-1/x; + return r; + } + + if((0.01<=x)&&(x<=100)&&(20.265252047716615<=x)&&(x<=21.833391961226663)) { + r = 1/(x+1)-1/x; + return r; + } + + if((0.01<=x)&&(x<=100)&&(26.911051511249386<=x)&&(x<=26.911051737877717)) { + r = 1/(x+1)-1/x; + return r; + } + + if((0.01<=x)&&(x<=100)&&(35.06295977463821<=x)&&(x<=35.06295977463821)) { + r = 1/(x+1)-1/x; + return r; + } + + if((0.01<=x)&&(x<=100)&&(36.87094614503849<=x)&&(x<=36.91473783652938)) { + r = 1/(x+1)-1/x; + return r; + } + + if((0.01<=x)&&(x<=100)) { + r_real = 1/(x_real+1)-1/x_real; + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_NMSEproblem331_NumOpt(double x) + { + return expr_NMSEproblem331_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/NMSEproblem332/expr_NMSEproblem332_NumOpt.cpp b/srcTest/NMSEproblem332/expr_NMSEproblem332_NumOpt.cpp new file mode 100644 index 0000000..935adf6 --- /dev/null +++ b/srcTest/NMSEproblem332/expr_NMSEproblem332_NumOpt.cpp @@ -0,0 +1,290 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_NMSEproblem332_CPP(double eps, double x) +{ + REAL eps_real(eps); + REAL x_real(x); + double r; + REAL r_real; + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.5108525710296906e-259<=eps)&&(eps<=1.3810372471893627e-258)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.2837283298644606e-257<=eps)&&(eps<=1.485693192901714e-257)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.5937379220003817e-250<=eps)&&(eps<=2.6338577988520412e-250)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.5873253771292057e-243<=eps)&&(eps<=4.3137968058495976e-243)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.258410397322062e-240<=eps)&&(eps<=1.070461965396641e-239)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.8116174241174647e-236<=eps)&&(eps<=4.502548001200871e-235)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.8668774180497522e-233<=eps)&&(eps<=4.059126848953666e-233)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.0380679275377245e-232<=eps)&&(eps<=1.8130696239647908e-230)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(4.4115886009494417e-228<=eps)&&(eps<=7.348039670501258e-228)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.296366325211081e-214<=eps)&&(eps<=5.202244574733544e-214)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.2990911370343056e-211<=eps)&&(eps<=2.900358433758034e-211)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(6.796385350766496e-201<=eps)&&(eps<=1.058184120660101e-200)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(5.872957808587388e-199<=eps)&&(eps<=7.722773529155683e-198)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.396128270401295e-197<=eps)&&(eps<=6.934932706648367e-197)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.3452190080741407e-194<=eps)&&(eps<=6.522728310635985e-193)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.3423510789598074e-185<=eps)&&(eps<=2.3979572245317566e-185)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(4.1608154753405134e-185<=eps)&&(eps<=4.203138335661809e-185)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.942787053495008e-180<=eps)&&(eps<=4.339783455751588e-180)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.8426023458269196e-176<=eps)&&(eps<=3.4305606070893033e-175)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.856378759585273e-173<=eps)&&(eps<=8.383318704711661e-173)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.3358948833316437e-164<=eps)&&(eps<=5.583945808137087e-163)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(7.658939752271011e-161<=eps)&&(eps<=1.2215141607506556e-160)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(4.141841651104984e-160<=eps)&&(eps<=1.0458026362338476e-159)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.769600169155007e-157<=eps)&&(eps<=3.9010899624253364e-150)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.990755229480191e-143<=eps)&&(eps<=2.017765760240066e-140)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.4616015127320596e-137<=eps)&&(eps<=1.2445066320222767e-136)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(8.735155558193516e-136<=eps)&&(eps<=1.3124173303111485e-135)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.6159948666980727e-134<=eps)&&(eps<=7.502428578473285e-134)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.5037755696477674e-131<=eps)&&(eps<=3.556800900319338e-130)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(8.124511117424646e-125<=eps)&&(eps<=4.591928032598656e-121)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(8.001268481853495e-121<=eps)&&(eps<=2.5800394856144636e-120)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(7.545526506227277e-119<=eps)&&(eps<=7.71784359835738e-112)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(9.72296697448404e-109<=eps)&&(eps<=5.511761180031092e-108)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.569352435377055e-104<=eps)&&(eps<=3.955947809938828e-96)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.5811022041334388e-95<=eps)&&(eps<=1.0290556941081322e-92)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.894108265478157e-92<=eps)&&(eps<=1.7541545378895835e-91)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(6.346060764557866e-91<=eps)&&(eps<=1.8143292138843098e-90)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(6.30398962710292e-90<=eps)&&(eps<=5.3790146277372494e-89)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(5.788085951764226e-88<=eps)&&(eps<=3.240135597120385e-85)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.1899051677613604e-84<=eps)&&(eps<=3.1780907922141284e-84)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.5565651946838346e-83<=eps)&&(eps<=3.0079477103113185e-80)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(9.347152145490561e-78<=eps)&&(eps<=1.5274832674456632e-76)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.0869520731939839e-75<=eps)&&(eps<=8.425083932230819e-75)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(6.394161166053848e-74<=eps)&&(eps<=2.3187369376982203e-73)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.615442602928697e-71<=eps)&&(eps<=4.609688418154432e-60)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.2695680292935905e-59<=eps)&&(eps<=9.682701544335003e-55)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(6.541818920111603e-54<=eps)&&(eps<=1.8725260274596118e-53)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.9384543331209372e-50<=eps)&&(eps<=2.1759563993712245e-24)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.0439747553056098e-23<=eps)&&(eps<=0.00022010511756444742)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(0.00082707746975666<=eps)&&(eps<=1.346717182916112)) { + r = tan(x+eps) - tan(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)) { + r_real = iRRAM::tan((REAL)x_real+eps_real) -iRRAM::tan((REAL)x_real); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_NMSEproblem332_NumOpt(double x) + { + return expr_NMSEproblem332_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/NMSEproblem333/expr_NMSEproblem333_NumOpt.cpp b/srcTest/NMSEproblem333/expr_NMSEproblem333_NumOpt.cpp new file mode 100644 index 0000000..7b69ff7 --- /dev/null +++ b/srcTest/NMSEproblem333/expr_NMSEproblem333_NumOpt.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_NMSEproblem333_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.01<=x)&&(x<=0.99)&&(0.010391799439447024<=x)&&(x<=0.9778015263847194)) { + r = 1/(x+1)-2/x + 1/(x-1); + return r; + } + + if((0.01<=x)&&(x<=0.99)) { + r_real = 1/(x_real+1)-2/x_real + 1/(x_real-1); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_NMSEproblem333_NumOpt(double x) + { + return expr_NMSEproblem333_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/NMSEproblem335/expr_NMSEproblem335_NumOpt.cpp b/srcTest/NMSEproblem335/expr_NMSEproblem335_NumOpt.cpp new file mode 100644 index 0000000..3d6f3b0 --- /dev/null +++ b/srcTest/NMSEproblem335/expr_NMSEproblem335_NumOpt.cpp @@ -0,0 +1,150 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_NMSEproblem335_CPP(double eps, double x) +{ + REAL eps_real(eps); + REAL x_real(x); + double r; + REAL r_real; + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(6.836365780936997e-307<=eps)&&(eps<=3.424964247987962e-286)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.4726572749881702e-284<=eps)&&(eps<=4.899721680844785e-276)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(9.80094852128588e-274<=eps)&&(eps<=1.3220756303131204e-273)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.341152635398035e-273<=eps)&&(eps<=2.918900847028547e-271)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(9.29909937817375e-271<=eps)&&(eps<=2.897571946081135e-268)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.621387621444098e-268<=eps)&&(eps<=1.1810455403243362e-262)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.514498316088665e-261<=eps)&&(eps<=3.098643090316515e-237)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.1653601092697618e-236<=eps)&&(eps<=1.3277313550692224e-234)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.4228950186893905e-232<=eps)&&(eps<=3.6394307297982443e-231)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.6441878125343605e-230<=eps)&&(eps<=3.481499204600951e-230)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.9298247866138715e-228<=eps)&&(eps<=9.663047728349257e-228)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(4.857761876152504e-225<=eps)&&(eps<=4.879029707768337e-225)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(5.071205544053575e-225<=eps)&&(eps<=7.091595230411618e-215)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(1.5762797129048622e-213<=eps)&&(eps<=3.5282659320622263e-211)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.0591935467739667e-207<=eps)&&(eps<=2.8599597521194703e-200)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.9584125502794065e-199<=eps)&&(eps<=2.231979479424809e-198)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.193289562872563e-194<=eps)&&(eps<=1.1553953239314083e-188)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.0905545118199726e-186<=eps)&&(eps<=6.688161258098464e-185)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(2.441837659122788e-182<=eps)&&(eps<=2.461687324698518e-182)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(3.8064388963675838e-177<=eps)&&(eps<=7.585816439837246e-176)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(4.585873421513115e-171<=eps)&&(eps<=7.329270630732846e-168)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)&&(4.275566960818706<=eps)&&(eps<=52.008103578053365)) { + r = cos(x+eps) - cos(x); + return r; + } + + if((0<=eps)&&(eps<=100)&&(0<=x)&&(x<=100)) { + r_real = iRRAM::cos((REAL)x_real+eps_real) -iRRAM::cos((REAL)x_real); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_NMSEproblem335_NumOpt(double x) + { + return expr_NMSEproblem335_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/NMSEproblem336/expr_NMSEproblem336_NumOpt.cpp b/srcTest/NMSEproblem336/expr_NMSEproblem336_NumOpt.cpp new file mode 100644 index 0000000..aabee72 --- /dev/null +++ b/srcTest/NMSEproblem336/expr_NMSEproblem336_NumOpt.cpp @@ -0,0 +1,69 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_NMSEproblem336_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.01<=x)&&(x<=100)&&(0.010135723879275712<=x)&&(x<=3.6176135153984816)) { + r = log(x+1)-log(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(3.6176135157657585<=x)&&(x<=5.136334826947236)) { + r = log(x+1)-log(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(5.1363348269486195<=x)&&(x<=6.399636245177773)) { + r = log(x+1)-log(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(6.479433154387088<=x)&&(x<=6.8201106928635555)) { + r = log(x+1)-log(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(7.174341807867794<=x)&&(x<=7.509392298899693)) { + r = log(x+1)-log(x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(12.572681689919902<=x)&&(x<=12.576213687473984)) { + r = log(x+1)-log(x); + return r; + } + + if((0.01<=x)&&(x<=100)) { + r_real = iRRAM::log((REAL)x_real+1)-iRRAM::log((REAL)x_real); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_NMSEproblem336_NumOpt(double x) + { + return expr_NMSEproblem336_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/NMSEproblem337/expr_NMSEproblem337_NumOpt.cpp b/srcTest/NMSEproblem337/expr_NMSEproblem337_NumOpt.cpp new file mode 100644 index 0000000..96bf5b4 --- /dev/null +++ b/srcTest/NMSEproblem337/expr_NMSEproblem337_NumOpt.cpp @@ -0,0 +1,49 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_NMSEproblem337_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.01<=x)&&(x<=100)&&(0.4479715718522299<=x)&&(x<=0.44842734433069176)) { + r = exp(x)+(-2)+exp(-x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.49358419750059995<=x)&&(x<=96.8690865155957)) { + r = exp(x)+(-2)+exp(-x); + return r; + } + + if((0.01<=x)&&(x<=100)) { + r_real = iRRAM::exp((REAL)x_real)+(-2)+iRRAM::exp((REAL)-x_real); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_NMSEproblem337_NumOpt(double x) + { + return expr_NMSEproblem337_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/NMSEproblem341/expr_NMSEproblem341_NumOpt.cpp b/srcTest/NMSEproblem341/expr_NMSEproblem341_NumOpt.cpp new file mode 100644 index 0000000..a0dc551 --- /dev/null +++ b/srcTest/NMSEproblem341/expr_NMSEproblem341_NumOpt.cpp @@ -0,0 +1,74 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_NMSEproblem341_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.01<=x)&&(x<=100)&&(0.2989954160583664<=x)&&(x<=0.3040578669088568)) { + r = (1 - cos(x))/(x*x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.31285789704270733<=x)&&(x<=0.3282430725719571)) { + r = (1 - cos(x))/(x*x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.34870518609020895<=x)&&(x<=6.034636508320054)) { + r = (1 - cos(x))/(x*x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(6.574480063196469<=x)&&(x<=49.988447914427496)) { + r = (1 - cos(x))/(x*x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(50.545623864527215<=x)&&(x<=56.3274051305552)) { + r = (1 - cos(x))/(x*x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(56.77482997906461<=x)&&(x<=94.04557348534465)) { + r = (1 - cos(x))/(x*x); + return r; + } + + if((0.01<=x)&&(x<=100)&&(94.50957064205821<=x)&&(x<=97.81728977191308)) { + r = (1 - cos(x))/(x*x); + return r; + } + + if((0.01<=x)&&(x<=100)) { + r_real = (1 -iRRAM::cos((REAL)x_real))/(x_real*x_real); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_NMSEproblem341_NumOpt(double x) + { + return expr_NMSEproblem341_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/NMSEproblem343/expr_NMSEproblem343_NumOpt.cpp b/srcTest/NMSEproblem343/expr_NMSEproblem343_NumOpt.cpp new file mode 100644 index 0000000..d519699 --- /dev/null +++ b/srcTest/NMSEproblem343/expr_NMSEproblem343_NumOpt.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_NMSEproblem343_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((-1<=x)&&(x<=1)&&(0.0580610989033317<=x)&&(x<=0.8393067263745277)) { + r = log((1 - x)/(1 + x)); + return r; + } + + if((-1<=x)&&(x<=1)) { + r_real = iRRAM::log((REAL)(1 - x_real)/(1 + x_real)); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_NMSEproblem343_NumOpt(double x) + { + return expr_NMSEproblem343_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/NMSEproblem344/expr_NMSEproblem344_NumOpt.cpp b/srcTest/NMSEproblem344/expr_NMSEproblem344_NumOpt.cpp new file mode 100644 index 0000000..ce5ab59 --- /dev/null +++ b/srcTest/NMSEproblem344/expr_NMSEproblem344_NumOpt.cpp @@ -0,0 +1,104 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_NMSEproblem344_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.01<=x)&&(x<=100)&&(0.013357758595457445<=x)&&(x<=0.013385753711132663)) { + r = sqrt((exp(2*x) - 1)/(exp(x) - 1)); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.02645968602728466<=x)&&(x<=0.02645980091091372)) { + r = sqrt((exp(2*x) - 1)/(exp(x) - 1)); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.0308420310518845<=x)&&(x<=0.030958041677699714)) { + r = sqrt((exp(2*x) - 1)/(exp(x) - 1)); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.03450520733174101<=x)&&(x<=0.03493048023928692)) { + r = sqrt((exp(2*x) - 1)/(exp(x) - 1)); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.03648830890925827<=x)&&(x<=0.037239332545066846)) { + r = sqrt((exp(2*x) - 1)/(exp(x) - 1)); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.03788666905979504<=x)&&(x<=0.03880369998557144)) { + r = sqrt((exp(2*x) - 1)/(exp(x) - 1)); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.042739541918337405<=x)&&(x<=0.045849343864546734)) { + r = sqrt((exp(2*x) - 1)/(exp(x) - 1)); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.047851128580444706<=x)&&(x<=0.04888244798170545)) { + r = sqrt((exp(2*x) - 1)/(exp(x) - 1)); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.04895292466058827<=x)&&(x<=0.053780429681729275)) { + r = sqrt((exp(2*x) - 1)/(exp(x) - 1)); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.054387927814817334<=x)&&(x<=0.05630020054267815)) { + r = sqrt((exp(2*x) - 1)/(exp(x) - 1)); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.05630374551650564<=x)&&(x<=0.05808592715342758)) { + r = sqrt((exp(2*x) - 1)/(exp(x) - 1)); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.058318470703043156<=x)&&(x<=0.06031276239723299)) { + r = sqrt((exp(2*x) - 1)/(exp(x) - 1)); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.06045652094587757<=x)&&(x<=98.60588550090255)) { + r = sqrt((exp(2*x) - 1)/(exp(x) - 1)); + return r; + } + + if((0.01<=x)&&(x<=100)) { + r_real = iRRAM::sqrt((REAL)(iRRAM::exp((REAL)2*x_real) - 1)/(iRRAM::exp((REAL)x_real) - 1)); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_NMSEproblem344_NumOpt(double x) + { + return expr_NMSEproblem344_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/NMSEsection311/expr_NMSEsection311_NumOpt.cpp b/srcTest/NMSEsection311/expr_NMSEsection311_NumOpt.cpp new file mode 100644 index 0000000..0fb5344 --- /dev/null +++ b/srcTest/NMSEsection311/expr_NMSEsection311_NumOpt.cpp @@ -0,0 +1,59 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_NMSEsection311_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.01<=x)&&(x<=100)&&(0.08776050680208015<=x)&&(x<=0.09169948774645326)) { + r = exp(x)/(exp(x) - 1); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.10275257911692376<=x)&&(x<=0.1415960752103245)) { + r = exp(x)/(exp(x) - 1); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.14621514922976026<=x)&&(x<=0.15438859275988195)) { + r = exp(x)/(exp(x) - 1); + return r; + } + + if((0.01<=x)&&(x<=100)&&(0.15506122639664188<=x)&&(x<=91.61769657003777)) { + r = exp(x)/(exp(x) - 1); + return r; + } + + if((0.01<=x)&&(x<=100)) { + r_real = iRRAM::exp((REAL)x_real)/(iRRAM::exp((REAL)x_real) - 1); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_NMSEsection311_NumOpt(double x) + { + return expr_NMSEsection311_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/NMSEsection35/expr_NMSEsection35_NumOpt.cpp b/srcTest/NMSEsection35/expr_NMSEsection35_NumOpt.cpp new file mode 100644 index 0000000..c9bc06b --- /dev/null +++ b/srcTest/NMSEsection35/expr_NMSEsection35_NumOpt.cpp @@ -0,0 +1,295 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_NMSEsection35_CPP(double a, double x) +{ + REAL a_real(a); + REAL x_real(x); + double r; + REAL r_real; + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(4.426373699520133e-308<=a)&&(a<=9.64641178539536e-308)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(1.6948708374261012e-307<=a)&&(a<=3.9249341671776736e-284)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(4.649806262146611e-284<=a)&&(a<=3.4356324368853e-283)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(5.906542297452248e-282<=a)&&(a<=2.755134209599056e-274)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(2.0318943730762596e-272<=a)&&(a<=2.7738693844230365e-271)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(3.3315755901300146e-269<=a)&&(a<=2.6548839261917256e-254)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(4.21696697671564e-253<=a)&&(a<=5.311576461986012e-253)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(3.557980324973411e-249<=a)&&(a<=7.333672713124773e-246)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(4.923454646654538e-240<=a)&&(a<=2.4061062418431877e-232)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(4.272696623841612e-231<=a)&&(a<=6.462408199985713e-230)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(4.29761774789014e-226<=a)&&(a<=5.798260580495262e-225)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(3.967510616744351e-224<=a)&&(a<=1.5997196082822979e-223)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(4.9038714382828537e-222<=a)&&(a<=9.4258671998903e-222)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(7.885285658528457e-217<=a)&&(a<=2.4582235253511398e-216)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(7.473669641528526e-214<=a)&&(a<=2.3074504388938207e-212)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(2.8175377090049797e-212<=a)&&(a<=7.320924502826052e-210)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(6.596850714120958e-209<=a)&&(a<=7.373701142864517e-209)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(1.0868874069389249e-206<=a)&&(a<=3.6297312271521133e-202)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(1.0444615897969181e-201<=a)&&(a<=1.1313898239841612e-201)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(1.218926513538059e-201<=a)&&(a<=2.238794931718217e-200)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(2.438847349661079e-199<=a)&&(a<=1.8638298136405453e-197)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(6.187473189394183e-195<=a)&&(a<=2.4179431708363923e-194)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(7.147228547210765e-193<=a)&&(a<=1.0556621508935791e-192)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(3.2693627627277624e-185<=a)&&(a<=1.5488962169710398e-183)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(9.065424123450533e-182<=a)&&(a<=1.6148243079533043e-180)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(1.0934680498544342e-179<=a)&&(a<=6.143055294468906e-179)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(2.0452078591736813e-177<=a)&&(a<=5.246383557371332e-177)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(2.7095574315168934e-174<=a)&&(a<=1.8863566328857507e-172)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(1.050886346755769e-168<=a)&&(a<=1.9069551156895272e-168)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(2.702333059655267e-159<=a)&&(a<=4.9934519412223734e-158)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(9.40725411246587e-157<=a)&&(a<=1.757871640370579e-156)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(2.1669089161143363e-149<=a)&&(a<=3.8905962201375516e-149)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(1.1624849687866556e-146<=a)&&(a<=5.003542481100123e-146)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(4.736261956112328e-143<=a)&&(a<=1.0734127479087532e-141)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(3.4413611179089185e-140<=a)&&(a<=2.3220924752490645e-133)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(2.495492460711346e-132<=a)&&(a<=5.912179201129228e-132)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(2.2981744918168988e-129<=a)&&(a<=3.387528007535946e-129)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(8.154123062603018e-128<=a)&&(a<=1.953495545504702e-118)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(6.293402389701233e-113<=a)&&(a<=6.382375629617307e-113)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(1.1114129271377846e-107<=a)&&(a<=1.134133197038909e-107)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(7.29206165132118e-105<=a)&&(a<=7.550127481531e-102)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(1.793285316300961e-100<=a)&&(a<=2.015354578447418e-100)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(4.252005104708829e-99<=a)&&(a<=7.325399104906234e-98)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(3.986283749270394e-94<=a)&&(a<=7.487162872529241e-94)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(7.939187086126673e-86<=a)&&(a<=1.502822334887249e-85)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(1.6189174735842615e-84<=a)&&(a<=4.373721508859242e-83)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(1.0832536067257414e-81<=a)&&(a<=1.1360161629319568e-81)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(6.749829020803986e-73<=a)&&(a<=9.886163559335155e-73)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(2.942296925238574e-59<=a)&&(a<=3.785510202018267e-59)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(1.8142400579696498e-56<=a)&&(a<=4.4289420443586965e-55)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)&&(8.478927914741885e-32<=a)&&(a<=8.478959252545897e-32)) { + r = exp(a*x) - 1; + return r; + } + + if((0<=a)&&(a<=1)&&(0<=x)&&(x<=1)) { + r_real = iRRAM::exp((REAL)a_real*x_real) - 1; + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_NMSEsection35_NumOpt(double x) + { + return expr_NMSEsection35_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/doppler1/expr_doppler1_NumOpt.cpp b/srcTest/doppler1/expr_doppler1_NumOpt.cpp new file mode 100644 index 0000000..a97f729 --- /dev/null +++ b/srcTest/doppler1/expr_doppler1_NumOpt.cpp @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_doppler1_CPP(double T, double v, double u) +{ + REAL T_real(T); + REAL v_real(v); + REAL u_real(u); + double r; + REAL r_real; + + if((-30<=T)&&(T<=50)&&(-100<=v)&&(v<=100)&&(20<=u)&&(u<=20000)&&(-7.338559287692092<=T)&&(T<=3.8325674523602244)) { + r = ((-(1657.0/5.0+3.0/5.0*T))*v)/(((1657.0/5.0+3.0/5.0*T)+u)*((1657.0/5.0+3.0/5.0*T)+u)); + return r; + } + + if((-30<=T)&&(T<=50)&&(-100<=v)&&(v<=100)&&(20<=u)&&(u<=20000)) { + r_real = ((-(REAL(1657.0)/REAL(5.0)+REAL(3.0)/REAL(5.0)*T_real))*v_real)/(((REAL(1657.0)/REAL(5.0)+REAL(3.0)/REAL(5.0)*T_real)+u_real)*((REAL(1657.0)/REAL(5.0)+REAL(3.0)/REAL(5.0)*T_real)+u_real)); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_doppler1_NumOpt(double x) + { + return expr_doppler1_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/doppler2/expr_doppler2_NumOpt.cpp b/srcTest/doppler2/expr_doppler2_NumOpt.cpp new file mode 100644 index 0000000..55d9b39 --- /dev/null +++ b/srcTest/doppler2/expr_doppler2_NumOpt.cpp @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_doppler2_CPP(double T, double v, double u) +{ + REAL T_real(T); + REAL v_real(v); + REAL u_real(u); + double r; + REAL r_real; + + if((-40<=T)&&(T<=60)&&(-125<=v)&&(v<=125)&&(15<=u)&&(u<=25000)&&(-10.915844254234749<=T)&&(T<=4.702493440196151)) { + r = ((-(1657.0/5.0+3.0/5.0*T))*v)/(((1657.0/5.0+3.0/5.0*T)+u)*((1657.0/5.0+3.0/5.0*T)+u)); + return r; + } + + if((-40<=T)&&(T<=60)&&(-125<=v)&&(v<=125)&&(15<=u)&&(u<=25000)) { + r_real = ((-(REAL(1657.0)/REAL(5.0)+REAL(3.0)/REAL(5.0)*T_real))*v_real)/(((REAL(1657.0)/REAL(5.0)+REAL(3.0)/REAL(5.0)*T_real)+u_real)*((REAL(1657.0)/REAL(5.0)+REAL(3.0)/REAL(5.0)*T_real)+u_real)); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_doppler2_NumOpt(double x) + { + return expr_doppler2_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/doppler3/expr_doppler3_NumOpt.cpp b/srcTest/doppler3/expr_doppler3_NumOpt.cpp new file mode 100644 index 0000000..e0f7dd3 --- /dev/null +++ b/srcTest/doppler3/expr_doppler3_NumOpt.cpp @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_doppler3_CPP(double T, double v, double u) +{ + REAL T_real(T); + REAL v_real(v); + REAL u_real(u); + double r; + REAL r_real; + + if((-50<=T)&&(T<=30)&&(-30<=v)&&(v<=120)&&(320<=u)&&(u<=20300)&&(-37.47075088910655<=T)&&(T<=0.011584792119040614)) { + r = ((-(1657.0/5.0+3.0/5.0*T))*v)/(((1657.0/5.0+3.0/5.0*T)+u)*((1657.0/5.0+3.0/5.0*T)+u)); + return r; + } + + if((-50<=T)&&(T<=30)&&(-30<=v)&&(v<=120)&&(320<=u)&&(u<=20300)) { + r_real = ((-(REAL(1657.0)/REAL(5.0)+REAL(3.0)/REAL(5.0)*T_real))*v_real)/(((REAL(1657.0)/REAL(5.0)+REAL(3.0)/REAL(5.0)*T_real)+u_real)*((REAL(1657.0)/REAL(5.0)+REAL(3.0)/REAL(5.0)*T_real)+u_real)); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_doppler3_NumOpt(double x) + { + return expr_doppler3_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/exp1x/expr_exp1x_NumOpt.cpp b/srcTest/exp1x/expr_exp1x_NumOpt.cpp index eb65eed..44bc546 100644 --- a/srcTest/exp1x/expr_exp1x_NumOpt.cpp +++ b/srcTest/exp1x/expr_exp1x_NumOpt.cpp @@ -67,8 +67,7 @@ double expr_exp1x_CPP(double x) r_real = (iRRAM::exp((REAL)x_real) - 1)/x_real; return r_real.as_double(); } - double result = (exp(x) - 1)/x; - return result; + return r; } diff --git a/srcTest/i4/expr_i4_NumOpt.cpp b/srcTest/i4/expr_i4_NumOpt.cpp new file mode 100644 index 0000000..b82b206 --- /dev/null +++ b/srcTest/i4/expr_i4_NumOpt.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_i4_CPP(double x, double y) +{ + REAL x_real(x); + REAL y_real(y); + double r; + REAL r_real; + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)) { + r_real = sqrtf(x_real+y_real*y_real); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_i4_NumOpt(double x) + { + return expr_i4_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/i6/expr_i6_NumOpt.cpp b/srcTest/i6/expr_i6_NumOpt.cpp new file mode 100644 index 0000000..62a072a --- /dev/null +++ b/srcTest/i6/expr_i6_NumOpt.cpp @@ -0,0 +1,395 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_i6_CPP(double x, double y) +{ + REAL x_real(x); + REAL y_real(y); + double r; + REAL r_real; + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.10071491596713421<=x)&&(x<=0.10071491596713421)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.1053836042303186<=x)&&(x<=0.11051040864515872)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.11404379252993174<=x)&&(x<=0.11406869570369474)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.1196878553177557<=x)&&(x<=0.11986688576062991)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.12083587909163973<=x)&&(x<=0.12416293781052298)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.1296710046377132<=x)&&(x<=0.13484524434417502)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.14313795199598728<=x)&&(x<=0.1478777196008121)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.14977974703933164<=x)&&(x<=0.1500838967372697)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.1541275384399594<=x)&&(x<=0.15931090695614844)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.16824693156849477<=x)&&(x<=0.16884078479729456)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.17661468695067525<=x)&&(x<=0.19793692952398442)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.21718413845690715<=x)&&(x<=0.2176411575340831)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.2181257385146177<=x)&&(x<=0.219499117908284)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.23310775934179803<=x)&&(x<=0.2331295350020998)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.24500503898672796<=x)&&(x<=0.24500503898672796)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.24637465786642831<=x)&&(x<=0.24781016981116571)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.2544006416562272<=x)&&(x<=0.26047750839558453)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.2828445408731395<=x)&&(x<=0.29243556599806314)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.33581043186371723<=x)&&(x<=0.3559051129481395)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.400288067707727<=x)&&(x<=0.40164267990617997)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.4219954372665478<=x)&&(x<=0.43584177131273044)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.44402330344912366<=x)&&(x<=0.44919938132558623)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.46147408643102317<=x)&&(x<=0.4630811151169514)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.4681589985783008<=x)&&(x<=0.47302471195299833)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.495833574566849<=x)&&(x<=0.49846998665107684)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.5273540624174293<=x)&&(x<=0.5392204058663272)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.7149300704487647<=x)&&(x<=0.7160382828581658)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.7336493480662737<=x)&&(x<=0.7457343323443442)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.7919388096673368<=x)&&(x<=0.8116135819159088)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.8148283304581184<=x)&&(x<=0.8258402664340495)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.9031044568989568<=x)&&(x<=0.9053785555613282)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.926411151571593<=x)&&(x<=0.9478161897040787)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.9763839106738912<=x)&&(x<=0.9862591020770785)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(0.9991329443123417<=x)&&(x<=1.0037513940462461)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(1.0522465407925807<=x)&&(x<=1.0663380945015626)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(1.1027709786499862<=x)&&(x<=1.3426316575541892)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(1.4145740129882527<=x)&&(x<=1.4423462196367673)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(1.453973275213065<=x)&&(x<=1.4681095327053475)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(1.6702083036290236<=x)&&(x<=1.6848830943200692)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(1.7012757309418471<=x)&&(x<=1.7390026344770144)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(1.769177640509429<=x)&&(x<=1.784851665947586)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(1.8167886403940527<=x)&&(x<=1.8226656129670942)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(1.839620997515629<=x)&&(x<=1.854829027820515)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(1.8739736153523887<=x)&&(x<=1.9304490736232036)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(1.9445442510611082<=x)&&(x<=1.9667152436948379)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(1.9817191818260296<=x)&&(x<=1.9818749989331292)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(2.002942721014129<=x)&&(x<=2.0301779382900538)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(2.1270173964484447<=x)&&(x<=2.1666448035815424)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(2.1913411549838444<=x)&&(x<=2.2078197970764095)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(2.218733399361363<=x)&&(x<=2.2741307848917405)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(2.3884601195484763<=x)&&(x<=2.4450511101848047)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(2.487155136961458<=x)&&(x<=2.5170836757499604)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(2.739859490179255<=x)&&(x<=2.822666613230787)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(2.9483361767971203<=x)&&(x<=2.977393894118924)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(3.0611523577555175<=x)&&(x<=3.1095019994613793)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(3.2345581686444076<=x)&&(x<=3.252183466986562)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(3.414243828589088<=x)&&(x<=3.464131191759912)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(3.554530400881847<=x)&&(x<=3.5817318264062292)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(3.840439149041625<=x)&&(x<=3.954029120776398)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(4.059685641963536<=x)&&(x<=4.099125595914213)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(4.134632353471027<=x)&&(x<=4.175148212175961)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(4.401757978892964<=x)&&(x<=4.41458614251811)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(4.7701808208116505<=x)&&(x<=4.8151994570154075)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(5.265369322407071<=x)&&(x<=5.501040319901122)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(6.616168463794458<=x)&&(x<=6.616168463794458)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(6.705095306902486<=x)&&(x<=6.709713292976247)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(6.927630510520447<=x)&&(x<=6.92891271935972)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(6.964379871125361<=x)&&(x<=7.112392338955565)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(7.676171132487572<=x)&&(x<=8.302694302006753)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(8.815716091702747<=x)&&(x<=8.970952538901194)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)&&(9.27087203999151<=x)&&(x<=9.987484065255082)) { + r = sinf(x*y); + return r; + } + + if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)) { + r_real = sinf(x_real*y_real); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_i6_NumOpt(double x) + { + return expr_i6_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/intro_example/expr_intro_example_NumOpt.cpp b/srcTest/intro_example/expr_intro_example_NumOpt.cpp new file mode 100644 index 0000000..4a4e35c --- /dev/null +++ b/srcTest/intro_example/expr_intro_example_NumOpt.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_intro_example_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0<=x)&&(x<=999)&&(4.006327493609276e-308<=x)&&(x<=627.2207225851557)) { + r = x/(x+1); + return r; + } + + if((0<=x)&&(x<=999)) { + r_real = x_real/(x_real+1); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_intro_example_NumOpt(double x) + { + return expr_intro_example_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/logexp/expr_logexp_NumOpt.cpp b/srcTest/logexp/expr_logexp_NumOpt.cpp new file mode 100644 index 0000000..8e01056 --- /dev/null +++ b/srcTest/logexp/expr_logexp_NumOpt.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_logexp_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((-8<=x)&&(x<=8)&&(-1.3012690852733133<=x)&&(x<=0.042406208954006805)) { + r = log(exp(x)+1); + return r; + } + + if((-8<=x)&&(x<=8)) { + r_real = iRRAM::log((REAL)iRRAM::exp((REAL)x_real)+1); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_logexp_NumOpt(double x) + { + return expr_logexp_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/polarToCarthesianX/expr_polarToCarthesianX_NumOpt.cpp b/srcTest/polarToCarthesianX/expr_polarToCarthesianX_NumOpt.cpp new file mode 100644 index 0000000..1288fff --- /dev/null +++ b/srcTest/polarToCarthesianX/expr_polarToCarthesianX_NumOpt.cpp @@ -0,0 +1,45 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_polarToCarthesianX_CPP(double radius, double theta) +{ + REAL radius_real(radius); + REAL theta_real(theta); + double r; + REAL r_real; + + if((1<=radius)&&(radius<=10)&&(0<=theta)&&(theta<=360)&&(1.010047581718489<=radius)&&(radius<=9.95152096691238)) { + r = radius*cos(3.14159265359/180*theta); + return r; + } + + if((1<=radius)&&(radius<=10)&&(0<=theta)&&(theta<=360)) { + r_real = radius_real*iRRAM::cos((REAL)REAL(3.14159265359)/180*theta_real); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_polarToCarthesianX_NumOpt(double x) + { + return expr_polarToCarthesianX_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/predatorPrey/expr_predatorPrey_NumOpt.cpp b/srcTest/predatorPrey/expr_predatorPrey_NumOpt.cpp new file mode 100644 index 0000000..4a68f10 --- /dev/null +++ b/srcTest/predatorPrey/expr_predatorPrey_NumOpt.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_predatorPrey_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.1<=x)&&(x<=0.3)&&(0.10017796345245293<=x)&&(x<=0.29895279590701196)) { + r = ((4.0 * x) * x) / (1.0 + ((x / 1.11) * (x / 1.11))); + return r; + } + + if((0.1<=x)&&(x<=0.3)) { + r_real = ((REAL(4.0) * x_real) * x_real) / (REAL(1.0) + ((x_real / REAL(1.11)) * (x_real / REAL(1.11)))); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_predatorPrey_NumOpt(double x) + { + return expr_predatorPrey_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/sine/expr_sine_NumOpt.cpp b/srcTest/sine/expr_sine_NumOpt.cpp new file mode 100644 index 0000000..dde485f --- /dev/null +++ b/srcTest/sine/expr_sine_NumOpt.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_sine_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((-1.57079632679<=x)&&(x<=1.57079632679)&&(-0.8284989478914876<=x)&&(x<=0.00033896859562810124)) { + r = x - (1.0/6.0)*x*x*x+(1.0/120.0)*x*x*x*x*x - (1.0/5040.0)*x*x*x*x*x*x*x; + return r; + } + + if((-1.57079632679<=x)&&(x<=1.57079632679)) { + r_real = x_real - (REAL(1.0)/REAL(6.0))*x_real*x_real*x_real+(REAL(1.0)/REAL(120.0))*x_real*x_real*x_real*x_real*x_real - (REAL(1.0)/REAL(5040.0))*x_real*x_real*x_real*x_real*x_real*x_real*x_real; + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_sine_NumOpt(double x) + { + return expr_sine_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/sineorder3/expr_sineorder3_NumOpt.cpp b/srcTest/sineorder3/expr_sineorder3_NumOpt.cpp new file mode 100644 index 0000000..058bf55 --- /dev/null +++ b/srcTest/sineorder3/expr_sineorder3_NumOpt.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_sineorder3_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((-2<=x)&&(x<=2)&&(-0.7637160874038874<=x)&&(x<=0.1979489862799192)) { + r = (238732414637843.0/250000000000000.0)*x - (6450306886639899.0/50000000000000000.0)*x*x*x; + return r; + } + + if((-2<=x)&&(x<=2)) { + r_real = (REAL(238732414637843.0)/REAL(250000000000000.0))*x_real - (REAL(6450306886639899.0)/REAL(50000000000000000.0))*x_real*x_real*x_real; + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_sineorder3_NumOpt(double x) + { + return expr_sineorder3_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/sqroot/expr_sqroot_NumOpt.cpp b/srcTest/sqroot/expr_sqroot_NumOpt.cpp new file mode 100644 index 0000000..b38304b --- /dev/null +++ b/srcTest/sqroot/expr_sqroot_NumOpt.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_sqroot_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0<=x)&&(x<=1)&&(5.917017099304835e-308<=x)&&(x<=0.48856674503851)) { + r = 1.0 + 0.5*x - 0.125*x*x + 0.0625*x*x*x - 0.0390625*x*x*x*x; + return r; + } + + if((0<=x)&&(x<=1)) { + r_real = REAL(1.0) + REAL(0.5)*x_real - REAL(0.125)*x_real*x_real + REAL(0.0625)*x_real*x_real*x_real - REAL(0.0390625)*x_real*x_real*x_real*x_real; + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_sqroot_NumOpt(double x) + { + return expr_sqroot_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/sqrt_add/expr_sqrt_add_NumOpt.cpp b/srcTest/sqrt_add/expr_sqrt_add_NumOpt.cpp new file mode 100644 index 0000000..7403a78 --- /dev/null +++ b/srcTest/sqrt_add/expr_sqrt_add_NumOpt.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_sqrt_add_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((1<=x)&&(x<=1000)&&(1.0360717432848836<=x)&&(x<=974.7054355731744)) { + r = 1/(sqrt(x + 1) + sqrt(x)); + return r; + } + + if((1<=x)&&(x<=1000)) { + r_real = 1/(iRRAM::sqrt((REAL)x_real + 1) +iRRAM::sqrt((REAL)x_real)); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_sqrt_add_NumOpt(double x) + { + return expr_sqrt_add_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/test05_nonlin1_r4/expr_test05_nonlin1_r4_NumOpt.cpp b/srcTest/test05_nonlin1_r4/expr_test05_nonlin1_r4_NumOpt.cpp new file mode 100644 index 0000000..0ef1241 --- /dev/null +++ b/srcTest/test05_nonlin1_r4/expr_test05_nonlin1_r4_NumOpt.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_test05_nonlin1_r4_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((1.00001<=x)&&(x<=2)&&(1.0552419072003931<=x)&&(x<=1.0552419120606928)) { + r = (x - 1)/(x*x - 1); + return r; + } + + if((1.00001<=x)&&(x<=2)&&(1.0741413908227626<=x)&&(x<=1.0771392064647325)) { + r = (x - 1)/(x*x - 1); + return r; + } + + if((1.00001<=x)&&(x<=2)&&(1.0867648158267522<=x)&&(x<=1.9975838929838903)) { + r = (x - 1)/(x*x - 1); + return r; + } + + if((1.00001<=x)&&(x<=2)) { + r_real = (x_real - 1)/(x_real*x_real - 1); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_test05_nonlin1_r4_NumOpt(double x) + { + return expr_test05_nonlin1_r4_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/test05_nonlin1_test2/expr_test05_nonlin1_test2_NumOpt.cpp b/srcTest/test05_nonlin1_test2/expr_test05_nonlin1_test2_NumOpt.cpp new file mode 100644 index 0000000..e30f867 --- /dev/null +++ b/srcTest/test05_nonlin1_test2/expr_test05_nonlin1_test2_NumOpt.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_test05_nonlin1_test2_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((1.00001<=x)&&(x<=2)&&(1.0052412782421196<=x)&&(x<=1.9962575350666676)) { + r = 1.0/(1+x); + return r; + } + + if((1.00001<=x)&&(x<=2)) { + r_real = REAL(1.0)/(1+x_real); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_test05_nonlin1_test2_NumOpt(double x) + { + return expr_test05_nonlin1_test2_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/verhulst/expr_verhulst_NumOpt.cpp b/srcTest/verhulst/expr_verhulst_NumOpt.cpp new file mode 100644 index 0000000..c79ba10 --- /dev/null +++ b/srcTest/verhulst/expr_verhulst_NumOpt.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_verhulst_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.1<=x)&&(x<=0.3)&&(0.10016810202123817<=x)&&(x<=0.29944364568656406)) { + r = (4*x)/(1+x/1.11); + return r; + } + + if((0.1<=x)&&(x<=0.3)) { + r_real = (4*x_real)/(1+x_real/REAL(1.11)); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_verhulst_NumOpt(double x) + { + return expr_verhulst_CPP(x); + } +} \ No newline at end of file -- Gitee From 68140793d2cf45c8b9e5e5ff640ad11c3c6d806e Mon Sep 17 00:00:00 2001 From: hjwLab Date: Wed, 12 Apr 2023 16:27:59 +0800 Subject: [PATCH 09/32] Implement error detect for NumOpt 2 params and improve codes --- detectErrorTwoFPEDParallelNumOpt.sh | 94 +++++++ srcTest/test1paramFPEDParallelNumOpt.cpp | 6 +- srcTest/test2paramFPEDParallelNumOpt.cpp | 343 +++++++++++++++++++++++ 3 files changed, 439 insertions(+), 4 deletions(-) create mode 100755 detectErrorTwoFPEDParallelNumOpt.sh create mode 100644 srcTest/test2paramFPEDParallelNumOpt.cpp diff --git a/detectErrorTwoFPEDParallelNumOpt.sh b/detectErrorTwoFPEDParallelNumOpt.sh new file mode 100755 index 0000000..7656d75 --- /dev/null +++ b/detectErrorTwoFPEDParallelNumOpt.sh @@ -0,0 +1,94 @@ +# Usage: ./detectErrorTwoFPEDParallel.sh ${uniqueLabel} ${x0Start} ${x0End} ${x1Start} ${x1End} ${x0Size} ${x1Size} ${prefix} ${middle} ${suffix} ${errfile} +# set -x + +path=`pwd` +cd ${path} +CC=gcc +CPP=g++ + +uniqueLabel=${1} # unique number +x0Start=${2} +x0End=${3} +x1Start=${4} +x1End=${5} + +if [ $# -eq 17 ]; then + x0Size=${6} + x1Size=${7} + x0startNowIdx=${8} # the index of the start point of the current interval. + x1startNowIdx=${9} + x0startOriginInterval=${10} # the value of the start point of the origin interval. + x1startOriginInterval=${11} + stepX0=${12} # the step for sampling points. + stepX1=${13} + prefix=${14} # expr_${uniqueLabel}. Eg: expr_20221030155958 + middle=${15} # intervalsInfo_sizes. Eg: 3.8_7.8_-4.5_-0.3_0.4_0.9_256_256_256 + suffix=${16} # different version. Eg: herbie daisy origin temp_0_3 final + errfile=${17} # 1 or 0: TRUE or False +elif [ $# -eq 16 ]; then + x0Size=${6} + x1Size=${7} + x0startNowIdx=${8} # the index of the start point of the current interval. + x1startNowIdx=${9} + x0startOriginInterval=${10} # the value of the start point of the origin interval. + x1startOriginInterval=${11} + stepX0=${12} # the step for sampling points. + stepX1=${13} + prefix=${14} # expr_${uniqueLabel}. Eg: expr_20221030155958 + middle=${15} # intervalsInfo_sizes. Eg: 3.8_7.8_-4.5_-0.3_0.4_0.9_256_256_256 + suffix=${16} # different version. Eg: herbie daisy origin temp_0_3 final + errfile=0 # 1 or 0: TRUE or False +elif [ $# -eq 14 ]; then + x0Size=1024 + x1Size=1024 + x0startNowIdx=${6} # the index of the start point of the current interval. + x1startNowIdx=${7} + x0startOriginInterval=${8} # the value of the start point of the origin interval. + x1startOriginInterval=${9} + stepX0=${10} # the step for sampling points. + stepX1=${11} + prefix=${12} + middle=${13} + suffix=${14} + errfile=0 # 1 or 0: TRUE or False +else + echo "detectErrorTwoFPEDParallel: Invalid input parameters" + exit +fi + +testFileName=test2paramFPEDParallelNumOpt +numProcs=32 + +echo "Detecting error: ${uniqueLabel} ${x0Start} ${x0End} ${x1Start} ${x1End} ${x0Size} ${x1Size} ${prefix} ${middle} ${suffix} ${errfile}" +directory="./srcTest"/${uniqueLabel} +suffixClean=`echo ${suffix} | sed 's@_x\|_y\|_z@@g'` +sourceFile=${prefix}_${suffixClean} +fileNameKernel=${prefix}__${middle}_${suffix} + +# compile the NumOpt version +${CPP} -c -IincludeNumOpt -o objs/points.o srcNumOpt/points.cpp +${CPP} -c -IincludeNumOpt -o objs/${sourceFile}.o ${directory}/${sourceFile}.cpp +${CC} -c -o objs/${prefix}_mpfr.o ${directory}/${prefix}_mpfr.c +${CC} -c -IincludeTEST -o objs/computeULP.o ./srcTest/computeULP.c +mpic++ -c -IincludeNumOpt -IincludeTEST -DEXPRESSION=${prefix}_ -DSUFFIX=${suffix} -DERRFILE=${errfile} -o objs/${testFileName}.o ./srcTest/${testFileName}.cpp +mpic++ objs/${testFileName}.o objs/${sourceFile}.o objs/${prefix}_mpfr.o objs/computeULP.o objs/points.o -Xlinker -rpath -Xlinker libs -Llibs -liRRAM -lgmp -lpthread -Llibs -lTGen -lmpfr -lm -lqd -o ${testFileName}.exe + +# run the NumOpt version +# echo "mpirun -n ${numProcs} ./${testFileName}.exe ${x0Start} ${x0End} ${x1Start} ${x1End} ${x2Start} ${x2End} ${x0Size} ${x1Size} ${x2Size} ${fileNameKernel}" +mpirun -n ${numProcs} ./${testFileName}.exe ${x0Start} ${x0End} ${x1Start} ${x1End} ${x0Size} ${x1Size} ${x0startNowIdx} ${x1startNowIdx} ${x0startOriginInterval} ${x1startOriginInterval} ${stepX0} ${stepX1} ${fileNameKernel} ${uniqueLabel} +rm ${testFileName}.exe + +# TODO: 进一步配适多参采样测试 +# combine files +if [ ${errfile} -eq 1 ]; then + cd ./outputs/${uniqueLabel} + findWord="${fileNameKernel}_sample_*.txt" + # echo "For suffix = ${suffix}, Find and combine by shell command cat: ${findWord}" + find . -name "${findWord}" | sort -h | xargs cat > sample_${uniqueLabel}_${suffix}.txt + # echo "sample file: `pwd`/sample_${uniqueLabel}_${suffix}.txt" + rm ${findWord} + cd - > /dev/null +fi + +echo "end detecting ${uniqueLabel}" +echo diff --git a/srcTest/test1paramFPEDParallelNumOpt.cpp b/srcTest/test1paramFPEDParallelNumOpt.cpp index c8d7da9..9ab42fd 100644 --- a/srcTest/test1paramFPEDParallelNumOpt.cpp +++ b/srcTest/test1paramFPEDParallelNumOpt.cpp @@ -104,10 +104,6 @@ struct errorInfo test1FPEDparamParallel(unsigned long int testNumX0, const char* // x0 = ii0.d; for(i0 = i0StartLocal; i0 <= i0EndLocal; i0++) { x0 = x0startOriginInterval + stepX0 * i0; - // if(myid == 2) - // { - // printf("i0 = %d, x0 = %lf\n", i0, x0); - // } computeResult1param(x0, mpfrResult); computeOrcle1param(x0, mpfrOrcle); #ifdef SINGLE @@ -169,12 +165,14 @@ int main_inner(const unsigned long int &testNumX0, const string &uniqueLabelStr, MPI_Datatype MPI_errorInfo; MPI_Type_contiguous(3, MPI_DOUBLE, &MPI_errorInfo); MPI_Type_commit(&MPI_errorInfo); + char *fileNameKernel; fileNameKernel = (char *)calloc(256, sizeof(char)); sprintf(fileNameKernel, "%s", fileNameKernelStr.c_str()); char *uniqueLabel; uniqueLabel = (char *)calloc(256, sizeof(char)); sprintf(uniqueLabel, "%s", uniqueLabelStr.c_str()); + // call the error test function struct errorInfo err = test1FPEDparamParallel(testNumX0, uniqueLabel, fileNameKernel, myid, i0StartLocal, i0EndLocal, x0startOriginInterval, stepX0); diff --git a/srcTest/test2paramFPEDParallelNumOpt.cpp b/srcTest/test2paramFPEDParallelNumOpt.cpp new file mode 100644 index 0000000..42db60a --- /dev/null +++ b/srcTest/test2paramFPEDParallelNumOpt.cpp @@ -0,0 +1,343 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "iRRAM/lib.h" + +using namespace std; +using namespace iRRAM; +// int iRRAM::MAXiterationnum = 30; +// bool iRRAM::enableReiterate = true; +// bool iRRAM::alwaysenableReiterate = true; + +extern "C" +{ +#include "common.h" +#include "mpi.h" + +struct errorInfo +{ + double sumError; + double maxError; + double maxInputX0; + double maxInputX1; +}; + +#ifndef SUFFIX +#define SUFFIX orgin +#endif +#ifndef EXPRESSION +#define EXPRESSION sum +#endif + +#define EXPRESSIONMINE ADDSUFFIX(EXPRESSION, SUFFIX) +#define SUFFIX1 mpfr +#define EXPRESSIONMPFR ADDSUFFIX(EXPRESSION, SUFFIX1) + +#define TESTNUMX0 1024 +#define TESTNUMX1 1024 +// #define FP +// #define DEBUG +#ifndef ERRFILE +#define ERRFILE 0 +#endif +double EXPRESSIONMPFR(double, double, mpfr_t); +double EXPRESSIONMINE(double, double); + +int computeOrcle2param(double x0, double x1, mpfr_t orcle) +{ + return EXPRESSIONMPFR(x0, x1, orcle); +} + +int computeResult2param(double x0, double x1, mpfr_t mpfrResult) +{ + int status = 1; + + double result = EXPRESSIONMINE(x0, x1); + mpfr_set_d(mpfrResult, result, MPFR_RNDN); + + return status; +} +} + +struct errorInfo test2paramFPEDParallel(unsigned long int testNumX0, unsigned long int testNumX1, const char* uniqueLabel, const char *fileNameKernel, int myid, int i0StartLocal, int i0EndLocal, int i1StartLocal, int i1EndLocal, double x0startOriginInterval, double x1startOriginInterval, double stepX0, double stepX1) +{ + DL maxInputX0, maxInputX1; + int i0, i1; + // int flag; + double x0, x1, reUlp, sumError, aveReUlp, maxReUlp, lenX0, lenX1; + + // mpfr + mpfr_t mpfrOrcle, mpfrResult; + mpfr_inits2(PRECISION, mpfrOrcle, mpfrResult, (mpfr_ptr)0); + + // write error data to file + #if ERRFILE + char *directory = "outputs"; + char *suffix = "sample"; + char *fileNameSample; + FILE *f; + fileNameSample = (char *) calloc(strlen(directory) + strlen(uniqueLabel) + strlen(fileNameKernel) + strlen(suffix) + 128, sizeof(char)); + sprintf(fileNameSample, "%s/%s/%s_%s_%02d.txt", directory, uniqueLabel, fileNameKernel, suffix, myid); + // printf("%s\n", fileNameSample); + if ((f = fopen(fileNameSample, "w")) == NULL) { + printf("Error opening file %s.\n", fileNameSample); + exit(0); + } + #endif + + // Real number average + maxReUlp = 0; + aveReUlp = 0; + // flag = 1; + // size_t testCount = 0; + sumError = 0; + for (i1 = i1StartLocal; i1 <= i1EndLocal; i1++) + { + x1 = x1startOriginInterval + stepX1 * i1; + for (i0 = i0StartLocal; i0 <= i0EndLocal; i0++) + { + x0 = x0startOriginInterval + stepX0 * i0; + computeResult2param(x0, x1, mpfrResult); + computeOrcle2param(x0, x1, mpfrOrcle); + #ifdef SINGLE + reUlp = computeUlpDiffF(mpfrOrcle, mpfrResult); + #else // compute Double ULP as default + reUlp = computeUlpDiff(mpfrOrcle, mpfrResult); + #endif + // if(reUlp <= 0.5) { + // reUlp = 0; + // } + // if (isfinite(reUlp) == 0) + // { + // printf("happen to NaN or inf\n"); + // exit(1); + // } + + if (isnormal(reUlp) != 0) + { + #if ERRFILE + fprintf(f, "%le\t%le\n", x0, reUlp); + #endif + sumError += reUlp; + if (reUlp > maxReUlp) { + // flag = 0; + maxInputX1.d = x1; + maxInputX0.d = x0; + maxReUlp = reUlp; + } + } + } + } + // aveReUlp = sumError / testCount; + // if(flag == 1) { + // printf("all error are 0!!\n"); + // } + // printf("average ulp\tmax ulp\n"); + // printf("%lg\t%lg\n", aveReUlp, maxReUlp); + // printf("\naveReUlp = %lg\nmaxInputX0 = 0x%016lx %lg, maxInputX1 = 0x%016lx %lg, maxInputX2 = 0x%016lx %lg, maxReUlp = %lg\n", aveReUlp, maxInputX0.l, maxInputX0.d, maxInputX1.l, maxInputX1.d, maxInputX2.l, maxInputX2.d, maxReUlp); + #if ERRFILE + // fprintf(f, "\n"); + + // clear + fclose(f); + free(fileNameSample); + #endif + mpfr_clears(mpfrOrcle, mpfrResult, (mpfr_ptr)0); + struct errorInfo err; + err.sumError = sumError; + err.maxError = maxReUlp; + err.maxInputX0 = maxInputX0.d; + err.maxInputX1 = maxInputX1.d; + return err; +} + +int main_inner(const unsigned long int &testNumX0, const unsigned long int &testNumX1, const string &uniqueLabelStr, const string &fileNameKernelStr, const int &myid, const int &numProcs, const int &i0StartLocal, const int &i0EndLocal, const int &i1StartLocal, const int &i1EndLocal, const double &x0startOriginInterval, const double &x1startOriginInterval, const double &stepX0, const double &stepX1) +{ + std::fesetround(FE_TONEAREST); + std::cout << std::scientific << std::setprecision(6); + iRRAM::cout << iRRAM::setRwidth(30); + + MPI_Datatype MPI_errorInfo; + MPI_Type_contiguous(4, MPI_DOUBLE, &MPI_errorInfo); + MPI_Type_commit(&MPI_errorInfo); + + char *fileNameKernel; + fileNameKernel = (char *)calloc(256, sizeof(char)); + sprintf(fileNameKernel, "%s", fileNameKernelStr.c_str()); + char *uniqueLabel; + uniqueLabel = (char *)calloc(256, sizeof(char)); + sprintf(uniqueLabel, "%s", uniqueLabelStr.c_str()); + + // call the error test function + struct errorInfo err = test2paramFPEDParallel(testNumX0, testNumX1, uniqueLabel, fileNameKernel, myid, i0StartLocal, i0EndLocal, i1StartLocal, i1EndLocal, x0startOriginInterval, x1startOriginInterval, stepX0, stepX1); + + // gather errors and find the max + struct errorInfo *errs; + errs = (struct errorInfo *)calloc(numProcs, sizeof(struct errorInfo)); + MPI_Gather(&err, 1, MPI_errorInfo, errs, 1, MPI_errorInfo, 0, MPI_COMM_WORLD); + if (myid == 0) + { + double maxError = -1; + double aveError = 0; + double errTmp = -1; + int maxErrorIdx = -1; + for (int i = 0; i < numProcs; i++) + { + errTmp = errs[i].maxError; + if (errTmp > maxError) + { + maxError = errTmp; + maxErrorIdx = i; + } + aveError += errs[i].sumError; + } + aveError = aveError / (testNumX0 * testNumX1); + DL maxInputX0, maxInputX1; + maxInputX0.d = errs[maxErrorIdx].maxInputX0; + maxInputX1.d = errs[maxErrorIdx].maxInputX1; + + std::string directory{"./outputs"}; + std::string suffixErr("error.txt"); + FILE *fErr; + char *fileNameErr; + fileNameErr = (char *) calloc(directory.length() + strlen(uniqueLabel) + strlen(fileNameKernel) + suffixErr.length() + 128, sizeof(char)); + sprintf(fileNameErr, "%s/%s/%s_%s", directory.c_str(), uniqueLabel, fileNameKernel, suffixErr.c_str()); + if ((fErr = fopen(fileNameErr, "w")) == NULL) + { + printf("Error opening file %s.\n", fileNameErr); + exit(0); + } + printf("average ulp\tmax ulp\n"); + printf("%.16le\t%.16le\n", aveError, maxError); + // printf("\naveReUlp = %lg\nmaxInputX0 = 0x%016lx %lg, maxInputX1 = 0x%016lx %lg, maxReUlp = %lg\n", aveError, maxInputX0.l, maxInputX0.d, maxInputX1.l, maxInputX1.d, maxError); + fprintf(fErr, "average ulp\tmax ulp\n"); + fprintf(fErr, "%.16le\t%.16le\n", aveError, maxError); + fprintf(fErr, "\naveReUlp = %lg\nmaxInputX0 = 0x%016lx %lg, maxInputX1 = 0x%016lx %lg, maxReUlp = %lg\n", aveError, maxInputX0.l, maxInputX0.d, maxInputX1.l, maxInputX1.d, maxError); + + free(fileNameErr); + free(uniqueLabel); + fclose(fErr); + } + + // clear + free(fileNameKernel); + free(errs); + MPI_Type_free(&MPI_errorInfo); + + return 0; +} + +int main(int argc, char **argv) +{ + // parallel + int myid, numProcs; + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &myid); + MPI_Comm_size(MPI_COMM_WORLD, &numProcs); + + // parameters init + DL x0Start, x0End, x1Start, x1End; + unsigned long int testNumX0, testNumX1; + x0Start.d = 1; + x0End.d = 2; + x1Start.d = 1; + x1End.d = 2; + int x0startNowIdx, x1startNowIdx; + double x0startOriginInterval, x1startOriginInterval; + double stepX0, stepX1; + + testNumX0 = TESTNUMX0; + testNumX1 = TESTNUMX1; + + char *fileNameKernel; + fileNameKernel = (char *)calloc(256, sizeof(char)); + char *uniqueLabel; + uniqueLabel = (char *)calloc(256, sizeof(char)); + if (argc == 15) + { + x0Start.d = strtod(argv[1], NULL); + x0End.d = strtod(argv[2], NULL); + x1Start.d = strtod(argv[3], NULL); + x1End.d = strtod(argv[4], NULL); + testNumX0 = strtod(argv[5], NULL); + testNumX1 = strtod(argv[6], NULL); + x0startNowIdx = atoi(argv[7]); + x1startNowIdx = atoi(argv[8]); + x0startOriginInterval = strtod(argv[9], NULL); + x1startOriginInterval = strtod(argv[10], NULL); + stepX0 = strtod(argv[11], NULL); + stepX1 = strtod(argv[12], NULL); + strcpy(fileNameKernel, argv[13]); + strcpy(uniqueLabel, argv[14]); + } + else if (argc == 13) + { + x0Start.d = strtod(argv[1], NULL); + x0End.d = strtod(argv[2], NULL); + x1Start.d = strtod(argv[3], NULL); + x1End.d = strtod(argv[4], NULL); + x0startNowIdx = atoi(argv[5]); + x1startNowIdx = atoi(argv[6]); + x0startOriginInterval = strtod(argv[7], NULL); + x1startOriginInterval = strtod(argv[8], NULL); + stepX0 = strtod(argv[9], NULL); + stepX1 = strtod(argv[10], NULL); + strcpy(fileNameKernel, argv[11]); + strcpy(uniqueLabel, argv[12]); + } + else if (argc == 11) + { + testNumX0 = strtod(argv[1], NULL); + testNumX1 = strtod(argv[2], NULL); + x0startNowIdx = atoi(argv[3]); + x1startNowIdx = atoi(argv[4]); + x0startOriginInterval = strtod(argv[5], NULL); + x1startOriginInterval = strtod(argv[6], NULL); + stepX0 = strtod(argv[7], NULL); + stepX1 = strtod(argv[8], NULL); + strcpy(fileNameKernel, argv[9]); + strcpy(uniqueLabel, argv[10]); + } + else + { + printf("Usage: ./test2paramParallel.exe [x0Start x0End x1Start x1End testNumX0 testNumX1 fileNameKernel]\n"); + printf("Usage: if no correct input:\n"); + printf("Usage: \tthe fixed inputs [%g %g %g %g %lu %lu] will be used\n", x0Start.d, x0End.d, x1Start.d, x1End.d, testNumX0, testNumX1); + } + + if (myid == 0) + { + printf("\n---------------------------------------------------start test2paramFPEDParallel\n"); + printf("Parameters: x0Start: %lg, x0End: %lg, x1Start: %lg, x1End: %lg, testNumX0 = %lu, testNumX1 = %lu, fileNameKernel: %s\n", x0Start.d, x0End.d, x1Start.d, x1End.d, testNumX0, testNumX1, fileNameKernel); + } + + // local parameters init + int lenX1Local = testNumX1 / numProcs; + int i1StartLocal; + i1StartLocal = x1startNowIdx + myid * lenX1Local; + int i1EndLocal; + if (myid != numProcs - 1) + { + i1EndLocal = x1startNowIdx + (myid + 1) * lenX1Local - 1; + } + else + { + i1EndLocal = x1startNowIdx + testNumX1; + } + int i0StartLocal = x0startNowIdx; + int i0EndLocal = x0startNowIdx + testNumX0; + + string uniqueLabelStr(uniqueLabel); + string fileNameKernelStr(fileNameKernel); + iRRAM_initialize(argc, argv); + iRRAM::iRRAM_exec(main_inner, testNumX0, testNumX1, uniqueLabelStr, fileNameKernelStr, myid, numProcs, i0StartLocal, i0EndLocal, i1StartLocal, i1EndLocal, x0startOriginInterval, x1startOriginInterval, stepX0, stepX1); + + MPI_Finalize(); + return 0; +} \ No newline at end of file -- Gitee From 3aa56182ea6b03aa7fa65458817ae8f99cb338f3 Mon Sep 17 00:00:00 2001 From: hjwLab Date: Wed, 12 Apr 2023 16:30:48 +0800 Subject: [PATCH 10/32] Update detectErrorAll.sh and 2 params fpbench code --- detectErrorAll.sh | 32 ++++++++++--------- .../expr_ComplexSinCos_NumOpt.cpp | 6 ++-- .../expr_ComplexSquareRoot_NumOpt.cpp | 4 +-- .../expr_NMSEexample33_NumOpt.cpp | 4 +-- .../expr_NMSEproblem332_NumOpt.cpp | 4 +-- .../expr_NMSEproblem335_NumOpt.cpp | 4 +-- .../expr_NMSEsection35_NumOpt.cpp | 4 +-- srcTest/i4/expr_i4_NumOpt.cpp | 4 +-- srcTest/i6/expr_i6_NumOpt.cpp | 4 +-- .../expr_polarToCarthesianX_NumOpt.cpp | 4 +-- 10 files changed, 36 insertions(+), 34 deletions(-) diff --git a/detectErrorAll.sh b/detectErrorAll.sh index 74906ed..508b84d 100755 --- a/detectErrorAll.sh +++ b/detectErrorAll.sh @@ -41,34 +41,36 @@ fi # ./detectErrorOneFPEDParallel${suffix}.sh test05_nonlin1_r4 1.00001 2 500000 0 1.00001 1.9999799999999998e-06 expr_test05_nonlin1_r4 1.00001_2_500000 ${target} # ./detectErrorOneFPEDParallel${suffix}.sh test05_nonlin1_test2 1.00001 2 500000 0 1.00001 1.9999799999999998e-06 expr_test05_nonlin1_test2 1.00001_2_500000 ${target} # ./detectErrorOneFPEDParallel${suffix}.sh verhulst 0.1 0.3 500000 0 0.1 4e-07 expr_verhulst 0.1_0.3_500000 ${target} +# ./detectErrorTwoFPEDParallel${suffix}.sh ComplexSinCos 0 1 0 1 1024 1024 0 0 0 0 0.0009765625 0.0009765625 expr_ComplexSinCos 0_1_0_1_1024_1024 ${target} +# ./detectErrorTwoFPEDParallel${suffix}.sh ComplexSquareRoot 0 1 0 1 1024 1024 0 0 0 0 0.0009765625 0.0009765625 expr_ComplexSquareRoot 0_1_0_1_1024_1024 ${target} +# ./detectErrorTwoFPEDParallel${suffix}.sh NMSEexample33 0 100 0 100 1024 1024 0 0 0 0 0.09765625 0.09765625 expr_NMSEexample33 0_100_0_100_1024_1024 ${target} +# ./detectErrorTwoFPEDParallel${suffix}.sh NMSEproblem332 0 100 0 100 1024 1024 0 0 0 0 0.09765625 0.09765625 expr_NMSEproblem332 0_100_0_100_1024_1024 ${target} +# ./detectErrorTwoFPEDParallel${suffix}.sh NMSEproblem335 0 100 0 100 1024 1024 0 0 0 0 0.09765625 0.09765625 expr_NMSEproblem335 0_100_0_100_1024_1024 ${target} +# ./detectErrorTwoFPEDParallel${suffix}.sh NMSEsection35 0 1 0 1 1024 1024 0 0 0 0 0.0009765625 0.0009765625 expr_NMSEsection35 0_1_0_1_1024_1024 ${target} # problem error are too big # ./detectErrorOneFPEDParallel${suffix}.sh intro_example 0 999 500000 0 0 0.001998 expr_intro_example 0_999_500000 ${target} # ./detectErrorOneFPEDParallel${suffix}.sh sqrt_add 1 1000 500000 0 1 0.001998 expr_sqrt_add 1_1000_500000 ${target} +# ./detectErrorTwoFPEDParallel${suffix}.sh polarToCarthesianX 1 10 0 360 1024 1024 0 0 1 0 0.0087890625 0.3515625 expr_polarToCarthesianX 1_10_0_360_1024_1024 ${target} -# TODO +# problem compile error +# ./detectErrorTwoFPEDParallel${suffix}.sh i4 0.1 10 -5 5 1024 1024 0 0 0.1 -5 0.00966796875 0.009765625 expr_i4 0.1_10_-5_5_1024_1024 ${target} +# ./detectErrorTwoFPEDParallel${suffix}.sh i6 0.1 10 -5 5 1024 1024 0 0 0.1 -5 0.00966796875 0.009765625 expr_i6 0.1_10_-5_5_1024_1024 ${target} + +# TODO: NO FILE # ./detectErrorOneFPEDParallel${suffix}.sh exp1x_log 0.01 0.5 500000 0 0.01 9.8e-07 expr_exp1x_log 0.01_0.5_500000 ${target} # ./detectErrorOneFPEDParallel${suffix}.sh NMSEexample310 -1 1 500000 0 -1 4e-06 expr_NMSEexample310 -1_1_500000 ${target} # ./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem334 0.01 100 500000 0 0.01 0.00019998 expr_NMSEproblem334 0.01_100_500000 ${target} # ./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem345 0.01 100 500000 0 0.01 0.00019998 expr_NMSEproblem345 0.01_100_500000 ${target} - -# DOING -# ./detectErrorTwoFPEDParallel${suffix}.sh ComplexSinCos 0 1 0 1 1024 1024 0 0 0 0 0.0009765625 0.0009765625 expr_ComplexSinCos 0_1_0_1_1024_1024 ${target} -# ./detectErrorTwoFPEDParallel${suffix}.sh ComplexSquareRoot 0 1 0 1 1024 1024 0 0 0 0 0.0009765625 0.0009765625 expr_ComplexSquareRoot 0_1_0_1_1024_1024 ${target} -# ./detectErrorThreeFPEDParallel${suffix}.sh doppler1 -30 50 -100 100 20 20000 256 256 256 0 0 0 -30 -100 20 0.3125 0.78125 78.046875 expr_doppler1 -30_50_-100_100_20_20000_256_256_256 ${target} -# ./detectErrorThreeFPEDParallel${suffix}.sh doppler2 -40 60 -125 125 15 25000 256 256 256 0 0 0 -40 -125 15 0.390625 0.9765625 97.59765625 expr_doppler2 -40_60_-125_125_15_25000_256_256_256 ${target} -# ./detectErrorThreeFPEDParallel${suffix}.sh doppler3 -50 30 -30 120 320 20300 256 256 256 0 0 0 -50 -30 320 0.3125 0.5859375 78.046875 expr_doppler3 -50_30_-30_120_320_20300_256_256_256 ${target} # ./detectErrorTwoFPEDParallel${suffix}.sh hypot32 1 100 1 100 1024 1024 0 0 1 1 0.0966796875 0.0966796875 expr_hypot32 1_100_1_100_1024_1024 ${target} -# ./detectErrorTwoFPEDParallel${suffix}.sh i4 0.1 10 -5 5 1024 1024 0 0 0.1 -5 0.00966796875 0.009765625 expr_i4 0.1_10_-5_5_1024_1024 ${target} -# ./detectErrorTwoFPEDParallel${suffix}.sh i6 0.1 10 -5 5 1024 1024 0 0 0.1 -5 0.00966796875 0.009765625 expr_i6 0.1_10_-5_5_1024_1024 ${target} -# ./detectErrorTwoFPEDParallel${suffix}.sh NMSEexample33 0 100 0 100 1024 1024 0 0 0 0 0.09765625 0.09765625 expr_NMSEexample33 0_100_0_100_1024_1024 ${target} -# ./detectErrorTwoFPEDParallel${suffix}.sh NMSEproblem332 0 100 0 100 1024 1024 0 0 0 0 0.09765625 0.09765625 expr_NMSEproblem332 0_100_0_100_1024_1024 ${target} -# ./detectErrorTwoFPEDParallel${suffix}.sh NMSEproblem335 0 100 0 100 1024 1024 0 0 0 0 0.09765625 0.09765625 expr_NMSEproblem335 0_100_0_100_1024_1024 ${target} # ./detectErrorTwoFPEDParallel${suffix}.sh NMSEproblem346 1 2 0 1 1024 1024 0 0 1 0 0.0009765625 0.0009765625 expr_NMSEproblem346 1_2_0_1_1024_1024 ${target} -# ./detectErrorTwoFPEDParallel${suffix}.sh NMSEsection35 0 1 0 1 1024 1024 0 0 0 0 0.0009765625 0.0009765625 expr_NMSEsection35 0_1_0_1_1024_1024 ${target} -# ./detectErrorTwoFPEDParallel${suffix}.sh polarToCarthesianX 1 10 0 360 1024 1024 0 0 1 0 0.0087890625 0.3515625 expr_polarToCarthesianX 1_10_0_360_1024_1024 ${target} # ./detectErrorTwoFPEDParallel${suffix}.sh polarToCarthesianY 1 10 0 360 1024 1024 0 0 1 0 0.0087890625 0.3515625 expr_polarToCarthesianY 1_10_0_360_1024_1024 ${target} # ./detectErrorTwoFPEDParallel${suffix}.sh sec4example 1.001 2 1.001 2 1024 1024 0 0 1.001 1.001 0.0009755859375000001 0.0009755859375000001 expr_sec4example 1.001_2_1.001_2_1024_1024 ${target} # ./detectErrorTwoFPEDParallel${suffix}.sh test03_nonlin2 0 1 -1 -0.1 1024 1024 0 0 0 -1 0.0009765625 0.00087890625 expr_test03_nonlin2 0_1_-1_-0.1_1024_1024 ${target} # ./detectErrorTwoFPEDParallel${suffix}.sh theta 1 100 1 100 1024 1024 0 0 1 1 0.0966796875 0.0966796875 expr_theta 1_100_1_100_1024_1024 ${target} + +# DOING +# ./detectErrorThreeFPEDParallel${suffix}.sh doppler1 -30 50 -100 100 20 20000 256 256 256 0 0 0 -30 -100 20 0.3125 0.78125 78.046875 expr_doppler1 -30_50_-100_100_20_20000_256_256_256 ${target} +# ./detectErrorThreeFPEDParallel${suffix}.sh doppler2 -40 60 -125 125 15 25000 256 256 256 0 0 0 -40 -125 15 0.390625 0.9765625 97.59765625 expr_doppler2 -40_60_-125_125_15_25000_256_256_256 ${target} +# ./detectErrorThreeFPEDParallel${suffix}.sh doppler3 -50 30 -30 120 320 20300 256 256 256 0 0 0 -50 -30 320 0.3125 0.5859375 78.046875 expr_doppler3 -50_30_-30_120_320_20300_256_256_256 ${target} # ./detectErrorThreeFPEDParallel${suffix}.sh turbine1 3.8 7.8 -4.5 -0.3 0.4 0.9 256 256 256 0 0 0 3.8 -4.5 0.4 0.015625 0.01640625 0.001953125 expr_turbine1 3.8_7.8_-4.5_-0.3_0.4_0.9_256_256_256 ${target} diff --git a/srcTest/ComplexSinCos/expr_ComplexSinCos_NumOpt.cpp b/srcTest/ComplexSinCos/expr_ComplexSinCos_NumOpt.cpp index d34ac85..3d707b9 100644 --- a/srcTest/ComplexSinCos/expr_ComplexSinCos_NumOpt.cpp +++ b/srcTest/ComplexSinCos/expr_ComplexSinCos_NumOpt.cpp @@ -16,7 +16,7 @@ bool iRRAM::alwaysenableReiterate = true; using namespace std; using namespace iRRAM; -double expr_ComplexSinCos_CPP(double r, double i) +double expr_ComplexSinCos_CPP(double i, double r) { REAL r_real(r); REAL i_real(i); @@ -43,8 +43,8 @@ double expr_ComplexSinCos_CPP(double r, double i) extern "C" { - double expr_ComplexSinCos_NumOpt(double x) + double expr_ComplexSinCos_NumOpt(double x0, double x1) { - return expr_ComplexSinCos_CPP(x); + return expr_ComplexSinCos_CPP(x0, x1); } } \ No newline at end of file diff --git a/srcTest/ComplexSquareRoot/expr_ComplexSquareRoot_NumOpt.cpp b/srcTest/ComplexSquareRoot/expr_ComplexSquareRoot_NumOpt.cpp index 4b02997..1447018 100644 --- a/srcTest/ComplexSquareRoot/expr_ComplexSquareRoot_NumOpt.cpp +++ b/srcTest/ComplexSquareRoot/expr_ComplexSquareRoot_NumOpt.cpp @@ -38,8 +38,8 @@ double expr_ComplexSquareRoot_CPP(double x1, double x2) extern "C" { - double expr_ComplexSquareRoot_NumOpt(double x) + double expr_ComplexSquareRoot_NumOpt(double x0, double x1) { - return expr_ComplexSquareRoot_CPP(x); + return expr_ComplexSquareRoot_CPP(x0, x1); } } \ No newline at end of file diff --git a/srcTest/NMSEexample33/expr_NMSEexample33_NumOpt.cpp b/srcTest/NMSEexample33/expr_NMSEexample33_NumOpt.cpp index 1a71b1a..823fc07 100644 --- a/srcTest/NMSEexample33/expr_NMSEexample33_NumOpt.cpp +++ b/srcTest/NMSEexample33/expr_NMSEexample33_NumOpt.cpp @@ -263,8 +263,8 @@ double expr_NMSEexample33_CPP(double eps, double x) extern "C" { - double expr_NMSEexample33_NumOpt(double x) + double expr_NMSEexample33_NumOpt(double x0, double x1) { - return expr_NMSEexample33_CPP(x); + return expr_NMSEexample33_CPP(x0, x1); } } \ No newline at end of file diff --git a/srcTest/NMSEproblem332/expr_NMSEproblem332_NumOpt.cpp b/srcTest/NMSEproblem332/expr_NMSEproblem332_NumOpt.cpp index 935adf6..0c6e621 100644 --- a/srcTest/NMSEproblem332/expr_NMSEproblem332_NumOpt.cpp +++ b/srcTest/NMSEproblem332/expr_NMSEproblem332_NumOpt.cpp @@ -283,8 +283,8 @@ double expr_NMSEproblem332_CPP(double eps, double x) extern "C" { - double expr_NMSEproblem332_NumOpt(double x) + double expr_NMSEproblem332_NumOpt(double x0, double x1) { - return expr_NMSEproblem332_CPP(x); + return expr_NMSEproblem332_CPP(x0, x1); } } \ No newline at end of file diff --git a/srcTest/NMSEproblem335/expr_NMSEproblem335_NumOpt.cpp b/srcTest/NMSEproblem335/expr_NMSEproblem335_NumOpt.cpp index 3d6f3b0..84e1a3f 100644 --- a/srcTest/NMSEproblem335/expr_NMSEproblem335_NumOpt.cpp +++ b/srcTest/NMSEproblem335/expr_NMSEproblem335_NumOpt.cpp @@ -143,8 +143,8 @@ double expr_NMSEproblem335_CPP(double eps, double x) extern "C" { - double expr_NMSEproblem335_NumOpt(double x) + double expr_NMSEproblem335_NumOpt(double x0, double x1) { - return expr_NMSEproblem335_CPP(x); + return expr_NMSEproblem335_CPP(x0, x1); } } \ No newline at end of file diff --git a/srcTest/NMSEsection35/expr_NMSEsection35_NumOpt.cpp b/srcTest/NMSEsection35/expr_NMSEsection35_NumOpt.cpp index c9bc06b..f1ce1bc 100644 --- a/srcTest/NMSEsection35/expr_NMSEsection35_NumOpt.cpp +++ b/srcTest/NMSEsection35/expr_NMSEsection35_NumOpt.cpp @@ -288,8 +288,8 @@ double expr_NMSEsection35_CPP(double a, double x) extern "C" { - double expr_NMSEsection35_NumOpt(double x) + double expr_NMSEsection35_NumOpt(double x0, double x1) { - return expr_NMSEsection35_CPP(x); + return expr_NMSEsection35_CPP(x0, x1); } } \ No newline at end of file diff --git a/srcTest/i4/expr_i4_NumOpt.cpp b/srcTest/i4/expr_i4_NumOpt.cpp index b82b206..1c49954 100644 --- a/srcTest/i4/expr_i4_NumOpt.cpp +++ b/srcTest/i4/expr_i4_NumOpt.cpp @@ -33,8 +33,8 @@ double expr_i4_CPP(double x, double y) extern "C" { - double expr_i4_NumOpt(double x) + double expr_i4_NumOpt(double x0, double x1) { - return expr_i4_CPP(x); + return expr_i4_CPP(x0, x1); } } \ No newline at end of file diff --git a/srcTest/i6/expr_i6_NumOpt.cpp b/srcTest/i6/expr_i6_NumOpt.cpp index 62a072a..1874fd4 100644 --- a/srcTest/i6/expr_i6_NumOpt.cpp +++ b/srcTest/i6/expr_i6_NumOpt.cpp @@ -388,8 +388,8 @@ double expr_i6_CPP(double x, double y) extern "C" { - double expr_i6_NumOpt(double x) + double expr_i6_NumOpt(double x0, double x1) { - return expr_i6_CPP(x); + return expr_i6_CPP(x0, x1); } } \ No newline at end of file diff --git a/srcTest/polarToCarthesianX/expr_polarToCarthesianX_NumOpt.cpp b/srcTest/polarToCarthesianX/expr_polarToCarthesianX_NumOpt.cpp index 1288fff..6d9388b 100644 --- a/srcTest/polarToCarthesianX/expr_polarToCarthesianX_NumOpt.cpp +++ b/srcTest/polarToCarthesianX/expr_polarToCarthesianX_NumOpt.cpp @@ -38,8 +38,8 @@ double expr_polarToCarthesianX_CPP(double radius, double theta) extern "C" { - double expr_polarToCarthesianX_NumOpt(double x) + double expr_polarToCarthesianX_NumOpt(double x0, double x1) { - return expr_polarToCarthesianX_CPP(x); + return expr_polarToCarthesianX_CPP(x0, x1); } } \ No newline at end of file -- Gitee From 27c6bcee73af3401c83f6310ef0bbe1ae0644887 Mon Sep 17 00:00:00 2001 From: hjwLab Date: Wed, 12 Apr 2023 17:08:12 +0800 Subject: [PATCH 11/32] Implement error detect for NumOpt 3 params --- detectErrorThreeFPEDParallelNumOpt.sh | 105 +++++++ srcTest/test3paramFPEDParallelNumOpt.cpp | 351 +++++++++++++++++++++++ 2 files changed, 456 insertions(+) create mode 100755 detectErrorThreeFPEDParallelNumOpt.sh create mode 100644 srcTest/test3paramFPEDParallelNumOpt.cpp diff --git a/detectErrorThreeFPEDParallelNumOpt.sh b/detectErrorThreeFPEDParallelNumOpt.sh new file mode 100755 index 0000000..e591a6c --- /dev/null +++ b/detectErrorThreeFPEDParallelNumOpt.sh @@ -0,0 +1,105 @@ +# Usage: ./detectErrorThreeParallel.sh ${uniqueLabel} ${x0Start} ${x0End} ${x1Start} ${x1End} ${x2Start} ${x2End} ${x0Size} ${x1Size} ${x2Size} ${prefix} ${middle} ${suffix} ${errfile} +# set -x + +path=`pwd` +cd ${path} +CC=gcc +CPP=g++ + +uniqueLabel=${1} # unique number +x0Start=${2} +x0End=${3} +x1Start=${4} +x1End=${5} +x2Start=${6} +x2End=${7} +if [ $# -eq 23 ]; then + x0Size=${8} + x1Size=${9} + x2Size=${10} + x0startNowIdx=${11} # the index of the start point of the current interval. + x1startNowIdx=${12} + x2startNowIdx=${13} + x0startOriginInterval=${14} # the value of the start point of the origin interval. + x1startOriginInterval=${15} + x2startOriginInterval=${16} + stepX0=${17} # the step for sampling points. + stepX1=${18} + stepX2=${19} + prefix=${20} # expr_${uniqueLabel}. Eg: expr_20221030155958 + middle=${21} # intervalsInfo_sizes. Eg: 3.8_7.8_-4.5_-0.3_0.4_0.9_256_256_256 + suffix=${22} # different version. Eg: herbie daisy origin temp_0_3 final + errfile=${23} # 1 or 0: TRUE or False +elif [ $# -eq 22 ]; then + x0Size=${8} + x1Size=${9} + x2Size=${10} + x0startNowIdx=${11} # the index of the start point of the current interval. + x1startNowIdx=${12} + x2startNowIdx=${13} + x0startOriginInterval=${14} # the value of the start point of the origin interval. + x1startOriginInterval=${15} + x2startOriginInterval=${16} + stepX0=${17} # the step for sampling points. + stepX1=${18} + stepX2=${19} + prefix=${20} # expr_${uniqueLabel}. Eg: expr_20221030155958 + middle=${21} # intervalsInfo_sizes. Eg: 3.8_7.8_-4.5_-0.3_0.4_0.9_256_256_256 + suffix=${22} # different version. Eg: herbie daisy origin temp_0_3 final + errfile=0 # 1 or 0: TRUE or False +elif [ $# -eq 19 ]; then + x0Size=256 + x1Size=256 + x2Size=256 + x0startNowIdx=${8} # the index of the start point of the current interval. + x1startNowIdx=${9} + x2startNowIdx=${10} + x0startOriginInterval=${11} # the value of the start point of the origin interval. + x1startOriginInterval=${12} + x2startOriginInterval=${13} + stepX0=${14} # the step for sampling points. + stepX1=${15} + stepX2=${16} + prefix=${17} # expr_${uniqueLabel}. Eg: expr_20221030155958 + middle=${18} # intervalsInfo_sizes. Eg: 3.8_7.8_-4.5_-0.3_0.4_0.9_256_256_256 + suffix=${19} # different version. Eg: herbie daisy origin temp_0_3 final + errfile=0 # 1 or 0: TRUE or False +else + echo "detectErrorThreeParallel: Invalid input parameters" + exit +fi +testFileName=test3paramFPEDParallelNumOpt +numProcs=32 + +echo "Detecting error: ${uniqueLabel} ${x0Start} ${x0End} ${x1Start} ${x1End} ${x2Start} ${x2End} ${x0Size} ${x1Size} ${x2Size} ${prefix} ${middle} ${suffix} ${errfile}" +directory="./srcTest"/${uniqueLabel} +sourceFile=${prefix}_${suffix} +fileNameKernel=${prefix}__${middle}_${suffix} + +# compile the NumOpt version +${CPP} -c -IincludeNumOpt -o objs/points.o srcNumOpt/points.cpp +${CPP} -c -IincludeNumOpt -o objs/${sourceFile}.o ${directory}/${sourceFile}.cpp +${CC} -c -o objs/${prefix}_mpfr.o ${directory}/${prefix}_mpfr.c +${CC} -c -IincludeTEST -o objs/computeULP.o ./srcTest/computeULP.c +mpic++ -c -IincludeNumOpt -IincludeTEST -DEXPRESSION=${prefix}_ -DSUFFIX=${suffix} -DERRFILE=${errfile} -o objs/${testFileName}.o ./srcTest/${testFileName}.cpp +mpic++ objs/${testFileName}.o objs/${sourceFile}.o objs/${prefix}_mpfr.o objs/computeULP.o objs/points.o -Xlinker -rpath -Xlinker libs -Llibs -liRRAM -lgmp -lpthread -Llibs -lTGen -lmpfr -lm -lqd -o ${testFileName}.exe + + +# run the NumOpt version +# echo "mpirun -n ${numProcs} ./${testFileName}.exe ${x0Start} ${x0End} ${x1Start} ${x1End} ${x2Start} ${x2End} ${x0Size} ${x1Size} ${x2Size} ${fileNameKernel}" +mpirun -n ${numProcs} ./${testFileName}.exe ${x0Start} ${x0End} ${x1Start} ${x1End} ${x2Start} ${x2End} ${x0Size} ${x1Size} ${x2Size} ${x0startNowIdx} ${x1startNowIdx} ${x2startNowIdx} ${x0startOriginInterval} ${x1startOriginInterval} ${x2startOriginInterval} ${stepX0} ${stepX1} ${stepX2} ${fileNameKernel} ${uniqueLabel} +rm ${testFileName}.exe + +# combine files +if [ ${errfile} -eq 1 ]; then + cd ./outputs/${uniqueLabel} + findWord="${fileNameKernel}_sample_*.txt" + # echo "For suffix = ${suffix}, Find and combine by shell command cat: ${findWord}" + find . -name "${findWord}" | sort -h | xargs cat > sample_${uniqueLabel}_${suffix}.txt + # echo "sample file: `pwd`/sample_${uniqueLabel}_${suffix}.txt" + rm ${findWord} + cd - > /dev/null +fi + +echo "end detecting ${uniqueLabel}" +echo diff --git a/srcTest/test3paramFPEDParallelNumOpt.cpp b/srcTest/test3paramFPEDParallelNumOpt.cpp new file mode 100644 index 0000000..e61fcef --- /dev/null +++ b/srcTest/test3paramFPEDParallelNumOpt.cpp @@ -0,0 +1,351 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "iRRAM/lib.h" + +using namespace std; +using namespace iRRAM; +// int iRRAM::MAXiterationnum = 30; +// bool iRRAM::enableReiterate = true; +// bool iRRAM::alwaysenableReiterate = true; + +extern "C" +{ +#include "common.h" +#include "mpi.h" + +struct errorInfo { + double sumError; + double maxError; + double maxInputX0; + double maxInputX1; + double maxInputX2; +}; + +#ifndef SUFFIX +#define SUFFIX orgin +#endif +#ifndef EXPRESSION +#define EXPRESSION sum +#endif + +#define EXPRESSIONMINE ADDSUFFIX(EXPRESSION, SUFFIX) +#define SUFFIX1 mpfr +#define EXPRESSIONMPFR ADDSUFFIX(EXPRESSION, SUFFIX1) + +#define TESTNUMX0 256 +#define TESTNUMX1 256 +#define TESTNUMX2 256 +// #define FP +// #define DEBUG +#ifndef ERRFILE +#define ERRFILE 0 +#endif +double EXPRESSIONMPFR(double, double, double, mpfr_t); +double EXPRESSIONMINE(double, double, double); + +int computeOrcle3param(double x0, double x1, double x2, mpfr_t orcle) { + return EXPRESSIONMPFR(x0, x1, x2, orcle); +} + +int computeResult3param(double x0, double x1, double x2, mpfr_t mpfrResult) { + int status = 1; + + double result = EXPRESSIONMINE(x0, x1, x2); + mpfr_set_d(mpfrResult, result, MPFR_RNDN); + + return status; +} +} + +struct errorInfo test3paramFPEDParallel(unsigned long int testNumX0, unsigned long int testNumX1, unsigned long int testNumX2, const char* uniqueLabel, const char* fileNameKernel, int myid, int i0StartLocal, int i0EndLocal, int i1StartLocal, int i1EndLocal, int i2StartLocal, int i2EndLocal, double x0startOriginInterval, double x1startOriginInterval, double x2startOriginInterval, double stepX0, double stepX1, double stepX2) { + DL maxInputX0, maxInputX1, maxInputX2; + int i0, i1, i2; + // int flag; + double x0, x1, x2, reUlp, sumError, aveReUlp, maxReUlp, lenX0, lenX1, lenX2; + + // mpfr + mpfr_t mpfrOrcle, mpfrResult; + mpfr_inits2(PRECISION, mpfrOrcle, mpfrResult, (mpfr_ptr) 0); + + // write error data to file + #if ERRFILE + char *directory = "outputs"; + char *suffix = "sample"; + char *fileNameSample; + FILE *f; + fileNameSample = (char *) calloc(strlen(directory) + strlen(uniqueLabel) + strlen(fileNameKernel) + strlen(suffix) + 128, sizeof(char)); + sprintf(fileNameSample, "%s/%s/%s_%s_%02d.txt", directory, uniqueLabel, fileNameKernel, suffix, myid); + // printf("%s\n", fileNameSample); + if ((f = fopen(fileNameSample, "w")) == NULL) { + printf("Error opening file %s.\n", fileNameSample); + exit(0); + } + #endif + + // Real number average + maxReUlp = 0; + // flag = 1; + // size_t testCount = 0; + sumError = 0; + for(i2 = i2StartLocal; i2 <= i2EndLocal; i2++) { + x2 = x2startOriginInterval + stepX2 * i2; + for(i1 = i1StartLocal; i1 <= i1EndLocal; i1++) { + x1 = x1startOriginInterval + stepX1 * i1; + for(i0 = i0StartLocal; i0 <= i0EndLocal; i0++) { + x0 = x0startOriginInterval + stepX0 * i0; + computeResult3param(x0, x1, x2, mpfrResult); + computeOrcle3param(x0, x1, x2, mpfrOrcle); + #ifdef SINGLE + reUlp = computeUlpDiffF(mpfrOrcle, mpfrResult); + #else // compute Double ULP as default + reUlp = computeUlpDiff(mpfrOrcle, mpfrResult); + #endif + // if(reUlp <= 0.5) { + // reUlp = 0; + // } + // if(isfinite(reUlp) == 0) { + // printf("happen to NaN or inf\n"); + // exit(1); + // } + // fprintf(f, "%le\t%le\t%le\t%e\n", x0, x1, x2, reUlp); + if (isnormal(reUlp) != 0) + { + #if ERRFILE + fprintf(f, "%le\t%le\n", x0, reUlp); + #endif + sumError += reUlp; + if (reUlp > maxReUlp) { + // flag = 0; + maxInputX2.d = x2; + maxInputX1.d = x1; + maxInputX0.d = x0; + maxReUlp = reUlp; + } + } + } + } + } + // aveReUlp = sumError / testCount; + // if(flag == 1) { + // printf("all error are 0!!\n"); + // } + // printf("average ulp\tmax ulp\n"); + // printf("%lg\t%lg\n", aveReUlp, maxReUlp); + // printf("\naveReUlp = %lg\nmaxInputX0 = 0x%016lx %lg, maxInputX1 = 0x%016lx %lg, maxInputX2 = 0x%016lx %lg, maxReUlp = %lg\n", aveReUlp, maxInputX0.l, maxInputX0.d, maxInputX1.l, maxInputX1.d, maxInputX2.l, maxInputX2.d, maxReUlp); + #if ERRFILE + // fprintf(f, "\n"); + + // clear + fclose(f); + free(fileNameSample); + #endif + mpfr_clears(mpfrOrcle, mpfrResult, (mpfr_ptr) 0); + struct errorInfo err; + err.sumError = sumError; + err.maxError = maxReUlp; + err.maxInputX0 = maxInputX0.d; + err.maxInputX1 = maxInputX1.d; + err.maxInputX2 = maxInputX2.d; + return err; +} + +int main_inner(const unsigned long int &testNumX0, const unsigned long int &testNumX1, const unsigned long int &testNumX2, const string &uniqueLabelStr, const string &fileNameKernelStr, const int &myid, const int &numProcs, const int &i0StartLocal, const int &i0EndLocal, const int &i1StartLocal, const int &i1EndLocal, const int &i2StartLocal, const int &i2EndLocal, const double &x0startOriginInterval, const double &x1startOriginInterval, const double &x2startOriginInterval, const double &stepX0, const double &stepX1, const double &stepX2) +{ + std::fesetround(FE_TONEAREST); + std::cout << std::scientific << std::setprecision(6); + iRRAM::cout << iRRAM::setRwidth(30); + + MPI_Datatype MPI_errorInfo; + MPI_Type_contiguous(5, MPI_DOUBLE, &MPI_errorInfo); + MPI_Type_commit(&MPI_errorInfo); + + char *fileNameKernel; + fileNameKernel = (char *)calloc(256, sizeof(char)); + sprintf(fileNameKernel, "%s", fileNameKernelStr.c_str()); + char *uniqueLabel; + uniqueLabel = (char *)calloc(256, sizeof(char)); + sprintf(uniqueLabel, "%s", uniqueLabelStr.c_str()); + + // call the error test function + struct errorInfo err = test3paramFPEDParallel(testNumX0, testNumX1, testNumX2, uniqueLabel, fileNameKernel, myid, i0StartLocal, i0EndLocal, i1StartLocal, i1EndLocal, i2StartLocal, i2EndLocal, x0startOriginInterval, x1startOriginInterval, x2startOriginInterval, stepX0, stepX1, stepX2); + + // gather errors and find the max + struct errorInfo *errs; + errs = (struct errorInfo *)calloc(numProcs, sizeof(struct errorInfo)); + MPI_Gather(&err, 1, MPI_errorInfo, errs, 1, MPI_errorInfo, 0, MPI_COMM_WORLD); + if(myid == 0) + { + double maxError = -1; + double aveError = 0; + double errTmp = -1; + int maxErrorIdx = -1; + for(int i = 0; i < numProcs; i++) + { + errTmp = errs[i].maxError; + if(errTmp > maxError) + { + maxError = errTmp; + maxErrorIdx = i; + } + aveError += errs[i].sumError; + } + aveError = aveError / (testNumX0 * testNumX1 * testNumX2); + DL maxInputX0, maxInputX1, maxInputX2; + maxInputX0.d = errs[maxErrorIdx].maxInputX0; + maxInputX1.d = errs[maxErrorIdx].maxInputX1; + maxInputX2.d = errs[maxErrorIdx].maxInputX2; + + std::string directory{"./outputs"}; + std::string suffixErr("error.txt"); + FILE *fErr; + char *fileNameErr; + fileNameErr = (char *) calloc(directory.length() + strlen(uniqueLabel) + strlen(fileNameKernel) + suffixErr.length() + 128, sizeof(char)); + sprintf(fileNameErr, "%s/%s/%s_%s", directory.c_str(), uniqueLabel, fileNameKernel, suffixErr.c_str()); + if ((fErr = fopen(fileNameErr, "w")) == NULL) + { + printf("Error opening file %s.\n", fileNameErr); + exit(0); + } + printf("average ulp\tmax ulp\n"); + printf("%.16le\t%.16le\n", aveError, maxError); + // printf("\naveReUlp = %lg\nmaxInputX0 = 0x%016lx %lg, maxInputX1 = 0x%016lx %lg, maxInputX2 = 0x%016lx %lg, maxReUlp = %lg\n", aveError, maxInputX0.l, maxInputX0.d, maxInputX1.l, maxInputX1.d, maxInputX2.l, maxInputX2.d, maxError); + fprintf(fErr, "average ulp\tmax ulp\n"); + fprintf(fErr, "%.16le\t%.16le\n", aveError, maxError); + fprintf(fErr, "\naveReUlp = %lg\nmaxInputX0 = 0x%016lx %lg, maxInputX1 = 0x%016lx %lg, maxInputX2 = 0x%016lx %lg, maxReUlp = %lg\n", aveError, maxInputX0.l, maxInputX0.d, maxInputX1.l, maxInputX1.d, maxInputX2.l, maxInputX2.d, maxError); + + free(fileNameErr); + free(uniqueLabel); + fclose(fErr); + } + + // clear + free(fileNameKernel); + free(errs); + MPI_Type_free(&MPI_errorInfo); + return 0; +} + + +int main(int argc, char **argv) { + // parallel + int myid, numProcs; + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &myid); + MPI_Comm_size(MPI_COMM_WORLD, &numProcs); + + // parameters init + DL x0Start, x0End, x1Start, x1End, x2Start, x2End; + unsigned long int testNumX0, testNumX1, testNumX2; + x0Start.d = 1; + x0End.d = 2; + x1Start.d = 1; + x1End.d = 2; + x2Start.d = 1; + x2End.d = 2; + int x0startNowIdx, x1startNowIdx, x2startNowIdx; + double x0startOriginInterval, x1startOriginInterval, x2startOriginInterval; + double stepX0, stepX1, stepX2; + + testNumX0 = TESTNUMX0; + testNumX1 = TESTNUMX1; + testNumX2 = TESTNUMX2; + + char *fileNameKernel; + fileNameKernel = (char *)calloc(256, sizeof(char)); + char *uniqueLabel; + uniqueLabel = (char *)calloc(256, sizeof(char)); + if(argc == 21) { + x0Start.d = strtod(argv[1], NULL); + x0End.d = strtod(argv[2], NULL); + x1Start.d = strtod(argv[3], NULL); + x1End.d = strtod(argv[4], NULL); + x2Start.d = strtod(argv[5], NULL); + x2End.d = strtod(argv[6], NULL); + testNumX0 = strtod(argv[7], NULL); + testNumX1 = strtod(argv[8], NULL); + testNumX2 = strtod(argv[9], NULL); + x0startNowIdx = atoi(argv[10]); + x1startNowIdx = atoi(argv[11]); + x2startNowIdx = atoi(argv[12]); + x0startOriginInterval = strtod(argv[13], NULL); + x1startOriginInterval = strtod(argv[14], NULL); + x2startOriginInterval = strtod(argv[15], NULL); + stepX0 = strtod(argv[16], NULL); + stepX1 = strtod(argv[17], NULL); + stepX2 = strtod(argv[18], NULL); + strcpy(fileNameKernel, argv[19]); + strcpy(uniqueLabel, argv[20]); + } else if(argc == 18) { + x0Start.d = strtod(argv[1], NULL); + x0End.d = strtod(argv[2], NULL); + x1Start.d = strtod(argv[3], NULL); + x1End.d = strtod(argv[4], NULL); + x2Start.d = strtod(argv[5], NULL); + x2End.d = strtod(argv[6], NULL); + x0startNowIdx = atoi(argv[7]); + x1startNowIdx = atoi(argv[8]); + x2startNowIdx = atoi(argv[9]); + x0startOriginInterval = strtod(argv[10], NULL); + x1startOriginInterval = strtod(argv[11], NULL); + x2startOriginInterval = strtod(argv[12], NULL); + stepX0 = strtod(argv[13], NULL); + stepX1 = strtod(argv[14], NULL); + stepX2 = strtod(argv[15], NULL); + strcpy(fileNameKernel, argv[16]); + strcpy(uniqueLabel, argv[17]); + } else if(argc == 15) { + testNumX0 = strtod(argv[1], NULL); + testNumX1 = strtod(argv[2], NULL); + testNumX2 = strtod(argv[3], NULL); + x0startNowIdx = atoi(argv[4]); + x1startNowIdx = atoi(argv[5]); + x2startNowIdx = atoi(argv[6]); + x0startOriginInterval = strtod(argv[7], NULL); + x1startOriginInterval = strtod(argv[8], NULL); + x2startOriginInterval = strtod(argv[9], NULL); + stepX0 = strtod(argv[10], NULL); + stepX1 = strtod(argv[11], NULL); + stepX2 = strtod(argv[12], NULL); + strcpy(fileNameKernel, argv[13]); + strcpy(uniqueLabel, argv[14]); + } else { + printf("Usage: ./test3paramFPEDParallel.exe [x0Start x0End x1Start x1End x2Start x2End testNumX0 testNumX1 testNumX2 fileNameKernel]\n"); + printf("Usage: if no correct input:\n"); + printf("Usage: \tthe fixed inputs [%g %g %g %g %g %g %lu %lu %lu] will be used\n", x0Start.d, x0End.d, x1Start.d, x1End.d, x2Start.d, x2End.d, testNumX0, testNumX1, testNumX2); + } + + if(myid == 0) { + printf("\n---------------------------------------------------start test3paramFPEDParallel\n"); + printf("Parameters: x0Start: %lg, x0End: %lg, x1Start: %lg, x1End: %lg, x2Start: %lg, x2End: %lg, testNumX0 = %lu, testNumX1 = %lu, testNumX2 = %lu, fileNameKernel: %s\n", x0Start.d, x0End.d, x1Start.d, x1End.d, x2Start.d, x2End.d, testNumX0, testNumX1, testNumX2, fileNameKernel); + } + + // local parameters init + int lenX2Local = testNumX2 / numProcs; + int i2StartLocal; + i2StartLocal = x2startNowIdx + myid * lenX2Local; + int i2EndLocal; + if(myid != numProcs - 1) { + i2EndLocal = x2startNowIdx + (myid + 1) * lenX2Local - 1; + } else { + i2EndLocal = x2startNowIdx + testNumX2; + } + int i1StartLocal = x1startNowIdx; + int i1EndLocal = x1startNowIdx + testNumX1; + int i0StartLocal = x0startNowIdx; + int i0EndLocal = x0startNowIdx + testNumX0; + + string uniqueLabelStr(uniqueLabel); + string fileNameKernelStr(fileNameKernel); + iRRAM_initialize(argc, argv); + iRRAM::iRRAM_exec(main_inner, testNumX0, testNumX1, testNumX2, uniqueLabelStr, fileNameKernelStr, myid, numProcs, i0StartLocal, i0EndLocal, i1StartLocal, i1EndLocal, i2StartLocal, i2EndLocal, x0startOriginInterval, x1startOriginInterval, x2startOriginInterval, stepX0, stepX1, stepX2); + + MPI_Finalize(); + return 0; +} \ No newline at end of file -- Gitee From 2f82ea171983a305c15838bed18554e8a6c44b60 Mon Sep 17 00:00:00 2001 From: hjwLab Date: Wed, 12 Apr 2023 17:08:32 +0800 Subject: [PATCH 12/32] Update detectErrorAll.sh and 3 params fpbench code --- detectErrorAll.sh | 10 ++++------ srcTest/doppler1/expr_doppler1_NumOpt.cpp | 6 +++--- srcTest/doppler2/expr_doppler2_NumOpt.cpp | 6 +++--- srcTest/doppler3/expr_doppler3_NumOpt.cpp | 6 +++--- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/detectErrorAll.sh b/detectErrorAll.sh index 508b84d..94aafe7 100755 --- a/detectErrorAll.sh +++ b/detectErrorAll.sh @@ -52,6 +52,9 @@ fi # ./detectErrorOneFPEDParallel${suffix}.sh intro_example 0 999 500000 0 0 0.001998 expr_intro_example 0_999_500000 ${target} # ./detectErrorOneFPEDParallel${suffix}.sh sqrt_add 1 1000 500000 0 1 0.001998 expr_sqrt_add 1_1000_500000 ${target} # ./detectErrorTwoFPEDParallel${suffix}.sh polarToCarthesianX 1 10 0 360 1024 1024 0 0 1 0 0.0087890625 0.3515625 expr_polarToCarthesianX 1_10_0_360_1024_1024 ${target} +# ./detectErrorThreeFPEDParallel${suffix}.sh doppler1 -30 50 -100 100 20 20000 256 256 256 0 0 0 -30 -100 20 0.3125 0.78125 78.046875 expr_doppler1 -30_50_-100_100_20_20000_256_256_256 ${target} +# ./detectErrorThreeFPEDParallel${suffix}.sh doppler2 -40 60 -125 125 15 25000 256 256 256 0 0 0 -40 -125 15 0.390625 0.9765625 97.59765625 expr_doppler2 -40_60_-125_125_15_25000_256_256_256 ${target} +# ./detectErrorThreeFPEDParallel${suffix}.sh doppler3 -50 30 -30 120 320 20300 256 256 256 0 0 0 -50 -30 320 0.3125 0.5859375 78.046875 expr_doppler3 -50_30_-30_120_320_20300_256_256_256 ${target} # problem compile error # ./detectErrorTwoFPEDParallel${suffix}.sh i4 0.1 10 -5 5 1024 1024 0 0 0.1 -5 0.00966796875 0.009765625 expr_i4 0.1_10_-5_5_1024_1024 ${target} @@ -68,9 +71,4 @@ fi # ./detectErrorTwoFPEDParallel${suffix}.sh sec4example 1.001 2 1.001 2 1024 1024 0 0 1.001 1.001 0.0009755859375000001 0.0009755859375000001 expr_sec4example 1.001_2_1.001_2_1024_1024 ${target} # ./detectErrorTwoFPEDParallel${suffix}.sh test03_nonlin2 0 1 -1 -0.1 1024 1024 0 0 0 -1 0.0009765625 0.00087890625 expr_test03_nonlin2 0_1_-1_-0.1_1024_1024 ${target} # ./detectErrorTwoFPEDParallel${suffix}.sh theta 1 100 1 100 1024 1024 0 0 1 1 0.0966796875 0.0966796875 expr_theta 1_100_1_100_1024_1024 ${target} - -# DOING -# ./detectErrorThreeFPEDParallel${suffix}.sh doppler1 -30 50 -100 100 20 20000 256 256 256 0 0 0 -30 -100 20 0.3125 0.78125 78.046875 expr_doppler1 -30_50_-100_100_20_20000_256_256_256 ${target} -# ./detectErrorThreeFPEDParallel${suffix}.sh doppler2 -40 60 -125 125 15 25000 256 256 256 0 0 0 -40 -125 15 0.390625 0.9765625 97.59765625 expr_doppler2 -40_60_-125_125_15_25000_256_256_256 ${target} -# ./detectErrorThreeFPEDParallel${suffix}.sh doppler3 -50 30 -30 120 320 20300 256 256 256 0 0 0 -50 -30 320 0.3125 0.5859375 78.046875 expr_doppler3 -50_30_-30_120_320_20300_256_256_256 ${target} -# ./detectErrorThreeFPEDParallel${suffix}.sh turbine1 3.8 7.8 -4.5 -0.3 0.4 0.9 256 256 256 0 0 0 3.8 -4.5 0.4 0.015625 0.01640625 0.001953125 expr_turbine1 3.8_7.8_-4.5_-0.3_0.4_0.9_256_256_256 ${target} +# ./detectErrorThreeFPEDParallel${suffix}.sh turbine1 3.8 7.8 -4.5 -0.3 0.4 0.9 256 256 256 0 0 0 3.8 -4.5 0.4 0.015625 0.01640625 0.001953125 expr_turbine1 3.8_7.8_-4.5_-0.3_0.4_0.9_256_256_256 ${target} \ No newline at end of file diff --git a/srcTest/doppler1/expr_doppler1_NumOpt.cpp b/srcTest/doppler1/expr_doppler1_NumOpt.cpp index a97f729..441b19c 100644 --- a/srcTest/doppler1/expr_doppler1_NumOpt.cpp +++ b/srcTest/doppler1/expr_doppler1_NumOpt.cpp @@ -16,7 +16,7 @@ bool iRRAM::alwaysenableReiterate = true; using namespace std; using namespace iRRAM; -double expr_doppler1_CPP(double T, double v, double u) +double expr_doppler1_CPP(double T, double u, double v) { REAL T_real(T); REAL v_real(v); @@ -39,8 +39,8 @@ double expr_doppler1_CPP(double T, double v, double u) extern "C" { - double expr_doppler1_NumOpt(double x) + double expr_doppler1_NumOpt(double x0, double x1, double x2) { - return expr_doppler1_CPP(x); + return expr_doppler1_CPP(x0, x1, x2); } } \ No newline at end of file diff --git a/srcTest/doppler2/expr_doppler2_NumOpt.cpp b/srcTest/doppler2/expr_doppler2_NumOpt.cpp index 55d9b39..789454d 100644 --- a/srcTest/doppler2/expr_doppler2_NumOpt.cpp +++ b/srcTest/doppler2/expr_doppler2_NumOpt.cpp @@ -16,7 +16,7 @@ bool iRRAM::alwaysenableReiterate = true; using namespace std; using namespace iRRAM; -double expr_doppler2_CPP(double T, double v, double u) +double expr_doppler2_CPP(double T, double u, double v) { REAL T_real(T); REAL v_real(v); @@ -39,8 +39,8 @@ double expr_doppler2_CPP(double T, double v, double u) extern "C" { - double expr_doppler2_NumOpt(double x) + double expr_doppler2_NumOpt(double x0, double x1, double x2) { - return expr_doppler2_CPP(x); + return expr_doppler2_CPP(x0, x1, x2); } } \ No newline at end of file diff --git a/srcTest/doppler3/expr_doppler3_NumOpt.cpp b/srcTest/doppler3/expr_doppler3_NumOpt.cpp index e0f7dd3..503cacb 100644 --- a/srcTest/doppler3/expr_doppler3_NumOpt.cpp +++ b/srcTest/doppler3/expr_doppler3_NumOpt.cpp @@ -16,7 +16,7 @@ bool iRRAM::alwaysenableReiterate = true; using namespace std; using namespace iRRAM; -double expr_doppler3_CPP(double T, double v, double u) +double expr_doppler3_CPP(double T, double u, double v) { REAL T_real(T); REAL v_real(v); @@ -39,8 +39,8 @@ double expr_doppler3_CPP(double T, double v, double u) extern "C" { - double expr_doppler3_NumOpt(double x) + double expr_doppler3_NumOpt(double x0, double x1, double x2) { - return expr_doppler3_CPP(x); + return expr_doppler3_CPP(x0, x1, x2); } } \ No newline at end of file -- Gitee From 9162d28dc9b7b1bc52658fd117c48b8556a52cd2 Mon Sep 17 00:00:00 2001 From: hjwLab Date: Wed, 12 Apr 2023 20:42:53 +0800 Subject: [PATCH 13/32] Update fpbench code, error detecting results, and test function --- detectErrorAll.sh | 18 ++++++++---------- srcTest/doppler1/expr_doppler1_NumOpt.cpp | 3 ++- srcTest/doppler2/expr_doppler2_NumOpt.cpp | 3 ++- srcTest/doppler3/expr_doppler3_NumOpt.cpp | 3 ++- srcTest/i4/expr_i4_NumOpt.cpp | 2 +- srcTest/i6/expr_i6_NumOpt.cpp | 2 +- .../expr_intro_example_NumOpt.cpp | 4 ++-- srcTest/sqrt_add/expr_sqrt_add_NumOpt.cpp | 3 ++- srcTest/test1paramFPEDParallelNumOpt.cpp | 3 +++ srcTest/test2paramFPEDParallelNumOpt.cpp | 1 + 10 files changed, 24 insertions(+), 18 deletions(-) diff --git a/detectErrorAll.sh b/detectErrorAll.sh index 94aafe7..17f0b5a 100755 --- a/detectErrorAll.sh +++ b/detectErrorAll.sh @@ -18,8 +18,10 @@ fi # DONE # ./detectErrorOneFPEDParallel${suffix}.sh Bsplines3 0 1 500000 0 0 2e-06 expr_Bsplines3 0_1_500000 ${target} # ./detectErrorOneFPEDParallel${suffix}.sh exp1x 0.01 0.5 500000 0 0.01 9.8e-07 expr_exp1x 0.01_0.5_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh intro_example 0 999 500000 0 0 0.001998 expr_intro_example 0_999_500000 ${target} # ./detectErrorOneFPEDParallel${suffix}.sh logexp -8 8 500000 0 -8 3.2e-05 expr_logexp -8_8_500000 ${target} # ./detectErrorOneFPEDParallel${suffix}.sh NMSEexample31 0.01 100 500000 0 0.01 0.00019998 expr_NMSEexample31 0.01_100_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh NMSEexample310 -1 1 500000 0 -1 4e-06 expr_NMSEexample310 -1_1_500000 ${target} # ./detectErrorOneFPEDParallel${suffix}.sh NMSEexample34 0.01 3 500000 0 0.01 5.98e-06 expr_NMSEexample34 0.01_3_500000 ${target} # ./detectErrorOneFPEDParallel${suffix}.sh NMSEexample35 0.01 100 500000 0 0.01 0.00019998 expr_NMSEexample35 0.01_100_500000 ${target} # ./detectErrorOneFPEDParallel${suffix}.sh NMSEexample36 0.01 100 500000 0 0.01 0.00019998 expr_NMSEexample36 0.01_100_500000 ${target} @@ -38,31 +40,27 @@ fi # ./detectErrorOneFPEDParallel${suffix}.sh sine -1.57079632679 1.57079632679 500000 0 -1.57079632679 6.28318530716e-06 expr_sine -1.57079632679_1.57079632679_500000 ${target} # ./detectErrorOneFPEDParallel${suffix}.sh sineorder3 -2 2 500000 0 -2 8e-06 expr_sineorder3 -2_2_500000 ${target} # ./detectErrorOneFPEDParallel${suffix}.sh sqroot 0 1 500000 0 0 2e-06 expr_sqroot 0_1_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh sqrt_add 1 1000 500000 0 1 0.001998 expr_sqrt_add 1_1000_500000 ${target} # ./detectErrorOneFPEDParallel${suffix}.sh test05_nonlin1_r4 1.00001 2 500000 0 1.00001 1.9999799999999998e-06 expr_test05_nonlin1_r4 1.00001_2_500000 ${target} # ./detectErrorOneFPEDParallel${suffix}.sh test05_nonlin1_test2 1.00001 2 500000 0 1.00001 1.9999799999999998e-06 expr_test05_nonlin1_test2 1.00001_2_500000 ${target} # ./detectErrorOneFPEDParallel${suffix}.sh verhulst 0.1 0.3 500000 0 0.1 4e-07 expr_verhulst 0.1_0.3_500000 ${target} # ./detectErrorTwoFPEDParallel${suffix}.sh ComplexSinCos 0 1 0 1 1024 1024 0 0 0 0 0.0009765625 0.0009765625 expr_ComplexSinCos 0_1_0_1_1024_1024 ${target} # ./detectErrorTwoFPEDParallel${suffix}.sh ComplexSquareRoot 0 1 0 1 1024 1024 0 0 0 0 0.0009765625 0.0009765625 expr_ComplexSquareRoot 0_1_0_1_1024_1024 ${target} +# ./detectErrorThreeFPEDParallel${suffix}.sh doppler1 -30 50 -100 100 20 20000 256 256 256 0 0 0 -30 -100 20 0.3125 0.78125 78.046875 expr_doppler1 -30_50_-100_100_20_20000_256_256_256 ${target} +# ./detectErrorThreeFPEDParallel${suffix}.sh doppler2 -40 60 -125 125 15 25000 256 256 256 0 0 0 -40 -125 15 0.390625 0.9765625 97.59765625 expr_doppler2 -40_60_-125_125_15_25000_256_256_256 ${target} +# ./detectErrorThreeFPEDParallel${suffix}.sh doppler3 -50 30 -30 120 320 20300 256 256 256 0 0 0 -50 -30 320 0.3125 0.5859375 78.046875 expr_doppler3 -50_30_-30_120_320_20300_256_256_256 ${target} +# ./detectErrorTwoFPEDParallel${suffix}.sh i4 0.1 10 -5 5 1024 1024 0 0 0.1 -5 0.00966796875 0.009765625 expr_i4 0.1_10_-5_5_1024_1024 ${target} +# ./detectErrorTwoFPEDParallel${suffix}.sh i6 0.1 10 -5 5 1024 1024 0 0 0.1 -5 0.00966796875 0.009765625 expr_i6 0.1_10_-5_5_1024_1024 ${target} # ./detectErrorTwoFPEDParallel${suffix}.sh NMSEexample33 0 100 0 100 1024 1024 0 0 0 0 0.09765625 0.09765625 expr_NMSEexample33 0_100_0_100_1024_1024 ${target} # ./detectErrorTwoFPEDParallel${suffix}.sh NMSEproblem332 0 100 0 100 1024 1024 0 0 0 0 0.09765625 0.09765625 expr_NMSEproblem332 0_100_0_100_1024_1024 ${target} # ./detectErrorTwoFPEDParallel${suffix}.sh NMSEproblem335 0 100 0 100 1024 1024 0 0 0 0 0.09765625 0.09765625 expr_NMSEproblem335 0_100_0_100_1024_1024 ${target} # ./detectErrorTwoFPEDParallel${suffix}.sh NMSEsection35 0 1 0 1 1024 1024 0 0 0 0 0.0009765625 0.0009765625 expr_NMSEsection35 0_1_0_1_1024_1024 ${target} - -# problem error are too big -# ./detectErrorOneFPEDParallel${suffix}.sh intro_example 0 999 500000 0 0 0.001998 expr_intro_example 0_999_500000 ${target} -# ./detectErrorOneFPEDParallel${suffix}.sh sqrt_add 1 1000 500000 0 1 0.001998 expr_sqrt_add 1_1000_500000 ${target} # ./detectErrorTwoFPEDParallel${suffix}.sh polarToCarthesianX 1 10 0 360 1024 1024 0 0 1 0 0.0087890625 0.3515625 expr_polarToCarthesianX 1_10_0_360_1024_1024 ${target} -# ./detectErrorThreeFPEDParallel${suffix}.sh doppler1 -30 50 -100 100 20 20000 256 256 256 0 0 0 -30 -100 20 0.3125 0.78125 78.046875 expr_doppler1 -30_50_-100_100_20_20000_256_256_256 ${target} -# ./detectErrorThreeFPEDParallel${suffix}.sh doppler2 -40 60 -125 125 15 25000 256 256 256 0 0 0 -40 -125 15 0.390625 0.9765625 97.59765625 expr_doppler2 -40_60_-125_125_15_25000_256_256_256 ${target} -# ./detectErrorThreeFPEDParallel${suffix}.sh doppler3 -50 30 -30 120 320 20300 256 256 256 0 0 0 -50 -30 320 0.3125 0.5859375 78.046875 expr_doppler3 -50_30_-30_120_320_20300_256_256_256 ${target} # problem compile error -# ./detectErrorTwoFPEDParallel${suffix}.sh i4 0.1 10 -5 5 1024 1024 0 0 0.1 -5 0.00966796875 0.009765625 expr_i4 0.1_10_-5_5_1024_1024 ${target} -# ./detectErrorTwoFPEDParallel${suffix}.sh i6 0.1 10 -5 5 1024 1024 0 0 0.1 -5 0.00966796875 0.009765625 expr_i6 0.1_10_-5_5_1024_1024 ${target} # TODO: NO FILE # ./detectErrorOneFPEDParallel${suffix}.sh exp1x_log 0.01 0.5 500000 0 0.01 9.8e-07 expr_exp1x_log 0.01_0.5_500000 ${target} -# ./detectErrorOneFPEDParallel${suffix}.sh NMSEexample310 -1 1 500000 0 -1 4e-06 expr_NMSEexample310 -1_1_500000 ${target} # ./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem334 0.01 100 500000 0 0.01 0.00019998 expr_NMSEproblem334 0.01_100_500000 ${target} # ./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem345 0.01 100 500000 0 0.01 0.00019998 expr_NMSEproblem345 0.01_100_500000 ${target} # ./detectErrorTwoFPEDParallel${suffix}.sh hypot32 1 100 1 100 1024 1024 0 0 1 1 0.0966796875 0.0966796875 expr_hypot32 1_100_1_100_1024_1024 ${target} diff --git a/srcTest/doppler1/expr_doppler1_NumOpt.cpp b/srcTest/doppler1/expr_doppler1_NumOpt.cpp index 441b19c..e5c4011 100644 --- a/srcTest/doppler1/expr_doppler1_NumOpt.cpp +++ b/srcTest/doppler1/expr_doppler1_NumOpt.cpp @@ -34,7 +34,8 @@ double expr_doppler1_CPP(double T, double u, double v) return r_real.as_double(); } - return r; + r_real = ((-(REAL(1657.0)/REAL(5.0)+REAL(3.0)/REAL(5.0)*T_real))*v_real)/(((REAL(1657.0)/REAL(5.0)+REAL(3.0)/REAL(5.0)*T_real)+u_real)*((REAL(1657.0)/REAL(5.0)+REAL(3.0)/REAL(5.0)*T_real)+u_real)); + return r_real.as_double(); } extern "C" diff --git a/srcTest/doppler2/expr_doppler2_NumOpt.cpp b/srcTest/doppler2/expr_doppler2_NumOpt.cpp index 789454d..b2d8e3a 100644 --- a/srcTest/doppler2/expr_doppler2_NumOpt.cpp +++ b/srcTest/doppler2/expr_doppler2_NumOpt.cpp @@ -34,7 +34,8 @@ double expr_doppler2_CPP(double T, double u, double v) return r_real.as_double(); } - return r; + r_real = ((-(REAL(1657.0)/REAL(5.0)+REAL(3.0)/REAL(5.0)*T_real))*v_real)/(((REAL(1657.0)/REAL(5.0)+REAL(3.0)/REAL(5.0)*T_real)+u_real)*((REAL(1657.0)/REAL(5.0)+REAL(3.0)/REAL(5.0)*T_real)+u_real)); + return r_real.as_double(); } extern "C" diff --git a/srcTest/doppler3/expr_doppler3_NumOpt.cpp b/srcTest/doppler3/expr_doppler3_NumOpt.cpp index 503cacb..abc4115 100644 --- a/srcTest/doppler3/expr_doppler3_NumOpt.cpp +++ b/srcTest/doppler3/expr_doppler3_NumOpt.cpp @@ -34,7 +34,8 @@ double expr_doppler3_CPP(double T, double u, double v) return r_real.as_double(); } - return r; + r_real = ((-(REAL(1657.0)/REAL(5.0)+REAL(3.0)/REAL(5.0)*T_real))*v_real)/(((REAL(1657.0)/REAL(5.0)+REAL(3.0)/REAL(5.0)*T_real)+u_real)*((REAL(1657.0)/REAL(5.0)+REAL(3.0)/REAL(5.0)*T_real)+u_real)); + return r_real.as_double(); } extern "C" diff --git a/srcTest/i4/expr_i4_NumOpt.cpp b/srcTest/i4/expr_i4_NumOpt.cpp index 1c49954..a566598 100644 --- a/srcTest/i4/expr_i4_NumOpt.cpp +++ b/srcTest/i4/expr_i4_NumOpt.cpp @@ -24,7 +24,7 @@ double expr_i4_CPP(double x, double y) REAL r_real; if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)) { - r_real = sqrtf(x_real+y_real*y_real); + r_real = iRRAM::sqrt(x_real+y_real*y_real); return r_real.as_double(); } diff --git a/srcTest/i6/expr_i6_NumOpt.cpp b/srcTest/i6/expr_i6_NumOpt.cpp index 1874fd4..c3cd7d5 100644 --- a/srcTest/i6/expr_i6_NumOpt.cpp +++ b/srcTest/i6/expr_i6_NumOpt.cpp @@ -379,7 +379,7 @@ double expr_i6_CPP(double x, double y) } if((0.1<=x)&&(x<=10)&&(-5<=y)&&(y<=5)) { - r_real = sinf(x_real*y_real); + r_real = iRRAM::sin(x_real*y_real); return r_real.as_double(); } diff --git a/srcTest/intro_example/expr_intro_example_NumOpt.cpp b/srcTest/intro_example/expr_intro_example_NumOpt.cpp index 4a4e35c..1e01f54 100644 --- a/srcTest/intro_example/expr_intro_example_NumOpt.cpp +++ b/srcTest/intro_example/expr_intro_example_NumOpt.cpp @@ -31,8 +31,8 @@ double expr_intro_example_CPP(double x) r_real = x_real/(x_real+1); return r_real.as_double(); } - - return r; + r_real = x_real/(x_real+1); + return r_real.as_double(); } extern "C" diff --git a/srcTest/sqrt_add/expr_sqrt_add_NumOpt.cpp b/srcTest/sqrt_add/expr_sqrt_add_NumOpt.cpp index 7403a78..d7af5e7 100644 --- a/srcTest/sqrt_add/expr_sqrt_add_NumOpt.cpp +++ b/srcTest/sqrt_add/expr_sqrt_add_NumOpt.cpp @@ -32,7 +32,8 @@ double expr_sqrt_add_CPP(double x) return r_real.as_double(); } - return r; + r_real = 1/(iRRAM::sqrt((REAL)x_real + 1) +iRRAM::sqrt((REAL)x_real)); + return r_real.as_double(); } extern "C" diff --git a/srcTest/test1paramFPEDParallelNumOpt.cpp b/srcTest/test1paramFPEDParallelNumOpt.cpp index 9ab42fd..5a45c9c 100644 --- a/srcTest/test1paramFPEDParallelNumOpt.cpp +++ b/srcTest/test1paramFPEDParallelNumOpt.cpp @@ -104,6 +104,9 @@ struct errorInfo test1FPEDparamParallel(unsigned long int testNumX0, const char* // x0 = ii0.d; for(i0 = i0StartLocal; i0 <= i0EndLocal; i0++) { x0 = x0startOriginInterval + stepX0 * i0; + if(x0 == -1 || x0 == 1 || x0 == 0) { // for NMSEproblem343, NMSEexample310 + continue; + } computeResult1param(x0, mpfrResult); computeOrcle1param(x0, mpfrOrcle); #ifdef SINGLE diff --git a/srcTest/test2paramFPEDParallelNumOpt.cpp b/srcTest/test2paramFPEDParallelNumOpt.cpp index 42db60a..e371cd7 100644 --- a/srcTest/test2paramFPEDParallelNumOpt.cpp +++ b/srcTest/test2paramFPEDParallelNumOpt.cpp @@ -43,6 +43,7 @@ struct errorInfo #define TESTNUMX1 1024 // #define FP // #define DEBUG +// #define SINGLE // for i4, i6, hypot32 #ifndef ERRFILE #define ERRFILE 0 #endif -- Gitee From 4ed5159828050148136dc64a90b1359f55577354 Mon Sep 17 00:00:00 2001 From: hjwLab Date: Wed, 12 Apr 2023 23:25:30 +0800 Subject: [PATCH 14/32] add fpbench exp1x_log --- detectErrorAll.sh | 2 +- script/input/exp1x_log_opt.cc | 49 +++++++++++++++++++++ script/replaceAll.sh | 1 + srcTest/exp1x_log/expr_exp1x_log_NumOpt.cpp | 44 ++++++++++++++++++ 4 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 script/input/exp1x_log_opt.cc create mode 100644 srcTest/exp1x_log/expr_exp1x_log_NumOpt.cpp diff --git a/detectErrorAll.sh b/detectErrorAll.sh index 17f0b5a..19e1027 100755 --- a/detectErrorAll.sh +++ b/detectErrorAll.sh @@ -18,6 +18,7 @@ fi # DONE # ./detectErrorOneFPEDParallel${suffix}.sh Bsplines3 0 1 500000 0 0 2e-06 expr_Bsplines3 0_1_500000 ${target} # ./detectErrorOneFPEDParallel${suffix}.sh exp1x 0.01 0.5 500000 0 0.01 9.8e-07 expr_exp1x 0.01_0.5_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh exp1x_log 0.01 0.5 500000 0 0.01 9.8e-07 expr_exp1x_log 0.01_0.5_500000 ${target} # ./detectErrorOneFPEDParallel${suffix}.sh intro_example 0 999 500000 0 0 0.001998 expr_intro_example 0_999_500000 ${target} # ./detectErrorOneFPEDParallel${suffix}.sh logexp -8 8 500000 0 -8 3.2e-05 expr_logexp -8_8_500000 ${target} # ./detectErrorOneFPEDParallel${suffix}.sh NMSEexample31 0.01 100 500000 0 0.01 0.00019998 expr_NMSEexample31 0.01_100_500000 ${target} @@ -60,7 +61,6 @@ fi # problem compile error # TODO: NO FILE -# ./detectErrorOneFPEDParallel${suffix}.sh exp1x_log 0.01 0.5 500000 0 0.01 9.8e-07 expr_exp1x_log 0.01_0.5_500000 ${target} # ./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem334 0.01 100 500000 0 0.01 0.00019998 expr_NMSEproblem334 0.01_100_500000 ${target} # ./detectErrorOneFPEDParallel${suffix}.sh NMSEproblem345 0.01 100 500000 0 0.01 0.00019998 expr_NMSEproblem345 0.01_100_500000 ${target} # ./detectErrorTwoFPEDParallel${suffix}.sh hypot32 1 100 1 100 1024 1024 0 0 1 1 0.0966796875 0.0966796875 expr_hypot32 1_100_1_100_1024_1024 ${target} diff --git a/script/input/exp1x_log_opt.cc b/script/input/exp1x_log_opt.cc new file mode 100644 index 0000000..c1f9619 --- /dev/null +++ b/script/input/exp1x_log_opt.cc @@ -0,0 +1,49 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.01<=x)&&(x<=0.5)&&(0.010023301815109261<=x)&&(x<=0.4988482364557297)) { + r = (exp(x) - 1)/log(exp(x)); + return r; + } + + if((0.01<=x)&&(x<=0.5)) { + r_real = (iRRAM::exp((REAL)x_real) - 1)/iRRAM::log((REAL)iRRAM::exp((REAL)x_real)); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/replaceAll.sh b/script/replaceAll.sh index db1fb65..a22aedc 100644 --- a/script/replaceAll.sh +++ b/script/replaceAll.sh @@ -3,6 +3,7 @@ ./replace.sh doppler1 ./replace.sh doppler2 ./replace.sh doppler3 +./replace.sh exp1x_log ./replace.sh i4 ./replace.sh i6 ./replace.sh intro_example diff --git a/srcTest/exp1x_log/expr_exp1x_log_NumOpt.cpp b/srcTest/exp1x_log/expr_exp1x_log_NumOpt.cpp new file mode 100644 index 0000000..c4ddb7d --- /dev/null +++ b/srcTest/exp1x_log/expr_exp1x_log_NumOpt.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_exp1x_log_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((0.01<=x)&&(x<=0.5)&&(0.010023301815109261<=x)&&(x<=0.4988482364557297)) { + r = (exp(x) - 1)/log(exp(x)); + return r; + } + + if((0.01<=x)&&(x<=0.5)) { + r_real = (iRRAM::exp((REAL)x_real) - 1)/iRRAM::log((REAL)iRRAM::exp((REAL)x_real)); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_exp1x_log_NumOpt(double x) + { + return expr_exp1x_log_CPP(x); + } +} \ No newline at end of file -- Gitee From 865bd86cc013c031a363dc421054ad93ff8d8286 Mon Sep 17 00:00:00 2001 From: hjwLab Date: Wed, 12 Apr 2023 23:58:17 +0800 Subject: [PATCH 15/32] update benchmark's interval --- benchMarkInterval.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/benchMarkInterval.txt b/benchMarkInterval.txt index 7dcf73b..c87021f 100644 --- a/benchMarkInterval.txt +++ b/benchMarkInterval.txt @@ -90,11 +90,11 @@ 0.00001 10 0 0.0001 0.0001 10 -0 10 -0 10 +1 10 +0 1 0 100 0 100 --2 2 --2 2 +-2 0.75 +0.75 2 1 9 1 9 1 9 1 9 1 9 1 9 \ No newline at end of file -- Gitee From 87794919d2cd79015dfe74225eade61f4fc8cb3b Mon Sep 17 00:00:00 2001 From: hjwLab Date: Wed, 12 Apr 2023 23:58:28 +0800 Subject: [PATCH 16/32] update gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 5927ad7..3b424da 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,7 @@ build/ srcGen/ libs/ +script/output/ main *.txt __pycache__/ -- Gitee From ee3509411a76205cde10a1faff0d7718e3852c5d Mon Sep 17 00:00:00 2001 From: hjwLab Date: Thu, 13 Apr 2023 00:26:19 +0800 Subject: [PATCH 17/32] Correcting the calculation of numIntervalsBefore --- include/basic.hpp | 18 +++++++++++- include/tools.hpp | 18 ++---------- src/basic.cpp | 55 +++++++++++++++++++++++++++++++++++- src/devideUpEdgeData.cpp | 6 ++++ src/main.cpp | 60 +++++----------------------------------- src/tools.cpp | 13 +++++++-- 6 files changed, 96 insertions(+), 74 deletions(-) diff --git a/include/basic.hpp b/include/basic.hpp index c384787..eeff8cc 100644 --- a/include/basic.hpp +++ b/include/basic.hpp @@ -26,6 +26,21 @@ extern const char callLevelChar; extern const char callCountChar; extern const size_t promtTimes; +class exprInfo +{ +public: + double start; + double end; + vector intervals; + string suffix; + string exprStr; + double error; + double aveError = -1; + double maxError = -1; + double performance = -1; + size_t rewriteID; +}; + //===----------------------------------------------------------------------===// // Abstract Syntax Tree (aka Parse Tree) //===----------------------------------------------------------------------===// @@ -244,8 +259,9 @@ vector> combination(const int num, const vector& indexs); size_t combination(size_t k, size_t n); -void write_to_file(const string &uniqueLabel, const string &exprOriginBest, const std::vector &data, const std::string &filename); +void write_to_file(const string &uniqueLabel, const string &exprOriginBest, const vector &numIntervalsSoloBefore, const vector &numIntervalsSoloAfter, const std::vector &data, const std::string &filename); +void write_to_file_wrapper(string uniqueLabel, string exprOriginBest, int dimension, int numIntervalsBefore, double numOfIntervals, const vector &numIntervalsSoloBefore, const vector &numIntervalsSoloAfter, int numOfExprs, vector thresholds, const exprInfo &originExprInfo, const exprInfo &herbieExprInfo, const exprInfo &finalInfo, double originPerformance, double elapsed_seconds, double init_seconds, double matlab_seconds, double regime_seconds, double rewrite_seconds, double final_seconds, double matlabKernelTime); // } // end anonymous namespace #endif \ No newline at end of file diff --git a/include/tools.hpp b/include/tools.hpp index 3da62f3..0f68d97 100644 --- a/include/tools.hpp +++ b/include/tools.hpp @@ -3,25 +3,11 @@ #include #include +#include "basic.hpp" using std::string; using std::vector; -class exprInfo -{ -public: - double start; - double end; - vector intervals; - string suffix; - string exprStr; - double error; - double aveError = -1; - double maxError = -1; - double performance = -1; - size_t rewriteID; -}; - string getUniqueLabel(); vector getIntervals(string interval, const char *split); @@ -48,7 +34,7 @@ vector geneIntervalData(vector upEdgeFileNames, string uniqueLab vector> getIntervalData(string filename); -vector> getIntervalData(vector upEdgeFileNames, vector &thresholds, vector &intervals, int &numIntervalsBefore); +vector> getIntervalData(vector upEdgeFileNames, vector &thresholds, vector &intervals, int &numIntervalsBefore, vector &numIntervalsSoloBefore, vector &numIntervalsSoloAfter); vector rewrite(string exprStr, string uniqueLabel, vector> &intervalData, int &numOfExprs, const vector &intervals); diff --git a/src/basic.cpp b/src/basic.cpp index 417766b..64f2f5d 100644 --- a/src/basic.cpp +++ b/src/basic.cpp @@ -6,6 +6,7 @@ #include #include #include +#include using std::cerr; using std::cout; @@ -741,7 +742,7 @@ size_t combination(size_t k, size_t n) return factorial(n) / (factorial(k) * factorial(n - k)); } -void write_to_file(const string &uniqueLabel, const string &exprOriginBest, const std::vector &data, const std::string &filename) +void write_to_file(const string &uniqueLabel, const string &exprOriginBest, const vector &numIntervalsSoloBefore, const vector &numIntervalsSoloAfter, const std::vector &data, const std::string &filename) { std::ofstream outputFile; outputFile.open(filename, std::ios::out | std::ios::app); @@ -750,6 +751,9 @@ void write_to_file(const string &uniqueLabel, const string &exprOriginBest, cons { outputFile << uniqueLabel << ", "; outputFile << exprOriginBest << ", "; + outputFile << fmt::format("\"{}\"", numIntervalsSoloBefore) << ", "; + outputFile << fmt::format("\"{}\"", numIntervalsSoloAfter) << ", "; + for (const auto &val : data) { if(int(val) - val == 0) @@ -767,3 +771,52 @@ void write_to_file(const string &uniqueLabel, const string &exprOriginBest, cons // std::cout << "Failed to open file!" << std::endl; // } } + +// write to file +void write_to_file_wrapper(string uniqueLabel, string exprOriginBest, int dimension, int numIntervalsBefore, double numOfIntervals, const vector &numIntervalsSoloBefore, const vector &numIntervalsSoloAfter, int numOfExprs, vector thresholds, const exprInfo &originExprInfo, const exprInfo &herbieExprInfo, const exprInfo &finalInfo, double originPerformance, double elapsed_seconds, double init_seconds, double matlab_seconds, double regime_seconds, double rewrite_seconds, double final_seconds, double matlabKernelTime) +{ + vector summaryData; + summaryData.push_back(dimension); + summaryData.push_back(numIntervalsBefore); + summaryData.push_back(numOfIntervals); + summaryData.push_back(double(numOfExprs)); + if (thresholds.size() == 1) + { + summaryData.push_back(thresholds.at(0)); + summaryData.push_back(-1); + summaryData.push_back(-1); + } + else if (thresholds.size() == 2) + { + summaryData.push_back(thresholds.at(0)); + summaryData.push_back(thresholds.at(1)); + summaryData.push_back(-1); + } + else if (thresholds.size() == 3) + { + summaryData.push_back(thresholds.at(0)); + summaryData.push_back(thresholds.at(1)); + summaryData.push_back(thresholds.at(2)); + } + else + { + fprintf(stderr, "ERROR: we can not support %ld demision now.\n", thresholds.size()); + exit(EXIT_FAILURE); + } + summaryData.push_back(originExprInfo.aveError); + summaryData.push_back(originExprInfo.maxError); + summaryData.push_back(herbieExprInfo.aveError); + summaryData.push_back(herbieExprInfo.maxError); + summaryData.push_back(finalInfo.aveError); + summaryData.push_back(finalInfo.maxError); + summaryData.push_back(originPerformance); + summaryData.push_back(finalInfo.performance); + summaryData.push_back(elapsed_seconds); + summaryData.push_back(init_seconds); + summaryData.push_back(matlab_seconds); + summaryData.push_back(regime_seconds); + summaryData.push_back(rewrite_seconds); + summaryData.push_back(final_seconds); + summaryData.push_back(matlabKernelTime); + write_to_file(uniqueLabel, exprOriginBest, numIntervalsSoloBefore, numIntervalsSoloAfter, summaryData, "runlog.csv"); +} diff --git a/src/devideUpEdgeData.cpp b/src/devideUpEdgeData.cpp index a0c3201..94041f7 100644 --- a/src/devideUpEdgeData.cpp +++ b/src/devideUpEdgeData.cpp @@ -339,6 +339,12 @@ vector devideUpEdgeData(string upEdgeFileName, double &threshold, int &n // Merge intervals that are close in distance. numIntervalsBefore = output_vector.size() / 2; + // fprintf(stderr, "output_vector: "); + // for(auto item : output_vector) + // { + // fprintf(stderr, "%f ", *item); + // } + // fprintf(stderr, "\n"); vector merge_vector; interval_merge(output_vector, merge_vector, thresholdCombine); // printRegime(merge_vector.size(), merge_vector, intervalFileName, "distanceTmp_afterCombine.txt", "widthTmp_afterCombine.txt"); diff --git a/src/main.cpp b/src/main.cpp index 5a84163..6c9968c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -89,55 +89,6 @@ map> benchmarkThresholds = { {"triangleSorted_2", {2, 2, 2}}, }; -// write to file -void write_to_file_wrapper(string uniqueLabel, string exprOriginBest, int dimension, int numIntervalsBefore, double numOfIntervals, int numOfExprs, vector thresholds, const exprInfo &originExprInfo, const exprInfo &herbieExprInfo, const exprInfo &finalInfo, double originPerformance, double elapsed_seconds, double init_seconds, double matlab_seconds, double regime_seconds, double rewrite_seconds, double final_seconds, double matlabKernelTime) -{ - vector summaryData; - summaryData.push_back(dimension); - summaryData.push_back(numIntervalsBefore); - summaryData.push_back(numOfIntervals); - summaryData.push_back(double(numOfExprs)); - if (thresholds.size() == 1) - { - summaryData.push_back(thresholds.at(0)); - summaryData.push_back(-1); - summaryData.push_back(-1); - } - else if (thresholds.size() == 2) - { - summaryData.push_back(thresholds.at(0)); - summaryData.push_back(thresholds.at(1)); - summaryData.push_back(-1); - } - else if (thresholds.size() == 3) - { - summaryData.push_back(thresholds.at(0)); - summaryData.push_back(thresholds.at(1)); - summaryData.push_back(thresholds.at(2)); - } - else - { - fprintf(stderr, "ERROR: we can not support %ld demision now.\n", thresholds.size()); - exit(EXIT_FAILURE); - } - summaryData.push_back(originExprInfo.aveError); - summaryData.push_back(originExprInfo.maxError); - summaryData.push_back(herbieExprInfo.aveError); - summaryData.push_back(herbieExprInfo.maxError); - summaryData.push_back(finalInfo.aveError); - summaryData.push_back(finalInfo.maxError); - summaryData.push_back(originPerformance); - summaryData.push_back(finalInfo.performance); - summaryData.push_back(elapsed_seconds); - summaryData.push_back(init_seconds); - summaryData.push_back(matlab_seconds); - summaryData.push_back(regime_seconds); - summaryData.push_back(rewrite_seconds); - summaryData.push_back(final_seconds); - summaryData.push_back(matlabKernelTime); - write_to_file(uniqueLabel, exprOriginBest, summaryData, "runlog.csv"); -} - //===----------------------------------------------------------------------===// // Main driver code. //===----------------------------------------------------------------------===// @@ -281,6 +232,8 @@ int main() auto &originExprInfo = initExprInfos.at(0); auto &herbieExprInfo = initExprInfos.at(1); auto &daisyExprInfo = initExprInfos.at(2); + vector numIntervalsSoloBefore; + vector numIntervalsSoloAfter; if (runAllFlag) { // the whole process if (!isBenchMark) @@ -370,7 +323,7 @@ int main() elapsed_seconds = timeEnd - timeStart; cout << BLUE << "the whole time: " << elapsed_seconds.count() << " s" << RESET << endl; - write_to_file_wrapper(uniqueLabel, exprOriginBest, dimension, numIntervalsBefore, numOfIntervals, numOfExprs, thresholds, originExprInfo, herbieExprInfo, finalInfo, originPerformance, elapsed_seconds.count(), init_seconds.count(), matlab_seconds.count(), regime_seconds.count(), rewrite_seconds.count(), final_seconds.count(), matlabKernelTime); + write_to_file_wrapper(uniqueLabel, exprOriginBest, dimension, numIntervalsBefore, numOfIntervals, numIntervalsSoloBefore, numIntervalsSoloAfter, numOfExprs, thresholds, originExprInfo, herbieExprInfo, finalInfo, originPerformance, elapsed_seconds.count(), init_seconds.count(), matlab_seconds.count(), regime_seconds.count(), rewrite_seconds.count(), final_seconds.count(), matlabKernelTime); fprintf(stderr, GREEN "ready> " RESET); continue; } @@ -421,8 +374,9 @@ int main() auto timeTmp2 = std::chrono::high_resolution_clock::now(); // matlab over matlab_seconds = timeTmp2 - timeTmp1; cout << BLUE << "regime time (matlab part): " << matlab_seconds.count() << " s" << RESET << endl; - - auto intervalData = getIntervalData(upEdgeFileNames, thresholds, intervals, numIntervalsBefore); + + auto intervalData = getIntervalData(upEdgeFileNames, thresholds, intervals, numIntervalsBefore, numIntervalsSoloBefore, numIntervalsSoloAfter); + fmt::print("numIntervalSoloBefore: {}, numIntervalSoloAfter: {}\n", numIntervalsSoloBefore, numIntervalsSoloAfter); // fmt::print("[INFO] main: thresholds {}\n", thresholds); numOfIntervals = intervalData.size(); fmt::print("after regime, we have {} intervals: {}\n", numOfIntervals, intervalData); @@ -504,7 +458,7 @@ int main() elapsed_seconds = timeEnd - timeStart; cout << BLUE << "the whole time: " << elapsed_seconds.count() << " s" << RESET << endl; - write_to_file_wrapper(uniqueLabel, exprOriginBest, dimension, numIntervalsBefore, numOfIntervals, numOfExprs, thresholds, originExprInfo, herbieExprInfo, finalInfo, originPerformance, elapsed_seconds.count(), init_seconds.count(), matlab_seconds.count(), regime_seconds.count(), rewrite_seconds.count(), final_seconds.count(), matlabKernelTime); + write_to_file_wrapper(uniqueLabel, exprOriginBest, dimension, numIntervalsBefore, numOfIntervals, numIntervalsSoloBefore, numIntervalsSoloAfter, numOfExprs, thresholds, originExprInfo, herbieExprInfo, finalInfo, originPerformance, elapsed_seconds.count(), init_seconds.count(), matlab_seconds.count(), regime_seconds.count(), rewrite_seconds.count(), final_seconds.count(), matlabKernelTime); fprintf(stderr, GREEN "ready> " RESET); } diff --git a/src/tools.cpp b/src/tools.cpp index 412a650..7132606 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -772,19 +772,26 @@ vector> getIntervalData(string filename) } // according to the corresponding upEdgeFile, generate intervalData for each dimension, and then combine all permutation of all dimensions. -vector> getIntervalData(vector upEdgeFileNames, vector &thresholds, vector &intervals, int &numIntervalsBefore) +vector> getIntervalData(vector upEdgeFileNames, vector &thresholds, vector &intervals, int &numIntervalsBefore, vector &numIntervalsSoloBefore, vector &numIntervalsSoloAfter) { vector> intervalDataMultiDim; int dimension = thresholds.size(); + int numIntervalsBeforeSolo = -1; + numIntervalsSoloBefore.clear(); + numIntervalsSoloAfter.clear(); + numIntervalsBefore = 1; for (int i = 0; i < dimension; i++) // iterate all the dimensions { // call devideUpEdgeData for each dimension: matlab upEdge ==> interval vector auto &upEdgeFileName = upEdgeFileNames.at(i); auto &threshold = thresholds.at(i); auto thresholdCombine = (intervals.at(2 * i + 1) - intervals.at(2 * i)) / 100; // thresholdCombine = 1% of the interval width at the target demision - auto intervalData1D = devideUpEdgeData(upEdgeFileName, threshold, numIntervalsBefore, thresholdCombine); - // fmt::print("thresholdCombine: {}, intervalData1D {}\n", thresholdCombine, intervalData1D); + auto intervalData1D = devideUpEdgeData(upEdgeFileName, threshold, numIntervalsBeforeSolo, thresholdCombine); + numIntervalsBefore = numIntervalsBefore * numIntervalsBeforeSolo; + // fmt::print("i = {}, numIntervalsBeforeSolo: {}, thresholdCombine: {}, intervalData1D {}\n", i, numIntervalsBeforeSolo, thresholdCombine, intervalData1D); intervalDataMultiDim.push_back(intervalData1D); + numIntervalsSoloBefore.push_back(numIntervalsBeforeSolo); + numIntervalsSoloAfter.push_back(intervalData1D.size() / 2); } // call permuteMultiVec to get all permutation auto results = permuteMultiVec(intervalDataMultiDim); -- Gitee From 53364afa8f8d375db8d6387f4c9639fd62e1e38e Mon Sep 17 00:00:00 2001 From: hjwLab Date: Thu, 13 Apr 2023 15:12:08 +0800 Subject: [PATCH 18/32] suppor 4 parameters' error detecting and sampling, and add a example benchmark for testing --- benchMark.txt | 3 +- benchMarkInterval.txt | 3 +- detectErrorFourFPEDParallel.sh | 110 ++++++++ sampleErrorFour.sh | 73 ++++++ src/basic.cpp | 9 +- src/geneCode.cpp | 2 + src/main.cpp | 60 +++-- src/tools.cpp | 52 +++- srcTest/sample4paramFPEDParallel.c | 387 +++++++++++++++++++++++++++++ srcTest/test4paramFPEDParallel.c | 327 ++++++++++++++++++++++++ 10 files changed, 995 insertions(+), 31 deletions(-) create mode 100755 detectErrorFourFPEDParallel.sh create mode 100755 sampleErrorFour.sh create mode 100644 srcTest/sample4paramFPEDParallel.c create mode 100644 srcTest/test4paramFPEDParallel.c diff --git a/benchMark.txt b/benchMark.txt index 17ccd1f..f074375 100644 --- a/benchMark.txt +++ b/benchMark.txt @@ -97,4 +97,5 @@ gustafsonExample_2 (exp(((fabs((x - sqrt(((x * x) + 1.0)))) - (1.0 / (x + sqrt(( smartRoot_1 (c * 2.0) / (-3.5 - sqrt(((3.5 * 3.5) - ((3.0 * c) * 4.0)))) smartRoot_2 (-3.5 + sqrt(((3.5 * 3.5) - ((3.0 * c) * 4.0)))) / (3.0 * 2.0) triangleSorted_1 sqrt(((((c + (b + a)) * (a - (c - b))) * (a + (c - b))) * (c + (b - a)))) / 4.0 -triangleSorted_2 sqrt(((((c + (a + b)) * (b - (c - a))) * (b + (c - a))) * (c + (a - b)))) / 4.0; \ No newline at end of file +triangleSorted_2 sqrt(((((c + (a + b)) * (b - (c - a))) * (b + (c - a))) * (c + (a - b)))) / 4.0; +example x0+x1+x2+x3 \ No newline at end of file diff --git a/benchMarkInterval.txt b/benchMarkInterval.txt index c87021f..a889172 100644 --- a/benchMarkInterval.txt +++ b/benchMarkInterval.txt @@ -97,4 +97,5 @@ -2 0.75 0.75 2 1 9 1 9 1 9 -1 9 1 9 1 9 \ No newline at end of file +1 9 1 9 1 9 +0 1 0 1 0 1 0 1 \ No newline at end of file diff --git a/detectErrorFourFPEDParallel.sh b/detectErrorFourFPEDParallel.sh new file mode 100755 index 0000000..234ffca --- /dev/null +++ b/detectErrorFourFPEDParallel.sh @@ -0,0 +1,110 @@ +# Usage: ./detectErrorFourParallel.sh ${uniqueLabel} ${x0Start} ${x0End} ${x1Start} ${x1End} ${x2Start} ${x2End} ${x0Size} ${x1Size} ${x2Size} ${prefix} ${middle} ${suffix} ${errfile} +# set -x + +path=`pwd` +cd ${path} +CC=mpicc + +uniqueLabel=${1} # unique number +x0Start=${2} +x0End=${3} +x1Start=${4} +x1End=${5} +x2Start=${6} +x2End=${7} +x3Start=${8} +x3End=${9} +if [ $# -eq 29 ]; then + x0Size=${10} + x1Size=${11} + x2Size=${12} + x3Size=${13} + x0startNowIdx=${14} # the index of the start point of the current interval. + x1startNowIdx=${15} + x2startNowIdx=${16} + x3startNowIdx=${17} + x0startOriginInterval=${18} # the value of the start point of the origin interval. + x1startOriginInterval=${19} + x2startOriginInterval=${20} + x3startOriginInterval=${21} + stepX0=${22} # the step for sampling points. + stepX1=${23} + stepX2=${24} + stepX3=${25} + prefix=${26} # expr_${uniqueLabel}. Eg: expr_20221030155958 + middle=${27} # intervalsInfo_sizes. Eg: 3.8_7.8_-4.5_-0.3_0.4_0.9_256_256_256 + suffix=${28} # different version. Eg: herbie daisy origin temp_0_3 final + errfile=${29} # 1 or 0: TRUE or False +elif [ $# -eq 28 ]; then + x0Size=${10} + x1Size=${11} + x2Size=${12} + x3Size=${13} + x0startNowIdx=${14} # the index of the start point of the current interval. + x1startNowIdx=${15} + x2startNowIdx=${16} + x3startNowIdx=${17} + x0startOriginInterval=${18} # the value of the start point of the origin interval. + x1startOriginInterval=${19} + x2startOriginInterval=${20} + x3startOriginInterval=${21} + stepX0=${22} # the step for sampling points. + stepX1=${23} + stepX2=${24} + stepX3=${25} + prefix=${26} # expr_${uniqueLabel}. Eg: expr_20221030155958 + middle=${27} # intervalsInfo_sizes. Eg: 3.8_7.8_-4.5_-0.3_0.4_0.9_256_256_256 + suffix=${28} # different version. Eg: herbie daisy origin temp_0_3 final + errfile=0 # 1 or 0: TRUE or False +elif [ $# -eq 24 ]; then + x0Size=64 + x1Size=64 + x2Size=64 + x3Size=64 + x0startNowIdx=${10} # the index of the start point of the current interval. + x1startNowIdx=${11} + x2startNowIdx=${12} + x3startNowIdx=${13} + x0startOriginInterval=${14} # the value of the start point of the origin interval. + x1startOriginInterval=${15} + x2startOriginInterval=${16} + x3startOriginInterval=${17} + stepX0=${18} # the step for sampling points. + stepX1=${19} + stepX2=${20} + stepX3=${21} + prefix=${22} # expr_${uniqueLabel}. Eg: expr_20221030155958 + middle=${23} # intervalsInfo_sizes. Eg: 3.8_7.8_-4.5_-0.3_0.4_0.9_256_256_256 + suffix=${24} # different version. Eg: herbie daisy origin temp_0_3 final + errfile=0 # 1 or 0: TRUE or False +else + echo "detectErrorFourParallel: Invalid input parameters" + exit +fi +testFileName=test4paramFPEDParallel +numProcs=32 + +echo "Detecting error: ${uniqueLabel} ${x0Start} ${x0End} ${x1Start} ${x1End} ${x2Start} ${x2End} ${x3End} ${x3Start} ${x0Size} ${x1Size} ${x2Size} ${x3Size} ${prefix} ${middle} ${suffix} ${errfile}" +directory="./srcTest"/${uniqueLabel} +sourceFile=${prefix}_${suffix} +fileNameKernel=${prefix}__${middle}_${suffix} + +# echo "${CC} ${testFileName}.c ${sourceFile}.c ${prefix}_mpfr.c computeULP.c -IincludeTEST -DEXPRESSION=${prefix}_ -DSUFFIX=${suffix} -lmpfr -lm -O3 -o ${testFileName}.exe" +${CC} ./srcTest/${testFileName}.c ${directory}/${sourceFile}.c ${directory}/${prefix}_mpfr.c ./srcTest/computeULP.c -IincludeTEST -IincludeDD -DEXPRESSION=${prefix}_ -DSUFFIX=${suffix} -DERRFILE=${errfile} -Llibs -lTGen -lmpfr -lm -lqd -o ${testFileName}.exe +# echo "mpirun -n ${numProcs} ./${testFileName}.exe ${x0Start} ${x0End} ${x1Start} ${x1End} ${x2Start} ${x2End} ${x0Size} ${x1Size} ${x2Size} ${fileNameKernel}" +mpirun -n ${numProcs} ./${testFileName}.exe ${x0Start} ${x0End} ${x1Start} ${x1End} ${x2Start} ${x2End} ${x3End} ${x3Start} ${x0Size} ${x1Size} ${x2Size} ${x3Size} ${x0startNowIdx} ${x1startNowIdx} ${x2startNowIdx} ${x3startNowIdx} ${x0startOriginInterval} ${x1startOriginInterval} ${x2startOriginInterval} ${x3startOriginInterval} ${stepX0} ${stepX1} ${stepX2} ${stepX3} ${fileNameKernel} ${uniqueLabel} +rm ${testFileName}.exe + +# combine files +if [ ${errfile} -eq 1 ]; then + cd ./outputs/${uniqueLabel} + findWord="${fileNameKernel}_sample_*.txt" + # echo "For suffix = ${suffix}, Find and combine by shell command cat: ${findWord}" + find . -name "${findWord}" | sort -h | xargs cat > sample_${uniqueLabel}_${suffix}.txt + # echo "sample file: `pwd`/sample_${uniqueLabel}_${suffix}.txt" + rm ${findWord} + cd - > /dev/null +fi + +echo "end detecting ${uniqueLabel}" +echo diff --git a/sampleErrorFour.sh b/sampleErrorFour.sh new file mode 100755 index 0000000..e0a3e41 --- /dev/null +++ b/sampleErrorFour.sh @@ -0,0 +1,73 @@ +#!/bin/bash +# Usage: ./sampleTwoFPEDParallel.sh ${uniqueLabel} ${x0Start} ${x0End} ${x1Start} ${x1End} ${x0Size} ${x1Size} ${prefix} ${middle} ${suffix} +# set -x + +path=`pwd` +cd ${path} +CC=mpicc + +uniqueLabel=${1} # unique number +x0Start=${2} +x0End=${3} +x1Start=${4} +x1End=${5} +x2Start=${6} +x2End=${7} +x3Start=${8} +x3End=${9} + +if [ $# -eq 14 ]; then + drawNum=${10} + findMaxNum=${11} + prefix=${12} # expr_${uniqueLabel}. Eg: expr_20221030155958 + middle=${13} # intervalsInfo_sizes. Eg: 3.8_7.8_-4.5_-0.3_0.4_0.9_256_256_256 + suffix=${14} # different version. Eg: herbie daisy origin temp_0_3 final +elif [ $# -eq 10 ]; then + drawNum=512 + findMaxNum=32 + prefix=${10} + middle=${11} + suffix=${12} +else + echo "sampleFourFPEDParallel: Invalid input parameters" + exit +fi + +testFileName=sample4paramFPEDParallel +numProcs=32 + +# echo "sampling: ${uniqueLabel} ${x0Start} ${x0End} ${x1Start} ${x1End} ${x2Start} ${x2End} ${drawNum} ${findMaxNum} ${prefix} ${middle} ${suffix} ${errfile}" +directory="./srcTest"/${uniqueLabel} +sourceFile=${prefix}_${suffix} +fileNameKernel=${prefix}__${middle}_${suffix} + +${CC} ./srcTest/${testFileName}.c ${directory}/${sourceFile}.c ${directory}/${prefix}_mpfr.c ./srcTest/computeULP.c -IincludeTEST -IincludeDD -DEXPRESSION=${prefix}_ -DSUFFIX=${suffix} -Llibs -lTGen -lmpfr -lm -lqd -o ${testFileName}.exe +mpirun -n ${numProcs} ./${testFileName}.exe ${x0Start} ${x0End} ${x1Start} ${x1End} ${x2Start} ${x2End} ${x3Start} ${x3End} ${drawNum} ${findMaxNum} ${fileNameKernel} ${uniqueLabel} +rm ${testFileName}.exe + +# combine files +cd ./outputs/${uniqueLabel} +## for sample_X +findWord="${fileNameKernel}_sample_X_*.txt" +# echo "For suffix = ${suffix}, Find and combine by shell command cat: ${findWord}" +find . -name "${findWord}" | sort -h | xargs cat > sample_${uniqueLabel}_${suffix}_X.txt +rm ${findWord} +## for sample_Y +findWord="${fileNameKernel}_sample_Y_*.txt" +# echo "For suffix = ${suffix}, Find and combine by shell command cat: ${findWord}" +find . -name "${findWord}" | sort -h | xargs cat > sample_${uniqueLabel}_${suffix}_Y.txt +rm ${findWord} +## for sample_Z +findWord="${fileNameKernel}_sample_Z_*.txt" +# echo "For suffix = ${suffix}, Find and combine by shell command cat: ${findWord}" +find . -name "${findWord}" | sort -h | xargs cat > sample_${uniqueLabel}_${suffix}_Z.txt +rm ${findWord} +## for sample_U +findWord="${fileNameKernel}_sample_U_*.txt" +# echo "For suffix = ${suffix}, Find and combine by shell command cat: ${findWord}" +find . -name "${findWord}" | sort -h | xargs cat > sample_${uniqueLabel}_${suffix}_U.txt +rm ${findWord} +cd - > /dev/null + +# echo "end sampling ${uniqueLabel}" +echo diff --git a/src/basic.cpp b/src/basic.cpp index 64f2f5d..c1f9e25 100644 --- a/src/basic.cpp +++ b/src/basic.cpp @@ -798,9 +798,16 @@ void write_to_file_wrapper(string uniqueLabel, string exprOriginBest, int dimens summaryData.push_back(thresholds.at(1)); summaryData.push_back(thresholds.at(2)); } + else if (thresholds.size() == 4) + { + summaryData.push_back(thresholds.at(0)); + summaryData.push_back(thresholds.at(1)); + summaryData.push_back(thresholds.at(2)); + summaryData.push_back(thresholds.at(3)); + } else { - fprintf(stderr, "ERROR: we can not support %ld demision now.\n", thresholds.size()); + fprintf(stderr, "ERROR: write_to_file_wrapper: we can not support %ld demision now.\n", thresholds.size()); exit(EXIT_FAILURE); } summaryData.push_back(originExprInfo.aveError); diff --git a/src/geneCode.cpp b/src/geneCode.cpp index a345279..e7638a9 100644 --- a/src/geneCode.cpp +++ b/src/geneCode.cpp @@ -300,6 +300,7 @@ string geneHerbieCode(string uniqueLabel) {"smartRoot_2", ""}, {"triangleSorted_1", ""}, {"triangleSorted_2", ""}, + {"example", "(x0+x1)+(x2+x3)"}, }; auto pos = benchmarkHerbie.find(uniqueLabel); @@ -386,6 +387,7 @@ string geneDaisyCode(string uniqueLabel) {"smartRoot_2", ""}, {"triangleSorted_1", ""}, {"triangleSorted_2", ""}, + {"example", "(x0+x2)+(x1+x3)"}, }; auto pos = benchmarkDaisy.find(uniqueLabel); diff --git a/src/main.cpp b/src/main.cpp index 6c9968c..3968f9f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -87,6 +87,7 @@ map> benchmarkThresholds = { {"smartRoot_2", {2}}, {"triangleSorted_1", {2, 2, 2}}, {"triangleSorted_2", {2, 2, 2}}, + {"example", {2, 2, 2, 2}}, }; //===----------------------------------------------------------------------===// @@ -199,6 +200,10 @@ int main() { sampleScale = 256; } + else if (dimension == 4) + { + sampleScale = 96; + } else { sampleScale = 10; @@ -252,25 +257,25 @@ int main() auto exprDaisy = geneDaisyCode(uniqueLabel); auto funcNameMpfr = geneMpfrCode(inputStr, uniqueLabel, vars); - if(exprOrigin != "") - { - originPerformance = testPerformance(uniqueLabel, "origin", intervals); - cout << "origin performance: " << originPerformance << "\n\n"; - } - else - { - fprintf(stderr, "exprOrigin is null!\n"); - exit(EXIT_FAILURE); - } - if(exprHerbie != "") - { - herbiePerformance = testPerformance(uniqueLabel, "herbie", intervals); - cout << "origin performance: " << originPerformance << "\n\n"; - } - else - { - fprintf(stderr, "exprHerbie is null!\n"); - } + // if(exprOrigin != "") + // { + // originPerformance = testPerformance(uniqueLabel, "origin", intervals); + // cout << "origin performance: " << originPerformance << "\n\n"; + // } + // else + // { + // fprintf(stderr, "exprOrigin is null!\n"); + // exit(EXIT_FAILURE); + // } + // if(exprHerbie != "") + // { + // herbiePerformance = testPerformance(uniqueLabel, "herbie", intervals); + // cout << "origin performance: " << originPerformance << "\n\n"; + // } + // else + // { + // fprintf(stderr, "exprHerbie is null!\n"); + // } vector suffixSet = {"origin"}; if (exprHerbie != "") @@ -363,6 +368,19 @@ int main() vector scales{512, 128}; // actually are drawNum and findMaxNum, so only need 2 numbers sampleError(uniqueLabel, exprOriginBest, intervals, scales); } + else if (dimension == 4) + { + suffixTmp = exprOriginBest + "_X"; + suffixTmps.push_back(suffixTmp); + suffixTmp = exprOriginBest + "_Y"; + suffixTmps.push_back(suffixTmp); + suffixTmp = exprOriginBest + "_Z"; + suffixTmps.push_back(suffixTmp); + suffixTmp = exprOriginBest + "_U"; + suffixTmps.push_back(suffixTmp); + vector scales{384, 96}; // actually are drawNum and findMaxNum, so only need 2 numbers + sampleError(uniqueLabel, exprOriginBest, intervals, scales); + } else { fprintf(stderr, "ERROR: main: we can not handle %d parameters (bigger than 3) now\n", dimension); @@ -411,8 +429,8 @@ int main() steps.push_back(step); } finalInfo = testError(uniqueLabel, "final", intervals, scales, startNowIdxs, startOriginIntervals, steps); - finalInfo.performance = testPerformance(uniqueLabel, "final", intervals); - cout << "performance: " << finalInfo.performance << "\n\n"; + // finalInfo.performance = testPerformance(uniqueLabel, "final", intervals); + // cout << "performance: " << finalInfo.performance << "\n\n"; cout << "=-=-=-=-=-=-=-=-=-=-=-=-= test final code's error and performance end =-=-=-=-=-=-=-=-=-=-=-=-=\n"; auto timeTmp5 = std::chrono::high_resolution_clock::now(); final_seconds = timeTmp5 - timeTmp4; diff --git a/src/tools.cpp b/src/tools.cpp index 7132606..c200026 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -364,7 +364,7 @@ exprInfo testError(string uniqueLabel, string suffix, const vector &inte exprInfo tempError; size_t size = scales.size(); - if (size < 4) + if (size < 5) { string prefix = "expr_" + uniqueLabel; vector params; @@ -409,7 +409,7 @@ exprInfo testError(string uniqueLabel, string suffix, const vector &inte namespace fs = std::filesystem; string currentPath = fs::current_path(); string testName = currentPath + "/outputs/" + uniqueLabel + "/" + fileNameKernel + "_error.txt"; // get the output of error detecting - string number[3] = {"One", "Two", "Three"}; + string number[4] = {"One", "Two", "Three", "Four"}; string scriptName = "./detectError" + number[size - 1] + "FPEDParallel.sh"; stringstream ss; ss << scriptName << " " << uniqueLabel; @@ -456,7 +456,7 @@ exprInfo testError(string uniqueLabel, string suffix, const vector &inte tempError.suffix = suffix; return tempError; } - else if (size == 4) + else if (size == 5) { tempError = testError(uniqueLabel, suffix, intervals); } @@ -473,7 +473,7 @@ void sampleError(string uniqueLabel, string suffix, const vector &interv exprInfo tempError; size_t size = intervals.size() / 2; - if (size < 4) + if (size < 5) { string prefix = "expr_" + uniqueLabel; vector params; @@ -503,7 +503,7 @@ void sampleError(string uniqueLabel, string suffix, const vector &interv namespace fs = std::filesystem; string currentPath = fs::current_path(); string testName = currentPath + "/outputs/" + uniqueLabel + "/" + fileNameKernel + "_error.txt"; // used to get the output of error detecting, not input parameters - string number[3] = {"One", "Two", "Three"}; + string number[4] = {"One", "Two", "Three", "Four"}; string scriptName = "./sampleError" + number[size - 1] + ".sh"; stringstream ss; ss << scriptName << " " << uniqueLabel; @@ -523,7 +523,7 @@ void sampleError(string uniqueLabel, string suffix, const vector &interv } else { - fprintf(stderr, "ERROR: testError: the intervalTmp's dimension is %ld, which we don't support now.\n", size); + fprintf(stderr, "ERROR: sampleError: the intervalTmp's dimension is %ld, which we don't support now.\n", size); exit(EXIT_FAILURE); } } @@ -794,6 +794,7 @@ vector> getIntervalData(vector upEdgeFileNames, vector> permuteMultiVec (vector> vec) { vector> suzu; size_t row = vec.size(); - if (row == 3) + if (row == 4) + { + vector tmp; + auto &row0 = vec.at(0); + auto &row1 = vec.at(1); + auto &row2 = vec.at(2); + auto &row3 = vec.at(3); + for(size_t i = 0; i < row0.size(); i += 2) + { + tmp.push_back(row0.at(i)); + tmp.push_back(row0.at(i + 1)); + for(size_t j = 0; j < row1.size(); j += 2) + { + tmp.push_back(row1.at(j)); + tmp.push_back(row1.at(j + 1)); + for(size_t k = 0; k < row2.size(); k += 2) + { + tmp.push_back(row2.at(k)); + tmp.push_back(row2.at(k + 1)); + for(size_t l = 0; l < row3.size(); l += 2) + { + tmp.push_back(row3.at(l)); + tmp.push_back(row3.at(l + 1)); + suzu.push_back(tmp); + tmp.pop_back(); + tmp.pop_back(); + } + tmp.pop_back(); + tmp.pop_back(); + } + tmp.pop_back(); + tmp.pop_back(); + } + tmp.pop_back(); + tmp.pop_back(); + } + } + else if (row == 3) { int rowSize = vec.size(); // 确定有几行 int columnSize = 2 * rowSize; // 新生成二维数组的列数 diff --git a/srcTest/sample4paramFPEDParallel.c b/srcTest/sample4paramFPEDParallel.c new file mode 100644 index 0000000..2435d82 --- /dev/null +++ b/srcTest/sample4paramFPEDParallel.c @@ -0,0 +1,387 @@ +#include "common.h" +#include "mpi.h" + +#ifndef SUFFIX +#define SUFFIX orgin +#endif +#ifndef EXPRESSION +#define EXPRESSION sum +#endif + +#define EXPRESSIONMINE ADDSUFFIX(EXPRESSION, SUFFIX) +#define SUFFIX1 mpfr +#define EXPRESSIONMPFR ADDSUFFIX(EXPRESSION, SUFFIX1) + +#define TESTNUMX 2048 +#define TESTNUMY 2048 + +double EXPRESSIONMPFR(double, double, double, double, mpfr_t); +double EXPRESSIONMINE(double, double, double, double); + +int computeOrcle4param(double x0, double x1, double x2, double x3, mpfr_t orcle) { + return EXPRESSIONMPFR(x0, x1, x2, x3, orcle); +} + +int computeResult4param(double x0, double x1, double x2, double x3, mpfr_t mpfrResult) { + int status = 1; + + double result = EXPRESSIONMINE(x0, x1, x2, x3); + mpfr_set_d(mpfrResult, result, MPFR_RNDN); + + return status; +} + +void sample4paramX(DL xStart, DL xEnd, DL yStart, DL yEnd, DL zStart, DL zEnd, DL uStart, DL uEnd, unsigned long int testNumX, unsigned long int testNumY, unsigned long int testNumZ, unsigned long int testNumU, const char* uniqueLabel, const char *fileNameKernel, int myid, int iStartLocal, int iEndLocal) +{ + DL i, j, k, l; + // DL maxInputX, maxInputY, maxInputZ, orcle, result; + int ii, jj, kk, ll; + double x, y, z, u, reUlp, maxReUlp, lenX, lenY, lenZ, lenU; + + // mpfr + mpfr_t mpfrOrcle, mpfrResult; + mpfr_inits2(PRECISION, mpfrOrcle, mpfrResult, (mpfr_ptr) 0); + + // write error data to file + char *directory = "outputs"; + char *suffix = "sample_X"; + char *fileNameSample; + FILE *f; + fileNameSample = (char *) calloc(strlen(directory) + strlen(uniqueLabel) + strlen(fileNameKernel) + strlen(suffix) + 128, sizeof(char)); + sprintf(fileNameSample, "%s/%s/%s_%s_%02d.txt", directory, uniqueLabel, fileNameKernel, suffix, myid); + // printf("%s\n", fileNameSample); + if ((f = fopen(fileNameSample, "w")) == NULL) { + printf("Error opening file %s.\n", fileNameSample); + exit(0); + } + + // loop boundary + lenX = xEnd.d - xStart.d; + lenY = yEnd.d - yStart.d; + lenZ = zEnd.d - zStart.d; + lenU = uEnd.d - uStart.d; + double stepX = lenX / (double)testNumX; + double stepY = lenY / (double)testNumY; + double stepZ = lenZ / (double)testNumZ; + double stepU = lenU / (double)testNumU; + + // Real number average + // 固定x值,求不同y值下的最大误差 + for(ii = iStartLocal; ii <= iEndLocal; ii++) { + i.d = xStart.d + stepX * ii; + x = i.d; + maxReUlp = 0; + for(jj = 0; jj <= testNumY; jj++) { + j.d = yStart.d + stepY * jj; + y = j.d; + for(kk = 0; kk <= testNumZ; kk++) { + k.d = zStart.d + stepZ * kk; + z = k.d; + for(ll = 0; ll <= testNumU; ll++) { + l.d = uStart.d + stepU * ll; + u = l.d; + computeResult4param(x, y, z, u, mpfrResult); + computeOrcle4param(x, y, z, u, mpfrOrcle); + // orcle.d = mpfr_get_d(mpfrOrcle, MPFR_RNDN); + // result.d = mpfr_get_d(mpfrResult, MPFR_RNDN); + #ifdef SINGLE + reUlp = computeUlpDiffF(mpfrOrcle, mpfrResult); + #else // compute Double ULP as default + reUlp = computeUlpDiff(mpfrOrcle, mpfrResult); + #endif + + if (reUlp > maxReUlp) { + // maxInputX = j; + maxReUlp = reUlp; + } + } + } + } + fprintf(f, "%.16le\t%.16e\n", x, maxReUlp); + } + fclose(f); +} + +void sample4paramY(DL xStart, DL xEnd, DL yStart, DL yEnd, DL zStart, DL zEnd, DL uStart, DL uEnd, unsigned long int testNumX, unsigned long int testNumY, unsigned long int testNumZ, unsigned long int testNumU, const char* uniqueLabel, const char *fileNameKernel, int myid, int iStartLocal, int iEndLocal) +{ + DL i, j, k, l; + // DL maxInputX, maxInputY, maxInputZ, orcle, result; + int ii, jj, kk, ll; + double x, y, z, u, reUlp, maxReUlp, lenX, lenY, lenZ, lenU; + + // mpfr + mpfr_t mpfrOrcle, mpfrResult; + mpfr_inits2(PRECISION, mpfrOrcle, mpfrResult, (mpfr_ptr) 0); + + // write error data to file + char *directory = "outputs"; + char *suffix = "sample_Y"; + char *fileNameSample; + FILE *f; + fileNameSample = (char *) calloc(strlen(directory) + strlen(uniqueLabel) + strlen(fileNameKernel) + strlen(suffix) + 128, sizeof(char)); + sprintf(fileNameSample, "%s/%s/%s_%s_%02d.txt", directory, uniqueLabel, fileNameKernel, suffix, myid); + // printf("%s\n", fileNameSample); + if ((f = fopen(fileNameSample, "w")) == NULL) { + printf("Error opening file %s.\n", fileNameSample); + exit(0); + } + + // loop boundary + lenX = xEnd.d - xStart.d; + lenY = yEnd.d - yStart.d; + lenZ = zEnd.d - zStart.d; + lenU = uEnd.d - uStart.d; + double stepX = lenX / (double)testNumX; + double stepY = lenY / (double)testNumY; + double stepZ = lenZ / (double)testNumZ; + double stepU = lenU / (double)testNumU; + + // Real number average + // 固定y值,求不同x值下的最大误差 + for(ii = iStartLocal; ii <= iEndLocal; ii++) { + i.d = yStart.d + stepY * ii; + y = i.d; + maxReUlp = 0; + for(jj = 0; jj <= testNumX; jj++) { + j.d = xStart.d + stepX * jj; + x = j.d; + for(kk = 0; kk <= testNumZ; kk++) { + k.d = zStart.d + stepZ * kk; + z = k.d; + for(ll = 0; ll <= testNumU; ll++) { + l.d = uStart.d + stepU * ll; + u = l.d; + computeResult4param(x, y, z, u, mpfrResult); + computeOrcle4param(x, y, z, u, mpfrOrcle); + // orcle.d = mpfr_get_d(mpfrOrcle, MPFR_RNDN); + // result.d = mpfr_get_d(mpfrResult, MPFR_RNDN); + #ifdef SINGLE + reUlp = computeUlpDiffF(mpfrOrcle, mpfrResult); + #else // compute Double ULP as default + reUlp = computeUlpDiff(mpfrOrcle, mpfrResult); + #endif + + if (reUlp > maxReUlp) { + // maxInputX = j; + maxReUlp = reUlp; + } + } + } + } + fprintf(f, "%.16le\t%.16e\n", y, maxReUlp); + } + fclose(f); +} + +void sample4paramZ(DL xStart, DL xEnd, DL yStart, DL yEnd, DL zStart, DL zEnd, DL uStart, DL uEnd, unsigned long int testNumX, unsigned long int testNumY, unsigned long int testNumZ, unsigned long int testNumU, const char* uniqueLabel, const char *fileNameKernel, int myid, int iStartLocal, int iEndLocal) +{ + DL i, j, k, l; + // DL maxInputX, maxInputY, maxInputZ, orcle, result; + int ii, jj, kk, ll; + double x, y, z, u, reUlp, maxReUlp, lenX, lenY, lenZ, lenU; + + // mpfr + mpfr_t mpfrOrcle, mpfrResult; + mpfr_inits2(PRECISION, mpfrOrcle, mpfrResult, (mpfr_ptr) 0); + + // write error data to file + char *directory = "outputs"; + char *suffix = "sample_Z"; + char *fileNameSample; + FILE *f; + fileNameSample = (char *) calloc(strlen(directory) + strlen(uniqueLabel) + strlen(fileNameKernel) + strlen(suffix) + 128, sizeof(char)); + sprintf(fileNameSample, "%s/%s/%s_%s_%02d.txt", directory, uniqueLabel, fileNameKernel, suffix, myid); + // printf("%s\n", fileNameSample); + if ((f = fopen(fileNameSample, "w")) == NULL) { + printf("Error opening file %s.\n", fileNameSample); + exit(0); + } + + // loop boundary + lenX = xEnd.d - xStart.d; + lenY = yEnd.d - yStart.d; + lenZ = zEnd.d - zStart.d; + lenU = uEnd.d - uStart.d; + double stepX = lenX / (double)testNumX; + double stepY = lenY / (double)testNumY; + double stepZ = lenZ / (double)testNumZ; + double stepU = lenU / (double)testNumU; + + // Real number average + // 固定z值,求不同x值下的最大误差 + for(ii = iStartLocal; ii <= iEndLocal; ii++) { + i.d = zStart.d + stepZ * ii; + z = i.d; + maxReUlp = 0; + for(jj = 0; jj <= testNumX; jj++) { + j.d = xStart.d + stepX * jj; + x = j.d; + for(kk = 0; kk <= testNumY; kk++) { + k.d = yStart.d + stepY * kk; + y = k.d; + for(ll = 0; ll <= testNumU; ll++) { + l.d = uStart.d + stepU * ll; + u = l.d; + computeResult4param(x, y, z, u, mpfrResult); + computeOrcle4param(x, y, z, u, mpfrOrcle); + // orcle.d = mpfr_get_d(mpfrOrcle, MPFR_RNDN); + // result.d = mpfr_get_d(mpfrResult, MPFR_RNDN); + #ifdef SINGLE + reUlp = computeUlpDiffF(mpfrOrcle, mpfrResult); + #else // compute Double ULP as default + reUlp = computeUlpDiff(mpfrOrcle, mpfrResult); + #endif + + if (reUlp > maxReUlp) { + // maxInputX = j; + maxReUlp = reUlp; + } + } + } + } + fprintf(f, "%.16le\t%.16e\n", z, maxReUlp); + } + fclose(f); +} + +void sample4paramU(DL xStart, DL xEnd, DL yStart, DL yEnd, DL zStart, DL zEnd, DL uStart, DL uEnd, unsigned long int testNumX, unsigned long int testNumY, unsigned long int testNumZ, unsigned long int testNumU, const char* uniqueLabel, const char *fileNameKernel, int myid, int iStartLocal, int iEndLocal) +{ + DL i, j, k, l; + // DL maxInputX, maxInputY, maxInputZ, orcle, result; + int ii, jj, kk, ll; + double x, y, z, u, reUlp, maxReUlp, lenX, lenY, lenZ, lenU; + + // mpfr + mpfr_t mpfrOrcle, mpfrResult; + mpfr_inits2(PRECISION, mpfrOrcle, mpfrResult, (mpfr_ptr) 0); + + // write error data to file + char *directory = "outputs"; + char *suffix = "sample_U"; + char *fileNameSample; + FILE *f; + fileNameSample = (char *) calloc(strlen(directory) + strlen(uniqueLabel) + strlen(fileNameKernel) + strlen(suffix) + 128, sizeof(char)); + sprintf(fileNameSample, "%s/%s/%s_%s_%02d.txt", directory, uniqueLabel, fileNameKernel, suffix, myid); + // printf("%s\n", fileNameSample); + if ((f = fopen(fileNameSample, "w")) == NULL) { + printf("Error opening file %s.\n", fileNameSample); + exit(0); + } + + // loop boundary + lenX = xEnd.d - xStart.d; + lenY = yEnd.d - yStart.d; + lenZ = zEnd.d - zStart.d; + lenU = uEnd.d - uStart.d; + double stepX = lenX / (double)testNumX; + double stepY = lenY / (double)testNumY; + double stepZ = lenZ / (double)testNumZ; + double stepU = lenU / (double)testNumU; + + // Real number average + // 固定u值,求不同x值下的最大误差 + for(ii = iStartLocal; ii <= iEndLocal; ii++) { + i.d = uStart.d + stepU * ii; + u = i.d; + maxReUlp = 0; + for(jj = 0; jj <= testNumX; jj++) { + j.d = xStart.d + stepX * jj; + x = j.d; + for(kk = 0; kk <= testNumY; kk++) { + k.d = yStart.d + stepY * kk; + y = k.d; + for(ll = 0; ll <= testNumZ; ll++) { + l.d = uStart.d + stepZ * ll; + z = l.d; + computeResult4param(x, y, z, u, mpfrResult); + computeOrcle4param(x, y, z, u, mpfrOrcle); + // orcle.d = mpfr_get_d(mpfrOrcle, MPFR_RNDN); + // result.d = mpfr_get_d(mpfrResult, MPFR_RNDN); + #ifdef SINGLE + reUlp = computeUlpDiffF(mpfrOrcle, mpfrResult); + #else // compute Double ULP as default + reUlp = computeUlpDiff(mpfrOrcle, mpfrResult); + #endif + + if (reUlp > maxReUlp) { + // maxInputX = j; + maxReUlp = reUlp; + } + } + } + } + fprintf(f, "%.16le\t%.16e\n", u, maxReUlp); + } + fclose(f); +} + +int main(int argc, char *argv[]) +{ + // parallel + int myid, numProcs; + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &myid); + MPI_Comm_size(MPI_COMM_WORLD, &numProcs); + + // parameters init + DL xStart, xEnd, yStart, yEnd, zStart, zEnd, uStart, uEnd; + unsigned long int drawNum, findMaxNum; + xStart.d = 0.1; + xEnd.d = 100; + yStart.d = 0.1; + yEnd.d = 100; + zStart.d = 0.1; + zEnd.d = 100; + uStart.d = 0.1; + uEnd.d = 100; + drawNum = TESTNUMX; + findMaxNum = TESTNUMY; + + char *fileNameKernel; + fileNameKernel = calloc(256, sizeof(char)); + char *uniqueLabel; + uniqueLabel = calloc(256, sizeof(char)); + + if(argc == 13) { + xStart.d = strtod(argv[1], NULL); + xEnd.d = strtod(argv[2], NULL); + yStart.d = strtod(argv[3], NULL); + yEnd.d = strtod(argv[4], NULL); + zStart.d = strtod(argv[5], NULL); + zEnd.d = strtod(argv[6], NULL); + uStart.d = strtod(argv[7], NULL); + uEnd.d = strtod(argv[8], NULL); + drawNum = strtod(argv[9], NULL); + findMaxNum = strtod(argv[10], NULL); + strcpy(fileNameKernel, argv[11]); + strcpy(uniqueLabel, argv[12]); + } else { + printf("Usage: ./sample4paramParallel.out xStart xEnd yStart yEnd zStart zEnd uStart uEnd drawNum findMaxNum fileNameKernel uniqueLabel\n"); + exit(EXIT_FAILURE); + } + + // local parameters init + int lenLocal = drawNum / numProcs; + int iStartLocal; + iStartLocal = myid * lenLocal; + int iEndLocal; + if (myid != numProcs - 1) + { + iEndLocal = (myid + 1) * lenLocal - 1; + } + else + { + iEndLocal = drawNum; + } + + sample4paramX(xStart, xEnd, yStart, yEnd, zStart, zEnd, uStart, uEnd, drawNum, findMaxNum, findMaxNum, findMaxNum, uniqueLabel, fileNameKernel, myid, iStartLocal, iEndLocal); + sample4paramY(xStart, xEnd, yStart, yEnd, zStart, zEnd, uStart, uEnd, findMaxNum, drawNum, findMaxNum, findMaxNum, uniqueLabel, fileNameKernel, myid, iStartLocal, iEndLocal); + sample4paramZ(xStart, xEnd, yStart, yEnd, zStart, zEnd, uStart, uEnd, findMaxNum, findMaxNum, drawNum, findMaxNum, uniqueLabel, fileNameKernel, myid, iStartLocal, iEndLocal); + sample4paramU(xStart, xEnd, yStart, yEnd, zStart, zEnd, uStart, uEnd, findMaxNum, findMaxNum, findMaxNum, drawNum, uniqueLabel, fileNameKernel, myid, iStartLocal, iEndLocal); + + // clear + free(uniqueLabel); + free(fileNameKernel); + MPI_Finalize(); + return 0; +} \ No newline at end of file diff --git a/srcTest/test4paramFPEDParallel.c b/srcTest/test4paramFPEDParallel.c new file mode 100644 index 0000000..e5dcc73 --- /dev/null +++ b/srcTest/test4paramFPEDParallel.c @@ -0,0 +1,327 @@ +#include "common.h" +#include "mpi.h" + +struct errorInfo { + double sumError; + double maxError; + double maxInputX0; + double maxInputX1; + double maxInputX2; + double maxInputX3; +}; + +#ifndef SUFFIX +#define SUFFIX orgin +#endif +#ifndef EXPRESSION +#define EXPRESSION sum +#endif + +#define EXPRESSIONMINE ADDSUFFIX(EXPRESSION, SUFFIX) +#define SUFFIX1 mpfr +#define EXPRESSIONMPFR ADDSUFFIX(EXPRESSION, SUFFIX1) + +#define TESTNUMX0 64 +#define TESTNUMX1 64 +#define TESTNUMX2 64 +#define TESTNUMX3 64 +// #define FP +// #define DEBUG +#ifndef ERRFILE +#define ERRFILE 0 +#endif +double EXPRESSIONMPFR(double, double, double, double, mpfr_t); +double EXPRESSIONMINE(double, double, double, double); + +int computeOrcle4param(double x0, double x1, double x2, double x3, mpfr_t orcle) { + return EXPRESSIONMPFR(x0, x1, x2, x3, orcle); +} + +int computeResult4param(double x0, double x1, double x2, double x3, mpfr_t mpfrResult) { + int status = 1; + + double result = EXPRESSIONMINE(x0, x1, x2, x3); + mpfr_set_d(mpfrResult, result, MPFR_RNDN); + + return status; +} + +struct errorInfo test4paramFPEDParallel(unsigned long int testNumX0, unsigned long int testNumX1, unsigned long int testNumX2, unsigned long int testNumX3, const char* uniqueLabel, const char* fileNameKernel, int myid, int i0StartLocal, int i0EndLocal, int i1StartLocal, int i1EndLocal, int i2StartLocal, int i2EndLocal, int i3StartLocal, int i3EndLocal, double x0startOriginInterval, double x1startOriginInterval, double x2startOriginInterval, double x3startOriginInterval, double stepX0, double stepX1, double stepX2, double stepX3) { + DL maxInputX0, maxInputX1, maxInputX2, maxInputX3; + int i0, i1, i2, i3; + // int flag; + double x0, x1, x2, x3, reUlp, sumError, aveReUlp, maxReUlp, lenX0, lenX1, lenX2, lenX3; + + // mpfr + mpfr_t mpfrOrcle, mpfrResult; + mpfr_inits2(PRECISION, mpfrOrcle, mpfrResult, (mpfr_ptr) 0); + + // write error data to file + #if ERRFILE + char *directory = "outputs"; + char *suffix = "sample"; + char *fileNameSample; + FILE *f; + fileNameSample = (char *) calloc(strlen(directory) + strlen(uniqueLabel) + strlen(fileNameKernel) + strlen(suffix) + 128, sizeof(char)); + sprintf(fileNameSample, "%s/%s/%s_%s_%02d.txt", directory, uniqueLabel, fileNameKernel, suffix, myid); + // printf("%s\n", fileNameSample); + if ((f = fopen(fileNameSample, "w")) == NULL) { + printf("Error opening file %s.\n", fileNameSample); + exit(0); + } + #endif + + // Real number average + maxReUlp = 0; + // flag = 1; + // size_t testCount = 0; + sumError = 0; + for(i3 = i3StartLocal; i3 <= i3EndLocal; i3++) { + x3 = x3startOriginInterval + stepX3 * i3; + for(i2 = i2StartLocal; i2 <= i2EndLocal; i2++) { + x2 = x2startOriginInterval + stepX2 * i2; + for(i1 = i1StartLocal; i1 <= i1EndLocal; i1++) { + x1 = x1startOriginInterval + stepX1 * i1; + for(i0 = i0StartLocal; i0 <= i0EndLocal; i0++) { + x0 = x0startOriginInterval + stepX0 * i0; + computeResult4param(x0, x1, x2, x3, mpfrResult); + computeOrcle4param(x0, x1, x2, x3, mpfrOrcle); + #ifdef SINGLE + reUlp = computeUlpDiffF(mpfrOrcle, mpfrResult); + #else // compute Double ULP as default + reUlp = computeUlpDiff(mpfrOrcle, mpfrResult); + #endif + // if(reUlp <= 0.5) { + // reUlp = 0; + // } + // if(isfinite(reUlp) == 0) { + // printf("happen to NaN or inf\n"); + // exit(1); + // } + // fprintf(f, "%le\t%le\t%le\t%e\n", x0, x1, x2, reUlp); + if (isnormal(reUlp) != 0) + { + #if ERRFILE + fprintf(f, "%le\t%le\n", x0, reUlp); + #endif + sumError += reUlp; + if (reUlp > maxReUlp) { + // flag = 0; + maxInputX3.d = x3; + maxInputX2.d = x2; + maxInputX1.d = x1; + maxInputX0.d = x0; + maxReUlp = reUlp; + } + } + } + } + } + } + // aveReUlp = sumError / testCount; + // if(flag == 1) { + // printf("all error are 0!!\n"); + // } + // printf("average ulp\tmax ulp\n"); + // printf("%lg\t%lg\n", aveReUlp, maxReUlp); + // printf("\naveReUlp = %lg\nmaxInputX0 = 0x%016lx %lg, maxInputX1 = 0x%016lx %lg, maxInputX2 = 0x%016lx %lg, maxReUlp = %lg\n", aveReUlp, maxInputX0.l, maxInputX0.d, maxInputX1.l, maxInputX1.d, maxInputX2.l, maxInputX2.d, maxReUlp); + #if ERRFILE + // fprintf(f, "\n"); + + // clear + fclose(f); + free(fileNameSample); + #endif + mpfr_clears(mpfrOrcle, mpfrResult, (mpfr_ptr) 0); + struct errorInfo err; + err.sumError = sumError; + err.maxError = maxReUlp; + err.maxInputX0 = maxInputX0.d; + err.maxInputX1 = maxInputX1.d; + err.maxInputX2 = maxInputX2.d; + err.maxInputX3 = maxInputX3.d; + return err; +} + +int main(int argc, char **argv) { + // parallel + int myid, numProcs; + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &myid); + MPI_Comm_size(MPI_COMM_WORLD, &numProcs); + MPI_Datatype MPI_errorInfo; + MPI_Type_contiguous(5, MPI_DOUBLE, &MPI_errorInfo); + MPI_Type_commit(&MPI_errorInfo); + + // parameters init + DL x0Start, x0End, x1Start, x1End, x2Start, x2End, x3Start, x3End; + unsigned long int testNumX0, testNumX1, testNumX2, testNumX3; + x0Start.d = 1; + x0End.d = 2; + x1Start.d = 1; + x1End.d = 2; + x2Start.d = 1; + x2End.d = 2; + x3Start.d = 1; + x3End.d = 2; + int x0startNowIdx, x1startNowIdx, x2startNowIdx, x3startNowIdx; + double x0startOriginInterval, x1startOriginInterval, x2startOriginInterval, x3startOriginInterval; + double stepX0, stepX1, stepX2, stepX3; + + testNumX0 = TESTNUMX0; + testNumX1 = TESTNUMX1; + testNumX2 = TESTNUMX2; + testNumX3 = TESTNUMX3; + + char *fileNameKernel; + fileNameKernel = calloc(256, sizeof(char)); + char *uniqueLabel; + uniqueLabel = calloc(256, sizeof(char)); + if(argc == 27) { + x0Start.d = strtod(argv[1], NULL); + x0End.d = strtod(argv[2], NULL); + x1Start.d = strtod(argv[3], NULL); + x1End.d = strtod(argv[4], NULL); + x2Start.d = strtod(argv[5], NULL); + x2End.d = strtod(argv[6], NULL); + x3Start.d = strtod(argv[7], NULL); + x3End.d = strtod(argv[8], NULL); + testNumX0 = strtod(argv[9], NULL); + testNumX1 = strtod(argv[10], NULL); + testNumX2 = strtod(argv[11], NULL); + testNumX3 = strtod(argv[12], NULL); + x0startNowIdx = atoi(argv[13]); + x1startNowIdx = atoi(argv[14]); + x2startNowIdx = atoi(argv[15]); + x3startNowIdx = atoi(argv[16]); + x0startOriginInterval = strtod(argv[17], NULL); + x1startOriginInterval = strtod(argv[18], NULL); + x2startOriginInterval = strtod(argv[19], NULL); + x3startOriginInterval = strtod(argv[20], NULL); + stepX0 = strtod(argv[21], NULL); + stepX1 = strtod(argv[22], NULL); + stepX2 = strtod(argv[23], NULL); + stepX3 = strtod(argv[24], NULL); + strcpy(fileNameKernel, argv[25]); + strcpy(uniqueLabel, argv[26]); + // } else if(argc == 18) { + // x0Start.d = strtod(argv[1], NULL); + // x0End.d = strtod(argv[2], NULL); + // x1Start.d = strtod(argv[3], NULL); + // x1End.d = strtod(argv[4], NULL); + // x2Start.d = strtod(argv[5], NULL); + // x2End.d = strtod(argv[6], NULL); + // x0startNowIdx = atoi(argv[7]); + // x1startNowIdx = atoi(argv[8]); + // x2startNowIdx = atoi(argv[9]); + // x0startOriginInterval = strtod(argv[10], NULL); + // x1startOriginInterval = strtod(argv[11], NULL); + // x2startOriginInterval = strtod(argv[12], NULL); + // stepX0 = strtod(argv[13], NULL); + // stepX1 = strtod(argv[14], NULL); + // stepX2 = strtod(argv[15], NULL); + // strcpy(fileNameKernel, argv[16]); + // strcpy(uniqueLabel, argv[17]); + // } else if(argc == 15) { + // testNumX0 = strtod(argv[1], NULL); + // testNumX1 = strtod(argv[2], NULL); + // testNumX2 = strtod(argv[3], NULL); + // x0startNowIdx = atoi(argv[4]); + // x1startNowIdx = atoi(argv[5]); + // x2startNowIdx = atoi(argv[6]); + // x0startOriginInterval = strtod(argv[7], NULL); + // x1startOriginInterval = strtod(argv[8], NULL); + // x2startOriginInterval = strtod(argv[9], NULL); + // stepX0 = strtod(argv[10], NULL); + // stepX1 = strtod(argv[11], NULL); + // stepX2 = strtod(argv[12], NULL); + // strcpy(fileNameKernel, argv[13]); + // strcpy(uniqueLabel, argv[14]); + } else { + printf("Usage: ./test3paramFPEDParallel.exe [x0Start x0End x1Start x1End x2Start x2End testNumX0 testNumX1 testNumX2 fileNameKernel]\n"); + printf("Usage: if no correct input:\n"); + printf("Usage: \tthe fixed inputs [%g %g %g %g %g %g %g %g %lu %lu %lu %lu] will be used\n", x0Start.d, x0End.d, x1Start.d, x1End.d, x2Start.d, x2End.d, x3Start.d, x3End.d, testNumX0, testNumX1, testNumX2, testNumX3); + } + + // if(myid == 0) { + // printf("\n---------------------------------------------------start test3paramFPEDParallel\n"); + // printf("Parameters: x0Start: %lg, x0End: %lg, x1Start: %lg, x1End: %lg, x2Start: %lg, x2End: %lg, testNumX0 = %lu, testNumX1 = %lu, testNumX2 = %lu, fileNameKernel: %s\n", x0Start.d, x0End.d, x1Start.d, x1End.d, x2Start.d, x2End.d, testNumX0, testNumX1, testNumX2, fileNameKernel); + // } + + // local parameters init + int lenX3Local = testNumX3 / numProcs; + int i3StartLocal; + i3StartLocal = x3startNowIdx + myid * lenX3Local; + int i3EndLocal; + if(myid != numProcs - 1) { + i3EndLocal = x3startNowIdx + (myid + 1) * lenX3Local - 1; + } else { + i3EndLocal = x3startNowIdx + testNumX3; + } + int i2StartLocal = x2startNowIdx; + int i2EndLocal = x2startNowIdx + testNumX2; + int i1StartLocal = x1startNowIdx; + int i1EndLocal = x1startNowIdx + testNumX1; + int i0StartLocal = x0startNowIdx; + int i0EndLocal = x0startNowIdx + testNumX0; + + // call the error test function + struct errorInfo err = test4paramFPEDParallel(testNumX0, testNumX1, testNumX2, testNumX3, uniqueLabel, fileNameKernel, myid, i0StartLocal, i0EndLocal, i1StartLocal, i1EndLocal, i2StartLocal, i2EndLocal, i3StartLocal, i3EndLocal, x0startOriginInterval, x1startOriginInterval, x2startOriginInterval, x3startOriginInterval, stepX0, stepX1, stepX2, stepX3); + + // gather errors and find the max + struct errorInfo *errs; + errs = (struct errorInfo *)calloc(numProcs, sizeof(struct errorInfo)); + MPI_Gather(&err, 1, MPI_errorInfo, errs, 1, MPI_errorInfo, 0, MPI_COMM_WORLD); + if(myid == 0) + { + double maxError = -1; + double aveError = 0; + double errTmp = -1; + int maxErrorIdx = -1; + for(int i = 0; i < numProcs; i++) + { + errTmp = errs[i].maxError; + if(errTmp > maxError) + { + maxError = errTmp; + maxErrorIdx = i; + } + aveError += errs[i].sumError; + } + aveError = aveError / (testNumX0 * testNumX1 * testNumX2 * testNumX3); + DL maxInputX0, maxInputX1, maxInputX2, maxInputX3; + maxInputX0.d = errs[maxErrorIdx].maxInputX0; + maxInputX1.d = errs[maxErrorIdx].maxInputX1; + maxInputX2.d = errs[maxErrorIdx].maxInputX2; + maxInputX3.d = errs[maxErrorIdx].maxInputX3; + + FILE *fErr; + char *directory = "./outputs"; + char *suffixErr = "error.txt"; + char *fileNameErr; + fileNameErr = (char *) calloc(strlen(directory) + strlen(uniqueLabel) + strlen(fileNameKernel) + strlen(suffixErr) + 128, sizeof(char)); + sprintf(fileNameErr, "%s/%s/%s_%s", directory, uniqueLabel, fileNameKernel, suffixErr); + if ((fErr = fopen(fileNameErr, "w")) == NULL) + { + printf("Error opening file %s.\n", fileNameErr); + exit(0); + } + printf("average ulp\tmax ulp\n"); + printf("%.16le\t%.16le\n", aveError, maxError); + // printf("\naveReUlp = %lg\nmaxInputX0 = 0x%016lx %lg, maxInputX1 = 0x%016lx %lg, maxInputX2 = 0x%016lx %lg, maxReUlp = %lg\n", aveError, maxInputX0.l, maxInputX0.d, maxInputX1.l, maxInputX1.d, maxInputX2.l, maxInputX2.d, maxError); + fprintf(fErr, "average ulp\tmax ulp\n"); + fprintf(fErr, "%.16le\t%.16le\n", aveError, maxError); + fprintf(fErr, "\naveReUlp = %lg\nmaxInputX0 = 0x%016lx %lg, maxInputX1 = 0x%016lx %lg, maxInputX2 = 0x%016lx %lg, maxInputX3 = 0x%016lx %lg, maxReUlp = %lg\n", aveError, maxInputX0.l, maxInputX0.d, maxInputX1.l, maxInputX1.d, maxInputX2.l, maxInputX2.d, maxInputX3.l, maxInputX3.d, maxError); + + free(fileNameErr); + free(uniqueLabel); + fclose(fErr); + } + + // clear + free(fileNameKernel); + free(errs); + MPI_Type_free(&MPI_errorInfo); + MPI_Finalize(); + return 0; +} \ No newline at end of file -- Gitee From 45a2fbf29898c6399667e8df3d19cd1044db9414 Mon Sep 17 00:00:00 2001 From: hjwLab Date: Thu, 13 Apr 2023 17:17:24 +0800 Subject: [PATCH 19/32] suppor 5 parameters' error detecting and sampling, and add a example benchmark for testing --- benchMark.txt | 7 +- benchMarkInterval.txt | 7 +- detectErrorFiveFPEDParallel.sh | 123 +++++++ sampleErrorFive.sh | 80 +++++ src/basic.cpp | 8 + src/geneCode.cpp | 10 + src/main.cpp | 24 ++ src/tools.cpp | 59 +++- srcTest/sample5paramFPEDParallel.c | 493 +++++++++++++++++++++++++++++ srcTest/test5paramFPEDParallel.c | 346 ++++++++++++++++++++ 10 files changed, 1148 insertions(+), 9 deletions(-) create mode 100755 detectErrorFiveFPEDParallel.sh create mode 100755 sampleErrorFive.sh create mode 100644 srcTest/sample5paramFPEDParallel.c create mode 100644 srcTest/test5paramFPEDParallel.c diff --git a/benchMark.txt b/benchMark.txt index f074375..d208078 100644 --- a/benchMark.txt +++ b/benchMark.txt @@ -98,4 +98,9 @@ smartRoot_1 (c * 2.0) / (-3.5 - sqrt(((3.5 * 3.5) - ((3.0 * c) * 4.0)))) smartRoot_2 (-3.5 + sqrt(((3.5 * 3.5) - ((3.0 * c) * 4.0)))) / (3.0 * 2.0) triangleSorted_1 sqrt(((((c + (b + a)) * (a - (c - b))) * (a + (c - b))) * (c + (b - a)))) / 4.0 triangleSorted_2 sqrt(((((c + (a + b)) * (b - (c - a))) * (b + (c - a))) * (c + (a - b)))) / 4.0; -example x0+x1+x2+x3 \ No newline at end of file +example x0+x1+x2+x3 +polyIDX0 (((-0.85073072819636686 * x1) + (-0.98664016916368502 * x2) + (1.3809517485817782 * x3) + (1.8653450939330991 * x4)) * ((-0.85073072819636686 * x1) + (-0.98664016916368502 * x2) + (1.3809517485817782 * x3) + (1.8653450939330991 * x4)) * ((-0.85073072819636686 * x1) + (-0.98664016916368502 * x2) + (1.3809517485817782 * x3) + (1.8653450939330991 * x4))) - (((0.18424469636214999 * x1) + (0.45123431334216657 * x2) + (0.80794264540764449 * x3) + (0.45071126534400952 * x4)) * ((0.18424469636214999 * x1) + (0.45123431334216657 * x2) + (0.80794264540764449 * x3) + (0.45071126534400952 * x4)) * ((0.18424469636214999 * x1) + (0.45123431334216657 * x2) + (0.80794264540764449 * x3) + (0.45071126534400952 * x4))) +polyIDX1 (((0.18424469636214999 * x1) + (0.45123431334216657 * x2) + (-0.80794264540764449 * x3) + (-0.45071126534400952 * x4)) * ((0.18424469636214999 * x1) + (0.45123431334216657 * x2) + (-0.80794264540764449 * x3) + (-0.45071126534400952 * x4)) * ((0.18424469636214999 * x1) + (0.45123431334216657 * x2) + (-0.80794264540764449 * x3) + (-0.45071126534400952 * x4)) - ((0.052100253064028955 * x1) + (-0.8942341911807864 * x2) + (0.40478255170032273 * x3) + (-0.93774690197704236 * x4)) * ((0.052100253064028955 * x1) + (-0.8942341911807864 * x2) + (0.40478255170032273 * x3) + (-0.93774690197704236 * x4)) * ((0.052100253064028955 * x1) + (-0.8942341911807864 * x2) + (0.40478255170032273 * x3) + (-0.93774690197704236 * x4))) +polyIDX2 (((0.052100253064028955 * x1) + (-0.8942341911807864 * x2) + (0.40478255170032273 * x3) + (-0.93774690197704236 * x4)) * ((0.052100253064028955 * x1) + (-0.8942341911807864 * x2) + (0.40478255170032273 * x3) + (-0.93774690197704236 * x4)) * ((0.052100253064028955 * x1) + (-0.8942341911807864 * x2) + (0.40478255170032273 * x3) + (-0.93774690197704236 * x4)) - ((-0.85073072819636686 * x1) + (-0.98664016916368502 * x2) + (1.3809517485817782 * x3) + (1.8653450939330991 * x4)) * ((-0.85073072819636686 * x1) + (-0.98664016916368502 * x2) + (1.3809517485817782 * x3) + (1.8653450939330991 * x4)) * ((-0.85073072819636686 * x1) + (-0.98664016916368502 * x2) + (1.3809517485817782 * x3) + (1.8653450939330991 * x4))) +example5param x0+x1+x2+x3+x4 +pov-ray x1*cos(x2)*cos(x3)+x4*cos(x2)+x5*cos(x2)*sin(x3) \ No newline at end of file diff --git a/benchMarkInterval.txt b/benchMarkInterval.txt index a889172..4a437fe 100644 --- a/benchMarkInterval.txt +++ b/benchMarkInterval.txt @@ -98,4 +98,9 @@ 0.75 2 1 9 1 9 1 9 1 9 1 9 1 9 -0 1 0 1 0 1 0 1 \ No newline at end of file +0 1 0 1 0 1 0 1 +3 9 1.5 5 -2 10 -1 3.5 +3 9 1.5 5 -2 10 -1 3.5 +3 9 1.5 5 -2 10 -1 3.5 +0 1 0 1 0 1 0 1 0 1 +-1 1 -3.14159265358979323846264 3.14159265358979323846264 -3.14159265358979323846264 3.14159265358979323846264 -1 1 -1 1 \ No newline at end of file diff --git a/detectErrorFiveFPEDParallel.sh b/detectErrorFiveFPEDParallel.sh new file mode 100755 index 0000000..b9feb26 --- /dev/null +++ b/detectErrorFiveFPEDParallel.sh @@ -0,0 +1,123 @@ +# Usage: ./detectErrorFourParallel.sh ${uniqueLabel} ${x0Start} ${x0End} ${x1Start} ${x1End} ${x2Start} ${x2End} ${x0Size} ${x1Size} ${x2Size} ${prefix} ${middle} ${suffix} ${errfile} +# set -x + +path=`pwd` +cd ${path} +CC=mpicc + +uniqueLabel=${1} # unique number +x0Start=${2} +x0End=${3} +x1Start=${4} +x1End=${5} +x2Start=${6} +x2End=${7} +x3Start=${8} +x3End=${9} +x4Start=${10} +x4End=${11} +if [ $# -eq 35 ]; then + x0Size=${12} + x1Size=${13} + x2Size=${14} + x3Size=${15} + x4Size=${16} + x0startNowIdx=${17} # the index of the start point of the current interval. + x1startNowIdx=${18} + x2startNowIdx=${19} + x3startNowIdx=${20} + x4startNowIdx=${21} + x0startOriginInterval=${22} # the value of the start point of the origin interval. + x1startOriginInterval=${23} + x2startOriginInterval=${24} + x3startOriginInterval=${25} + x4startOriginInterval=${26} + stepX0=${27} # the step for sampling points. + stepX1=${28} + stepX2=${29} + stepX3=${30} + stepX4=${31} + prefix=${32} # expr_${uniqueLabel}. Eg: expr_20221030155958 + middle=${33} # intervalsInfo_sizes. Eg: 3.8_7.8_-4.5_-0.3_0.4_0.9_256_256_256 + suffix=${34} # different version. Eg: herbie daisy origin temp_0_3 final + errfile=${35} # 1 or 0: TRUE or False +elif [ $# -eq 32 ]; then + x0Size=${12} + x1Size=${13} + x2Size=${14} + x3Size=${15} + x4Size=${16} + x0startNowIdx=${17} # the index of the start point of the current interval. + x1startNowIdx=${18} + x2startNowIdx=${19} + x3startNowIdx=${20} + x4startNowIdx=${21} + x0startOriginInterval=${22} # the value of the start point of the origin interval. + x1startOriginInterval=${23} + x2startOriginInterval=${24} + x3startOriginInterval=${25} + x4startOriginInterval=${26} + stepX0=${27} # the step for sampling points. + stepX1=${28} + stepX2=${29} + stepX3=${30} + stepX4=${31} + prefix=${32} # expr_${uniqueLabel}. Eg: expr_20221030155958 + middle=${33} # intervalsInfo_sizes. Eg: 3.8_7.8_-4.5_-0.3_0.4_0.9_256_256_256 + suffix=${34} # different version. Eg: herbie daisy origin temp_0_3 final + errfile=0 # 1 or 0: TRUE or False +elif [ $# -eq 29 ]; then + x0Size=32 + x1Size=32 + x2Size=32 + x3Size=32 + x0startNowIdx=${12} # the index of the start point of the current interval. + x1startNowIdx=${13} + x2startNowIdx=${14} + x3startNowIdx=${15} + x4startNowIdx=${16} + x0startOriginInterval=${17} # the value of the start point of the origin interval. + x1startOriginInterval=${18} + x2startOriginInterval=${19} + x3startOriginInterval=${20} + x4startOriginInterval=${21} + stepX0=${22} # the step for sampling points. + stepX1=${23} + stepX2=${24} + stepX3=${25} + stepX4=${26} + prefix=${27} # expr_${uniqueLabel}. Eg: expr_20221030155958 + middle=${28} # intervalsInfo_sizes. Eg: 3.8_7.8_-4.5_-0.3_0.4_0.9_256_256_256 + suffix=${29} # different version. Eg: herbie daisy origin temp_0_3 final + errfile=0 # 1 or 0: TRUE or False +else + echo "detectErrorFiveParallel: Invalid input parameters" + exit +fi +testFileName=test5paramFPEDParallel +numProcs=32 + +echo "Detecting error: ${uniqueLabel} ${x0Start} ${x0End} ${x1Start} ${x1End} ${x2Start} ${x2End} ${x3End} ${x3Start} ${x4End} ${x4Start} ${x0Size} ${x1Size} ${x2Size} ${x3Size} ${x4Size} ${prefix} ${middle} ${suffix} ${errfile}" +directory="./srcTest"/${uniqueLabel} +sourceFile=${prefix}_${suffix} +fileNameKernel=${prefix}__${middle}_${suffix} + +# echo "${CC} ${testFileName}.c ${sourceFile}.c ${prefix}_mpfr.c computeULP.c -IincludeTEST -DEXPRESSION=${prefix}_ -DSUFFIX=${suffix} -lmpfr -lm -O3 -o ${testFileName}.exe" +${CC} ./srcTest/${testFileName}.c ${directory}/${sourceFile}.c ${directory}/${prefix}_mpfr.c ./srcTest/computeULP.c -IincludeTEST -IincludeDD -DEXPRESSION=${prefix}_ -DSUFFIX=${suffix} -DERRFILE=${errfile} -Llibs -lTGen -lmpfr -lm -lqd -o ${testFileName}.exe +# echo "mpirun -n ${numProcs} ./${testFileName}.exe ${x0Start} ${x0End} ${x1Start} ${x1End} ${x2Start} ${x2End} ${x0Size} ${x1Size} ${x2Size} ${fileNameKernel}" +mpirun -n ${numProcs} ./${testFileName}.exe ${x0Start} ${x0End} ${x1Start} ${x1End} ${x2Start} ${x2End} ${x3End} ${x3Start} ${x4End} ${x4Start} ${x0Size} ${x1Size} ${x2Size} ${x3Size} ${x4Size} ${x0startNowIdx} ${x1startNowIdx} ${x2startNowIdx} ${x3startNowIdx} ${x4startNowIdx} ${x0startOriginInterval} ${x1startOriginInterval} ${x2startOriginInterval} ${x3startOriginInterval} ${x4startOriginInterval} ${stepX0} ${stepX1} ${stepX2} ${stepX3} ${stepX4} ${fileNameKernel} ${uniqueLabel} +rm ${testFileName}.exe + +# combine files +if [ ${errfile} -eq 1 ]; then + cd ./outputs/${uniqueLabel} + findWord="${fileNameKernel}_sample_*.txt" + # echo "For suffix = ${suffix}, Find and combine by shell command cat: ${findWord}" + find . -name "${findWord}" | sort -h | xargs cat > sample_${uniqueLabel}_${suffix}.txt + # echo "sample file: `pwd`/sample_${uniqueLabel}_${suffix}.txt" + rm ${findWord} + cd - > /dev/null +fi + +echo "end detecting ${uniqueLabel}" +echo diff --git a/sampleErrorFive.sh b/sampleErrorFive.sh new file mode 100755 index 0000000..f46817d --- /dev/null +++ b/sampleErrorFive.sh @@ -0,0 +1,80 @@ +#!/bin/bash +# Usage: ./sampleTwoFPEDParallel.sh ${uniqueLabel} ${x0Start} ${x0End} ${x1Start} ${x1End} ${x0Size} ${x1Size} ${prefix} ${middle} ${suffix} +# set -x + +path=`pwd` +cd ${path} +CC=mpicc + +uniqueLabel=${1} # unique number +x0Start=${2} +x0End=${3} +x1Start=${4} +x1End=${5} +x2Start=${6} +x2End=${7} +x3Start=${8} +x3End=${9} +x4Start=${10} +x4End=${11} + +if [ $# -eq 16 ]; then + drawNum=${12} + findMaxNum=${13} + prefix=${14} # expr_${uniqueLabel}. Eg: expr_20221030155958 + middle=${15} # intervalsInfo_sizes. Eg: 3.8_7.8_-4.5_-0.3_0.4_0.9_256_256_256 + suffix=${16} # different version. Eg: herbie daisy origin temp_0_3 final +elif [ $# -eq 1 ]; then + drawNum=384 + findMaxNum=32 + prefix=${12} + middle=${13} + suffix=${14} +else + echo "sampleFiveFPEDParallel: Invalid input parameters" + exit +fi + +testFileName=sample5paramFPEDParallel +numProcs=32 + +# echo "sampling: ${uniqueLabel} ${x0Start} ${x0End} ${x1Start} ${x1End} ${x2Start} ${x2End} ${drawNum} ${findMaxNum} ${prefix} ${middle} ${suffix} ${errfile}" +directory="./srcTest"/${uniqueLabel} +sourceFile=${prefix}_${suffix} +fileNameKernel=${prefix}__${middle}_${suffix} + +${CC} ./srcTest/${testFileName}.c ${directory}/${sourceFile}.c ${directory}/${prefix}_mpfr.c ./srcTest/computeULP.c -IincludeTEST -IincludeDD -DEXPRESSION=${prefix}_ -DSUFFIX=${suffix} -Llibs -lTGen -lmpfr -lm -lqd -o ${testFileName}.exe +mpirun -n ${numProcs} ./${testFileName}.exe ${x0Start} ${x0End} ${x1Start} ${x1End} ${x2Start} ${x2End} ${x3Start} ${x3End} ${x4Start} ${x4End} ${drawNum} ${findMaxNum} ${fileNameKernel} ${uniqueLabel} +rm ${testFileName}.exe + +# combine files +cd ./outputs/${uniqueLabel} +## for sample_X +findWord="${fileNameKernel}_sample_X_*.txt" +# echo "For suffix = ${suffix}, Find and combine by shell command cat: ${findWord}" +find . -name "${findWord}" | sort -h | xargs cat > sample_${uniqueLabel}_${suffix}_X.txt +rm ${findWord} +## for sample_Y +findWord="${fileNameKernel}_sample_Y_*.txt" +# echo "For suffix = ${suffix}, Find and combine by shell command cat: ${findWord}" +find . -name "${findWord}" | sort -h | xargs cat > sample_${uniqueLabel}_${suffix}_Y.txt +rm ${findWord} +## for sample_Z +findWord="${fileNameKernel}_sample_Z_*.txt" +# echo "For suffix = ${suffix}, Find and combine by shell command cat: ${findWord}" +find . -name "${findWord}" | sort -h | xargs cat > sample_${uniqueLabel}_${suffix}_Z.txt +rm ${findWord} +## for sample_U +findWord="${fileNameKernel}_sample_U_*.txt" +# echo "For suffix = ${suffix}, Find and combine by shell command cat: ${findWord}" +find . -name "${findWord}" | sort -h | xargs cat > sample_${uniqueLabel}_${suffix}_U.txt +rm ${findWord} +## for sample_V +findWord="${fileNameKernel}_sample_V_*.txt" +# echo "For suffix = ${suffix}, Find and combine by shell command cat: ${findWord}" +find . -name "${findWord}" | sort -h | xargs cat > sample_${uniqueLabel}_${suffix}_V.txt +rm ${findWord} +cd - > /dev/null + +# echo "end sampling ${uniqueLabel}" +echo diff --git a/src/basic.cpp b/src/basic.cpp index c1f9e25..97f1691 100644 --- a/src/basic.cpp +++ b/src/basic.cpp @@ -805,6 +805,14 @@ void write_to_file_wrapper(string uniqueLabel, string exprOriginBest, int dimens summaryData.push_back(thresholds.at(2)); summaryData.push_back(thresholds.at(3)); } + else if (thresholds.size() == 5) + { + summaryData.push_back(thresholds.at(0)); + summaryData.push_back(thresholds.at(1)); + summaryData.push_back(thresholds.at(2)); + summaryData.push_back(thresholds.at(3)); + summaryData.push_back(thresholds.at(4)); + } else { fprintf(stderr, "ERROR: write_to_file_wrapper: we can not support %ld demision now.\n", thresholds.size()); diff --git a/src/geneCode.cpp b/src/geneCode.cpp index e7638a9..0428a51 100644 --- a/src/geneCode.cpp +++ b/src/geneCode.cpp @@ -301,6 +301,11 @@ string geneHerbieCode(string uniqueLabel) {"triangleSorted_1", ""}, {"triangleSorted_2", ""}, {"example", "(x0+x1)+(x2+x3)"}, + {"polyIDX0", ""}, + {"polyIDX1", ""}, + {"polyIDX2", ""}, + {"example5param", "(x0+x1)+(x2+x3)+x4"}, + {"pov-ray", ""}, }; auto pos = benchmarkHerbie.find(uniqueLabel); @@ -388,6 +393,11 @@ string geneDaisyCode(string uniqueLabel) {"triangleSorted_1", ""}, {"triangleSorted_2", ""}, {"example", "(x0+x2)+(x1+x3)"}, + {"polyIDX0", ""}, + {"polyIDX1", ""}, + {"polyIDX2", ""}, + {"example5param", "(x0+x1)+(x2+x3)+x4"}, + {"pov-ray", ""}, }; auto pos = benchmarkDaisy.find(uniqueLabel); diff --git a/src/main.cpp b/src/main.cpp index 3968f9f..7b6e118 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -88,6 +88,11 @@ map> benchmarkThresholds = { {"triangleSorted_1", {2, 2, 2}}, {"triangleSorted_2", {2, 2, 2}}, {"example", {2, 2, 2, 2}}, + {"polyIDX0", {2, 2, 2, 2}}, + {"polyIDX1", {2, 2, 2, 2}}, + {"polyIDX2", {2, 2, 2, 2}}, + {"example5param", {2, 2, 2, 2, 2}}, + {"pov-ray", {2, 2, 2, 2, 2}}, }; //===----------------------------------------------------------------------===// @@ -204,6 +209,10 @@ int main() { sampleScale = 96; } + else if (dimension == 5) + { + sampleScale = 24; + } else { sampleScale = 10; @@ -381,6 +390,21 @@ int main() vector scales{384, 96}; // actually are drawNum and findMaxNum, so only need 2 numbers sampleError(uniqueLabel, exprOriginBest, intervals, scales); } + else if (dimension == 5) + { + suffixTmp = exprOriginBest + "_X"; + suffixTmps.push_back(suffixTmp); + suffixTmp = exprOriginBest + "_Y"; + suffixTmps.push_back(suffixTmp); + suffixTmp = exprOriginBest + "_Z"; + suffixTmps.push_back(suffixTmp); + suffixTmp = exprOriginBest + "_U"; + suffixTmps.push_back(suffixTmp); + suffixTmp = exprOriginBest + "_V"; + suffixTmps.push_back(suffixTmp); + vector scales{384, 24}; // actually are drawNum and findMaxNum, so only need 2 numbers + sampleError(uniqueLabel, exprOriginBest, intervals, scales); + } else { fprintf(stderr, "ERROR: main: we can not handle %d parameters (bigger than 3) now\n", dimension); diff --git a/src/tools.cpp b/src/tools.cpp index c200026..8c2c351 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -364,7 +364,7 @@ exprInfo testError(string uniqueLabel, string suffix, const vector &inte exprInfo tempError; size_t size = scales.size(); - if (size < 5) + if (size < 6) { string prefix = "expr_" + uniqueLabel; vector params; @@ -409,7 +409,7 @@ exprInfo testError(string uniqueLabel, string suffix, const vector &inte namespace fs = std::filesystem; string currentPath = fs::current_path(); string testName = currentPath + "/outputs/" + uniqueLabel + "/" + fileNameKernel + "_error.txt"; // get the output of error detecting - string number[4] = {"One", "Two", "Three", "Four"}; + string number[5] = {"One", "Two", "Three", "Four", "Five"}; string scriptName = "./detectError" + number[size - 1] + "FPEDParallel.sh"; stringstream ss; ss << scriptName << " " << uniqueLabel; @@ -456,7 +456,7 @@ exprInfo testError(string uniqueLabel, string suffix, const vector &inte tempError.suffix = suffix; return tempError; } - else if (size == 5) + else if (size == 7) { tempError = testError(uniqueLabel, suffix, intervals); } @@ -473,7 +473,7 @@ void sampleError(string uniqueLabel, string suffix, const vector &interv exprInfo tempError; size_t size = intervals.size() / 2; - if (size < 5) + if (size < 6) { string prefix = "expr_" + uniqueLabel; vector params; @@ -503,7 +503,7 @@ void sampleError(string uniqueLabel, string suffix, const vector &interv namespace fs = std::filesystem; string currentPath = fs::current_path(); string testName = currentPath + "/outputs/" + uniqueLabel + "/" + fileNameKernel + "_error.txt"; // used to get the output of error detecting, not input parameters - string number[4] = {"One", "Two", "Three", "Four"}; + string number[5] = {"One", "Two", "Three", "Four", "Five"}; string scriptName = "./sampleError" + number[size - 1] + ".sh"; stringstream ss; ss << scriptName << " " << uniqueLabel; @@ -517,7 +517,7 @@ void sampleError(string uniqueLabel, string suffix, const vector &interv // cout << "fileNameKernel: " << fileNameKernel << "\n"; cout << "command: " << commandStr << "\n"; // cout << "testName: " << testName << "\n"; - char command[200] = {0}; + char command[512] = {0}; strcat(command, commandStr.c_str()); system(command); } @@ -947,7 +947,52 @@ vector> permuteMultiVec (vector> vec) { vector> suzu; size_t row = vec.size(); - if (row == 4) + if (row == 5) + { + vector tmp; + auto &row0 = vec.at(0); + auto &row1 = vec.at(1); + auto &row2 = vec.at(2); + auto &row3 = vec.at(3); + auto &row4 = vec.at(4); + for(size_t i = 0; i < row0.size(); i += 2) + { + tmp.push_back(row0.at(i)); + tmp.push_back(row0.at(i + 1)); + for(size_t j = 0; j < row1.size(); j += 2) + { + tmp.push_back(row1.at(j)); + tmp.push_back(row1.at(j + 1)); + for(size_t k = 0; k < row2.size(); k += 2) + { + tmp.push_back(row2.at(k)); + tmp.push_back(row2.at(k + 1)); + for(size_t l = 0; l < row3.size(); l += 2) + { + tmp.push_back(row3.at(l)); + tmp.push_back(row3.at(l + 1)); + for(size_t m = 0; m < row4.size(); m += 2) + { + tmp.push_back(row4.at(m)); + tmp.push_back(row4.at(m + 1)); + suzu.push_back(tmp); + tmp.pop_back(); + tmp.pop_back(); + } + tmp.pop_back(); + tmp.pop_back(); + } + tmp.pop_back(); + tmp.pop_back(); + } + tmp.pop_back(); + tmp.pop_back(); + } + tmp.pop_back(); + tmp.pop_back(); + } + } + else if (row == 4) { vector tmp; auto &row0 = vec.at(0); diff --git a/srcTest/sample5paramFPEDParallel.c b/srcTest/sample5paramFPEDParallel.c new file mode 100644 index 0000000..ba1e5d1 --- /dev/null +++ b/srcTest/sample5paramFPEDParallel.c @@ -0,0 +1,493 @@ +#include "common.h" +#include "mpi.h" + +#ifndef SUFFIX +#define SUFFIX orgin +#endif +#ifndef EXPRESSION +#define EXPRESSION sum +#endif + +#define EXPRESSIONMINE ADDSUFFIX(EXPRESSION, SUFFIX) +#define SUFFIX1 mpfr +#define EXPRESSIONMPFR ADDSUFFIX(EXPRESSION, SUFFIX1) + +#define TESTNUMX 2048 +#define TESTNUMY 2048 + +double EXPRESSIONMPFR(double, double, double, double, double, mpfr_t); +double EXPRESSIONMINE(double, double, double, double, double); + +int computeOrcle5param(double x0, double x1, double x2, double x3, double x4, mpfr_t orcle) { + return EXPRESSIONMPFR(x0, x1, x2, x3, x4, orcle); +} + +int computeResult5param(double x0, double x1, double x2, double x3, double x4, mpfr_t mpfrResult) { + int status = 1; + + double result = EXPRESSIONMINE(x0, x1, x2, x3, x4); + mpfr_set_d(mpfrResult, result, MPFR_RNDN); + + return status; +} + +void sample5paramX(DL xStart, DL xEnd, DL yStart, DL yEnd, DL zStart, DL zEnd, DL uStart, DL uEnd, DL vStart, DL vEnd, unsigned long int testNumX, unsigned long int testNumY, unsigned long int testNumZ, unsigned long int testNumU, unsigned long int testNumV, const char* uniqueLabel, const char *fileNameKernel, int myid, int iStartLocal, int iEndLocal) +{ + DL i, j, k, l, m; + // DL maxInputX, maxInputY, maxInputZ, orcle, result; + int ii, jj, kk, ll, mm; + double x, y, z, u, v, reUlp, maxReUlp, lenX, lenY, lenZ, lenU, lenV; + + // mpfr + mpfr_t mpfrOrcle, mpfrResult; + mpfr_inits2(PRECISION, mpfrOrcle, mpfrResult, (mpfr_ptr) 0); + + // write error data to file + char *directory = "outputs"; + char *suffix = "sample_X"; + char *fileNameSample; + FILE *f; + fileNameSample = (char *) calloc(strlen(directory) + strlen(uniqueLabel) + strlen(fileNameKernel) + strlen(suffix) + 128, sizeof(char)); + sprintf(fileNameSample, "%s/%s/%s_%s_%02d.txt", directory, uniqueLabel, fileNameKernel, suffix, myid); + // printf("%s\n", fileNameSample); + if ((f = fopen(fileNameSample, "w")) == NULL) { + printf("Error opening file %s.\n", fileNameSample); + exit(0); + } + + // loop boundary + lenX = xEnd.d - xStart.d; + lenY = yEnd.d - yStart.d; + lenZ = zEnd.d - zStart.d; + lenU = uEnd.d - uStart.d; + lenV = vEnd.d - vStart.d; + double stepX = lenX / (double)testNumX; + double stepY = lenY / (double)testNumY; + double stepZ = lenZ / (double)testNumZ; + double stepU = lenU / (double)testNumU; + double stepV = lenV / (double)testNumV; + + // Real number average + // 固定x值,求不同y值下的最大误差 + for(ii = iStartLocal; ii <= iEndLocal; ii++) { + i.d = xStart.d + stepX * ii; + x = i.d; + maxReUlp = 0; + for(jj = 0; jj <= testNumY; jj++) { + j.d = yStart.d + stepY * jj; + y = j.d; + for(kk = 0; kk <= testNumZ; kk++) { + k.d = zStart.d + stepZ * kk; + z = k.d; + for(ll = 0; ll <= testNumU; ll++) { + l.d = uStart.d + stepU * ll; + u = l.d; + for(mm = 0; mm <= testNumV; mm++) { + m.d = vStart.d + stepV * mm; + v = m.d; + computeResult5param(x, y, z, u, v, mpfrResult); + computeOrcle5param(x, y, z, u, v, mpfrOrcle); + // orcle.d = mpfr_get_d(mpfrOrcle, MPFR_RNDN); + // result.d = mpfr_get_d(mpfrResult, MPFR_RNDN); + #ifdef SINGLE + reUlp = computeUlpDiffF(mpfrOrcle, mpfrResult); + #else // compute Double ULP as default + reUlp = computeUlpDiff(mpfrOrcle, mpfrResult); + #endif + + if (reUlp > maxReUlp) { + // maxInputX = j; + maxReUlp = reUlp; + } + } + } + } + } + fprintf(f, "%.16le\t%.16e\n", x, maxReUlp); + } + fclose(f); +} + +void sample5paramY(DL xStart, DL xEnd, DL yStart, DL yEnd, DL zStart, DL zEnd, DL uStart, DL uEnd, DL vStart, DL vEnd, unsigned long int testNumX, unsigned long int testNumY, unsigned long int testNumZ, unsigned long int testNumU, unsigned long int testNumV, const char* uniqueLabel, const char *fileNameKernel, int myid, int iStartLocal, int iEndLocal) +{ + DL i, j, k, l, m; + // DL maxInputX, maxInputY, maxInputZ, orcle, result; + int ii, jj, kk, ll, mm; + double x, y, z, u, v, reUlp, maxReUlp, lenX, lenY, lenZ, lenU, lenV; + + // mpfr + mpfr_t mpfrOrcle, mpfrResult; + mpfr_inits2(PRECISION, mpfrOrcle, mpfrResult, (mpfr_ptr) 0); + + // write error data to file + char *directory = "outputs"; + char *suffix = "sample_Y"; + char *fileNameSample; + FILE *f; + fileNameSample = (char *) calloc(strlen(directory) + strlen(uniqueLabel) + strlen(fileNameKernel) + strlen(suffix) + 128, sizeof(char)); + sprintf(fileNameSample, "%s/%s/%s_%s_%02d.txt", directory, uniqueLabel, fileNameKernel, suffix, myid); + // printf("%s\n", fileNameSample); + if ((f = fopen(fileNameSample, "w")) == NULL) { + printf("Error opening file %s.\n", fileNameSample); + exit(0); + } + + // loop boundary + lenX = xEnd.d - xStart.d; + lenY = yEnd.d - yStart.d; + lenZ = zEnd.d - zStart.d; + lenU = uEnd.d - uStart.d; + lenV = vEnd.d - vStart.d; + double stepX = lenX / (double)testNumX; + double stepY = lenY / (double)testNumY; + double stepZ = lenZ / (double)testNumZ; + double stepU = lenU / (double)testNumU; + double stepV = lenV / (double)testNumV; + + // Real number average + // 固定y值,求不同x值下的最大误差 + for(ii = iStartLocal; ii <= iEndLocal; ii++) { + i.d = yStart.d + stepY * ii; + y = i.d; + maxReUlp = 0; + for(jj = 0; jj <= testNumX; jj++) { + j.d = xStart.d + stepX * jj; + x = j.d; + for(kk = 0; kk <= testNumZ; kk++) { + k.d = zStart.d + stepZ * kk; + z = k.d; + for(ll = 0; ll <= testNumU; ll++) { + l.d = uStart.d + stepU * ll; + u = l.d; + for(mm = 0; mm <= testNumV; mm++) { + m.d = vStart.d + stepV * mm; + v = m.d; + computeResult5param(x, y, z, u, v, mpfrResult); + computeOrcle5param(x, y, z, u, v, mpfrOrcle); + // orcle.d = mpfr_get_d(mpfrOrcle, MPFR_RNDN); + // result.d = mpfr_get_d(mpfrResult, MPFR_RNDN); + #ifdef SINGLE + reUlp = computeUlpDiffF(mpfrOrcle, mpfrResult); + #else // compute Double ULP as default + reUlp = computeUlpDiff(mpfrOrcle, mpfrResult); + #endif + + if (reUlp > maxReUlp) { + // maxInputX = j; + maxReUlp = reUlp; + } + } + } + } + } + fprintf(f, "%.16le\t%.16e\n", y, maxReUlp); + } + fclose(f); +} + +void sample5paramZ(DL xStart, DL xEnd, DL yStart, DL yEnd, DL zStart, DL zEnd, DL uStart, DL uEnd, DL vStart, DL vEnd, unsigned long int testNumX, unsigned long int testNumY, unsigned long int testNumZ, unsigned long int testNumU, unsigned long int testNumV, const char* uniqueLabel, const char *fileNameKernel, int myid, int iStartLocal, int iEndLocal) +{ + DL i, j, k, l, m; + // DL maxInputX, maxInputY, maxInputZ, orcle, result; + int ii, jj, kk, ll, mm; + double x, y, z, u, v, reUlp, maxReUlp, lenX, lenY, lenZ, lenU, lenV; + + // mpfr + mpfr_t mpfrOrcle, mpfrResult; + mpfr_inits2(PRECISION, mpfrOrcle, mpfrResult, (mpfr_ptr) 0); + + // write error data to file + char *directory = "outputs"; + char *suffix = "sample_Z"; + char *fileNameSample; + FILE *f; + fileNameSample = (char *) calloc(strlen(directory) + strlen(uniqueLabel) + strlen(fileNameKernel) + strlen(suffix) + 128, sizeof(char)); + sprintf(fileNameSample, "%s/%s/%s_%s_%02d.txt", directory, uniqueLabel, fileNameKernel, suffix, myid); + // printf("%s\n", fileNameSample); + if ((f = fopen(fileNameSample, "w")) == NULL) { + printf("Error opening file %s.\n", fileNameSample); + exit(0); + } + + // loop boundary + lenX = xEnd.d - xStart.d; + lenY = yEnd.d - yStart.d; + lenZ = zEnd.d - zStart.d; + lenU = uEnd.d - uStart.d; + lenV = vEnd.d - vStart.d; + double stepX = lenX / (double)testNumX; + double stepY = lenY / (double)testNumY; + double stepZ = lenZ / (double)testNumZ; + double stepU = lenU / (double)testNumU; + double stepV = lenV / (double)testNumV; + + // Real number average + // 固定z值,求不同x值下的最大误差 + for(ii = iStartLocal; ii <= iEndLocal; ii++) { + i.d = zStart.d + stepZ * ii; + z = i.d; + maxReUlp = 0; + for(jj = 0; jj <= testNumX; jj++) { + j.d = xStart.d + stepX * jj; + x = j.d; + for(kk = 0; kk <= testNumY; kk++) { + k.d = yStart.d + stepY * kk; + y = k.d; + for(ll = 0; ll <= testNumU; ll++) { + l.d = uStart.d + stepU * ll; + u = l.d; + for(mm = 0; mm <= testNumV; mm++) { + m.d = vStart.d + stepV * mm; + v = m.d; + computeResult5param(x, y, z, u, v, mpfrResult); + computeOrcle5param(x, y, z, u, v, mpfrOrcle); + // orcle.d = mpfr_get_d(mpfrOrcle, MPFR_RNDN); + // result.d = mpfr_get_d(mpfrResult, MPFR_RNDN); + #ifdef SINGLE + reUlp = computeUlpDiffF(mpfrOrcle, mpfrResult); + #else // compute Double ULP as default + reUlp = computeUlpDiff(mpfrOrcle, mpfrResult); + #endif + + if (reUlp > maxReUlp) { + // maxInputX = j; + maxReUlp = reUlp; + } + } + } + } + } + fprintf(f, "%.16le\t%.16e\n", z, maxReUlp); + } + fclose(f); +} + +void sample5paramU(DL xStart, DL xEnd, DL yStart, DL yEnd, DL zStart, DL zEnd, DL uStart, DL uEnd, DL vStart, DL vEnd, unsigned long int testNumX, unsigned long int testNumY, unsigned long int testNumZ, unsigned long int testNumU, unsigned long int testNumV, const char* uniqueLabel, const char *fileNameKernel, int myid, int iStartLocal, int iEndLocal) +{ + DL i, j, k, l, m; + // DL maxInputX, maxInputY, maxInputZ, orcle, result; + int ii, jj, kk, ll, mm; + double x, y, z, u, v, reUlp, maxReUlp, lenX, lenY, lenZ, lenU, lenV; + + // mpfr + mpfr_t mpfrOrcle, mpfrResult; + mpfr_inits2(PRECISION, mpfrOrcle, mpfrResult, (mpfr_ptr) 0); + + // write error data to file + char *directory = "outputs"; + char *suffix = "sample_U"; + char *fileNameSample; + FILE *f; + fileNameSample = (char *) calloc(strlen(directory) + strlen(uniqueLabel) + strlen(fileNameKernel) + strlen(suffix) + 128, sizeof(char)); + sprintf(fileNameSample, "%s/%s/%s_%s_%02d.txt", directory, uniqueLabel, fileNameKernel, suffix, myid); + // printf("%s\n", fileNameSample); + if ((f = fopen(fileNameSample, "w")) == NULL) { + printf("Error opening file %s.\n", fileNameSample); + exit(0); + } + + // loop boundary + lenX = xEnd.d - xStart.d; + lenY = yEnd.d - yStart.d; + lenZ = zEnd.d - zStart.d; + lenU = uEnd.d - uStart.d; + lenV = vEnd.d - vStart.d; + double stepX = lenX / (double)testNumX; + double stepY = lenY / (double)testNumY; + double stepZ = lenZ / (double)testNumZ; + double stepU = lenU / (double)testNumU; + double stepV = lenV / (double)testNumV; + + // Real number average + // 固定u值,求不同x值下的最大误差 + for(ii = iStartLocal; ii <= iEndLocal; ii++) { + i.d = uStart.d + stepU * ii; + u = i.d; + maxReUlp = 0; + for(jj = 0; jj <= testNumX; jj++) { + j.d = xStart.d + stepX * jj; + x = j.d; + for(kk = 0; kk <= testNumY; kk++) { + k.d = yStart.d + stepY * kk; + y = k.d; + for(ll = 0; ll <= testNumZ; ll++) { + l.d = uStart.d + stepZ * ll; + z = l.d; + for(mm = 0; mm <= testNumV; mm++) { + m.d = vStart.d + stepV * mm; + v = m.d; + computeResult5param(x, y, z, u, v, mpfrResult); + computeOrcle5param(x, y, z, u, v, mpfrOrcle); + // orcle.d = mpfr_get_d(mpfrOrcle, MPFR_RNDN); + // result.d = mpfr_get_d(mpfrResult, MPFR_RNDN); + #ifdef SINGLE + reUlp = computeUlpDiffF(mpfrOrcle, mpfrResult); + #else // compute Double ULP as default + reUlp = computeUlpDiff(mpfrOrcle, mpfrResult); + #endif + + if (reUlp > maxReUlp) { + // maxInputX = j; + maxReUlp = reUlp; + } + } + } + } + } + fprintf(f, "%.16le\t%.16e\n", u, maxReUlp); + } + fclose(f); +} + +void sample5paramV(DL xStart, DL xEnd, DL yStart, DL yEnd, DL zStart, DL zEnd, DL uStart, DL uEnd, DL vStart, DL vEnd, unsigned long int testNumX, unsigned long int testNumY, unsigned long int testNumZ, unsigned long int testNumU, unsigned long int testNumV, const char* uniqueLabel, const char *fileNameKernel, int myid, int iStartLocal, int iEndLocal) +{ + DL i, j, k, l, m; + // DL maxInputX, maxInputY, maxInputZ, orcle, result; + int ii, jj, kk, ll, mm; + double x, y, z, u, v, reUlp, maxReUlp, lenX, lenY, lenZ, lenU, lenV; + + // mpfr + mpfr_t mpfrOrcle, mpfrResult; + mpfr_inits2(PRECISION, mpfrOrcle, mpfrResult, (mpfr_ptr) 0); + + // write error data to file + char *directory = "outputs"; + char *suffix = "sample_V"; + char *fileNameSample; + FILE *f; + fileNameSample = (char *) calloc(strlen(directory) + strlen(uniqueLabel) + strlen(fileNameKernel) + strlen(suffix) + 128, sizeof(char)); + sprintf(fileNameSample, "%s/%s/%s_%s_%02d.txt", directory, uniqueLabel, fileNameKernel, suffix, myid); + // printf("%s\n", fileNameSample); + if ((f = fopen(fileNameSample, "w")) == NULL) { + printf("Error opening file %s.\n", fileNameSample); + exit(0); + } + + // loop boundary + lenX = xEnd.d - xStart.d; + lenY = yEnd.d - yStart.d; + lenZ = zEnd.d - zStart.d; + lenU = uEnd.d - uStart.d; + lenV = vEnd.d - vStart.d; + double stepX = lenX / (double)testNumX; + double stepY = lenY / (double)testNumY; + double stepZ = lenZ / (double)testNumZ; + double stepU = lenU / (double)testNumU; + double stepV = lenV / (double)testNumV; + + // Real number average + // 固定u值,求不同x值下的最大误差 + for(ii = iStartLocal; ii <= iEndLocal; ii++) { + i.d = vStart.d + stepV * ii; + v = i.d; + maxReUlp = 0; + for(jj = 0; jj <= testNumX; jj++) { + j.d = xStart.d + stepX * jj; + x = j.d; + for(kk = 0; kk <= testNumY; kk++) { + k.d = yStart.d + stepY * kk; + y = k.d; + for(ll = 0; ll <= testNumZ; ll++) { + l.d = uStart.d + stepZ * ll; + z = l.d; + for(mm = 0; mm <= testNumU; mm++) { + m.d = uStart.d + stepU * mm; + u = m.d; + computeResult5param(x, y, z, u, v, mpfrResult); + computeOrcle5param(x, y, z, u, v, mpfrOrcle); + // orcle.d = mpfr_get_d(mpfrOrcle, MPFR_RNDN); + // result.d = mpfr_get_d(mpfrResult, MPFR_RNDN); + #ifdef SINGLE + reUlp = computeUlpDiffF(mpfrOrcle, mpfrResult); + #else // compute Double ULP as default + reUlp = computeUlpDiff(mpfrOrcle, mpfrResult); + #endif + + if (reUlp > maxReUlp) { + // maxInputX = j; + maxReUlp = reUlp; + } + } + } + } + } + fprintf(f, "%.16le\t%.16e\n", v, maxReUlp); + } + fclose(f); +} + +int main(int argc, char *argv[]) +{ + // parallel + int myid, numProcs; + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &myid); + MPI_Comm_size(MPI_COMM_WORLD, &numProcs); + + // parameters init + DL xStart, xEnd, yStart, yEnd, zStart, zEnd, uStart, uEnd, vStart, vEnd; + unsigned long int drawNum, findMaxNum; + xStart.d = 0.1; + xEnd.d = 100; + yStart.d = 0.1; + yEnd.d = 100; + zStart.d = 0.1; + zEnd.d = 100; + uStart.d = 0.1; + uEnd.d = 100; + vStart.d = 0.1; + vEnd.d = 100; + drawNum = TESTNUMX; + findMaxNum = TESTNUMY; + + char *fileNameKernel; + fileNameKernel = calloc(256, sizeof(char)); + char *uniqueLabel; + uniqueLabel = calloc(256, sizeof(char)); + + if(argc == 15) { + xStart.d = strtod(argv[1], NULL); + xEnd.d = strtod(argv[2], NULL); + yStart.d = strtod(argv[3], NULL); + yEnd.d = strtod(argv[4], NULL); + zStart.d = strtod(argv[5], NULL); + zEnd.d = strtod(argv[6], NULL); + uStart.d = strtod(argv[7], NULL); + uEnd.d = strtod(argv[8], NULL); + vStart.d = strtod(argv[9], NULL); + vEnd.d = strtod(argv[10], NULL); + drawNum = strtod(argv[11], NULL); + findMaxNum = strtod(argv[12], NULL); + strcpy(fileNameKernel, argv[13]); + strcpy(uniqueLabel, argv[14]); + } else { + printf("Usage: ./sample4paramParallel.out xStart xEnd yStart yEnd zStart zEnd uStart uEnd vStart vEnd drawNum findMaxNum fileNameKernel uniqueLabel\n"); + exit(EXIT_FAILURE); + } + + // local parameters init + int lenLocal = drawNum / numProcs; + int iStartLocal; + iStartLocal = myid * lenLocal; + int iEndLocal; + if (myid != numProcs - 1) + { + iEndLocal = (myid + 1) * lenLocal - 1; + } + else + { + iEndLocal = drawNum; + } + + sample5paramX(xStart, xEnd, yStart, yEnd, zStart, zEnd, uStart, uEnd, vStart, vEnd, drawNum, findMaxNum, findMaxNum, findMaxNum, findMaxNum, uniqueLabel, fileNameKernel, myid, iStartLocal, iEndLocal); + sample5paramY(xStart, xEnd, yStart, yEnd, zStart, zEnd, uStart, uEnd, vStart, vEnd, findMaxNum, drawNum, findMaxNum, findMaxNum, findMaxNum, uniqueLabel, fileNameKernel, myid, iStartLocal, iEndLocal); + sample5paramZ(xStart, xEnd, yStart, yEnd, zStart, zEnd, uStart, uEnd, vStart, vEnd, findMaxNum, findMaxNum, drawNum, findMaxNum, findMaxNum, uniqueLabel, fileNameKernel, myid, iStartLocal, iEndLocal); + sample5paramU(xStart, xEnd, yStart, yEnd, zStart, zEnd, uStart, uEnd, vStart, vEnd, findMaxNum, findMaxNum, findMaxNum, drawNum, findMaxNum, uniqueLabel, fileNameKernel, myid, iStartLocal, iEndLocal); + sample5paramV(xStart, xEnd, yStart, yEnd, zStart, zEnd, uStart, uEnd, vStart, vEnd, findMaxNum, findMaxNum, findMaxNum, findMaxNum, drawNum, uniqueLabel, fileNameKernel, myid, iStartLocal, iEndLocal); + + // clear + free(uniqueLabel); + free(fileNameKernel); + MPI_Finalize(); + return 0; +} \ No newline at end of file diff --git a/srcTest/test5paramFPEDParallel.c b/srcTest/test5paramFPEDParallel.c new file mode 100644 index 0000000..02de0ff --- /dev/null +++ b/srcTest/test5paramFPEDParallel.c @@ -0,0 +1,346 @@ +#include "common.h" +#include "mpi.h" + +struct errorInfo { + double sumError; + double maxError; + double maxInputX0; + double maxInputX1; + double maxInputX2; + double maxInputX3; + double maxInputX4; +}; + +#ifndef SUFFIX +#define SUFFIX orgin +#endif +#ifndef EXPRESSION +#define EXPRESSION sum +#endif + +#define EXPRESSIONMINE ADDSUFFIX(EXPRESSION, SUFFIX) +#define SUFFIX1 mpfr +#define EXPRESSIONMPFR ADDSUFFIX(EXPRESSION, SUFFIX1) + +#define TESTNUMX0 24 +#define TESTNUMX1 24 +#define TESTNUMX2 24 +#define TESTNUMX3 24 +#define TESTNUMX4 24 +// #define FP +// #define DEBUG +#ifndef ERRFILE +#define ERRFILE 0 +#endif +double EXPRESSIONMPFR(double, double, double, double, double, mpfr_t); +double EXPRESSIONMINE(double, double, double, double, double); + +int computeOrcle5param(double x0, double x1, double x2, double x3, double x4, mpfr_t orcle) { + return EXPRESSIONMPFR(x0, x1, x2, x3, x4, orcle); +} + +int computeResult5param(double x0, double x1, double x2, double x3, double x4, mpfr_t mpfrResult) { + int status = 1; + + double result = EXPRESSIONMINE(x0, x1, x2, x3, x4); + mpfr_set_d(mpfrResult, result, MPFR_RNDN); + + return status; +} + +struct errorInfo test5paramFPEDParallel(unsigned long int testNumX0, unsigned long int testNumX1, unsigned long int testNumX2, unsigned long int testNumX3, unsigned long int testNumX4, const char* uniqueLabel, const char* fileNameKernel, int myid, int i0StartLocal, int i0EndLocal, int i1StartLocal, int i1EndLocal, int i2StartLocal, int i2EndLocal, int i3StartLocal, int i3EndLocal, int i4StartLocal, int i4EndLocal, double x0startOriginInterval, double x1startOriginInterval, double x2startOriginInterval, double x3startOriginInterval, double x4startOriginInterval, double stepX0, double stepX1, double stepX2, double stepX3, double stepX4) { + DL maxInputX0, maxInputX1, maxInputX2, maxInputX3, maxInputX4; + int i0, i1, i2, i3, i4; + // int flag; + double x0, x1, x2, x3, x4, reUlp, sumError, aveReUlp, maxReUlp, lenX0, lenX1, lenX2, lenX3, lenX4; + + // mpfr + mpfr_t mpfrOrcle, mpfrResult; + mpfr_inits2(PRECISION, mpfrOrcle, mpfrResult, (mpfr_ptr) 0); + + // write error data to file + #if ERRFILE + char *directory = "outputs"; + char *suffix = "sample"; + char *fileNameSample; + FILE *f; + fileNameSample = (char *) calloc(strlen(directory) + strlen(uniqueLabel) + strlen(fileNameKernel) + strlen(suffix) + 128, sizeof(char)); + sprintf(fileNameSample, "%s/%s/%s_%s_%02d.txt", directory, uniqueLabel, fileNameKernel, suffix, myid); + // printf("%s\n", fileNameSample); + if ((f = fopen(fileNameSample, "w")) == NULL) { + printf("Error opening file %s.\n", fileNameSample); + exit(0); + } + #endif + + // Real number average + maxReUlp = 0; + // flag = 1; + // size_t testCount = 0; + sumError = 0; + for(i4 = i4StartLocal; i4 <= i4EndLocal; i4++) { + x4 = x4startOriginInterval + stepX4 * i4; + for(i3 = i3StartLocal; i3 <= i3EndLocal; i3++) { + x3 = x3startOriginInterval + stepX3 * i3; + for(i2 = i2StartLocal; i2 <= i2EndLocal; i2++) { + x2 = x2startOriginInterval + stepX2 * i2; + for(i1 = i1StartLocal; i1 <= i1EndLocal; i1++) { + x1 = x1startOriginInterval + stepX1 * i1; + for(i0 = i0StartLocal; i0 <= i0EndLocal; i0++) { + x0 = x0startOriginInterval + stepX0 * i0; + computeResult5param(x0, x1, x2, x3, x4, mpfrResult); + computeOrcle5param(x0, x1, x2, x3, x4, mpfrOrcle); + #ifdef SINGLE + reUlp = computeUlpDiffF(mpfrOrcle, mpfrResult); + #else // compute Double ULP as default + reUlp = computeUlpDiff(mpfrOrcle, mpfrResult); + #endif + // if(reUlp <= 0.5) { + // reUlp = 0; + // } + // if(isfinite(reUlp) == 0) { + // printf("happen to NaN or inf\n"); + // exit(1); + // } + // fprintf(f, "%le\t%le\t%le\t%e\n", x0, x1, x2, reUlp); + if (isnormal(reUlp) != 0) + { + #if ERRFILE + fprintf(f, "%le\t%le\n", x0, reUlp); + #endif + sumError += reUlp; + if (reUlp > maxReUlp) { + // flag = 0; + maxInputX4.d = x4; + maxInputX3.d = x3; + maxInputX2.d = x2; + maxInputX1.d = x1; + maxInputX0.d = x0; + maxReUlp = reUlp; + } + } + } + } + } + } + } + // aveReUlp = sumError / testCount; + // if(flag == 1) { + // printf("all error are 0!!\n"); + // } + // printf("average ulp\tmax ulp\n"); + // printf("%lg\t%lg\n", aveReUlp, maxReUlp); + // printf("\naveReUlp = %lg\nmaxInputX0 = 0x%016lx %lg, maxInputX1 = 0x%016lx %lg, maxInputX2 = 0x%016lx %lg, maxReUlp = %lg\n", aveReUlp, maxInputX0.l, maxInputX0.d, maxInputX1.l, maxInputX1.d, maxInputX2.l, maxInputX2.d, maxReUlp); + #if ERRFILE + // fprintf(f, "\n"); + + // clear + fclose(f); + free(fileNameSample); + #endif + mpfr_clears(mpfrOrcle, mpfrResult, (mpfr_ptr) 0); + struct errorInfo err; + err.sumError = sumError; + err.maxError = maxReUlp; + err.maxInputX0 = maxInputX0.d; + err.maxInputX1 = maxInputX1.d; + err.maxInputX2 = maxInputX2.d; + err.maxInputX3 = maxInputX3.d; + err.maxInputX4 = maxInputX4.d; + return err; +} + +int main(int argc, char **argv) { + // parallel + int myid, numProcs; + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &myid); + MPI_Comm_size(MPI_COMM_WORLD, &numProcs); + MPI_Datatype MPI_errorInfo; + MPI_Type_contiguous(5, MPI_DOUBLE, &MPI_errorInfo); + MPI_Type_commit(&MPI_errorInfo); + + // parameters init + DL x0Start, x0End, x1Start, x1End, x2Start, x2End, x3Start, x3End, x4Start, x4End; + unsigned long int testNumX0, testNumX1, testNumX2, testNumX3, testNumX4; + x0Start.d = 1; + x0End.d = 2; + x1Start.d = 1; + x1End.d = 2; + x2Start.d = 1; + x2End.d = 2; + x3Start.d = 1; + x3End.d = 2; + x4Start.d = 1; + x4End.d = 2; + int x0startNowIdx, x1startNowIdx, x2startNowIdx, x3startNowIdx, x4startNowIdx; + double x0startOriginInterval, x1startOriginInterval, x2startOriginInterval, x3startOriginInterval, x4startOriginInterval; + double stepX0, stepX1, stepX2, stepX3, stepX4; + + testNumX0 = TESTNUMX0; + testNumX1 = TESTNUMX1; + testNumX2 = TESTNUMX2; + testNumX3 = TESTNUMX3; + testNumX4 = TESTNUMX4; + + char *fileNameKernel; + fileNameKernel = calloc(256, sizeof(char)); + char *uniqueLabel; + uniqueLabel = calloc(256, sizeof(char)); + if(argc == 33) { + x0Start.d = strtod(argv[1], NULL); + x0End.d = strtod(argv[2], NULL); + x1Start.d = strtod(argv[3], NULL); + x1End.d = strtod(argv[4], NULL); + x2Start.d = strtod(argv[5], NULL); + x2End.d = strtod(argv[6], NULL); + x3Start.d = strtod(argv[7], NULL); + x3End.d = strtod(argv[8], NULL); + x4Start.d = strtod(argv[9], NULL); + x4End.d = strtod(argv[10], NULL); + testNumX0 = strtod(argv[11], NULL); + testNumX1 = strtod(argv[12], NULL); + testNumX2 = strtod(argv[13], NULL); + testNumX3 = strtod(argv[14], NULL); + testNumX4 = strtod(argv[15], NULL); + x0startNowIdx = atoi(argv[16]); + x1startNowIdx = atoi(argv[17]); + x2startNowIdx = atoi(argv[18]); + x3startNowIdx = atoi(argv[19]); + x4startNowIdx = atoi(argv[20]); + x0startOriginInterval = strtod(argv[21], NULL); + x1startOriginInterval = strtod(argv[22], NULL); + x2startOriginInterval = strtod(argv[23], NULL); + x3startOriginInterval = strtod(argv[24], NULL); + x4startOriginInterval = strtod(argv[25], NULL); + stepX0 = strtod(argv[26], NULL); + stepX1 = strtod(argv[27], NULL); + stepX2 = strtod(argv[28], NULL); + stepX3 = strtod(argv[29], NULL); + stepX4 = strtod(argv[30], NULL); + strcpy(fileNameKernel, argv[31]); + strcpy(uniqueLabel, argv[32]); + // } else if(argc == 18) { + // x0Start.d = strtod(argv[1], NULL); + // x0End.d = strtod(argv[2], NULL); + // x1Start.d = strtod(argv[3], NULL); + // x1End.d = strtod(argv[4], NULL); + // x2Start.d = strtod(argv[5], NULL); + // x2End.d = strtod(argv[6], NULL); + // x0startNowIdx = atoi(argv[7]); + // x1startNowIdx = atoi(argv[8]); + // x2startNowIdx = atoi(argv[9]); + // x0startOriginInterval = strtod(argv[10], NULL); + // x1startOriginInterval = strtod(argv[11], NULL); + // x2startOriginInterval = strtod(argv[12], NULL); + // stepX0 = strtod(argv[13], NULL); + // stepX1 = strtod(argv[14], NULL); + // stepX2 = strtod(argv[15], NULL); + // strcpy(fileNameKernel, argv[16]); + // strcpy(uniqueLabel, argv[17]); + // } else if(argc == 15) { + // testNumX0 = strtod(argv[1], NULL); + // testNumX1 = strtod(argv[2], NULL); + // testNumX2 = strtod(argv[3], NULL); + // x0startNowIdx = atoi(argv[4]); + // x1startNowIdx = atoi(argv[5]); + // x2startNowIdx = atoi(argv[6]); + // x0startOriginInterval = strtod(argv[7], NULL); + // x1startOriginInterval = strtod(argv[8], NULL); + // x2startOriginInterval = strtod(argv[9], NULL); + // stepX0 = strtod(argv[10], NULL); + // stepX1 = strtod(argv[11], NULL); + // stepX2 = strtod(argv[12], NULL); + // strcpy(fileNameKernel, argv[13]); + // strcpy(uniqueLabel, argv[14]); + } else { + printf("Usage: ./test3paramFPEDParallel.exe [x0Start x0End x1Start x1End x2Start x2End testNumX0 testNumX1 testNumX2 fileNameKernel]\n"); + printf("Usage: if no correct input:\n"); + printf("Usage: \tthe fixed inputs [%g %g %g %g %g %g %g %g %lu %lu %lu %lu] will be used\n", x0Start.d, x0End.d, x1Start.d, x1End.d, x2Start.d, x2End.d, x3Start.d, x3End.d, testNumX0, testNumX1, testNumX2, testNumX3); + } + + // if(myid == 0) { + // printf("\n---------------------------------------------------start test3paramFPEDParallel\n"); + // printf("Parameters: x0Start: %lg, x0End: %lg, x1Start: %lg, x1End: %lg, x2Start: %lg, x2End: %lg, testNumX0 = %lu, testNumX1 = %lu, testNumX2 = %lu, fileNameKernel: %s\n", x0Start.d, x0End.d, x1Start.d, x1End.d, x2Start.d, x2End.d, testNumX0, testNumX1, testNumX2, fileNameKernel); + // } + + // local parameters init + int lenX4Local = testNumX4 / numProcs; + int i4StartLocal; + i4StartLocal = x4startNowIdx + myid * lenX4Local; + int i4EndLocal; + if(myid != numProcs - 1) { + i4EndLocal = x4startNowIdx + (myid + 1) * lenX4Local - 1; + } else { + i4EndLocal = x4startNowIdx + testNumX4; + } + int i3StartLocal = x3startNowIdx; + int i3EndLocal = x3startNowIdx + testNumX3; + int i2StartLocal = x2startNowIdx; + int i2EndLocal = x2startNowIdx + testNumX2; + int i1StartLocal = x1startNowIdx; + int i1EndLocal = x1startNowIdx + testNumX1; + int i0StartLocal = x0startNowIdx; + int i0EndLocal = x0startNowIdx + testNumX0; + + // call the error test function + struct errorInfo err = test5paramFPEDParallel(testNumX0, testNumX1, testNumX2, testNumX3, testNumX4, uniqueLabel, fileNameKernel, myid, i0StartLocal, i0EndLocal, i1StartLocal, i1EndLocal, i2StartLocal, i2EndLocal, i3StartLocal, i3EndLocal, i4StartLocal, i4EndLocal, x0startOriginInterval, x1startOriginInterval, x2startOriginInterval, x3startOriginInterval, x4startOriginInterval, stepX0, stepX1, stepX2, stepX3, stepX4); + + // gather errors and find the max + struct errorInfo *errs; + errs = (struct errorInfo *)calloc(numProcs, sizeof(struct errorInfo)); + MPI_Gather(&err, 1, MPI_errorInfo, errs, 1, MPI_errorInfo, 0, MPI_COMM_WORLD); + if(myid == 0) + { + double maxError = -1; + double aveError = 0; + double errTmp = -1; + int maxErrorIdx = -1; + for(int i = 0; i < numProcs; i++) + { + errTmp = errs[i].maxError; + if(errTmp > maxError) + { + maxError = errTmp; + maxErrorIdx = i; + } + aveError += errs[i].sumError; + } + aveError = aveError / (testNumX0 * testNumX1 * testNumX2 * testNumX3 * testNumX4); + DL maxInputX0, maxInputX1, maxInputX2, maxInputX3, maxInputX4; + maxInputX0.d = errs[maxErrorIdx].maxInputX0; + maxInputX1.d = errs[maxErrorIdx].maxInputX1; + maxInputX2.d = errs[maxErrorIdx].maxInputX2; + maxInputX3.d = errs[maxErrorIdx].maxInputX3; + maxInputX4.d = errs[maxErrorIdx].maxInputX4; + + FILE *fErr; + char *directory = "./outputs"; + char *suffixErr = "error.txt"; + char *fileNameErr; + fileNameErr = (char *) calloc(strlen(directory) + strlen(uniqueLabel) + strlen(fileNameKernel) + strlen(suffixErr) + 128, sizeof(char)); + sprintf(fileNameErr, "%s/%s/%s_%s", directory, uniqueLabel, fileNameKernel, suffixErr); + if ((fErr = fopen(fileNameErr, "w")) == NULL) + { + printf("Error opening file %s.\n", fileNameErr); + exit(0); + } + printf("average ulp\tmax ulp\n"); + printf("%.16le\t%.16le\n", aveError, maxError); + // printf("\naveReUlp = %lg\nmaxInputX0 = 0x%016lx %lg, maxInputX1 = 0x%016lx %lg, maxInputX2 = 0x%016lx %lg, maxReUlp = %lg\n", aveError, maxInputX0.l, maxInputX0.d, maxInputX1.l, maxInputX1.d, maxInputX2.l, maxInputX2.d, maxError); + fprintf(fErr, "average ulp\tmax ulp\n"); + fprintf(fErr, "%.16le\t%.16le\n", aveError, maxError); + fprintf(fErr, "\naveReUlp = %lg\nmaxInputX0 = 0x%016lx %lg, maxInputX1 = 0x%016lx %lg, maxInputX2 = 0x%016lx %lg, maxInputX3 = 0x%016lx %lg, maxInputX4 = 0x%016lx %lg, maxReUlp = %lg\n", aveError, maxInputX0.l, maxInputX0.d, maxInputX1.l, maxInputX1.d, maxInputX2.l, maxInputX2.d, maxInputX3.l, maxInputX3.d, maxInputX4.l, maxInputX4.d, maxError); + + free(fileNameErr); + free(uniqueLabel); + fclose(fErr); + } + + // clear + free(fileNameKernel); + free(errs); + MPI_Type_free(&MPI_errorInfo); + MPI_Finalize(); + return 0; +} \ No newline at end of file -- Gitee From c256986b4845736af8064e503462f9b4b28e9b4a Mon Sep 17 00:00:00 2001 From: hjwLab Date: Thu, 13 Apr 2023 21:19:54 +0800 Subject: [PATCH 20/32] fix a bug --- src/main.cpp | 2 +- src/polyRewrite.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7b6e118..5e66779 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -207,7 +207,7 @@ int main() } else if (dimension == 4) { - sampleScale = 96; + sampleScale = 12; } else if (dimension == 5) { diff --git a/src/polyRewrite.cpp b/src/polyRewrite.cpp index 987fd84..4dd5a18 100644 --- a/src/polyRewrite.cpp +++ b/src/polyRewrite.cpp @@ -819,8 +819,8 @@ vector createExpr(const vector &monomials) // if consider commutative law,hasCommutativeLaw is true,and the result is more. bool isFullyCofactor = true; // the key to control the rewrite results.IsFullyCofactor is true,the result is more. for(int i = 0; i < (int)vars.size();i++){ - int term[10] = {0}; // {0, 1, 2, 3, 4, 5}; - double coefficient[10] = {0.0}; // {1.0, 2.0, 3.0, 4.0, 5.0, 6.0}; + int term[128] = {0}; // {0, 1, 2, 3, 4, 5}; + double coefficient[128] = {0.0}; // {1.0, 2.0, 3.0, 4.0, 5.0, 6.0}; variable = vars.at(i); if(isFullyCofactor){ vector sortAftermonomials = sortMonomials(variable,monomials); -- Gitee From 88f825139020eaf5610e13062e0783bdd74db685 Mon Sep 17 00:00:00 2001 From: hjwLab Date: Fri, 14 Apr 2023 00:45:28 +0800 Subject: [PATCH 21/32] fix a bug and change pov-ray to pov_ray --- benchMark.txt | 2 +- benchMarkInterval.txt | 2 +- src/geneCode.cpp | 4 ++-- src/main.cpp | 14 +++++--------- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/benchMark.txt b/benchMark.txt index d208078..9f2f6a6 100644 --- a/benchMark.txt +++ b/benchMark.txt @@ -103,4 +103,4 @@ polyIDX0 (((-0.85073072819636686 * x1) + (-0.98664016916368502 * x2) + (1.380951 polyIDX1 (((0.18424469636214999 * x1) + (0.45123431334216657 * x2) + (-0.80794264540764449 * x3) + (-0.45071126534400952 * x4)) * ((0.18424469636214999 * x1) + (0.45123431334216657 * x2) + (-0.80794264540764449 * x3) + (-0.45071126534400952 * x4)) * ((0.18424469636214999 * x1) + (0.45123431334216657 * x2) + (-0.80794264540764449 * x3) + (-0.45071126534400952 * x4)) - ((0.052100253064028955 * x1) + (-0.8942341911807864 * x2) + (0.40478255170032273 * x3) + (-0.93774690197704236 * x4)) * ((0.052100253064028955 * x1) + (-0.8942341911807864 * x2) + (0.40478255170032273 * x3) + (-0.93774690197704236 * x4)) * ((0.052100253064028955 * x1) + (-0.8942341911807864 * x2) + (0.40478255170032273 * x3) + (-0.93774690197704236 * x4))) polyIDX2 (((0.052100253064028955 * x1) + (-0.8942341911807864 * x2) + (0.40478255170032273 * x3) + (-0.93774690197704236 * x4)) * ((0.052100253064028955 * x1) + (-0.8942341911807864 * x2) + (0.40478255170032273 * x3) + (-0.93774690197704236 * x4)) * ((0.052100253064028955 * x1) + (-0.8942341911807864 * x2) + (0.40478255170032273 * x3) + (-0.93774690197704236 * x4)) - ((-0.85073072819636686 * x1) + (-0.98664016916368502 * x2) + (1.3809517485817782 * x3) + (1.8653450939330991 * x4)) * ((-0.85073072819636686 * x1) + (-0.98664016916368502 * x2) + (1.3809517485817782 * x3) + (1.8653450939330991 * x4)) * ((-0.85073072819636686 * x1) + (-0.98664016916368502 * x2) + (1.3809517485817782 * x3) + (1.8653450939330991 * x4))) example5param x0+x1+x2+x3+x4 -pov-ray x1*cos(x2)*cos(x3)+x4*cos(x2)+x5*cos(x2)*sin(x3) \ No newline at end of file +pov_ray x1*cos(x2)*cos(x3)+x4*cos(x2)+x5*cos(x2)*sin(x3) \ No newline at end of file diff --git a/benchMarkInterval.txt b/benchMarkInterval.txt index 4a437fe..40fa42e 100644 --- a/benchMarkInterval.txt +++ b/benchMarkInterval.txt @@ -103,4 +103,4 @@ 3 9 1.5 5 -2 10 -1 3.5 3 9 1.5 5 -2 10 -1 3.5 0 1 0 1 0 1 0 1 0 1 --1 1 -3.14159265358979323846264 3.14159265358979323846264 -3.14159265358979323846264 3.14159265358979323846264 -1 1 -1 1 \ No newline at end of file +-1 1 -3.14159265358979323846264 3.14159265358979323846264 -3.14159265358979323846264 3.14159265358979323846264 -1 1 -1 1 \ No newline at end of file diff --git a/src/geneCode.cpp b/src/geneCode.cpp index 0428a51..1ed174c 100644 --- a/src/geneCode.cpp +++ b/src/geneCode.cpp @@ -305,7 +305,7 @@ string geneHerbieCode(string uniqueLabel) {"polyIDX1", ""}, {"polyIDX2", ""}, {"example5param", "(x0+x1)+(x2+x3)+x4"}, - {"pov-ray", ""}, + {"pov_ray", ""}, }; auto pos = benchmarkHerbie.find(uniqueLabel); @@ -397,7 +397,7 @@ string geneDaisyCode(string uniqueLabel) {"polyIDX1", ""}, {"polyIDX2", ""}, {"example5param", "(x0+x1)+(x2+x3)+x4"}, - {"pov-ray", ""}, + {"pov_ray", ""}, }; auto pos = benchmarkDaisy.find(uniqueLabel); diff --git a/src/main.cpp b/src/main.cpp index 5e66779..455cfb3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -92,7 +92,7 @@ map> benchmarkThresholds = { {"polyIDX1", {2, 2, 2, 2}}, {"polyIDX2", {2, 2, 2, 2}}, {"example5param", {2, 2, 2, 2, 2}}, - {"pov-ray", {2, 2, 2, 2, 2}}, + {"pov_ray", {2, 2, 2, 2, 2}}, }; //===----------------------------------------------------------------------===// @@ -207,15 +207,11 @@ int main() } else if (dimension == 4) { - sampleScale = 12; - } - else if (dimension == 5) - { - sampleScale = 24; + sampleScale = 16; } else { - sampleScale = 10; + sampleScale = 8; } vector scales; for (int i = 0; i < dimension; i++) @@ -387,7 +383,7 @@ int main() suffixTmps.push_back(suffixTmp); suffixTmp = exprOriginBest + "_U"; suffixTmps.push_back(suffixTmp); - vector scales{384, 96}; // actually are drawNum and findMaxNum, so only need 2 numbers + vector scales{512, 16}; // actually are drawNum and findMaxNum, so only need 2 numbers sampleError(uniqueLabel, exprOriginBest, intervals, scales); } else if (dimension == 5) @@ -402,7 +398,7 @@ int main() suffixTmps.push_back(suffixTmp); suffixTmp = exprOriginBest + "_V"; suffixTmps.push_back(suffixTmp); - vector scales{384, 24}; // actually are drawNum and findMaxNum, so only need 2 numbers + vector scales{512, 8}; // actually are drawNum and findMaxNum, so only need 2 numbers sampleError(uniqueLabel, exprOriginBest, intervals, scales); } else -- Gitee From d030ad6863a3db061abdf318e71b65d126cd73ec Mon Sep 17 00:00:00 2001 From: hjwLab Date: Fri, 14 Apr 2023 01:01:16 +0800 Subject: [PATCH 22/32] improve write_to_file --- include/basic.hpp | 2 +- src/basic.cpp | 81 ++++++++++++++++++++++++----------------------- 2 files changed, 42 insertions(+), 41 deletions(-) diff --git a/include/basic.hpp b/include/basic.hpp index eeff8cc..ec01f59 100644 --- a/include/basic.hpp +++ b/include/basic.hpp @@ -259,7 +259,7 @@ vector> combination(const int num, const vector& indexs); size_t combination(size_t k, size_t n); -void write_to_file(const string &uniqueLabel, const string &exprOriginBest, const vector &numIntervalsSoloBefore, const vector &numIntervalsSoloAfter, const std::vector &data, const std::string &filename); +void write_to_file(const string &uniqueLabel, const string &exprOriginBest, const vector &numIntervalsSoloBefore, const vector &numIntervalsSoloAfter, const std::vector thresholds, const std::vector &data, const std::string &filename); void write_to_file_wrapper(string uniqueLabel, string exprOriginBest, int dimension, int numIntervalsBefore, double numOfIntervals, const vector &numIntervalsSoloBefore, const vector &numIntervalsSoloAfter, int numOfExprs, vector thresholds, const exprInfo &originExprInfo, const exprInfo &herbieExprInfo, const exprInfo &finalInfo, double originPerformance, double elapsed_seconds, double init_seconds, double matlab_seconds, double regime_seconds, double rewrite_seconds, double final_seconds, double matlabKernelTime); // } // end anonymous namespace diff --git a/src/basic.cpp b/src/basic.cpp index 97f1691..9483ebc 100644 --- a/src/basic.cpp +++ b/src/basic.cpp @@ -742,7 +742,7 @@ size_t combination(size_t k, size_t n) return factorial(n) / (factorial(k) * factorial(n - k)); } -void write_to_file(const string &uniqueLabel, const string &exprOriginBest, const vector &numIntervalsSoloBefore, const vector &numIntervalsSoloAfter, const std::vector &data, const std::string &filename) +void write_to_file(const string &uniqueLabel, const string &exprOriginBest, const vector &numIntervalsSoloBefore, const vector &numIntervalsSoloAfter, const std::vector thresholds, const std::vector &data, const std::string &filename) { std::ofstream outputFile; outputFile.open(filename, std::ios::out | std::ios::app); @@ -753,6 +753,7 @@ void write_to_file(const string &uniqueLabel, const string &exprOriginBest, cons outputFile << exprOriginBest << ", "; outputFile << fmt::format("\"{}\"", numIntervalsSoloBefore) << ", "; outputFile << fmt::format("\"{}\"", numIntervalsSoloAfter) << ", "; + outputFile << fmt::format("\"{}\"", thresholds) << ", "; for (const auto &val : data) { @@ -780,44 +781,44 @@ void write_to_file_wrapper(string uniqueLabel, string exprOriginBest, int dimens summaryData.push_back(numIntervalsBefore); summaryData.push_back(numOfIntervals); summaryData.push_back(double(numOfExprs)); - if (thresholds.size() == 1) - { - summaryData.push_back(thresholds.at(0)); - summaryData.push_back(-1); - summaryData.push_back(-1); - } - else if (thresholds.size() == 2) - { - summaryData.push_back(thresholds.at(0)); - summaryData.push_back(thresholds.at(1)); - summaryData.push_back(-1); - } - else if (thresholds.size() == 3) - { - summaryData.push_back(thresholds.at(0)); - summaryData.push_back(thresholds.at(1)); - summaryData.push_back(thresholds.at(2)); - } - else if (thresholds.size() == 4) - { - summaryData.push_back(thresholds.at(0)); - summaryData.push_back(thresholds.at(1)); - summaryData.push_back(thresholds.at(2)); - summaryData.push_back(thresholds.at(3)); - } - else if (thresholds.size() == 5) - { - summaryData.push_back(thresholds.at(0)); - summaryData.push_back(thresholds.at(1)); - summaryData.push_back(thresholds.at(2)); - summaryData.push_back(thresholds.at(3)); - summaryData.push_back(thresholds.at(4)); - } - else - { - fprintf(stderr, "ERROR: write_to_file_wrapper: we can not support %ld demision now.\n", thresholds.size()); - exit(EXIT_FAILURE); - } + // if (thresholds.size() == 1) + // { + // summaryData.push_back(thresholds.at(0)); + // summaryData.push_back(-1); + // summaryData.push_back(-1); + // } + // else if (thresholds.size() == 2) + // { + // summaryData.push_back(thresholds.at(0)); + // summaryData.push_back(thresholds.at(1)); + // summaryData.push_back(-1); + // } + // else if (thresholds.size() == 3) + // { + // summaryData.push_back(thresholds.at(0)); + // summaryData.push_back(thresholds.at(1)); + // summaryData.push_back(thresholds.at(2)); + // } + // else if (thresholds.size() == 4) + // { + // summaryData.push_back(thresholds.at(0)); + // summaryData.push_back(thresholds.at(1)); + // summaryData.push_back(thresholds.at(2)); + // summaryData.push_back(thresholds.at(3)); + // } + // else if (thresholds.size() == 5) + // { + // summaryData.push_back(thresholds.at(0)); + // summaryData.push_back(thresholds.at(1)); + // summaryData.push_back(thresholds.at(2)); + // summaryData.push_back(thresholds.at(3)); + // summaryData.push_back(thresholds.at(4)); + // } + // else + // { + // fprintf(stderr, "ERROR: write_to_file_wrapper: we can not support %ld demision now.\n", thresholds.size()); + // exit(EXIT_FAILURE); + // } summaryData.push_back(originExprInfo.aveError); summaryData.push_back(originExprInfo.maxError); summaryData.push_back(herbieExprInfo.aveError); @@ -833,5 +834,5 @@ void write_to_file_wrapper(string uniqueLabel, string exprOriginBest, int dimens summaryData.push_back(rewrite_seconds); summaryData.push_back(final_seconds); summaryData.push_back(matlabKernelTime); - write_to_file(uniqueLabel, exprOriginBest, numIntervalsSoloBefore, numIntervalsSoloAfter, summaryData, "runlog.csv"); + write_to_file(uniqueLabel, exprOriginBest, numIntervalsSoloBefore, numIntervalsSoloAfter, thresholds, summaryData, "runlog.csv"); } -- Gitee From 0efc2c3f592ad699cf7c4c32b4b0a17690157aef Mon Sep 17 00:00:00 2001 From: hjwLab Date: Fri, 14 Apr 2023 04:55:58 +0800 Subject: [PATCH 23/32] update 10 benchmarks' error test --- benchMark.txt | 2 +- detectErrorAll10.sh | 55 ++++++ src/geneCode.cpp | 6 +- srcTest/cav10_2/expr_cav10_2_final.c | 24 +++ srcTest/cav10_2/expr_cav10_2_herbie.c | 9 + srcTest/cav10_2/expr_cav10_2_herbieArfa.c | 58 ++++++ srcTest/cav10_2/expr_cav10_2_herbiePlus.c | 9 + srcTest/cav10_2/expr_cav10_2_mpfr.c | 52 +++++ srcTest/cav10_2/expr_cav10_2_origin.c | 11 ++ srcTest/polyIDX0/expr_polyIDX0_herbie.c | 6 + srcTest/polyIDX0/expr_polyIDX0_herbieArfa.c | 15 ++ srcTest/polyIDX0/expr_polyIDX0_herbiePlus.c | 6 + srcTest/polyIDX1/expr_polyIDX1_daisy.c | 6 + srcTest/polyIDX1/expr_polyIDX1_daisyArfa.c | 10 + srcTest/polyIDX1/expr_polyIDX1_herbie.c | 7 + srcTest/polyIDX1/expr_polyIDX1_herbieArfa.c | 12 ++ srcTest/polyIDX1/expr_polyIDX1_herbiePlus.c | 7 + srcTest/polyIDX2/expr_polyIDX2_daisy.c | 6 + srcTest/polyIDX2/expr_polyIDX2_daisyArfa.c | 11 ++ srcTest/polyIDX2/expr_polyIDX2_herbie.c | 6 + srcTest/polyIDX2/expr_polyIDX2_herbieArfa.c | 16 ++ srcTest/polyIDX2/expr_polyIDX2_herbiePlus.c | 7 + srcTest/smartRoot_2/expr_smartRoot_2_final.c | 20 ++ srcTest/smartRoot_2/expr_smartRoot_2_herbie.c | 20 ++ .../smartRoot_2/expr_smartRoot_2_herbieArfa.c | 8 + srcTest/smartRoot_2/expr_smartRoot_2_mpfr.c | 137 +++++++++++++ srcTest/smartRoot_2/expr_smartRoot_2_origin.c | 11 ++ .../expr_squareRoot3Invalid_2_final.c | 21 ++ .../expr_squareRoot3Invalid_2_herbie.c | 10 + .../expr_squareRoot3Invalid_2_herbieArfa.c | 38 ++++ .../expr_squareRoot3Invalid_2_herbiePlus.c | 10 + .../expr_squareRoot3Invalid_2_mpfr.c | 55 ++++++ .../expr_squareRoot3Invalid_2_origin.c | 11 ++ .../squareRoot3_2/expr_squareRoot3_2_final.c | 20 ++ .../squareRoot3_2/expr_squareRoot3_2_herbie.c | 10 + .../expr_squareRoot3_2_herbieArfa.c | 38 ++++ .../expr_squareRoot3_2_herbiePlus.c | 10 + .../squareRoot3_2/expr_squareRoot3_2_mpfr.c | 55 ++++++ .../squareRoot3_2/expr_squareRoot3_2_origin.c | 11 ++ .../expr_triangleSorted_2_herbie.c | 12 ++ .../expr_triangleSorted_2_herbiePlus.c | 12 ++ .../expr_triangleSorted_2_mpfr.c | 184 ++++++++++++++++++ .../expr_triangleSorted_2_origin.c | 10 + 43 files changed, 1040 insertions(+), 4 deletions(-) create mode 100644 detectErrorAll10.sh create mode 100644 srcTest/cav10_2/expr_cav10_2_final.c create mode 100644 srcTest/cav10_2/expr_cav10_2_herbie.c create mode 100644 srcTest/cav10_2/expr_cav10_2_herbieArfa.c create mode 100644 srcTest/cav10_2/expr_cav10_2_herbiePlus.c create mode 100644 srcTest/cav10_2/expr_cav10_2_mpfr.c create mode 100644 srcTest/cav10_2/expr_cav10_2_origin.c create mode 100644 srcTest/polyIDX0/expr_polyIDX0_herbie.c create mode 100644 srcTest/polyIDX0/expr_polyIDX0_herbieArfa.c create mode 100644 srcTest/polyIDX0/expr_polyIDX0_herbiePlus.c create mode 100644 srcTest/polyIDX1/expr_polyIDX1_daisy.c create mode 100644 srcTest/polyIDX1/expr_polyIDX1_daisyArfa.c create mode 100644 srcTest/polyIDX1/expr_polyIDX1_herbie.c create mode 100644 srcTest/polyIDX1/expr_polyIDX1_herbieArfa.c create mode 100644 srcTest/polyIDX1/expr_polyIDX1_herbiePlus.c create mode 100644 srcTest/polyIDX2/expr_polyIDX2_daisy.c create mode 100644 srcTest/polyIDX2/expr_polyIDX2_daisyArfa.c create mode 100644 srcTest/polyIDX2/expr_polyIDX2_herbie.c create mode 100644 srcTest/polyIDX2/expr_polyIDX2_herbieArfa.c create mode 100644 srcTest/polyIDX2/expr_polyIDX2_herbiePlus.c create mode 100644 srcTest/smartRoot_2/expr_smartRoot_2_final.c create mode 100644 srcTest/smartRoot_2/expr_smartRoot_2_herbie.c create mode 100644 srcTest/smartRoot_2/expr_smartRoot_2_herbieArfa.c create mode 100644 srcTest/smartRoot_2/expr_smartRoot_2_mpfr.c create mode 100644 srcTest/smartRoot_2/expr_smartRoot_2_origin.c create mode 100644 srcTest/squareRoot3Invalid_2/expr_squareRoot3Invalid_2_final.c create mode 100644 srcTest/squareRoot3Invalid_2/expr_squareRoot3Invalid_2_herbie.c create mode 100644 srcTest/squareRoot3Invalid_2/expr_squareRoot3Invalid_2_herbieArfa.c create mode 100644 srcTest/squareRoot3Invalid_2/expr_squareRoot3Invalid_2_herbiePlus.c create mode 100644 srcTest/squareRoot3Invalid_2/expr_squareRoot3Invalid_2_mpfr.c create mode 100644 srcTest/squareRoot3Invalid_2/expr_squareRoot3Invalid_2_origin.c create mode 100644 srcTest/squareRoot3_2/expr_squareRoot3_2_final.c create mode 100644 srcTest/squareRoot3_2/expr_squareRoot3_2_herbie.c create mode 100644 srcTest/squareRoot3_2/expr_squareRoot3_2_herbieArfa.c create mode 100644 srcTest/squareRoot3_2/expr_squareRoot3_2_herbiePlus.c create mode 100644 srcTest/squareRoot3_2/expr_squareRoot3_2_mpfr.c create mode 100644 srcTest/squareRoot3_2/expr_squareRoot3_2_origin.c create mode 100644 srcTest/triangleSorted_2/expr_triangleSorted_2_herbie.c create mode 100644 srcTest/triangleSorted_2/expr_triangleSorted_2_herbiePlus.c create mode 100644 srcTest/triangleSorted_2/expr_triangleSorted_2_mpfr.c create mode 100644 srcTest/triangleSorted_2/expr_triangleSorted_2_origin.c diff --git a/benchMark.txt b/benchMark.txt index 9f2f6a6..3e2ea63 100644 --- a/benchMark.txt +++ b/benchMark.txt @@ -97,7 +97,7 @@ gustafsonExample_2 (exp(((fabs((x - sqrt(((x * x) + 1.0)))) - (1.0 / (x + sqrt(( smartRoot_1 (c * 2.0) / (-3.5 - sqrt(((3.5 * 3.5) - ((3.0 * c) * 4.0)))) smartRoot_2 (-3.5 + sqrt(((3.5 * 3.5) - ((3.0 * c) * 4.0)))) / (3.0 * 2.0) triangleSorted_1 sqrt(((((c + (b + a)) * (a - (c - b))) * (a + (c - b))) * (c + (b - a)))) / 4.0 -triangleSorted_2 sqrt(((((c + (a + b)) * (b - (c - a))) * (b + (c - a))) * (c + (a - b)))) / 4.0; +triangleSorted_2 sqrt(((((c + (a + b)) * (b - (c - a))) * (b + (c - a))) * (c + (a - b)))) / 4.0 example x0+x1+x2+x3 polyIDX0 (((-0.85073072819636686 * x1) + (-0.98664016916368502 * x2) + (1.3809517485817782 * x3) + (1.8653450939330991 * x4)) * ((-0.85073072819636686 * x1) + (-0.98664016916368502 * x2) + (1.3809517485817782 * x3) + (1.8653450939330991 * x4)) * ((-0.85073072819636686 * x1) + (-0.98664016916368502 * x2) + (1.3809517485817782 * x3) + (1.8653450939330991 * x4))) - (((0.18424469636214999 * x1) + (0.45123431334216657 * x2) + (0.80794264540764449 * x3) + (0.45071126534400952 * x4)) * ((0.18424469636214999 * x1) + (0.45123431334216657 * x2) + (0.80794264540764449 * x3) + (0.45071126534400952 * x4)) * ((0.18424469636214999 * x1) + (0.45123431334216657 * x2) + (0.80794264540764449 * x3) + (0.45071126534400952 * x4))) polyIDX1 (((0.18424469636214999 * x1) + (0.45123431334216657 * x2) + (-0.80794264540764449 * x3) + (-0.45071126534400952 * x4)) * ((0.18424469636214999 * x1) + (0.45123431334216657 * x2) + (-0.80794264540764449 * x3) + (-0.45071126534400952 * x4)) * ((0.18424469636214999 * x1) + (0.45123431334216657 * x2) + (-0.80794264540764449 * x3) + (-0.45071126534400952 * x4)) - ((0.052100253064028955 * x1) + (-0.8942341911807864 * x2) + (0.40478255170032273 * x3) + (-0.93774690197704236 * x4)) * ((0.052100253064028955 * x1) + (-0.8942341911807864 * x2) + (0.40478255170032273 * x3) + (-0.93774690197704236 * x4)) * ((0.052100253064028955 * x1) + (-0.8942341911807864 * x2) + (0.40478255170032273 * x3) + (-0.93774690197704236 * x4))) diff --git a/detectErrorAll10.sh b/detectErrorAll10.sh new file mode 100644 index 0000000..02f9cd2 --- /dev/null +++ b/detectErrorAll10.sh @@ -0,0 +1,55 @@ +#!/bin/bash +# set -x +if [ $# -eq 1 ]; then + target=${1} +else + target=NumOpt +fi + +if [ $target == "origin" ]; then + suffix="" +elif [ $target == "NumOpt" ]; then + suffix="NumOpt" +else + echo "Invalid target" + exit +fi + +./detectErrorFourFPEDParallel.sh polyIDX0 3 9 1.5 5 -2 10 -1 3.5 16 16 16 16 0 0 0 0 3 1.5 -2 -1 0.375 0.21875 0.75 0.28125 expr_polyIDX0 3_9_1.5_5_-2_10_-1_3.5_16_16_16_16 origin +./detectErrorFourFPEDParallel.sh polyIDX0 3 9 1.5 5 -2 10 -1 3.5 16 16 16 16 0 0 0 0 3 1.5 -2 -1 0.375 0.21875 0.75 0.28125 expr_polyIDX0 3_9_1.5_5_-2_10_-1_3.5_16_16_16_16 herbie +./detectErrorFourFPEDParallel.sh polyIDX0 3 9 1.5 5 -2 10 -1 3.5 16 16 16 16 0 0 0 0 3 1.5 -2 -1 0.375 0.21875 0.75 0.28125 expr_polyIDX0 3_9_1.5_5_-2_10_-1_3.5_16_16_16_16 herbiePlus +./detectErrorFourFPEDParallel.sh polyIDX1 3 9 1.5 5 -2 10 -1 3.5 16 16 16 16 0 0 0 0 3 1.5 -2 -1 0.375 0.21875 0.75 0.28125 expr_polyIDX1 3_9_1.5_5_-2_10_-1_3.5_16_16_16_16 origin +./detectErrorFourFPEDParallel.sh polyIDX1 3 9 1.5 5 -2 10 -1 3.5 16 16 16 16 0 0 0 0 3 1.5 -2 -1 0.375 0.21875 0.75 0.28125 expr_polyIDX1 3_9_1.5_5_-2_10_-1_3.5_16_16_16_16 herbie +./detectErrorFourFPEDParallel.sh polyIDX1 3 9 1.5 5 -2 10 -1 3.5 16 16 16 16 0 0 0 0 3 1.5 -2 -1 0.375 0.21875 0.75 0.28125 expr_polyIDX1 3_9_1.5_5_-2_10_-1_3.5_16_16_16_16 herbiePlus +./detectErrorFourFPEDParallel.sh polyIDX1 3 9 1.5 5 -2 10 -1 3.5 16 16 16 16 0 0 0 0 3 1.5 -2 -1 0.375 0.21875 0.75 0.28125 expr_polyIDX1 3_9_1.5_5_-2_10_-1_3.5_16_16_16_16 herbieArfa +./detectErrorFourFPEDParallel.sh polyIDX1 3 9 1.5 5 -2 10 -1 3.5 16 16 16 16 0 0 0 0 3 1.5 -2 -1 0.375 0.21875 0.75 0.28125 expr_polyIDX1 3_9_1.5_5_-2_10_-1_3.5_16_16_16_16 daisy +./detectErrorFourFPEDParallel.sh polyIDX1 3 9 1.5 5 -2 10 -1 3.5 16 16 16 16 0 0 0 0 3 1.5 -2 -1 0.375 0.21875 0.75 0.28125 expr_polyIDX1 3_9_1.5_5_-2_10_-1_3.5_16_16_16_16 daisyArfa +./detectErrorFourFPEDParallel.sh polyIDX2 3 9 1.5 5 -2 10 -1 3.5 16 16 16 16 0 0 0 0 3 1.5 -2 -1 0.375 0.21875 0.75 0.28125 expr_polyIDX2 3_9_1.5_5_-2_10_-1_3.5_16_16_16_16 origin +./detectErrorFourFPEDParallel.sh polyIDX2 3 9 1.5 5 -2 10 -1 3.5 16 16 16 16 0 0 0 0 3 1.5 -2 -1 0.375 0.21875 0.75 0.28125 expr_polyIDX2 3_9_1.5_5_-2_10_-1_3.5_16_16_16_16 herbie +./detectErrorFourFPEDParallel.sh polyIDX2 3 9 1.5 5 -2 10 -1 3.5 16 16 16 16 0 0 0 0 3 1.5 -2 -1 0.375 0.21875 0.75 0.28125 expr_polyIDX2 3_9_1.5_5_-2_10_-1_3.5_16_16_16_16 herbiePlus +./detectErrorFourFPEDParallel.sh polyIDX2 3 9 1.5 5 -2 10 -1 3.5 16 16 16 16 0 0 0 0 3 1.5 -2 -1 0.375 0.21875 0.75 0.28125 expr_polyIDX2 3_9_1.5_5_-2_10_-1_3.5_16_16_16_16 herbieArfa +./detectErrorFourFPEDParallel.sh polyIDX2 3 9 1.5 5 -2 10 -1 3.5 16 16 16 16 0 0 0 0 3 1.5 -2 -1 0.375 0.21875 0.75 0.28125 expr_polyIDX2 3_9_1.5_5_-2_10_-1_3.5_16_16_16_16 daisy +./detectErrorFourFPEDParallel.sh polyIDX2 3 9 1.5 5 -2 10 -1 3.5 16 16 16 16 0 0 0 0 3 1.5 -2 -1 0.375 0.21875 0.75 0.28125 expr_polyIDX2 3_9_1.5_5_-2_10_-1_3.5_16_16_16_16 daisyArfa +./detectErrorOneFPEDParallel.sh squareRoot3_2 0 10 500000 0 0 2e-05 expr_squareRoot3_2 0_10_500000 origin +./detectErrorOneFPEDParallel.sh squareRoot3_2 0 10 500000 0 0 2e-05 expr_squareRoot3_2 0_10_500000 herbie +./detectErrorOneFPEDParallel.sh squareRoot3_2 0 10 500000 0 0 2e-05 expr_squareRoot3_2 0_10_500000 herbiePlus +./detectErrorOneFPEDParallel.sh squareRoot3_2 0 10 500000 0 0 2e-05 expr_squareRoot3_2 0_10_500000 herbieArfa +./detectErrorOneFPEDParallel.sh squareRoot3_2 0 10 500000 0 0 2e-05 expr_squareRoot3_2 0_10_500000 final +./detectErrorOneFPEDParallel.sh squareRoot3Invalid_2 0 10 500000 0 0 2e-05 expr_squareRoot3Invalid_2 0_10_500000 origin +./detectErrorOneFPEDParallel.sh squareRoot3Invalid_2 0 10 500000 0 0 2e-05 expr_squareRoot3Invalid_2 0_10_500000 herbie +./detectErrorOneFPEDParallel.sh squareRoot3Invalid_2 0 10 500000 0 0 2e-05 expr_squareRoot3Invalid_2 0_10_500000 herbiePlus +./detectErrorOneFPEDParallel.sh squareRoot3Invalid_2 0 10 500000 0 0 2e-05 expr_squareRoot3Invalid_2 0_10_500000 herbieArfa +./detectErrorOneFPEDParallel.sh squareRoot3Invalid_2 0 10 500000 0 0 2e-05 expr_squareRoot3Invalid_2 0_10_500000 herbie +./detectErrorOneFPEDParallel.sh cav10_2 0 10 500000 0 0 2e-05 expr_cav10_2 0_10_500000 origin +./detectErrorOneFPEDParallel.sh cav10_2 0 10 500000 0 0 2e-05 expr_cav10_2 0_10_500000 herbie +./detectErrorOneFPEDParallel.sh cav10_2 0 10 500000 0 0 2e-05 expr_cav10_2 0_10_500000 herbiePlus +./detectErrorOneFPEDParallel.sh cav10_2 0 10 500000 0 0 2e-05 expr_cav10_2 0_10_500000 herbieArfa +./detectErrorOneFPEDParallel.sh cav10_2 0 10 500000 0 0 2e-05 expr_cav10_2 0_10_500000 final +./detectErrorOneFPEDParallel.sh smartRoot_2 -2 2 500000 0 -2 8e-06 expr_smartRoot_2 -2_2_500000 origin +./detectErrorOneFPEDParallel.sh smartRoot_2 -2 2 500000 0 -2 8e-06 expr_smartRoot_2 -2_2_500000 herbie +./detectErrorOneFPEDParallel.sh smartRoot_2 -2 2 500000 0 -2 8e-06 expr_smartRoot_2 -2_2_500000 herbiePlus +./detectErrorOneFPEDParallel.sh smartRoot_2 -2 2 500000 0 -2 8e-06 expr_smartRoot_2 -2_2_500000 herbieArfa +./detectErrorOneFPEDParallel.sh smartRoot_2 -2 2 500000 0 -2 8e-06 expr_smartRoot_2 -2_2_500000 final +./detectErrorThreeFPEDParallel.sh triangleSorted_2 1 9 1 9 1 9 256 256 256 0 0 0 1 1 1 0.03125 0.03125 0.03125 expr_triangleSorted_2 1_9_1_9_1_9_256_256_256 origin +./detectErrorThreeFPEDParallel.sh triangleSorted_2 1 9 1 9 1 9 256 256 256 0 0 0 1 1 1 0.03125 0.03125 0.03125 expr_triangleSorted_2 1_9_1_9_1_9_256_256_256 herbie +./detectErrorThreeFPEDParallel.sh triangleSorted_2 1 9 1 9 1 9 256 256 256 0 0 0 1 1 1 0.03125 0.03125 0.03125 expr_triangleSorted_2 1_9_1_9_1_9_256_256_256 herbiePlus diff --git a/src/geneCode.cpp b/src/geneCode.cpp index 1ed174c..3fd5995 100644 --- a/src/geneCode.cpp +++ b/src/geneCode.cpp @@ -301,8 +301,8 @@ string geneHerbieCode(string uniqueLabel) {"triangleSorted_1", ""}, {"triangleSorted_2", ""}, {"example", "(x0+x1)+(x2+x3)"}, - {"polyIDX0", ""}, - {"polyIDX1", ""}, + {"polyIDX0", "((pow(x4, 2.0) * ((3.4795123194602824 * ((-0.8507307281963669 * x1) + ((-0.986640169163685 * x2) + (1.3809517485817782 * x3)))) + (((-0.8507307281963669 * x1) + ((-0.986640169163685 * x2) + (1.3809517485817782 * x3))) * 6.959024638920565))) + (pow(((-0.8507307281963669 * x1) + ((-0.986640169163685 * x2) + (1.3809517485817782 * x3))), 3.0) + ((x4 * ((3.730690187866198 * pow(((-0.8507307281963669 * x1) + ((-0.986640169163685 * x2) + (1.3809517485817782 * x3))), 2.0)) + (pow(((-0.8507307281963669 * x1) + ((-0.986640169163685 * x2) + (1.3809517485817782 * x3))), 2.0) * 1.865345093933099))) + (6.490491234385016 * pow(x4, 3.0))))) + (((((x1 * 0.18424469636215) + (x2 * 0.45123431334216657)) + (x3 * 0.8079426454076445)) + (x4 * 0.4507112653440095)) * (((((x1 * 0.18424469636215) + (x2 * 0.45123431334216657)) + (x3 * 0.8079426454076445)) + (x4 * 0.4507112653440095)) * ((((x1 * -0.18424469636215) - (x2 * 0.45123431334216657)) + (x3 * -0.8079426454076445)) + (x4 * -0.4507112653440095))))"}, + {"polyIDX1", "x0"}, // error but not influence the result {"polyIDX2", ""}, {"example5param", "(x0+x1)+(x2+x3)+x4"}, {"pov_ray", ""}, @@ -394,7 +394,7 @@ string geneDaisyCode(string uniqueLabel) {"triangleSorted_2", ""}, {"example", "(x0+x2)+(x1+x3)"}, {"polyIDX0", ""}, - {"polyIDX1", ""}, + {"polyIDX1", "((((((((0.18424469636215 * x1) + (0.45123431334216657 * x2)) + (-(0.8079426454076445) * x3)) + (-(0.4507112653440095) * x4)) * ((((0.18424469636215 * x1) + (0.45123431334216657 * x2)) + (-(0.8079426454076445) * x3)) + (-(0.4507112653440095) * x4))) * ((((0.18424469636215 * x1) + (0.45123431334216657 * x2)) + (-(0.8079426454076445) * x3)) - (0.4507112653440095 * x4))) - (((((((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3)) * (((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3))) + ((((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3)) * (-(0.9377469019770424) * x4))) + (((((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3)) * (-(0.9377469019770424) * x4)) + ((-(0.9377469019770424) * x4) * (-(0.9377469019770424) * x4)))) * (((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3)))) - (((((((0.052100253064028955 * x1) - (0.8942341911807864 * x2)) + (0.40478255170032273 * x3)) * (((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3))) + ((((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3)) * (-(0.9377469019770424) * x4))) + ((((x3 * 0.40478255170032273) + ((-(0.8942341911807864) * x2) + (x1 * 0.052100253064028955))) * (-(0.9377469019770424) * x4)) + ((-(0.9377469019770424) * x4) * (-(0.9377469019770424) * x4)))) * (-(0.9377469019770424) * x4)))"}, {"polyIDX2", ""}, {"example5param", "(x0+x1)+(x2+x3)+x4"}, {"pov_ray", ""}, diff --git a/srcTest/cav10_2/expr_cav10_2_final.c b/srcTest/cav10_2/expr_cav10_2_final.c new file mode 100644 index 0000000..e770d75 --- /dev/null +++ b/srcTest/cav10_2/expr_cav10_2_final.c @@ -0,0 +1,24 @@ +#include "mine.h" +double expr_cav10_2_final(double x) { + double tmp; + if (((x * x) - x) >= 0.0) { + tmp = x / 10.0; + } else { + double result; + if((0.05338 < x && x < 2.00062)) { + result = fma(x, x, 2.0); + } else if((2.44688 < x && x < 2.83436)) { + result = fma(x, x, 2.0); + } else if((3.73768 < x && x < 4.00484)) { + result = fma(x, x, 2.0); + } else if((5.47684 < x && x < 5.65892)) { + result = fma(x, x, 2.0); + } else if((7.86748 < x && x < 8.00748)) { + result = fma(x, x, 2.0); + } else { + result = x * x + 2; + } + return result; + } + return tmp; +} diff --git a/srcTest/cav10_2/expr_cav10_2_herbie.c b/srcTest/cav10_2/expr_cav10_2_herbie.c new file mode 100644 index 0000000..5cdda79 --- /dev/null +++ b/srcTest/cav10_2/expr_cav10_2_herbie.c @@ -0,0 +1,9 @@ +double expr_cav10_2_herbie(double x) { + double tmp; + if (((x * x) - x) >= 0.0) { + tmp = x / 10.0; + } else { + tmp = (x * x) + 2.0; + } + return tmp; +} \ No newline at end of file diff --git a/srcTest/cav10_2/expr_cav10_2_herbieArfa.c b/srcTest/cav10_2/expr_cav10_2_herbieArfa.c new file mode 100644 index 0000000..51c9a5e --- /dev/null +++ b/srcTest/cav10_2/expr_cav10_2_herbieArfa.c @@ -0,0 +1,58 @@ +#include +double expr_cav10_2_herbieArfa(double x) { + double tmp; + if (((x * x) - x) >= 0.0) { + tmp = x / 10.0; + } else { + if((0.05338 < x && x < 2.00062)) { + double tmp; + if (-x >= 0.0) { + tmp = x * 0.1; + } else { + tmp = fma(x, x, 2.0); + } + return tmp; + } else if((2.44688 < x && x < 2.83436)) { + double tmp; + if (-x >= 0.0) { + tmp = x * 0.1; + } else { + tmp = fma(x, x, 2.0); + } + return tmp; + } else if((3.73768 < x && x < 4.00484)) { + double tmp; + if (-x >= 0.0) { + tmp = x * 0.1; + } else { + tmp = fma(x, x, 2.0); + } + return tmp; + } else if((5.47684 < x && x < 5.65892)) { + double tmp; + if (-x >= 0.0) { + tmp = x * 0.1; + } else { + tmp = fma(x, x, 2.0); + } + return tmp; + } else if((7.86748 < x && x < 8.00748)) { + double tmp; + if (-x >= 0.0) { + tmp = x * 0.1; + } else { + tmp = fma(x, x, 2.0); + } + return tmp; + } else { + double tmp; + if (-x >= 0.0) { + tmp = x * 0.1; + } else { + tmp = fma(x, x, 2.0); + } + return tmp; + } + } + return tmp; +} \ No newline at end of file diff --git a/srcTest/cav10_2/expr_cav10_2_herbiePlus.c b/srcTest/cav10_2/expr_cav10_2_herbiePlus.c new file mode 100644 index 0000000..1f31351 --- /dev/null +++ b/srcTest/cav10_2/expr_cav10_2_herbiePlus.c @@ -0,0 +1,9 @@ +double expr_cav10_2_herbiePlus(double x) { + double tmp; + if (((x * x) - x) >= 0.0) { + tmp = x / 10.0; + } else { + tmp = (x * x) + 2.0; + } + return tmp; +} \ No newline at end of file diff --git a/srcTest/cav10_2/expr_cav10_2_mpfr.c b/srcTest/cav10_2/expr_cav10_2_mpfr.c new file mode 100644 index 0000000..87b0d30 --- /dev/null +++ b/srcTest/cav10_2/expr_cav10_2_mpfr.c @@ -0,0 +1,52 @@ +#include +#include +#include +#include +int expr_cav10_1_mpfr(double x, mpfr_t mpfrResult) { + int status = 0; + mpfr_t mp1, mp2, mp3; + mpfr_init2(mp1, 128); + mpfr_init2(mp2, 128); + mpfr_init2(mp3, 128); + mpfr_set_d(mp1, x, MPFR_RNDN); + mpfr_set_d(mp2, 10, MPFR_RNDN); + mpfr_div(mp3, mp1, mp2, MPFR_RNDN); + + mpfr_set(mpfrResult, mp3, MPFR_RNDN); + mpfr_clear(mp1); + mpfr_clear(mp2); + mpfr_clear(mp3); + return status; +} + +int expr_cav10_2_mpfr_old(double x, mpfr_t mpfrResult) { + int status = 0; + mpfr_t mp1, mp2, mp3, mp4, mp5; + mpfr_init2(mp1, 128); + mpfr_init2(mp2, 128); + mpfr_init2(mp3, 128); + mpfr_init2(mp4, 128); + mpfr_init2(mp5, 128); + mpfr_set_d(mp1, x, MPFR_RNDN); + mpfr_set_d(mp2, x, MPFR_RNDN); + mpfr_mul(mp3, mp1, mp2, MPFR_RNDN); + mpfr_set_d(mp4, 2, MPFR_RNDN); + mpfr_add(mp5, mp3, mp4, MPFR_RNDN); + + mpfr_set(mpfrResult, mp5, MPFR_RNDN); + mpfr_clear(mp1); + mpfr_clear(mp2); + mpfr_clear(mp3); + mpfr_clear(mp4); + mpfr_clear(mp5); + return status; +} + +int expr_cav10_2_mpfr(double x, mpfr_t mpfrResult) { + if (((x * x) - x) >= 0.0) { + expr_cav10_1_mpfr(x, mpfrResult); + } else { + expr_cav10_2_mpfr_old(x, mpfrResult); + } + return 0; +} \ No newline at end of file diff --git a/srcTest/cav10_2/expr_cav10_2_origin.c b/srcTest/cav10_2/expr_cav10_2_origin.c new file mode 100644 index 0000000..109a821 --- /dev/null +++ b/srcTest/cav10_2/expr_cav10_2_origin.c @@ -0,0 +1,11 @@ +#include +double expr_cav10_2_origin(double x) +{ + double tmp; + if (((x * x) - x) >= 0.0) { + tmp = x / 10.0; + } else { + tmp = (x * x) + 2.0; + } + return tmp; +} diff --git a/srcTest/polyIDX0/expr_polyIDX0_herbie.c b/srcTest/polyIDX0/expr_polyIDX0_herbie.c new file mode 100644 index 0000000..7cdef4e --- /dev/null +++ b/srcTest/polyIDX0/expr_polyIDX0_herbie.c @@ -0,0 +1,6 @@ +#include +double expr_polyIDX0_herbie(double x1, double x2, double x3, double x4) +{ + double result = ((pow(x4, 2.0) * ((3.4795123194602824 * ((-0.8507307281963669 * x1) + ((-0.986640169163685 * x2) + (1.3809517485817782 * x3)))) + (((-0.8507307281963669 * x1) + ((-0.986640169163685 * x2) + (1.3809517485817782 * x3))) * 6.959024638920565))) + (pow(((-0.8507307281963669 * x1) + ((-0.986640169163685 * x2) + (1.3809517485817782 * x3))), 3.0) + ((x4 * ((3.730690187866198 * pow(((-0.8507307281963669 * x1) + ((-0.986640169163685 * x2) + (1.3809517485817782 * x3))), 2.0)) + (pow(((-0.8507307281963669 * x1) + ((-0.986640169163685 * x2) + (1.3809517485817782 * x3))), 2.0) * 1.865345093933099))) + (6.490491234385016 * pow(x4, 3.0))))) + (((((x1 * 0.18424469636215) + (x2 * 0.45123431334216657)) + (x3 * 0.8079426454076445)) + (x4 * 0.4507112653440095)) * (((((x1 * 0.18424469636215) + (x2 * 0.45123431334216657)) + (x3 * 0.8079426454076445)) + (x4 * 0.4507112653440095)) * ((((x1 * -0.18424469636215) - (x2 * 0.45123431334216657)) + (x3 * -0.8079426454076445)) + (x4 * -0.4507112653440095)))); + return result; +} diff --git a/srcTest/polyIDX0/expr_polyIDX0_herbieArfa.c b/srcTest/polyIDX0/expr_polyIDX0_herbieArfa.c new file mode 100644 index 0000000..f7732b8 --- /dev/null +++ b/srcTest/polyIDX0/expr_polyIDX0_herbieArfa.c @@ -0,0 +1,15 @@ +#include +double expr_polyIDX0_herbieArfa(double x1, double x2, double x3, double x4) { + double result; + if((3 < x1 && x1 < 5.4) && (2.2 < x2 && x2 < 3.95) && (6.4 < x3 && x3 < 8.8) && (0.8 < x4 && x4 < 3.05)) { + double t_0 = (-0.8507307281963669 * x1) + ((1.865345093933099 * x4) + (-0.986640169163685 * x2)); + double t_1 = pow(t_0, 2.0); + double t_2 = (1.865345093933099 * x4) + ((-0.8507307281963669 * x1) + (-0.986640169163685 * x2)); + return ((2.6335132809765356 * pow(x3, 3.0)) + ((t_2 * t_1) + ((x3 * ((t_1 * 1.3809517485817782) + (2.7619034971635563 * (t_2 * t_0)))) + (((t_2 * 1.9070277319110707) + (t_0 * 3.8140554638221413)) * pow(x3, 2.0))))) - pow(fma(x1, 0.18424469636215, fma(x2, 0.45123431334216657, fma(x3, 0.8079426454076445, (x4 * 0.4507112653440095)))), 3.0); + } else { + result = ((pow(x4, 2.0) * ((3.4795123194602824 * ((-0.8507307281963669 * x1) + ((-0.986640169163685 * x2) + (1.3809517485817782 * x3)))) + (((-0.8507307281963669 * x1) + ((-0.986640169163685 * x2) + (1.3809517485817782 * x3))) * 6.959024638920565))) + (pow(((-0.8507307281963669 * x1) + ((-0.986640169163685 * x2) + (1.3809517485817782 * x3))), 3.0) + ((x4 * ((3.730690187866198 * pow(((-0.8507307281963669 * x1) + ((-0.986640169163685 * x2) + (1.3809517485817782 * x3))), 2.0)) + (pow(((-0.8507307281963669 * x1) + ((-0.986640169163685 * x2) + (1.3809517485817782 * x3))), 2.0) * 1.865345093933099))) + (6.490491234385016 * pow(x4, 3.0))))) + (((((x1 * 0.18424469636215) + (x2 * 0.45123431334216657)) + (x3 * 0.8079426454076445)) + (x4 * 0.4507112653440095)) * (((((x1 * 0.18424469636215) + (x2 * 0.45123431334216657)) + (x3 * 0.8079426454076445)) + (x4 * 0.4507112653440095)) * ((((x1 * -0.18424469636215) - (x2 * 0.45123431334216657)) + (x3 * -0.8079426454076445)) + (x4 * -0.4507112653440095)))); + } + return result; + + +} \ No newline at end of file diff --git a/srcTest/polyIDX0/expr_polyIDX0_herbiePlus.c b/srcTest/polyIDX0/expr_polyIDX0_herbiePlus.c new file mode 100644 index 0000000..4b00453 --- /dev/null +++ b/srcTest/polyIDX0/expr_polyIDX0_herbiePlus.c @@ -0,0 +1,6 @@ +#include +double expr_polyIDX0_herbiePlus(double x1, double x2, double x3, double x4) { + double t_0 = (-0.8507307281963669 * x1) + ((1.865345093933099 * x4) + (1.3809517485817782 * x3)); + double t_1 = (((x1 * 0.18424469636215) + (x2 * 0.45123431334216657)) + (x3 * 0.8079426454076445)) + (x4 * 0.4507112653440095); + return (((0.973458823407345 * pow(x2, 2.0)) + ((-1.97328033832737 * (x2 * t_0)) + pow(t_0, 2.0))) * ((1.865345093933099 * x4) + ((1.3809517485817782 * x3) + ((-0.8507307281963669 * x1) + (x2 * -0.986640169163685))))) + (t_1 * (t_1 * ((((x1 * -0.18424469636215) - (x2 * 0.45123431334216657)) + (x3 * -0.8079426454076445)) + (x4 * -0.4507112653440095)))); +} \ No newline at end of file diff --git a/srcTest/polyIDX1/expr_polyIDX1_daisy.c b/srcTest/polyIDX1/expr_polyIDX1_daisy.c new file mode 100644 index 0000000..bfc8d67 --- /dev/null +++ b/srcTest/polyIDX1/expr_polyIDX1_daisy.c @@ -0,0 +1,6 @@ +#include +double expr_polyIDX1_daisy(double x1, double x2, double x3, double x4) +{ + double result = ((((((((0.18424469636215 * x1) + (0.45123431334216657 * x2)) + (-(0.8079426454076445) * x3)) + (-(0.4507112653440095) * x4)) * ((((0.18424469636215 * x1) + (0.45123431334216657 * x2)) + (-(0.8079426454076445) * x3)) + (-(0.4507112653440095) * x4))) * ((((0.18424469636215 * x1) + (0.45123431334216657 * x2)) + (-(0.8079426454076445) * x3)) - (0.4507112653440095 * x4))) - (((((((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3)) * (((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3))) + ((((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3)) * (-(0.9377469019770424) * x4))) + (((((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3)) * (-(0.9377469019770424) * x4)) + ((-(0.9377469019770424) * x4) * (-(0.9377469019770424) * x4)))) * (((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3)))) - (((((((0.052100253064028955 * x1) - (0.8942341911807864 * x2)) + (0.40478255170032273 * x3)) * (((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3))) + ((((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3)) * (-(0.9377469019770424) * x4))) + ((((x3 * 0.40478255170032273) + ((-(0.8942341911807864) * x2) + (x1 * 0.052100253064028955))) * (-(0.9377469019770424) * x4)) + ((-(0.9377469019770424) * x4) * (-(0.9377469019770424) * x4)))) * (-(0.9377469019770424) * x4))); + return result; +} diff --git a/srcTest/polyIDX1/expr_polyIDX1_daisyArfa.c b/srcTest/polyIDX1/expr_polyIDX1_daisyArfa.c new file mode 100644 index 0000000..fae3bf9 --- /dev/null +++ b/srcTest/polyIDX1/expr_polyIDX1_daisyArfa.c @@ -0,0 +1,10 @@ +#include +double expr_polyIDX1_daisyArfa(double x1, double x2, double x3, double x4) { + double result; + if((3.6 < x1 && x1 < 5.4) && (1.85 < x2 && x2 < 4.65) && (5.2 < x3 && x3 < 7.6) && (3.05 < x4 && x4 < 3.5)) { + result = (((((((0.18424469636215 * x1) + (0.45123431334216657 * x2)) + (-(0.8079426454076445) * x3)) - (0.4507112653440095 * x4)) * ((((0.18424469636215 * x1) + (0.45123431334216657 * x2)) + (-(0.8079426454076445) * x3)) + (-(0.4507112653440095) * x4))) * ((((0.18424469636215 * x1) + (0.45123431334216657 * x2)) + (-(0.8079426454076445) * x3)) + (-(0.4507112653440095) * x4))) - ((((((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3)) * ((((x1 * 0.052100253064028955) - (0.8942341911807864 * x2)) + (0.40478255170032273 * x3)) + (x4 * -(0.9377469019770424)))) * (((x3 * 0.40478255170032273) + ((x1 * 0.052100253064028955) + (-(0.8942341911807864) * x2))) - (x4 * 0.9377469019770424))) + ((x4 * -(0.9377469019770424)) * (((((0.052100253064028955 * x1) - (0.8942341911807864 * x2)) + (0.40478255170032273 * x3)) + (x4 * -(0.9377469019770424))) * ((((x3 * 0.40478255170032273) + (x1 * 0.052100253064028955)) + (x2 * -(0.8942341911807864))) - (x4 * 0.9377469019770424)))))); + } else { + result = ((((((((0.18424469636215 * x1) + (0.45123431334216657 * x2)) + (-(0.8079426454076445) * x3)) + (-(0.4507112653440095) * x4)) * ((((0.18424469636215 * x1) + (0.45123431334216657 * x2)) + (-(0.8079426454076445) * x3)) + (-(0.4507112653440095) * x4))) * ((((0.18424469636215 * x1) + (0.45123431334216657 * x2)) + (-(0.8079426454076445) * x3)) - (0.4507112653440095 * x4))) - (((((((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3)) * (((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3))) + ((((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3)) * (-(0.9377469019770424) * x4))) + (((((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3)) * (-(0.9377469019770424) * x4)) + ((-(0.9377469019770424) * x4) * (-(0.9377469019770424) * x4)))) * (((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3)))) - (((((((0.052100253064028955 * x1) - (0.8942341911807864 * x2)) + (0.40478255170032273 * x3)) * (((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3))) + ((((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3)) * (-(0.9377469019770424) * x4))) + ((((x3 * 0.40478255170032273) + ((-(0.8942341911807864) * x2) + (x1 * 0.052100253064028955))) * (-(0.9377469019770424) * x4)) + ((-(0.9377469019770424) * x4) * (-(0.9377469019770424) * x4)))) * (-(0.9377469019770424) * x4))); + } + return result; +} \ No newline at end of file diff --git a/srcTest/polyIDX1/expr_polyIDX1_herbie.c b/srcTest/polyIDX1/expr_polyIDX1_herbie.c new file mode 100644 index 0000000..5fb227b --- /dev/null +++ b/srcTest/polyIDX1/expr_polyIDX1_herbie.c @@ -0,0 +1,7 @@ +#include +double expr_polyIDX1_herbie(double x1, double x2, double x3, double x4) { + double t_0 = (-0.4507112653440095 * x4) + ((-0.8079426454076445 * x3) + (0.45123431334216657 * x2)); + double t_1 = pow(t_0, 2.0); + double t_2 = (((x1 * 0.052100253064028955) + (x2 * -0.8942341911807864)) + (x3 * 0.40478255170032273)) + (x4 * -0.9377469019770424); + return ((0.006254390386485292 * pow(x1, 3.0)) + ((((0.06789221627516169 * t_0) + (t_0 * 0.033946108137580845)) * pow(x1, 2.0)) + (pow(t_0, 3.0) + (x1 * ((0.3684893927243 * t_1) + (t_1 * 0.18424469636215)))))) + (t_2 * (t_2 * ((((x2 * 0.8942341911807864) - (x1 * 0.052100253064028955)) - (x3 * 0.40478255170032273)) + (x4 * 0.9377469019770424)))); +} \ No newline at end of file diff --git a/srcTest/polyIDX1/expr_polyIDX1_herbieArfa.c b/srcTest/polyIDX1/expr_polyIDX1_herbieArfa.c new file mode 100644 index 0000000..3430538 --- /dev/null +++ b/srcTest/polyIDX1/expr_polyIDX1_herbieArfa.c @@ -0,0 +1,12 @@ +#include +double expr_polyIDX1_herbieArfa(double x1, double x2, double x3, double x4) { + double result; + if((3.6 < x1 && x1 < 5.4) && (1.85 < x2 && x2 < 4.65) && (5.2 < x3 && x3 < 7.6) && (3.05 < x4 && x4 < 3.5)) { + double t_0 = (x2 * -0.8942341911807864) + ((x3 * 0.40478255170032273) + (x1 * 0.052100253064028955)); + double t_1 = pow(t_0, 2.0); + result = pow(fma(0.45123431334216657, x2, fma(0.18424469636215, x1, fma(-0.8079426454076445, x3, (-0.4507112653440095 * x4)))), 3.0) + ((pow(x4, 3.0) * 0.8246257919139798) - ((((0.8793692521675407 * t_0) + (t_0 * 1.7587385043350814)) * pow(x4, 2.0)) + (pow(t_0, 3.0) + (x4 * ((-1.8754938039540847 * t_1) + (t_1 * -0.9377469019770424)))))); + } else { + result = ((((((((0.18424469636215 * x1) + (0.45123431334216657 * x2)) + (-(0.8079426454076445) * x3)) + (-(0.4507112653440095) * x4)) * ((((0.18424469636215 * x1) + (0.45123431334216657 * x2)) + (-(0.8079426454076445) * x3)) + (-(0.4507112653440095) * x4))) * ((((0.18424469636215 * x1) + (0.45123431334216657 * x2)) + (-(0.8079426454076445) * x3)) - (0.4507112653440095 * x4))) - (((((((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3)) * (((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3))) + ((((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3)) * (-(0.9377469019770424) * x4))) + (((((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3)) * (-(0.9377469019770424) * x4)) + ((-(0.9377469019770424) * x4) * (-(0.9377469019770424) * x4)))) * (((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3)))) - (((((((0.052100253064028955 * x1) - (0.8942341911807864 * x2)) + (0.40478255170032273 * x3)) * (((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3))) + ((((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3)) * (-(0.9377469019770424) * x4))) + ((((x3 * 0.40478255170032273) + ((-(0.8942341911807864) * x2) + (x1 * 0.052100253064028955))) * (-(0.9377469019770424) * x4)) + ((-(0.9377469019770424) * x4) * (-(0.9377469019770424) * x4)))) * (-(0.9377469019770424) * x4))); + } + return result; +} \ No newline at end of file diff --git a/srcTest/polyIDX1/expr_polyIDX1_herbiePlus.c b/srcTest/polyIDX1/expr_polyIDX1_herbiePlus.c new file mode 100644 index 0000000..6445db6 --- /dev/null +++ b/srcTest/polyIDX1/expr_polyIDX1_herbiePlus.c @@ -0,0 +1,7 @@ +#include +double expr_polyIDX1_herbiePlus(double x1, double x2, double x3, double x4) { + double t_0 = (((x1 * 0.052100253064028955) + (x2 * -0.8942341911807864)) + (x3 * 0.40478255170032273)) + (x4 * -0.9377469019770424); + double t_1 = (-0.4507112653440095 * x4) + ((0.18424469636215 * x1) + (0.45123431334216657 * x2)); + double t_2 = pow(t_1, 2.0); + return ((((-0.8079426454076445 * t_2) + (t_2 * -1.615885290815289)) * x3) + ((((t_1 * 1.3055426365366054) + (t_1 * 0.6527713182683027)) * pow(x3, 2.0)) + (pow(t_1, 3.0) + (-0.527401785727928 * pow(x3, 3.0))))) + (t_0 * (t_0 * ((((x1 * -0.052100253064028955) + (x2 * 0.8942341911807864)) + (x3 * -0.40478255170032273)) + (x4 * 0.9377469019770424)))); +} \ No newline at end of file diff --git a/srcTest/polyIDX2/expr_polyIDX2_daisy.c b/srcTest/polyIDX2/expr_polyIDX2_daisy.c new file mode 100644 index 0000000..7ef16f6 --- /dev/null +++ b/srcTest/polyIDX2/expr_polyIDX2_daisy.c @@ -0,0 +1,6 @@ +#include +double expr_polyIDX2_daisy(double x1, double x2, double x3, double x4) +{ + double result = (((((((((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3)) + (-(0.9377469019770424) * x4)) * (((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3))) + ((((0.052100253064028955 * x1) + ((-(0.8942341911807864) * x2) + (0.40478255170032273 * x3))) + (-(0.9377469019770424) * x4)) * (-(0.9377469019770424) * x4))) * (-(0.9377469019770424) * x4)) + (((((((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3)) + (-(0.9377469019770424) * x4)) * (((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3))) + (-(0.9377469019770424) * (x4 * (((-(0.8942341911807864) * x2) + ((0.052100253064028955 * x1) + (-(0.9377469019770424) * x4))) + (0.40478255170032273 * x3))))) * (((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3)))) - ((((x4 * 1.865345093933099) + (((x1 * -(0.8507307281963669)) + (-(0.986640169163685) * x2)) + (1.3809517485817782 * x3))) * ((((-(0.8507307281963669) * x1) + (-(0.986640169163685) * x2)) + (1.3809517485817782 * x3)) + (x4 * 1.865345093933099))) * ((((-(0.8507307281963669) * x1) + (-(0.986640169163685) * x2)) + (1.3809517485817782 * x3)) + (x4 * 1.865345093933099)))); + return result; +} diff --git a/srcTest/polyIDX2/expr_polyIDX2_daisyArfa.c b/srcTest/polyIDX2/expr_polyIDX2_daisyArfa.c new file mode 100644 index 0000000..940e08f --- /dev/null +++ b/srcTest/polyIDX2/expr_polyIDX2_daisyArfa.c @@ -0,0 +1,11 @@ +#include "mine.h" +double expr_polyIDX2_daisyArfa(double x1, double x2, double x3, double x4) { + double result; + if((6 < x1 && x1 < 6.6) && (1.85 < x2 && x2 < 4.3) && (-2 < x3 && x3 < 6.4) && (1.25 < x4 && x4 < 2.6)) { + result = (((((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + ((0.40478255170032273 * x3) + (-(0.9377469019770424) * x4))) * (((-(0.9377469019770424) * x4) + (((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + (0.40478255170032273 * x3))) * (((0.052100253064028955 * x1) + (-(0.8942341911807864) * x2)) + ((0.40478255170032273 * x3) + (-(0.9377469019770424) * x4))))) - (((((-(0.8507307281963669) * x1) + ((-(0.986640169163685) * x2) + (1.3809517485817782 * x3))) + (1.865345093933099 * x4)) * (((x1 * -(0.8507307281963669)) + ((-(0.986640169163685) * x2) + (1.3809517485817782 * x3))) + (x4 * 1.865345093933099))) * (((x1 * -(0.8507307281963669)) + (x4 * 1.865345093933099)) + ((1.3809517485817782 * x3) - (0.986640169163685 * x2))))); + } else { + result = (((0.052100253064028955 * x1) + (-0.8942341911807864 * x2) + (0.40478255170032273 * x3) + (-0.93774690197704236 * x4)) * ((0.052100253064028955 * x1) + (-0.8942341911807864 * x2) + (0.40478255170032273 * x3) + (-0.93774690197704236 * x4)) * ((0.052100253064028955 * x1) + (-0.8942341911807864 * x2) + (0.40478255170032273 * x3) + (-0.93774690197704236 * x4)) - ((-0.85073072819636686 * x1) + (-0.98664016916368502 * x2) + (1.3809517485817782 * x3) + (1.8653450939330991 * x4)) * ((-0.85073072819636686 * x1) + (-0.98664016916368502 * x2) + (1.3809517485817782 * x3) + (1.8653450939330991 * x4)) * ((-0.85073072819636686 * x1) + (-0.98664016916368502 * x2) + (1.3809517485817782 * x3) + (1.8653450939330991 * x4))) +; + } + return result; +} \ No newline at end of file diff --git a/srcTest/polyIDX2/expr_polyIDX2_herbie.c b/srcTest/polyIDX2/expr_polyIDX2_herbie.c new file mode 100644 index 0000000..e2f5340 --- /dev/null +++ b/srcTest/polyIDX2/expr_polyIDX2_herbie.c @@ -0,0 +1,6 @@ +#include +double expr_polyIDX2_herbie(double x0) +{ + double result = x0; + return result; +} diff --git a/srcTest/polyIDX2/expr_polyIDX2_herbieArfa.c b/srcTest/polyIDX2/expr_polyIDX2_herbieArfa.c new file mode 100644 index 0000000..dce35e2 --- /dev/null +++ b/srcTest/polyIDX2/expr_polyIDX2_herbieArfa.c @@ -0,0 +1,16 @@ +#include "mine.h" +double expr_polyIDX2_herbieArfa(double x1, double x2, double x3, double x4) { + double result; + if((6 < x1 && x1 < 6.6) && (1.85 < x2 && x2 < 4.3) && (-2 < x3 && x3 < 6.4) && (1.25 < x4 && x4 < 2.6)) { + double t_0 = (x4 * -1.865345093933099) + ((x1 * 0.8507307281963669) + (x3 * -1.3809517485817782)); + double t_1 = (0.40478255170032273 * x3) + ((0.052100253064028955 * x1) + (-0.9377469019770424 * x4)); + double t_2 = pow(t_1, 2.0); + double t_3 = (x1 * -0.8507307281963669) + ((x4 * 1.865345093933099) + (x3 * 1.3809517485817782)); + double t_4 = pow(t_3, 2.0); + result = (((((-0.8942341911807864 * t_2) + (t_2 * -1.7884683823615728)) + ((-1.97328033832737 * (t_3 * t_0)) + (t_4 * 0.986640169163685))) * x2) + ((0.24537492502430377 * pow(x2, 3.0)) + (pow(t_1, 3.0) + (pow(x2, 2.0) * (((t_1 * 0.7996547886767552) + (t_1 * 1.5993095773535104)) + ((t_3 * -1.94691764681469) + (0.973458823407345 * t_0))))))) + (t_4 * t_0); + } else { + result = (((0.052100253064028955 * x1) + (-0.8942341911807864 * x2) + (0.40478255170032273 * x3) + (-0.93774690197704236 * x4)) * ((0.052100253064028955 * x1) + (-0.8942341911807864 * x2) + (0.40478255170032273 * x3) + (-0.93774690197704236 * x4)) * ((0.052100253064028955 * x1) + (-0.8942341911807864 * x2) + (0.40478255170032273 * x3) + (-0.93774690197704236 * x4)) - ((-0.85073072819636686 * x1) + (-0.98664016916368502 * x2) + (1.3809517485817782 * x3) + (1.8653450939330991 * x4)) * ((-0.85073072819636686 * x1) + (-0.98664016916368502 * x2) + (1.3809517485817782 * x3) + (1.8653450939330991 * x4)) * ((-0.85073072819636686 * x1) + (-0.98664016916368502 * x2) + (1.3809517485817782 * x3) + (1.8653450939330991 * x4))) +; + } + return result; +} diff --git a/srcTest/polyIDX2/expr_polyIDX2_herbiePlus.c b/srcTest/polyIDX2/expr_polyIDX2_herbiePlus.c new file mode 100644 index 0000000..115738a --- /dev/null +++ b/srcTest/polyIDX2/expr_polyIDX2_herbiePlus.c @@ -0,0 +1,7 @@ +#include +double expr_polyIDX2_herbiePlus(double x1, double x2, double x3, double x4) { + double t_0 = fma(x1, -0.8507307281963669, fma(1.3809517485817782, x3, (x4 * 1.865345093933099))); + double t_1 = fma(x3, 0.40478255170032273, fma(x1, 0.052100253064028955, (-0.9377469019770424 * x4))); + double t_2 = fma(x1, -0.8507307281963669, (x3 * 1.3809517485817782)); + return fma(0.24537492502430377, pow(x2, 3.0), pow(t_1, 3.0)) + (((x2 * (x2 * ((t_1 * 2.3989643660302655) - fma(-0.986640169163685, fma(x4, -3.6808487980536055, ((x1 * 1.6787302191608167) + (x3 * -2.7250049336552244))), (0.973458823407345 * t_0))))) + (x2 * (fma(t_0, fma(x4, 3.6808487980536055, ((x1 * -1.6787302191608167) + (x3 * 2.7250049336552244))), (((x4 * (x4 * 3.4795123194602824)) + (t_2 * (t_2 + (x4 * 3.730690187866198)))) * 0.986640169163685)) + (pow(t_1, 2.0) * -2.6827025735423593)))) + (t_0 * ((x4 * (x4 * -3.4795123194602824)) + (t_2 * ((x4 * -3.730690187866198) - t_2))))); +} \ No newline at end of file diff --git a/srcTest/smartRoot_2/expr_smartRoot_2_final.c b/srcTest/smartRoot_2/expr_smartRoot_2_final.c new file mode 100644 index 0000000..6e6c37c --- /dev/null +++ b/srcTest/smartRoot_2/expr_smartRoot_2_final.c @@ -0,0 +1,20 @@ +#include "mine.h" +double expr_smartRoot_2_final(double c) { + double result; + if (c < 0.75) { + if((-1.05741 < c && c < -1.02509)) { + result = ((2.0 * c) / (-3.5 + (-1.0 * sqrt(((-12.0 * c) + 12.25))))); + } else { + result = (c * 2.0) / (-3.5 - sqrt(((3.5 * 3.5) - ((3.0 * c) * 4.0)))); + } + return result; + } else { + if((0.769698 < c && c < 1.02083)) { + result = ((-3.5 + sqrt(fma(-12.0, c, 12.25))) / 6.0); + } else { + result = (-3.5 + sqrt(((3.5 * 3.5) - ((3.0 * c) * 4.0)))) / (3.0 * 2.0); + } + return result; + } + return result; +} diff --git a/srcTest/smartRoot_2/expr_smartRoot_2_herbie.c b/srcTest/smartRoot_2/expr_smartRoot_2_herbie.c new file mode 100644 index 0000000..0143542 --- /dev/null +++ b/srcTest/smartRoot_2/expr_smartRoot_2_herbie.c @@ -0,0 +1,20 @@ +#include +double expr_smartRoot_2_herbie(double c) { + double t_0 = sqrt((12.25 + ((3.0 * c) * -4.0))); + double t_1 = (-3.5 + t_0) / 6.0; + double tmp_1; + if ((12.25 - (3.0 * c)) > 10.0) { + double tmp_2; + if (3.5 > 0.0) { + tmp_2 = (c * 2.0) / (-3.5 - t_0); + } else if (3.5 < 0.0) { + tmp_2 = t_1; + } else { + tmp_2 = t_1; + } + tmp_1 = tmp_2; + } else { + tmp_1 = t_1; + } + return tmp_1; +} \ No newline at end of file diff --git a/srcTest/smartRoot_2/expr_smartRoot_2_herbieArfa.c b/srcTest/smartRoot_2/expr_smartRoot_2_herbieArfa.c new file mode 100644 index 0000000..ebfadd1 --- /dev/null +++ b/srcTest/smartRoot_2/expr_smartRoot_2_herbieArfa.c @@ -0,0 +1,8 @@ +#include +double expr_smartRoot_2_herbieArfa(double c) { + if (c < 0.75) { + return 2.0 * (c / (-3.5 - sqrt((12.25 + (c * -12.0))))); + } else { + return (-3.5 + sqrt(fma(c, -12.0, 12.25))) / 6.0; + } +} diff --git a/srcTest/smartRoot_2/expr_smartRoot_2_mpfr.c b/srcTest/smartRoot_2/expr_smartRoot_2_mpfr.c new file mode 100644 index 0000000..dad4307 --- /dev/null +++ b/srcTest/smartRoot_2/expr_smartRoot_2_mpfr.c @@ -0,0 +1,137 @@ +#include +#include +#include +#include + +int expr_smartRoot_1_mpfr(double c, mpfr_t mpfrResult) { + int status = 0; + mpfr_t mp1, mp2, mp3, mp4, mp5, mp6, mp7, mp8, mp9, mp10, mp11, mp12, mp13, mp14, mp15, mp16, mp17, mp18; + mpfr_init2(mp1, 128); + mpfr_init2(mp2, 128); + mpfr_init2(mp3, 128); + mpfr_init2(mp4, 128); + mpfr_init2(mp5, 128); + mpfr_init2(mp6, 128); + mpfr_init2(mp7, 128); + mpfr_init2(mp8, 128); + mpfr_init2(mp9, 128); + mpfr_init2(mp10, 128); + mpfr_init2(mp11, 128); + mpfr_init2(mp12, 128); + mpfr_init2(mp13, 128); + mpfr_init2(mp14, 128); + mpfr_init2(mp15, 128); + mpfr_init2(mp16, 128); + mpfr_init2(mp17, 128); + mpfr_init2(mp18, 128); + mpfr_set_d(mp1, c, MPFR_RNDN); + mpfr_set_d(mp2, 2, MPFR_RNDN); + mpfr_mul(mp3, mp1, mp2, MPFR_RNDN); + mpfr_set_d(mp4, -1, MPFR_RNDN); + mpfr_set_d(mp5, 3.5, MPFR_RNDN); + mpfr_mul(mp6, mp4, mp5, MPFR_RNDN); + mpfr_set_d(mp7, 3.5, MPFR_RNDN); + mpfr_set_d(mp8, 3.5, MPFR_RNDN); + mpfr_mul(mp9, mp7, mp8, MPFR_RNDN); + mpfr_set_d(mp10, 3, MPFR_RNDN); + mpfr_set_d(mp11, c, MPFR_RNDN); + mpfr_mul(mp12, mp10, mp11, MPFR_RNDN); + mpfr_set_d(mp13, 4, MPFR_RNDN); + mpfr_mul(mp14, mp12, mp13, MPFR_RNDN); + mpfr_sub(mp15, mp9, mp14, MPFR_RNDN); + mpfr_sqrt(mp16, mp15, MPFR_RNDN); + mpfr_sub(mp17, mp6, mp16, MPFR_RNDN); + mpfr_div(mp18, mp3, mp17, MPFR_RNDN); + + mpfr_set(mpfrResult, mp18, MPFR_RNDN); + mpfr_clear(mp1); + mpfr_clear(mp2); + mpfr_clear(mp3); + mpfr_clear(mp4); + mpfr_clear(mp5); + mpfr_clear(mp6); + mpfr_clear(mp7); + mpfr_clear(mp8); + mpfr_clear(mp9); + mpfr_clear(mp10); + mpfr_clear(mp11); + mpfr_clear(mp12); + mpfr_clear(mp13); + mpfr_clear(mp14); + mpfr_clear(mp15); + mpfr_clear(mp16); + mpfr_clear(mp17); + mpfr_clear(mp18); + return status; +} + +int expr_smartRoot_2_mpfr_old(double c, mpfr_t mpfrResult) { + int status = 0; + mpfr_t mp1, mp2, mp3, mp4, mp5, mp6, mp7, mp8, mp9, mp10, mp11, mp12, mp13, mp14, mp15, mp16, mp17, mp18; + mpfr_init2(mp1, 128); + mpfr_init2(mp2, 128); + mpfr_init2(mp3, 128); + mpfr_init2(mp4, 128); + mpfr_init2(mp5, 128); + mpfr_init2(mp6, 128); + mpfr_init2(mp7, 128); + mpfr_init2(mp8, 128); + mpfr_init2(mp9, 128); + mpfr_init2(mp10, 128); + mpfr_init2(mp11, 128); + mpfr_init2(mp12, 128); + mpfr_init2(mp13, 128); + mpfr_init2(mp14, 128); + mpfr_init2(mp15, 128); + mpfr_init2(mp16, 128); + mpfr_init2(mp17, 128); + mpfr_init2(mp18, 128); + mpfr_set_d(mp1, -1, MPFR_RNDN); + mpfr_set_d(mp2, 3.5, MPFR_RNDN); + mpfr_mul(mp3, mp1, mp2, MPFR_RNDN); + mpfr_set_d(mp4, 3.5, MPFR_RNDN); + mpfr_set_d(mp5, 3.5, MPFR_RNDN); + mpfr_mul(mp6, mp4, mp5, MPFR_RNDN); + mpfr_set_d(mp7, 3, MPFR_RNDN); + mpfr_set_d(mp8, c, MPFR_RNDN); + mpfr_mul(mp9, mp7, mp8, MPFR_RNDN); + mpfr_set_d(mp10, 4, MPFR_RNDN); + mpfr_mul(mp11, mp9, mp10, MPFR_RNDN); + mpfr_sub(mp12, mp6, mp11, MPFR_RNDN); + mpfr_sqrt(mp13, mp12, MPFR_RNDN); + mpfr_add(mp14, mp3, mp13, MPFR_RNDN); + mpfr_set_d(mp15, 3, MPFR_RNDN); + mpfr_set_d(mp16, 2, MPFR_RNDN); + mpfr_mul(mp17, mp15, mp16, MPFR_RNDN); + mpfr_div(mp18, mp14, mp17, MPFR_RNDN); + + mpfr_set(mpfrResult, mp18, MPFR_RNDN); + mpfr_clear(mp1); + mpfr_clear(mp2); + mpfr_clear(mp3); + mpfr_clear(mp4); + mpfr_clear(mp5); + mpfr_clear(mp6); + mpfr_clear(mp7); + mpfr_clear(mp8); + mpfr_clear(mp9); + mpfr_clear(mp10); + mpfr_clear(mp11); + mpfr_clear(mp12); + mpfr_clear(mp13); + mpfr_clear(mp14); + mpfr_clear(mp15); + mpfr_clear(mp16); + mpfr_clear(mp17); + mpfr_clear(mp18); + return status; +} + +int expr_smartRoot_2_mpfr(double c, mpfr_t mpfrResult) { + if (c < 0.75) { + expr_smartRoot_1_mpfr(c, mpfrResult); + } else { + expr_smartRoot_2_mpfr_old(c, mpfrResult); + } + return 0; +} \ No newline at end of file diff --git a/srcTest/smartRoot_2/expr_smartRoot_2_origin.c b/srcTest/smartRoot_2/expr_smartRoot_2_origin.c new file mode 100644 index 0000000..428fb34 --- /dev/null +++ b/srcTest/smartRoot_2/expr_smartRoot_2_origin.c @@ -0,0 +1,11 @@ +#include +double expr_smartRoot_2_origin(double c) +{ + double result; + if (c < 0.75) { + result = (c * 2.0) / (-3.5 - sqrt(((3.5 * 3.5) - ((3.0 * c) * 4.0)))); + } else { + result = (-3.5 + sqrt(((3.5 * 3.5) - ((3.0 * c) * 4.0)))) / (3.0 * 2.0); + } + return result; +} diff --git a/srcTest/squareRoot3Invalid_2/expr_squareRoot3Invalid_2_final.c b/srcTest/squareRoot3Invalid_2/expr_squareRoot3Invalid_2_final.c new file mode 100644 index 0000000..5e84861 --- /dev/null +++ b/srcTest/squareRoot3Invalid_2/expr_squareRoot3Invalid_2_final.c @@ -0,0 +1,21 @@ +#include "mine.h" +double expr_squareRoot3Invalid_2_final(double x) { + double tmp; + if (x < 0.0001) { + tmp = 1.0 + (x * 0.5); + } else { + double result; + if((0.0001 < x && x < 2.00874)) { + result = expr_squareRoot3Invalid_2_mpfr1(x); + } else if((3.00019 < x && x < 4.00354)) { + result = expr_squareRoot3Invalid_2_mpfr1(x); + } else if((6.98683 < x && x < 8.00514)) { + result = expr_squareRoot3Invalid_2_mpfr1(x); + } else { + result = sqrt(1 + x); + } + return result; + } + return tmp; + +} diff --git a/srcTest/squareRoot3Invalid_2/expr_squareRoot3Invalid_2_herbie.c b/srcTest/squareRoot3Invalid_2/expr_squareRoot3Invalid_2_herbie.c new file mode 100644 index 0000000..a6c882d --- /dev/null +++ b/srcTest/squareRoot3Invalid_2/expr_squareRoot3Invalid_2_herbie.c @@ -0,0 +1,10 @@ +#include +double expr_squareRoot3Invalid_2_herbie(double x) { + double tmp; + if (x < 0.0001) { + tmp = 1.0 + (x * 0.5); + } else { + tmp = sqrt((x + 1.0)); + } + return tmp; +} \ No newline at end of file diff --git a/srcTest/squareRoot3Invalid_2/expr_squareRoot3Invalid_2_herbieArfa.c b/srcTest/squareRoot3Invalid_2/expr_squareRoot3Invalid_2_herbieArfa.c new file mode 100644 index 0000000..14d9ebf --- /dev/null +++ b/srcTest/squareRoot3Invalid_2/expr_squareRoot3Invalid_2_herbieArfa.c @@ -0,0 +1,38 @@ +#include +double expr_squareRoot3Invalid_2_herbieArfa(double x) { + double tmp; + if (x < 0.0001) { + tmp = 1.0 + (x * 0.5); + } else { + double result; + if((0.0001 < x && x < 2.00874)) { + double tmp; + if (x < 0.0001) { + tmp = 1.0 + (x * 0.5); + } else { + tmp = exp((0.5 * log1p(x))); + } + return tmp; + } else if((3.00019 < x && x < 4.00354)) { + double tmp; + if (x < 0.0001) { + tmp = 1.0 + (x * 0.5); + } else { + tmp = exp((0.5 * log1p(x))); + } + return tmp; + } else if((6.98683 < x && x < 8.00514)) { + double tmp; + if (x < 0.0001) { + tmp = 1.0 + (x * 0.5); + } else { + tmp = exp((0.5 * log1p(x))); + } + return tmp; + } else { + result = sqrt(1 + x); + } + return result; + } + return tmp; +} \ No newline at end of file diff --git a/srcTest/squareRoot3Invalid_2/expr_squareRoot3Invalid_2_herbiePlus.c b/srcTest/squareRoot3Invalid_2/expr_squareRoot3Invalid_2_herbiePlus.c new file mode 100644 index 0000000..89fa18c --- /dev/null +++ b/srcTest/squareRoot3Invalid_2/expr_squareRoot3Invalid_2_herbiePlus.c @@ -0,0 +1,10 @@ +#include +double expr_squareRoot3Invalid_2_herbiePlus(double x) { + double tmp; + if (x < 0.0001) { + tmp = fma(x, 0.5, 1.0); + } else { + tmp = sqrt((x + 1.0)); + } + return tmp; +} \ No newline at end of file diff --git a/srcTest/squareRoot3Invalid_2/expr_squareRoot3Invalid_2_mpfr.c b/srcTest/squareRoot3Invalid_2/expr_squareRoot3Invalid_2_mpfr.c new file mode 100644 index 0000000..adabe47 --- /dev/null +++ b/srcTest/squareRoot3Invalid_2/expr_squareRoot3Invalid_2_mpfr.c @@ -0,0 +1,55 @@ +#include +#include +#include +#include + +int expr_squareRoot3Invalid_1_mpfr(double x, mpfr_t mpfrResult) { + int status = 0; + mpfr_t mp1, mp2, mp3, mp4, mp5; + mpfr_init2(mp1, 128); + mpfr_init2(mp2, 128); + mpfr_init2(mp3, 128); + mpfr_init2(mp4, 128); + mpfr_init2(mp5, 128); + mpfr_set_d(mp1, 1, MPFR_RNDN); + mpfr_set_d(mp2, 0.5, MPFR_RNDN); + mpfr_set_d(mp3, x, MPFR_RNDN); + mpfr_mul(mp4, mp2, mp3, MPFR_RNDN); + mpfr_add(mp5, mp1, mp4, MPFR_RNDN); + + mpfr_set(mpfrResult, mp5, MPFR_RNDN); + mpfr_clear(mp1); + mpfr_clear(mp2); + mpfr_clear(mp3); + mpfr_clear(mp4); + mpfr_clear(mp5); + return status; +} + +int expr_squareRoot3Invalid_2_mpfr_old(double x, mpfr_t mpfrResult) { + int status = 0; + mpfr_t mp1, mp2, mp3, mp4; + mpfr_init2(mp1, 128); + mpfr_init2(mp2, 128); + mpfr_init2(mp3, 128); + mpfr_init2(mp4, 128); + mpfr_set_d(mp1, 1, MPFR_RNDN); + mpfr_set_d(mp2, x, MPFR_RNDN); + mpfr_add(mp3, mp1, mp2, MPFR_RNDN); + mpfr_sqrt(mp4, mp3, MPFR_RNDN); + + mpfr_set(mpfrResult, mp4, MPFR_RNDN); + mpfr_clear(mp1); + mpfr_clear(mp2); + mpfr_clear(mp3); + mpfr_clear(mp4); + return status; +} + +int expr_squareRoot3Invalid_2_mpfr(double x, mpfr_t mpfrResult) { + if (x < 0.0001) { + expr_squareRoot3Invalid_1_mpfr(x, mpfrResult); + } else { + expr_squareRoot3Invalid_2_mpfr_old(x, mpfrResult); + } +} \ No newline at end of file diff --git a/srcTest/squareRoot3Invalid_2/expr_squareRoot3Invalid_2_origin.c b/srcTest/squareRoot3Invalid_2/expr_squareRoot3Invalid_2_origin.c new file mode 100644 index 0000000..bc55a61 --- /dev/null +++ b/srcTest/squareRoot3Invalid_2/expr_squareRoot3Invalid_2_origin.c @@ -0,0 +1,11 @@ +#include +double expr_squareRoot3Invalid_2_origin(double x) +{ + double tmp; + if (x < 0.0001) { + tmp = 1.0 + (x * 0.5); + } else { + tmp = sqrt((x + 1.0)); + } + return tmp; +} diff --git a/srcTest/squareRoot3_2/expr_squareRoot3_2_final.c b/srcTest/squareRoot3_2/expr_squareRoot3_2_final.c new file mode 100644 index 0000000..926d2f6 --- /dev/null +++ b/srcTest/squareRoot3_2/expr_squareRoot3_2_final.c @@ -0,0 +1,20 @@ +#include "mine.h" +double expr_squareRoot3_2_final(double x) { + double tmp; + if (x < 1e-5) { + tmp = 1.0 + 0.5 * x; + } else { + double result; + if((0.00015 < x && x < 2.01059)) { + result = expr_squareRoot3_2_mpfr1(x); + } else if((2.98753 < x && x < 4.01163)) { + result = expr_squareRoot3_2_mpfr1(x); + } else if((6.99244 < x && x < 8.0116)) { + result = expr_squareRoot3_2_mpfr1(x); + } else { + result = sqrt(1 + x); + } + return result; + } + return tmp; +} diff --git a/srcTest/squareRoot3_2/expr_squareRoot3_2_herbie.c b/srcTest/squareRoot3_2/expr_squareRoot3_2_herbie.c new file mode 100644 index 0000000..2669401 --- /dev/null +++ b/srcTest/squareRoot3_2/expr_squareRoot3_2_herbie.c @@ -0,0 +1,10 @@ +#include +double expr_squareRoot3_2_herbie(double x) { + double tmp; + if (x < 1e-5) { + tmp = fma(x, 0.5, 1.0); + } else { + tmp = sqrt((x + 1.0)); + } + return tmp; +} \ No newline at end of file diff --git a/srcTest/squareRoot3_2/expr_squareRoot3_2_herbieArfa.c b/srcTest/squareRoot3_2/expr_squareRoot3_2_herbieArfa.c new file mode 100644 index 0000000..8e2a6d7 --- /dev/null +++ b/srcTest/squareRoot3_2/expr_squareRoot3_2_herbieArfa.c @@ -0,0 +1,38 @@ +#include +double expr_squareRoot3_2_herbieArfa(double x) { + double tmp; + double result; + if (x < 1e-5) { + tmp = 1.0 + 0.5 * x; + } else { + if((0.00015 < x && x < 2.01059)) { + double tmp; + if (x < 1e-5) { + tmp = fma(x, 0.5, 1.0); + } else { + tmp = exp((0.5 * log1p(x))); + } + return tmp; + } else if((2.98753 < x && x < 4.01163)) { + double tmp; + if (x < 1e-5) { + tmp = fma(x, 0.5, 1.0); + } else { + tmp = exp((0.5 * log1p(x))); + } + return tmp; + } else if((6.99244 < x && x < 8.0116)) { + double tmp; + if (x < 1e-5) { + tmp = fma(x, 0.5, 1.0); + } else { + tmp = exp((0.5 * log1p(x))); + } + return tmp; + } else { + result = sqrt(1 + x); + } + return result; + } + return tmp; +} \ No newline at end of file diff --git a/srcTest/squareRoot3_2/expr_squareRoot3_2_herbiePlus.c b/srcTest/squareRoot3_2/expr_squareRoot3_2_herbiePlus.c new file mode 100644 index 0000000..1373899 --- /dev/null +++ b/srcTest/squareRoot3_2/expr_squareRoot3_2_herbiePlus.c @@ -0,0 +1,10 @@ +#include +double expr_squareRoot3_2_herbiePlus(double x) { + double tmp; + if (x < 1e-5) { + tmp = fma(x, 0.5, 1.0); + } else { + tmp = sqrt((x + 1.0)); + } + return tmp; +} \ No newline at end of file diff --git a/srcTest/squareRoot3_2/expr_squareRoot3_2_mpfr.c b/srcTest/squareRoot3_2/expr_squareRoot3_2_mpfr.c new file mode 100644 index 0000000..1ac2b5c --- /dev/null +++ b/srcTest/squareRoot3_2/expr_squareRoot3_2_mpfr.c @@ -0,0 +1,55 @@ +#include +#include +#include +#include + +int expr_squareRoot3_2_mpfr_old(double x, mpfr_t mpfrResult) { + int status = 0; + mpfr_t mp1, mp2, mp3, mp4; + mpfr_init2(mp1, 128); + mpfr_init2(mp2, 128); + mpfr_init2(mp3, 128); + mpfr_init2(mp4, 128); + mpfr_set_d(mp1, 1, MPFR_RNDN); + mpfr_set_d(mp2, x, MPFR_RNDN); + mpfr_add(mp3, mp1, mp2, MPFR_RNDN); + mpfr_sqrt(mp4, mp3, MPFR_RNDN); + + mpfr_set(mpfrResult, mp4, MPFR_RNDN); + mpfr_clear(mp1); + mpfr_clear(mp2); + mpfr_clear(mp3); + mpfr_clear(mp4); + return status; +} + +int expr_squareRoot3_1_mpfr(double x, mpfr_t mpfrResult) { + int status = 0; + mpfr_t mp1, mp2, mp3, mp4, mp5; + mpfr_init2(mp1, 128); + mpfr_init2(mp2, 128); + mpfr_init2(mp3, 128); + mpfr_init2(mp4, 128); + mpfr_init2(mp5, 128); + mpfr_set_d(mp1, 1, MPFR_RNDN); + mpfr_set_d(mp2, 0.5, MPFR_RNDN); + mpfr_set_d(mp3, x, MPFR_RNDN); + mpfr_mul(mp4, mp2, mp3, MPFR_RNDN); + mpfr_add(mp5, mp1, mp4, MPFR_RNDN); + + mpfr_set(mpfrResult, mp5, MPFR_RNDN); + mpfr_clear(mp1); + mpfr_clear(mp2); + mpfr_clear(mp3); + mpfr_clear(mp4); + mpfr_clear(mp5); + return status; +} + +int expr_squareRoot3_2_mpfr(double x, mpfr_t mpfrResult) { + if (x < 1e-5) { + expr_squareRoot3_1_mpfr(x, mpfrResult); + } else { + expr_squareRoot3_2_mpfr_old(x, mpfrResult); + } +} \ No newline at end of file diff --git a/srcTest/squareRoot3_2/expr_squareRoot3_2_origin.c b/srcTest/squareRoot3_2/expr_squareRoot3_2_origin.c new file mode 100644 index 0000000..0c297cf --- /dev/null +++ b/srcTest/squareRoot3_2/expr_squareRoot3_2_origin.c @@ -0,0 +1,11 @@ +#include +double expr_squareRoot3_2_origin(double x) +{ + double tmp; + if (x < 1e-5) { + tmp = 1.0 + (x * 0.5); + } else { + tmp = sqrt((x + 1.0)); + } + return tmp; +} diff --git a/srcTest/triangleSorted_2/expr_triangleSorted_2_herbie.c b/srcTest/triangleSorted_2/expr_triangleSorted_2_herbie.c new file mode 100644 index 0000000..824d54b --- /dev/null +++ b/srcTest/triangleSorted_2/expr_triangleSorted_2_herbie.c @@ -0,0 +1,12 @@ +#include +double expr_triangleSorted_2_herbie(double a, double b, double c) { + double t_0 = b + (c - a); + double t_1 = (c + (a - b)) * (a + (b + c)); + double tmp; + if (a < b) { + tmp = sqrt((((a + (b - c)) * t_1) * t_0)) / 4.0; + } else { + tmp = sqrt((t_0 * (t_1 * (b + (a - c))))) / 4.0; + } + return tmp; +} \ No newline at end of file diff --git a/srcTest/triangleSorted_2/expr_triangleSorted_2_herbiePlus.c b/srcTest/triangleSorted_2/expr_triangleSorted_2_herbiePlus.c new file mode 100644 index 0000000..2981c78 --- /dev/null +++ b/srcTest/triangleSorted_2/expr_triangleSorted_2_herbiePlus.c @@ -0,0 +1,12 @@ +#include +double expr_triangleSorted_2_herbiePlus(double a, double b, double c) { + double t_0 = b + (c - a); + double t_1 = (c + (a - b)) * (a + (b + c)); + double tmp; + if (a < b) { + tmp = sqrt((((a + (b - c)) * t_1) * t_0)) / 4.0; + } else { + tmp = sqrt((t_0 * (t_1 * (b + (a - c))))) / 4.0; + } + return tmp; +} \ No newline at end of file diff --git a/srcTest/triangleSorted_2/expr_triangleSorted_2_mpfr.c b/srcTest/triangleSorted_2/expr_triangleSorted_2_mpfr.c new file mode 100644 index 0000000..146f149 --- /dev/null +++ b/srcTest/triangleSorted_2/expr_triangleSorted_2_mpfr.c @@ -0,0 +1,184 @@ +#include +#include +#include +#include + +int expr_triangleSorted_1_mpfr(double a, double b, double c, mpfr_t mpfrResult) { + int status = 0; + mpfr_t mp1, mp2, mp3, mp4, mp5, mp6, mp7, mp8, mp9, mp10, mp11, mp12, mp13, mp14, mp15, mp16, mp17, mp18, mp19, mp20, mp21, mp22, mp23, mp24, mp25, mp26; + mpfr_init2(mp1, 128); + mpfr_init2(mp2, 128); + mpfr_init2(mp3, 128); + mpfr_init2(mp4, 128); + mpfr_init2(mp5, 128); + mpfr_init2(mp6, 128); + mpfr_init2(mp7, 128); + mpfr_init2(mp8, 128); + mpfr_init2(mp9, 128); + mpfr_init2(mp10, 128); + mpfr_init2(mp11, 128); + mpfr_init2(mp12, 128); + mpfr_init2(mp13, 128); + mpfr_init2(mp14, 128); + mpfr_init2(mp15, 128); + mpfr_init2(mp16, 128); + mpfr_init2(mp17, 128); + mpfr_init2(mp18, 128); + mpfr_init2(mp19, 128); + mpfr_init2(mp20, 128); + mpfr_init2(mp21, 128); + mpfr_init2(mp22, 128); + mpfr_init2(mp23, 128); + mpfr_init2(mp24, 128); + mpfr_init2(mp25, 128); + mpfr_init2(mp26, 128); + mpfr_set_d(mp1, c, MPFR_RNDN); + mpfr_set_d(mp2, b, MPFR_RNDN); + mpfr_set_d(mp3, a, MPFR_RNDN); + mpfr_add(mp4, mp2, mp3, MPFR_RNDN); + mpfr_add(mp5, mp1, mp4, MPFR_RNDN); + mpfr_set_d(mp6, a, MPFR_RNDN); + mpfr_set_d(mp7, c, MPFR_RNDN); + mpfr_set_d(mp8, b, MPFR_RNDN); + mpfr_sub(mp9, mp7, mp8, MPFR_RNDN); + mpfr_sub(mp10, mp6, mp9, MPFR_RNDN); + mpfr_mul(mp11, mp5, mp10, MPFR_RNDN); + mpfr_set_d(mp12, a, MPFR_RNDN); + mpfr_set_d(mp13, c, MPFR_RNDN); + mpfr_set_d(mp14, b, MPFR_RNDN); + mpfr_sub(mp15, mp13, mp14, MPFR_RNDN); + mpfr_add(mp16, mp12, mp15, MPFR_RNDN); + mpfr_mul(mp17, mp11, mp16, MPFR_RNDN); + mpfr_set_d(mp18, c, MPFR_RNDN); + mpfr_set_d(mp19, b, MPFR_RNDN); + mpfr_set_d(mp20, a, MPFR_RNDN); + mpfr_sub(mp21, mp19, mp20, MPFR_RNDN); + mpfr_add(mp22, mp18, mp21, MPFR_RNDN); + mpfr_mul(mp23, mp17, mp22, MPFR_RNDN); + mpfr_sqrt(mp24, mp23, MPFR_RNDN); + mpfr_set_d(mp25, 4, MPFR_RNDN); + mpfr_div(mp26, mp24, mp25, MPFR_RNDN); + + mpfr_set(mpfrResult, mp26, MPFR_RNDN); + mpfr_clear(mp1); + mpfr_clear(mp2); + mpfr_clear(mp3); + mpfr_clear(mp4); + mpfr_clear(mp5); + mpfr_clear(mp6); + mpfr_clear(mp7); + mpfr_clear(mp8); + mpfr_clear(mp9); + mpfr_clear(mp10); + mpfr_clear(mp11); + mpfr_clear(mp12); + mpfr_clear(mp13); + mpfr_clear(mp14); + mpfr_clear(mp15); + mpfr_clear(mp16); + mpfr_clear(mp17); + mpfr_clear(mp18); + mpfr_clear(mp19); + mpfr_clear(mp20); + mpfr_clear(mp21); + mpfr_clear(mp22); + mpfr_clear(mp23); + mpfr_clear(mp24); + mpfr_clear(mp25); + mpfr_clear(mp26); + return status; +} + +int expr_triangleSorted_2_mpfr_old(double a, double b, double c, mpfr_t mpfrResult) { + int status = 0; + mpfr_t mp1, mp2, mp3, mp4, mp5, mp6, mp7, mp8, mp9, mp10, mp11, mp12, mp13, mp14, mp15, mp16, mp17, mp18, mp19, mp20, mp21, mp22, mp23, mp24, mp25, mp26; + mpfr_init2(mp1, 128); + mpfr_init2(mp2, 128); + mpfr_init2(mp3, 128); + mpfr_init2(mp4, 128); + mpfr_init2(mp5, 128); + mpfr_init2(mp6, 128); + mpfr_init2(mp7, 128); + mpfr_init2(mp8, 128); + mpfr_init2(mp9, 128); + mpfr_init2(mp10, 128); + mpfr_init2(mp11, 128); + mpfr_init2(mp12, 128); + mpfr_init2(mp13, 128); + mpfr_init2(mp14, 128); + mpfr_init2(mp15, 128); + mpfr_init2(mp16, 128); + mpfr_init2(mp17, 128); + mpfr_init2(mp18, 128); + mpfr_init2(mp19, 128); + mpfr_init2(mp20, 128); + mpfr_init2(mp21, 128); + mpfr_init2(mp22, 128); + mpfr_init2(mp23, 128); + mpfr_init2(mp24, 128); + mpfr_init2(mp25, 128); + mpfr_init2(mp26, 128); + mpfr_set_d(mp1, c, MPFR_RNDN); + mpfr_set_d(mp2, a, MPFR_RNDN); + mpfr_set_d(mp3, b, MPFR_RNDN); + mpfr_add(mp4, mp2, mp3, MPFR_RNDN); + mpfr_add(mp5, mp1, mp4, MPFR_RNDN); + mpfr_set_d(mp6, b, MPFR_RNDN); + mpfr_set_d(mp7, c, MPFR_RNDN); + mpfr_set_d(mp8, a, MPFR_RNDN); + mpfr_sub(mp9, mp7, mp8, MPFR_RNDN); + mpfr_sub(mp10, mp6, mp9, MPFR_RNDN); + mpfr_mul(mp11, mp5, mp10, MPFR_RNDN); + mpfr_set_d(mp12, b, MPFR_RNDN); + mpfr_set_d(mp13, c, MPFR_RNDN); + mpfr_set_d(mp14, a, MPFR_RNDN); + mpfr_sub(mp15, mp13, mp14, MPFR_RNDN); + mpfr_add(mp16, mp12, mp15, MPFR_RNDN); + mpfr_mul(mp17, mp11, mp16, MPFR_RNDN); + mpfr_set_d(mp18, c, MPFR_RNDN); + mpfr_set_d(mp19, a, MPFR_RNDN); + mpfr_set_d(mp20, b, MPFR_RNDN); + mpfr_sub(mp21, mp19, mp20, MPFR_RNDN); + mpfr_add(mp22, mp18, mp21, MPFR_RNDN); + mpfr_mul(mp23, mp17, mp22, MPFR_RNDN); + mpfr_sqrt(mp24, mp23, MPFR_RNDN); + mpfr_set_d(mp25, 4, MPFR_RNDN); + mpfr_div(mp26, mp24, mp25, MPFR_RNDN); + + mpfr_set(mpfrResult, mp26, MPFR_RNDN); + mpfr_clear(mp1); + mpfr_clear(mp2); + mpfr_clear(mp3); + mpfr_clear(mp4); + mpfr_clear(mp5); + mpfr_clear(mp6); + mpfr_clear(mp7); + mpfr_clear(mp8); + mpfr_clear(mp9); + mpfr_clear(mp10); + mpfr_clear(mp11); + mpfr_clear(mp12); + mpfr_clear(mp13); + mpfr_clear(mp14); + mpfr_clear(mp15); + mpfr_clear(mp16); + mpfr_clear(mp17); + mpfr_clear(mp18); + mpfr_clear(mp19); + mpfr_clear(mp20); + mpfr_clear(mp21); + mpfr_clear(mp22); + mpfr_clear(mp23); + mpfr_clear(mp24); + mpfr_clear(mp25); + mpfr_clear(mp26); + return status; +} + +int expr_triangleSorted_2_mpfr(double a, double b, double c, mpfr_t mpfrResult) { + if (a < b) { + expr_triangleSorted_2_mpfr_old(a, b, c, mpfrResult); + } else { + expr_triangleSorted_1_mpfr(a, b, c, mpfrResult); + } +} \ No newline at end of file diff --git a/srcTest/triangleSorted_2/expr_triangleSorted_2_origin.c b/srcTest/triangleSorted_2/expr_triangleSorted_2_origin.c new file mode 100644 index 0000000..e84eee6 --- /dev/null +++ b/srcTest/triangleSorted_2/expr_triangleSorted_2_origin.c @@ -0,0 +1,10 @@ +#include +double expr_triangleSorted_2_origin(double a, double b, double c) { + double tmp; + if (a < b) { + tmp = sqrt(((((c + (b + a)) * (a - (c - b))) * (a + (c - b))) * (c + (b - a)))) / 4.0; + } else { + tmp = sqrt(((((c + (a + b)) * (b - (c - a))) * (b + (c - a))) * (c + (a - b)))) / 4.0; + } + return tmp; +} -- Gitee From 5ce9a6c1f53ec6003f1a6b59a1066050355ce9a3 Mon Sep 17 00:00:00 2001 From: hjwLab Date: Fri, 14 Apr 2023 05:13:42 +0800 Subject: [PATCH 24/32] Add NumOpt code and update detectErrorAll.sh --- detectErrorAll.sh | 8 +- script/input/cav10_2_opt.cc | 59 ++++++++++ script/input/pov_ray_opt.cc | 57 +++++++++ script/input/smartRoot_2_opt.cc | 59 ++++++++++ script/input/squareRoot3Invalid_2_opt.cc | 59 ++++++++++ script/input/squareRoot3_2_opt.cc | 59 ++++++++++ script/input/triangleSorted_2_opt.cc | 108 ++++++++++++++++++ script/replaceAll.sh | 6 + srcTest/cav10_2/expr_cav10_2_NumOpt.cpp | 54 +++++++++ srcTest/pov_ray/expr_pov_ray_NumOpt.cpp | 48 ++++++++ .../smartRoot_2/expr_smartRoot_2_NumOpt.cpp | 54 +++++++++ .../expr_squareRoot3Invalid_2_NumOpt.cpp | 54 +++++++++ .../expr_squareRoot3_2_NumOpt.cpp | 54 +++++++++ .../expr_triangleSorted_2_NumOpt.cpp | 101 ++++++++++++++++ 14 files changed, 779 insertions(+), 1 deletion(-) create mode 100644 script/input/cav10_2_opt.cc create mode 100644 script/input/pov_ray_opt.cc create mode 100644 script/input/smartRoot_2_opt.cc create mode 100644 script/input/squareRoot3Invalid_2_opt.cc create mode 100644 script/input/squareRoot3_2_opt.cc create mode 100644 script/input/triangleSorted_2_opt.cc create mode 100644 srcTest/cav10_2/expr_cav10_2_NumOpt.cpp create mode 100644 srcTest/pov_ray/expr_pov_ray_NumOpt.cpp create mode 100644 srcTest/smartRoot_2/expr_smartRoot_2_NumOpt.cpp create mode 100644 srcTest/squareRoot3Invalid_2/expr_squareRoot3Invalid_2_NumOpt.cpp create mode 100644 srcTest/squareRoot3_2/expr_squareRoot3_2_NumOpt.cpp create mode 100644 srcTest/triangleSorted_2/expr_triangleSorted_2_NumOpt.cpp diff --git a/detectErrorAll.sh b/detectErrorAll.sh index 19e1027..eac27c2 100755 --- a/detectErrorAll.sh +++ b/detectErrorAll.sh @@ -69,4 +69,10 @@ fi # ./detectErrorTwoFPEDParallel${suffix}.sh sec4example 1.001 2 1.001 2 1024 1024 0 0 1.001 1.001 0.0009755859375000001 0.0009755859375000001 expr_sec4example 1.001_2_1.001_2_1024_1024 ${target} # ./detectErrorTwoFPEDParallel${suffix}.sh test03_nonlin2 0 1 -1 -0.1 1024 1024 0 0 0 -1 0.0009765625 0.00087890625 expr_test03_nonlin2 0_1_-1_-0.1_1024_1024 ${target} # ./detectErrorTwoFPEDParallel${suffix}.sh theta 1 100 1 100 1024 1024 0 0 1 1 0.0966796875 0.0966796875 expr_theta 1_100_1_100_1024_1024 ${target} -# ./detectErrorThreeFPEDParallel${suffix}.sh turbine1 3.8 7.8 -4.5 -0.3 0.4 0.9 256 256 256 0 0 0 3.8 -4.5 0.4 0.015625 0.01640625 0.001953125 expr_turbine1 3.8_7.8_-4.5_-0.3_0.4_0.9_256_256_256 ${target} \ No newline at end of file +# ./detectErrorThreeFPEDParallel${suffix}.sh turbine1 3.8 7.8 -4.5 -0.3 0.4 0.9 256 256 256 0 0 0 3.8 -4.5 0.4 0.015625 0.01640625 0.001953125 expr_turbine1 3.8_7.8_-4.5_-0.3_0.4_0.9_256_256_256 ${target} + +# DONE +./detectErrorOneFPEDParallelNumOpt.sh squareRoot3_2 0 10 500000 0 0 2e-05 expr_squareRoot3_2 0_10_500000 NumOpt +./detectErrorOneFPEDParallelNumOpt.sh smartRoot_2 -2 2 500000 0 -2 8e-06 expr_smartRoot_2 -2_2_500000 NumOpt +./detectErrorOneFPEDParallelNumOpt.sh squareRoot3Invalid_2 0 10 500000 0 0 2e-05 expr_squareRoot3Invalid_2 0_10_500000 NumOpt +./detectErrorOneFPEDParallelNumOpt.sh cav10_2 0 10 500000 0 0 2e-05 expr_cav10_2 0_10_500000 NumOpt \ No newline at end of file diff --git a/script/input/cav10_2_opt.cc b/script/input/cav10_2_opt.cc new file mode 100644 index 0000000..bdb633a --- /dev/null +++ b/script/input/cav10_2_opt.cc @@ -0,0 +1,59 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((x*x)-x>=0&&(-6.083282645501321e+303<=x)&&(x<=3.875119102832546e+307)) { + r = x/10; + return r; + } + + if((x*x)-x<0&&(1.114287922540996e-298<=x)&&(x<=1.2770265159116257e-05)) { + r = x*x+2; + return r; + } + + if((x*x)-x>=0) { + r_real = x_real/10; + return r_real.as_double(); + } + + if((x*x)-x<0) { + r_real = x_real*x_real+2; + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/pov_ray_opt.cc b/script/input/pov_ray_opt.cc new file mode 100644 index 0000000..a62e851 --- /dev/null +++ b/script/input/pov_ray_opt.cc @@ -0,0 +1,57 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x1, double x2, double x3, double x4, double x5) +{ + REAL x1_real(x1); + REAL x2_real(x2); + REAL x3_real(x3); + REAL x4_real(x4); + REAL x5_real(x5); + double r; + REAL r_real; + + if(((-1 <= x1) && (x1 <= 1) && (-1<=x5) && (x5<=1) && (-3.1415926535897932384626433832795 <= x2) && (x2 <= 3.1415926535897932384626433832795) && (-3.1415926535897932384626433832795 <= x3) && (x3 <= 3.1415926535897932384626433832795) && (-1 <= x4) && (x4 <= 1))&&(-4.9361672509868313e-05<=x1)&&(x1<=0.00012576726982661083)) { + r = x1*cos(x2)*cos(x3)+x4*cos(x2)+x5*cos(x2)*sin(x3); + return r; + } + + if(((-1 <= x1) && (x1 <= 1) && (-1<=x5) && (x5<=1) && (-3.1415926535897932384626433832795 <= x2) && (x2 <= 3.1415926535897932384626433832795) && (-3.1415926535897932384626433832795 <= x3) && (x3 <= 3.1415926535897932384626433832795) && (-1 <= x4) && (x4 <= 1))) { + r_real = x1_real*iRRAM::cos((REAL)x2_real)*iRRAM::cos((REAL)x3_real)+x4_real*iRRAM::cos((REAL)x2_real)+x5_real*iRRAM::cos((REAL)x2_real)*iRRAM::sin((REAL)x3_real); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x1_str,x2_str,x3_str,x4_str,x5_str; + iRRAM::cin >> x1_str >> x2_str >> x3_str >> x4_str >> x5_str; + double x1_double = binary2double(x1_str); + double x2_double = binary2double(x2_str); + double x3_double = binary2double(x3_str); + double x4_double = binary2double(x4_str); + double x5_double = binary2double(x5_str); + double r_double = irram_sintan(x1_double, x2_double, x3_double, x4_double, x5_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/smartRoot_2_opt.cc b/script/input/smartRoot_2_opt.cc new file mode 100644 index 0000000..e24d089 --- /dev/null +++ b/script/input/smartRoot_2_opt.cc @@ -0,0 +1,59 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if(((3.5*3.5)-(3.0*x))>10.0&&(-1.498077612385249e+307<=x)&&(x<=0.030049679510853158)) { + r = (x*2.0)/(-3.5-sqrt(((3.5*3.5)-((3.0*x)*4.0)))); + return r; + } + + if(((3.5*3.5)-(3.0*x))<=10.0&&(1.0208333333332282<=x)&&(x<=1.0208333333332282)) { + r = (x*2.0)/(-3.5-sqrt(((3.5*3.5)-((3.0*x)*4.0)))); + return r; + } + + if(((3.5*3.5)-(3.0*x))>10.0) { + r_real = (x_real*REAL(2.0))/(-REAL(3.5)-iRRAM::sqrt((REAL)((REAL(3.5)*REAL(3.5))-((REAL(3.0)*x_real)*REAL(4.0))))); + return r_real.as_double(); + } + + if(((3.5*3.5)-(3.0*x))<=10.0) { + r_real = (x_real*REAL(2.0))/(-REAL(3.5)-iRRAM::sqrt((REAL)((REAL(3.5)*REAL(3.5))-((REAL(3.0)*x_real)*REAL(4.0))))); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/squareRoot3Invalid_2_opt.cc b/script/input/squareRoot3Invalid_2_opt.cc new file mode 100644 index 0000000..c445b6e --- /dev/null +++ b/script/input/squareRoot3Invalid_2_opt.cc @@ -0,0 +1,59 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if(x<0.0001&&(-5.849734155840792e+303<=x)&&(x<=4.8372664685901273e-05)) { + r = 1.0+(0.5*x); + return r; + } + + if(x>=0.0001&&(487476.22196357907<=x)&&(x<=1.2943681476239454e+303)) { + r = sqrt((1.0+x)); + return r; + } + + if(x<0.0001) { + r_real = REAL(1.0)+(REAL(0.5)*x_real); + return r_real.as_double(); + } + + if(x>=0.0001) { + r_real = iRRAM::sqrt((REAL)(REAL(1.0)+x_real)); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/squareRoot3_2_opt.cc b/script/input/squareRoot3_2_opt.cc new file mode 100644 index 0000000..77a5c7f --- /dev/null +++ b/script/input/squareRoot3_2_opt.cc @@ -0,0 +1,59 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if(x<1e-5&&(-4.884449476155393e+306<=x)&&(x<=1.6567059425414487e-14)) { + r = 1.0+(0.5*x); + return r; + } + + if(x>=1e-5&&(0.2162655827879985<=x)&&(x<=7.556698972072338e+306)) { + r = sqrt((1.0+x)); + return r; + } + + if(x<1e-5) { + r_real = REAL(1.0)+(REAL(0.5)*x_real); + return r_real.as_double(); + } + + if(x>=1e-5) { + r_real = iRRAM::sqrt((REAL)(REAL(1.0)+x_real)); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string x_str; + iRRAM::cin >> x_str; + double x_double = binary2double(x_str); + double r_double = irram_sintan(x_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/input/triangleSorted_2_opt.cc b/script/input/triangleSorted_2_opt.cc new file mode 100644 index 0000000..721358e --- /dev/null +++ b/script/input/triangleSorted_2_opt.cc @@ -0,0 +1,108 @@ + +#include +#include +#include +#include +#include + +#include "iRRAM.h" +#include "../../../../Source/backend/points.h" +#include "../../../../Source/backend/self_math.h" +#include "../../../../Source/backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + + +double irram_sintan(double a, double b, double c) +{ + REAL a_real(a); + REAL b_real(b); + REAL c_real(c); + double r; + REAL r_real; + + if(a < b&&(-9.838516996763401e-208<=a)&&(a<=-4.1527009680941224e-210)) { + r = sqrt(((((c + (b + a)) * (a - (c - b))) * (a + (c - b))) * (c + (b - a)))) / 4.0; + return r; + } + + if(a < b&&(-1.8472342742723307e-249<=a)&&(a<=-1.8472342742723307e-249)) { + r = sqrt(((((c + (b + a)) * (a - (c - b))) * (a + (c - b))) * (c + (b - a)))) / 4.0; + return r; + } + + if(a < b&&(-7.106569030933685e-277<=a)&&(a<=-6.532353551725582e-277)) { + r = sqrt(((((c + (b + a)) * (a - (c - b))) * (a + (c - b))) * (c + (b - a)))) / 4.0; + return r; + } + + if(a < b&&(2.5683516051161374e-257<=a)&&(a<=3.720652011351933e-257)) { + r = sqrt(((((c + (b + a)) * (a - (c - b))) * (a + (c - b))) * (c + (b - a)))) / 4.0; + return r; + } + + if(a < b&&(4.963328843187051e-245<=a)&&(a<=5.001730032770586e-245)) { + r = sqrt(((((c + (b + a)) * (a - (c - b))) * (a + (c - b))) * (c + (b - a)))) / 4.0; + return r; + } + + if(a < b&&(2.5192554908951825e-163<=a)&&(a<=2.6317839716959753e-163)) { + r = sqrt(((((c + (b + a)) * (a - (c - b))) * (a + (c - b))) * (c + (b - a)))) / 4.0; + return r; + } + + if(a >= b&&(-2.3836811794075206e-244<=a)&&(a<=-1.59705048161082e-244)) { + r = sqrt(((((c + (a + b)) * (b - (c - a))) * (b + (c - a))) * (c + (a - b)))) / 4.0; + return r; + } + + if(a >= b&&(-8.676363299047421e-277<=a)&&(a<=-8.676363299047421e-277)) { + r = sqrt(((((c + (a + b)) * (b - (c - a))) * (b + (c - a))) * (c + (a - b)))) / 4.0; + return r; + } + + if(a >= b&&(1.2731075244774277e-257<=a)&&(a<=1.2731075244774277e-257)) { + r = sqrt(((((c + (a + b)) * (b - (c - a))) * (b + (c - a))) * (c + (a - b)))) / 4.0; + return r; + } + + if(a >= b&&(2.821538577212522e-247<=a)&&(a<=2.821538577212522e-247)) { + r = sqrt(((((c + (a + b)) * (b - (c - a))) * (b + (c - a))) * (c + (a - b)))) / 4.0; + return r; + } + + if(a >= b&&(7.71945767527287e-164<=a)&&(a<=7.71945767527287e-164)) { + r = sqrt(((((c + (a + b)) * (b - (c - a))) * (b + (c - a))) * (c + (a - b)))) / 4.0; + return r; + } + + if(a < b) { + r_real = iRRAM::sqrt((REAL)((((c_real + (b_real + a_real)) * (a_real - (c_real - b_real))) * (a_real + (c_real - b_real))) * (c_real + (b_real - a_real)))) / REAL(4.0); + return r_real.as_double(); + } + + if(a >= b) { + r_real = iRRAM::sqrt((REAL)((((c_real + (a_real + b_real)) * (b_real - (c_real - a_real))) * (b_real + (c_real - a_real))) * (c_real + (a_real - b_real)))) / REAL(4.0); + return r_real.as_double(); + } + + return r; +} + +void compute() { + std::fesetround(FE_DOWNWARD); + std::string a_str,b_str,c_str; + iRRAM::cin >> a_str >> b_str >> c_str; + double a_double = binary2double(a_str); + double b_double = binary2double(b_str); + double c_double = binary2double(c_str); + double r_double = irram_sintan(a_double, b_double, c_double); + iRRAM::cout << double2binary(r_double) << "\n"; +} + diff --git a/script/replaceAll.sh b/script/replaceAll.sh index a22aedc..44c7083 100644 --- a/script/replaceAll.sh +++ b/script/replaceAll.sh @@ -37,3 +37,9 @@ ./replace.sh test05_nonlin1_r4 ./replace.sh test05_nonlin1_test2 ./replace.sh verhulst +./replace.sh squareRoot3_2 +./replace.sh squareRoot3Invalid_2 +./replace.sh cav10_2 +./replace.sh smartRoot_2 +./replace.sh triangleSorted_2 +./replace.sh pov_ray diff --git a/srcTest/cav10_2/expr_cav10_2_NumOpt.cpp b/srcTest/cav10_2/expr_cav10_2_NumOpt.cpp new file mode 100644 index 0000000..8e29cb5 --- /dev/null +++ b/srcTest/cav10_2/expr_cav10_2_NumOpt.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_cav10_2_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if((x*x)-x>=0&&(-6.083282645501321e+303<=x)&&(x<=3.875119102832546e+307)) { + r = x/10; + return r; + } + + if((x*x)-x<0&&(1.114287922540996e-298<=x)&&(x<=1.2770265159116257e-05)) { + r = x*x+2; + return r; + } + + if((x*x)-x>=0) { + r_real = x_real/10; + return r_real.as_double(); + } + + if((x*x)-x<0) { + r_real = x_real*x_real+2; + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_cav10_2_NumOpt(double x) + { + return expr_cav10_2_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/pov_ray/expr_pov_ray_NumOpt.cpp b/srcTest/pov_ray/expr_pov_ray_NumOpt.cpp new file mode 100644 index 0000000..56ce522 --- /dev/null +++ b/srcTest/pov_ray/expr_pov_ray_NumOpt.cpp @@ -0,0 +1,48 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_pov_ray_CPP(double x1, double x2, double x3, double x4, double x5) +{ + REAL x1_real(x1); + REAL x2_real(x2); + REAL x3_real(x3); + REAL x4_real(x4); + REAL x5_real(x5); + double r; + REAL r_real; + + if(((-1 <= x1) && (x1 <= 1) && (-1<=x5) && (x5<=1) && (-3.1415926535897932384626433832795 <= x2) && (x2 <= 3.1415926535897932384626433832795) && (-3.1415926535897932384626433832795 <= x3) && (x3 <= 3.1415926535897932384626433832795) && (-1 <= x4) && (x4 <= 1))&&(-4.9361672509868313e-05<=x1)&&(x1<=0.00012576726982661083)) { + r = x1*cos(x2)*cos(x3)+x4*cos(x2)+x5*cos(x2)*sin(x3); + return r; + } + + if(((-1 <= x1) && (x1 <= 1) && (-1<=x5) && (x5<=1) && (-3.1415926535897932384626433832795 <= x2) && (x2 <= 3.1415926535897932384626433832795) && (-3.1415926535897932384626433832795 <= x3) && (x3 <= 3.1415926535897932384626433832795) && (-1 <= x4) && (x4 <= 1))) { + r_real = x1_real*iRRAM::cos((REAL)x2_real)*iRRAM::cos((REAL)x3_real)+x4_real*iRRAM::cos((REAL)x2_real)+x5_real*iRRAM::cos((REAL)x2_real)*iRRAM::sin((REAL)x3_real); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_pov_ray_NumOpt(double x) + { + return expr_pov_ray_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/smartRoot_2/expr_smartRoot_2_NumOpt.cpp b/srcTest/smartRoot_2/expr_smartRoot_2_NumOpt.cpp new file mode 100644 index 0000000..ada0214 --- /dev/null +++ b/srcTest/smartRoot_2/expr_smartRoot_2_NumOpt.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_smartRoot_2_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if(((3.5*3.5)-(3.0*x))>10.0&&(-1.498077612385249e+307<=x)&&(x<=0.030049679510853158)) { + r = (x*2.0)/(-3.5-sqrt(((3.5*3.5)-((3.0*x)*4.0)))); + return r; + } + + if(((3.5*3.5)-(3.0*x))<=10.0&&(1.0208333333332282<=x)&&(x<=1.0208333333332282)) { + r = (x*2.0)/(-3.5-sqrt(((3.5*3.5)-((3.0*x)*4.0)))); + return r; + } + + if(((3.5*3.5)-(3.0*x))>10.0) { + r_real = (x_real*REAL(2.0))/(-REAL(3.5)-iRRAM::sqrt((REAL)((REAL(3.5)*REAL(3.5))-((REAL(3.0)*x_real)*REAL(4.0))))); + return r_real.as_double(); + } + + if(((3.5*3.5)-(3.0*x))<=10.0) { + r_real = (x_real*REAL(2.0))/(-REAL(3.5)-iRRAM::sqrt((REAL)((REAL(3.5)*REAL(3.5))-((REAL(3.0)*x_real)*REAL(4.0))))); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_smartRoot_2_NumOpt(double x) + { + return expr_smartRoot_2_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/squareRoot3Invalid_2/expr_squareRoot3Invalid_2_NumOpt.cpp b/srcTest/squareRoot3Invalid_2/expr_squareRoot3Invalid_2_NumOpt.cpp new file mode 100644 index 0000000..8048617 --- /dev/null +++ b/srcTest/squareRoot3Invalid_2/expr_squareRoot3Invalid_2_NumOpt.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_squareRoot3Invalid_2_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if(x<0.0001&&(-5.849734155840792e+303<=x)&&(x<=4.8372664685901273e-05)) { + r = 1.0+(0.5*x); + return r; + } + + if(x>=0.0001&&(487476.22196357907<=x)&&(x<=1.2943681476239454e+303)) { + r = sqrt((1.0+x)); + return r; + } + + if(x<0.0001) { + r_real = REAL(1.0)+(REAL(0.5)*x_real); + return r_real.as_double(); + } + + if(x>=0.0001) { + r_real = iRRAM::sqrt((REAL)(REAL(1.0)+x_real)); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_squareRoot3Invalid_2_NumOpt(double x) + { + return expr_squareRoot3Invalid_2_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/squareRoot3_2/expr_squareRoot3_2_NumOpt.cpp b/srcTest/squareRoot3_2/expr_squareRoot3_2_NumOpt.cpp new file mode 100644 index 0000000..904766b --- /dev/null +++ b/srcTest/squareRoot3_2/expr_squareRoot3_2_NumOpt.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_squareRoot3_2_CPP(double x) +{ + REAL x_real(x); + double r; + REAL r_real; + + if(x<1e-5&&(-4.884449476155393e+306<=x)&&(x<=1.6567059425414487e-14)) { + r = 1.0+(0.5*x); + return r; + } + + if(x>=1e-5&&(0.2162655827879985<=x)&&(x<=7.556698972072338e+306)) { + r = sqrt((1.0+x)); + return r; + } + + if(x<1e-5) { + r_real = REAL(1.0)+(REAL(0.5)*x_real); + return r_real.as_double(); + } + + if(x>=1e-5) { + r_real = iRRAM::sqrt((REAL)(REAL(1.0)+x_real)); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_squareRoot3_2_NumOpt(double x) + { + return expr_squareRoot3_2_CPP(x); + } +} \ No newline at end of file diff --git a/srcTest/triangleSorted_2/expr_triangleSorted_2_NumOpt.cpp b/srcTest/triangleSorted_2/expr_triangleSorted_2_NumOpt.cpp new file mode 100644 index 0000000..066246a --- /dev/null +++ b/srcTest/triangleSorted_2/expr_triangleSorted_2_NumOpt.cpp @@ -0,0 +1,101 @@ +#include +#include +#include +#include +#include + +#include "backend/points.h" +#include "backend/self_math.h" +#include "backend/gamma.h" +#include "iRRAM/lib.h" + +int iRRAM::MAXiterationnum = 30; +bool iRRAM::enableReiterate = true; +bool iRRAM::alwaysenableReiterate = true; + +using namespace std; +using namespace iRRAM; + +double expr_triangleSorted_2_CPP(double a, double b, double c) +{ + REAL a_real(a); + REAL b_real(b); + REAL c_real(c); + double r; + REAL r_real; + + if(a < b&&(-9.838516996763401e-208<=a)&&(a<=-4.1527009680941224e-210)) { + r = sqrt(((((c + (b + a)) * (a - (c - b))) * (a + (c - b))) * (c + (b - a)))) / 4.0; + return r; + } + + if(a < b&&(-1.8472342742723307e-249<=a)&&(a<=-1.8472342742723307e-249)) { + r = sqrt(((((c + (b + a)) * (a - (c - b))) * (a + (c - b))) * (c + (b - a)))) / 4.0; + return r; + } + + if(a < b&&(-7.106569030933685e-277<=a)&&(a<=-6.532353551725582e-277)) { + r = sqrt(((((c + (b + a)) * (a - (c - b))) * (a + (c - b))) * (c + (b - a)))) / 4.0; + return r; + } + + if(a < b&&(2.5683516051161374e-257<=a)&&(a<=3.720652011351933e-257)) { + r = sqrt(((((c + (b + a)) * (a - (c - b))) * (a + (c - b))) * (c + (b - a)))) / 4.0; + return r; + } + + if(a < b&&(4.963328843187051e-245<=a)&&(a<=5.001730032770586e-245)) { + r = sqrt(((((c + (b + a)) * (a - (c - b))) * (a + (c - b))) * (c + (b - a)))) / 4.0; + return r; + } + + if(a < b&&(2.5192554908951825e-163<=a)&&(a<=2.6317839716959753e-163)) { + r = sqrt(((((c + (b + a)) * (a - (c - b))) * (a + (c - b))) * (c + (b - a)))) / 4.0; + return r; + } + + if(a >= b&&(-2.3836811794075206e-244<=a)&&(a<=-1.59705048161082e-244)) { + r = sqrt(((((c + (a + b)) * (b - (c - a))) * (b + (c - a))) * (c + (a - b)))) / 4.0; + return r; + } + + if(a >= b&&(-8.676363299047421e-277<=a)&&(a<=-8.676363299047421e-277)) { + r = sqrt(((((c + (a + b)) * (b - (c - a))) * (b + (c - a))) * (c + (a - b)))) / 4.0; + return r; + } + + if(a >= b&&(1.2731075244774277e-257<=a)&&(a<=1.2731075244774277e-257)) { + r = sqrt(((((c + (a + b)) * (b - (c - a))) * (b + (c - a))) * (c + (a - b)))) / 4.0; + return r; + } + + if(a >= b&&(2.821538577212522e-247<=a)&&(a<=2.821538577212522e-247)) { + r = sqrt(((((c + (a + b)) * (b - (c - a))) * (b + (c - a))) * (c + (a - b)))) / 4.0; + return r; + } + + if(a >= b&&(7.71945767527287e-164<=a)&&(a<=7.71945767527287e-164)) { + r = sqrt(((((c + (a + b)) * (b - (c - a))) * (b + (c - a))) * (c + (a - b)))) / 4.0; + return r; + } + + if(a < b) { + r_real = iRRAM::sqrt((REAL)((((c_real + (b_real + a_real)) * (a_real - (c_real - b_real))) * (a_real + (c_real - b_real))) * (c_real + (b_real - a_real)))) / REAL(4.0); + return r_real.as_double(); + } + + if(a >= b) { + r_real = iRRAM::sqrt((REAL)((((c_real + (a_real + b_real)) * (b_real - (c_real - a_real))) * (b_real + (c_real - a_real))) * (c_real + (a_real - b_real)))) / REAL(4.0); + return r_real.as_double(); + } + + return r; +} + +extern "C" +{ + double expr_triangleSorted_2_NumOpt(double x) + { + return expr_triangleSorted_2_CPP(x); + } +} \ No newline at end of file -- Gitee From d36a62b075b1fe019b8b6584c82e031c6437f7db Mon Sep 17 00:00:00 2001 From: hjwLab Date: Fri, 14 Apr 2023 05:50:17 +0800 Subject: [PATCH 25/32] update pov_ray error test --- detectErrorAll10.sh | 5 +++++ srcTest/pov_ray/expr_pov_ray_final.c | 12 ++++++++++++ srcTest/pov_ray/expr_pov_ray_herbie.c | 6 ++++++ srcTest/pov_ray/expr_pov_ray_herbieArfa.c | 12 ++++++++++++ srcTest/pov_ray/expr_pov_ray_herbiePlus.c | 4 ++++ 5 files changed, 39 insertions(+) create mode 100644 srcTest/pov_ray/expr_pov_ray_final.c create mode 100644 srcTest/pov_ray/expr_pov_ray_herbie.c create mode 100644 srcTest/pov_ray/expr_pov_ray_herbieArfa.c create mode 100644 srcTest/pov_ray/expr_pov_ray_herbiePlus.c diff --git a/detectErrorAll10.sh b/detectErrorAll10.sh index 02f9cd2..148c95f 100644 --- a/detectErrorAll10.sh +++ b/detectErrorAll10.sh @@ -30,6 +30,11 @@ fi ./detectErrorFourFPEDParallel.sh polyIDX2 3 9 1.5 5 -2 10 -1 3.5 16 16 16 16 0 0 0 0 3 1.5 -2 -1 0.375 0.21875 0.75 0.28125 expr_polyIDX2 3_9_1.5_5_-2_10_-1_3.5_16_16_16_16 herbieArfa ./detectErrorFourFPEDParallel.sh polyIDX2 3 9 1.5 5 -2 10 -1 3.5 16 16 16 16 0 0 0 0 3 1.5 -2 -1 0.375 0.21875 0.75 0.28125 expr_polyIDX2 3_9_1.5_5_-2_10_-1_3.5_16_16_16_16 daisy ./detectErrorFourFPEDParallel.sh polyIDX2 3 9 1.5 5 -2 10 -1 3.5 16 16 16 16 0 0 0 0 3 1.5 -2 -1 0.375 0.21875 0.75 0.28125 expr_polyIDX2 3_9_1.5_5_-2_10_-1_3.5_16_16_16_16 daisyArfa +./detectErrorFiveFPEDParallel.sh pov_ray -1 1 -3.141592653589793 3.141592653589793 -3.141592653589793 3.141592653589793 -1 1 -1 1 8 8 8 8 8 0 0 0 0 0 -1 -3.141592653589793 -3.141592653589793 -1 -1 0.25 0.7853981633974483 0.7853981633974483 0.25 0.25 expr_pov_ray -1_1_-3.141592653589793_3.141592653589793_-3.141592653589793_3.141592653589793_-1_1_-1_1_8_8_8_8_8 origin +./detectErrorFiveFPEDParallel.sh pov_ray -1 1 -3.141592653589793 3.141592653589793 -3.141592653589793 3.141592653589793 -1 1 -1 1 8 8 8 8 8 0 0 0 0 0 -1 -3.141592653589793 -3.141592653589793 -1 -1 0.25 0.7853981633974483 0.7853981633974483 0.25 0.25 expr_pov_ray -1_1_-3.141592653589793_3.141592653589793_-3.141592653589793_3.141592653589793_-1_1_-1_1_8_8_8_8_8 herbie +./detectErrorFiveFPEDParallel.sh pov_ray -1 1 -3.141592653589793 3.141592653589793 -3.141592653589793 3.141592653589793 -1 1 -1 1 8 8 8 8 8 0 0 0 0 0 -1 -3.141592653589793 -3.141592653589793 -1 -1 0.25 0.7853981633974483 0.7853981633974483 0.25 0.25 expr_pov_ray -1_1_-3.141592653589793_3.141592653589793_-3.141592653589793_3.141592653589793_-1_1_-1_1_8_8_8_8_8 herbiePlus +./detectErrorFiveFPEDParallel.sh pov_ray -1 1 -3.141592653589793 3.141592653589793 -3.141592653589793 3.141592653589793 -1 1 -1 1 8 8 8 8 8 0 0 0 0 0 -1 -3.141592653589793 -3.141592653589793 -1 -1 0.25 0.7853981633974483 0.7853981633974483 0.25 0.25 expr_pov_ray -1_1_-3.141592653589793_3.141592653589793_-3.141592653589793_3.141592653589793_-1_1_-1_1_8_8_8_8_8 herbieArfa +./detectErrorFiveFPEDParallel.sh pov_ray -1 1 -3.141592653589793 3.141592653589793 -3.141592653589793 3.141592653589793 -1 1 -1 1 8 8 8 8 8 0 0 0 0 0 -1 -3.141592653589793 -3.141592653589793 -1 -1 0.25 0.7853981633974483 0.7853981633974483 0.25 0.25 expr_pov_ray -1_1_-3.141592653589793_3.141592653589793_-3.141592653589793_3.141592653589793_-1_1_-1_1_8_8_8_8_8 final ./detectErrorOneFPEDParallel.sh squareRoot3_2 0 10 500000 0 0 2e-05 expr_squareRoot3_2 0_10_500000 origin ./detectErrorOneFPEDParallel.sh squareRoot3_2 0 10 500000 0 0 2e-05 expr_squareRoot3_2 0_10_500000 herbie ./detectErrorOneFPEDParallel.sh squareRoot3_2 0 10 500000 0 0 2e-05 expr_squareRoot3_2 0_10_500000 herbiePlus diff --git a/srcTest/pov_ray/expr_pov_ray_final.c b/srcTest/pov_ray/expr_pov_ray_final.c new file mode 100644 index 0000000..49aeaaf --- /dev/null +++ b/srcTest/pov_ray/expr_pov_ray_final.c @@ -0,0 +1,12 @@ +#include "mine.h" +double expr_pov_ray_final(double x1, double x2, double x3, double x4, double x5) { + double result; + if((-1 <= x1 && x1 <= 0) && (-3.141592653589793 <= x2 && x2 <= -1.8849555921538759) && (-3.141592653589793 <= x3 && x3 <= 1.2566370614359172) && (-1 <= x4 && x4 <= -0.6) && (-0.8 <= x5 && x5 <= 0.6000000000000001)) { + result = ((((cos(x2) * cos(x3)) * x1) + (x4 * cos(x2))) + ((cos(x2) * sin(x3)) * x5)); + } else if((-1 <= x1 && x1 <= 0) && (-3.141592653589793 <= x2 && x2 <= -1.8849555921538759) && (-3.141592653589793 <= x3 && x3 <= 1.2566370614359172) && (0.40000000000000013 <= x4 && x4 <= 0.8) && (-0.8 <= x5 && x5 <= 0.6)) { + result = (cos(x2) * fma(x1, cos(x3), fma(x5, sin(x3), x4))); + } else { + result = cos(x2) * fma(x1, cos(x3), fma(x5, sin(x3), x4)); + } + return result; +} diff --git a/srcTest/pov_ray/expr_pov_ray_herbie.c b/srcTest/pov_ray/expr_pov_ray_herbie.c new file mode 100644 index 0000000..c4ba4ea --- /dev/null +++ b/srcTest/pov_ray/expr_pov_ray_herbie.c @@ -0,0 +1,6 @@ +#include +double expr_pov_ray_herbie(double x1, double x2, double x3, double x4, double x5) +{ + double result = cos(x2) * fma(x1, cos(x3), fma(x5, sin(x3), x4)); + return result; +} diff --git a/srcTest/pov_ray/expr_pov_ray_herbieArfa.c b/srcTest/pov_ray/expr_pov_ray_herbieArfa.c new file mode 100644 index 0000000..9f1fe67 --- /dev/null +++ b/srcTest/pov_ray/expr_pov_ray_herbieArfa.c @@ -0,0 +1,12 @@ +#include +double expr_pov_ray_herbieArfa(double x1, double x2, double x3, double x4, double x5) { + double result; + if((-1 <= x1 && x1 <= 0) && (-3.141592653589793 <= x2 && x2 <= -1.8849555921538759) && (-3.141592653589793 <= x3 && x3 <= 1.2566370614359172) && (-1 <= x4 && x4 <= -0.6) && (-0.8 <= x5 && x5 <= 0.6000000000000001)) { + return (((x1 * cos(x2)) * cos(x3)) + (cos(x2) * x4)) + ((cos(x2) * x5) * sin(x3)); + } else if((-1 <= x1 && x1 <= 0) && (-3.141592653589793 <= x2 && x2 <= -1.8849555921538759) && (-3.141592653589793 <= x3 && x3 <= 1.2566370614359172) && (0.40000000000000013 <= x4 && x4 <= 0.8) && (-0.8 <= x5 && x5 <= 0.6)) { + return (((x1 * cos(x2)) * cos(x3)) + (cos(x2) * x4)) + ((cos(x2) * x5) * sin(x3)); + } else { + result = cos(x2) * fma(x1, cos(x3), fma(x5, sin(x3), x4)); + } + return result; +} \ No newline at end of file diff --git a/srcTest/pov_ray/expr_pov_ray_herbiePlus.c b/srcTest/pov_ray/expr_pov_ray_herbiePlus.c new file mode 100644 index 0000000..947f46d --- /dev/null +++ b/srcTest/pov_ray/expr_pov_ray_herbiePlus.c @@ -0,0 +1,4 @@ +#include +double expr_pov_ray_herbiePlus(double x1, double x2, double x3, double x4, double x5) { + return (((x1 * cos(x2)) * cos(x3)) + (cos(x2) * x4)) + (x5 * (cos(x2) * sin(x3))); +} \ No newline at end of file -- Gitee From abea9883184bae9c81aac97d88f15761d06c8682 Mon Sep 17 00:00:00 2001 From: hjwLab Date: Fri, 14 Apr 2023 05:50:31 +0800 Subject: [PATCH 26/32] fix a bug --- detectErrorFiveFPEDParallel.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/detectErrorFiveFPEDParallel.sh b/detectErrorFiveFPEDParallel.sh index b9feb26..3a258f8 100755 --- a/detectErrorFiveFPEDParallel.sh +++ b/detectErrorFiveFPEDParallel.sh @@ -41,7 +41,7 @@ if [ $# -eq 35 ]; then middle=${33} # intervalsInfo_sizes. Eg: 3.8_7.8_-4.5_-0.3_0.4_0.9_256_256_256 suffix=${34} # different version. Eg: herbie daisy origin temp_0_3 final errfile=${35} # 1 or 0: TRUE or False -elif [ $# -eq 32 ]; then +elif [ $# -eq 34 ]; then x0Size=${12} x1Size=${13} x2Size=${14} -- Gitee From cbe5ca2295e135489aa712739496a04dbf8b4e9c Mon Sep 17 00:00:00 2001 From: hjwLab Date: Fri, 14 Apr 2023 06:58:40 +0800 Subject: [PATCH 27/32] implement 5 parameters' NumOpt error test --- detectErrorFiveFPEDParallelNumOpt.sh | 132 ++++++++ srcTest/pov_ray/expr_pov_ray_NumOpt.cpp | 4 +- srcTest/test5paramFPEDParallelNumOpt.cpp | 388 +++++++++++++++++++++++ 3 files changed, 522 insertions(+), 2 deletions(-) create mode 100755 detectErrorFiveFPEDParallelNumOpt.sh create mode 100644 srcTest/test5paramFPEDParallelNumOpt.cpp diff --git a/detectErrorFiveFPEDParallelNumOpt.sh b/detectErrorFiveFPEDParallelNumOpt.sh new file mode 100755 index 0000000..8214b0f --- /dev/null +++ b/detectErrorFiveFPEDParallelNumOpt.sh @@ -0,0 +1,132 @@ +# Usage: ./detectErrorFourParallel.sh ${uniqueLabel} ${x0Start} ${x0End} ${x1Start} ${x1End} ${x2Start} ${x2End} ${x0Size} ${x1Size} ${x2Size} ${prefix} ${middle} ${suffix} ${errfile} +# set -x + +path=`pwd` +cd ${path} +CC=gcc +CPP=g++ + +uniqueLabel=${1} # unique number +x0Start=${2} +x0End=${3} +x1Start=${4} +x1End=${5} +x2Start=${6} +x2End=${7} +x3Start=${8} +x3End=${9} +x4Start=${10} +x4End=${11} +if [ $# -eq 35 ]; then + x0Size=${12} + x1Size=${13} + x2Size=${14} + x3Size=${15} + x4Size=${16} + x0startNowIdx=${17} # the index of the start point of the current interval. + x1startNowIdx=${18} + x2startNowIdx=${19} + x3startNowIdx=${20} + x4startNowIdx=${21} + x0startOriginInterval=${22} # the value of the start point of the origin interval. + x1startOriginInterval=${23} + x2startOriginInterval=${24} + x3startOriginInterval=${25} + x4startOriginInterval=${26} + stepX0=${27} # the step for sampling points. + stepX1=${28} + stepX2=${29} + stepX3=${30} + stepX4=${31} + prefix=${32} # expr_${uniqueLabel}. Eg: expr_20221030155958 + middle=${33} # intervalsInfo_sizes. Eg: 3.8_7.8_-4.5_-0.3_0.4_0.9_256_256_256 + suffix=${34} # different version. Eg: herbie daisy origin temp_0_3 final + errfile=${35} # 1 or 0: TRUE or False +elif [ $# -eq 34 ]; then + x0Size=${12} + x1Size=${13} + x2Size=${14} + x3Size=${15} + x4Size=${16} + x0startNowIdx=${17} # the index of the start point of the current interval. + x1startNowIdx=${18} + x2startNowIdx=${19} + x3startNowIdx=${20} + x4startNowIdx=${21} + x0startOriginInterval=${22} # the value of the start point of the origin interval. + x1startOriginInterval=${23} + x2startOriginInterval=${24} + x3startOriginInterval=${25} + x4startOriginInterval=${26} + stepX0=${27} # the step for sampling points. + stepX1=${28} + stepX2=${29} + stepX3=${30} + stepX4=${31} + prefix=${32} # expr_${uniqueLabel}. Eg: expr_20221030155958 + middle=${33} # intervalsInfo_sizes. Eg: 3.8_7.8_-4.5_-0.3_0.4_0.9_256_256_256 + suffix=${34} # different version. Eg: herbie daisy origin temp_0_3 final + errfile=0 # 1 or 0: TRUE or False +elif [ $# -eq 29 ]; then + x0Size=32 + x1Size=32 + x2Size=32 + x3Size=32 + x0startNowIdx=${12} # the index of the start point of the current interval. + x1startNowIdx=${13} + x2startNowIdx=${14} + x3startNowIdx=${15} + x4startNowIdx=${16} + x0startOriginInterval=${17} # the value of the start point of the origin interval. + x1startOriginInterval=${18} + x2startOriginInterval=${19} + x3startOriginInterval=${20} + x4startOriginInterval=${21} + stepX0=${22} # the step for sampling points. + stepX1=${23} + stepX2=${24} + stepX3=${25} + stepX4=${26} + prefix=${27} # expr_${uniqueLabel}. Eg: expr_20221030155958 + middle=${28} # intervalsInfo_sizes. Eg: 3.8_7.8_-4.5_-0.3_0.4_0.9_256_256_256 + suffix=${29} # different version. Eg: herbie daisy origin temp_0_3 final + errfile=0 # 1 or 0: TRUE or False +else + echo "detectErrorFiveParallel: Invalid input parameters" + exit +fi +testFileName=test5paramFPEDParallelNumOpt +numProcs=32 + +echo "Detecting error: ${uniqueLabel} ${x0Start} ${x0End} ${x1Start} ${x1End} ${x2Start} ${x2End} ${x3End} ${x3Start} ${x4End} ${x4Start} ${x0Size} ${x1Size} ${x2Size} ${x3Size} ${x4Size} ${prefix} ${middle} ${suffix} ${errfile}" +directory="./srcTest"/${uniqueLabel} +sourceFile=${prefix}_${suffix} +fileNameKernel=${prefix}__${middle}_${suffix} + +# compile the NumOpt version +${CPP} -c -IincludeNumOpt -o objs/points.o srcNumOpt/points.cpp +${CPP} -c -IincludeNumOpt -o objs/${sourceFile}.o ${directory}/${sourceFile}.cpp +${CC} -c -o objs/${prefix}_mpfr.o ${directory}/${prefix}_mpfr.c +${CC} -c -IincludeTEST -o objs/computeULP.o ./srcTest/computeULP.c +mpic++ -c -IincludeNumOpt -IincludeTEST -DEXPRESSION=${prefix}_ -DSUFFIX=${suffix} -DERRFILE=${errfile} -o objs/${testFileName}.o ./srcTest/${testFileName}.cpp +mpic++ objs/${testFileName}.o objs/${sourceFile}.o objs/${prefix}_mpfr.o objs/computeULP.o objs/points.o -Xlinker -rpath -Xlinker libs -Llibs -liRRAM -lgmp -lpthread -Llibs -lTGen -lmpfr -lm -lqd -o ${testFileName}.exe + + +# run the NumOpt version +# echo "mpirun -n ${numProcs} ./${testFileName}.exe ${x0Start} ${x0End} ${x1Start} ${x1End} ${x2Start} ${x2End} ${x0Size} ${x1Size} ${x2Size} ${fileNameKernel}" +mpirun -n ${numProcs} ./${testFileName}.exe ${x0Start} ${x0End} ${x1Start} ${x1End} ${x2Start} ${x2End} ${x3End} ${x3Start} ${x4End} ${x4Start} ${x0Size} ${x1Size} ${x2Size} ${x3Size} ${x4Size} ${x0startNowIdx} ${x1startNowIdx} ${x2startNowIdx} ${x3startNowIdx} ${x4startNowIdx} ${x0startOriginInterval} ${x1startOriginInterval} ${x2startOriginInterval} ${x3startOriginInterval} ${x4startOriginInterval} ${stepX0} ${stepX1} ${stepX2} ${stepX3} ${stepX4} ${fileNameKernel} ${uniqueLabel} +rm ${testFileName}.exe + +# combine files +if [ ${errfile} -eq 1 ]; then + cd ./outputs/${uniqueLabel} + findWord="${fileNameKernel}_sample_*.txt" + # echo "For suffix = ${suffix}, Find and combine by shell command cat: ${findWord}" + find . -name "${findWord}" | sort -h | xargs cat > sample_${uniqueLabel}_${suffix}.txt + # echo "sample file: `pwd`/sample_${uniqueLabel}_${suffix}.txt" + rm ${findWord} + cd - > /dev/null +fi + +echo "end detecting ${uniqueLabel}" +echo diff --git a/srcTest/pov_ray/expr_pov_ray_NumOpt.cpp b/srcTest/pov_ray/expr_pov_ray_NumOpt.cpp index 56ce522..92e6482 100644 --- a/srcTest/pov_ray/expr_pov_ray_NumOpt.cpp +++ b/srcTest/pov_ray/expr_pov_ray_NumOpt.cpp @@ -41,8 +41,8 @@ double expr_pov_ray_CPP(double x1, double x2, double x3, double x4, double x5) extern "C" { - double expr_pov_ray_NumOpt(double x) + double expr_pov_ray_NumOpt(double x1, double x2, double x3, double x4, double x5) { - return expr_pov_ray_CPP(x); + return expr_pov_ray_CPP(x1, x2, x3, x4, x5); } } \ No newline at end of file diff --git a/srcTest/test5paramFPEDParallelNumOpt.cpp b/srcTest/test5paramFPEDParallelNumOpt.cpp new file mode 100644 index 0000000..12cfa26 --- /dev/null +++ b/srcTest/test5paramFPEDParallelNumOpt.cpp @@ -0,0 +1,388 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "iRRAM/lib.h" + +using namespace std; +using namespace iRRAM; +// int iRRAM::MAXiterationnum = 30; +// bool iRRAM::enableReiterate = true; +// bool iRRAM::alwaysenableReiterate = true; + +extern "C" +{ +#include "common.h" +#include "mpi.h" + +struct errorInfo { + double sumError; + double maxError; + double maxInputX0; + double maxInputX1; + double maxInputX2; + double maxInputX3; + double maxInputX4; +}; + +#ifndef SUFFIX +#define SUFFIX orgin +#endif +#ifndef EXPRESSION +#define EXPRESSION sum +#endif + +#define EXPRESSIONMINE ADDSUFFIX(EXPRESSION, SUFFIX) +#define SUFFIX1 mpfr +#define EXPRESSIONMPFR ADDSUFFIX(EXPRESSION, SUFFIX1) + +#define TESTNUMX0 24 +#define TESTNUMX1 24 +#define TESTNUMX2 24 +#define TESTNUMX3 24 +#define TESTNUMX4 24 +// #define FP +// #define DEBUG +#ifndef ERRFILE +#define ERRFILE 0 +#endif +double EXPRESSIONMPFR(double, double, double, double, double, mpfr_t); +double EXPRESSIONMINE(double, double, double, double, double); + +int computeOrcle5param(double x0, double x1, double x2, double x3, double x4, mpfr_t orcle) { + return EXPRESSIONMPFR(x0, x1, x2, x3, x4, orcle); +} + +int computeResult5param(double x0, double x1, double x2, double x3, double x4, mpfr_t mpfrResult) { + int status = 1; + + double result = EXPRESSIONMINE(x0, x1, x2, x3, x4); + mpfr_set_d(mpfrResult, result, MPFR_RNDN); + + return status; +} +} + +struct errorInfo test5paramFPEDParallel(unsigned long int testNumX0, unsigned long int testNumX1, unsigned long int testNumX2, unsigned long int testNumX3, unsigned long int testNumX4, const char* uniqueLabel, const char* fileNameKernel, int myid, int i0StartLocal, int i0EndLocal, int i1StartLocal, int i1EndLocal, int i2StartLocal, int i2EndLocal, int i3StartLocal, int i3EndLocal, int i4StartLocal, int i4EndLocal, double x0startOriginInterval, double x1startOriginInterval, double x2startOriginInterval, double x3startOriginInterval, double x4startOriginInterval, double stepX0, double stepX1, double stepX2, double stepX3, double stepX4) { + DL maxInputX0, maxInputX1, maxInputX2, maxInputX3, maxInputX4; + int i0, i1, i2, i3, i4; + // int flag; + double x0, x1, x2, x3, x4, reUlp, sumError, aveReUlp, maxReUlp, lenX0, lenX1, lenX2, lenX3, lenX4; + + // mpfr + mpfr_t mpfrOrcle, mpfrResult; + mpfr_inits2(PRECISION, mpfrOrcle, mpfrResult, (mpfr_ptr) 0); + + // write error data to file + #if ERRFILE + char *directory = "outputs"; + char *suffix = "sample"; + char *fileNameSample; + FILE *f; + fileNameSample = (char *) calloc(strlen(directory) + strlen(uniqueLabel) + strlen(fileNameKernel) + strlen(suffix) + 128, sizeof(char)); + sprintf(fileNameSample, "%s/%s/%s_%s_%02d.txt", directory, uniqueLabel, fileNameKernel, suffix, myid); + // printf("%s\n", fileNameSample); + if ((f = fopen(fileNameSample, "w")) == NULL) { + printf("Error opening file %s.\n", fileNameSample); + exit(0); + } + #endif + + // Real number average + maxReUlp = 0; + // flag = 1; + // size_t testCount = 0; + sumError = 0; + for(i4 = i4StartLocal; i4 <= i4EndLocal; i4++) { + x4 = x4startOriginInterval + stepX4 * i4; + for(i3 = i3StartLocal; i3 <= i3EndLocal; i3++) { + x3 = x3startOriginInterval + stepX3 * i3; + for(i2 = i2StartLocal; i2 <= i2EndLocal; i2++) { + x2 = x2startOriginInterval + stepX2 * i2; + for(i1 = i1StartLocal; i1 <= i1EndLocal; i1++) { + x1 = x1startOriginInterval + stepX1 * i1; + for(i0 = i0StartLocal; i0 <= i0EndLocal; i0++) { + x0 = x0startOriginInterval + stepX0 * i0; + computeResult5param(x0, x1, x2, x3, x4, mpfrResult); + computeOrcle5param(x0, x1, x2, x3, x4, mpfrOrcle); + #ifdef SINGLE + reUlp = computeUlpDiffF(mpfrOrcle, mpfrResult); + #else // compute Double ULP as default + reUlp = computeUlpDiff(mpfrOrcle, mpfrResult); + #endif + // if(reUlp <= 0.5) { + // reUlp = 0; + // } + // if(isfinite(reUlp) == 0) { + // printf("happen to NaN or inf\n"); + // exit(1); + // } + // fprintf(f, "%le\t%le\t%le\t%e\n", x0, x1, x2, reUlp); + if (isnormal(reUlp) != 0) + { + #if ERRFILE + fprintf(f, "%le\t%le\n", x0, reUlp); + #endif + sumError += reUlp; + if (reUlp > maxReUlp) { + // flag = 0; + maxInputX4.d = x4; + maxInputX3.d = x3; + maxInputX2.d = x2; + maxInputX1.d = x1; + maxInputX0.d = x0; + maxReUlp = reUlp; + } + } + } + } + } + } + } + // aveReUlp = sumError / testCount; + // if(flag == 1) { + // printf("all error are 0!!\n"); + // } + // printf("average ulp\tmax ulp\n"); + // printf("%lg\t%lg\n", aveReUlp, maxReUlp); + // printf("\naveReUlp = %lg\nmaxInputX0 = 0x%016lx %lg, maxInputX1 = 0x%016lx %lg, maxInputX2 = 0x%016lx %lg, maxReUlp = %lg\n", aveReUlp, maxInputX0.l, maxInputX0.d, maxInputX1.l, maxInputX1.d, maxInputX2.l, maxInputX2.d, maxReUlp); + #if ERRFILE + // fprintf(f, "\n"); + + // clear + fclose(f); + free(fileNameSample); + #endif + mpfr_clears(mpfrOrcle, mpfrResult, (mpfr_ptr) 0); + struct errorInfo err; + err.sumError = sumError; + err.maxError = maxReUlp; + err.maxInputX0 = maxInputX0.d; + err.maxInputX1 = maxInputX1.d; + err.maxInputX2 = maxInputX2.d; + err.maxInputX3 = maxInputX3.d; + err.maxInputX4 = maxInputX4.d; + return err; +} + +int main_inner(const unsigned long int &testNumX0, const unsigned long int &testNumX1, const unsigned long int &testNumX2, const unsigned long int &testNumX3, const unsigned long int &testNumX4, const string &uniqueLabelStr, const string &fileNameKernelStr, const int &myid, const int &numProcs, const int &i0StartLocal, const int &i0EndLocal, const int &i1StartLocal, const int &i1EndLocal, const int &i2StartLocal, const int &i2EndLocal, const int &i3StartLocal, const int &i3EndLocal, const int &i4StartLocal, const int &i4EndLocal, const double &x0startOriginInterval, const double &x1startOriginInterval, const double &x2startOriginInterval, const double &x3startOriginInterval, const double &x4startOriginInterval, const double &stepX0, const double &stepX1, const double &stepX2, const double &stepX3, const double &stepX4) +{ + std::fesetround(FE_TONEAREST); + std::cout << std::scientific << std::setprecision(6); + iRRAM::cout << iRRAM::setRwidth(30); + + MPI_Datatype MPI_errorInfo; + MPI_Type_contiguous(5, MPI_DOUBLE, &MPI_errorInfo); + MPI_Type_commit(&MPI_errorInfo); + + char *fileNameKernel; + fileNameKernel = (char *)calloc(256, sizeof(char)); + sprintf(fileNameKernel, "%s", fileNameKernelStr.c_str()); + char *uniqueLabel; + uniqueLabel = (char *)calloc(256, sizeof(char)); + sprintf(uniqueLabel, "%s", uniqueLabelStr.c_str()); + + // call the error test function + struct errorInfo err = test5paramFPEDParallel(testNumX0, testNumX1, testNumX2, testNumX3, testNumX4, uniqueLabel, fileNameKernel, myid, i0StartLocal, i0EndLocal, i1StartLocal, i1EndLocal, i2StartLocal, i2EndLocal, i3StartLocal, i3EndLocal, i4StartLocal, i4EndLocal, x0startOriginInterval, x1startOriginInterval, x2startOriginInterval, x3startOriginInterval, x4startOriginInterval, stepX0, stepX1, stepX2, stepX3, stepX4); + + // gather errors and find the max + struct errorInfo *errs; + errs = (struct errorInfo *)calloc(numProcs, sizeof(struct errorInfo)); + MPI_Gather(&err, 1, MPI_errorInfo, errs, 1, MPI_errorInfo, 0, MPI_COMM_WORLD); + if(myid == 0) + { + double maxError = -1; + double aveError = 0; + double errTmp = -1; + int maxErrorIdx = -1; + for(int i = 0; i < numProcs; i++) + { + errTmp = errs[i].maxError; + if(errTmp > maxError) + { + maxError = errTmp; + maxErrorIdx = i; + } + aveError += errs[i].sumError; + } + aveError = aveError / (testNumX0 * testNumX1 * testNumX2 * testNumX3 * testNumX4); + DL maxInputX0, maxInputX1, maxInputX2, maxInputX3, maxInputX4; + maxInputX0.d = errs[maxErrorIdx].maxInputX0; + maxInputX1.d = errs[maxErrorIdx].maxInputX1; + maxInputX2.d = errs[maxErrorIdx].maxInputX2; + maxInputX3.d = errs[maxErrorIdx].maxInputX3; + maxInputX4.d = errs[maxErrorIdx].maxInputX4; + + std::string directory{"./outputs"}; + std::string suffixErr("error.txt"); + FILE *fErr; + char *fileNameErr; + fileNameErr = (char *) calloc(directory.length() + strlen(uniqueLabel) + strlen(fileNameKernel) + suffixErr.length() + 128, sizeof(char)); + sprintf(fileNameErr, "%s/%s/%s_%s", directory.c_str(), uniqueLabel, fileNameKernel, suffixErr.c_str()); + if ((fErr = fopen(fileNameErr, "w")) == NULL) + { + printf("Error opening file %s.\n", fileNameErr); + exit(0); + } + printf("average ulp\tmax ulp\n"); + printf("%.16le\t%.16le\n", aveError, maxError); + // printf("\naveReUlp = %lg\nmaxInputX0 = 0x%016lx %lg, maxInputX1 = 0x%016lx %lg, maxInputX2 = 0x%016lx %lg, maxReUlp = %lg\n", aveError, maxInputX0.l, maxInputX0.d, maxInputX1.l, maxInputX1.d, maxInputX2.l, maxInputX2.d, maxError); + fprintf(fErr, "average ulp\tmax ulp\n"); + fprintf(fErr, "%.16le\t%.16le\n", aveError, maxError); + fprintf(fErr, "\naveReUlp = %lg\nmaxInputX0 = 0x%016lx %lg, maxInputX1 = 0x%016lx %lg, maxInputX2 = 0x%016lx %lg, maxInputX3 = 0x%016lx %lg, maxInputX4 = 0x%016lx %lg, maxReUlp = %lg\n", aveError, maxInputX0.l, maxInputX0.d, maxInputX1.l, maxInputX1.d, maxInputX2.l, maxInputX2.d, maxInputX3.l, maxInputX3.d, maxInputX4.l, maxInputX4.d, maxError); + + free(fileNameErr); + free(uniqueLabel); + fclose(fErr); + } + + // clear + free(fileNameKernel); + free(errs); + MPI_Type_free(&MPI_errorInfo); +} + + +int main(int argc, char **argv) { + // parallel + int myid, numProcs; + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &myid); + MPI_Comm_size(MPI_COMM_WORLD, &numProcs); + + // parameters init + DL x0Start, x0End, x1Start, x1End, x2Start, x2End, x3Start, x3End, x4Start, x4End; + unsigned long int testNumX0, testNumX1, testNumX2, testNumX3, testNumX4; + x0Start.d = 1; + x0End.d = 2; + x1Start.d = 1; + x1End.d = 2; + x2Start.d = 1; + x2End.d = 2; + x3Start.d = 1; + x3End.d = 2; + x4Start.d = 1; + x4End.d = 2; + int x0startNowIdx, x1startNowIdx, x2startNowIdx, x3startNowIdx, x4startNowIdx; + double x0startOriginInterval, x1startOriginInterval, x2startOriginInterval, x3startOriginInterval, x4startOriginInterval; + double stepX0, stepX1, stepX2, stepX3, stepX4; + + testNumX0 = TESTNUMX0; + testNumX1 = TESTNUMX1; + testNumX2 = TESTNUMX2; + testNumX3 = TESTNUMX3; + testNumX4 = TESTNUMX4; + + char *fileNameKernel; + fileNameKernel = (char *)calloc(256, sizeof(char)); + char *uniqueLabel; + uniqueLabel = (char *)calloc(256, sizeof(char)); + if(argc == 33) { + x0Start.d = strtod(argv[1], NULL); + x0End.d = strtod(argv[2], NULL); + x1Start.d = strtod(argv[3], NULL); + x1End.d = strtod(argv[4], NULL); + x2Start.d = strtod(argv[5], NULL); + x2End.d = strtod(argv[6], NULL); + x3Start.d = strtod(argv[7], NULL); + x3End.d = strtod(argv[8], NULL); + x4Start.d = strtod(argv[9], NULL); + x4End.d = strtod(argv[10], NULL); + testNumX0 = strtod(argv[11], NULL); + testNumX1 = strtod(argv[12], NULL); + testNumX2 = strtod(argv[13], NULL); + testNumX3 = strtod(argv[14], NULL); + testNumX4 = strtod(argv[15], NULL); + x0startNowIdx = atoi(argv[16]); + x1startNowIdx = atoi(argv[17]); + x2startNowIdx = atoi(argv[18]); + x3startNowIdx = atoi(argv[19]); + x4startNowIdx = atoi(argv[20]); + x0startOriginInterval = strtod(argv[21], NULL); + x1startOriginInterval = strtod(argv[22], NULL); + x2startOriginInterval = strtod(argv[23], NULL); + x3startOriginInterval = strtod(argv[24], NULL); + x4startOriginInterval = strtod(argv[25], NULL); + stepX0 = strtod(argv[26], NULL); + stepX1 = strtod(argv[27], NULL); + stepX2 = strtod(argv[28], NULL); + stepX3 = strtod(argv[29], NULL); + stepX4 = strtod(argv[30], NULL); + strcpy(fileNameKernel, argv[31]); + strcpy(uniqueLabel, argv[32]); + // } else if(argc == 18) { + // x0Start.d = strtod(argv[1], NULL); + // x0End.d = strtod(argv[2], NULL); + // x1Start.d = strtod(argv[3], NULL); + // x1End.d = strtod(argv[4], NULL); + // x2Start.d = strtod(argv[5], NULL); + // x2End.d = strtod(argv[6], NULL); + // x0startNowIdx = atoi(argv[7]); + // x1startNowIdx = atoi(argv[8]); + // x2startNowIdx = atoi(argv[9]); + // x0startOriginInterval = strtod(argv[10], NULL); + // x1startOriginInterval = strtod(argv[11], NULL); + // x2startOriginInterval = strtod(argv[12], NULL); + // stepX0 = strtod(argv[13], NULL); + // stepX1 = strtod(argv[14], NULL); + // stepX2 = strtod(argv[15], NULL); + // strcpy(fileNameKernel, argv[16]); + // strcpy(uniqueLabel, argv[17]); + // } else if(argc == 15) { + // testNumX0 = strtod(argv[1], NULL); + // testNumX1 = strtod(argv[2], NULL); + // testNumX2 = strtod(argv[3], NULL); + // x0startNowIdx = atoi(argv[4]); + // x1startNowIdx = atoi(argv[5]); + // x2startNowIdx = atoi(argv[6]); + // x0startOriginInterval = strtod(argv[7], NULL); + // x1startOriginInterval = strtod(argv[8], NULL); + // x2startOriginInterval = strtod(argv[9], NULL); + // stepX0 = strtod(argv[10], NULL); + // stepX1 = strtod(argv[11], NULL); + // stepX2 = strtod(argv[12], NULL); + // strcpy(fileNameKernel, argv[13]); + // strcpy(uniqueLabel, argv[14]); + } else { + printf("Usage: ./test3paramFPEDParallel.exe [x0Start x0End x1Start x1End x2Start x2End testNumX0 testNumX1 testNumX2 fileNameKernel]\n"); + printf("Usage: if no correct input:\n"); + printf("Usage: \tthe fixed inputs [%g %g %g %g %g %g %g %g %lu %lu %lu %lu] will be used\n", x0Start.d, x0End.d, x1Start.d, x1End.d, x2Start.d, x2End.d, x3Start.d, x3End.d, testNumX0, testNumX1, testNumX2, testNumX3); + } + + // if(myid == 0) { + // printf("\n---------------------------------------------------start test3paramFPEDParallel\n"); + // printf("Parameters: x0Start: %lg, x0End: %lg, x1Start: %lg, x1End: %lg, x2Start: %lg, x2End: %lg, testNumX0 = %lu, testNumX1 = %lu, testNumX2 = %lu, fileNameKernel: %s\n", x0Start.d, x0End.d, x1Start.d, x1End.d, x2Start.d, x2End.d, testNumX0, testNumX1, testNumX2, fileNameKernel); + // } + + // local parameters init + int lenX4Local = testNumX4 / numProcs; + int i4StartLocal; + i4StartLocal = x4startNowIdx + myid * lenX4Local; + int i4EndLocal; + if(myid != numProcs - 1) { + i4EndLocal = x4startNowIdx + (myid + 1) * lenX4Local - 1; + } else { + i4EndLocal = x4startNowIdx + testNumX4; + } + int i3StartLocal = x3startNowIdx; + int i3EndLocal = x3startNowIdx + testNumX3; + int i2StartLocal = x2startNowIdx; + int i2EndLocal = x2startNowIdx + testNumX2; + int i1StartLocal = x1startNowIdx; + int i1EndLocal = x1startNowIdx + testNumX1; + int i0StartLocal = x0startNowIdx; + int i0EndLocal = x0startNowIdx + testNumX0; + + string uniqueLabelStr(uniqueLabel); + string fileNameKernelStr(fileNameKernel); + iRRAM_initialize(argc, argv); + iRRAM::iRRAM_exec(main_inner, testNumX0, testNumX1, testNumX2, testNumX3, testNumX4, uniqueLabelStr, fileNameKernelStr, myid, numProcs, i0StartLocal, i0EndLocal, i1StartLocal, i1EndLocal, i2StartLocal, i2EndLocal, i3StartLocal, i3EndLocal, i4StartLocal, i4EndLocal, x0startOriginInterval, x1startOriginInterval, x2startOriginInterval, x3startOriginInterval, x4startOriginInterval, stepX0, stepX1, stepX2, stepX3, stepX4); + + MPI_Finalize(); + return 0; +} \ No newline at end of file -- Gitee From 641dec973e472c41077c4d11865b793e0d018316 Mon Sep 17 00:00:00 2001 From: hjwLab Date: Fri, 14 Apr 2023 10:59:11 +0800 Subject: [PATCH 28/32] fix bugs and improve codes --- detectErrorAll10.sh | 1 + src/geneCode.cpp | 2 +- src/tools.cpp | 2 ++ srcTest/polyIDX2/expr_polyIDX2_herbie.c | 13 ++++++++----- srcTest/test4paramFPEDParallel.c | 2 +- srcTest/test5paramFPEDParallel.c | 2 +- 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/detectErrorAll10.sh b/detectErrorAll10.sh index 148c95f..9e0797d 100644 --- a/detectErrorAll10.sh +++ b/detectErrorAll10.sh @@ -18,6 +18,7 @@ fi ./detectErrorFourFPEDParallel.sh polyIDX0 3 9 1.5 5 -2 10 -1 3.5 16 16 16 16 0 0 0 0 3 1.5 -2 -1 0.375 0.21875 0.75 0.28125 expr_polyIDX0 3_9_1.5_5_-2_10_-1_3.5_16_16_16_16 origin ./detectErrorFourFPEDParallel.sh polyIDX0 3 9 1.5 5 -2 10 -1 3.5 16 16 16 16 0 0 0 0 3 1.5 -2 -1 0.375 0.21875 0.75 0.28125 expr_polyIDX0 3_9_1.5_5_-2_10_-1_3.5_16_16_16_16 herbie ./detectErrorFourFPEDParallel.sh polyIDX0 3 9 1.5 5 -2 10 -1 3.5 16 16 16 16 0 0 0 0 3 1.5 -2 -1 0.375 0.21875 0.75 0.28125 expr_polyIDX0 3_9_1.5_5_-2_10_-1_3.5_16_16_16_16 herbiePlus +./detectErrorFourFPEDParallel.sh polyIDX0 3 9 1.5 5 -2 10 -1 3.5 16 16 16 16 0 0 0 0 3 1.5 -2 -1 0.375 0.21875 0.75 0.28125 expr_polyIDX0 3_9_1.5_5_-2_10_-1_3.5_16_16_16_16 final ./detectErrorFourFPEDParallel.sh polyIDX1 3 9 1.5 5 -2 10 -1 3.5 16 16 16 16 0 0 0 0 3 1.5 -2 -1 0.375 0.21875 0.75 0.28125 expr_polyIDX1 3_9_1.5_5_-2_10_-1_3.5_16_16_16_16 origin ./detectErrorFourFPEDParallel.sh polyIDX1 3 9 1.5 5 -2 10 -1 3.5 16 16 16 16 0 0 0 0 3 1.5 -2 -1 0.375 0.21875 0.75 0.28125 expr_polyIDX1 3_9_1.5_5_-2_10_-1_3.5_16_16_16_16 herbie ./detectErrorFourFPEDParallel.sh polyIDX1 3 9 1.5 5 -2 10 -1 3.5 16 16 16 16 0 0 0 0 3 1.5 -2 -1 0.375 0.21875 0.75 0.28125 expr_polyIDX1 3_9_1.5_5_-2_10_-1_3.5_16_16_16_16 herbiePlus diff --git a/src/geneCode.cpp b/src/geneCode.cpp index 3fd5995..d19338e 100644 --- a/src/geneCode.cpp +++ b/src/geneCode.cpp @@ -305,7 +305,7 @@ string geneHerbieCode(string uniqueLabel) {"polyIDX1", "x0"}, // error but not influence the result {"polyIDX2", ""}, {"example5param", "(x0+x1)+(x2+x3)+x4"}, - {"pov_ray", ""}, + {"pov_ray", "cos(x2) * fma(x1, cos(x3), fma(x5, sin(x3), x4))"}, }; auto pos = benchmarkHerbie.find(uniqueLabel); diff --git a/src/tools.cpp b/src/tools.cpp index 8c2c351..e31584f 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -851,6 +851,8 @@ vector rewrite(string exprStr, string uniqueLabel, vector newTempExprs; + // newTempExprs.push_back(tempExpr->Clone()); numOfExprs = newTempExprs.size(); string suffix = "temp_" + std::to_string(count) + "_"; diff --git a/srcTest/polyIDX2/expr_polyIDX2_herbie.c b/srcTest/polyIDX2/expr_polyIDX2_herbie.c index e2f5340..b68466e 100644 --- a/srcTest/polyIDX2/expr_polyIDX2_herbie.c +++ b/srcTest/polyIDX2/expr_polyIDX2_herbie.c @@ -1,6 +1,9 @@ #include -double expr_polyIDX2_herbie(double x0) -{ - double result = x0; - return result; -} +double expr_polyIDX2_herbie(double x1, double x2, double x3, double x4) { + double t_0 = (x1 * -0.8507307281963669) + ((x4 * 1.865345093933099) + (x3 * 1.3809517485817782)); + double t_1 = (0.40478255170032273 * x3) + ((0.052100253064028955 * x1) + (-0.9377469019770424 * x4)); + double t_2 = pow(t_1, 2.0); + double t_3 = (x4 * 1.865345093933099) + ((x1 * -0.8507307281963669) + (x3 * 1.3809517485817782)); + double t_4 = pow(t_3, 2.0); + return ((0.24537492502430377 * pow(x2, 3.0)) + (pow(t_1, 3.0) + ((pow(x2, 2.0) * (((t_1 * 0.7996547886767552) + (t_1 * 1.5993095773535104)) - ((0.973458823407345 * t_0) + (1.94691764681469 * t_3)))) + (x2 * (((-0.8942341911807864 * t_2) + (t_2 * -1.7884683823615728)) - ((-1.97328033832737 * (t_0 * t_3)) + (-0.986640169163685 * t_4))))))) + (t_4 * ((x1 * 0.8507307281963669) + ((x4 * -1.865345093933099) + (x3 * -1.3809517485817782)))); +} \ No newline at end of file diff --git a/srcTest/test4paramFPEDParallel.c b/srcTest/test4paramFPEDParallel.c index e5dcc73..ca6c1c0 100644 --- a/srcTest/test4paramFPEDParallel.c +++ b/srcTest/test4paramFPEDParallel.c @@ -150,7 +150,7 @@ int main(int argc, char **argv) { MPI_Comm_rank(MPI_COMM_WORLD, &myid); MPI_Comm_size(MPI_COMM_WORLD, &numProcs); MPI_Datatype MPI_errorInfo; - MPI_Type_contiguous(5, MPI_DOUBLE, &MPI_errorInfo); + MPI_Type_contiguous(6, MPI_DOUBLE, &MPI_errorInfo); MPI_Type_commit(&MPI_errorInfo); // parameters init diff --git a/srcTest/test5paramFPEDParallel.c b/srcTest/test5paramFPEDParallel.c index 02de0ff..fca9496 100644 --- a/srcTest/test5paramFPEDParallel.c +++ b/srcTest/test5paramFPEDParallel.c @@ -157,7 +157,7 @@ int main(int argc, char **argv) { MPI_Comm_rank(MPI_COMM_WORLD, &myid); MPI_Comm_size(MPI_COMM_WORLD, &numProcs); MPI_Datatype MPI_errorInfo; - MPI_Type_contiguous(5, MPI_DOUBLE, &MPI_errorInfo); + MPI_Type_contiguous(7, MPI_DOUBLE, &MPI_errorInfo); MPI_Type_commit(&MPI_errorInfo); // parameters init -- Gitee From fd6a0a3ea0e102c59d63b99cf4c080a469c61901 Mon Sep 17 00:00:00 2001 From: hjwLab Date: Fri, 14 Apr 2023 11:00:36 +0800 Subject: [PATCH 29/32] fix a bug about MPI DIY type --- srcTest/test5paramFPEDParallelNumOpt.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/srcTest/test5paramFPEDParallelNumOpt.cpp b/srcTest/test5paramFPEDParallelNumOpt.cpp index 12cfa26..0abe7ed 100644 --- a/srcTest/test5paramFPEDParallelNumOpt.cpp +++ b/srcTest/test5paramFPEDParallelNumOpt.cpp @@ -177,7 +177,7 @@ int main_inner(const unsigned long int &testNumX0, const unsigned long int &test iRRAM::cout << iRRAM::setRwidth(30); MPI_Datatype MPI_errorInfo; - MPI_Type_contiguous(5, MPI_DOUBLE, &MPI_errorInfo); + MPI_Type_contiguous(7, MPI_DOUBLE, &MPI_errorInfo); MPI_Type_commit(&MPI_errorInfo); char *fileNameKernel; -- Gitee From 3764a1fe5454a61aa2a3ce44c09fc5180c66043a Mon Sep 17 00:00:00 2001 From: hjwLab Date: Fri, 14 Apr 2023 11:07:01 +0800 Subject: [PATCH 30/32] improve code --- src/tools.cpp | 2 ++ srcTest/test5paramFPEDParallelNumOpt.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/tools.cpp b/src/tools.cpp index 7323b18..27727fd 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -919,6 +919,8 @@ vector rewrite(string exprStr, string uniqueLabel, vector newTempExprs; + // newTempExprs.push_back(tempExpr->Clone()); numOfExprs = newTempExprs.size(); string suffix = "temp_" + std::to_string(count) + "_"; diff --git a/srcTest/test5paramFPEDParallelNumOpt.cpp b/srcTest/test5paramFPEDParallelNumOpt.cpp index 0abe7ed..ea5b58f 100644 --- a/srcTest/test5paramFPEDParallelNumOpt.cpp +++ b/srcTest/test5paramFPEDParallelNumOpt.cpp @@ -245,6 +245,8 @@ int main_inner(const unsigned long int &testNumX0, const unsigned long int &test free(fileNameKernel); free(errs); MPI_Type_free(&MPI_errorInfo); + + return 0; } -- Gitee From 402458cfd064dbda252b552c7a432dd487bedb39 Mon Sep 17 00:00:00 2001 From: hjwLab Date: Fri, 14 Apr 2023 14:10:26 +0800 Subject: [PATCH 31/32] implement limitExprNumByRandom to limit the number of exprs --- src/exprAuto.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/exprAuto.cpp b/src/exprAuto.cpp index 86b58d5..88bf351 100644 --- a/src/exprAuto.cpp +++ b/src/exprAuto.cpp @@ -927,6 +927,21 @@ void sortExpr(ast_ptr &expr){ sortExprAST(min ,max ,v ,expr); } +// limitExprNumByRandom uses random_shuffle to limit the number of elements in exprs +// we set limitExprNumByNum at the 3 different level, so the number of the rewritten exprs shouble be about 10^3. +void limitExprNumByRandom(vector &exprs, const size_t thresholdExprNum = 10) +{ + if (exprs.size() > thresholdExprNum) + { + random_shuffle(exprs.begin(), exprs.end()); + int deleteNum = exprs.size() - thresholdExprNum; + for (int i = 0; i < deleteNum; i++) + { + exprs.pop_back(); + } + } +} + vector polyRewrite(const ast_ptr &expr) { static size_t callCount = 0; @@ -949,11 +964,13 @@ vector polyRewrite(const ast_ptr &expr) } auto numeratorsFinal = mergePolynomial(numerators); auto results = createExpr(numeratorsFinal); - for(int i = 0 ;i < (int)results.size();i++){ + for (int i = 0; i < (int)results.size(); i++) + { ast_ptr &a = results.at(i); sortExpr(a); } vector resultsNew; + limitExprNumByRandom(results); for(auto &result : results) { resultsNew.push_back(result->Clone()); // the key to control the rewrite results @@ -969,6 +986,7 @@ vector polyRewrite(const ast_ptr &expr) // tmps1.push_back(std::move(tmp->Clone())); tmps1.push_back(std::move(tmp1)); } + limitExprNumByRandom(tmps1); if(tmps1.empty()) { resultsNew.push_back(std::move(result)); @@ -1031,9 +1049,11 @@ vector tryRewrite(ast_ptr expr, bool addSelf) } if(callCount == 1) printExpr(exprNew, prompt + "tryRewrites: before mathfuncRewrite: "); auto middles = mathfuncRewrite(exprNew, addSelf); - if(callCount == 1) printExpr(exprNew, prompt + "tryRewrites: after mathfuncRewrite: "); + // if(callCount == 1) printExprs(middles, prompt + "tryRewrites: after mathfuncRewrite: "); vector results; size_t index = 0; + // cout << "tryRewrite middles.size() = " << middles.size() << endl; + limitExprNumByRandom(middles); for(const auto &middle : middles) { // cout << prompt << "For expr NO." << index << ": " << PrintExpression(middle) << ", do polyRewrite" << endl; @@ -1050,8 +1070,10 @@ vector tryRewrite(ast_ptr expr, bool addSelf) // } auto tmp = polyRewrite(middle); mineAppend(results, tmp); + // results.push_back(middle->Clone()); index++; } + // cout << "tryRewrite results.size() = " << results.size() << endl; // if(callCount == 1) printExprs(results, "tryRewrites: before delete: "); for(int i = 0 ;i < (int)results.size();i++){ ast_ptr &a = results.at(i); -- Gitee From b8abce7fe29d5f6e40dfcef19b77607e891981b0 Mon Sep 17 00:00:00 2001 From: hjwLab Date: Mon, 17 Apr 2023 09:29:56 +0800 Subject: [PATCH 32/32] Modify and improve some outdated code --- detectErrorAll.sh | 8 ++++---- src/main.cpp | 35 ++++++++++++++++++----------------- src/tools.cpp | 4 +--- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/detectErrorAll.sh b/detectErrorAll.sh index eac27c2..1f3e3bd 100755 --- a/detectErrorAll.sh +++ b/detectErrorAll.sh @@ -72,7 +72,7 @@ fi # ./detectErrorThreeFPEDParallel${suffix}.sh turbine1 3.8 7.8 -4.5 -0.3 0.4 0.9 256 256 256 0 0 0 3.8 -4.5 0.4 0.015625 0.01640625 0.001953125 expr_turbine1 3.8_7.8_-4.5_-0.3_0.4_0.9_256_256_256 ${target} # DONE -./detectErrorOneFPEDParallelNumOpt.sh squareRoot3_2 0 10 500000 0 0 2e-05 expr_squareRoot3_2 0_10_500000 NumOpt -./detectErrorOneFPEDParallelNumOpt.sh smartRoot_2 -2 2 500000 0 -2 8e-06 expr_smartRoot_2 -2_2_500000 NumOpt -./detectErrorOneFPEDParallelNumOpt.sh squareRoot3Invalid_2 0 10 500000 0 0 2e-05 expr_squareRoot3Invalid_2 0_10_500000 NumOpt -./detectErrorOneFPEDParallelNumOpt.sh cav10_2 0 10 500000 0 0 2e-05 expr_cav10_2 0_10_500000 NumOpt \ No newline at end of file +# ./detectErrorOneFPEDParallel${suffix}.sh squareRoot3_2 0 10 500000 0 0 2e-05 expr_squareRoot3_2 0_10_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh smartRoot_2 -2 2 500000 0 -2 8e-06 expr_smartRoot_2 -2_2_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh squareRoot3Invalid_2 0 10 500000 0 0 2e-05 expr_squareRoot3Invalid_2 0_10_500000 ${target} +# ./detectErrorOneFPEDParallel${suffix}.sh cav10_2 0 10 500000 0 0 2e-05 expr_cav10_2 0_10_500000 ${target} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 765557d..f192b85 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -123,8 +123,8 @@ int main() fprintf(stderr, GREEN "ready> " RESET); string inputStr = ""; - while (getline(infile, inputStr)) // read line from file's input - // while (getline(cin, inputStr)) // read line from keyboard input + // while (getline(infile, inputStr)) // read line from file's input + while (getline(cin, inputStr)) // read line from keyboard input { // only rewrite // getlineCount++; @@ -257,21 +257,22 @@ int main() auto exprOrigin = geneExprCodeKernel(inputStr, vars, uniqueLabel, "origin"); - vector startNowIdxsTmp(dimension, 0); - vector startOriginIntervalsTmp; - vector stepsTmp; - for (int i = 0; i < dimension; i++) - { - auto &startOriginInterval = intervals.at(i * 2); - auto &endOriginInterval = intervals.at(i * 2 + 1); - startOriginIntervalsTmp.push_back(startOriginInterval); - double width = endOriginInterval - startOriginInterval; - double step = width / (double)scales.at(i); - stepsTmp.push_back(step); - } - geneErrorDetectScript(uniqueLabel, "tmp", intervals, scales, startNowIdxsTmp, startOriginIntervalsTmp, stepsTmp); - fprintf(stderr, GREEN "ready> " RESET); - continue; + // generate error detect script + // vector startNowIdxsTmp(dimension, 0); + // vector startOriginIntervalsTmp; + // vector stepsTmp; + // for (int i = 0; i < dimension; i++) + // { + // auto &startOriginInterval = intervals.at(i * 2); + // auto &endOriginInterval = intervals.at(i * 2 + 1); + // startOriginIntervalsTmp.push_back(startOriginInterval); + // double width = endOriginInterval - startOriginInterval; + // double step = width / (double)scales.at(i); + // stepsTmp.push_back(step); + // } + // geneErrorDetectScript(uniqueLabel, "tmp", intervals, scales, startNowIdxsTmp, startOriginIntervalsTmp, stepsTmp); + // fprintf(stderr, GREEN "ready> " RESET); + // continue; // auto funcNameOrigin = geneExprCode(inputStr, uniqueLabel, "origin"); // auto funcNameHerbie = geneHerbieCode(inputStr, uniqueLabel, "herbie"); diff --git a/src/tools.cpp b/src/tools.cpp index 27727fd..685d446 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -422,9 +422,6 @@ exprInfo testError(string uniqueLabel, string suffix, const vector &inte // cout << "fileNameKernel: " << fileNameKernel << "\n"; cout << "command: " << commandStr << "\n"; - - return tempError; - // cout << "testName: " << testName << "\n"; char command[512] = {0}; strcat(command, commandStr.c_str()); @@ -531,6 +528,7 @@ void sampleError(string uniqueLabel, string suffix, const vector &interv } } +// generate error detect script void geneErrorDetectScript(string uniqueLabel, string suffix, const vector &intervals, const vector &scales, const vector &startNowIdxs, const vector &startOriginIntervals, const vector &steps) { size_t size = scales.size(); -- Gitee