comp.lang.ada
 help / color / mirror / Atom feed
* Any good package for mathematical function in Ada?
@ 2020-05-31 10:46 reinert
  2020-05-31 11:26 ` Dmitry A. Kazakov
  2020-05-31 23:25 ` Jerry
  0 siblings, 2 replies; 18+ messages in thread
From: reinert @ 2020-05-31 10:46 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Any good package for mathematical function in Ada?
  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
  1 sibling, 1 reply; 18+ messages in thread
From: Dmitry A. Kazakov @ 2020-05-31 11:26 UTC (permalink / raw)


On 31/05/2020 12:46, reinert wrote:

> I would like to use for example the bessel function from Ada.

Do you mean something concrete? I don't remember how many dozens Bessel 
functions and integrals exist. You need all of them?

> I need in case to program it from scratch?

That depends on the approximation method, of which there are lots. 
Something universal, well, if you have coefficients of Chebyshev series 
e.g. from

https://www.amazon.com/Special-Functions-Their-Approximations/dp/0124110371

I have an Ada implementation for:

http://www.dmitry-kazakov.de/ada/components.htm#15.2

> Any hint?

If you need something concrete and frequently used, you certainly could 
find a library and use it. Ada bindings to a mathematical library is a 
matter of minutes to do.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Any good package for mathematical function in Ada?
  2020-05-31 10:46 Any good package for mathematical function in Ada? reinert
  2020-05-31 11:26 ` Dmitry A. Kazakov
@ 2020-05-31 23:25 ` Jerry
  2020-06-01  8:24   ` reinert
  2020-06-01 10:43   ` Dmitry A. Kazakov
  1 sibling, 2 replies; 18+ messages in thread
From: Jerry @ 2020-05-31 23:25 UTC (permalink / raw)


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;

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Any good package for mathematical function in Ada?
  2020-05-31 11:26 ` Dmitry A. Kazakov
@ 2020-06-01  8:17   ` reinert
  0 siblings, 0 replies; 18+ messages in thread
From: reinert @ 2020-06-01  8:17 UTC (permalink / raw)


søndag 31. mai 2020 13.26.40 UTC+2 skrev Dmitry A. Kazakov følgende:

> If you need something concrete and frequently used, you certainly could 
> find a library and use it. Ada bindings to a mathematical library is a 
> matter of minutes to do.
> 

Bessel functions are just an example for what I am looking for. Now I just reinvented the wheel and wrote the code for the modified Bessel function of order 0 :-)  OK, a bit waste of time but programming is also a way to understand.

reinert



reinert

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Any good package for mathematical function in Ada?
  2020-05-31 23:25 ` Jerry
@ 2020-06-01  8:24   ` reinert
  2020-06-01 10:19     ` Dmitry A. Kazakov
  2020-06-01 10:43   ` Dmitry A. Kazakov
  1 sibling, 1 reply; 18+ messages in thread
From: reinert @ 2020-06-01  8:24 UTC (permalink / raw)


Thanks for the hints,

Anybody having a simple (complete - runable) code example using GSL from Ada?

reinert

