doc: document Polyhedron_Reduced_Basis and Polyhedron_Sample
[barvinok.git] / combine.c
blob0eb0beb873ff53ae25715989cbe06318251c1fbe
1 #include <polylib/polylibgmp.h>
2 #include "combine.h"
4 /*
5 * Vector p3 is a linear combination of two vectors (p1 and p2) such that
6 * p3[pos] is zero. First element of each vector (p1,p2,p3) is a status
7 * element and is not changed in p3. The value of 'pos' may be 0 however.
8 * The parameter 'length' does not include status element one.
9 *
10 * This function was copied from the PolyLib source.
11 */
12 void Combine(Value *p1, Value *p2, Value *p3, int pos, unsigned length) {
14 Value a1, a2, gcd;
15 Value abs_a1,abs_a2,neg_a1;
17 /* Initialize all the 'Value' variables */
18 value_init(a1); value_init(a2); value_init(gcd);
19 value_init(abs_a1); value_init(abs_a2); value_init(neg_a1);
21 /* a1 = p1[pos] */
22 value_assign(a1,p1[pos]);
24 /* a2 = p2[pos] */
25 value_assign(a2,p2[pos]);
27 /* a1_abs = |a1| */
28 value_absolute(abs_a1,a1);
30 /* a2_abs = |a2| */
31 value_absolute(abs_a2,a2);
33 /* gcd = Gcd(abs(a1), abs(a2)) */
34 Gcd(abs_a1,abs_a2,&gcd);
36 /* a1 = a1/gcd */
37 value_division (a1,a1,gcd);
39 /* a2 = a2/gcd */
40 value_division (a2,a2,gcd);
42 /* neg_a1 = -(a1) */
43 value_oppose(neg_a1,a1);
45 Vector_Combine(p1+1,p2+1,p3+1,a2,neg_a1,length);
46 Vector_Normalize(p3+1,length);
48 /* Clear all the 'Value' variables */
49 value_clear(a1); value_clear(a2); value_clear(gcd);
50 value_clear(abs_a1); value_clear(abs_a2); value_clear(neg_a1);
52 return;
53 } /* Combine */