2016-01-02 14:51:32 +00:00
|
|
|
/*************************************************************************************
|
|
|
|
|
|
|
|
Grid physics library, www.github.com/paboyle/Grid
|
|
|
|
|
|
|
|
Source file: ./tests/Test_remez.cc
|
|
|
|
|
|
|
|
Copyright (C) 2015
|
|
|
|
|
|
|
|
Author: Azusa Yamaguchi <ayamaguc@staffmail.ed.ac.uk>
|
|
|
|
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program 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 General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
|
|
|
See the full license in the file "LICENSE" in the top level distribution directory
|
|
|
|
*************************************************************************************/
|
|
|
|
/* END LEGAL */
|
2015-05-18 12:09:25 +01:00
|
|
|
#include <Grid.h>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Grid;
|
|
|
|
using namespace Grid::QCD;
|
|
|
|
|
|
|
|
int main (int argc, char ** argv)
|
|
|
|
{
|
|
|
|
Grid_init(&argc,&argv);
|
|
|
|
|
2015-07-23 17:31:13 +01:00
|
|
|
std::cout<<GridLogMessage << "Testing Remez"<<std::endl;
|
2015-05-18 12:09:25 +01:00
|
|
|
|
|
|
|
double lo=0.01;
|
|
|
|
double hi=1.0;
|
|
|
|
int precision=64;
|
|
|
|
int degree=10;
|
|
|
|
AlgRemez remez(0.001,1.0,precision);
|
|
|
|
|
|
|
|
////////////////////////////////////////
|
|
|
|
// sqrt and inverse sqrt
|
|
|
|
////////////////////////////////////////
|
|
|
|
|
2015-07-23 17:31:13 +01:00
|
|
|
std::cout<<GridLogMessage << "Generating degree "<<degree<<" for x^(1/2)"<<std::endl;
|
2015-05-18 12:09:25 +01:00
|
|
|
remez.generateApprox(degree,1,2);
|
2015-06-08 11:52:44 +01:00
|
|
|
MultiShiftFunction Sqrt(remez,1.0,false);
|
|
|
|
MultiShiftFunction InvSqrt(remez,1.0,true);
|
|
|
|
|
2015-05-18 12:09:25 +01:00
|
|
|
|
2015-07-23 17:31:13 +01:00
|
|
|
std::cout<<GridLogMessage << "Generating degree "<<degree<<" for x^(1/4)"<<std::endl;
|
2015-05-18 12:09:25 +01:00
|
|
|
remez.generateApprox(degree,1,4);
|
2015-06-08 11:52:44 +01:00
|
|
|
MultiShiftFunction SqrtSqrt(remez,1.0,false);
|
|
|
|
MultiShiftFunction InvSqrtSqrt(remez,1.0,true);
|
|
|
|
|
2015-05-18 12:09:25 +01:00
|
|
|
|
|
|
|
ofstream gnuplot(std::string("Sqrt.gnu"),std::ios::out|std::ios::trunc);
|
|
|
|
Sqrt.gnuplot(gnuplot);
|
|
|
|
|
|
|
|
ofstream gnuplot_inv(std::string("InvSqrt.gnu"),std::ios::out|std::ios::trunc);
|
|
|
|
InvSqrt.gnuplot(gnuplot);
|
|
|
|
|
|
|
|
double x=0.6789;
|
2015-06-08 12:03:36 +01:00
|
|
|
double sx=std::sqrt(x);
|
|
|
|
double ssx=std::sqrt(sx);
|
2015-05-18 12:09:25 +01:00
|
|
|
double isx=1.0/sx;
|
|
|
|
double issx=1.0/ssx;
|
|
|
|
|
|
|
|
double asx =Sqrt.approx(x);
|
|
|
|
double assx =SqrtSqrt.approx(x);
|
|
|
|
double aisx =InvSqrt.approx(x);
|
|
|
|
double aissx=InvSqrtSqrt.approx(x);
|
|
|
|
|
2015-07-23 17:31:13 +01:00
|
|
|
std::cout<<GridLogMessage << "x^(1/2) : "<<sx<<" "<<asx<<std::endl;
|
|
|
|
std::cout<<GridLogMessage << "x^(1/4) : "<<ssx<<" "<<assx<<std::endl;
|
|
|
|
std::cout<<GridLogMessage << "x^(-1/2): "<<isx<<" "<<aisx<<std::endl;
|
|
|
|
std::cout<<GridLogMessage << "x^(-1/4): "<<issx<<" "<<aissx<<std::endl;
|
2015-05-18 12:09:25 +01:00
|
|
|
assert(fabs(sx-asx)<1.0e-6);
|
|
|
|
assert(fabs(ssx-assx)<1.0e-6);
|
|
|
|
assert(fabs(isx-aisx)<1.0e-6);
|
|
|
|
assert(fabs(issx-aissx)<1.0e-6);
|
|
|
|
|
|
|
|
Grid_finalize();
|
|
|
|
}
|