mandag 1. juni 2020 01.25.32 UTC+2 skrev Jerry følgende:
> 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;

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Any good package for mathematical function in Ada?
  2020-06-01  8:24   ` reinert
@ 2020-06-01 10:19     ` Dmitry A. Kazakov
  2020-06-01 10:48       ` Nasser M. Abbasi
  0 siblings, 1 reply; 18+ messages in thread
From: Dmitry A. Kazakov @ 2020-06-01 10:19 UTC (permalink / raw)


On 01/06/2020 10:24, reinert wrote:

> Anybody having a simple (complete - runable) code example using GSL from Ada?

Assuming Windows.

Install MSYS2 if you did not already. [64-bit, GNAT GPL is not available 
for 32-bit anymore.]

Install GSL mingw-w64-x86_64-gsl under MSYS.

Now, assuming that MSYS2 is under C:\MSYS64\MinGW, here you go:

---gsl.gpr--------------
project GSL is
    for Main use ("test.adb");

    package Linker is
       for Default_Switches ("ada")
          use ("-L/c/msys64/mingw/lib", "-lgsl");
    end Linker;

end GSL;

---gsl.ads-------------
with Interfaces.C;  use Interfaces.C;

package GSL is
   function Bessel_J0 (X : double) return double;

private
    pragma Import (C, Bessel_J0, "gsl_sf_bessel_J0");
end GSL;

---test.adb------------>
with Ada.Text_IO;   use Ada.Text_IO;
with GSL;           use GSL;
with Interfaces.C;  use Interfaces.C;

procedure Test is
begin
    Put_Line ("J0(1)=" & double'Image (Bessel_J0 (1.0)));
end Test;
-----------------------

The test produces:

J0(1)= 7.65197686557967E-01

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Any good package for mathematical function in Ada?
  2020-05-31 23:25 ` Jerry
  2020-06-01  8:24   ` reinert
@ 2020-06-01 10:43   ` Dmitry A. Kazakov
  2020-06-02  1:51     ` Jerry
  2020-06-03 15:07     ` reinert
  1 sibling, 2 replies; 18+ messages in thread
From: Dmitry A. Kazakov @ 2020-06-01 10:43 UTC (permalink / raw)


On 01/06/2020 01:25, Jerry wrote:

> 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.

That is true.

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

Yes, but it is a lot of work and maintenance. And with mathematical 
functions good binding should take advantage of Ada subtypes, e.g. when 
the documentation says X > 0 and then uses double!

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Any good package for mathematical function in Ada?
  2020-06-01 10:19     ` Dmitry A. Kazakov
@ 2020-06-01 10:48       ` Nasser M. Abbasi
  2020-06-01 11:34         ` Dmitry A. Kazakov
  0 siblings, 1 reply; 18+ messages in thread
From: Nasser M. Abbasi @ 2020-06-01 10:48 UTC (permalink / raw)


On 6/1/2020 5:19 AM, Dmitry A. Kazakov wrote:

> The test produces:
> 
> J0(1)= 7.65197686557967E-01
> 

That is good. In Mathematica

N[BesselJ[0, 1], 100]

0.76519768655796655144971752610266322090927428975532524186154754911927\
89122152724401671806000989156340

In Maple

Digits:=100;
                          Digits := 100
evalf(BesselJ(0,1))
0.76519768655796655144971752610266322090927428975532524186154754911927\
89122152724401671806000989156340

Want 1,000 digits? 2,000 digits? all can be done.

I think these systems both link to GMP "GNU Multiple Precision Arithmetic Library"
for this. "There are no practical limits to the precision "
https://en.wikipedia.org/wiki/GNU_Multiple_Precision_Arithmetic_Library

https://www.wolfram.com/legal/third-party-licenses/gmp.html


--Nasser


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Any good package for mathematical function in Ada?
  2020-06-01 10:48       ` Nasser M. Abbasi
@ 2020-06-01 11:34         ` Dmitry A. Kazakov
  2020-06-01 11:52           ` Nasser M. Abbasi
                             ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Dmitry A. Kazakov @ 2020-06-01 11:34 UTC (permalink / raw)


On 01/06/2020 12:48, Nasser M. Abbasi wrote:
> On 6/1/2020 5:19 AM, Dmitry A. Kazakov wrote:
> 
>> The test produces:
>>
>> J0(1)= 7.65197686557967E-01
> 
> That is good. In Mathematica
> 
> N[BesselJ[0, 1], 100]
> 
> 0.76519768655796655144971752610266322090927428975532524186154754911927\
> 89122152724401671806000989156340
> 
> In Maple
> 
> Digits:=100;
>                           Digits := 100
> evalf(BesselJ(0,1))
> 0.76519768655796655144971752610266322090927428975532524186154754911927\
> 89122152724401671806000989156340
> 
> Want 1,000 digits? 2,000 digits? all can be done.

