• Why no complex ERF intrinsic?

    From Al Greynolds@21:1/5 to All on Tue Oct 19 06:53:49 2021
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From gah4@21:1/5 to Al Greynolds on Tue Oct 19 23:21:13 2021
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Arjen Markus@21:1/5 to All on Wed Oct 20 00:33:35 2021
    On Wednesday, October 20, 2021 at 8:21:15 AM UTC+2, gah4 wrote:
    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.

    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From gah4@21:1/5 to arjen.m...@gmail.com on Wed Oct 20 02:49:31 2021
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Arjen Markus@21:1/5 to All on Wed Oct 20 04:46:39 2021
    On Wednesday, October 20, 2021 at 11:49:32 AM UTC+2, gah4 wrote:
    On Wednesday, October 20, 2021 at 12:33:37 AM UTC-7, arjen 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.
    Hm, might be a nice addition for the Fortran stdlib, as it is being developed at https://github.com/fortran-lang/stdlib/.

    Regards,

    Arjen

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Rudi Gaelzer@21:1/5 to Al Greynolds on Wed Oct 20 06:24:28 2021
    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/

    On Tuesday, October 19, 2021 at 10:53:51 AM UTC-3, 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. 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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From gah4@21:1/5 to Al Greynolds on Wed Oct 20 08:09:48 2021
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From gah4@21:1/5 to Al Greynolds on Thu Oct 21 01:14:26 2021
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)