PIPS
scanning_base.c
Go to the documentation of this file.
1 /*
2 
3  $Id: scanning_base.c 23065 2016-03-02 09:05:50Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of PIPS.
8 
9  PIPS is free software: you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 #ifdef HAVE_CONFIG_H
25  #include "pips_config.h"
26 #endif
27 /*
28  * package hyperplane.
29  *
30  * Build a change of basis matrix G compatible with a hyperplane direction h
31  */
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 /* #include <sys/stdtypes.h> */ /* for debug with dbmalloc */
36 /* #include "stdlib.h" */
37 
38 #include "genC.h"
39 #include "linear.h"
40 #include "ri.h"
41 #include "misc.h"
42 
43 
44 #include "boolean.h"
45 #include "arithmetique.h"
46 #include "vecteur.h"
47 #include "contrainte.h"
48 #include "sc.h"
49 #include "matrice.h"
50 
51 #include "hyperplane.h"
52 
53 /* void scanning_base_hyperplane(int h[],int n,matrice U)
54  * compute the matrix U :
55  * -> -> ->
56  * U1 = h (U1 the first column of U)
57  * determinant(U) = +(/-)1.
58  *
59  * Let G the scanning basis, the relation between U and T is
60  * -1 T
61  * G = (U )
62  * the parameters of the function are:
63  *
64  * int h[] : hyperplan direction ---- input
65  * int n : iteration dimension ---- input
66  * matrice G : matrix ---- output
67  *
68  */
70 Value h[];
71 int n;
72 matrice G;
73 {
74  int k=1;
75 
76  if (value_zero_p(h[0])){
77  /* search the first k / h[k]!=0 */
78  while(k<n && value_zero_p(h[k]))
79  k++;
80  if (k==n) user_error("scanning_base_hyperplane", "h is null vector\n");
81  else{ /* permution de h[0] et h[k] */
82  h[0] = h[k];
83  h[k] = VALUE_ZERO;
84  base_G_h1_unnull(h,n,G);
85  matrice_swap_rows(G,n,n,1,k+1);
86  }
87  }
88  else
89  base_G_h1_unnull(h,n,G);
90 }
91 
92 /*void base_G_h1_unnull(int h[],int n,matrice G)
93  */
94 void base_G_h1_unnull(h, n, G)
95 Value h[];
96 int n;
97 matrice G;
98 {
99  matrice U = matrice_new(n,n);
100  matrice G1 = matrice_new(n,n);
101  Value det_Ui = VALUE_ONE;
102  Value det_Ui1 = VALUE_ZERO; /* determinant of Ui and Ui-1*/
103  Value Xi,Yi;
104  int i,j;
105  Value r;
106 
107  /* computation of matrix U */
108  assert(n>0);
109  assert(h[0]!=0);
110  /* initialisation */
111  matrice_nulle(U,n,n);
112  ACCESS(U,n,1,1) = h[0];
113  det_Ui1 = h[0];
114 
115  for(i=2; i<=n; i++){
116  /* computation of Xi,Yi / Xi.det(Ui-1) - Yi.hi = GCD(det(Ui-1),hi) */
117  det_Ui = bezout_grl(det_Ui1,h[i-1],&Xi,&Yi);
118  if (i ==2 || i%2 != 0)
119  value_oppose(Yi);
120  /* make Ui - the i-th line: U[i,1]=h[i-1],U[i,2..n-1] =0,U[i,n] = Xi*/
121  ACCESS(U,n,i,1) = h[i-1];
122  ACCESS(U,n,i,i) = Xi;
123  /* ->i-1 */
124  /* the i-th column:U[1..n-1] = Yi/det(Ui-1) . h */
125  for (j=1; j<=i-1; j++){
126  r = value_div(h[j-1],det_Ui1);
127  ACCESS(U,n,j,i) = value_mult(Yi,r);
128  }
129  det_Ui1 = det_Ui;
130  }
131  for (i=1; i<=n; i++)
132  /* -> ->*/
133  /* divide U1 par GCD(h) */
134  value_division(ACCESS(U,n,i,1),det_Ui);
135 
136  /* computation of matrix G */
138  matrice_transpose(G1,G,n,n);
139 }
#define VALUE_ZERO
#define value_oppose(ref)
#define value_zero_p(val)
int Value
#define value_division(ref, val)
#define VALUE_ONE
#define value_mult(v, w)
whether the default is protected or not this define makes no sense any more...
#define value_div(v1, v2)
Value bezout_grl(Value, Value, Value *, Value *)
int bezout_grl(int a, int b, int *x, int *y): calcule x et y, les deux entiers quelconcs qui verifien...
Definition: pgcd.c:324
#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_general_inversion(matrice a, matrice inv_a, int n)
void matrice_general_inversion(matrice a; matrice inv_a; int n) calcul de l'inversion du matrice gene...
Definition: inversion.c:222
void matrice_transpose(matrice a, matrice a_t, int n, int m)
package matrice
Definition: matrice.c:48
void matrice_swap_rows(matrice a, int n, int m, int r1, int r2)
void matrice_swap_rows(matrice a, int n, int m, int r1, int r2): exchange rows r1 and r2 of an (nxm) ...
Definition: matrice.c:230
void matrice_nulle(matrice Z, int n, int m)
void matrice_nulle(matrice Z, int n, int m): Initialisation de la matrice Z a la valeur matrice nulle
Definition: matrice.c:311
#define user_error(fn,...)
Definition: misc-local.h:265
#define assert(ex)
Definition: newgen_assert.h:41
#define G(j, a, b)
maybe most of them should be functions?
void scanning_base_hyperplane(h, int n, matrice G)
package hyperplane.
Definition: scanning_base.c:69
void base_G_h1_unnull(h, int n, matrice G)
oid base_G_h1_unnull(int h[],int n,matrice G)
Definition: scanning_base.c:94