In how many microseconds?

> I think these systems both link to GMP "GNU Multiple Precision 
> Arithmetic Library"
> for this. "There are no practical limits to the precision "
> https://en.wikipedia.org/wiki/GNU_Multiple_Precision_Arithmetic_Library

There is no best numerical library as requirements greatly vary. One 
would probably never want to use multiple precision arithmetic in 
production code. Less improbable, but still, in laboratory computations 
when other factors control precision.

As for GMP specifically, I think that arbitrary precision numeric types 
must be an integral part of Ada. Unfortunately, this would introduce 
same mess Unbounded_String did. So, for now, I would not push for them 
until the language type system mature to accommodate them smoothly.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Any good package for mathematical function in Ada?
  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
  2 siblings, 2 replies; 18+ messages in thread
From: Nasser M. Abbasi @ 2020-06-01 11:52 UTC (permalink / raw)


On 6/1/2020 6:34 AM, Dmitry A. Kazakov wrote:
89122152724401671806000989156340
>>
>> Want 1,000 digits? 2,000 digits? all can be done.
> 
> In how many microseconds?
> 

In my PC, intel i-7-8086K CPU, 4 GHZ, it takes 6.2*10^-7 second
for 20,000 digits (I put ";" to prevent the 20,000 digits from
being printed on screen)

In[20]:= RepeatedTiming[N[BesselJ[0,1],20000];]
Out[20]= {6.2*10^-7,Null}

"RepeatedTiming[expr] evaluates expr repeatedly and returns a list of
the average time in seconds used, together with the result obtained.
"

>> I think these systems both link to GMP "GNU Multiple Precision
>> Arithmetic Library"
>> for this. "There are no practical limits to the precision "
>> https://en.wikipedia.org/wiki/GNU_Multiple_Precision_Arithmetic_Library
> 
> There is no best numerical library as requirements greatly vary. One
> would probably never want to use multiple precision arithmetic in
> production code. Less improbable, but still, in laboratory computations
> when other factors control precision.
> 
> As for GMP specifically, I think that arbitrary precision numeric types
> must be an integral part of Ada. Unfortunately, this would introduce
> same mess Unbounded_String did. So, for now, I would not push for them
> until the language type system mature to accommodate them smoothly.
> 

Best,
--Nasser

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Any good package for mathematical function in Ada?
  2020-06-01 11:52           ` Nasser M. Abbasi
@ 2020-06-01 13:37             ` Dmitry A. Kazakov
  2020-06-02  1:48             ` Jerry
  1 sibling, 0 replies; 18+ messages in thread
From: Dmitry A. Kazakov @ 2020-06-01 13:37 UTC (permalink / raw)


On 01/06/2020 13:52, Nasser M. Abbasi wrote:
> On 6/1/2020 6:34 AM, Dmitry A. Kazakov wrote:
> 89122152724401671806000989156340
>>>
>>> Want 1,000 digits? 2,000 digits? all can be done.
>>
>> In how many microseconds?
> 
> In my PC, intel i-7-8086K CPU, 4 GHZ, it takes 6.2*10^-7 second
> for 20,000 digits (I put ";" to prevent the 20,000 digits from
> being printed on screen)
> 
> In[20]:= RepeatedTiming[N[BesselJ[0,1],20000];]
> Out[20]= {6.2*10^-7,Null}
> 
> "RepeatedTiming[expr] evaluates expr repeatedly and returns a list of
> the average time in seconds used, together with the result obtained.
> "

It looks too good, though I do not know the method used.

As a reference, GSL takess 34ns on a bit faster i9 machine.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Any good package for mathematical function in Ada?
  2020-06-01 11:52           ` Nasser M. Abbasi
  2020-06-01 13:37             ` Dmitry A. Kazakov
@ 2020-06-02  1:48             ` Jerry
  1 sibling, 0 replies; 18+ messages in thread
