Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Why no complex ERF intrinsic?

187 views
Skip to first unread message

Al Greynolds

unread,
Oct 19, 2021, 9:53:51 AM10/19/21
to
For a simulation I needed the complex Fresnel Integral which can be simply related to an error function with a complex argument. Checking the Fortran 2018 standard I was surprised it only allowed real arguments for ERF. More surprising I found that the plotting package I use with my Fortran codes, the venerable Gnuplot, does support a complex CERF, e.g. a Cornu spiral plot:

fresnel(x) = {1.,1.}*cerf(sqrt(pi)*{1.,-1.}*x/2.)/2.
set parametric
unset key
set samples 1000
plot real(fresnel(t)),imag(fresnel(t))

Didn't check to see how many other useful Fortran math intrinsics only support real and not complex arguments. I'm sure in some cases it doesn't make sense, but not in this one.

Al

gah4

unread,
Oct 20, 2021, 2:21:15 AM10/20/21
to
On Tuesday, October 19, 2021 at 6:53:51 AM UTC-7, Al Greynolds wrote:

(snip)
> Didn't check to see how many other useful Fortran math intrinsics only support
> real and not complex arguments. I'm sure in some cases it doesn't make sense,
> but not in this one.

Going down the list, it seems that the BESSEL functions, GAMMA,
LOG_GAMMA, LOG10, and NORM2.

As far as I know, all are defined for complex values.

Arjen Markus

unread,
Oct 20, 2021, 3:33:37 AM10/20/21
to
One reason I can think of for this lack of support is that complex functions add, well, a complication that is not easily solved: branch cuts. Of course there are conventions for most of these functions that you could adhere to, but doing so is less than trivial (see for instance the article by Anton Shterenlikht in the Fortran Forum a few years ago) and the features are probably of importance to a small group of programmers only. (I do not claim any empirical insight in the cost/benefit ratio, merely my intuition).

Regards,

Arjen

gah4

unread,
Oct 20, 2021, 5:49:32 AM10/20/21
to
On Wednesday, October 20, 2021 at 12:33:37 AM UTC-7, arjen.m...@gmail.com wrote:

(snip)

> One reason I can think of for this lack of support is that complex functions add,
> well, a complication that is not easily solved: branch cuts.
> Of course there are conventions for most of these functions that you could
> adhere to, but doing so is less than trivial (see for instance the article by Anton
> Shterenlikht in the Fortran Forum a few years ago) and the features are probably
> of importance to a small group of programmers only.

It seems that gamma is well defined for complex values, other than non-positive
integers.

https://en.wikipedia.org/wiki/Gamma_function

As for erf(z), from: https://en.wikipedia.org/wiki/Error_function
it seems also to be defined for complex values.

It mentions libcerf, which is a broken link, but then:

http://ab-initio.mit.edu/wiki/index.php/Faddeeva_Package

which seems to be C++ with a C wrapper, so should be callable from Fortran.

Arjen Markus

unread,
Oct 20, 2021, 7:46:41 AM10/20/21
to
On Wednesday, October 20, 2021 at 11:49:32 AM UTC+2, gah4 wrote:
Hm, might be a nice addition for the Fortran stdlib, as it is being developed at https://github.com/fortran-lang/stdlib/.

Regards,

Arjen

Rudi Gaelzer

unread,
Oct 20, 2021, 9:24:30 AM10/20/21
to
The error function is an entire function, so there is a priori reason for the absence of a standard implementation, other than possibly the limited time available to the programmers that maintain the (standard) library of intrinsic functions.
I usually employ the dcerf.f90 function you can download from Alan Miller's repository: https://jblevins.org/mirror/amiller/

gah4

unread,
Oct 20, 2021, 11:09:51 AM10/20/21
to
On Tuesday, October 19, 2021 at 6:53:51 AM UTC-7, Al Greynolds wrote:
> For a simulation I needed the complex Fresnel Integral which can be simply related
> to an error function with a complex argument.

I have the book "Computation of Special Functions" by Zhang and Jin, that I got
on eBay some years ago.

I was looking for something else, and accidentally found it, maybe in other
items from the same seller. (If I remember, I also bought a tie with pictures
of xenon arc lamps on it, at about that time.)

The price was about $30, which seemed a good deal at the time.

The examples seem to be in, more or less, Fortran 77.
Maybe VAX Fortran, which might have been popular about that time.

It does have a COMPLEX*16 erf().

One that it does have, and that I was using about that time, is elliptic
integrals, which might have been the reason to buy one.

gah4

unread,
Oct 21, 2021, 4:14:28 AM10/21/21
to
On Tuesday, October 19, 2021 at 6:53:51 AM UTC-7, Al Greynolds wrote:
> For a simulation I needed the complex Fresnel Integral which can be simply related
> to an error function with a complex argument. Checking the Fortran 2018 standard
> I was surprised it only allowed real arguments for ERF.

There is also libcerf:

https://jugit.fz-juelich.de/mlz/libcerf

which includes Fortran binding.
0 new messages