-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
List of special mathematical functions to include #179
Comments
Indeed, this document looks like a nice starting point. Would this go to I suppose many of these functions could be adapted from the following sources:
Also the scipy.special module gives references to many of these older codes. |
Do we know why it was rejected? Maybe the author(s) of this proposal has/have already some implementations that could be integrated in |
It was @vansnyder's proposal. Van, do you know why it was rejected? |
I don't remember why it was rejected. It was eleven years ago.
Might have been as simple as "We don't like optional parts of the
standard. The first two didn't do anything useful."
…On Tue, 2020-05-05 at 13:13 -0700, Ondřej Čertík wrote:
It was @vansnyder's proposal. Van, do you know why it was rejected?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
JPL Math77 is now available without license from netlib. |
I've revised my 2009 proposal to correspond to Fortran 2020. ISO doesn't allow the kind of revision suffix that J3 allows, but I did it anyway. I just can't ask Steve to put it on the WG5 server with that number. I think the stdlib should be packaged in modules, each one a coherent set of related procedures (and types and constants). These should ultimately all be described in a consistent style, as an optional part of the standard. Procedures should be described in the same format as in subclause 16.9 of part 1 of the standard. Constants and opaque types can be described as in subclause 16.10. Types that have public components and bindings could be described by a type definition that shows only type parameters, and the public components and bindings. Type-bound procedures should be described as in subclause 16.9. |
Thanks @vansnyder for the updated document. Yes, that is our goal to have stdlib organized as modules with coherent set of procedures and documented in a Standard compatible way. Thanks for the tips how to do that. |
I've found this post from 2017 on Julia Discourse by Steven Johnson, where he comments on the implementation of special functions in Fortran vs Julia:
While I don't think we should focus strongly on optimization to begin with, it would be interesting to see if we can do something similar with fypp. |
@ivan-pi nice find. Initially indeed we should focus on functionality, but later our goal should definitely be to be as fast or faster than Julia. It might be a nice benchmark for Flang and LFortran also. |
As my weekend project, I had a go at implementing Horner's algorithm with fypp (see mentioned issue aradi/fypp#8). This way polynomials can be efficiently inlined. The syntax looks like
and gets expanded into
There is still some space for improvement with respect to the preprocessor syntax. I've implemented the inverse error function using the Horner macro. The expanded code is:
Edit: there was an error in my erfinv version near the ends of the domain (-1,1), that I've now replaced. Swapping axes to compare with the error function in gnuplot I can see the code works correctly: |
On Sun, 2020-06-21 at 13:33 -0700, Ivan wrote:
Swapping axes to compare with the error function in gnuplot I can see
the code works correctly:
This is reassuring, but wouldn't be adequate justification to publish
in a professional journal.
For mathematical function testing, one method uses a higher-precision
reference that is computed using a different algorithm, that can be
implemented in a transparently-correct way. Run the function, and the
reference, using randomly-selected values in thousands or millions of
little boxes, over the range of applicability (or several sub ranges).
Then tabulate the fraction that are correct within 1/2 unit in the last
position (ULP), 1 ULP, 2 ULP, ....
For inverses, such as ERF and ERFINV, one can compute and tabulate
ERF(ERFINV(X)) - X, using a higher-precision and previously-verified
version of ERF.
When implementing a published approximation, not verifying that the
approximation computes the desired function, testing would verify that
you've correctly transcribed the constants. Errors other than the most
egregious ones wouldn't be visible on a plot.
|
Curious. Did you time your example against any intrinsics? |
Thanks @vansnyder for the suggestions. After tabulating the error, I found the precision dropped slightly in one of the intervals. I replaced the code above now with some slightly more accuracte coefficients. After tabulating ERF(ERFINV(X)) - X (calculated in double precision) over the range (-0.995,0.995), the error does not exceed
Not yet. I went down the rabbit-hole so to say, and started designing some benchmarking macros similar to those in BenchmarkTools.jl. For comparison, the inverse error function is available in
|
On comp.lang.fortran Al Greynolds asked Why no complex ERF intrinsic? and @arjenmarkus mentioned that it is a candidate for stdlib. |
On Mon, 2021-10-25 at 07:52 -0700, Beliavsky wrote:
On comp.lang.fortran Al Greynolds asked Why no complex ERF intrinsic?
and @arjenmarkus mentioned that it is a candidate for stdlib.
Depending upon your requirements for speed as opposed to precision,
there are at several candidates:
* G. P. M. Poppe and C. M. J. Wijers, More efficient computation of
the complex error function, ACM Transcations on Mathematical
Software 16, 1 (March 1990) pp 38-46, and its companion G. P. M.
Poppe and C. M. J. Wijers, and Algorithm 690: Evaluation of the
complex error function, same issue. Good for 14 digits. Fortran.
* Mofreh R. Zaghloul and Ahmen N. Ali, Algorithm 916: Computing the
Faddeyeva and Voigt functions, ACM Transcations on Mathematical
Software 38, 2 (December 2011) Article 15. Adjustable precision,
faster than Poppe and Wijers. Matlab and Fortran.
* Mofreh R. Zaghloul, Algorithm 985: Simple, efficient, and relatively
accurate approximation for the evaluation of the Faddeyeva
function, ACM Transcations on Mathematical Software 44, 2 (October
2017) Article 22. Very fast, but only five digits.
There are older algorithms by Gautschi, Weideman, Hui,Humlíček, and
others, which all have defects explained by Zaghloul the December
2011 article.
1.
|
@vansnyder on your 2.3 line 24, I can easily see someone's designing hardware for spherical harmonics for geoid models, so having an intrinsic for code-gen is not too far-fetched. (Hi, Van, yes, it's the same Brian Beckman from 40 years ago at JPL and Earth models in MASTERFIT :) |
Here is a paper from 2007 that was submitted to the Fortran Committee, but ultimately rejected:
https://wg5-fortran.org/N1651-N1700/N1688.pdf
The functions there seem to be exactly in the scope of stdlib, so we should include them and we can use this paper as a starting point.
The text was updated successfully, but these errors were encountered: