public inbox for gsl-discuss@sourceware.org
 help / color / mirror / Atom feed
From: Jonathan Leto <jonathan@leto.net>
To: gsl-discuss@sources.redhat.com
Subject: sf_gamma questions
Date: Wed, 19 Dec 2001 13:20:00 -0000	[thread overview]
Message-ID: <20011201214553.A31518@leto.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 1895 bytes --]

I was writing some test cases for Math::Gsl, when I saw some
failing, because gamma(19) was off by 1 and gamma(20) is off by
16. So I wrote a little test program to compare absolute difference
between gamma(x) and factorial(x-1) . The output was: 

-------------- Actual error vs. Theoretical Error
Difference (1):0 vs 2.22044604925031308e-16
Difference (2):0 vs 2.22044604925031308e-16
Difference (3):1.77635683940025046e-15 vs 1.4246133846675888e-14
Difference (4):7.99360577730112709e-15 vs 4.71293383088833937e-14
Difference (5):1.06581410364015028e-14 vs 6.92426984602974577e-14
Difference (6):2.84217094304040074e-14 vs 2.96806016881859386e-13
Difference (7):1.1368683772161603e-13 vs 1.45976589371855462e-12
Difference (8):9.09494701772928238e-13 vs 1.02398955184829092e-11
Difference (9):7.2759576141834259e-12 vs 1.01934226616975847e-10
Difference (10):5.82076609134674072e-11 vs 1.00719432793994222e-09
Difference (11):4.65661287307739258e-10 vs 1.08776987417513721e-08
Difference (12):0 vs 1.28517996245136601e-07
Difference (13):5.9604644775390625e-08 vs 1.64857567597209688e-06
Difference (14):0 vs 2.28141601610332145e-05
Difference (15):1.52587890625e-05 vs 0.000338755711482008391
Difference (16):0 vs 0.00537169771064327506
Difference (17):0 vs 0.090592955984902801
Difference (18):0.0625 vs 1.61905872619172486
Difference (19):1 vs 30.5646696115218255
Difference (20):16 vs 607.739360880259596
Difference (21):0 vs 12694.999982832087
Difference (22):0 vs 277939.467709238641
Difference (23):131072 vs 6364246.58713807818
Difference (24):1572864 vs 152117972.34747678
Difference (25):104857600 vs 3788598556.57866812

Why is the error so large for  gamma(x>18) ? Would it be possible
to just return factorial(x-1) if gamma is given an integer argument?

Test program (perl) is attached.

-- 
jonathan@leto.net 
"Wir muessen wissen. Wir werden wissen."
	-- David Hilbert, 1931