From: Jerry @ 2020-06-02  1:48 UTC (permalink / raw)


On Monday, June 1, 2020 at 4:52:20 AM UTC-7, Nasser M. Abbasi wrote:

> In[20]:= RepeatedTiming[N[BesselJ[0,1],20000];]
> Out[20]= {6.2*10^-7,Null}
> --Nasser

That's faster than looking it up in Abramowitz and Stegun!

Jerry

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Any good package for mathematical function in Ada?
  2020-06-01 10:43   ` Dmitry A. Kazakov
@ 2020-06-02  1:51     ` Jerry
  2020-06-03 15:07     ` reinert
  1 sibling, 0 replies; 18+ messages in thread
From: Jerry @ 2020-06-02  1:51 UTC (permalink / raw)


On Monday, June 1, 2020 at 3:43:04 AM UTC-7, Dmitry A. Kazakov wrote:
> On 01/06/2020 01:25, Jerry wrote:

> > I really wish Ada had a good binding to at least one of these libraries.
> 
> Yes, but it is a lot of work and maintenance. And with mathematical 
> functions good binding should take advantage of Ada subtypes, e.g. when 
> the documentation says X > 0 and then uses double!
> 
> Dmitry A. Kazakov

If the original library is broad and assuming new mathematical functions aren't invented too often, I think maintenance might not be too bad.

Jerry

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Any good package for mathematical function in Ada?
  2020-06-01 10:43   ` Dmitry A. Kazakov
  2020-06-02  1:51     ` Jerry
@ 2020-06-03 15:07     ` reinert
  1 sibling, 0 replies; 18+ messages in thread
From: reinert @ 2020-06-03 15:07 UTC (permalink / raw)


mandag 1. juni 2020 12.43.04 UTC+2 skrev Dmitry A. Kazakov følgende:
> On 01/06/2020 01:25, Jerry wrote:
> 
> > 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.
> 
> That is true.
> 
> > I really wish Ada had a good binding to at least one of these libraries.
> 
> Yes, but it is a lot of work and maintenance. And with mathematical 
> functions good binding should take advantage of Ada subtypes, e.g. when 
> the documentation says X > 0 and then uses double!
> 
> -- 
> Regards,
> Dmitry A. Kazakov
> http://www.dmitry-kazakov.de

Thanks, I will try it out (on linux)

reinert

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Any good package for mathematical function in Ada?
  2020-06-01 11:34         ` Dmitry A. Kazakov
  2020-06-01 11:52           ` Nasser M. Abbasi
@ 2020-06-05 22:49           ` Randy Brukardt
  2020-06-05 22:54           ` Paul Rubin
  2 siblings, 0 replies; 18+ messages in thread
From: Randy Brukardt @ 2020-06-05 22:49 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
news:rb2p52$qvl$1@gioia.aioe.org...
...
> As for GMP specifically, I think that arbitrary precision numeric types 
> must be an integral part of Ada. Unfortunately, this would introduce same 
> mess Unbounded_String did. So, for now, I would not push for them until 
> the language type system mature to accommodate them smoothly.

You're a little late for that. See Big_Integer:

http://www.ada-auth.org/standards/2xrm/html/RM-A-5-6.html

and Big_Real:

http://www.ada-auth.org/standards/2xrm/html/RM-A-5-7.html

Since Ada 202x has user-defined literals and user-defined Image, this is 
almost as good as a built-in number. The only downside would be using them 
in generics (like GEF), but most of those implementations assume a maximum 
precision that's not true for these so they'd need rewriting anyway.

                           Randy.


^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Any good package for mathematical function in Ada?
  2020-06-01 11:34         ` Dmitry A. Kazakov
  2020-06-01 11:52           ` Nasser M. Abbasi
  2020-06-05 22:49           ` Randy Brukardt
@ 2020-06-05 22:54           ` Paul Rubin
  2020-06-06  7:06             ` Dmitry A. Kazakov
  2 siblings, 1 reply; 18+ messages in thread
From: Paul Rubin @ 2020-06-05 22:54 UTC (permalink / raw)


"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
> As for GMP specifically, I think that arbitrary precision numeric
> types must be an integral part of Ada. Unfortunately, this would
> introduce same mess Unbounded_String did. So, for now, I would not
> push for them until the language type system mature to accommodate
> them smoothly.

What happened with Unbounded_String if you don't mind telling the story?
I wasn't around for it.

I can see why unbounded strings and numbers could be a problem for Ada,
but that's because of storage management consequences, not the type
system.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Any good package for mathematical function in Ada?
  2020-06-05 22:54           ` Paul Rubin
@ 2020-06-06  7:06             ` Dmitry A. Kazakov
  2020-06-06 13:58               ` AdaMagica
  0 siblings, 1 reply; 18+ messages in thread
From: Dmitry A. Kazakov @ 2020-06-06  7:06 UTC (permalink / raw)


On 06/06/2020 00:54, Paul Rubin wrote:
> "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> writes:
>> As for GMP specifically, I think that arbitrary precision numeric
>> types must be an integral part of Ada. Unfortunately, this would
>> introduce same mess Unbounded_String did. So, for now, I would not
>> push for them until the language type system mature to accommodate
>> them smoothly.
> 
> What happened with Unbounded_String if you don't mind telling the story?
> I wasn't around for it.

Unbounded_String is not string and not array, end of story.

> I can see why unbounded strings and numbers could be a problem for Ada,
> but that's because of storage management consequences, not the type
> system.

No, it is the type system. Randy posted links to the drafts for 
unbounded integer and real. Same story. They are not numbers. As a 
consequence you have no conversions to/from legal numeric types, you 
need to instantiate generics. They do not match formal numeric types in 
generics. They have no attributes (some of which would have no sense 
anyway).

In essence the problem is that numeric types have no explicit interface 
a private type could implement.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: Any good package for mathematical function in Ada?
  2020-06-06  7:06             ` Dmitry A. Kazakov
@ 2020-06-06 13:58               ` AdaMagica
  0 siblings, 0 replies; 18+ messages in thread
From: AdaMagica @ 2020-06-06 13:58 UTC (permalink / raw)


Am Samstag, 6. Juni 2020 09:06:57 UTC+2 schrieb Dmitry A. Kazakov:
> No, it is the type system. Randy posted links to the drafts for 
> unbounded integer and real. Same story. They are not numbers. As a 
> consequence you have no conversions to/from legal numeric types, you 
> need to instantiate generics. They do not match formal numeric types in 
> generics. They have no attributes (some of which would have no sense 
> anyway).

GNAT CE 2020 has them (albeit not in the latest RM form). They behave much like numbers.

pragma Warnings (Off);
with Ada.Numerics.Big_Numbers.Big_Integers, Ada.Numerics.Big_Numbers.Big_Reals;
use  Ada.Numerics.Big_Numbers.Big_Integers, Ada.Numerics.Big_Numbers.Big_Reals;
pragma Warnings (On);

with Ada.Text_IO;
use  Ada.Text_IO;

procedure Main is

  I: Big_Integer := From_String ("   42   ");
  J: Big_Integer := 42;
  R: Big_Real := From_String("10.0")**100 - 1.0;
  S: Big_Real := 10.0**100 - 1/1;
  D: Big_Real := 1 / 3;

begin

  Put_Line (Boolean'(I=J)'Image);
  Put_Line (to_String (R));
  Put_Line (Boolean'Image(R=S));
  Put_Line (to_String (Numerator (S)) & to_String (Denominator (S)));
  Put_Line (to_String (D, Aft => 110));
  Put_Line (to_String (Numerator (D)) & to_String (Denominator (D)));

end Main;

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2020-06-06 13:58 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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