C routines for Special Functions

J

Joe Blow

Some heroes out there generously provide a tarball
(usually called "specfun.tar.gz") containing
routines that compute special functions like Gamma,
Confluent Hypergeometric, Struve, and other standard
and exotic beasts. I've found this collection in
Fortran77 and Matlab (see links below), but I've been
unable to locate the analogous routines written in C.
Does anyone know a link where I can get these routines
in C?

Here's some links for the interested:

Fortran77
http://iris-lee3.ece.uiuc.edu/~jjin/routines/routines.html

Matlab
http://ceta.mit.edu/comp_spec_func/

Much thanks,
JB
 
K

Keith A. Lewis

Some heroes out there generously provide a tarball
(usually called "specfun.tar.gz") containing
routines that compute special functions like Gamma,
Confluent Hypergeometric, Struve, and other standard
and exotic beasts. I've found this collection in
Fortran77 and Matlab (see links below), but I've been
unable to locate the analogous routines written in C.
Does anyone know a link where I can get these routines
in C?

Have a look at http://www.netlib.org/cephes/. GSL ties you into a number
of bad design decisions that make it clumsy to use.
 
A

Arthur J. O'Dwyer

Some heroes out there generously provide a tarball
(usually called "specfun.tar.gz") containing
routines that compute special functions like Gamma,
Confluent Hypergeometric, Struve, and other standard
and exotic beasts. I've found this collection in
Fortran77 and Matlab (see links below), but I've been
unable to locate the analogous routines written in C.
Does anyone know a link where I can get these routines
in C?

I did a Google search for
"Computation of Special Functions" C source
and found:
http://www.esg.dees.unict.it/esg/gborzi/mathlib.html
http://www.crbond.com/math.htm

But comp.lang.c is not comp.sources.wanted, so please take this
discussion elsewhere.

HTH,
-Arthur
 
B

beliavsky

Some heroes out there generously provide a tarball
(usually called "specfun.tar.gz") containing
routines that compute special functions like Gamma,
Confluent Hypergeometric, Struve, and other standard
and exotic beasts. I've found this collection in
Fortran77 and Matlab (see links below), but I've been
unable to locate the analogous routines written in C.
Does anyone know a link where I can get these routines
in C?

<SNIP>

Some sources of C code for special functions, the first two being the
most important, are

C Mathematical Function Handbook (1992)
by Louis Baker

Atlas for Computing Mathematical Functions: An Illustrated Guide for
Practitioners: With Programs in C and Mathematica (1997)
by William J. Thompson

A Numerical Library in C for Scientists and Engineers (1994)
by H. T. Lau

www.nr.com
Numerical Recipes in C, 2nd Edition (1992)
by Press, Flannery, Teukolsky, and Vetterling
 
K

Keith A. Lewis

Would you care to elaborate?

Of course this is just my opinion. I think the GSL group is doing
a great service and since the code is GPL I should really be rolling
up my sleeves and coding instead of complaining. :)

When the first example program in their documentation defines 'int
main(void) { ... }' you have to wonder a bit. Why the 'void'? It
is perfectly legal, just odd looking and unnecessary. When I was
evaluating this for use in a production library at a large Equity
Derivatives firm a couple of years ago, I kept finding 'odd' things.
Ultimately I chose a Fortran library because GSL was not sufficiently
mature at that time. It has definitely come a long way since then.

If you belive a modern library should be written in C instead of C++,
you can stop reading now. Many of my qualms are due to issues relating
to the gyrations GSL goes to because it does not use C++. I've taken
flak over the years for insisting on writing certain libraries in C (and
even more flak for using Fortran) but I have come to the conclusion that
the small audience that insists on C is, well, small. I'm open to data
indicating otherwise.

Error Handling

