Recent

Author Topic: Announce: Pascal libraries for maths and statistics  (Read 9971 times)

ebuxbaum

  • New member
  • *
  • Posts: 7
Announce: Pascal libraries for maths and statistics
« on: June 06, 2021, 11:10:59 am »
Hi,

I have just set up an archive on https://github.com/ebuxbaum/statistics, which contains routines in Object Pascal for general maths, vector and matrix algebra, and statistics (descriptive, decision, multivariate). User interaction is on the command line, so they should work under any OS. Also included is an extensive documentation in LaTeX.

Any comments welcome.

Sincerely

Engelbert

Leledumbo

  • Hero Member
  • *****
  • Posts: 8744
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Announce: Pascal libraries for maths and statistics
« Reply #1 on: June 06, 2021, 01:42:14 pm »
Ah, you have PCA. Thank you.

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Announce: Pascal libraries for maths and statistics
« Reply #2 on: June 13, 2021, 02:38:35 am »
GPL3? I don't know...
I thought more permissive licenses like MIT are more popular these days.

AlexTP

  • Hero Member
  • *****
  • Posts: 2365
    • UVviewsoft
Re: Announce: Pascal libraries for maths and statistics
« Reply #3 on: June 13, 2021, 04:36:58 pm »
Because of GPL I cannot use these codes,  my app has MPL 2.0 license.

schuler

  • Full Member
  • ***
  • Posts: 223
Re: Announce: Pascal libraries for maths and statistics
« Reply #4 on: June 17, 2021, 07:02:56 pm »
@ebuxbaum,
Given that I'm feeling lazy, instead of looking at the code, I'll just ask you: do you have an example/test with PCA?

Paolo

  • Sr. Member
  • ****
  • Posts: 499
Re: Announce: Pascal libraries for maths and statistics
« Reply #5 on: July 19, 2021, 08:57:43 pm »
just look at complex.pas, please note that functon Polar is wrong
Code: Pascal  [Select][+][-]
  1.  PROCEDURE Polar(z: ComplexTyp; VAR r, phi: float);
  2.  
  3. BEGIN
  4.   r := ComplexAbs(z);
  5.   IF r <> 0                                                                   // r > 0 should be enough
  6.     THEN IF Abs(Im(z) / r) = 1
  7.            THEN phi := Pi / 2 * (Im(z) / r) / Abs(Im(z) / r)  // why not just Im(z)/Abs(z) or sign(Im(z))
  8.            ELSE phi := ArcTan(Im(z) / Re(z))                      //you can stay here even with Re(z) < 0
  9.     ELSE
  10.       BEGIN
  11.         phi := 0;                                                          
  12.         IF Re(z) < 0                     //if you stay here r=0 so how is it possible that Re(z) < 0 ?
  13.           THEN
  14.             IF Im(z) <> 0                //if you stay here r=0 so how is it possible that Im(z) <> 0 ?
  15.               THEN phi := phi + Pi * Abs(Im(z)) / Im(z)
  16.               ELSE phi := Pi;
  17.       END;
  18. END;
  19.  

using arctan you cannot distinguish among quadrants (plus some redundancy in the code, see the notes)

all the code above can be made by arctan2 function, and in your case in your case you already have ComplexArg function that do the job, not tested anyway.

but as I said you can simply use arctan2

Code: Pascal  [Select][+][-]
  1. {$ifndef FPC_MATH_HAS_ARCTAN2}
  2. function arctan2(y,x : float) : float;
  3.   begin
  4.     if (x=0) then
  5.       begin
  6.         if y=0 then
  7.           arctan2:=0.0
  8.         else if y>0 then
  9.           arctan2:=pi/2
  10.         else if y<0 then  //why such test, here "else" should be sufficent
  11.           arctan2:=-pi/2;
  12.       end
  13.     else
  14.       ArcTan2:=ArcTan(y/x);  
  15.     if x<0.0 then                      
  16.       ArcTan2:=ArcTan2+pi;
  17.     if ArcTan2>pi then
  18.       ArcTan2:=ArcTan2-2*pi;
  19.   end;
  20. {$endif FPC_MATH_HAS_ARCTAN2}
  21.  

where is defined "FPC_MATH_HAS_ARCTAN2" ?

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Announce: Pascal libraries for maths and statistics
« Reply #6 on: July 19, 2021, 09:18:22 pm »
Hi!

{$define FPC_MATH_HAS_ARCTAN2}

is defined in the file mathu.inc

What  kind of complicated source is your arctan2?

Mine for a 64 bit CPU is just

Code: Pascal  [Select][+][-]
  1. function arctan2(y,x : float) : float;assembler;
  2.   asm
  3.      fldt y
  4.      fldt x
  5.      fpatan
  6.      fwait
  7.   end;  

Winni

Paolo

  • Sr. Member
  • ****
  • Posts: 499
Re: Announce: Pascal libraries for maths and statistics
« Reply #7 on: July 19, 2021, 10:30:47 pm »
@winni,
I found it in math.pas, doing ctrl+click in the code I jump there even if ti seems not reachable during debug pressing F7, but it seems active like if FPC_MATH_HAS_ARCTAN2 were not defined ($ifndef...).
I was expecting something like you showed, where is located such function ?

here laz 2.0.10, fpc 3.2.0, win 10.
« Last Edit: July 19, 2021, 10:32:22 pm by Paolo »

Paolo

  • Sr. Member
  • ****
  • Posts: 499
Re: Announce: Pascal libraries for maths and statistics
« Reply #8 on: July 19, 2021, 10:46:58 pm »
ok it is in mathu.inc, but it is disabled ! it has in front {$ifdef FPC_HAS_TYPE_EXTENDED} that seems not true...

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Announce: Pascal libraries for maths and statistics
« Reply #9 on: July 19, 2021, 11:53:17 pm »
Hi!

In my case {$ifdef FPC_HAS_TYPE_EXTENDED} is not off.

Otherwise the code would be greyed.
Remember: For 64 bit machines extended is just mapped to Double!!!

Winni

fpc 3.2.0 Lazarus 2.0.12 one Suse Tumbleweed (that is 64 bit)

ccrause

  • Hero Member
  • *****
  • Posts: 843
Re: Announce: Pascal libraries for maths and statistics
« Reply #10 on: July 20, 2021, 08:10:03 am »
@Paolo
the extended type is available on all Intel x86 processors, except on the Windows 64-bit platform.

Which would explain why FPC_HAS_TYPE_EXTENDED is not defined in your case.

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: Announce: Pascal libraries for maths and statistics
« Reply #11 on: July 20, 2021, 10:08:46 am »
hello,
and  what about DMath, LMath packages ? do they do the same job ?
Quote
DMath is a mathematical library for Delphi and Free Pascal, written natively in Pascal.

It includes routines for:

Elementary functions
Special functions
Probability distributions
Linear algebra
Optimisation
Polinomials
Numerical integration and differential equations
Fourier transform
Random numbers
Statistics
Linear regression
Multilinear regression and principal component analysis
Nonlinear regression with a library of non-linear regression models
Complex numbers and functions
Fractals and chaos
Expression parsing
Graphical functions
Author: Jean Debord, Laboratoire de Pharmacologie, Faculté de Médecine, Limoges, France

License: LGPL 2.0
Friendly, J.P
« Last Edit: July 20, 2021, 11:26:37 am by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

Paolo

  • Sr. Member
  • ****
  • Posts: 499
Re: Announce: Pascal libraries for maths and statistics
« Reply #12 on: July 20, 2021, 01:39:01 pm »
@ccrause, thaks it seems the cause (sigh!  :'()

 

TinyPortal © 2005-2018