[-- Attachment #2: a --]
[-- Type: text/plain, Size: 318 bytes --]

#!/usr/bin/perl -w

use strict;
use Math::Gsl::Sf qw(gamma gamma_e);
my $r = new Math::Gsl::Sf::Result;


for (1 .. 25 ){
	gamma_e( $_ , $r );
	print "Difference ($_):" .  abs( $r->val - fact($_- 1) )  . " vs ";
	print $r->err . "\n";
}

sub fact {
	my $x = shift;
	return 1 if $x == 0;
	return $x * fact( $x - 1 );
}

WARNING: multiple messages have this Message-ID
From: Jonathan Leto <jonathan@leto.net>
To: gsl-discuss@sources.redhat.com
Subject: sf_gamma questions
Date: Wed, 19 Dec 2001 13:20:00 -0000	[thread overview]
Message-ID: <20011201214553.A31518@leto.net> (raw)
Message-ID: <20011219132000.pNe25Xa8UGA_1fu8DpueuwNQTgfWq1ya3IFf3Ak0rI0@z> (raw)

I was writing some test cases for Math::Gsl, when I saw some
failing, because gamma(19) was off by 1 and gamma(20) is off by
16. So I wrote a little test program to compare absolute difference
between gamma(x) and factorial(x-1) . The output was: 

-------------- Actual error vs. Theoretical Error
Difference (1):0 vs 2.22044604925031308e-16
Difference (2):0 vs 2.22044604925031308e-16
Difference (3):1.77635683940025046e-15 vs 1.4246133846675888e-14
Difference (4):7.99360577730112709e-15 vs 4.71293383088833937e-14
Difference (5):1.06581410364015028e-14 vs 6.92426984602974577e-14
Difference (6):2.84217094304040074e-14 vs 2.96806016881859386e-13
Difference (7):1.1368683772161603e-13 vs 1.45976589371855462e-12
Difference (8):9.09494701772928238e-13 vs 1.02398955184829092e-11
Difference (9):7.2759576141834259e-12 vs 1.01934226616975847e-10
Difference (10):5.82076609134674072e-11 vs 1.00719432793994222e-09
Difference (11):4.65661287307739258e-10 vs 1.08776987417513721e-08
Difference (12):0 vs 1.28517996245136601e-07
Difference (13):5.9604644775390625e-08 vs 1.64857567597209688e-06
Difference (14):0 vs 2.28141601610332145e-05
Difference (15):1.52587890625e-05 vs 0.000338755711482008391
Difference (16):0 vs 0.00537169771064327506
Difference (17):0 vs 0.090592955984902801
Difference (18):0.0625 vs 1.61905872619172486
Difference (19):1 vs 30.5646696115218255
Difference (20):16 vs 607.739360880259596
Difference (21):0 vs 12694.999982832087
Difference (22):0 vs 277939.467709238641
Difference (23):131072 vs 6364246.58713807818
Difference (24):1572864 vs 152117972.34747678
Difference (25):104857600 vs 3788598556.57866812

Why is the error so large for  gamma(x>18) ? Would it be possible
to just return factorial(x-1) if gamma is given an integer argument?

Test program (perl) is attached.

-- 
jonathan@leto.net 
"Wir muessen wissen. Wir werden wissen."
	-- David Hilbert, 1931


WARNING: multiple messages have this Message-ID
From: Jonathan Leto <jonathan@leto.net>
To: gsl-discuss@sources.redhat.com
Subject: sf_gamma questions
Date: Mon, 26 Nov 2001 23:50:00 -0000	[thread overview]
Message-ID: <20011201214553.A31518@leto.net> (raw)
Message-ID: <20011126235000.IP362Opz6n27IZDiTXicYvJLl636oCRqOqmfgq-3aGk@z> (raw)

[-- Attachment #1: Type: text/plain, Size: 1895 bytes --]

I was writing some test cases for Math::Gsl, when I saw some
failing, because gamma(19) was off by 1 and gamma(20) is off by
16. So I wrote a little test program to compare absolute difference
between gamma(x) and factorial(x-1) . The output was: 

-------------- Actual error vs. Theoretical Error
Difference (1):0 vs 2.22044604925031308e-16
Difference (2):0 vs 2.22044604925031308e-16
Difference (3):1.77635683940025046e-15 vs 1.4246133846675888e-14
Difference (4):7.99360577730112709e-15 vs 4.71293383088833937e-14
Difference (5):1.06581410364015028e-14 vs 6.92426984602974577e-14
Difference (6):2.84217094304040074e-14 vs 2.96806016881859386e-13
Difference (7):1.1368683772161603e-13 vs 1.45976589371855462e-12
Difference (8):9.09494701772928238e-13 vs 1.02398955184829092e-11
Difference (9):7.2759576141834259e-12 vs 1.01934226616975847e-10
Difference (10):5.82076609134674072e-11 vs 1.00719432793994222e-09
Difference (11):4.65661287307739258e-10 vs 1.08776987417513721e-08
Difference (12):0 vs 1.28517996245136601e-07
Difference (13):5.9604644775390625e-08 vs 1.64857567597209688e-06
Difference (14):0 vs 2.28141601610332145e-05
Difference (15):1.52587890625e-05 vs 0.000338755711482008391
Difference (16):0 vs 0.00537169771064327506
Difference (17):0 vs 0.090592955984902801
Difference (18):0.0625 vs 1.61905872619172486
Difference (19):1 vs 30.5646696115218255
Difference (20):16 vs 607.739360880259596
Difference (21):0 vs 12694.999982832087
Difference (22):0 vs 277939.467709238641
Difference (23):131072 vs 6364246.58713807818
Difference (24):1572864 vs 152117972.34747678
Difference (25):104857600 vs 3788598556.57866812

Why is the error so large for  gamma(x>18) ? Would it be possible
to just return factorial(x-1) if gamma is given an integer argument?

Test program (perl) is attached.

-- 
jonathan@leto.net 
"Wir muessen wissen. Wir werden wissen."
	-- David Hilbert, 1931



[-- Attachment #2: a --]
[-- Type: text/plain, Size: 318 bytes --]

#!/usr/bin/perl -w

use strict;
use Math::Gsl::Sf qw(gamma gamma_e);
my $r = new Math::Gsl::Sf::Result;


for (1 .. 25 ){
	gamma_e( $_ , $r );
	print "Difference ($_):" .  abs( $r->val - fact($_- 1) )  . " vs ";
	print $r->err . "\n";
}

sub fact {
	my $x = shift;
	return 1 if $x == 0;
	return $x * fact( $x - 1 );
}

             reply	other threads:[~2001-12-02  2:46 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-12-19 13:20 Jonathan Leto [this message]
2001-11-26 23:50 ` Jonathan Leto
2001-12-19 13:20 ` Brian Gough
2001-11-29  1:08   ` Brian Gough
2001-12-19 13:20   ` Jonathan Leto
2001-12-01 18:46     ` Jonathan Leto
2001-12-19 13:20     ` Jonathan Leto
2001-12-19 13:20     ` Brian Gough
2001-12-03 15:28       ` Brian Gough
2001-12-19 13:20 ` Dan, Ho-Jin
2001-11-28 12:19   ` Dan, Ho-Jin
2001-12-19 13:20 ` Jonathan Leto
2002-12-31  9:55 Dherminder Kainth
2002-01-03  2:18 ` Dherminder Kainth
2002-12-31  9:55 ` Brian Gough
2002-01-05 11:37   ` Brian Gough

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20011201214553.A31518@leto.net \
    --to=jonathan@leto.net \
    --cc=gsl-discuss@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).