PIPS
determinant.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include "linear_assert.h"
#include "boolean.h"
#include "arithmetique.h"
#include "matrice.h"
+ Include dependency graph for determinant.c:

Go to the source code of this file.

Functions

void matrice_determinant (matrice a, int n, result)
 package matrice More...
 
void matrice_sous_determinant (matrice a, int n, int i, int j, result)
 void matrice_sous_determinant(matrice a, int n,int i, int j, int result[]) calculate sub determinant of a matrix More...
 

Function Documentation

◆ matrice_determinant()

void matrice_determinant ( matrice  a,
int  n,
result   
)

package matrice

int matrice_determinant(matrice a, int n, int * result):
calculate determinant of an (nxn) rational matrix a

The result consists of two integers, a numerator result[1] and a denominator result[0].

Algorithm: integer matrix triangularisation by Hermite normal form (because the routine is available)

Complexity: O(n**3) – up to gcd computations...

Authors: Francois Irigoin, September 1989, Yi-qing Yang, January 1990 output

cette routine est FAUSSE car la factorisation de Hermite peut s'appuyer sur des matrice unimodulaires de determinant 1 ou -1. Il faudrait donc ecrire un code de calcul de determinant de matrice unimodulaire...

Ou tout reprendre avec une triangularisation rapide et n'utilisant que des matrice de determinant +1. Voir mon code des US. Cette triangularisation donnera en derivation une routine d'inversion rapide pour matrice unimodulaire

matrice_hermite expects an integer matrix

product of diagonal elements

product of determinants of three matrixs P, H, Q

free useless matrices

reduce result

Parameters
nint matrice_determinant(matrice a, int n, int * result):
calculate determinant of an (nxn) rational matrix a

The result consists of two integers, a numerator result[1] and a denominator result[0].

Algorithm: integer matrix triangularisation by Hermite normal form (because the routine is available)

Complexity: O(n**3) – up to gcd computations...

Authors: Francois Irigoin, September 1989, Yi-qing Yang, January 1990 input

Definition at line 54 of file determinant.c.

58 {
59  Value determinant_gcd;
60  Value determinant_p;
61  Value determinant_q;
62 
63  Value denominator = DENOMINATOR(a);
64  int i;
65  /* cette routine est FAUSSE car la factorisation de Hermite peut
66  s'appuyer sur des matrice unimodulaires de determinant 1 ou -1.
67  Il faudrait donc ecrire un code de calcul de determinant de
68  matrice unimodulaire...
69 
70  Ou tout reprendre avec une triangularisation rapide et n'utilisant
71  que des matrice de determinant +1. Voir mon code des US.
72  Cette triangularisation donnera en derivation une routine
73  d'inversion rapide pour matrice unimodulaire */
74 
75  assert(n > 0 && denominator != 0);
76 
77  switch(n) {
78 
79  case 1:
80  result[1] = ACCESS(a,n,1,1);
81  result[0] = denominator;
82  break;
83 
84  case 2:
85  {
86  register Value v1, v2, a1, a2;
87  a1 = ACCESS(a,n,1,1);
88  a2 = ACCESS(a,n,2,2);
89  v1 = value_mult(a1,a2);
90  a1 = ACCESS(a,n,1,2);
91  a2 = ACCESS(a,n,2,1);
92  v2 = value_mult(a1,a2);
93 
94  result[1] = value_minus(v1,v2);
95  result[0] = value_mult(denominator,denominator);
96 
97  break;
98  }
99  default: {
100  matrice p = matrice_new(n,n);
101  matrice h = matrice_new(n,n);
102  matrice q = matrice_new(n,n);
103 
104  /* matrice_hermite expects an integer matrix */
105  DENOMINATOR(a) = VALUE_ONE;
106  matrice_hermite(a,n,n,p,h,q,&determinant_p,&determinant_q);
107  DENOMINATOR(a) = denominator;
108 
109  /* product of diagonal elements */
110  result[1] = ACCESS(h,n,1,1);
111  result[0] = denominator;
112  for(i=2; i <= n && result[1]!=0; i++) {
113  register Value a = ACCESS(h,n,i,i);
114  value_product(result[1], a);
115  value_product(result[0], denominator);
116  determinant_gcd = pgcd_slow(result[0],result[1]);
117  if(value_notone_p(determinant_gcd)) {
118  value_division(result[0],determinant_gcd);
119  value_division(result[1],determinant_gcd);
120  }
121  }
122 
123  /* product of determinants of three matrixs P, H, Q */
124  value_product(result[1],determinant_p);
125  value_product(result[1],determinant_q);
126 
127  /* free useless matrices */
128  matrice_free(p);
129  matrice_free(h);
130  matrice_free(q);
131  }
132  }
133  /* reduce result */
134  determinant_gcd = pgcd_slow(result[0],result[1]);\
135  if(value_notone_p(determinant_gcd)) {
136  value_division(result[0],determinant_gcd);
137  value_division(result[1],determinant_gcd);
138  }
139 }
#define value_minus(v1, v2)
#define value_notone_p(val)
int Value
#define value_division(ref, val)
#define value_product(v, w)
#define VALUE_ONE
#define value_mult(v, w)
whether the default is protected or not this define makes no sense any more...
Value pgcd_slow(Value, Value)
pgcd.c
Definition: pgcd.c:44
#define DENOMINATOR(matrix)
int DENOMINATEUR(matrix): acces au denominateur global d'une matrice matrix La combinaison *(&()) est...
Definition: matrice-local.h:93
#define matrice_free(m)
Definition: matrice-local.h:78
#define ACCESS(matrix, column, i, j)
Macros d'acces aux elements d'une matrice.
Definition: matrice-local.h:86
#define matrice_new(n, m)
Allocation et desallocation d'une matrice.
Definition: matrice-local.h:77
Value * matrice
package matrice
Definition: matrice-local.h:71
void matrice_hermite(Value *MAT, int n, int m, Value *P, Value *H, Value *Q, Value *det_p, Value *det_q)
package matrice
Definition: hermite.c:78
#define assert(ex)
Definition: newgen_assert.h:41

