Results of PROMISE with the arclength program
We use the same program for arclength computation as in [1] with
all floating-point variables initially declared in double precision.
Initial code:
double fun( double x){
int k, n = 5;
double t1;
double d1 = 1.0;
t1 = x;
for ( k = 1; k <= n; k++ )
{
d1 = 2.0 * d1;
t1 = t1+ sin(d1 * x)/d1;
}
return t1;
}
int main( int argc, char **argv) {
int i,n = 1000000;
double h, t1, t2, dppi;
double s1;
t1 = -1.0;
dppi = acos(t1);
s1 = 0.0;
t1 = 0.0;
h = dppi / n;
for ( i = 1; i <= n; i++)
{
t2 = fun(i * h);
s1 = s1 + sqrt(h*h + (t2 - t1) * (t2 - t1));
t1 = t2;
}
std::cout << s1 << std::endl;
return 0;
}
Result: 5.79577632241303
Code modified to be used with PROMISE:
double fun(double x){
int k, n = 5;
double t1;
double d1 = 1.0;
t1 = x;
for ( k = 1; k <= n; k++ )
{
d1 = 2.0 * d1;
t1 = t1+ sin(d1 * x)/d1;
}
return t1;
}
int main( int argc, char **argv) {
cadna_init(0);
int i,n = 1000000;
double h;
double t1;
double t2;
double dppi;
double s1;
t1 = -1.0;
dppi = acos(t1);
s1 = 0.0;
t1 = 0.0;
h = dppi / n;
for ( i = 1; i <= n; i++)
{
t2 = fun(i * h);
s1 = s1 + sqrt(h*h + (t2 - t1) * (t2 - t1));
t1 = t2;
}
dump(s1);
std::cout << s1 << std::endl;
return 0;
}
Code after the use of PROMISE (6 digits requested):
double fun( double x){
int k, n = 5;
double t1;
float d1 = 1.0;
t1 = x;
for ( k = 1; k <= n; k++ )
{
d1 = 2.0 * d1;
t1 = t1+ sin(d1 * x)/d1;
}
return t1;
}
int main( int argc, char **argv) {
int i,n = 1000000;
double h;
double t1;
double t2;
float dppi;
double s1;
t1 = -1.0;
dppi = acos(t1);
s1 = 0.0;
t1 = 0.0;
h = dppi / n;
for ( i = 1; i <= n; i++)
{
t2 = fun(i * h);
s1 = s1 + sqrt(h*h + (t2 - t1) * (t2 - t1));
t1 = t2;
}
std::cout << s1 << std::endl;
return 0;
}
If printed without using CADNA,
Result: 5.79577686259398
If printed using CADNA,
Result: 0.579577E+001 (other digits are affected by round-off errors)
Reference
[1] C. Rubio-González, C. Nguyen, H.D. Nguyen, J. Demmel, W. Kahan, K. Sen, D.H. Bailey, C. Iancu, D. Hough, Precimonious: Tuning assistant for floating-point precision, in: Proceedings of the International Conference on High Performance Computing, Networking, Storage and Analysis, SC '13, ACM, New York, NY, USA, 2013, pp. 27:1-27:12.