I'm not a fan of the 'int status = gsl_function(...); if (status)
{...' method of error handling for functions that return doubles.
I am especially not a fan of having default error handlers call
abort(), like the assert macro in C. Of course I've had the head
of IT tear me a new asshole when a programmer of mine left an assert
in production code that got called 15 minutes before market open,
so I can't claim to be unbiased.

GSL does have 'natural form' calling conventions available (more
code on their side to maintain) but they do not permit error
checking. I prefer returning NaN's that have embedded error
information. If you don't check the return codes, at least your
program is more likely to return gibberish than to crash.

Vector and Matrix Routines

They do a fine job, but I would love to see something more along
the lines of http://okmij.org/ftp/LinAlg.README.txt. I've tried out
every vector/matix library on the planet, I think, from BLAS and LAPACK
to the compiler busting Blitz++. Simple C++ wrappers for the former seem
to be the best solution for my needs.

General Comments

Excessive use of C macros in source code. Makes the code hard to
understand/fix/maintain.

Not modular. Dependencies between modules should be explicit.

At any rate, that's my 2 cents. Feel free to disagree, it's an internet
newsgroup after all. Comments are welcome.
 
J

Joe Blow

Arthur J. O'Dwyer said:
But comp.lang.c is not comp.sources.wanted, so please take this
discussion elsewhere.

HTH,
-Arthur


Ahh...blow it out yer arse, Arthur. I suppose
you're trying to deal a lesson in netiquette,
but the fact is that I'm interested in routines
written in the computational language of C, and
even if my fishing cast didn't meet your tight-assed
according-to-Hoyle criterion for a proper post to
this group, it's still obviously close enough. Guys
like you who enforce netiquette like Nazis are usually
the rudest bungholes on the web. Next time a simple
"you may get better information out of the
comp.sources.wanted group" will suffice. There's a
real netiquette lesson for you, Art old boy. Take
your jive netiquette advice elsewhere, ya bloody stickler.

JB
 
J

Joe Blow

Have a look at http://www.netlib.org/cephes/. GSL ties you into a number
of bad design decisions that make it clumsy to use.


Thanks for the link Keith...it's pretty useful. In
response to another poster, I am aware of the GSL
software. I avoid it when I can for a variety of reasons,
none of them particularly deep. I'll mention a couple of
things though. I don't like the cumbersome routine names
with gsl_blah_blah tacked onto everything in sight. It
makes for ugly code, in my opinion. Second, they'll have
things like the F-distribution, but no function for the
inverse of the F-distribution. Things like that are annoying...
GSL is incomplete for my purposes. Fortran and Matlab have
many free routines available for the special functions and I
just figured the same thing was out there for C, that's all.

By the way, from my brief perusal of this newsgroup, I must say
I'm stunned that so much time is spent by people bitching about
netiquette (for what seem usually to be rather innocent or trivial
breaches). Must be that programmer mentality at work...

Thanks again Keith,
JB
 
G

Gareth McCaughan

Keith said:
....
When the first example program in their documentation defines 'int
main(void) { ... }' you have to wonder a bit. Why the 'void'? It
is perfectly legal, just odd looking and unnecessary.

It would be unnecessary in C++, but not in C.
I'm not a fan of the 'int status = gsl_function(...); if (status)
{...' method of error handling for functions that return doubles.
I am especially not a fan of having default error handlers call
abort(), like the assert macro in C. Of course I've had the head
of IT tear me a new asshole when a programmer of mine left an assert
in production code that got called 15 minutes before market open,
so I can't claim to be unbiased.

GSL does have 'natural form' calling conventions available (more
code on their side to maintain) but they do not permit error
checking. I prefer returning NaN's that have embedded error
information. If you don't check the return codes, at least your
program is more likely to return gibberish than to crash.

It could be argued that it's better for your program
to crash than to return gibberish, especially if it's
because you haven't bothered to check for errors...
 
G

Gareth McCaughan

Keith said:
When the first example program in their documentation defines 'int
main(void) { ... }' you have to wonder a bit. Why the 'void'? It
is perfectly legal, just odd looking and unnecessary.

.... and I replied that in C, as opposed to C++, it is necessary.
That was an error; I apologize. It is unnecessary in C as well
as in C++. However, I don't think it's "odd looking" in C. After
all, when you're declaring but not defining a no-argument function
in C you have to[1] include the "void", so C programmers are
used to seeing no-argument functions with "(void)" for argument list.

[1] If you want the compiler to be able to check that
the function is being used properly, anyway.
 
C

CBFalconer

Joe said:
Ahh...blow it out yer arse, Arthur. I suppose
you're trying to deal a lesson in netiquette,
but the fact is that I'm interested in routines
written in the computational language of C, and
even if my fishing cast didn't meet your tight-assed
according-to-Hoyle criterion for a proper post to
this group, it's still obviously close enough. Guys
like you who enforce netiquette like Nazis are usually
the rudest bungholes on the web. Next time a simple
"you may get better information out of the
comp.sources.wanted group" will suffice. There's a
real netiquette lesson for you, Art old boy. Take
your jive netiquette advice elsewhere, ya bloody stickler.

Your crudity is only exceeded by Arthurs politeness. He was also
succint, which you were not. Your attitude will probably be
remembered when you have something on topic to discuss or request
help with.
 
B

Brian Gough

Of course this is just my opinion. I think the GSL group is doing
a great service and since the code is GPL I should really be rolling
up my sleeves and coding instead of complaining. :)

When the first example program in their documentation defines 'int
main(void) { ... }' you have to wonder a bit. Why the 'void'?
It is perfectly legal, just odd looking and unnecessary.

Hmmm, odd looking and unnecessary and ... part of the C standard ;-)
e.g. see ANSI/ISO/IEC 9899:1990 section 5.1.2.2.1 for "int main(void)"
If you belive a modern library should be written in C instead of C++,
you can stop reading now.

