`#!perl -l
# Looking at function F = pi ^ y
#
# F = pi ^ y
# error = dF = y * pi ^ (y-1) * dpi
# => dpi = error / ( y * x ^ (y-1) )
#
# So if we want to limit the error in F to 0.1:
use constant ERROR => 0.1;
use constant PI => 4 * atan2(1,1);
warn "Check: pi is ", PI, "\n";
my @y = (1..9, map(10 * $_, 1..9), map(100*$_,1..10));
foreach my $y (@y) {
printf "y=%d dpi=%g\n", $y, dpi($y);
}
sub dpi {
my $y = $_[0];
my $denom = $y * PI ** ($y-1);
return ERROR / $denom;
}
__END__
Check: pi is 3.14159265358979
y=1 dpi=0.1
y=2 dpi=0.0159155
y=3 dpi=0.00337737
y=4 dpi=0.000806288
y=5 dpi=0.00020532
y=6 dpi=5.44627e-05
y=7 dpi=1.48594e-05
y=8 dpi=4.13867e-06
y=9 dpi=1.171e-06
y=10 dpi=3.35468e-07
y=20 dpi=1.79111e-12
y=30 dpi=1.27507e-17
y=40 dpi=1.02116e-22
y=50 dpi=8.72341e-28
y=60 dpi=7.76258e-33
y=70 dpi=7.10495e-38
y=80 dpi=6.6385e-43
y=90 dpi=6.30114e-48
y=100 dpi=6.05568e-53
y=200 dpi=5.8364e-103
y=300 dpi=7.5001e-153
y=400 dpi=1.08428e-202
y=500 dpi=1.67203e-252
y=600 dpi=2.68581e-302
y=700 dpi=0
y=800 dpi=0
y=900 dpi=0
y=1000 dpi=0
`
**Update:** yes, for example if we're calculating pi^y for @y=5..15, and we introduce an error to pi of 1e-7:
`#!perl -l
use strict;
use warnings;
use constant PI => 4 * atan2(1,1);
use constant DPI => 1e-7;
my @y = (5..15);
foreach my $y (@y) {
my $f1 = F(PI,$y);
my $f2 = F(PI+DPI,$y);
my $delta = $f2 - $f1;
printf "y=%-2d delta=%g\n", $y, $delta;
}
# F = pi ^ y
sub F {
my ($pi, $y) = @_;
return $pi ** $y,
}
__END__
y=5 delta=4.87045e-05
y=6 delta=0.000183612
y=7 delta=0.000672972
y=8 delta=0.00241623
y=9 delta=0.00853968
y=10 delta=0.0298091
y=11 delta=0.103013
y=12 delta=0.353045
y=13 delta=1.20155
y=14 delta=4.06515
y=15 delta=13.6833
`
So an error of 1e-7 in pi doesn't affect the output of F by more than 0.1 until we hit y=11. |