comp.lang.ada
 help / color / mirror / Atom feed
From: Jerry <list_email@icloud.com>
Subject: Re: Any good package for mathematical function in Ada?
Date: Sun, 31 May 2020 16:25:31 -0700 (PDT)
Date: 2020-05-31T16:25:31-07:00	[thread overview]
Message-ID: <e1f13cec-7398-4bd1-a856-5e5a8107b669@googlegroups.com> (raw)
In-Reply-To: <45af26dc-c35f-4a01-8115-7b30021cc064@googlegroups.com>

On Sunday, May 31, 2020 at 3:46:47 AM UTC-7, reinert wrote:
> Hello,
> 
> I would like to use for example the bessel function from Ada.
> I need in case to program it from scratch?
> 
> Any hint?
> 
> reinert

You have hit on what, for me, is a PITA for Ada, generally speaking, and that is a lack of broad numerical functions.

You can link to the GNU Scientific Library (GSL) or the Octave binary library (I have also once written a very simple special-case Octave code generator to run interpreter code since some functionality is not available as compiled code). You might also enjoy ALGLIB, IMSL, NAG, and NetLib depending on the licenses. You might be able to link to the Python libraries scipy and numpy if, as I _suppose_ ,they are written in C. Consult this list if you like: 

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

BTW if you have access to Numerical Recipes it can be a lifesaver sometimes. I have an early book with Pascal code in an appendix.

If the binary you are linking to is in C or Fortran your job as an Ada programmer isn't too bad but if you have never done it, it will take you a while to figure it out. Just remember that Ada is built to do this. I did a complete thick binding for PLplot a few years ago. It was lot of work to make it Ada-friendly but in large part because I didn't know C. And in a smaller part because it seems that programming in a crappy language spawns crappy programming techniques. Some of the things C programmers do are abominable and not required by the language. Sorry for the OT rant.

I just remembered that I did this (Bessel) for GSL--I'm on a Mac and I got GSL via MacPorts. Note well that you don't have to link to the whole library, only the function(s) that you need. I'll paste the Ada with my comments which might be superfluous for you, and a gpr file as well; the gpr is included in a larger gpr.

I really wish Ada had a good binding to at least one of these libraries.

Jerry


library project GSL_Library is
	for Externally_Built use "true";
	for Library_Dir use "/opt/local/lib/";
    for Library_Name use "gsl"; -- Delete "lib" from front of file name, .dylib from end.
	for Library_Kind use "dynamic";
end GSL_Library;




-- Partial Ada binding to the GNU Scientific Library aka GSL library, libgsl.dylib.
-- See http://www.gnu.org/software/gsl/.
-- Use $nm library_name | grep symbol_name to find if symbol_name is in a library.
-- This binding will be developed as needed. See build.gpr and GSL_Library.gpr.
-- Consider this binding as an adjunct to e.g. Octave binding and Numerical Recipes.

package GSL_Thin is
    
    ---------------------------------------------------------------------------
    --  CHAPTER 7: SPECIAL FUNCTIONS                                         --
    ---------------------------------------------------------------------------
    
    -- See GSL Reference 7.3 about modes. _Apparently_ double precision is the default and no
    -- mode flag (argument) is necessary. The Reference could be less ambiguous about this.

    -- Regular cylindrical Bessel function of zeroth order, J_0(x).
    function gsl_sf_bessel_J0(x : Long_Float) return Long_Float;
    pragma Import(C, gsl_sf_bessel_J0, "gsl_sf_bessel_J0");
    
    -- Complete elliptical integral of the first kind, K(k). GSL Reference 7.13.3.
    -- Mathematica EllipticK and Abramowitz & Stegun 17.3 use argument m = k^2.
    -- As far as I can tell, this returns correct results only for 0 < k < 1, and then only if
    -- sqrt(k) is given as the argument. I have contacted the list (April, 2015) about this and got
    -- no response. I am using this for the PDF of the sum of two unit-amplitude sine random
    -- variables where this limitation is not a problem. Otherwise, I don't see how to use this to
    -- get results such as returned by A&S or Octave. (The Octave function is coded as Octave code,
    -- not a compiled library.)
    function gsl_sf_ellint_Kcomp(k : Long_Float) return Long_Float;
    pragma Import(C, gsl_sf_ellint_Kcomp, "gsl_sf_ellint_Kcomp");
    
end GSL_Thin;

  parent reply	other threads:[~2020-05-31 23:25 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-31 10:46 Any good package for mathematical function in Ada? reinert
2020-05-31 11:26 ` Dmitry A. Kazakov
2020-06-01  8:17   ` reinert
2020-05-31 23:25 ` Jerry [this message]
2020-06-01  8:24   ` reinert
2020-06-01 10:19     ` Dmitry A. Kazakov
2020-06-01 10:48       ` Nasser M. Abbasi
2020-06-01 11:34         ` Dmitry A. Kazakov
2020-06-01 11:52           ` Nasser M. Abbasi
2020-06-01 13:37             ` Dmitry A. Kazakov
2020-06-02  1:48             ` Jerry
2020-06-05 22:49           ` Randy Brukardt
2020-06-05 22:54           ` Paul Rubin
2020-06-06  7:06             ` Dmitry A. Kazakov
2020-06-06 13:58               ` AdaMagica
2020-06-01 10:43   ` Dmitry A. Kazakov
2020-06-02  1:51     ` Jerry
2020-06-03 15:07     ` reinert
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox