bernstein.cc: handle input with unions + relation violated in the whole union
[barvinok.git] / combine.c
blob201068445bf15618617d92bc1862294b19c90bdb
1 #include "combine.h"
3 /*
4 * Vector p3 is a linear combination of two vectors (p1 and p2) such that
5 * p3[pos] is zero. First element of each vector (p1,p2,p3) is a status
6 * element and is not changed in p3. The value of 'pos' may be 0 however.
7 * The parameter 'length' does not include status element one.
8 *
9 * This function was copied from the PolyLib source.
10 */
11 void Combine(Value *p1, Value *p2, Value *p3, int pos, unsigned length) {
13 Value a1, a2, gcd;
14 Value abs_a1,abs_a2,neg_a1;
16 /* Initialize all the 'Value' variables */
17 value_init(a1); value_init(a2); value_init(gcd);
18 value_init(abs_a1); value_init(abs_a2); value_init(neg_a1);
20 /* a1 = p1[pos] */
21 value_assign(a1,p1[pos]);
23 /* a2 = p2[pos] */
24 value_assign(a2,p2[pos]);
26 /* a1_abs = |a1| */
27 value_absolute(abs_a1,a1);
29 /* a2_abs = |a2| */
30 value_absolute(abs_a2,a2);
32 /* gcd = Gcd(abs(a1), abs(a2)) */
33 Gcd(abs_a1,abs_a2,&gcd);
35 /* a1 = a1/gcd */
36 value_division (a1,a1,gcd);
38 /* a2 = a2/gcd */
39 value_division (a2,a2,gcd);
41 /* neg_a1 = -(a1) */
42 value_oppose(neg_a1,a1);
44 Vector_Combine(p1+1,p2+1,p3+1,a2,neg_a1,length);
45 Vector_Normalize(p3+1,length);
47 /* Clear all the 'Value' variables */
48 value_clear(a1); value_clear(a2); value_clear(gcd);
49 value_clear(abs_a1); value_clear(abs_a2); value_clear(neg_a1);
51 return;
52 } /* Combine */