References ACCESS, assert, DENOMINATOR, matrice_free, matrice_hermite(), matrice_new, pgcd_slow(), value_division, value_minus, value_mult, value_notone_p, VALUE_ONE, and value_product.

Referenced by matrice_sous_determinant().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ matrice_sous_determinant()

void matrice_sous_determinant ( matrice  a,
int  n,
int  i,
int  j,
result   
)

void matrice_sous_determinant(matrice a, int n,int i, int j, int result[]) calculate sub determinant of a matrix

The sub determinant indicated by (i,j) is the one obtained by deleting row i and column j from matrix of dimension n. The result passed back consists of two integers, a numerator result[1] and a denominator result[0].

Precondition: n >= i > 0 && n >= j > 0

Algorithm: put 0 in row i and in column j, and 1 in a[i,j], and then call matrice_determinant, restore a

Complexity: O(n**3) output

save column j

save row i, but for the (i,j) elements

restore row i

restore column j, with proper (i,j) element

Parameters
nThe sub determinant indicated by (i,j) is the one obtained by deleting row i and column j from matrix of dimension n. The result passed back consists of two integers, a numerator result[1] and a denominator result[0].

Precondition: n >= i > 0 && n >= j > 0

Algorithm: put 0 in row i and in column j, and 1 in a[i,j], and then call matrice_determinant, restore a

Complexity: O(n**3) input matrix

Parameters
iThe sub determinant indicated by (i,j) is the one obtained by deleting row i and column j from matrix of dimension n. The result passed back consists of two integers, a numerator result[1] and a denominator result[0].

Precondition: n >= i > 0 && n >= j > 0

Algorithm: put 0 in row i and in column j, and 1 in a[i,j], and then call matrice_determinant, restore a

Complexity: O(n**3) dimension of matrix

Definition at line 156 of file determinant.c.

161 {
162  int r;
163  int c;
164  matrice save_row = matrice_new(1,n);
165  matrice save_column = matrice_new(1,n);
166 
167  /* save column j */
168  for(r=1; r <= n; r++) {
169  ACCESS(save_column,1,1,r) = ACCESS(a,n,r,j);
170  ACCESS(a,n,r,j) = 0;
171  }
172  /* save row i, but for the (i,j) elements */
173  for(c=1; c <= n; c++) {
174  ACCESS(save_row,1,1,c) = ACCESS(a,n,i,c);
175  ACCESS(a,n,i,c) = 0;
176  }
177  ACCESS(a,n,i,j) = VALUE_ONE;
178 
179  matrice_determinant(a,n,result);
180 
181  /* restore row i */
182  for(c=1; c <= n; c++) {
183  ACCESS(a,n,i,c) = ACCESS(save_row,1,1,c);
184  }
185  /* restore column j, with proper (i,j) element */
186  for(r=1; r <= n; r++) {
187  ACCESS(a,n,r,j) = ACCESS(save_column,1,1,r);
188  }
189 
190  matrice_free(save_row);
191  matrice_free(save_column);
192 }
void matrice_determinant(matrice a, int n, result)
package matrice
Definition: determinant.c:54

References ACCESS, matrice_determinant(), matrice_free, matrice_new, and VALUE_ONE.

Referenced by matrice_triangulaire_inversion().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: