| 1 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2 |
% |
| 3 |
% Betti numbers calculation |
| 4 |
% |
| 5 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 6 |
|
| 7 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 8 |
%% Copyright (C) 1996,1998 |
| 9 |
%% Alexander Podoplelov |
| 10 |
%% |
| 11 |
%% Bergman and Anick are distributed in the hope that they will be |
| 12 |
%% useful, but WITHOUT ANY WARRANTY. No author or distributor |
| 13 |
%% accepts responsibility to anyone for the consequences of using them |
| 14 |
%% or for whether they serve any particular purpose or work at all, |
| 15 |
%% unless (s)he says so in writing. Refer to the Bergman General Public |
| 16 |
%% License for full details. |
| 17 |
|
| 18 |
%% Everyone is granted permission to copy, modify and redistribute |
| 19 |
%% bergman, but only under the conditions described in the |
| 20 |
%% Bergman General Public License. A copy of this license is |
| 21 |
%% supposed to have been given to you along with bergman so you |
| 22 |
%% can know your rights and responsibilities. It should be in a |
| 23 |
%% file named copyright. Among other things, the copyright notice |
| 24 |
%% and this notice must be preserved on all copies. |
| 25 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 26 |
|
| 27 |
|
| 28 |
% CHANGES 1997-03-19 -- ... : |
| 29 |
% RANK now calls the new procedure INPUTMATRIX2REDANDMATRIX, which |
| 30 |
% replaces the input coefficients in its matrix input with reductand |
| 31 |
% coefficients. |
| 32 |
|
| 33 |
|
| 34 |
(OFF RAISE) |
| 35 |
|
| 36 |
(GLOBAL '(anZERO)) |
| 37 |
|
| 38 |
% MPRINT (mat:matrix) : bool ; |
| 39 |
% Prints mat as a matrix to standard output and returns T, if |
| 40 |
% that is not NIL. Else it prints nothing and returns NIL. |
| 41 |
(DE MPRINT (matrix) |
| 42 |
(PROG (r c) |
| 43 |
(SETQ r matrix) |
| 44 |
L1 (COND ( (NULL r) (RETURN NIL) )) |
| 45 |
(SETQ c (CAR r)) |
| 46 |
L2 (COND ( (NULL c) (GO LNEXT) )) |
| 47 |
(PRIN2 (CAR c)) (PRIN2 (LIST2STRING '(9)) ) |
| 48 |
(SETQ c (CDR c)) |
| 49 |
(GO L2) |
| 50 |
LNEXT (TERPRI) |
| 51 |
(SETQ r (CDR r)) |
| 52 |
(GO L1) |
| 53 |
LOUT (RETURN T) |
| 54 |
) |
| 55 |
) |
| 56 |
|
| 57 |
% CFLINEPRINT (ln:lcoeff) : bool ; |
| 58 |
% Prints the list of coefficients ln in one line and returns |
| 59 |
% T if ln is non-NIL. Else it prints nothing and returns NIL. |
| 60 |
(DE CFLINEPRINT (line) |
| 61 |
(PROG (c) |
| 62 |
(COND ( (NULL (SETQ c line)) (RETURN NIL))) |
| 63 |
L1 (COND ( (NOT (CAR c)) (PRIN2 0)) |
| 64 |
( (NOT (PRINTRATCF (CAR c))) (PRIN2 1))) |
| 65 |
(COND ( (SETQ c (CDR c)) |
| 66 |
(PRIN2 (LIST2STRING '(9)) ) |
| 67 |
(GO L1) )) |
| 68 |
(TERPRI) |
| 69 |
(RETURN T) |
| 70 |
) |
| 71 |
) |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
% RANK (mat:inputmatrix) : int ; |
| 77 |
% Returns the rank of mat calculated in present coefficient |
| 78 |
% field. |
| 79 |
(DE RANK (matrix) |
| 80 |
(PROG (n m r) |
| 81 |
(COND ( (NULL matrix) (RETURN 0) )) |
| 82 |
(SETQ m (LENGTH (CAR matrix))) |
| 83 |
(SETQ n (LENGTH matrix)) |
| 84 |
(SETQ r matrix) |
| 85 |
L1 (COND |
| 86 |
( (NOT (NULL r)) |
| 87 |
(COND ( (NEQ m (LENGTH (CAR r))) |
| 88 |
(PRIN2 "***Invalid matrix format to calculate its rank") |
| 89 |
(TERPRI) |
| 90 |
(RETURN NIL) |
| 91 |
)) |
| 92 |
(SETQ r (CDR r)) |
| 93 |
(GO L1) |
| 94 |
) |
| 95 |
) |
| 96 |
(RETURN (anRANK (INPUTMATRIX2REDANDMATRIX (COPY matrix)))) |
| 97 |
) |
| 98 |
) |
| 99 |
|
| 100 |
|
| 101 |
% INPUTMATRIX2REDANDMATRIX (mtrx:inputmatrix) : matrix ; DESTRUCTIVE |
| 102 |
% Modifies the elements of mtrx so that their type is of |
| 103 |
% acceptance by further procedures. |
| 104 |
(DE INPUTMATRIX2REDANDMATRIX (mtrx) |
| 105 |
(PROG (rp cp) % Row position; Column position. |
| 106 |
(SETQ rp mtrx) |
| 107 |
Ml (COND ((NULL rp) |
| 108 |
(RETURN NIL))) |
| 109 |
(SETQ cp (CAR rp)) |
| 110 |
Sl (COND (cp |
| 111 |
(RPLACA cp (InCoeff2RedandCoeff (CAR cp))) |
| 112 |
(SETQ cp (CDR cp)) |
| 113 |
(GO Sl))) |
| 114 |
(SETQ rp (CDR rp)) |
| 115 |
(GO Ml) )) |
| 116 |
|
| 117 |
|
| 118 |
% anRANK (mat:matrix) : int ; DESTRUCTIVE |
| 119 |
% Returns the rank of mat. |
| 120 |
% Transform mat to triangular form by applying Gauss |
| 121 |
% method. |
| 122 |
(DE anRANK (matrix) |
| 123 |
(PROG (r r1 c c0 c1 tm tm1 i i1 nod a1 rt) % Changed 1997-03-20/JoeB |
| 124 |
(SETQ r matrix) |
| 125 |
(SETQ rt 0) |
| 126 |
L1 (COND ( (NULL r) (RETURN rt) )) |
| 127 |
(SETQ c (CAR r)) |
| 128 |
(SETQ i 0) |
| 129 |
L2 (COND ( (NULL c) (SETQ r (CDR r)) (GO L1) ) |
| 130 |
( (EQ (CAR c) anZERO) (SETQ i (ADD1 i)) (SETQ c (CDR c)) (GO L2) ) |
| 131 |
) |
| 132 |
(RedandLine2RedorLine c) |
| 133 |
(SETQ rt (ADD1 rt)) |
| 134 |
(SETQ r1 (CDR r)) |
| 135 |
L3 (COND ( (NULL r1) (SETQ r (CDR r)) (GO L1) )) |
| 136 |
(SETQ c1 (CAR r1)) |
| 137 |
(SETQ i1 i) |
| 138 |
L4 (COND ( (LESSP 0 i1) |
| 139 |
(SETQ i1 (SUB1 i1)) (SETQ c1 (CDR c1)) (GO L4) ) |
| 140 |
( (EQ (CAR c1) anZERO) |
| 141 |
(SETQ r1 (CDR r1)) (GO L3) ) |
| 142 |
) |
| 143 |
(ReduceLineStep (CAR r1) c1 c) |
| 144 |
(SETQ r1 (CDR r1)) |
| 145 |
(GO L3) |
| 146 |
) |
| 147 |
) |
| 148 |
|
| 149 |
|
| 150 |
(ON RAISE) |