Fair enough. It's a GNU project so the main reason we used C is
because of the GNU coding standards (which specify that C be used
where possible). At the time GSL was started (over seven years ago)
C++ techniques such as template metaexpressions and traits were just
being developed. I am still waiting to see a good general numerical
library in C++ however.

(We recommend using C with a very high-level object oriented language
such as Lisp or Python.)
I'm not a fan of the 'int status = gsl_function(...); if (status)
{...' method of error handling for functions that return doubles.

I'm not a particular fan of it either, but it is the conventional way
to handle it in C. We worked on a very flexible dynamically-scoped
error context system for a while but it was not popular.
I am especially not a fan of having default error handlers call
abort(), like the assert macro in C.

Without the abort() on error default we had many users blithely
ignoring errors and complaining that GSL was producing incorrect
results. So we had to make abort() the default.

It is done with a single configurable gsl_error() function so it can
be changed globally.
GSL does have 'natural form' calling conventions available (more
code on their side to maintain) but they do not permit error
checking.

These should return NaN/Inf for error/overflow conditions (if there
are any that don't, it is bug).
I prefer returning NaN's that have embedded error information.

We have to be portable so this is not really an option for a core
feature (?).
Excessive use of C macros in source code. Makes the code hard to
understand/fix/maintain.

I agree the macros for the implementation of the different types of
vectors and matrices are inelegant. Possibly it would be better to
use a scripting language or m4 to generate the code, rather than cpp.
Not modular. Dependencies between modules should be explicit.

Tried, but turns out to be difficult in practice (originally all
modules were independent) and users seem not particularly interested.

Probably one could write a script to determine the dependencies
automatically, from the source, #includes or the .a file.
At any rate, that's my 2 cents. Feel free to disagree, it's an internet
newsgroup after all. Comments are welcome.

I would say that we did have to make some design decisions, but
hopefully they are not intrinsically bad, just a question of not being
able to please all of the people all of the time.

regards
--
Brian Gough
(GSL Maintainer)

Network Theory Ltd
http://www.network-theory.co.uk/
 
P

Peter Nilsson

[f'ups to comp.lang.c]

Brian Gough said:
Hmmm, odd looking and unnecessary and ... part of the C standard ;-)
e.g. see ANSI/ISO/IEC 9899:1990 section 5.1.2.2.1 for "int main(void)"

More so, C99 has deprecated ()...

6.11.6 Function declarators
The use of function declarators with empty parentheses (not prototype-
format parameter type declarators) is an obsolescent feature.
 
J

Joe Blow

CBFalconer said:
Your crudity is only exceeded by Arthurs politeness. He was also
succint, which you were not. Your attitude will probably be
remembered when you have something on topic to discuss or request
help with.


Hah! Like I'd ever ask this group anything again. This
newsgroup has been absolutely useless, far more interested
in ridiculous netiquette issues than anything else. That succinct
enough for ya?
 
S

Sidney Cadot

Joe said:
Hah! Like I'd ever ask this group anything again. This
newsgroup has been absolutely useless, far more interested
in ridiculous netiquette issues than anything else. That succinct
enough for ya?

<OT>

As a non-native speaker of american-english, this leaves me to wonder:
when you want to come across real forceful and convincing, is that the
time where the spelling of "you" changes to "ya", or is there something
deeper that I'm missing?

Best regards,

Sidney
 
J

Joona I Palaste

Sidney Cadot said:
As a non-native speaker of american-english, this leaves me to wonder:
when you want to come across real forceful and convincing, is that the
time where the spelling of "you" changes to "ya", or is there something
deeper that I'm missing?

Maybe it's the native speaker equivalent of the non-native speaker use
of "u"?
<g, d & r>

--
/-- Joona Palaste ([email protected]) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"I said 'play as you've never played before', not 'play as IF you've never
played before'!"
- Andy Capp
 
M

Morris Dovey

Sidney said:
<OT>

As a non-native speaker of american-english, this leaves me to wonder:
when you want to come across real forceful and convincing, is that the
time where the spelling of "you" changes to "ya", or is there something
deeper that I'm missing?

No. That kind of affectation is normally employed when the
speaker/writer wishes to communicate loss of self-control and the
onset of uncivilized/subhuman behaviors.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top