mathpaqs_20230121.0.0_773568e5/lin_alg/generic_real_linear_equations.ads

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
-- Author: Jon Squire
-- Original code here:
--   http://www.cs.umbc.edu/~squire/adaclass/gnatmath95/
-- Changes:
--   - Generic_Real_Arrays = Ada.Numerics.Generic_Real_Arrays (Ada 2005)
--   - removed dependency on others non-standard packages
--   - (18-Mar-2015): Integer_Vector as generic parameter. Added a few "_JS"
--       suffixes to address ambiguities with Ada.Numerics.Generic_Real_Arrays
--   - many fixes

with Ada.Numerics.Generic_Real_Arrays;

generic
  type Real is digits <>;
  with package Real_Arrays is new Ada.Numerics.Generic_Real_Arrays (Real);
  type Integer_Vector is array (Integer range <>) of Integer;

package Generic_Real_Linear_Equations is

  use Real_Arrays;

  function Linear_Equations ( A : Real_Matrix ;
                              Y : Real_Vector ) return Real_Vector ;

  function Linear_Equations ( A : Real_Matrix ;
                              Y : Real_Matrix ) return Real_Matrix ;

  --  Suffix "_JS" was added to address ambiguity with
  --  Ada 2005's Ada.Numerics.Generic_Real_Arrays.Determinant and .Inverse

  function Determinant_JS ( A : Real_Matrix ) return Real ;

  function Inverse_JS ( A : Real_Matrix ) return Real_Matrix ;

  procedure Inverse_JS ( A : in out Real_Matrix ) ;

  -- !! Crout_Solve is flawed !!
  function Crout_Solve ( A : Real_Matrix ;
                         Y : Real_Vector ) return Real_Vector ;

  function Cholesky_Decomposition ( A : Real_Matrix) return Real_Matrix ;

  function Cholesky_Solve ( L : Real_Matrix ;
                            Y : Real_Vector ) return Real_Vector ;

  procedure LU_Decomposition ( A : Real_Matrix ;
                               L : in out Real_Matrix ;
                               U : in out Real_Matrix ;
                               P : in out Integer_Vector) ;

  function LU_Solve ( L : Real_Matrix ;
                      U : Real_Matrix ;
                      P : Integer_Vector ;
                      Y : Real_Vector ) return Real_Vector ;

  -- !! QR_Decomposition fixed, but still implemented only for square matrices !!
  procedure QR_Decomposition ( A : Real_Matrix ;
                               Q : in out Real_Matrix ;
                               R : in out Real_Matrix ) ;

  function QR_Solve ( Q : Real_Matrix ;
                      R : Real_Matrix ;
                      Y : Real_Vector ) return Real_Vector ;

  -- !! SV_Decomposition: Caution - not tested !!
  procedure SV_Decomposition ( A : Real_Matrix ;
                               UU : in out Real_Matrix ;
                               VV : in out Real_Matrix ;
                               WW : in out Real_Vector ) ;

  -- !! SV_Solve: Caution - not tested !!
  function SV_Solve ( U : Real_Matrix ;
                      V : Real_Matrix ;
                      W : Real_Vector ;
                      Y : Real_Vector ) return Real_Vector ;

  --  Matrix_Data_Error is raised for singular, non positive definate, not symmetric, etc.
  Matrix_Data_Error : exception;

end Generic_Real_Linear_Equations ;